nx 17.0.3 → 17.0.5
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/LICENSE +1 -1
- package/README.md +9 -4
- package/bin/init-local.js +10 -60
- package/bin/nx-cloud.js +6 -0
- package/bin/nx.js +1 -9
- package/bin/post-install.js +5 -1
- package/bin/run-executor.js +1 -1
- package/migrations.json +18 -0
- package/package.json +21 -18
- package/plugins/package-json.js +1 -1
- package/{changelog-renderer → release/changelog-renderer}/index.d.ts +18 -3
- package/{changelog-renderer → release/changelog-renderer}/index.js +78 -34
- package/release/index.d.ts +4 -0
- package/release/index.js +11 -0
- package/schemas/nx-schema.json +203 -19
- package/schemas/project-schema.json +20 -0
- package/src/adapter/angular-json.js +28 -18
- package/src/adapter/compat.d.ts +2 -2
- package/src/adapter/compat.js +6 -1
- package/src/adapter/ngcli-adapter.d.ts +16 -4
- package/src/adapter/ngcli-adapter.js +85 -28
- package/src/command-line/add/add.d.ts +2 -0
- package/src/command-line/add/add.js +169 -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.js +0 -3
- package/src/command-line/affected/command-object.d.ts +4 -4
- package/src/command-line/affected/command-object.js +53 -26
- package/src/command-line/affected/print-affected.js +10 -1
- package/src/command-line/connect/command-object.d.ts +1 -2
- package/src/command-line/connect/command-object.js +3 -7
- package/src/command-line/connect/connect-to-nx-cloud.d.ts +4 -5
- package/src/command-line/connect/connect-to-nx-cloud.js +43 -31
- package/src/command-line/connect/view-logs.js +5 -21
- package/src/command-line/examples.js +18 -0
- package/src/command-line/exec/command-object.js +2 -1
- package/src/command-line/exec/exec.d.ts +1 -1
- package/src/command-line/exec/exec.js +78 -35
- package/src/command-line/format/format.js +13 -4
- package/src/command-line/generate/generate.js +9 -9
- package/src/command-line/generate/generator-utils.d.ts +3 -2
- package/src/command-line/generate/generator-utils.js +5 -5
- package/src/command-line/graph/graph.d.ts +1 -1
- package/src/command-line/graph/graph.js +82 -37
- package/src/command-line/init/command-object.js +70 -43
- package/src/command-line/init/implementation/add-nx-to-monorepo.d.ts +4 -2
- package/src/command-line/init/implementation/add-nx-to-monorepo.js +11 -2
- package/src/command-line/init/implementation/add-nx-to-nest.d.ts +1 -1
- package/src/command-line/init/implementation/add-nx-to-nest.js +9 -6
- package/src/command-line/init/implementation/add-nx-to-npm-repo.d.ts +4 -2
- package/src/command-line/init/implementation/add-nx-to-npm-repo.js +14 -4
- package/src/command-line/init/implementation/angular/index.js +4 -1
- package/src/command-line/init/implementation/angular/legacy-angular-versions.js +10 -5
- package/src/command-line/init/implementation/angular/standalone-workspace.js +1 -1
- package/src/command-line/init/implementation/angular/types.d.ts +1 -1
- package/src/command-line/init/implementation/dot-nx/nxw.js +47 -16
- package/src/command-line/init/implementation/react/index.d.ts +1 -1
- package/src/command-line/init/implementation/react/index.js +4 -2
- package/src/command-line/init/implementation/react/rename-js-to-jsx.js +4 -2
- package/src/command-line/init/implementation/utils.d.ts +5 -5
- package/src/command-line/init/implementation/utils.js +46 -44
- package/src/command-line/init/{init.js → init-v1.js} +5 -13
- package/src/command-line/init/init-v2.d.ts +7 -0
- package/src/command-line/init/init-v2.js +201 -0
- package/src/command-line/list/list.js +6 -5
- package/src/command-line/migrate/command-object.js +19 -4
- package/src/command-line/migrate/migrate.js +21 -17
- package/src/command-line/new/new.js +1 -1
- package/src/command-line/nx-commands.js +4 -1
- package/src/command-line/release/changelog.d.ts +22 -1
- package/src/command-line/release/changelog.js +459 -257
- package/src/command-line/release/command-object.d.ts +29 -7
- package/src/command-line/release/command-object.js +120 -20
- package/src/command-line/release/config/config.d.ts +26 -21
- package/src/command-line/release/config/config.js +416 -59
- package/src/command-line/release/config/conventional-commits.d.ts +2 -0
- package/src/command-line/release/config/conventional-commits.js +98 -0
- package/src/command-line/release/config/filter-release-groups.d.ts +1 -2
- package/src/command-line/release/config/filter-release-groups.js +38 -1
- 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 +7 -3
- package/src/command-line/release/publish.js +89 -37
- package/src/command-line/release/release.d.ts +4 -0
- package/src/command-line/release/release.js +176 -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 +34 -1
- package/src/command-line/release/utils/git.js +238 -34
- package/src/command-line/release/utils/github.d.ts +5 -5
- package/src/command-line/release/utils/github.js +155 -8
- package/src/command-line/release/utils/markdown.js +6 -1
- package/src/command-line/release/utils/print-changes.d.ts +1 -1
- package/src/command-line/release/utils/print-changes.js +3 -3
- package/src/command-line/release/utils/resolve-nx-json-error-message.js +4 -1
- package/src/command-line/release/utils/resolve-semver-specifier.d.ts +4 -0
- package/src/command-line/release/utils/resolve-semver-specifier.js +58 -0
- package/src/command-line/release/utils/semver.d.ts +8 -0
- package/src/command-line/release/utils/semver.js +30 -1
- package/src/command-line/release/utils/shared.d.ts +39 -0
- package/src/command-line/release/utils/shared.js +213 -0
- package/src/command-line/release/version.d.ts +37 -3
- package/src/command-line/release/version.js +312 -117
- package/src/command-line/repair/repair.js +13 -9
- package/src/command-line/report/report.d.ts +3 -0
- package/src/command-line/report/report.js +22 -5
- package/src/command-line/run/command-object.d.ts +4 -0
- package/src/command-line/run/command-object.js +18 -2
- package/src/command-line/run/executor-utils.d.ts +2 -1
- package/src/command-line/run/executor-utils.js +4 -4
- package/src/command-line/run/run-one.js +3 -6
- package/src/command-line/run/run.js +34 -9
- package/src/command-line/run-many/command-object.js +4 -1
- package/src/command-line/run-many/run-many.js +0 -3
- package/src/command-line/show/command-object.d.ts +3 -0
- package/src/command-line/show/command-object.js +29 -2
- package/src/command-line/show/show.js +9 -0
- package/src/command-line/yargs-utils/shared-options.d.ts +4 -1
- package/src/command-line/yargs-utils/shared-options.js +23 -9
- 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/nx-json.d.ts +160 -25
- package/src/config/project-graph.d.ts +3 -3
- package/src/config/workspace-json-project-json.d.ts +23 -1
- package/src/config/workspaces.d.ts +1 -1
- package/src/config/workspaces.js +4 -6
- package/src/core/graph/3rdpartylicenses.txt +144 -74
- package/src/core/graph/environment.js +1 -1
- package/src/core/graph/index.html +4 -6
- package/src/core/graph/main.js +1 -1
- package/src/core/graph/runtime.js +1 -1
- package/src/core/graph/styles.css +3 -3
- package/src/core/graph/styles.js +1 -1
- package/src/daemon/client/client.d.ts +5 -1
- package/src/daemon/client/client.js +27 -8
- package/src/daemon/client/{socket-messenger.d.ts → daemon-socket-messenger.d.ts} +1 -1
- package/src/daemon/client/{socket-messenger.js → daemon-socket-messenger.js} +3 -3
- package/src/daemon/daemon-project-graph-error.d.ts +8 -0
- package/src/daemon/daemon-project-graph-error.js +13 -0
- package/src/daemon/server/handle-hash-tasks.js +12 -2
- package/src/daemon/server/handle-request-project-graph.js +1 -1
- package/src/daemon/server/project-graph-incremental-recomputation.d.ts +14 -13
- package/src/daemon/server/project-graph-incremental-recomputation.js +98 -33
- package/src/daemon/server/shutdown-utils.js +2 -4
- package/src/daemon/server/watcher.js +0 -3
- package/src/daemon/socket-utils.d.ts +2 -1
- package/src/daemon/socket-utils.js +15 -4
- package/src/daemon/tmp-dir.d.ts +1 -0
- package/src/daemon/tmp-dir.js +4 -4
- package/src/devkit-exports.d.ts +2 -2
- package/src/devkit-exports.js +3 -2
- package/src/devkit-internals.d.ts +3 -0
- package/src/devkit-internals.js +7 -1
- package/src/executors/noop/schema.json +1 -1
- package/src/executors/run-commands/run-commands.impl.d.ts +10 -2
- package/src/executors/run-commands/run-commands.impl.js +152 -48
- package/src/executors/run-commands/schema.json +11 -1
- package/src/executors/run-script/run-script.impl.js +43 -11
- package/src/executors/utils/convert-nx-executor.js +1 -1
- package/src/generators/internal-utils/format-changed-files-with-prettier-if-available.d.ts +3 -1
- package/src/generators/internal-utils/format-changed-files-with-prettier-if-available.js +4 -2
- package/src/generators/testing-utils/create-tree-with-empty-workspace.js +0 -6
- package/src/generators/tree.d.ts +1 -0
- package/src/generators/utils/glob.js +2 -2
- package/src/generators/utils/project-configuration.js +28 -9
- package/src/hasher/create-task-hasher.d.ts +4 -0
- package/src/hasher/create-task-hasher.js +16 -0
- package/src/hasher/hash-task.js +9 -3
- 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 +33 -21
- package/src/hasher/task-hasher.js +30 -428
- package/src/migrations/update-15-0-0/migrate-to-inputs.js +5 -5
- package/src/migrations/update-15-1-0/set-project-names.js +2 -1
- package/src/migrations/update-15-8-2/update-nxw.js +2 -6
- package/src/migrations/update-17-0-0/rm-default-collection-npm-scope.js +3 -3
- package/src/migrations/update-17-0-0/use-minimal-config-for-tasks-runner-options.js +49 -13
- package/src/migrations/update-17-2-0/move-default-base.d.ts +5 -0
- package/src/migrations/update-17-2-0/move-default-base.js +21 -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 +48 -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/migrations/update-18-0-0/disable-crystal-for-existing-workspaces.d.ts +2 -0
- package/src/migrations/update-18-0-0/disable-crystal-for-existing-workspaces.js +9 -0
- package/src/native/index.d.ts +65 -15
- package/src/native/index.js +6 -2
- package/src/native/transform-objects.js +2 -0
- package/src/nx-cloud/generators/connect-to-nx-cloud/connect-to-nx-cloud.d.ts +1 -0
- package/src/nx-cloud/generators/connect-to-nx-cloud/connect-to-nx-cloud.js +13 -12
- package/src/nx-cloud/generators/connect-to-nx-cloud/schema.json +6 -1
- package/src/nx-cloud/update-manager.js +2 -1
- package/src/plugins/js/index.d.ts +1 -1
- package/src/plugins/js/index.js +3 -3
- package/src/plugins/js/lock-file/lock-file.d.ts +2 -2
- package/src/plugins/js/lock-file/lock-file.js +15 -3
- package/src/plugins/js/package-json/create-package-json.js +1 -1
- package/src/plugins/js/project-graph/build-dependencies/strip-source-code.d.ts +1 -1
- package/src/plugins/js/project-graph/build-dependencies/strip-source-code.js +1 -1
- package/src/plugins/js/project-graph/build-dependencies/typescript-import-locator.d.ts +1 -1
- package/src/plugins/js/project-graph/build-dependencies/typescript-import-locator.js +1 -1
- package/src/plugins/js/utils/register.d.ts +1 -1
- package/src/plugins/js/utils/register.js +28 -8
- package/src/plugins/js/versions.d.ts +1 -1
- package/src/plugins/js/versions.js +1 -1
- package/{plugins/package-json-workspaces.d.ts → src/plugins/package-json-workspaces/create-nodes.d.ts} +4 -4
- package/{plugins/package-json-workspaces.js → src/plugins/package-json-workspaces/create-nodes.js} +34 -12
- 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 +2 -5
- package/src/plugins/project-json/build-nodes/project-json.js +6 -44
- package/src/plugins/target-defaults/target-defaults-plugin.d.ts +66 -0
- package/src/plugins/target-defaults/target-defaults-plugin.js +182 -0
- package/src/project-graph/affected/locators/project-glob-changes.js +3 -3
- package/src/project-graph/affected/locators/workspace-projects.d.ts +0 -2
- package/src/project-graph/affected/locators/workspace-projects.js +16 -29
- package/src/project-graph/build-project-graph.d.ts +20 -1
- package/src/project-graph/build-project-graph.js +91 -33
- package/src/project-graph/file-map-utils.d.ts +9 -5
- package/src/project-graph/file-map-utils.js +16 -63
- package/src/project-graph/file-utils.d.ts +1 -1
- package/src/project-graph/file-utils.js +44 -2
- package/src/project-graph/nx-deps-cache.js +1 -1
- package/src/project-graph/project-graph-builder.d.ts +1 -1
- package/src/project-graph/project-graph-builder.js +1 -1
- package/src/project-graph/project-graph.d.ts +32 -1
- package/src/project-graph/project-graph.js +147 -23
- 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/normalize-project-nodes.d.ts +2 -3
- package/src/project-graph/utils/normalize-project-nodes.js +7 -33
- package/src/project-graph/utils/project-configuration-utils.d.ts +66 -4
- package/src/project-graph/utils/project-configuration-utils.js +509 -62
- package/src/project-graph/utils/retrieve-workspace-files.d.ts +12 -31
- package/src/project-graph/utils/retrieve-workspace-files.js +27 -90
- package/src/tasks-runner/batch/run-batch.js +3 -3
- package/src/tasks-runner/cache.js +6 -3
- package/src/tasks-runner/create-task-graph.js +1 -1
- 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 +13 -5
- package/src/tasks-runner/forked-process-task-runner.js +112 -21
- package/src/tasks-runner/init-tasks-runner.js +1 -1
- package/src/tasks-runner/life-cycles/dynamic-run-many-terminal-output-life-cycle.js +28 -28
- package/src/tasks-runner/life-cycles/dynamic-run-one-terminal-output-life-cycle.js +19 -22
- package/src/tasks-runner/life-cycles/empty-terminal-output-life-cycle.js +1 -3
- package/src/tasks-runner/life-cycles/invoke-runner-terminal-output-life-cycle.js +1 -3
- package/src/tasks-runner/life-cycles/static-run-many-terminal-output-life-cycle.js +2 -4
- package/src/tasks-runner/life-cycles/static-run-one-terminal-output-life-cycle.d.ts +1 -0
- package/src/tasks-runner/life-cycles/static-run-one-terminal-output-life-cycle.js +11 -5
- package/src/tasks-runner/life-cycles/view-logs-utils.js +1 -1
- package/src/tasks-runner/pseudo-ipc.d.ts +49 -0
- package/src/tasks-runner/pseudo-ipc.js +140 -0
- package/src/tasks-runner/pseudo-terminal.d.ts +43 -0
- package/src/tasks-runner/pseudo-terminal.js +159 -0
- package/src/tasks-runner/run-command.d.ts +1 -1
- package/src/tasks-runner/run-command.js +13 -19
- package/src/tasks-runner/task-env.js +1 -2
- package/src/tasks-runner/task-graph-utils.d.ts +7 -3
- package/src/tasks-runner/task-graph-utils.js +15 -15
- package/src/tasks-runner/task-orchestrator.js +68 -12
- package/src/tasks-runner/tasks-schedule.js +3 -3
- package/src/tasks-runner/utils.d.ts +16 -7
- package/src/tasks-runner/utils.js +30 -16
- package/src/utils/ab-testing.d.ts +36 -2
- package/src/utils/ab-testing.js +34 -16
- package/src/utils/assert-workspace-validity.js +1 -1
- package/src/utils/cache-directory.d.ts +1 -0
- package/src/utils/cache-directory.js +5 -1
- package/src/utils/child-process.d.ts +15 -1
- package/src/utils/child-process.js +91 -1
- package/src/utils/command-line-utils.js +2 -1
- package/src/utils/exit-codes.d.ts +6 -0
- package/src/utils/exit-codes.js +20 -0
- package/src/utils/fileutils.d.ts +1 -0
- package/src/utils/find-matching-projects.js +5 -5
- package/src/utils/find-workspace-root.js +1 -0
- package/src/utils/ignore.js +8 -1
- package/src/utils/json-diff.d.ts +1 -0
- package/src/utils/json-diff.js +2 -1
- package/src/utils/json.js +3 -1
- package/src/utils/logger.js +1 -1
- package/src/utils/nx-cloud-utils.d.ts +1 -1
- package/src/utils/nx-cloud-utils.js +9 -4
- package/src/utils/nx-plugin.d.ts +32 -15
- package/src/utils/nx-plugin.deprecated.d.ts +10 -5
- package/src/utils/nx-plugin.deprecated.js +23 -0
- package/src/utils/nx-plugin.js +71 -80
- package/src/utils/output.d.ts +4 -2
- package/src/utils/output.js +44 -9
- package/src/utils/package-json.d.ts +4 -4
- package/src/utils/package-json.js +18 -12
- package/src/utils/package-manager.d.ts +7 -0
- package/src/utils/package-manager.js +24 -4
- package/src/utils/params.d.ts +12 -4
- package/src/utils/params.js +37 -4
- package/src/utils/plugins/core-plugins.js +8 -0
- package/src/utils/plugins/installed-plugins.d.ts +2 -1
- package/src/utils/plugins/installed-plugins.js +2 -2
- package/src/utils/plugins/local-plugins.js +1 -1
- package/src/utils/plugins/plugin-capabilities.d.ts +3 -2
- package/src/utils/plugins/plugin-capabilities.js +7 -7
- package/src/utils/typescript.js +1 -1
- package/src/utils/update-nxw.d.ts +2 -0
- package/src/utils/update-nxw.js +12 -0
- package/src/utils/workspace-configuration-check.js +1 -1
- package/src/utils/workspace-context.d.ts +6 -4
- package/src/utils/workspace-context.js +19 -9
- package/src/core/graph/polyfills.js +0 -1
- /package/src/command-line/init/{init.d.ts → init-v1.d.ts} +0 -0
|
@@ -10,11 +10,14 @@ const output_1 = require("../../../../utils/output");
|
|
|
10
10
|
const package_json_1 = require("../../../../utils/package-json");
|
|
11
11
|
const package_manager_1 = require("../../../../utils/package-manager");
|
|
12
12
|
const utils_1 = require("../utils");
|
|
13
|
+
const connect_to_nx_cloud_1 = require("../../../connect/connect-to-nx-cloud");
|
|
13
14
|
// map of Angular major versions to Nx versions to use for legacy `nx init` migrations,
|
|
14
15
|
// key is major Angular version and value is Nx version to use
|
|
15
|
-
const nxAngularLegacyVersionMap = {
|
|
16
|
+
const nxAngularLegacyVersionMap = {
|
|
17
|
+
14: '~17.0.0',
|
|
18
|
+
};
|
|
16
19
|
// min major angular version supported in latest Nx
|
|
17
|
-
const minMajorAngularVersionSupported =
|
|
20
|
+
const minMajorAngularVersionSupported = 15;
|
|
18
21
|
// version when the Nx CLI changed from @nrwl/tao & @nrwl/cli to nx
|
|
19
22
|
const versionWithConsolidatedPackages = '13.9.0';
|
|
20
23
|
// version when packages were rescoped from @nrwl/* to @nx/*
|
|
@@ -66,7 +69,9 @@ async function getLegacyMigrationFunctionIfApplicable(repoRoot, options) {
|
|
|
66
69
|
return async () => {
|
|
67
70
|
output_1.output.log({ title: '🐳 Nx initialization' });
|
|
68
71
|
const useNxCloud = options.nxCloud ??
|
|
69
|
-
(options.interactive
|
|
72
|
+
(options.interactive
|
|
73
|
+
? await (0, connect_to_nx_cloud_1.connectExistingRepoToNxCloudPrompt)()
|
|
74
|
+
: false);
|
|
70
75
|
output_1.output.log({ title: '📦 Installing dependencies' });
|
|
71
76
|
const pmc = (0, package_manager_1.getPackageManagerCommand)();
|
|
72
77
|
await installDependencies(repoRoot, {
|
|
@@ -74,7 +79,7 @@ async function getLegacyMigrationFunctionIfApplicable(repoRoot, options) {
|
|
|
74
79
|
pkgScope,
|
|
75
80
|
pkgVersion,
|
|
76
81
|
unscopedPkgName,
|
|
77
|
-
},
|
|
82
|
+
}, pmc);
|
|
78
83
|
output_1.output.log({ title: '📝 Setting up workspace' });
|
|
79
84
|
(0, child_process_1.execSync)(`${pmc.exec} ${legacyMigrationCommand}`, { stdio: [0, 1, 2] });
|
|
80
85
|
if (useNxCloud) {
|
|
@@ -90,7 +95,7 @@ async function getLegacyMigrationFunctionIfApplicable(repoRoot, options) {
|
|
|
90
95
|
};
|
|
91
96
|
}
|
|
92
97
|
exports.getLegacyMigrationFunctionIfApplicable = getLegacyMigrationFunctionIfApplicable;
|
|
93
|
-
async function installDependencies(repoRoot, pkgInfo,
|
|
98
|
+
async function installDependencies(repoRoot, pkgInfo, pmc) {
|
|
94
99
|
const json = (0, fileutils_1.readJsonFile)((0, path_1.join)(repoRoot, 'package.json'));
|
|
95
100
|
json.devDependencies ??= {};
|
|
96
101
|
json.devDependencies[`${pkgInfo.pkgScope}/workspace`] = pkgInfo.pkgVersion;
|
|
@@ -98,7 +98,7 @@ function createNxJson(repoRoot, angularJson, cacheableOperations, { eslintProjec
|
|
|
98
98
|
inputs: ['default', '^production'],
|
|
99
99
|
};
|
|
100
100
|
}
|
|
101
|
-
// Angular
|
|
101
|
+
// Angular 15 workspaces still support defaultProject. Support was removed in Angular 16.
|
|
102
102
|
nxJson.defaultProject = angularJson.defaultProject;
|
|
103
103
|
(0, fileutils_1.writeJsonFile)((0, path_1.join)(repoRoot, 'nx.json'), nxJson);
|
|
104
104
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { InitArgs } from '../../init';
|
|
1
|
+
import { InitArgs } from '../../init-v1';
|
|
2
2
|
import type { TargetConfiguration } from '../../../../config/workspace-json-project-json';
|
|
3
3
|
export type Options = Pick<InitArgs, 'nxCloud' | 'integrated' | 'interactive' | 'cacheable'>;
|
|
4
4
|
export type AngularJsonConfigTargetConfiguration = Exclude<TargetConfiguration, 'command' | 'executor' | 'outputs' | 'dependsOn' | 'inputs'> & {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// This file should be committed to your repository! It wraps Nx and ensures
|
|
3
3
|
// that your local installation matches nx.json.
|
|
4
|
-
// See: https://nx.dev/
|
|
4
|
+
// See: https://nx.dev/recipes/installation/install-non-javascript for more info.
|
|
5
5
|
//
|
|
6
6
|
//# The contents of this file are executed before packages are installed.
|
|
7
7
|
//# As such, we should not import anything from nx, other @nrwl packages,
|
|
@@ -12,9 +12,12 @@ const fs = require('fs');
|
|
|
12
12
|
const path = require('path');
|
|
13
13
|
const cp = require('child_process');
|
|
14
14
|
const installationPath = path.join(__dirname, 'installation', 'package.json');
|
|
15
|
-
function matchesCurrentNxInstall(nxJsonInstallation) {
|
|
15
|
+
function matchesCurrentNxInstall(currentInstallation, nxJsonInstallation) {
|
|
16
|
+
if (!currentInstallation.devDependencies ||
|
|
17
|
+
!Object.keys(currentInstallation.devDependencies).length) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
16
20
|
try {
|
|
17
|
-
const currentInstallation = require(installationPath);
|
|
18
21
|
if (currentInstallation.devDependencies['nx'] !==
|
|
19
22
|
nxJsonInstallation.version ||
|
|
20
23
|
require(path.join(path.dirname(installationPath), 'node_modules', 'nx', 'package.json')).version !== nxJsonInstallation.version) {
|
|
@@ -36,30 +39,58 @@ function ensureDir(p) {
|
|
|
36
39
|
fs.mkdirSync(p, { recursive: true });
|
|
37
40
|
}
|
|
38
41
|
}
|
|
42
|
+
function getCurrentInstallation() {
|
|
43
|
+
try {
|
|
44
|
+
return require(installationPath);
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return {
|
|
48
|
+
name: 'nx-installation',
|
|
49
|
+
version: '0.0.0',
|
|
50
|
+
devDependencies: {},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function performInstallation(currentInstallation, nxJson) {
|
|
55
|
+
fs.writeFileSync(installationPath, JSON.stringify({
|
|
56
|
+
name: 'nx-installation',
|
|
57
|
+
devDependencies: {
|
|
58
|
+
nx: nxJson.installation.version,
|
|
59
|
+
...nxJson.installation.plugins,
|
|
60
|
+
},
|
|
61
|
+
}));
|
|
62
|
+
try {
|
|
63
|
+
cp.execSync('npm i', {
|
|
64
|
+
cwd: path.dirname(installationPath),
|
|
65
|
+
stdio: 'inherit',
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
catch (e) {
|
|
69
|
+
// revert possible changes to the current installation
|
|
70
|
+
fs.writeFileSync(installationPath, JSON.stringify(currentInstallation));
|
|
71
|
+
// rethrow
|
|
72
|
+
throw e;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
39
75
|
function ensureUpToDateInstallation() {
|
|
40
76
|
const nxJsonPath = path.join(__dirname, '..', 'nx.json');
|
|
41
77
|
let nxJson;
|
|
42
78
|
try {
|
|
43
79
|
nxJson = require(nxJsonPath);
|
|
80
|
+
if (!nxJson.installation) {
|
|
81
|
+
console.error('[NX]: The "installation" entry in the "nx.json" file is required when running the nx wrapper. See https://nx.dev/recipes/installation/install-non-javascript');
|
|
82
|
+
process.exit(1);
|
|
83
|
+
}
|
|
44
84
|
}
|
|
45
85
|
catch {
|
|
46
|
-
console.error('[NX]: nx.json is required when running the nx wrapper. See https://nx.dev/
|
|
86
|
+
console.error('[NX]: The "nx.json" file is required when running the nx wrapper. See https://nx.dev/recipes/installation/install-non-javascript');
|
|
47
87
|
process.exit(1);
|
|
48
88
|
}
|
|
49
89
|
try {
|
|
50
90
|
ensureDir(path.join(__dirname, 'installation'));
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
devDependencies: {
|
|
55
|
-
nx: nxJson.installation.version,
|
|
56
|
-
...nxJson.installation.plugins,
|
|
57
|
-
},
|
|
58
|
-
}));
|
|
59
|
-
cp.execSync('npm i', {
|
|
60
|
-
cwd: path.dirname(installationPath),
|
|
61
|
-
stdio: 'inherit',
|
|
62
|
-
});
|
|
91
|
+
const currentInstallation = getCurrentInstallation();
|
|
92
|
+
if (!matchesCurrentNxInstall(currentInstallation, nxJson.installation)) {
|
|
93
|
+
performInstallation(currentInstallation, nxJson);
|
|
63
94
|
}
|
|
64
95
|
}
|
|
65
96
|
catch (e) {
|
|
@@ -17,6 +17,7 @@ const tsconfig_setup_1 = require("./tsconfig-setup");
|
|
|
17
17
|
const write_craco_config_1 = require("./write-craco-config");
|
|
18
18
|
const write_vite_config_1 = require("./write-vite-config");
|
|
19
19
|
const write_vite_index_html_1 = require("./write-vite-index-html");
|
|
20
|
+
const connect_to_nx_cloud_1 = require("../../../connect/connect-to-nx-cloud");
|
|
20
21
|
async function addNxToCraRepo(options) {
|
|
21
22
|
if (!options.force) {
|
|
22
23
|
(0, check_for_uncommitted_changes_1.checkForUncommittedChanges)();
|
|
@@ -60,7 +61,8 @@ async function normalizeOptions(options) {
|
|
|
60
61
|
const npxYesFlagNeeded = !npmVersion.startsWith('6'); // npm 7 added -y flag to npx
|
|
61
62
|
const isVite = options.vite;
|
|
62
63
|
const isStandalone = !options.integrated;
|
|
63
|
-
const nxCloud = options.nxCloud ??
|
|
64
|
+
const nxCloud = options.nxCloud ??
|
|
65
|
+
(options.interactive ? await (0, connect_to_nx_cloud_1.connectExistingRepoToNxCloudPrompt)() : false);
|
|
64
66
|
return {
|
|
65
67
|
...options,
|
|
66
68
|
nxCloud,
|
|
@@ -126,7 +128,7 @@ async function reorgnizeWorkspaceStructure(options) {
|
|
|
126
128
|
}
|
|
127
129
|
function createTempWorkspace(options) {
|
|
128
130
|
(0, fs_extra_1.removeSync)('temp-workspace');
|
|
129
|
-
(0, child_process_1.execSync)(`npx ${options.npxYesFlagNeeded ? '-y' : ''} create-nx-workspace@latest temp-workspace --appName=${options.reactAppName} --preset=react-monorepo --style=css --bundler=${options.isVite ? 'vite' : 'webpack'} --packageManager=${options.packageManager} ${options.nxCloud ? '--nxCloud' : '--nxCloud=
|
|
131
|
+
(0, child_process_1.execSync)(`npx ${options.npxYesFlagNeeded ? '-y' : ''} create-nx-workspace@latest temp-workspace --appName=${options.reactAppName} --preset=react-monorepo --style=css --bundler=${options.isVite ? 'vite' : 'webpack'} --packageManager=${options.packageManager} ${options.nxCloud ? '--nxCloud=yes' : '--nxCloud=skip'} ${options.addE2e ? '--e2eTestRunner=cypress' : '--e2eTestRunner=none'}`, { stdio: [0, 1, 2] });
|
|
130
132
|
output_1.output.log({ title: '👋 Welcome to Nx!' });
|
|
131
133
|
output_1.output.log({ title: '🧹 Clearing unused files' });
|
|
132
134
|
(0, fs_extra_1.copySync)((0, path_1.join)('temp-workspace', 'apps', options.reactAppName, 'project.json'), 'project.json');
|
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.renameJsToJsx = void 0;
|
|
4
4
|
const fs_extra_1 = require("fs-extra");
|
|
5
|
-
const
|
|
5
|
+
const workspace_context_1 = require("../../../../utils/workspace-context");
|
|
6
6
|
const fileutils_1 = require("../../../../utils/fileutils");
|
|
7
7
|
// Vite cannot process JSX like <div> or <Header> unless the file is named .jsx or .tsx
|
|
8
8
|
function renameJsToJsx(appName, isStandalone) {
|
|
9
|
-
const files = (0,
|
|
9
|
+
const files = (0, workspace_context_1.globWithWorkspaceContext)(process.cwd(), [
|
|
10
|
+
isStandalone ? 'src/**/*.js' : `apps/${appName}/src/**/*.js`,
|
|
11
|
+
]);
|
|
10
12
|
files.forEach((file) => {
|
|
11
13
|
if ((0, fileutils_1.fileExists)(file)) {
|
|
12
14
|
const content = (0, fs_extra_1.readFileSync)(file).toString();
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
+
import { PackageJson } from '../../../utils/package-json';
|
|
1
2
|
import { PackageManagerCommands } from '../../../utils/package-manager';
|
|
2
|
-
export declare function askAboutNxCloud(): Promise<boolean>;
|
|
3
3
|
export declare function createNxJsonFile(repoRoot: string, topologicalTargets: string[], cacheableOperations: string[], scriptOutputs: {
|
|
4
4
|
[name: string]: string;
|
|
5
5
|
}): void;
|
|
6
|
-
export declare function addDepsToPackageJson(repoRoot: string): void;
|
|
6
|
+
export declare function addDepsToPackageJson(repoRoot: string, additionalPackages?: string[]): void;
|
|
7
7
|
export declare function updateGitIgnore(root: string): void;
|
|
8
8
|
export declare function runInstall(repoRoot: string, pmc?: PackageManagerCommands): void;
|
|
9
9
|
export declare function initCloud(repoRoot: string, installationSource: 'nx-init-angular' | 'nx-init-cra' | 'nx-init-monorepo' | 'nx-init-nest' | 'nx-init-npm-repo'): void;
|
|
10
10
|
export declare function addVsCodeRecommendedExtensions(repoRoot: string, extensions: string[]): void;
|
|
11
|
-
export declare function
|
|
12
|
-
|
|
13
|
-
}, pmc: PackageManagerCommands): void;
|
|
11
|
+
export declare function markRootPackageJsonAsNxProjectLegacy(repoRoot: string, cacheableScripts: string[], pmc: PackageManagerCommands): void;
|
|
12
|
+
export declare function markPackageJsonAsNxProject(packageJsonPath: string, cacheableScripts: string[]): void;
|
|
14
13
|
export declare function printFinalMessage({ learnMoreLink, bodyLines, }: {
|
|
15
14
|
learnMoreLink?: string;
|
|
16
15
|
bodyLines?: string[];
|
|
17
16
|
}): void;
|
|
17
|
+
export declare function isMonorepo(packageJson: PackageJson): boolean;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.printFinalMessage = exports.
|
|
3
|
+
exports.isMonorepo = exports.printFinalMessage = exports.markPackageJsonAsNxProject = exports.markRootPackageJsonAsNxProjectLegacy = exports.addVsCodeRecommendedExtensions = exports.initCloud = exports.runInstall = exports.updateGitIgnore = exports.addDepsToPackageJson = exports.createNxJsonFile = void 0;
|
|
4
4
|
const child_process_1 = require("child_process");
|
|
5
|
-
const enquirer = require("enquirer");
|
|
6
5
|
const path_1 = require("path");
|
|
7
6
|
const child_process_2 = require("../../../utils/child-process");
|
|
8
7
|
const fileutils_1 = require("../../../utils/fileutils");
|
|
@@ -11,28 +10,6 @@ const package_manager_1 = require("../../../utils/package-manager");
|
|
|
11
10
|
const path_2 = require("../../../utils/path");
|
|
12
11
|
const versions_1 = require("../../../utils/versions");
|
|
13
12
|
const fs_1 = require("fs");
|
|
14
|
-
async function askAboutNxCloud() {
|
|
15
|
-
return await enquirer
|
|
16
|
-
.prompt([
|
|
17
|
-
{
|
|
18
|
-
name: 'NxCloud',
|
|
19
|
-
message: `Enable distributed caching to make your CI faster`,
|
|
20
|
-
type: 'autocomplete',
|
|
21
|
-
choices: [
|
|
22
|
-
{
|
|
23
|
-
name: 'Yes',
|
|
24
|
-
hint: 'I want faster builds',
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
name: 'No',
|
|
28
|
-
},
|
|
29
|
-
],
|
|
30
|
-
initial: 'Yes',
|
|
31
|
-
},
|
|
32
|
-
])
|
|
33
|
-
.then((a) => a.NxCloud === 'Yes');
|
|
34
|
-
}
|
|
35
|
-
exports.askAboutNxCloud = askAboutNxCloud;
|
|
36
13
|
function createNxJsonFile(repoRoot, topologicalTargets, cacheableOperations, scriptOutputs) {
|
|
37
14
|
const nxJsonPath = (0, path_2.joinPathFragments)(repoRoot, 'nx.json');
|
|
38
15
|
let nxJson = {};
|
|
@@ -41,27 +18,30 @@ function createNxJsonFile(repoRoot, topologicalTargets, cacheableOperations, scr
|
|
|
41
18
|
// eslint-disable-next-line no-empty
|
|
42
19
|
}
|
|
43
20
|
catch { }
|
|
21
|
+
nxJson.$schema = './node_modules/nx/schemas/nx-schema.json';
|
|
44
22
|
nxJson.targetDefaults ??= {};
|
|
45
23
|
if (topologicalTargets.length > 0) {
|
|
46
24
|
for (const scriptName of topologicalTargets) {
|
|
47
25
|
nxJson.targetDefaults[scriptName] ??= {};
|
|
48
26
|
nxJson.targetDefaults[scriptName] = { dependsOn: [`^${scriptName}`] };
|
|
49
27
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
nxJson.targetDefaults[scriptName] ??= {};
|
|
56
|
-
nxJson.targetDefaults[scriptName].outputs = [`{projectRoot}/${output}`];
|
|
28
|
+
}
|
|
29
|
+
for (const [scriptName, output] of Object.entries(scriptOutputs)) {
|
|
30
|
+
if (!output) {
|
|
31
|
+
// eslint-disable-next-line no-continue
|
|
32
|
+
continue;
|
|
57
33
|
}
|
|
34
|
+
nxJson.targetDefaults[scriptName] ??= {};
|
|
35
|
+
nxJson.targetDefaults[scriptName].outputs = [`{projectRoot}/${output}`];
|
|
58
36
|
}
|
|
59
37
|
for (const target of cacheableOperations) {
|
|
60
38
|
nxJson.targetDefaults[target] ??= {};
|
|
61
39
|
nxJson.targetDefaults[target].cache ??= true;
|
|
62
40
|
}
|
|
63
|
-
nxJson.
|
|
64
|
-
|
|
41
|
+
if (Object.keys(nxJson.targetDefaults).length === 0) {
|
|
42
|
+
delete nxJson.targetDefaults;
|
|
43
|
+
}
|
|
44
|
+
nxJson.defaultBase ??= deduceDefaultBase();
|
|
65
45
|
(0, fileutils_1.writeJsonFile)(nxJsonPath, nxJson);
|
|
66
46
|
}
|
|
67
47
|
exports.createNxJsonFile = createNxJsonFile;
|
|
@@ -100,12 +80,17 @@ function deduceDefaultBase() {
|
|
|
100
80
|
}
|
|
101
81
|
}
|
|
102
82
|
}
|
|
103
|
-
function addDepsToPackageJson(repoRoot) {
|
|
83
|
+
function addDepsToPackageJson(repoRoot, additionalPackages) {
|
|
104
84
|
const path = (0, path_2.joinPathFragments)(repoRoot, `package.json`);
|
|
105
85
|
const json = (0, fileutils_1.readJsonFile)(path);
|
|
106
86
|
if (!json.devDependencies)
|
|
107
87
|
json.devDependencies = {};
|
|
108
88
|
json.devDependencies['nx'] = versions_1.nxVersion;
|
|
89
|
+
if (additionalPackages) {
|
|
90
|
+
for (const p of additionalPackages) {
|
|
91
|
+
json.devDependencies[p] = versions_1.nxVersion;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
109
94
|
(0, fileutils_1.writeJsonFile)(path, json);
|
|
110
95
|
}
|
|
111
96
|
exports.addDepsToPackageJson = addDepsToPackageJson;
|
|
@@ -149,16 +134,9 @@ function addVsCodeRecommendedExtensions(repoRoot, extensions) {
|
|
|
149
134
|
}
|
|
150
135
|
}
|
|
151
136
|
exports.addVsCodeRecommendedExtensions = addVsCodeRecommendedExtensions;
|
|
152
|
-
function
|
|
137
|
+
function markRootPackageJsonAsNxProjectLegacy(repoRoot, cacheableScripts, pmc) {
|
|
153
138
|
const json = (0, fileutils_1.readJsonFile)((0, path_2.joinPathFragments)(repoRoot, `package.json`));
|
|
154
|
-
json.nx = {
|
|
155
|
-
for (let script of Object.keys(scriptOutputs)) {
|
|
156
|
-
if (scriptOutputs[script]) {
|
|
157
|
-
json.nx.targets[script] = {
|
|
158
|
-
outputs: [`{projectRoot}/${scriptOutputs[script]}`],
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
}
|
|
139
|
+
json.nx = {};
|
|
162
140
|
for (let script of cacheableScripts) {
|
|
163
141
|
const scriptDefinition = json.scripts[script];
|
|
164
142
|
if (!scriptDefinition) {
|
|
@@ -175,7 +153,21 @@ function markRootPackageJsonAsNxProject(repoRoot, cacheableScripts, scriptOutput
|
|
|
175
153
|
}
|
|
176
154
|
(0, fileutils_1.writeJsonFile)(`package.json`, json);
|
|
177
155
|
}
|
|
178
|
-
exports.
|
|
156
|
+
exports.markRootPackageJsonAsNxProjectLegacy = markRootPackageJsonAsNxProjectLegacy;
|
|
157
|
+
function markPackageJsonAsNxProject(packageJsonPath, cacheableScripts) {
|
|
158
|
+
const json = (0, fileutils_1.readJsonFile)(packageJsonPath);
|
|
159
|
+
if (!json.scripts) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
json.nx = { includedScripts: [] };
|
|
163
|
+
for (let script of cacheableScripts) {
|
|
164
|
+
if (json.scripts[script]) {
|
|
165
|
+
json.nx.includedScripts.push(script);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
(0, fileutils_1.writeJsonFile)(packageJsonPath, json);
|
|
169
|
+
}
|
|
170
|
+
exports.markPackageJsonAsNxProject = markPackageJsonAsNxProject;
|
|
179
171
|
function printFinalMessage({ learnMoreLink, bodyLines, }) {
|
|
180
172
|
const normalizedBodyLines = (bodyLines ?? []).map((l) => l.startsWith('- ') ? l : `- ${l}`);
|
|
181
173
|
output_1.output.success({
|
|
@@ -188,3 +180,13 @@ function printFinalMessage({ learnMoreLink, bodyLines, }) {
|
|
|
188
180
|
});
|
|
189
181
|
}
|
|
190
182
|
exports.printFinalMessage = printFinalMessage;
|
|
183
|
+
function isMonorepo(packageJson) {
|
|
184
|
+
if (!!packageJson.workspaces)
|
|
185
|
+
return true;
|
|
186
|
+
if ((0, fs_1.existsSync)('pnpm-workspace.yaml') || (0, fs_1.existsSync)('pnpm-workspace.yml'))
|
|
187
|
+
return true;
|
|
188
|
+
if ((0, fs_1.existsSync)('lerna.json'))
|
|
189
|
+
return true;
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
exports.isMonorepo = isMonorepo;
|
|
@@ -14,6 +14,7 @@ const react_1 = require("./implementation/react");
|
|
|
14
14
|
const child_process_2 = require("../../utils/child-process");
|
|
15
15
|
const fileutils_1 = require("../../utils/fileutils");
|
|
16
16
|
const versions_1 = require("../../utils/versions");
|
|
17
|
+
const utils_1 = require("./implementation/utils");
|
|
17
18
|
async function initHandler(options) {
|
|
18
19
|
// strip the 'init' command itself so we don't forward it
|
|
19
20
|
const args = process.argv.slice(3).join(' ');
|
|
@@ -35,11 +36,11 @@ async function initHandler(options) {
|
|
|
35
36
|
else if (isNestCLI(packageJson)) {
|
|
36
37
|
await (0, add_nx_to_nest_1.addNxToNest)(options, packageJson);
|
|
37
38
|
}
|
|
38
|
-
else if (isMonorepo(packageJson)) {
|
|
39
|
-
await (0, add_nx_to_monorepo_1.addNxToMonorepo)(options);
|
|
39
|
+
else if ((0, utils_1.isMonorepo)(packageJson)) {
|
|
40
|
+
await (0, add_nx_to_monorepo_1.addNxToMonorepo)({ ...options, legacy: true });
|
|
40
41
|
}
|
|
41
42
|
else {
|
|
42
|
-
await (0, add_nx_to_npm_repo_1.addNxToNpmRepo)(options);
|
|
43
|
+
await (0, add_nx_to_npm_repo_1.addNxToNpmRepo)({ ...options, legacy: true });
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
46
|
else {
|
|
@@ -96,15 +97,6 @@ function isNestCLI(packageJson) {
|
|
|
96
97
|
combinedDependencies['@nestjs/core'] &&
|
|
97
98
|
combinedDependencies['@nestjs/cli']);
|
|
98
99
|
}
|
|
99
|
-
function isMonorepo(packageJson) {
|
|
100
|
-
if (!!packageJson.workspaces)
|
|
101
|
-
return true;
|
|
102
|
-
if ((0, fs_1.existsSync)('pnpm-workspace.yaml') || (0, fs_1.existsSync)('pnpm-workspace.yml'))
|
|
103
|
-
return true;
|
|
104
|
-
if ((0, fs_1.existsSync)('lerna.json'))
|
|
105
|
-
return true;
|
|
106
|
-
return false;
|
|
107
|
-
}
|
|
108
100
|
function setupDotNxInstallation(version) {
|
|
109
101
|
if (process.platform !== 'win32') {
|
|
110
102
|
console.log('Setting Nx up installation in `.nx`. You can run nx commands like: `./nx --help`');
|
|
@@ -114,5 +106,5 @@ function setupDotNxInstallation(version) {
|
|
|
114
106
|
}
|
|
115
107
|
(0, add_nx_scripts_1.generateDotNxSetup)(version);
|
|
116
108
|
// invokes the wrapper, thus invoking the initial installation process
|
|
117
|
-
(0, child_process_2.runNxSync)('');
|
|
109
|
+
(0, child_process_2.runNxSync)('--version');
|
|
118
110
|
}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initHandler = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const semver_1 = require("semver");
|
|
6
|
+
const output_1 = require("../../utils/output");
|
|
7
|
+
const package_manager_1 = require("../../utils/package-manager");
|
|
8
|
+
const add_nx_scripts_1 = require("./implementation/dot-nx/add-nx-scripts");
|
|
9
|
+
const child_process_1 = require("../../utils/child-process");
|
|
10
|
+
const fileutils_1 = require("../../utils/fileutils");
|
|
11
|
+
const versions_1 = require("../../utils/versions");
|
|
12
|
+
const utils_1 = require("./implementation/utils");
|
|
13
|
+
const enquirer_1 = require("enquirer");
|
|
14
|
+
const child_process_2 = require("child_process");
|
|
15
|
+
const angular_1 = require("./implementation/angular");
|
|
16
|
+
const workspace_context_1 = require("../../utils/workspace-context");
|
|
17
|
+
const connect_to_nx_cloud_1 = require("../connect/connect-to-nx-cloud");
|
|
18
|
+
const add_nx_to_npm_repo_1 = require("./implementation/add-nx-to-npm-repo");
|
|
19
|
+
const add_nx_to_monorepo_1 = require("./implementation/add-nx-to-monorepo");
|
|
20
|
+
const path_1 = require("path");
|
|
21
|
+
async function initHandler(options) {
|
|
22
|
+
process.env.NX_RUNNING_NX_INIT = 'true';
|
|
23
|
+
const version = process.env.NX_VERSION ?? ((0, semver_1.prerelease)(versions_1.nxVersion) ? 'next' : 'latest');
|
|
24
|
+
if (process.env.NX_VERSION) {
|
|
25
|
+
output_1.output.log({ title: `Using version ${process.env.NX_VERSION}` });
|
|
26
|
+
}
|
|
27
|
+
if (!(0, fs_1.existsSync)('package.json') || options.useDotNxInstallation) {
|
|
28
|
+
if (process.platform !== 'win32') {
|
|
29
|
+
console.log('Setting Nx up installation in `.nx`. You can run Nx commands like: `./nx --help`');
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
console.log('Setting Nx up installation in `.nx`. You can run Nx commands like: `./nx.bat --help`');
|
|
33
|
+
}
|
|
34
|
+
(0, add_nx_scripts_1.generateDotNxSetup)(version);
|
|
35
|
+
const { plugins } = await detectPlugins();
|
|
36
|
+
plugins.forEach((plugin) => {
|
|
37
|
+
(0, child_process_2.execSync)(`./nx add ${plugin}`, {
|
|
38
|
+
stdio: 'inherit',
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
// invokes the wrapper, thus invoking the initial installation process
|
|
42
|
+
(0, child_process_1.runNxSync)('--version', { stdio: 'ignore' });
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
// TODO(jack): Remove this Angular logic once `@nx/angular` is compatible with inferred targets.
|
|
46
|
+
if ((0, fs_1.existsSync)('angular.json')) {
|
|
47
|
+
await (0, angular_1.addNxToAngularCliRepo)({
|
|
48
|
+
...options,
|
|
49
|
+
integrated: !!options.integrated,
|
|
50
|
+
});
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
output_1.output.log({ title: '🧐 Checking dependencies' });
|
|
54
|
+
const { plugins, updatePackageScripts } = await detectPlugins();
|
|
55
|
+
if (!plugins.length) {
|
|
56
|
+
// If no plugins are detected/chosen, guide users to setup
|
|
57
|
+
// their targetDefaults correctly so their package scripts will work.
|
|
58
|
+
const packageJson = (0, fileutils_1.readJsonFile)('package.json');
|
|
59
|
+
if ((0, utils_1.isMonorepo)(packageJson)) {
|
|
60
|
+
await (0, add_nx_to_monorepo_1.addNxToMonorepo)({ interactive: options.interactive });
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
await (0, add_nx_to_npm_repo_1.addNxToNpmRepo)({ interactive: options.interactive });
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
const useNxCloud = options.nxCloud ??
|
|
68
|
+
(options.interactive
|
|
69
|
+
? await (0, connect_to_nx_cloud_1.connectExistingRepoToNxCloudPrompt)()
|
|
70
|
+
: false);
|
|
71
|
+
const repoRoot = process.cwd();
|
|
72
|
+
const pmc = (0, package_manager_1.getPackageManagerCommand)();
|
|
73
|
+
(0, utils_1.createNxJsonFile)(repoRoot, [], [], {});
|
|
74
|
+
(0, utils_1.updateGitIgnore)(repoRoot);
|
|
75
|
+
(0, utils_1.addDepsToPackageJson)(repoRoot, plugins);
|
|
76
|
+
output_1.output.log({ title: '📦 Installing Nx' });
|
|
77
|
+
(0, utils_1.runInstall)(repoRoot, pmc);
|
|
78
|
+
output_1.output.log({ title: '🔨 Configuring plugins' });
|
|
79
|
+
for (const plugin of plugins) {
|
|
80
|
+
(0, child_process_2.execSync)(`${pmc.exec} nx g ${plugin}:init --keepExistingVersions ${updatePackageScripts ? '--updatePackageScripts' : ''} --no-interactive`, {
|
|
81
|
+
stdio: [0, 1, 2],
|
|
82
|
+
cwd: repoRoot,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
if (!updatePackageScripts) {
|
|
86
|
+
const rootPackageJsonPath = (0, path_1.join)(repoRoot, 'package.json');
|
|
87
|
+
const json = (0, fileutils_1.readJsonFile)(rootPackageJsonPath);
|
|
88
|
+
json.nx = { includedScripts: [] };
|
|
89
|
+
(0, fileutils_1.writeJsonFile)(rootPackageJsonPath, json);
|
|
90
|
+
}
|
|
91
|
+
if (useNxCloud) {
|
|
92
|
+
output_1.output.log({ title: '🛠️ Setting up Nx Cloud' });
|
|
93
|
+
(0, child_process_2.execSync)(`${pmc.exec} nx g nx:connect-to-nx-cloud --installationSource=nx-init --quiet --hideFormatLogs --no-interactive`, {
|
|
94
|
+
stdio: [0, 1, 2],
|
|
95
|
+
cwd: repoRoot,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
output_1.output.log({
|
|
100
|
+
title: '👀 Explore Your Workspace',
|
|
101
|
+
bodyLines: [
|
|
102
|
+
`Run "nx graph" to show the graph of the workspace. It will show tasks that you can run with Nx.`,
|
|
103
|
+
`Read this guide on exploring your workspace: https://nx.dev/core-features/explore-graph`,
|
|
104
|
+
],
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
exports.initHandler = initHandler;
|
|
108
|
+
const npmPackageToPluginMap = {
|
|
109
|
+
// Generic JS tools
|
|
110
|
+
eslint: '@nx/eslint',
|
|
111
|
+
storybook: '@nx/storybook',
|
|
112
|
+
// Bundlers
|
|
113
|
+
vite: '@nx/vite',
|
|
114
|
+
vitest: '@nx/vite',
|
|
115
|
+
webpack: '@nx/webpack',
|
|
116
|
+
rollup: '@nx/rollup',
|
|
117
|
+
// Testing tools
|
|
118
|
+
jest: '@nx/jest',
|
|
119
|
+
cypress: '@nx/cypress',
|
|
120
|
+
'@playwright/test': '@nx/playwright',
|
|
121
|
+
// Frameworks
|
|
122
|
+
detox: '@nx/detox',
|
|
123
|
+
expo: '@nx/expo',
|
|
124
|
+
next: '@nx/next',
|
|
125
|
+
nuxt: '@nx/nuxt',
|
|
126
|
+
'react-native': '@nx/react-native',
|
|
127
|
+
'@remix-run/dev': '@nx/remix',
|
|
128
|
+
};
|
|
129
|
+
async function detectPlugins() {
|
|
130
|
+
let files = ['package.json'].concat((0, workspace_context_1.globWithWorkspaceContext)(process.cwd(), ['**/*/package.json']));
|
|
131
|
+
const detectedPlugins = new Set();
|
|
132
|
+
for (const file of files) {
|
|
133
|
+
if (!(0, fs_1.existsSync)(file))
|
|
134
|
+
continue;
|
|
135
|
+
let packageJson;
|
|
136
|
+
try {
|
|
137
|
+
packageJson = (0, fileutils_1.readJsonFile)(file);
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
// Could have malformed JSON for unit tests, etc.
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
const deps = {
|
|
144
|
+
...packageJson.dependencies,
|
|
145
|
+
...packageJson.devDependencies,
|
|
146
|
+
};
|
|
147
|
+
for (const [dep, plugin] of Object.entries(npmPackageToPluginMap)) {
|
|
148
|
+
if (deps[dep]) {
|
|
149
|
+
detectedPlugins.add(plugin);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if ((0, fs_1.existsSync)('gradlew') || (0, fs_1.existsSync)('gradlew.bat')) {
|
|
154
|
+
detectedPlugins.add('@nx/gradle');
|
|
155
|
+
}
|
|
156
|
+
const plugins = Array.from(detectedPlugins);
|
|
157
|
+
if (plugins.length === 0) {
|
|
158
|
+
return {
|
|
159
|
+
plugins: [],
|
|
160
|
+
updatePackageScripts: false,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
output_1.output.log({
|
|
164
|
+
title: `Recommended Plugins:`,
|
|
165
|
+
bodyLines: [
|
|
166
|
+
`Add these Nx plugins to integrate with the tools used in your workspace.`,
|
|
167
|
+
],
|
|
168
|
+
});
|
|
169
|
+
const pluginsToInstall = await (0, enquirer_1.prompt)([
|
|
170
|
+
{
|
|
171
|
+
name: 'plugins',
|
|
172
|
+
type: 'multiselect',
|
|
173
|
+
message: `Which plugins would you like to add?`,
|
|
174
|
+
choices: plugins.map((p) => ({ name: p, value: p })),
|
|
175
|
+
initial: plugins.map((_, i) => i), // casting to avoid type error due to bad d.ts file from enquirer
|
|
176
|
+
},
|
|
177
|
+
]).then((r) => r.plugins);
|
|
178
|
+
if (pluginsToInstall?.length === 0)
|
|
179
|
+
return {
|
|
180
|
+
plugins: [],
|
|
181
|
+
updatePackageScripts: false,
|
|
182
|
+
};
|
|
183
|
+
const updatePackageScripts = (0, fs_1.existsSync)('package.json') &&
|
|
184
|
+
(await (0, enquirer_1.prompt)([
|
|
185
|
+
{
|
|
186
|
+
name: 'updatePackageScripts',
|
|
187
|
+
type: 'autocomplete',
|
|
188
|
+
message: `Do you want to start using Nx in your package.json scripts?`,
|
|
189
|
+
choices: [
|
|
190
|
+
{
|
|
191
|
+
name: 'Yes',
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
name: 'No',
|
|
195
|
+
},
|
|
196
|
+
],
|
|
197
|
+
initial: 0,
|
|
198
|
+
},
|
|
199
|
+
]).then((r) => r.updatePackageScripts === 'Yes'));
|
|
200
|
+
return { plugins: pluginsToInstall, updatePackageScripts };
|
|
201
|
+
}
|