Skip to content

Remove excessive reloading before VS Code is ready #4589

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 12 additions & 51 deletions ci/dev/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
})

Expand All @@ -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()
}
}

Expand All @@ -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()
}
}
Expand All @@ -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/**/*"])
}

/**
Expand All @@ -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
}

Expand Down
7 changes: 0 additions & 7 deletions src/node/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down