Skip to content

Commit 806489d

Browse files
authored
Merge branch 'main' into fix-spawn
2 parents 64c192a + c3eb9b8 commit 806489d

File tree

2 files changed

+12
-58
lines changed

2 files changed

+12
-58
lines changed

ci/dev/watch.ts

+12-51
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
}
@@ -153,11 +127,7 @@ class Watcher {
153127
private cleanFiles(): Promise<string[]> {
154128
console.log("[Watcher]", "Cleaning files from previous builds...")
155129

156-
return del([
157-
"out/**/*",
158-
// Included because the cache can sometimes enter bad state when debugging compiled files.
159-
".cache/**/*",
160-
])
130+
return del(["out/**/*"])
161131
}
162132

163133
/**
@@ -166,31 +136,22 @@ class Watcher {
166136
*/
167137
private emitCompilationStats(): Promise<void> {
168138
const stats: CompilationStats = {
169-
status: this.vscodeCompileStatus,
170139
lastCompiledAt: new Date(),
171140
}
172141

173-
this.log("Writing watcher stats...")
142+
console.log("Writing watcher stats...")
174143
return fs.writeFile(this.paths.compilationStatsFile, JSON.stringify(stats, null, 2))
175144
}
176145

177-
private log(...entries: string[]) {
178-
process.stdout.write(entries.join(" "))
179-
}
180-
181146
private dispose(code: number | null): void {
182147
for (const [processName, devProcess] of Object.entries(this.compilers)) {
183-
this.log(`[${processName}]`, "Killing...\n")
148+
console.log(`[${processName}]`, "Killing...\n")
184149
devProcess?.removeAllListeners()
185150
devProcess?.kill()
186151
}
187152
process.exit(typeof code === "number" ? code : 0)
188153
}
189154

190-
private get hasVerboseLogging() {
191-
return process.argv.includes("--log")
192-
}
193-
194155
//#endregion
195156
}
196157

src/node/util.ts

-7
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)