diff --git a/patches/integration.diff b/patches/integration.diff index 8372cae35d3e..90539c88d0b8 100644 --- a/patches/integration.diff +++ b/patches/integration.diff @@ -272,18 +272,98 @@ Index: code-server/lib/vscode/src/vs/server/node/webClientServer.ts embedderIdentifier: 'server-distro', extensionsGallery: this._webExtensionResourceUrlTemplate && this._productService.extensionsGallery ? { ...this._productService.extensionsGallery, -Index: code-server/lib/vscode/src/server-main.js +Index: code-server/lib/vscode/src/code-server.js =================================================================== ---- code-server.orig/lib/vscode/src/server-main.js -+++ code-server/lib/vscode/src/server-main.js -@@ -339,4 +339,9 @@ function prompt(question) { - }); - } - --start(); +--- /dev/null ++++ code-server/lib/vscode/src/code-server.js +@@ -0,0 +1,66 @@ ++// This is a copy of server-main.js (the parts we use), before it was converted ++// to ESM. Directly importing it in code-server has proven difficult. We will ++// need to to consider some new options going forward. ++// ++// 1. Convert code-server to ESM (best option?). ++// 2. Do not import, fork a process, and communicate via IPC. ++ ++// @ts-check ++'use strict'; ++ ++/** ++ * @import { INLSConfiguration } from './vs/nls' ++ */ ++ ++// Keep bootstrap-amd.js from redefining 'fs'. ++delete process.env['ELECTRON_RUN_AS_NODE']; ++ ++const path = require('path'); ++const performance = require('perf_hooks').performance; ++const bootstrapNode = require('./bootstrap-node'); ++const bootstrapAmd = require('./bootstrap-amd'); ++const { resolveNLSConfiguration } = require('./vs/base/node/nls'); ++const product = require('./bootstrap-meta').product; ++const perf = require(`./vs/base/common/performance`); ++ ++perf.mark('code/server/start'); ++// @ts-ignore ++global.vscodeServerStartTime = performance.now(); ++ ++/** ++ * @param {INLSConfiguration} nlsConfiguration ++ * @returns { Promise } ++ */ ++function loadCode(nlsConfiguration) { ++ return new Promise((resolve, reject) => { ++ ++ /** @type {INLSConfiguration} */ ++ process.env['VSCODE_NLS_CONFIG'] = JSON.stringify(nlsConfiguration); // required for `bootstrap-amd` to pick up NLS messages ++ ++ // See https://github.com/microsoft/vscode-remote-release/issues/6543 ++ // We would normally install a SIGPIPE listener in bootstrap-node.js ++ // But in certain situations, the console itself can be in a broken pipe state ++ // so logging SIGPIPE to the console will cause an infinite async loop ++ process.env['VSCODE_HANDLES_SIGPIPE'] = 'true'; ++ ++ if (process.env['VSCODE_DEV']) { ++ // When running out of sources, we need to load node modules from remote/node_modules, ++ // which are compiled against nodejs, not electron ++ process.env['VSCODE_DEV_INJECT_NODE_MODULE_LOOKUP_PATH'] = process.env['VSCODE_DEV_INJECT_NODE_MODULE_LOOKUP_PATH'] || path.join(__dirname, '..', 'remote', 'node_modules'); ++ bootstrapNode.devInjectNodeModuleLookupPath(process.env['VSCODE_DEV_INJECT_NODE_MODULE_LOOKUP_PATH']); ++ } else { ++ delete process.env['VSCODE_DEV_INJECT_NODE_MODULE_LOOKUP_PATH']; ++ } ++ bootstrapAmd.load('vs/server/node/server.main', resolve, reject); ++ }); ++} ++ ++/** ++ * @returns { Promise } ++ */ +async function loadCodeWithNls() { + const nlsConfiguration = await resolveNLSConfiguration({ userLocale: 'en', osLocale: 'en', commit: product.commit, userDataPath: '', nlsMetadataPath: __dirname }); + return loadCode(nlsConfiguration); +} + +module.exports.loadCodeWithNls = loadCodeWithNls; +Index: code-server/lib/vscode/build/gulpfile.reh.js +=================================================================== +--- code-server.orig/lib/vscode/build/gulpfile.reh.js ++++ code-server/lib/vscode/build/gulpfile.reh.js +@@ -164,6 +164,7 @@ const serverWithWebEntryPoints = [ + + const commonJSEntryPoints = [ + 'out-build/server-main.js', ++ 'out-build/code-server.js', + 'out-build/server-cli.js', + 'out-build/bootstrap-fork.js', + ]; +Index: code-server/lib/vscode/src/tsconfig.json +=================================================================== +--- code-server.orig/lib/vscode/src/tsconfig.json ++++ code-server/lib/vscode/src/tsconfig.json +@@ -36,6 +36,7 @@ + "./bootstrap-window.js", + "./cli.js", + "./main.js", ++ "./code-server.js", + "./server-main.js", + "./server-cli.js", + "./vs/base/common/jsonc.js", diff --git a/src/node/main.ts b/src/node/main.ts index 0458f66ad9b2..7bd5f9448f34 100644 --- a/src/node/main.ts +++ b/src/node/main.ts @@ -49,7 +49,7 @@ export interface OpenCommandPipeArgs { export const runCodeCli = async (args: DefaultedArgs): Promise => { logger.debug("Running Code CLI") try { - const mod = require(path.join(vsRootPath, "out/server-main")) as VSCodeModule + const mod = require(path.join(vsRootPath, "out/code-server")) as VSCodeModule const serverModule = await mod.loadCodeWithNls() await serverModule.spawnCli(await toCodeArgs(args)) // Rather than have the caller handle errors and exit, spawnCli will exit diff --git a/src/node/routes/vscode.ts b/src/node/routes/vscode.ts index b3f04fd6cd90..434aed00112d 100644 --- a/src/node/routes/vscode.ts +++ b/src/node/routes/vscode.ts @@ -41,19 +41,19 @@ export interface IVSCodeServerAPI { */ export type VSCodeModule = { // See ../../../lib/vscode/src/server-main.js:339. - loadCodeWithNls(): { + loadCodeWithNls(): Promise<{ // See ../../../lib/vscode/src/vs/server/node/server.main.ts:72. createServer(address: string | net.AddressInfo | null, args: CodeArgs): Promise // See ../../../lib/vscode/src/vs/server/node/server.main.ts:65. spawnCli(args: CodeArgs): Promise - } + }> } /** * Load then create the VS Code server. */ async function loadVSCode(req: express.Request): Promise { - const mod = require(path.join(vsRootPath, "out/server-main")) as VSCodeModule + const mod = require(path.join(vsRootPath, "out/code-server")) as VSCodeModule const serverModule = await mod.loadCodeWithNls() return serverModule.createServer(null, { ...(await toCodeArgs(req.args)), diff --git a/tsconfig.json b/tsconfig.json index 6ff95cccab31..62e3235aea08 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { - "target": "es6", - "lib": ["es2020", "dom", "dom.iterable"], + "target": "es2022", + "lib": ["es2022", "dom", "dom.iterable"], "module": "commonjs", "moduleResolution": "node", "strict": true,