Skip to content

Commit 5ac6834

Browse files
committed
feat(serve): collapse numbered chunk output and summarize
This commit hides the following output: ``` [ng] chunk {1} 1.js, 1.js.map () 93.4 kB [rendered] [ng] chunk {2} 2.js, 2.js.map () 1.85 kB [rendered] [ng] chunk {3} 3.js, 3.js.map () 1.06 kB [rendered] ... ``` These chunks aren't app code, so it's not so useful to show.
1 parent b37fa03 commit 5ac6834

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

packages/ionic/src/lib/project/angular/serve.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import chalk from 'chalk';
22

33
import { CommandGroup, OptionGroup, ParsedArgs, unparseArgs } from '@ionic/cli-framework';
4+
import { stripAnsi } from '@ionic/cli-framework/utils/format';
45
import { findClosestOpenPort } from '@ionic/utils-network';
56

67
import { AngularServeOptions, CommandLineInputs, CommandLineOptions, CommandMetadata, ServeDetails } from '../../../definitions';
@@ -116,17 +117,40 @@ export class AngularServeCLI extends ServeCLI<AngularServeOptions> {
116117
readonly program = 'ng';
117118
readonly prefix = 'ng';
118119
readonly script = SERVE_SCRIPT;
120+
protected chunks = 0;
121+
122+
async serve(options: AngularServeOptions): Promise<void> {
123+
this.on('compile', chunks => {
124+
if (chunks > 0) {
125+
this.e.log.info(`... and ${chalk.bold(chunks.toString())} additional chunks`);
126+
}
127+
});
128+
129+
return super.serve(options);
130+
}
119131

120132
protected stdoutFilter(line: string): boolean {
121133
if (this.resolvedProgram !== this.program) {
122134
return super.stdoutFilter(line);
123135
}
124136

125-
if (line.includes('Development Server is listening')) {
137+
const strippedLine = stripAnsi(line);
138+
139+
if (strippedLine.includes('Development Server is listening')) {
126140
this.emit('ready');
127141
return false;
128142
}
129143

144+
if (strippedLine.match(/.*chunk\s{\d+}.+/)) {
145+
this.chunks++;
146+
return false;
147+
}
148+
149+
if (strippedLine.includes('Compiled successfully')) {
150+
this.emit('compile', this.chunks);
151+
this.chunks = 0;
152+
}
153+
130154
return true;
131155
}
132156

packages/ionic/src/lib/serve.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,12 @@ export interface ServeCLIOptions {
386386
}
387387

388388
export interface ServeCLI<T extends ServeCLIOptions> {
389+
emit(event: 'compile', chunks: number): boolean;
390+
emit(event: 'ready'): boolean;
391+
on(event: 'compile', handler: (chunks: number) => void): this;
389392
on(event: 'ready', handler: () => void): this;
393+
once(event: 'compile', handler: (chunks: number) => void): this;
390394
once(event: 'ready', handler: () => void): this;
391-
emit(event: 'ready'): boolean;
392395
}
393396

394397
export abstract class ServeCLI<T extends ServeCLIOptions> extends EventEmitter {

0 commit comments

Comments
 (0)