nx 18.1.0-canary.20240210-b1d0294 → 18.1.0-canary.20240214-b625a79

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.
@@ -155,17 +155,27 @@ async function gitTag({ tag, message, additionalArgs, dryRun, verbose, logFn, })
155
155
  }
156
156
  }
157
157
  exports.gitTag = gitTag;
158
- async function gitPush(gitRemote) {
158
+ async function gitPush({ gitRemote, dryRun, verbose, }) {
159
+ const commandArgs = [
160
+ 'push',
161
+ // NOTE: It's important we use --follow-tags, and not --tags, so that we are precise about what we are pushing
162
+ '--follow-tags',
163
+ '--no-verify',
164
+ '--atomic',
165
+ // Set custom git remote if provided
166
+ ...(gitRemote ? [gitRemote] : []),
167
+ ];
168
+ if (verbose) {
169
+ console.log(dryRun
170
+ ? `Would push the current branch to the remote with the following command, but --dry-run was set:`
171
+ : `Pushing the current branch to the remote with the following command:`);
172
+ console.log(`git ${commandArgs.join(' ')}`);
173
+ }
174
+ if (dryRun) {
175
+ return;
176
+ }
159
177
  try {
160
- await (0, exec_command_1.execCommand)('git', [
161
- 'push',
162
- // NOTE: It's important we use --follow-tags, and not --tags, so that we are precise about what we are pushing
163
- '--follow-tags',
164
- '--no-verify',
165
- '--atomic',
166
- // Set custom git remote if provided
167
- ...(gitRemote ? [gitRemote] : []),
168
- ]);
178
+ await (0, exec_command_1.execCommand)('git', commandArgs);
169
179
  }
170
180
  catch (err) {
171
181
  throw new Error(`Unexpected git push error: ${err}`);
@@ -252,7 +262,12 @@ async function getCommitHash(ref) {
252
262
  exports.getCommitHash = getCommitHash;
253
263
  async function getFirstGitCommit() {
254
264
  try {
255
- return (await (0, exec_command_1.execCommand)('git', ['rev-list', '--max-parents=0', 'HEAD'])).trim();
265
+ return (await (0, exec_command_1.execCommand)('git', [
266
+ 'rev-list',
267
+ '--max-parents=0',
268
+ 'HEAD',
269
+ '--first-parent',
270
+ ])).trim();
256
271
  }
257
272
  catch (e) {
258
273
  throw new Error(`Unable to find first commit in git history`);
@@ -1,4 +1,5 @@
1
1
  import { Reference } from './git';
2
+ import { ReleaseVersion } from './shared';
2
3
  export type RepoSlug = `${string}/${string}`;
3
4
  export interface GithubRequestConfig {
4
5
  repo: string;
@@ -14,14 +15,9 @@ export interface GithubRelease {
14
15
  prerelease?: boolean;
15
16
  }
16
17
  export declare function getGitHubRepoSlug(remoteName?: string): RepoSlug;
17
- interface GithubReleaseOptions {
18
- version: string;
19
- body: string;
20
- prerelease: boolean;
21
- commit: string;
22
- }
23
- export declare function createOrUpdateGithubRelease(githubRequestConfig: GithubRequestConfig, release: GithubReleaseOptions, existingGithubReleaseForVersion?: GithubRelease): Promise<void>;
18
+ export declare function createOrUpdateGithubRelease(releaseVersion: ReleaseVersion, changelogContents: string, latestCommit: string, { dryRun }: {
19
+ dryRun: boolean;
20
+ }): Promise<void>;
24
21
  export declare function resolveGithubToken(): Promise<string | null>;
25
22
  export declare function getGithubReleaseByTag(config: GithubRequestConfig, tag: string): Promise<GithubRelease>;
26
23
  export declare function formatReferences(references: Reference[], repoSlug: RepoSlug): string;
27
- export {};
@@ -8,6 +8,8 @@ const node_fs_1 = require("node:fs");
8
8
  const node_os_1 = require("node:os");
9
9
  const output_1 = require("../../../utils/output");
10
10
  const path_1 = require("../../../utils/path");
11
+ const print_changes_1 = require("./print-changes");
12
+ const shared_1 = require("./shared");
11
13
  // axios types and values don't seem to match
12
14
  const _axios = require("axios");
13
15
  const axios = _axios;
@@ -32,7 +34,65 @@ function getGitHubRepoSlug(remoteName = 'origin') {
32
34
  }
33
35
  }
34
36
  exports.getGitHubRepoSlug = getGitHubRepoSlug;
35
- async function createOrUpdateGithubRelease(githubRequestConfig, release, existingGithubReleaseForVersion) {
37
+ async function createOrUpdateGithubRelease(releaseVersion, changelogContents, latestCommit, { dryRun }) {
38
+ const githubRepoSlug = getGitHubRepoSlug();
39
+ if (!githubRepoSlug) {
40
+ output_1.output.error({
41
+ title: `Unable to create a GitHub release because the GitHub repo slug could not be determined.`,
42
+ bodyLines: [
43
+ `Please ensure you have a valid GitHub remote configured. You can run \`git remote -v\` to list your current remotes.`,
44
+ ],
45
+ });
46
+ process.exit(1);
47
+ }
48
+ const token = await resolveGithubToken();
49
+ const githubRequestConfig = {
50
+ repo: githubRepoSlug,
51
+ token,
52
+ };
53
+ let existingGithubReleaseForVersion;
54
+ try {
55
+ existingGithubReleaseForVersion = await getGithubReleaseByTag(githubRequestConfig, releaseVersion.gitTag);
56
+ }
57
+ catch (err) {
58
+ if (err.response?.status === 401) {
59
+ output_1.output.error({
60
+ title: `Unable to resolve data via the GitHub API. You can use any of the following options to resolve this:`,
61
+ bodyLines: [
62
+ '- Set the `GITHUB_TOKEN` or `GH_TOKEN` environment variable to a valid GitHub token with `repo` scope',
63
+ '- Have an active session via the official gh CLI tool (https://cli.github.com) in your current terminal',
64
+ ],
65
+ });
66
+ process.exit(1);
67
+ }
68
+ if (err.response?.status === 404) {
69
+ // No existing release found, this is fine
70
+ }
71
+ else {
72
+ // Rethrow unknown errors for now
73
+ throw err;
74
+ }
75
+ }
76
+ const logTitle = `https://github.com/${githubRepoSlug}/releases/tag/${releaseVersion.gitTag}`;
77
+ if (existingGithubReleaseForVersion) {
78
+ console.error(`${chalk.white('UPDATE')} ${logTitle}${dryRun ? chalk.keyword('orange')(' [dry-run]') : ''}`);
79
+ }
80
+ else {
81
+ console.error(`${chalk.green('CREATE')} ${logTitle}${dryRun ? chalk.keyword('orange')(' [dry-run]') : ''}`);
82
+ }
83
+ console.log('');
84
+ (0, print_changes_1.printDiff)(existingGithubReleaseForVersion ? existingGithubReleaseForVersion.body : '', changelogContents, 3, shared_1.noDiffInChangelogMessage);
85
+ if (!dryRun) {
86
+ await createOrUpdateGithubReleaseInternal(githubRequestConfig, {
87
+ version: releaseVersion.gitTag,
88
+ prerelease: releaseVersion.isPrerelease,
89
+ body: changelogContents,
90
+ commit: latestCommit,
91
+ }, existingGithubReleaseForVersion);
92
+ }
93
+ }
94
+ exports.createOrUpdateGithubRelease = createOrUpdateGithubRelease;
95
+ async function createOrUpdateGithubReleaseInternal(githubRequestConfig, release, existingGithubReleaseForVersion) {
36
96
  const result = await syncGithubRelease(githubRequestConfig, release, existingGithubReleaseForVersion);
37
97
  /**
38
98
  * If something went wrong POSTing to Github we can still pre-populate the web form on github.com
@@ -98,7 +158,6 @@ async function createOrUpdateGithubRelease(githubRequestConfig, release, existin
98
158
  });
99
159
  }
100
160
  }
101
- exports.createOrUpdateGithubRelease = createOrUpdateGithubRelease;
102
161
  async function promptForContinueInGitHub() {
103
162
  try {
104
163
  const reply = await (0, enquirer_1.prompt)([
@@ -2,6 +2,7 @@ import { ProjectGraph } from '../../../config/project-graph';
2
2
  import { Tree } from '../../../generators/tree';
3
3
  import type { ReleaseGroupWithName } from '../config/filter-release-groups';
4
4
  import { GitCommit } from './git';
5
+ export declare const noDiffInChangelogMessage: string;
5
6
  export type ReleaseVersionGeneratorResult = {
6
7
  data: VersionData;
7
8
  callback: (tree: Tree, opts: {
@@ -1,11 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getCommitsRelevantToProjects = exports.handleDuplicateGitTags = exports.createGitTagValues = exports.createCommitMessageValues = exports.commitChanges = exports.ReleaseVersion = void 0;
3
+ exports.getCommitsRelevantToProjects = exports.handleDuplicateGitTags = exports.createGitTagValues = exports.createCommitMessageValues = exports.commitChanges = exports.ReleaseVersion = exports.noDiffInChangelogMessage = void 0;
4
+ const chalk = require("chalk");
4
5
  const semver_1 = require("semver");
5
6
  const file_map_utils_1 = require("../../../project-graph/file-map-utils");
6
7
  const utils_1 = require("../../../tasks-runner/utils");
7
8
  const output_1 = require("../../../utils/output");
8
9
  const git_1 = require("./git");
10
+ exports.noDiffInChangelogMessage = chalk.yellow(`NOTE: There was no diff detected for the changelog entry. Maybe you intended to pass alternative git references via --from and --to?`);
9
11
  function isPrerelease(version) {
10
12
  // prerelease returns an array of matching prerelease "components", or null if the version is not a prerelease
11
13
  return (0, semver_1.prerelease)(version) !== null;
@@ -31,9 +31,6 @@ interface NxInstallationConfiguration {
31
31
  */
32
32
  plugins?: Record<string, string>;
33
33
  }
34
- /**
35
- * **ALPHA**
36
- */
37
34
  export interface NxReleaseVersionConfiguration {
38
35
  generator?: string;
39
36
  generatorOptions?: Record<string, unknown>;
@@ -49,9 +46,6 @@ export interface NxReleaseVersionConfiguration {
49
46
  */
50
47
  conventionalCommits?: boolean;
51
48
  }
52
- /**
53
- * **ALPHA**
54
- */
55
49
  export interface NxReleaseChangelogConfiguration {
56
50
  /**
57
51
  * Optionally create a release containing all relevant changes on a supported version control system, it
@@ -93,9 +87,6 @@ export interface NxReleaseChangelogConfiguration {
93
87
  renderer?: string;
94
88
  renderOptions?: ChangelogRenderOptions;
95
89
  }
96
- /**
97
- * **ALPHA**
98
- */
99
90
  export interface NxReleaseGitConfiguration {
100
91
  /**
101
92
  * Whether or not to automatically commit the changes made by current command
@@ -126,9 +117,6 @@ export interface NxReleaseGitConfiguration {
126
117
  */
127
118
  tagArgs?: string;
128
119
  }
129
- /**
130
- * **ALPHA**
131
- */
132
120
  interface NxReleaseConfiguration {
133
121
  /**
134
122
  * Shorthand for amending the projects which will be included in the implicit default release group (all projects by default).
@@ -333,7 +321,7 @@ export interface NxJsonConfiguration<T = '*' | string[]> {
333
321
  */
334
322
  installation?: NxInstallationConfiguration;
335
323
  /**
336
- * **ALPHA**: Configuration for `nx release` (versioning and publishing of applications and libraries)
324
+ * Configuration for `nx release` (versioning and publishing of applications and libraries)
337
325
  */
338
326
  release?: NxReleaseConfiguration;
339
327
  /**