Remove excessive reloading before VS Code is ready (#4589)
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.
This commit is contained in:
parent
6c9c84090e
commit
c3eb9b800e
@ -2,7 +2,7 @@ import { spawn, fork, ChildProcess } from "child_process"
|
||||
import del from "del"
|
||||
import { promises as fs } from "fs"
|
||||
import * as path from "path"
|
||||
import { CompilationStats, onLine, OnLineCallback, VSCodeCompileStatus } from "../../src/node/util"
|
||||
import { CompilationStats, onLine, OnLineCallback } from "../../src/node/util"
|
||||
|
||||
interface DevelopmentCompilers {
|
||||
[key: string]: ChildProcess | undefined
|
||||
@ -52,24 +52,18 @@ class Watcher {
|
||||
plugins: this.paths.pluginDir ? spawn("yarn", ["build", "--watch"], { cwd: this.paths.pluginDir }) : undefined,
|
||||
}
|
||||
|
||||
private vscodeCompileStatus = VSCodeCompileStatus.Loading
|
||||
|
||||
public async initialize(): Promise<void> {
|
||||
for (const event of ["SIGINT", "SIGTERM"]) {
|
||||
process.on(event, () => this.dispose(0))
|
||||
}
|
||||
|
||||
if (!this.hasVerboseLogging) {
|
||||
console.log("\n[Watcher]", "Compiler logs will be minimal. Pass --log to show all output.")
|
||||
}
|
||||
|
||||
this.cleanFiles()
|
||||
|
||||
for (const [processName, devProcess] of Object.entries(this.compilers)) {
|
||||
if (!devProcess) continue
|
||||
|
||||
devProcess.on("exit", (code) => {
|
||||
this.log(`[${processName}]`, "Terminated unexpectedly")
|
||||
console.log(`[${processName}]`, "Terminated unexpectedly")
|
||||
this.dispose(code)
|
||||
})
|
||||
|
||||
@ -91,33 +85,14 @@ class Watcher {
|
||||
//#region Line Parsers
|
||||
|
||||
private parseVSCodeLine: OnLineCallback = (strippedLine, originalLine) => {
|
||||
if (!strippedLine.includes("watch-extensions") || this.hasVerboseLogging) {
|
||||
console.log("[VS Code]", originalLine)
|
||||
}
|
||||
if (!strippedLine.length) return
|
||||
|
||||
switch (this.vscodeCompileStatus) {
|
||||
case VSCodeCompileStatus.Loading:
|
||||
// Wait for watch-client since "Finished compilation" will appear multiple
|
||||
// times before the client starts building.
|
||||
if (strippedLine.includes("Starting 'watch-client'")) {
|
||||
console.log("[VS Code] 🚧 Compiling 🚧", "(This may take a moment!)")
|
||||
this.vscodeCompileStatus = VSCodeCompileStatus.Compiling
|
||||
}
|
||||
break
|
||||
case VSCodeCompileStatus.Compiling:
|
||||
if (strippedLine.includes("Finished compilation")) {
|
||||
console.log("[VS Code] ✨ Finished compiling! ✨", "(Refresh your web browser ♻️)")
|
||||
this.vscodeCompileStatus = VSCodeCompileStatus.Compiled
|
||||
console.log("[VS Code]", originalLine)
|
||||
|
||||
this.emitCompilationStats()
|
||||
this.reloadWebServer()
|
||||
}
|
||||
break
|
||||
case VSCodeCompileStatus.Compiled:
|
||||
console.log("[VS Code] 🔔 Finished recompiling! 🔔", "(Refresh your web browser ♻️)")
|
||||
this.emitCompilationStats()
|
||||
this.reloadWebServer()
|
||||
break
|
||||
if (strippedLine.includes("Finished compilation with")) {
|
||||
console.log("[VS Code] ✨ Finished compiling! ✨", "(Refresh your web browser ♻️)")
|
||||
this.emitCompilationStats()
|
||||
this.reloadWebServer()
|
||||
}
|
||||
}
|
||||
|
||||
@ -128,7 +103,6 @@ class Watcher {
|
||||
|
||||
if (strippedLine.includes("Watching for file changes")) {
|
||||
console.log("[Compiler][Code Server]", "Finished compiling!", "(Refresh your web browser ♻️)")
|
||||
|
||||
this.reloadWebServer()
|
||||
}
|
||||
}
|
||||
@ -153,11 +127,7 @@ class Watcher {
|
||||
private cleanFiles(): Promise<string[]> {
|
||||
console.log("[Watcher]", "Cleaning files from previous builds...")
|
||||
|
||||
return del([
|
||||
"out/**/*",
|
||||
// Included because the cache can sometimes enter bad state when debugging compiled files.
|
||||
".cache/**/*",
|
||||
])
|
||||
return del(["out/**/*"])
|
||||
}
|
||||
|
||||
/**
|
||||
@ -166,31 +136,22 @@ class Watcher {
|
||||
*/
|
||||
private emitCompilationStats(): Promise<void> {
|
||||
const stats: CompilationStats = {
|
||||
status: this.vscodeCompileStatus,
|
||||
lastCompiledAt: new Date(),
|
||||
}
|
||||
|
||||
this.log("Writing watcher stats...")
|
||||
console.log("Writing watcher stats...")
|
||||
return fs.writeFile(this.paths.compilationStatsFile, JSON.stringify(stats, null, 2))
|
||||
}
|
||||
|
||||
private log(...entries: string[]) {
|
||||
process.stdout.write(entries.join(" "))
|
||||
}
|
||||
|
||||
private dispose(code: number | null): void {
|
||||
for (const [processName, devProcess] of Object.entries(this.compilers)) {
|
||||
this.log(`[${processName}]`, "Killing...\n")
|
||||
console.log(`[${processName}]`, "Killing...\n")
|
||||
devProcess?.removeAllListeners()
|
||||
devProcess?.kill()
|
||||
}
|
||||
process.exit(typeof code === "number" ? code : 0)
|
||||
}
|
||||
|
||||
private get hasVerboseLogging() {
|
||||
return process.argv.includes("--log")
|
||||
}
|
||||
|
||||
//#endregion
|
||||
}
|
||||
|
||||
|
@ -524,14 +524,7 @@ export const loadAMDModule = async <T>(amdPath: string, exportName: string): Pro
|
||||
return module[exportName] as T
|
||||
}
|
||||
|
||||
export const enum VSCodeCompileStatus {
|
||||
Loading = "Loading",
|
||||
Compiling = "Compiling",
|
||||
Compiled = "Compiled",
|
||||
}
|
||||
|
||||
export interface CompilationStats {
|
||||
status: VSCodeCompileStatus
|
||||
lastCompiledAt: Date
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user