@ohos-ports/nx 17.3.2-beta.0
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/.eslintrc.json +106 -0
- package/LICENSE +22 -0
- package/README.md +66 -0
- package/bin/init-local.d.ts +8 -0
- package/bin/init-local.js +175 -0
- package/bin/nx-cloud.d.ts +2 -0
- package/bin/nx-cloud.js +55 -0
- package/bin/nx.d.ts +2 -0
- package/bin/nx.js +230 -0
- package/bin/post-install.d.ts +1 -0
- package/bin/post-install.js +55 -0
- package/bin/run-executor.d.ts +1 -0
- package/bin/run-executor.js +66 -0
- package/executors.json +19 -0
- package/generators.json +10 -0
- package/migrations.json +87 -0
- package/package.json +186 -0
- package/plugins/package-json.d.ts +1 -0
- package/plugins/package-json.js +12 -0
- package/presets/core.json +1 -0
- package/presets/npm.json +7 -0
- package/release/changelog-renderer/index.d.ts +56 -0
- package/release/changelog-renderer/index.js +238 -0
- package/release/index.d.ts +4 -0
- package/release/index.js +11 -0
- package/schemas/nx-schema.json +623 -0
- package/schemas/project-schema.json +244 -0
- package/schemas/workspace-schema.json +185 -0
- package/src/adapter/angular-json.d.ts +9 -0
- package/src/adapter/angular-json.js +127 -0
- package/src/adapter/compat.d.ts +2 -0
- package/src/adapter/compat.js +136 -0
- package/src/adapter/decorate-cli.d.ts +1 -0
- package/src/adapter/decorate-cli.js +25 -0
- package/src/adapter/ngcli-adapter.d.ts +90 -0
- package/src/adapter/ngcli-adapter.js +848 -0
- package/src/adapter/rxjs-for-await.d.ts +109 -0
- package/src/adapter/rxjs-for-await.js +362 -0
- package/src/command-line/add/add.d.ts +2 -0
- package/src/command-line/add/add.js +165 -0
- package/src/command-line/add/command-object.d.ts +7 -0
- package/src/command-line/add/command-object.js +24 -0
- package/src/command-line/affected/affected.d.ts +7 -0
- package/src/command-line/affected/affected.js +105 -0
- package/src/command-line/affected/command-object.d.ts +16 -0
- package/src/command-line/affected/command-object.js +93 -0
- package/src/command-line/affected/print-affected.d.ts +11 -0
- package/src/command-line/affected/print-affected.js +108 -0
- package/src/command-line/connect/command-object.d.ts +3 -0
- package/src/command-line/connect/command-object.js +19 -0
- package/src/command-line/connect/connect-to-nx-cloud.d.ts +8 -0
- package/src/command-line/connect/connect-to-nx-cloud.js +96 -0
- package/src/command-line/connect/view-logs.d.ts +1 -0
- package/src/command-line/connect/view-logs.js +53 -0
- package/src/command-line/daemon/command-object.d.ts +2 -0
- package/src/command-line/daemon/command-object.js +21 -0
- package/src/command-line/daemon/daemon.d.ts +2 -0
- package/src/command-line/daemon/daemon.js +27 -0
- package/src/command-line/examples.d.ts +5 -0
- package/src/command-line/examples.js +347 -0
- package/src/command-line/exec/command-object.d.ts +2 -0
- package/src/command-line/exec/command-object.js +19 -0
- package/src/command-line/exec/exec.d.ts +1 -0
- package/src/command-line/exec/exec.js +141 -0
- package/src/command-line/format/command-object.d.ts +3 -0
- package/src/command-line/format/command-object.js +46 -0
- package/src/command-line/format/format.d.ts +2 -0
- package/src/command-line/format/format.js +155 -0
- package/src/command-line/generate/command-object.d.ts +2 -0
- package/src/command-line/generate/command-object.js +70 -0
- package/src/command-line/generate/generate.d.ts +21 -0
- package/src/command-line/generate/generate.js +266 -0
- package/src/command-line/generate/generator-utils.d.ts +17 -0
- package/src/command-line/generate/generator-utils.js +87 -0
- package/src/command-line/graph/command-object.d.ts +2 -0
- package/src/command-line/graph/command-object.js +21 -0
- package/src/command-line/graph/graph.d.ts +39 -0
- package/src/command-line/graph/graph.js +661 -0
- package/src/command-line/init/command-object.d.ts +2 -0
- package/src/command-line/init/command-object.js +81 -0
- package/src/command-line/init/implementation/add-nx-to-monorepo.d.ts +4 -0
- package/src/command-line/init/implementation/add-nx-to-monorepo.js +133 -0
- package/src/command-line/init/implementation/add-nx-to-nest.d.ts +5 -0
- package/src/command-line/init/implementation/add-nx-to-nest.js +346 -0
- package/src/command-line/init/implementation/add-nx-to-npm-repo.d.ts +4 -0
- package/src/command-line/init/implementation/add-nx-to-npm-repo.js +66 -0
- package/src/command-line/init/implementation/angular/index.d.ts +2 -0
- package/src/command-line/init/implementation/angular/index.js +128 -0
- package/src/command-line/init/implementation/angular/integrated-workspace.d.ts +1 -0
- package/src/command-line/init/implementation/angular/integrated-workspace.js +10 -0
- package/src/command-line/init/implementation/angular/legacy-angular-versions.d.ts +2 -0
- package/src/command-line/init/implementation/angular/legacy-angular-versions.js +125 -0
- package/src/command-line/init/implementation/angular/standalone-workspace.d.ts +1 -0
- package/src/command-line/init/implementation/angular/standalone-workspace.js +178 -0
- package/src/command-line/init/implementation/angular/types.d.ts +20 -0
- package/src/command-line/init/implementation/angular/types.js +2 -0
- package/src/command-line/init/implementation/dot-nx/add-nx-scripts.d.ts +7 -0
- package/src/command-line/init/implementation/dot-nx/add-nx-scripts.js +91 -0
- package/src/command-line/init/implementation/dot-nx/nxw.d.ts +1 -0
- package/src/command-line/init/implementation/dot-nx/nxw.js +116 -0
- package/src/command-line/init/implementation/react/add-craco-commands-to-package-scripts.d.ts +1 -0
- package/src/command-line/init/implementation/react/add-craco-commands-to-package-scripts.js +22 -0
- package/src/command-line/init/implementation/react/add-vite-commands-to-package-scripts.d.ts +1 -0
- package/src/command-line/init/implementation/react/add-vite-commands-to-package-scripts.js +19 -0
- package/src/command-line/init/implementation/react/check-for-custom-webpack-setup.d.ts +1 -0
- package/src/command-line/init/implementation/react/check-for-custom-webpack-setup.js +18 -0
- package/src/command-line/init/implementation/react/check-for-uncommitted-changes.d.ts +1 -0
- package/src/command-line/init/implementation/react/check-for-uncommitted-changes.js +16 -0
- package/src/command-line/init/implementation/react/clean-up-files.d.ts +1 -0
- package/src/command-line/init/implementation/react/clean-up-files.js +31 -0
- package/src/command-line/init/implementation/react/index.d.ts +4 -0
- package/src/command-line/init/implementation/react/index.js +230 -0
- package/src/command-line/init/implementation/react/read-name-from-package-json.d.ts +1 -0
- package/src/command-line/init/implementation/react/read-name-from-package-json.js +17 -0
- package/src/command-line/init/implementation/react/rename-js-to-jsx.d.ts +1 -0
- package/src/command-line/init/implementation/react/rename-js-to-jsx.js +23 -0
- package/src/command-line/init/implementation/react/tsconfig-setup.d.ts +1 -0
- package/src/command-line/init/implementation/react/tsconfig-setup.js +109 -0
- package/src/command-line/init/implementation/react/write-craco-config.d.ts +1 -0
- package/src/command-line/init/implementation/react/write-craco-config.js +62 -0
- package/src/command-line/init/implementation/react/write-vite-config.d.ts +1 -0
- package/src/command-line/init/implementation/react/write-vite-config.js +38 -0
- package/src/command-line/init/implementation/react/write-vite-index-html.d.ts +1 -0
- package/src/command-line/init/implementation/react/write-vite-index-html.js +25 -0
- package/src/command-line/init/implementation/utils.d.ts +16 -0
- package/src/command-line/init/implementation/utils.js +176 -0
- package/src/command-line/init/init-v1.d.ts +11 -0
- package/src/command-line/init/init-v1.js +118 -0
- package/src/command-line/init/init-v2.d.ts +7 -0
- package/src/command-line/init/init-v2.js +165 -0
- package/src/command-line/list/command-object.d.ts +2 -0
- package/src/command-line/list/command-object.js +15 -0
- package/src/command-line/list/list.d.ts +13 -0
- package/src/command-line/list/list.js +47 -0
- package/src/command-line/migrate/command-object.d.ts +3 -0
- package/src/command-line/migrate/command-object.js +150 -0
- package/src/command-line/migrate/migrate.d.ts +114 -0
- package/src/command-line/migrate/migrate.js +1115 -0
- package/src/command-line/new/command-object.d.ts +2 -0
- package/src/command-line/new/command-object.js +25 -0
- package/src/command-line/new/new.d.ts +3 -0
- package/src/command-line/new/new.js +30 -0
- package/src/command-line/nx-commands.d.ts +10 -0
- package/src/command-line/nx-commands.js +77 -0
- package/src/command-line/release/changelog.d.ts +8 -0
- package/src/command-line/release/changelog.js +696 -0
- package/src/command-line/release/command-object.d.ts +45 -0
- package/src/command-line/release/command-object.js +237 -0
- package/src/command-line/release/config/config.d.ts +56 -0
- package/src/command-line/release/config/config.js +501 -0
- package/src/command-line/release/config/filter-release-groups.d.ts +13 -0
- package/src/command-line/release/config/filter-release-groups.js +150 -0
- package/src/command-line/release/index.d.ts +16 -0
- package/src/command-line/release/index.js +23 -0
- package/src/command-line/release/publish.d.ts +8 -0
- package/src/command-line/release/publish.js +149 -0
- package/src/command-line/release/release.d.ts +4 -0
- package/src/command-line/release/release.js +124 -0
- package/src/command-line/release/utils/batch-projects-by-generator-config.d.ts +7 -0
- package/src/command-line/release/utils/batch-projects-by-generator-config.js +37 -0
- package/src/command-line/release/utils/exec-command.d.ts +1 -0
- package/src/command-line/release/utils/exec-command.js +34 -0
- package/src/command-line/release/utils/git.d.ts +55 -0
- package/src/command-line/release/utils/git.js +261 -0
- package/src/command-line/release/utils/github.d.ts +27 -0
- package/src/command-line/release/utils/github.js +229 -0
- package/src/command-line/release/utils/launch-editor.d.ts +1 -0
- package/src/command-line/release/utils/launch-editor.js +42 -0
- package/src/command-line/release/utils/markdown.d.ts +6 -0
- package/src/command-line/release/utils/markdown.js +29 -0
- package/src/command-line/release/utils/print-changes.d.ts +7 -0
- package/src/command-line/release/utils/print-changes.js +60 -0
- package/src/command-line/release/utils/resolve-nx-json-error-message.d.ts +1 -0
- package/src/command-line/release/utils/resolve-nx-json-error-message.js +52 -0
- package/src/command-line/release/utils/resolve-semver-specifier.d.ts +3 -0
- package/src/command-line/release/utils/resolve-semver-specifier.js +69 -0
- package/src/command-line/release/utils/semver.d.ts +17 -0
- package/src/command-line/release/utils/semver.js +56 -0
- package/src/command-line/release/utils/shared.d.ts +34 -0
- package/src/command-line/release/utils/shared.js +211 -0
- package/src/command-line/release/version.d.ts +42 -0
- package/src/command-line/release/version.js +347 -0
- package/src/command-line/repair/command-object.d.ts +2 -0
- package/src/command-line/repair/command-object.js +22 -0
- package/src/command-line/repair/repair.d.ts +3 -0
- package/src/command-line/repair/repair.js +37 -0
- package/src/command-line/repair.d.ts +4 -0
- package/src/command-line/repair.js +7 -0
- package/src/command-line/report/command-object.d.ts +2 -0
- package/src/command-line/report/command-object.js +11 -0
- package/src/command-line/report/report.d.ts +48 -0
- package/src/command-line/report/report.js +232 -0
- package/src/command-line/reset/command-object.d.ts +2 -0
- package/src/command-line/reset/command-object.js +9 -0
- package/src/command-line/reset/reset.d.ts +1 -0
- package/src/command-line/reset/reset.js +23 -0
- package/src/command-line/run/command-object.d.ts +6 -0
- package/src/command-line/run/command-object.js +25 -0
- package/src/command-line/run/executor-utils.d.ts +7 -0
- package/src/command-line/run/executor-utils.js +73 -0
- package/src/command-line/run/run-one.d.ts +7 -0
- package/src/command-line/run/run-one.js +117 -0
- package/src/command-line/run/run.d.ts +51 -0
- package/src/command-line/run/run.js +172 -0
- package/src/command-line/run-many/command-object.d.ts +2 -0
- package/src/command-line/run-many/command-object.js +11 -0
- package/src/command-line/run-many/run-many.d.ts +10 -0
- package/src/command-line/run-many/run-many.js +90 -0
- package/src/command-line/run-many.d.ts +4 -0
- package/src/command-line/run-many.js +7 -0
- package/src/command-line/run-one.d.ts +4 -0
- package/src/command-line/run-one.js +7 -0
- package/src/command-line/run.d.ts +4 -0
- package/src/command-line/run.js +7 -0
- package/src/command-line/show/command-object.d.ts +22 -0
- package/src/command-line/show/command-object.js +84 -0
- package/src/command-line/show/show.d.ts +3 -0
- package/src/command-line/show/show.js +126 -0
- package/src/command-line/watch/command-object.d.ts +2 -0
- package/src/command-line/watch/command-object.js +64 -0
- package/src/command-line/watch/watch.d.ts +23 -0
- package/src/command-line/watch/watch.js +169 -0
- package/src/command-line/watch.d.ts +4 -0
- package/src/command-line/watch.js +7 -0
- package/src/command-line/yargs-utils/documentation.d.ts +2 -0
- package/src/command-line/yargs-utils/documentation.js +12 -0
- package/src/command-line/yargs-utils/shared-options.d.ts +89 -0
- package/src/command-line/yargs-utils/shared-options.js +284 -0
- package/src/commands-runner/command-graph.d.ts +13 -0
- package/src/commands-runner/command-graph.js +2 -0
- package/src/commands-runner/create-command-graph.d.ts +4 -0
- package/src/commands-runner/create-command-graph.js +44 -0
- package/src/commands-runner/get-command-projects.d.ts +3 -0
- package/src/commands-runner/get-command-projects.js +19 -0
- package/src/config/calculate-default-project-name.d.ts +4 -0
- package/src/config/calculate-default-project-name.js +42 -0
- package/src/config/configuration.d.ts +8 -0
- package/src/config/configuration.js +17 -0
- package/src/config/misc-interfaces.d.ts +199 -0
- package/src/config/misc-interfaces.js +2 -0
- package/src/config/nx-json.d.ts +372 -0
- package/src/config/nx-json.js +40 -0
- package/src/config/project-graph.d.ts +137 -0
- package/src/config/project-graph.js +37 -0
- package/src/config/schema-utils.d.ts +15 -0
- package/src/config/schema-utils.js +59 -0
- package/src/config/task-graph.d.ts +100 -0
- package/src/config/task-graph.js +2 -0
- package/src/config/workspace-json-project-json.d.ts +189 -0
- package/src/config/workspace-json-project-json.js +2 -0
- package/src/config/workspaces.d.ts +18 -0
- package/src/config/workspaces.js +35 -0
- package/src/core/graph/3rdpartylicenses.txt +833 -0
- package/src/core/graph/environment.js +1 -0
- package/src/core/graph/favicon.ico +0 -0
- package/src/core/graph/index.html +31 -0
- package/src/core/graph/main.js +1 -0
- package/src/core/graph/polyfills.js +1 -0
- package/src/core/graph/runtime.js +1 -0
- package/src/core/graph/styles.css +3 -0
- package/src/core/graph/styles.js +1 -0
- package/src/daemon/cache.d.ts +9 -0
- package/src/daemon/cache.js +52 -0
- package/src/daemon/client/client.d.ts +56 -0
- package/src/daemon/client/client.js +359 -0
- package/src/daemon/client/daemon-socket-messenger.d.ts +13 -0
- package/src/daemon/client/daemon-socket-messenger.js +26 -0
- package/src/daemon/client/exec-is-server-available.d.ts +1 -0
- package/src/daemon/client/exec-is-server-available.js +11 -0
- package/src/daemon/client/generate-help-output.d.ts +1 -0
- package/src/daemon/client/generate-help-output.js +26 -0
- package/src/daemon/server/file-watching/changed-projects.d.ts +10 -0
- package/src/daemon/server/file-watching/changed-projects.js +45 -0
- package/src/daemon/server/file-watching/file-watcher-sockets.d.ts +13 -0
- package/src/daemon/server/file-watching/file-watcher-sockets.js +66 -0
- package/src/daemon/server/handle-hash-tasks.d.ts +10 -0
- package/src/daemon/server/handle-hash-tasks.js +26 -0
- package/src/daemon/server/handle-outputs-tracking.d.ts +15 -0
- package/src/daemon/server/handle-outputs-tracking.js +36 -0
- package/src/daemon/server/handle-process-in-background.d.ts +6 -0
- package/src/daemon/server/handle-process-in-background.js +33 -0
- package/src/daemon/server/handle-request-file-data.d.ts +4 -0
- package/src/daemon/server/handle-request-file-data.js +13 -0
- package/src/daemon/server/handle-request-project-graph.d.ts +2 -0
- package/src/daemon/server/handle-request-project-graph.js +37 -0
- package/src/daemon/server/handle-request-shutdown.d.ts +6 -0
- package/src/daemon/server/handle-request-shutdown.js +26 -0
- package/src/daemon/server/logger.d.ts +18 -0
- package/src/daemon/server/logger.js +37 -0
- package/src/daemon/server/outputs-tracking.d.ts +8 -0
- package/src/daemon/server/outputs-tracking.js +94 -0
- package/src/daemon/server/project-graph-incremental-recomputation.d.ts +22 -0
- package/src/daemon/server/project-graph-incremental-recomputation.js +227 -0
- package/src/daemon/server/server.d.ts +9 -0
- package/src/daemon/server/server.js +303 -0
- package/src/daemon/server/shutdown-utils.d.ts +17 -0
- package/src/daemon/server/shutdown-utils.js +77 -0
- package/src/daemon/server/start.d.ts +1 -0
- package/src/daemon/server/start.js +17 -0
- package/src/daemon/server/watcher.d.ts +12 -0
- package/src/daemon/server/watcher.js +96 -0
- package/src/daemon/socket-utils.d.ts +11 -0
- package/src/daemon/socket-utils.js +42 -0
- package/src/daemon/tmp-dir.d.ts +8 -0
- package/src/daemon/tmp-dir.js +68 -0
- package/src/devkit-exports.d.ts +135 -0
- package/src/devkit-exports.js +140 -0
- package/src/devkit-internals.d.ts +19 -0
- package/src/devkit-internals.js +37 -0
- package/src/devkit-testing-exports.d.ts +2 -0
- package/src/devkit-testing-exports.js +8 -0
- package/src/executors/noop/noop.impl.d.ts +3 -0
- package/src/executors/noop/noop.impl.js +6 -0
- package/src/executors/noop/schema.json +10 -0
- package/src/executors/run-commands/run-commands.impl.d.ts +42 -0
- package/src/executors/run-commands/run-commands.impl.js +247 -0
- package/src/executors/run-commands/schema.json +150 -0
- package/src/executors/run-script/run-script.impl.d.ts +8 -0
- package/src/executors/run-script/run-script.impl.js +56 -0
- package/src/executors/run-script/schema.json +28 -0
- package/src/executors/utils/convert-nx-executor.d.ts +10 -0
- package/src/executors/utils/convert-nx-executor.js +82 -0
- package/src/generators/internal-utils/format-changed-files-with-prettier-if-available.d.ts +8 -0
- package/src/generators/internal-utils/format-changed-files-with-prettier-if-available.js +49 -0
- package/src/generators/testing-utils/create-tree-with-empty-workspace.d.ts +11 -0
- package/src/generators/testing-utils/create-tree-with-empty-workspace.js +46 -0
- package/src/generators/testing-utils/create-tree.d.ts +5 -0
- package/src/generators/testing-utils/create-tree.js +11 -0
- package/src/generators/tree.d.ts +128 -0
- package/src/generators/tree.js +309 -0
- package/src/generators/utils/glob.d.ts +11 -0
- package/src/generators/utils/glob.js +35 -0
- package/src/generators/utils/json.d.ts +28 -0
- package/src/generators/utils/json.js +48 -0
- package/src/generators/utils/nx-json.d.ts +11 -0
- package/src/generators/utils/nx-json.js +59 -0
- package/src/generators/utils/project-configuration.d.ts +42 -0
- package/src/generators/utils/project-configuration.js +239 -0
- package/src/hasher/create-task-hasher.d.ts +4 -0
- package/src/hasher/create-task-hasher.js +16 -0
- package/src/hasher/file-hasher.d.ts +2 -0
- package/src/hasher/file-hasher.js +19 -0
- package/src/hasher/hash-task.d.ts +7 -0
- package/src/hasher/hash-task.js +54 -0
- package/src/hasher/native-task-hasher-impl.d.ts +19 -0
- package/src/hasher/native-task-hasher-impl.js +37 -0
- package/src/hasher/node-task-hasher-impl.d.ts +49 -0
- package/src/hasher/node-task-hasher-impl.js +431 -0
- package/src/hasher/task-hasher.d.ts +129 -0
- package/src/hasher/task-hasher.js +266 -0
- package/src/index.d.ts +1 -0
- package/src/index.js +5 -0
- package/src/migrations/update-15-0-0/migrate-to-inputs.d.ts +2 -0
- package/src/migrations/update-15-0-0/migrate-to-inputs.js +102 -0
- package/src/migrations/update-15-0-0/prefix-outputs.d.ts +2 -0
- package/src/migrations/update-15-0-0/prefix-outputs.js +64 -0
- package/src/migrations/update-15-1-0/set-project-names.d.ts +2 -0
- package/src/migrations/update-15-1-0/set-project-names.js +32 -0
- package/src/migrations/update-15-8-2/update-nxw.d.ts +2 -0
- package/src/migrations/update-15-8-2/update-nxw.js +7 -0
- package/src/migrations/update-16-0-0/remove-nrwl-cli.d.ts +2 -0
- package/src/migrations/update-16-0-0/remove-nrwl-cli.js +16 -0
- package/src/migrations/update-16-0-0/update-depends-on-to-tokens.d.ts +2 -0
- package/src/migrations/update-16-0-0/update-depends-on-to-tokens.js +97 -0
- package/src/migrations/update-16-0-0/update-nx-cloud-runner.d.ts +2 -0
- package/src/migrations/update-16-0-0/update-nx-cloud-runner.js +27 -0
- package/src/migrations/update-16-2-0/remove-run-commands-output-path.d.ts +2 -0
- package/src/migrations/update-16-2-0/remove-run-commands-output-path.js +45 -0
- package/src/migrations/update-16-8-0/escape-dollar-sign-env-variables.d.ts +12 -0
- package/src/migrations/update-16-8-0/escape-dollar-sign-env-variables.js +60 -0
- package/src/migrations/update-16-9-0/remove-project-name-and-root-format.d.ts +2 -0
- package/src/migrations/update-16-9-0/remove-project-name-and-root-format.js +21 -0
- package/src/migrations/update-17-0-0/move-cache-directory.d.ts +2 -0
- package/src/migrations/update-17-0-0/move-cache-directory.js +35 -0
- package/src/migrations/update-17-0-0/rm-default-collection-npm-scope.d.ts +2 -0
- package/src/migrations/update-17-0-0/rm-default-collection-npm-scope.js +72 -0
- package/src/migrations/update-17-0-0/use-minimal-config-for-tasks-runner-options.d.ts +2 -0
- package/src/migrations/update-17-0-0/use-minimal-config-for-tasks-runner-options.js +122 -0
- package/src/migrations/update-17-3-0/nx-release-path.d.ts +3 -0
- package/src/migrations/update-17-3-0/nx-release-path.js +49 -0
- package/src/migrations/update-17-3-0/update-nxw.d.ts +2 -0
- package/src/migrations/update-17-3-0/update-nxw.js +7 -0
- package/src/native/assert-supported-platform.d.ts +1 -0
- package/src/native/assert-supported-platform.js +39 -0
- package/src/native/index.d.ts +192 -0
- package/src/native/index.js +289 -0
- package/src/native/transform-objects.d.ts +3 -0
- package/src/native/transform-objects.js +50 -0
- package/src/nx-cloud/debug-logger.d.ts +1 -0
- package/src/nx-cloud/debug-logger.js +9 -0
- package/src/nx-cloud/generators/connect-to-nx-cloud/connect-to-nx-cloud.d.ts +8 -0
- package/src/nx-cloud/generators/connect-to-nx-cloud/connect-to-nx-cloud.js +107 -0
- package/src/nx-cloud/generators/connect-to-nx-cloud/schema.json +27 -0
- package/src/nx-cloud/nx-cloud-tasks-runner-shell.d.ts +15 -0
- package/src/nx-cloud/nx-cloud-tasks-runner-shell.js +41 -0
- package/src/nx-cloud/resolution-helpers.d.ts +1 -0
- package/src/nx-cloud/resolution-helpers.js +20 -0
- package/src/nx-cloud/update-manager.d.ts +17 -0
- package/src/nx-cloud/update-manager.js +240 -0
- package/src/nx-cloud/utilities/axios.d.ts +2 -0
- package/src/nx-cloud/utilities/axios.js +24 -0
- package/src/nx-cloud/utilities/environment.d.ts +3 -0
- package/src/nx-cloud/utilities/environment.js +47 -0
- package/src/nx-cloud/utilities/get-cloud-options.d.ts +2 -0
- package/src/nx-cloud/utilities/get-cloud-options.js +11 -0
- package/src/plugins/js/hasher/hasher.d.ts +5 -0
- package/src/plugins/js/hasher/hasher.js +52 -0
- package/src/plugins/js/index.d.ts +4 -0
- package/src/plugins/js/index.js +96 -0
- package/src/plugins/js/lock-file/lock-file.d.ts +34 -0
- package/src/plugins/js/lock-file/lock-file.js +169 -0
- package/src/plugins/js/lock-file/npm-parser.d.ts +7 -0
- package/src/plugins/js/lock-file/npm-parser.js +463 -0
- package/src/plugins/js/lock-file/pnpm-parser.d.ts +7 -0
- package/src/plugins/js/lock-file/pnpm-parser.js +294 -0
- package/src/plugins/js/lock-file/project-graph-pruning.d.ts +7 -0
- package/src/plugins/js/lock-file/project-graph-pruning.js +155 -0
- package/src/plugins/js/lock-file/utils/package-json.d.ts +10 -0
- package/src/plugins/js/lock-file/utils/package-json.js +34 -0
- package/src/plugins/js/lock-file/utils/pnpm-normalizer.d.ts +38 -0
- package/src/plugins/js/lock-file/utils/pnpm-normalizer.js +575 -0
- package/src/plugins/js/lock-file/yarn-parser.d.ts +7 -0
- package/src/plugins/js/lock-file/yarn-parser.js +437 -0
- package/src/plugins/js/package-json/create-package-json.d.ts +27 -0
- package/src/plugins/js/package-json/create-package-json.js +207 -0
- package/src/plugins/js/project-graph/affected/lock-file-changes.d.ts +4 -0
- package/src/plugins/js/project-graph/affected/lock-file-changes.js +16 -0
- package/src/plugins/js/project-graph/affected/npm-packages.d.ts +4 -0
- package/src/plugins/js/project-graph/affected/npm-packages.js +56 -0
- package/src/plugins/js/project-graph/affected/touched-projects.d.ts +2 -0
- package/src/plugins/js/project-graph/affected/touched-projects.js +18 -0
- package/src/plugins/js/project-graph/affected/tsconfig-json-changes.d.ts +4 -0
- package/src/plugins/js/project-graph/affected/tsconfig-json-changes.js +63 -0
- package/src/plugins/js/project-graph/build-dependencies/build-dependencies.d.ts +6 -0
- package/src/plugins/js/project-graph/build-dependencies/build-dependencies.js +33 -0
- package/src/plugins/js/project-graph/build-dependencies/explicit-package-json-dependencies.d.ts +3 -0
- package/src/plugins/js/project-graph/build-dependencies/explicit-package-json-dependencies.js +82 -0
- package/src/plugins/js/project-graph/build-dependencies/explicit-project-dependencies.d.ts +3 -0
- package/src/plugins/js/project-graph/build-dependencies/explicit-project-dependencies.js +94 -0
- package/src/plugins/js/project-graph/build-dependencies/strip-source-code.d.ts +7 -0
- package/src/plugins/js/project-graph/build-dependencies/strip-source-code.js +156 -0
- package/src/plugins/js/project-graph/build-dependencies/target-project-locator.d.ts +32 -0
- package/src/plugins/js/project-graph/build-dependencies/target-project-locator.js +183 -0
- package/src/plugins/js/project-graph/build-dependencies/typescript-import-locator.d.ts +16 -0
- package/src/plugins/js/project-graph/build-dependencies/typescript-import-locator.js +120 -0
- package/src/plugins/js/project-graph/build-nodes/build-npm-package-nodes.d.ts +2 -0
- package/src/plugins/js/project-graph/build-nodes/build-npm-package-nodes.js +32 -0
- package/src/plugins/js/utils/config.d.ts +2 -0
- package/src/plugins/js/utils/config.js +65 -0
- package/src/plugins/js/utils/register.d.ts +151 -0
- package/src/plugins/js/utils/register.js +215 -0
- package/src/plugins/js/utils/typescript.d.ts +14 -0
- package/src/plugins/js/utils/typescript.js +98 -0
- package/src/plugins/js/versions.d.ts +1 -0
- package/src/plugins/js/versions.js +4 -0
- package/src/plugins/package-json-workspaces/create-nodes.d.ts +19 -0
- package/src/plugins/package-json-workspaces/create-nodes.js +130 -0
- package/src/plugins/package-json-workspaces/index.d.ts +1 -0
- package/src/plugins/package-json-workspaces/index.js +4 -0
- package/src/plugins/project-json/build-nodes/package-json-next-to-project-json.d.ts +2 -0
- package/src/plugins/project-json/build-nodes/package-json-next-to-project-json.js +47 -0
- package/src/plugins/project-json/build-nodes/project-json.d.ts +4 -0
- package/src/plugins/project-json/build-nodes/project-json.js +29 -0
- package/src/plugins/target-defaults/target-defaults-plugin.d.ts +8 -0
- package/src/plugins/target-defaults/target-defaults-plugin.js +103 -0
- package/src/project-graph/affected/affected-project-graph-models.d.ts +11 -0
- package/src/project-graph/affected/affected-project-graph-models.js +2 -0
- package/src/project-graph/affected/affected-project-graph.d.ts +4 -0
- package/src/project-graph/affected/affected-project-graph.js +83 -0
- package/src/project-graph/affected/locators/project-glob-changes.d.ts +2 -0
- package/src/project-graph/affected/locators/project-glob-changes.js +31 -0
- package/src/project-graph/affected/locators/workspace-json-changes.d.ts +4 -0
- package/src/project-graph/affected/locators/workspace-json-changes.js +47 -0
- package/src/project-graph/affected/locators/workspace-projects.d.ts +5 -0
- package/src/project-graph/affected/locators/workspace-projects.js +85 -0
- package/src/project-graph/build-project-graph.d.ts +14 -0
- package/src/project-graph/build-project-graph.js +219 -0
- package/src/project-graph/file-map-utils.d.ts +15 -0
- package/src/project-graph/file-map-utils.js +63 -0
- package/src/project-graph/file-utils.d.ts +31 -0
- package/src/project-graph/file-utils.js +181 -0
- package/src/project-graph/nx-deps-cache.d.ts +48 -0
- package/src/project-graph/nx-deps-cache.js +228 -0
- package/src/project-graph/operators.d.ts +12 -0
- package/src/project-graph/operators.js +114 -0
- package/src/project-graph/project-graph-builder.d.ts +133 -0
- package/src/project-graph/project-graph-builder.js +379 -0
- package/src/project-graph/project-graph.d.ts +48 -0
- package/src/project-graph/project-graph.js +188 -0
- package/src/project-graph/utils/build-all-workspace-files.d.ts +2 -0
- package/src/project-graph/utils/build-all-workspace-files.js +15 -0
- package/src/project-graph/utils/find-project-for-path.d.ts +20 -0
- package/src/project-graph/utils/find-project-for-path.js +57 -0
- package/src/project-graph/utils/implicit-project-dependencies.d.ts +3 -0
- package/src/project-graph/utils/implicit-project-dependencies.js +19 -0
- package/src/project-graph/utils/normalize-project-nodes.d.ts +10 -0
- package/src/project-graph/utils/normalize-project-nodes.js +92 -0
- package/src/project-graph/utils/project-configuration-utils.d.ts +53 -0
- package/src/project-graph/utils/project-configuration-utils.js +456 -0
- package/src/project-graph/utils/retrieve-workspace-files.d.ts +37 -0
- package/src/project-graph/utils/retrieve-workspace-files.js +109 -0
- package/src/tasks-runner/batch/batch-messages.d.ts +33 -0
- package/src/tasks-runner/batch/batch-messages.js +9 -0
- package/src/tasks-runner/batch/run-batch.d.ts +1 -0
- package/src/tasks-runner/batch/run-batch.js +77 -0
- package/src/tasks-runner/cache.d.ts +36 -0
- package/src/tasks-runner/cache.js +236 -0
- package/src/tasks-runner/create-task-graph.d.ts +25 -0
- package/src/tasks-runner/create-task-graph.js +225 -0
- package/src/tasks-runner/default-tasks-runner.d.ts +20 -0
- package/src/tasks-runner/default-tasks-runner.js +29 -0
- package/src/tasks-runner/fork.d.ts +1 -0
- package/src/tasks-runner/fork.js +23 -0
- package/src/tasks-runner/forked-process-task-runner.d.ts +44 -0
- package/src/tasks-runner/forked-process-task-runner.js +396 -0
- package/src/tasks-runner/init-tasks-runner.d.ts +11 -0
- package/src/tasks-runner/init-tasks-runner.js +57 -0
- package/src/tasks-runner/life-cycle.d.ts +43 -0
- package/src/tasks-runner/life-cycle.js +71 -0
- package/src/tasks-runner/life-cycles/dynamic-run-many-terminal-output-life-cycle.d.ts +25 -0
- package/src/tasks-runner/life-cycles/dynamic-run-many-terminal-output-life-cycle.js +345 -0
- package/src/tasks-runner/life-cycles/dynamic-run-one-terminal-output-life-cycle.d.ts +24 -0
- package/src/tasks-runner/life-cycles/dynamic-run-one-terminal-output-life-cycle.js +224 -0
- package/src/tasks-runner/life-cycles/empty-terminal-output-life-cycle.d.ts +5 -0
- package/src/tasks-runner/life-cycles/empty-terminal-output-life-cycle.js +16 -0
- package/src/tasks-runner/life-cycles/formatting-utils.d.ts +3 -0
- package/src/tasks-runner/life-cycles/formatting-utils.js +44 -0
- package/src/tasks-runner/life-cycles/invoke-runner-terminal-output-life-cycle.d.ts +17 -0
- package/src/tasks-runner/life-cycles/invoke-runner-terminal-output-life-cycle.js +67 -0
- package/src/tasks-runner/life-cycles/pretty-time.d.ts +4 -0
- package/src/tasks-runner/life-cycles/pretty-time.js +74 -0
- package/src/tasks-runner/life-cycles/static-run-many-terminal-output-life-cycle.d.ts +33 -0
- package/src/tasks-runner/life-cycles/static-run-many-terminal-output-life-cycle.js +99 -0
- package/src/tasks-runner/life-cycles/static-run-one-terminal-output-life-cycle.d.ts +31 -0
- package/src/tasks-runner/life-cycles/static-run-one-terminal-output-life-cycle.js +89 -0
- package/src/tasks-runner/life-cycles/store-run-information-life-cycle.d.ts +22 -0
- package/src/tasks-runner/life-cycles/store-run-information-life-cycle.js +87 -0
- package/src/tasks-runner/life-cycles/task-profiling-life-cycle.d.ts +19 -0
- package/src/tasks-runner/life-cycles/task-profiling-life-cycle.js +73 -0
- package/src/tasks-runner/life-cycles/task-timings-life-cycle.d.ts +13 -0
- package/src/tasks-runner/life-cycles/task-timings-life-cycle.js +39 -0
- package/src/tasks-runner/life-cycles/view-logs-utils.d.ts +1 -0
- package/src/tasks-runner/life-cycles/view-logs-utils.js +16 -0
- package/src/tasks-runner/psuedo-ipc.d.ts +49 -0
- package/src/tasks-runner/psuedo-ipc.js +140 -0
- package/src/tasks-runner/remove-old-cache-records.d.ts +1 -0
- package/src/tasks-runner/remove-old-cache-records.js +61 -0
- package/src/tasks-runner/run-command.d.ts +28 -0
- package/src/tasks-runner/run-command.js +353 -0
- package/src/tasks-runner/task-env.d.ts +8 -0
- package/src/tasks-runner/task-env.js +144 -0
- package/src/tasks-runner/task-graph-utils.d.ts +7 -0
- package/src/tasks-runner/task-graph-utils.js +55 -0
- package/src/tasks-runner/task-orchestrator.d.ts +50 -0
- package/src/tasks-runner/task-orchestrator.js +375 -0
- package/src/tasks-runner/tasks-runner.d.ts +23 -0
- package/src/tasks-runner/tasks-runner.js +2 -0
- package/src/tasks-runner/tasks-schedule.d.ts +36 -0
- package/src/tasks-runner/tasks-schedule.js +142 -0
- package/src/tasks-runner/utils.d.ts +51 -0
- package/src/tasks-runner/utils.js +293 -0
- package/src/utils/ab-testing.d.ts +51 -0
- package/src/utils/ab-testing.js +91 -0
- package/src/utils/all-file-data.d.ts +2 -0
- package/src/utils/all-file-data.js +15 -0
- package/src/utils/app-root.d.ts +8 -0
- package/src/utils/app-root.js +12 -0
- package/src/utils/assert-workspace-validity.d.ts +3 -0
- package/src/utils/assert-workspace-validity.js +84 -0
- package/src/utils/async-iterator.d.ts +2 -0
- package/src/utils/async-iterator.js +17 -0
- package/src/utils/cache-directory.d.ts +6 -0
- package/src/utils/cache-directory.js +60 -0
- package/src/utils/child-process.d.ts +19 -0
- package/src/utils/child-process.js +117 -0
- package/src/utils/chunkify.d.ts +1 -0
- package/src/utils/chunkify.js +38 -0
- package/src/utils/code-frames.d.ts +14 -0
- package/src/utils/code-frames.js +119 -0
- package/src/utils/collapse-expanded-outputs.d.ts +1 -0
- package/src/utils/collapse-expanded-outputs.js +41 -0
- package/src/utils/command-line-utils.d.ts +48 -0
- package/src/utils/command-line-utils.js +254 -0
- package/src/utils/consume-messages-from-socket.d.ts +1 -0
- package/src/utils/consume-messages-from-socket.js +22 -0
- package/src/utils/default-base.d.ts +1 -0
- package/src/utils/default-base.js +15 -0
- package/src/utils/exit-codes.d.ts +6 -0
- package/src/utils/exit-codes.js +20 -0
- package/src/utils/fileutils.d.ts +69 -0
- package/src/utils/fileutils.js +135 -0
- package/src/utils/find-matching-projects.d.ts +10 -0
- package/src/utils/find-matching-projects.js +198 -0
- package/src/utils/find-workspace-root.d.ts +11 -0
- package/src/utils/find-workspace-root.js +34 -0
- package/src/utils/globs.d.ts +1 -0
- package/src/utils/globs.js +8 -0
- package/src/utils/ignore.d.ts +8 -0
- package/src/utils/ignore.js +68 -0
- package/src/utils/installation-directory.d.ts +2 -0
- package/src/utils/installation-directory.js +13 -0
- package/src/utils/is-ci.d.ts +1 -0
- package/src/utils/is-ci.js +20 -0
- package/src/utils/json-diff.d.ts +18 -0
- package/src/utils/json-diff.js +112 -0
- package/src/utils/json.d.ts +44 -0
- package/src/utils/json.js +60 -0
- package/src/utils/logger.d.ts +11 -0
- package/src/utils/logger.js +47 -0
- package/src/utils/nx-cloud-utils.d.ts +4 -0
- package/src/utils/nx-cloud-utils.js +27 -0
- package/src/utils/nx-plugin.d.ts +119 -0
- package/src/utils/nx-plugin.deprecated.d.ts +31 -0
- package/src/utils/nx-plugin.deprecated.js +25 -0
- package/src/utils/nx-plugin.js +293 -0
- package/src/utils/object-sort.d.ts +1 -0
- package/src/utils/object-sort.js +10 -0
- package/src/utils/output.d.ts +72 -0
- package/src/utils/output.js +239 -0
- package/src/utils/package-json.d.ts +98 -0
- package/src/utils/package-json.js +134 -0
- package/src/utils/package-manager.d.ts +93 -0
- package/src/utils/package-manager.js +300 -0
- package/src/utils/params.d.ts +138 -0
- package/src/utils/params.js +684 -0
- package/src/utils/path.d.ts +19 -0
- package/src/utils/path.js +38 -0
- package/src/utils/perf-logging.d.ts +1 -0
- package/src/utils/perf-logging.js +11 -0
- package/src/utils/plugins/community-plugins.d.ts +2 -0
- package/src/utils/plugins/community-plugins.js +29 -0
- package/src/utils/plugins/core-plugins.d.ts +3 -0
- package/src/utils/plugins/core-plugins.js +114 -0
- package/src/utils/plugins/index.d.ts +4 -0
- package/src/utils/plugins/index.js +14 -0
- package/src/utils/plugins/installed-plugins.d.ts +6 -0
- package/src/utils/plugins/installed-plugins.js +104 -0
- package/src/utils/plugins/local-plugins.d.ts +5 -0
- package/src/utils/plugins/local-plugins.js +58 -0
- package/src/utils/plugins/models.d.ts +22 -0
- package/src/utils/plugins/models.js +2 -0
- package/src/utils/plugins/plugin-capabilities.d.ts +4 -0
- package/src/utils/plugins/plugin-capabilities.js +124 -0
- package/src/utils/plugins/shared.d.ts +1 -0
- package/src/utils/plugins/shared.js +8 -0
- package/src/utils/print-help.d.ts +11 -0
- package/src/utils/print-help.js +265 -0
- package/src/utils/project-graph-utils.d.ts +13 -0
- package/src/utils/project-graph-utils.js +74 -0
- package/src/utils/promised-based-queue.d.ts +6 -0
- package/src/utils/promised-based-queue.js +43 -0
- package/src/utils/serialize-overrides-into-command-line.d.ts +3 -0
- package/src/utils/serialize-overrides-into-command-line.js +43 -0
- package/src/utils/split-target.d.ts +3 -0
- package/src/utils/split-target.js +49 -0
- package/src/utils/strip-indents.d.ts +14 -0
- package/src/utils/strip-indents.js +24 -0
- package/src/utils/typescript.d.ts +1 -0
- package/src/utils/typescript.js +5 -0
- package/src/utils/update-nxw.d.ts +2 -0
- package/src/utils/update-nxw.js +12 -0
- package/src/utils/versions.d.ts +1 -0
- package/src/utils/versions.js +4 -0
- package/src/utils/workspace-configuration-check.d.ts +1 -0
- package/src/utils/workspace-configuration-check.js +37 -0
- package/src/utils/workspace-context.d.ts +10 -0
- package/src/utils/workspace-context.js +56 -0
- package/src/utils/workspace-root.d.ts +6 -0
- package/src/utils/workspace-root.js +39 -0
- package/tasks-runners/default.d.ts +1 -0
- package/tasks-runners/default.js +5 -0
|
@@ -0,0 +1,1115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.migrate = exports.executeMigrations = exports.parseMigrationsOptions = exports.Migrator = exports.normalizeVersion = void 0;
|
|
4
|
+
const chalk = require("chalk");
|
|
5
|
+
const child_process_1 = require("child_process");
|
|
6
|
+
const enquirer_1 = require("enquirer");
|
|
7
|
+
const path_1 = require("path");
|
|
8
|
+
const semver_1 = require("semver");
|
|
9
|
+
const node_url_1 = require("node:url");
|
|
10
|
+
const util_1 = require("util");
|
|
11
|
+
const tree_1 = require("../../generators/tree");
|
|
12
|
+
const fileutils_1 = require("../../utils/fileutils");
|
|
13
|
+
const logger_1 = require("../../utils/logger");
|
|
14
|
+
const package_json_1 = require("../../utils/package-json");
|
|
15
|
+
const package_manager_1 = require("../../utils/package-manager");
|
|
16
|
+
const params_1 = require("../../utils/params");
|
|
17
|
+
const connect_to_nx_cloud_1 = require("../connect/connect-to-nx-cloud");
|
|
18
|
+
const output_1 = require("../../utils/output");
|
|
19
|
+
const fs_1 = require("fs");
|
|
20
|
+
const workspace_root_1 = require("../../utils/workspace-root");
|
|
21
|
+
const is_ci_1 = require("../../utils/is-ci");
|
|
22
|
+
const installation_directory_1 = require("../../utils/installation-directory");
|
|
23
|
+
const configuration_1 = require("../../config/configuration");
|
|
24
|
+
const child_process_2 = require("../../utils/child-process");
|
|
25
|
+
const client_1 = require("../../daemon/client/client");
|
|
26
|
+
const nx_cloud_utils_1 = require("../../utils/nx-cloud-utils");
|
|
27
|
+
const project_graph_1 = require("../../project-graph/project-graph");
|
|
28
|
+
const execAsync = (0, util_1.promisify)(child_process_1.exec);
|
|
29
|
+
function normalizeVersion(version) {
|
|
30
|
+
const [semver, ...prereleaseTagParts] = version.split('-');
|
|
31
|
+
// Handle versions like 1.0.0-beta-next.2
|
|
32
|
+
const prereleaseTag = prereleaseTagParts.join('-');
|
|
33
|
+
const [major, minor, patch] = semver.split('.');
|
|
34
|
+
const newSemver = `${major || 0}.${minor || 0}.${patch || 0}`;
|
|
35
|
+
const newVersion = prereleaseTag
|
|
36
|
+
? `${newSemver}-${prereleaseTag}`
|
|
37
|
+
: newSemver;
|
|
38
|
+
const withoutPatch = `${major || 0}.${minor || 0}.0`;
|
|
39
|
+
const withoutPatchAndMinor = `${major || 0}.0.0`;
|
|
40
|
+
const variationsToCheck = [
|
|
41
|
+
newVersion,
|
|
42
|
+
newSemver,
|
|
43
|
+
withoutPatch,
|
|
44
|
+
withoutPatchAndMinor,
|
|
45
|
+
];
|
|
46
|
+
for (const variation of variationsToCheck) {
|
|
47
|
+
try {
|
|
48
|
+
if ((0, semver_1.gt)(variation, '0.0.0')) {
|
|
49
|
+
return variation;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
catch { }
|
|
53
|
+
}
|
|
54
|
+
return '0.0.0';
|
|
55
|
+
}
|
|
56
|
+
exports.normalizeVersion = normalizeVersion;
|
|
57
|
+
function cleanSemver(version) {
|
|
58
|
+
return (0, semver_1.clean)(version) ?? (0, semver_1.coerce)(version);
|
|
59
|
+
}
|
|
60
|
+
function normalizeSlashes(packageName) {
|
|
61
|
+
return packageName.replace(/\\/g, '/');
|
|
62
|
+
}
|
|
63
|
+
class Migrator {
|
|
64
|
+
constructor(opts) {
|
|
65
|
+
this.packageUpdates = {};
|
|
66
|
+
this.collectedVersions = {};
|
|
67
|
+
this.promptAnswers = {};
|
|
68
|
+
this.packageJson = opts.packageJson;
|
|
69
|
+
this.nxInstallation = opts.nxInstallation;
|
|
70
|
+
this.getInstalledPackageVersion = opts.getInstalledPackageVersion;
|
|
71
|
+
this.fetch = opts.fetch;
|
|
72
|
+
this.installedPkgVersionOverrides = opts.from;
|
|
73
|
+
this.to = opts.to;
|
|
74
|
+
this.interactive = opts.interactive;
|
|
75
|
+
this.excludeAppliedMigrations = opts.excludeAppliedMigrations;
|
|
76
|
+
}
|
|
77
|
+
async migrate(targetPackage, targetVersion) {
|
|
78
|
+
await this.buildPackageJsonUpdates(targetPackage, {
|
|
79
|
+
version: targetVersion,
|
|
80
|
+
addToPackageJson: false,
|
|
81
|
+
});
|
|
82
|
+
const migrations = await this.createMigrateJson();
|
|
83
|
+
return {
|
|
84
|
+
packageUpdates: this.packageUpdates,
|
|
85
|
+
migrations,
|
|
86
|
+
minVersionWithSkippedUpdates: this.minVersionWithSkippedUpdates,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
async createMigrateJson() {
|
|
90
|
+
const migrations = await Promise.all(Object.keys(this.packageUpdates).map(async (packageName) => {
|
|
91
|
+
const currentVersion = this.getPkgVersion(packageName);
|
|
92
|
+
if (currentVersion === null)
|
|
93
|
+
return [];
|
|
94
|
+
const { version } = this.packageUpdates[packageName];
|
|
95
|
+
const { generators } = await this.fetch(packageName, version);
|
|
96
|
+
if (!generators)
|
|
97
|
+
return [];
|
|
98
|
+
return Object.entries(generators)
|
|
99
|
+
.filter(([, migration]) => migration.version &&
|
|
100
|
+
this.gt(migration.version, currentVersion) &&
|
|
101
|
+
this.lte(migration.version, version) &&
|
|
102
|
+
this.areMigrationRequirementsMet(packageName, migration))
|
|
103
|
+
.map(([migrationName, migration]) => ({
|
|
104
|
+
...migration,
|
|
105
|
+
package: packageName,
|
|
106
|
+
name: migrationName,
|
|
107
|
+
}));
|
|
108
|
+
}));
|
|
109
|
+
return migrations.flat();
|
|
110
|
+
}
|
|
111
|
+
async buildPackageJsonUpdates(targetPackage, target) {
|
|
112
|
+
const packagesToCheck = await this.populatePackageJsonUpdatesAndGetPackagesToCheck(targetPackage, target);
|
|
113
|
+
for (const packageToCheck of packagesToCheck) {
|
|
114
|
+
const filteredUpdates = {};
|
|
115
|
+
for (const packageUpdate of packageToCheck.updates) {
|
|
116
|
+
if (this.areRequirementsMet(packageUpdate.requires) &&
|
|
117
|
+
(!this.interactive ||
|
|
118
|
+
(await this.runPackageJsonUpdatesConfirmationPrompt(packageUpdate)))) {
|
|
119
|
+
Object.entries(packageUpdate.packages).forEach(([name, update]) => {
|
|
120
|
+
filteredUpdates[name] = update;
|
|
121
|
+
this.packageUpdates[name] = update;
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
await Promise.all(Object.entries(filteredUpdates).map(([name, update]) => this.buildPackageJsonUpdates(name, update)));
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
async populatePackageJsonUpdatesAndGetPackagesToCheck(targetPackage, target) {
|
|
129
|
+
let targetVersion = target.version;
|
|
130
|
+
if (this.to[targetPackage]) {
|
|
131
|
+
targetVersion = this.to[targetPackage];
|
|
132
|
+
}
|
|
133
|
+
if (!this.getPkgVersion(targetPackage)) {
|
|
134
|
+
this.addPackageUpdate(targetPackage, {
|
|
135
|
+
version: target.version,
|
|
136
|
+
addToPackageJson: target.addToPackageJson || false,
|
|
137
|
+
});
|
|
138
|
+
return [];
|
|
139
|
+
}
|
|
140
|
+
let migrationConfig;
|
|
141
|
+
try {
|
|
142
|
+
migrationConfig = await this.fetch(targetPackage, targetVersion);
|
|
143
|
+
}
|
|
144
|
+
catch (e) {
|
|
145
|
+
if (e?.message?.includes('No matching version')) {
|
|
146
|
+
throw new Error(`${e.message}\nRun migrate with --to="package1@version1,package2@version2"`);
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
throw e;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
targetVersion = migrationConfig.version;
|
|
153
|
+
if (this.collectedVersions[targetPackage] &&
|
|
154
|
+
(0, semver_1.gte)(this.collectedVersions[targetPackage], targetVersion)) {
|
|
155
|
+
return [];
|
|
156
|
+
}
|
|
157
|
+
this.collectedVersions[targetPackage] = targetVersion;
|
|
158
|
+
this.addPackageUpdate(targetPackage, {
|
|
159
|
+
version: migrationConfig.version,
|
|
160
|
+
addToPackageJson: target.addToPackageJson || false,
|
|
161
|
+
});
|
|
162
|
+
const { packageJsonUpdates, packageGroupOrder } = this.getPackageJsonUpdatesFromMigrationConfig(targetPackage, targetVersion, migrationConfig);
|
|
163
|
+
if (!packageJsonUpdates.length) {
|
|
164
|
+
return [];
|
|
165
|
+
}
|
|
166
|
+
const shouldCheckUpdates = packageJsonUpdates.some((packageJsonUpdate) => (this.interactive && packageJsonUpdate['x-prompt']) ||
|
|
167
|
+
Object.keys(packageJsonUpdate.requires ?? {}).length);
|
|
168
|
+
if (shouldCheckUpdates) {
|
|
169
|
+
return [{ package: targetPackage, updates: packageJsonUpdates }];
|
|
170
|
+
}
|
|
171
|
+
const packageUpdatesToApply = packageJsonUpdates.reduce((m, c) => ({ ...m, ...c.packages }), {});
|
|
172
|
+
return (await Promise.all(Object.entries(packageUpdatesToApply).map(([packageName, packageUpdate]) => this.populatePackageJsonUpdatesAndGetPackagesToCheck(packageName, packageUpdate))))
|
|
173
|
+
.filter((pkgs) => pkgs.length)
|
|
174
|
+
.flat()
|
|
175
|
+
.sort((pkgUpdate1, pkgUpdate2) => packageGroupOrder.indexOf(pkgUpdate1.package) -
|
|
176
|
+
packageGroupOrder.indexOf(pkgUpdate2.package));
|
|
177
|
+
}
|
|
178
|
+
getPackageJsonUpdatesFromMigrationConfig(packageName, targetVersion, migrationConfig) {
|
|
179
|
+
const packageGroupOrder = this.getPackageJsonUpdatesFromPackageGroup(packageName, targetVersion, migrationConfig);
|
|
180
|
+
if (!migrationConfig.packageJsonUpdates ||
|
|
181
|
+
!this.getPkgVersion(packageName)) {
|
|
182
|
+
return { packageJsonUpdates: [], packageGroupOrder };
|
|
183
|
+
}
|
|
184
|
+
const packageJsonUpdates = this.filterPackageJsonUpdates(migrationConfig.packageJsonUpdates, packageName, targetVersion);
|
|
185
|
+
return { packageJsonUpdates, packageGroupOrder };
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Mutates migrationConfig, adding package group updates into packageJsonUpdates section
|
|
189
|
+
*
|
|
190
|
+
* @param packageName Package which is being migrated
|
|
191
|
+
* @param targetVersion Version which is being migrated to
|
|
192
|
+
* @param migrationConfig Configuration which is mutated to contain package json updates
|
|
193
|
+
* @returns Order of package groups
|
|
194
|
+
*/
|
|
195
|
+
getPackageJsonUpdatesFromPackageGroup(packageName, targetVersion, migrationConfig) {
|
|
196
|
+
const packageGroup = packageName === '@nrwl/workspace' && (0, semver_1.lt)(targetVersion, '14.0.0-beta.0')
|
|
197
|
+
? LEGACY_NRWL_PACKAGE_GROUP
|
|
198
|
+
: migrationConfig.packageGroup ?? [];
|
|
199
|
+
let packageGroupOrder = [];
|
|
200
|
+
if (packageGroup.length) {
|
|
201
|
+
packageGroupOrder = packageGroup.map((packageConfig) => packageConfig.package);
|
|
202
|
+
migrationConfig.packageJsonUpdates ??= {};
|
|
203
|
+
const packages = {};
|
|
204
|
+
migrationConfig.packageJsonUpdates[targetVersion + '--PackageGroup'] = {
|
|
205
|
+
version: targetVersion,
|
|
206
|
+
packages,
|
|
207
|
+
};
|
|
208
|
+
for (const packageConfig of packageGroup) {
|
|
209
|
+
packages[packageConfig.package] = {
|
|
210
|
+
version: packageConfig.version === '*'
|
|
211
|
+
? targetVersion
|
|
212
|
+
: packageConfig.version,
|
|
213
|
+
alwaysAddToPackageJson: false,
|
|
214
|
+
};
|
|
215
|
+
if (packageConfig.version === '*' &&
|
|
216
|
+
this.installedPkgVersionOverrides[packageName]) {
|
|
217
|
+
this.installedPkgVersionOverrides[packageConfig.package] ??=
|
|
218
|
+
this.installedPkgVersionOverrides[packageName];
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return packageGroupOrder;
|
|
223
|
+
}
|
|
224
|
+
filterPackageJsonUpdates(packageJsonUpdates, packageName, targetVersion) {
|
|
225
|
+
const filteredPackageJsonUpdates = [];
|
|
226
|
+
for (const packageJsonUpdate of Object.values(packageJsonUpdates)) {
|
|
227
|
+
if (!packageJsonUpdate.packages ||
|
|
228
|
+
this.lt(packageJsonUpdate.version, this.getPkgVersion(packageName)) ||
|
|
229
|
+
this.gt(packageJsonUpdate.version, targetVersion)) {
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
232
|
+
const dependencies = {
|
|
233
|
+
...this.packageJson?.dependencies,
|
|
234
|
+
...this.packageJson?.devDependencies,
|
|
235
|
+
...this.nxInstallation?.plugins,
|
|
236
|
+
...(this.nxInstallation && { nx: this.nxInstallation.version }),
|
|
237
|
+
};
|
|
238
|
+
const filtered = {};
|
|
239
|
+
for (const [packageName, packageUpdate] of Object.entries(packageJsonUpdate.packages)) {
|
|
240
|
+
if (this.shouldApplyPackageUpdate(packageUpdate, packageName, dependencies)) {
|
|
241
|
+
filtered[packageName] = {
|
|
242
|
+
version: packageUpdate.version,
|
|
243
|
+
addToPackageJson: packageUpdate.alwaysAddToPackageJson
|
|
244
|
+
? 'dependencies'
|
|
245
|
+
: packageUpdate.addToPackageJson || false,
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
if (Object.keys(filtered).length) {
|
|
250
|
+
packageJsonUpdate.packages = filtered;
|
|
251
|
+
filteredPackageJsonUpdates.push(packageJsonUpdate);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return filteredPackageJsonUpdates;
|
|
255
|
+
}
|
|
256
|
+
shouldApplyPackageUpdate(packageUpdate, packageName, dependencies) {
|
|
257
|
+
return ((!packageUpdate.ifPackageInstalled ||
|
|
258
|
+
this.getPkgVersion(packageUpdate.ifPackageInstalled)) &&
|
|
259
|
+
(packageUpdate.alwaysAddToPackageJson ||
|
|
260
|
+
packageUpdate.addToPackageJson ||
|
|
261
|
+
!!dependencies?.[packageName]) &&
|
|
262
|
+
(!this.collectedVersions[packageName] ||
|
|
263
|
+
this.gt(packageUpdate.version, this.collectedVersions[packageName])));
|
|
264
|
+
}
|
|
265
|
+
addPackageUpdate(name, packageUpdate) {
|
|
266
|
+
if (!this.packageUpdates[name] ||
|
|
267
|
+
this.gt(packageUpdate.version, this.packageUpdates[name].version)) {
|
|
268
|
+
this.packageUpdates[name] = packageUpdate;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
areRequirementsMet(requirements) {
|
|
272
|
+
if (!requirements || !Object.keys(requirements).length) {
|
|
273
|
+
return true;
|
|
274
|
+
}
|
|
275
|
+
return Object.entries(requirements).every(([pkgName, versionRange]) => {
|
|
276
|
+
if (this.packageUpdates[pkgName]) {
|
|
277
|
+
return (0, semver_1.satisfies)(cleanSemver(this.packageUpdates[pkgName].version), versionRange, { includePrerelease: true });
|
|
278
|
+
}
|
|
279
|
+
return (this.getPkgVersion(pkgName) &&
|
|
280
|
+
(0, semver_1.satisfies)(this.getPkgVersion(pkgName), versionRange, {
|
|
281
|
+
includePrerelease: true,
|
|
282
|
+
}));
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
areMigrationRequirementsMet(packageName, migration) {
|
|
286
|
+
if (!this.excludeAppliedMigrations) {
|
|
287
|
+
return this.areRequirementsMet(migration.requires);
|
|
288
|
+
}
|
|
289
|
+
return ((this.wasMigrationSkipped(migration.requires) ||
|
|
290
|
+
this.isMigrationForHigherVersionThanWhatIsInstalled(packageName, migration)) &&
|
|
291
|
+
this.areRequirementsMet(migration.requires));
|
|
292
|
+
}
|
|
293
|
+
isMigrationForHigherVersionThanWhatIsInstalled(packageName, migration) {
|
|
294
|
+
const installedVersion = this.getInstalledPackageVersion(packageName);
|
|
295
|
+
return (migration.version &&
|
|
296
|
+
(!installedVersion || this.gt(migration.version, installedVersion)) &&
|
|
297
|
+
this.lte(migration.version, this.packageUpdates[packageName].version));
|
|
298
|
+
}
|
|
299
|
+
wasMigrationSkipped(requirements) {
|
|
300
|
+
// no requiremets, so it ran before
|
|
301
|
+
if (!requirements || !Object.keys(requirements).length) {
|
|
302
|
+
return false;
|
|
303
|
+
}
|
|
304
|
+
// at least a requirement was not met, it was skipped
|
|
305
|
+
return Object.entries(requirements).some(([pkgName, versionRange]) => !this.getInstalledPackageVersion(pkgName) ||
|
|
306
|
+
!(0, semver_1.satisfies)(this.getInstalledPackageVersion(pkgName), versionRange, {
|
|
307
|
+
includePrerelease: true,
|
|
308
|
+
}));
|
|
309
|
+
}
|
|
310
|
+
async runPackageJsonUpdatesConfirmationPrompt(packageUpdate) {
|
|
311
|
+
if (!packageUpdate['x-prompt']) {
|
|
312
|
+
return Promise.resolve(true);
|
|
313
|
+
}
|
|
314
|
+
const promptKey = this.getPackageUpdatePromptKey(packageUpdate);
|
|
315
|
+
if (this.promptAnswers[promptKey] !== undefined) {
|
|
316
|
+
// a same prompt was already answered, skip
|
|
317
|
+
return Promise.resolve(false);
|
|
318
|
+
}
|
|
319
|
+
return await (0, enquirer_1.prompt)([
|
|
320
|
+
{
|
|
321
|
+
name: 'shouldApply',
|
|
322
|
+
type: 'confirm',
|
|
323
|
+
message: packageUpdate['x-prompt'],
|
|
324
|
+
initial: true,
|
|
325
|
+
},
|
|
326
|
+
]).then(({ shouldApply }) => {
|
|
327
|
+
this.promptAnswers[promptKey] = shouldApply;
|
|
328
|
+
if (!shouldApply &&
|
|
329
|
+
(!this.minVersionWithSkippedUpdates ||
|
|
330
|
+
(0, semver_1.lt)(packageUpdate.version, this.minVersionWithSkippedUpdates))) {
|
|
331
|
+
this.minVersionWithSkippedUpdates = packageUpdate.version;
|
|
332
|
+
}
|
|
333
|
+
return shouldApply;
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
getPackageUpdatePromptKey(packageUpdate) {
|
|
337
|
+
return Object.entries(packageUpdate.packages)
|
|
338
|
+
.map(([name, update]) => `${name}:${JSON.stringify(update)}`)
|
|
339
|
+
.join('|');
|
|
340
|
+
}
|
|
341
|
+
getPkgVersion(pkg) {
|
|
342
|
+
return this.getInstalledPackageVersion(pkg, this.installedPkgVersionOverrides);
|
|
343
|
+
}
|
|
344
|
+
gt(v1, v2) {
|
|
345
|
+
return (0, semver_1.gt)(normalizeVersion(v1), normalizeVersion(v2));
|
|
346
|
+
}
|
|
347
|
+
lt(v1, v2) {
|
|
348
|
+
return (0, semver_1.lt)(normalizeVersion(v1), normalizeVersion(v2));
|
|
349
|
+
}
|
|
350
|
+
lte(v1, v2) {
|
|
351
|
+
return (0, semver_1.lte)(normalizeVersion(v1), normalizeVersion(v2));
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
exports.Migrator = Migrator;
|
|
355
|
+
const LEGACY_NRWL_PACKAGE_GROUP = [
|
|
356
|
+
{ package: '@nrwl/workspace', version: '*' },
|
|
357
|
+
{ package: '@nrwl/angular', version: '*' },
|
|
358
|
+
{ package: '@nrwl/cypress', version: '*' },
|
|
359
|
+
{ package: '@nrwl/devkit', version: '*' },
|
|
360
|
+
{ package: '@nrwl/eslint-plugin-nx', version: '*' },
|
|
361
|
+
{ package: '@nrwl/express', version: '*' },
|
|
362
|
+
{ package: '@nrwl/jest', version: '*' },
|
|
363
|
+
{ package: '@nrwl/linter', version: '*' },
|
|
364
|
+
{ package: '@nrwl/nest', version: '*' },
|
|
365
|
+
{ package: '@nrwl/next', version: '*' },
|
|
366
|
+
{ package: '@nrwl/node', version: '*' },
|
|
367
|
+
{ package: '@nrwl/nx-plugin', version: '*' },
|
|
368
|
+
{ package: '@nrwl/react', version: '*' },
|
|
369
|
+
{ package: '@nrwl/storybook', version: '*' },
|
|
370
|
+
{ package: '@nrwl/web', version: '*' },
|
|
371
|
+
{ package: '@nrwl/js', version: '*' },
|
|
372
|
+
{ package: 'nx-cloud', version: 'latest' },
|
|
373
|
+
{ package: '@nrwl/react-native', version: '*' },
|
|
374
|
+
{ package: '@nrwl/detox', version: '*' },
|
|
375
|
+
{ package: '@nrwl/expo', version: '*' },
|
|
376
|
+
{ package: '@nrwl/tao', version: '*' },
|
|
377
|
+
];
|
|
378
|
+
async function normalizeVersionWithTagCheck(pkg, version) {
|
|
379
|
+
// This doesn't seem like a valid version, lets check if its a tag on the registry.
|
|
380
|
+
if (version && !(0, semver_1.coerce)(version)) {
|
|
381
|
+
try {
|
|
382
|
+
return (0, package_manager_1.packageRegistryView)(pkg, version, 'version');
|
|
383
|
+
}
|
|
384
|
+
catch {
|
|
385
|
+
// fall through to old logic
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
return normalizeVersion(version);
|
|
389
|
+
}
|
|
390
|
+
async function versionOverrides(overrides, param) {
|
|
391
|
+
const res = {};
|
|
392
|
+
const promises = overrides.split(',').map((p) => {
|
|
393
|
+
const split = p.lastIndexOf('@');
|
|
394
|
+
if (split === -1 || split === 0) {
|
|
395
|
+
throw new Error(`Incorrect '${param}' section. Use --${param}="package@version"`);
|
|
396
|
+
}
|
|
397
|
+
const selectedPackage = p.substring(0, split).trim();
|
|
398
|
+
const selectedVersion = p.substring(split + 1).trim();
|
|
399
|
+
if (!selectedPackage || !selectedVersion) {
|
|
400
|
+
throw new Error(`Incorrect '${param}' section. Use --${param}="package@version"`);
|
|
401
|
+
}
|
|
402
|
+
return normalizeVersionWithTagCheck(selectedPackage, selectedVersion).then((version) => {
|
|
403
|
+
res[normalizeSlashes(selectedPackage)] = version;
|
|
404
|
+
});
|
|
405
|
+
});
|
|
406
|
+
await Promise.all(promises);
|
|
407
|
+
return res;
|
|
408
|
+
}
|
|
409
|
+
async function parseTargetPackageAndVersion(args) {
|
|
410
|
+
if (!args) {
|
|
411
|
+
throw new Error(`Provide the correct package name and version. E.g., my-package@9.0.0.`);
|
|
412
|
+
}
|
|
413
|
+
if (args.indexOf('@') > -1) {
|
|
414
|
+
const i = args.lastIndexOf('@');
|
|
415
|
+
if (i === 0) {
|
|
416
|
+
const targetPackage = args.trim();
|
|
417
|
+
const targetVersion = 'latest';
|
|
418
|
+
return { targetPackage, targetVersion };
|
|
419
|
+
}
|
|
420
|
+
else {
|
|
421
|
+
const targetPackage = args.substring(0, i);
|
|
422
|
+
const maybeVersion = args.substring(i + 1);
|
|
423
|
+
if (!targetPackage || !maybeVersion) {
|
|
424
|
+
throw new Error(`Provide the correct package name and version. E.g., my-package@9.0.0.`);
|
|
425
|
+
}
|
|
426
|
+
const targetVersion = await normalizeVersionWithTagCheck(targetPackage, maybeVersion);
|
|
427
|
+
return { targetPackage, targetVersion };
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
else {
|
|
431
|
+
if (args === 'latest' ||
|
|
432
|
+
args === 'next' ||
|
|
433
|
+
(0, semver_1.valid)(args) ||
|
|
434
|
+
args.match(/^\d+(?:\.\d+)?(?:\.\d+)?$/)) {
|
|
435
|
+
// Passing `nx` here may seem wrong, but nx and @nrwl/workspace are synced in version.
|
|
436
|
+
// We could duplicate the ternary below, but its not necessary since they are equivalent
|
|
437
|
+
// on the registry
|
|
438
|
+
const targetVersion = await normalizeVersionWithTagCheck('nx', args);
|
|
439
|
+
const targetPackage = !['latest', 'next'].includes(args) && (0, semver_1.lt)(targetVersion, '14.0.0-beta.0')
|
|
440
|
+
? '@nrwl/workspace'
|
|
441
|
+
: 'nx';
|
|
442
|
+
return {
|
|
443
|
+
targetPackage,
|
|
444
|
+
targetVersion,
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
else {
|
|
448
|
+
return {
|
|
449
|
+
targetPackage: args,
|
|
450
|
+
targetVersion: 'latest',
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
async function parseMigrationsOptions(options) {
|
|
456
|
+
if (options.runMigrations === '') {
|
|
457
|
+
options.runMigrations = 'migrations.json';
|
|
458
|
+
}
|
|
459
|
+
if (!options.runMigrations) {
|
|
460
|
+
const [from, to] = await Promise.all([
|
|
461
|
+
options.from
|
|
462
|
+
? versionOverrides(options.from, 'from')
|
|
463
|
+
: Promise.resolve({}),
|
|
464
|
+
options.to
|
|
465
|
+
? await versionOverrides(options.to, 'to')
|
|
466
|
+
: Promise.resolve({}),
|
|
467
|
+
]);
|
|
468
|
+
const { targetPackage, targetVersion } = await parseTargetPackageAndVersion(options['packageAndVersion']);
|
|
469
|
+
return {
|
|
470
|
+
type: 'generateMigrations',
|
|
471
|
+
targetPackage: normalizeSlashes(targetPackage),
|
|
472
|
+
targetVersion,
|
|
473
|
+
from,
|
|
474
|
+
to,
|
|
475
|
+
interactive: options.interactive,
|
|
476
|
+
excludeAppliedMigrations: options.excludeAppliedMigrations,
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
else {
|
|
480
|
+
return {
|
|
481
|
+
type: 'runMigrations',
|
|
482
|
+
runMigrations: options.runMigrations,
|
|
483
|
+
ifExists: options.ifExists,
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
exports.parseMigrationsOptions = parseMigrationsOptions;
|
|
488
|
+
function createInstalledPackageVersionsResolver(root) {
|
|
489
|
+
const cache = {};
|
|
490
|
+
function getInstalledPackageVersion(packageName, overrides) {
|
|
491
|
+
try {
|
|
492
|
+
if (overrides?.[packageName]) {
|
|
493
|
+
return overrides[packageName];
|
|
494
|
+
}
|
|
495
|
+
if (!cache[packageName]) {
|
|
496
|
+
const { packageJson, path } = (0, package_json_1.readModulePackageJson)(packageName, (0, installation_directory_1.getNxRequirePaths)());
|
|
497
|
+
// old workspaces would have the temp installation of nx in the cache,
|
|
498
|
+
// so the resolved package is not the one we need
|
|
499
|
+
if (!path.startsWith(workspace_root_1.workspaceRoot)) {
|
|
500
|
+
throw new Error('Resolved a package outside the workspace root.');
|
|
501
|
+
}
|
|
502
|
+
cache[packageName] = packageJson.version;
|
|
503
|
+
}
|
|
504
|
+
return cache[packageName];
|
|
505
|
+
}
|
|
506
|
+
catch {
|
|
507
|
+
// Support migrating old workspaces without nx package
|
|
508
|
+
if (packageName === 'nx') {
|
|
509
|
+
cache[packageName] = getInstalledPackageVersion('@nrwl/workspace', overrides);
|
|
510
|
+
return cache[packageName];
|
|
511
|
+
}
|
|
512
|
+
return null;
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
return getInstalledPackageVersion;
|
|
516
|
+
}
|
|
517
|
+
// testing-fetch-start
|
|
518
|
+
function createFetcher() {
|
|
519
|
+
const migrationsCache = {};
|
|
520
|
+
const resolvedVersionCache = {};
|
|
521
|
+
function fetchMigrations(packageName, packageVersion, setCache) {
|
|
522
|
+
const cacheKey = packageName + '-' + packageVersion;
|
|
523
|
+
return Promise.resolve(resolvedVersionCache[cacheKey])
|
|
524
|
+
.then((cachedResolvedVersion) => {
|
|
525
|
+
if (cachedResolvedVersion) {
|
|
526
|
+
return cachedResolvedVersion;
|
|
527
|
+
}
|
|
528
|
+
resolvedVersionCache[cacheKey] = (0, package_manager_1.resolvePackageVersionUsingRegistry)(packageName, packageVersion);
|
|
529
|
+
return resolvedVersionCache[cacheKey];
|
|
530
|
+
})
|
|
531
|
+
.then((resolvedVersion) => {
|
|
532
|
+
if (resolvedVersion !== packageVersion &&
|
|
533
|
+
migrationsCache[`${packageName}-${resolvedVersion}`]) {
|
|
534
|
+
return migrationsCache[`${packageName}-${resolvedVersion}`];
|
|
535
|
+
}
|
|
536
|
+
setCache(packageName, resolvedVersion);
|
|
537
|
+
return getPackageMigrationsUsingRegistry(packageName, resolvedVersion);
|
|
538
|
+
})
|
|
539
|
+
.catch(() => {
|
|
540
|
+
logger_1.logger.info(`Fetching ${packageName}@${packageVersion}`);
|
|
541
|
+
return getPackageMigrationsUsingInstall(packageName, packageVersion);
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
return function nxMigrateFetcher(packageName, packageVersion) {
|
|
545
|
+
if (migrationsCache[`${packageName}-${packageVersion}`]) {
|
|
546
|
+
return migrationsCache[`${packageName}-${packageVersion}`];
|
|
547
|
+
}
|
|
548
|
+
let resolvedVersion = packageVersion;
|
|
549
|
+
let migrations;
|
|
550
|
+
function setCache(packageName, packageVersion) {
|
|
551
|
+
migrationsCache[packageName + '-' + packageVersion] = migrations;
|
|
552
|
+
}
|
|
553
|
+
migrations = fetchMigrations(packageName, packageVersion, setCache).then((result) => {
|
|
554
|
+
if (result.schematics) {
|
|
555
|
+
result.generators = { ...result.schematics, ...result.generators };
|
|
556
|
+
delete result.schematics;
|
|
557
|
+
}
|
|
558
|
+
resolvedVersion = result.version;
|
|
559
|
+
return result;
|
|
560
|
+
});
|
|
561
|
+
setCache(packageName, packageVersion);
|
|
562
|
+
return migrations;
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
// testing-fetch-end
|
|
566
|
+
async function getPackageMigrationsUsingRegistry(packageName, packageVersion) {
|
|
567
|
+
// check if there are migrations in the packages by looking at the
|
|
568
|
+
// registry directly
|
|
569
|
+
const migrationsConfig = await getPackageMigrationsConfigFromRegistry(packageName, packageVersion);
|
|
570
|
+
if (!migrationsConfig) {
|
|
571
|
+
return {
|
|
572
|
+
name: packageName,
|
|
573
|
+
version: packageVersion,
|
|
574
|
+
};
|
|
575
|
+
}
|
|
576
|
+
if (!migrationsConfig.migrations) {
|
|
577
|
+
return {
|
|
578
|
+
name: packageName,
|
|
579
|
+
version: packageVersion,
|
|
580
|
+
packageGroup: migrationsConfig.packageGroup,
|
|
581
|
+
};
|
|
582
|
+
}
|
|
583
|
+
logger_1.logger.info(`Fetching ${packageName}@${packageVersion}`);
|
|
584
|
+
// try to obtain the migrations from the registry directly
|
|
585
|
+
return await downloadPackageMigrationsFromRegistry(packageName, packageVersion, migrationsConfig);
|
|
586
|
+
}
|
|
587
|
+
async function getPackageMigrationsConfigFromRegistry(packageName, packageVersion) {
|
|
588
|
+
const result = await (0, package_manager_1.packageRegistryView)(packageName, packageVersion, 'nx-migrations ng-update dist --json');
|
|
589
|
+
if (!result) {
|
|
590
|
+
return null;
|
|
591
|
+
}
|
|
592
|
+
const json = JSON.parse(result);
|
|
593
|
+
if (!json['nx-migrations'] && !json['ng-update']) {
|
|
594
|
+
const registry = new node_url_1.URL('dist' in json ? json.dist.tarball : json.tarball)
|
|
595
|
+
.hostname;
|
|
596
|
+
// Registries other than npmjs and the local registry may not support full metadata via npm view
|
|
597
|
+
// so throw error so that fetcher falls back to getting config via install
|
|
598
|
+
if (!['registry.npmjs.org', 'localhost', 'artifactory'].some((v) => registry.includes(v))) {
|
|
599
|
+
throw new Error(`Getting migration config from registry is not supported from ${registry}`);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
return (0, package_json_1.readNxMigrateConfig)(json);
|
|
603
|
+
}
|
|
604
|
+
async function downloadPackageMigrationsFromRegistry(packageName, packageVersion, { migrations: migrationsFilePath, packageGroup, }) {
|
|
605
|
+
const { dir, cleanup } = (0, package_manager_1.createTempNpmDirectory)();
|
|
606
|
+
let result;
|
|
607
|
+
try {
|
|
608
|
+
const { tarballPath } = await (0, package_manager_1.packageRegistryPack)(dir, packageName, packageVersion);
|
|
609
|
+
const migrations = await (0, fileutils_1.extractFileFromTarball)((0, path_1.join)(dir, tarballPath), (0, path_1.join)('package', migrationsFilePath), (0, path_1.join)(dir, migrationsFilePath)).then((path) => (0, fileutils_1.readJsonFile)(path));
|
|
610
|
+
result = { ...migrations, packageGroup, version: packageVersion };
|
|
611
|
+
}
|
|
612
|
+
catch {
|
|
613
|
+
throw new Error(`Failed to find migrations file "${migrationsFilePath}" in package "${packageName}@${packageVersion}".`);
|
|
614
|
+
}
|
|
615
|
+
finally {
|
|
616
|
+
await cleanup();
|
|
617
|
+
}
|
|
618
|
+
return result;
|
|
619
|
+
}
|
|
620
|
+
async function getPackageMigrationsUsingInstall(packageName, packageVersion) {
|
|
621
|
+
const { dir, cleanup } = (0, package_manager_1.createTempNpmDirectory)();
|
|
622
|
+
let result;
|
|
623
|
+
try {
|
|
624
|
+
const pmc = (0, package_manager_1.getPackageManagerCommand)((0, package_manager_1.detectPackageManager)(dir), dir);
|
|
625
|
+
await execAsync(`${pmc.add} ${packageName}@${packageVersion}`, {
|
|
626
|
+
cwd: dir,
|
|
627
|
+
});
|
|
628
|
+
const { migrations: migrationsFilePath, packageGroup, packageJson, } = readPackageMigrationConfig(packageName, dir);
|
|
629
|
+
let migrations = undefined;
|
|
630
|
+
if (migrationsFilePath) {
|
|
631
|
+
migrations = (0, fileutils_1.readJsonFile)(migrationsFilePath);
|
|
632
|
+
}
|
|
633
|
+
result = { ...migrations, packageGroup, version: packageJson.version };
|
|
634
|
+
}
|
|
635
|
+
finally {
|
|
636
|
+
await cleanup();
|
|
637
|
+
}
|
|
638
|
+
return result;
|
|
639
|
+
}
|
|
640
|
+
function readPackageMigrationConfig(packageName, dir) {
|
|
641
|
+
const { path: packageJsonPath, packageJson: json } = (0, package_json_1.readModulePackageJson)(packageName, (0, installation_directory_1.getNxRequirePaths)(dir));
|
|
642
|
+
const config = (0, package_json_1.readNxMigrateConfig)(json);
|
|
643
|
+
if (!config) {
|
|
644
|
+
return { packageJson: json, migrations: null, packageGroup: [] };
|
|
645
|
+
}
|
|
646
|
+
try {
|
|
647
|
+
const migrationFile = require.resolve(config.migrations, {
|
|
648
|
+
paths: [(0, path_1.dirname)(packageJsonPath)],
|
|
649
|
+
});
|
|
650
|
+
return {
|
|
651
|
+
packageJson: json,
|
|
652
|
+
migrations: migrationFile,
|
|
653
|
+
packageGroup: config.packageGroup,
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
catch {
|
|
657
|
+
return {
|
|
658
|
+
packageJson: json,
|
|
659
|
+
migrations: null,
|
|
660
|
+
packageGroup: config.packageGroup,
|
|
661
|
+
};
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
function createMigrationsFile(root, migrations) {
|
|
665
|
+
(0, fileutils_1.writeJsonFile)((0, path_1.join)(root, 'migrations.json'), { migrations });
|
|
666
|
+
}
|
|
667
|
+
function updatePackageJson(root, updatedPackages) {
|
|
668
|
+
const packageJsonPath = (0, path_1.join)(root, 'package.json');
|
|
669
|
+
if (!(0, fs_1.existsSync)(packageJsonPath)) {
|
|
670
|
+
return;
|
|
671
|
+
}
|
|
672
|
+
const parseOptions = {};
|
|
673
|
+
const json = (0, fileutils_1.readJsonFile)(packageJsonPath, parseOptions);
|
|
674
|
+
Object.keys(updatedPackages).forEach((p) => {
|
|
675
|
+
if (json.devDependencies?.[p]) {
|
|
676
|
+
json.devDependencies[p] = updatedPackages[p].version;
|
|
677
|
+
return;
|
|
678
|
+
}
|
|
679
|
+
if (json.dependencies?.[p]) {
|
|
680
|
+
json.dependencies[p] = updatedPackages[p].version;
|
|
681
|
+
return;
|
|
682
|
+
}
|
|
683
|
+
const dependencyType = updatedPackages[p].addToPackageJson;
|
|
684
|
+
if (typeof dependencyType === 'string') {
|
|
685
|
+
json[dependencyType] ??= {};
|
|
686
|
+
json[dependencyType][p] = updatedPackages[p].version;
|
|
687
|
+
}
|
|
688
|
+
});
|
|
689
|
+
(0, fileutils_1.writeJsonFile)(packageJsonPath, json, {
|
|
690
|
+
appendNewLine: parseOptions.endsWithNewline,
|
|
691
|
+
});
|
|
692
|
+
}
|
|
693
|
+
async function updateInstallationDetails(root, updatedPackages) {
|
|
694
|
+
const nxJsonPath = (0, path_1.join)(root, 'nx.json');
|
|
695
|
+
const parseOptions = {};
|
|
696
|
+
const nxJson = (0, fileutils_1.readJsonFile)(nxJsonPath, parseOptions);
|
|
697
|
+
if (!nxJson.installation) {
|
|
698
|
+
return;
|
|
699
|
+
}
|
|
700
|
+
const nxVersion = updatedPackages.nx?.version;
|
|
701
|
+
if (nxVersion) {
|
|
702
|
+
nxJson.installation.version = nxVersion;
|
|
703
|
+
}
|
|
704
|
+
if (nxJson.installation.plugins) {
|
|
705
|
+
for (const dep in nxJson.installation.plugins) {
|
|
706
|
+
const update = updatedPackages[dep];
|
|
707
|
+
if (update) {
|
|
708
|
+
nxJson.installation.plugins[dep] = (0, semver_1.valid)(update.version)
|
|
709
|
+
? update.version
|
|
710
|
+
: await (0, package_manager_1.resolvePackageVersionUsingRegistry)(dep, update.version);
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
(0, fileutils_1.writeJsonFile)(nxJsonPath, nxJson, {
|
|
715
|
+
appendNewLine: parseOptions.endsWithNewline,
|
|
716
|
+
});
|
|
717
|
+
}
|
|
718
|
+
async function isMigratingToNewMajor(from, to) {
|
|
719
|
+
from = normalizeVersion(from);
|
|
720
|
+
to = ['latest', 'next'].includes(to) ? to : normalizeVersion(to);
|
|
721
|
+
if (!(0, semver_1.valid)(from)) {
|
|
722
|
+
from = await (0, package_manager_1.resolvePackageVersionUsingRegistry)('nx', from);
|
|
723
|
+
}
|
|
724
|
+
if (!(0, semver_1.valid)(to)) {
|
|
725
|
+
to = await (0, package_manager_1.resolvePackageVersionUsingRegistry)('nx', to);
|
|
726
|
+
}
|
|
727
|
+
return (0, semver_1.major)(from) < (0, semver_1.major)(to);
|
|
728
|
+
}
|
|
729
|
+
function readNxVersion(packageJson) {
|
|
730
|
+
return (packageJson?.devDependencies?.['nx'] ??
|
|
731
|
+
packageJson?.dependencies?.['nx'] ??
|
|
732
|
+
packageJson?.devDependencies?.['@nx/workspace'] ??
|
|
733
|
+
packageJson?.dependencies?.['@nx/workspace'] ??
|
|
734
|
+
packageJson?.devDependencies?.['@nrwl/workspace'] ??
|
|
735
|
+
packageJson?.dependencies?.['@nrwl/workspace']);
|
|
736
|
+
}
|
|
737
|
+
async function generateMigrationsJsonAndUpdatePackageJson(root, opts) {
|
|
738
|
+
const pmc = (0, package_manager_1.getPackageManagerCommand)();
|
|
739
|
+
try {
|
|
740
|
+
const rootPkgJsonPath = (0, path_1.join)(root, 'package.json');
|
|
741
|
+
let originalPackageJson = (0, fs_1.existsSync)(rootPkgJsonPath)
|
|
742
|
+
? (0, fileutils_1.readJsonFile)(rootPkgJsonPath)
|
|
743
|
+
: null;
|
|
744
|
+
const originalNxJson = (0, configuration_1.readNxJson)();
|
|
745
|
+
const from = originalNxJson.installation?.version ??
|
|
746
|
+
readNxVersion(originalPackageJson);
|
|
747
|
+
try {
|
|
748
|
+
if (['nx', '@nrwl/workspace'].includes(opts.targetPackage) &&
|
|
749
|
+
(await isMigratingToNewMajor(from, opts.targetVersion)) &&
|
|
750
|
+
!(0, is_ci_1.isCI)() &&
|
|
751
|
+
!(0, nx_cloud_utils_1.isNxCloudUsed)(originalNxJson)) {
|
|
752
|
+
await (0, connect_to_nx_cloud_1.connectToNxCloudWithPrompt)('migrate');
|
|
753
|
+
originalPackageJson = (0, fileutils_1.readJsonFile)((0, path_1.join)(root, 'package.json'));
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
catch {
|
|
757
|
+
// The above code is to remind folks when updating to a new major and not currently using Nx cloud.
|
|
758
|
+
// If for some reason it fails, it shouldn't affect the overall migration process
|
|
759
|
+
}
|
|
760
|
+
logger_1.logger.info(`Fetching meta data about packages.`);
|
|
761
|
+
logger_1.logger.info(`It may take a few minutes.`);
|
|
762
|
+
const migrator = new Migrator({
|
|
763
|
+
packageJson: originalPackageJson,
|
|
764
|
+
nxInstallation: originalNxJson.installation,
|
|
765
|
+
getInstalledPackageVersion: createInstalledPackageVersionsResolver(root),
|
|
766
|
+
fetch: createFetcher(),
|
|
767
|
+
from: opts.from,
|
|
768
|
+
to: opts.to,
|
|
769
|
+
interactive: opts.interactive && !(0, is_ci_1.isCI)(),
|
|
770
|
+
excludeAppliedMigrations: opts.excludeAppliedMigrations,
|
|
771
|
+
});
|
|
772
|
+
const { migrations, packageUpdates, minVersionWithSkippedUpdates } = await migrator.migrate(opts.targetPackage, opts.targetVersion);
|
|
773
|
+
updatePackageJson(root, packageUpdates);
|
|
774
|
+
await updateInstallationDetails(root, packageUpdates);
|
|
775
|
+
if (migrations.length > 0) {
|
|
776
|
+
createMigrationsFile(root, [
|
|
777
|
+
...addSplitConfigurationMigrationIfAvailable(from, packageUpdates),
|
|
778
|
+
...migrations,
|
|
779
|
+
]);
|
|
780
|
+
}
|
|
781
|
+
output_1.output.success({
|
|
782
|
+
title: `The migrate command has run successfully.`,
|
|
783
|
+
bodyLines: [
|
|
784
|
+
`- package.json has been updated.`,
|
|
785
|
+
migrations.length > 0
|
|
786
|
+
? `- migrations.json has been generated.`
|
|
787
|
+
: `- There are no migrations to run, so migrations.json has not been created.`,
|
|
788
|
+
],
|
|
789
|
+
});
|
|
790
|
+
output_1.output.log({
|
|
791
|
+
title: 'Next steps:',
|
|
792
|
+
bodyLines: [
|
|
793
|
+
`- Make sure package.json changes make sense and then run '${pmc.install}',`,
|
|
794
|
+
...(migrations.length > 0
|
|
795
|
+
? [`- Run '${pmc.exec} nx migrate --run-migrations'`]
|
|
796
|
+
: []),
|
|
797
|
+
...(opts.interactive && minVersionWithSkippedUpdates
|
|
798
|
+
? [
|
|
799
|
+
`- You opted out of some migrations for now. Write the following command down somewhere to apply these migrations later:`,
|
|
800
|
+
` nx migrate ${opts.targetVersion} --from ${opts.targetPackage}@${minVersionWithSkippedUpdates} --exclude-applied-migrations`,
|
|
801
|
+
`- To learn more go to https://nx.dev/recipes/tips-n-tricks/advanced-update`,
|
|
802
|
+
]
|
|
803
|
+
: [
|
|
804
|
+
`- To learn more go to https://nx.dev/core-features/automate-updating-dependencies`,
|
|
805
|
+
]),
|
|
806
|
+
...(showConnectToCloudMessage()
|
|
807
|
+
? [
|
|
808
|
+
`- You may run '${pmc.run('nx', 'connect-to-nx-cloud')}' to get faster builds, GitHub integration, and more. Check out https://nx.app`,
|
|
809
|
+
]
|
|
810
|
+
: []),
|
|
811
|
+
],
|
|
812
|
+
});
|
|
813
|
+
}
|
|
814
|
+
catch (e) {
|
|
815
|
+
output_1.output.error({
|
|
816
|
+
title: `The migrate command failed.`,
|
|
817
|
+
});
|
|
818
|
+
throw e;
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
function addSplitConfigurationMigrationIfAvailable(from, packageJson) {
|
|
822
|
+
if (!packageJson['@nrwl/workspace'])
|
|
823
|
+
return [];
|
|
824
|
+
if ((0, semver_1.gte)(packageJson['@nrwl/workspace'].version, '15.7.0-beta.0') &&
|
|
825
|
+
(0, semver_1.lt)(normalizeVersion(from), '15.7.0-beta.0')) {
|
|
826
|
+
return [
|
|
827
|
+
{
|
|
828
|
+
version: '15.7.0-beta.0',
|
|
829
|
+
description: 'Split global configuration files into individual project.json files. This migration has been added automatically to the beginning of your migration set to retroactively make them work with the new version of Nx.',
|
|
830
|
+
cli: 'nx',
|
|
831
|
+
implementation: './src/migrations/update-15-7-0/split-configuration-into-project-json-files',
|
|
832
|
+
package: '@nrwl/workspace',
|
|
833
|
+
name: '15-7-0-split-configuration-into-project-json-files',
|
|
834
|
+
},
|
|
835
|
+
];
|
|
836
|
+
}
|
|
837
|
+
else {
|
|
838
|
+
return [];
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
function showConnectToCloudMessage() {
|
|
842
|
+
try {
|
|
843
|
+
const nxJson = (0, configuration_1.readNxJson)();
|
|
844
|
+
const defaultRunnerIsUsed = (0, connect_to_nx_cloud_1.onlyDefaultRunnerIsUsed)(nxJson);
|
|
845
|
+
return !!defaultRunnerIsUsed;
|
|
846
|
+
}
|
|
847
|
+
catch {
|
|
848
|
+
return false;
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
function runInstall() {
|
|
852
|
+
const pmCommands = (0, package_manager_1.getPackageManagerCommand)();
|
|
853
|
+
// TODO: remove this
|
|
854
|
+
if ((0, package_manager_1.detectPackageManager)() === 'npm') {
|
|
855
|
+
process.env.npm_config_legacy_peer_deps ??= 'true';
|
|
856
|
+
}
|
|
857
|
+
output_1.output.log({
|
|
858
|
+
title: `Running '${pmCommands.install}' to make sure necessary packages are installed`,
|
|
859
|
+
});
|
|
860
|
+
(0, child_process_1.execSync)(pmCommands.install, { stdio: [0, 1, 2] });
|
|
861
|
+
}
|
|
862
|
+
async function executeMigrations(root, migrations, isVerbose, shouldCreateCommits, commitPrefix) {
|
|
863
|
+
const depsBeforeMigrations = getStringifiedPackageJsonDeps(root);
|
|
864
|
+
const migrationsWithNoChanges = [];
|
|
865
|
+
for (const m of migrations) {
|
|
866
|
+
try {
|
|
867
|
+
const { collection, collectionPath } = readMigrationCollection(m.package, root);
|
|
868
|
+
if (!isAngularMigration(collection, collectionPath, m.name)) {
|
|
869
|
+
const changes = await runNxMigration(root, collectionPath, collection, m.name);
|
|
870
|
+
if (changes.length < 1) {
|
|
871
|
+
migrationsWithNoChanges.push(m);
|
|
872
|
+
// If no changes are made, continue on without printing anything
|
|
873
|
+
continue;
|
|
874
|
+
}
|
|
875
|
+
logger_1.logger.info(`Ran ${m.name} from ${m.package}`);
|
|
876
|
+
logger_1.logger.info(` ${m.description}\n`);
|
|
877
|
+
(0, tree_1.printChanges)(changes, ' ');
|
|
878
|
+
}
|
|
879
|
+
else {
|
|
880
|
+
const ngCliAdapter = await getNgCompatLayer();
|
|
881
|
+
const { madeChanges, loggingQueue } = await ngCliAdapter.runMigration(root, m.package, m.name, (0, project_graph_1.readProjectsConfigurationFromProjectGraph)(await (0, project_graph_1.createProjectGraphAsync)()).projects, isVerbose);
|
|
882
|
+
if (!madeChanges) {
|
|
883
|
+
migrationsWithNoChanges.push(m);
|
|
884
|
+
// If no changes are made, continue on without printing anything
|
|
885
|
+
continue;
|
|
886
|
+
}
|
|
887
|
+
logger_1.logger.info(`Ran ${m.name} from ${m.package}`);
|
|
888
|
+
logger_1.logger.info(` ${m.description}\n`);
|
|
889
|
+
loggingQueue.forEach((log) => logger_1.logger.info(' ' + log));
|
|
890
|
+
}
|
|
891
|
+
if (shouldCreateCommits) {
|
|
892
|
+
const commitMessage = `${commitPrefix}${m.name}`;
|
|
893
|
+
try {
|
|
894
|
+
const committedSha = commitChanges(commitMessage);
|
|
895
|
+
if (committedSha) {
|
|
896
|
+
logger_1.logger.info(chalk.dim(`- Commit created for changes: ${committedSha}`));
|
|
897
|
+
}
|
|
898
|
+
else {
|
|
899
|
+
logger_1.logger.info(chalk.red(`- A commit could not be created/retrieved for an unknown reason`));
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
catch (e) {
|
|
903
|
+
logger_1.logger.info(chalk.red(`- ${e.message}`));
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
logger_1.logger.info(`---------------------------------------------------------`);
|
|
907
|
+
}
|
|
908
|
+
catch (e) {
|
|
909
|
+
output_1.output.error({
|
|
910
|
+
title: `Failed to run ${m.name} from ${m.package}. This workspace is NOT up to date!`,
|
|
911
|
+
});
|
|
912
|
+
throw e;
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
const depsAfterMigrations = getStringifiedPackageJsonDeps(root);
|
|
916
|
+
if (depsBeforeMigrations !== depsAfterMigrations) {
|
|
917
|
+
runInstall();
|
|
918
|
+
}
|
|
919
|
+
return migrationsWithNoChanges;
|
|
920
|
+
}
|
|
921
|
+
exports.executeMigrations = executeMigrations;
|
|
922
|
+
async function runMigrations(root, opts, args, isVerbose, shouldCreateCommits = false, commitPrefix) {
|
|
923
|
+
if (!process.env.NX_MIGRATE_SKIP_INSTALL) {
|
|
924
|
+
runInstall();
|
|
925
|
+
}
|
|
926
|
+
if (!__dirname.startsWith(workspace_root_1.workspaceRoot)) {
|
|
927
|
+
// we are running from a temp installation with nx latest, switch to running
|
|
928
|
+
// from local installation
|
|
929
|
+
(0, child_process_2.runNxSync)(`migrate ${args.join(' ')}`, {
|
|
930
|
+
stdio: ['inherit', 'inherit', 'inherit'],
|
|
931
|
+
env: {
|
|
932
|
+
...process.env,
|
|
933
|
+
NX_MIGRATE_SKIP_INSTALL: 'true',
|
|
934
|
+
NX_MIGRATE_USE_LOCAL: 'true',
|
|
935
|
+
},
|
|
936
|
+
});
|
|
937
|
+
return;
|
|
938
|
+
}
|
|
939
|
+
const migrationsExists = (0, fileutils_1.fileExists)(opts.runMigrations);
|
|
940
|
+
if (opts.ifExists && !migrationsExists) {
|
|
941
|
+
output_1.output.log({
|
|
942
|
+
title: `Migrations file '${opts.runMigrations}' doesn't exist`,
|
|
943
|
+
});
|
|
944
|
+
return;
|
|
945
|
+
}
|
|
946
|
+
else if (!opts.ifExists && !migrationsExists) {
|
|
947
|
+
throw new Error(`File '${opts.runMigrations}' doesn't exist, can't run migrations. Use flag --if-exists to run migrations only if the file exists`);
|
|
948
|
+
}
|
|
949
|
+
output_1.output.log({
|
|
950
|
+
title: `Running migrations from '${opts.runMigrations}'` +
|
|
951
|
+
(shouldCreateCommits ? ', with each applied in a dedicated commit' : ''),
|
|
952
|
+
});
|
|
953
|
+
const migrations = (0, fileutils_1.readJsonFile)((0, path_1.join)(root, opts.runMigrations)).migrations;
|
|
954
|
+
const migrationsWithNoChanges = await executeMigrations(root, migrations, isVerbose, shouldCreateCommits, commitPrefix);
|
|
955
|
+
if (migrationsWithNoChanges.length < migrations.length) {
|
|
956
|
+
output_1.output.success({
|
|
957
|
+
title: `Successfully finished running migrations from '${opts.runMigrations}'. This workspace is up to date!`,
|
|
958
|
+
});
|
|
959
|
+
}
|
|
960
|
+
else {
|
|
961
|
+
output_1.output.success({
|
|
962
|
+
title: `No changes were made from running '${opts.runMigrations}'. This workspace is up to date!`,
|
|
963
|
+
});
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
function getStringifiedPackageJsonDeps(root) {
|
|
967
|
+
try {
|
|
968
|
+
const { dependencies, devDependencies } = (0, fileutils_1.readJsonFile)((0, path_1.join)(root, 'package.json'));
|
|
969
|
+
return JSON.stringify([dependencies, devDependencies]);
|
|
970
|
+
}
|
|
971
|
+
catch {
|
|
972
|
+
// We don't really care if the .nx/installation property changes,
|
|
973
|
+
// whenever nxw is invoked it will handle the dep updates.
|
|
974
|
+
return '';
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
function commitChanges(commitMessage) {
|
|
978
|
+
try {
|
|
979
|
+
(0, child_process_1.execSync)('git add -A', { encoding: 'utf8', stdio: 'pipe' });
|
|
980
|
+
(0, child_process_1.execSync)('git commit --no-verify -F -', {
|
|
981
|
+
encoding: 'utf8',
|
|
982
|
+
stdio: 'pipe',
|
|
983
|
+
input: commitMessage,
|
|
984
|
+
});
|
|
985
|
+
}
|
|
986
|
+
catch (err) {
|
|
987
|
+
throw new Error(`Error committing changes:\n${err.stderr}`);
|
|
988
|
+
}
|
|
989
|
+
return getLatestCommitSha();
|
|
990
|
+
}
|
|
991
|
+
function getLatestCommitSha() {
|
|
992
|
+
try {
|
|
993
|
+
return (0, child_process_1.execSync)('git rev-parse HEAD', {
|
|
994
|
+
encoding: 'utf8',
|
|
995
|
+
stdio: 'pipe',
|
|
996
|
+
}).trim();
|
|
997
|
+
}
|
|
998
|
+
catch {
|
|
999
|
+
return null;
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
async function runNxMigration(root, collectionPath, collection, name) {
|
|
1003
|
+
const { path: implPath, fnSymbol } = getImplementationPath(collection, collectionPath, name);
|
|
1004
|
+
const fn = require(implPath)[fnSymbol];
|
|
1005
|
+
const host = new tree_1.FsTree(root, process.env.NX_VERBOSE_LOGGING === 'true', `migration ${collection.name}:${name}`);
|
|
1006
|
+
await fn(host, {});
|
|
1007
|
+
host.lock();
|
|
1008
|
+
const changes = host.listChanges();
|
|
1009
|
+
(0, tree_1.flushChanges)(root, changes);
|
|
1010
|
+
return changes;
|
|
1011
|
+
}
|
|
1012
|
+
async function migrate(root, args, rawArgs) {
|
|
1013
|
+
if (args['verbose']) {
|
|
1014
|
+
process.env.NX_VERBOSE_LOGGING = 'true';
|
|
1015
|
+
}
|
|
1016
|
+
await client_1.daemonClient.stop();
|
|
1017
|
+
return (0, params_1.handleErrors)(process.env.NX_VERBOSE_LOGGING === 'true', async () => {
|
|
1018
|
+
const opts = await parseMigrationsOptions(args);
|
|
1019
|
+
if (opts.type === 'generateMigrations') {
|
|
1020
|
+
await generateMigrationsJsonAndUpdatePackageJson(root, opts);
|
|
1021
|
+
}
|
|
1022
|
+
else {
|
|
1023
|
+
await runMigrations(root, opts, rawArgs, args['verbose'], args['createCommits'], args['commitPrefix']);
|
|
1024
|
+
}
|
|
1025
|
+
});
|
|
1026
|
+
}
|
|
1027
|
+
exports.migrate = migrate;
|
|
1028
|
+
function readMigrationCollection(packageName, root) {
|
|
1029
|
+
const collectionPath = readPackageMigrationConfig(packageName, root).migrations;
|
|
1030
|
+
const collection = (0, fileutils_1.readJsonFile)(collectionPath);
|
|
1031
|
+
collection.name ??= packageName;
|
|
1032
|
+
return {
|
|
1033
|
+
collection,
|
|
1034
|
+
collectionPath,
|
|
1035
|
+
};
|
|
1036
|
+
}
|
|
1037
|
+
function getImplementationPath(collection, collectionPath, name) {
|
|
1038
|
+
const g = collection.generators?.[name] || collection.schematics?.[name];
|
|
1039
|
+
if (!g) {
|
|
1040
|
+
throw new Error(`Unable to determine implementation path for "${collectionPath}:${name}"`);
|
|
1041
|
+
}
|
|
1042
|
+
const implRelativePathAndMaybeSymbol = g.implementation || g.factory;
|
|
1043
|
+
const [implRelativePath, fnSymbol = 'default'] = implRelativePathAndMaybeSymbol.split('#');
|
|
1044
|
+
let implPath;
|
|
1045
|
+
try {
|
|
1046
|
+
implPath = require.resolve(implRelativePath, {
|
|
1047
|
+
paths: [(0, path_1.dirname)(collectionPath)],
|
|
1048
|
+
});
|
|
1049
|
+
}
|
|
1050
|
+
catch (e) {
|
|
1051
|
+
// workaround for a bug in node 12
|
|
1052
|
+
implPath = require.resolve(`${(0, path_1.dirname)(collectionPath)}/${implRelativePath}`);
|
|
1053
|
+
}
|
|
1054
|
+
return { path: implPath, fnSymbol };
|
|
1055
|
+
}
|
|
1056
|
+
// TODO (v17): This should just become something like:
|
|
1057
|
+
// ```
|
|
1058
|
+
// return !collection.generators[name] && collection.schematics[name]
|
|
1059
|
+
// ```
|
|
1060
|
+
function isAngularMigration(collection, collectionPath, name) {
|
|
1061
|
+
const entry = collection.generators?.[name] || collection.schematics?.[name];
|
|
1062
|
+
// In the future we will determine this based on the location of the entry in the collection.
|
|
1063
|
+
// If the entry is under `schematics`, it will be assumed to be an angular cli migration.
|
|
1064
|
+
// If the entry is under `generators`, it will be assumed to be an nx migration.
|
|
1065
|
+
// For now, we will continue to obey the cli property, if it exists.
|
|
1066
|
+
// If it doesn't exist, we will check if the implementation references @angular/devkit.
|
|
1067
|
+
const shouldBeNx = !!collection.generators?.[name];
|
|
1068
|
+
const shouldBeNg = !!collection.schematics?.[name];
|
|
1069
|
+
let useAngularDevkitToRunMigration = false;
|
|
1070
|
+
const { path: implementationPath } = getImplementationPath(collection, collectionPath, name);
|
|
1071
|
+
const implStringContents = (0, fs_1.readFileSync)(implementationPath, 'utf-8');
|
|
1072
|
+
// TODO (v17): Remove this check and the cli property access - it is only here for backwards compatibility.
|
|
1073
|
+
if (['@angular/material', '@angular/cdk'].includes(collection.name) ||
|
|
1074
|
+
[
|
|
1075
|
+
"import('@angular-devkit",
|
|
1076
|
+
'import("@angular-devkit',
|
|
1077
|
+
"require('@angular-devkit",
|
|
1078
|
+
'require("@angular-devkit',
|
|
1079
|
+
"from '@angular-devkit",
|
|
1080
|
+
'from "@angular-devkit',
|
|
1081
|
+
].some((s) => implStringContents.includes(s))) {
|
|
1082
|
+
useAngularDevkitToRunMigration = true;
|
|
1083
|
+
}
|
|
1084
|
+
if (useAngularDevkitToRunMigration && shouldBeNx) {
|
|
1085
|
+
output_1.output.warn({
|
|
1086
|
+
title: `The migration '${collection.name}:${name}' appears to be an Angular CLI migration, but is located in the 'generators' section of migrations.json.`,
|
|
1087
|
+
bodyLines: [
|
|
1088
|
+
'In Nx 17, migrations inside `generators` will be treated as Angular Devkit migrations.',
|
|
1089
|
+
"Please open an issue on the plugin's repository if you believe this is an error.",
|
|
1090
|
+
],
|
|
1091
|
+
});
|
|
1092
|
+
}
|
|
1093
|
+
if (!useAngularDevkitToRunMigration && entry.cli === 'nx' && shouldBeNg) {
|
|
1094
|
+
output_1.output.warn({
|
|
1095
|
+
title: `The migration '${collection.name}:${name}' appears to be an Nx migration, but is located in the 'schematics' section of migrations.json.`,
|
|
1096
|
+
bodyLines: [
|
|
1097
|
+
'In Nx 17, migrations inside `generators` will be treated as nx devkit migrations.',
|
|
1098
|
+
"Please open an issue on the plugin's repository if you believe this is an error.",
|
|
1099
|
+
],
|
|
1100
|
+
});
|
|
1101
|
+
}
|
|
1102
|
+
// Currently, if the cli property exists we listen to it. If its nx, its not an ng cli migration.
|
|
1103
|
+
// If the property is not set, we will fall back to our intuition.
|
|
1104
|
+
return entry.cli ? entry.cli !== 'nx' : useAngularDevkitToRunMigration;
|
|
1105
|
+
}
|
|
1106
|
+
const getNgCompatLayer = (() => {
|
|
1107
|
+
let _ngCliAdapter;
|
|
1108
|
+
return async function getNgCompatLayer() {
|
|
1109
|
+
if (!_ngCliAdapter) {
|
|
1110
|
+
_ngCliAdapter = await Promise.resolve().then(() => require('../../adapter/ngcli-adapter'));
|
|
1111
|
+
require('../../adapter/compat');
|
|
1112
|
+
}
|
|
1113
|
+
return _ngCliAdapter;
|
|
1114
|
+
};
|
|
1115
|
+
})();
|