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 3bfcbc7

Browse files
committedDec 7, 2021
Reduce excessive reloading before VS Code is ready
The watch script was reloading the web server after every extension compilation which is not necessary plus VS Code will not even be ready at that point anyway. Instead restart when the main compilation is finished. The string to match with includes a "with" because otherwise it would match "Finished compilation extensions" which is not the main compilation task where we actually need to restart the web server. I also replaced this.log with console.log because the former does not include a newline and it appears we want newlines with all these (otherwise the next log starts on the same line which looks odd). I removed the cache clean as well because the cache is meant to stay there to speed up builds.
1 parent d15731a commit 3bfcbc7

File tree

2 files changed

+11
-55
lines changed

2 files changed

+11
-55
lines changed
 

‎ci/dev/watch.ts

Lines changed: 11 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { spawn, fork, ChildProcess } from "child_process"
22
import del from "del"
33
import { promises as fs } from "fs"
44
import * as path from "path"
5-
import { CompilationStats, onLine, OnLineCallback, VSCodeCompileStatus } from "../../src/node/util"
5+
import { CompilationStats, onLine, OnLineCallback } from "../../src/node/util"
66

77
interface DevelopmentCompilers {
88
[key: string]: ChildProcess | undefined
@@ -52,24 +52,18 @@ class Watcher {
5252
plugins: this.paths.pluginDir ? spawn("yarn", ["build", "--watch"], { cwd: this.paths.pluginDir }) : undefined,
5353
}
5454

55-
private vscodeCompileStatus = VSCodeCompileStatus.Loading
56-
5755
public async initialize(): Promise<void> {
5856
for (const event of ["SIGINT", "SIGTERM"]) {
5957
process.on(event, () => this.dispose(0))
6058
}
6159

62-
if (!this.hasVerboseLogging) {
63-
console.log("\n[Watcher]", "Compiler logs will be minimal. Pass --log to show all output.")
64-
}
65-
6660
this.cleanFiles()
6761

6862
for (const [processName, devProcess] of Object.entries(this.compilers)) {
6963
if (!devProcess) continue
7064

7165
devProcess.on("exit", (code) => {
72-
this.log(`[${processName}]`, "Terminated unexpectedly")
66+
console.log(`[${processName}]`, "Terminated unexpectedly")
7367
this.dispose(code)
7468
})
7569

@@ -91,33 +85,14 @@ class Watcher {
9185
//#region Line Parsers
9286

9387
private parseVSCodeLine: OnLineCallback = (strippedLine, originalLine) => {
94-
if (!strippedLine.includes("watch-extensions") || this.hasVerboseLogging) {
95-
console.log("[VS Code]", originalLine)
96-
}
88+
if (!strippedLine.length) return
89+
90+
console.log("[VS Code]", originalLine)
9791

98-
switch (this.vscodeCompileStatus) {
99-
case VSCodeCompileStatus.Loading:
100-
// Wait for watch-client since "Finished compilation" will appear multiple
101-
// times before the client starts building.
102-
if (strippedLine.includes("Starting 'watch-client'")) {
103-
console.log("[VS Code] 🚧 Compiling 🚧", "(This may take a moment!)")
104-
this.vscodeCompileStatus = VSCodeCompileStatus.Compiling
105-
}
106-
break
107-
case VSCodeCompileStatus.Compiling:
108-
if (strippedLine.includes("Finished compilation")) {
109-
console.log("[VS Code] ✨ Finished compiling! ✨", "(Refresh your web browser ♻️)")
110-
this.vscodeCompileStatus = VSCodeCompileStatus.Compiled
111-
112-
this.emitCompilationStats()
113-
this.reloadWebServer()
114-
}
115-
break
116-
case VSCodeCompileStatus.Compiled:
117-
console.log("[VS Code] 🔔 Finished recompiling! 🔔", "(Refresh your web browser ♻️)")
118-
this.emitCompilationStats()
119-
this.reloadWebServer()
120-
break
92+
if (strippedLine.includes("Finished compilation with")) {
93+
console.log("[VS Code] ✨ Finished compiling! ✨", "(Refresh your web browser ♻️)")
94+
this.emitCompilationStats()
95+
this.reloadWebServer()
12196
}
12297
}
12398

@@ -128,7 +103,6 @@ class Watcher {
128103

129104
if (strippedLine.includes("Watching for file changes")) {
130105
console.log("[Compiler][Code Server]", "Finished compiling!", "(Refresh your web browser ♻️)")
131-
132106
this.reloadWebServer()
133107
}
134108
}
@@ -155,8 +129,6 @@ class Watcher {
155129

156130
return del([
157131
"out/**/*",
158-
// Included because the cache can sometimes enter bad state when debugging compiled files.
159-
".cache/**/*",
160132
])
161133
}
162134

@@ -166,31 +138,22 @@ class Watcher {
166138
*/
167139
private emitCompilationStats(): Promise<void> {
168140
const stats: CompilationStats = {
169-
status: this.vscodeCompileStatus,
170141
lastCompiledAt: new Date(),
171142
}
172143

173-
this.log("Writing watcher stats...")
144+
console.log("Writing watcher stats...")
174145
return fs.writeFile(this.paths.compilationStatsFile, JSON.stringify(stats, null, 2))
175146
}
176147

177-
private log(...entries: string[]) {
178-
process.stdout.write(entries.join(" "))
179-
}
180-
181148
private dispose(code: number | null): void {
182149
for (const [processName, devProcess] of Object.entries(this.compilers)) {
183-
this.log(`[${processName}]`, "Killing...\n")
150+
console.log(`[${processName}]`, "Killing...\n")
184151
devProcess?.removeAllListeners()
185152
devProcess?.kill()
186153
}
187154
process.exit(typeof code === "number" ? code : 0)
188155
}
189156

190-
private get hasVerboseLogging() {
191-
return process.argv.includes("--log")
192-
}
193-
194157
//#endregion
195158
}
196159

‎src/node/util.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -524,14 +524,7 @@ export const loadAMDModule = async <T>(amdPath: string, exportName: string): Pro
524524
return module[exportName] as T
525525
}
526526

527-
export const enum VSCodeCompileStatus {
528-
Loading = "Loading",
529-
Compiling = "Compiling",
530-
Compiled = "Compiled",
531-
}
532-
533527
export interface CompilationStats {
534-
status: VSCodeCompileStatus
535528
lastCompiledAt: Date
536529
}
537530

0 commit comments

Comments
 (0)
Please sign in to comment.