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

Commit

Permalink
Merge pull request #285 from sveltejs/event-on-exit
Browse files Browse the repository at this point in the history
emit a fatal event if server crashes
  • Loading branch information
Rich-Harris authored Jun 17, 2018
2 parents 8f3454c + 0800fa0 commit 5375422
Showing 1 changed file with 17 additions and 0 deletions.
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

0 comments on commit 5375422

Please sign in to comment.