nx 21.0.0-beta.1 → 21.0.0-beta.3
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/package.json +12 -12
- package/release/index.d.ts +1 -1
- package/release/index.js +2 -1
- package/schemas/nx-schema.json +186 -35
- 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 +47 -35
- 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 +4 -1
- package/src/command-line/init/implementation/utils.js +108 -44
- 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 +68 -38
- 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 +2 -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 +129 -42
- 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 +251 -0
- package/src/command-line/release/version/release-group-processor.js +1040 -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 +95 -0
- package/src/command-line/release/version/test-utils.js +416 -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 +170 -0
- package/src/command-line/release/version/version-actions.js +183 -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 +80 -262
- 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/run.js +1 -1
- 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/nx-json.d.ts +153 -15
- 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-internals.d.ts +2 -1
- package/src/devkit-internals.js +4 -1
- package/src/executors/run-commands/run-commands.impl.d.ts +3 -5
- package/src/executors/run-commands/run-commands.impl.js +14 -42
- package/src/executors/run-commands/running-tasks.d.ts +7 -5
- package/src/executors/run-commands/running-tasks.js +64 -27
- 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/native/index.d.ts +93 -19
- package/src/native/index.js +16 -2
- package/src/native/native-bindings.js +6 -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/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 +2 -1
- 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 +3 -1
- 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/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/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 +1 -1
- package/src/project-graph/utils/project-configuration-utils.js +25 -11
- 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 +2 -3
- package/src/tasks-runner/cache.d.ts +20 -6
- package/src/tasks-runner/cache.js +104 -20
- package/src/tasks-runner/create-task-graph.d.ts +1 -1
- package/src/tasks-runner/create-task-graph.js +12 -11
- package/src/tasks-runner/default-tasks-runner.js +4 -13
- package/src/tasks-runner/forked-process-task-runner.d.ts +8 -3
- package/src/tasks-runner/forked-process-task-runner.js +56 -46
- package/src/tasks-runner/init-tasks-runner.d.ts +15 -1
- package/src/tasks-runner/init-tasks-runner.js +55 -2
- package/src/tasks-runner/is-tui-enabled.d.ts +2 -0
- package/src/tasks-runner/is-tui-enabled.js +58 -0
- package/src/tasks-runner/life-cycle.d.ts +10 -3
- package/src/tasks-runner/life-cycle.js +23 -2
- package/src/tasks-runner/life-cycles/task-history-life-cycle-old.js +7 -2
- package/src/tasks-runner/life-cycles/task-history-life-cycle.js +6 -1
- package/src/tasks-runner/life-cycles/tui-summary-life-cycle.d.ts +17 -0
- package/src/tasks-runner/life-cycles/tui-summary-life-cycle.js +221 -0
- package/src/tasks-runner/pseudo-terminal.d.ts +10 -7
- package/src/tasks-runner/pseudo-terminal.js +37 -35
- package/src/tasks-runner/run-command.d.ts +1 -0
- package/src/tasks-runner/run-command.js +180 -23
- package/src/tasks-runner/task-env.d.ts +1 -4
- package/src/tasks-runner/task-env.js +2 -0
- package/src/tasks-runner/task-orchestrator.d.ts +21 -9
- package/src/tasks-runner/task-orchestrator.js +127 -44
- package/src/tasks-runner/utils.d.ts +2 -2
- package/src/tasks-runner/utils.js +15 -11
- 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/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-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/utils/powerpack.d.ts +0 -5
- package/src/utils/powerpack.js +0 -33
@@ -0,0 +1,453 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.validReleaseVersionPrefixes = exports.deriveNewSemverVersion = void 0;
|
4
|
+
exports.releaseVersionLegacy = releaseVersionLegacy;
|
5
|
+
const chalk = require("chalk");
|
6
|
+
const node_child_process_1 = require("node:child_process");
|
7
|
+
const node_fs_1 = require("node:fs");
|
8
|
+
const node_path_1 = require("node:path");
|
9
|
+
const tree_1 = require("../../generators/tree");
|
10
|
+
const project_graph_1 = require("../../project-graph/project-graph");
|
11
|
+
const output_1 = require("../../utils/output");
|
12
|
+
const params_1 = require("../../utils/params");
|
13
|
+
const path_1 = require("../../utils/path");
|
14
|
+
const workspace_root_1 = require("../../utils/workspace-root");
|
15
|
+
const generate_1 = require("../generate/generate");
|
16
|
+
const generator_utils_1 = require("../generate/generator-utils");
|
17
|
+
const filter_release_groups_1 = require("./config/filter-release-groups");
|
18
|
+
const version_plans_1 = require("./config/version-plans");
|
19
|
+
const batch_projects_by_generator_config_1 = require("./utils/batch-projects-by-generator-config");
|
20
|
+
const git_1 = require("./utils/git");
|
21
|
+
const print_changes_1 = require("./utils/print-changes");
|
22
|
+
const resolve_nx_json_error_message_1 = require("./utils/resolve-nx-json-error-message");
|
23
|
+
const shared_1 = require("./utils/shared");
|
24
|
+
// Re-export some utils for use in plugin release-version generator implementations
|
25
|
+
var semver_1 = require("./utils/semver");
|
26
|
+
Object.defineProperty(exports, "deriveNewSemverVersion", { enumerable: true, get: function () { return semver_1.deriveNewSemverVersion; } });
|
27
|
+
exports.validReleaseVersionPrefixes = ['auto', '', '~', '^', '='];
|
28
|
+
const LARGE_BUFFER = 1024 * 1000000;
|
29
|
+
async function releaseVersionLegacy(projectGraph, args, nxJson, nxReleaseConfig, userProvidedReleaseConfig) {
|
30
|
+
const { projects } = (0, project_graph_1.readProjectsConfigurationFromProjectGraph)(projectGraph);
|
31
|
+
// The nx release top level command will always override these three git args. This is how we can tell
|
32
|
+
// if the top level release command was used or if the user is using the changelog subcommand.
|
33
|
+
// If the user explicitly overrides these args, then it doesn't matter if the top level config is set,
|
34
|
+
// as all of the git options would be overridden anyway.
|
35
|
+
if ((args.gitCommit === undefined ||
|
36
|
+
args.gitTag === undefined ||
|
37
|
+
args.stageChanges === undefined) &&
|
38
|
+
userProvidedReleaseConfig.git) {
|
39
|
+
const nxJsonMessage = await (0, resolve_nx_json_error_message_1.resolveNxJsonConfigErrorMessage)([
|
40
|
+
'release',
|
41
|
+
'git',
|
42
|
+
]);
|
43
|
+
output_1.output.error({
|
44
|
+
title: `The "release.git" property in nx.json may not be used with the "nx release version" subcommand or programmatic API. Instead, configure git options for subcommands directly with "release.version.git" and "release.changelog.git".`,
|
45
|
+
bodyLines: [nxJsonMessage],
|
46
|
+
});
|
47
|
+
process.exit(1);
|
48
|
+
}
|
49
|
+
const { error: filterError, filterLog, releaseGroups, releaseGroupToFilteredProjects, } = (0, filter_release_groups_1.filterReleaseGroups)(projectGraph, nxReleaseConfig, args.projects, args.groups);
|
50
|
+
if (filterError) {
|
51
|
+
output_1.output.error(filterError);
|
52
|
+
process.exit(1);
|
53
|
+
}
|
54
|
+
if (filterLog &&
|
55
|
+
process.env.NX_RELEASE_INTERNAL_SUPPRESS_FILTER_LOG !== 'true') {
|
56
|
+
output_1.output.note(filterLog);
|
57
|
+
}
|
58
|
+
if (!args.specifier) {
|
59
|
+
const rawVersionPlans = await (0, version_plans_1.readRawVersionPlans)();
|
60
|
+
await (0, version_plans_1.setResolvedVersionPlansOnGroups)(rawVersionPlans, releaseGroups, Object.keys(projectGraph.nodes), args.verbose);
|
61
|
+
}
|
62
|
+
else {
|
63
|
+
if (args.verbose && releaseGroups.some((g) => !!g.versionPlans)) {
|
64
|
+
console.log(`Skipping version plan discovery as a specifier was provided`);
|
65
|
+
}
|
66
|
+
}
|
67
|
+
if (args.deleteVersionPlans === undefined) {
|
68
|
+
// default to not delete version plans after versioning as they may be needed for changelog generation
|
69
|
+
args.deleteVersionPlans = false;
|
70
|
+
}
|
71
|
+
runPreVersionCommand(nxReleaseConfig.version.preVersionCommand, {
|
72
|
+
dryRun: args.dryRun,
|
73
|
+
verbose: args.verbose,
|
74
|
+
});
|
75
|
+
const tree = new tree_1.FsTree(workspace_root_1.workspaceRoot, args.verbose);
|
76
|
+
const versionData = {};
|
77
|
+
const commitMessage = args.gitCommitMessage || nxReleaseConfig.version.git.commitMessage;
|
78
|
+
const generatorCallbacks = [];
|
79
|
+
/**
|
80
|
+
* additionalChangedFiles are files which need to be updated as a side-effect of versioning (such as package manager lock files),
|
81
|
+
* and need to get staged and committed as part of the existing commit, if applicable.
|
82
|
+
*/
|
83
|
+
const additionalChangedFiles = new Set();
|
84
|
+
const additionalDeletedFiles = new Set();
|
85
|
+
if (args.projects?.length) {
|
86
|
+
/**
|
87
|
+
* Run versioning for all remaining release groups and filtered projects within them
|
88
|
+
*/
|
89
|
+
for (const releaseGroup of releaseGroups) {
|
90
|
+
const releaseGroupName = releaseGroup.name;
|
91
|
+
const releaseGroupProjectNames = Array.from(releaseGroupToFilteredProjects.get(releaseGroup));
|
92
|
+
const projectBatches = (0, batch_projects_by_generator_config_1.batchProjectsByGeneratorConfig)(projectGraph, releaseGroup,
|
93
|
+
// Only batch based on the filtered projects within the release group
|
94
|
+
releaseGroupProjectNames);
|
95
|
+
for (const [generatorConfigString, projectNames,] of projectBatches.entries()) {
|
96
|
+
const [generatorName, generatorOptions] = JSON.parse(generatorConfigString);
|
97
|
+
// Resolve the generator for the batch and run versioning on the projects within the batch
|
98
|
+
const generatorData = resolveGeneratorData({
|
99
|
+
...extractGeneratorCollectionAndName(`batch "${JSON.stringify(projectNames)}" for release-group "${releaseGroupName}"`, generatorName),
|
100
|
+
configGeneratorOptions: generatorOptions,
|
101
|
+
// all project data from the project graph (not to be confused with projectNamesToRunVersionOn)
|
102
|
+
projects,
|
103
|
+
});
|
104
|
+
const generatorCallback = await runVersionOnProjects(projectGraph, nxJson, args, tree, generatorData, args.generatorOptionsOverrides, projectNames, releaseGroup, versionData, nxReleaseConfig.conventionalCommits);
|
105
|
+
// Capture the callback so that we can run it after flushing the changes to disk
|
106
|
+
generatorCallbacks.push(async () => {
|
107
|
+
const result = await generatorCallback(tree, {
|
108
|
+
dryRun: !!args.dryRun,
|
109
|
+
verbose: !!args.verbose,
|
110
|
+
generatorOptions: {
|
111
|
+
...generatorOptions,
|
112
|
+
...args.generatorOptionsOverrides,
|
113
|
+
},
|
114
|
+
});
|
115
|
+
const { changedFiles, deletedFiles } = parseGeneratorCallbackResult(result);
|
116
|
+
changedFiles.forEach((f) => additionalChangedFiles.add(f));
|
117
|
+
deletedFiles.forEach((f) => additionalDeletedFiles.add(f));
|
118
|
+
});
|
119
|
+
}
|
120
|
+
}
|
121
|
+
// Resolve any git tags as early as possible so that we can hard error in case of any duplicates before reaching the actual git command
|
122
|
+
const gitTagValues = args.gitTag ?? nxReleaseConfig.version.git.tag
|
123
|
+
? (0, shared_1.createGitTagValues)(releaseGroups, releaseGroupToFilteredProjects, versionData)
|
124
|
+
: [];
|
125
|
+
(0, shared_1.handleDuplicateGitTags)(gitTagValues);
|
126
|
+
printAndFlushChanges(tree, !!args.dryRun);
|
127
|
+
for (const generatorCallback of generatorCallbacks) {
|
128
|
+
await generatorCallback();
|
129
|
+
}
|
130
|
+
const changedFiles = [
|
131
|
+
...tree.listChanges().map((f) => f.path),
|
132
|
+
...additionalChangedFiles,
|
133
|
+
];
|
134
|
+
// No further actions are necessary in this scenario (e.g. if conventional commits detected no changes)
|
135
|
+
if (!changedFiles.length) {
|
136
|
+
return {
|
137
|
+
// An overall workspace version cannot be relevant when filtering to independent projects
|
138
|
+
workspaceVersion: undefined,
|
139
|
+
projectsVersionData: versionData,
|
140
|
+
};
|
141
|
+
}
|
142
|
+
if (args.gitCommit ?? nxReleaseConfig.version.git.commit) {
|
143
|
+
await (0, shared_1.commitChanges)({
|
144
|
+
changedFiles,
|
145
|
+
deletedFiles: Array.from(additionalDeletedFiles),
|
146
|
+
isDryRun: !!args.dryRun,
|
147
|
+
isVerbose: !!args.verbose,
|
148
|
+
gitCommitMessages: (0, shared_1.createCommitMessageValues)(releaseGroups, releaseGroupToFilteredProjects, versionData, commitMessage),
|
149
|
+
gitCommitArgs: args.gitCommitArgs || nxReleaseConfig.version.git.commitArgs,
|
150
|
+
});
|
151
|
+
}
|
152
|
+
else if (args.stageChanges ?? nxReleaseConfig.version.git.stageChanges) {
|
153
|
+
output_1.output.logSingleLine(`Staging changed files with git`);
|
154
|
+
await (0, git_1.gitAdd)({
|
155
|
+
changedFiles,
|
156
|
+
dryRun: args.dryRun,
|
157
|
+
verbose: args.verbose,
|
158
|
+
});
|
159
|
+
}
|
160
|
+
if (args.gitTag ?? nxReleaseConfig.version.git.tag) {
|
161
|
+
output_1.output.logSingleLine(`Tagging commit with git`);
|
162
|
+
for (const tag of gitTagValues) {
|
163
|
+
await (0, git_1.gitTag)({
|
164
|
+
tag,
|
165
|
+
message: args.gitTagMessage || nxReleaseConfig.version.git.tagMessage,
|
166
|
+
additionalArgs: args.gitTagArgs || nxReleaseConfig.version.git.tagArgs,
|
167
|
+
dryRun: args.dryRun,
|
168
|
+
verbose: args.verbose,
|
169
|
+
});
|
170
|
+
}
|
171
|
+
}
|
172
|
+
if (args.gitPush ?? nxReleaseConfig.version.git.push) {
|
173
|
+
output_1.output.logSingleLine(`Pushing to git remote "${args.gitRemote}"`);
|
174
|
+
await (0, git_1.gitPush)({
|
175
|
+
gitRemote: args.gitRemote,
|
176
|
+
dryRun: args.dryRun,
|
177
|
+
verbose: args.verbose,
|
178
|
+
additionalArgs: args.gitPushArgs || nxReleaseConfig.version.git.pushArgs,
|
179
|
+
});
|
180
|
+
}
|
181
|
+
return {
|
182
|
+
// An overall workspace version cannot be relevant when filtering to independent projects
|
183
|
+
workspaceVersion: undefined,
|
184
|
+
projectsVersionData: versionData,
|
185
|
+
};
|
186
|
+
}
|
187
|
+
/**
|
188
|
+
* Run versioning for all remaining release groups
|
189
|
+
*/
|
190
|
+
for (const releaseGroup of releaseGroups) {
|
191
|
+
const releaseGroupName = releaseGroup.name;
|
192
|
+
runPreVersionCommand(releaseGroup.version.groupPreVersionCommand, {
|
193
|
+
dryRun: args.dryRun,
|
194
|
+
verbose: args.verbose,
|
195
|
+
}, releaseGroup);
|
196
|
+
const projectBatches = (0, batch_projects_by_generator_config_1.batchProjectsByGeneratorConfig)(projectGraph, releaseGroup,
|
197
|
+
// Batch based on all projects within the release group
|
198
|
+
releaseGroup.projects);
|
199
|
+
for (const [generatorConfigString, projectNames,] of projectBatches.entries()) {
|
200
|
+
const [generatorName, generatorOptions] = JSON.parse(generatorConfigString);
|
201
|
+
// Resolve the generator for the batch and run versioning on the projects within the batch
|
202
|
+
const generatorData = resolveGeneratorData({
|
203
|
+
...extractGeneratorCollectionAndName(`batch "${JSON.stringify(projectNames)}" for release-group "${releaseGroupName}"`, generatorName),
|
204
|
+
configGeneratorOptions: generatorOptions,
|
205
|
+
// all project data from the project graph (not to be confused with projectNamesToRunVersionOn)
|
206
|
+
projects,
|
207
|
+
});
|
208
|
+
const generatorCallback = await runVersionOnProjects(projectGraph, nxJson, args, tree, generatorData, args.generatorOptionsOverrides, projectNames, releaseGroup, versionData, nxReleaseConfig.conventionalCommits);
|
209
|
+
// Capture the callback so that we can run it after flushing the changes to disk
|
210
|
+
generatorCallbacks.push(async () => {
|
211
|
+
const result = await generatorCallback(tree, {
|
212
|
+
dryRun: !!args.dryRun,
|
213
|
+
verbose: !!args.verbose,
|
214
|
+
generatorOptions: {
|
215
|
+
...generatorOptions,
|
216
|
+
...args.generatorOptionsOverrides,
|
217
|
+
},
|
218
|
+
});
|
219
|
+
const { changedFiles, deletedFiles } = parseGeneratorCallbackResult(result);
|
220
|
+
changedFiles.forEach((f) => additionalChangedFiles.add(f));
|
221
|
+
deletedFiles.forEach((f) => additionalDeletedFiles.add(f));
|
222
|
+
});
|
223
|
+
}
|
224
|
+
}
|
225
|
+
// Resolve any git tags as early as possible so that we can hard error in case of any duplicates before reaching the actual git command
|
226
|
+
const gitTagValues = args.gitTag ?? nxReleaseConfig.version.git.tag
|
227
|
+
? (0, shared_1.createGitTagValues)(releaseGroups, releaseGroupToFilteredProjects, versionData)
|
228
|
+
: [];
|
229
|
+
(0, shared_1.handleDuplicateGitTags)(gitTagValues);
|
230
|
+
printAndFlushChanges(tree, !!args.dryRun);
|
231
|
+
for (const generatorCallback of generatorCallbacks) {
|
232
|
+
await generatorCallback();
|
233
|
+
}
|
234
|
+
// Only applicable when there is a single release group with a fixed relationship
|
235
|
+
let workspaceVersion = undefined;
|
236
|
+
if (releaseGroups.length === 1) {
|
237
|
+
const releaseGroup = releaseGroups[0];
|
238
|
+
if (releaseGroup.projectsRelationship === 'fixed') {
|
239
|
+
const releaseGroupProjectNames = Array.from(releaseGroupToFilteredProjects.get(releaseGroup));
|
240
|
+
workspaceVersion = versionData[releaseGroupProjectNames[0]].newVersion; // all projects have the same version so we can just grab the first
|
241
|
+
}
|
242
|
+
}
|
243
|
+
const changedFiles = [
|
244
|
+
...tree.listChanges().map((f) => f.path),
|
245
|
+
...additionalChangedFiles,
|
246
|
+
];
|
247
|
+
const deletedFiles = Array.from(additionalDeletedFiles);
|
248
|
+
// No further actions are necessary in this scenario (e.g. if conventional commits detected no changes)
|
249
|
+
if (!changedFiles.length && !deletedFiles.length) {
|
250
|
+
return {
|
251
|
+
workspaceVersion,
|
252
|
+
projectsVersionData: versionData,
|
253
|
+
};
|
254
|
+
}
|
255
|
+
if (args.gitCommit ?? nxReleaseConfig.version.git.commit) {
|
256
|
+
await (0, shared_1.commitChanges)({
|
257
|
+
changedFiles,
|
258
|
+
deletedFiles,
|
259
|
+
isDryRun: !!args.dryRun,
|
260
|
+
isVerbose: !!args.verbose,
|
261
|
+
gitCommitMessages: (0, shared_1.createCommitMessageValues)(releaseGroups, releaseGroupToFilteredProjects, versionData, commitMessage),
|
262
|
+
gitCommitArgs: args.gitCommitArgs || nxReleaseConfig.version.git.commitArgs,
|
263
|
+
});
|
264
|
+
}
|
265
|
+
else if (args.stageChanges ?? nxReleaseConfig.version.git.stageChanges) {
|
266
|
+
output_1.output.logSingleLine(`Staging changed files with git`);
|
267
|
+
await (0, git_1.gitAdd)({
|
268
|
+
changedFiles,
|
269
|
+
deletedFiles,
|
270
|
+
dryRun: args.dryRun,
|
271
|
+
verbose: args.verbose,
|
272
|
+
});
|
273
|
+
}
|
274
|
+
if (args.gitTag ?? nxReleaseConfig.version.git.tag) {
|
275
|
+
output_1.output.logSingleLine(`Tagging commit with git`);
|
276
|
+
for (const tag of gitTagValues) {
|
277
|
+
await (0, git_1.gitTag)({
|
278
|
+
tag,
|
279
|
+
message: args.gitTagMessage || nxReleaseConfig.version.git.tagMessage,
|
280
|
+
additionalArgs: args.gitTagArgs || nxReleaseConfig.version.git.tagArgs,
|
281
|
+
dryRun: args.dryRun,
|
282
|
+
verbose: args.verbose,
|
283
|
+
});
|
284
|
+
}
|
285
|
+
}
|
286
|
+
if (args.gitPush ?? nxReleaseConfig.version.git.push) {
|
287
|
+
output_1.output.logSingleLine(`Pushing to git remote "${args.gitRemote}"`);
|
288
|
+
await (0, git_1.gitPush)({
|
289
|
+
gitRemote: args.gitRemote,
|
290
|
+
dryRun: args.dryRun,
|
291
|
+
verbose: args.verbose,
|
292
|
+
additionalArgs: args.gitPushArgs || nxReleaseConfig.version.git.pushArgs,
|
293
|
+
});
|
294
|
+
}
|
295
|
+
return {
|
296
|
+
workspaceVersion,
|
297
|
+
projectsVersionData: versionData,
|
298
|
+
};
|
299
|
+
}
|
300
|
+
function appendVersionData(existingVersionData, newVersionData) {
|
301
|
+
// Mutate the existing version data
|
302
|
+
for (const [key, value] of Object.entries(newVersionData)) {
|
303
|
+
if (existingVersionData[key]) {
|
304
|
+
throw new Error(`Version data key "${key}" already exists in version data. This is likely a bug, please report your use-case on https://github.com/nrwl/nx`);
|
305
|
+
}
|
306
|
+
existingVersionData[key] = value;
|
307
|
+
}
|
308
|
+
return existingVersionData;
|
309
|
+
}
|
310
|
+
async function runVersionOnProjects(projectGraph, nxJson, args, tree, generatorData, generatorOverrides, projectNames, releaseGroup, versionData, conventionalCommitsConfig) {
|
311
|
+
const generatorOptions = {
|
312
|
+
// Always ensure a string to avoid generator schema validation errors
|
313
|
+
specifier: args.specifier ?? '',
|
314
|
+
preid: args.preid ?? '',
|
315
|
+
...generatorData.configGeneratorOptions,
|
316
|
+
...(generatorOverrides ?? {}),
|
317
|
+
// The following are not overridable by user config
|
318
|
+
projects: projectNames.map((p) => projectGraph.nodes[p]),
|
319
|
+
projectGraph,
|
320
|
+
releaseGroup,
|
321
|
+
firstRelease: args.firstRelease ?? false,
|
322
|
+
conventionalCommitsConfig,
|
323
|
+
deleteVersionPlans: args.deleteVersionPlans,
|
324
|
+
};
|
325
|
+
// Apply generator defaults from schema.json file etc
|
326
|
+
const combinedOpts = await (0, params_1.combineOptionsForGenerator)(generatorOptions, generatorData.collectionName, generatorData.normalizedGeneratorName, (0, project_graph_1.readProjectsConfigurationFromProjectGraph)(projectGraph), nxJson, generatorData.schema, false, null, (0, node_path_1.relative)(process.cwd(), workspace_root_1.workspaceRoot), args.verbose);
|
327
|
+
const releaseVersionGenerator = generatorData.implementationFactory();
|
328
|
+
// We expect all version generator implementations to return a ReleaseVersionGeneratorResult object, rather than a GeneratorCallback
|
329
|
+
const versionResult = (await releaseVersionGenerator(tree, combinedOpts));
|
330
|
+
if (typeof versionResult === 'function') {
|
331
|
+
throw new Error(`The version generator ${generatorData.collectionName}:${generatorData.normalizedGeneratorName} returned a function instead of an expected ReleaseVersionGeneratorResult`);
|
332
|
+
}
|
333
|
+
// Merge the extra version data into the existing
|
334
|
+
appendVersionData(versionData, versionResult.data);
|
335
|
+
return versionResult.callback;
|
336
|
+
}
|
337
|
+
function printAndFlushChanges(tree, isDryRun) {
|
338
|
+
const changes = tree.listChanges();
|
339
|
+
console.log('');
|
340
|
+
// Print the changes
|
341
|
+
changes.forEach((f) => {
|
342
|
+
if (f.type === 'CREATE') {
|
343
|
+
console.error(`${chalk.green('CREATE')} ${f.path}${isDryRun ? chalk.keyword('orange')(' [dry-run]') : ''}`);
|
344
|
+
(0, print_changes_1.printDiff)('', f.content?.toString() || '');
|
345
|
+
}
|
346
|
+
else if (f.type === 'UPDATE') {
|
347
|
+
console.error(`${chalk.white('UPDATE')} ${f.path}${isDryRun ? chalk.keyword('orange')(' [dry-run]') : ''}`);
|
348
|
+
const currentContentsOnDisk = (0, node_fs_1.readFileSync)((0, path_1.joinPathFragments)(tree.root, f.path)).toString();
|
349
|
+
(0, print_changes_1.printDiff)(currentContentsOnDisk, f.content?.toString() || '');
|
350
|
+
}
|
351
|
+
else if (f.type === 'DELETE' && !f.path.includes('.nx')) {
|
352
|
+
throw new Error('Unexpected DELETE change, please report this as an issue');
|
353
|
+
}
|
354
|
+
});
|
355
|
+
if (!isDryRun) {
|
356
|
+
(0, tree_1.flushChanges)(workspace_root_1.workspaceRoot, changes);
|
357
|
+
}
|
358
|
+
}
|
359
|
+
function extractGeneratorCollectionAndName(description, generatorString) {
|
360
|
+
let collectionName;
|
361
|
+
let generatorName;
|
362
|
+
const parsedGeneratorString = (0, generate_1.parseGeneratorString)(generatorString);
|
363
|
+
collectionName = parsedGeneratorString.collection;
|
364
|
+
generatorName = parsedGeneratorString.generator;
|
365
|
+
if (!collectionName || !generatorName) {
|
366
|
+
throw new Error(`Invalid generator string: ${generatorString} used for ${description}. Must be in the format of [collectionName]:[generatorName]`);
|
367
|
+
}
|
368
|
+
return { collectionName, generatorName };
|
369
|
+
}
|
370
|
+
function resolveGeneratorData({ collectionName, generatorName, configGeneratorOptions, projects, }) {
|
371
|
+
try {
|
372
|
+
const { normalizedGeneratorName, schema, implementationFactory } = (0, generator_utils_1.getGeneratorInformation)(collectionName, generatorName, workspace_root_1.workspaceRoot, projects);
|
373
|
+
return {
|
374
|
+
collectionName,
|
375
|
+
generatorName,
|
376
|
+
configGeneratorOptions,
|
377
|
+
normalizedGeneratorName,
|
378
|
+
schema,
|
379
|
+
implementationFactory,
|
380
|
+
};
|
381
|
+
}
|
382
|
+
catch (err) {
|
383
|
+
if (err.message.startsWith('Unable to resolve')) {
|
384
|
+
// See if it is because the plugin is not installed
|
385
|
+
try {
|
386
|
+
require.resolve(collectionName);
|
387
|
+
// is installed
|
388
|
+
throw new Error(`Unable to resolve the generator called "${generatorName}" within the "${collectionName}" package`);
|
389
|
+
}
|
390
|
+
catch {
|
391
|
+
/**
|
392
|
+
* Special messaging for the most common case (especially as the user is unlikely to explicitly have
|
393
|
+
* the @nx/js generator config in their nx.json so we need to be clear about what the problem is)
|
394
|
+
*/
|
395
|
+
if (collectionName === '@nx/js') {
|
396
|
+
throw new Error('The @nx/js plugin is required in order to version your JavaScript packages. Run "nx add @nx/js" to add it to your workspace.');
|
397
|
+
}
|
398
|
+
throw new Error(`Unable to resolve the package ${collectionName} in order to load the generator called ${generatorName}. Is the package installed?`);
|
399
|
+
}
|
400
|
+
}
|
401
|
+
// Unexpected error, rethrow
|
402
|
+
throw err;
|
403
|
+
}
|
404
|
+
}
|
405
|
+
function runPreVersionCommand(preVersionCommand, { dryRun, verbose }, releaseGroup) {
|
406
|
+
if (!preVersionCommand) {
|
407
|
+
return;
|
408
|
+
}
|
409
|
+
output_1.output.logSingleLine(releaseGroup
|
410
|
+
? `Executing release group pre-version command for "${releaseGroup.name}"`
|
411
|
+
: `Executing pre-version command`);
|
412
|
+
if (verbose) {
|
413
|
+
console.log(`Executing the following pre-version command:`);
|
414
|
+
console.log(preVersionCommand);
|
415
|
+
}
|
416
|
+
let env = {
|
417
|
+
...process.env,
|
418
|
+
};
|
419
|
+
if (dryRun) {
|
420
|
+
env.NX_DRY_RUN = 'true';
|
421
|
+
}
|
422
|
+
const stdio = verbose ? 'inherit' : 'pipe';
|
423
|
+
try {
|
424
|
+
(0, node_child_process_1.execSync)(preVersionCommand, {
|
425
|
+
encoding: 'utf-8',
|
426
|
+
maxBuffer: LARGE_BUFFER,
|
427
|
+
stdio,
|
428
|
+
env,
|
429
|
+
windowsHide: false,
|
430
|
+
});
|
431
|
+
}
|
432
|
+
catch (e) {
|
433
|
+
const title = verbose
|
434
|
+
? `The pre-version command failed. See the full output above.`
|
435
|
+
: `The pre-version command failed. Retry with --verbose to see the full output of the pre-version command.`;
|
436
|
+
output_1.output.error({
|
437
|
+
title,
|
438
|
+
bodyLines: [preVersionCommand, e],
|
439
|
+
});
|
440
|
+
process.exit(1);
|
441
|
+
}
|
442
|
+
}
|
443
|
+
function parseGeneratorCallbackResult(result) {
|
444
|
+
if (Array.isArray(result)) {
|
445
|
+
return {
|
446
|
+
changedFiles: result,
|
447
|
+
deletedFiles: [],
|
448
|
+
};
|
449
|
+
}
|
450
|
+
else {
|
451
|
+
return result;
|
452
|
+
}
|
453
|
+
}
|
@@ -1,47 +1,7 @@
|
|
1
1
|
import { NxReleaseConfiguration } from '../../config/nx-json';
|
2
|
-
import { ProjectGraph, ProjectGraphProjectNode } from '../../config/project-graph';
|
3
2
|
import { VersionOptions } from './command-object';
|
4
|
-
import { NxReleaseConfig } from './config/config';
|
5
|
-
import { ReleaseGroupWithName } from './config/filter-release-groups';
|
6
3
|
import { VersionData } from './utils/shared';
|
7
|
-
export { deriveNewSemverVersion } from './utils/semver';
|
8
|
-
export type { ReleaseVersionGeneratorResult, VersionData, } from './utils/shared';
|
9
4
|
export declare const validReleaseVersionPrefixes: readonly ["auto", "", "~", "^", "="];
|
10
|
-
export interface ReleaseVersionGeneratorSchema {
|
11
|
-
projects: ProjectGraphProjectNode[];
|
12
|
-
releaseGroup: ReleaseGroupWithName;
|
13
|
-
projectGraph: ProjectGraph;
|
14
|
-
specifier?: string;
|
15
|
-
specifierSource?: 'prompt' | 'conventional-commits' | 'version-plans';
|
16
|
-
preid?: string;
|
17
|
-
packageRoot?: string;
|
18
|
-
currentVersionResolver?: 'registry' | 'disk' | 'git-tag';
|
19
|
-
currentVersionResolverMetadata?: Record<string, unknown>;
|
20
|
-
fallbackCurrentVersionResolver?: 'disk';
|
21
|
-
firstRelease?: boolean;
|
22
|
-
versionPrefix?: (typeof validReleaseVersionPrefixes)[number];
|
23
|
-
skipLockFileUpdate?: boolean;
|
24
|
-
installArgs?: string;
|
25
|
-
installIgnoreScripts?: boolean;
|
26
|
-
conventionalCommitsConfig?: NxReleaseConfig['conventionalCommits'];
|
27
|
-
deleteVersionPlans?: boolean;
|
28
|
-
/**
|
29
|
-
* 'auto' is the default and will cause dependents to be updated (a patch version bump) when a dependency is versioned.
|
30
|
-
* This is only applicable to independently released projects. 'never' will cause dependents to not be updated.
|
31
|
-
*/
|
32
|
-
updateDependents?: 'auto' | 'never';
|
33
|
-
/**
|
34
|
-
* Whether or not to completely omit project logs when that project has no applicable changes. This can be useful for
|
35
|
-
* large monorepos which have a large number of projects, especially when only a subset are released together.
|
36
|
-
*/
|
37
|
-
logUnchangedProjects?: boolean;
|
38
|
-
/**
|
39
|
-
* Whether or not to keep local dependency protocols (e.g. file:, workspace:) when updating dependencies in
|
40
|
-
* package.json files. This is `false` by default as not all package managers support publishing with these protocols
|
41
|
-
* still present in the package.json.
|
42
|
-
*/
|
43
|
-
preserveLocalDependencyProtocols?: boolean;
|
44
|
-
}
|
45
5
|
export interface NxReleaseVersionResult {
|
46
6
|
/**
|
47
7
|
* In one specific (and very common) case, an overall workspace version is relevant, for example when there is
|