Skip to content

[RL-67] Emit type sidecars during builds (Milestone 2) - #43

Merged
yeskiy merged 1 commit into
mainfrom
rl-67-typed-rs-imports-m2
Jun 28, 2026
Merged

[RL-67] Emit type sidecars during builds (Milestone 2)#43
yeskiy merged 1 commit into
mainfrom
rl-67-typed-rs-imports-m2

Conversation

@yeskiy

@yeskiy yeskiy commented Jun 28, 2026

Copy link
Copy Markdown
Owner

What

Milestone 2 of typed .rs imports (RL-67): an opt-in types option (default off) that makes a normal build also write the <name>.d.rs.ts sidecar, so types stay fresh for tsc/ESLint without running the gen-types CLI. Opt-in (not default-on) so existing users see no new files in their source tree unless they ask.

How

  • pack.js - the shared engine every surface calls gains an emitTypes flag. When set it keeps wasm-bindgen's typings in the build it already runs (no second wasm-pack run), transforms the generated .d.ts with the M1 engine, and writes the sidecar. The emission is a pure side effect: the module a consumer imports is byte-identical whether the option is on or off (asserted by a test).
  • src/utils/writeSidecar.util.js - shared sidecar writer; generateTypes (M1) refactored to reuse it (DRY).
  • Surfaces - a types: boolean option (default off) on the webpack loader, the vite/rollup/esbuild/bun plugins, and the Next helper, threaded down to emitTypes. The Next helper now spreads a shared {logLevel, types} object onto every webpack pass and turbopack rule.
  • eslint ignores the generated *.d.rs.ts (joins the existing generated-output ignores).

Verified locally (GNU toolchain)

  • 20 src unit tests, incl. the byte-identical-glue proof and the per-surface threading (webpack loader, all 3 turbopack rules, rollup via shared-load).
  • example/typed-imports: M1 fidelity suite + a new test proving the webpack build writes the sidecar with types: true.
  • Regressions unchanged on the default-off path: node-webpack 3/3, esbuild 3/3, rollup 3/3.
  • eslint clean.

Scope

Milestone 2 of the epic. Remaining: the tsserver Language Service plugin (live editor types, no extension), classes/structs, docs.

Add an opt-in `types` option (default off) on every surface: the webpack
loader, the vite/rollup/esbuild/bun plugins, and the Next helper. When set, the
build also writes the `<name>.d.rs.ts` sidecar, reusing the wasm-pack run it
already does - wasm-bindgen's typings are kept instead of dropped, and the
generated `.d.ts` is transformed into the sidecar. The module a consumer imports
is byte-identical whether the option is on or off.

- pack.js: `emitTypes` keeps the typings and writes the sidecar as a side effect
- src/utils/writeSidecar.util.js: shared sidecar writer; generateTypes reuses it
- index.js / shared-load / vite / rollup / esbuild / bun / next: the `types` option, default off
- eslint: ignore generated `*.d.rs.ts`

Refs: RL-67
@yeskiy
yeskiy merged commit d70f9bf into main Jun 28, 2026
163 checks passed
@yeskiy
yeskiy deleted the rl-67-typed-rs-imports-m2 branch June 28, 2026 22:32
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant