nx 23.1.1 → 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.
- package/dist/release/changelog-renderer/index.js +4 -5
- package/dist/release/index.d.ts +1 -1
- package/dist/src/command-line/add/add.js +5 -0
- package/dist/src/command-line/affected/affected.js +1 -0
- package/dist/src/command-line/configure-ai-agents/configure-ai-agents.js +2 -2
- package/dist/src/command-line/import/import.js +1 -2
- package/dist/src/command-line/init/init-v2.js +4 -5
- package/dist/src/command-line/migrate/migrate.d.ts +4 -0
- package/dist/src/command-line/migrate/migrate.js +89 -26
- package/dist/src/command-line/release/changelog.js +5 -0
- package/dist/src/command-line/release/index.d.ts +1 -1
- package/dist/src/command-line/release/utils/git.js +1 -1
- package/dist/src/command-line/release/utils/release-graph.d.ts +17 -0
- package/dist/src/command-line/release/utils/release-graph.js +71 -19
- package/dist/src/command-line/release/utils/remote-release-clients/github.js +6 -0
- package/dist/src/command-line/release/version/release-group-processor.d.ts +24 -0
- package/dist/src/command-line/release/version/release-group-processor.js +80 -6
- package/dist/src/command-line/release/version/version-actions.d.ts +27 -2
- package/dist/src/command-line/release/version/version-actions.js +9 -1
- package/dist/src/command-line/release/version.js +9 -5
- package/dist/src/command-line/reset/reset.js +6 -1
- package/dist/src/command-line/run/run-one.js +1 -0
- package/dist/src/command-line/run-many/run-many.js +1 -0
- package/dist/src/command-line/watch/watch.js +13 -0
- package/dist/src/core/graph/main.js +1 -1
- package/dist/src/core/graph/styles.js +1 -1
- package/dist/src/daemon/client/client.d.ts +52 -1
- package/dist/src/daemon/client/client.js +160 -36
- package/dist/src/daemon/client/daemon-environment.d.ts +17 -0
- package/dist/src/daemon/client/daemon-environment.js +110 -2
- package/dist/src/daemon/client/daemon-socket-messenger.js +4 -0
- package/dist/src/daemon/message-types/daemon-message.d.ts +32 -0
- package/dist/src/daemon/message-types/daemon-message.js +25 -0
- package/dist/src/daemon/server/file-watching/file-watcher-sockets.d.ts +5 -0
- package/dist/src/daemon/server/file-watching/file-watcher-sockets.js +16 -0
- package/dist/src/daemon/server/latest-nx.js +5 -2
- package/dist/src/daemon/server/server.js +24 -0
- package/dist/src/daemon/server/shutdown-utils.d.ts +5 -0
- package/dist/src/daemon/server/shutdown-utils.js +11 -4
- package/dist/src/daemon/socket-utils.d.ts +1 -0
- package/dist/src/daemon/socket-utils.js +24 -3
- package/dist/src/daemon/tmp-dir.d.ts +43 -3
- package/dist/src/daemon/tmp-dir.js +437 -15
- package/dist/src/devkit-internals.d.ts +93 -3
- package/dist/src/devkit-internals.js +192 -5
- package/dist/src/generators/internal-utils/format-changed-files-with-prettier-if-available.d.ts +5 -0
- package/dist/src/generators/internal-utils/format-changed-files-with-prettier-if-available.js +9 -2
- package/dist/src/generators/tree.d.ts +4 -2
- package/dist/src/migrations/update-23-2-0/set-cache-on-executor-target-defaults.d.ts +12 -0
- package/dist/src/migrations/update-23-2-0/set-cache-on-executor-target-defaults.js +250 -0
- package/dist/src/migrations/update-23-2-0/set-cache-on-executor-target-defaults.md +50 -0
- package/dist/src/native/index.d.ts +10 -0
- package/dist/src/native/index.js +71 -28
- package/dist/src/native/native-bindings.js +1 -0
- package/dist/src/native/native-file-cache-location.d.ts +17 -1
- package/dist/src/native/native-file-cache-location.js +86 -12
- package/dist/src/native/nx.wasm32-wasi.debug.wasm +0 -0
- package/dist/src/native/nx.wasm32-wasi.wasm +0 -0
- package/dist/src/nx-cloud/utilities/get-cloud-options.js +5 -2
- package/dist/src/nx-cloud/utilities/onboarding.js +5 -2
- package/dist/src/plugins/js/lock-file/bun-parser.js +43 -10
- package/dist/src/plugins/js/lock-file/pnpm-parser.js +60 -0
- package/dist/src/plugins/js/lock-file/project-graph-pruning.js +14 -8
- package/dist/src/plugins/js/project-graph/affected/npm-packages.js +51 -20
- package/dist/src/plugins/js/project-graph/build-dependencies/target-project-locator.js +2 -0
- package/dist/src/project-graph/affected/affected-project-graph-models.d.ts +1 -1
- package/dist/src/project-graph/affected/affected-project-graph.d.ts +1 -1
- package/dist/src/project-graph/affected/affected-project-graph.js +2 -2
- package/dist/src/project-graph/affected/locators/project-glob-changes.js +5 -2
- package/dist/src/project-graph/error-types.d.ts +12 -1
- package/dist/src/project-graph/error-types.js +27 -2
- package/dist/src/project-graph/plugins/isolation/isolated-plugin.d.ts +1 -0
- package/dist/src/project-graph/plugins/isolation/isolated-plugin.js +18 -1
- package/dist/src/project-graph/plugins/isolation/messaging.d.ts +16 -3
- package/dist/src/project-graph/plugins/isolation/messaging.js +3 -0
- package/dist/src/project-graph/plugins/isolation/plugin-worker.js +58 -8
- package/dist/src/project-graph/project-graph.js +20 -0
- package/dist/src/project-graph/utils/project-configuration/project-nodes-manager.js +5 -1
- package/dist/src/project-graph/utils/project-configuration/target-normalization.js +133 -3
- package/dist/src/tasks-runner/task-env.js +5 -2
- package/dist/src/tasks-runner/utils.js +2 -6
- package/dist/src/utils/assert-workspace-validity.js +7 -2
- package/dist/src/utils/fileutils.d.ts +5 -0
- package/dist/src/utils/fileutils.js +7 -2
- package/dist/src/utils/git-worktrees.d.ts +30 -0
- package/dist/src/utils/git-worktrees.js +212 -0
- package/dist/src/utils/ignore.d.ts +128 -1
- package/dist/src/utils/ignore.js +182 -12
- package/dist/src/utils/long-running-target.d.ts +10 -0
- package/dist/src/utils/long-running-target.js +19 -0
- package/dist/src/utils/min-release-age/behavior/bun.js +7 -11
- package/dist/src/utils/min-release-age/behavior/npm.js +5 -2
- package/dist/src/utils/min-release-age/packument.js +1 -1
- package/dist/src/utils/nx-tmp-dir.d.ts +18 -0
- package/dist/src/utils/nx-tmp-dir.js +40 -0
- package/dist/src/utils/owned-private-dir.d.ts +132 -0
- package/dist/src/utils/owned-private-dir.js +323 -0
- package/dist/src/utils/package-manager-config/bunfig.d.ts +14 -0
- package/dist/src/utils/package-manager-config/bunfig.js +49 -0
- package/dist/src/utils/package-manager-config/npmrc.d.ts +23 -0
- package/dist/src/utils/package-manager-config/npmrc.js +124 -0
- package/dist/src/utils/package-manager-config/pnpm-config.d.ts +17 -0
- package/dist/src/utils/package-manager-config/pnpm-config.js +60 -0
- package/dist/src/utils/package-manager.d.ts +21 -2
- package/dist/src/utils/package-manager.js +244 -47
- package/dist/src/utils/provenance.js +6 -14
- package/dist/src/utils/registry-config/bun.d.ts +2 -0
- package/dist/src/utils/registry-config/bun.js +257 -0
- package/dist/src/utils/registry-config/index.d.ts +13 -0
- package/dist/src/utils/registry-config/index.js +102 -0
- package/dist/src/utils/registry-config/pnpm.d.ts +2 -0
- package/dist/src/utils/registry-config/pnpm.js +1551 -0
- package/dist/src/utils/registry-config/utils.d.ts +195 -0
- package/dist/src/utils/registry-config/utils.js +496 -0
- package/dist/src/utils/registry-config/yarn-berry.d.ts +2 -0
- package/dist/src/utils/registry-config/yarn-berry.js +612 -0
- package/dist/src/utils/registry-config/yarn-classic.d.ts +2 -0
- package/dist/src/utils/registry-config/yarn-classic.js +1001 -0
- package/dist/src/utils/safe-spawn.d.ts +24 -0
- package/dist/src/utils/safe-spawn.js +104 -0
- package/dist/src/utils/shell-quoting.d.ts +15 -0
- package/dist/src/utils/shell-quoting.js +35 -0
- package/dist/src/utils/wait-for-socket-connection.d.ts +11 -0
- package/dist/src/utils/wait-for-socket-connection.js +14 -8
- package/migrations.json +6 -0
- package/package.json +12 -12
- package/dist/src/utils/min-release-age/npmrc.d.ts +0 -15
- package/dist/src/utils/min-release-age/npmrc.js +0 -45
|
@@ -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
|
+
}
|