From 00d64ab07058ee11f34cb1601802228833177b22 Mon Sep 17 00:00:00 2001 From: Asher Date: Tue, 7 Dec 2021 21:56:28 +0000 Subject: [PATCH] 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. --- ci/dev/watch.ts | 63 +++++++++--------------------------------------- src/node/util.ts | 7 ------ 2 files changed, 12 insertions(+), 58 deletions(-) diff --git a/ci/dev/watch.ts b/ci/dev/watch.ts index 0bd3c5673b73..6f7291099620 100644 --- a/ci/dev/watch.ts +++ b/ci/dev/watch.ts @@ -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 { 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 + + console.log("[VS Code]", originalLine) - 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 - - 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 { 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 { 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 } diff --git a/src/node/util.ts b/src/node/util.ts index d12ba6f0c004..24cd8b30efc0 100644 --- a/src/node/util.ts +++ b/src/node/util.ts @@ -524,14 +524,7 @@ export const loadAMDModule = async (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 }