Skip to content

feat(bundling): integrate oxc-transform for TypeScript declaration generation#35113

Open
benpsnyder wants to merge 3 commits intonrwl:masterfrom
benpsnyder:feat/oxc-transform
Open

feat(bundling): integrate oxc-transform for TypeScript declaration generation#35113
benpsnyder wants to merge 3 commits intonrwl:masterfrom
benpsnyder:feat/oxc-transform

Conversation

@benpsnyder
Copy link
Copy Markdown
Contributor

@benpsnyder benpsnyder commented Apr 1, 2026

Current Behavior

TypeScript declaration (.d.ts) generation in Nx library builds relies exclusively on the TypeScript compiler (tsc), either via @rollup/plugin-typescript, rollup-plugin-typescript2, or vite-plugin-dts. This works but is significantly slower than the JavaScript compilation step, especially in large monorepos. There is no way to use faster alternatives like OXC's isolatedDeclaration for .d.ts emission.

Expected Behavior

A new useOxcDeclarations option is available across @nx/rollup, @nx/esbuild, and @nx/vite that uses oxc-transform's isolatedDeclaration() to generate .d.ts files instead of tsc. This is significantly faster and requires isolatedDeclarations: true in the project's tsconfig.

What's included

Shared core (@nx/js):

  • oxc-declaration-emitter.ts — standalone function that walks source files and emits .d.ts via oxc-transform's isolatedDeclaration(). Supports sourcemaps and @internal stripping.
  • oxc-declarations.ts — Rollup plugin wrapper around the emitter, used by both @nx/rollup and @nx/vite
  • Unit tests for the Rollup plugin (328 lines)
  • oxcTransformVersion added to versions.ts

@nx/rollup:

  • useOxcDeclarations option in withNx() — when enabled with SWC/Babel compiler, skips the TypeScript plugin entirely (SWC/Babel handles JS, OXC handles declarations)
  • Schema and type updates
  • Conditional oxc-transform dependency installation in ensure-dependencies.ts

@nx/esbuild:

  • useOxcDeclarations option in the esbuild executor — runs the OXC emitter as a post-build step alongside the existing emitDeclarationOnly tsc pass (or as a replacement when enabled)
  • Schema and type updates

@nx/vite:

  • nxOxcDeclarationsPlugin — a Vite plugin that wraps the shared Rollup plugin for use in vite.config.ts
  • Conditional dependency installation and declarations: 'oxc' option in the configuration generator

Architecture

@nx/js (shared core)
├── oxc-declaration-emitter.ts    — walks files, calls isolatedDeclaration()
└── plugins/rollup/oxc-declarations.ts — Rollup/Vite plugin wrapper

@nx/rollup  → uses oxc-declarations plugin via withNx({ useOxcDeclarations: true })
@nx/esbuild → calls emitOxcDeclarations() as post-build step
@nx/vite    → re-exports as nxOxcDeclarationsPlugin() for vite.config.ts

Context: AnalogJS and ng-packagr

This work is motivated by the OXC ecosystem adoption tracked in our broader issue. AnalogJS 3.0-alpha already uses oxc-transform for declaration generation across 15+ packages. ng-packagr is also preparing for OXC-based declarations (TypeScript 6 with isolatedDeclarations landed in ng-packagr#3259, oxc-transform is staged in ng-packagr#3252).

Related Issue(s)

#35111

@benpsnyder benpsnyder requested a review from a team as a code owner April 1, 2026 03:46
@benpsnyder benpsnyder requested a review from MaxKless April 1, 2026 03:46
@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 1, 2026

Deploy Preview for nx-docs canceled.

Name Link
🔨 Latest commit c9fcd31
🔍 Latest deploy log https://app.netlify.com/projects/nx-docs/deploys/69cc952387deca000898f7de

@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 1, 2026

Deploy Preview for nx-dev canceled.

Name Link
🔨 Latest commit c9fcd31
🔍 Latest deploy log https://app.netlify.com/projects/nx-dev/deploys/69cc9523222c440008fd7497

Comment thread packages/js/src/plugins/rollup/oxc-declarations.ts Outdated
@FrozenPandaz FrozenPandaz added the priority: low Low Priority (does not affect many people or not severely or has an easy workaround) label Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority: low Low Priority (does not affect many people or not severely or has an easy workaround)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants