Skip to content

Commit d5b4f64

Browse files
committed
Use CLI directly.
1 parent e81a37e commit d5b4f64

File tree

5 files changed

+41
-33
lines changed

5 files changed

+41
-33
lines changed

src/node/cli.ts

-15
Original file line numberDiff line numberDiff line change
@@ -652,21 +652,6 @@ function bindAddrFromAllSources(...argsConfig: Args[]): Addr {
652652
return addr
653653
}
654654

655-
export const shouldRunVsCodeCli = (args: Args): boolean => {
656-
// Create new interface with only Arg keys
657-
// keyof Args
658-
// Turn that into an array
659-
// Array<...>
660-
type ExtensionArgs = Array<keyof Args>
661-
const extensionRelatedArgs: ExtensionArgs = ["list-extensions", "install-extension", "uninstall-extension"]
662-
663-
const argKeys = Object.keys(args)
664-
665-
// If any of the extensionRelatedArgs are included in args
666-
// then we don't want to run the vscode cli
667-
return extensionRelatedArgs.some((arg) => argKeys.includes(arg))
668-
}
669-
670655
/**
671656
* Determine if it looks like the user is trying to open a file or folder in an
672657
* existing instance. The arguments here should be the arguments the user

src/node/entry.ts

+4-11
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
import { logger } from "@coder/logger"
2-
import {
3-
optionDescriptions,
4-
parse,
5-
readConfigFile,
6-
setDefaults,
7-
shouldOpenInExistingInstance,
8-
shouldRunVsCodeCli,
9-
} from "./cli"
2+
import { optionDescriptions, parse, readConfigFile, setDefaults, shouldOpenInExistingInstance } from "./cli"
103
import { commit, version } from "./constants"
11-
import { openInExistingInstance, runCodeServer, runVsCodeCli } from "./main"
4+
import { openInExistingInstance, runCodeServer, runVsCodeCli, shouldSpawnCliProcess } from "./main"
125
import { monkeyPatchProxyProtocols } from "./proxy_agent"
136
import { isChild, wrapper } from "./wrapper"
147

@@ -59,8 +52,8 @@ async function entry(): Promise<void> {
5952
return
6053
}
6154

62-
if (shouldRunVsCodeCli(args)) {
63-
return runVsCodeCli(args)
55+
if (await shouldSpawnCliProcess(args)) {
56+
return runVsCodeCli()
6457
}
6558

6659
const socketPath = await shouldOpenInExistingInstance(cliArgs)

src/node/main.ts

+34-4
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,53 @@ import { plural } from "../common/util"
55
import { createApp, ensureAddress } from "./app"
66
import { AuthType, DefaultedArgs, Feature } from "./cli"
77
import { coderCloudBind } from "./coder_cloud"
8-
import { commit, version } from "./constants"
8+
import { commit, version, vsRootPath } from "./constants"
99
import { startLink } from "./link"
1010
import { register } from "./routes"
1111
import { humanPath, isFile, loadAMDModule, open } from "./util"
1212

13+
export const shouldSpawnCliProcess = async (args: DefaultedArgs): Promise<boolean> => {
14+
const shouldSpawn = await loadAMDModule<(argv: DefaultedArgs) => boolean>("vs/code/node/cli", "shouldSpawnCliProcess")
15+
16+
return shouldSpawn(args)
17+
}
18+
1319
/**
1420
* This is useful when an CLI arg should be passed to VS Code directly,
1521
* such as when managing extensions.
1622
* @deprecated This should be removed when code-server merges with lib/vscode.
1723
*/
18-
export const runVsCodeCli = async (args: DefaultedArgs): Promise<void> => {
24+
export const runVsCodeCli = async (): Promise<void> => {
1925
logger.debug("Running VS Code CLI")
2026

21-
const cliProcessMain = await loadAMDModule<CodeServerLib.IMainCli["main"]>("vs/code/node/cliProcessMain", "main")
27+
// Delete `VSCODE_CWD` very early even before
28+
// importing bootstrap files. We have seen
29+
// reports where `code .` would use the wrong
30+
// current working directory due to our variable
31+
// somehow escaping to the parent shell
32+
// (https://github.com/microsoft/vscode/issues/126399)
33+
delete process.env["VSCODE_CWD"]
34+
35+
const bootstrap = require(path.join(vsRootPath, "out", "bootstrap"))
36+
const bootstrapNode = require(path.join(vsRootPath, "out", "bootstrap-node"))
37+
const product = require(path.join(vsRootPath, "product.json"))
38+
39+
// Avoid Monkey Patches from Application Insights
40+
bootstrap.avoidMonkeyPatchFromAppInsights()
41+
42+
// Enable portable support
43+
bootstrapNode.configurePortable(product)
44+
45+
// Enable ASAR support
46+
bootstrap.enableASARSupport()
47+
48+
// Signal processes that we got launched as CLI
49+
process.env["VSCODE_CLI"] = "1"
50+
51+
const cliProcessMain = await loadAMDModule<CodeServerLib.IMainCli["main"]>("vs/code/node/cli", "initialize")
2252

2353
try {
24-
await cliProcessMain(args)
54+
await cliProcessMain(process.argv)
2555
} catch (error: any) {
2656
logger.error("Got error from VS Code", error)
2757
}

vendor/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
"postinstall": "./postinstall.sh"
88
},
99
"devDependencies": {
10-
"code-oss-dev": "cdr/vscode#6310f73bbded91cfadc64c08d9be503bf2f633cc"
10+
"code-oss-dev": "cdr/vscode#54bde0ad8502bd34c91dc65b8430bf7710048009"
1111
}
1212
}

vendor/yarn.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,9 @@ clone-response@^1.0.2:
296296
dependencies:
297297
mimic-response "^1.0.0"
298298

299-
code-oss-dev@cdr/vscode#6310f73bbded91cfadc64c08d9be503bf2f633cc:
299+
code-oss-dev@cdr/vscode#54bde0ad8502bd34c91dc65b8430bf7710048009:
300300
version "1.61.1"
301-
resolved "https://codeload.github.com/cdr/vscode/tar.gz/6310f73bbded91cfadc64c08d9be503bf2f633cc"
301+
resolved "https://codeload.github.com/cdr/vscode/tar.gz/54bde0ad8502bd34c91dc65b8430bf7710048009"
302302
dependencies:
303303
"@microsoft/applicationinsights-web" "^2.6.4"
304304
"@vscode/sqlite3" "4.0.12"

0 commit comments

Comments
 (0)