mirror of
https://github.com/coder/code-server.git
synced 2026-02-05 06:23:35 -06:00
* Remove extra VS Code CLI spawn We already spawn VS Code's CLI when necessary in the lines below. Having the CLI spawn unconditionally when in a VS Code environment makes it impossible to run code-server within code-server (for example to develop it). * Update VS Code This sanitizes our environment variables so code-server does not always think it is a child spawn. Fixes https://github.com/cdr/code-server/issues/4519.
76 lines
2.4 KiB
TypeScript
76 lines
2.4 KiB
TypeScript
import { logger } from "@coder/logger"
|
|
import { optionDescriptions, parse, readConfigFile, setDefaults, shouldOpenInExistingInstance } from "./cli"
|
|
import { commit, version } from "./constants"
|
|
import { openInExistingInstance, runCodeServer, runVsCodeCli, shouldSpawnCliProcess } from "./main"
|
|
import { monkeyPatchProxyProtocols } from "./proxy_agent"
|
|
import { isChild, wrapper } from "./wrapper"
|
|
|
|
async function entry(): Promise<void> {
|
|
monkeyPatchProxyProtocols()
|
|
|
|
// There's no need to check flags like --help or to spawn in an existing
|
|
// instance for the child process because these would have already happened in
|
|
// the parent and the child wouldn't have been spawned. We also get the
|
|
// arguments from the parent so we don't have to parse twice and to account
|
|
// for environment manipulation (like how PASSWORD gets removed to avoid
|
|
// leaking to child processes).
|
|
if (isChild(wrapper)) {
|
|
const args = await wrapper.handshake()
|
|
wrapper.preventExit()
|
|
const server = await runCodeServer(args)
|
|
wrapper.onDispose(() => server.dispose())
|
|
return
|
|
}
|
|
|
|
const cliArgs = parse(process.argv.slice(2))
|
|
const configArgs = await readConfigFile(cliArgs.config)
|
|
const args = await setDefaults(cliArgs, configArgs)
|
|
|
|
if (args.help) {
|
|
console.log("code-server", version, commit)
|
|
console.log("")
|
|
console.log(`Usage: code-server [options] [path]`)
|
|
console.log(` - Opening a directory: code-server ./path/to/your/project`)
|
|
console.log(` - Opening a saved workspace: code-server ./path/to/your/project.code-workspace`)
|
|
console.log("")
|
|
console.log("Options")
|
|
optionDescriptions().forEach((description) => {
|
|
console.log("", description)
|
|
})
|
|
return
|
|
}
|
|
|
|
if (args.version) {
|
|
if (args.json) {
|
|
console.log(
|
|
JSON.stringify({
|
|
codeServer: version,
|
|
commit,
|
|
vscode: require("../../vendor/modules/code-oss-dev/package.json").version,
|
|
}),
|
|
)
|
|
} else {
|
|
console.log(version, commit)
|
|
}
|
|
return
|
|
}
|
|
|
|
if (shouldSpawnCliProcess(args)) {
|
|
logger.debug("Found VS Code arguments; spawning VS Code CLI")
|
|
return runVsCodeCli(args)
|
|
}
|
|
|
|
const socketPath = await shouldOpenInExistingInstance(cliArgs)
|
|
if (socketPath) {
|
|
logger.debug("Trying to open in existing instance")
|
|
return openInExistingInstance(args, socketPath)
|
|
}
|
|
|
|
return wrapper.start(args)
|
|
}
|
|
|
|
entry().catch((error) => {
|
|
logger.error(error.message)
|
|
wrapper.exit(error)
|
|
})
|