Archived
1
0

Fix watch exiting if no plugin

This commit is contained in:
Asher 2020-08-18 12:03:49 -05:00
parent 74910ffcdf
commit c6f054ad6f
No known key found for this signature in database
GPG Key ID: D63C1EF81242354A

View File

@ -37,7 +37,9 @@ class Watcher {
const vscode = cp.spawn("yarn", ["watch"], { cwd: this.vscodeSourcePath }) const vscode = cp.spawn("yarn", ["watch"], { cwd: this.vscodeSourcePath })
const tsc = cp.spawn("tsc", ["--watch", "--pretty", "--preserveWatchOutput"], { cwd: this.rootPath }) const tsc = cp.spawn("tsc", ["--watch", "--pretty", "--preserveWatchOutput"], { cwd: this.rootPath })
const plugin = cp.spawn("yarn", ["build", "--watch"], { cwd: process.env.PLUGIN_DIR }) const plugin = process.env.PLUGIN_DIR
? cp.spawn("yarn", ["build", "--watch"], { cwd: process.env.PLUGIN_DIR })
: undefined
const bundler = this.createBundler() const bundler = this.createBundler()
const cleanup = (code?: number | null): void => { const cleanup = (code?: number | null): void => {
@ -49,9 +51,11 @@ class Watcher {
tsc.removeAllListeners() tsc.removeAllListeners()
tsc.kill() tsc.kill()
if (plugin) {
Watcher.log("killing plugin") Watcher.log("killing plugin")
plugin.removeAllListeners() plugin.removeAllListeners()
plugin.kill() plugin.kill()
}
if (server) { if (server) {
Watcher.log("killing server") Watcher.log("killing server")
@ -74,10 +78,12 @@ class Watcher {
Watcher.log("tsc terminated unexpectedly") Watcher.log("tsc terminated unexpectedly")
cleanup(code) cleanup(code)
}) })
if (plugin) {
plugin.on("exit", (code) => { plugin.on("exit", (code) => {
Watcher.log("plugin terminated unexpectedly") Watcher.log("plugin terminated unexpectedly")
cleanup(code) cleanup(code)
}) })
}
const bundle = bundler.bundle().catch(() => { const bundle = bundler.bundle().catch(() => {
Watcher.log("parcel watcher terminated unexpectedly") Watcher.log("parcel watcher terminated unexpectedly")
cleanup(1) cleanup(1)
@ -91,7 +97,9 @@ class Watcher {
vscode.stderr.on("data", (d) => process.stderr.write(d)) vscode.stderr.on("data", (d) => process.stderr.write(d))
tsc.stderr.on("data", (d) => process.stderr.write(d)) tsc.stderr.on("data", (d) => process.stderr.write(d))
if (plugin) {
plugin.stderr.on("data", (d) => process.stderr.write(d)) plugin.stderr.on("data", (d) => process.stderr.write(d))
}
// From https://github.com/chalk/ansi-regex // From https://github.com/chalk/ansi-regex
const pattern = [ const pattern = [
@ -151,6 +159,7 @@ class Watcher {
} }
}) })
if (plugin) {
onLine(plugin, (line, original) => { onLine(plugin, (line, original) => {
// tsc outputs blank lines; skip them. // tsc outputs blank lines; skip them.
if (line !== "") { if (line !== "") {
@ -161,6 +170,7 @@ class Watcher {
} }
}) })
} }
}
private createBundler(out = "dist"): Bundler { private createBundler(out = "dist"): Bundler {
return new Bundler( return new Bundler(