Adopt explicit type imports and re-enable onlyRemoveTypeImports - #443
Conversation
|
All changed packages have been documented.
Show changes
|
## What Cleans up and modernizes the Babel-based build tooling, removing duplicated configuration and giving the Rollup/Vite plugin a real API. ### `@alloy-js/babel-preset` - Converted from plain JS to TypeScript with real type declarations, so consumers import the preset without `@ts-expect-error`. - package.json hygiene: description/author/homepage/bugs/exports/types, `build`/`clean` scripts, `node >=22`. ### `@alloy-js/rollup-plugin` - Real typed `AlloyPluginOptions` (`addSourceInfo`, `sourceMaps`) that are actually forwarded (previously ignored). - Adds a Vite `config` hook that auto-configures `esbuild.jsx: "preserve"` and the `source` resolve/ssr conditions, so **consumers no longer set these by hand**. - Typed `PluginOption` return (was `any`). ### Consumers - `@alloy-js/cli` and the plugin compose the typed preset chain inline (`@babel/preset-typescript` + Alloy preset). - Removed the now-redundant `esbuild`/`resolve.conditions`/`ssr` boilerplate from 16 `vitest.config.ts` files. ## Validation - `pnpm build` ✔ - `pnpm test` — 243 files / 2103 tests ✔ - `pnpm run lint` (0 warnings), `format:check`, `sync-publish-config:check`, `chronus verify` ✔ ## Notes The stale assumption that `onlyRemoveTypeImports: false` was required is no longer true — #443 re-enabled the Babel 8 default via explicit type imports, so the preset chain uses `typescriptPreset` plainly.
Fixes #442
What
Migrate the codebase to explicit type-only imports/exports (
import type/export type) so we can drop the Babel 8 stopgap and rely on the defaultonlyRemoveTypeImports: true.Approach:
verbatimModuleSyntaxRather than a lint rule, enforcement is done via TypeScript's
verbatimModuleSyntax(added totsconfig.base.json). It's compiler-enforced by thetsctypecheck the build already runs, and — unlike oxlint'sconsistent-type-imports— it also coverssamples/**,**/scripts/**, and other oxlint-ignored dirs. It errors (TS1484/TS1485) precisely on the pure type symbols that would break at runtime underonlyRemoveTypeImports: true.Changes
tsconfig.base.json: enableverbatimModuleSyntax.import type/export type(bulk-applied via oxlint'sconsistent-type-imports/consistent-type-exportsfixer as a one-time mechanical tool; the rules are not kept in.oxlintrc.json). This includes previously oxlint-ignored dirs:samples/**,**/scripts/**, andpackages/babel-plugin-alloy(NodePath).onlyRemoveTypeImports: falseoverride inpackages/cli/src/babel.tsandpackages/rollup-plugin/src/index.ts(Babel 8 default istrue).packages/core/testing/index.ts: theexport * from "./extend-expect.js"re-export was rewritten toexport type *, which dropped theexpect.extend(...)side effect that registers thetoRenderTomatchers. Added an explicit side-effectimport "./extend-expect.js"alongside the type-only re-export.Verification
pnpm build✅pnpm test— 210 files / 1717 tests pass ✅ (incl.packages/core/test/browser-build.test.ts)pnpm lint✅pnpm format:check✅npx chronus verify✅