@@ -5,23 +5,53 @@ import { plural } from "../common/util"
55import { createApp , ensureAddress } from "./app"
66import { AuthType , DefaultedArgs , Feature } from "./cli"
77import { coderCloudBind } from "./coder_cloud"
8- import { commit , version } from "./constants"
8+ import { commit , version , vsRootPath } from "./constants"
99import { startLink } from "./link"
1010import { register } from "./routes"
1111import { 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 }
0 commit comments