nx 21.0.0-beta.1 → 21.0.0-beta.11
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 +5 -1
- package/migrations.json +15 -35
- package/package.json +12 -12
- package/release/index.d.ts +1 -1
- package/release/index.js +2 -1
- package/schemas/nx-schema.json +187 -35
- package/schemas/project-schema.json +5 -0
- package/src/adapter/angular-json.js +11 -0
- package/src/adapter/compat.d.ts +1 -1
- package/src/adapter/compat.js +3 -0
- package/src/command-line/add/add.js +6 -16
- package/src/command-line/affected/command-object.js +6 -6
- package/src/command-line/examples.js +0 -4
- package/src/command-line/exec/command-object.js +1 -1
- package/src/command-line/generate/generator-utils.js +8 -3
- package/src/command-line/import/import.js +1 -1
- package/src/command-line/init/command-object.js +18 -6
- package/src/command-line/init/configure-plugins.d.ts +6 -7
- package/src/command-line/init/configure-plugins.js +52 -38
- package/src/command-line/init/implementation/add-nx-to-turborepo.d.ts +4 -0
- package/src/command-line/init/implementation/add-nx-to-turborepo.js +49 -0
- package/src/command-line/init/implementation/check-compatible-with-plugins.js +7 -1
- package/src/command-line/init/implementation/deduce-default-base.d.ts +1 -0
- package/src/command-line/init/implementation/deduce-default-base.js +53 -0
- package/src/command-line/init/implementation/react/add-vite-commands-to-package-scripts.js +6 -4
- package/src/command-line/init/implementation/react/index.d.ts +1 -1
- package/src/command-line/init/implementation/react/index.js +32 -185
- package/src/command-line/init/implementation/react/write-vite-config.js +19 -3
- package/src/command-line/init/implementation/utils.d.ts +6 -2
- package/src/command-line/init/implementation/utils.js +110 -45
- package/src/command-line/init/init-v1.js +1 -1
- package/src/command-line/init/init-v2.d.ts +1 -0
- package/src/command-line/init/init-v2.js +70 -39
- package/src/command-line/migrate/migrate-ui-api.d.ts +58 -0
- package/src/command-line/migrate/migrate-ui-api.js +227 -0
- package/src/command-line/migrate/migrate.d.ts +23 -4
- package/src/command-line/migrate/migrate.js +138 -86
- package/src/command-line/nx-commands.js +19 -5
- package/src/command-line/register/command-object.d.ts +6 -0
- package/src/command-line/{activate-powerpack → register}/command-object.js +9 -9
- package/src/command-line/register/register.d.ts +2 -0
- package/src/command-line/register/register.js +9 -0
- package/src/command-line/release/changelog.js +18 -15
- package/src/command-line/release/command-object.d.ts +8 -0
- package/src/command-line/release/command-object.js +9 -0
- package/src/command-line/release/config/config.d.ts +8 -7
- package/src/command-line/release/config/config.js +139 -45
- package/src/command-line/release/config/use-legacy-versioning.d.ts +2 -0
- package/src/command-line/release/config/use-legacy-versioning.js +9 -0
- package/src/command-line/release/index.d.ts +4 -0
- package/src/command-line/release/index.js +6 -1
- package/src/command-line/release/plan-check.js +6 -3
- package/src/command-line/release/plan.js +7 -3
- package/src/command-line/release/publish.js +7 -3
- package/src/command-line/release/release.js +8 -3
- package/src/command-line/release/utils/batch-projects-by-generator-config.js +6 -3
- package/src/command-line/release/utils/git.d.ts +3 -2
- package/src/command-line/release/utils/git.js +65 -9
- package/src/command-line/release/utils/github.js +3 -1
- package/src/command-line/release/utils/resolve-semver-specifier.d.ts +2 -1
- package/src/command-line/release/utils/resolve-semver-specifier.js +2 -1
- package/src/command-line/release/utils/semver.d.ts +8 -0
- package/src/command-line/release/utils/semver.js +8 -0
- package/src/command-line/release/utils/shared-legacy.d.ts +25 -0
- package/src/command-line/release/utils/shared-legacy.js +2 -0
- package/src/command-line/release/utils/shared.d.ts +11 -17
- package/src/command-line/release/version/derive-specifier-from-conventional-commits.d.ts +7 -0
- package/src/command-line/release/version/derive-specifier-from-conventional-commits.js +47 -0
- package/src/command-line/release/version/deriver-specifier-from-version-plans.d.ts +8 -0
- package/src/command-line/release/version/deriver-specifier-from-version-plans.js +59 -0
- package/src/command-line/release/version/project-logger.d.ts +8 -0
- package/src/command-line/release/version/project-logger.js +45 -0
- package/src/command-line/release/version/release-group-processor.d.ts +252 -0
- package/src/command-line/release/version/release-group-processor.js +1057 -0
- package/src/command-line/release/version/resolve-current-version.d.ts +32 -0
- package/src/command-line/release/version/resolve-current-version.js +241 -0
- package/src/command-line/release/version/test-utils.d.ts +93 -0
- package/src/command-line/release/version/test-utils.js +415 -0
- package/src/command-line/release/version/topological-sort.d.ts +9 -0
- package/src/command-line/release/version/topological-sort.js +41 -0
- package/src/command-line/release/version/version-actions.d.ts +171 -0
- package/src/command-line/release/version/version-actions.js +195 -0
- package/src/command-line/release/version-legacy.d.ts +46 -0
- package/src/command-line/release/version-legacy.js +453 -0
- package/src/command-line/release/version.d.ts +0 -40
- package/src/command-line/release/version.js +84 -262
- package/src/command-line/repair/repair.js +8 -3
- package/src/command-line/report/report.d.ts +7 -3
- package/src/command-line/report/report.js +52 -18
- package/src/command-line/run/command-object.js +2 -2
- package/src/command-line/run/executor-utils.d.ts +6 -1
- package/src/command-line/run/executor-utils.js +10 -1
- package/src/command-line/run/run.js +2 -2
- package/src/command-line/run-many/command-object.js +2 -2
- package/src/command-line/yargs-utils/shared-options.d.ts +4 -0
- package/src/command-line/yargs-utils/shared-options.js +20 -0
- package/src/config/misc-interfaces.d.ts +20 -2
- package/src/config/nx-json.d.ts +158 -18
- package/src/config/project-graph.d.ts +4 -2
- package/src/config/project-graph.js +8 -0
- package/src/config/workspace-json-project-json.d.ts +2 -2
- package/src/core/graph/main.js +1 -1
- package/src/core/graph/runtime.js +1 -1
- package/src/core/graph/styles.css +2 -2
- package/src/core/graph/styles.js +1 -1
- package/src/daemon/client/client.d.ts +2 -0
- package/src/daemon/client/client.js +15 -0
- package/src/daemon/message-types/glob.d.ts +7 -0
- package/src/daemon/message-types/glob.js +9 -1
- package/src/daemon/message-types/hash-glob.d.ts +6 -0
- package/src/daemon/message-types/hash-glob.js +9 -1
- package/src/daemon/server/handle-glob.d.ts +1 -0
- package/src/daemon/server/handle-glob.js +8 -0
- package/src/daemon/server/handle-hash-glob.d.ts +1 -0
- package/src/daemon/server/handle-hash-glob.js +8 -0
- package/src/daemon/server/logger.js +2 -1
- package/src/daemon/server/server.js +7 -0
- package/src/devkit-exports.d.ts +1 -1
- package/src/devkit-internals.d.ts +3 -2
- package/src/devkit-internals.js +5 -1
- package/src/executors/run-commands/run-commands.impl.d.ts +2 -5
- package/src/executors/run-commands/run-commands.impl.js +14 -42
- package/src/executors/run-commands/running-tasks.d.ts +9 -4
- package/src/executors/run-commands/running-tasks.js +103 -30
- package/src/executors/run-script/run-script.impl.js +4 -3
- package/src/generators/internal-utils/format-changed-files-with-prettier-if-available.js +8 -0
- package/src/generators/testing-utils/create-tree.js +5 -1
- package/src/migrations/update-21-0-0/release-version-config-changes.d.ts +2 -0
- package/src/migrations/update-21-0-0/release-version-config-changes.js +111 -0
- package/src/migrations/update-21-0-0/remove-custom-tasks-runner.d.ts +2 -0
- package/src/migrations/update-21-0-0/remove-custom-tasks-runner.js +38 -0
- package/src/migrations/{update-18-0-0/disable-crystal-for-existing-workspaces.js → update-21-0-0/remove-legacy-cache.js} +10 -4
- package/src/native/index.d.ts +98 -19
- package/src/native/index.js +16 -2
- package/src/native/native-bindings.js +7 -0
- package/src/native/nx.wasi-browser.js +20 -19
- package/src/native/nx.wasi.cjs +20 -19
- package/src/native/nx.wasm32-wasi.wasm +0 -0
- package/src/nx-cloud/nx-cloud-tasks-runner-shell.js +3 -3
- package/src/plugins/js/index.d.ts +2 -1
- package/src/plugins/js/index.js +8 -1
- package/src/plugins/js/lock-file/lock-file.js +28 -13
- package/src/plugins/js/lock-file/utils/package-json.d.ts +1 -1
- package/src/plugins/js/lock-file/utils/package-json.js +8 -6
- package/src/plugins/js/lock-file/utils/pnpm-normalizer.js +3 -3
- package/src/plugins/js/lock-file/yarn-parser.js +85 -39
- package/src/plugins/js/project-graph/affected/lock-file-changes.js +1 -0
- package/src/plugins/js/project-graph/build-dependencies/explicit-project-dependencies.js +1 -1
- package/src/plugins/js/project-graph/build-dependencies/target-project-locator.d.ts +10 -1
- package/src/plugins/js/project-graph/build-dependencies/target-project-locator.js +59 -6
- package/src/plugins/js/utils/packages.js +22 -3
- package/src/plugins/js/utils/register.js +1 -0
- package/src/plugins/js/utils/typescript.js +3 -3
- package/src/plugins/package-json/create-nodes.d.ts +1 -1
- package/src/plugins/package-json/create-nodes.js +4 -2
- package/src/project-graph/affected/locators/project-glob-changes.js +2 -2
- package/src/project-graph/error-types.js +32 -2
- package/src/project-graph/file-utils.d.ts +1 -10
- package/src/project-graph/file-utils.js +2 -77
- package/src/project-graph/plugins/get-plugins.js +2 -1
- package/src/project-graph/plugins/in-process-loader.js +1 -1
- package/src/project-graph/plugins/isolation/plugin-worker.js +12 -6
- package/src/project-graph/plugins/loaded-nx-plugin.d.ts +2 -1
- package/src/project-graph/plugins/loaded-nx-plugin.js +1 -5
- package/src/project-graph/plugins/public-api.d.ts +1 -1
- package/src/project-graph/plugins/utils.d.ts +2 -2
- package/src/project-graph/plugins/utils.js +2 -2
- package/src/project-graph/project-graph.js +1 -1
- package/src/project-graph/utils/project-configuration-utils.d.ts +3 -3
- package/src/project-graph/utils/project-configuration-utils.js +54 -21
- package/src/project-graph/utils/retrieve-workspace-files.d.ts +1 -1
- package/src/project-graph/utils/retrieve-workspace-files.js +14 -18
- package/src/tasks-runner/batch/batch-messages.d.ts +2 -0
- package/src/tasks-runner/batch/run-batch.js +4 -5
- package/src/tasks-runner/cache.d.ts +21 -8
- package/src/tasks-runner/cache.js +106 -38
- package/src/tasks-runner/create-task-graph.d.ts +0 -1
- package/src/tasks-runner/create-task-graph.js +11 -11
- package/src/tasks-runner/default-tasks-runner.js +5 -14
- package/src/tasks-runner/forked-process-task-runner.d.ts +8 -3
- package/src/tasks-runner/forked-process-task-runner.js +59 -46
- package/src/tasks-runner/init-tasks-runner.d.ts +15 -1
- package/src/tasks-runner/init-tasks-runner.js +62 -2
- package/src/tasks-runner/is-tui-enabled.d.ts +2 -0
- package/src/tasks-runner/is-tui-enabled.js +64 -0
- package/src/tasks-runner/life-cycle.d.ts +14 -3
- package/src/tasks-runner/life-cycle.js +37 -2
- package/src/tasks-runner/life-cycles/task-history-life-cycle-old.d.ts +2 -0
- package/src/tasks-runner/life-cycles/task-history-life-cycle-old.js +15 -7
- package/src/tasks-runner/life-cycles/task-history-life-cycle.d.ts +5 -0
- package/src/tasks-runner/life-cycles/task-history-life-cycle.js +35 -5
- package/src/tasks-runner/life-cycles/tui-summary-life-cycle.d.ts +18 -0
- package/src/tasks-runner/life-cycles/tui-summary-life-cycle.js +230 -0
- package/src/tasks-runner/pseudo-terminal.d.ts +11 -7
- package/src/tasks-runner/pseudo-terminal.js +47 -35
- package/src/tasks-runner/run-command.d.ts +4 -1
- package/src/tasks-runner/run-command.js +219 -63
- package/src/tasks-runner/running-tasks/node-child-process.js +4 -11
- package/src/tasks-runner/running-tasks/running-task.d.ts +3 -0
- package/src/tasks-runner/running-tasks/shared-running-task.d.ts +14 -0
- package/src/tasks-runner/running-tasks/shared-running-task.js +30 -0
- package/src/tasks-runner/task-env.d.ts +1 -4
- package/src/tasks-runner/task-env.js +2 -0
- package/src/tasks-runner/task-graph-utils.d.ts +3 -0
- package/src/tasks-runner/task-graph-utils.js +31 -2
- package/src/tasks-runner/task-orchestrator.d.ts +26 -10
- package/src/tasks-runner/task-orchestrator.js +221 -57
- package/src/tasks-runner/tasks-runner.d.ts +1 -0
- package/src/tasks-runner/tasks-schedule.d.ts +1 -0
- package/src/tasks-runner/tasks-schedule.js +9 -0
- package/src/tasks-runner/utils.d.ts +2 -2
- package/src/tasks-runner/utils.js +18 -12
- package/src/utils/child-process.d.ts +4 -0
- package/src/utils/child-process.js +23 -30
- package/src/utils/command-line-utils.d.ts +1 -1
- package/src/utils/find-matching-projects.js +2 -2
- package/src/utils/git-utils.d.ts +1 -1
- package/src/utils/git-utils.js +8 -3
- package/src/utils/handle-errors.js +15 -0
- package/src/utils/is-ci.js +4 -1
- package/src/utils/is-using-prettier.d.ts +3 -0
- package/src/utils/is-using-prettier.js +62 -0
- package/src/utils/nx-key.d.ts +7 -0
- package/src/utils/nx-key.js +52 -0
- package/src/utils/package-json.d.ts +1 -1
- package/src/utils/package-json.js +16 -2
- package/src/utils/package-manager.js +2 -2
- package/src/utils/path.js +1 -1
- package/src/utils/require-nx-key.d.ts +1 -0
- package/src/utils/require-nx-key.js +22 -0
- package/src/utils/workspace-context.d.ts +2 -0
- package/src/utils/workspace-context.js +16 -0
- package/src/command-line/activate-powerpack/activate-powerpack.d.ts +0 -2
- package/src/command-line/activate-powerpack/activate-powerpack.js +0 -34
- package/src/command-line/activate-powerpack/command-object.d.ts +0 -6
- package/src/command-line/init/implementation/react/write-craco-config.d.ts +0 -1
- package/src/command-line/init/implementation/react/write-craco-config.js +0 -61
- package/src/migrations/update-17-0-0/move-cache-directory.d.ts +0 -2
- package/src/migrations/update-17-0-0/move-cache-directory.js +0 -35
- package/src/migrations/update-17-0-0/rm-default-collection-npm-scope.js +0 -72
- package/src/migrations/update-17-0-0/use-minimal-config-for-tasks-runner-options.d.ts +0 -2
- package/src/migrations/update-17-0-0/use-minimal-config-for-tasks-runner-options.js +0 -122
- package/src/migrations/update-17-2-0/move-default-base.d.ts +0 -5
- package/src/migrations/update-17-2-0/move-default-base.js +0 -21
- package/src/migrations/update-17-3-0/nx-release-path.d.ts +0 -3
- package/src/migrations/update-17-3-0/nx-release-path.js +0 -47
- package/src/migrations/update-18-0-0/disable-crystal-for-existing-workspaces.d.ts +0 -2
- package/src/utils/powerpack.d.ts +0 -5
- package/src/utils/powerpack.js +0 -33
- /package/src/migrations/{update-17-0-0/rm-default-collection-npm-scope.d.ts → update-21-0-0/remove-legacy-cache.d.ts} +0 -0
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.writeViteConfig = writeViteConfig;
|
4
4
|
const fs_1 = require("fs");
|
5
5
|
function writeViteConfig(appName, isStandalone, isJs) {
|
6
|
-
let port =
|
6
|
+
let port = 3000;
|
7
7
|
// Use PORT from .env file if it exists in project.
|
8
8
|
if ((0, fs_1.existsSync)(`../.env`)) {
|
9
9
|
const envFile = (0, fs_1.readFileSync)(`../.env`).toString();
|
@@ -13,8 +13,20 @@ function writeViteConfig(appName, isStandalone, isJs) {
|
|
13
13
|
port = portCandidate;
|
14
14
|
}
|
15
15
|
}
|
16
|
-
(0, fs_1.writeFileSync)(isStandalone ? 'vite.config.
|
16
|
+
(0, fs_1.writeFileSync)(isStandalone ? 'vite.config.mjs' : `apps/${appName}/vite.config.mjs`, `import { defineConfig } from 'vite'
|
17
17
|
import react from '@vitejs/plugin-react'
|
18
|
+
import replace from '@rollup/plugin-replace';
|
19
|
+
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
|
20
|
+
|
21
|
+
// Match CRA's environment variables.
|
22
|
+
// TODO: Replace these with VITE_ prefixed environment variables, and using import.meta.env.VITE_* instead of process.env.REACT_APP_*.
|
23
|
+
const craEnvVarRegex = /^REACT_APP/i;
|
24
|
+
const craEnvVars = Object.keys(process.env)
|
25
|
+
.filter((key) => craEnvVarRegex.test(key))
|
26
|
+
.reduce((env, key) => {
|
27
|
+
env[\`process.env.\${key}\`] = JSON.stringify(process.env[key]);
|
28
|
+
return env;
|
29
|
+
}, {});
|
18
30
|
|
19
31
|
// https://vitejs.dev/config/
|
20
32
|
export default defineConfig({
|
@@ -31,7 +43,11 @@ export default defineConfig({
|
|
31
43
|
setupFiles: 'src/setupTests.${isJs ? 'js' : 'ts'}',
|
32
44
|
css: true,
|
33
45
|
},
|
34
|
-
plugins: [
|
46
|
+
plugins: [
|
47
|
+
react(),
|
48
|
+
replace({ values: craEnvVars, preventAssignment: true }),
|
49
|
+
nxViteTsPaths(),
|
50
|
+
],
|
35
51
|
});
|
36
52
|
`);
|
37
53
|
}
|
@@ -1,16 +1,20 @@
|
|
1
|
+
import { NxJsonConfiguration } from '../../../config/nx-json';
|
1
2
|
import { PackageJson } from '../../../utils/package-json';
|
2
3
|
import { PackageManagerCommands } from '../../../utils/package-manager';
|
3
4
|
export declare function createNxJsonFile(repoRoot: string, topologicalTargets: string[], cacheableOperations: string[], scriptOutputs: {
|
4
5
|
[name: string]: string;
|
5
6
|
}): void;
|
7
|
+
export declare function createNxJsonFromTurboJson(turboJson: Record<string, any>): NxJsonConfiguration;
|
6
8
|
export declare function addDepsToPackageJson(repoRoot: string, additionalPackages?: string[]): void;
|
7
9
|
export declare function updateGitIgnore(root: string): void;
|
8
10
|
export declare function runInstall(repoRoot: string, pmc?: PackageManagerCommands): void;
|
9
|
-
export declare function initCloud(installationSource: 'nx-init' | 'nx-init-angular' | 'nx-init-cra' | 'nx-init-monorepo' | 'nx-init-nest' | 'nx-init-npm-repo'): Promise<void>;
|
11
|
+
export declare function initCloud(installationSource: 'nx-init' | 'nx-init-angular' | 'nx-init-cra' | 'nx-init-monorepo' | 'nx-init-nest' | 'nx-init-npm-repo' | 'nx-init-turborepo'): Promise<void>;
|
10
12
|
export declare function addVsCodeRecommendedExtensions(repoRoot: string, extensions: string[]): void;
|
11
13
|
export declare function markRootPackageJsonAsNxProjectLegacy(repoRoot: string, cacheableScripts: string[], pmc: PackageManagerCommands): void;
|
12
14
|
export declare function markPackageJsonAsNxProject(packageJsonPath: string): void;
|
13
|
-
export declare function printFinalMessage({ learnMoreLink, }: {
|
15
|
+
export declare function printFinalMessage({ learnMoreLink, appendLines, }: {
|
14
16
|
learnMoreLink?: string;
|
17
|
+
appendLines?: string[];
|
15
18
|
}): void;
|
16
19
|
export declare function isMonorepo(packageJson: PackageJson): boolean;
|
20
|
+
export declare function isCRA(packageJson: PackageJson): boolean;
|
@@ -1,6 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.createNxJsonFile = createNxJsonFile;
|
4
|
+
exports.createNxJsonFromTurboJson = createNxJsonFromTurboJson;
|
4
5
|
exports.addDepsToPackageJson = addDepsToPackageJson;
|
5
6
|
exports.updateGitIgnore = updateGitIgnore;
|
6
7
|
exports.runInstall = runInstall;
|
@@ -10,6 +11,7 @@ exports.markRootPackageJsonAsNxProjectLegacy = markRootPackageJsonAsNxProjectLeg
|
|
10
11
|
exports.markPackageJsonAsNxProject = markPackageJsonAsNxProject;
|
11
12
|
exports.printFinalMessage = printFinalMessage;
|
12
13
|
exports.isMonorepo = isMonorepo;
|
14
|
+
exports.isCRA = isCRA;
|
13
15
|
const child_process_1 = require("child_process");
|
14
16
|
const path_1 = require("path");
|
15
17
|
const fileutils_1 = require("../../../utils/fileutils");
|
@@ -21,7 +23,8 @@ const fs_1 = require("fs");
|
|
21
23
|
const connect_to_nx_cloud_1 = require("../../../nx-cloud/generators/connect-to-nx-cloud/connect-to-nx-cloud");
|
22
24
|
const url_shorten_1 = require("../../../nx-cloud/utilities/url-shorten");
|
23
25
|
const connect_to_nx_cloud_2 = require("../../connect/connect-to-nx-cloud");
|
24
|
-
const
|
26
|
+
const deduce_default_base_1 = require("./deduce-default-base");
|
27
|
+
const child_process_2 = require("../../../utils/child-process");
|
25
28
|
function createNxJsonFile(repoRoot, topologicalTargets, cacheableOperations, scriptOutputs) {
|
26
29
|
const nxJsonPath = (0, path_2.joinPathFragments)(repoRoot, 'nx.json');
|
27
30
|
let nxJson = {};
|
@@ -53,56 +56,104 @@ function createNxJsonFile(repoRoot, topologicalTargets, cacheableOperations, scr
|
|
53
56
|
if (Object.keys(nxJson.targetDefaults).length === 0) {
|
54
57
|
delete nxJson.targetDefaults;
|
55
58
|
}
|
56
|
-
|
59
|
+
const defaultBase = (0, deduce_default_base_1.deduceDefaultBase)();
|
60
|
+
// Do not add defaultBase if it is inferred to be the Nx default value of main
|
61
|
+
if (defaultBase !== 'main') {
|
62
|
+
nxJson.defaultBase ??= defaultBase;
|
63
|
+
}
|
57
64
|
(0, fileutils_1.writeJsonFile)(nxJsonPath, nxJson);
|
58
65
|
}
|
59
|
-
function
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
66
|
+
function createNxJsonFromTurboJson(turboJson) {
|
67
|
+
const nxJson = {
|
68
|
+
$schema: './node_modules/nx/schemas/nx-schema.json',
|
69
|
+
};
|
70
|
+
// Handle global dependencies
|
71
|
+
if (turboJson.globalDependencies?.length > 0) {
|
72
|
+
nxJson.namedInputs = {
|
73
|
+
sharedGlobals: turboJson.globalDependencies.map((dep) => `{workspaceRoot}/${dep}`),
|
74
|
+
default: ['{projectRoot}/**/*', 'sharedGlobals'],
|
75
|
+
};
|
76
|
+
}
|
77
|
+
// Handle global env vars
|
78
|
+
if (turboJson.globalEnv?.length > 0) {
|
79
|
+
nxJson.namedInputs = nxJson.namedInputs || {};
|
80
|
+
nxJson.namedInputs.sharedGlobals = nxJson.namedInputs.sharedGlobals || [];
|
81
|
+
nxJson.namedInputs.sharedGlobals.push(...turboJson.globalEnv.map((env) => ({ env })));
|
82
|
+
nxJson.namedInputs.default = nxJson.namedInputs.default || [];
|
83
|
+
if (!nxJson.namedInputs.default.includes('{projectRoot}/**/*')) {
|
84
|
+
nxJson.namedInputs.default.push('{projectRoot}/**/*');
|
74
85
|
}
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
86
|
+
if (!nxJson.namedInputs.default.includes('sharedGlobals')) {
|
87
|
+
nxJson.namedInputs.default.push('sharedGlobals');
|
88
|
+
}
|
89
|
+
}
|
90
|
+
// Handle task configurations
|
91
|
+
if (turboJson.tasks) {
|
92
|
+
nxJson.targetDefaults = {};
|
93
|
+
for (const [taskName, taskConfig] of Object.entries(turboJson.tasks)) {
|
94
|
+
// Skip project-specific tasks (containing #)
|
95
|
+
if (taskName.includes('#'))
|
96
|
+
continue;
|
97
|
+
const config = taskConfig;
|
98
|
+
nxJson.targetDefaults[taskName] = {};
|
99
|
+
// Handle dependsOn
|
100
|
+
if (config.dependsOn?.length > 0) {
|
101
|
+
nxJson.targetDefaults[taskName].dependsOn = config.dependsOn;
|
82
102
|
}
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
return 'next';
|
90
|
-
}
|
91
|
-
catch {
|
92
|
-
try {
|
93
|
-
(0, child_process_1.execSync)(`git rev-parse --verify master`, {
|
94
|
-
stdio: ['ignore', 'ignore', 'ignore'],
|
95
|
-
windowsHide: false,
|
96
|
-
});
|
97
|
-
return 'master';
|
103
|
+
// Handle inputs
|
104
|
+
if (config.inputs?.length > 0) {
|
105
|
+
nxJson.targetDefaults[taskName].inputs = config.inputs
|
106
|
+
.map((input) => {
|
107
|
+
if (input === '$TURBO_DEFAULT$') {
|
108
|
+
return '{projectRoot}/**/*';
|
98
109
|
}
|
99
|
-
|
100
|
-
|
110
|
+
// Don't add projectRoot if it's already there or if it's an env var
|
111
|
+
if (input.startsWith('{projectRoot}/') ||
|
112
|
+
input.startsWith('{env.') ||
|
113
|
+
input.startsWith('$'))
|
114
|
+
return input;
|
115
|
+
return `{projectRoot}/${input}`;
|
116
|
+
})
|
117
|
+
.map((input) => {
|
118
|
+
// Don't add projectRoot if it's already there or if it's an env var
|
119
|
+
if (input.startsWith('{projectRoot}/') ||
|
120
|
+
input.startsWith('{env.') ||
|
121
|
+
input.startsWith('$'))
|
122
|
+
return input;
|
123
|
+
return `{projectRoot}/${input}`;
|
124
|
+
});
|
125
|
+
}
|
126
|
+
// Handle outputs
|
127
|
+
if (config.outputs?.length > 0) {
|
128
|
+
nxJson.targetDefaults[taskName].outputs = config.outputs.map((output) => {
|
129
|
+
// Don't add projectRoot if it's already there
|
130
|
+
if (output.startsWith('{projectRoot}/'))
|
131
|
+
return output;
|
132
|
+
// Handle negated patterns by adding projectRoot after the !
|
133
|
+
if (output.startsWith('!')) {
|
134
|
+
return `!{projectRoot}/${output.slice(1)}`;
|
101
135
|
}
|
102
|
-
|
136
|
+
return `{projectRoot}/${output}`;
|
137
|
+
});
|
103
138
|
}
|
139
|
+
// Handle cache setting - true by default in Turbo
|
140
|
+
nxJson.targetDefaults[taskName].cache = config.cache !== false;
|
104
141
|
}
|
105
142
|
}
|
143
|
+
/**
|
144
|
+
* The fact that cacheDir was in use suggests the user had a reason for deviating from the default.
|
145
|
+
* We can't know what that reason was, nor if it would still be applicable in Nx, but we can at least
|
146
|
+
* improve discoverability of the relevant Nx option by explicitly including it with its default value.
|
147
|
+
*/
|
148
|
+
if (turboJson.cacheDir) {
|
149
|
+
nxJson.cacheDirectory = '.nx/cache';
|
150
|
+
}
|
151
|
+
const defaultBase = (0, deduce_default_base_1.deduceDefaultBase)();
|
152
|
+
// Do not add defaultBase if it is inferred to be the Nx default value of main
|
153
|
+
if (defaultBase !== 'main') {
|
154
|
+
nxJson.defaultBase ??= defaultBase;
|
155
|
+
}
|
156
|
+
return nxJson;
|
106
157
|
}
|
107
158
|
function addDepsToPackageJson(repoRoot, additionalPackages) {
|
108
159
|
const path = (0, path_2.joinPathFragments)(repoRoot, `package.json`);
|
@@ -197,14 +248,15 @@ function markPackageJsonAsNxProject(packageJsonPath) {
|
|
197
248
|
json.nx = {};
|
198
249
|
(0, fileutils_1.writeJsonFile)(packageJsonPath, json);
|
199
250
|
}
|
200
|
-
function printFinalMessage({ learnMoreLink, }) {
|
251
|
+
function printFinalMessage({ learnMoreLink, appendLines, }) {
|
201
252
|
const pmc = (0, package_manager_1.getPackageManagerCommand)();
|
202
253
|
output_1.output.success({
|
203
254
|
title: '🎉 Done!',
|
204
255
|
bodyLines: [
|
205
|
-
`- Run "${pmc
|
206
|
-
`- Run "${pmc
|
256
|
+
`- Run "${(0, child_process_2.getRunNxBaseCommand)(pmc)} run-many -t build" to run the build target for every project in the workspace. Run it again to replay the cached computation. https://nx.dev/features/cache-task-results`,
|
257
|
+
`- Run "${(0, child_process_2.getRunNxBaseCommand)(pmc)} graph" to see the graph of projects and tasks in your workspace. https://nx.dev/core-features/explore-graph`,
|
207
258
|
learnMoreLink ? `- Learn more at ${learnMoreLink}.` : undefined,
|
259
|
+
...(appendLines ?? []),
|
208
260
|
].filter(Boolean),
|
209
261
|
});
|
210
262
|
}
|
@@ -217,3 +269,16 @@ function isMonorepo(packageJson) {
|
|
217
269
|
return true;
|
218
270
|
return false;
|
219
271
|
}
|
272
|
+
function isCRA(packageJson) {
|
273
|
+
const combinedDependencies = {
|
274
|
+
...packageJson.dependencies,
|
275
|
+
...packageJson.devDependencies,
|
276
|
+
};
|
277
|
+
return (
|
278
|
+
// Required dependencies for CRA projects
|
279
|
+
combinedDependencies['react'] &&
|
280
|
+
combinedDependencies['react-dom'] &&
|
281
|
+
combinedDependencies['react-scripts'] &&
|
282
|
+
(0, fileutils_1.directoryExists)('src') &&
|
283
|
+
(0, fileutils_1.directoryExists)('public'));
|
284
|
+
}
|
@@ -18,7 +18,7 @@ const utils_1 = require("./implementation/utils");
|
|
18
18
|
async function initHandler(options) {
|
19
19
|
// strip the 'init' command itself so we don't forward it
|
20
20
|
const args = process.argv.slice(3).join(' ');
|
21
|
-
const version = process.env.NX_VERSION ?? ((0, semver_1.prerelease)(versions_1.nxVersion) ?
|
21
|
+
const version = process.env.NX_VERSION ?? ((0, semver_1.prerelease)(versions_1.nxVersion) ? versions_1.nxVersion : 'latest');
|
22
22
|
if (process.env.NX_VERSION) {
|
23
23
|
console.log(`Using version ${process.env.NX_VERSION}`);
|
24
24
|
}
|
@@ -5,6 +5,7 @@ export interface InitArgs {
|
|
5
5
|
useDotNxInstallation?: boolean;
|
6
6
|
integrated?: boolean;
|
7
7
|
verbose?: boolean;
|
8
|
+
force?: boolean;
|
8
9
|
}
|
9
10
|
export declare function initHandler(options: InitArgs): Promise<void>;
|
10
11
|
export declare function detectPlugins(nxJson: NxJsonConfiguration, interactive: boolean, includeAngularCli?: boolean): Promise<{
|
@@ -3,48 +3,30 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.initHandler = initHandler;
|
4
4
|
exports.detectPlugins = detectPlugins;
|
5
5
|
const fs_1 = require("fs");
|
6
|
+
const enquirer_1 = require("enquirer");
|
6
7
|
const semver_1 = require("semver");
|
8
|
+
const nx_json_1 = require("../../config/nx-json");
|
9
|
+
const fileutils_1 = require("../../utils/fileutils");
|
10
|
+
const get_package_name_from_import_path_1 = require("../../utils/get-package-name-from-import-path");
|
7
11
|
const output_1 = require("../../utils/output");
|
8
12
|
const package_manager_1 = require("../../utils/package-manager");
|
9
|
-
const add_nx_scripts_1 = require("./implementation/dot-nx/add-nx-scripts");
|
10
|
-
const child_process_1 = require("../../utils/child-process");
|
11
|
-
const fileutils_1 = require("../../utils/fileutils");
|
12
13
|
const versions_1 = require("../../utils/versions");
|
13
|
-
const utils_1 = require("./implementation/utils");
|
14
|
-
const enquirer_1 = require("enquirer");
|
15
|
-
const angular_1 = require("./implementation/angular");
|
16
14
|
const workspace_context_1 = require("../../utils/workspace-context");
|
17
15
|
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 nx_json_1 = require("../../config/nx-json");
|
21
|
-
const get_package_name_from_import_path_1 = require("../../utils/get-package-name-from-import-path");
|
22
16
|
const configure_plugins_1 = require("./configure-plugins");
|
17
|
+
const add_nx_to_monorepo_1 = require("./implementation/add-nx-to-monorepo");
|
18
|
+
const add_nx_to_npm_repo_1 = require("./implementation/add-nx-to-npm-repo");
|
19
|
+
const add_nx_to_turborepo_1 = require("./implementation/add-nx-to-turborepo");
|
20
|
+
const angular_1 = require("./implementation/angular");
|
21
|
+
const add_nx_scripts_1 = require("./implementation/dot-nx/add-nx-scripts");
|
22
|
+
const utils_1 = require("./implementation/utils");
|
23
|
+
const react_1 = require("./implementation/react");
|
23
24
|
async function initHandler(options) {
|
24
25
|
process.env.NX_RUNNING_NX_INIT = 'true';
|
25
|
-
const version = process.env.NX_VERSION ?? ((0, semver_1.prerelease)(versions_1.nxVersion) ?
|
26
|
+
const version = process.env.NX_VERSION ?? ((0, semver_1.prerelease)(versions_1.nxVersion) ? versions_1.nxVersion : 'latest');
|
26
27
|
if (process.env.NX_VERSION) {
|
27
28
|
output_1.output.log({ title: `Using version ${process.env.NX_VERSION}` });
|
28
29
|
}
|
29
|
-
if (!(0, fs_1.existsSync)('package.json') || options.useDotNxInstallation) {
|
30
|
-
if (process.platform !== 'win32') {
|
31
|
-
console.log('Setting Nx up installation in `.nx`. You can run Nx commands like: `./nx --help`');
|
32
|
-
}
|
33
|
-
else {
|
34
|
-
console.log('Setting Nx up installation in `.nx`. You can run Nx commands like: `./nx.bat --help`');
|
35
|
-
}
|
36
|
-
(0, add_nx_scripts_1.generateDotNxSetup)(version);
|
37
|
-
const nxJson = (0, nx_json_1.readNxJson)(process.cwd());
|
38
|
-
const { plugins } = await detectPlugins(nxJson, options.interactive);
|
39
|
-
plugins.forEach((plugin) => {
|
40
|
-
(0, child_process_1.runNxSync)(`add ${plugin}`, {
|
41
|
-
stdio: 'inherit',
|
42
|
-
});
|
43
|
-
});
|
44
|
-
// invokes the wrapper, thus invoking the initial installation process
|
45
|
-
(0, child_process_1.runNxSync)('--version', { stdio: 'ignore' });
|
46
|
-
return;
|
47
|
-
}
|
48
30
|
// TODO(jack): Remove this Angular logic once `@nx/angular` is compatible with inferred targets.
|
49
31
|
if ((0, fs_1.existsSync)('angular.json')) {
|
50
32
|
await (0, angular_1.addNxToAngularCliRepo)({
|
@@ -56,40 +38,88 @@ async function initHandler(options) {
|
|
56
38
|
});
|
57
39
|
return;
|
58
40
|
}
|
59
|
-
const
|
60
|
-
|
41
|
+
const _isNonJs = !(0, fs_1.existsSync)('package.json') || options.useDotNxInstallation;
|
42
|
+
const packageJson = _isNonJs
|
43
|
+
? null
|
44
|
+
: (0, fileutils_1.readJsonFile)('package.json');
|
45
|
+
const _isTurborepo = (0, fs_1.existsSync)('turbo.json');
|
46
|
+
const _isMonorepo = _isNonJs ? false : (0, utils_1.isMonorepo)(packageJson);
|
47
|
+
const _isCRA = _isNonJs ? false : (0, utils_1.isCRA)(packageJson);
|
48
|
+
/**
|
49
|
+
* Turborepo users must have set up individual scripts already, and we keep the transition as minimal as possible.
|
50
|
+
* We log a message during the conversion process in addNxToTurborepo about how they can learn more about the power
|
51
|
+
* of Nx plugins and how it would allow them to infer all the relevant scripts automatically, including all cache
|
52
|
+
* inputs and outputs.
|
53
|
+
*/
|
54
|
+
if (_isTurborepo) {
|
55
|
+
await (0, add_nx_to_turborepo_1.addNxToTurborepo)({
|
56
|
+
interactive: options.interactive,
|
57
|
+
});
|
58
|
+
(0, utils_1.printFinalMessage)({
|
59
|
+
learnMoreLink: 'https://nx.dev/recipes/adopting-nx/from-turborepo',
|
60
|
+
});
|
61
|
+
return;
|
62
|
+
}
|
63
|
+
const pmc = (0, package_manager_1.getPackageManagerCommand)();
|
64
|
+
if (_isCRA) {
|
65
|
+
await (0, react_1.addNxToCraRepo)({
|
66
|
+
addE2e: false,
|
67
|
+
force: options.force,
|
68
|
+
vite: true,
|
69
|
+
integrated: false,
|
70
|
+
interactive: options.interactive,
|
71
|
+
nxCloud: false,
|
72
|
+
});
|
73
|
+
}
|
74
|
+
else if (_isMonorepo) {
|
61
75
|
await (0, add_nx_to_monorepo_1.addNxToMonorepo)({
|
62
76
|
interactive: options.interactive,
|
63
77
|
nxCloud: false,
|
64
78
|
});
|
65
79
|
}
|
80
|
+
else if (_isNonJs) {
|
81
|
+
(0, add_nx_scripts_1.generateDotNxSetup)(version);
|
82
|
+
console.log('');
|
83
|
+
}
|
66
84
|
else {
|
67
85
|
await (0, add_nx_to_npm_repo_1.addNxToNpmRepo)({
|
68
86
|
interactive: options.interactive,
|
69
87
|
nxCloud: false,
|
70
88
|
});
|
71
89
|
}
|
72
|
-
const learnMoreLink = (0, utils_1.isMonorepo)(packageJson)
|
73
|
-
? 'https://nx.dev/getting-started/tutorials/npm-workspaces-tutorial'
|
74
|
-
: 'https://nx.dev/recipes/adopting-nx/adding-to-existing-project';
|
75
90
|
const useNxCloud = options.nxCloud ??
|
76
91
|
(options.interactive ? await (0, connect_to_nx_cloud_1.connectExistingRepoToNxCloudPrompt)() : false);
|
77
92
|
const repoRoot = process.cwd();
|
78
|
-
const pmc = (0, package_manager_1.getPackageManagerCommand)();
|
79
93
|
(0, utils_1.createNxJsonFile)(repoRoot, [], [], {});
|
80
94
|
(0, utils_1.updateGitIgnore)(repoRoot);
|
81
95
|
const nxJson = (0, nx_json_1.readNxJson)(repoRoot);
|
82
96
|
output_1.output.log({ title: '🧐 Checking dependencies' });
|
83
|
-
|
97
|
+
let plugins;
|
98
|
+
let updatePackageScripts;
|
99
|
+
if (_isCRA) {
|
100
|
+
plugins = ['@nx/vite'];
|
101
|
+
updatePackageScripts = true;
|
102
|
+
}
|
103
|
+
else {
|
104
|
+
const { plugins: _plugins, updatePackageScripts: _updatePackageScripts } = await detectPlugins(nxJson, options.interactive);
|
105
|
+
plugins = _plugins;
|
106
|
+
updatePackageScripts = _updatePackageScripts;
|
107
|
+
}
|
84
108
|
output_1.output.log({ title: '📦 Installing Nx' });
|
85
|
-
(0, configure_plugins_1.
|
109
|
+
(0, configure_plugins_1.installPluginPackages)(repoRoot, pmc, plugins);
|
86
110
|
await (0, configure_plugins_1.configurePlugins)(plugins, updatePackageScripts, pmc, repoRoot, options.verbose);
|
87
111
|
if (useNxCloud) {
|
88
112
|
output_1.output.log({ title: '🛠️ Setting up Nx Cloud' });
|
89
113
|
await (0, utils_1.initCloud)('nx-init');
|
90
114
|
}
|
91
115
|
(0, utils_1.printFinalMessage)({
|
92
|
-
|
116
|
+
appendLines: _isMonorepo
|
117
|
+
? [
|
118
|
+
`- Learn how Nx helps manage your TypeScript monorepo at https://nx.dev/features/maintain-ts-monorepos.`,
|
119
|
+
]
|
120
|
+
: [
|
121
|
+
`- Learn how Nx works with any type of project at https://nx.dev/recipes/adopting-nx/adding-to-existing-project.`,
|
122
|
+
],
|
93
123
|
});
|
94
124
|
}
|
95
125
|
const npmPackageToPluginMap = {
|
@@ -114,6 +144,7 @@ const npmPackageToPluginMap = {
|
|
114
144
|
'react-native': '@nx/react-native',
|
115
145
|
'@remix-run/dev': '@nx/remix',
|
116
146
|
'@rsbuild/core': '@nx/rsbuild',
|
147
|
+
'@react-router/dev': '@nx/react',
|
117
148
|
};
|
118
149
|
async function detectPlugins(nxJson, interactive, includeAngularCli) {
|
119
150
|
let files = ['package.json'].concat((0, workspace_context_1.globWithWorkspaceContextSync)(process.cwd(), ['**/*/package.json']));
|
@@ -0,0 +1,58 @@
|
|
1
|
+
import type { MigrationDetailsWithId } from '../../config/misc-interfaces';
|
2
|
+
import type { FileChange } from '../../generators/tree';
|
3
|
+
export type MigrationsJsonMetadata = {
|
4
|
+
completedMigrations?: Record<string, SuccessfulMigration | FailedMigration | SkippedMigration>;
|
5
|
+
runningMigrations?: string[];
|
6
|
+
initialGitRef?: {
|
7
|
+
ref: string;
|
8
|
+
subject: string;
|
9
|
+
};
|
10
|
+
confirmedPackageUpdates?: boolean;
|
11
|
+
targetVersion?: string;
|
12
|
+
};
|
13
|
+
export type SuccessfulMigration = {
|
14
|
+
type: 'successful';
|
15
|
+
name: string;
|
16
|
+
changedFiles: Omit<FileChange, 'content'>[];
|
17
|
+
ref: string;
|
18
|
+
};
|
19
|
+
export type FailedMigration = {
|
20
|
+
type: 'failed';
|
21
|
+
name: string;
|
22
|
+
error: string;
|
23
|
+
};
|
24
|
+
export type SkippedMigration = {
|
25
|
+
type: 'skipped';
|
26
|
+
};
|
27
|
+
export declare function recordInitialMigrationMetadata(workspacePath: string, versionToMigrateTo: string): void;
|
28
|
+
export declare function finishMigrationProcess(workspacePath: string, squashCommits: boolean, commitMessage: string): void;
|
29
|
+
export declare function runSingleMigration(workspacePath: string, migration: MigrationDetailsWithId, configuration: {
|
30
|
+
createCommits: boolean;
|
31
|
+
commitPrefix?: string;
|
32
|
+
}): Promise<void>;
|
33
|
+
export declare function getImplementationPath(workspacePath: string, migration: MigrationDetailsWithId): Promise<string>;
|
34
|
+
export declare function modifyMigrationsJsonMetadata(workspacePath: string, modify: (migrationsJsonMetadata: MigrationsJsonMetadata) => MigrationsJsonMetadata): void;
|
35
|
+
export declare function addSuccessfulMigration(id: string, fileChanges: Omit<FileChange, 'content'>[], ref: string): (migrationsJsonMetadata: MigrationsJsonMetadata) => MigrationsJsonMetadata;
|
36
|
+
export declare function updateRefForSuccessfulMigration(id: string, ref: string): (migrationsJsonMetadata: MigrationsJsonMetadata) => MigrationsJsonMetadata;
|
37
|
+
export declare function addFailedMigration(id: string, error: string): (migrationsJsonMetadata: MigrationsJsonMetadata) => {
|
38
|
+
completedMigrations?: Record<string, SuccessfulMigration | FailedMigration | SkippedMigration>;
|
39
|
+
runningMigrations?: string[];
|
40
|
+
initialGitRef?: {
|
41
|
+
ref: string;
|
42
|
+
subject: string;
|
43
|
+
};
|
44
|
+
confirmedPackageUpdates?: boolean;
|
45
|
+
targetVersion?: string;
|
46
|
+
};
|
47
|
+
export declare function addSkippedMigration(id: string): (migrationsJsonMetadata: MigrationsJsonMetadata) => {
|
48
|
+
completedMigrations?: Record<string, SuccessfulMigration | FailedMigration | SkippedMigration>;
|
49
|
+
runningMigrations?: string[];
|
50
|
+
initialGitRef?: {
|
51
|
+
ref: string;
|
52
|
+
subject: string;
|
53
|
+
};
|
54
|
+
confirmedPackageUpdates?: boolean;
|
55
|
+
targetVersion?: string;
|
56
|
+
};
|
57
|
+
export declare function readMigrationsJsonMetadata(workspacePath: string): MigrationsJsonMetadata;
|
58
|
+
export declare function undoMigration(workspacePath: string, id: string): (migrationsJsonMetadata: MigrationsJsonMetadata) => MigrationsJsonMetadata;
|