Skip to content

Commit 90a10a8

Browse files
fahslajFrozenPandaz
authored andcommitted
fix(release): logging improvements (#21692)
(cherry picked from commit 49bba42)
1 parent 3623505 commit 90a10a8

File tree

6 files changed

+87
-87
lines changed

6 files changed

+87
-87
lines changed

packages/nx/src/command-line/release/changelog.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { FsTree, Tree } from '../../generators/tree';
1212
import { registerTsProject } from '../../plugins/js/utils/register';
1313
import { createProjectGraphAsync } from '../../project-graph/project-graph';
1414
import { interpolate } from '../../tasks-runner/utils';
15-
import { logger } from '../../utils/logger';
1615
import { output } from '../../utils/output';
1716
import { handleErrors } from '../../utils/params';
1817
import { joinPathFragments } from '../../utils/path';
@@ -476,12 +475,6 @@ async function applyChangesAndExit(
476475
await postGitTask(latestCommit);
477476
}
478477

479-
if (args.dryRun) {
480-
logger.warn(
481-
`\nNOTE: The "dryRun" flag means no changelogs were actually created.`
482-
);
483-
}
484-
485478
return 0;
486479
}
487480

packages/nx/src/command-line/release/command-object.ts

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Argv, CommandModule, showHelp } from 'yargs';
22
import { readNxJson } from '../../project-graph/file-utils';
3+
import { logger } from '../../utils/logger';
34
import {
45
OutputStyle,
56
RunManyOptions,
@@ -159,15 +160,18 @@ const releaseCommand: CommandModule<NxReleaseArgs, ReleaseOptions> = {
159160
}
160161
return true;
161162
}),
162-
handler: (args) =>
163-
import('./release')
164-
.then((m) => m.releaseCLIHandler(args))
165-
.then((versionDataOrExitCode) => {
166-
if (typeof versionDataOrExitCode === 'number') {
167-
return process.exit(versionDataOrExitCode);
168-
}
169-
process.exit(0);
170-
}),
163+
handler: async (args) => {
164+
const release = await import('./release');
165+
const result = await release.releaseCLIHandler(args);
166+
if (args.dryRun) {
167+
logger.warn(`\nNOTE: The "dryRun" flag means no changes were made.`);
168+
}
169+
170+
if (typeof result === 'number') {
171+
process.exit(result);
172+
}
173+
process.exit(0);
174+
},
171175
};
172176

173177
const versionCommand: CommandModule<NxReleaseArgs, VersionOptions> = {
@@ -195,15 +199,18 @@ const versionCommand: CommandModule<NxReleaseArgs, VersionOptions> = {
195199
'Whether or not to stage the changes made by this command. Useful when combining this command with changelog generation.',
196200
})
197201
),
198-
handler: (args) =>
199-
import('./version')
200-
.then((m) => m.releaseVersionCLIHandler(args))
201-
.then((versionDataOrExitCode) => {
202-
if (typeof versionDataOrExitCode === 'number') {
203-
return process.exit(versionDataOrExitCode);
204-
}
205-
process.exit(0);
206-
}),
202+
handler: async (args) => {
203+
const release = await import('./version');
204+
const result = await release.releaseVersionCLIHandler(args);
205+
if (args.dryRun) {
206+
logger.warn(`\nNOTE: The "dryRun" flag means no changes were made.`);
207+
}
208+
209+
if (typeof result === 'number') {
210+
process.exit(result);
211+
}
212+
process.exit(0);
213+
},
207214
};
208215

209216
const changelogCommand: CommandModule<NxReleaseArgs, ChangelogOptions> = {
@@ -254,10 +261,16 @@ const changelogCommand: CommandModule<NxReleaseArgs, ChangelogOptions> = {
254261
})
255262
),
256263
handler: async (args) => {
257-
const status = await (
258-
await import('./changelog')
259-
).releaseChangelogCLIHandler(args);
260-
process.exit(status);
264+
const release = await import('./changelog');
265+
const result = await release.releaseChangelogCLIHandler(args);
266+
if (args.dryRun) {
267+
logger.warn(`\nNOTE: The "dryRun" flag means no changes were made.`);
268+
}
269+
270+
if (typeof result === 'number') {
271+
process.exit(result);
272+
}
273+
process.exit(0);
261274
},
262275
};
263276

@@ -284,6 +297,10 @@ const publishCommand: CommandModule<NxReleaseArgs, PublishOptions> = {
284297
const status = await (
285298
await import('./publish')
286299
).releasePublishCLIHandler(coerceParallelOption(withOverrides(args, 2)));
300+
if (args.dryRun) {
301+
logger.warn(`\nNOTE: The "dryRun" flag means no changes were made.`);
302+
}
303+
287304
process.exit(status);
288305
},
289306
};

packages/nx/src/command-line/release/publish.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
createOverrides,
1111
readGraphFileFromGraphArg,
1212
} from '../../utils/command-line-utils';
13-
import { logger } from '../../utils/logger';
1413
import { handleErrors } from '../../utils/params';
1514
import { projectHasTarget } from '../../utils/project-graph-utils';
1615
import { generateGraph } from '../graph/graph';
@@ -120,12 +119,6 @@ export async function releasePublish(
120119
}
121120
}
122121

123-
if (_args.dryRun) {
124-
logger.warn(
125-
`\nNOTE: The "dryRun" flag means no projects were actually published.`
126-
);
127-
}
128-
129122
return overallExitStatus;
130123
}
131124

packages/nx/src/command-line/release/release.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,13 @@ export async function release(
150150
if (shouldPublish) {
151151
await releasePublish(args);
152152
} else {
153-
console.log('Skipped publishing packages.');
153+
output.logSingleLine('Skipped publishing packages.');
154154
}
155155

156156
return versionResult;
157157
}
158158

159159
async function promptForPublish(): Promise<boolean> {
160-
console.log('\n');
161-
162160
try {
163161
const reply = await prompt<{ confirmation: boolean }>([
164162
{
@@ -169,7 +167,6 @@ async function promptForPublish(): Promise<boolean> {
169167
]);
170168
return reply.confirmation;
171169
} catch (e) {
172-
console.log('\n');
173170
// Handle the case where the user exits the prompt with ctrl+c
174171
return false;
175172
}

packages/nx/src/command-line/release/utils/github.ts

Lines changed: 47 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -103,45 +103,27 @@ export async function createOrUpdateGithubRelease(
103103
}
104104
}
105105

106-
const reply = await prompt<{ open: 'Yes' | 'No' }>([
107-
{
108-
name: 'open',
109-
message:
110-
'Do you want to finish creating the release manually in your browser?',
111-
type: 'autocomplete',
112-
choices: [
113-
{
114-
name: 'Yes',
115-
hint: 'It will pre-populate the form for you',
116-
},
117-
{
118-
name: 'No',
119-
},
120-
],
121-
initial: 0,
122-
},
123-
]).catch(() => {
124-
return { open: 'No' };
125-
});
126-
127-
if (reply.open === 'Yes') {
128-
const open = require('open');
129-
await open(result.url)
130-
.then(() => {
131-
console.info(
132-
`\nFollow up in the browser to manually create the release:\n\n` +
133-
chalk.underline(chalk.cyan(result.url)) +
134-
`\n`
135-
);
136-
})
137-
.catch(() => {
138-
console.info(
139-
`Open this link to manually create a release: \n` +
140-
chalk.underline(chalk.cyan(result.url)) +
141-
'\n'
142-
);
143-
});
106+
const shouldContinueInGitHub = await promptForContinueInGitHub();
107+
if (!shouldContinueInGitHub) {
108+
return;
144109
}
110+
111+
const open = require('open');
112+
await open(result.url)
113+
.then(() => {
114+
console.info(
115+
`\nFollow up in the browser to manually create the release:\n\n` +
116+
chalk.underline(chalk.cyan(result.url)) +
117+
`\n`
118+
);
119+
})
120+
.catch(() => {
121+
console.info(
122+
`Open this link to manually create a release: \n` +
123+
chalk.underline(chalk.cyan(result.url)) +
124+
'\n'
125+
);
126+
});
145127
}
146128

147129
/**
@@ -170,6 +152,33 @@ export async function createOrUpdateGithubRelease(
170152
}
171153
}
172154

155+
async function promptForContinueInGitHub(): Promise<boolean> {
156+
try {
157+
const reply = await prompt<{ open: 'Yes' | 'No' }>([
158+
{
159+
name: 'open',
160+
message:
161+
'Do you want to finish creating the release manually in your browser?',
162+
type: 'autocomplete',
163+
choices: [
164+
{
165+
name: 'Yes',
166+
hint: 'It will pre-populate the form for you',
167+
},
168+
{
169+
name: 'No',
170+
},
171+
],
172+
initial: 0,
173+
},
174+
]);
175+
return reply.open === 'Yes';
176+
} catch (e) {
177+
// Handle the case where the user exits the prompt with ctrl+c
178+
process.exit(1);
179+
}
180+
}
181+
173182
async function syncGithubRelease(
174183
githubRequestConfig: GithubRequestConfig,
175184
release: GithubReleaseOptions,

packages/nx/src/command-line/release/version.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
import {
1111
NxJsonConfiguration,
1212
joinPathFragments,
13-
logger,
1413
output,
1514
workspaceRoot,
1615
} from '../../devkit-exports';
@@ -281,10 +280,6 @@ export async function releaseVersion(
281280
}
282281
}
283282

284-
if (args.dryRun) {
285-
logger.warn(`\nNOTE: The "dryRun" flag means no changes were made.`);
286-
}
287-
288283
return {
289284
// An overall workspace version cannot be relevant when filtering to independent projects
290285
workspaceVersion: undefined,
@@ -422,10 +417,6 @@ export async function releaseVersion(
422417
}
423418
}
424419

425-
if (args.dryRun) {
426-
logger.warn(`\nNOTE: The "dryRun" flag means no changes were made.`);
427-
}
428-
429420
return {
430421
workspaceVersion,
431422
projectsVersionData: versionData,

0 commit comments

Comments
 (0)