From c6f054ad6f4dcb24d4a70525e9aeca5b395ca83b Mon Sep 17 00:00:00 2001 From: Asher Date: Tue, 18 Aug 2020 12:03:49 -0500 Subject: [PATCH] Fix watch exiting if no plugin --- ci/dev/watch.ts | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/ci/dev/watch.ts b/ci/dev/watch.ts index 73823d03..646da328 100644 --- a/ci/dev/watch.ts +++ b/ci/dev/watch.ts @@ -37,7 +37,9 @@ class Watcher { const vscode = cp.spawn("yarn", ["watch"], { cwd: this.vscodeSourcePath }) 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 cleanup = (code?: number | null): void => { @@ -49,9 +51,11 @@ class Watcher { tsc.removeAllListeners() tsc.kill() - Watcher.log("killing plugin") - plugin.removeAllListeners() - plugin.kill() + if (plugin) { + Watcher.log("killing plugin") + plugin.removeAllListeners() + plugin.kill() + } if (server) { Watcher.log("killing server") @@ -74,10 +78,12 @@ class Watcher { Watcher.log("tsc terminated unexpectedly") cleanup(code) }) - plugin.on("exit", (code) => { - Watcher.log("plugin terminated unexpectedly") - cleanup(code) - }) + if (plugin) { + plugin.on("exit", (code) => { + Watcher.log("plugin terminated unexpectedly") + cleanup(code) + }) + } const bundle = bundler.bundle().catch(() => { Watcher.log("parcel watcher terminated unexpectedly") cleanup(1) @@ -91,7 +97,9 @@ class Watcher { vscode.stderr.on("data", (d) => process.stderr.write(d)) tsc.stderr.on("data", (d) => process.stderr.write(d)) - plugin.stderr.on("data", (d) => process.stderr.write(d)) + if (plugin) { + plugin.stderr.on("data", (d) => process.stderr.write(d)) + } // From https://github.com/chalk/ansi-regex const pattern = [ @@ -151,15 +159,17 @@ class Watcher { } }) - onLine(plugin, (line, original) => { - // tsc outputs blank lines; skip them. - if (line !== "") { - console.log("[plugin]", original) - } - if (line.includes("Watching for file changes")) { - bundle.then(restartServer) - } - }) + if (plugin) { + onLine(plugin, (line, original) => { + // tsc outputs blank lines; skip them. + if (line !== "") { + console.log("[plugin]", original) + } + if (line.includes("Watching for file changes")) { + bundle.then(restartServer) + } + }) + } } private createBundler(out = "dist"): Bundler {