Skip to content

Commit

Permalink
feat: add entry name in console output
Browse files Browse the repository at this point in the history
Useful for quickly identifying the error source.
  • Loading branch information
swashata committed Aug 6, 2020
1 parent 480f190 commit e1e4599
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
24 changes: 16 additions & 8 deletions packages/scripts/src/bin/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,33 +162,41 @@ export function serve(options: ProgramOptions | undefined): void {
printGeneralInfoMessage(`changed: ${chalk.bold(file)}`);
printGeneralInfoMessage('reloading browser');
},
onTcStart() {
printGeneralInfoMessage('waiting for typecheck results...');
onTcStart(name) {
const msg = `${
name ? `[${chalk.green(name)}] ` : ''
}waiting for typecheck results...`;
printGeneralInfoMessage(msg);
},
onInfo(msg: string, symbol: string) {
printGeneralInfoMessage(msg, symbol);
},
onTcEnd(messages) {
const name = messages.name;
if (messages.errors.length || messages.warnings.length) {
if (messages.errors.length) {
printErrorHeading('TS ERROR');
printErrorHeading(
`${name ? `[${name}] ` : ''}TS ERROR`
);
messages.errors.forEach(e => {
console.log(e);
console.log('');
});
}
if (messages.warnings.length) {
printWarningHeading('TS WARNING');
printWarningHeading(
`${name ? `[${name}] ` : ''}TS WARNING`
);
messages.warnings.forEach(e => {
console.log(e);
console.log('');
});
}
} else {
printGeneralInfoMessage(
'no typecheck errors',
logSymbols.success
);
const msg = `${
name ? `[${chalk.green(name)}] ` : ''
}no typecheck errors`;
printGeneralInfoMessage(msg, logSymbols.success);
}
},
},
Expand Down
4 changes: 2 additions & 2 deletions packages/scripts/src/bin/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export function printCompileTimeMessage(stat: any, lastStat: any | null) {
} else if (stat.warnings.length) {
name = chalk.yellow(entryName);
}
name = `${name} `;
name = `[${name}] `;
}

// get log symbol
Expand All @@ -108,7 +108,7 @@ export function printCompileTimeMessage(stat: any, lastStat: any | null) {

console.log(
addTimeStampToLog(
`${symbol} bundle ${name}${msg} ${chalk.magenta(
`${symbol} ${name}bundle ${msg} ${chalk.magenta(
`${stat.time}ms`
)}.`
)
Expand Down
7 changes: 5 additions & 2 deletions packages/scripts/src/scripts/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { WpackioError } from '../errors/WpackioError';
interface FormattedMessage {
errors: string[];
warnings: string[];
name?: string;
}

interface Callbacks {
Expand All @@ -31,7 +32,7 @@ interface Callbacks {
onWarn(warn: FormattedMessage): void;
onBsChange(file: string): void;
onEmit(stats: webpack.Stats): void;
onTcStart(): void;
onTcStart(name?: string): void;
onTcEnd(err: FormattedMessage): void;
onWatching(): void;
onInfo(msg: string, symbol: string): void;
Expand Down Expand Up @@ -414,6 +415,7 @@ export class Server {
tsMessagesResolver({
errors: [],
warnings: [],
name: compiler.name,
});
}
}
Expand All @@ -438,14 +440,15 @@ export class Server {
warnings: issues
.filter(msg => msg.severity === 'warning')
.map(format),
name: compiler.name,
});
});

// Once compilation is done, then show the message
done.tap('wpackIoServerDoneTs', async () => {
if (this.firstCompileCompleted) {
const delayedMsg = setTimeout(() => {
this.callbacks.onTcStart();
this.callbacks.onTcStart(compiler.name);
}, 100);
try {
const messages = await tsMessagesPromise;
Expand Down

0 comments on commit e1e4599

Please sign in to comment.