nx 23.1.0 → 23.1.2

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 (223) hide show
  1. package/dist/bin/nx.js +2 -1
  2. package/dist/release/changelog-renderer/index.js +4 -5
  3. package/dist/release/index.d.ts +1 -1
  4. package/dist/src/ai/configure-ai-agents-disclaimer.d.ts +5 -0
  5. package/dist/src/ai/configure-ai-agents-disclaimer.js +31 -0
  6. package/dist/src/analytics/analytics.d.ts +6 -0
  7. package/dist/src/analytics/analytics.js +16 -8
  8. package/dist/src/analytics/index.d.ts +1 -1
  9. package/dist/src/analytics/index.js +2 -1
  10. package/dist/src/command-line/add/add.js +13 -1
  11. package/dist/src/command-line/affected/affected.js +1 -0
  12. package/dist/src/command-line/configure-ai-agents/configure-ai-agents.js +2 -2
  13. package/dist/src/command-line/graph/graph.d.ts +1 -0
  14. package/dist/src/command-line/graph/graph.js +15 -6
  15. package/dist/src/command-line/import/import.js +2 -3
  16. package/dist/src/command-line/init/ai-agent-prompts.d.ts +1 -1
  17. package/dist/src/command-line/init/ai-agent-prompts.js +7 -6
  18. package/dist/src/command-line/init/command-object.js +10 -2
  19. package/dist/src/command-line/init/configure-plugins.js +3 -2
  20. package/dist/src/command-line/init/implementation/add-nx-to-monorepo.js +4 -2
  21. package/dist/src/command-line/init/implementation/add-nx-to-nest.js +4 -3
  22. package/dist/src/command-line/init/implementation/add-nx-to-npm-repo.js +4 -3
  23. package/dist/src/command-line/init/implementation/add-nx-to-turborepo.js +4 -3
  24. package/dist/src/command-line/init/implementation/angular/index.js +4 -2
  25. package/dist/src/command-line/init/implementation/angular/integrated-workspace.js +2 -5
  26. package/dist/src/command-line/init/implementation/angular/legacy-angular-versions.js +3 -0
  27. package/dist/src/command-line/init/implementation/dot-nx/add-nx-scripts.js +4 -1
  28. package/dist/src/command-line/init/implementation/utils.d.ts +3 -3
  29. package/dist/src/command-line/init/implementation/utils.js +22 -3
  30. package/dist/src/command-line/init/init-v2.js +4 -5
  31. package/dist/src/command-line/migrate/execute-migration.d.ts +72 -0
  32. package/dist/src/command-line/migrate/execute-migration.js +389 -0
  33. package/dist/src/command-line/migrate/migrate-ui-api.js +17 -12
  34. package/dist/src/command-line/migrate/migrate.d.ts +5 -45
  35. package/dist/src/command-line/migrate/migrate.js +122 -402
  36. package/dist/src/command-line/nx-cloud/connect/connect-to-nx-cloud.js +1 -1
  37. package/dist/src/command-line/nx-cloud/connect/view-logs.js +2 -0
  38. package/dist/src/command-line/release/changelog.js +5 -0
  39. package/dist/src/command-line/release/index.d.ts +1 -1
  40. package/dist/src/command-line/release/utils/git.js +7 -3
  41. package/dist/src/command-line/release/utils/release-graph.d.ts +19 -2
  42. package/dist/src/command-line/release/utils/release-graph.js +71 -19
  43. package/dist/src/command-line/release/utils/remote-release-clients/github.js +7 -1
  44. package/dist/src/command-line/release/utils/remote-release-clients/gitlab.js +1 -1
  45. package/dist/src/command-line/release/utils/shared.d.ts +2 -2
  46. package/dist/src/command-line/release/version/release-group-processor.d.ts +24 -0
  47. package/dist/src/command-line/release/version/release-group-processor.js +80 -6
  48. package/dist/src/command-line/release/version/version-actions.d.ts +27 -2
  49. package/dist/src/command-line/release/version/version-actions.js +9 -1
  50. package/dist/src/command-line/release/version.js +9 -5
  51. package/dist/src/command-line/reset/reset.js +6 -1
  52. package/dist/src/command-line/run/run-one.js +1 -0
  53. package/dist/src/command-line/run-many/run-many.js +1 -0
  54. package/dist/src/command-line/show/show-target/info.js +11 -2
  55. package/dist/src/command-line/show/show-target/inputs.js +50 -153
  56. package/dist/src/command-line/show/show-target/outputs.js +48 -173
  57. package/dist/src/command-line/show/show-target/utils.d.ts +28 -0
  58. package/dist/src/command-line/show/show-target/utils.js +83 -3
  59. package/dist/src/command-line/watch/watch.js +13 -0
  60. package/dist/src/command-line/yargs-utils/shared-options.d.ts +1 -1
  61. package/dist/src/commands-runner/create-command-graph.js +5 -0
  62. package/dist/src/config/nx-json.d.ts +5 -3
  63. package/dist/src/core/graph/main.js +1 -1
  64. package/dist/src/core/graph/styles.js +1 -1
  65. package/dist/src/daemon/client/client.d.ts +52 -3
  66. package/dist/src/daemon/client/client.js +177 -55
  67. package/dist/src/daemon/client/daemon-environment.d.ts +17 -0
  68. package/dist/src/daemon/client/daemon-environment.js +110 -2
  69. package/dist/src/daemon/client/daemon-socket-messenger.js +4 -0
  70. package/dist/src/daemon/message-types/daemon-message.d.ts +32 -0
  71. package/dist/src/daemon/message-types/daemon-message.js +25 -0
  72. package/dist/src/daemon/server/file-watching/file-watcher-sockets.d.ts +5 -0
  73. package/dist/src/daemon/server/file-watching/file-watcher-sockets.js +16 -0
  74. package/dist/src/daemon/server/handle-tasks-execution-hooks.d.ts +1 -1
  75. package/dist/src/daemon/server/latest-nx.js +5 -2
  76. package/dist/src/daemon/server/server.js +31 -4
  77. package/dist/src/daemon/server/shutdown-utils.d.ts +5 -0
  78. package/dist/src/daemon/server/shutdown-utils.js +11 -4
  79. package/dist/src/daemon/socket-utils.d.ts +1 -0
  80. package/dist/src/daemon/socket-utils.js +24 -3
  81. package/dist/src/daemon/tmp-dir.d.ts +43 -3
  82. package/dist/src/daemon/tmp-dir.js +437 -15
  83. package/dist/src/devkit-internals.d.ts +96 -3
  84. package/dist/src/devkit-internals.js +200 -4
  85. package/dist/src/generators/internal-utils/format-changed-files-with-prettier-if-available.d.ts +5 -0
  86. package/dist/src/generators/internal-utils/format-changed-files-with-prettier-if-available.js +9 -2
  87. package/dist/src/generators/tree.d.ts +4 -2
  88. package/dist/src/generators/utils/nx-json.js +13 -3
  89. package/dist/src/hasher/check-task-files.d.ts +86 -0
  90. package/dist/src/hasher/check-task-files.js +378 -0
  91. package/dist/src/migrations/update-23-2-0/set-cache-on-executor-target-defaults.d.ts +12 -0
  92. package/dist/src/migrations/update-23-2-0/set-cache-on-executor-target-defaults.js +250 -0
  93. package/dist/src/migrations/update-23-2-0/set-cache-on-executor-target-defaults.md +50 -0
  94. package/dist/src/native/index.d.ts +31 -2
  95. package/dist/src/native/index.js +71 -28
  96. package/dist/src/native/native-bindings.js +3 -0
  97. package/dist/src/native/native-file-cache-location.d.ts +17 -1
  98. package/dist/src/native/native-file-cache-location.js +86 -12
  99. package/dist/src/native/nx.wasm32-wasi.debug.wasm +0 -0
  100. package/dist/src/native/nx.wasm32-wasi.wasm +0 -0
  101. package/dist/src/nx-cloud/utilities/get-cloud-options.js +5 -2
  102. package/dist/src/nx-cloud/utilities/onboarding.js +5 -2
  103. package/dist/src/plugins/js/lock-file/bun-parser.js +43 -10
  104. package/dist/src/plugins/js/lock-file/npm-parser.js +71 -27
  105. package/dist/src/plugins/js/lock-file/pnpm-parser.js +110 -17
  106. package/dist/src/plugins/js/lock-file/project-graph-pruning.js +15 -9
  107. package/dist/src/plugins/js/lock-file/utils/pnpm-normalizer.js +3 -0
  108. package/dist/src/plugins/js/lock-file/yarn-parser.js +32 -5
  109. package/dist/src/plugins/js/project-graph/affected/npm-packages.js +51 -20
  110. package/dist/src/plugins/js/project-graph/build-dependencies/target-project-locator.js +14 -4
  111. package/dist/src/plugins/js/utils/register.d.ts +18 -0
  112. package/dist/src/plugins/js/utils/register.js +81 -0
  113. package/dist/src/plugins/js/utils/typescript.d.ts +9 -0
  114. package/dist/src/plugins/js/utils/typescript.js +15 -0
  115. package/dist/src/project-graph/affected/affected-project-graph-models.d.ts +1 -1
  116. package/dist/src/project-graph/affected/affected-project-graph.d.ts +1 -1
  117. package/dist/src/project-graph/affected/affected-project-graph.js +2 -2
  118. package/dist/src/project-graph/affected/locators/project-glob-changes.js +5 -2
  119. package/dist/src/project-graph/build-project-graph.js +7 -1
  120. package/dist/src/project-graph/error-types.d.ts +12 -1
  121. package/dist/src/project-graph/error-types.js +68 -3
  122. package/dist/src/project-graph/file-utils.js +6 -1
  123. package/dist/src/project-graph/plugins/isolation/isolated-plugin.d.ts +1 -0
  124. package/dist/src/project-graph/plugins/isolation/isolated-plugin.js +22 -1
  125. package/dist/src/project-graph/plugins/isolation/messaging.d.ts +16 -3
  126. package/dist/src/project-graph/plugins/isolation/messaging.js +3 -0
  127. package/dist/src/project-graph/plugins/isolation/plugin-worker.js +58 -8
  128. package/dist/src/project-graph/plugins/loaded-nx-plugin.js +1 -0
  129. package/dist/src/project-graph/plugins/transpiler.js +4 -0
  130. package/dist/src/project-graph/project-graph.js +23 -0
  131. package/dist/src/project-graph/utils/project-configuration/name-substitution-manager.d.ts +10 -12
  132. package/dist/src/project-graph/utils/project-configuration/name-substitution-manager.js +93 -63
  133. package/dist/src/project-graph/utils/project-configuration/project-nodes-manager.d.ts +5 -8
  134. package/dist/src/project-graph/utils/project-configuration/project-nodes-manager.js +16 -15
  135. package/dist/src/project-graph/utils/project-configuration/source-maps.d.ts +12 -5
  136. package/dist/src/project-graph/utils/project-configuration/source-maps.js +21 -7
  137. package/dist/src/project-graph/utils/project-configuration/target-defaults.d.ts +1 -1
  138. package/dist/src/project-graph/utils/project-configuration/target-defaults.js +26 -27
  139. package/dist/src/project-graph/utils/project-configuration/target-merging.js +50 -8
  140. package/dist/src/project-graph/utils/project-configuration/target-normalization.js +149 -6
  141. package/dist/src/project-graph/utils/project-configuration/utils.d.ts +15 -0
  142. package/dist/src/project-graph/utils/project-configuration/utils.js +42 -6
  143. package/dist/src/project-graph/utils/project-configuration-utils.d.ts +15 -12
  144. package/dist/src/project-graph/utils/project-configuration-utils.js +79 -101
  145. package/dist/src/tasks-runner/life-cycles/performance-analysis.d.ts +11 -4
  146. package/dist/src/tasks-runner/life-cycles/performance-analysis.js +15 -6
  147. package/dist/src/tasks-runner/life-cycles/performance-life-cycle.js +5 -4
  148. package/dist/src/tasks-runner/life-cycles/performance-report.d.ts +18 -8
  149. package/dist/src/tasks-runner/life-cycles/performance-report.js +66 -29
  150. package/dist/src/tasks-runner/run-command.js +4 -2
  151. package/dist/src/tasks-runner/task-env.d.ts +9 -0
  152. package/dist/src/tasks-runner/task-env.js +31 -4
  153. package/dist/src/tasks-runner/task-orchestrator.d.ts +4 -1
  154. package/dist/src/tasks-runner/task-orchestrator.js +23 -10
  155. package/dist/src/tasks-runner/utils.js +2 -6
  156. package/dist/src/utils/acknowledge-build-scripts.d.ts +13 -0
  157. package/dist/src/utils/acknowledge-build-scripts.js +102 -0
  158. package/dist/src/utils/analytics-prompt.d.ts +0 -6
  159. package/dist/src/utils/analytics-prompt.js +0 -51
  160. package/dist/src/utils/assert-workspace-validity.js +7 -2
  161. package/dist/src/utils/catalog/manager-utils.d.ts +1 -2
  162. package/dist/src/utils/catalog/manager-utils.js +22 -5
  163. package/dist/src/utils/catalog/pnpm-manager.d.ts +1 -0
  164. package/dist/src/utils/catalog/pnpm-manager.js +3 -15
  165. package/dist/src/utils/catalog/yarn-manager.d.ts +1 -0
  166. package/dist/src/utils/catalog/yarn-manager.js +3 -15
  167. package/dist/src/utils/command-line-utils.js +30 -20
  168. package/dist/src/utils/fileutils.d.ts +5 -0
  169. package/dist/src/utils/fileutils.js +7 -2
  170. package/dist/src/utils/git-revision.d.ts +12 -0
  171. package/dist/src/utils/git-revision.js +25 -0
  172. package/dist/src/utils/git-utils.d.ts +16 -3
  173. package/dist/src/utils/git-utils.js +146 -52
  174. package/dist/src/utils/git-worktrees.d.ts +30 -0
  175. package/dist/src/utils/git-worktrees.js +212 -0
  176. package/dist/src/utils/ignore.d.ts +128 -1
  177. package/dist/src/utils/ignore.js +182 -12
  178. package/dist/src/utils/long-running-target.d.ts +10 -0
  179. package/dist/src/utils/long-running-target.js +19 -0
  180. package/dist/src/utils/min-release-age/behavior/bun.js +7 -11
  181. package/dist/src/utils/min-release-age/behavior/npm.js +5 -2
  182. package/dist/src/utils/min-release-age/behavior/pnpm.js +9 -7
  183. package/dist/src/utils/min-release-age/packument.js +1 -1
  184. package/dist/src/utils/nx-tmp-dir.d.ts +18 -0
  185. package/dist/src/utils/nx-tmp-dir.js +40 -0
  186. package/dist/src/utils/owned-private-dir.d.ts +132 -0
  187. package/dist/src/utils/owned-private-dir.js +323 -0
  188. package/dist/src/utils/package-json.js +11 -7
  189. package/dist/src/utils/package-manager-config/bunfig.d.ts +14 -0
  190. package/dist/src/utils/package-manager-config/bunfig.js +49 -0
  191. package/dist/src/utils/package-manager-config/npmrc.d.ts +23 -0
  192. package/dist/src/utils/package-manager-config/npmrc.js +124 -0
  193. package/dist/src/utils/package-manager-config/pnpm-config.d.ts +17 -0
  194. package/dist/src/utils/package-manager-config/pnpm-config.js +60 -0
  195. package/dist/src/utils/package-manager.d.ts +23 -2
  196. package/dist/src/utils/package-manager.js +264 -43
  197. package/dist/src/utils/provenance.js +18 -16
  198. package/dist/src/utils/registry-config/bun.d.ts +2 -0
  199. package/dist/src/utils/registry-config/bun.js +257 -0
  200. package/dist/src/utils/registry-config/index.d.ts +13 -0
  201. package/dist/src/utils/registry-config/index.js +102 -0
  202. package/dist/src/utils/registry-config/pnpm.d.ts +2 -0
  203. package/dist/src/utils/registry-config/pnpm.js +1551 -0
  204. package/dist/src/utils/registry-config/utils.d.ts +195 -0
  205. package/dist/src/utils/registry-config/utils.js +496 -0
  206. package/dist/src/utils/registry-config/yarn-berry.d.ts +2 -0
  207. package/dist/src/utils/registry-config/yarn-berry.js +612 -0
  208. package/dist/src/utils/registry-config/yarn-classic.d.ts +2 -0
  209. package/dist/src/utils/registry-config/yarn-classic.js +1001 -0
  210. package/dist/src/utils/safe-spawn.d.ts +24 -0
  211. package/dist/src/utils/safe-spawn.js +104 -0
  212. package/dist/src/utils/shell-quoting.d.ts +15 -0
  213. package/dist/src/utils/shell-quoting.js +35 -0
  214. package/dist/src/utils/wait-for-socket-connection.d.ts +11 -0
  215. package/dist/src/utils/wait-for-socket-connection.js +14 -8
  216. package/dist/src/utils/workspace-id.d.ts +20 -0
  217. package/dist/src/utils/workspace-id.js +54 -0
  218. package/migrations.json +13 -1
  219. package/package.json +22 -17
  220. package/dist/src/migrations/update-17-3-0/nx-release-path.d.ts +0 -3
  221. package/dist/src/migrations/update-17-3-0/nx-release-path.js +0 -47
  222. package/dist/src/utils/min-release-age/npmrc.d.ts +0 -15
  223. package/dist/src/utils/min-release-age/npmrc.js +0 -45
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ProvenanceError = void 0;
4
4
  exports.ensurePackageHasProvenance = ensurePackageHasProvenance;
5
5
  exports.getNxPackageGroup = getNxPackageGroup;
6
- const child_process_1 = require("child_process");
7
6
  const module_1 = require("module");
8
7
  const fileutils_1 = require("./fileutils");
9
8
  const package_manager_1 = require("./package-manager");
@@ -21,9 +20,22 @@ async function ensurePackageHasProvenance(packageName, packageVersion) {
21
20
  return;
22
21
  }
23
22
  try {
24
- const result = await (0, package_manager_1.packageRegistryView)(packageName, packageVersion, '--json --silent');
25
- const npmViewResult = JSON.parse(result);
26
- const attURL = npmViewResult.dist?.attestations?.url;
23
+ const result = await (0, package_manager_1.packageRegistryView)(packageName, packageVersion, [
24
+ '--json',
25
+ '--silent',
26
+ ]);
27
+ const parsed = JSON.parse(result);
28
+ // `npm view <pkg>@<spec> --json` returns a bare object on npm <= 11 but an
29
+ // array on npm 12 and pnpm, even for a single resolved version. A version
30
+ // range matches several versions and the registry lists all of them
31
+ // (including deprecated ones the installer skips), so we cannot tell which
32
+ // one will actually be installed; refuse rather than verify the wrong
33
+ // artifact.
34
+ if (Array.isArray(parsed) && parsed.length > 1) {
35
+ throw new ProvenanceError(packageName, packageVersion, 'Provenance can only be verified for a single version, but this version resolved to multiple candidates. Specify an exact version.');
36
+ }
37
+ const npmViewResult = Array.isArray(parsed) ? parsed[0] : parsed;
38
+ const attURL = npmViewResult?.dist?.attestations?.url;
27
39
  if (!attURL)
28
40
  throw new ProvenanceError(packageName, packageVersion, 'No attestation URL found');
29
41
  const response = await fetch(attURL);
@@ -67,19 +79,9 @@ class ProvenanceError extends Error {
67
79
  constructor(packageName, packageVersion, error) {
68
80
  let customRegistry = undefined;
69
81
  try {
70
- const packageManager = (0, package_manager_1.detectPackageManager)();
71
- const commands = (0, package_manager_1.getPackageManagerCommand)(packageManager);
72
- // Try to get registry from current package manager, fall back to npm
73
- const registryCommand = commands.getRegistryUrl ?? 'npm config get registry';
74
- const registry = (0, child_process_1.execSync)(registryCommand, {
75
- timeout: 5000,
76
- windowsHide: true,
77
- encoding: 'utf-8',
78
- }).trim();
82
+ const registry = (0, package_manager_1.getWorkspaceRegistryUrlForDisplay)(packageName);
79
83
  // Only consider it custom if it's not the default npm registry
80
- if (registry &&
81
- registry !== 'undefined' &&
82
- !registry.includes('registry.npmjs.org')) {
84
+ if (registry && !registry.includes('registry.npmjs.org')) {
83
85
  customRegistry = registry;
84
86
  }
85
87
  }
@@ -0,0 +1,2 @@
1
+ import { type NpmConfigEnv } from './utils';
2
+ export declare function getBunSpawnRegistryEnv(packageName: string, root: string, bunVersion: string | null): NpmConfigEnv;
@@ -0,0 +1,257 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getBunSpawnRegistryEnv = getBunSpawnRegistryEnv;
4
+ const path_1 = require("path");
5
+ const semver_1 = require("semver");
6
+ const bunfig_1 = require("../package-manager-config/bunfig");
7
+ const npmrc_1 = require("../package-manager-config/npmrc");
8
+ const utils_1 = require("./utils");
9
+ /*
10
+ * bun registry resolution (verified on 1.2.23 and 1.3.14, gates bisected):
11
+ *
12
+ * CLI --registry > BUN_CONFIG_REGISTRY > NPM_CONFIG_REGISTRY >
13
+ * npm_config_registry > project .npmrc > global ($XDG_CONFIG_HOME else
14
+ * $HOME)/.npmrc > project bunfig.toml > global bunfig > registry.npmjs.org.
15
+ * .npmrc beats bunfig at every level, including scoped keys. Env registry
16
+ * values must start with http(s):// or they are ignored. .npmrc support
17
+ * exists from bun 1.1.18; [install].ca/cafile from 1.1.31. When
18
+ * XDG_CONFIG_HOME is set, bun reads $XDG_CONFIG_HOME/.npmrc INSTEAD of
19
+ * ~/.npmrc, which npm always reads.
20
+ * See https://github.com/oven-sh/bun/blob/bun-v1.2.23/src/install/PackageManager.zig#L791
21
+ *
22
+ * The final default/scoped registry is always injected: bun does not read
23
+ * npm-only surfaces (e.g. $PREFIX/etc/npmrc), so npm must not fall back to
24
+ * them.
25
+ */
26
+ const BUN_DEFAULT_REGISTRY = 'https://registry.npmjs.org/';
27
+ function getBunSpawnRegistryEnv(packageName, root, bunVersion) {
28
+ const env = {};
29
+ const scope = (0, utils_1.getPackageScope)(packageName);
30
+ const npmrcSupported = !bunVersion || (0, semver_1.gte)(bunVersion, '1.1.18');
31
+ const tlsSupported = !bunVersion || (0, semver_1.gte)(bunVersion, '1.1.31');
32
+ const globalConfigBase = (0, bunfig_1.getBunGlobalConfigBase)(process.env);
33
+ const projectNpmrc = npmrcSupported
34
+ ? readBunNpmrcMap((0, path_1.join)(root, '.npmrc'))
35
+ : null;
36
+ const globalNpmrc = npmrcSupported && globalConfigBase
37
+ ? readBunNpmrcMap((0, path_1.join)(globalConfigBase, '.npmrc'))
38
+ : null;
39
+ const projectBunfig = readBunfigInstall((0, path_1.join)(root, 'bunfig.toml'));
40
+ const globalBunfig = globalConfigBase
41
+ ? readBunfigInstall((0, path_1.join)(globalConfigBase, '.bunfig.toml'))
42
+ : null;
43
+ // Swap npm's userconfig so the auth/TLS keys npm reads natively come from
44
+ // the same file bun would use.
45
+ if (npmrcSupported && process.env.XDG_CONFIG_HOME) {
46
+ env['npm_config_userconfig'] = (0, path_1.join)(process.env.XDG_CONFIG_HOME, '.npmrc');
47
+ }
48
+ const envRegistry = [
49
+ process.env.BUN_CONFIG_REGISTRY,
50
+ process.env.NPM_CONFIG_REGISTRY,
51
+ process.env.npm_config_registry,
52
+ ].find((value) => value && /^https?:\/\//.test(value));
53
+ // An .npmrc registry goes through both of bun's expansions: its ini reader
54
+ // resolves `${VAR}` anywhere in the value, and the scope it then builds
55
+ // resolves a whole-value `$VAR`. Without the second, `registry=$MY_REGISTRY`
56
+ // stays a literal npm rejects as an invalid URL.
57
+ const npmrcRegistryValue = (key) => {
58
+ const raw = projectNpmrc?.get(key) ?? globalNpmrc?.get(key);
59
+ return raw === undefined
60
+ ? undefined
61
+ : expandBunRegistryUrl((0, utils_1.expandEnvVars)(raw));
62
+ };
63
+ const bunfigValue = (read, fallbackUrl) => {
64
+ for (const install of [projectBunfig, globalBunfig]) {
65
+ if (!install) {
66
+ continue;
67
+ }
68
+ const value = read(install);
69
+ if (value !== undefined) {
70
+ return normalizeBunRegistryValue(value, fallbackUrl);
71
+ }
72
+ }
73
+ return undefined;
74
+ };
75
+ const npmrcRegistry = npmrcRegistryValue('registry');
76
+ const defaultPick = envRegistry
77
+ ? { url: envRegistry }
78
+ : npmrcRegistry
79
+ ? { url: npmrcRegistry }
80
+ : (bunfigValue((install) => install.registry, BUN_DEFAULT_REGISTRY) ?? {
81
+ url: BUN_DEFAULT_REGISTRY,
82
+ });
83
+ (0, utils_1.setRegistry)(env, defaultPick.url);
84
+ applyBunAuth(env, defaultPick);
85
+ if (scope) {
86
+ const npmrcScoped = npmrcRegistryValue(`${scope}:registry`);
87
+ // [install.scopes] keys are accepted with or without the leading @.
88
+ const scopedPick = npmrcScoped
89
+ ? { url: npmrcScoped }
90
+ : (bunfigValue((install) => install.scopes?.[scope] ?? install.scopes?.[scope.slice(1)],
91
+ // A scope entry that declares only credentials keeps the default
92
+ // registry as its url, so its token still reaches the right host.
93
+ defaultPick.url) ?? defaultPick);
94
+ (0, utils_1.setScopedRegistry)(env, scope, scopedPick.url);
95
+ if (scopedPick !== defaultPick) {
96
+ applyBunAuth(env, scopedPick);
97
+ }
98
+ }
99
+ if (tlsSupported) {
100
+ // .npmrc TLS keys beat bunfig's; npm reads the npmrc family natively.
101
+ const npmrcHasTls = projectNpmrc?.has('cafile') ||
102
+ projectNpmrc?.has('ca') ||
103
+ globalNpmrc?.has('cafile') ||
104
+ globalNpmrc?.has('ca');
105
+ if (!npmrcHasTls) {
106
+ const cafile = projectBunfig?.cafile ?? globalBunfig?.cafile;
107
+ if (cafile) {
108
+ // bun resolves cafile relative to the project dir.
109
+ (0, utils_1.setCafile)(env, (0, path_1.resolve)(root, cafile));
110
+ }
111
+ else {
112
+ const ca = projectBunfig?.ca ?? globalBunfig?.ca;
113
+ if (ca) {
114
+ // npm reconstructs a config array from the env by splitting the
115
+ // value on a blank line.
116
+ env['npm_config_ca'] = Array.isArray(ca) ? ca.join('\n\n') : ca;
117
+ }
118
+ }
119
+ }
120
+ }
121
+ return env;
122
+ }
123
+ // bun silently resolves as though an .npmrc it cannot read were absent
124
+ // (verified on 1.3.13, EACCES and EISDIR both), so collapse that state the
125
+ // same way rather than warning or aborting.
126
+ function readBunNpmrcMap(path) {
127
+ const map = (0, npmrc_1.readNpmrcMap)(path);
128
+ return map === 'unreadable' ? null : map;
129
+ }
130
+ function normalizeBunRegistryValue(value, fallbackUrl) {
131
+ if (typeof value !== 'string') {
132
+ const result = {
133
+ url: value.url ? expandBunRegistryUrl(value.url) : fallbackUrl,
134
+ };
135
+ for (const field of ['token', 'username', 'password']) {
136
+ const expanded = expandBunAuthValue(value[field]);
137
+ if (expanded !== undefined) {
138
+ result[field] = expanded;
139
+ }
140
+ }
141
+ return result;
142
+ }
143
+ const expanded = expandBunRegistryUrl(value);
144
+ try {
145
+ const url = new URL(expanded);
146
+ if (url.username || url.password) {
147
+ // bun treats a username with no password as no credentials at all.
148
+ const credentials = url.username && url.password
149
+ ? { username: url.username, password: url.password }
150
+ : url.password
151
+ ? // `https://:token@host/` carries a token as the bare password.
152
+ { token: url.password }
153
+ : {};
154
+ url.username = '';
155
+ url.password = '';
156
+ return { url: url.toString(), ...credentials };
157
+ }
158
+ }
159
+ catch { }
160
+ return { url: expanded };
161
+ }
162
+ // bun expands a whole-value `$VARNAME` (no braces) in bunfig credential fields
163
+ // via env.getAuto; an unset var keeps the literal, and `${VAR}` is expanded
164
+ // only in its .npmrc.
165
+ function expandBunAuthValue(value) {
166
+ if (value === undefined || value.length < 2 || value[0] !== '$') {
167
+ return value;
168
+ }
169
+ return process.env[value.slice(1)] ?? value;
170
+ }
171
+ // Bun expands a `$`-prefixed bunfig registry URL (Scope.fromAPI): it looks up
172
+ // the name with surrounding slashes trimmed and uses it only when the result is
173
+ // longer than one character, else keeps the literal.
174
+ function expandBunRegistryUrl(value) {
175
+ if (!value || value[0] !== '$') {
176
+ return value;
177
+ }
178
+ const name = value.slice(1).replace(/^\/+|\/+$/g, '');
179
+ const replaced = process.env[name];
180
+ return replaced && replaced.length > 1 ? replaced : value;
181
+ }
182
+ function applyBunAuth(env, value) {
183
+ if (value.token) {
184
+ (0, utils_1.setAuthToken)(env, value.url, value.token);
185
+ }
186
+ else if (value.username && value.password) {
187
+ const dart = (0, utils_1.requestNerfDart)(value.url);
188
+ if (dart) {
189
+ env[`npm_config_${dart}:username`] = value.username;
190
+ // npm expects _password base64-encoded.
191
+ env[`npm_config_${dart}:_password`] = Buffer.from(value.password).toString('base64');
192
+ }
193
+ }
194
+ }
195
+ function readBunfigInstall(path) {
196
+ const parsed = (0, bunfig_1.readBunfigRaw)(path);
197
+ if (parsed === null || parsed === 'unreadable') {
198
+ return null;
199
+ }
200
+ if (parsed === 'invalid') {
201
+ // The throw reaches the caller's fall-open. Skipping the file instead would
202
+ // pin npm to the default registry as though the workspace configured none,
203
+ // overriding a registry npm resolves from a file of its own.
204
+ throw new Error(`The bunfig at ${path} could not be parsed.`);
205
+ }
206
+ const install = parsed.install;
207
+ if (!install || typeof install !== 'object' || Array.isArray(install)) {
208
+ return null;
209
+ }
210
+ validateBunfigInstall(install, path);
211
+ return install;
212
+ }
213
+ /**
214
+ * bun type-checks the [install] table before it resolves anything and aborts on
215
+ * a value of the wrong shape. Reproduce that rather than carrying a number into
216
+ * a URL parse or a path join, where it would throw somewhere unrelated or
217
+ * bridge a value bun never accepted.
218
+ */
219
+ function validateBunfigInstall(install, path) {
220
+ const fail = (what) => {
221
+ throw new Error(`The bunfig at ${path} declares ${what}.`);
222
+ };
223
+ if (install.registry !== undefined) {
224
+ validateBunRegistryValue(install.registry, 'install.registry', fail);
225
+ }
226
+ if (install.scopes !== undefined) {
227
+ if (typeof install.scopes !== 'object' || Array.isArray(install.scopes)) {
228
+ fail('an install.scopes that is not a table');
229
+ }
230
+ for (const [key, value] of Object.entries(install.scopes)) {
231
+ validateBunRegistryValue(value, `install.scopes["${key}"]`, fail);
232
+ }
233
+ }
234
+ if (install.cafile !== undefined && typeof install.cafile !== 'string') {
235
+ fail('an install.cafile that is not a string');
236
+ }
237
+ if (install.ca !== undefined &&
238
+ typeof install.ca !== 'string' &&
239
+ !(Array.isArray(install.ca) &&
240
+ install.ca.every((entry) => typeof entry === 'string'))) {
241
+ fail('an install.ca that is neither a string nor an array of strings');
242
+ }
243
+ }
244
+ function validateBunRegistryValue(value, setting, fail) {
245
+ if (typeof value === 'string') {
246
+ return;
247
+ }
248
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
249
+ fail(`a ${setting} that is neither a URL string nor a table`);
250
+ }
251
+ for (const field of ['url', 'token', 'username', 'password']) {
252
+ const field_ = value[field];
253
+ if (field_ !== undefined && typeof field_ !== 'string') {
254
+ fail(`a ${setting}.${field} that is not a string`);
255
+ }
256
+ }
257
+ }
@@ -0,0 +1,13 @@
1
+ import { type NpmConfigEnv } from './utils';
2
+ import type { PackageManager } from '../package-manager';
3
+ export type { NpmConfigEnv } from './utils';
4
+ export { getPackageScope, mergeNpmConfigEnv, ignoresNpmConfigEnv, } from './utils';
5
+ /**
6
+ * Computes the npm_config_* environment entries a spawned `npm view`/`npm pack`
7
+ * (or a pre-v11 `pnpm view`, which passes through to npm) needs so its registry,
8
+ * auth and TLS resolution reproduces what the workspace's package manager would
9
+ * do for `packageName`. Returns an empty object when nothing needs bridging (npm
10
+ * workspaces, or config npm already resolves identically on its own) and when
11
+ * resolution fails, which is warned about rather than thrown.
12
+ */
13
+ export declare function getNpmSpawnRegistryEnv(packageName: string, root: string, packageManager: PackageManager, packageManagerVersion: string | null): NpmConfigEnv;
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ignoresNpmConfigEnv = exports.mergeNpmConfigEnv = exports.getPackageScope = void 0;
4
+ exports.getNpmSpawnRegistryEnv = getNpmSpawnRegistryEnv;
5
+ const semver_1 = require("semver");
6
+ const logger_1 = require("../logger");
7
+ const bun_1 = require("./bun");
8
+ const pnpm_1 = require("./pnpm");
9
+ const yarn_berry_1 = require("./yarn-berry");
10
+ const yarn_classic_1 = require("./yarn-classic");
11
+ const utils_1 = require("./utils");
12
+ var utils_2 = require("./utils");
13
+ Object.defineProperty(exports, "getPackageScope", { enumerable: true, get: function () { return utils_2.getPackageScope; } });
14
+ Object.defineProperty(exports, "mergeNpmConfigEnv", { enumerable: true, get: function () { return utils_2.mergeNpmConfigEnv; } });
15
+ Object.defineProperty(exports, "ignoresNpmConfigEnv", { enumerable: true, get: function () { return utils_2.ignoresNpmConfigEnv; } });
16
+ /**
17
+ * Computes the npm_config_* environment entries a spawned `npm view`/`npm pack`
18
+ * (or a pre-v11 `pnpm view`, which passes through to npm) needs so its registry,
19
+ * auth and TLS resolution reproduces what the workspace's package manager would
20
+ * do for `packageName`. Returns an empty object when nothing needs bridging (npm
21
+ * workspaces, or config npm already resolves identically on its own) and when
22
+ * resolution fails, which is warned about rather than thrown.
23
+ */
24
+ function getNpmSpawnRegistryEnv(packageName, root, packageManager, packageManagerVersion) {
25
+ try {
26
+ const env = resolveSpawnRegistryEnv(packageName, root, packageManager, packageManagerVersion);
27
+ reconcileScopedRegistryKey(env, packageName);
28
+ return env;
29
+ }
30
+ catch (e) {
31
+ // The warning omits the cause because an rc parse error quotes the lines
32
+ // around the fault, which in these files is credential material.
33
+ warnUnresolvedConfig(packageManager);
34
+ logger_1.logger.verbose(`Failed to resolve the ${packageManager} registry configuration; falling back to npm's own resolution.`, e);
35
+ return {};
36
+ }
37
+ }
38
+ function resolveSpawnRegistryEnv(packageName, root, packageManager, packageManagerVersion) {
39
+ switch (packageManager) {
40
+ case 'npm':
41
+ // npm resolves its own config; the spawned npm IS the package manager.
42
+ return {};
43
+ case 'pnpm':
44
+ if (!packageManagerVersion) {
45
+ // Which surfaces pnpm honors depends on its version.
46
+ warnUnknownVersion('pnpm', 'a registry configured only in pnpm-workspace.yaml');
47
+ return {};
48
+ }
49
+ return (0, pnpm_1.getPnpmSpawnRegistryEnv)(packageName, root, packageManagerVersion);
50
+ case 'yarn':
51
+ if (!packageManagerVersion) {
52
+ // Without the version we cannot tell classic from berry.
53
+ warnUnknownVersion('yarn', 'a registry configured only in .yarnrc.yml');
54
+ return {};
55
+ }
56
+ return (0, semver_1.major)(packageManagerVersion) >= 2
57
+ ? (0, yarn_berry_1.getYarnBerrySpawnRegistryEnv)(packageName, root, packageManagerVersion)
58
+ : (0, yarn_classic_1.getYarnClassicSpawnRegistryEnv)(packageName, root);
59
+ case 'bun':
60
+ return (0, bun_1.getBunSpawnRegistryEnv)(packageName, root, packageManagerVersion);
61
+ default: {
62
+ // getNpmSpawnRegistryEnv catches this and falls open to no bridging.
63
+ const _exhaustive = packageManager;
64
+ throw new Error(`Unhandled package manager: ${_exhaustive}`);
65
+ }
66
+ }
67
+ }
68
+ // npm's loadEnv lowercases an env key and rewrites its non-leading `_` to `-`,
69
+ // but looks @scope:registry up verbatim, so a bridged override for such a scope
70
+ // is never found. The command targets this package, so redirect the default.
71
+ function reconcileScopedRegistryKey(env, packageName) {
72
+ const scope = (0, utils_1.getPackageScope)(packageName);
73
+ if (!scope) {
74
+ return;
75
+ }
76
+ const scopedRegistry = env[`npm_config_${scope}:registry`];
77
+ if (!scopedRegistry) {
78
+ return;
79
+ }
80
+ const key = `${scope}:registry`;
81
+ if ((0, utils_1.normalizeNpmConfigKey)(key) !== key) {
82
+ (0, utils_1.setRegistry)(env, scopedRegistry);
83
+ }
84
+ }
85
+ const warnedUnresolvedConfigs = new Set();
86
+ // Reached by a failed read and equally by a malformed value the read returned,
87
+ // so the wording stays on resolution rather than naming a file.
88
+ function warnUnresolvedConfig(packageManager) {
89
+ if (warnedUnresolvedConfigs.has(packageManager)) {
90
+ return;
91
+ }
92
+ warnedUnresolvedConfigs.add(packageManager);
93
+ logger_1.logger.warn(`Could not resolve the ${packageManager} configuration; packages will be fetched using npm's own registry resolution, which may differ from ${packageManager}'s. Run with NX_VERBOSE_LOGGING=true for the cause.`);
94
+ }
95
+ const warnedUnknownVersions = new Set();
96
+ function warnUnknownVersion(packageManager, example) {
97
+ if (warnedUnknownVersions.has(packageManager)) {
98
+ return;
99
+ }
100
+ warnedUnknownVersions.add(packageManager);
101
+ logger_1.logger.warn(`Could not determine the ${packageManager} version; skipping ${packageManager} registry configuration when fetching packages. They will be fetched using npm's own registry resolution, which may differ from ${packageManager}'s (for example, ${example}).`);
102
+ }
@@ -0,0 +1,2 @@
1
+ import { type NpmConfigEnv } from './utils';
2
+ export declare function getPnpmSpawnRegistryEnv(packageName: string, root: string, pnpmVersion: string | null): NpmConfigEnv;