print file/location/frame when encountering an initial error in dev

This commit is contained in:
Richard Harris
2019-02-22 09:28:08 -05:00
parent 411e2594af
commit 4fe3c96c2d
3 changed files with 18 additions and 8 deletions

View File

@@ -199,9 +199,10 @@ class Watcher extends EventEmitter {
}); });
manifest_data = new_manifest_data; manifest_data = new_manifest_data;
} catch (err) { } catch (error) {
this.emit('error', <ErrorEvent>{ this.emit('error', <ErrorEvent>{
message: err.message type: 'manifest',
error
}); });
} }
} }
@@ -408,11 +409,11 @@ class Watcher extends EventEmitter {
}) { }) {
compiler.oninvalid(invalid); compiler.oninvalid(invalid);
compiler.watch((err?: Error, result?: CompileResult) => { compiler.watch((error?: Error, result?: CompileResult) => {
if (err) { if (error) {
this.emit('error', <ErrorEvent>{ this.emit('error', <ErrorEvent>{
type: name, type: name,
message: err.message error
}); });
} else { } else {
this.emit('build', { this.emit('build', {

View File

@@ -89,8 +89,17 @@ prog.command('dev')
}); });
watcher.on('error', (event: ErrorEvent) => { watcher.on('error', (event: ErrorEvent) => {
console.log(colors.red(`${event.type}`)); const { type, error } = event;
console.log(colors.red(event.message));
console.log(colors.bold().red(`${type}`));
if (error.loc) {
let file = error.loc.file && `${path.relative(process.cwd(), error.loc.file)} (${error.loc.line}:${error.loc.column})`;
if (file) console.log(colors.bold(file));
}
console.log(colors.red(event.error.message));
if (error.frame) console.log(error.frame);
}); });
watcher.on('fatal', (event: FatalEvent) => { watcher.on('fatal', (event: FatalEvent) => {

View File

@@ -69,7 +69,7 @@ export type ReadyEvent = {
export type ErrorEvent = { export type ErrorEvent = {
type: string; type: string;
message: string; error: Error;
}; };
export type FatalEvent = { export type FatalEvent = {