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.
Files changed (274) hide show
  1. package/dist/bin/init-local.js +11 -20
  2. package/dist/bin/nx.d.ts +1 -0
  3. package/dist/bin/nx.js +28 -2
  4. package/dist/plugins/package-json.js +4 -2
  5. package/dist/src/adapter/ngcli-adapter.d.ts +2 -1
  6. package/dist/src/adapter/ngcli-adapter.js +25 -2
  7. package/dist/src/ai/clone-ai-config-repo.js +20 -3
  8. package/dist/src/analytics/analytics.js +10 -1
  9. package/dist/src/command-line/add/completion.d.ts +1 -0
  10. package/dist/src/command-line/add/completion.js +15 -0
  11. package/dist/src/command-line/affected/completion.d.ts +1 -0
  12. package/dist/src/command-line/affected/completion.js +15 -0
  13. package/dist/src/command-line/completion/argv-layout.d.ts +6 -0
  14. package/dist/src/command-line/completion/argv-layout.js +19 -0
  15. package/dist/src/command-line/completion/command-completions.d.ts +19 -0
  16. package/dist/src/command-line/completion/command-completions.js +120 -0
  17. package/dist/src/command-line/completion/command-handlers.d.ts +30 -0
  18. package/dist/src/command-line/completion/command-handlers.js +69 -0
  19. package/dist/src/command-line/completion/command-object.d.ts +10 -0
  20. package/dist/src/command-line/completion/command-object.js +95 -0
  21. package/dist/src/command-line/completion/completion-providers.d.ts +21 -0
  22. package/dist/src/command-line/completion/completion-providers.js +194 -0
  23. package/dist/src/command-line/completion/infix-targets.d.ts +1 -0
  24. package/dist/src/command-line/completion/infix-targets.js +48 -0
  25. package/dist/src/command-line/completion/metadata.d.ts +22 -0
  26. package/dist/src/command-line/completion/metadata.js +71 -0
  27. package/dist/src/command-line/completion/registrations.d.ts +9 -0
  28. package/dist/src/command-line/completion/registrations.js +16 -0
  29. package/dist/src/command-line/completion/scripts/bash.sh +51 -0
  30. package/dist/src/command-line/completion/scripts/fish.fish +47 -0
  31. package/dist/src/command-line/completion/scripts/powershell.ps1 +52 -0
  32. package/dist/src/command-line/completion/scripts/zsh.zsh +69 -0
  33. package/dist/src/command-line/completion/scripts.d.ts +18 -0
  34. package/dist/src/command-line/completion/scripts.js +140 -0
  35. package/dist/src/command-line/completion/trigger.d.ts +3 -0
  36. package/dist/src/command-line/completion/trigger.js +21 -0
  37. package/dist/src/command-line/completion/value-completions.d.ts +3 -0
  38. package/dist/src/command-line/completion/value-completions.js +21 -0
  39. package/dist/src/command-line/examples.js +1 -1
  40. package/dist/src/command-line/format/format.js +15 -5
  41. package/dist/src/command-line/generate/completion.d.ts +1 -0
  42. package/dist/src/command-line/generate/completion.js +9 -0
  43. package/dist/src/command-line/graph/completion.d.ts +1 -0
  44. package/dist/src/command-line/graph/completion.js +13 -0
  45. package/dist/src/command-line/init/implementation/angular/standalone-workspace.js +14 -18
  46. package/dist/src/command-line/init/implementation/dot-nx/add-nx-scripts.js +1 -0
  47. package/dist/src/command-line/init/implementation/utils.d.ts +7 -1
  48. package/dist/src/command-line/init/implementation/utils.js +51 -14
  49. package/dist/src/command-line/migrate/agentic/capture-generator-output.d.ts +22 -0
  50. package/dist/src/command-line/migrate/agentic/capture-generator-output.js +100 -0
  51. package/dist/src/command-line/migrate/agentic/cli-args.d.ts +12 -0
  52. package/dist/src/command-line/migrate/agentic/cli-args.js +38 -0
  53. package/dist/src/command-line/migrate/agentic/definitions.d.ts +6 -0
  54. package/dist/src/command-line/migrate/agentic/definitions.js +98 -0
  55. package/dist/src/command-line/migrate/agentic/detect-installed.d.ts +10 -0
  56. package/dist/src/command-line/migrate/agentic/detect-installed.js +68 -0
  57. package/dist/src/command-line/migrate/agentic/handoff-gitignore.d.ts +46 -0
  58. package/dist/src/command-line/migrate/agentic/handoff-gitignore.js +87 -0
  59. package/dist/src/command-line/migrate/agentic/handoff.d.ts +63 -0
  60. package/dist/src/command-line/migrate/agentic/handoff.js +183 -0
  61. package/dist/src/command-line/migrate/agentic/inception.d.ts +9 -0
  62. package/dist/src/command-line/migrate/agentic/inception.js +15 -0
  63. package/dist/src/command-line/migrate/agentic/print-dropped-agent-context.d.ts +22 -0
  64. package/dist/src/command-line/migrate/agentic/print-dropped-agent-context.js +50 -0
  65. package/dist/src/command-line/migrate/agentic/prompts/generic-validation.d.ts +51 -0
  66. package/dist/src/command-line/migrate/agentic/prompts/generic-validation.js +65 -0
  67. package/dist/src/command-line/migrate/agentic/prompts/hybrid-prompt-migration.d.ts +44 -0
  68. package/dist/src/command-line/migrate/agentic/prompts/hybrid-prompt-migration.js +52 -0
  69. package/dist/src/command-line/migrate/agentic/prompts/prompt-migration.d.ts +21 -0
  70. package/dist/src/command-line/migrate/agentic/prompts/prompt-migration.js +26 -0
  71. package/dist/src/command-line/migrate/agentic/prompts/shared-rendering.d.ts +18 -0
  72. package/dist/src/command-line/migrate/agentic/prompts/shared-rendering.js +130 -0
  73. package/dist/src/command-line/migrate/agentic/prompts/system-prompt.d.ts +46 -0
  74. package/dist/src/command-line/migrate/agentic/prompts/system-prompt.js +88 -0
  75. package/dist/src/command-line/migrate/agentic/run-step.d.ts +51 -0
  76. package/dist/src/command-line/migrate/agentic/run-step.js +121 -0
  77. package/dist/src/command-line/migrate/agentic/runner.d.ts +33 -0
  78. package/dist/src/command-line/migrate/agentic/runner.js +442 -0
  79. package/dist/src/command-line/migrate/agentic/select.d.ts +14 -0
  80. package/dist/src/command-line/migrate/agentic/select.js +150 -0
  81. package/dist/src/command-line/migrate/agentic/types.d.ts +102 -0
  82. package/dist/src/command-line/migrate/agentic/types.js +2 -0
  83. package/dist/src/command-line/migrate/command-object.d.ts +1 -0
  84. package/dist/src/command-line/migrate/command-object.js +32 -7
  85. package/dist/src/command-line/migrate/migrate-commits.d.ts +50 -0
  86. package/dist/src/command-line/migrate/migrate-commits.js +102 -0
  87. package/dist/src/command-line/migrate/migrate-output.d.ts +180 -0
  88. package/dist/src/command-line/migrate/migrate-output.js +258 -0
  89. package/dist/src/command-line/migrate/migrate.d.ts +122 -12
  90. package/dist/src/command-line/migrate/migrate.js +1036 -217
  91. package/dist/src/command-line/migrate/migration-shape.d.ts +8 -0
  92. package/dist/src/command-line/migrate/migration-shape.js +13 -0
  93. package/dist/src/command-line/migrate/multi-major.d.ts +30 -0
  94. package/dist/src/command-line/migrate/multi-major.js +185 -0
  95. package/dist/src/command-line/migrate/prompt-files.d.ts +31 -0
  96. package/dist/src/command-line/migrate/prompt-files.js +141 -0
  97. package/dist/src/command-line/migrate/run-migration-process.js +28 -6
  98. package/dist/src/command-line/migrate/safe-prompt.d.ts +28 -0
  99. package/dist/src/command-line/migrate/safe-prompt.js +49 -0
  100. package/dist/src/command-line/migrate/update-filters.d.ts +11 -0
  101. package/dist/src/command-line/migrate/update-filters.js +44 -0
  102. package/dist/src/command-line/migrate/version-utils.d.ts +6 -0
  103. package/dist/src/command-line/migrate/version-utils.js +59 -0
  104. package/dist/src/command-line/nx-commands.js +9 -0
  105. package/dist/src/command-line/release/config/config.d.ts +3 -6
  106. package/dist/src/command-line/release/config/config.js +77 -45
  107. package/dist/src/command-line/release/config/use-legacy-versioning.d.ts +2 -0
  108. package/dist/src/command-line/release/config/use-legacy-versioning.js +8 -0
  109. package/dist/src/command-line/release/utils/release-graph.js +2 -3
  110. package/dist/src/command-line/release/utils/repository-git-tags.js +1 -1
  111. package/dist/src/command-line/release/utils/resolve-changelog-renderer.js +7 -19
  112. package/dist/src/command-line/release/version/resolve-current-version.js +1 -1
  113. package/dist/src/command-line/release/version/version-actions.js +3 -7
  114. package/dist/src/command-line/report/report.js +2 -2
  115. package/dist/src/command-line/run/completion.d.ts +1 -0
  116. package/dist/src/command-line/run/completion.js +7 -0
  117. package/dist/src/command-line/run-many/completion.d.ts +1 -0
  118. package/dist/src/command-line/run-many/completion.js +13 -0
  119. package/dist/src/command-line/show/completion.d.ts +1 -0
  120. package/dist/src/command-line/show/completion.js +27 -0
  121. package/dist/src/command-line/show/show-target/info.d.ts +1 -0
  122. package/dist/src/command-line/show/show-target/info.js +100 -19
  123. package/dist/src/command-line/watch/command-object.js +24 -4
  124. package/dist/src/command-line/watch/completion.d.ts +1 -0
  125. package/dist/src/command-line/watch/completion.js +10 -0
  126. package/dist/src/command-line/watch/watch.d.ts +7 -0
  127. package/dist/src/command-line/watch/watch.js +1 -1
  128. package/dist/src/config/misc-interfaces.d.ts +25 -2
  129. package/dist/src/config/nx-json.d.ts +43 -56
  130. package/dist/src/config/schema-utils.d.ts +21 -0
  131. package/dist/src/config/schema-utils.js +92 -18
  132. package/dist/src/config/task-graph.d.ts +4 -107
  133. package/dist/src/core/graph/main.js +1 -1
  134. package/dist/src/core/graph/styles.css +2 -3
  135. package/dist/src/core/graph/styles.js +1 -1
  136. package/dist/src/daemon/client/client.d.ts +1 -1
  137. package/dist/src/daemon/server/file-watching/file-watcher-sockets.d.ts +1 -1
  138. package/dist/src/daemon/server/file-watching/file-watcher-sockets.js +1 -1
  139. package/dist/src/daemon/server/file-watching/route-workspace-changes.d.ts +9 -0
  140. package/dist/src/daemon/server/file-watching/route-workspace-changes.js +76 -0
  141. package/dist/src/daemon/server/project-graph-incremental-recomputation.js +45 -11
  142. package/dist/src/daemon/server/server.js +4 -43
  143. package/dist/src/daemon/server/start.d.ts +1 -1
  144. package/dist/src/daemon/server/start.js +2 -0
  145. package/dist/src/devkit-exports.d.ts +2 -2
  146. package/dist/src/devkit-internals.d.ts +5 -1
  147. package/dist/src/devkit-internals.js +17 -1
  148. package/dist/src/executors/run-commands/running-tasks.d.ts +7 -0
  149. package/dist/src/executors/run-commands/running-tasks.js +178 -105
  150. package/dist/src/executors/run-script/run-script.impl.js +3 -10
  151. package/dist/src/executors/utils/convert-nx-executor.js +1 -1
  152. package/dist/src/hasher/hash-plan-inspector.d.ts +1 -1
  153. package/dist/src/hasher/task-hasher.js +6 -4
  154. package/dist/src/index.d.ts +1 -1
  155. package/dist/src/index.js +0 -3
  156. package/dist/src/migrations/update-16-2-0/remove-run-commands-output-path.js +6 -2
  157. package/dist/src/migrations/update-17-0-0/move-cache-directory.md +31 -0
  158. package/dist/src/migrations/update-17-0-0/use-minimal-config-for-tasks-runner-options.js +20 -4
  159. package/dist/src/migrations/update-20-0-0/move-use-daemon-process.md +27 -0
  160. package/dist/src/migrations/update-20-0-1/use-legacy-cache.md +24 -0
  161. package/dist/src/migrations/update-21-0-0/release-changelog-config-changes.md +49 -0
  162. package/dist/src/migrations/update-21-0-0/release-version-config-changes.md +54 -0
  163. package/dist/src/migrations/update-21-0-0/remove-custom-tasks-runner.md +28 -0
  164. package/dist/src/migrations/update-21-0-0/remove-legacy-cache.md +22 -0
  165. package/dist/src/migrations/update-22-2-0/add-self-healing-to-gitignore.md +11 -0
  166. package/dist/src/migrations/update-23-0-0/add-migrate-runs-to-git-ignore.d.ts +2 -0
  167. package/dist/src/migrations/update-23-0-0/add-migrate-runs-to-git-ignore.js +16 -0
  168. package/dist/src/migrations/update-23-0-0/consolidate-release-tag-config.d.ts +9 -0
  169. package/dist/src/migrations/update-23-0-0/consolidate-release-tag-config.js +18 -0
  170. package/dist/src/migrations/update-23-0-0/convert-target-defaults-to-array.d.ts +35 -0
  171. package/dist/src/migrations/update-23-0-0/convert-target-defaults-to-array.js +139 -0
  172. package/dist/src/migrations/update-23-0-0/convert-target-defaults-to-array.md +66 -0
  173. package/dist/src/native/index.d.ts +79 -2
  174. package/dist/src/native/native-bindings.js +3 -0
  175. package/dist/src/native/nx.wasm32-wasi.debug.wasm +0 -0
  176. package/dist/src/native/nx.wasm32-wasi.wasm +0 -0
  177. package/dist/src/plugins/js/lock-file/npm-parser.js +37 -19
  178. package/dist/src/plugins/js/lock-file/pnpm-parser.js +51 -4
  179. package/dist/src/plugins/js/lock-file/project-graph-pruning.js +12 -4
  180. package/dist/src/plugins/js/utils/packages.js +1 -1
  181. package/dist/src/plugins/js/utils/register.d.ts +103 -14
  182. package/dist/src/plugins/js/utils/register.js +434 -39
  183. package/dist/src/plugins/js/utils/typescript.d.ts +7 -0
  184. package/dist/src/plugins/js/utils/typescript.js +39 -0
  185. package/dist/src/plugins/package-json/create-nodes.d.ts +3 -2
  186. package/dist/src/plugins/package-json/create-nodes.js +7 -5
  187. package/dist/src/project-graph/affected/locators/project-glob-changes.js +2 -1
  188. package/dist/src/project-graph/build-project-graph.d.ts +5 -0
  189. package/dist/src/project-graph/build-project-graph.js +6 -2
  190. package/dist/src/project-graph/file-map-utils.d.ts +5 -0
  191. package/dist/src/project-graph/file-map-utils.js +10 -1
  192. package/dist/src/project-graph/plugins/get-plugins.d.ts +7 -2
  193. package/dist/src/project-graph/plugins/get-plugins.js +8 -5
  194. package/dist/src/project-graph/plugins/isolation/plugin-worker.d.ts +1 -0
  195. package/dist/src/project-graph/plugins/isolation/plugin-worker.js +2 -0
  196. package/dist/src/project-graph/plugins/resolve-plugin.d.ts +7 -4
  197. package/dist/src/project-graph/plugins/resolve-plugin.js +152 -33
  198. package/dist/src/project-graph/plugins/tasks-execution-hooks.js +4 -2
  199. package/dist/src/project-graph/plugins/transpiler.d.ts +12 -0
  200. package/dist/src/project-graph/plugins/transpiler.js +37 -0
  201. package/dist/src/project-graph/plugins/utils.js +13 -7
  202. package/dist/src/project-graph/project-graph.js +1 -1
  203. package/dist/src/project-graph/utils/project-configuration/target-defaults.d.ts +95 -4
  204. package/dist/src/project-graph/utils/project-configuration/target-defaults.js +515 -68
  205. package/dist/src/project-graph/utils/project-configuration-utils.d.ts +13 -5
  206. package/dist/src/project-graph/utils/project-configuration-utils.js +14 -6
  207. package/dist/src/project-graph/utils/retrieve-workspace-files.js +1 -1
  208. package/dist/src/tasks-runner/create-task-graph.d.ts +4 -4
  209. package/dist/src/tasks-runner/create-task-graph.js +1 -1
  210. package/dist/src/tasks-runner/default-tasks-runner.d.ts +0 -2
  211. package/dist/src/tasks-runner/forked-process-task-runner.d.ts +1 -1
  212. package/dist/src/tasks-runner/forked-process-task-runner.js +11 -6
  213. package/dist/src/tasks-runner/init-tasks-runner.d.ts +0 -15
  214. package/dist/src/tasks-runner/init-tasks-runner.js +0 -63
  215. package/dist/src/tasks-runner/legacy-depends-on-warning.d.ts +18 -0
  216. package/dist/src/tasks-runner/legacy-depends-on-warning.js +109 -0
  217. package/dist/src/tasks-runner/life-cycle.d.ts +7 -8
  218. package/dist/src/tasks-runner/life-cycles/invoke-runner-terminal-output-life-cycle.js +6 -6
  219. package/dist/src/tasks-runner/life-cycles/task-history-life-cycle-old.js +13 -2
  220. package/dist/src/tasks-runner/life-cycles/task-history-life-cycle.js +16 -5
  221. package/dist/src/tasks-runner/life-cycles/tui-summary-life-cycle.js +11 -2
  222. package/dist/src/tasks-runner/pseudo-terminal.d.ts +1 -1
  223. package/dist/src/tasks-runner/pseudo-terminal.js +22 -10
  224. package/dist/src/tasks-runner/run-command.js +8 -11
  225. package/dist/src/tasks-runner/running-tasks/batch-process.d.ts +1 -1
  226. package/dist/src/tasks-runner/running-tasks/batch-process.js +3 -5
  227. package/dist/src/tasks-runner/running-tasks/node-child-process.d.ts +2 -2
  228. package/dist/src/tasks-runner/running-tasks/node-child-process.js +5 -7
  229. package/dist/src/tasks-runner/task-env.d.ts +1 -1
  230. package/dist/src/tasks-runner/task-env.js +6 -1
  231. package/dist/src/tasks-runner/task-orchestrator.d.ts +11 -1
  232. package/dist/src/tasks-runner/task-orchestrator.js +112 -38
  233. package/dist/src/tasks-runner/tasks-schedule.js +3 -3
  234. package/dist/src/tasks-runner/utils.d.ts +7 -8
  235. package/dist/src/tasks-runner/utils.js +23 -27
  236. package/dist/src/utils/child-process.js +2 -2
  237. package/dist/src/utils/compile-cache.d.ts +24 -0
  238. package/dist/src/utils/compile-cache.js +49 -0
  239. package/dist/src/utils/enable-compile-cache.d.ts +1 -0
  240. package/dist/src/utils/enable-compile-cache.js +7 -0
  241. package/dist/src/utils/fileutils.d.ts +0 -8
  242. package/dist/src/utils/fileutils.js +0 -40
  243. package/dist/src/utils/git-utils.d.ts +15 -0
  244. package/dist/src/utils/git-utils.js +138 -0
  245. package/dist/src/utils/handle-import.d.ts +4 -1
  246. package/dist/src/utils/handle-import.js +56 -2
  247. package/dist/src/utils/has-nx-js-plugin.d.ts +9 -0
  248. package/dist/src/utils/has-nx-js-plugin.js +24 -0
  249. package/dist/src/utils/installed-nx-version.d.ts +14 -4
  250. package/dist/src/utils/installed-nx-version.js +54 -7
  251. package/dist/src/utils/logger.d.ts +12 -1
  252. package/dist/src/utils/logger.js +57 -36
  253. package/dist/src/utils/nx-key.d.ts +0 -1
  254. package/dist/src/utils/nx-key.js +20 -23
  255. package/dist/src/utils/nx-package-group.d.ts +8 -0
  256. package/dist/src/utils/nx-package-group.js +15 -0
  257. package/dist/src/utils/output.d.ts +3 -2
  258. package/dist/src/utils/output.js +29 -28
  259. package/dist/src/utils/package-json.d.ts +14 -1
  260. package/dist/src/utils/package-json.js +20 -21
  261. package/dist/src/utils/perf-logging.js +3 -1
  262. package/dist/src/utils/plugin-cache-utils.d.ts +13 -4
  263. package/dist/src/utils/plugin-cache-utils.js +23 -13
  264. package/dist/src/utils/plugins/local-plugins.d.ts +18 -0
  265. package/dist/src/utils/plugins/local-plugins.js +30 -0
  266. package/dist/src/utils/tar.d.ts +8 -0
  267. package/dist/src/utils/tar.js +44 -0
  268. package/migrations.json +16 -0
  269. package/package.json +28 -28
  270. package/schemas/nx-schema.json +114 -80
  271. package/dist/src/plugins/js/project-graph/build-dependencies/strip-source-code.d.ts +0 -7
  272. package/dist/src/plugins/js/project-graph/build-dependencies/strip-source-code.js +0 -155
  273. package/dist/src/plugins/js/project-graph/build-dependencies/typescript-import-locator.d.ts +0 -16
  274. 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 version supports native TypeScript execution
55
- * via type stripping (Node 22.6+).
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 in Node 22.6+
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 and the user has opted in via
63
- * NX_PREFER_NODE_STRIP_TYPES=true, we can skip registering swc-node or ts-node
64
- * transpilers since Node.js will handle TypeScript natively.
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
- * This can significantly improve performance when loading TypeScript config files, but there are some things
67
- * that won't work. See: https://nodejs.org/api/typescript.html#full-typescript-support
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
- * TODO(v23): We should turn this on by default, but look at if need to fallback to SWC/ts-node if it fails.
152
+ * See: https://nodejs.org/api/typescript.html#full-typescript-support
70
153
  */
71
154
  const preferNodeStripTypes = (() => {
72
- if (process.env.NX_PREFER_NODE_STRIP_TYPES !== 'true') {
155
+ if (!nodeSupportsNativeTypescript) {
73
156
  return false;
74
157
  }
75
- return nodeSupportsNativeTypescript;
158
+ return process.env.NX_PREFER_NODE_STRIP_TYPES !== 'false';
76
159
  })();
77
- function registerTsProject(path, configFilename) {
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
- // Add ESM support for `.ts` files.
95
- // NOTE: There is no cleanup function for this, as it's not possible to unregister the loader.
96
- // Based on limited testing, it doesn't seem to matter if we register it multiple times, but just in
97
- // case let's keep a flag to prevent it.
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 Node will handle .ts files via type stripping.
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
  /**