nx 23.2.0-beta.2 → 23.2.0-beta.3
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/nx.js +1 -0
- package/dist/src/analytics/analytics.js +9 -7
- package/dist/src/command-line/graph/graph.d.ts +1 -0
- package/dist/src/command-line/graph/graph.js +15 -6
- package/dist/src/command-line/migrate/migrate.js +16 -1
- package/dist/src/command-line/nx-cloud/connect/connect-to-nx-cloud.js +1 -1
- package/dist/src/command-line/release/utils/remote-release-clients/github.js +1 -1
- package/dist/src/command-line/release/utils/remote-release-clients/gitlab.js +1 -1
- package/dist/src/config/nx-json.d.ts +4 -2
- package/dist/src/core/graph/main.js +1 -1
- package/dist/src/native/index.d.ts +2 -2
- package/dist/src/native/nx.wasm32-wasi.debug.wasm +0 -0
- package/dist/src/native/nx.wasm32-wasi.wasm +0 -0
- package/dist/src/plugins/js/project-graph/build-dependencies/target-project-locator.js +12 -4
- package/dist/src/project-graph/utils/project-configuration/name-substitution-manager.d.ts +1 -0
- package/dist/src/project-graph/utils/project-configuration/name-substitution-manager.js +16 -2
- package/dist/src/project-graph/utils/project-configuration/project-nodes-manager.d.ts +5 -8
- package/dist/src/project-graph/utils/project-configuration/project-nodes-manager.js +11 -14
- package/dist/src/project-graph/utils/project-configuration/source-maps.d.ts +12 -5
- package/dist/src/project-graph/utils/project-configuration/source-maps.js +21 -7
- package/dist/src/project-graph/utils/project-configuration/target-defaults.d.ts +1 -1
- package/dist/src/project-graph/utils/project-configuration/target-defaults.js +26 -27
- package/dist/src/project-graph/utils/project-configuration/target-merging.js +50 -8
- package/dist/src/project-graph/utils/project-configuration/target-normalization.js +16 -3
- package/dist/src/project-graph/utils/project-configuration/utils.d.ts +15 -0
- package/dist/src/project-graph/utils/project-configuration/utils.js +42 -6
- package/dist/src/project-graph/utils/project-configuration-utils.d.ts +15 -12
- package/dist/src/project-graph/utils/project-configuration-utils.js +79 -99
- package/dist/src/tasks-runner/task-env.d.ts +9 -0
- package/dist/src/tasks-runner/task-env.js +26 -2
- package/dist/src/tasks-runner/task-orchestrator.js +2 -6
- package/dist/src/utils/analytics-prompt.d.ts +0 -6
- package/dist/src/utils/analytics-prompt.js +0 -51
- package/dist/src/utils/catalog/bun-manager-utils.d.ts +8 -0
- package/dist/src/utils/catalog/bun-manager-utils.js +174 -0
- package/dist/src/utils/catalog/bun-manager.d.ts +28 -0
- package/dist/src/utils/catalog/bun-manager.js +130 -0
- package/dist/src/utils/catalog/index.d.ts +1 -1
- package/dist/src/utils/catalog/index.js +1 -1
- package/dist/src/utils/catalog/manager-factory.js +3 -0
- package/dist/src/utils/catalog/manager-utils.d.ts +8 -1
- package/dist/src/utils/catalog/manager-utils.js +9 -4
- package/dist/src/utils/catalog/manager.d.ts +13 -1
- package/dist/src/utils/catalog/manager.js +30 -0
- package/dist/src/utils/catalog/pnpm-manager.d.ts +2 -1
- package/dist/src/utils/catalog/pnpm-manager.js +3 -0
- package/dist/src/utils/catalog/types.d.ts +4 -0
- package/dist/src/utils/catalog/yarn-manager.d.ts +6 -2
- package/dist/src/utils/catalog/yarn-manager.js +23 -32
- package/dist/src/utils/git-utils.d.ts +15 -0
- package/dist/src/utils/git-utils.js +64 -6
- package/dist/src/utils/package-manager.d.ts +3 -1
- package/dist/src/utils/package-manager.js +22 -2
- package/dist/src/utils/workspace-id.d.ts +20 -0
- package/dist/src/utils/workspace-id.js +54 -0
- package/package.json +20 -15
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BunCatalogManager = void 0;
|
|
4
|
+
const manager_1 = require("./manager");
|
|
5
|
+
const bun_manager_utils_1 = require("./bun-manager-utils");
|
|
6
|
+
const BUN_CATALOG_FILENAME = 'package.json';
|
|
7
|
+
/**
|
|
8
|
+
* Bun-specific catalog manager implementation.
|
|
9
|
+
*
|
|
10
|
+
* Bun declares catalogs in the root package.json `catalog`/`catalogs` fields,
|
|
11
|
+
* either at the top level or nested under the object form of `workspaces`.
|
|
12
|
+
* Unlike pnpm, the name "default" is not special: `catalog:` resolves only
|
|
13
|
+
* against `catalog`, and `catalog:default` against `catalogs.default`.
|
|
14
|
+
*/
|
|
15
|
+
class BunCatalogManager {
|
|
16
|
+
constructor() {
|
|
17
|
+
this.name = 'bun';
|
|
18
|
+
this.catalogProtocol = 'catalog:';
|
|
19
|
+
// Parsed fs-root definitions, cached per pass. See readBunCatalogDefinitions.
|
|
20
|
+
this.definitionsByRoot = new Map();
|
|
21
|
+
}
|
|
22
|
+
isCatalogReference(version) {
|
|
23
|
+
return version.startsWith(this.catalogProtocol);
|
|
24
|
+
}
|
|
25
|
+
parseCatalogReference(version) {
|
|
26
|
+
if (!this.isCatalogReference(version)) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
const catalogName = version.substring(this.catalogProtocol.length).trim();
|
|
30
|
+
// Only an empty/whitespace name selects the default catalog; "default" is
|
|
31
|
+
// a regular named catalog in bun.
|
|
32
|
+
const isDefault = !catalogName;
|
|
33
|
+
return {
|
|
34
|
+
catalogName: isDefault ? undefined : catalogName,
|
|
35
|
+
isDefaultCatalog: isDefault,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
getCatalogDefinitionFilePaths() {
|
|
39
|
+
return [BUN_CATALOG_FILENAME];
|
|
40
|
+
}
|
|
41
|
+
getCatalogDefinitions(treeOrRoot) {
|
|
42
|
+
return (0, bun_manager_utils_1.readBunCatalogDefinitions)(BUN_CATALOG_FILENAME, treeOrRoot, this.definitionsByRoot);
|
|
43
|
+
}
|
|
44
|
+
resolveCatalogReference(treeOrRoot, packageName, version) {
|
|
45
|
+
const catalogRef = this.parseCatalogReference(version);
|
|
46
|
+
if (!catalogRef) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
const catalogDefs = this.getCatalogDefinitions(treeOrRoot);
|
|
50
|
+
if (!catalogDefs) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
let catalogToUse;
|
|
54
|
+
if (catalogRef.isDefaultCatalog) {
|
|
55
|
+
catalogToUse = catalogDefs.catalog;
|
|
56
|
+
}
|
|
57
|
+
else if (catalogRef.catalogName) {
|
|
58
|
+
catalogToUse = catalogDefs.catalogs?.[catalogRef.catalogName];
|
|
59
|
+
}
|
|
60
|
+
return catalogToUse?.[packageName] || null;
|
|
61
|
+
}
|
|
62
|
+
getCatalogReferencesForPackage(treeOrRoot, packageName) {
|
|
63
|
+
return (0, manager_1.collectCatalogReferencesForPackage)(this, treeOrRoot, packageName);
|
|
64
|
+
}
|
|
65
|
+
validateCatalogReference(treeOrRoot, packageName, version) {
|
|
66
|
+
const catalogRef = this.parseCatalogReference(version);
|
|
67
|
+
if (!catalogRef) {
|
|
68
|
+
throw new Error(`Invalid catalog reference syntax: "${version}". Expected format: "catalog:" or "catalog:name"`);
|
|
69
|
+
}
|
|
70
|
+
const catalogDefs = this.getCatalogDefinitions(treeOrRoot);
|
|
71
|
+
if (!catalogDefs) {
|
|
72
|
+
throw new Error((0, manager_1.formatCatalogError)(`Cannot get Bun catalog definitions. No catalog defined in ${BUN_CATALOG_FILENAME}.`, [
|
|
73
|
+
`Add a "catalog" or "catalogs" field to ${BUN_CATALOG_FILENAME} in your workspace root`,
|
|
74
|
+
]));
|
|
75
|
+
}
|
|
76
|
+
let catalogToUse;
|
|
77
|
+
if (catalogRef.isDefaultCatalog) {
|
|
78
|
+
catalogToUse = catalogDefs.catalog;
|
|
79
|
+
if (!catalogToUse) {
|
|
80
|
+
const availableCatalogs = Object.keys(catalogDefs.catalogs || {});
|
|
81
|
+
const suggestions = [
|
|
82
|
+
`Define a default catalog in ${BUN_CATALOG_FILENAME} under the "catalog" key`,
|
|
83
|
+
];
|
|
84
|
+
if (availableCatalogs.length > 0) {
|
|
85
|
+
suggestions.push(`Or select from the available named catalogs: ${availableCatalogs
|
|
86
|
+
.map((c) => `"catalog:${c}"`)
|
|
87
|
+
.join(', ')}`);
|
|
88
|
+
}
|
|
89
|
+
throw new Error((0, manager_1.formatCatalogError)(`No default catalog defined in ${BUN_CATALOG_FILENAME}`, suggestions));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
else if (catalogRef.catalogName) {
|
|
93
|
+
catalogToUse = catalogDefs.catalogs?.[catalogRef.catalogName];
|
|
94
|
+
if (!catalogToUse) {
|
|
95
|
+
const availableCatalogs = Object.keys(catalogDefs.catalogs || {});
|
|
96
|
+
const suggestions = [
|
|
97
|
+
`Define the catalog in ${BUN_CATALOG_FILENAME} under the "catalogs" key`,
|
|
98
|
+
];
|
|
99
|
+
if (availableCatalogs.length > 0) {
|
|
100
|
+
suggestions.push(`Or select from the available named catalogs: ${availableCatalogs
|
|
101
|
+
.map((c) => `"catalog:${c}"`)
|
|
102
|
+
.join(', ')}`);
|
|
103
|
+
}
|
|
104
|
+
if (catalogDefs.catalog) {
|
|
105
|
+
suggestions.push(`Or use the default catalog ("catalog:")`);
|
|
106
|
+
}
|
|
107
|
+
throw new Error((0, manager_1.formatCatalogError)(`Catalog "${catalogRef.catalogName}" not found in ${BUN_CATALOG_FILENAME}`, suggestions));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (!catalogToUse[packageName]) {
|
|
111
|
+
const catalogName = catalogRef.isDefaultCatalog
|
|
112
|
+
? 'default catalog ("catalog")'
|
|
113
|
+
: `catalog '${catalogRef.catalogName}'`;
|
|
114
|
+
const availablePackages = Object.keys(catalogToUse);
|
|
115
|
+
const suggestions = [
|
|
116
|
+
`Add "${packageName}" to ${catalogName} in ${BUN_CATALOG_FILENAME}`,
|
|
117
|
+
];
|
|
118
|
+
if (availablePackages.length > 0) {
|
|
119
|
+
suggestions.push(`Or select from the available packages in ${catalogName}: ${availablePackages
|
|
120
|
+
.map((p) => `"${p}"`)
|
|
121
|
+
.join(', ')}`);
|
|
122
|
+
}
|
|
123
|
+
throw new Error((0, manager_1.formatCatalogError)(`Package "${packageName}" not found in ${catalogName}`, suggestions));
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
updateCatalogVersions(treeOrRoot, updates) {
|
|
127
|
+
(0, bun_manager_utils_1.updateBunCatalogVersionsInFile)(BUN_CATALOG_FILENAME, treeOrRoot, updates);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
exports.BunCatalogManager = BunCatalogManager;
|
|
@@ -4,7 +4,7 @@ import type { CatalogManager } from './manager';
|
|
|
4
4
|
import { getCatalogManager } from './manager-factory';
|
|
5
5
|
export { type CatalogManager, getCatalogManager };
|
|
6
6
|
/**
|
|
7
|
-
* Dereferences a pnpm/yarn catalog reference to a concrete version spec. Returns
|
|
7
|
+
* Dereferences a pnpm/yarn/bun catalog reference to a concrete version spec. Returns
|
|
8
8
|
* the input unchanged when it is not a catalog reference (or no catalog manager
|
|
9
9
|
* applies). Throws when the reference cannot be resolved.
|
|
10
10
|
*/
|
|
@@ -9,7 +9,7 @@ const workspace_root_1 = require("../workspace-root");
|
|
|
9
9
|
const manager_factory_1 = require("./manager-factory");
|
|
10
10
|
Object.defineProperty(exports, "getCatalogManager", { enumerable: true, get: function () { return manager_factory_1.getCatalogManager; } });
|
|
11
11
|
/**
|
|
12
|
-
* Dereferences a pnpm/yarn catalog reference to a concrete version spec. Returns
|
|
12
|
+
* Dereferences a pnpm/yarn/bun catalog reference to a concrete version spec. Returns
|
|
13
13
|
* the input unchanged when it is not a catalog reference (or no catalog manager
|
|
14
14
|
* applies). Throws when the reference cannot be resolved.
|
|
15
15
|
*/
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getCatalogManager = getCatalogManager;
|
|
4
4
|
const package_manager_1 = require("../package-manager");
|
|
5
|
+
const bun_manager_1 = require("./bun-manager");
|
|
5
6
|
const pnpm_manager_1 = require("./pnpm-manager");
|
|
6
7
|
const yarn_manager_1 = require("./yarn-manager");
|
|
7
8
|
/**
|
|
@@ -14,6 +15,8 @@ function getCatalogManager(workspaceRoot) {
|
|
|
14
15
|
return new pnpm_manager_1.PnpmCatalogManager();
|
|
15
16
|
case 'yarn':
|
|
16
17
|
return new yarn_manager_1.YarnCatalogManager();
|
|
18
|
+
case 'bun':
|
|
19
|
+
return new bun_manager_1.BunCatalogManager();
|
|
17
20
|
default:
|
|
18
21
|
return null;
|
|
19
22
|
}
|
|
@@ -5,4 +5,11 @@ export declare function updateCatalogVersionsInFile(filename: string, treeOrRoot
|
|
|
5
5
|
packageName: string;
|
|
6
6
|
version: string;
|
|
7
7
|
catalogName?: string;
|
|
8
|
-
}
|
|
8
|
+
}>, options?: {
|
|
9
|
+
/**
|
|
10
|
+
* Treat "default" as an alias for the `catalog` field and route default
|
|
11
|
+
* updates through a populated `catalogs.default` (pnpm semantics). When
|
|
12
|
+
* false, "default" is an ordinary named catalog (yarn semantics).
|
|
13
|
+
*/
|
|
14
|
+
aliasDefaultCatalog?: boolean;
|
|
15
|
+
}): void;
|
|
@@ -136,7 +136,8 @@ function readCatalogDefinitions(filename, treeOrRoot, cache) {
|
|
|
136
136
|
}
|
|
137
137
|
return readCatalogConfigFromTree(filename, treeOrRoot);
|
|
138
138
|
}
|
|
139
|
-
function updateCatalogVersionsInFile(filename, treeOrRoot, updates) {
|
|
139
|
+
function updateCatalogVersionsInFile(filename, treeOrRoot, updates, options) {
|
|
140
|
+
const aliasDefaultCatalog = options?.aliasDefaultCatalog ?? true;
|
|
140
141
|
let checkExists;
|
|
141
142
|
let readYaml;
|
|
142
143
|
let writeYaml;
|
|
@@ -194,13 +195,17 @@ function updateCatalogVersionsInFile(filename, treeOrRoot, updates) {
|
|
|
194
195
|
let hasChanges = false;
|
|
195
196
|
for (const update of updates) {
|
|
196
197
|
const { packageName, version, catalogName } = update;
|
|
197
|
-
const normalizedCatalogName = catalogName === 'default'
|
|
198
|
+
const normalizedCatalogName = aliasDefaultCatalog && catalogName === 'default'
|
|
199
|
+
? undefined
|
|
200
|
+
: catalogName;
|
|
198
201
|
let targetPath;
|
|
199
202
|
if (!normalizedCatalogName) {
|
|
200
203
|
// An empty `catalog:` placeholder must not claim the default route
|
|
201
204
|
// when `catalogs.default` is populated; that would create a
|
|
202
|
-
// duplicate-default config rejected by pnpm.
|
|
203
|
-
|
|
205
|
+
// duplicate-default config rejected by pnpm. Without the alias,
|
|
206
|
+
// "default" is an ordinary named catalog and the default route is
|
|
207
|
+
// always the `catalog` field.
|
|
208
|
+
if (!aliasDefaultCatalog || isMapAt(doc, ['catalog'])) {
|
|
204
209
|
targetPath = ['catalog', packageName];
|
|
205
210
|
}
|
|
206
211
|
else if (existsAt(doc, ['catalogs', 'default'])) {
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import type { Tree } from '../../generators/tree';
|
|
2
|
-
import type { CatalogDefinitions, CatalogReference } from './types';
|
|
2
|
+
import type { CatalogDefinitions, CatalogReference, CatalogReferenceMatch } from './types';
|
|
3
3
|
export declare function formatCatalogError(error: string, suggestions: string[]): string;
|
|
4
|
+
/**
|
|
5
|
+
* Shared implementation of getCatalogReferencesForPackage: enumerates the
|
|
6
|
+
* default and named catalog references and keeps those the manager resolves,
|
|
7
|
+
* so per-manager default-catalog semantics apply without duplication.
|
|
8
|
+
*/
|
|
9
|
+
export declare function collectCatalogReferencesForPackage(manager: CatalogManager, treeOrRoot: Tree | string, packageName: string): CatalogReferenceMatch[];
|
|
4
10
|
/**
|
|
5
11
|
* Interface for catalog managers that handle package manager-specific catalog implementations.
|
|
6
12
|
*/
|
|
@@ -19,6 +25,12 @@ export interface CatalogManager {
|
|
|
19
25
|
*/
|
|
20
26
|
resolveCatalogReference(workspaceRoot: string, packageName: string, version: string): string | null;
|
|
21
27
|
resolveCatalogReference(tree: Tree, packageName: string, version: string): string | null;
|
|
28
|
+
/**
|
|
29
|
+
* Get every catalog reference that resolves to a version for a package,
|
|
30
|
+
* following the package manager's own default-catalog semantics.
|
|
31
|
+
*/
|
|
32
|
+
getCatalogReferencesForPackage(workspaceRoot: string, packageName: string): CatalogReferenceMatch[];
|
|
33
|
+
getCatalogReferencesForPackage(tree: Tree, packageName: string): CatalogReferenceMatch[];
|
|
22
34
|
/**
|
|
23
35
|
* Check that a catalog reference is valid.
|
|
24
36
|
*/
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.formatCatalogError = formatCatalogError;
|
|
4
|
+
exports.collectCatalogReferencesForPackage = collectCatalogReferencesForPackage;
|
|
4
5
|
function formatCatalogError(error, suggestions) {
|
|
5
6
|
let message = error;
|
|
6
7
|
if (suggestions.length > 0) {
|
|
@@ -11,3 +12,32 @@ function formatCatalogError(error, suggestions) {
|
|
|
11
12
|
}
|
|
12
13
|
return message;
|
|
13
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Shared implementation of getCatalogReferencesForPackage: enumerates the
|
|
17
|
+
* default and named catalog references and keeps those the manager resolves,
|
|
18
|
+
* so per-manager default-catalog semantics apply without duplication.
|
|
19
|
+
*/
|
|
20
|
+
function collectCatalogReferencesForPackage(manager, treeOrRoot, packageName) {
|
|
21
|
+
// The overload pairs don't accept the Tree | string union directly.
|
|
22
|
+
const source = treeOrRoot;
|
|
23
|
+
const catalogDefs = manager.getCatalogDefinitions(source);
|
|
24
|
+
if (!catalogDefs) {
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
const catalogRefs = ['catalog:'];
|
|
28
|
+
for (const name of Object.keys(catalogDefs.catalogs ?? {})) {
|
|
29
|
+
// Skip names the manager treats as the default catalog (e.g. pnpm's
|
|
30
|
+
// "default") — already covered by the `catalog:` candidate.
|
|
31
|
+
if (!manager.parseCatalogReference(`catalog:${name}`)?.isDefaultCatalog) {
|
|
32
|
+
catalogRefs.push(`catalog:${name}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const matches = [];
|
|
36
|
+
for (const catalogRef of catalogRefs) {
|
|
37
|
+
const versionSpec = manager.resolveCatalogReference(source, packageName, catalogRef);
|
|
38
|
+
if (versionSpec) {
|
|
39
|
+
matches.push({ catalogRef, versionSpec });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return matches;
|
|
43
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Tree } from '../../generators/tree';
|
|
2
2
|
import { type CatalogManager } from './manager';
|
|
3
|
-
import type { CatalogDefinitions, CatalogReference } from './types';
|
|
3
|
+
import type { CatalogDefinitions, CatalogReference, CatalogReferenceMatch } from './types';
|
|
4
4
|
/**
|
|
5
5
|
* PNPM-specific catalog manager implementation
|
|
6
6
|
*/
|
|
@@ -13,6 +13,7 @@ export declare class PnpmCatalogManager implements CatalogManager {
|
|
|
13
13
|
getCatalogDefinitionFilePaths(): string[];
|
|
14
14
|
getCatalogDefinitions(treeOrRoot: Tree | string): CatalogDefinitions | null;
|
|
15
15
|
resolveCatalogReference(treeOrRoot: Tree | string, packageName: string, version: string): string | null;
|
|
16
|
+
getCatalogReferencesForPackage(treeOrRoot: Tree | string, packageName: string): CatalogReferenceMatch[];
|
|
16
17
|
validateCatalogReference(treeOrRoot: Tree | string, packageName: string, version: string): void;
|
|
17
18
|
updateCatalogVersions(treeOrRoot: Tree | string, updates: Array<{
|
|
18
19
|
packageName: string;
|
|
@@ -54,6 +54,9 @@ class PnpmCatalogManager {
|
|
|
54
54
|
}
|
|
55
55
|
return catalogToUse?.[packageName] || null;
|
|
56
56
|
}
|
|
57
|
+
getCatalogReferencesForPackage(treeOrRoot, packageName) {
|
|
58
|
+
return (0, manager_1.collectCatalogReferencesForPackage)(this, treeOrRoot, packageName);
|
|
59
|
+
}
|
|
57
60
|
validateCatalogReference(treeOrRoot, packageName, version) {
|
|
58
61
|
const catalogRef = this.parseCatalogReference(version);
|
|
59
62
|
if (!catalogRef) {
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type { Tree } from '../../generators/tree';
|
|
2
2
|
import { type CatalogManager } from './manager';
|
|
3
|
-
import type { CatalogDefinitions, CatalogReference } from './types';
|
|
3
|
+
import type { CatalogDefinitions, CatalogReference, CatalogReferenceMatch } from './types';
|
|
4
4
|
/**
|
|
5
|
-
* Yarn Berry (v4+) catalog manager implementation
|
|
5
|
+
* Yarn Berry (v4.10+) catalog manager implementation.
|
|
6
|
+
*
|
|
7
|
+
* Unlike pnpm, the name "default" is not special: `catalog:` resolves only
|
|
8
|
+
* against `catalog`, and `catalog:default` against `catalogs.default`.
|
|
6
9
|
*/
|
|
7
10
|
export declare class YarnCatalogManager implements CatalogManager {
|
|
8
11
|
readonly name = "yarn";
|
|
@@ -13,6 +16,7 @@ export declare class YarnCatalogManager implements CatalogManager {
|
|
|
13
16
|
getCatalogDefinitionFilePaths(): string[];
|
|
14
17
|
getCatalogDefinitions(treeOrRoot: Tree | string): CatalogDefinitions | null;
|
|
15
18
|
resolveCatalogReference(treeOrRoot: Tree | string, packageName: string, version: string): string | null;
|
|
19
|
+
getCatalogReferencesForPackage(treeOrRoot: Tree | string, packageName: string): CatalogReferenceMatch[];
|
|
16
20
|
validateCatalogReference(treeOrRoot: Tree | string, packageName: string, version: string): void;
|
|
17
21
|
updateCatalogVersions(treeOrRoot: Tree | string, updates: Array<{
|
|
18
22
|
packageName: string;
|
|
@@ -5,7 +5,10 @@ const manager_1 = require("./manager");
|
|
|
5
5
|
const manager_utils_1 = require("./manager-utils");
|
|
6
6
|
const YARNRC_FILENAME = '.yarnrc.yml';
|
|
7
7
|
/**
|
|
8
|
-
* Yarn Berry (v4+) catalog manager implementation
|
|
8
|
+
* Yarn Berry (v4.10+) catalog manager implementation.
|
|
9
|
+
*
|
|
10
|
+
* Unlike pnpm, the name "default" is not special: `catalog:` resolves only
|
|
11
|
+
* against `catalog`, and `catalog:default` against `catalogs.default`.
|
|
9
12
|
*/
|
|
10
13
|
class YarnCatalogManager {
|
|
11
14
|
constructor() {
|
|
@@ -22,8 +25,9 @@ class YarnCatalogManager {
|
|
|
22
25
|
return null;
|
|
23
26
|
}
|
|
24
27
|
const catalogName = version.substring(this.catalogProtocol.length);
|
|
25
|
-
//
|
|
26
|
-
|
|
28
|
+
// Only an empty name selects the default catalog; unlike pnpm, "default"
|
|
29
|
+
// is a regular named catalog in yarn.
|
|
30
|
+
const isDefault = !catalogName;
|
|
27
31
|
return {
|
|
28
32
|
catalogName: isDefault ? undefined : catalogName,
|
|
29
33
|
isDefaultCatalog: isDefault,
|
|
@@ -46,14 +50,16 @@ class YarnCatalogManager {
|
|
|
46
50
|
}
|
|
47
51
|
let catalogToUse;
|
|
48
52
|
if (catalogRef.isDefaultCatalog) {
|
|
49
|
-
|
|
50
|
-
catalogToUse = catalogDefs.catalog ?? catalogDefs.catalogs?.default;
|
|
53
|
+
catalogToUse = catalogDefs.catalog;
|
|
51
54
|
}
|
|
52
55
|
else if (catalogRef.catalogName) {
|
|
53
56
|
catalogToUse = catalogDefs.catalogs?.[catalogRef.catalogName];
|
|
54
57
|
}
|
|
55
58
|
return catalogToUse?.[packageName] || null;
|
|
56
59
|
}
|
|
60
|
+
getCatalogReferencesForPackage(treeOrRoot, packageName) {
|
|
61
|
+
return (0, manager_1.collectCatalogReferencesForPackage)(this, treeOrRoot, packageName);
|
|
62
|
+
}
|
|
57
63
|
validateCatalogReference(treeOrRoot, packageName, version) {
|
|
58
64
|
const catalogRef = this.parseCatalogReference(version);
|
|
59
65
|
if (!catalogRef) {
|
|
@@ -65,13 +71,9 @@ class YarnCatalogManager {
|
|
|
65
71
|
}
|
|
66
72
|
let catalogToUse;
|
|
67
73
|
if (catalogRef.isDefaultCatalog) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (hasCatalog && hasCatalogsDefault) {
|
|
72
|
-
throw new Error("The 'default' catalog was defined multiple times. Use the 'catalog' field or 'catalogs.default', but not both.");
|
|
73
|
-
}
|
|
74
|
-
catalogToUse = catalogDefs.catalog ?? catalogDefs.catalogs?.default;
|
|
74
|
+
// Yarn's default catalog is only the `catalog` field; unlike pnpm,
|
|
75
|
+
// `catalogs.default` does not act as a fallback.
|
|
76
|
+
catalogToUse = catalogDefs.catalog;
|
|
75
77
|
if (!catalogToUse) {
|
|
76
78
|
const availableCatalogs = Object.keys(catalogDefs.catalogs || {});
|
|
77
79
|
const suggestions = [
|
|
@@ -88,12 +90,7 @@ class YarnCatalogManager {
|
|
|
88
90
|
else if (catalogRef.catalogName) {
|
|
89
91
|
catalogToUse = catalogDefs.catalogs?.[catalogRef.catalogName];
|
|
90
92
|
if (!catalogToUse) {
|
|
91
|
-
const availableCatalogs = Object.keys(catalogDefs.catalogs || {})
|
|
92
|
-
const defaultCatalog = !!catalogDefs.catalog
|
|
93
|
-
? 'catalog'
|
|
94
|
-
: !catalogDefs.catalogs?.default
|
|
95
|
-
? 'catalogs.default'
|
|
96
|
-
: null;
|
|
93
|
+
const availableCatalogs = Object.keys(catalogDefs.catalogs || {});
|
|
97
94
|
const suggestions = [
|
|
98
95
|
`Define the catalog in ${YARNRC_FILENAME} under the "catalogs" key`,
|
|
99
96
|
];
|
|
@@ -102,24 +99,16 @@ class YarnCatalogManager {
|
|
|
102
99
|
.map((c) => `"catalog:${c}"`)
|
|
103
100
|
.join(', ')}`);
|
|
104
101
|
}
|
|
105
|
-
if (
|
|
106
|
-
suggestions.push(`Or use the default catalog ("
|
|
102
|
+
if (catalogDefs.catalog) {
|
|
103
|
+
suggestions.push(`Or use the default catalog ("catalog:")`);
|
|
107
104
|
}
|
|
108
105
|
throw new Error((0, manager_1.formatCatalogError)(`Catalog "${catalogRef.catalogName}" not found in ${YARNRC_FILENAME}`, suggestions));
|
|
109
106
|
}
|
|
110
107
|
}
|
|
111
108
|
if (!catalogToUse[packageName]) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
const hasCatalog = !!catalogDefs.catalog;
|
|
116
|
-
catalogName = hasCatalog
|
|
117
|
-
? 'default catalog ("catalog")'
|
|
118
|
-
: 'default catalog ("catalogs.default")';
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
catalogName = `catalog '${catalogRef.catalogName}'`;
|
|
122
|
-
}
|
|
109
|
+
const catalogName = catalogRef.isDefaultCatalog
|
|
110
|
+
? 'default catalog ("catalog")'
|
|
111
|
+
: `catalog '${catalogRef.catalogName}'`;
|
|
123
112
|
const availablePackages = Object.keys(catalogToUse);
|
|
124
113
|
const suggestions = [
|
|
125
114
|
`Add "${packageName}" to ${catalogName} in ${YARNRC_FILENAME}`,
|
|
@@ -133,7 +122,9 @@ class YarnCatalogManager {
|
|
|
133
122
|
}
|
|
134
123
|
}
|
|
135
124
|
updateCatalogVersions(treeOrRoot, updates) {
|
|
136
|
-
(0, manager_utils_1.updateCatalogVersionsInFile)(YARNRC_FILENAME, treeOrRoot, updates
|
|
125
|
+
(0, manager_utils_1.updateCatalogVersionsInFile)(YARNRC_FILENAME, treeOrRoot, updates, {
|
|
126
|
+
aliasDefaultCatalog: false,
|
|
127
|
+
});
|
|
137
128
|
}
|
|
138
129
|
}
|
|
139
130
|
exports.YarnCatalogManager = YarnCatalogManager;
|
|
@@ -36,6 +36,21 @@ export interface VcsRemoteInfo {
|
|
|
36
36
|
}
|
|
37
37
|
export declare function parseVcsRemoteUrl(url: string): VcsRemoteInfo | null;
|
|
38
38
|
export declare function getVcsRemoteInfo(directory?: string): VcsRemoteInfo | null;
|
|
39
|
+
export declare function getGitRootPath(cwd?: string): string;
|
|
40
|
+
/**
|
|
41
|
+
* Path of `directory` relative to its git root, posix-separated so it is
|
|
42
|
+
* identical on every OS, and '' when the directory is the git root itself.
|
|
43
|
+
* Null outside a git repository.
|
|
44
|
+
*/
|
|
45
|
+
export declare function getGitRootRelativePath(directory: string): string | null;
|
|
46
|
+
/** A shallow clone's truncated history has no stable root commit. */
|
|
47
|
+
export declare function isShallowRepository(directory?: string): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* SHA of the repository's first commit. Merged unrelated histories leave
|
|
50
|
+
* several root commits — the sorted-first one is picked so every clone
|
|
51
|
+
* agrees. Null when there are no commits, or outside a git repository.
|
|
52
|
+
*/
|
|
53
|
+
export declare function getFirstCommitSha(directory?: string): string | null;
|
|
39
54
|
export declare function isGitRepository(directory?: string): boolean;
|
|
40
55
|
export declare function getGitCurrentBranch(directory?: string): string | null;
|
|
41
56
|
export declare function hasUncommittedChanges(directory?: string): boolean;
|
|
@@ -4,6 +4,10 @@ exports.GitRepository = void 0;
|
|
|
4
4
|
exports.cloneFromUpstream = cloneFromUpstream;
|
|
5
5
|
exports.parseVcsRemoteUrl = parseVcsRemoteUrl;
|
|
6
6
|
exports.getVcsRemoteInfo = getVcsRemoteInfo;
|
|
7
|
+
exports.getGitRootPath = getGitRootPath;
|
|
8
|
+
exports.getGitRootRelativePath = getGitRootRelativePath;
|
|
9
|
+
exports.isShallowRepository = isShallowRepository;
|
|
10
|
+
exports.getFirstCommitSha = getFirstCommitSha;
|
|
7
11
|
exports.isGitRepository = isGitRepository;
|
|
8
12
|
exports.getGitCurrentBranch = getGitCurrentBranch;
|
|
9
13
|
exports.hasUncommittedChanges = hasUncommittedChanges;
|
|
@@ -49,12 +53,7 @@ class GitRepository {
|
|
|
49
53
|
this.root = this.getGitRootPath(this.directory);
|
|
50
54
|
}
|
|
51
55
|
getGitRootPath(cwd) {
|
|
52
|
-
return (
|
|
53
|
-
cwd,
|
|
54
|
-
windowsHide: true,
|
|
55
|
-
})
|
|
56
|
-
.toString()
|
|
57
|
-
.trim();
|
|
56
|
+
return getGitRootPath(cwd);
|
|
58
57
|
}
|
|
59
58
|
async hasUncommittedChanges() {
|
|
60
59
|
const data = await this.execGit(['status', '--porcelain']);
|
|
@@ -297,6 +296,65 @@ function getVcsRemoteInfo(directory) {
|
|
|
297
296
|
return null;
|
|
298
297
|
}
|
|
299
298
|
}
|
|
299
|
+
function getGitRootPath(cwd) {
|
|
300
|
+
return (0, child_process_1.execFileSync)('git', ['rev-parse', '--show-toplevel'], {
|
|
301
|
+
cwd,
|
|
302
|
+
windowsHide: true,
|
|
303
|
+
})
|
|
304
|
+
.toString()
|
|
305
|
+
.trim();
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Path of `directory` relative to its git root, posix-separated so it is
|
|
309
|
+
* identical on every OS, and '' when the directory is the git root itself.
|
|
310
|
+
* Null outside a git repository.
|
|
311
|
+
*/
|
|
312
|
+
function getGitRootRelativePath(directory) {
|
|
313
|
+
try {
|
|
314
|
+
return (0, path_1.relative)(getGitRootPath(directory), directory)
|
|
315
|
+
.split(path_1.sep)
|
|
316
|
+
.join(path_1.posix.sep);
|
|
317
|
+
}
|
|
318
|
+
catch {
|
|
319
|
+
return null;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
/** A shallow clone's truncated history has no stable root commit. */
|
|
323
|
+
function isShallowRepository(directory) {
|
|
324
|
+
try {
|
|
325
|
+
return ((0, child_process_1.execFileSync)('git', ['rev-parse', '--is-shallow-repository'], {
|
|
326
|
+
encoding: 'utf8',
|
|
327
|
+
stdio: 'pipe',
|
|
328
|
+
cwd: directory,
|
|
329
|
+
windowsHide: true,
|
|
330
|
+
}).trim() === 'true');
|
|
331
|
+
}
|
|
332
|
+
catch {
|
|
333
|
+
return false;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* SHA of the repository's first commit. Merged unrelated histories leave
|
|
338
|
+
* several root commits — the sorted-first one is picked so every clone
|
|
339
|
+
* agrees. Null when there are no commits, or outside a git repository.
|
|
340
|
+
*/
|
|
341
|
+
function getFirstCommitSha(directory) {
|
|
342
|
+
try {
|
|
343
|
+
const roots = (0, child_process_1.execFileSync)('git', ['rev-list', '--max-parents=0', 'HEAD'], {
|
|
344
|
+
encoding: 'utf8',
|
|
345
|
+
stdio: 'pipe',
|
|
346
|
+
cwd: directory,
|
|
347
|
+
windowsHide: true,
|
|
348
|
+
})
|
|
349
|
+
.trim()
|
|
350
|
+
.split(/\r?\n/)
|
|
351
|
+
.filter(Boolean);
|
|
352
|
+
return roots.sort()[0] ?? null;
|
|
353
|
+
}
|
|
354
|
+
catch {
|
|
355
|
+
return null;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
300
358
|
function isGitRepository(directory) {
|
|
301
359
|
try {
|
|
302
360
|
(0, child_process_1.execSync)('git rev-parse --is-inside-work-tree', {
|
|
@@ -121,7 +121,9 @@ export declare function resolvePackageVersionUsingInstallation(packageName: stri
|
|
|
121
121
|
export declare function packageRegistryView(pkg: string, version: string, args: string, options?: {
|
|
122
122
|
forceNpm?: boolean;
|
|
123
123
|
}): Promise<string>;
|
|
124
|
-
export declare function packageRegistryPack(cwd: string, pkg: string, version: string
|
|
124
|
+
export declare function packageRegistryPack(cwd: string, pkg: string, version: string, options?: {
|
|
125
|
+
bypassMinReleaseAge?: boolean;
|
|
126
|
+
}): Promise<{
|
|
125
127
|
tarballPath: string;
|
|
126
128
|
}>;
|
|
127
129
|
/**
|
|
@@ -349,6 +349,20 @@ function modifyPnpmWorkspaceYamlToFitNewDirectory(contents) {
|
|
|
349
349
|
doc.set('packages', ['.']);
|
|
350
350
|
// Relative patch paths don't resolve in the temp dir.
|
|
351
351
|
doc.delete('patchedDependencies');
|
|
352
|
+
// link:/file: overrides (e.g. written by `pnpm link`) point at paths that
|
|
353
|
+
// don't exist in the temp dir, and an override would hijack an exact-version
|
|
354
|
+
// add (`pnpm add pkg@x.y.z` would install the linked dir instead).
|
|
355
|
+
const overrides = doc.toJS()?.overrides;
|
|
356
|
+
if (overrides && typeof overrides === 'object') {
|
|
357
|
+
for (const [name, spec] of Object.entries(overrides)) {
|
|
358
|
+
if (typeof spec === 'string' && /^(link|file):/.test(spec)) {
|
|
359
|
+
doc.deleteIn(['overrides', name]);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
if (Object.keys(doc.toJS()?.overrides ?? {}).length === 0) {
|
|
363
|
+
doc.delete('overrides');
|
|
364
|
+
}
|
|
365
|
+
}
|
|
352
366
|
return doc.toString();
|
|
353
367
|
}
|
|
354
368
|
function copyPackageManagerConfigurationFiles(root, destination) {
|
|
@@ -519,7 +533,7 @@ options) {
|
|
|
519
533
|
});
|
|
520
534
|
return stdout.toString().trim();
|
|
521
535
|
}
|
|
522
|
-
async function packageRegistryPack(cwd, pkg, version) {
|
|
536
|
+
async function packageRegistryPack(cwd, pkg, version, options) {
|
|
523
537
|
/**
|
|
524
538
|
* Only `npm pack` supports downloading a tarball of a specified remote
|
|
525
539
|
* package. `yarn` packs the active workspace, `pnpm pack` only packs
|
|
@@ -533,7 +547,13 @@ async function packageRegistryPack(cwd, pkg, version) {
|
|
|
533
547
|
windowsHide: true,
|
|
534
548
|
// npm enforces `devEngines.packageManager` even on `pack`; force keeps the
|
|
535
549
|
// download working in workspaces that pin a non-npm manager (onFail: error).
|
|
536
|
-
env: {
|
|
550
|
+
env: {
|
|
551
|
+
...process.env,
|
|
552
|
+
npm_config_force: 'true',
|
|
553
|
+
...(options?.bypassMinReleaseAge
|
|
554
|
+
? { npm_config_min_release_age: '0' }
|
|
555
|
+
: {}),
|
|
556
|
+
},
|
|
537
557
|
});
|
|
538
558
|
const tarballPath = stdout.trim();
|
|
539
559
|
return { tarballPath };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { NxJsonConfiguration } from '../config/nx-json';
|
|
2
|
+
/**
|
|
3
|
+
* The workspace's analytics identity: the Nx Cloud id when the workspace has
|
|
4
|
+
* one (most stable — it survives repo moves and renames), else the repo key.
|
|
5
|
+
* Null when neither is available, in which case nothing is reported.
|
|
6
|
+
*/
|
|
7
|
+
export declare function generateWorkspaceId(root: string, nxJson: NxJsonConfiguration | null): string | null;
|
|
8
|
+
/**
|
|
9
|
+
* Derive the stable, unsalted key identifying this workspace in the
|
|
10
|
+
* repoTelemetry registry: `sha256(<repo identity> + '#' + <workspace path
|
|
11
|
+
* relative to the git root>)`.
|
|
12
|
+
*
|
|
13
|
+
* The repo identity is the normalized `domain/slug` from the git remote
|
|
14
|
+
* (protocol-independent: ssh, https, and token-authenticated URLs of the
|
|
15
|
+
* same repo produce the same key), falling back to the first-commit SHA
|
|
16
|
+
* when no remote exists. Returns null when no identity is derivable — not
|
|
17
|
+
* a git repository, or a shallow clone without a remote.
|
|
18
|
+
*/
|
|
19
|
+
export declare function deriveRepoKey(directory: string): string | null;
|
|
20
|
+
export declare function computeRepoKey(identity: string, relativePath: string): string;
|