nx 20.5.0-beta.2 → 20.5.0-beta.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 (69) hide show
  1. package/package.json +11 -11
  2. package/schemas/nx-schema.json +36 -2
  3. package/src/adapter/compat.d.ts +1 -1
  4. package/src/adapter/compat.js +1 -0
  5. package/src/command-line/add/add.js +6 -16
  6. package/src/command-line/init/command-object.js +13 -6
  7. package/src/command-line/init/configure-plugins.d.ts +5 -6
  8. package/src/command-line/init/configure-plugins.js +13 -22
  9. package/src/command-line/init/implementation/add-nx-to-turborepo.d.ts +4 -0
  10. package/src/command-line/init/implementation/add-nx-to-turborepo.js +49 -0
  11. package/src/command-line/init/implementation/deduce-default-base.d.ts +1 -0
  12. package/src/command-line/init/implementation/deduce-default-base.js +53 -0
  13. package/src/command-line/init/implementation/utils.d.ts +3 -1
  14. package/src/command-line/init/implementation/utils.js +91 -42
  15. package/src/command-line/init/init-v2.js +34 -14
  16. package/src/command-line/release/changelog.js +3 -5
  17. package/src/command-line/release/command-object.d.ts +1 -0
  18. package/src/command-line/release/command-object.js +5 -0
  19. package/src/command-line/release/config/config.js +6 -0
  20. package/src/command-line/release/utils/git.d.ts +1 -1
  21. package/src/command-line/release/utils/git.js +55 -7
  22. package/src/config/nx-json.d.ts +22 -3
  23. package/src/core/graph/main.js +1 -1
  24. package/src/core/graph/runtime.js +1 -1
  25. package/src/core/graph/styles.css +2 -2
  26. package/src/core/graph/styles.js +1 -1
  27. package/src/daemon/client/client.d.ts +2 -1
  28. package/src/daemon/client/client.js +17 -60
  29. package/src/daemon/client/enabled.d.ts +2 -0
  30. package/src/daemon/client/enabled.js +64 -0
  31. package/src/daemon/message-types/glob.d.ts +7 -0
  32. package/src/daemon/message-types/glob.js +9 -1
  33. package/src/daemon/message-types/hash-glob.d.ts +6 -0
  34. package/src/daemon/message-types/hash-glob.js +9 -1
  35. package/src/daemon/server/handle-glob.d.ts +1 -0
  36. package/src/daemon/server/handle-glob.js +8 -0
  37. package/src/daemon/server/handle-hash-glob.d.ts +1 -0
  38. package/src/daemon/server/handle-hash-glob.js +8 -0
  39. package/src/daemon/server/server.js +7 -0
  40. package/src/devkit-exports.d.ts +1 -1
  41. package/src/devkit-exports.js +2 -2
  42. package/src/devkit-internals.d.ts +1 -1
  43. package/src/devkit-internals.js +2 -1
  44. package/src/native/index.d.ts +9 -1
  45. package/src/native/nx.wasi.cjs +7 -7
  46. package/src/native/nx.wasm32-wasi.wasm +0 -0
  47. package/src/plugins/js/lock-file/lock-file.js +28 -13
  48. package/src/plugins/js/project-graph/affected/lock-file-changes.js +1 -0
  49. package/src/plugins/js/project-graph/build-dependencies/explicit-project-dependencies.js +1 -1
  50. package/src/plugins/js/utils/typescript.js +3 -3
  51. package/src/project-graph/affected/locators/project-glob-changes.js +2 -2
  52. package/src/project-graph/error-types.js +4 -1
  53. package/src/project-graph/plugins/get-plugins.js +2 -1
  54. package/src/project-graph/plugins/isolation/plugin-worker.js +12 -6
  55. package/src/project-graph/plugins/loaded-nx-plugin.d.ts +2 -1
  56. package/src/project-graph/plugins/loaded-nx-plugin.js +3 -2
  57. package/src/project-graph/plugins/tasks-execution-hooks.js +4 -3
  58. package/src/project-graph/plugins/utils.d.ts +2 -2
  59. package/src/project-graph/plugins/utils.js +2 -2
  60. package/src/project-graph/project-graph.js +1 -1
  61. package/src/project-graph/utils/project-configuration-utils.d.ts +1 -1
  62. package/src/project-graph/utils/project-configuration-utils.js +11 -9
  63. package/src/project-graph/utils/retrieve-workspace-files.d.ts +1 -1
  64. package/src/project-graph/utils/retrieve-workspace-files.js +14 -18
  65. package/src/tasks-runner/run-command.js +2 -3
  66. package/src/utils/command-line-utils.d.ts +1 -1
  67. package/src/utils/package-manager.js +2 -2
  68. package/src/utils/workspace-context.d.ts +2 -0
  69. package/src/utils/workspace-context.js +16 -0
@@ -3,23 +3,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.initHandler = initHandler;
4
4
  exports.detectPlugins = detectPlugins;
5
5
  const fs_1 = require("fs");
6
+ const enquirer_1 = require("enquirer");
6
7
  const semver_1 = require("semver");
7
- const output_1 = require("../../utils/output");
8
- const package_manager_1 = require("../../utils/package-manager");
9
- const add_nx_scripts_1 = require("./implementation/dot-nx/add-nx-scripts");
8
+ const nx_json_1 = require("../../config/nx-json");
10
9
  const child_process_1 = require("../../utils/child-process");
11
10
  const fileutils_1 = require("../../utils/fileutils");
11
+ const get_package_name_from_import_path_1 = require("../../utils/get-package-name-from-import-path");
12
+ const output_1 = require("../../utils/output");
13
+ const package_manager_1 = require("../../utils/package-manager");
12
14
  const versions_1 = require("../../utils/versions");
13
- const utils_1 = require("./implementation/utils");
14
- const enquirer_1 = require("enquirer");
15
- const angular_1 = require("./implementation/angular");
16
15
  const workspace_context_1 = require("../../utils/workspace-context");
17
16
  const connect_to_nx_cloud_1 = require("../connect/connect-to-nx-cloud");
18
- const add_nx_to_npm_repo_1 = require("./implementation/add-nx-to-npm-repo");
19
- const add_nx_to_monorepo_1 = require("./implementation/add-nx-to-monorepo");
20
- const nx_json_1 = require("../../config/nx-json");
21
- const get_package_name_from_import_path_1 = require("../../utils/get-package-name-from-import-path");
22
17
  const configure_plugins_1 = require("./configure-plugins");
18
+ const add_nx_to_monorepo_1 = require("./implementation/add-nx-to-monorepo");
19
+ const add_nx_to_npm_repo_1 = require("./implementation/add-nx-to-npm-repo");
20
+ const add_nx_to_turborepo_1 = require("./implementation/add-nx-to-turborepo");
21
+ const angular_1 = require("./implementation/angular");
22
+ const add_nx_scripts_1 = require("./implementation/dot-nx/add-nx-scripts");
23
+ const utils_1 = require("./implementation/utils");
23
24
  async function initHandler(options) {
24
25
  process.env.NX_RUNNING_NX_INIT = 'true';
25
26
  const version = process.env.NX_VERSION ?? ((0, semver_1.prerelease)(versions_1.nxVersion) ? 'next' : 'latest');
@@ -57,7 +58,29 @@ async function initHandler(options) {
57
58
  return;
58
59
  }
59
60
  const packageJson = (0, fileutils_1.readJsonFile)('package.json');
60
- if ((0, utils_1.isMonorepo)(packageJson)) {
61
+ const _isTurborepo = (0, fs_1.existsSync)('turbo.json');
62
+ const _isMonorepo = (0, utils_1.isMonorepo)(packageJson);
63
+ const learnMoreLink = _isTurborepo
64
+ ? 'https://nx.dev/recipes/adopting-nx/from-turborepo'
65
+ : _isMonorepo
66
+ ? 'https://nx.dev/getting-started/tutorials/npm-workspaces-tutorial'
67
+ : 'https://nx.dev/recipes/adopting-nx/adding-to-existing-project';
68
+ /**
69
+ * Turborepo users must have set up individual scripts already, and we keep the transition as minimal as possible.
70
+ * We log a message during the conversion process in addNxToTurborepo about how they can learn more about the power
71
+ * of Nx plugins and how it would allow them to infer all the relevant scripts automatically, including all cache
72
+ * inputs and outputs.
73
+ */
74
+ if (_isTurborepo) {
75
+ await (0, add_nx_to_turborepo_1.addNxToTurborepo)({
76
+ interactive: options.interactive,
77
+ });
78
+ (0, utils_1.printFinalMessage)({
79
+ learnMoreLink,
80
+ });
81
+ return;
82
+ }
83
+ if (_isMonorepo) {
61
84
  await (0, add_nx_to_monorepo_1.addNxToMonorepo)({
62
85
  interactive: options.interactive,
63
86
  nxCloud: false,
@@ -69,9 +92,6 @@ async function initHandler(options) {
69
92
  nxCloud: false,
70
93
  });
71
94
  }
72
- const learnMoreLink = (0, utils_1.isMonorepo)(packageJson)
73
- ? 'https://nx.dev/getting-started/tutorials/npm-workspaces-tutorial'
74
- : 'https://nx.dev/recipes/adopting-nx/adding-to-existing-project';
75
95
  const useNxCloud = options.nxCloud ??
76
96
  (options.interactive ? await (0, connect_to_nx_cloud_1.connectExistingRepoToNxCloudPrompt)() : false);
77
97
  const repoRoot = process.cwd();
@@ -191,8 +191,7 @@ function createAPI(overrideReleaseConfig) {
191
191
  }
192
192
  else {
193
193
  let workspaceChangelogFromRef = args.from ||
194
- (await (0, git_1.getLatestGitTagForPattern)(nxReleaseConfig.releaseTagPattern))
195
- ?.tag;
194
+ (await (0, git_1.getLatestGitTagForPattern)(nxReleaseConfig.releaseTagPattern, {}, nxReleaseConfig.releaseTagPatternCheckAllBranchesWhen))?.tag;
196
195
  if (!workspaceChangelogFromRef) {
197
196
  if (useAutomaticFromRef) {
198
197
  workspaceChangelogFromRef = await (0, git_1.getFirstGitCommit)();
@@ -335,7 +334,7 @@ function createAPI(overrideReleaseConfig) {
335
334
  (await (0, git_1.getLatestGitTagForPattern)(releaseGroup.releaseTagPattern, {
336
335
  projectName: project.name,
337
336
  releaseGroupName: releaseGroup.name,
338
- }))?.tag;
337
+ }, releaseGroup.releaseTagPatternCheckAllBranchesWhen))?.tag;
339
338
  if (!fromRef && useAutomaticFromRef) {
340
339
  const firstCommit = await (0, git_1.getFirstGitCommit)();
341
340
  const allCommits = await getCommits(firstCommit, toSHA);
@@ -442,8 +441,7 @@ function createAPI(overrideReleaseConfig) {
442
441
  }
443
442
  else {
444
443
  let fromRef = args.from ||
445
- (await (0, git_1.getLatestGitTagForPattern)(releaseGroup.releaseTagPattern))
446
- ?.tag;
444
+ (await (0, git_1.getLatestGitTagForPattern)(releaseGroup.releaseTagPattern, {}, releaseGroup.releaseTagPatternCheckAllBranchesWhen))?.tag;
447
445
  if (!fromRef) {
448
446
  if (useAutomaticFromRef) {
449
447
  fromRef = await (0, git_1.getFirstGitCommit)();
@@ -58,6 +58,7 @@ export type PlanCheckOptions = BaseNxReleaseArgs & {
58
58
  export type ReleaseOptions = NxReleaseArgs & FirstReleaseArgs & {
59
59
  specifier?: string;
60
60
  yes?: boolean;
61
+ preid?: VersionOptions['preid'];
61
62
  skipPublish?: boolean;
62
63
  };
63
64
  export type VersionPlanArgs = {
@@ -75,6 +75,11 @@ const releaseCommand = {
75
75
  .positional('specifier', {
76
76
  type: 'string',
77
77
  describe: 'Exact version or semver keyword to apply to the selected release group.',
78
+ })
79
+ .option('preid', {
80
+ type: 'string',
81
+ describe: 'The optional prerelease identifier to apply to the version. This will only be applied in the case that the specifier argument has been set to `prerelease` OR when conventional commits are enabled, in which case it will modify the resolved specifier from conventional commits to be its prerelease equivalent. E.g. minor -> preminor.',
82
+ default: '',
78
83
  })
79
84
  .option('yes', {
80
85
  type: 'boolean',
@@ -177,6 +177,7 @@ async function createNxReleaseConfig(projectGraph, projectFileMap, userConfig =
177
177
  (workspaceProjectsRelationship === 'independent'
178
178
  ? defaultIndependentReleaseTagPattern
179
179
  : defaultFixedReleaseTagPattern),
180
+ releaseTagPatternCheckAllBranchesWhen: userConfig.releaseTagPatternCheckAllBranchesWhen ?? undefined,
180
181
  conventionalCommits: conventional_commits_1.DEFAULT_CONVENTIONAL_COMMITS_CONFIG,
181
182
  versionPlans: (userConfig.versionPlans ||
182
183
  false),
@@ -207,6 +208,7 @@ async function createNxReleaseConfig(projectGraph, projectFileMap, userConfig =
207
208
  groupProjectsRelationship === 'independent'
208
209
  ? defaultIndependentReleaseTagPattern
209
210
  : WORKSPACE_DEFAULTS.releaseTagPattern,
211
+ releaseTagPatternCheckAllBranchesWhen: userConfig.releaseTagPatternCheckAllBranchesWhen ?? undefined,
210
212
  versionPlans: false,
211
213
  };
212
214
  /**
@@ -365,6 +367,9 @@ async function createNxReleaseConfig(projectGraph, projectFileMap, userConfig =
365
367
  (projectsRelationship === 'independent'
366
368
  ? defaultIndependentReleaseTagPattern
367
369
  : userConfig.releaseTagPattern || defaultFixedReleaseTagPattern),
370
+ releaseTagPatternCheckAllBranchesWhen: releaseGroup.releaseTagPatternCheckAllBranchesWhen ??
371
+ userConfig.releaseTagPatternCheckAllBranchesWhen ??
372
+ undefined,
368
373
  versionPlans: releaseGroup.versionPlans ?? rootVersionPlansConfig,
369
374
  };
370
375
  const finalReleaseGroup = deepMergeDefaults([groupDefaults], {
@@ -413,6 +418,7 @@ async function createNxReleaseConfig(projectGraph, projectFileMap, userConfig =
413
418
  nxReleaseConfig: {
414
419
  projectsRelationship: WORKSPACE_DEFAULTS.projectsRelationship,
415
420
  releaseTagPattern: WORKSPACE_DEFAULTS.releaseTagPattern,
421
+ releaseTagPatternCheckAllBranchesWhen: WORKSPACE_DEFAULTS.releaseTagPatternCheckAllBranchesWhen,
416
422
  git: rootGitConfig,
417
423
  version: rootVersionConfig,
418
424
  changelog: rootChangelogConfig,
@@ -22,7 +22,7 @@ export interface GitCommit extends RawGitCommit {
22
22
  affectedFiles: string[];
23
23
  revertedHashes: string[];
24
24
  }
25
- export declare function getLatestGitTagForPattern(releaseTagPattern: string, additionalInterpolationData?: {}): Promise<{
25
+ export declare function getLatestGitTagForPattern(releaseTagPattern: string, additionalInterpolationData?: {}, checkAllBranchesWhen?: boolean | string[]): Promise<{
26
26
  tag: string;
27
27
  extractedVersion: string;
28
28
  } | null>;
@@ -16,6 +16,7 @@ exports.getFirstGitCommit = getFirstGitCommit;
16
16
  * https://github.com/unjs/changelogen
17
17
  */
18
18
  const node_path_1 = require("node:path");
19
+ const minimatch_1 = require("minimatch");
19
20
  const utils_1 = require("../../../tasks-runner/utils");
20
21
  const workspace_root_1 = require("../../../utils/workspace-root");
21
22
  const exec_command_1 = require("./exec-command");
@@ -24,22 +25,69 @@ function escapeRegExp(string) {
24
25
  }
25
26
  // https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
26
27
  const SEMVER_REGEX = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/g;
27
- async function getLatestGitTagForPattern(releaseTagPattern, additionalInterpolationData = {}) {
28
+ async function getLatestGitTagForPattern(releaseTagPattern, additionalInterpolationData = {}, checkAllBranchesWhen) {
29
+ /**
30
+ * By default, we will try and resolve the latest match for the releaseTagPattern from the current branch,
31
+ * falling back to all branches if no match is found on the current branch.
32
+ *
33
+ * - If checkAllBranchesWhen is true it will cause us to ALWAYS check all branches for the latest match.
34
+ * - If checkAllBranchesWhen is explicitly set to false it will cause us to ONLY check the current branch for the latest match.
35
+ * - If checkAllBranchesWhen is an array of strings it will cause us to check all branches WHEN the current branch is one of the strings in the array.
36
+ */
37
+ let alwaysCheckAllBranches = false;
38
+ if (typeof checkAllBranchesWhen !== 'undefined') {
39
+ if (typeof checkAllBranchesWhen === 'boolean') {
40
+ alwaysCheckAllBranches = checkAllBranchesWhen;
41
+ }
42
+ else if (Array.isArray(checkAllBranchesWhen)) {
43
+ /**
44
+ * Get the current git branch and determine whether to check all branches based on the checkAllBranchesWhen parameter
45
+ */
46
+ const currentBranch = await (0, exec_command_1.execCommand)('git', [
47
+ 'rev-parse',
48
+ '--abbrev-ref',
49
+ 'HEAD',
50
+ ]).then((r) => r.trim());
51
+ // Check exact match first
52
+ alwaysCheckAllBranches = checkAllBranchesWhen.includes(currentBranch);
53
+ // Check if any glob pattern matches next
54
+ if (!alwaysCheckAllBranches) {
55
+ alwaysCheckAllBranches = checkAllBranchesWhen.some((pattern) => {
56
+ const r = minimatch_1.minimatch.makeRe(pattern, { dot: true });
57
+ if (!r) {
58
+ return false;
59
+ }
60
+ return r.test(currentBranch);
61
+ });
62
+ }
63
+ }
64
+ }
65
+ const defaultGitArgs = [
66
+ // Apply git config to take version suffixes into account when sorting, e.g. 1.0.0 is newer than 1.0.0-beta.1
67
+ '-c',
68
+ 'versionsort.suffix=-',
69
+ 'tag',
70
+ '--sort',
71
+ '-v:refname',
72
+ ];
28
73
  try {
29
74
  let tags;
30
75
  tags = await (0, exec_command_1.execCommand)('git', [
31
- 'tag',
32
- '--sort',
33
- '-v:refname',
34
- '--merged',
76
+ ...defaultGitArgs,
77
+ ...(alwaysCheckAllBranches ? [] : ['--merged']),
35
78
  ]).then((r) => r
36
79
  .trim()
37
80
  .split('\n')
38
81
  .map((t) => t.trim())
39
82
  .filter(Boolean));
40
- if (!tags.length) {
83
+ if (
84
+ // Do not run this fallback if the user explicitly set checkAllBranchesWhen to false
85
+ checkAllBranchesWhen !== false &&
86
+ !tags.length &&
87
+ // There is no point in running this fallback if we already checked against all branches
88
+ !alwaysCheckAllBranches) {
41
89
  // try again, but include all tags on the repo instead of just --merged ones
42
- tags = await (0, exec_command_1.execCommand)('git', ['tag', '--sort', '-v:refname']).then((r) => r
90
+ tags = await (0, exec_command_1.execCommand)('git', defaultGitArgs).then((r) => r
43
91
  .trim()
44
92
  .split('\n')
45
93
  .map((t) => t.trim())
@@ -1,6 +1,6 @@
1
1
  import type { ChangelogRenderOptions } from '../../release/changelog-renderer';
2
- import { PackageManager } from '../utils/package-manager';
3
- import { InputDefinition, TargetConfiguration, TargetDependencyConfig } from './workspace-json-project-json';
2
+ import type { PackageManager } from '../utils/package-manager';
3
+ import type { InputDefinition, TargetConfiguration, TargetDependencyConfig } from './workspace-json-project-json';
4
4
  export type ImplicitDependencyEntry<T = '*' | string[]> = {
5
5
  [key: string]: T | ImplicitJsonSubsetDependency<T>;
6
6
  };
@@ -215,6 +215,15 @@ export interface NxReleaseConfiguration {
215
215
  * Optionally override the git/release tag pattern to use for this group.
216
216
  */
217
217
  releaseTagPattern?: string;
218
+ /**
219
+ * By default, we will try and resolve the latest match for the releaseTagPattern from the current branch,
220
+ * falling back to all branches if no match is found on the current branch.
221
+ *
222
+ * - Setting this to true will cause us to ALWAYS check all branches for the latest match.
223
+ * - Setting it to false will cause us to ONLY check the current branch for the latest match.
224
+ * - Setting it to an array of strings will cause us to check all branches WHEN the current branch matches one of the strings in the array. Glob patterns are supported.
225
+ */
226
+ releaseTagPatternCheckAllBranchesWhen?: boolean | string[];
218
227
  /**
219
228
  * Enables using version plans as a specifier source for versioning and
220
229
  * to determine changes for changelog generation.
@@ -281,6 +290,15 @@ export interface NxReleaseConfiguration {
281
290
  * The default releaseTagPattern for independent releases at the project level is: "{projectName}@{version}"
282
291
  */
283
292
  releaseTagPattern?: string;
293
+ /**
294
+ * By default, we will try and resolve the latest match for the releaseTagPattern from the current branch,
295
+ * falling back to all branches if no match is found on the current branch.
296
+ *
297
+ * - Setting this to true will cause us to ALWAYS check all branches for the latest match.
298
+ * - Setting it to false will cause us to ONLY check the current branch for the latest match.
299
+ * - Setting it to an array of strings will cause us to check all branches WHEN the current branch matches one of the strings in the array. Glob patterns are supported.
300
+ */
301
+ releaseTagPatternCheckAllBranchesWhen?: boolean | string[];
284
302
  /**
285
303
  * Enable and configure automatic git operations as part of the release
286
304
  */
@@ -321,6 +339,7 @@ export interface NxSyncConfiguration {
321
339
  * @note: when adding properties here add them to `allowedWorkspaceExtensions` in adapter/compat.ts
322
340
  */
323
341
  export interface NxJsonConfiguration<T = '*' | string[]> {
342
+ $schema?: string;
324
343
  /**
325
344
  * Optional (additional) Nx.json configuration file which becomes a base for this one
326
345
  */
@@ -357,7 +376,7 @@ export interface NxJsonConfiguration<T = '*' | string[]> {
357
376
  appsDir?: string;
358
377
  };
359
378
  /**
360
- * @deprecated Custom task runners will no longer be supported in Nx 21. Use Nx Cloud or Nx Powerpack instead.
379
+ * @deprecated Custom task runners will be replaced by a new API starting with Nx 21. More info: https://nx.dev/deprecated/custom-tasks-runner
361
380
  * Available Task Runners for Nx to use
362
381
  */
363
382
  tasksRunnerOptions?: {