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

Commit 5375422

Browse files
authored
Merge pull request #285 from sveltejs/event-on-exit
emit a fatal event if server crashes
2 parents 8f3454c + 0800fa0 commit 5375422

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/api/dev.ts

+17
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ class Watcher extends EventEmitter {
130130
// TODO watch the configs themselves?
131131
const compilers = create_compilers({ webpack: this.dirs.webpack });
132132

133+
const emitFatal = () => {
134+
this.emit('fatal', <events.FatalEvent>{
135+
message: `Server crashed`
136+
});
137+
};
138+
133139
this.watch(compilers.server, {
134140
name: 'server',
135141

@@ -158,6 +164,7 @@ class Watcher extends EventEmitter {
158164
};
159165

160166
if (this.proc) {
167+
this.proc.removeListener('exit', emitFatal);
161168
this.proc.kill();
162169
this.proc.on('exit', restart);
163170
} else {
@@ -172,13 +179,23 @@ class Watcher extends EventEmitter {
172179
stdio: ['ipc']
173180
});
174181

182+
this.proc.stdout.on('data', chunk => {
183+
this.emit('stdout', chunk);
184+
});
185+
186+
this.proc.stderr.on('data', chunk => {
187+
this.emit('stderr', chunk);
188+
});
189+
175190
this.proc.on('message', message => {
176191
if (message.__sapper__ && message.event === 'basepath') {
177192
this.emit('basepath', {
178193
basepath: message.basepath
179194
});
180195
}
181196
});
197+
198+
this.proc.on('exit', emitFatal);
182199
});
183200
}
184201
});

0 commit comments

Comments
 (0)