nx 19.6.0-beta.2 → 19.6.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 (38) hide show
  1. package/package.json +12 -12
  2. package/schemas/nx-schema.json +30 -4
  3. package/src/command-line/import/command-object.d.ts +2 -0
  4. package/src/command-line/import/command-object.js +38 -0
  5. package/src/command-line/import/import.d.ts +21 -0
  6. package/src/command-line/import/import.js +173 -0
  7. package/src/command-line/import/utils/merge-remote-source.d.ts +2 -0
  8. package/src/command-line/import/utils/merge-remote-source.js +14 -0
  9. package/src/command-line/import/utils/needs-install.d.ts +3 -0
  10. package/src/command-line/import/utils/needs-install.js +31 -0
  11. package/src/command-line/import/utils/prepare-source-repo.d.ts +2 -0
  12. package/src/command-line/import/utils/prepare-source-repo.js +104 -0
  13. package/src/command-line/init/init-v2.d.ts +7 -0
  14. package/src/command-line/init/init-v2.js +48 -15
  15. package/src/command-line/nx-commands.js +33 -31
  16. package/src/command-line/release/changelog.js +9 -9
  17. package/src/command-line/release/command-object.d.ts +12 -3
  18. package/src/command-line/release/command-object.js +16 -1
  19. package/src/command-line/release/config/config.js +4 -2
  20. package/src/command-line/release/config/filter-release-groups.d.ts +2 -2
  21. package/src/command-line/release/config/filter-release-groups.js +1 -1
  22. package/src/command-line/release/config/version-plans.d.ts +1 -1
  23. package/src/command-line/release/config/version-plans.js +12 -12
  24. package/src/command-line/release/plan-check.d.ts +4 -0
  25. package/src/command-line/release/plan-check.js +225 -0
  26. package/src/command-line/release/plan.js +1 -1
  27. package/src/command-line/release/release.js +3 -3
  28. package/src/command-line/release/version.js +1 -1
  29. package/src/command-line/yargs-utils/shared-options.d.ts +1 -1
  30. package/src/config/nx-json.d.ts +9 -2
  31. package/src/native/nx.wasm32-wasi.wasm +0 -0
  32. package/src/utils/command-line-utils.d.ts +1 -0
  33. package/src/utils/command-line-utils.js +6 -3
  34. package/src/utils/git-utils.d.ts +35 -0
  35. package/src/utils/git-utils.js +111 -0
  36. package/src/utils/package-manager.js +1 -1
  37. package/src/utils/squash.d.ts +1 -0
  38. package/src/utils/squash.js +12 -0
@@ -84,7 +84,7 @@ function createAPI(overrideReleaseConfig) {
84
84
  process.exit(1);
85
85
  }
86
86
  const rawVersionPlans = await (0, version_plans_1.readRawVersionPlans)();
87
- (0, version_plans_1.setVersionPlansOnGroups)(rawVersionPlans, releaseGroups, Object.keys(projectGraph.nodes));
87
+ (0, version_plans_1.setResolvedVersionPlansOnGroups)(rawVersionPlans, releaseGroups, Object.keys(projectGraph.nodes));
88
88
  if (args.deleteVersionPlans === undefined) {
89
89
  // default to not delete version plans after versioning as they may be needed for changelog generation
90
90
  args.deleteVersionPlans = false;
@@ -29,7 +29,7 @@ export declare function withTargetAndConfigurationOption(yargs: Argv, demandOpti
29
29
  export declare function withConfiguration(yargs: Argv): Argv<{
30
30
  configuration: string;
31
31
  }>;
32
- export declare function withVerbose(yargs: Argv): Argv<{
32
+ export declare function withVerbose<T>(yargs: Argv<T>): Argv<T & {
33
33
  verbose: boolean;
34
34
  }>;
35
35
  export declare function withBatch(yargs: Argv): any;
@@ -145,6 +145,13 @@ export interface NxReleaseConventionalCommitsConfiguration {
145
145
  } | boolean;
146
146
  } | boolean>;
147
147
  }
148
+ export interface NxReleaseVersionPlansConfiguration {
149
+ /**
150
+ * Changes to files matching any of these optional patterns will be excluded from the affected project logic within the `nx release plan:check`
151
+ * command. This is useful for ignoring files that are not relevant to the versioning process, such as documentation or configuration files.
152
+ */
153
+ ignorePatternsForPlanCheck?: string[];
154
+ }
148
155
  export interface NxReleaseConfiguration {
149
156
  /**
150
157
  * Shorthand for amending the projects which will be included in the implicit default release group (all projects by default).
@@ -193,7 +200,7 @@ export interface NxReleaseConfiguration {
193
200
  * Enables using version plans as a specifier source for versioning and
194
201
  * to determine changes for changelog generation.
195
202
  */
196
- versionPlans?: boolean;
203
+ versionPlans?: NxReleaseVersionPlansConfiguration | boolean;
197
204
  }>;
198
205
  /**
199
206
  * Configures the default value for all groups that don't explicitly state their own projectsRelationship.
@@ -264,7 +271,7 @@ export interface NxReleaseConfiguration {
264
271
  * Enables using version plans as a specifier source for versioning and
265
272
  * to determine changes for changelog generation.
266
273
  */
267
- versionPlans?: boolean;
274
+ versionPlans?: NxReleaseVersionPlansConfiguration | boolean;
268
275
  }
269
276
  export interface NxSyncConfiguration {
270
277
  /**
Binary file
@@ -32,6 +32,7 @@ export interface NxArgs {
32
32
  excludeTaskDependencies?: boolean;
33
33
  }
34
34
  export declare function createOverrides(__overrides_unparsed__?: string[]): Record<string, any>;
35
+ export declare function getBaseRef(nxJson: NxJsonConfiguration): string;
35
36
  export declare function splitArgsIntoNxArgsAndOverrides(args: {
36
37
  [k: string]: any;
37
38
  }, mode: 'run-one' | 'run-many' | 'affected' | 'print-affected', options: {
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createOverrides = createOverrides;
4
+ exports.getBaseRef = getBaseRef;
4
5
  exports.splitArgsIntoNxArgsAndOverrides = splitArgsIntoNxArgsAndOverrides;
5
6
  exports.readParallelFromArgsAndEnv = readParallelFromArgsAndEnv;
6
7
  exports.parseFiles = parseFiles;
@@ -24,6 +25,9 @@ function createOverrides(__overrides_unparsed__ = []) {
24
25
  overrides.__overrides_unparsed__ = __overrides_unparsed__;
25
26
  return overrides;
26
27
  }
28
+ function getBaseRef(nxJson) {
29
+ return nxJson.defaultBase ?? nxJson.affected?.defaultBase ?? 'main';
30
+ }
27
31
  function splitArgsIntoNxArgsAndOverrides(args, mode, options = { printWarnings: true }, nxJson) {
28
32
  // this is to lerna case when this function is invoked imperatively
29
33
  if (args['target'] && !args['targets']) {
@@ -70,7 +74,7 @@ function splitArgsIntoNxArgsAndOverrides(args, mode, options = { printWarnings:
70
74
  ],
71
75
  });
72
76
  }
73
- // Allow setting base and head via environment variables (lower priority then direct command arguments)
77
+ // Allow setting base and head via environment variables (lower priority than direct command arguments)
74
78
  if (!nxArgs.base && process.env.NX_BASE) {
75
79
  nxArgs.base = process.env.NX_BASE;
76
80
  if (options.printWarnings) {
@@ -88,8 +92,7 @@ function splitArgsIntoNxArgsAndOverrides(args, mode, options = { printWarnings:
88
92
  }
89
93
  }
90
94
  if (!nxArgs.base) {
91
- nxArgs.base =
92
- nxJson.defaultBase ?? nxJson.affected?.defaultBase ?? 'main';
95
+ nxArgs.base = getBaseRef(nxJson);
93
96
  // No user-provided arguments to set the affected criteria, so inform the user of the defaults being used
94
97
  if (options.printWarnings &&
95
98
  !nxArgs.head &&
@@ -1,3 +1,38 @@
1
+ import { ExecSyncOptions } from 'child_process';
2
+ export declare function cloneFromUpstream(url: string, destination: string, { originName }?: {
3
+ originName: string;
4
+ }): Promise<GitRepository>;
5
+ export declare class GitRepository {
6
+ private directory;
7
+ root: string;
8
+ constructor(directory: string);
9
+ getGitRootPath(cwd: string): string;
10
+ addFetchRemote(remoteName: string, branch: string): Promise<string>;
11
+ private execAsync;
12
+ showStat(): Promise<string>;
13
+ listBranches(): Promise<string[]>;
14
+ getGitFiles(path: string): Promise<string[]>;
15
+ reset(ref: string): Promise<string>;
16
+ squashLastTwoCommits(): Promise<string>;
17
+ mergeUnrelatedHistories(ref: string, message: string): Promise<string>;
18
+ fetch(remote: string, ref?: string): Promise<string>;
19
+ checkout(branch: string, opts: {
20
+ new: boolean;
21
+ base: string;
22
+ }): Promise<string>;
23
+ move(path: string, destination: string): Promise<string>;
24
+ push(ref: string, remoteName: string): Promise<string>;
25
+ commit(message: string): Promise<string>;
26
+ amendCommit(): Promise<string>;
27
+ deleteGitRemote(name: string): Promise<string>;
28
+ deleteBranch(branch: string): Promise<string>;
29
+ addGitRemote(name: string, url: string): Promise<string>;
30
+ }
31
+ /**
32
+ * This is used by the squash editor script to update the rebase file.
33
+ */
34
+ export declare function updateRebaseFile(contents: string): string;
35
+ export declare function fetchGitRemote(name: string, branch: string, execOptions: ExecSyncOptions): string | Buffer;
1
36
  export declare function getGithubSlugOrNull(): string | null;
2
37
  export declare function extractUserAndRepoFromGitHubUrl(gitRemotes: string): string | null;
3
38
  export declare function commitChanges(commitMessage: string, directory?: string): string | null;
@@ -1,11 +1,122 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GitRepository = void 0;
4
+ exports.cloneFromUpstream = cloneFromUpstream;
5
+ exports.updateRebaseFile = updateRebaseFile;
6
+ exports.fetchGitRemote = fetchGitRemote;
3
7
  exports.getGithubSlugOrNull = getGithubSlugOrNull;
4
8
  exports.extractUserAndRepoFromGitHubUrl = extractUserAndRepoFromGitHubUrl;
5
9
  exports.commitChanges = commitChanges;
6
10
  exports.getLatestCommitSha = getLatestCommitSha;
7
11
  const child_process_1 = require("child_process");
8
12
  const devkit_exports_1 = require("../devkit-exports");
13
+ const path_1 = require("path");
14
+ const SQUASH_EDITOR = (0, path_1.join)(__dirname, 'squash.js');
15
+ function execAsync(command, execOptions) {
16
+ return new Promise((res, rej) => {
17
+ (0, child_process_1.exec)(command, execOptions, (err, stdout, stderr) => {
18
+ if (err) {
19
+ return rej(err);
20
+ }
21
+ res(stdout);
22
+ });
23
+ });
24
+ }
25
+ async function cloneFromUpstream(url, destination, { originName } = { originName: 'origin' }) {
26
+ await execAsync(`git clone ${url} ${destination} --depth 1 --origin ${originName}`, {
27
+ cwd: (0, path_1.dirname)(destination),
28
+ });
29
+ return new GitRepository(destination);
30
+ }
31
+ class GitRepository {
32
+ constructor(directory) {
33
+ this.directory = directory;
34
+ this.root = this.getGitRootPath(this.directory);
35
+ }
36
+ getGitRootPath(cwd) {
37
+ return (0, child_process_1.execSync)('git rev-parse --show-toplevel', {
38
+ cwd,
39
+ })
40
+ .toString()
41
+ .trim();
42
+ }
43
+ addFetchRemote(remoteName, branch) {
44
+ return this.execAsync(`git config --add remote.${remoteName}.fetch "+refs/heads/${branch}:refs/remotes/${remoteName}/${branch}"`);
45
+ }
46
+ execAsync(command) {
47
+ return execAsync(command, {
48
+ cwd: this.root,
49
+ });
50
+ }
51
+ async showStat() {
52
+ return await this.execAsync(`git show --stat`);
53
+ }
54
+ async listBranches() {
55
+ return (await this.execAsync(`git ls-remote --heads --quiet`))
56
+ .trim()
57
+ .split('\n')
58
+ .map((s) => s
59
+ .trim()
60
+ .substring(s.indexOf('\t') + 1)
61
+ .replace('refs/heads/', ''));
62
+ }
63
+ async getGitFiles(path) {
64
+ return (await this.execAsync(`git ls-files ${path}`))
65
+ .trim()
66
+ .split('\n')
67
+ .map((s) => s.trim())
68
+ .filter(Boolean);
69
+ }
70
+ async reset(ref) {
71
+ return this.execAsync(`git reset ${ref} --hard`);
72
+ }
73
+ async squashLastTwoCommits() {
74
+ return this.execAsync(`git -c core.editor="node ${SQUASH_EDITOR}" rebase --interactive --no-autosquash HEAD~2`);
75
+ }
76
+ async mergeUnrelatedHistories(ref, message) {
77
+ return this.execAsync(`git merge ${ref} -X ours --allow-unrelated-histories -m "${message}"`);
78
+ }
79
+ async fetch(remote, ref) {
80
+ return this.execAsync(`git fetch ${remote}${ref ? ` ${ref}` : ''}`);
81
+ }
82
+ async checkout(branch, opts) {
83
+ return this.execAsync(`git checkout ${opts.new ? '-b ' : ' '}${branch}${opts.base ? ' ' + opts.base : ''}`);
84
+ }
85
+ async move(path, destination) {
86
+ return this.execAsync(`git mv ${path} ${destination}`);
87
+ }
88
+ async push(ref, remoteName) {
89
+ return this.execAsync(`git push -u -f ${remoteName} ${ref}`);
90
+ }
91
+ async commit(message) {
92
+ return this.execAsync(`git commit -am "${message}"`);
93
+ }
94
+ async amendCommit() {
95
+ return this.execAsync(`git commit --amend -a --no-edit`);
96
+ }
97
+ deleteGitRemote(name) {
98
+ return this.execAsync(`git remote rm ${name}`);
99
+ }
100
+ deleteBranch(branch) {
101
+ return this.execAsync(`git branch -D ${branch}`);
102
+ }
103
+ addGitRemote(name, url) {
104
+ return this.execAsync(`git remote add ${name} ${url}`);
105
+ }
106
+ }
107
+ exports.GitRepository = GitRepository;
108
+ /**
109
+ * This is used by the squash editor script to update the rebase file.
110
+ */
111
+ function updateRebaseFile(contents) {
112
+ const lines = contents.split('\n');
113
+ const lastCommitIndex = lines.findIndex((line) => line === '') - 1;
114
+ lines[lastCommitIndex] = lines[lastCommitIndex].replace('pick', 'fixup');
115
+ return lines.join('\n');
116
+ }
117
+ function fetchGitRemote(name, branch, execOptions) {
118
+ return (0, child_process_1.execSync)(`git fetch ${name} ${branch} --depth 1`, execOptions);
119
+ }
9
120
  function getGithubSlugOrNull() {
10
121
  try {
11
122
  const gitRemote = (0, child_process_1.execSync)('git remote -v', {
@@ -49,7 +49,7 @@ function isWorkspacesEnabled(packageManager = detectPackageManager(), root = wor
49
49
  if (packageManager === 'pnpm') {
50
50
  return (0, fs_1.existsSync)((0, path_1.join)(root, 'pnpm-workspace.yaml'));
51
51
  }
52
- // yarn and pnpm both use the same 'workspaces' property in package.json
52
+ // yarn and npm both use the same 'workspaces' property in package.json
53
53
  const packageJson = (0, file_utils_1.readPackageJson)();
54
54
  return !!packageJson?.workspaces;
55
55
  }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const fs_1 = require("fs");
4
+ const git_utils_1 = require("./git-utils");
5
+ // This script is used as an editor for git rebase -i
6
+ // This is the file which git creates. When this script exits, the updates should be written to this file.
7
+ const filePath = process.argv[2];
8
+ // Change the second commit from pick to fixup
9
+ const contents = (0, fs_1.readFileSync)(filePath).toString();
10
+ const newContents = (0, git_utils_1.updateRebaseFile)(contents);
11
+ // Write the updated contents back to the file
12
+ (0, fs_1.writeFileSync)(filePath, newContents);