nx 23.0.0-beta.2 → 23.0.0-beta.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/init-local.js +11 -20
- package/dist/bin/nx.d.ts +1 -0
- package/dist/bin/nx.js +28 -2
- package/dist/plugins/package-json.js +4 -2
- package/dist/src/adapter/ngcli-adapter.d.ts +2 -1
- package/dist/src/adapter/ngcli-adapter.js +25 -2
- package/dist/src/ai/clone-ai-config-repo.js +20 -3
- package/dist/src/analytics/analytics.js +10 -1
- package/dist/src/command-line/add/completion.d.ts +1 -0
- package/dist/src/command-line/add/completion.js +15 -0
- package/dist/src/command-line/affected/completion.d.ts +1 -0
- package/dist/src/command-line/affected/completion.js +15 -0
- package/dist/src/command-line/completion/argv-layout.d.ts +6 -0
- package/dist/src/command-line/completion/argv-layout.js +19 -0
- package/dist/src/command-line/completion/command-completions.d.ts +19 -0
- package/dist/src/command-line/completion/command-completions.js +120 -0
- package/dist/src/command-line/completion/command-handlers.d.ts +30 -0
- package/dist/src/command-line/completion/command-handlers.js +69 -0
- package/dist/src/command-line/completion/command-object.d.ts +10 -0
- package/dist/src/command-line/completion/command-object.js +95 -0
- package/dist/src/command-line/completion/completion-providers.d.ts +21 -0
- package/dist/src/command-line/completion/completion-providers.js +194 -0
- package/dist/src/command-line/completion/infix-targets.d.ts +1 -0
- package/dist/src/command-line/completion/infix-targets.js +48 -0
- package/dist/src/command-line/completion/metadata.d.ts +22 -0
- package/dist/src/command-line/completion/metadata.js +71 -0
- package/dist/src/command-line/completion/registrations.d.ts +9 -0
- package/dist/src/command-line/completion/registrations.js +16 -0
- package/dist/src/command-line/completion/scripts/bash.sh +51 -0
- package/dist/src/command-line/completion/scripts/fish.fish +47 -0
- package/dist/src/command-line/completion/scripts/powershell.ps1 +52 -0
- package/dist/src/command-line/completion/scripts/zsh.zsh +69 -0
- package/dist/src/command-line/completion/scripts.d.ts +18 -0
- package/dist/src/command-line/completion/scripts.js +140 -0
- package/dist/src/command-line/completion/trigger.d.ts +3 -0
- package/dist/src/command-line/completion/trigger.js +21 -0
- package/dist/src/command-line/completion/value-completions.d.ts +3 -0
- package/dist/src/command-line/completion/value-completions.js +21 -0
- package/dist/src/command-line/examples.js +1 -1
- package/dist/src/command-line/format/format.js +15 -5
- package/dist/src/command-line/generate/completion.d.ts +1 -0
- package/dist/src/command-line/generate/completion.js +9 -0
- package/dist/src/command-line/graph/completion.d.ts +1 -0
- package/dist/src/command-line/graph/completion.js +13 -0
- package/dist/src/command-line/init/implementation/angular/standalone-workspace.js +14 -18
- package/dist/src/command-line/init/implementation/dot-nx/add-nx-scripts.js +1 -0
- package/dist/src/command-line/init/implementation/utils.d.ts +7 -1
- package/dist/src/command-line/init/implementation/utils.js +51 -14
- package/dist/src/command-line/migrate/agentic/capture-generator-output.d.ts +22 -0
- package/dist/src/command-line/migrate/agentic/capture-generator-output.js +100 -0
- package/dist/src/command-line/migrate/agentic/cli-args.d.ts +12 -0
- package/dist/src/command-line/migrate/agentic/cli-args.js +38 -0
- package/dist/src/command-line/migrate/agentic/definitions.d.ts +6 -0
- package/dist/src/command-line/migrate/agentic/definitions.js +98 -0
- package/dist/src/command-line/migrate/agentic/detect-installed.d.ts +10 -0
- package/dist/src/command-line/migrate/agentic/detect-installed.js +68 -0
- package/dist/src/command-line/migrate/agentic/handoff-gitignore.d.ts +46 -0
- package/dist/src/command-line/migrate/agentic/handoff-gitignore.js +87 -0
- package/dist/src/command-line/migrate/agentic/handoff.d.ts +63 -0
- package/dist/src/command-line/migrate/agentic/handoff.js +183 -0
- package/dist/src/command-line/migrate/agentic/inception.d.ts +9 -0
- package/dist/src/command-line/migrate/agentic/inception.js +15 -0
- package/dist/src/command-line/migrate/agentic/print-dropped-agent-context.d.ts +22 -0
- package/dist/src/command-line/migrate/agentic/print-dropped-agent-context.js +50 -0
- package/dist/src/command-line/migrate/agentic/prompts/generic-validation.d.ts +51 -0
- package/dist/src/command-line/migrate/agentic/prompts/generic-validation.js +65 -0
- package/dist/src/command-line/migrate/agentic/prompts/hybrid-prompt-migration.d.ts +44 -0
- package/dist/src/command-line/migrate/agentic/prompts/hybrid-prompt-migration.js +52 -0
- package/dist/src/command-line/migrate/agentic/prompts/prompt-migration.d.ts +21 -0
- package/dist/src/command-line/migrate/agentic/prompts/prompt-migration.js +26 -0
- package/dist/src/command-line/migrate/agentic/prompts/shared-rendering.d.ts +18 -0
- package/dist/src/command-line/migrate/agentic/prompts/shared-rendering.js +130 -0
- package/dist/src/command-line/migrate/agentic/prompts/system-prompt.d.ts +46 -0
- package/dist/src/command-line/migrate/agentic/prompts/system-prompt.js +88 -0
- package/dist/src/command-line/migrate/agentic/run-step.d.ts +51 -0
- package/dist/src/command-line/migrate/agentic/run-step.js +121 -0
- package/dist/src/command-line/migrate/agentic/runner.d.ts +33 -0
- package/dist/src/command-line/migrate/agentic/runner.js +442 -0
- package/dist/src/command-line/migrate/agentic/select.d.ts +14 -0
- package/dist/src/command-line/migrate/agentic/select.js +150 -0
- package/dist/src/command-line/migrate/agentic/types.d.ts +102 -0
- package/dist/src/command-line/migrate/agentic/types.js +2 -0
- package/dist/src/command-line/migrate/command-object.d.ts +1 -0
- package/dist/src/command-line/migrate/command-object.js +32 -7
- package/dist/src/command-line/migrate/migrate-commits.d.ts +50 -0
- package/dist/src/command-line/migrate/migrate-commits.js +102 -0
- package/dist/src/command-line/migrate/migrate-output.d.ts +180 -0
- package/dist/src/command-line/migrate/migrate-output.js +258 -0
- package/dist/src/command-line/migrate/migrate.d.ts +122 -12
- package/dist/src/command-line/migrate/migrate.js +1036 -217
- package/dist/src/command-line/migrate/migration-shape.d.ts +8 -0
- package/dist/src/command-line/migrate/migration-shape.js +13 -0
- package/dist/src/command-line/migrate/multi-major.d.ts +30 -0
- package/dist/src/command-line/migrate/multi-major.js +185 -0
- package/dist/src/command-line/migrate/prompt-files.d.ts +31 -0
- package/dist/src/command-line/migrate/prompt-files.js +141 -0
- package/dist/src/command-line/migrate/run-migration-process.js +28 -6
- package/dist/src/command-line/migrate/safe-prompt.d.ts +28 -0
- package/dist/src/command-line/migrate/safe-prompt.js +49 -0
- package/dist/src/command-line/migrate/update-filters.d.ts +11 -0
- package/dist/src/command-line/migrate/update-filters.js +44 -0
- package/dist/src/command-line/migrate/version-utils.d.ts +6 -0
- package/dist/src/command-line/migrate/version-utils.js +59 -0
- package/dist/src/command-line/nx-commands.js +9 -0
- package/dist/src/command-line/release/config/config.d.ts +3 -6
- package/dist/src/command-line/release/config/config.js +77 -45
- package/dist/src/command-line/release/config/use-legacy-versioning.d.ts +2 -0
- package/dist/src/command-line/release/config/use-legacy-versioning.js +8 -0
- package/dist/src/command-line/release/utils/release-graph.js +2 -3
- package/dist/src/command-line/release/utils/repository-git-tags.js +1 -1
- package/dist/src/command-line/release/utils/resolve-changelog-renderer.js +7 -19
- package/dist/src/command-line/release/version/resolve-current-version.js +1 -1
- package/dist/src/command-line/release/version/version-actions.js +3 -7
- package/dist/src/command-line/report/report.js +2 -2
- package/dist/src/command-line/run/completion.d.ts +1 -0
- package/dist/src/command-line/run/completion.js +7 -0
- package/dist/src/command-line/run-many/completion.d.ts +1 -0
- package/dist/src/command-line/run-many/completion.js +13 -0
- package/dist/src/command-line/show/completion.d.ts +1 -0
- package/dist/src/command-line/show/completion.js +27 -0
- package/dist/src/command-line/show/show-target/info.d.ts +1 -0
- package/dist/src/command-line/show/show-target/info.js +100 -19
- package/dist/src/command-line/watch/command-object.js +24 -4
- package/dist/src/command-line/watch/completion.d.ts +1 -0
- package/dist/src/command-line/watch/completion.js +10 -0
- package/dist/src/command-line/watch/watch.d.ts +7 -0
- package/dist/src/command-line/watch/watch.js +1 -1
- package/dist/src/config/misc-interfaces.d.ts +25 -2
- package/dist/src/config/nx-json.d.ts +43 -56
- package/dist/src/config/schema-utils.d.ts +21 -0
- package/dist/src/config/schema-utils.js +92 -18
- package/dist/src/config/task-graph.d.ts +4 -107
- package/dist/src/core/graph/main.js +1 -1
- package/dist/src/core/graph/styles.css +2 -3
- package/dist/src/core/graph/styles.js +1 -1
- package/dist/src/daemon/client/client.d.ts +1 -1
- package/dist/src/daemon/server/file-watching/file-watcher-sockets.d.ts +1 -1
- package/dist/src/daemon/server/file-watching/file-watcher-sockets.js +1 -1
- package/dist/src/daemon/server/file-watching/route-workspace-changes.d.ts +9 -0
- package/dist/src/daemon/server/file-watching/route-workspace-changes.js +76 -0
- package/dist/src/daemon/server/project-graph-incremental-recomputation.js +45 -11
- package/dist/src/daemon/server/server.js +4 -43
- package/dist/src/daemon/server/start.d.ts +1 -1
- package/dist/src/daemon/server/start.js +2 -0
- package/dist/src/devkit-exports.d.ts +2 -2
- package/dist/src/devkit-internals.d.ts +5 -1
- package/dist/src/devkit-internals.js +17 -1
- package/dist/src/executors/run-commands/running-tasks.d.ts +7 -0
- package/dist/src/executors/run-commands/running-tasks.js +178 -105
- package/dist/src/executors/run-script/run-script.impl.js +3 -10
- package/dist/src/executors/utils/convert-nx-executor.js +1 -1
- package/dist/src/hasher/hash-plan-inspector.d.ts +1 -1
- package/dist/src/hasher/task-hasher.js +6 -4
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +0 -3
- package/dist/src/migrations/update-16-2-0/remove-run-commands-output-path.js +6 -2
- package/dist/src/migrations/update-17-0-0/move-cache-directory.md +31 -0
- package/dist/src/migrations/update-17-0-0/use-minimal-config-for-tasks-runner-options.js +20 -4
- package/dist/src/migrations/update-20-0-0/move-use-daemon-process.md +27 -0
- package/dist/src/migrations/update-20-0-1/use-legacy-cache.md +24 -0
- package/dist/src/migrations/update-21-0-0/release-changelog-config-changes.md +49 -0
- package/dist/src/migrations/update-21-0-0/release-version-config-changes.md +54 -0
- package/dist/src/migrations/update-21-0-0/remove-custom-tasks-runner.md +28 -0
- package/dist/src/migrations/update-21-0-0/remove-legacy-cache.md +22 -0
- package/dist/src/migrations/update-22-2-0/add-self-healing-to-gitignore.md +11 -0
- package/dist/src/migrations/update-23-0-0/add-migrate-runs-to-git-ignore.d.ts +2 -0
- package/dist/src/migrations/update-23-0-0/add-migrate-runs-to-git-ignore.js +16 -0
- package/dist/src/migrations/update-23-0-0/consolidate-release-tag-config.d.ts +9 -0
- package/dist/src/migrations/update-23-0-0/consolidate-release-tag-config.js +18 -0
- package/dist/src/migrations/update-23-0-0/convert-target-defaults-to-array.d.ts +35 -0
- package/dist/src/migrations/update-23-0-0/convert-target-defaults-to-array.js +139 -0
- package/dist/src/migrations/update-23-0-0/convert-target-defaults-to-array.md +66 -0
- package/dist/src/native/index.d.ts +79 -2
- package/dist/src/native/native-bindings.js +3 -0
- package/dist/src/native/nx.wasm32-wasi.debug.wasm +0 -0
- package/dist/src/native/nx.wasm32-wasi.wasm +0 -0
- package/dist/src/plugins/js/lock-file/npm-parser.js +37 -19
- package/dist/src/plugins/js/lock-file/pnpm-parser.js +51 -4
- package/dist/src/plugins/js/lock-file/project-graph-pruning.js +12 -4
- package/dist/src/plugins/js/utils/packages.js +1 -1
- package/dist/src/plugins/js/utils/register.d.ts +103 -14
- package/dist/src/plugins/js/utils/register.js +434 -39
- package/dist/src/plugins/js/utils/typescript.d.ts +7 -0
- package/dist/src/plugins/js/utils/typescript.js +39 -0
- package/dist/src/plugins/package-json/create-nodes.d.ts +3 -2
- package/dist/src/plugins/package-json/create-nodes.js +7 -5
- package/dist/src/project-graph/affected/locators/project-glob-changes.js +2 -1
- package/dist/src/project-graph/build-project-graph.d.ts +5 -0
- package/dist/src/project-graph/build-project-graph.js +6 -2
- package/dist/src/project-graph/file-map-utils.d.ts +5 -0
- package/dist/src/project-graph/file-map-utils.js +10 -1
- package/dist/src/project-graph/plugins/get-plugins.d.ts +7 -2
- package/dist/src/project-graph/plugins/get-plugins.js +8 -5
- package/dist/src/project-graph/plugins/isolation/plugin-worker.d.ts +1 -0
- package/dist/src/project-graph/plugins/isolation/plugin-worker.js +2 -0
- package/dist/src/project-graph/plugins/resolve-plugin.d.ts +7 -4
- package/dist/src/project-graph/plugins/resolve-plugin.js +152 -33
- package/dist/src/project-graph/plugins/tasks-execution-hooks.js +4 -2
- package/dist/src/project-graph/plugins/transpiler.d.ts +12 -0
- package/dist/src/project-graph/plugins/transpiler.js +37 -0
- package/dist/src/project-graph/plugins/utils.js +13 -7
- package/dist/src/project-graph/project-graph.js +1 -1
- package/dist/src/project-graph/utils/project-configuration/target-defaults.d.ts +95 -4
- package/dist/src/project-graph/utils/project-configuration/target-defaults.js +515 -68
- package/dist/src/project-graph/utils/project-configuration-utils.d.ts +13 -5
- package/dist/src/project-graph/utils/project-configuration-utils.js +14 -6
- package/dist/src/project-graph/utils/retrieve-workspace-files.js +1 -1
- package/dist/src/tasks-runner/create-task-graph.d.ts +4 -4
- package/dist/src/tasks-runner/create-task-graph.js +1 -1
- package/dist/src/tasks-runner/default-tasks-runner.d.ts +0 -2
- package/dist/src/tasks-runner/forked-process-task-runner.d.ts +1 -1
- package/dist/src/tasks-runner/forked-process-task-runner.js +11 -6
- package/dist/src/tasks-runner/init-tasks-runner.d.ts +0 -15
- package/dist/src/tasks-runner/init-tasks-runner.js +0 -63
- package/dist/src/tasks-runner/legacy-depends-on-warning.d.ts +18 -0
- package/dist/src/tasks-runner/legacy-depends-on-warning.js +109 -0
- package/dist/src/tasks-runner/life-cycle.d.ts +7 -8
- package/dist/src/tasks-runner/life-cycles/invoke-runner-terminal-output-life-cycle.js +6 -6
- package/dist/src/tasks-runner/life-cycles/task-history-life-cycle-old.js +13 -2
- package/dist/src/tasks-runner/life-cycles/task-history-life-cycle.js +16 -5
- package/dist/src/tasks-runner/life-cycles/tui-summary-life-cycle.js +11 -2
- package/dist/src/tasks-runner/pseudo-terminal.d.ts +1 -1
- package/dist/src/tasks-runner/pseudo-terminal.js +22 -10
- package/dist/src/tasks-runner/run-command.js +8 -11
- package/dist/src/tasks-runner/running-tasks/batch-process.d.ts +1 -1
- package/dist/src/tasks-runner/running-tasks/batch-process.js +3 -5
- package/dist/src/tasks-runner/running-tasks/node-child-process.d.ts +2 -2
- package/dist/src/tasks-runner/running-tasks/node-child-process.js +5 -7
- package/dist/src/tasks-runner/task-env.d.ts +1 -1
- package/dist/src/tasks-runner/task-env.js +6 -1
- package/dist/src/tasks-runner/task-orchestrator.d.ts +11 -1
- package/dist/src/tasks-runner/task-orchestrator.js +112 -38
- package/dist/src/tasks-runner/tasks-schedule.js +3 -3
- package/dist/src/tasks-runner/utils.d.ts +7 -8
- package/dist/src/tasks-runner/utils.js +23 -27
- package/dist/src/utils/child-process.js +2 -2
- package/dist/src/utils/compile-cache.d.ts +24 -0
- package/dist/src/utils/compile-cache.js +49 -0
- package/dist/src/utils/enable-compile-cache.d.ts +1 -0
- package/dist/src/utils/enable-compile-cache.js +7 -0
- package/dist/src/utils/fileutils.d.ts +0 -8
- package/dist/src/utils/fileutils.js +0 -40
- package/dist/src/utils/git-utils.d.ts +15 -0
- package/dist/src/utils/git-utils.js +138 -0
- package/dist/src/utils/handle-import.d.ts +4 -1
- package/dist/src/utils/handle-import.js +56 -2
- package/dist/src/utils/has-nx-js-plugin.d.ts +9 -0
- package/dist/src/utils/has-nx-js-plugin.js +24 -0
- package/dist/src/utils/installed-nx-version.d.ts +14 -4
- package/dist/src/utils/installed-nx-version.js +54 -7
- package/dist/src/utils/logger.d.ts +12 -1
- package/dist/src/utils/logger.js +57 -36
- package/dist/src/utils/nx-key.d.ts +0 -1
- package/dist/src/utils/nx-key.js +20 -23
- package/dist/src/utils/nx-package-group.d.ts +8 -0
- package/dist/src/utils/nx-package-group.js +15 -0
- package/dist/src/utils/output.d.ts +3 -2
- package/dist/src/utils/output.js +29 -28
- package/dist/src/utils/package-json.d.ts +14 -1
- package/dist/src/utils/package-json.js +20 -21
- package/dist/src/utils/perf-logging.js +3 -1
- package/dist/src/utils/plugin-cache-utils.d.ts +13 -4
- package/dist/src/utils/plugin-cache-utils.js +23 -13
- package/dist/src/utils/plugins/local-plugins.d.ts +18 -0
- package/dist/src/utils/plugins/local-plugins.js +30 -0
- package/dist/src/utils/tar.d.ts +8 -0
- package/dist/src/utils/tar.js +44 -0
- package/migrations.json +16 -0
- package/package.json +28 -28
- package/schemas/nx-schema.json +114 -80
- package/dist/src/plugins/js/project-graph/build-dependencies/strip-source-code.d.ts +0 -7
- package/dist/src/plugins/js/project-graph/build-dependencies/strip-source-code.js +0 -155
- package/dist/src/plugins/js/project-graph/build-dependencies/typescript-import-locator.d.ts +0 -16
- package/dist/src/plugins/js/project-graph/build-dependencies/typescript-import-locator.js +0 -121
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.forceRegisterEsmLoader = forceRegisterEsmLoader;
|
|
4
|
+
exports.isNativeStripPreferred = isNativeStripPreferred;
|
|
3
5
|
exports.registerTsProject = registerTsProject;
|
|
4
6
|
exports.getSwcTranspiler = getSwcTranspiler;
|
|
5
7
|
exports.getTsNodeTranspiler = getTsNodeTranspiler;
|
|
6
8
|
exports.getTranspiler = getTranspiler;
|
|
9
|
+
exports.isNativeTypeStripError = isNativeTypeStripError;
|
|
10
|
+
exports.isCjsSyntaxError = isCjsSyntaxError;
|
|
11
|
+
exports.isRequireInEsmScopeError = isRequireInEsmScopeError;
|
|
12
|
+
exports.isTsEsmSyntaxError = isTsEsmSyntaxError;
|
|
13
|
+
exports.isTsEsmNamedExportLinkageError = isTsEsmNamedExportLinkageError;
|
|
14
|
+
exports.loadTsFile = loadTsFile;
|
|
15
|
+
exports.requireWithTsconfigFallback = requireWithTsconfigFallback;
|
|
7
16
|
exports.registerTranspiler = registerTranspiler;
|
|
8
17
|
exports.registerTsConfigPaths = registerTsConfigPaths;
|
|
9
18
|
exports.getTsNodeCompilerOptions = getTsNodeCompilerOptions;
|
|
@@ -16,6 +25,74 @@ const swcNodeInstalled = packageIsInstalled('@swc-node/register');
|
|
|
16
25
|
const tsNodeInstalled = packageIsInstalled('ts-node/register');
|
|
17
26
|
let ts;
|
|
18
27
|
let isTsEsmLoaderRegistered = false;
|
|
28
|
+
/**
|
|
29
|
+
* Force-register an ESM loader (`@swc-node/register/esm` if available, else
|
|
30
|
+
* `ts-node/esm`) via `Module.register` so dynamic `import()` of TS files
|
|
31
|
+
* goes through a transpiler.
|
|
32
|
+
*
|
|
33
|
+
* **IMPORTANT — global side effect:** `Module.register` is one-shot per
|
|
34
|
+
* process and applies to *every* subsequent ESM resolution in the process.
|
|
35
|
+
* Calling this trades native Node.js TypeScript stripping for transpiled
|
|
36
|
+
* loading on the dynamic-import path for the rest of the run. CJS
|
|
37
|
+
* `require()` is unaffected (different hook), so `.cts` files via require
|
|
38
|
+
* keep using native strip + swc-node's `Module._extensions` hook.
|
|
39
|
+
*
|
|
40
|
+
* Required for the niche case where an ESM config (`.mts` or `.ts` resolved
|
|
41
|
+
* as ESM) combines top-level await with TypeScript syntax that native strip
|
|
42
|
+
* can't handle (`enum`, runtime `namespace`, etc.). TLA forces dynamic
|
|
43
|
+
* `import()`, which bypasses the CJS hook chain - the only way to intercept
|
|
44
|
+
* is `Module.register`.
|
|
45
|
+
*
|
|
46
|
+
* Idempotent: subsequent calls are no-ops.
|
|
47
|
+
*
|
|
48
|
+
* Throws if neither `@swc-node/register` nor `ts-node` is installed.
|
|
49
|
+
*/
|
|
50
|
+
function forceRegisterEsmLoader() {
|
|
51
|
+
ensureEsmLoaderRegistered({ required: true });
|
|
52
|
+
}
|
|
53
|
+
function ensureEsmLoaderRegistered(opts) {
|
|
54
|
+
if (isTsEsmLoaderRegistered)
|
|
55
|
+
return;
|
|
56
|
+
const module = require('node:module');
|
|
57
|
+
if (typeof module.register !== 'function') {
|
|
58
|
+
if (opts.required) {
|
|
59
|
+
throw new Error(`${logger_1.NX_PREFIX} Module.register is not available in this Node.js version - cannot register an ESM loader for the TypeScript fallback. ${STRIP_TYPES_OPT_OUT_HINT}`);
|
|
60
|
+
}
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
// ts-node reads compilerOptions from this env var. Setting nodenext
|
|
64
|
+
// module/resolution avoids surprises when ts-node is the chosen loader.
|
|
65
|
+
process.env.TS_NODE_COMPILER_OPTIONS ??= JSON.stringify({
|
|
66
|
+
moduleResolution: 'nodenext',
|
|
67
|
+
module: 'nodenext',
|
|
68
|
+
});
|
|
69
|
+
// Prefer @swc-node/register/esm (faster) over ts-node/esm.
|
|
70
|
+
const swcEsm = tryResolveLoader('@swc-node/register/esm');
|
|
71
|
+
const tsNodeEsm = tryResolveLoader('ts-node/esm');
|
|
72
|
+
const loaderPath = swcEsm ?? tsNodeEsm;
|
|
73
|
+
if (!loaderPath) {
|
|
74
|
+
if (opts.required) {
|
|
75
|
+
throw new Error(`${logger_1.NX_PREFIX} Cannot register an ESM TypeScript loader to fall back from native stripping. Install @swc-node/register or ts-node, or ${STRIP_TYPES_OPT_OUT_HINT}`);
|
|
76
|
+
}
|
|
77
|
+
isTsEsmLoaderRegistered = true;
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (process.env.NX_VERBOSE_LOGGING === 'true') {
|
|
81
|
+
const loaderName = swcEsm ? '@swc-node/register/esm' : 'ts-node/esm';
|
|
82
|
+
logger_1.logger.warn((0, logger_1.stripIndent)(`${logger_1.NX_PREFIX} Registering ESM TypeScript loader ${loaderName}. All subsequent ESM imports in this process will go through it - native Node.js TypeScript stripping is forfeited for the dynamic-import path.`));
|
|
83
|
+
}
|
|
84
|
+
const url = require('node:url');
|
|
85
|
+
module.register(url.pathToFileURL(loaderPath));
|
|
86
|
+
isTsEsmLoaderRegistered = true;
|
|
87
|
+
}
|
|
88
|
+
function tryResolveLoader(specifier) {
|
|
89
|
+
try {
|
|
90
|
+
return require.resolve(specifier);
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
19
96
|
/**
|
|
20
97
|
* tsx is a utility to run TypeScript files in node which is growing in popularity:
|
|
21
98
|
* https://tsx.is
|
|
@@ -51,65 +128,72 @@ const isInvokedByTsx = (() => {
|
|
|
51
128
|
importArgs.some((a) => isTsxPath(a)));
|
|
52
129
|
})();
|
|
53
130
|
/**
|
|
54
|
-
* Whether the current Node.js
|
|
55
|
-
*
|
|
131
|
+
* Whether the current Node.js runtime exposes native TypeScript type
|
|
132
|
+
* stripping. This is the authoritative gate - it correctly handles every
|
|
133
|
+
* way Node ships TS support:
|
|
134
|
+
* - Node 23.6+: unflagged, on by default
|
|
135
|
+
* - Node 22.18+ LTS: backported unflagged
|
|
136
|
+
* - Node 22.6-22.17 + `--experimental-strip-types` (or `--experimental-transform-types`)
|
|
56
137
|
*
|
|
57
|
-
* process.features.typescript is 'strip' | 'transform' | false
|
|
138
|
+
* `process.features.typescript` is `'strip' | 'transform' | false`.
|
|
58
139
|
*/
|
|
59
140
|
const nodeSupportsNativeTypescript = !!process.features
|
|
60
141
|
?.typescript;
|
|
61
142
|
/**
|
|
62
|
-
* When process.features.typescript is truthy
|
|
63
|
-
*
|
|
64
|
-
*
|
|
143
|
+
* When process.features.typescript is truthy, default to letting Node.js
|
|
144
|
+
* handle TypeScript natively via type stripping and skip registering swc-node
|
|
145
|
+
* or ts-node. Users can opt out by setting NX_PREFER_NODE_STRIP_TYPES=false.
|
|
65
146
|
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
147
|
+
* Some constructs (enum, runtime namespace, legacy decorators,
|
|
148
|
+
* import = require, parameter properties, etc.) aren't supported by native
|
|
149
|
+
* type stripping. `loadTsFile` catches these failures and falls back to
|
|
150
|
+
* registering swc/ts-node + tsconfig-paths automatically.
|
|
68
151
|
*
|
|
69
|
-
*
|
|
152
|
+
* See: https://nodejs.org/api/typescript.html#full-typescript-support
|
|
70
153
|
*/
|
|
71
154
|
const preferNodeStripTypes = (() => {
|
|
72
|
-
if (
|
|
155
|
+
if (!nodeSupportsNativeTypescript) {
|
|
73
156
|
return false;
|
|
74
157
|
}
|
|
75
|
-
return
|
|
158
|
+
return process.env.NX_PREFER_NODE_STRIP_TYPES !== 'false';
|
|
76
159
|
})();
|
|
77
|
-
|
|
160
|
+
/**
|
|
161
|
+
* Skip tsconfig-paths registration on the swc/ts-node fallback path. Useful
|
|
162
|
+
* for workspaces relying on package manager workspaces (pnpm, yarn, npm) for
|
|
163
|
+
* project linking, where tsconfig path aliases aren't needed.
|
|
164
|
+
*/
|
|
165
|
+
const disableTsConfigPaths = process.env.NX_DISABLE_TSCONFIG_PATHS === 'true';
|
|
166
|
+
/**
|
|
167
|
+
* Whether Nx will defer to Node's native TypeScript stripping for the next
|
|
168
|
+
* `.ts` load. Mirrors the gate used by `loadTsFile`/`registerTsProject` so
|
|
169
|
+
* other registration sites (e.g. plugin transpiler) can stay aligned.
|
|
170
|
+
*/
|
|
171
|
+
function isNativeStripPreferred() {
|
|
172
|
+
return preferNodeStripTypes;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* This function registers either ts-node or swc-node to transpile TypeScript files on the fly.
|
|
176
|
+
* It also registers tsconfig-paths to handle path mapping based on the provided tsconfig.
|
|
177
|
+
*
|
|
178
|
+
* The TypeScript transpiler registration is done regardless of NX_PREFER_NODE_STRIP_TYPES.
|
|
179
|
+
* If you want to skip transpiler registration, it is recommended that you check `process.features.typescript`.
|
|
180
|
+
*
|
|
181
|
+
* @returns cleanup function
|
|
182
|
+
*/
|
|
183
|
+
function registerTsProject(tsConfigPath) {
|
|
78
184
|
// See explanation alongside isInvokedByTsx declaration
|
|
79
185
|
if (isInvokedByTsx) {
|
|
80
186
|
return () => { };
|
|
81
187
|
}
|
|
82
|
-
const tsConfigPath = configFilename ? (0, path_1.join)(path, configFilename) : path;
|
|
83
|
-
// See explanation alongside preferNodeStripTypes declaration
|
|
84
|
-
// When using Node.js native type stripping, skip transpiler registration
|
|
85
|
-
// but still register tsconfig-paths for path mapping support
|
|
86
|
-
if (preferNodeStripTypes) {
|
|
87
|
-
return registerTsConfigPaths(tsConfigPath);
|
|
88
|
-
}
|
|
89
188
|
const { compilerOptions, tsConfigRaw } = readCompilerOptions(tsConfigPath);
|
|
90
189
|
const cleanupFunctions = [
|
|
91
190
|
registerTsConfigPaths(tsConfigPath),
|
|
92
191
|
registerTranspiler(compilerOptions, tsConfigRaw),
|
|
93
192
|
];
|
|
94
|
-
//
|
|
95
|
-
//
|
|
96
|
-
//
|
|
97
|
-
|
|
98
|
-
if (!isTsEsmLoaderRegistered) {
|
|
99
|
-
// We need a way to ensure that `.ts` files are treated as ESM not CJS.
|
|
100
|
-
// Since there is no way to pass compilerOptions like we do with the programmatic API, we should default
|
|
101
|
-
// the environment variable that ts-node checks.
|
|
102
|
-
process.env.TS_NODE_COMPILER_OPTIONS ??= JSON.stringify({
|
|
103
|
-
moduleResolution: 'nodenext',
|
|
104
|
-
module: 'nodenext',
|
|
105
|
-
});
|
|
106
|
-
const module = require('node:module');
|
|
107
|
-
if (module.register && packageIsInstalled('ts-node/esm')) {
|
|
108
|
-
const url = require('node:url');
|
|
109
|
-
module.register(url.pathToFileURL(require.resolve('ts-node/esm')));
|
|
110
|
-
}
|
|
111
|
-
isTsEsmLoaderRegistered = true;
|
|
112
|
-
}
|
|
193
|
+
// Best-effort ESM loader registration so dynamic import() of .ts/.mts
|
|
194
|
+
// files goes through a transpiler. No-op if no ESM loader package is
|
|
195
|
+
// installed.
|
|
196
|
+
ensureEsmLoaderRegistered({ required: false });
|
|
113
197
|
return () => {
|
|
114
198
|
for (const fn of cleanupFunctions) {
|
|
115
199
|
fn();
|
|
@@ -253,6 +337,307 @@ function getTranspiler(compilerOptions, tsConfigRaw) {
|
|
|
253
337
|
return currRegistrationEntry.cleanup;
|
|
254
338
|
}
|
|
255
339
|
}
|
|
340
|
+
/**
|
|
341
|
+
* Node.js throws this code when native type stripping hits an unsupported
|
|
342
|
+
* construct (enum, runtime namespace, legacy decorators, import = require,
|
|
343
|
+
* parameter properties on older Node, etc.).
|
|
344
|
+
*
|
|
345
|
+
* Exported for tests.
|
|
346
|
+
*/
|
|
347
|
+
function isNativeTypeStripError(err) {
|
|
348
|
+
if (!err || typeof err !== 'object')
|
|
349
|
+
return false;
|
|
350
|
+
return (err.code === 'ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX');
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Module resolution failures - typically a tsconfig path alias that hasn't
|
|
354
|
+
* been registered yet, or a workspace lib not surfaced via package manager
|
|
355
|
+
* symlinks. CJS uses `MODULE_NOT_FOUND`, ESM uses `ERR_MODULE_NOT_FOUND`.
|
|
356
|
+
*/
|
|
357
|
+
function isModuleNotFoundError(err) {
|
|
358
|
+
if (!err || typeof err !== 'object')
|
|
359
|
+
return false;
|
|
360
|
+
const code = err.code;
|
|
361
|
+
return code === 'MODULE_NOT_FOUND' || code === 'ERR_MODULE_NOT_FOUND';
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* A SyntaxError thrown while parsing a forced-CJS file (`.cts`/`.cjs`) as
|
|
365
|
+
* CommonJS - typically ESM syntax in a CJS file (e.g. `export default` in
|
|
366
|
+
* `.cts`). Pre-v23 this worked because swc-node's CJS hook compiled away the
|
|
367
|
+
* ESM syntax; under native strip swc-node isn't registered, so the file
|
|
368
|
+
* reaches Node's strict CJS parser. swc-node tolerates ESM syntax in `.cts`
|
|
369
|
+
* (`register()` forces `module: commonjs` regardless of extension), so
|
|
370
|
+
* escalating to the swc/ts-node fallback recovers the legacy behavior.
|
|
371
|
+
*/
|
|
372
|
+
function isCjsSyntaxError(err, filePath) {
|
|
373
|
+
if (!(err instanceof SyntaxError))
|
|
374
|
+
return false;
|
|
375
|
+
return filePath.endsWith('.cts') || filePath.endsWith('.cjs');
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* A ReferenceError from Node treating a `.ts`/`.mts` file as ESM and the file
|
|
379
|
+
* relying on a CJS-only global: `require`, `__dirname`, or `__filename`.
|
|
380
|
+
* Pre-v23 swc-node compiled `.ts` to CJS where these globals exist; under
|
|
381
|
+
* native strip Node detects ESM via `import`/`export` syntax and these globals
|
|
382
|
+
* are undefined. Registering swc/ts-node compiles ESM->CJS and restores the
|
|
383
|
+
* legacy globals.
|
|
384
|
+
*/
|
|
385
|
+
function isRequireInEsmScopeError(err, filePath) {
|
|
386
|
+
if (!(err instanceof ReferenceError))
|
|
387
|
+
return false;
|
|
388
|
+
if (!(filePath.endsWith('.ts') || filePath.endsWith('.mts')))
|
|
389
|
+
return false;
|
|
390
|
+
// Node's exact phrasing varies across versions / strip modes. Match the
|
|
391
|
+
// bare-name form too (e.g. `__dirname is not defined`) so the fallback
|
|
392
|
+
// still triggers when the trailing "in ES module scope" is absent.
|
|
393
|
+
const msg = err.message;
|
|
394
|
+
return /(require|__dirname|__filename) is not defined/.test(msg);
|
|
395
|
+
}
|
|
396
|
+
function isTsEsmSyntaxError(err, filePath) {
|
|
397
|
+
if (!(err instanceof SyntaxError))
|
|
398
|
+
return false;
|
|
399
|
+
if (!filePath.endsWith('.ts'))
|
|
400
|
+
return false;
|
|
401
|
+
// Node has multiple phrasings for ESM-in-CJS-scope syntax errors depending
|
|
402
|
+
// on whether the offending token is `import` or `export` and which parser
|
|
403
|
+
// path triggered: "Cannot use import statement outside a module" or
|
|
404
|
+
// "Unexpected token 'export'" / "Unexpected token 'import'". swc-node's
|
|
405
|
+
// CJS hook compiles ESM->CJS regardless of the surface error, so all of
|
|
406
|
+
// these should escalate to the same fallback.
|
|
407
|
+
const msg = err.message;
|
|
408
|
+
return (msg.includes('Cannot use import statement outside a module') ||
|
|
409
|
+
/Unexpected token ['"](export|import)['"]/.test(msg));
|
|
410
|
+
}
|
|
411
|
+
function isTsEsmNamedExportLinkageError(err, filePath) {
|
|
412
|
+
if (!(err instanceof SyntaxError))
|
|
413
|
+
return false;
|
|
414
|
+
return ((filePath.endsWith('.ts') || filePath.endsWith('.mts')) &&
|
|
415
|
+
err.message.includes('does not provide an export named'));
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Hint appended to errors that the lazy fallback couldn't recover from.
|
|
419
|
+
* Points users at the env opt-out for cases native strip can't reach (e.g.
|
|
420
|
+
* ESM with top-level await + unsupported TS syntax, where swc-node's CJS
|
|
421
|
+
* Module._extensions hook can't intercept dynamic `import()`).
|
|
422
|
+
*/
|
|
423
|
+
const NX_PREFER_NODE_STRIP_TYPES_DOCS_URL = 'https://nx.dev/docs/reference/environment-variables#nx-prefer-node-strip-types';
|
|
424
|
+
const STRIP_TYPES_OPT_OUT_HINT = `Set NX_PREFER_NODE_STRIP_TYPES=false to opt out of Node's native TypeScript stripping and use swc/ts-node instead. See ${NX_PREFER_NODE_STRIP_TYPES_DOCS_URL}`;
|
|
425
|
+
/**
|
|
426
|
+
* Load a TypeScript file via `require()`.
|
|
427
|
+
*
|
|
428
|
+
* When the runtime exposes native TypeScript stripping
|
|
429
|
+
* (`process.features.typescript`) and the user hasn't opted out via
|
|
430
|
+
* `NX_PREFER_NODE_STRIP_TYPES=false`, the file loads directly with no
|
|
431
|
+
* swc/ts-node and no tsconfig-paths registration. If Node throws on an
|
|
432
|
+
* unsupported construct (enum, runtime namespace, legacy decorators, etc.),
|
|
433
|
+
* this registers swc/ts-node + tsconfig-paths and retries - matching the
|
|
434
|
+
* pre-v23 registration. Set `NX_DISABLE_TSCONFIG_PATHS=true` to skip
|
|
435
|
+
* tsconfig-paths even on fallback (useful when relying on package manager
|
|
436
|
+
* workspaces). Set `NX_VERBOSE_LOGGING=true` to log when fallback triggers.
|
|
437
|
+
*
|
|
438
|
+
* When native strip is opted out (`NX_PREFER_NODE_STRIP_TYPES=false` or
|
|
439
|
+
* unsupported Node), uses the legacy `registerTsProject` path.
|
|
440
|
+
*
|
|
441
|
+
* `tsConfigPath` is only consulted on the swc/ts-node fallback path (for
|
|
442
|
+
* compilerOptions) and for tsconfig-paths registration. Native strip ignores
|
|
443
|
+
* it. When omitted, defaults to the workspace root tsconfig.
|
|
444
|
+
*
|
|
445
|
+
* Note on ESM: Node 22.12+ supports `require()` of synchronous ESM by default,
|
|
446
|
+
* so most ESM `.ts` configs load via this function without issue. Modules
|
|
447
|
+
* that use top-level await throw `ERR_REQUIRE_ASYNC_MODULE` and must be
|
|
448
|
+
* loaded with dynamic `import()` instead. `ERR_REQUIRE_ESM` (legacy code)
|
|
449
|
+
* bubbles unchanged for the rare case it still fires, so async-aware callers
|
|
450
|
+
* can dispatch to `import()`.
|
|
451
|
+
*
|
|
452
|
+
* @returns the loaded module
|
|
453
|
+
*/
|
|
454
|
+
function loadTsFile(filePath, tsConfigPath) {
|
|
455
|
+
const resolvedTsConfigPath = tsConfigPath ?? (0, typescript_1.getRootTsConfigPath)();
|
|
456
|
+
if (isInvokedByTsx) {
|
|
457
|
+
return require(filePath);
|
|
458
|
+
}
|
|
459
|
+
if (!preferNodeStripTypes) {
|
|
460
|
+
if (!resolvedTsConfigPath) {
|
|
461
|
+
throw new Error(`${logger_1.NX_PREFIX} loadTsFile could not find a workspace tsconfig while loading ${filePath} on the swc/ts-node path. Pass an explicit tsConfigPath or add a tsconfig.base.json/tsconfig.json at the workspace root.`);
|
|
462
|
+
}
|
|
463
|
+
const cleanup = registerTsProject(resolvedTsConfigPath);
|
|
464
|
+
try {
|
|
465
|
+
return require(filePath);
|
|
466
|
+
}
|
|
467
|
+
finally {
|
|
468
|
+
cleanup();
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
// Native strip path: no registration up front. pnpm/npm/yarn workspaces
|
|
472
|
+
// resolve aliases without tsconfig-paths. On failure, lazy-register what
|
|
473
|
+
// the specific error code indicates is needed and retry:
|
|
474
|
+
// - MODULE_NOT_FOUND -> first try tsconfig-paths (alias resolution).
|
|
475
|
+
// If that still fails (e.g. extensionless `import './foo'` when
|
|
476
|
+
// `foo.ts` is adjacent - Node's resolver doesn't add `.ts`), escalate
|
|
477
|
+
// to swc/ts-node which handles `.ts` extension resolution.
|
|
478
|
+
// - ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX -> register swc/ts-node + tsconfig-paths
|
|
479
|
+
// Each registration kind runs at most once, so a file recovers in at
|
|
480
|
+
// most three attempts.
|
|
481
|
+
let pathsRegistered = false;
|
|
482
|
+
let transpilerRegistered = false;
|
|
483
|
+
const cleanups = [];
|
|
484
|
+
const registerTranspilerFallback = (err) => {
|
|
485
|
+
if (!swcNodeInstalled && !tsNodeInstalled) {
|
|
486
|
+
const original = err instanceof Error ? err.message : String(err);
|
|
487
|
+
throw new Error(`${logger_1.NX_PREFIX} ${filePath} could not be loaded under Node's native TypeScript stripping (${original}). Install @swc-node/register and @swc/core (or ts-node) to enable the swc/ts-node fallback, or ${STRIP_TYPES_OPT_OUT_HINT}`);
|
|
488
|
+
}
|
|
489
|
+
if (!resolvedTsConfigPath) {
|
|
490
|
+
throw new Error(`${logger_1.NX_PREFIX} ${filePath} requires the swc/ts-node fallback but no workspace tsconfig was found. Pass an explicit tsConfigPath or add a tsconfig.base.json/tsconfig.json at the workspace root. ${STRIP_TYPES_OPT_OUT_HINT}`);
|
|
491
|
+
}
|
|
492
|
+
if (!pathsRegistered && !disableTsConfigPaths) {
|
|
493
|
+
cleanups.push(registerTsConfigPaths(resolvedTsConfigPath));
|
|
494
|
+
pathsRegistered = true;
|
|
495
|
+
}
|
|
496
|
+
const { compilerOptions, tsConfigRaw } = readCompilerOptions(resolvedTsConfigPath);
|
|
497
|
+
cleanups.push(registerTranspiler(compilerOptions, tsConfigRaw));
|
|
498
|
+
transpilerRegistered = true;
|
|
499
|
+
};
|
|
500
|
+
try {
|
|
501
|
+
for (let attempt = 1;; attempt++) {
|
|
502
|
+
try {
|
|
503
|
+
if (attempt > 1) {
|
|
504
|
+
try {
|
|
505
|
+
delete require.cache[require.resolve(filePath)];
|
|
506
|
+
}
|
|
507
|
+
catch {
|
|
508
|
+
// require.resolve may throw if the failed load never reached cache
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
return require(filePath);
|
|
512
|
+
}
|
|
513
|
+
catch (err) {
|
|
514
|
+
// Cheap fallback first: register tsconfig-paths and retry.
|
|
515
|
+
if (isModuleNotFoundError(err) &&
|
|
516
|
+
!pathsRegistered &&
|
|
517
|
+
!disableTsConfigPaths &&
|
|
518
|
+
resolvedTsConfigPath) {
|
|
519
|
+
logFallback(filePath, err, 'Module not found; registering tsconfig-paths and retrying.');
|
|
520
|
+
cleanups.push(registerTsConfigPaths(resolvedTsConfigPath));
|
|
521
|
+
pathsRegistered = true;
|
|
522
|
+
continue;
|
|
523
|
+
}
|
|
524
|
+
// Heavy fallback: register swc/ts-node (+ paths) and retry. Triggered
|
|
525
|
+
// by:
|
|
526
|
+
// - strip-types failure (`ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX`)
|
|
527
|
+
// - module resolution failure that tsconfig-paths alone can't fix
|
|
528
|
+
// (extensionless `./foo` -> `./foo.ts`)
|
|
529
|
+
// - SyntaxError in a `.cts`/`.cjs` file (ESM syntax in a forced-CJS
|
|
530
|
+
// file). swc-node compiles ESM->CJS regardless of extension.
|
|
531
|
+
// - SyntaxError from Node parsing a `.ts` config with ESM syntax as
|
|
532
|
+
// CJS. swc/ts-node preserves the pre-v23 behavior for these files.
|
|
533
|
+
// - ReferenceError from Node treating a `.ts`/`.mts` config as ESM
|
|
534
|
+
// when it contains legacy CJS `require`.
|
|
535
|
+
// - SyntaxError from native ESM linkage when generated TS config
|
|
536
|
+
// imports a type-only symbol as a runtime named export.
|
|
537
|
+
if ((isNativeTypeStripError(err) ||
|
|
538
|
+
isModuleNotFoundError(err) ||
|
|
539
|
+
isCjsSyntaxError(err, filePath) ||
|
|
540
|
+
isTsEsmSyntaxError(err, filePath) ||
|
|
541
|
+
isRequireInEsmScopeError(err, filePath) ||
|
|
542
|
+
isTsEsmNamedExportLinkageError(err, filePath)) &&
|
|
543
|
+
!transpilerRegistered) {
|
|
544
|
+
logFallback(filePath, err, isNativeTypeStripError(err)
|
|
545
|
+
? 'Native Node.js TypeScript stripping failed; falling back to swc/ts-node + tsconfig-paths.'
|
|
546
|
+
: isCjsSyntaxError(err, filePath)
|
|
547
|
+
? 'ESM syntax in forced-CJS file; falling back to swc/ts-node + tsconfig-paths.'
|
|
548
|
+
: isTsEsmSyntaxError(err, filePath)
|
|
549
|
+
? 'ESM syntax in TypeScript file parsed as CommonJS; falling back to swc/ts-node + tsconfig-paths.'
|
|
550
|
+
: isRequireInEsmScopeError(err, filePath)
|
|
551
|
+
? 'CommonJS require in native ESM TypeScript file; falling back to swc/ts-node + tsconfig-paths.'
|
|
552
|
+
: isTsEsmNamedExportLinkageError(err, filePath)
|
|
553
|
+
? 'Native ESM named export linkage failed; falling back to swc/ts-node + tsconfig-paths.'
|
|
554
|
+
: 'Module not found after tsconfig-paths; falling back to swc/ts-node + tsconfig-paths.');
|
|
555
|
+
registerTranspilerFallback(err);
|
|
556
|
+
continue;
|
|
557
|
+
}
|
|
558
|
+
throw augmentLoadFailure(filePath, err);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
finally {
|
|
563
|
+
for (const fn of cleanups)
|
|
564
|
+
fn();
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
/**
|
|
568
|
+
* Plain `require()` with a lazy `tsconfig-paths` fallback. Use for files that
|
|
569
|
+
* are NOT TypeScript (no transpilation needed) but may still import workspace
|
|
570
|
+
* packages through TS path aliases (e.g. a `.js` changelog renderer that
|
|
571
|
+
* `require`s `@my-org/lib`).
|
|
572
|
+
*
|
|
573
|
+
* `tsconfig-paths` is only registered after the first `require()` fails with
|
|
574
|
+
* a module-resolution error, so workspaces that resolve aliases through
|
|
575
|
+
* package-manager symlinks pay nothing. Set `NX_DISABLE_TSCONFIG_PATHS=true`
|
|
576
|
+
* to skip the fallback entirely.
|
|
577
|
+
*
|
|
578
|
+
* @returns the loaded module
|
|
579
|
+
*/
|
|
580
|
+
function requireWithTsconfigFallback(filePath, tsConfigPath) {
|
|
581
|
+
try {
|
|
582
|
+
return require(filePath);
|
|
583
|
+
}
|
|
584
|
+
catch (err) {
|
|
585
|
+
if (!isModuleNotFoundError(err) || disableTsConfigPaths) {
|
|
586
|
+
throw err;
|
|
587
|
+
}
|
|
588
|
+
const resolvedTsConfigPath = tsConfigPath ?? (0, typescript_1.getRootTsConfigPath)();
|
|
589
|
+
if (!resolvedTsConfigPath) {
|
|
590
|
+
throw err;
|
|
591
|
+
}
|
|
592
|
+
const cleanup = registerTsConfigPaths(resolvedTsConfigPath);
|
|
593
|
+
try {
|
|
594
|
+
delete require.cache[require.resolve(filePath)];
|
|
595
|
+
}
|
|
596
|
+
catch {
|
|
597
|
+
// require.resolve may throw if the failed load never reached cache
|
|
598
|
+
}
|
|
599
|
+
try {
|
|
600
|
+
return require(filePath);
|
|
601
|
+
}
|
|
602
|
+
finally {
|
|
603
|
+
cleanup();
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
/**
|
|
608
|
+
* Append the `NX_PREFER_NODE_STRIP_TYPES=false` opt-out hint so users know
|
|
609
|
+
* there's an escape hatch for cases native strip can't reach (e.g. ESM with
|
|
610
|
+
* top-level await + unsupported TS syntax). Skipped for:
|
|
611
|
+
* - ESM-redispatch signals callers expect to handle
|
|
612
|
+
* (`ERR_REQUIRE_ESM`, `ERR_REQUIRE_ASYNC_MODULE`)
|
|
613
|
+
* - plain module-resolution failures (`MODULE_NOT_FOUND`,
|
|
614
|
+
* `ERR_MODULE_NOT_FOUND`) - disabling strip-types doesn't fix a missing
|
|
615
|
+
* module, the hint just misleads.
|
|
616
|
+
*/
|
|
617
|
+
function augmentLoadFailure(filePath, err) {
|
|
618
|
+
if (!(err instanceof Error))
|
|
619
|
+
return err;
|
|
620
|
+
const code = err.code;
|
|
621
|
+
if (code === 'ERR_REQUIRE_ESM' ||
|
|
622
|
+
code === 'ERR_REQUIRE_ASYNC_MODULE' ||
|
|
623
|
+
code === 'MODULE_NOT_FOUND' ||
|
|
624
|
+
code === 'ERR_MODULE_NOT_FOUND') {
|
|
625
|
+
return err;
|
|
626
|
+
}
|
|
627
|
+
if (err.message.includes(NX_PREFER_NODE_STRIP_TYPES_DOCS_URL)) {
|
|
628
|
+
return err;
|
|
629
|
+
}
|
|
630
|
+
err.message = `${err.message}\n\n${logger_1.NX_PREFIX} Failed to load ${filePath} under Node's native TypeScript stripping. ${STRIP_TYPES_OPT_OUT_HINT}`;
|
|
631
|
+
return err;
|
|
632
|
+
}
|
|
633
|
+
function logFallback(filePath, err, summary) {
|
|
634
|
+
if (process.env.NX_VERBOSE_LOGGING !== 'true') {
|
|
635
|
+
return;
|
|
636
|
+
}
|
|
637
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
638
|
+
logger_1.logger.warn((0, logger_1.stripIndent)(`${logger_1.NX_PREFIX} ${summary} (${filePath})
|
|
639
|
+
${message}`));
|
|
640
|
+
}
|
|
256
641
|
/**
|
|
257
642
|
* Register ts-node or swc-node given a set of compiler options.
|
|
258
643
|
*
|
|
@@ -266,7 +651,7 @@ function registerTranspiler(compilerOptions, tsConfigRaw) {
|
|
|
266
651
|
const transpiler = getTranspiler(compilerOptions, tsConfigRaw);
|
|
267
652
|
if (!transpiler) {
|
|
268
653
|
// If Node.js natively supports TypeScript (22.6+), no transpiler is needed.
|
|
269
|
-
// Don't warn
|
|
654
|
+
// Don't warn - Node will handle .ts files via type stripping.
|
|
270
655
|
if (!nodeSupportsNativeTypescript) {
|
|
271
656
|
warnNoTranspiler();
|
|
272
657
|
}
|
|
@@ -290,6 +675,16 @@ function registerTsConfigPaths(tsConfigPath) {
|
|
|
290
675
|
* can be imported and used within project
|
|
291
676
|
*/
|
|
292
677
|
if (tsConfigResult.resultType === 'success') {
|
|
678
|
+
// Short-circuit when the tsconfig has no `paths` entries. Installing
|
|
679
|
+
// tsconfig-paths' resolver hook adds a per-require cost on every
|
|
680
|
+
// module load; in package-manager-workspace setups (which resolve via
|
|
681
|
+
// symlinks instead of TS path mappings), the hook never has anything
|
|
682
|
+
// to do. Avoid paying that overhead on workspaces that don't use
|
|
683
|
+
// `paths`.
|
|
684
|
+
if (!tsConfigResult.paths ||
|
|
685
|
+
Object.keys(tsConfigResult.paths).length === 0) {
|
|
686
|
+
return () => { };
|
|
687
|
+
}
|
|
293
688
|
return tsconfigPaths.register({
|
|
294
689
|
baseUrl: resolvePathsBaseUrl(tsConfigPath),
|
|
295
690
|
paths: tsConfigResult.paths,
|
|
@@ -13,4 +13,11 @@ export declare function readTsConfigOptions(tsConfigPath: string): ts.CompilerOp
|
|
|
13
13
|
export declare function resolveModuleByImport(importExpr: string, filePath: string, tsConfigPath: string): string;
|
|
14
14
|
export declare function getRootTsConfigFileName(): string | null;
|
|
15
15
|
export declare function getRootTsConfigPath(): string | null;
|
|
16
|
+
export declare function getRootTsConfigCustomConditions(root?: string): string[];
|
|
17
|
+
/**
|
|
18
|
+
* Conditions list for `resolve.exports`: workspace `customConditions` plus
|
|
19
|
+
* `development` as backward-compat for workspaces not yet migrated by
|
|
20
|
+
* `migrate-development-custom-condition` (21.5).
|
|
21
|
+
*/
|
|
22
|
+
export declare function getRootTsConfigResolveExportsConditions(root?: string): string[];
|
|
16
23
|
export declare function findNodes(node: Node, kind: SyntaxKind | SyntaxKind[], max?: number): Node[];
|
|
@@ -6,6 +6,8 @@ exports.readTsConfigOptions = readTsConfigOptions;
|
|
|
6
6
|
exports.resolveModuleByImport = resolveModuleByImport;
|
|
7
7
|
exports.getRootTsConfigFileName = getRootTsConfigFileName;
|
|
8
8
|
exports.getRootTsConfigPath = getRootTsConfigPath;
|
|
9
|
+
exports.getRootTsConfigCustomConditions = getRootTsConfigCustomConditions;
|
|
10
|
+
exports.getRootTsConfigResolveExportsConditions = getRootTsConfigResolveExportsConditions;
|
|
9
11
|
exports.findNodes = findNodes;
|
|
10
12
|
const workspace_root_1 = require("../../../utils/workspace-root");
|
|
11
13
|
const fs_1 = require("fs");
|
|
@@ -74,6 +76,43 @@ function getRootTsConfigPath() {
|
|
|
74
76
|
const tsConfigFileName = getRootTsConfigFileName();
|
|
75
77
|
return tsConfigFileName ? (0, path_1.join)(workspace_root_1.workspaceRoot, tsConfigFileName) : null;
|
|
76
78
|
}
|
|
79
|
+
const customConditionsCache = new Map();
|
|
80
|
+
function getRootTsConfigCustomConditions(root = workspace_root_1.workspaceRoot) {
|
|
81
|
+
if (customConditionsCache.has(root)) {
|
|
82
|
+
return customConditionsCache.get(root);
|
|
83
|
+
}
|
|
84
|
+
// Resolve via the TypeScript API rather than a raw JSON read so that
|
|
85
|
+
// `customConditions` inherited through `extends` chains are honored —
|
|
86
|
+
// matches what TypeScript itself sees when resolving package exports.
|
|
87
|
+
let conditions = [];
|
|
88
|
+
for (const name of ['tsconfig.base.json', 'tsconfig.json']) {
|
|
89
|
+
const tsConfigPath = (0, path_1.join)(root, name);
|
|
90
|
+
if (!(0, fs_1.existsSync)(tsConfigPath)) {
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
try {
|
|
94
|
+
const options = readTsConfigOptions(tsConfigPath);
|
|
95
|
+
if (Array.isArray(options.customConditions)) {
|
|
96
|
+
conditions = options.customConditions.filter((c) => typeof c === 'string');
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
catch { }
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
customConditionsCache.set(root, conditions);
|
|
103
|
+
return conditions;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Conditions list for `resolve.exports`: workspace `customConditions` plus
|
|
107
|
+
* `development` as backward-compat for workspaces not yet migrated by
|
|
108
|
+
* `migrate-development-custom-condition` (21.5).
|
|
109
|
+
*/
|
|
110
|
+
function getRootTsConfigResolveExportsConditions(root = workspace_root_1.workspaceRoot) {
|
|
111
|
+
const conditions = getRootTsConfigCustomConditions(root);
|
|
112
|
+
return conditions.includes('development')
|
|
113
|
+
? conditions
|
|
114
|
+
: [...conditions, 'development'];
|
|
115
|
+
}
|
|
77
116
|
function findNodes(node, kind, max = Infinity) {
|
|
78
117
|
if (!node || max == 0) {
|
|
79
118
|
return [];
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { NxJsonConfiguration } from '../../config/nx-json';
|
|
2
2
|
import type { ProjectConfiguration } from '../../config/workspace-json-project-json';
|
|
3
3
|
import { PackageJson } from '../../utils/package-json';
|
|
4
|
+
import { PackageManagerCommands } from '../../utils/package-manager';
|
|
4
5
|
import { CreateNodesV2 } from '../../project-graph/plugins';
|
|
5
6
|
import { PackageJsonConfigurationCache } from '../../../plugins/package-json';
|
|
6
7
|
export declare const createNodesV2: CreateNodesV2;
|
|
@@ -12,12 +13,12 @@ type PackageJsonPatterns = {
|
|
|
12
13
|
negativeLookup: Record<string, boolean>;
|
|
13
14
|
};
|
|
14
15
|
export declare function buildPackageJsonWorkspacesMatcher(patterns: PackageJsonPatterns): (p: any) => boolean;
|
|
15
|
-
export declare function createNodeFromPackageJson(pkgJsonPath: string, workspaceRoot: string, cache: PackageJsonConfigurationCache, isInPackageManagerWorkspaces: boolean): {
|
|
16
|
+
export declare function createNodeFromPackageJson(pkgJsonPath: string, workspaceRoot: string, cache: PackageJsonConfigurationCache, isInPackageManagerWorkspaces: boolean, packageManagerCommand: PackageManagerCommands): {
|
|
16
17
|
projects: {
|
|
17
18
|
[x: string]: ProjectConfiguration;
|
|
18
19
|
};
|
|
19
20
|
};
|
|
20
|
-
export declare function buildProjectConfigurationFromPackageJson(packageJson: PackageJson, workspaceRoot: string, packageJsonPath: string, nxJson: NxJsonConfiguration, isInPackageManagerWorkspaces: boolean): ProjectConfiguration & {
|
|
21
|
+
export declare function buildProjectConfigurationFromPackageJson(packageJson: PackageJson, workspaceRoot: string, packageJsonPath: string, nxJson: NxJsonConfiguration, isInPackageManagerWorkspaces: boolean, packageManagerCommand: PackageManagerCommands): ProjectConfiguration & {
|
|
21
22
|
name: string;
|
|
22
23
|
};
|
|
23
24
|
/**
|