Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

emit a fatal event if server crashes #285

Merged
merged 1 commit into from
Jun 17, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/api/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ class Watcher extends EventEmitter {
// TODO watch the configs themselves?
const compilers = create_compilers({ webpack: this.dirs.webpack });

const emitFatal = () => {
this.emit('fatal', <events.FatalEvent>{
message: `Server crashed`
});
};

this.watch(compilers.server, {
name: 'server',

Expand Down Expand Up @@ -158,6 +164,7 @@ class Watcher extends EventEmitter {
};

if (this.proc) {
this.proc.removeListener('exit', emitFatal);
this.proc.kill();
this.proc.on('exit', restart);
} else {
Expand All @@ -172,13 +179,23 @@ class Watcher extends EventEmitter {
stdio: ['ipc']
});

this.proc.stdout.on('data', chunk => {
this.emit('stdout', chunk);
});

this.proc.stderr.on('data', chunk => {
this.emit('stderr', chunk);
});

this.proc.on('message', message => {
if (message.__sapper__ && message.event === 'basepath') {
this.emit('basepath', {
basepath: message.basepath
});
}
});

this.proc.on('exit', emitFatal);
});
}
});
Expand Down