mirror of
https://github.com/coder/code-server.git
synced 2026-05-24 13:17:28 +02:00
Fix issues surrounding initial web server load. (#4509)
- Clean up watcher behaviors.
This commit is contained in:
@@ -3,14 +3,15 @@ import * as argon2 from "argon2"
|
||||
import * as cp from "child_process"
|
||||
import * as crypto from "crypto"
|
||||
import envPaths from "env-paths"
|
||||
import { promises as fs } from "fs"
|
||||
import { promises as fs, Stats } from "fs"
|
||||
import * as net from "net"
|
||||
import * as os from "os"
|
||||
import * as path from "path"
|
||||
import safeCompare from "safe-compare"
|
||||
import * as util from "util"
|
||||
import xdgBasedir from "xdg-basedir"
|
||||
import { vsRootPath } from "./constants"
|
||||
import { logError } from "../common/util"
|
||||
import { isDevMode, rootPath, vsRootPath } from "./constants"
|
||||
|
||||
export interface Paths {
|
||||
data: string
|
||||
@@ -25,10 +26,11 @@ const pattern = [
|
||||
].join("|")
|
||||
const re = new RegExp(pattern, "g")
|
||||
|
||||
export type OnLineCallback = (strippedLine: string, originalLine: string) => void
|
||||
/**
|
||||
* Split stdout on newlines and strip ANSI codes.
|
||||
*/
|
||||
export const onLine = (proc: cp.ChildProcess, callback: (strippedLine: string, originalLine: string) => void): void => {
|
||||
export const onLine = (proc: cp.ChildProcess, callback: OnLineCallback): void => {
|
||||
let buffer = ""
|
||||
if (!proc.stdout) {
|
||||
throw new Error("no stdout")
|
||||
@@ -521,3 +523,41 @@ 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
|
||||
}
|
||||
|
||||
export const readCompilationStats = async (): Promise<null | CompilationStats> => {
|
||||
if (!isDevMode) {
|
||||
throw new Error("Compilation stats are only present in development")
|
||||
}
|
||||
|
||||
const filePath = path.join(rootPath, "out/watcher.json")
|
||||
let stat: Stats
|
||||
try {
|
||||
stat = await fs.stat(filePath)
|
||||
} catch (error) {
|
||||
return null
|
||||
}
|
||||
|
||||
if (!stat.isFile()) {
|
||||
return null
|
||||
}
|
||||
|
||||
try {
|
||||
const file = await fs.readFile(filePath)
|
||||
return JSON.parse(file.toString("utf-8"))
|
||||
} catch (error) {
|
||||
logError(logger, "VS Code", error)
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user