@nx/js 17.0.4 → 17.0.6
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 +4 -9
- package/babel.js +16 -36
- package/executors.json +1 -1
- package/migrations.json +0 -56
- package/package.json +9 -9
- package/src/executors/node/node.impl.js +1 -1
- package/src/executors/node/schema.json +1 -1
- package/src/executors/release-publish/release-publish.impl.js +32 -135
- package/src/executors/release-publish/schema.d.ts +0 -2
- package/src/executors/release-publish/schema.json +1 -1
- package/src/executors/swc/schema.json +1 -1
- package/src/executors/swc/swc.impl.js +7 -6
- package/src/executors/verdaccio/schema.json +1 -1
- package/src/executors/verdaccio/verdaccio.impl.js +1 -1
- package/src/generators/convert-to-swc/schema.json +1 -1
- package/src/generators/init/init.js +2 -3
- package/src/generators/init/schema.d.ts +0 -1
- package/src/generators/init/schema.json +1 -7
- package/src/generators/library/files/{readme → lib}/README.md +1 -1
- package/src/generators/library/files/lib/tsconfig.lib.json__tmpl__ +1 -5
- package/src/generators/library/library.d.ts +1 -1
- package/src/generators/library/library.js +29 -171
- package/src/generators/library/schema.json +2 -8
- package/src/generators/release-version/release-version.d.ts +1 -2
- package/src/generators/release-version/release-version.js +86 -341
- package/src/generators/release-version/schema.json +4 -26
- package/src/generators/release-version/utils/resolve-local-package-dependencies.d.ts +1 -7
- package/src/generators/release-version/utils/resolve-local-package-dependencies.js +4 -14
- package/src/generators/release-version/utils/resolve-version-spec.js +1 -4
- package/src/generators/setup-build/generator.js +0 -3
- package/src/generators/setup-build/schema.json +1 -1
- package/src/generators/setup-verdaccio/schema.json +1 -1
- package/src/utils/add-local-registry-scripts.js +6 -26
- package/src/utils/assets/copy-assets-handler.js +4 -4
- package/src/utils/buildable-libs-utils.js +2 -6
- package/src/utils/find-npm-dependencies.d.ts +1 -2
- package/src/utils/find-npm-dependencies.js +11 -28
- package/src/utils/inline.js +4 -6
- package/src/utils/minimal-publish-script.d.ts +2 -0
- package/src/utils/minimal-publish-script.js +74 -0
- package/src/utils/schema.d.ts +0 -3
- package/src/utils/swc/get-swcrc-path.d.ts +1 -4
- package/src/utils/swc/get-swcrc-path.js +1 -6
- package/src/utils/swc/inline.d.ts +1 -1
- package/src/utils/swc/inline.js +2 -1
- package/src/utils/typescript/ast-utils.js +3 -2
- package/src/utils/typescript/ts-config.js +0 -1
- package/src/utils/versions.d.ts +4 -4
- package/src/utils/versions.js +4 -4
- package/src/generators/release-version/utils/update-lock-file.d.ts +0 -5
- package/src/generators/release-version/utils/update-lock-file.js +0 -105
- package/src/utils/npm-config.d.ts +0 -25
- package/src/utils/npm-config.js +0 -90
|
@@ -3,367 +3,112 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.releaseVersionGenerator = void 0;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const chalk = require("chalk");
|
|
6
|
-
const
|
|
7
|
-
const node_path_1 = require("node:path");
|
|
8
|
-
const config_1 = require("nx/src/command-line/release/config/config");
|
|
9
|
-
const git_1 = require("nx/src/command-line/release/utils/git");
|
|
10
|
-
const resolve_semver_specifier_1 = require("nx/src/command-line/release/utils/resolve-semver-specifier");
|
|
11
|
-
const semver_1 = require("nx/src/command-line/release/utils/semver");
|
|
6
|
+
const child_process_1 = require("child_process");
|
|
12
7
|
const version_1 = require("nx/src/command-line/release/version");
|
|
13
8
|
const utils_1 = require("nx/src/tasks-runner/utils");
|
|
14
9
|
const ora = require("ora");
|
|
15
|
-
const
|
|
16
|
-
const npm_config_1 = require("../../utils/npm-config");
|
|
10
|
+
const path_1 = require("path");
|
|
17
11
|
const resolve_local_package_dependencies_1 = require("./utils/resolve-local-package-dependencies");
|
|
18
|
-
const update_lock_file_1 = require("./utils/update-lock-file");
|
|
19
12
|
async function releaseVersionGenerator(tree, options) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
projectNameToPackageRootMap.set(project.name, resolvePackageRoot(project));
|
|
48
|
-
}
|
|
49
|
-
let currentVersion = undefined;
|
|
50
|
-
let currentVersionResolvedFromFallback = false;
|
|
51
|
-
// only used for options.currentVersionResolver === 'git-tag', but
|
|
52
|
-
// must be declared here in order to reuse it for additional projects
|
|
53
|
-
let latestMatchingGitTag = undefined;
|
|
54
|
-
// if specifier is undefined, then we haven't resolved it yet
|
|
55
|
-
// if specifier is null, then it has been resolved and no changes are necessary
|
|
56
|
-
let specifier = options.specifier
|
|
57
|
-
? options.specifier
|
|
58
|
-
: undefined;
|
|
59
|
-
for (const project of projects) {
|
|
60
|
-
const projectName = project.name;
|
|
61
|
-
const packageRoot = projectNameToPackageRootMap.get(projectName);
|
|
62
|
-
if (!packageRoot) {
|
|
63
|
-
throw new Error(`The project "${projectName}" does not have a packageRoot available. Please report this issue on https://github.com/nrwl/nx`);
|
|
64
|
-
}
|
|
65
|
-
const packageJsonPath = (0, node_path_1.join)(packageRoot, 'package.json');
|
|
66
|
-
const color = getColor(projectName);
|
|
67
|
-
const log = (msg) => {
|
|
68
|
-
console.log(color.instance.bold(projectName) + ' ' + msg);
|
|
69
|
-
};
|
|
70
|
-
if (!tree.exists(packageJsonPath)) {
|
|
71
|
-
throw new Error(`The project "${projectName}" does not have a package.json available at ${packageJsonPath}.
|
|
72
|
-
|
|
13
|
+
const projects = options.projects;
|
|
14
|
+
// Resolve any custom package roots for each project upfront as they will need to be reused during dependency resolution
|
|
15
|
+
const projectNameToPackageRootMap = new Map();
|
|
16
|
+
for (const project of projects) {
|
|
17
|
+
projectNameToPackageRootMap.set(project.name,
|
|
18
|
+
// Default to the project root if no custom packageRoot
|
|
19
|
+
!options.packageRoot
|
|
20
|
+
? project.data.root
|
|
21
|
+
: (0, utils_1.interpolate)(options.packageRoot, {
|
|
22
|
+
workspaceRoot: '',
|
|
23
|
+
projectRoot: project.data.root,
|
|
24
|
+
projectName: project.name,
|
|
25
|
+
}));
|
|
26
|
+
}
|
|
27
|
+
let currentVersion;
|
|
28
|
+
for (const project of projects) {
|
|
29
|
+
const projectName = project.name;
|
|
30
|
+
const packageRoot = projectNameToPackageRootMap.get(projectName);
|
|
31
|
+
const packageJsonPath = (0, devkit_1.joinPathFragments)(packageRoot, 'package.json');
|
|
32
|
+
const workspaceRelativePackageJsonPath = (0, path_1.relative)(devkit_1.workspaceRoot, packageJsonPath);
|
|
33
|
+
const color = getColor(projectName);
|
|
34
|
+
const log = (msg) => {
|
|
35
|
+
console.log(color.instance.bold(projectName) + ' ' + msg);
|
|
36
|
+
};
|
|
37
|
+
if (!tree.exists(packageJsonPath)) {
|
|
38
|
+
throw new Error(`The project "${projectName}" does not have a package.json available at ${workspaceRelativePackageJsonPath}.
|
|
39
|
+
|
|
73
40
|
To fix this you will either need to add a package.json file at that location, or configure "release" within your nx.json to exclude "${projectName}" from the current release group, or amend the packageRoot configuration to point to where the package.json should be.`);
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}, warnFn);
|
|
96
|
-
/**
|
|
97
|
-
* If the currentVersionResolver is set to registry, and the projects are not independent, we only want to make the request once for the whole batch of projects.
|
|
98
|
-
* For independent projects, we need to make a request for each project individually as they will most likely have different versions.
|
|
99
|
-
*/
|
|
100
|
-
if (!currentVersion ||
|
|
101
|
-
options.releaseGroup.projectsRelationship === 'independent') {
|
|
102
|
-
const spinner = ora(`${Array.from(new Array(projectName.length + 3)).join(' ')}Resolving the current version for tag "${tag}" on ${registry}`);
|
|
103
|
-
spinner.color =
|
|
104
|
-
color.spinnerColor;
|
|
105
|
-
spinner.start();
|
|
106
|
-
try {
|
|
107
|
-
// Must be non-blocking async to allow spinner to render
|
|
108
|
-
currentVersion = await new Promise((resolve, reject) => {
|
|
109
|
-
(0, node_child_process_1.exec)(`npm view ${packageName} version --"${registryConfigKey}=${registry}" --tag=${tag}`, (error, stdout, stderr) => {
|
|
110
|
-
if (error) {
|
|
111
|
-
return reject(error);
|
|
112
|
-
}
|
|
113
|
-
if (stderr) {
|
|
114
|
-
return reject(stderr);
|
|
115
|
-
}
|
|
116
|
-
return resolve(stdout.trim());
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
spinner.stop();
|
|
120
|
-
log(`📄 Resolved the current version as ${currentVersion} for tag "${tag}" from registry ${registry}`);
|
|
121
|
-
}
|
|
122
|
-
catch (e) {
|
|
123
|
-
spinner.stop();
|
|
124
|
-
if (options.fallbackCurrentVersionResolver === 'disk') {
|
|
125
|
-
log(`📄 Unable to resolve the current version from the registry ${registry}. Falling back to the version on disk of ${currentVersionFromDisk}`);
|
|
126
|
-
currentVersion = currentVersionFromDisk;
|
|
127
|
-
currentVersionResolvedFromFallback = true;
|
|
41
|
+
}
|
|
42
|
+
devkit_1.output.logSingleLine(`Running release version for project: ${color.instance.bold(project.name)}`);
|
|
43
|
+
const projectPackageJson = (0, devkit_1.readJson)(tree, packageJsonPath);
|
|
44
|
+
log(`🔍 Reading data for package "${projectPackageJson.name}" from ${workspaceRelativePackageJsonPath}`);
|
|
45
|
+
const { name: packageName, version: currentVersionFromDisk } = projectPackageJson;
|
|
46
|
+
switch (options.currentVersionResolver) {
|
|
47
|
+
case 'registry': {
|
|
48
|
+
const metadata = options.currentVersionResolverMetadata;
|
|
49
|
+
const registry = metadata?.registry ?? 'https://registry.npmjs.org';
|
|
50
|
+
const tag = metadata?.tag ?? 'latest';
|
|
51
|
+
// If the currentVersionResolver is set to registry, we only want to make the request once for the whole batch of projects
|
|
52
|
+
if (!currentVersion) {
|
|
53
|
+
const spinner = ora(`${Array.from(new Array(projectName.length + 3)).join(' ')}Resolving the current version for tag "${tag}" on ${registry}`);
|
|
54
|
+
spinner.color =
|
|
55
|
+
color.spinnerColor;
|
|
56
|
+
spinner.start();
|
|
57
|
+
// Must be non-blocking async to allow spinner to render
|
|
58
|
+
currentVersion = await new Promise((resolve, reject) => {
|
|
59
|
+
(0, child_process_1.exec)(`npm view ${packageName} version --registry=${registry} --tag=${tag}`, (error, stdout, stderr) => {
|
|
60
|
+
if (error) {
|
|
61
|
+
return reject(error);
|
|
128
62
|
}
|
|
129
|
-
|
|
130
|
-
|
|
63
|
+
if (stderr) {
|
|
64
|
+
return reject(stderr);
|
|
131
65
|
}
|
|
132
|
-
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
if (currentVersionResolvedFromFallback) {
|
|
136
|
-
log(`📄 Using the current version ${currentVersion} already resolved from disk fallback.`);
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
log(`📄 Using the current version ${currentVersion} already resolved from the registry ${registry}`);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
break;
|
|
143
|
-
}
|
|
144
|
-
case 'disk':
|
|
145
|
-
currentVersion = currentVersionFromDisk;
|
|
146
|
-
log(`📄 Resolved the current version as ${currentVersion} from ${packageJsonPath}`);
|
|
147
|
-
break;
|
|
148
|
-
case 'git-tag': {
|
|
149
|
-
if (!currentVersion ||
|
|
150
|
-
// We always need to independently resolve the current version from git tag per project if the projects are independent
|
|
151
|
-
options.releaseGroup.projectsRelationship === 'independent') {
|
|
152
|
-
const releaseTagPattern = options.releaseGroup.releaseTagPattern;
|
|
153
|
-
latestMatchingGitTag = await (0, git_1.getLatestGitTagForPattern)(releaseTagPattern, {
|
|
154
|
-
projectName: project.name,
|
|
66
|
+
return resolve(stdout.trim());
|
|
155
67
|
});
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
currentVersion = currentVersionFromDisk;
|
|
160
|
-
currentVersionResolvedFromFallback = true;
|
|
161
|
-
}
|
|
162
|
-
else {
|
|
163
|
-
throw new Error(`No git tags matching pattern "${releaseTagPattern}" for project "${project.name}" were found. You will need to create an initial matching tag to use as a base for determining the next version. Alternatively, you can use the --first-release option or set "release.version.generatorOptions.fallbackCurrentVersionResolver" to "disk" in order to fallback to the version on disk when no matching git tags are found.`);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
currentVersion = latestMatchingGitTag.extractedVersion;
|
|
168
|
-
log(`📄 Resolved the current version as ${currentVersion} from git tag "${latestMatchingGitTag.tag}".`);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
else {
|
|
172
|
-
if (currentVersionResolvedFromFallback) {
|
|
173
|
-
log(`📄 Using the current version ${currentVersion} already resolved from disk fallback.`);
|
|
174
|
-
}
|
|
175
|
-
else {
|
|
176
|
-
log(
|
|
177
|
-
// In this code path we know that latestMatchingGitTag is defined, because we are not relying on the fallbackCurrentVersionResolver, so we can safely use the non-null assertion operator
|
|
178
|
-
`📄 Using the current version ${currentVersion} already resolved from git tag "${latestMatchingGitTag.tag}".`);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
break;
|
|
182
|
-
}
|
|
183
|
-
default:
|
|
184
|
-
throw new Error(`Invalid value for options.currentVersionResolver: ${options.currentVersionResolver}`);
|
|
185
|
-
}
|
|
186
|
-
if (options.specifier) {
|
|
187
|
-
log(`📄 Using the provided version specifier "${options.specifier}".`);
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* If we are versioning independently then we always need to determine the specifier for each project individually, except
|
|
191
|
-
* for the case where the user has provided an explicit specifier on the command.
|
|
192
|
-
*
|
|
193
|
-
* Otherwise, if versioning the projects together we only need to perform this logic if the specifier is still unset from
|
|
194
|
-
* previous iterations of the loop.
|
|
195
|
-
*
|
|
196
|
-
* NOTE: In the case that we have previously determined via conventional commits that no changes are necessary, the specifier
|
|
197
|
-
* will be explicitly set to `null`, so that is why we only check for `undefined` explicitly here.
|
|
198
|
-
*/
|
|
199
|
-
if (specifier === undefined ||
|
|
200
|
-
(options.releaseGroup.projectsRelationship === 'independent' &&
|
|
201
|
-
!options.specifier)) {
|
|
202
|
-
const specifierSource = options.specifierSource;
|
|
203
|
-
switch (specifierSource) {
|
|
204
|
-
case 'conventional-commits': {
|
|
205
|
-
if (options.currentVersionResolver !== 'git-tag') {
|
|
206
|
-
throw new Error(`Invalid currentVersionResolver "${options.currentVersionResolver}" provided for release group "${options.releaseGroup.name}". Must be "git-tag" when "specifierSource" is "conventional-commits"`);
|
|
207
|
-
}
|
|
208
|
-
const affectedProjects = options.releaseGroup.projectsRelationship === 'independent'
|
|
209
|
-
? [projectName]
|
|
210
|
-
: projects.map((p) => p.name);
|
|
211
|
-
// latestMatchingGitTag will be undefined if the current version was resolved from the disk fallback.
|
|
212
|
-
// In this case, we want to use the first commit as the ref to be consistent with the changelog command.
|
|
213
|
-
const previousVersionRef = latestMatchingGitTag
|
|
214
|
-
? latestMatchingGitTag.tag
|
|
215
|
-
: options.fallbackCurrentVersionResolver === 'disk'
|
|
216
|
-
? await (0, git_1.getFirstGitCommit)()
|
|
217
|
-
: undefined;
|
|
218
|
-
if (!previousVersionRef) {
|
|
219
|
-
// This should never happen since the checks above should catch if the current version couldn't be resolved
|
|
220
|
-
throw new Error(`Unable to determine previous version ref for the projects ${affectedProjects.join(', ')}. This is likely a bug in Nx.`);
|
|
221
|
-
}
|
|
222
|
-
specifier = await (0, resolve_semver_specifier_1.resolveSemverSpecifierFromConventionalCommits)(previousVersionRef, options.projectGraph, affectedProjects, options.conventionalCommitsConfig);
|
|
223
|
-
if (!specifier) {
|
|
224
|
-
log(`🚫 No changes were detected using git history and the conventional commits standard.`);
|
|
225
|
-
break;
|
|
226
|
-
}
|
|
227
|
-
// TODO: reevaluate this logic/workflow for independent projects
|
|
228
|
-
//
|
|
229
|
-
// Always assume that if the current version is a prerelease, then the next version should be a prerelease.
|
|
230
|
-
// Users must manually graduate from a prerelease to a release by providing an explicit specifier.
|
|
231
|
-
if ((0, semver_2.prerelease)(currentVersion ?? '')) {
|
|
232
|
-
specifier = 'prerelease';
|
|
233
|
-
log(`📄 Resolved the specifier as "${specifier}" since the current version is a prerelease.`);
|
|
234
|
-
}
|
|
235
|
-
else {
|
|
236
|
-
log(`📄 Resolved the specifier as "${specifier}" using git history and the conventional commits standard.`);
|
|
237
|
-
}
|
|
238
|
-
break;
|
|
239
|
-
}
|
|
240
|
-
case 'prompt': {
|
|
241
|
-
// Only add the release group name to the log if it is one set by the user, otherwise it is useless noise
|
|
242
|
-
const maybeLogReleaseGroup = (log) => {
|
|
243
|
-
if (options.releaseGroup.name === config_1.IMPLICIT_DEFAULT_RELEASE_GROUP) {
|
|
244
|
-
return log;
|
|
245
|
-
}
|
|
246
|
-
return `${log} within release group "${options.releaseGroup.name}"`;
|
|
247
|
-
};
|
|
248
|
-
if (options.releaseGroup.projectsRelationship === 'independent') {
|
|
249
|
-
specifier = await (0, resolve_semver_specifier_1.resolveSemverSpecifierFromPrompt)(`${maybeLogReleaseGroup(`What kind of change is this for project "${projectName}"`)}?`, `${maybeLogReleaseGroup(`What is the exact version for project "${projectName}"`)}?`);
|
|
250
|
-
}
|
|
251
|
-
else {
|
|
252
|
-
specifier = await (0, resolve_semver_specifier_1.resolveSemverSpecifierFromPrompt)(`${maybeLogReleaseGroup(`What kind of change is this for the ${projects.length} matched projects(s)`)}?`, `${maybeLogReleaseGroup(`What is the exact version for the ${projects.length} matched project(s)`)}?`);
|
|
253
|
-
}
|
|
254
|
-
break;
|
|
255
|
-
}
|
|
256
|
-
default:
|
|
257
|
-
throw new Error(`Invalid specifierSource "${specifierSource}" provided. Must be one of "prompt" or "conventional-commits"`);
|
|
68
|
+
});
|
|
69
|
+
spinner.stop();
|
|
70
|
+
log(`📄 Resolved the current version as ${currentVersion} for tag "${tag}" from registry ${registry}`);
|
|
258
71
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
const localPackageDependencies = (0, resolve_local_package_dependencies_1.resolveLocalPackageDependencies)(tree, options.projectGraph, projects, projectNameToPackageRootMap, resolvePackageRoot,
|
|
262
|
-
// includeAll when the release group is independent, as we may be filtering to a specific subset of projects, but we still want to update their dependents
|
|
263
|
-
options.releaseGroup.projectsRelationship === 'independent');
|
|
264
|
-
const dependentProjects = Object.values(localPackageDependencies)
|
|
265
|
-
.flat()
|
|
266
|
-
.filter((localPackageDependency) => {
|
|
267
|
-
return localPackageDependency.target === project.name;
|
|
268
|
-
});
|
|
269
|
-
if (!currentVersion) {
|
|
270
|
-
throw new Error(`The current version for project "${project.name}" could not be resolved. Please report this on https://github.com/nrwl/nx`);
|
|
271
|
-
}
|
|
272
|
-
versionData[projectName] = {
|
|
273
|
-
currentVersion,
|
|
274
|
-
dependentProjects,
|
|
275
|
-
// @ts-ignore: The types will be updated in a future version of Nx
|
|
276
|
-
newVersion: null, // will stay as null in the final result in the case that no changes are detected
|
|
277
|
-
};
|
|
278
|
-
if (!specifier) {
|
|
279
|
-
log(`🚫 Skipping versioning "${packageJson.name}" as no changes were detected.`);
|
|
280
|
-
continue;
|
|
281
|
-
}
|
|
282
|
-
const newVersion = (0, version_1.deriveNewSemverVersion)(currentVersion, specifier, options.preid);
|
|
283
|
-
versionData[projectName].newVersion = newVersion;
|
|
284
|
-
(0, devkit_1.writeJson)(tree, packageJsonPath, {
|
|
285
|
-
...packageJson,
|
|
286
|
-
version: newVersion,
|
|
287
|
-
});
|
|
288
|
-
log(`✍️ New version ${newVersion} written to ${packageJsonPath}`);
|
|
289
|
-
if (dependentProjects.length > 0) {
|
|
290
|
-
log(`✍️ Applying new version ${newVersion} to ${dependentProjects.length} ${dependentProjects.length > 1
|
|
291
|
-
? 'packages which depend'
|
|
292
|
-
: 'package which depends'} on ${project.name}`);
|
|
293
|
-
}
|
|
294
|
-
for (const dependentProject of dependentProjects) {
|
|
295
|
-
const dependentPackageRoot = projectNameToPackageRootMap.get(dependentProject.source);
|
|
296
|
-
if (!dependentPackageRoot) {
|
|
297
|
-
throw new Error(`The dependent project "${dependentProject.source}" does not have a packageRoot available. Please report this issue on https://github.com/nrwl/nx`);
|
|
72
|
+
else {
|
|
73
|
+
log(`📄 Using the current version ${currentVersion} already resolved from the registry ${registry}`);
|
|
298
74
|
}
|
|
299
|
-
|
|
300
|
-
// Auto (i.e.infer existing) by default
|
|
301
|
-
let versionPrefix = options.versionPrefix ?? 'auto';
|
|
302
|
-
// For auto, we infer the prefix based on the current version of the dependent
|
|
303
|
-
if (versionPrefix === 'auto') {
|
|
304
|
-
versionPrefix = ''; // we don't want to end up printing auto
|
|
305
|
-
const current = json[dependentProject.dependencyCollection][packageName];
|
|
306
|
-
if (current) {
|
|
307
|
-
const prefixMatch = current.match(/^[~^]/);
|
|
308
|
-
if (prefixMatch) {
|
|
309
|
-
versionPrefix = prefixMatch[0];
|
|
310
|
-
}
|
|
311
|
-
else {
|
|
312
|
-
versionPrefix = '';
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
json[dependentProject.dependencyCollection][packageName] = `${versionPrefix}${newVersion}`;
|
|
317
|
-
return json;
|
|
318
|
-
});
|
|
75
|
+
break;
|
|
319
76
|
}
|
|
77
|
+
case 'disk':
|
|
78
|
+
currentVersion = currentVersionFromDisk;
|
|
79
|
+
log(`📄 Resolved the current version as ${currentVersion} from ${packageJsonPath}`);
|
|
80
|
+
break;
|
|
81
|
+
default:
|
|
82
|
+
throw new Error(`Invalid value for options.currentVersionResolver: ${options.currentVersionResolver}`);
|
|
320
83
|
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
devkit_1.output.error({
|
|
339
|
-
title: e.message,
|
|
340
|
-
});
|
|
341
|
-
// Dump the full stack trace in verbose mode
|
|
342
|
-
console.error(e);
|
|
84
|
+
// Resolve any local package dependencies for this project (before applying the new version)
|
|
85
|
+
const localPackageDependencies = (0, resolve_local_package_dependencies_1.resolveLocalPackageDependencies)(tree, options.projectGraph, projects, projectNameToPackageRootMap);
|
|
86
|
+
const newVersion = (0, version_1.deriveNewSemverVersion)(currentVersion, options.specifier, options.preid);
|
|
87
|
+
(0, devkit_1.writeJson)(tree, packageJsonPath, {
|
|
88
|
+
...projectPackageJson,
|
|
89
|
+
version: newVersion,
|
|
90
|
+
});
|
|
91
|
+
log(`✍️ New version ${newVersion} written to ${workspaceRelativePackageJsonPath}`);
|
|
92
|
+
const dependentProjects = Object.values(localPackageDependencies)
|
|
93
|
+
.filter((localPackageDependencies) => {
|
|
94
|
+
return localPackageDependencies.some((localPackageDependency) => localPackageDependency.target === project.name);
|
|
95
|
+
})
|
|
96
|
+
.flat();
|
|
97
|
+
if (dependentProjects.length > 0) {
|
|
98
|
+
log(`✍️ Applying new version ${newVersion} to ${dependentProjects.length} ${dependentProjects.length > 1
|
|
99
|
+
? 'packages which depend'
|
|
100
|
+
: 'package which depends'} on ${project.name}`);
|
|
343
101
|
}
|
|
344
|
-
|
|
345
|
-
devkit_1.
|
|
346
|
-
|
|
102
|
+
for (const dependentProject of dependentProjects) {
|
|
103
|
+
(0, devkit_1.updateJson)(tree, (0, devkit_1.joinPathFragments)(projectNameToPackageRootMap.get(dependentProject.source), 'package.json'), (json) => {
|
|
104
|
+
json[dependentProject.dependencyCollection][packageName] = newVersion;
|
|
105
|
+
return json;
|
|
347
106
|
});
|
|
348
107
|
}
|
|
349
|
-
process.exit(1);
|
|
350
108
|
}
|
|
351
109
|
}
|
|
352
110
|
exports.releaseVersionGenerator = releaseVersionGenerator;
|
|
353
111
|
exports.default = releaseVersionGenerator;
|
|
354
|
-
function createResolvePackageRoot(customPackageRoot) {
|
|
355
|
-
return (projectNode) => {
|
|
356
|
-
// Default to the project root if no custom packageRoot
|
|
357
|
-
if (!customPackageRoot) {
|
|
358
|
-
return projectNode.data.root;
|
|
359
|
-
}
|
|
360
|
-
return (0, utils_1.interpolate)(customPackageRoot, {
|
|
361
|
-
workspaceRoot: '',
|
|
362
|
-
projectRoot: projectNode.data.root,
|
|
363
|
-
projectName: projectNode.name,
|
|
364
|
-
});
|
|
365
|
-
};
|
|
366
|
-
}
|
|
367
112
|
const colors = [
|
|
368
113
|
{ instance: chalk.green, spinnerColor: 'green' },
|
|
369
114
|
{ instance: chalk.greenBright, spinnerColor: 'green' },
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$schema": "
|
|
2
|
+
"$schema": "http://json-schema.org/schema",
|
|
3
3
|
"$id": "NxJSReleaseVersionGenerator",
|
|
4
4
|
"cli": "nx",
|
|
5
5
|
"title": "Implementation details of `nx release version`",
|
|
@@ -19,17 +19,7 @@
|
|
|
19
19
|
},
|
|
20
20
|
"specifier": {
|
|
21
21
|
"type": "string",
|
|
22
|
-
"description": "Exact version or semver keyword to apply to the selected release group.
|
|
23
|
-
},
|
|
24
|
-
"releaseGroup": {
|
|
25
|
-
"type": "object",
|
|
26
|
-
"description": "The resolved release group configuration, including name, relevant to all projects in the current execution."
|
|
27
|
-
},
|
|
28
|
-
"specifierSource": {
|
|
29
|
-
"type": "string",
|
|
30
|
-
"default": "prompt",
|
|
31
|
-
"description": "Which approach to use to determine the semver specifier used to bump the version of the project.",
|
|
32
|
-
"enum": ["prompt", "conventional-commits"]
|
|
22
|
+
"description": "Exact version or semver keyword to apply to the selected release group. NOTE: This should be set on the release group level, not the project level."
|
|
33
23
|
},
|
|
34
24
|
"preid": {
|
|
35
25
|
"type": "string",
|
|
@@ -43,25 +33,13 @@
|
|
|
43
33
|
"type": "string",
|
|
44
34
|
"default": "disk",
|
|
45
35
|
"description": "Which approach to use to determine the current version of the project.",
|
|
46
|
-
"enum": ["registry", "disk"
|
|
36
|
+
"enum": ["registry", "disk"]
|
|
47
37
|
},
|
|
48
38
|
"currentVersionResolverMetadata": {
|
|
49
39
|
"type": "object",
|
|
50
40
|
"description": "Additional metadata to pass to the current version resolver.",
|
|
51
41
|
"default": {}
|
|
52
|
-
},
|
|
53
|
-
"skipLockFileUpdate": {
|
|
54
|
-
"type": "boolean",
|
|
55
|
-
"description": "Whether to skip updating the lock file after updating the version."
|
|
56
|
-
},
|
|
57
|
-
"installArgs": {
|
|
58
|
-
"type": "string",
|
|
59
|
-
"description": "Additional arguments to pass to the package manager when updating the lock file with an install command."
|
|
60
|
-
},
|
|
61
|
-
"installIgnoreScripts": {
|
|
62
|
-
"type": "boolean",
|
|
63
|
-
"description": "Whether to ignore install lifecycle scripts when updating the lock file with an install command."
|
|
64
42
|
}
|
|
65
43
|
},
|
|
66
|
-
"required": ["projects", "projectGraph", "
|
|
44
|
+
"required": ["projects", "projectGraph", "specifier"]
|
|
67
45
|
}
|
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import { ProjectGraph, ProjectGraphDependency, ProjectGraphProjectNode, Tree } from '@nx/devkit';
|
|
2
2
|
interface LocalPackageDependency extends ProjectGraphDependency {
|
|
3
|
-
/**
|
|
4
|
-
* The rawVersionSpec contains the value of the version spec as it was defined in the package.json
|
|
5
|
-
* of the dependent project. This can be useful in cases where the version spec is a range, path or
|
|
6
|
-
* workspace reference, and it needs to be be reverted to that original value as part of the release.
|
|
7
|
-
*/
|
|
8
|
-
rawVersionSpec: string;
|
|
9
3
|
dependencyCollection: 'dependencies' | 'devDependencies' | 'optionalDependencies';
|
|
10
4
|
}
|
|
11
|
-
export declare function resolveLocalPackageDependencies(tree: Tree, projectGraph: ProjectGraph,
|
|
5
|
+
export declare function resolveLocalPackageDependencies(tree: Tree, projectGraph: ProjectGraph, projects: ProjectGraphProjectNode[], projectNameToPackageRootMap: Map<string, string>): Record<string, LocalPackageDependency[]>;
|
|
12
6
|
export {};
|
|
@@ -5,24 +5,15 @@ const devkit_1 = require("@nx/devkit");
|
|
|
5
5
|
const semver_1 = require("semver");
|
|
6
6
|
const package_1 = require("./package");
|
|
7
7
|
const resolve_version_spec_1 = require("./resolve-version-spec");
|
|
8
|
-
function resolveLocalPackageDependencies(tree, projectGraph,
|
|
8
|
+
function resolveLocalPackageDependencies(tree, projectGraph, projects, projectNameToPackageRootMap) {
|
|
9
9
|
const localPackageDependencies = {};
|
|
10
10
|
const projectNodeToPackageMap = new Map();
|
|
11
|
-
const projects = includeAll
|
|
12
|
-
? Object.values(projectGraph.nodes)
|
|
13
|
-
: filteredProjects;
|
|
14
11
|
// Iterate through the projects being released and resolve any relevant package.json data
|
|
15
12
|
for (const projectNode of projects) {
|
|
16
13
|
// Resolve the package.json path for the project, taking into account any custom packageRoot settings
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
packageRoot = resolvePackageRoot(projectNode);
|
|
21
|
-
if (!packageRoot) {
|
|
22
|
-
continue;
|
|
23
|
-
}
|
|
24
|
-
// Append it to the map for later use within the release version generator
|
|
25
|
-
projectNameToPackageRootMap.set(projectNode.name, packageRoot);
|
|
14
|
+
const packageRoot = projectNameToPackageRootMap.get(projectNode.name);
|
|
15
|
+
if (!packageRoot) {
|
|
16
|
+
continue;
|
|
26
17
|
}
|
|
27
18
|
const packageJsonPath = (0, devkit_1.joinPathFragments)(packageRoot, 'package.json');
|
|
28
19
|
if (!tree.exists(packageJsonPath)) {
|
|
@@ -64,7 +55,6 @@ function resolveLocalPackageDependencies(tree, projectGraph, filteredProjects, p
|
|
|
64
55
|
{
|
|
65
56
|
...dep,
|
|
66
57
|
dependencyCollection: sourceNpmDependency.collection,
|
|
67
|
-
rawVersionSpec: sourceNpmDependency.spec,
|
|
68
58
|
},
|
|
69
59
|
];
|
|
70
60
|
}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.resolveVersionSpec = void 0;
|
|
4
4
|
const npa = require("npm-package-arg");
|
|
5
|
-
const devkit_1 = require("@nx/devkit");
|
|
6
5
|
function resolveVersionSpec(name, version, spec, location) {
|
|
7
6
|
// yarn classic uses link instead of file, normalize to match what npm expects
|
|
8
7
|
spec = spec.replace(/^link:/, 'file:');
|
|
@@ -22,8 +21,6 @@ function resolveVersionSpec(name, version, spec, location) {
|
|
|
22
21
|
}
|
|
23
22
|
}
|
|
24
23
|
const npaResult = npa.resolve(name, spec, location);
|
|
25
|
-
return npaResult.fetchSpec
|
|
26
|
-
? (0, devkit_1.normalizePath)(npaResult.fetchSpec)
|
|
27
|
-
: npaResult.fetchSpec;
|
|
24
|
+
return npaResult.fetchSpec;
|
|
28
25
|
}
|
|
29
26
|
exports.resolveVersionSpec = resolveVersionSpec;
|
|
@@ -5,7 +5,6 @@ const devkit_1 = require("@nx/devkit");
|
|
|
5
5
|
const add_swc_config_1 = require("../../utils/swc/add-swc-config");
|
|
6
6
|
const add_swc_dependencies_1 = require("../../utils/swc/add-swc-dependencies");
|
|
7
7
|
const versions_1 = require("../../utils/versions");
|
|
8
|
-
const add_build_target_defaults_1 = require("@nx/devkit/src/generators/add-build-target-defaults");
|
|
9
8
|
async function setupBuildGenerator(tree, options) {
|
|
10
9
|
const tasks = [];
|
|
11
10
|
const project = (0, devkit_1.readProjectConfiguration)(tree, options.project);
|
|
@@ -102,7 +101,6 @@ async function setupBuildGenerator(tree, options) {
|
|
|
102
101
|
break;
|
|
103
102
|
}
|
|
104
103
|
case 'tsc': {
|
|
105
|
-
(0, add_build_target_defaults_1.addBuildTargetDefaults)(tree, '@nx/js:tsc');
|
|
106
104
|
const outputPath = (0, devkit_1.joinPathFragments)('dist', project.root);
|
|
107
105
|
project.targets[buildTarget] = {
|
|
108
106
|
executor: `@nx/js:tsc`,
|
|
@@ -118,7 +116,6 @@ async function setupBuildGenerator(tree, options) {
|
|
|
118
116
|
break;
|
|
119
117
|
}
|
|
120
118
|
case 'swc': {
|
|
121
|
-
(0, add_build_target_defaults_1.addBuildTargetDefaults)(tree, '@nx/js:swc');
|
|
122
119
|
const outputPath = (0, devkit_1.joinPathFragments)('dist', project.root);
|
|
123
120
|
project.targets[buildTarget] = {
|
|
124
121
|
executor: `@nx/js:swc`,
|