nx 23.1.0 → 23.1.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 +2 -1
- package/dist/release/changelog-renderer/index.js +4 -5
- package/dist/release/index.d.ts +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/analytics/analytics.d.ts +6 -0
- package/dist/src/analytics/analytics.js +16 -8
- package/dist/src/analytics/index.d.ts +1 -1
- package/dist/src/analytics/index.js +2 -1
- package/dist/src/command-line/add/add.js +13 -1
- package/dist/src/command-line/affected/affected.js +1 -0
- package/dist/src/command-line/configure-ai-agents/configure-ai-agents.js +2 -2
- package/dist/src/command-line/graph/graph.d.ts +1 -0
- package/dist/src/command-line/graph/graph.js +15 -6
- package/dist/src/command-line/import/import.js +2 -3
- 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/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/init/implementation/utils.d.ts +3 -3
- package/dist/src/command-line/init/implementation/utils.js +22 -3
- package/dist/src/command-line/init/init-v2.js +4 -5
- 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 +5 -45
- package/dist/src/command-line/migrate/migrate.js +122 -402
- package/dist/src/command-line/nx-cloud/connect/connect-to-nx-cloud.js +1 -1
- package/dist/src/command-line/nx-cloud/connect/view-logs.js +2 -0
- package/dist/src/command-line/release/changelog.js +5 -0
- package/dist/src/command-line/release/index.d.ts +1 -1
- package/dist/src/command-line/release/utils/git.js +7 -3
- package/dist/src/command-line/release/utils/release-graph.d.ts +19 -2
- package/dist/src/command-line/release/utils/release-graph.js +71 -19
- package/dist/src/command-line/release/utils/remote-release-clients/github.js +7 -1
- package/dist/src/command-line/release/utils/remote-release-clients/gitlab.js +1 -1
- package/dist/src/command-line/release/utils/shared.d.ts +2 -2
- package/dist/src/command-line/release/version/release-group-processor.d.ts +24 -0
- package/dist/src/command-line/release/version/release-group-processor.js +80 -6
- package/dist/src/command-line/release/version/version-actions.d.ts +27 -2
- package/dist/src/command-line/release/version/version-actions.js +9 -1
- package/dist/src/command-line/release/version.js +9 -5
- package/dist/src/command-line/reset/reset.js +6 -1
- package/dist/src/command-line/run/run-one.js +1 -0
- package/dist/src/command-line/run-many/run-many.js +1 -0
- package/dist/src/command-line/show/show-target/info.js +11 -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/watch/watch.js +13 -0
- 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 +5 -3
- package/dist/src/core/graph/main.js +1 -1
- package/dist/src/core/graph/styles.js +1 -1
- package/dist/src/daemon/client/client.d.ts +52 -3
- package/dist/src/daemon/client/client.js +177 -55
- package/dist/src/daemon/client/daemon-environment.d.ts +17 -0
- package/dist/src/daemon/client/daemon-environment.js +110 -2
- package/dist/src/daemon/client/daemon-socket-messenger.js +4 -0
- package/dist/src/daemon/message-types/daemon-message.d.ts +32 -0
- package/dist/src/daemon/message-types/daemon-message.js +25 -0
- package/dist/src/daemon/server/file-watching/file-watcher-sockets.d.ts +5 -0
- package/dist/src/daemon/server/file-watching/file-watcher-sockets.js +16 -0
- package/dist/src/daemon/server/handle-tasks-execution-hooks.d.ts +1 -1
- package/dist/src/daemon/server/latest-nx.js +5 -2
- package/dist/src/daemon/server/server.js +31 -4
- package/dist/src/daemon/server/shutdown-utils.d.ts +5 -0
- package/dist/src/daemon/server/shutdown-utils.js +11 -4
- package/dist/src/daemon/socket-utils.d.ts +1 -0
- package/dist/src/daemon/socket-utils.js +24 -3
- package/dist/src/daemon/tmp-dir.d.ts +43 -3
- package/dist/src/daemon/tmp-dir.js +437 -15
- package/dist/src/devkit-internals.d.ts +96 -3
- package/dist/src/devkit-internals.js +200 -4
- package/dist/src/generators/internal-utils/format-changed-files-with-prettier-if-available.d.ts +5 -0
- package/dist/src/generators/internal-utils/format-changed-files-with-prettier-if-available.js +9 -2
- package/dist/src/generators/tree.d.ts +4 -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/migrations/update-23-2-0/set-cache-on-executor-target-defaults.d.ts +12 -0
- package/dist/src/migrations/update-23-2-0/set-cache-on-executor-target-defaults.js +250 -0
- package/dist/src/migrations/update-23-2-0/set-cache-on-executor-target-defaults.md +50 -0
- package/dist/src/native/index.d.ts +31 -2
- package/dist/src/native/index.js +71 -28
- package/dist/src/native/native-bindings.js +3 -0
- package/dist/src/native/native-file-cache-location.d.ts +17 -1
- package/dist/src/native/native-file-cache-location.js +86 -12
- package/dist/src/native/nx.wasm32-wasi.debug.wasm +0 -0
- package/dist/src/native/nx.wasm32-wasi.wasm +0 -0
- package/dist/src/nx-cloud/utilities/get-cloud-options.js +5 -2
- package/dist/src/nx-cloud/utilities/onboarding.js +5 -2
- package/dist/src/plugins/js/lock-file/bun-parser.js +43 -10
- package/dist/src/plugins/js/lock-file/npm-parser.js +71 -27
- package/dist/src/plugins/js/lock-file/pnpm-parser.js +110 -17
- package/dist/src/plugins/js/lock-file/project-graph-pruning.js +15 -9
- package/dist/src/plugins/js/lock-file/utils/pnpm-normalizer.js +3 -0
- package/dist/src/plugins/js/lock-file/yarn-parser.js +32 -5
- package/dist/src/plugins/js/project-graph/affected/npm-packages.js +51 -20
- package/dist/src/plugins/js/project-graph/build-dependencies/target-project-locator.js +14 -4
- 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/affected/affected-project-graph-models.d.ts +1 -1
- package/dist/src/project-graph/affected/affected-project-graph.d.ts +1 -1
- package/dist/src/project-graph/affected/affected-project-graph.js +2 -2
- package/dist/src/project-graph/affected/locators/project-glob-changes.js +5 -2
- package/dist/src/project-graph/build-project-graph.js +7 -1
- package/dist/src/project-graph/error-types.d.ts +12 -1
- package/dist/src/project-graph/error-types.js +68 -3
- package/dist/src/project-graph/file-utils.js +6 -1
- package/dist/src/project-graph/plugins/isolation/isolated-plugin.d.ts +1 -0
- package/dist/src/project-graph/plugins/isolation/isolated-plugin.js +22 -1
- package/dist/src/project-graph/plugins/isolation/messaging.d.ts +16 -3
- package/dist/src/project-graph/plugins/isolation/messaging.js +3 -0
- package/dist/src/project-graph/plugins/isolation/plugin-worker.js +58 -8
- package/dist/src/project-graph/plugins/loaded-nx-plugin.js +1 -0
- package/dist/src/project-graph/plugins/transpiler.js +4 -0
- package/dist/src/project-graph/project-graph.js +23 -0
- package/dist/src/project-graph/utils/project-configuration/name-substitution-manager.d.ts +10 -12
- package/dist/src/project-graph/utils/project-configuration/name-substitution-manager.js +93 -63
- package/dist/src/project-graph/utils/project-configuration/project-nodes-manager.d.ts +5 -8
- package/dist/src/project-graph/utils/project-configuration/project-nodes-manager.js +16 -15
- package/dist/src/project-graph/utils/project-configuration/source-maps.d.ts +12 -5
- package/dist/src/project-graph/utils/project-configuration/source-maps.js +21 -7
- package/dist/src/project-graph/utils/project-configuration/target-defaults.d.ts +1 -1
- package/dist/src/project-graph/utils/project-configuration/target-defaults.js +26 -27
- package/dist/src/project-graph/utils/project-configuration/target-merging.js +50 -8
- package/dist/src/project-graph/utils/project-configuration/target-normalization.js +149 -6
- package/dist/src/project-graph/utils/project-configuration/utils.d.ts +15 -0
- package/dist/src/project-graph/utils/project-configuration/utils.js +42 -6
- package/dist/src/project-graph/utils/project-configuration-utils.d.ts +15 -12
- package/dist/src/project-graph/utils/project-configuration-utils.js +79 -101
- 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 +4 -2
- package/dist/src/tasks-runner/task-env.d.ts +9 -0
- package/dist/src/tasks-runner/task-env.js +31 -4
- package/dist/src/tasks-runner/task-orchestrator.d.ts +4 -1
- package/dist/src/tasks-runner/task-orchestrator.js +23 -10
- package/dist/src/tasks-runner/utils.js +2 -6
- package/dist/src/utils/acknowledge-build-scripts.d.ts +13 -0
- package/dist/src/utils/acknowledge-build-scripts.js +102 -0
- package/dist/src/utils/analytics-prompt.d.ts +0 -6
- package/dist/src/utils/analytics-prompt.js +0 -51
- package/dist/src/utils/assert-workspace-validity.js +7 -2
- 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/fileutils.d.ts +5 -0
- package/dist/src/utils/fileutils.js +7 -2
- 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 +16 -3
- package/dist/src/utils/git-utils.js +146 -52
- package/dist/src/utils/git-worktrees.d.ts +30 -0
- package/dist/src/utils/git-worktrees.js +212 -0
- package/dist/src/utils/ignore.d.ts +128 -1
- package/dist/src/utils/ignore.js +182 -12
- package/dist/src/utils/long-running-target.d.ts +10 -0
- package/dist/src/utils/long-running-target.js +19 -0
- package/dist/src/utils/min-release-age/behavior/bun.js +7 -11
- package/dist/src/utils/min-release-age/behavior/npm.js +5 -2
- package/dist/src/utils/min-release-age/behavior/pnpm.js +9 -7
- package/dist/src/utils/min-release-age/packument.js +1 -1
- package/dist/src/utils/nx-tmp-dir.d.ts +18 -0
- package/dist/src/utils/nx-tmp-dir.js +40 -0
- package/dist/src/utils/owned-private-dir.d.ts +132 -0
- package/dist/src/utils/owned-private-dir.js +323 -0
- package/dist/src/utils/package-json.js +11 -7
- package/dist/src/utils/package-manager-config/bunfig.d.ts +14 -0
- package/dist/src/utils/package-manager-config/bunfig.js +49 -0
- package/dist/src/utils/package-manager-config/npmrc.d.ts +23 -0
- package/dist/src/utils/package-manager-config/npmrc.js +124 -0
- package/dist/src/utils/package-manager-config/pnpm-config.d.ts +17 -0
- package/dist/src/utils/package-manager-config/pnpm-config.js +60 -0
- package/dist/src/utils/package-manager.d.ts +23 -2
- package/dist/src/utils/package-manager.js +264 -43
- package/dist/src/utils/provenance.js +18 -16
- package/dist/src/utils/registry-config/bun.d.ts +2 -0
- package/dist/src/utils/registry-config/bun.js +257 -0
- package/dist/src/utils/registry-config/index.d.ts +13 -0
- package/dist/src/utils/registry-config/index.js +102 -0
- package/dist/src/utils/registry-config/pnpm.d.ts +2 -0
- package/dist/src/utils/registry-config/pnpm.js +1551 -0
- package/dist/src/utils/registry-config/utils.d.ts +195 -0
- package/dist/src/utils/registry-config/utils.js +496 -0
- package/dist/src/utils/registry-config/yarn-berry.d.ts +2 -0
- package/dist/src/utils/registry-config/yarn-berry.js +612 -0
- package/dist/src/utils/registry-config/yarn-classic.d.ts +2 -0
- package/dist/src/utils/registry-config/yarn-classic.js +1001 -0
- package/dist/src/utils/safe-spawn.d.ts +24 -0
- package/dist/src/utils/safe-spawn.js +104 -0
- package/dist/src/utils/shell-quoting.d.ts +15 -0
- package/dist/src/utils/shell-quoting.js +35 -0
- package/dist/src/utils/wait-for-socket-connection.d.ts +11 -0
- package/dist/src/utils/wait-for-socket-connection.js +14 -8
- package/dist/src/utils/workspace-id.d.ts +20 -0
- package/dist/src/utils/workspace-id.js +54 -0
- package/migrations.json +13 -1
- package/package.json +22 -17
- 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
- package/dist/src/utils/min-release-age/npmrc.d.ts +0 -15
- package/dist/src/utils/min-release-age/npmrc.js +0 -45
|
@@ -18,9 +18,11 @@ exports.printFinalMessage = printFinalMessage;
|
|
|
18
18
|
exports.isMonorepo = isMonorepo;
|
|
19
19
|
const child_process_1 = require("child_process");
|
|
20
20
|
const path_1 = require("path");
|
|
21
|
+
const semver_1 = require("semver");
|
|
21
22
|
const fileutils_1 = require("../../../utils/fileutils");
|
|
22
23
|
const output_1 = require("../../../utils/output");
|
|
23
24
|
const package_manager_1 = require("../../../utils/package-manager");
|
|
25
|
+
const acknowledge_build_scripts_1 = require("../../../utils/acknowledge-build-scripts");
|
|
24
26
|
const path_2 = require("../../../utils/path");
|
|
25
27
|
const versions_1 = require("../../../utils/versions");
|
|
26
28
|
const fs_1 = require("fs");
|
|
@@ -207,7 +209,7 @@ function createNxJsonFromTurboJson(turboJson) {
|
|
|
207
209
|
}
|
|
208
210
|
return nxJson;
|
|
209
211
|
}
|
|
210
|
-
function addDepsToPackageJson(repoRoot, additionalPackages) {
|
|
212
|
+
function addDepsToPackageJson(repoRoot, packageManager, additionalPackages) {
|
|
211
213
|
const path = (0, path_2.joinPathFragments)(repoRoot, `package.json`);
|
|
212
214
|
const json = (0, fileutils_1.readJsonFile)(path);
|
|
213
215
|
if (!json.devDependencies)
|
|
@@ -219,6 +221,9 @@ function addDepsToPackageJson(repoRoot, additionalPackages) {
|
|
|
219
221
|
}
|
|
220
222
|
}
|
|
221
223
|
(0, fileutils_1.writeJsonFile)(path, json);
|
|
224
|
+
// nx has a postinstall script, which pnpm 11+ refuses to install
|
|
225
|
+
// unacknowledged.
|
|
226
|
+
(0, acknowledge_build_scripts_1.acknowledgeBuildScripts)(repoRoot, packageManager, { nx: true });
|
|
222
227
|
}
|
|
223
228
|
function updateGitIgnore(root) {
|
|
224
229
|
const ignorePath = (0, path_1.join)(root, '.gitignore');
|
|
@@ -251,9 +256,23 @@ function updateGitIgnore(root) {
|
|
|
251
256
|
}
|
|
252
257
|
catch { }
|
|
253
258
|
}
|
|
254
|
-
function runInstall(repoRoot, pmc = (0, package_manager_1.getPackageManagerCommand)()) {
|
|
259
|
+
function runInstall(repoRoot, packageManager = (0, package_manager_1.detectPackageManager)(repoRoot), pmc = (0, package_manager_1.getPackageManagerCommand)(packageManager)) {
|
|
260
|
+
let command = pmc.install;
|
|
261
|
+
// Plugins added during init can pull build-script deps whose allowBuilds
|
|
262
|
+
// entries are only recorded by their init generators after this install;
|
|
263
|
+
// warn and skip for this one install, like pnpm 10 did.
|
|
264
|
+
if (packageManager === 'pnpm') {
|
|
265
|
+
try {
|
|
266
|
+
if ((0, semver_1.gte)((0, package_manager_1.getPackageManagerVersion)('pnpm', repoRoot), '11.0.0')) {
|
|
267
|
+
command += ' --config.strictDepBuilds=false';
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
catch {
|
|
271
|
+
// The version cannot be probed; run the install unmodified.
|
|
272
|
+
}
|
|
273
|
+
}
|
|
255
274
|
try {
|
|
256
|
-
(0, child_process_1.execSync)(
|
|
275
|
+
(0, child_process_1.execSync)(command, {
|
|
257
276
|
stdio: ['ignore', 'ignore', 'pipe'],
|
|
258
277
|
encoding: 'utf8',
|
|
259
278
|
cwd: repoRoot,
|
|
@@ -11,6 +11,7 @@ const nx_json_1 = require("../../config/nx-json");
|
|
|
11
11
|
const fileutils_1 = require("../../utils/fileutils");
|
|
12
12
|
const get_package_name_from_import_path_1 = require("../../utils/get-package-name-from-import-path");
|
|
13
13
|
const output_1 = require("../../utils/output");
|
|
14
|
+
const package_json_1 = require("../../utils/package-json");
|
|
14
15
|
const package_manager_1 = require("../../utils/package-manager");
|
|
15
16
|
const versions_1 = require("../../utils/versions");
|
|
16
17
|
const workspace_context_1 = require("../../utils/workspace-context");
|
|
@@ -26,14 +27,12 @@ const angular_1 = require("./implementation/angular");
|
|
|
26
27
|
const add_nx_scripts_1 = require("./implementation/dot-nx/add-nx-scripts");
|
|
27
28
|
const utils_1 = require("./implementation/utils");
|
|
28
29
|
const provenance_1 = require("../../utils/provenance");
|
|
29
|
-
const devkit_internals_1 = require("../../devkit-internals");
|
|
30
30
|
const handle_import_1 = require("../../utils/handle-import");
|
|
31
31
|
const native_1 = require("../../native");
|
|
32
32
|
const detect_ai_agent_1 = require("../../ai/detect-ai-agent");
|
|
33
33
|
const ab_testing_1 = require("../../utils/ab-testing");
|
|
34
34
|
const analytics_prompt_1 = require("../../utils/analytics-prompt");
|
|
35
35
|
const is_ci_1 = require("../../utils/is-ci");
|
|
36
|
-
const package_manager_2 = require("../../utils/package-manager");
|
|
37
36
|
const ai_output_1 = require("./utils/ai-output");
|
|
38
37
|
async function initHandler(options, inner = false) {
|
|
39
38
|
// Use environment variable to force local execution
|
|
@@ -43,7 +42,7 @@ async function initHandler(options, inner = false) {
|
|
|
43
42
|
let cleanup;
|
|
44
43
|
try {
|
|
45
44
|
await (0, provenance_1.ensurePackageHasProvenance)('nx', 'latest');
|
|
46
|
-
const packageInstallResults = (0,
|
|
45
|
+
const packageInstallResults = (0, package_json_1.installPackageToTmp)('nx', 'latest', (0, package_manager_1.detectPackageManager)(process.cwd()));
|
|
47
46
|
cleanup = packageInstallResults.cleanup;
|
|
48
47
|
let modulePath = require.resolve('nx/src/command-line/init/init-v2.js', {
|
|
49
48
|
paths: [packageInstallResults.tempDir],
|
|
@@ -95,7 +94,7 @@ async function initHandlerImpl(options) {
|
|
|
95
94
|
const baseMeta = {
|
|
96
95
|
nodeVersion: process.versions.node,
|
|
97
96
|
os: process.platform,
|
|
98
|
-
packageManager: (0,
|
|
97
|
+
packageManager: (0, package_manager_1.detectPackageManager)(),
|
|
99
98
|
aiAgent: (0, native_1.isAiAgent)(),
|
|
100
99
|
isCI: (0, is_ci_1.isCI)(),
|
|
101
100
|
};
|
|
@@ -368,7 +367,7 @@ async function runInit(options, baseMeta) {
|
|
|
368
367
|
analyticsPrompt,
|
|
369
368
|
nodeVersion: process.versions.node,
|
|
370
369
|
os: process.platform,
|
|
371
|
-
packageManager: (0,
|
|
370
|
+
packageManager: (0, package_manager_1.detectPackageManager)(),
|
|
372
371
|
aiAgent: aiMode,
|
|
373
372
|
isCI: (0, is_ci_1.isCI)(),
|
|
374
373
|
pluginsInstalled: pluginsToInstall.join(','),
|
|
@@ -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
|
+
})();
|
|
@@ -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,
|