Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c6f054a

Browse files
committedAug 18, 2020
Fix watch exiting if no plugin
1 parent 74910ff commit c6f054a

File tree

1 file changed

+28
-18
lines changed

1 file changed

+28
-18
lines changed
 

‎ci/dev/watch.ts

+28-18
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ class Watcher {
3737

3838
const vscode = cp.spawn("yarn", ["watch"], { cwd: this.vscodeSourcePath })
3939
const tsc = cp.spawn("tsc", ["--watch", "--pretty", "--preserveWatchOutput"], { cwd: this.rootPath })
40-
const plugin = cp.spawn("yarn", ["build", "--watch"], { cwd: process.env.PLUGIN_DIR })
40+
const plugin = process.env.PLUGIN_DIR
41+
? cp.spawn("yarn", ["build", "--watch"], { cwd: process.env.PLUGIN_DIR })
42+
: undefined
4143
const bundler = this.createBundler()
4244

4345
const cleanup = (code?: number | null): void => {
@@ -49,9 +51,11 @@ class Watcher {
4951
tsc.removeAllListeners()
5052
tsc.kill()
5153

52-
Watcher.log("killing plugin")
53-
plugin.removeAllListeners()
54-
plugin.kill()
54+
if (plugin) {
55+
Watcher.log("killing plugin")
56+
plugin.removeAllListeners()
57+
plugin.kill()
58+
}
5559

5660
if (server) {
5761
Watcher.log("killing server")
@@ -74,10 +78,12 @@ class Watcher {
7478
Watcher.log("tsc terminated unexpectedly")
7579
cleanup(code)
7680
})
77-
plugin.on("exit", (code) => {
78-
Watcher.log("plugin terminated unexpectedly")
79-
cleanup(code)
80-
})
81+
if (plugin) {
82+
plugin.on("exit", (code) => {
83+
Watcher.log("plugin terminated unexpectedly")
84+
cleanup(code)
85+
})
86+
}
8187
const bundle = bundler.bundle().catch(() => {
8288
Watcher.log("parcel watcher terminated unexpectedly")
8389
cleanup(1)
@@ -91,7 +97,9 @@ class Watcher {
9197

9298
vscode.stderr.on("data", (d) => process.stderr.write(d))
9399
tsc.stderr.on("data", (d) => process.stderr.write(d))
94-
plugin.stderr.on("data", (d) => process.stderr.write(d))
100+
if (plugin) {
101+
plugin.stderr.on("data", (d) => process.stderr.write(d))
102+
}
95103

96104
// From https://github.com/chalk/ansi-regex
97105
const pattern = [
@@ -151,15 +159,17 @@ class Watcher {
151159
}
152160
})
153161

154-
onLine(plugin, (line, original) => {
155-
// tsc outputs blank lines; skip them.
156-
if (line !== "") {
157-
console.log("[plugin]", original)
158-
}
159-
if (line.includes("Watching for file changes")) {
160-
bundle.then(restartServer)
161-
}
162-
})
162+
if (plugin) {
163+
onLine(plugin, (line, original) => {
164+
// tsc outputs blank lines; skip them.
165+
if (line !== "") {
166+
console.log("[plugin]", original)
167+
}
168+
if (line.includes("Watching for file changes")) {
169+
bundle.then(restartServer)
170+
}
171+
})
172+
}
163173
}
164174

165175
private createBundler(out = "dist"): Bundler {

0 commit comments

Comments
 (0)
Please sign in to comment.