From 0800fa016b315b2dc9e7d48c872a2bfd66446faa Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 16 Jun 2018 20:18:32 -0400 Subject: [PATCH] emit a fatal event if server crashes --- src/api/dev.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/api/dev.ts b/src/api/dev.ts index 7f87781..a70bdd6 100644 --- a/src/api/dev.ts +++ b/src/api/dev.ts @@ -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', { + message: `Server crashed` + }); + }; + this.watch(compilers.server, { name: 'server', @@ -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 { @@ -172,6 +179,14 @@ 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', { @@ -179,6 +194,8 @@ class Watcher extends EventEmitter { }); } }); + + this.proc.on('exit', emitFatal); }); } });