nx 24.1.0-beta.0 → 24.1.0-beta.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/bin/init-local.js +2 -4
- package/dist/bin/nx-cloud.js +2 -1
- package/dist/bin/nx.js +12 -14
- package/dist/bin/run-executor.js +5 -0
- package/dist/src/adapter/compat.d.ts +1 -1
- package/dist/src/adapter/compat.js +1 -0
- package/dist/src/command-line/completion/scripts/bash.sh +9 -2
- package/dist/src/command-line/completion/scripts/fish.fish +10 -2
- package/dist/src/command-line/completion/scripts/zsh.zsh +8 -2
- package/dist/src/command-line/completion/scripts.js +18 -8
- package/dist/src/command-line/conformance/command-object.d.ts +3 -0
- package/dist/src/command-line/conformance/command-object.js +66 -0
- package/dist/src/command-line/generate/generate.js +2 -4
- package/dist/src/command-line/generate/generator-utils.d.ts +1 -0
- package/dist/src/command-line/generate/generator-utils.js +9 -0
- package/dist/src/command-line/import/import.js +26 -2
- package/dist/src/command-line/import/utils/ai-output.d.ts +9 -1
- package/dist/src/command-line/import/utils/ai-output.js +20 -1
- package/dist/src/command-line/nx-commands.d.ts +1 -1
- package/dist/src/command-line/nx-commands.js +82 -132
- package/dist/src/command-line/release/command-object.d.ts +1 -0
- package/dist/src/command-line/release/command-object.js +4 -0
- package/dist/src/command-line/release/release.js +6 -4
- package/dist/src/command-line/release/utils/repository-git-tags.js +3 -3
- package/dist/src/command-line/release/utils/resolve-nx-json-error-message.js +2 -24
- package/dist/src/command-line/report/report.js +1 -1
- package/dist/src/command-line/reset/reset.js +51 -2
- package/dist/src/config/nx-json.d.ts +117 -0
- package/dist/src/config/workspace-json-project-json.d.ts +6 -7
- package/dist/src/daemon/client/daemon-environment.js +15 -0
- package/dist/src/daemon/server/project-graph-incremental-recomputation.js +13 -20
- package/dist/src/devkit-exports.d.ts +1 -1
- package/dist/src/devkit-internals.d.ts +14 -7
- package/dist/src/devkit-internals.js +29 -4
- package/dist/src/executors/run-commands/run-commands.impl.d.ts +1 -1
- package/dist/src/executors/run-commands/run-commands.impl.js +35 -13
- package/dist/src/generators/utils/glob.js +3 -3
- package/dist/src/hasher/hash-task.d.ts +3 -1
- package/dist/src/hasher/hash-task.js +3 -2
- package/dist/src/migrations/update-24-1-0/replace-powerpack-conformance.d.ts +4 -0
- package/dist/src/migrations/update-24-1-0/replace-powerpack-conformance.js +117 -0
- package/dist/src/migrations/update-24-1-0/replace-powerpack-conformance.md +38 -0
- package/dist/src/native/index.d.ts +6 -8
- package/dist/src/native/index.js +18 -0
- package/dist/src/native/native-bindings.js +1 -0
- package/dist/src/native/nx.wasm32-wasi.debug.wasm +0 -0
- package/dist/src/native/nx.wasm32-wasi.wasm +0 -0
- package/dist/src/native/transform-objects.d.ts +2 -0
- package/dist/src/native/transform-objects.js +15 -0
- package/dist/src/plugins/js/index.js +24 -9
- package/dist/src/plugins/js/lock-file/bun-parser.d.ts +75 -4
- package/dist/src/plugins/js/lock-file/bun-parser.js +976 -142
- package/dist/src/plugins/js/lock-file/lock-file-names.d.ts +6 -0
- package/dist/src/plugins/js/lock-file/lock-file-names.js +16 -0
- package/dist/src/plugins/js/lock-file/lock-file.d.ts +33 -14
- package/dist/src/plugins/js/lock-file/lock-file.js +213 -74
- package/dist/src/plugins/js/lock-file/npm-parser.d.ts +1 -0
- package/dist/src/plugins/js/lock-file/npm-parser.js +66 -2
- package/dist/src/plugins/js/lock-file/pnpm-parser.d.ts +5 -1
- package/dist/src/plugins/js/lock-file/pnpm-parser.js +107 -54
- package/dist/src/plugins/js/lock-file/pruned-output.d.ts +52 -10
- package/dist/src/plugins/js/lock-file/pruned-output.js +132 -66
- package/dist/src/plugins/js/lock-file/utils/local-path-hashes.d.ts +27 -0
- package/dist/src/plugins/js/lock-file/utils/local-path-hashes.js +155 -0
- package/dist/src/plugins/js/lock-file/utils/package-json.d.ts +1 -1
- package/dist/src/plugins/js/lock-file/utils/package-json.js +2 -1
- package/dist/src/plugins/js/package-json/create-package-json.d.ts +1 -0
- package/dist/src/plugins/js/package-json/create-package-json.js +197 -8
- package/dist/src/plugins/js/project-graph/affected/npm-packages.js +50 -2
- package/dist/src/plugins/js/project-graph/build-dependencies/build-dependencies.d.ts +1 -1
- package/dist/src/plugins/js/project-graph/build-dependencies/build-dependencies.js +2 -2
- package/dist/src/plugins/js/project-graph/build-dependencies/explicit-package-json-dependencies.js +16 -9
- package/dist/src/plugins/js/project-graph/build-dependencies/explicit-project-dependencies.js +17 -28
- package/dist/src/plugins/js/project-graph/build-dependencies/target-project-locator.d.ts +52 -1
- package/dist/src/plugins/js/project-graph/build-dependencies/target-project-locator.js +336 -28
- package/dist/src/plugins/js/utils/register.js +13 -6
- package/dist/src/project-graph/build-project-graph.js +5 -2
- package/dist/src/project-graph/error-types.d.ts +2 -2
- package/dist/src/project-graph/error-types.js +2 -2
- package/dist/src/project-graph/nx-deps-cache.d.ts +3 -2
- package/dist/src/project-graph/nx-deps-cache.js +8 -2
- package/dist/src/project-graph/utils/project-graph-paths.d.ts +8 -0
- package/dist/src/project-graph/utils/project-graph-paths.js +170 -0
- package/dist/src/tasks-runner/batch/run-batch.js +3 -13
- package/dist/src/tasks-runner/cache.js +19 -18
- package/dist/src/tasks-runner/init-tasks-runner.js +23 -17
- package/dist/src/tasks-runner/run-command.js +6 -3
- package/dist/src/tasks-runner/task-orchestrator.d.ts +1 -0
- package/dist/src/tasks-runner/task-orchestrator.js +29 -4
- package/dist/src/tasks-runner/tasks-schedule.js +1 -1
- package/dist/src/tasks-runner/utils.d.ts +2 -1
- package/dist/src/tasks-runner/utils.js +2 -1
- package/dist/src/utils/child-process.js +2 -1
- package/dist/src/utils/find-matching-projects.js +7 -9
- package/dist/src/utils/find-workspace-root.js +2 -4
- package/dist/src/utils/git-utils.d.ts +5 -0
- package/dist/src/utils/git-utils.js +23 -1
- package/dist/src/utils/handle-import.js +14 -2
- package/dist/src/utils/installation-directory.d.ts +16 -0
- package/dist/src/utils/installation-directory.js +96 -2
- package/dist/src/utils/json.d.ts +7 -0
- package/dist/src/utils/json.js +32 -0
- package/dist/src/utils/nx-key.js +11 -8
- package/dist/src/utils/output.d.ts +5 -0
- package/dist/src/utils/output.js +11 -4
- package/dist/src/utils/owned-private-dir.d.ts +10 -0
- package/dist/src/utils/owned-private-dir.js +28 -0
- package/dist/src/utils/package-json.d.ts +7 -0
- package/dist/src/utils/package-json.js +9 -0
- package/dist/src/utils/require-nx-key.js +6 -4
- package/dist/src/utils/workspace-root.d.ts +12 -0
- package/dist/src/utils/workspace-root.js +56 -7
- package/migrations.json +6 -0
- package/package.json +15 -12
- package/schemas/nx-schema.json +75 -9
- package/schemas/project-schema.json +5 -0
|
@@ -13,6 +13,8 @@ const nx_deps_cache_1 = require("../../../project-graph/nx-deps-cache");
|
|
|
13
13
|
const path_1 = require("path");
|
|
14
14
|
const task_hasher_1 = require("../../../hasher/task-hasher");
|
|
15
15
|
const output_1 = require("../../../utils/output");
|
|
16
|
+
const package_manager_1 = require("../../../utils/package-manager");
|
|
17
|
+
const path_2 = require("../../../utils/path");
|
|
16
18
|
const project_graph_pruning_1 = require("../lock-file/project-graph-pruning");
|
|
17
19
|
const logger_1 = require("../../../utils/logger");
|
|
18
20
|
/**
|
|
@@ -58,12 +60,23 @@ function createPackageJson(projectName, graph, options = {}, fileMap = null) {
|
|
|
58
60
|
}
|
|
59
61
|
catch (e) { }
|
|
60
62
|
}
|
|
63
|
+
const getInheritedLocalPathSpec = createInheritedLocalPathSpecResolver(projectNode, graph, root, rootPackageJson);
|
|
61
64
|
const getVersion = (packageName, version, section) => {
|
|
62
65
|
// Try project package.json first (single section)
|
|
63
66
|
const projectVersion = (0, package_json_1.getDependencyVersionFromPackageJson)(packageName, root, packageJson, [section]);
|
|
64
67
|
if (projectVersion) {
|
|
65
68
|
return projectVersion;
|
|
66
69
|
}
|
|
70
|
+
// A Bun tarball's graph version is its path, which can parse as semver
|
|
71
|
+
// (`1.0.0-rc.tgz`)
|
|
72
|
+
const recordedVersion = getAliasedVersion(version);
|
|
73
|
+
if ((0, project_graph_pruning_1.isLocalPathSpecifier)(recordedVersion) ||
|
|
74
|
+
(0, package_json_1.isTarballPath)(recordedVersion)) {
|
|
75
|
+
const localPathSpec = getInheritedLocalPathSpec(packageName, version, npmDeps.importingProjects[packageName] ?? projectName);
|
|
76
|
+
if (localPathSpec) {
|
|
77
|
+
return localPathSpec;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
67
80
|
// For libraries, fall back to root package.json (single section)
|
|
68
81
|
if (isLibrary) {
|
|
69
82
|
const rootVersion = (0, package_json_1.getDependencyVersionFromPackageJson)(packageName, root, rootPackageJson, [section]);
|
|
@@ -138,9 +151,12 @@ function createPackageJson(projectName, graph, options = {}, fileMap = null) {
|
|
|
138
151
|
// region Overrides/Resolutions
|
|
139
152
|
// npm
|
|
140
153
|
if (rootPackageJson.overrides && !options.skipOverrides) {
|
|
141
|
-
// npm throws EOVERRIDE when an override
|
|
142
|
-
// (unless specs match). The pruned dist pins
|
|
143
|
-
// resolved everything via the lockfile, so drop
|
|
154
|
+
// npm throws EOVERRIDE when an override sets the version of a package that
|
|
155
|
+
// is also a direct dependency (unless specs match). The pruned dist pins
|
|
156
|
+
// exact versions and already resolved everything via the lockfile, so drop
|
|
157
|
+
// those redundant overrides. An object form without a `.` key sets no
|
|
158
|
+
// version for the package itself, only for its dependencies, so npm
|
|
159
|
+
// accepts it next to a direct dependency and it has to be kept.
|
|
144
160
|
const mergedOverrides = {
|
|
145
161
|
...rootPackageJson.overrides,
|
|
146
162
|
...packageJson.overrides,
|
|
@@ -148,13 +164,16 @@ function createPackageJson(projectName, graph, options = {}, fileMap = null) {
|
|
|
148
164
|
const overrides = {};
|
|
149
165
|
let hasOverrides = false;
|
|
150
166
|
for (const name in mergedOverrides) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
packageJson.
|
|
167
|
+
const override = mergedOverrides[name];
|
|
168
|
+
const constrainsDependenciesOnly = typeof override === 'object' && override !== null && !('.' in override);
|
|
169
|
+
if (!constrainsDependenciesOnly &&
|
|
170
|
+
(packageJson.dependencies?.[name] ||
|
|
171
|
+
packageJson.devDependencies?.[name] ||
|
|
172
|
+
packageJson.peerDependencies?.[name] ||
|
|
173
|
+
packageJson.optionalDependencies?.[name])) {
|
|
155
174
|
continue;
|
|
156
175
|
}
|
|
157
|
-
overrides[name] =
|
|
176
|
+
overrides[name] = override;
|
|
158
177
|
hasOverrides = true;
|
|
159
178
|
}
|
|
160
179
|
if (hasOverrides) {
|
|
@@ -212,6 +231,173 @@ function createPackageJson(projectName, graph, options = {}, fileMap = null) {
|
|
|
212
231
|
// endregion Overrides/Resolutions
|
|
213
232
|
return packageJson;
|
|
214
233
|
}
|
|
234
|
+
const LOCAL_PATH_SPEC_SECTIONS = [
|
|
235
|
+
'dependencies',
|
|
236
|
+
'optionalDependencies',
|
|
237
|
+
'devDependencies',
|
|
238
|
+
'peerDependencies',
|
|
239
|
+
];
|
|
240
|
+
/**
|
|
241
|
+
* A local-path spec for a dependency the project inherits, rebased from its
|
|
242
|
+
* declarer to the project root, where the pnpm and Bun deploy outputs relocate
|
|
243
|
+
* local-path specs from. Declarers are searched in the order the import
|
|
244
|
+
* resolves: for pnpm from the importing project through the projects enclosing
|
|
245
|
+
* it to the root, and for Bun from the root, whose copy of a tarball Bun
|
|
246
|
+
* installs for every workspace declaring the same spec. A declarer counts only
|
|
247
|
+
* when its spec resolves to the path the graph version records. Nx's pnpm graph
|
|
248
|
+
* takes a shared `link:` node's version from the first importer, so a `link:`
|
|
249
|
+
* on the chain also counts when its node_modules links that target.
|
|
250
|
+
*/
|
|
251
|
+
function createInheritedLocalPathSpecResolver(projectNode, graph, root, rootPackageJson) {
|
|
252
|
+
const rootDeclarer = {
|
|
253
|
+
root: '',
|
|
254
|
+
manifest: rootPackageJson,
|
|
255
|
+
};
|
|
256
|
+
const projectDeclarers = new Map();
|
|
257
|
+
const getProjectDeclarer = (projectName) => {
|
|
258
|
+
if (!projectDeclarers.has(projectName)) {
|
|
259
|
+
projectDeclarers.set(projectName, readLocalPathSpecDeclarer(graph.nodes[projectName], root));
|
|
260
|
+
}
|
|
261
|
+
return projectDeclarers.get(projectName);
|
|
262
|
+
};
|
|
263
|
+
const declarersByImporter = new Map();
|
|
264
|
+
let lookup;
|
|
265
|
+
return (packageName, version, importingProject) => {
|
|
266
|
+
if (lookup === undefined) {
|
|
267
|
+
const packageManager = (0, package_manager_1.detectPackageManager)(root);
|
|
268
|
+
lookup =
|
|
269
|
+
packageManager === 'pnpm' || packageManager === 'bun'
|
|
270
|
+
? {
|
|
271
|
+
packageManager,
|
|
272
|
+
reachableProjects: getReachableProjects(projectNode, graph),
|
|
273
|
+
}
|
|
274
|
+
: null;
|
|
275
|
+
}
|
|
276
|
+
if (lookup === null) {
|
|
277
|
+
return undefined;
|
|
278
|
+
}
|
|
279
|
+
if (!declarersByImporter.has(importingProject)) {
|
|
280
|
+
const chain = getImportResolutionChain(graph, importingProject);
|
|
281
|
+
const others = lookup.reachableProjects.filter((projectName) => !chain.includes(projectName));
|
|
282
|
+
const chainDeclarers = chain.map(getProjectDeclarer).filter(Boolean);
|
|
283
|
+
const otherDeclarers = others.map(getProjectDeclarer).filter(Boolean);
|
|
284
|
+
declarersByImporter.set(importingProject, {
|
|
285
|
+
ordered: lookup.packageManager === 'bun'
|
|
286
|
+
? [rootDeclarer, ...chainDeclarers, ...otherDeclarers]
|
|
287
|
+
: [...chainDeclarers, rootDeclarer, ...otherDeclarers],
|
|
288
|
+
onChain: new Set(chainDeclarers),
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
const { ordered, onChain } = declarersByImporter.get(importingProject);
|
|
292
|
+
const isPnpmLink = lookup.packageManager === 'pnpm' && version.startsWith('link:');
|
|
293
|
+
for (const declarer of ordered) {
|
|
294
|
+
// The helper detects the package manager on every call, and most
|
|
295
|
+
// manifests don't list the package
|
|
296
|
+
if (!LOCAL_PATH_SPEC_SECTIONS.some((section) => declarer.manifest[section]?.[packageName])) {
|
|
297
|
+
continue;
|
|
298
|
+
}
|
|
299
|
+
const spec = (0, package_json_1.getDependencyVersionFromPackageJson)(packageName, root, declarer.manifest, LOCAL_PATH_SPEC_SECTIONS);
|
|
300
|
+
if (!spec || !(0, project_graph_pruning_1.isLocalPathSpecifier)(spec)) {
|
|
301
|
+
continue;
|
|
302
|
+
}
|
|
303
|
+
const protocol = spec.startsWith('link:') ? 'link:' : 'file:';
|
|
304
|
+
const path = (0, path_2.normalizePath)(spec.slice(protocol.length));
|
|
305
|
+
const target = withoutTrailingSlash((0, path_1.isAbsolute)(path) ? path : path_1.posix.join(declarer.root, path));
|
|
306
|
+
const isChainLink = isPnpmLink &&
|
|
307
|
+
protocol === 'link:' &&
|
|
308
|
+
onChain.has(declarer) &&
|
|
309
|
+
isInstalledLinkTarget(root, declarer.root, packageName, target);
|
|
310
|
+
if (!isChainLink &&
|
|
311
|
+
getRecordedLocalPath(version, protocol, declarer.root, lookup.packageManager) !== target) {
|
|
312
|
+
continue;
|
|
313
|
+
}
|
|
314
|
+
if ((0, path_1.isAbsolute)(path)) {
|
|
315
|
+
return spec;
|
|
316
|
+
}
|
|
317
|
+
return `${protocol}${path_1.posix.relative(projectNode.data.root, target)}`;
|
|
318
|
+
}
|
|
319
|
+
return undefined;
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* The path a graph version names, read the way the lockfile records a
|
|
324
|
+
* `protocol` spec of the manifest at `declarerRoot`. pnpm records a `file:`
|
|
325
|
+
* path from the workspace root and a `link:` path from the importer. Bun
|
|
326
|
+
* records directories and `link:` paths from the workspace root, and a tarball
|
|
327
|
+
* from its declarer without the `file:` protocol. Both record a dependency
|
|
328
|
+
* named differently from its package as an `npm:<package>@<version>` alias.
|
|
329
|
+
*/
|
|
330
|
+
function getRecordedLocalPath(graphVersion, protocol, declarerRoot, packageManager) {
|
|
331
|
+
const version = getAliasedVersion(graphVersion);
|
|
332
|
+
const isBunTarball = packageManager === 'bun' &&
|
|
333
|
+
protocol === 'file:' &&
|
|
334
|
+
!(0, project_graph_pruning_1.isLocalPathSpecifier)(version);
|
|
335
|
+
if (!isBunTarball && !version.startsWith(protocol)) {
|
|
336
|
+
return undefined;
|
|
337
|
+
}
|
|
338
|
+
const path = (0, path_2.normalizePath)(isBunTarball ? version : version.slice(protocol.length));
|
|
339
|
+
if ((0, path_1.isAbsolute)(path)) {
|
|
340
|
+
return withoutTrailingSlash(path);
|
|
341
|
+
}
|
|
342
|
+
const isDeclarerRelative = isBunTarball || (protocol === 'link:' && packageManager === 'pnpm');
|
|
343
|
+
return withoutTrailingSlash(path_1.posix.join(isDeclarerRelative ? declarerRoot : '', path));
|
|
344
|
+
}
|
|
345
|
+
// An override can make pnpm link a target other than the declared one
|
|
346
|
+
function isInstalledLinkTarget(root, declarerRoot, packageName, target) {
|
|
347
|
+
try {
|
|
348
|
+
return ((0, fs_1.realpathSync)((0, path_1.join)(root, declarerRoot, 'node_modules', packageName)) ===
|
|
349
|
+
(0, fs_1.realpathSync)((0, path_1.isAbsolute)(target) ? target : (0, path_1.join)(root, target)));
|
|
350
|
+
}
|
|
351
|
+
catch {
|
|
352
|
+
return false;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
// The search starts past the package name's first character, the `@` of a
|
|
356
|
+
// scoped name, so an `@` in the version's path stays in the version
|
|
357
|
+
function getAliasedVersion(version) {
|
|
358
|
+
if (!version.startsWith('npm:')) {
|
|
359
|
+
return version;
|
|
360
|
+
}
|
|
361
|
+
const separator = version.indexOf('@', 'npm:'.length + 1);
|
|
362
|
+
return separator === -1 ? version : version.slice(separator + 1);
|
|
363
|
+
}
|
|
364
|
+
// posix.join keeps a trailing slash, so `dir/` and `dir` would differ
|
|
365
|
+
function withoutTrailingSlash(path) {
|
|
366
|
+
return path.replace(/(?<=.)\/$/, '');
|
|
367
|
+
}
|
|
368
|
+
function readLocalPathSpecDeclarer(project, root) {
|
|
369
|
+
const manifestPath = (0, path_1.join)(root, project.data.root, 'package.json');
|
|
370
|
+
if (!(0, fs_1.existsSync)(manifestPath)) {
|
|
371
|
+
return null;
|
|
372
|
+
}
|
|
373
|
+
try {
|
|
374
|
+
return { root: project.data.root, manifest: (0, fileutils_1.readJsonFile)(manifestPath) };
|
|
375
|
+
}
|
|
376
|
+
catch {
|
|
377
|
+
return null;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
function getImportResolutionChain(graph, projectName) {
|
|
381
|
+
const projectRoot = graph.nodes[projectName].data.root;
|
|
382
|
+
const enclosing = Object.values(graph.nodes)
|
|
383
|
+
.filter(({ data }) => projectRoot.startsWith(`${data.root}/`))
|
|
384
|
+
.sort((a, b) => b.data.root.length - a.data.root.length)
|
|
385
|
+
.map(({ name }) => name);
|
|
386
|
+
return [projectName, ...enclosing];
|
|
387
|
+
}
|
|
388
|
+
function getReachableProjects(projectNode, graph) {
|
|
389
|
+
const reachable = [projectNode.name];
|
|
390
|
+
const seen = new Set(reachable);
|
|
391
|
+
for (let i = 0; i < reachable.length; i++) {
|
|
392
|
+
for (const { target } of graph.dependencies[reachable[i]] ?? []) {
|
|
393
|
+
if (graph.nodes[target] && !seen.has(target)) {
|
|
394
|
+
seen.add(target);
|
|
395
|
+
reachable.push(target);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
return reachable;
|
|
400
|
+
}
|
|
215
401
|
function findProjectsNpmDependencies(projectNode, graph, target, rootPackageJson, options, fileMap, root = workspace_root_1.workspaceRoot) {
|
|
216
402
|
if (fileMap == null) {
|
|
217
403
|
fileMap = (0, nx_deps_cache_1.readFileMapCache)()?.fileMap?.projectFileMap || {};
|
|
@@ -223,6 +409,7 @@ function findProjectsNpmDependencies(projectNode, graph, target, rootPackageJson
|
|
|
223
409
|
dependencies: {},
|
|
224
410
|
peerDependencies: {},
|
|
225
411
|
peerDependenciesMeta: {},
|
|
412
|
+
importingProjects: {},
|
|
226
413
|
};
|
|
227
414
|
const seen = new Set();
|
|
228
415
|
options.helperDependencies?.forEach((dep) => {
|
|
@@ -260,6 +447,7 @@ function findAllNpmDeps(projectFileMap, projectNode, graph, npmDeps, seen, root,
|
|
|
260
447
|
// since this is a direct dependency of the project
|
|
261
448
|
if (node && npmDeps.peerDependencies[node.data.packageName]) {
|
|
262
449
|
npmDeps.dependencies[node.data.packageName] = node.data.version;
|
|
450
|
+
npmDeps.importingProjects[node.data.packageName] = projectNode.name;
|
|
263
451
|
delete npmDeps.peerDependencies[node.data.packageName];
|
|
264
452
|
}
|
|
265
453
|
}
|
|
@@ -272,6 +460,7 @@ function findAllNpmDeps(projectFileMap, projectNode, graph, npmDeps, seen, root,
|
|
|
272
460
|
continue;
|
|
273
461
|
}
|
|
274
462
|
npmDeps.dependencies[node.data.packageName] = node.data.version;
|
|
463
|
+
npmDeps.importingProjects[node.data.packageName] = projectNode.name;
|
|
275
464
|
recursivelyCollectPeerDependencies(node.name, graph, npmDeps, seen, root);
|
|
276
465
|
}
|
|
277
466
|
else if (graph.nodes[dep]) {
|
|
@@ -25,18 +25,62 @@ function packageJsonDependencyChanges(touchedFiles, nxJson, projectGraph) {
|
|
|
25
25
|
projects: touched.filter((name) => name in projectGraph.nodes),
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
|
+
const PNPM_WORKSPACE_FILES = ['pnpm-workspace.yaml', 'pnpm-workspace.yml'];
|
|
28
29
|
/**
|
|
29
30
|
* External nodes and workspace projects the root package.json change names,
|
|
30
31
|
* or null when it cannot be pinned to them: a removed dependency, a global
|
|
31
32
|
* package, or an override selector matching nothing in the graph.
|
|
33
|
+
*
|
|
34
|
+
* Also reads `overrides` from `pnpm-workspace.yaml` (pnpm 10+): the field
|
|
35
|
+
* moves there when the root `package.json` has no `pnpm` block, and pnpm 12
|
|
36
|
+
* no longer reads `package.json#pnpm` at all. Yaml override diffs are rewritten
|
|
37
|
+
* to the `pnpm.overrides.*` path and matched by the existing pnpm selector
|
|
38
|
+
* logic. Catalog and other workspace settings are left alone.
|
|
32
39
|
*/
|
|
33
40
|
function touchedNpmPackages(touchedFiles, nxJson, projectGraph) {
|
|
34
41
|
const packageJsonChange = touchedFiles.find((f) => f.file === 'package.json');
|
|
35
|
-
|
|
42
|
+
const workspaceYamlChange = touchedFiles.find((f) => PNPM_WORKSPACE_FILES.includes(f.file));
|
|
43
|
+
if (!packageJsonChange && !workspaceYamlChange)
|
|
36
44
|
return [];
|
|
37
45
|
const globalPackages = new Set(getGlobalPackages(nxJson.plugins));
|
|
38
46
|
let touched = [];
|
|
39
|
-
const changes = packageJsonChange
|
|
47
|
+
const changes = packageJsonChange
|
|
48
|
+
? [...packageJsonChange.getChanges()]
|
|
49
|
+
: [];
|
|
50
|
+
if (workspaceYamlChange) {
|
|
51
|
+
for (const c of workspaceYamlChange.getChanges()) {
|
|
52
|
+
// Unparseable yaml - be conservative and fall back to all projects.
|
|
53
|
+
if (!(0, json_diff_1.isJsonChange)(c))
|
|
54
|
+
return null;
|
|
55
|
+
// Catalog, patchedDependencies, settings, etc. do not change which
|
|
56
|
+
// packages the lockfile resolves to.
|
|
57
|
+
if (c.path[0] !== 'overrides')
|
|
58
|
+
continue;
|
|
59
|
+
// Replacing the whole `overrides` map with something non-mappy
|
|
60
|
+
// (null, scalar, array) is a shape we don't understand - fall back.
|
|
61
|
+
if (c.path.length === 1) {
|
|
62
|
+
if (!isObjectOrUndefined(c.value.lhs))
|
|
63
|
+
return null;
|
|
64
|
+
if (!isObjectOrUndefined(c.value.rhs))
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
// pnpm's workspace overrides take string selectors as keys and
|
|
69
|
+
// string versions as leaves; a non-string leaf is a shape we
|
|
70
|
+
// don't model.
|
|
71
|
+
if (c.value.lhs !== undefined && typeof c.value.lhs !== 'string') {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
if (c.value.rhs !== undefined && typeof c.value.rhs !== 'string') {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
changes.push({
|
|
79
|
+
...c,
|
|
80
|
+
path: ['pnpm', 'overrides', ...c.path.slice(1)],
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
40
84
|
const npmPackages = Object.values(projectGraph.externalNodes);
|
|
41
85
|
let packagesByName;
|
|
42
86
|
const missingTouchedNpmPackages = [];
|
|
@@ -143,3 +187,7 @@ function getGlobalPackages(plugins) {
|
|
|
143
187
|
.map((p) => (0, get_package_name_from_import_path_1.getPackageNameFromImportPath)(typeof p === 'string' ? p : p.plugin))
|
|
144
188
|
.concat('nx');
|
|
145
189
|
}
|
|
190
|
+
function isObjectOrUndefined(value) {
|
|
191
|
+
return (value === undefined ||
|
|
192
|
+
(value !== null && typeof value === 'object' && !Array.isArray(value)));
|
|
193
|
+
}
|
|
@@ -3,4 +3,4 @@ import { RawProjectGraphDependency } from '../../../../project-graph/project-gra
|
|
|
3
3
|
export declare function buildExplicitDependencies(jsPluginConfig: {
|
|
4
4
|
analyzeSourceFiles?: boolean;
|
|
5
5
|
analyzePackageJson?: boolean;
|
|
6
|
-
}, ctx: CreateDependenciesContext): RawProjectGraphDependency[];
|
|
6
|
+
}, ctx: CreateDependenciesContext, installedLocalPathNodes?: Record<string, Record<string, string>>): RawProjectGraphDependency[];
|
|
@@ -5,7 +5,7 @@ const installation_directory_1 = require("../../../../utils/installation-directo
|
|
|
5
5
|
const explicit_package_json_dependencies_1 = require("./explicit-package-json-dependencies");
|
|
6
6
|
const explicit_project_dependencies_1 = require("./explicit-project-dependencies");
|
|
7
7
|
const target_project_locator_1 = require("./target-project-locator");
|
|
8
|
-
function buildExplicitDependencies(jsPluginConfig, ctx) {
|
|
8
|
+
function buildExplicitDependencies(jsPluginConfig, ctx, installedLocalPathNodes) {
|
|
9
9
|
if (totalNumberOfFilesToProcess(ctx) === 0)
|
|
10
10
|
return [];
|
|
11
11
|
let dependencies = [];
|
|
@@ -20,7 +20,7 @@ function buildExplicitDependencies(jsPluginConfig, ctx) {
|
|
|
20
20
|
data: ctx.projects[key],
|
|
21
21
|
};
|
|
22
22
|
});
|
|
23
|
-
const targetProjectLocator = new target_project_locator_1.TargetProjectLocator(nodes, ctx.externalNodes);
|
|
23
|
+
const targetProjectLocator = new target_project_locator_1.TargetProjectLocator(nodes, ctx.externalNodes, undefined, undefined, installedLocalPathNodes);
|
|
24
24
|
if (jsPluginConfig.analyzeSourceFiles === undefined ||
|
|
25
25
|
jsPluginConfig.analyzeSourceFiles === true) {
|
|
26
26
|
let tsExists = false;
|
package/dist/src/plugins/js/project-graph/build-dependencies/explicit-package-json-dependencies.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.buildExplicitPackageJsonDependencies = buildExplicitPackageJsonDependencies;
|
|
4
|
+
const posix_1 = require("node:path/posix");
|
|
4
5
|
const project_graph_1 = require("../../../../config/project-graph");
|
|
5
6
|
const file_utils_1 = require("../../../../project-graph/file-utils");
|
|
6
7
|
const project_graph_builder_1 = require("../../../../project-graph/project-graph-builder");
|
|
@@ -47,18 +48,24 @@ function processPackageJson(sourceProject, packageJsonPath, ctx, targetProjectLo
|
|
|
47
48
|
collectedDeps.push(dependency);
|
|
48
49
|
return;
|
|
49
50
|
}
|
|
50
|
-
const externalNodeName = targetProjectLocator.
|
|
51
|
+
const externalNodeName = targetProjectLocator.findInstalledLocalPathNpmProject(packageName, (0, posix_1.dirname)(packageJsonPath)) ??
|
|
52
|
+
targetProjectLocator.findNpmProjectFromImport(packageName, packageJsonPath);
|
|
51
53
|
if (!externalNodeName) {
|
|
52
54
|
return;
|
|
53
55
|
}
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
56
|
+
const linkedProject = targetProjectLocator.findLinkedProject(externalNodeName, packageName, packageJsonPath);
|
|
57
|
+
for (const target of linkedProject
|
|
58
|
+
? [linkedProject, externalNodeName]
|
|
59
|
+
: [externalNodeName]) {
|
|
60
|
+
const dependency = {
|
|
61
|
+
source: sourceProject,
|
|
62
|
+
target,
|
|
63
|
+
sourceFile: packageJsonPath,
|
|
64
|
+
type: project_graph_1.DependencyType.static,
|
|
65
|
+
};
|
|
66
|
+
(0, project_graph_builder_1.validateDependency)(dependency, ctx);
|
|
67
|
+
collectedDeps.push(dependency);
|
|
68
|
+
}
|
|
62
69
|
});
|
|
63
70
|
}
|
|
64
71
|
catch (e) {
|
package/dist/src/plugins/js/project-graph/build-dependencies/explicit-project-dependencies.js
CHANGED
|
@@ -9,17 +9,10 @@ const workspace_root_1 = require("../../../../utils/workspace-root");
|
|
|
9
9
|
function isRoot(projects, projectName) {
|
|
10
10
|
return projects[projectName]?.root === '.';
|
|
11
11
|
}
|
|
12
|
-
function
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
return {
|
|
18
|
-
source,
|
|
19
|
-
target,
|
|
20
|
-
sourceFile,
|
|
21
|
-
type,
|
|
22
|
-
};
|
|
12
|
+
function convertImportToDependencies(importExpr, sourceFile, source, type, targetProjectLocator) {
|
|
13
|
+
return targetProjectLocator
|
|
14
|
+
.findDependencyTargetsFromImport(importExpr, sourceFile)
|
|
15
|
+
.map((target) => ({ source, target, sourceFile, type }));
|
|
23
16
|
}
|
|
24
17
|
function buildExplicitTypeScriptDependencies(ctx, targetProjectLocator) {
|
|
25
18
|
const res = [];
|
|
@@ -48,26 +41,22 @@ function buildExplicitTypeScriptDependencies(ctx, targetProjectLocator) {
|
|
|
48
41
|
for (const { sourceProject, file, staticImportExpressions, dynamicImportExpressions, } of imports) {
|
|
49
42
|
const normalizedFilePath = (0, path_2.normalizePath)((0, path_1.relative)(workspace_root_1.workspaceRoot, file));
|
|
50
43
|
for (const importExpr of staticImportExpressions) {
|
|
51
|
-
const dependency
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
!isRoot(ctx.projects, dependency.target)) {
|
|
58
|
-
res.push(dependency);
|
|
44
|
+
for (const dependency of convertImportToDependencies(importExpr, normalizedFilePath, sourceProject, project_graph_1.DependencyType.static, targetProjectLocator)) {
|
|
45
|
+
// TODO: These edges technically should be allowed but we need to figure out how to separate config files out from root
|
|
46
|
+
if (isRoot(ctx.projects, dependency.source) ||
|
|
47
|
+
!isRoot(ctx.projects, dependency.target)) {
|
|
48
|
+
res.push(dependency);
|
|
49
|
+
}
|
|
59
50
|
}
|
|
60
51
|
}
|
|
61
52
|
for (const importExpr of dynamicImportExpressions) {
|
|
62
|
-
const dependency
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
(0, project_graph_builder_1.validateDependency)(dependency, ctx);
|
|
70
|
-
res.push(dependency);
|
|
53
|
+
for (const dependency of convertImportToDependencies(importExpr, normalizedFilePath, sourceProject, project_graph_1.DependencyType.dynamic, targetProjectLocator)) {
|
|
54
|
+
// TODO: These edges technically should be allowed but we need to figure out how to separate config files out from root
|
|
55
|
+
if (isRoot(ctx.projects, dependency.source) ||
|
|
56
|
+
!isRoot(ctx.projects, dependency.target)) {
|
|
57
|
+
(0, project_graph_builder_1.validateDependency)(dependency, ctx);
|
|
58
|
+
res.push(dependency);
|
|
59
|
+
}
|
|
71
60
|
}
|
|
72
61
|
}
|
|
73
62
|
}
|
|
@@ -18,14 +18,19 @@ export declare class TargetProjectLocator {
|
|
|
18
18
|
private readonly externalNodes;
|
|
19
19
|
private readonly npmResolutionCache;
|
|
20
20
|
private readonly packageJsonResolutionCache;
|
|
21
|
+
private readonly installedLocalPathNodes;
|
|
21
22
|
private projectRootMappings;
|
|
22
23
|
private npmProjects;
|
|
24
|
+
private packageNamesWithSeveralNodes;
|
|
25
|
+
private packageNamesWithLocalPathNodes;
|
|
26
|
+
private localPathNpmResolutionCache;
|
|
23
27
|
private tsConfig;
|
|
24
28
|
private paths;
|
|
25
29
|
private parsedPathPatterns;
|
|
26
30
|
private typescriptResolutionCache;
|
|
31
|
+
private linkedProjectCache;
|
|
27
32
|
private packagesMetadata;
|
|
28
|
-
constructor(nodes: Record<string, ProjectGraphProjectNode>, externalNodes?: Record<string, ProjectGraphExternalNode>, npmResolutionCache?: NpmResolutionCache, packageJsonResolutionCache?: PackageJsonResolutionCache);
|
|
33
|
+
constructor(nodes: Record<string, ProjectGraphProjectNode>, externalNodes?: Record<string, ProjectGraphExternalNode>, npmResolutionCache?: NpmResolutionCache, packageJsonResolutionCache?: PackageJsonResolutionCache, installedLocalPathNodes?: Record<string, Record<string, string>>);
|
|
29
34
|
/**
|
|
30
35
|
* Resolve any workspace or external project that matches the given import expression,
|
|
31
36
|
* originating from the given filePath.
|
|
@@ -34,6 +39,13 @@ export declare class TargetProjectLocator {
|
|
|
34
39
|
* @param filePath
|
|
35
40
|
*/
|
|
36
41
|
findProjectFromImport(importExpr: string, filePath: string): string;
|
|
42
|
+
/**
|
|
43
|
+
* The targets of an import's dependencies: the one `findProjectFromImport`
|
|
44
|
+
* returns, plus the external node of the `link:` package that resolved the
|
|
45
|
+
* import to that project.
|
|
46
|
+
*/
|
|
47
|
+
findDependencyTargetsFromImport(importExpr: string, filePath: string): string[];
|
|
48
|
+
private resolveImportTarget;
|
|
37
49
|
/**
|
|
38
50
|
* Resolve any external project that matches the given import expression,
|
|
39
51
|
* relative to the given file path.
|
|
@@ -42,6 +54,40 @@ export declare class TargetProjectLocator {
|
|
|
42
54
|
* @param projectRoot
|
|
43
55
|
*/
|
|
44
56
|
findNpmProjectFromImport(importExpr: string, fromFilePath: string): string | null;
|
|
57
|
+
/**
|
|
58
|
+
* The external node of the local package that the importer at
|
|
59
|
+
* `importerRoot` installs for `packageName`, as the lockfile records it. An
|
|
60
|
+
* override can replace the copy a `file:` or `link:` spec names, so the spec
|
|
61
|
+
* alone does not tell.
|
|
62
|
+
*
|
|
63
|
+
* @param importerRoot the importer's workspace-relative root, '.' for the
|
|
64
|
+
* workspace root
|
|
65
|
+
*/
|
|
66
|
+
findInstalledLocalPathNpmProject(packageName: string, importerRoot: string): string | null;
|
|
67
|
+
/**
|
|
68
|
+
* The external node of the local package behind the copy an import resolves
|
|
69
|
+
* to: the record of the nearest importer up to the workspace root, unless a
|
|
70
|
+
* directory on the way has its own copy, which the import loads instead.
|
|
71
|
+
*/
|
|
72
|
+
private findInstalledLocalPathNpmProjectFromDir;
|
|
73
|
+
/**
|
|
74
|
+
* The node an unreadable import gets once its package can be read: the
|
|
75
|
+
* record of the nearest importer up to the directory that installs the
|
|
76
|
+
* package. Null when no directory installs it.
|
|
77
|
+
*/
|
|
78
|
+
private findUnreadableLocalPathNpmProjectFromDir;
|
|
79
|
+
/**
|
|
80
|
+
* The project that holds the target of the importer's installed `link:`
|
|
81
|
+
* package.
|
|
82
|
+
* pnpm and Bun give such a link an external node, which would otherwise
|
|
83
|
+
* shadow the project. Importers can share that node with different targets,
|
|
84
|
+
* so the link the importer installs decides.
|
|
85
|
+
*/
|
|
86
|
+
findLinkedProject(externalNodeName: string, importExpr: string, fromFilePath: string): string | null;
|
|
87
|
+
private findLinkedProjectFromDir;
|
|
88
|
+
private findProjectHoldingLinkTarget;
|
|
89
|
+
private getNpmResolutionCache;
|
|
90
|
+
private hasSeveralNodes;
|
|
45
91
|
/**
|
|
46
92
|
* Return file paths matching the import relative to the repo root
|
|
47
93
|
* @param normalizedImportExpr
|
|
@@ -75,7 +121,12 @@ export declare class TargetProjectLocator {
|
|
|
75
121
|
* In some cases, such as when multiple module formats are published, the resolved package.json
|
|
76
122
|
* might only contain the "type" field - no "name" or "version", so in such cases we keep traversing
|
|
77
123
|
* until we find a package.json that contains the "name" and "version" fields.
|
|
124
|
+
*
|
|
125
|
+
* A nested manifest whose name is a subpath of the requested package (for example
|
|
126
|
+
* `@stencil/core/internal`) is not that package. Prefer `node_modules/<name>/package.json`
|
|
127
|
+
* — aliases keep that file's own name — and skip subpath manifests while walking up.
|
|
78
128
|
*/
|
|
79
129
|
private readPackageJson;
|
|
130
|
+
private readCompletePackageJson;
|
|
80
131
|
}
|
|
81
132
|
export {};
|