Skip to content

Commit 391d37b

Browse files
authored
Merge pull request #2839 from elliot-nelson/experimental-terminal
[rush] Move ConfigurationFile logging to new "debug" severity
2 parents 8993063 + fbc181e commit 391d37b

20 files changed

+423
-22
lines changed

apps/rush-lib/src/cli/scriptActions/BulkScriptAction.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ export class BulkScriptAction extends BaseScriptAction {
110110
const stopwatch: Stopwatch = Stopwatch.start();
111111

112112
const isQuietMode: boolean = !this._verboseParameter.value;
113+
const isDebugMode: boolean = !!this.parser.isDebug;
113114

114115
// if this is parallelizable, then use the value from the flag (undefined or a number),
115116
// if parallelism is not enabled, then restrict to 1 core
@@ -144,6 +145,7 @@ export class BulkScriptAction extends BaseScriptAction {
144145
commandToRun: this._commandToRun,
145146
customParameterValues,
146147
isQuietMode: isQuietMode,
148+
isDebugMode: isDebugMode,
147149
isIncrementalBuildAllowed: this._isIncrementalBuildAllowed,
148150
ignoreMissingScript: this._ignoreMissingScript,
149151
ignoreDependencyOrder: this._ignoreDependencyOrder,
@@ -152,6 +154,7 @@ export class BulkScriptAction extends BaseScriptAction {
152154

153155
const taskRunnerOptions: ITaskRunnerOptions = {
154156
quietMode: isQuietMode,
157+
debugMode: this.parser.isDebug,
155158
parallelism: parallelism,
156159
changedProjectsOnly: changedProjectsOnly,
157160
allowWarningsInSuccessfulBuild: this._allowWarningsInSuccessfulBuild,

apps/rush-lib/src/logic/TaskSelector.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export interface ITaskSelectorConstructor {
1616
commandToRun: string;
1717
customParameterValues: string[];
1818
isQuietMode: boolean;
19+
isDebugMode: boolean;
1920
isIncrementalBuildAllowed: boolean;
2021
ignoreMissingScript: boolean;
2122
ignoreDependencyOrder: boolean;

apps/rush-lib/src/logic/taskRunner/BaseBuilder.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export interface IBuilderContext {
1212
collatedWriter: CollatedWriter;
1313
stdioSummarizer: StdioSummarizer;
1414
quietMode: boolean;
15+
debugMode: boolean;
1516
}
1617

1718
/**

apps/rush-lib/src/logic/taskRunner/ProjectBuilder.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,12 @@ export class ProjectBuilder extends BaseBuilder {
167167
newlineKind: NewlineKind.Lf // for StdioSummarizer
168168
});
169169

170-
const quietModeTransform: DiscardStdoutTransform = new DiscardStdoutTransform({
170+
const discardTransform: DiscardStdoutTransform = new DiscardStdoutTransform({
171171
destination: context.collatedWriter
172172
});
173173

174174
const splitterTransform1: SplitterTransform = new SplitterTransform({
175-
destinations: [context.quietMode ? quietModeTransform : context.collatedWriter, stderrLineTransform]
175+
destinations: [context.quietMode ? discardTransform : context.collatedWriter, stderrLineTransform]
176176
});
177177

178178
const normalizeNewlineTransform: TextRewriterTransform = new TextRewriterTransform({
@@ -182,7 +182,9 @@ export class ProjectBuilder extends BaseBuilder {
182182
});
183183

184184
const collatedTerminal: CollatedTerminal = new CollatedTerminal(normalizeNewlineTransform);
185-
const terminalProvider: CollatedTerminalProvider = new CollatedTerminalProvider(collatedTerminal);
185+
const terminalProvider: CollatedTerminalProvider = new CollatedTerminalProvider(collatedTerminal, {
186+
debugEnabled: context.debugMode
187+
});
186188
const terminal: Terminal = new Terminal(terminalProvider);
187189

188190
let hasWarningOrError: boolean = false;

apps/rush-lib/src/logic/taskRunner/TaskRunner.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { CommandLineConfiguration } from '../../api/CommandLineConfiguration';
2121

2222
export interface ITaskRunnerOptions {
2323
quietMode: boolean;
24+
debugMode: boolean;
2425
parallelism: string | undefined;
2526
changedProjectsOnly: boolean;
2627
allowWarningsInSuccessfulBuild: boolean;
@@ -43,6 +44,7 @@ export class TaskRunner {
4344
private readonly _allowWarningsInSuccessfulBuild: boolean;
4445
private readonly _buildQueue: Task[];
4546
private readonly _quietMode: boolean;
47+
private readonly _debugMode: boolean;
4648
private readonly _parallelism: number;
4749
private readonly _repoCommandLineConfiguration: CommandLineConfiguration | undefined;
4850
private _hasAnyFailures: boolean;
@@ -60,6 +62,7 @@ export class TaskRunner {
6062
public constructor(orderedTasks: Task[], options: ITaskRunnerOptions) {
6163
const {
6264
quietMode,
65+
debugMode,
6366
parallelism,
6467
changedProjectsOnly,
6568
allowWarningsInSuccessfulBuild,
@@ -68,6 +71,7 @@ export class TaskRunner {
6871
this._tasks = orderedTasks;
6972
this._buildQueue = orderedTasks.slice(0);
7073
this._quietMode = quietMode;
74+
this._debugMode = debugMode;
7175
this._hasAnyFailures = false;
7276
this._hasAnyWarnings = false;
7377
this._changedProjectsOnly = changedProjectsOnly;
@@ -239,7 +243,8 @@ export class TaskRunner {
239243
repoCommandLineConfiguration: this._repoCommandLineConfiguration,
240244
stdioSummarizer: task.stdioSummarizer,
241245
collatedWriter: task.collatedWriter,
242-
quietMode: this._quietMode
246+
quietMode: this._quietMode,
247+
debugMode: this._debugMode
243248
};
244249

245250
try {

apps/rush-lib/src/logic/taskRunner/test/TaskRunner.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ describe('TaskRunner', () => {
6363
() =>
6464
new TaskRunner([], {
6565
quietMode: false,
66+
debugMode: false,
6667
parallelism: 'tequila',
6768
changedProjectsOnly: false,
6869
destination: mockWritable,
@@ -77,6 +78,7 @@ describe('TaskRunner', () => {
7778
beforeEach(() => {
7879
taskRunnerOptions = {
7980
quietMode: false,
81+
debugMode: false,
8082
parallelism: '1',
8183
changedProjectsOnly: false,
8284
destination: mockWritable,
@@ -134,6 +136,7 @@ describe('TaskRunner', () => {
134136
beforeEach(() => {
135137
taskRunnerOptions = {
136138
quietMode: false,
139+
debugMode: false,
137140
parallelism: '1',
138141
changedProjectsOnly: false,
139142
destination: mockWritable,
@@ -169,6 +172,7 @@ describe('TaskRunner', () => {
169172
beforeEach(() => {
170173
taskRunnerOptions = {
171174
quietMode: false,
175+
debugMode: false,
172176
parallelism: '1',
173177
changedProjectsOnly: false,
174178
destination: mockWritable,

apps/rush-lib/src/utilities/CollatedTerminalProvider.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@
44
import { ITerminalProvider, TerminalProviderSeverity } from '@rushstack/node-core-library';
55
import { CollatedTerminal } from '@rushstack/stream-collator';
66

7+
export interface ICollatedTerminalProviderOptions {
8+
debugEnabled: boolean;
9+
}
10+
711
export class CollatedTerminalProvider implements ITerminalProvider {
812
private readonly _collatedTerminal: CollatedTerminal;
913
private _hasErrors: boolean = false;
1014
private _hasWarnings: boolean = false;
15+
private _debugEnabled: boolean = false;
1116

1217
public readonly supportsColor: boolean = true;
1318
public readonly eolCharacter: string = '\n';
@@ -20,18 +25,34 @@ export class CollatedTerminalProvider implements ITerminalProvider {
2025
return this._hasWarnings;
2126
}
2227

23-
public constructor(collatedTerminal: CollatedTerminal) {
28+
public constructor(
29+
collatedTerminal: CollatedTerminal,
30+
options?: Partial<ICollatedTerminalProviderOptions>
31+
) {
2432
this._collatedTerminal = collatedTerminal;
33+
this._debugEnabled = !!options?.debugEnabled;
2534
}
2635

2736
public write(data: string, severity: TerminalProviderSeverity): void {
2837
switch (severity) {
2938
case TerminalProviderSeverity.log:
3039
case TerminalProviderSeverity.verbose: {
40+
// Unlike the basic ConsoleTerminalProvider, verbose messages are always passed
41+
// to stdout -- by convention the user-controlled build script output is sent
42+
// to verbose, and will be routed to a variety of other providers in the ProjectBuilder.
3143
this._collatedTerminal.writeStdoutLine(data);
3244
break;
3345
}
3446

47+
case TerminalProviderSeverity.debug: {
48+
// Similar to the basic ConsoleTerminalProvider, debug messages are discarded
49+
// unless they are explicitly enabled.
50+
if (this._debugEnabled) {
51+
this._collatedTerminal.writeStdoutLine(data);
52+
}
53+
break;
54+
}
55+
3556
case TerminalProviderSeverity.error: {
3657
this._collatedTerminal.writeStderrLine(data);
3758
this._hasErrors = true;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@microsoft/rush",
5+
"comment": "The --debug flag now also shows additional diagnostic information.",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@microsoft/rush",
10+
"email": "[email protected]"
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@rushstack/heft-config-file",
5+
"comment": "Move detailed logging from verbose to debug severity.",
6+
"type": "patch"
7+
}
8+
],
9+
"packageName": "@rushstack/heft-config-file",
10+
"email": "[email protected]"
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@rushstack/node-core-library",
5+
"comment": "Add new Terminal message severity \"debug\", below verbose.",
6+
"type": "minor"
7+
}
8+
],
9+
"packageName": "@rushstack/node-core-library",
10+
"email": "[email protected]"
11+
}

common/reviews/api/node-core-library.api.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ export enum ColorValue {
120120
// @beta
121121
export class ConsoleTerminalProvider implements ITerminalProvider {
122122
constructor(options?: Partial<IConsoleTerminalProviderOptions>);
123+
debugEnabled: boolean;
123124
get eolCharacter(): string;
124125
get supportsColor(): boolean;
125126
verboseEnabled: boolean;
@@ -289,6 +290,7 @@ export interface IColorableSequence {
289290

290291
// @beta
291292
export interface IConsoleTerminalProviderOptions {
293+
debugEnabled: boolean;
292294
verboseEnabled: boolean;
293295
}
294296

@@ -718,6 +720,7 @@ export class Sort {
718720
export class StringBufferTerminalProvider implements ITerminalProvider {
719721
constructor(supportsColor?: boolean);
720722
get eolCharacter(): string;
723+
getDebugOutput(options?: IStringBufferOutputOptions): string;
721724
getErrorOutput(options?: IStringBufferOutputOptions): string;
722725
getOutput(options?: IStringBufferOutputOptions): string;
723726
getVerbose(options?: IStringBufferOutputOptions): string;
@@ -739,6 +742,8 @@ export class Terminal {
739742
registerProvider(provider: ITerminalProvider): void;
740743
unregisterProvider(provider: ITerminalProvider): void;
741744
write(...messageParts: (string | IColorableSequence)[]): void;
745+
writeDebug(...messageParts: (string | IColorableSequence)[]): void;
746+
writeDebugLine(...messageParts: (string | IColorableSequence)[]): void;
742747
writeError(...messageParts: (string | IColorableSequence)[]): void;
743748
writeErrorLine(...messageParts: (string | IColorableSequence)[]): void;
744749
writeLine(...messageParts: (string | IColorableSequence)[]): void;
@@ -748,8 +753,10 @@ export class Terminal {
748753
writeWarningLine(...messageParts: (string | IColorableSequence)[]): void;
749754
}
750755

751-
// @beta (undocumented)
756+
// @beta
752757
export enum TerminalProviderSeverity {
758+
// (undocumented)
759+
debug = 4,
753760
// (undocumented)
754761
error = 2,
755762
// (undocumented)

libraries/heft-config-file/src/ConfigurationFile.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ export class ConfigurationFile<TConfigurationFile> {
341341
} catch (e) {
342342
if (FileSystem.isNotExistError(e)) {
343343
if (rigConfig) {
344-
terminal.writeVerboseLine(
344+
terminal.writeDebugLine(
345345
`Config file "${resolvedConfigurationFilePathForLogging}" does not exist. Attempting to load via rig.`
346346
);
347347
const rigResult: TConfigurationFile | undefined = await this._tryLoadConfigurationFileInRigAsync(
@@ -353,7 +353,7 @@ export class ConfigurationFile<TConfigurationFile> {
353353
return rigResult;
354354
}
355355
} else {
356-
terminal.writeVerboseLine(
356+
terminal.writeDebugLine(
357357
`Configuration file "${resolvedConfigurationFilePathForLogging}" not found.`
358358
);
359359
}
@@ -570,15 +570,15 @@ export class ConfigurationFile<TConfigurationFile> {
570570
if (!FileSystem.isNotExistError(e)) {
571571
throw e;
572572
} else {
573-
terminal.writeVerboseLine(
573+
terminal.writeDebugLine(
574574
`Configuration file "${
575575
this.projectRelativeFilePath
576576
}" not found in rig ("${ConfigurationFile._formatPathForLogging(rigProfileFolder)}")`
577577
);
578578
}
579579
}
580580
} else {
581-
terminal.writeVerboseLine(
581+
terminal.writeDebugLine(
582582
`No rig found for "${ConfigurationFile._formatPathForLogging(rigConfig.projectFolderPath)}"`
583583
);
584584
}

libraries/heft-config-file/src/test/ConfigurationFile.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ describe('ConfigurationFile', () => {
3434
log: terminalProvider.getOutput(),
3535
warning: terminalProvider.getWarningOutput(),
3636
error: terminalProvider.getErrorOutput(),
37-
verbose: terminalProvider.getVerbose()
37+
verbose: terminalProvider.getVerbose(),
38+
debug: terminalProvider.getDebugOutput()
3839
}).toMatchSnapshot();
3940
});
4041

0 commit comments

Comments
 (0)