@nx/js 17.2.0-beta.0 → 17.2.0-beta.10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/js",
3
- "version": "17.2.0-beta.0",
3
+ "version": "17.2.0-beta.10",
4
4
  "private": false,
5
5
  "description": "The JS plugin for Nx contains executors and generators that provide the best experience for developing JavaScript and TypeScript projects. ",
6
6
  "repository": {
@@ -57,9 +57,9 @@
57
57
  "semver": "7.5.3",
58
58
  "source-map-support": "0.5.19",
59
59
  "tslib": "^2.3.0",
60
- "@nx/devkit": "17.2.0-beta.0",
61
- "@nx/workspace": "17.2.0-beta.0",
62
- "@nrwl/js": "17.2.0-beta.0"
60
+ "@nx/devkit": "17.2.0-beta.10",
61
+ "@nx/workspace": "17.2.0-beta.10",
62
+ "@nrwl/js": "17.2.0-beta.10"
63
63
  },
64
64
  "peerDependencies": {
65
65
  "verdaccio": "^5.0.4"
@@ -27,24 +27,111 @@ async function runExecutor(options, context) {
27
27
  ? `package "${packageName}"`
28
28
  : `package "${packageName}" from project "${context.projectName}"`;
29
29
  if (projectPackageJson.private === true) {
30
- console.warn(`Skipping ${packageTxt}, because it has \`"private": true\` in ${packageJsonPath}`);
30
+ console.warn(`Skipped ${packageTxt}, because it has \`"private": true\` in ${packageJsonPath}`);
31
31
  return {
32
32
  success: true,
33
33
  };
34
34
  }
35
35
  const npmPublishCommandSegments = [`npm publish --json`];
36
+ const npmViewCommandSegments = [
37
+ `npm view ${packageName} versions dist-tags --json`,
38
+ ];
36
39
  if (options.registry) {
37
40
  npmPublishCommandSegments.push(`--registry=${options.registry}`);
41
+ npmViewCommandSegments.push(`--registry=${options.registry}`);
38
42
  }
39
43
  if (options.tag) {
40
44
  npmPublishCommandSegments.push(`--tag=${options.tag}`);
41
45
  }
46
+ if (options.otp) {
47
+ npmPublishCommandSegments.push(`--otp=${options.otp}`);
48
+ }
42
49
  if (options.dryRun) {
43
50
  npmPublishCommandSegments.push(`--dry-run`);
44
51
  }
45
52
  // Resolve values using the `npm config` command so that things like environment variables and `publishConfig`s are accounted for
46
53
  const registry = options.registry ?? (0, child_process_1.execSync)(`npm config get registry`).toString().trim();
47
54
  const tag = options.tag ?? (0, child_process_1.execSync)(`npm config get tag`).toString().trim();
55
+ /**
56
+ * In a dry-run scenario, it is most likely that all commands are being run with dry-run, therefore
57
+ * the most up to date/relevant version might not exist on disk for us to read and make the npm view
58
+ * request with.
59
+ *
60
+ * Therefore, so as to not produce misleading output in dry around dist-tags being altered, we do not
61
+ * perform the npm view step, and just show npm publish's dry-run output.
62
+ */
63
+ if (!options.dryRun) {
64
+ const currentVersion = projectPackageJson.version;
65
+ try {
66
+ const result = (0, child_process_1.execSync)(npmViewCommandSegments.join(' '), {
67
+ env: processEnv(true),
68
+ cwd: packageRoot,
69
+ stdio: ['ignore', 'pipe', 'pipe'],
70
+ });
71
+ const resultJson = JSON.parse(result.toString());
72
+ const distTags = resultJson['dist-tags'] || {};
73
+ if (distTags[tag] === currentVersion) {
74
+ console.warn(`Skipped ${packageTxt} because v${currentVersion} already exists in ${registry} with tag "${tag}"`);
75
+ return {
76
+ success: true,
77
+ };
78
+ }
79
+ if (resultJson.versions.includes(currentVersion)) {
80
+ try {
81
+ if (!options.dryRun) {
82
+ (0, child_process_1.execSync)(`npm dist-tag add ${packageName}@${currentVersion} ${tag} --registry=${registry}`, {
83
+ env: processEnv(true),
84
+ cwd: packageRoot,
85
+ stdio: 'ignore',
86
+ });
87
+ console.log(`Added the dist-tag ${tag} to v${currentVersion} for registry ${registry}.\n`);
88
+ }
89
+ else {
90
+ console.log(`Would add the dist-tag ${tag} to v${currentVersion} for registry ${registry}, but ${chalk.keyword('orange')('[dry-run]')} was set.\n`);
91
+ }
92
+ return {
93
+ success: true,
94
+ };
95
+ }
96
+ catch (err) {
97
+ try {
98
+ const stdoutData = JSON.parse(err.stdout?.toString() || '{}');
99
+ console.error('npm dist-tag add error:');
100
+ if (stdoutData.error.summary) {
101
+ console.error(stdoutData.error.summary);
102
+ }
103
+ if (stdoutData.error.detail) {
104
+ console.error(stdoutData.error.detail);
105
+ }
106
+ if (context.isVerbose) {
107
+ console.error('npm dist-tag add stdout:');
108
+ console.error(JSON.stringify(stdoutData, null, 2));
109
+ }
110
+ return {
111
+ success: false,
112
+ };
113
+ }
114
+ catch (err) {
115
+ console.error('Something unexpected went wrong when processing the npm dist-tag add output\n', err);
116
+ return {
117
+ success: false,
118
+ };
119
+ }
120
+ }
121
+ }
122
+ }
123
+ catch (err) {
124
+ const stdoutData = JSON.parse(err.stdout?.toString() || '{}');
125
+ // If the error is that the package doesn't exist, then we can ignore it because we will be publishing it for the first time in the next step
126
+ if (!(stdoutData.error?.code?.includes('E404') &&
127
+ stdoutData.error?.summary?.includes('no such package available'))) {
128
+ console.error(`Something unexpected went wrong when checking for existing dist-tags.\n`, err);
129
+ return {
130
+ success: false,
131
+ };
132
+ }
133
+ }
134
+ }
48
135
  try {
49
136
  const output = (0, child_process_1.execSync)(npmPublishCommandSegments.join(' '), {
50
137
  maxBuffer: LARGE_BUFFER,
@@ -68,22 +155,7 @@ async function runExecutor(options, context) {
68
155
  }
69
156
  catch (err) {
70
157
  try {
71
- const currentVersion = projectPackageJson.version;
72
158
  const stdoutData = JSON.parse(err.stdout?.toString() || '{}');
73
- if (
74
- // handle npm conflict error
75
- stdoutData.error?.code === 'EPUBLISHCONFLICT' ||
76
- // handle npm conflict error when the package has a scope
77
- (stdoutData.error?.code === 'E403' &&
78
- stdoutData.error?.summary?.includes('You cannot publish over the previously published versions')) ||
79
- // handle verdaccio conflict error
80
- (stdoutData.error?.code === 'E409' &&
81
- stdoutData.error?.summary?.includes('this package is already present'))) {
82
- console.warn(`Skipping ${packageTxt}, as v${currentVersion} has already been published to ${registry} with tag "${tag}"`);
83
- return {
84
- success: true,
85
- };
86
- }
87
159
  console.error('npm publish error:');
88
160
  if (stdoutData.error.summary) {
89
161
  console.error(stdoutData.error.summary);
@@ -100,8 +172,6 @@ async function runExecutor(options, context) {
100
172
  };
101
173
  }
102
174
  catch (err) {
103
- // npm v9 onwards seems to guarantee stdout will be well formed JSON when --json is used, so maybe we need to
104
- // specify that as minimum supported version? (comes with node 18 and 20 by default)
105
175
  console.error('Something unexpected went wrong when processing the npm publish output\n', err);
106
176
  return {
107
177
  success: false,
@@ -2,5 +2,6 @@ export interface PublishExecutorSchema {
2
2
  packageRoot?: string;
3
3
  registry?: string;
4
4
  tag?: string;
5
+ otp?: number;
5
6
  dryRun?: boolean;
6
7
  }
@@ -162,9 +162,6 @@ function addProject(tree, options) {
162
162
  }
163
163
  async function addLint(tree, options) {
164
164
  const { lintProjectGenerator } = (0, devkit_1.ensurePackage)('@nx/eslint', versions_1.nxVersion);
165
- const { mapLintPattern } =
166
- // nx-ignore-next-line
167
- require('@nx/eslint/src/generators/lint-project/lint-project');
168
165
  const projectConfiguration = (0, devkit_1.readProjectConfiguration)(tree, options.name);
169
166
  const task = lintProjectGenerator(tree, {
170
167
  project: options.name,
@@ -174,9 +171,6 @@ async function addLint(tree, options) {
174
171
  (0, devkit_1.joinPathFragments)(options.projectRoot, 'tsconfig.lib.json'),
175
172
  ],
176
173
  unitTestRunner: options.unitTestRunner,
177
- eslintFilePatterns: [
178
- mapLintPattern(options.projectRoot, options.js ? 'js' : 'ts', options.rootProject),
179
- ],
180
174
  setParserOptionsProject: options.setParserOptionsProject,
181
175
  rootProject: options.rootProject,
182
176
  });
@@ -1,4 +1,5 @@
1
1
  import { Tree } from '@nx/devkit';
2
+ import { VersionData } from 'nx/src/command-line/release/version';
2
3
  import { ReleaseVersionGeneratorSchema } from './schema';
3
- export declare function releaseVersionGenerator(tree: Tree, options: ReleaseVersionGeneratorSchema): Promise<void>;
4
+ export declare function releaseVersionGenerator(tree: Tree, options: ReleaseVersionGeneratorSchema): Promise<VersionData>;
4
5
  export default releaseVersionGenerator;
@@ -4,6 +4,7 @@ exports.releaseVersionGenerator = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const chalk = require("chalk");
6
6
  const child_process_1 = require("child_process");
7
+ const config_1 = require("nx/src/command-line/release/config/config");
7
8
  const git_1 = require("nx/src/command-line/release/utils/git");
8
9
  const resolve_semver_specifier_1 = require("nx/src/command-line/release/utils/resolve-semver-specifier");
9
10
  const semver_1 = require("nx/src/command-line/release/utils/semver");
@@ -15,23 +16,28 @@ const semver_2 = require("semver");
15
16
  const resolve_local_package_dependencies_1 = require("./utils/resolve-local-package-dependencies");
16
17
  async function releaseVersionGenerator(tree, options) {
17
18
  try {
19
+ const versionData = {};
18
20
  // If the user provided a specifier, validate that it is valid semver or a relative semver keyword
19
21
  if (options.specifier && !(0, semver_1.isValidSemverSpecifier)(options.specifier)) {
20
22
  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.`);
21
23
  }
22
24
  const projects = options.projects;
25
+ const createResolvePackageRoot = (customPackageRoot) => (projectNode) => {
26
+ // Default to the project root if no custom packageRoot
27
+ if (!customPackageRoot) {
28
+ return projectNode.data.root;
29
+ }
30
+ return (0, utils_1.interpolate)(customPackageRoot, {
31
+ workspaceRoot: '',
32
+ projectRoot: projectNode.data.root,
33
+ projectName: projectNode.name,
34
+ });
35
+ };
36
+ const resolvePackageRoot = createResolvePackageRoot(options.packageRoot);
23
37
  // Resolve any custom package roots for each project upfront as they will need to be reused during dependency resolution
24
38
  const projectNameToPackageRootMap = new Map();
25
39
  for (const project of projects) {
26
- projectNameToPackageRootMap.set(project.name,
27
- // Default to the project root if no custom packageRoot
28
- !options.packageRoot
29
- ? project.data.root
30
- : (0, utils_1.interpolate)(options.packageRoot, {
31
- workspaceRoot: '',
32
- projectRoot: project.data.root,
33
- projectName: project.name,
34
- }));
40
+ projectNameToPackageRootMap.set(project.name, resolvePackageRoot(project));
35
41
  }
36
42
  let currentVersion;
37
43
  // only used for options.currentVersionResolver === 'git-tag', but
@@ -65,8 +71,12 @@ To fix this you will either need to add a package.json file at that location, or
65
71
  (await getNpmRegistry()) ??
66
72
  'https://registry.npmjs.org';
67
73
  const tag = metadata?.tag ?? 'latest';
68
- // If the currentVersionResolver is set to registry, we only want to make the request once for the whole batch of projects
69
- if (!currentVersion) {
74
+ /**
75
+ * 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.
76
+ * For independent projects, we need to make a request for each project individually as they will most likely have different versions.
77
+ */
78
+ if (!currentVersion ||
79
+ options.releaseGroup.projectsRelationship === 'independent') {
70
80
  const spinner = ora(`${Array.from(new Array(projectName.length + 3)).join(' ')}Resolving the current version for tag "${tag}" on ${registry}`);
71
81
  spinner.color =
72
82
  color.spinnerColor;
@@ -96,13 +106,15 @@ To fix this you will either need to add a package.json file at that location, or
96
106
  log(`📄 Resolved the current version as ${currentVersion} from ${packageJsonPath}`);
97
107
  break;
98
108
  case 'git-tag': {
99
- if (!currentVersion) {
109
+ if (!currentVersion ||
110
+ // We always need to independently resolve the current version from git tag per project if the projects are independent
111
+ options.releaseGroup.projectsRelationship === 'independent') {
100
112
  const releaseTagPattern = options.releaseGroup.releaseTagPattern;
101
113
  latestMatchingGitTag = await (0, git_1.getLatestGitTagForPattern)(releaseTagPattern, {
102
114
  projectName: project.name,
103
115
  });
104
116
  if (!latestMatchingGitTag) {
105
- throw new Error(`No git tags matching pattern "${releaseTagPattern}" for project "${project.name}" were found.`);
117
+ 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.`);
106
118
  }
107
119
  currentVersion = latestMatchingGitTag.extractedVersion;
108
120
  log(`📄 Resolved the current version as ${currentVersion} from git tag "${latestMatchingGitTag.tag}".`);
@@ -118,8 +130,19 @@ To fix this you will either need to add a package.json file at that location, or
118
130
  if (options.specifier) {
119
131
  log(`📄 Using the provided version specifier "${options.specifier}".`);
120
132
  }
121
- // if specifier is null, then we determined previously via conventional commits that no changes are necessary
122
- if (specifier === undefined) {
133
+ /**
134
+ * If we are versioning independently then we always need to determine the specifier for each project individually, except
135
+ * for the case where the user has provided an explicit specifier on the command.
136
+ *
137
+ * Otherwise, if versioning the projects together we only need to perform this logic if the specifier is still unset from
138
+ * previous iterations of the loop.
139
+ *
140
+ * NOTE: In the case that we have previously determined via conventional commits that no changes are necessary, the specifier
141
+ * will be explicitly set to `null`, so that is why we only check for `undefined` explicitly here.
142
+ */
143
+ if (specifier === undefined ||
144
+ (options.releaseGroup.projectsRelationship === 'independent' &&
145
+ !options.specifier)) {
123
146
  const specifierSource = options.specifierSource;
124
147
  switch (specifierSource) {
125
148
  case 'conventional-commits':
@@ -131,6 +154,8 @@ To fix this you will either need to add a package.json file at that location, or
131
154
  log(`🚫 No changes were detected using git history and the conventional commits standard.`);
132
155
  break;
133
156
  }
157
+ // TODO: reevaluate this logic/workflow for independent projects
158
+ //
134
159
  // Always assume that if the current version is a prerelease, then the next version should be a prerelease.
135
160
  // Users must manually graduate from a prerelease to a release by providing an explicit specifier.
136
161
  if ((0, semver_2.prerelease)(currentVersion)) {
@@ -141,30 +166,51 @@ To fix this you will either need to add a package.json file at that location, or
141
166
  log(`📄 Resolved the specifier as "${specifier}" using git history and the conventional commits standard.`);
142
167
  }
143
168
  break;
144
- case 'prompt':
145
- specifier = await (0, resolve_semver_specifier_1.resolveSemverSpecifierFromPrompt)(`What kind of change is this for the ${projects.length} matched projects(s) within release group "${options.releaseGroup.name}"?`, `What is the exact version for the ${projects.length} matched project(s) within release group "${options.releaseGroup.name}"?`);
169
+ case 'prompt': {
170
+ // Only add the release group name to the log if it is one set by the user, otherwise it is useless noise
171
+ const maybeLogReleaseGroup = (log) => {
172
+ if (options.releaseGroup.name === config_1.CATCH_ALL_RELEASE_GROUP) {
173
+ return log;
174
+ }
175
+ return `${log} within release group "${options.releaseGroup.name}"`;
176
+ };
177
+ if (options.releaseGroup.projectsRelationship === 'independent') {
178
+ 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}"`)}?`);
179
+ }
180
+ else {
181
+ 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)`)}?`);
182
+ }
146
183
  break;
184
+ }
147
185
  default:
148
186
  throw new Error(`Invalid specifierSource "${specifierSource}" provided. Must be one of "prompt" or "conventional-commits"`);
149
187
  }
150
188
  }
189
+ // Resolve any local package dependencies for this project (before applying the new version or updating the versionData)
190
+ const localPackageDependencies = (0, resolve_local_package_dependencies_1.resolveLocalPackageDependencies)(tree, options.projectGraph, projects, projectNameToPackageRootMap, resolvePackageRoot,
191
+ // 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
192
+ options.releaseGroup.projectsRelationship === 'independent');
193
+ const dependentProjects = Object.values(localPackageDependencies)
194
+ .flat()
195
+ .filter((localPackageDependency) => {
196
+ return localPackageDependency.target === project.name;
197
+ });
198
+ versionData[projectName] = {
199
+ currentVersion,
200
+ dependentProjects,
201
+ newVersion: null, // will stay as null in the final result the case that no changes are detected
202
+ };
151
203
  if (!specifier) {
152
204
  log(`🚫 Skipping versioning "${projectPackageJson.name}" as no changes were detected.`);
153
205
  continue;
154
206
  }
155
- // Resolve any local package dependencies for this project (before applying the new version)
156
- const localPackageDependencies = (0, resolve_local_package_dependencies_1.resolveLocalPackageDependencies)(tree, options.projectGraph, projects, projectNameToPackageRootMap);
157
207
  const newVersion = (0, version_1.deriveNewSemverVersion)(currentVersion, specifier, options.preid);
208
+ versionData[projectName].newVersion = newVersion;
158
209
  (0, devkit_1.writeJson)(tree, packageJsonPath, {
159
210
  ...projectPackageJson,
160
211
  version: newVersion,
161
212
  });
162
213
  log(`✍️ New version ${newVersion} written to ${workspaceRelativePackageJsonPath}`);
163
- const dependentProjects = Object.values(localPackageDependencies)
164
- .flat()
165
- .filter((localPackageDependency) => {
166
- return localPackageDependency.target === project.name;
167
- });
168
214
  if (dependentProjects.length > 0) {
169
215
  log(`✍️ Applying new version ${newVersion} to ${dependentProjects.length} ${dependentProjects.length > 1
170
216
  ? 'packages which depend'
@@ -178,6 +224,13 @@ To fix this you will either need to add a package.json file at that location, or
178
224
  });
179
225
  }
180
226
  }
227
+ /**
228
+ * Ensure that formatting is applied so that version bump diffs are as mimimal as possible
229
+ * within the context of the user's workspace.
230
+ */
231
+ await (0, devkit_1.formatFiles)(tree);
232
+ // Return the version data so that it can be leveraged by the overall version command
233
+ return versionData;
181
234
  }
182
235
  catch (e) {
183
236
  if (process.env.NX_VERBOSE_LOGGING === 'true') {
@@ -2,5 +2,5 @@ import { ProjectGraph, ProjectGraphDependency, ProjectGraphProjectNode, Tree } f
2
2
  interface LocalPackageDependency extends ProjectGraphDependency {
3
3
  dependencyCollection: 'dependencies' | 'devDependencies' | 'optionalDependencies';
4
4
  }
5
- export declare function resolveLocalPackageDependencies(tree: Tree, projectGraph: ProjectGraph, projects: ProjectGraphProjectNode[], projectNameToPackageRootMap: Map<string, string>): Record<string, LocalPackageDependency[]>;
5
+ export declare function resolveLocalPackageDependencies(tree: Tree, projectGraph: ProjectGraph, filteredProjects: ProjectGraphProjectNode[], projectNameToPackageRootMap: Map<string, string>, resolvePackageRoot: (projectNode: ProjectGraphProjectNode) => string, includeAll?: boolean): Record<string, LocalPackageDependency[]>;
6
6
  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)) {
@@ -3,11 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.findNpmDependencies = void 0;
4
4
  const path_1 = require("path");
5
5
  const configuration_1 = require("nx/src/config/configuration");
6
- const task_hasher_1 = require("nx/src/hasher/task-hasher");
7
6
  const devkit_1 = require("@nx/devkit");
8
7
  const fileutils_1 = require("nx/src/utils/fileutils");
9
8
  const project_graph_1 = require("nx/src/config/project-graph");
10
9
  const ts_config_1 = require("./typescript/ts-config");
10
+ const task_hasher_1 = require("nx/src/hasher/task-hasher");
11
11
  /**
12
12
  * Finds all npm dependencies and their expected versions for a given project.
13
13
  */