Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@
"open": "^8.4.0",
"openai": "~4.3.1",
"ora": "5.3.0",
"oxc-transform": "^0.123.0",
"parse-markdown-links": "^1.0.4",
"parse5": "4.0.0",
"picocolors": "catalog:",
Expand Down
63 changes: 61 additions & 2 deletions packages/esbuild/src/executors/esbuild/esbuild.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
runTypeCheck as _runTypeCheck,
TypeCheckOptions,
} from '@nx/js';
import { emitOxcDeclarations } from '@nx/js/src/utils/typescript/oxc-declaration-emitter';
import * as esbuild from 'esbuild';
import { normalizeOptions } from './lib/normalize';

Expand Down Expand Up @@ -136,6 +137,36 @@ export async function* esbuildExecutor(
setup(build: esbuild.PluginBuild) {
build.onEnd(async (result: esbuild.BuildResult) => {
if (
options.useOxcDeclarations &&
options.declaration
) {
// Type-check without emitting if needed
if (!options.skipTypeCheck) {
const typeCheckOpts = getTypeCheckOptions(
options,
context
);
typeCheckOpts.mode = 'noEmit';
const { errors, warnings } =
await _runTypeCheck(typeCheckOpts);
if (errors.length > 0 || warnings.length > 0) {
await printDiagnostics(errors, warnings);
}
hasTypeErrors = errors.length > 0;
}
// Emit declarations with oxc
const projectRoot =
context.projectGraph.nodes[context.projectName]
.data.root;
const oxcResult = await emitOxcDeclarations({
projectRoot: join(context.root, projectRoot),
outDir: options.outputPath,
rootDir:
options.declarationRootDir ?? context.root,
});
hasTypeErrors =
hasTypeErrors || oxcResult.errors.length > 0;
} else if (
!options.skipTypeCheck ||
(options.isTsSolutionSetup && options.declaration)
) {
Expand Down Expand Up @@ -191,8 +222,36 @@ export async function* esbuildExecutor(
}
);
} else {
// Run type-checks first and bail if they don't pass.
if (
// Run type-checks and/or declaration emission.
if (options.useOxcDeclarations && options.declaration) {
// When using oxc for declarations, run type-check separately (noEmit mode)
// if needed, then emit declarations with oxc-transform.
if (!options.skipTypeCheck) {
const typeCheckOpts = getTypeCheckOptions(options, context);
// Override to noEmit since oxc handles declaration emission
typeCheckOpts.mode = 'noEmit';
const { errors, warnings } = await _runTypeCheck(typeCheckOpts);
if (errors.length > 0 || warnings.length > 0) {
await printDiagnostics(errors, warnings);
}
if (errors.length > 0) {
yield { success: false };
return;
}
}

const projectRoot =
context.projectGraph.nodes[context.projectName].data.root;
const { errors } = await emitOxcDeclarations({
projectRoot: join(context.root, projectRoot),
outDir: options.outputPath,
rootDir: options.declarationRootDir ?? context.root,
});
if (errors.length > 0) {
yield { success: false };
return;
}
} else if (
!options.skipTypeCheck ||
(options.isTsSolutionSetup && options.declaration)
) {
Expand Down
6 changes: 6 additions & 0 deletions packages/esbuild/src/executors/esbuild/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ export interface EsBuildExecutorOptions {
bundle?: boolean;
declaration?: boolean;
declarationRootDir?: string;
/**
* Use oxc-transform for generating TypeScript declaration files (.d.ts)
* instead of the TypeScript compiler. Requires `isolatedDeclarations: true`
* in the project's tsconfig.
*/
useOxcDeclarations?: boolean;
deleteOutputPath?: boolean;
esbuildOptions?: Record<string, any>;
esbuildConfig?: string;
Expand Down
5 changes: 5 additions & 0 deletions packages/esbuild/src/executors/esbuild/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@
"type": "string",
"description": "Sets the rootDir for the declaration (*.d.ts) files."
},
"useOxcDeclarations": {
"type": "boolean",
"description": "Use oxc-transform for generating TypeScript declaration files (.d.ts) instead of the TypeScript compiler. Requires `isolatedDeclarations: true` in the project's tsconfig. Significantly faster than TSC-based emission.",
"default": false
},
"watch": {
"type": "boolean",
"description": "Enable re-building when files change.",
Expand Down
4 changes: 4 additions & 0 deletions packages/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,13 @@
"nx": "workspace:*"
},
"peerDependencies": {
"oxc-transform": "^0.123.0",
"verdaccio": "^6.0.5"
},
"peerDependenciesMeta": {
"oxc-transform": {
"optional": true
},
"verdaccio": {
"optional": true
}
Expand Down
Loading