Fix watch exiting if no plugin
This commit is contained in:
parent
74910ffcdf
commit
c6f054ad6f
@ -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()
|
||||||
|
|
||||||
Watcher.log("killing plugin")
|
if (plugin) {
|
||||||
plugin.removeAllListeners()
|
Watcher.log("killing plugin")
|
||||||
plugin.kill()
|
plugin.removeAllListeners()
|
||||||
|
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)
|
||||||
})
|
})
|
||||||
plugin.on("exit", (code) => {
|
if (plugin) {
|
||||||
Watcher.log("plugin terminated unexpectedly")
|
plugin.on("exit", (code) => {
|
||||||
cleanup(code)
|
Watcher.log("plugin terminated unexpectedly")
|
||||||
})
|
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))
|
||||||
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
|
// From https://github.com/chalk/ansi-regex
|
||||||
const pattern = [
|
const pattern = [
|
||||||
@ -151,15 +159,17 @@ class Watcher {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
onLine(plugin, (line, original) => {
|
if (plugin) {
|
||||||
// tsc outputs blank lines; skip them.
|
onLine(plugin, (line, original) => {
|
||||||
if (line !== "") {
|
// tsc outputs blank lines; skip them.
|
||||||
console.log("[plugin]", original)
|
if (line !== "") {
|
||||||
}
|
console.log("[plugin]", original)
|
||||||
if (line.includes("Watching for file changes")) {
|
}
|
||||||
bundle.then(restartServer)
|
if (line.includes("Watching for file changes")) {
|
||||||
}
|
bundle.then(restartServer)
|
||||||
})
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private createBundler(out = "dist"): Bundler {
|
private createBundler(out = "dist"): Bundler {
|
||||||
|
Loading…
Reference in New Issue
Block a user