@nx/js 17.0.2 → 17.0.4

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.
Files changed (55) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +9 -4
  3. package/babel.js +37 -16
  4. package/executors.json +1 -1
  5. package/migrations.json +62 -0
  6. package/package.json +10 -9
  7. package/src/executors/node/node.impl.js +1 -1
  8. package/src/executors/node/schema.json +1 -1
  9. package/src/executors/release-publish/release-publish.impl.js +135 -32
  10. package/src/executors/release-publish/schema.d.ts +2 -0
  11. package/src/executors/release-publish/schema.json +1 -1
  12. package/src/executors/swc/schema.json +1 -1
  13. package/src/executors/swc/swc.impl.js +6 -7
  14. package/src/executors/verdaccio/schema.json +1 -1
  15. package/src/executors/verdaccio/verdaccio.impl.js +1 -1
  16. package/src/generators/convert-to-swc/schema.json +1 -1
  17. package/src/generators/init/init.js +3 -2
  18. package/src/generators/init/schema.d.ts +1 -0
  19. package/src/generators/init/schema.json +7 -1
  20. package/src/generators/library/files/lib/tsconfig.lib.json__tmpl__ +5 -1
  21. package/src/generators/library/files/{lib → readme}/README.md +1 -1
  22. package/src/generators/library/library.d.ts +1 -1
  23. package/src/generators/library/library.js +173 -29
  24. package/src/generators/library/schema.json +8 -2
  25. package/src/generators/release-version/release-version.d.ts +2 -1
  26. package/src/generators/release-version/release-version.js +341 -86
  27. package/src/generators/release-version/schema.json +26 -4
  28. package/src/generators/release-version/utils/resolve-local-package-dependencies.d.ts +7 -1
  29. package/src/generators/release-version/utils/resolve-local-package-dependencies.js +14 -4
  30. package/src/generators/release-version/utils/resolve-version-spec.js +4 -1
  31. package/src/generators/release-version/utils/update-lock-file.d.ts +5 -0
  32. package/src/generators/release-version/utils/update-lock-file.js +105 -0
  33. package/src/generators/setup-build/generator.js +3 -0
  34. package/src/generators/setup-build/schema.json +1 -1
  35. package/src/generators/setup-verdaccio/schema.json +1 -1
  36. package/src/migrations/update-17-0-0/remove-deprecated-build-options.js +2 -1
  37. package/src/utils/add-local-registry-scripts.js +26 -6
  38. package/src/utils/assets/copy-assets-handler.js +4 -4
  39. package/src/utils/buildable-libs-utils.js +6 -2
  40. package/src/utils/find-npm-dependencies.d.ts +2 -1
  41. package/src/utils/find-npm-dependencies.js +28 -11
  42. package/src/utils/inline.js +6 -4
  43. package/src/utils/npm-config.d.ts +25 -0
  44. package/src/utils/npm-config.js +90 -0
  45. package/src/utils/schema.d.ts +3 -0
  46. package/src/utils/swc/get-swcrc-path.d.ts +4 -1
  47. package/src/utils/swc/get-swcrc-path.js +6 -1
  48. package/src/utils/swc/inline.d.ts +1 -1
  49. package/src/utils/swc/inline.js +1 -2
  50. package/src/utils/typescript/ast-utils.js +2 -3
  51. package/src/utils/typescript/ts-config.js +1 -0
  52. package/src/utils/versions.d.ts +4 -4
  53. package/src/utils/versions.js +4 -4
  54. package/src/utils/minimal-publish-script.d.ts +0 -2
  55. package/src/utils/minimal-publish-script.js +0 -74
@@ -3,112 +3,367 @@ 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 child_process_1 = require("child_process");
6
+ const node_child_process_1 = require("node:child_process");
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");
7
12
  const version_1 = require("nx/src/command-line/release/version");
8
13
  const utils_1 = require("nx/src/tasks-runner/utils");
9
14
  const ora = require("ora");
10
- const path_1 = require("path");
15
+ const semver_2 = require("semver");
16
+ const npm_config_1 = require("../../utils/npm-config");
11
17
  const resolve_local_package_dependencies_1 = require("./utils/resolve-local-package-dependencies");
18
+ const update_lock_file_1 = require("./utils/update-lock-file");
12
19
  async function releaseVersionGenerator(tree, options) {
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
-
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.`);
20
+ try {
21
+ const versionData = {};
22
+ // If the user provided a specifier, validate that it is valid semver or a relative semver keyword
23
+ if (options.specifier) {
24
+ if (!(0, semver_1.isValidSemverSpecifier)(options.specifier)) {
25
+ throw new Error(`The given version specifier "${options.specifier}" is not valid. You provide an exact version or a valid semver keyword such as "major", "minor", "patch", etc.`);
26
+ }
27
+ // The node semver library classes a leading `v` as valid, but we want to ensure it is not present in the final version
28
+ options.specifier = options.specifier.replace(/^v/, '');
41
29
  }
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);
30
+ if (options.versionPrefix &&
31
+ version_1.validReleaseVersionPrefixes.indexOf(options.versionPrefix) === -1) {
32
+ throw new Error(`Invalid value for version.generatorOptions.versionPrefix: "${options.versionPrefix}"
33
+
34
+ Valid values are: ${version_1.validReleaseVersionPrefixes
35
+ .map((s) => `"${s}"`)
36
+ .join(', ')}`);
37
+ }
38
+ if (options.firstRelease) {
39
+ // always use disk as a fallback for the first release
40
+ options.fallbackCurrentVersionResolver = 'disk';
41
+ }
42
+ const projects = options.projects;
43
+ const resolvePackageRoot = createResolvePackageRoot(options.packageRoot);
44
+ // Resolve any custom package roots for each project upfront as they will need to be reused during dependency resolution
45
+ const projectNameToPackageRootMap = new Map();
46
+ for (const project of projects) {
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
+
73
+ 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
+ devkit_1.output.logSingleLine(`Running release version for project: ${color.instance.bold(project.name)}`);
76
+ const packageJson = (0, devkit_1.readJson)(tree, packageJsonPath);
77
+ log(`🔍 Reading data for package "${packageJson.name}" from ${packageJsonPath}`);
78
+ const { name: packageName, version: currentVersionFromDisk } = packageJson;
79
+ switch (options.currentVersionResolver) {
80
+ case 'registry': {
81
+ const metadata = options.currentVersionResolverMetadata;
82
+ const registryArg = typeof metadata?.registry === 'string'
83
+ ? metadata.registry
84
+ : undefined;
85
+ const tagArg = typeof metadata?.tag === 'string' ? metadata.tag : undefined;
86
+ const warnFn = (message) => {
87
+ console.log(chalk.keyword('orange')(message));
88
+ };
89
+ const { registry, tag, registryConfigKey } = await (0, npm_config_1.parseRegistryOptions)(devkit_1.workspaceRoot, {
90
+ packageRoot: (0, node_path_1.join)(devkit_1.workspaceRoot, packageRoot),
91
+ packageJson,
92
+ }, {
93
+ registry: registryArg,
94
+ tag: tagArg,
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;
62
128
  }
63
- if (stderr) {
64
- return reject(stderr);
129
+ else {
130
+ throw new Error(`Unable to resolve the current version from the registry ${registry}. Please ensure that the package exists in the registry in order to use the "registry" currentVersionResolver. 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 the registry lookup fails.`);
65
131
  }
66
- return resolve(stdout.trim());
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,
67
155
  });
68
- });
69
- spinner.stop();
70
- log(`📄 Resolved the current version as ${currentVersion} for tag "${tag}" from registry ${registry}`);
156
+ if (!latestMatchingGitTag) {
157
+ if (options.fallbackCurrentVersionResolver === 'disk') {
158
+ log(`📄 Unable to resolve the current version from git tag using pattern "${releaseTagPattern}". Falling back to the version on disk of ${currentVersionFromDisk}`);
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"`);
71
258
  }
72
- else {
73
- log(`📄 Using the current version ${currentVersion} already resolved from the registry ${registry}`);
259
+ }
260
+ // Resolve any local package dependencies for this project (before applying the new version or updating the versionData)
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`);
74
298
  }
75
- break;
299
+ (0, devkit_1.updateJson)(tree, (0, node_path_1.join)(dependentPackageRoot, 'package.json'), (json) => {
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
+ });
76
319
  }
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}`);
83
320
  }
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}`);
321
+ /**
322
+ * Ensure that formatting is applied so that version bump diffs are as minimal as possible
323
+ * within the context of the user's workspace.
324
+ */
325
+ await (0, devkit_1.formatFiles)(tree);
326
+ // Return the version data so that it can be leveraged by the overall version command
327
+ return {
328
+ data: versionData,
329
+ callback: async (tree, opts) => {
330
+ const cwd = tree.root;
331
+ const updatedFiles = await (0, update_lock_file_1.updateLockFile)(cwd, opts);
332
+ return updatedFiles;
333
+ },
334
+ };
335
+ }
336
+ catch (e) {
337
+ if (process.env.NX_VERBOSE_LOGGING === 'true') {
338
+ devkit_1.output.error({
339
+ title: e.message,
340
+ });
341
+ // Dump the full stack trace in verbose mode
342
+ console.error(e);
101
343
  }
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;
344
+ else {
345
+ devkit_1.output.error({
346
+ title: e.message,
106
347
  });
107
348
  }
349
+ process.exit(1);
108
350
  }
109
351
  }
110
352
  exports.releaseVersionGenerator = releaseVersionGenerator;
111
353
  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
+ }
112
367
  const colors = [
113
368
  { instance: chalk.green, spinnerColor: 'green' },
114
369
  { instance: chalk.greenBright, spinnerColor: 'green' },
@@ -1,5 +1,5 @@
1
1
  {
2
- "$schema": "http://json-schema.org/schema",
2
+ "$schema": "https://json-schema.org/schema",
3
3
  "$id": "NxJSReleaseVersionGenerator",
4
4
  "cli": "nx",
5
5
  "title": "Implementation details of `nx release version`",
@@ -19,7 +19,17 @@
19
19
  },
20
20
  "specifier": {
21
21
  "type": "string",
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."
22
+ "description": "Exact version or semver keyword to apply to the selected release group. Overrides specifierSource."
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"]
23
33
  },
24
34
  "preid": {
25
35
  "type": "string",
@@ -33,13 +43,25 @@
33
43
  "type": "string",
34
44
  "default": "disk",
35
45
  "description": "Which approach to use to determine the current version of the project.",
36
- "enum": ["registry", "disk"]
46
+ "enum": ["registry", "disk", "git-tag"]
37
47
  },
38
48
  "currentVersionResolverMetadata": {
39
49
  "type": "object",
40
50
  "description": "Additional metadata to pass to the current version resolver.",
41
51
  "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."
42
64
  }
43
65
  },
44
- "required": ["projects", "projectGraph", "specifier"]
66
+ "required": ["projects", "projectGraph", "releaseGroup"]
45
67
  }
@@ -1,6 +1,12 @@
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;
3
9
  dependencyCollection: 'dependencies' | 'devDependencies' | 'optionalDependencies';
4
10
  }
5
- export declare function resolveLocalPackageDependencies(tree: Tree, projectGraph: ProjectGraph, projects: ProjectGraphProjectNode[], projectNameToPackageRootMap: Map<string, string>): Record<string, LocalPackageDependency[]>;
11
+ export declare function resolveLocalPackageDependencies(tree: Tree, projectGraph: ProjectGraph, filteredProjects: ProjectGraphProjectNode[], projectNameToPackageRootMap: Map<string, string>, resolvePackageRoot: (projectNode: ProjectGraphProjectNode) => string, includeAll?: boolean): Record<string, LocalPackageDependency[]>;
6
12
  export {};
@@ -5,15 +5,24 @@ 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, projects, projectNameToPackageRootMap) {
8
+ function resolveLocalPackageDependencies(tree, projectGraph, filteredProjects, projectNameToPackageRootMap, resolvePackageRoot, includeAll = false) {
9
9
  const localPackageDependencies = {};
10
10
  const projectNodeToPackageMap = new Map();
11
+ const projects = includeAll
12
+ ? Object.values(projectGraph.nodes)
13
+ : filteredProjects;
11
14
  // Iterate through the projects being released and resolve any relevant package.json data
12
15
  for (const projectNode of projects) {
13
16
  // Resolve the package.json path for the project, taking into account any custom packageRoot settings
14
- const packageRoot = projectNameToPackageRootMap.get(projectNode.name);
15
- if (!packageRoot) {
16
- continue;
17
+ let packageRoot = projectNameToPackageRootMap.get(projectNode.name);
18
+ // packageRoot wasn't added to the map yet, try to resolve it dynamically
19
+ if (!packageRoot && includeAll) {
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);
17
26
  }
18
27
  const packageJsonPath = (0, devkit_1.joinPathFragments)(packageRoot, 'package.json');
19
28
  if (!tree.exists(packageJsonPath)) {
@@ -55,6 +64,7 @@ function resolveLocalPackageDependencies(tree, projectGraph, projects, projectNa
55
64
  {
56
65
  ...dep,
57
66
  dependencyCollection: sourceNpmDependency.collection,
67
+ rawVersionSpec: sourceNpmDependency.spec,
58
68
  },
59
69
  ];
60
70
  }
@@ -2,6 +2,7 @@
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");
5
6
  function resolveVersionSpec(name, version, spec, location) {
6
7
  // yarn classic uses link instead of file, normalize to match what npm expects
7
8
  spec = spec.replace(/^link:/, 'file:');
@@ -21,6 +22,8 @@ function resolveVersionSpec(name, version, spec, location) {
21
22
  }
22
23
  }
23
24
  const npaResult = npa.resolve(name, spec, location);
24
- return npaResult.fetchSpec;
25
+ return npaResult.fetchSpec.includes('\\')
26
+ ? (0, devkit_1.normalizePath)(npaResult.fetchSpec)
27
+ : npaResult.fetchSpec;
25
28
  }
26
29
  exports.resolveVersionSpec = resolveVersionSpec;
@@ -0,0 +1,5 @@
1
+ export declare function updateLockFile(cwd: string, { dryRun, verbose, generatorOptions, }: {
2
+ dryRun?: boolean;
3
+ verbose?: boolean;
4
+ generatorOptions?: Record<string, unknown>;
5
+ }): Promise<string[]>;