nx 23.1.0 → 23.2.0-beta.1
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 -1
- package/dist/src/ai/configure-ai-agents-disclaimer.d.ts +5 -0
- package/dist/src/ai/configure-ai-agents-disclaimer.js +31 -0
- package/dist/src/command-line/add/add.js +8 -1
- package/dist/src/command-line/import/import.js +1 -1
- package/dist/src/command-line/init/ai-agent-prompts.d.ts +1 -1
- package/dist/src/command-line/init/ai-agent-prompts.js +7 -6
- package/dist/src/command-line/init/command-object.js +10 -2
- package/dist/src/command-line/init/configure-plugins.js +3 -2
- package/dist/src/command-line/init/implementation/add-nx-to-monorepo.js +4 -2
- package/dist/src/command-line/init/implementation/add-nx-to-nest.js +4 -3
- package/dist/src/command-line/init/implementation/add-nx-to-npm-repo.js +4 -3
- package/dist/src/command-line/init/implementation/add-nx-to-turborepo.js +4 -3
- package/dist/src/command-line/init/implementation/angular/index.js +4 -2
- package/dist/src/command-line/init/implementation/utils.d.ts +3 -3
- package/dist/src/command-line/init/implementation/utils.js +22 -3
- package/dist/src/command-line/migrate/execute-migration.d.ts +72 -0
- package/dist/src/command-line/migrate/execute-migration.js +389 -0
- package/dist/src/command-line/migrate/migrate-ui-api.js +17 -12
- package/dist/src/command-line/migrate/migrate.d.ts +14 -45
- package/dist/src/command-line/migrate/migrate.js +58 -375
- package/dist/src/command-line/release/utils/git.js +6 -2
- package/dist/src/command-line/release/utils/release-graph.d.ts +2 -2
- package/dist/src/command-line/release/utils/shared.d.ts +2 -2
- package/dist/src/command-line/show/show-target/info.js +11 -2
- package/dist/src/commands-runner/create-command-graph.js +5 -0
- package/dist/src/config/nx-json.d.ts +1 -1
- package/dist/src/core/graph/main.js +1 -1
- package/dist/src/daemon/client/client.d.ts +0 -2
- package/dist/src/daemon/client/client.js +17 -19
- package/dist/src/devkit-internals.d.ts +2 -0
- package/dist/src/devkit-internals.js +7 -1
- package/dist/src/generators/utils/nx-json.js +13 -3
- package/dist/src/native/index.d.ts +1 -1
- 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/lock-file/npm-parser.js +71 -27
- package/dist/src/plugins/js/lock-file/pnpm-parser.js +46 -15
- package/dist/src/plugins/js/lock-file/project-graph-pruning.js +1 -1
- package/dist/src/plugins/js/lock-file/yarn-parser.js +32 -5
- package/dist/src/plugins/js/utils/register.d.ts +18 -0
- package/dist/src/plugins/js/utils/register.js +81 -0
- package/dist/src/plugins/js/utils/typescript.d.ts +9 -0
- package/dist/src/plugins/js/utils/typescript.js +15 -0
- package/dist/src/project-graph/error-types.js +41 -1
- package/dist/src/project-graph/file-utils.js +6 -1
- package/dist/src/project-graph/plugins/isolation/isolated-plugin.js +4 -0
- package/dist/src/project-graph/plugins/transpiler.js +4 -0
- package/dist/src/project-graph/utils/project-configuration/name-substitution-manager.d.ts +9 -12
- package/dist/src/project-graph/utils/project-configuration/name-substitution-manager.js +77 -61
- package/dist/src/project-graph/utils/project-configuration/project-nodes-manager.d.ts +1 -1
- package/dist/src/project-graph/utils/project-configuration/project-nodes-manager.js +1 -1
- package/dist/src/project-graph/utils/project-configuration-utils.js +4 -6
- package/dist/src/tasks-runner/life-cycles/performance-analysis.d.ts +11 -4
- package/dist/src/tasks-runner/life-cycles/performance-analysis.js +15 -6
- package/dist/src/tasks-runner/life-cycles/performance-life-cycle.js +5 -4
- package/dist/src/tasks-runner/life-cycles/performance-report.d.ts +18 -8
- package/dist/src/tasks-runner/life-cycles/performance-report.js +66 -29
- package/dist/src/tasks-runner/run-command.js +5 -3
- package/dist/src/utils/acknowledge-build-scripts.d.ts +13 -0
- package/dist/src/utils/acknowledge-build-scripts.js +100 -0
- package/dist/src/utils/catalog/manager-utils.d.ts +1 -2
- package/dist/src/utils/catalog/manager-utils.js +22 -5
- package/dist/src/utils/catalog/pnpm-manager.d.ts +1 -0
- package/dist/src/utils/catalog/pnpm-manager.js +3 -15
- package/dist/src/utils/catalog/yarn-manager.d.ts +1 -0
- package/dist/src/utils/catalog/yarn-manager.js +3 -15
- package/dist/src/utils/command-line-utils.js +30 -20
- package/dist/src/utils/git-revision.d.ts +12 -0
- package/dist/src/utils/git-revision.js +25 -0
- package/dist/src/utils/git-utils.d.ts +2 -3
- package/dist/src/utils/git-utils.js +101 -47
- package/dist/src/utils/min-release-age/behavior/pnpm.js +9 -7
- package/dist/src/utils/package-manager.js +6 -2
- package/dist/src/utils/provenance.js +12 -2
- package/migrations.json +7 -1
- package/package.json +11 -11
- package/dist/src/migrations/update-17-3-0/nx-release-path.d.ts +0 -3
- package/dist/src/migrations/update-17-3-0/nx-release-path.js +0 -47
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getNgCompatLayer = exports.MigrationImplementationMissingError = exports.ChangedDepInstaller = exports.NpmPeerDepsInstallError = void 0;
|
|
4
|
+
exports.readPackageMigrationConfig = readPackageMigrationConfig;
|
|
5
|
+
exports.runInstall = runInstall;
|
|
6
|
+
exports.isNpmPeerDepsError = isNpmPeerDepsError;
|
|
7
|
+
exports.logNpmPeerDepsError = logNpmPeerDepsError;
|
|
8
|
+
exports.runNxOrAngularMigration = runNxOrAngularMigration;
|
|
9
|
+
exports.getStringifiedPackageJsonDeps = getStringifiedPackageJsonDeps;
|
|
10
|
+
exports.runNxMigration = runNxMigration;
|
|
11
|
+
exports.parseMigrationReturn = parseMigrationReturn;
|
|
12
|
+
exports.filterStrings = filterStrings;
|
|
13
|
+
exports.readMigrationCollection = readMigrationCollection;
|
|
14
|
+
exports.getImplementationPath = getImplementationPath;
|
|
15
|
+
exports.isAngularMigration = isAngularMigration;
|
|
16
|
+
const tslib_1 = require("tslib");
|
|
17
|
+
const pc = tslib_1.__importStar(require("picocolors"));
|
|
18
|
+
const child_process_1 = require("child_process");
|
|
19
|
+
const path_1 = require("path");
|
|
20
|
+
const semver_1 = require("semver");
|
|
21
|
+
const handle_import_1 = require("../../utils/handle-import");
|
|
22
|
+
const tree_1 = require("../../generators/tree");
|
|
23
|
+
const fileutils_1 = require("../../utils/fileutils");
|
|
24
|
+
const logger_1 = require("../../utils/logger");
|
|
25
|
+
const package_json_1 = require("../../utils/package-json");
|
|
26
|
+
const package_manager_1 = require("../../utils/package-manager");
|
|
27
|
+
const output_1 = require("../../utils/output");
|
|
28
|
+
const fs_1 = require("fs");
|
|
29
|
+
const installation_directory_1 = require("../../utils/installation-directory");
|
|
30
|
+
const project_graph_1 = require("../../project-graph/project-graph");
|
|
31
|
+
const version_utils_1 = require("./version-utils");
|
|
32
|
+
function readPackageMigrationConfig(packageName, dir) {
|
|
33
|
+
const { path: packageJsonPath, packageJson: json } = (0, package_json_1.readModulePackageJson)(packageName, (0, installation_directory_1.getNxRequirePaths)(dir));
|
|
34
|
+
const config = (0, package_json_1.readNxMigrateConfig)(json);
|
|
35
|
+
if (!config) {
|
|
36
|
+
return { packageJson: json, migrations: null, packageGroup: [] };
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
const migrationFile = require.resolve(config.migrations, {
|
|
40
|
+
paths: [(0, path_1.dirname)(packageJsonPath)],
|
|
41
|
+
});
|
|
42
|
+
return {
|
|
43
|
+
packageJson: json,
|
|
44
|
+
migrations: migrationFile,
|
|
45
|
+
packageGroup: config.packageGroup,
|
|
46
|
+
supportsOptionalMigrations: config.supportsOptionalMigrations,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return {
|
|
51
|
+
packageJson: json,
|
|
52
|
+
migrations: null,
|
|
53
|
+
packageGroup: config.packageGroup,
|
|
54
|
+
supportsOptionalMigrations: config.supportsOptionalMigrations,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function runInstall(nxWorkspaceRoot, phase = 'pre-migration') {
|
|
59
|
+
const cwd = nxWorkspaceRoot ?? process.cwd();
|
|
60
|
+
const packageManager = (0, package_manager_1.detectPackageManager)(cwd);
|
|
61
|
+
const pmCommands = (0, package_manager_1.getPackageManagerCommand)(packageManager, cwd);
|
|
62
|
+
const installCommand = `${pmCommands.install} ${pmCommands.ignoreScriptsFlag ?? ''}`;
|
|
63
|
+
output_1.output.log({
|
|
64
|
+
title: `Running '${installCommand}' to make sure necessary packages are installed`,
|
|
65
|
+
});
|
|
66
|
+
return new Promise((resolve, reject) => {
|
|
67
|
+
// For npm, pipe stderr so we can detect peer dependency errors while still
|
|
68
|
+
// mirroring it live to the user's terminal. Other package managers inherit
|
|
69
|
+
// stderr directly since we don't need to inspect their output.
|
|
70
|
+
const shouldCaptureStderr = packageManager === 'npm';
|
|
71
|
+
const child = (0, child_process_1.spawn)(installCommand, {
|
|
72
|
+
shell: true,
|
|
73
|
+
stdio: ['inherit', 'inherit', shouldCaptureStderr ? 'pipe' : 'inherit'],
|
|
74
|
+
windowsHide: true,
|
|
75
|
+
cwd,
|
|
76
|
+
});
|
|
77
|
+
const stderrChunks = [];
|
|
78
|
+
child.stderr?.on('data', (chunk) => {
|
|
79
|
+
process.stderr.write(chunk);
|
|
80
|
+
stderrChunks.push(chunk);
|
|
81
|
+
});
|
|
82
|
+
child.on('error', reject);
|
|
83
|
+
child.on('close', (code) => {
|
|
84
|
+
if (code === 0) {
|
|
85
|
+
resolve();
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (shouldCaptureStderr) {
|
|
89
|
+
const stderr = Buffer.concat(stderrChunks).toString().trim();
|
|
90
|
+
if (isNpmPeerDepsError(stderr)) {
|
|
91
|
+
// Log the remediation guidance here so every caller of `runInstall`
|
|
92
|
+
// (CLI migrate, `nx repair`, single-migration runner, etc.) surfaces
|
|
93
|
+
// it consistently. Top-level callers catch `NpmPeerDepsInstallError`
|
|
94
|
+
// and return a non-zero exit code without re-logging.
|
|
95
|
+
logNpmPeerDepsError(phase);
|
|
96
|
+
reject(new NpmPeerDepsInstallError());
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
reject(new Error(`Command failed: ${installCommand}`));
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
class NpmPeerDepsInstallError extends Error {
|
|
105
|
+
constructor() {
|
|
106
|
+
super('npm install failed due to peer dependency conflicts.');
|
|
107
|
+
this.name = 'NpmPeerDepsInstallError';
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
exports.NpmPeerDepsInstallError = NpmPeerDepsInstallError;
|
|
111
|
+
/**
|
|
112
|
+
* Detects npm peer-dependency resolution failures. Keyed on the `ERESOLVE`
|
|
113
|
+
* error code, which npm consistently emits for this class of failure across
|
|
114
|
+
* v7+ (`npm ERR! code ERESOLVE` / `npm error code ERESOLVE`). Falls back to a
|
|
115
|
+
* small set of stable phrases in case the code line is missing from the
|
|
116
|
+
* captured output.
|
|
117
|
+
*/
|
|
118
|
+
function isNpmPeerDepsError(stderr) {
|
|
119
|
+
if (/\bERESOLVE\b/.test(stderr)) {
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
const lowerStderr = stderr.toLowerCase();
|
|
123
|
+
return (lowerStderr.includes('unable to resolve dependency tree') ||
|
|
124
|
+
lowerStderr.includes('could not resolve dependency') ||
|
|
125
|
+
lowerStderr.includes('conflicting peer dependency'));
|
|
126
|
+
}
|
|
127
|
+
function logNpmPeerDepsError(phase) {
|
|
128
|
+
const peerDepsResolutionSteps = [
|
|
129
|
+
'Recommended approaches (in order of preference):',
|
|
130
|
+
'',
|
|
131
|
+
'1. Use "overrides" in package.json to force compatible versions across the dependency tree.',
|
|
132
|
+
' See https://docs.npmjs.com/cli/configuring-npm/package-json#overrides',
|
|
133
|
+
'2. Persist legacy peer deps resolution in the project ".npmrc":',
|
|
134
|
+
' npm config set legacy-peer-deps=true --location=project',
|
|
135
|
+
' (bypasses peer dependency resolution; use with caution)',
|
|
136
|
+
'3. As a last resort, force the installation by running "npm install --force".',
|
|
137
|
+
' (does not persist and may produce broken installs)',
|
|
138
|
+
];
|
|
139
|
+
const manualInstallHint = [
|
|
140
|
+
'If you installed the dependencies manually, pass "--skip-install" to avoid re-installing them:',
|
|
141
|
+
' nx migrate --run-migrations --skip-install',
|
|
142
|
+
];
|
|
143
|
+
if (phase === 'pre-migration') {
|
|
144
|
+
output_1.output.error({
|
|
145
|
+
title: 'You need to resolve the peer dependency conflicts before the migration can continue',
|
|
146
|
+
bodyLines: [
|
|
147
|
+
...peerDepsResolutionSteps,
|
|
148
|
+
'',
|
|
149
|
+
'Once the conflicts are resolved, re-run the migrations:',
|
|
150
|
+
' nx migrate --run-migrations',
|
|
151
|
+
'',
|
|
152
|
+
...manualInstallHint,
|
|
153
|
+
],
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
output_1.output.error({
|
|
158
|
+
title: 'Some migrations have been applied, but installing the updated dependencies failed',
|
|
159
|
+
bodyLines: [
|
|
160
|
+
...peerDepsResolutionSteps,
|
|
161
|
+
'',
|
|
162
|
+
'Once the conflicts are resolved, run "npm install" to install the updated dependencies.',
|
|
163
|
+
'If the migration was interrupted before completing, re-run the remaining migrations:',
|
|
164
|
+
' nx migrate --run-migrations',
|
|
165
|
+
'',
|
|
166
|
+
...manualInstallHint,
|
|
167
|
+
],
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
class ChangedDepInstaller {
|
|
172
|
+
constructor(root, shouldSkipInstall = false) {
|
|
173
|
+
this.root = root;
|
|
174
|
+
this.shouldSkipInstall = shouldSkipInstall;
|
|
175
|
+
this._skippedInstall = false;
|
|
176
|
+
this.initialDeps = getStringifiedPackageJsonDeps(root);
|
|
177
|
+
}
|
|
178
|
+
get skippedInstall() {
|
|
179
|
+
return this._skippedInstall;
|
|
180
|
+
}
|
|
181
|
+
async installDepsIfChanged() {
|
|
182
|
+
const currentDeps = getStringifiedPackageJsonDeps(this.root);
|
|
183
|
+
if (this.initialDeps !== currentDeps) {
|
|
184
|
+
if (this.shouldSkipInstall) {
|
|
185
|
+
this._skippedInstall = true;
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
await runInstall(this.root, 'post-migration');
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
this.initialDeps = currentDeps;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
exports.ChangedDepInstaller = ChangedDepInstaller;
|
|
195
|
+
async function runNxOrAngularMigration(root, migration, isVerbose, captureGeneratorOutput = false, resolvedCollection) {
|
|
196
|
+
const { collection, collectionPath } = resolvedCollection ?? readMigrationCollection(migration.package, root);
|
|
197
|
+
let changes = [];
|
|
198
|
+
let nextSteps = [];
|
|
199
|
+
let agentContext = [];
|
|
200
|
+
let logs = '';
|
|
201
|
+
// Angular's `ngResult.changes` is synthesized from the schematic's
|
|
202
|
+
// DryRunEvent stream so Nx and Angular paths can share commit/validation
|
|
203
|
+
// gating via `changes.length > 0`.
|
|
204
|
+
let madeChanges = false;
|
|
205
|
+
logger_1.logger.info(pc.dim('→ Running generator…'));
|
|
206
|
+
if (!isAngularMigration(collection, migration.name)) {
|
|
207
|
+
({ nextSteps, changes, agentContext, logs } = await runNxMigration(root, collectionPath, collection, migration.name, migration.version, captureGeneratorOutput));
|
|
208
|
+
madeChanges = changes.length > 0;
|
|
209
|
+
logger_1.logger.info(`Ran ${migration.name} from ${migration.package}`);
|
|
210
|
+
if (migration.description) {
|
|
211
|
+
logger_1.logger.info(` ${migration.description}`);
|
|
212
|
+
}
|
|
213
|
+
logger_1.logger.info('');
|
|
214
|
+
if (!madeChanges) {
|
|
215
|
+
logger_1.logger.info(`No changes were made\n`);
|
|
216
|
+
return { changes, nextSteps, agentContext, logs, madeChanges };
|
|
217
|
+
}
|
|
218
|
+
logger_1.logger.info('Changes:');
|
|
219
|
+
(0, tree_1.printChanges)(changes, ' ');
|
|
220
|
+
logger_1.logger.info('');
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
const ngCliAdapter = await (0, exports.getNgCompatLayer)();
|
|
224
|
+
const migrationProjectGraph = await (0, project_graph_1.createProjectGraphAsync)();
|
|
225
|
+
const ngResult = await ngCliAdapter.runMigration(root, migration.package, migration.name, (0, project_graph_1.readProjectsConfigurationFromProjectGraph)(migrationProjectGraph).projects, isVerbose, migrationProjectGraph);
|
|
226
|
+
changes = ngResult.changes;
|
|
227
|
+
madeChanges = ngResult.madeChanges;
|
|
228
|
+
logs = ngResult.loggingQueue.join('\n');
|
|
229
|
+
logger_1.logger.info(`Ran ${migration.name} from ${migration.package}`);
|
|
230
|
+
if (migration.description) {
|
|
231
|
+
logger_1.logger.info(` ${migration.description}`);
|
|
232
|
+
}
|
|
233
|
+
logger_1.logger.info('');
|
|
234
|
+
if (!madeChanges) {
|
|
235
|
+
logger_1.logger.info(`No changes were made\n`);
|
|
236
|
+
return { changes, nextSteps, agentContext, logs, madeChanges };
|
|
237
|
+
}
|
|
238
|
+
logger_1.logger.info('Changes:');
|
|
239
|
+
ngResult.loggingQueue.forEach((log) => logger_1.logger.info(' ' + log));
|
|
240
|
+
logger_1.logger.info('');
|
|
241
|
+
}
|
|
242
|
+
return { changes, nextSteps, agentContext, logs, madeChanges };
|
|
243
|
+
}
|
|
244
|
+
function getStringifiedPackageJsonDeps(root) {
|
|
245
|
+
try {
|
|
246
|
+
const { dependencies, devDependencies } = (0, fileutils_1.readJsonFile)((0, path_1.join)(root, 'package.json'));
|
|
247
|
+
return JSON.stringify([dependencies, devDependencies]);
|
|
248
|
+
}
|
|
249
|
+
catch {
|
|
250
|
+
// We don't really care if the .nx/installation property changes,
|
|
251
|
+
// whenever nxw is invoked it will handle the dep updates.
|
|
252
|
+
return '';
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
async function runNxMigration(root, collectionPath, collection, name, migrationVersion, captureGeneratorOutput) {
|
|
256
|
+
const { path: implPath, fnSymbol } = getImplementationPath(collection, collectionPath, name, migrationVersion);
|
|
257
|
+
const fn = require(implPath)[fnSymbol];
|
|
258
|
+
const host = new tree_1.FsTree(root, process.env.NX_VERBOSE_LOGGING === 'true', `migration ${collection.name}:${name}`);
|
|
259
|
+
let result;
|
|
260
|
+
let logs = '';
|
|
261
|
+
if (captureGeneratorOutput) {
|
|
262
|
+
const { withGeneratorOutputCapture } = require('./agentic/capture-generator-output');
|
|
263
|
+
({ result, logs } = await withGeneratorOutputCapture(() => fn(host, {})));
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
result = await fn(host, {});
|
|
267
|
+
}
|
|
268
|
+
const { nextSteps, agentContext } = parseMigrationReturn(result);
|
|
269
|
+
host.lock();
|
|
270
|
+
const changes = host.listChanges();
|
|
271
|
+
(0, tree_1.flushChanges)(root, changes);
|
|
272
|
+
return { changes, nextSteps, agentContext, logs };
|
|
273
|
+
}
|
|
274
|
+
function parseMigrationReturn(value) {
|
|
275
|
+
if (Array.isArray(value)) {
|
|
276
|
+
return { nextSteps: filterStrings(value), agentContext: [] };
|
|
277
|
+
}
|
|
278
|
+
if (value && typeof value === 'object') {
|
|
279
|
+
const obj = value;
|
|
280
|
+
return {
|
|
281
|
+
nextSteps: filterStrings(obj.nextSteps),
|
|
282
|
+
agentContext: filterStrings(obj.agentContext),
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
// Catches `void`, mistakenly-returned generator callbacks, malformed values.
|
|
286
|
+
return { nextSteps: [], agentContext: [] };
|
|
287
|
+
}
|
|
288
|
+
// Bucket-level tolerance: a single non-string entry shouldn't discard the
|
|
289
|
+
// whole `nextSteps` / `agentContext` array. Migration authors occasionally
|
|
290
|
+
// push `null` / `undefined` / a number into the array; we drop the bad entries
|
|
291
|
+
// and keep the rest so end-of-run guidance isn't silently lost.
|
|
292
|
+
function filterStrings(value) {
|
|
293
|
+
if (!Array.isArray(value))
|
|
294
|
+
return [];
|
|
295
|
+
return value.filter((v) => typeof v === 'string');
|
|
296
|
+
}
|
|
297
|
+
function readMigrationCollection(packageName, root) {
|
|
298
|
+
const collectionPath = readPackageMigrationConfig(packageName, root).migrations;
|
|
299
|
+
const collection = (0, fileutils_1.readJsonFile)(collectionPath);
|
|
300
|
+
collection.name ??= packageName;
|
|
301
|
+
return {
|
|
302
|
+
collection,
|
|
303
|
+
collectionPath,
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
function getImplementationPath(collection, collectionPath, name, migrationVersion) {
|
|
307
|
+
const g = collection.generators?.[name] || collection.schematics?.[name];
|
|
308
|
+
if (!g) {
|
|
309
|
+
throw new MigrationImplementationMissingError(`Unable to determine implementation path for "${collectionPath}:${name}"`, collectionPath, migrationVersion);
|
|
310
|
+
}
|
|
311
|
+
const implRelativePathAndMaybeSymbol = g.implementation || g.factory;
|
|
312
|
+
const [implRelativePath, fnSymbol = 'default'] = implRelativePathAndMaybeSymbol.split('#');
|
|
313
|
+
let implPath;
|
|
314
|
+
try {
|
|
315
|
+
implPath = require.resolve(implRelativePath, {
|
|
316
|
+
paths: [(0, path_1.dirname)(collectionPath)],
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
catch (e) {
|
|
320
|
+
try {
|
|
321
|
+
// workaround for a bug in node 12
|
|
322
|
+
implPath = require.resolve(`${(0, path_1.dirname)(collectionPath)}/${implRelativePath}`);
|
|
323
|
+
}
|
|
324
|
+
catch {
|
|
325
|
+
throw new MigrationImplementationMissingError(`Could not resolve implementation for migration "${name}" from "${collectionPath}"`, collectionPath, migrationVersion ?? g.version);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
return { path: implPath, fnSymbol };
|
|
329
|
+
}
|
|
330
|
+
class MigrationImplementationMissingError extends Error {
|
|
331
|
+
constructor(baseMessage, collectionPath, migrationVersion) {
|
|
332
|
+
super(buildMigrationMissingMessage(baseMessage, collectionPath, migrationVersion));
|
|
333
|
+
this.name = 'MigrationImplementationMissingError';
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
exports.MigrationImplementationMissingError = MigrationImplementationMissingError;
|
|
337
|
+
function buildMigrationMissingMessage(baseMessage, collectionPath, migrationVersion) {
|
|
338
|
+
if (!migrationVersion) {
|
|
339
|
+
return baseMessage;
|
|
340
|
+
}
|
|
341
|
+
try {
|
|
342
|
+
const packageJsonPath = (0, path_1.join)((0, path_1.dirname)(collectionPath), 'package.json');
|
|
343
|
+
if (!(0, fs_1.existsSync)(packageJsonPath)) {
|
|
344
|
+
return baseMessage;
|
|
345
|
+
}
|
|
346
|
+
const packageJson = (0, fileutils_1.readJsonFile)(packageJsonPath);
|
|
347
|
+
const installedVersion = packageJson.version;
|
|
348
|
+
if (installedVersion &&
|
|
349
|
+
(0, semver_1.lt)((0, version_utils_1.normalizeVersion)(installedVersion), (0, version_utils_1.normalizeVersion)(migrationVersion))) {
|
|
350
|
+
const packageManager = (0, package_manager_1.detectPackageManager)();
|
|
351
|
+
const pmc = (0, package_manager_1.getPackageManagerCommand)(packageManager);
|
|
352
|
+
const overrideFieldName = getOverrideFieldName(packageManager);
|
|
353
|
+
return (`${baseMessage}\n\n` +
|
|
354
|
+
`The installed version of "${packageJson.name}" is ${installedVersion}, ` +
|
|
355
|
+
`but this migration requires version ${migrationVersion}. ` +
|
|
356
|
+
`This likely means the package version is being held back by an ${overrideFieldName} ` +
|
|
357
|
+
`in your package.json. ` +
|
|
358
|
+
`Remove the ${overrideFieldName} and run "${pmc.install}" to install the correct version.`);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
catch {
|
|
362
|
+
// Fall through to return the base message if we can't read package info
|
|
363
|
+
}
|
|
364
|
+
return baseMessage;
|
|
365
|
+
}
|
|
366
|
+
function getOverrideFieldName(packageManager) {
|
|
367
|
+
switch (packageManager) {
|
|
368
|
+
case 'pnpm':
|
|
369
|
+
return '"pnpm.overrides"';
|
|
370
|
+
case 'yarn':
|
|
371
|
+
return '"resolutions"';
|
|
372
|
+
case 'npm':
|
|
373
|
+
case 'bun':
|
|
374
|
+
return '"overrides"';
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
function isAngularMigration(collection, name) {
|
|
378
|
+
return !collection.generators?.[name] && collection.schematics?.[name];
|
|
379
|
+
}
|
|
380
|
+
exports.getNgCompatLayer = (() => {
|
|
381
|
+
let _ngCliAdapter;
|
|
382
|
+
return async function getNgCompatLayer() {
|
|
383
|
+
if (!_ngCliAdapter) {
|
|
384
|
+
_ngCliAdapter = await (0, handle_import_1.handleImport)('../../adapter/ngcli-adapter.js', __dirname);
|
|
385
|
+
require('../../adapter/compat');
|
|
386
|
+
}
|
|
387
|
+
return _ngCliAdapter;
|
|
388
|
+
};
|
|
389
|
+
})();
|
|
@@ -19,6 +19,7 @@ exports.stopMigration = stopMigration;
|
|
|
19
19
|
const child_process_1 = require("child_process");
|
|
20
20
|
const fs_1 = require("fs");
|
|
21
21
|
const path_1 = require("path");
|
|
22
|
+
const git_revision_1 = require("../../utils/git-revision");
|
|
22
23
|
const migrate_1 = require("./migrate");
|
|
23
24
|
Object.defineProperty(exports, "isHybridMigration", { enumerable: true, get: function () { return migrate_1.isHybridMigration; } });
|
|
24
25
|
Object.defineProperty(exports, "isPromptOnlyMigration", { enumerable: true, get: function () { return migrate_1.isPromptOnlyMigration; } });
|
|
@@ -51,6 +52,9 @@ function finishMigrationProcess(workspacePath, squashCommits, commitMessage) {
|
|
|
51
52
|
const migrationsJsonPath = (0, path_1.join)(workspacePath, 'migrations.json');
|
|
52
53
|
const parsedMigrationsJson = JSON.parse((0, fs_1.readFileSync)(migrationsJsonPath, 'utf-8'));
|
|
53
54
|
const initialGitRef = parsedMigrationsJson['nx-console'].initialGitRef;
|
|
55
|
+
if (squashCommits && initialGitRef) {
|
|
56
|
+
(0, git_revision_1.assertValidGitSha)(initialGitRef.ref);
|
|
57
|
+
}
|
|
54
58
|
if ((0, fs_1.existsSync)(migrationsJsonPath)) {
|
|
55
59
|
(0, fs_1.rmSync)(migrationsJsonPath);
|
|
56
60
|
}
|
|
@@ -59,24 +63,24 @@ function finishMigrationProcess(workspacePath, squashCommits, commitMessage) {
|
|
|
59
63
|
encoding: 'utf-8',
|
|
60
64
|
windowsHide: true,
|
|
61
65
|
});
|
|
62
|
-
(
|
|
63
|
-
cwd: workspacePath,
|
|
64
|
-
encoding: 'utf-8',
|
|
65
|
-
windowsHide: true,
|
|
66
|
-
});
|
|
66
|
+
commit(workspacePath, commitMessage);
|
|
67
67
|
if (squashCommits && initialGitRef) {
|
|
68
|
-
(0, child_process_1.
|
|
69
|
-
cwd: workspacePath,
|
|
70
|
-
encoding: 'utf-8',
|
|
71
|
-
windowsHide: true,
|
|
72
|
-
});
|
|
73
|
-
(0, child_process_1.execSync)(`git commit -m "${commitMessage}" --no-verify`, {
|
|
68
|
+
(0, child_process_1.execFileSync)('git', ['reset', '--soft', initialGitRef.ref], {
|
|
74
69
|
cwd: workspacePath,
|
|
75
70
|
encoding: 'utf-8',
|
|
76
71
|
windowsHide: true,
|
|
77
72
|
});
|
|
73
|
+
commit(workspacePath, commitMessage);
|
|
78
74
|
}
|
|
79
75
|
}
|
|
76
|
+
function commit(workspacePath, commitMessage) {
|
|
77
|
+
(0, child_process_1.execSync)('git commit --no-verify -F -', {
|
|
78
|
+
cwd: workspacePath,
|
|
79
|
+
encoding: 'utf-8',
|
|
80
|
+
windowsHide: true,
|
|
81
|
+
input: commitMessage,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
80
84
|
async function runSingleMigration(workspacePath, migration, configuration) {
|
|
81
85
|
try {
|
|
82
86
|
// Set current migration tracking
|
|
@@ -342,7 +346,8 @@ function undoMigration(workspacePath, id) {
|
|
|
342
346
|
// `existing.ref` is the unmodified HEAD at run time, so `ref^` would
|
|
343
347
|
// reset past unrelated history. Only flip the metadata to skipped.
|
|
344
348
|
if (existing.changedFiles.length > 0) {
|
|
345
|
-
(0,
|
|
349
|
+
(0, git_revision_1.assertValidGitSha)(existing.ref);
|
|
350
|
+
(0, child_process_1.execFileSync)('git', ['reset', '--hard', `${existing.ref}^`], {
|
|
346
351
|
cwd: workspacePath,
|
|
347
352
|
encoding: 'utf-8',
|
|
348
353
|
windowsHide: true,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { MigrationsJson, PackageJsonUpdateForPackage as PackageUpdate } from '../../config/misc-interfaces';
|
|
2
2
|
import { NxJsonConfiguration } from '../../config/nx-json';
|
|
3
|
-
import { FileChange } from '../../generators/tree';
|
|
4
3
|
import { ArrayPackageGroup, PackageJson } from '../../utils/package-json';
|
|
5
4
|
import { PackageManagerCommands } from '../../utils/package-manager';
|
|
6
5
|
import { type MigrateFetchStats, type MigrateMultiMajorChoice } from './migrate-analytics';
|
|
@@ -10,6 +9,7 @@ import type { ResolvedAgentic } from './agentic/types';
|
|
|
10
9
|
import { isHybridMigration, isPromptOnlyMigration } from './migration-shape';
|
|
11
10
|
import { filterDowngradedUpdates } from './update-filters';
|
|
12
11
|
import { normalizeVersion } from './version-utils';
|
|
12
|
+
export * from './execute-migration';
|
|
13
13
|
export { normalizeVersion };
|
|
14
14
|
export interface ResolvedMigrationConfiguration extends MigrationsJson {
|
|
15
15
|
packageGroup?: ArrayPackageGroup;
|
|
@@ -174,14 +174,6 @@ export declare function createFetcher(pmc: PackageManagerCommands): ((pkg: strin
|
|
|
174
174
|
};
|
|
175
175
|
export { filterDowngradedUpdates };
|
|
176
176
|
export declare function generateMigrationsJsonAndUpdatePackageJson(root: string, opts: GenerateMigrations, fetch?: MigratorOptions['fetch']): Promise<void>;
|
|
177
|
-
/**
|
|
178
|
-
* Detects npm peer-dependency resolution failures. Keyed on the `ERESOLVE`
|
|
179
|
-
* error code, which npm consistently emits for this class of failure across
|
|
180
|
-
* v7+ (`npm ERR! code ERESOLVE` / `npm error code ERESOLVE`). Falls back to a
|
|
181
|
-
* small set of stable phrases in case the code line is missing from the
|
|
182
|
-
* captured output.
|
|
183
|
-
*/
|
|
184
|
-
export declare function isNpmPeerDepsError(stderr: string): boolean;
|
|
185
177
|
type ExecutableMigration = {
|
|
186
178
|
package: string;
|
|
187
179
|
name: string;
|
|
@@ -217,6 +209,19 @@ export declare function resolveCreateCommits(args: {
|
|
|
217
209
|
warning?: string;
|
|
218
210
|
error?: string;
|
|
219
211
|
};
|
|
212
|
+
/**
|
|
213
|
+
* Confirms before creating per-migration commits while the user sits on the
|
|
214
|
+
* repository's default branch, so migrations don't silently commit there (most
|
|
215
|
+
* relevant since `--agentic` enables commits by default). Only the default
|
|
216
|
+
* branch triggers a prompt; a detached HEAD, a different branch, or an
|
|
217
|
+
* unresolved default branch all proceed untouched. Callers gate this on
|
|
218
|
+
* commits being effective and prompting being possible, so non-interactive
|
|
219
|
+
* runs (CI, `--no-interactive`) never reach here.
|
|
220
|
+
*/
|
|
221
|
+
export declare function confirmCommitsOnDefaultBranch(args: {
|
|
222
|
+
currentBranch: string | null;
|
|
223
|
+
defaultBranch: string | null;
|
|
224
|
+
}): Promise<boolean>;
|
|
220
225
|
/**
|
|
221
226
|
* Resolves whether the framework-owned generic-validation agent step should run
|
|
222
227
|
* after generator-only migrations.
|
|
@@ -240,46 +245,10 @@ export declare function executeMigrations(root: string, migrations: ExecutableMi
|
|
|
240
245
|
committedShasCount: number;
|
|
241
246
|
retainedAtSuccess: string[];
|
|
242
247
|
}>;
|
|
243
|
-
export declare class ChangedDepInstaller {
|
|
244
|
-
private readonly root;
|
|
245
|
-
private readonly shouldSkipInstall;
|
|
246
|
-
private initialDeps;
|
|
247
|
-
private _skippedInstall;
|
|
248
|
-
constructor(root: string, shouldSkipInstall?: boolean);
|
|
249
|
-
get skippedInstall(): boolean;
|
|
250
|
-
installDepsIfChanged(): Promise<void>;
|
|
251
|
-
}
|
|
252
|
-
export declare function runNxOrAngularMigration(root: string, migration: {
|
|
253
|
-
package: string;
|
|
254
|
-
name: string;
|
|
255
|
-
description?: string;
|
|
256
|
-
version: string;
|
|
257
|
-
}, isVerbose: boolean, captureGeneratorOutput?: boolean, resolvedCollection?: {
|
|
258
|
-
collection: MigrationsJson;
|
|
259
|
-
collectionPath: string;
|
|
260
|
-
}): Promise<{
|
|
261
|
-
changes: FileChange[];
|
|
262
|
-
nextSteps: string[];
|
|
263
|
-
agentContext: string[];
|
|
264
|
-
logs: string;
|
|
265
|
-
madeChanges: boolean;
|
|
266
|
-
}>;
|
|
267
|
-
export declare function parseMigrationReturn(value: unknown): {
|
|
268
|
-
nextSteps: string[];
|
|
269
|
-
agentContext: string[];
|
|
270
|
-
};
|
|
271
248
|
export declare function migrate(root: string, args: {
|
|
272
249
|
[k: string]: any;
|
|
273
250
|
}, rawArgs: string[]): Promise<number>;
|
|
274
251
|
export declare function runMigration(): Promise<number>;
|
|
275
|
-
export declare function readMigrationCollection(packageName: string, root: string): {
|
|
276
|
-
collection: MigrationsJson;
|
|
277
|
-
collectionPath: string;
|
|
278
|
-
};
|
|
279
|
-
export declare function getImplementationPath(collection: MigrationsJson, collectionPath: string, name: string, migrationVersion?: string): {
|
|
280
|
-
path: string;
|
|
281
|
-
fnSymbol: string;
|
|
282
|
-
};
|
|
283
252
|
/**
|
|
284
253
|
* Resolves a migration's collection once and derives everything the run loop
|
|
285
254
|
* needs from that single read: the implementation context (`collection` +
|