nx 22.0.0-canary.20251014-82acc84 → 22.0.0-canary.20251016-849f356
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/package.json +11 -11
- package/release/changelog-renderer/index.d.ts +5 -0
- package/release/changelog-renderer/index.d.ts.map +1 -1
- package/release/changelog-renderer/index.js +48 -16
- package/src/command-line/init/implementation/angular/index.d.ts.map +1 -1
- package/src/command-line/init/implementation/angular/index.js +4 -6
- package/src/command-line/migrate/migrate.d.ts.map +1 -1
- package/src/command-line/migrate/migrate.js +25 -8
- package/src/command-line/release/changelog.d.ts +1 -1
- package/src/command-line/release/changelog.d.ts.map +1 -1
- package/src/command-line/release/changelog.js +8 -6
- package/src/command-line/release/command-object.d.ts +1 -0
- package/src/command-line/release/command-object.d.ts.map +1 -1
- package/src/command-line/release/command-object.js +5 -0
- package/src/command-line/release/config/config.d.ts.map +1 -1
- package/src/command-line/release/config/config.js +6 -3
- package/src/command-line/release/index.d.ts +14 -2
- package/src/command-line/release/index.d.ts.map +1 -1
- package/src/command-line/release/index.js +13 -6
- package/src/command-line/release/publish.d.ts +1 -1
- package/src/command-line/release/publish.d.ts.map +1 -1
- package/src/command-line/release/publish.js +6 -3
- package/src/command-line/release/release.d.ts +1 -1
- package/src/command-line/release/release.d.ts.map +1 -1
- package/src/command-line/release/release.js +9 -7
- package/src/command-line/release/utils/resolve-changelog-renderer.d.ts +1 -1
- package/src/command-line/release/utils/resolve-changelog-renderer.d.ts.map +1 -1
- package/src/command-line/release/utils/resolve-changelog-renderer.js +6 -2
- package/src/command-line/release/version.d.ts +1 -1
- package/src/command-line/release/version.d.ts.map +1 -1
- package/src/command-line/release/version.js +6 -4
- package/src/config/nx-json.d.ts +10 -4
- package/src/config/nx-json.d.ts.map +1 -1
- package/src/core/graph/main.js +1 -1
- package/src/devkit-internals.d.ts +1 -0
- package/src/devkit-internals.d.ts.map +1 -1
- package/src/devkit-internals.js +3 -1
- package/src/native/nx.wasm32-wasi.wasm +0 -0
- package/src/plugins/js/lock-file/lock-file.d.ts.map +1 -1
- package/src/plugins/js/lock-file/lock-file.js +1 -1
- package/src/plugins/js/lock-file/pnpm-parser.d.ts +1 -1
- package/src/plugins/js/lock-file/pnpm-parser.d.ts.map +1 -1
- package/src/plugins/js/lock-file/pnpm-parser.js +12 -4
- package/src/plugins/js/lock-file/project-graph-pruning.d.ts +2 -2
- package/src/plugins/js/lock-file/project-graph-pruning.d.ts.map +1 -1
- package/src/plugins/js/lock-file/project-graph-pruning.js +22 -9
- package/src/plugins/js/package-json/create-package-json.d.ts.map +1 -1
- package/src/plugins/js/package-json/create-package-json.js +17 -5
- package/src/utils/catalog/index.d.ts +10 -0
- package/src/utils/catalog/index.d.ts.map +1 -0
- package/src/utils/catalog/index.js +38 -0
- package/src/utils/catalog/manager-factory.d.ts +6 -0
- package/src/utils/catalog/manager-factory.d.ts.map +1 -0
- package/src/utils/catalog/manager-factory.js +17 -0
- package/src/utils/catalog/manager.d.ts +40 -0
- package/src/utils/catalog/manager.d.ts.map +1 -0
- package/src/utils/catalog/manager.js +2 -0
- package/src/utils/catalog/pnpm-manager.d.ts +22 -0
- package/src/utils/catalog/pnpm-manager.d.ts.map +1 -0
- package/src/utils/catalog/pnpm-manager.js +257 -0
- package/src/utils/catalog/types.d.ts +5 -0
- package/src/utils/catalog/types.d.ts.map +1 -0
- package/src/utils/catalog/types.js +2 -0
- package/src/utils/package-json.d.ts +79 -0
- package/src/utils/package-json.d.ts.map +1 -1
- package/src/utils/package-json.js +81 -2
- package/src/utils/package-manager.d.ts.map +1 -1
- package/src/utils/package-manager.js +23 -6
- package/src/utils/pnpm-workspace.d.ts +9 -0
- package/src/utils/pnpm-workspace.d.ts.map +1 -0
- package/src/utils/pnpm-workspace.js +2 -0
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PnpmCatalogManager = void 0;
|
|
4
|
+
const js_yaml_1 = require("@zkochan/js-yaml");
|
|
5
|
+
const node_fs_1 = require("node:fs");
|
|
6
|
+
const node_path_1 = require("node:path");
|
|
7
|
+
const fileutils_1 = require("../fileutils");
|
|
8
|
+
const output_1 = require("../output");
|
|
9
|
+
/**
|
|
10
|
+
* PNPM-specific catalog manager implementation
|
|
11
|
+
*/
|
|
12
|
+
class PnpmCatalogManager {
|
|
13
|
+
constructor() {
|
|
14
|
+
this.name = 'pnpm';
|
|
15
|
+
this.catalogProtocol = 'catalog:';
|
|
16
|
+
}
|
|
17
|
+
isCatalogReference(version) {
|
|
18
|
+
return version.startsWith(this.catalogProtocol);
|
|
19
|
+
}
|
|
20
|
+
parseCatalogReference(version) {
|
|
21
|
+
if (!this.isCatalogReference(version)) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
const catalogName = version.substring(this.catalogProtocol.length);
|
|
25
|
+
// Normalize both "catalog:" and "catalog:default" to the same representation
|
|
26
|
+
const isDefault = !catalogName || catalogName === 'default';
|
|
27
|
+
return {
|
|
28
|
+
catalogName: isDefault ? undefined : catalogName,
|
|
29
|
+
isDefaultCatalog: isDefault,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
getCatalogDefinitions(treeOrRoot) {
|
|
33
|
+
if (typeof treeOrRoot === 'string') {
|
|
34
|
+
const pnpmWorkspacePath = (0, node_path_1.join)(treeOrRoot, 'pnpm-workspace.yaml');
|
|
35
|
+
if (!(0, node_fs_1.existsSync)(pnpmWorkspacePath)) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
return readYamlFileFromFs(pnpmWorkspacePath);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
if (!treeOrRoot.exists('pnpm-workspace.yaml')) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
return readYamlFileFromTree(treeOrRoot, 'pnpm-workspace.yaml');
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
resolveCatalogReference(treeOrRoot, packageName, version) {
|
|
48
|
+
const catalogRef = this.parseCatalogReference(version);
|
|
49
|
+
if (!catalogRef) {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
const workspaceConfig = this.getCatalogDefinitions(treeOrRoot);
|
|
53
|
+
if (!workspaceConfig) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
let catalogToUse;
|
|
57
|
+
if (catalogRef.isDefaultCatalog) {
|
|
58
|
+
// Check both locations for default catalog
|
|
59
|
+
catalogToUse =
|
|
60
|
+
workspaceConfig.catalog ?? workspaceConfig.catalogs?.default;
|
|
61
|
+
}
|
|
62
|
+
else if (catalogRef.catalogName) {
|
|
63
|
+
catalogToUse = workspaceConfig.catalogs?.[catalogRef.catalogName];
|
|
64
|
+
}
|
|
65
|
+
return catalogToUse?.[packageName] || null;
|
|
66
|
+
}
|
|
67
|
+
validateCatalogReference(treeOrRoot, packageName, version) {
|
|
68
|
+
const catalogRef = this.parseCatalogReference(version);
|
|
69
|
+
if (!catalogRef) {
|
|
70
|
+
throw new Error(`Invalid catalog reference syntax: "${version}". Expected format: "catalog:" or "catalog:name"`);
|
|
71
|
+
}
|
|
72
|
+
const workspaceConfig = this.getCatalogDefinitions(treeOrRoot);
|
|
73
|
+
if (!workspaceConfig) {
|
|
74
|
+
throw new Error(formatCatalogError('Cannot get Pnpm catalog definitions. No pnpm-workspace.yaml found in workspace root.', ['Create a pnpm-workspace.yaml file in your workspace root']));
|
|
75
|
+
}
|
|
76
|
+
let catalogToUse;
|
|
77
|
+
if (catalogRef.isDefaultCatalog) {
|
|
78
|
+
const hasCatalog = !!workspaceConfig.catalog;
|
|
79
|
+
const hasCatalogsDefault = !!workspaceConfig.catalogs?.default;
|
|
80
|
+
// Error if both defined (matches pnpm behavior)
|
|
81
|
+
if (hasCatalog && hasCatalogsDefault) {
|
|
82
|
+
throw new Error("The 'default' catalog was defined multiple times. Use the 'catalog' field or 'catalogs.default', but not both.");
|
|
83
|
+
}
|
|
84
|
+
catalogToUse =
|
|
85
|
+
workspaceConfig.catalog ?? workspaceConfig.catalogs?.default;
|
|
86
|
+
if (!catalogToUse) {
|
|
87
|
+
const availableCatalogs = Object.keys(workspaceConfig.catalogs || {});
|
|
88
|
+
const suggestions = [
|
|
89
|
+
'Define a default catalog in pnpm-workspace.yaml under the "catalog" key',
|
|
90
|
+
];
|
|
91
|
+
if (availableCatalogs.length > 0) {
|
|
92
|
+
suggestions.push(`Or select from the available named catalogs: ${availableCatalogs
|
|
93
|
+
.map((c) => `"catalog:${c}"`)
|
|
94
|
+
.join(', ')}`);
|
|
95
|
+
}
|
|
96
|
+
throw new Error(formatCatalogError('No default catalog defined in pnpm-workspace.yaml', suggestions));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
else if (catalogRef.catalogName) {
|
|
100
|
+
catalogToUse = workspaceConfig.catalogs?.[catalogRef.catalogName];
|
|
101
|
+
if (!catalogToUse) {
|
|
102
|
+
const availableCatalogs = Object.keys(workspaceConfig.catalogs || {}).filter((c) => c !== 'default');
|
|
103
|
+
const defaultCatalog = !!workspaceConfig.catalog
|
|
104
|
+
? 'catalog'
|
|
105
|
+
: !workspaceConfig.catalogs?.default
|
|
106
|
+
? 'catalogs.default'
|
|
107
|
+
: null;
|
|
108
|
+
const suggestions = [
|
|
109
|
+
'Define the catalog in pnpm-workspace.yaml under the "catalogs" key',
|
|
110
|
+
];
|
|
111
|
+
if (availableCatalogs.length > 0) {
|
|
112
|
+
suggestions.push(`Or select from the available named catalogs: ${availableCatalogs
|
|
113
|
+
.map((c) => `"catalog:${c}"`)
|
|
114
|
+
.join(', ')}`);
|
|
115
|
+
}
|
|
116
|
+
if (defaultCatalog) {
|
|
117
|
+
suggestions.push(`Or use the default catalog ("${defaultCatalog}")`);
|
|
118
|
+
}
|
|
119
|
+
throw new Error(formatCatalogError(`Catalog "${catalogRef.catalogName}" not found in pnpm-workspace.yaml`, suggestions));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (!catalogToUse[packageName]) {
|
|
123
|
+
let catalogName;
|
|
124
|
+
if (catalogRef.isDefaultCatalog) {
|
|
125
|
+
// Context-aware messaging based on which location exists
|
|
126
|
+
const hasCatalog = !!workspaceConfig.catalog;
|
|
127
|
+
catalogName = hasCatalog
|
|
128
|
+
? 'default catalog ("catalog")'
|
|
129
|
+
: 'default catalog ("catalogs.default")';
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
catalogName = `catalog '${catalogRef.catalogName}'`;
|
|
133
|
+
}
|
|
134
|
+
const availablePackages = Object.keys(catalogToUse);
|
|
135
|
+
const suggestions = [
|
|
136
|
+
`Add "${packageName}" to ${catalogName} in pnpm-workspace.yaml`,
|
|
137
|
+
];
|
|
138
|
+
if (availablePackages.length > 0) {
|
|
139
|
+
suggestions.push(`Or select from the available packages in ${catalogName}: ${availablePackages
|
|
140
|
+
.map((p) => `"${p}"`)
|
|
141
|
+
.join(', ')}`);
|
|
142
|
+
}
|
|
143
|
+
throw new Error(formatCatalogError(`Package "${packageName}" not found in ${catalogName}`, suggestions));
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
updateCatalogVersions(treeOrRoot, updates) {
|
|
147
|
+
let checkExists;
|
|
148
|
+
let readYaml;
|
|
149
|
+
let writeYaml;
|
|
150
|
+
if (typeof treeOrRoot === 'string') {
|
|
151
|
+
const workspaceYamlPath = (0, node_path_1.join)(treeOrRoot, 'pnpm-workspace.yaml');
|
|
152
|
+
checkExists = () => (0, node_fs_1.existsSync)(workspaceYamlPath);
|
|
153
|
+
readYaml = () => (0, node_fs_1.readFileSync)(workspaceYamlPath, 'utf-8');
|
|
154
|
+
writeYaml = (content) => (0, node_fs_1.writeFileSync)(workspaceYamlPath, content, 'utf-8');
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
checkExists = () => treeOrRoot.exists('pnpm-workspace.yaml');
|
|
158
|
+
readYaml = () => treeOrRoot.read('pnpm-workspace.yaml', 'utf-8');
|
|
159
|
+
writeYaml = (content) => treeOrRoot.write('pnpm-workspace.yaml', content);
|
|
160
|
+
}
|
|
161
|
+
if (!checkExists()) {
|
|
162
|
+
output_1.output.warn({
|
|
163
|
+
title: 'No pnpm-workspace.yaml found',
|
|
164
|
+
bodyLines: [
|
|
165
|
+
'Cannot update catalog versions without a pnpm-workspace.yaml file.',
|
|
166
|
+
'Create a pnpm-workspace.yaml file to use catalogs.',
|
|
167
|
+
],
|
|
168
|
+
});
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
try {
|
|
172
|
+
const workspaceContent = readYaml();
|
|
173
|
+
const workspaceData = (0, js_yaml_1.load)(workspaceContent) || {};
|
|
174
|
+
let hasChanges = false;
|
|
175
|
+
for (const update of updates) {
|
|
176
|
+
const { packageName, version, catalogName } = update;
|
|
177
|
+
const normalizedCatalogName = catalogName === 'default' ? undefined : catalogName;
|
|
178
|
+
let targetCatalog;
|
|
179
|
+
if (!normalizedCatalogName) {
|
|
180
|
+
// Default catalog - update whichever exists, prefer catalog over catalogs.default
|
|
181
|
+
if (workspaceData.catalog) {
|
|
182
|
+
targetCatalog = workspaceData.catalog;
|
|
183
|
+
}
|
|
184
|
+
else if (workspaceData.catalogs?.default) {
|
|
185
|
+
targetCatalog = workspaceData.catalogs.default;
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
// Neither exists, create catalog (shorthand syntax)
|
|
189
|
+
workspaceData.catalog ??= {};
|
|
190
|
+
targetCatalog = workspaceData.catalog;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
// Named catalog
|
|
195
|
+
workspaceData.catalogs ??= {};
|
|
196
|
+
workspaceData.catalogs[normalizedCatalogName] ??= {};
|
|
197
|
+
targetCatalog = workspaceData.catalogs[normalizedCatalogName];
|
|
198
|
+
}
|
|
199
|
+
if (targetCatalog[packageName] !== version) {
|
|
200
|
+
targetCatalog[packageName] = version;
|
|
201
|
+
hasChanges = true;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
if (hasChanges) {
|
|
205
|
+
writeYaml((0, js_yaml_1.dump)(workspaceData, {
|
|
206
|
+
indent: 2,
|
|
207
|
+
quotingType: '"',
|
|
208
|
+
forceQuotes: true,
|
|
209
|
+
}));
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
catch (error) {
|
|
213
|
+
output_1.output.error({
|
|
214
|
+
title: 'Failed to update catalog versions',
|
|
215
|
+
bodyLines: [error instanceof Error ? error.message : String(error)],
|
|
216
|
+
});
|
|
217
|
+
throw error;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
exports.PnpmCatalogManager = PnpmCatalogManager;
|
|
222
|
+
function readYamlFileFromFs(path) {
|
|
223
|
+
try {
|
|
224
|
+
return (0, fileutils_1.readYamlFile)(path);
|
|
225
|
+
}
|
|
226
|
+
catch (error) {
|
|
227
|
+
output_1.output.warn({
|
|
228
|
+
title: 'Unable to parse pnpm-workspace.yaml',
|
|
229
|
+
bodyLines: [error.toString()],
|
|
230
|
+
});
|
|
231
|
+
return null;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
function readYamlFileFromTree(tree, path) {
|
|
235
|
+
const content = tree.read(path, 'utf-8');
|
|
236
|
+
const { load } = require('@zkochan/js-yaml');
|
|
237
|
+
try {
|
|
238
|
+
return load(content, { filename: path });
|
|
239
|
+
}
|
|
240
|
+
catch (error) {
|
|
241
|
+
output_1.output.warn({
|
|
242
|
+
title: 'Unable to parse pnpm-workspace.yaml',
|
|
243
|
+
bodyLines: [error.toString()],
|
|
244
|
+
});
|
|
245
|
+
return null;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
function formatCatalogError(error, suggestions) {
|
|
249
|
+
let message = error;
|
|
250
|
+
if (suggestions && suggestions.length > 0) {
|
|
251
|
+
message += '\n\nSuggestions:';
|
|
252
|
+
suggestions.forEach((suggestion) => {
|
|
253
|
+
message += `\n • ${suggestion}`;
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
return message;
|
|
257
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../../packages/nx/src/utils/catalog/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC/B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gBAAgB,EAAE,OAAO,CAAC;CAC3B"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { NxJsonConfiguration } from '../config/nx-json';
|
|
2
2
|
import { ProjectConfiguration, ProjectMetadata, TargetConfiguration } from '../config/workspace-json-project-json';
|
|
3
|
+
import type { Tree } from '../generators/tree';
|
|
3
4
|
import { PackageManagerCommands } from './package-manager';
|
|
4
5
|
export interface NxProjectPackageJsonConfiguration extends Partial<ProjectConfiguration> {
|
|
5
6
|
includedScripts?: string[];
|
|
@@ -13,6 +14,7 @@ export type MixedPackageGroup = (string | {
|
|
|
13
14
|
version: string;
|
|
14
15
|
})[] | Record<string, string>;
|
|
15
16
|
export type PackageGroup = MixedPackageGroup | ArrayPackageGroup;
|
|
17
|
+
export type PackageJsonDependencySection = 'dependencies' | 'devDependencies' | 'peerDependencies' | 'optionalDependencies';
|
|
16
18
|
export interface NxMigrationsConfiguration {
|
|
17
19
|
migrations?: string;
|
|
18
20
|
packageGroup?: PackageGroup;
|
|
@@ -108,5 +110,82 @@ export declare function installPackageToTmp(pkg: string, requiredVersion: string
|
|
|
108
110
|
tempDir: string;
|
|
109
111
|
cleanup: () => void;
|
|
110
112
|
};
|
|
113
|
+
/**
|
|
114
|
+
* Get the resolved version of a dependency from package.json.
|
|
115
|
+
*
|
|
116
|
+
* Retrieves a package version and automatically resolves PNPM catalog references
|
|
117
|
+
* (e.g., "catalog:default") to their actual version strings. By default, searches
|
|
118
|
+
* `dependencies` first, then falls back to `devDependencies`.
|
|
119
|
+
*
|
|
120
|
+
* **Tree-based usage** (generators and migrations):
|
|
121
|
+
* Use when you have a `Tree` object, which is typical in Nx generators and migrations.
|
|
122
|
+
*
|
|
123
|
+
* **Filesystem-based usage** (CLI commands and scripts):
|
|
124
|
+
* Use when reading directly from the filesystem without a `Tree` object.
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```typescript
|
|
128
|
+
* // Tree-based - from root package.json (checks dependencies then devDependencies)
|
|
129
|
+
* const reactVersion = getDependencyVersionFromPackageJson(tree, 'react');
|
|
130
|
+
* // Returns: "^18.0.0" (resolves "catalog:default" if present)
|
|
131
|
+
*
|
|
132
|
+
* // Tree-based - check only dependencies section
|
|
133
|
+
* const version = getDependencyVersionFromPackageJson(
|
|
134
|
+
* tree,
|
|
135
|
+
* 'react',
|
|
136
|
+
* 'package.json',
|
|
137
|
+
* ['dependencies']
|
|
138
|
+
* );
|
|
139
|
+
*
|
|
140
|
+
* // Tree-based - check only devDependencies section
|
|
141
|
+
* const version = getDependencyVersionFromPackageJson(
|
|
142
|
+
* tree,
|
|
143
|
+
* 'jest',
|
|
144
|
+
* 'package.json',
|
|
145
|
+
* ['devDependencies']
|
|
146
|
+
* );
|
|
147
|
+
*
|
|
148
|
+
* // Tree-based - custom lookup order
|
|
149
|
+
* const version = getDependencyVersionFromPackageJson(
|
|
150
|
+
* tree,
|
|
151
|
+
* 'pkg',
|
|
152
|
+
* 'package.json',
|
|
153
|
+
* ['devDependencies', 'dependencies', 'peerDependencies']
|
|
154
|
+
* );
|
|
155
|
+
*
|
|
156
|
+
* // Tree-based - with pre-loaded package.json
|
|
157
|
+
* const packageJson = readJson(tree, 'package.json');
|
|
158
|
+
* const version = getDependencyVersionFromPackageJson(
|
|
159
|
+
* tree,
|
|
160
|
+
* 'react',
|
|
161
|
+
* packageJson,
|
|
162
|
+
* ['dependencies']
|
|
163
|
+
* );
|
|
164
|
+
* ```
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```typescript
|
|
168
|
+
* // Filesystem-based - from current directory
|
|
169
|
+
* const reactVersion = getDependencyVersionFromPackageJson('react');
|
|
170
|
+
*
|
|
171
|
+
* // Filesystem-based - with workspace root
|
|
172
|
+
* const version = getDependencyVersionFromPackageJson('react', '/path/to/workspace');
|
|
173
|
+
*
|
|
174
|
+
* // Filesystem-based - with specific package.json and section
|
|
175
|
+
* const version = getDependencyVersionFromPackageJson(
|
|
176
|
+
* 'react',
|
|
177
|
+
* '/path/to/workspace',
|
|
178
|
+
* 'apps/my-app/package.json',
|
|
179
|
+
* ['dependencies']
|
|
180
|
+
* );
|
|
181
|
+
* ```
|
|
182
|
+
*
|
|
183
|
+
* @param dependencyLookup Array of dependency sections to check in order. Defaults to ['dependencies', 'devDependencies']
|
|
184
|
+
* @returns The resolved version string, or `null` if the package is not found in any of the specified sections
|
|
185
|
+
*/
|
|
186
|
+
export declare function getDependencyVersionFromPackageJson(tree: Tree, packageName: string, packageJsonPath?: string, dependencyLookup?: PackageJsonDependencySection[]): string | null;
|
|
187
|
+
export declare function getDependencyVersionFromPackageJson(tree: Tree, packageName: string, packageJson?: PackageJson, dependencyLookup?: PackageJsonDependencySection[]): string | null;
|
|
188
|
+
export declare function getDependencyVersionFromPackageJson(packageName: string, workspaceRootPath?: string, packageJsonPath?: string, dependencyLookup?: PackageJsonDependencySection[]): string | null;
|
|
189
|
+
export declare function getDependencyVersionFromPackageJson(packageName: string, workspaceRootPath?: string, packageJson?: PackageJson, dependencyLookup?: PackageJsonDependencySection[]): string | null;
|
|
111
190
|
export {};
|
|
112
191
|
//# sourceMappingURL=package-json.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"package-json.d.ts","sourceRoot":"","sources":["../../../../../packages/nx/src/utils/package-json.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"package-json.d.ts","sourceRoot":"","sources":["../../../../../packages/nx/src/utils/package-json.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,O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eAAe,EAAE,MAAM,EACvB,YAAY,WAAsB,GACjC;IACD,WAAW,EAAE,WAAW,CAAC;IACzB,IAAI,EAAE,MAAM,CAAC;CACd,CAgCA;AAED,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,MAAM,EACX,eAAe,EAAE,MAAM,GACtB;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CAwCA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwEG;AACH,wBAAgB,mCAAmC,CACjD,IAAI,EAAE,IAAI,EACV,WAAW,EAAE,MAAM,EACnB,eAAe,CAAC,EAAE,MAAM,EACxB,gBAAgB,CAAC,EAAE,4BAA4B,EAAE,GAChD,MAAM,GAAG,IAAI,CAAC;AACjB,wBAAgB,mCAAmC,CACjD,IAAI,EAAE,IAAI,EACV,WAAW,EAAE,MAAM,EACnB,WAAW,CAAC,EAAE,WAAW,EACzB,gBAAgB,CAAC,EAAE,4BAA4B,EAAE,GAChD,MAAM,GAAG,IAAI,CAAC;AACjB,wBAAgB,mCAAmC,CACjD,WAAW,EAAE,MAAM,EACnB,iBAAiB,CAAC,EAAE,MAAM,EAC1B,eAAe,CAAC,EAAE,MAAM,EACxB,gBAAgB,CAAC,EAAE,4BAA4B,EAAE,GAChD,MAAM,GAAG,IAAI,CAAC;AACjB,wBAAgB,mCAAmC,CACjD,WAAW,EAAE,MAAM,EACnB,iBAAiB,CAAC,EAAE,MAAM,EAC1B,WAAW,CAAC,EAAE,WAAW,EACzB,gBAAgB,CAAC,EAAE,4BAA4B,EAAE,GAChD,MAAM,GAAG,IAAI,CAAC"}
|
|
@@ -9,14 +9,18 @@ exports.readTargetsFromPackageJson = readTargetsFromPackageJson;
|
|
|
9
9
|
exports.readModulePackageJsonWithoutFallbacks = readModulePackageJsonWithoutFallbacks;
|
|
10
10
|
exports.readModulePackageJson = readModulePackageJson;
|
|
11
11
|
exports.installPackageToTmp = installPackageToTmp;
|
|
12
|
+
exports.getDependencyVersionFromPackageJson = getDependencyVersionFromPackageJson;
|
|
13
|
+
const child_process_1 = require("child_process");
|
|
12
14
|
const fs_1 = require("fs");
|
|
13
15
|
const path_1 = require("path");
|
|
16
|
+
const tmp_1 = require("tmp");
|
|
17
|
+
const json_1 = require("../generators/utils/json");
|
|
14
18
|
const project_configuration_utils_1 = require("../project-graph/utils/project-configuration-utils");
|
|
19
|
+
const catalog_1 = require("./catalog");
|
|
15
20
|
const fileutils_1 = require("./fileutils");
|
|
16
21
|
const installation_directory_1 = require("./installation-directory");
|
|
17
22
|
const package_manager_1 = require("./package-manager");
|
|
18
|
-
const
|
|
19
|
-
const child_process_1 = require("child_process");
|
|
23
|
+
const workspace_root_1 = require("./workspace-root");
|
|
20
24
|
function normalizePackageGroup(packageGroup) {
|
|
21
25
|
return Array.isArray(packageGroup)
|
|
22
26
|
? packageGroup.map((x) => typeof x === 'string' ? { package: x, version: '*' } : x)
|
|
@@ -228,6 +232,81 @@ function installPackageToTmp(pkg, requiredVersion) {
|
|
|
228
232
|
cleanup,
|
|
229
233
|
};
|
|
230
234
|
}
|
|
235
|
+
function getDependencyVersionFromPackageJson(treeOrPackageName, packageNameOrRoot, packageJsonPathOrObjectOrRoot, dependencyLookup) {
|
|
236
|
+
if (typeof treeOrPackageName !== 'string') {
|
|
237
|
+
return getDependencyVersionFromPackageJsonFromTree(treeOrPackageName, packageNameOrRoot, packageJsonPathOrObjectOrRoot, dependencyLookup);
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
return getDependencyVersionFromPackageJsonFromFileSystem(treeOrPackageName, packageNameOrRoot, packageJsonPathOrObjectOrRoot, dependencyLookup);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Tree-based implementation for getDependencyVersionFromPackageJson
|
|
245
|
+
*/
|
|
246
|
+
function getDependencyVersionFromPackageJsonFromTree(tree, packageName, packageJsonPathOrObject = 'package.json', dependencyLookup = [
|
|
247
|
+
'dependencies',
|
|
248
|
+
'devDependencies',
|
|
249
|
+
]) {
|
|
250
|
+
let packageJson;
|
|
251
|
+
if (typeof packageJsonPathOrObject === 'object') {
|
|
252
|
+
packageJson = packageJsonPathOrObject;
|
|
253
|
+
}
|
|
254
|
+
else if (tree.exists(packageJsonPathOrObject)) {
|
|
255
|
+
packageJson = (0, json_1.readJson)(tree, packageJsonPathOrObject);
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
return null;
|
|
259
|
+
}
|
|
260
|
+
let version = null;
|
|
261
|
+
for (const section of dependencyLookup) {
|
|
262
|
+
const foundVersion = packageJson[section]?.[packageName];
|
|
263
|
+
if (foundVersion) {
|
|
264
|
+
version = foundVersion;
|
|
265
|
+
break;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
// Resolve catalog reference if needed
|
|
269
|
+
const manager = (0, catalog_1.getCatalogManager)(tree.root);
|
|
270
|
+
if (version && manager?.isCatalogReference(version)) {
|
|
271
|
+
version = manager.resolveCatalogReference(tree, packageName, version);
|
|
272
|
+
}
|
|
273
|
+
return version;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Filesystem-based implementation for getDependencyVersionFromPackageJson
|
|
277
|
+
*/
|
|
278
|
+
function getDependencyVersionFromPackageJsonFromFileSystem(packageName, root = workspace_root_1.workspaceRoot, packageJsonPathOrObject = 'package.json', dependencyLookup = [
|
|
279
|
+
'dependencies',
|
|
280
|
+
'devDependencies',
|
|
281
|
+
]) {
|
|
282
|
+
let packageJson;
|
|
283
|
+
if (typeof packageJsonPathOrObject === 'object') {
|
|
284
|
+
packageJson = packageJsonPathOrObject;
|
|
285
|
+
}
|
|
286
|
+
else {
|
|
287
|
+
const packageJsonPath = (0, path_1.resolve)(root, packageJsonPathOrObject);
|
|
288
|
+
if ((0, fs_1.existsSync)(packageJsonPath)) {
|
|
289
|
+
packageJson = (0, fileutils_1.readJsonFile)(packageJsonPath);
|
|
290
|
+
}
|
|
291
|
+
else {
|
|
292
|
+
return null;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
let version = null;
|
|
296
|
+
for (const section of dependencyLookup) {
|
|
297
|
+
const foundVersion = packageJson[section]?.[packageName];
|
|
298
|
+
if (foundVersion) {
|
|
299
|
+
version = foundVersion;
|
|
300
|
+
break;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
// Resolve catalog reference if needed
|
|
304
|
+
const manager = (0, catalog_1.getCatalogManager)(root);
|
|
305
|
+
if (version && manager?.isCatalogReference(version)) {
|
|
306
|
+
version = manager.resolveCatalogReference(packageName, version, root);
|
|
307
|
+
}
|
|
308
|
+
return version;
|
|
309
|
+
}
|
|
231
310
|
/**
|
|
232
311
|
* Generates necessary files needed for the package manager to work
|
|
233
312
|
* and for the node_modules to be accessible.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"package-manager.d.ts","sourceRoot":"","sources":["../../../../../packages/nx/src/utils/package-manager.ts"],"names":[],"mappings":"AA+BA,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,GAAG,KAAK,CAAC;AAE7D,MAAM,WAAW,sBAAsB;IACrC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,MAAM,CAAC;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;IAE/C,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,CACP,WAAW,EAA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1
|
+
{"version":3,"file":"package-manager.d.ts","sourceRoot":"","sources":["../../../../../packages/nx/src/utils/package-manager.ts"],"names":[],"mappings":"AA+BA,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,GAAG,KAAK,CAAC;AAE7D,MAAM,WAAW,sBAAsB;IACrC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,MAAM,CAAC;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;IAE/C,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,CACP,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,EAChB,iBAAiB,EAAE,MAAM,EACzB,GAAG,EAAE,MAAM,KACR,MAAM,CAAC;IAEZ,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,GAAE,MAAW,GAAG,cAAc,CAYrE;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,cAAc,GAAE,cAAuC,EACvD,IAAI,GAAE,MAAsB,GAC3B,OAAO,CAmBT;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,wBAAwB,CACtC,cAAc,GAAE,cAAuC,EACvD,IAAI,GAAE,MAAsB,GAC3B,sBAAsB,CA8HxB;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CACtC,cAAc,GAAE,cAAuC,EACvD,GAAG,SAAgB,GAClB,MAAM,CAwBR;AAED,wBAAgB,mCAAm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AW,EAAE,MAAM,EACnB,cAAc,GAAE,cAAuC,EACvD,UAAU,GAAE,MAAM,EAAyC,EAC3D,IAAI,GAAE,MAAsB,GAC3B,IAAI,CAiEN"}
|
|
@@ -18,14 +18,15 @@ exports.getPackageWorkspaces = getPackageWorkspaces;
|
|
|
18
18
|
exports.addPackagePathToWorkspaces = addPackagePathToWorkspaces;
|
|
19
19
|
const child_process_1 = require("child_process");
|
|
20
20
|
const fs_1 = require("fs");
|
|
21
|
-
const yaml_1 = require("yaml");
|
|
22
21
|
const promises_1 = require("node:fs/promises");
|
|
23
22
|
const path_1 = require("path");
|
|
24
23
|
const semver_1 = require("semver");
|
|
25
24
|
const tmp_1 = require("tmp");
|
|
26
25
|
const util_1 = require("util");
|
|
26
|
+
const yaml_1 = require("yaml");
|
|
27
27
|
const configuration_1 = require("../config/configuration");
|
|
28
28
|
const file_utils_1 = require("../project-graph/file-utils");
|
|
29
|
+
const catalog_1 = require("./catalog");
|
|
29
30
|
const fileutils_1 = require("./fileutils");
|
|
30
31
|
const installation_directory_1 = require("./installation-directory");
|
|
31
32
|
const package_json_1 = require("./package-json");
|
|
@@ -366,9 +367,17 @@ function createTempNpmDirectory(skipCopy = false) {
|
|
|
366
367
|
*/
|
|
367
368
|
async function resolvePackageVersionUsingRegistry(packageName, version) {
|
|
368
369
|
try {
|
|
369
|
-
|
|
370
|
+
let resolvedVersion = version;
|
|
371
|
+
const manager = (0, catalog_1.getCatalogManager)(workspace_root_1.workspaceRoot);
|
|
372
|
+
if (manager?.isCatalogReference(version)) {
|
|
373
|
+
resolvedVersion = manager.resolveCatalogReference(packageName, version, workspace_root_1.workspaceRoot);
|
|
374
|
+
if (!resolvedVersion) {
|
|
375
|
+
throw new Error(`Unable to resolve catalog reference ${packageName}@${version}.`);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
const result = await packageRegistryView(packageName, resolvedVersion, 'version');
|
|
370
379
|
if (!result) {
|
|
371
|
-
throw new Error(`Unable to resolve version ${packageName}@${
|
|
380
|
+
throw new Error(`Unable to resolve version ${packageName}@${resolvedVersion}.`);
|
|
372
381
|
}
|
|
373
382
|
const lines = result.split('\n');
|
|
374
383
|
if (lines.length === 1) {
|
|
@@ -381,12 +390,12 @@ async function resolvePackageVersionUsingRegistry(packageName, version) {
|
|
|
381
390
|
*
|
|
382
391
|
* <package>@<version> '<version>'
|
|
383
392
|
*/
|
|
384
|
-
const
|
|
393
|
+
const finalResolvedVersion = lines
|
|
385
394
|
.map((line) => line.split(' ')[1])
|
|
386
395
|
.sort()
|
|
387
396
|
.pop()
|
|
388
397
|
.replace(/'/g, '');
|
|
389
|
-
return
|
|
398
|
+
return finalResolvedVersion;
|
|
390
399
|
}
|
|
391
400
|
catch {
|
|
392
401
|
throw new Error(`Unable to resolve version ${packageName}@${version}.`);
|
|
@@ -400,8 +409,16 @@ async function resolvePackageVersionUsingRegistry(packageName, version) {
|
|
|
400
409
|
async function resolvePackageVersionUsingInstallation(packageName, version) {
|
|
401
410
|
const { dir, cleanup } = createTempNpmDirectory();
|
|
402
411
|
try {
|
|
412
|
+
let resolvedVersion = version;
|
|
413
|
+
const manager = (0, catalog_1.getCatalogManager)(workspace_root_1.workspaceRoot);
|
|
414
|
+
if (manager.isCatalogReference(version)) {
|
|
415
|
+
resolvedVersion = manager.resolveCatalogReference(packageName, version, workspace_root_1.workspaceRoot);
|
|
416
|
+
if (!resolvedVersion) {
|
|
417
|
+
throw new Error(`Unable to resolve catalog reference ${packageName}@${version}.`);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
403
420
|
const pmc = getPackageManagerCommand();
|
|
404
|
-
await execAsync(`${pmc.add} ${packageName}@${
|
|
421
|
+
await execAsync(`${pmc.add} ${packageName}@${resolvedVersion}`, {
|
|
405
422
|
cwd: dir,
|
|
406
423
|
windowsHide: true,
|
|
407
424
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pnpm-workspace.d.ts","sourceRoot":"","sources":["../../../../../packages/nx/src/utils/pnpm-workspace.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC/B,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAAC;CAC/B;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,OAAO,CAAC,EAAE,gBAAgB,CAAC;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;CAC7C"}
|