nx 23.2.0-beta.0 → 23.2.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/nx.js +1 -1
- package/dist/src/analytics/analytics.d.ts +6 -0
- package/dist/src/analytics/analytics.js +7 -1
- package/dist/src/analytics/index.d.ts +1 -1
- package/dist/src/analytics/index.js +2 -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/implementation/angular/integrated-workspace.js +2 -5
- package/dist/src/command-line/init/implementation/angular/legacy-angular-versions.js +3 -0
- package/dist/src/command-line/init/implementation/dot-nx/add-nx-scripts.js +4 -1
- 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 +1 -45
- package/dist/src/command-line/migrate/migrate.js +17 -375
- package/dist/src/command-line/nx-cloud/connect/view-logs.js +2 -0
- 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/inputs.js +50 -153
- package/dist/src/command-line/show/show-target/outputs.js +48 -173
- package/dist/src/command-line/show/show-target/utils.d.ts +28 -0
- package/dist/src/command-line/show/show-target/utils.js +83 -3
- package/dist/src/command-line/yargs-utils/shared-options.d.ts +1 -1
- 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/server/handle-tasks-execution-hooks.d.ts +1 -1
- package/dist/src/daemon/server/server.js +7 -4
- package/dist/src/devkit-internals.d.ts +1 -0
- package/dist/src/devkit-internals.js +5 -2
- package/dist/src/generators/utils/nx-json.js +13 -3
- package/dist/src/hasher/check-task-files.d.ts +86 -0
- package/dist/src/hasher/check-task-files.js +378 -0
- package/dist/src/native/index.d.ts +25 -2
- package/dist/src/native/native-bindings.js +2 -0
- package/dist/src/native/nx.wasm32-wasi.debug.wasm +0 -0
- package/dist/src/native/nx.wasm32-wasi.wasm +0 -0
- package/dist/src/plugins/js/lock-file/utils/pnpm-normalizer.js +3 -0
- package/dist/src/project-graph/build-project-graph.js +7 -1
- package/dist/src/project-graph/file-utils.js +6 -1
- package/dist/src/project-graph/plugins/loaded-nx-plugin.js +1 -0
- package/dist/src/project-graph/project-graph.js +3 -0
- package/dist/src/tasks-runner/life-cycle.d.ts +2 -2
- package/dist/src/tasks-runner/life-cycle.js +2 -2
- package/dist/src/tasks-runner/life-cycles/performance-analysis.d.ts +9 -4
- package/dist/src/tasks-runner/life-cycles/performance-life-cycle.js +5 -4
- package/dist/src/tasks-runner/life-cycles/performance-report.d.ts +16 -8
- package/dist/src/tasks-runner/life-cycles/performance-report.js +55 -27
- package/dist/src/tasks-runner/pseudo-terminal.d.ts +1 -1
- package/dist/src/tasks-runner/pseudo-terminal.js +2 -2
- package/dist/src/tasks-runner/task-orchestrator.d.ts +4 -1
- package/dist/src/tasks-runner/task-orchestrator.js +23 -6
- package/dist/src/utils/acknowledge-build-scripts.js +7 -5
- 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/package-manager.js +6 -2
- package/package.json +11 -11
package/dist/bin/nx.js
CHANGED
|
@@ -258,7 +258,7 @@ function warnIfUsingOutdatedGlobalInstall(globalNxVersion, localNxVersion) {
|
|
|
258
258
|
`Your repository uses a higher version of Nx (${localNxVersion}) than your global CLI version (${globalNxVersion})`,
|
|
259
259
|
]
|
|
260
260
|
: [];
|
|
261
|
-
bodyLines.push('For more information, see https://nx.dev/
|
|
261
|
+
bodyLines.push('For more information, see https://nx.dev/docs/getting-started/installation#global-installation');
|
|
262
262
|
output_1.output.warn({
|
|
263
263
|
title: `It's time to update Nx 🎉`,
|
|
264
264
|
bodyLines,
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import type { EventDimensions } from '../native';
|
|
2
2
|
export declare const customDimensions: EventDimensions;
|
|
3
3
|
export type EventParameters = Partial<Record<EventDimensions[keyof EventDimensions], string | number | boolean>>;
|
|
4
|
+
/**
|
|
5
|
+
* Fraction of sessions that report perf spans. Stamping this rate on a
|
|
6
|
+
* measure's detail (as the sampleRate dimension) opts it into sampling; see
|
|
7
|
+
* is_sampled_in in native/telemetry/service.rs. Multiply GA counts by 1/rate.
|
|
8
|
+
*/
|
|
9
|
+
export declare const PERF_SPAN_SAMPLE_RATE = 0.1;
|
|
4
10
|
export declare function startAnalytics(): Promise<void>;
|
|
5
11
|
export declare function reportNxAddCommand(packageName: string, version: string): void;
|
|
6
12
|
export declare function reportNxGenerateCommand(generator: string): void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.customDimensions = void 0;
|
|
3
|
+
exports.PERF_SPAN_SAMPLE_RATE = exports.customDimensions = void 0;
|
|
4
4
|
exports.startAnalytics = startAnalytics;
|
|
5
5
|
exports.reportNxAddCommand = reportNxAddCommand;
|
|
6
6
|
exports.reportNxGenerateCommand = reportNxGenerateCommand;
|
|
@@ -42,6 +42,12 @@ exports.customDimensions = native_1.IS_WASM
|
|
|
42
42
|
? null
|
|
43
43
|
: (getEventDimensions?.() ?? null);
|
|
44
44
|
let _telemetryInitialized = false;
|
|
45
|
+
/**
|
|
46
|
+
* Fraction of sessions that report perf spans. Stamping this rate on a
|
|
47
|
+
* measure's detail (as the sampleRate dimension) opts it into sampling; see
|
|
48
|
+
* is_sampled_in in native/telemetry/service.rs. Multiply GA counts by 1/rate.
|
|
49
|
+
*/
|
|
50
|
+
exports.PERF_SPAN_SAMPLE_RATE = 0.1;
|
|
45
51
|
async function startAnalytics() {
|
|
46
52
|
// Analytics not supported on WASM
|
|
47
53
|
if (native_1.IS_WASM) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { customDimensions, EventParameters, startAnalytics, reportNxAddCommand, reportNxGenerateCommand, reportCommandRunEvent, reportEvent, flushAnalytics, } from './analytics';
|
|
1
|
+
export { customDimensions, EventParameters, PERF_SPAN_SAMPLE_RATE, startAnalytics, reportNxAddCommand, reportNxGenerateCommand, reportCommandRunEvent, reportEvent, flushAnalytics, } from './analytics';
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.flushAnalytics = exports.reportEvent = exports.reportCommandRunEvent = exports.reportNxGenerateCommand = exports.reportNxAddCommand = exports.startAnalytics = exports.customDimensions = void 0;
|
|
3
|
+
exports.flushAnalytics = exports.reportEvent = exports.reportCommandRunEvent = exports.reportNxGenerateCommand = exports.reportNxAddCommand = exports.startAnalytics = exports.PERF_SPAN_SAMPLE_RATE = exports.customDimensions = void 0;
|
|
4
4
|
var analytics_1 = require("./analytics");
|
|
5
5
|
Object.defineProperty(exports, "customDimensions", { enumerable: true, get: function () { return analytics_1.customDimensions; } });
|
|
6
|
+
Object.defineProperty(exports, "PERF_SPAN_SAMPLE_RATE", { enumerable: true, get: function () { return analytics_1.PERF_SPAN_SAMPLE_RATE; } });
|
|
6
7
|
Object.defineProperty(exports, "startAnalytics", { enumerable: true, get: function () { return analytics_1.startAnalytics; } });
|
|
7
8
|
Object.defineProperty(exports, "reportNxAddCommand", { enumerable: true, get: function () { return analytics_1.reportNxAddCommand; } });
|
|
8
9
|
Object.defineProperty(exports, "reportNxGenerateCommand", { enumerable: true, get: function () { return analytics_1.reportNxGenerateCommand; } });
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Agent } from '../../ai/utils';
|
|
2
|
-
export declare function determineAiAgents(aiAgents?: Agent[], interactive?: boolean): Promise<Agent[]>;
|
|
2
|
+
export declare function determineAiAgents(aiAgents?: (Agent | 'none')[], interactive?: boolean): Promise<Agent[]>;
|
|
@@ -8,16 +8,17 @@ const utils_1 = require("../../ai/utils");
|
|
|
8
8
|
const detect_ai_agent_1 = require("../../ai/detect-ai-agent");
|
|
9
9
|
const pc = tslib_1.__importStar(require("picocolors"));
|
|
10
10
|
async function determineAiAgents(aiAgents, interactive) {
|
|
11
|
-
if (
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
if (aiAgents) {
|
|
12
|
+
const filtered = aiAgents.filter((a) => a !== 'none');
|
|
13
|
+
if (filtered.length > 0) {
|
|
14
|
+
return filtered;
|
|
14
15
|
}
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
if (interactive === false || (0, is_ci_1.isCI)()) {
|
|
15
19
|
const detected = (0, detect_ai_agent_1.detectAiAgent)();
|
|
16
20
|
return detected ? [detected] : [];
|
|
17
21
|
}
|
|
18
|
-
if (aiAgents) {
|
|
19
|
-
return aiAgents;
|
|
20
|
-
}
|
|
21
22
|
return await aiAgentsPrompt();
|
|
22
23
|
}
|
|
23
24
|
async function aiAgentsPrompt() {
|
|
@@ -64,8 +64,16 @@ async function withInitOptions(yargs) {
|
|
|
64
64
|
.option('aiAgents', {
|
|
65
65
|
type: 'array',
|
|
66
66
|
string: true,
|
|
67
|
-
description: 'List of AI agents to set up.',
|
|
68
|
-
choices: [
|
|
67
|
+
description: 'List of AI agents to set up. Use "none" to skip.',
|
|
68
|
+
choices: [
|
|
69
|
+
'claude',
|
|
70
|
+
'codex',
|
|
71
|
+
'copilot',
|
|
72
|
+
'cursor',
|
|
73
|
+
'gemini',
|
|
74
|
+
'opencode',
|
|
75
|
+
'none',
|
|
76
|
+
],
|
|
69
77
|
})
|
|
70
78
|
.option('plugins', {
|
|
71
79
|
type: 'string',
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.setupIntegratedWorkspace = setupIntegratedWorkspace;
|
|
4
|
-
const child_process_1 = require("
|
|
5
|
-
const package_manager_1 = require("../../../../utils/package-manager");
|
|
4
|
+
const child_process_1 = require("../../../../utils/child-process");
|
|
6
5
|
function setupIntegratedWorkspace() {
|
|
7
|
-
|
|
8
|
-
(0, child_process_1.execSync)(`${pmc.exec} nx g @nx/angular:ng-add`, {
|
|
6
|
+
(0, child_process_1.runNxSync)(`g @nx/angular:ng-add`, {
|
|
9
7
|
stdio: [0, 1, 2],
|
|
10
|
-
windowsHide: true,
|
|
11
8
|
});
|
|
12
9
|
}
|
|
@@ -107,6 +107,9 @@ async function getLegacyMigrationFunctionIfApplicable(repoRoot, options) {
|
|
|
107
107
|
unscopedPkgName,
|
|
108
108
|
}, pmc);
|
|
109
109
|
output_1.output.log({ title: '📝 Setting up workspace' });
|
|
110
|
+
// Intentionally not runNxSync: legacyMigrationCommand is either the Angular
|
|
111
|
+
// CLI (`ng g ...:ng-add`) or a version-pinned `nx@<version> init`, neither
|
|
112
|
+
// of which is the local nx that runNxSync would resolve.
|
|
110
113
|
(0, child_process_1.execSync)(`${pmc.exec} ${legacyMigrationCommand}`, {
|
|
111
114
|
stdio: [0, 1, 2],
|
|
112
115
|
windowsHide: true,
|
|
@@ -69,7 +69,10 @@ function generateDotNxSetup(version) {
|
|
|
69
69
|
(0, tree_1.flushChanges)(host.root, changes);
|
|
70
70
|
// Ensure that the dot-nx installation is available.
|
|
71
71
|
// This is needed when using a global nx with dot-nx, otherwise running any nx command using global command will fail due to missing modules.
|
|
72
|
-
//
|
|
72
|
+
// Intentionally not runNxSync: when the repo has a package.json it would run
|
|
73
|
+
// `<pm> exec nx` instead of the wrapper, but this call must run the
|
|
74
|
+
// just-written wrapper itself so it bootstraps .nx/installation.
|
|
75
|
+
// Pipe stderr so failures surface in telemetry instead of bare "Command failed".
|
|
73
76
|
try {
|
|
74
77
|
(0, child_process_1.execSync)(getDotNxWrapperVersionCommand(), {
|
|
75
78
|
stdio: ['ignore', 'ignore', 'pipe'],
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { MigrationsJson } from '../../config/misc-interfaces';
|
|
2
|
+
import { FileChange } from '../../generators/tree';
|
|
3
|
+
import { ArrayPackageGroup, NxMigrationsConfiguration, PackageJson } from '../../utils/package-json';
|
|
4
|
+
interface PackageMigrationConfig extends NxMigrationsConfiguration {
|
|
5
|
+
packageJson: PackageJson;
|
|
6
|
+
packageGroup: ArrayPackageGroup;
|
|
7
|
+
}
|
|
8
|
+
export declare function readPackageMigrationConfig(packageName: string, dir: string): PackageMigrationConfig;
|
|
9
|
+
export declare function runInstall(nxWorkspaceRoot?: string, phase?: MigrationInstallPhase): Promise<void>;
|
|
10
|
+
export type MigrationInstallPhase = 'pre-migration' | 'post-migration';
|
|
11
|
+
export declare class NpmPeerDepsInstallError extends Error {
|
|
12
|
+
constructor();
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Detects npm peer-dependency resolution failures. Keyed on the `ERESOLVE`
|
|
16
|
+
* error code, which npm consistently emits for this class of failure across
|
|
17
|
+
* v7+ (`npm ERR! code ERESOLVE` / `npm error code ERESOLVE`). Falls back to a
|
|
18
|
+
* small set of stable phrases in case the code line is missing from the
|
|
19
|
+
* captured output.
|
|
20
|
+
*/
|
|
21
|
+
export declare function isNpmPeerDepsError(stderr: string): boolean;
|
|
22
|
+
export declare function logNpmPeerDepsError(phase: MigrationInstallPhase): void;
|
|
23
|
+
export declare class ChangedDepInstaller {
|
|
24
|
+
private readonly root;
|
|
25
|
+
private readonly shouldSkipInstall;
|
|
26
|
+
private initialDeps;
|
|
27
|
+
private _skippedInstall;
|
|
28
|
+
constructor(root: string, shouldSkipInstall?: boolean);
|
|
29
|
+
get skippedInstall(): boolean;
|
|
30
|
+
installDepsIfChanged(): Promise<void>;
|
|
31
|
+
}
|
|
32
|
+
export declare function runNxOrAngularMigration(root: string, migration: {
|
|
33
|
+
package: string;
|
|
34
|
+
name: string;
|
|
35
|
+
description?: string;
|
|
36
|
+
version: string;
|
|
37
|
+
}, isVerbose: boolean, captureGeneratorOutput?: boolean, resolvedCollection?: {
|
|
38
|
+
collection: MigrationsJson;
|
|
39
|
+
collectionPath: string;
|
|
40
|
+
}): Promise<{
|
|
41
|
+
changes: FileChange[];
|
|
42
|
+
nextSteps: string[];
|
|
43
|
+
agentContext: string[];
|
|
44
|
+
logs: string;
|
|
45
|
+
madeChanges: boolean;
|
|
46
|
+
}>;
|
|
47
|
+
export declare function getStringifiedPackageJsonDeps(root: string): string;
|
|
48
|
+
export declare function runNxMigration(root: string, collectionPath: string, collection: MigrationsJson, name: string, migrationVersion: string | undefined, captureGeneratorOutput: boolean): Promise<{
|
|
49
|
+
changes: FileChange[];
|
|
50
|
+
nextSteps: string[];
|
|
51
|
+
agentContext: string[];
|
|
52
|
+
logs: string;
|
|
53
|
+
}>;
|
|
54
|
+
export declare function parseMigrationReturn(value: unknown): {
|
|
55
|
+
nextSteps: string[];
|
|
56
|
+
agentContext: string[];
|
|
57
|
+
};
|
|
58
|
+
export declare function filterStrings(value: unknown): string[];
|
|
59
|
+
export declare function readMigrationCollection(packageName: string, root: string): {
|
|
60
|
+
collection: MigrationsJson;
|
|
61
|
+
collectionPath: string;
|
|
62
|
+
};
|
|
63
|
+
export declare function getImplementationPath(collection: MigrationsJson, collectionPath: string, name: string, migrationVersion?: string): {
|
|
64
|
+
path: string;
|
|
65
|
+
fnSymbol: string;
|
|
66
|
+
};
|
|
67
|
+
export declare class MigrationImplementationMissingError extends Error {
|
|
68
|
+
constructor(baseMessage: string, collectionPath: string, migrationVersion: string | undefined);
|
|
69
|
+
}
|
|
70
|
+
export declare function isAngularMigration(collection: MigrationsJson, name: string): import("../../config/misc-interfaces").MigrationsJsonEntry;
|
|
71
|
+
export declare const getNgCompatLayer: () => Promise<typeof import("../../adapter/ngcli-adapter")>;
|
|
72
|
+
export {};
|
|
@@ -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
|
+
})();
|