Skip to content

Commit 37e915c

Browse files
refactor(cli): remove pagination and stats output
1 parent 43b1221 commit 37e915c

2 files changed

Lines changed: 13 additions & 167 deletions

File tree

packages/webpack-cli/src/ui-renderer.ts

Lines changed: 2 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,6 @@ export interface CommandMeta {
6565
description: string;
6666
}
6767

68-
/** Summary line shown at the bottom of a build output block. */
69-
export interface BuildSummary {
70-
success: boolean;
71-
message: string;
72-
}
73-
7468
/** One section emitted by `renderInfoOutput`, e.g. "System" or "Binaries". */
7569
export interface InfoSection {
7670
title: string;
@@ -188,104 +182,7 @@ function _renderHelpOptions(
188182
}
189183
}
190184

191-
async function _page(lines: string[], opts: RenderOptions): Promise<void> {
192-
const { colors, log } = opts;
193-
194-
if (
195-
!process.stdin.isTTY ||
196-
typeof (process.stdin as NodeJS.ReadStream & { setRawMode?: unknown }).setRawMode !== "function"
197-
) {
198-
for (const line of lines) log(line);
199-
return;
200-
}
201-
202-
const termHeight: number = (process.stdout as NodeJS.WriteStream & { rows?: number }).rows ?? 24;
203-
const pageSize = termHeight - 2;
204-
let pos = 0;
205-
206-
const flush = (count: number) => {
207-
const end = Math.min(pos + count, lines.length);
208-
for (let i = pos; i < end; i++) log(lines[i]);
209-
pos = end;
210-
};
211-
212-
flush(pageSize);
213-
if (pos >= lines.length) return;
214-
215-
process.stdin.setRawMode(true);
216-
process.stdin.resume();
217-
process.stdin.setEncoding("utf8");
218-
219-
const hint =
220-
`${indent(INDENT)}${colors.cyan("─")} ` +
221-
`${colors.bold("Enter")} next line ` +
222-
`${colors.bold("Space")} next page ` +
223-
`${colors.bold("q")} quit`;
224-
225-
process.stdout.write(`\n${hint}\r`);
226-
227-
await new Promise<void>((resolve) => {
228-
const clearHint = () => process.stdout.write(`\r${" ".repeat(process.stdout.columns ?? 80)}\r`);
229-
const printHint = () => process.stdout.write(`${hint}`);
230-
const onKey = (key: string) => {
231-
if (key === "\u0003") {
232-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
233-
cleanup();
234-
process.exit(0);
235-
}
236-
237-
if (key === "q" || key === "Q" || key === "\u001B") {
238-
clearHint();
239-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
240-
cleanup();
241-
resolve();
242-
return;
243-
}
244-
245-
if (key === " " || key === "d") {
246-
clearHint();
247-
flush(Math.floor(pageSize / 2));
248-
if (pos < lines.length) {
249-
process.stdout.write("\n");
250-
printHint();
251-
} else {
252-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
253-
cleanup();
254-
resolve();
255-
}
256-
return;
257-
}
258-
259-
if ((key === "\r" || key === "\n" || key === "\u001B[B") && pos < lines.length) {
260-
clearHint();
261-
process.stdout.write(`${lines[pos]}\n`);
262-
pos++;
263-
if (pos < lines.length) {
264-
printHint();
265-
} else {
266-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
267-
cleanup();
268-
resolve();
269-
}
270-
}
271-
};
272-
273-
const cleanup = () => {
274-
process.stdin.removeListener("data", onKey);
275-
process.stdin.setRawMode(false);
276-
process.stdin.pause();
277-
process.stdout.write("\n");
278-
};
279-
280-
process.stdin.on("data", onKey);
281-
});
282-
}
283-
284-
export async function renderCommandHelp(
285-
data: CommandHelpData,
286-
opts: RenderOptions,
287-
paginate = true,
288-
): Promise<void> {
185+
export function renderCommandHelp(data: CommandHelpData, opts: RenderOptions): void {
289186
const { colors } = opts;
290187
const termWidth = Math.min(opts.columns || MAX_WIDTH, MAX_WIDTH);
291188
const div = divider(termWidth, colors);
@@ -335,21 +232,7 @@ export async function renderCommandHelp(
335232
);
336233
push("");
337234

338-
const termHeight = (process.stdout as NodeJS.WriteStream & { rows?: number }).rows ?? 24;
339-
const canPage =
340-
paginate &&
341-
process.stdout.isTTY &&
342-
process.stdin.isTTY &&
343-
typeof (process.stdin as NodeJS.ReadStream & { setRawMode?: unknown }).setRawMode ===
344-
"function";
345-
const shouldPage = canPage && lines.length > termHeight - 2;
346-
347-
if (!shouldPage) {
348-
for (const line of lines) opts.log(line);
349-
return;
350-
}
351-
352-
await _page(lines, opts);
235+
for (const line of lines) opts.log(line);
353236
}
354237

355238
export function renderOptionHelp(data: OptionHelpData, opts: RenderOptions): void {
@@ -493,34 +376,6 @@ export function renderVersionOutput(rawEnvinfo: string, opts: RenderOptions): vo
493376
}
494377
}
495378

496-
export function renderStatsOutput(
497-
statsString: string,
498-
summary: BuildSummary | null,
499-
opts: RenderOptions,
500-
): void {
501-
const { log } = opts;
502-
const trimmed = statsString.trim();
503-
504-
if (trimmed) {
505-
// Output the entire indented stats block as a single log() call so all
506-
// lines arrive in one stdout chunk, watch mode tests depend on this.
507-
const indented = trimmed
508-
.split("\n")
509-
.map((line) => `${indent(INDENT)}${line}`)
510-
.join("\n");
511-
log(`\n${indented}`);
512-
}
513-
514-
if (summary) {
515-
log("");
516-
if (summary.success) {
517-
renderSuccess(summary.message, opts);
518-
} else {
519-
renderError(summary.message, opts);
520-
}
521-
}
522-
}
523-
524379
export function renderSection(title: string, opts: RenderOptions): void {
525380
const { colors, log } = opts;
526381
const termWidth = Math.min(opts.columns, MAX_WIDTH);

packages/webpack-cli/src/webpack-cli.ts

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ import {
4444
renderInfo,
4545
renderInfoOutput,
4646
renderOptionHelp,
47-
renderStatsOutput,
4847
renderSuccess,
4948
renderVersionOutput,
5049
renderWarning,
@@ -119,6 +118,7 @@ interface CommandOptions<
119118
dependencies?: string[];
120119
pkg?: string;
121120
preload?: () => Promise<C>;
121+
header?: { name: string; description: string };
122122
options?:
123123
| CommandOption[]
124124
| ((command: Command & { context: C }) => CommandOption[])
@@ -692,13 +692,7 @@ class WebpackCLI {
692692
isVerbose,
693693
);
694694

695-
const canPaginate =
696-
Boolean(process.stdout.isTTY) &&
697-
Boolean(process.stdin.isTTY) &&
698-
typeof (process.stdin as NodeJS.ReadStream & { setRawMode?: unknown }).setRawMode ===
699-
"function";
700-
701-
await renderCommandHelp(commandHelpData, this.#renderOptions(), canPaginate);
695+
renderCommandHelp(commandHelpData, this.#renderOptions());
702696
renderFooter(this.#renderOptions(), { verbose: isVerbose });
703697
process.exit(0);
704698
});
@@ -1039,12 +1033,16 @@ class WebpackCLI {
10391033
}
10401034

10411035
#renderOptions(): RenderOptions {
1036+
const helpConfig = this.program.configureHelp();
1037+
const columns =
1038+
typeof helpConfig.helpWidth === "number"
1039+
? helpConfig.helpWidth
1040+
: (process.stdout.columns ?? 80);
1041+
10421042
return {
10431043
colors: this.colors,
10441044
log: (line) => this.logger.raw(line),
1045-
// process.stdout.columns can be undefined in non-TTY environments
1046-
// (CI, test runners, pipes). Fall back to 80 which fits most terminals.
1047-
columns: process.stdout.columns ?? 80,
1045+
columns,
10481046
};
10491047
}
10501048

@@ -1258,13 +1256,8 @@ class WebpackCLI {
12581256
}
12591257

12601258
const commandHelpData = this.#buildCommandHelpData(command, program, isVerbose);
1261-
const canPaginate =
1262-
Boolean(process.stdout.isTTY) &&
1263-
Boolean(process.stdin.isTTY) &&
1264-
typeof (process.stdin as NodeJS.ReadStream & { setRawMode?: unknown }).setRawMode ===
1265-
"function";
12661259

1267-
await renderCommandHelp(commandHelpData, this.#renderOptions(), canPaginate);
1260+
renderCommandHelp(commandHelpData, this.#renderOptions());
12681261
renderFooter(this.#renderOptions(), { verbose: isVerbose });
12691262
process.exit(0);
12701263
}
@@ -2935,8 +2928,6 @@ class WebpackCLI {
29352928
})
29362929
: null;
29372930

2938-
const renderOpts = this.#renderOptions();
2939-
29402931
const callback: WebpackCallback = (error, stats): void => {
29412932
if (error) {
29422933
this.logger.error(error);
@@ -3028,14 +3019,14 @@ class WebpackCLI {
30283019
message: `Compiled with ${warnCount} warning${warnCount !== 1 ? "s" : ""}${time}`,
30293020
};
30303021
} else {
3022+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
30313023
summary = { success: true, message: `Compiled successfully${time}` };
30323024
}
30333025
} catch {
30343026
// proceed without summary
30353027
}
30363028
}
30373029

3038-
renderStatsOutput(printedStats, summary, renderOpts);
30393030
onFirstBuildComplete?.();
30403031
}
30413032
};

0 commit comments

Comments
 (0)