Skip to content

Commit d303968

Browse files
committed
Fix import of server-main.js
1 parent 184800a commit d303968

File tree

4 files changed

+82
-14
lines changed

4 files changed

+82
-14
lines changed

patches/integration.diff

+76-8
Original file line numberDiff line numberDiff line change
@@ -272,18 +272,86 @@ Index: code-server/lib/vscode/src/vs/server/node/webClientServer.ts
272272
embedderIdentifier: 'server-distro',
273273
extensionsGallery: this._webExtensionResourceUrlTemplate && this._productService.extensionsGallery ? {
274274
...this._productService.extensionsGallery,
275-
Index: code-server/lib/vscode/src/server-main.js
275+
Index: code-server/lib/vscode/src/code-server.js
276276
===================================================================
277-
--- code-server.orig/lib/vscode/src/server-main.js
278-
+++ code-server/lib/vscode/src/server-main.js
279-
@@ -339,4 +339,9 @@ function prompt(question) {
280-
});
281-
}
282-
283-
-start();
277+
--- /dev/null
278+
+++ code-server/lib/vscode/src/code-server.js
279+
@@ -0,0 +1,66 @@
280+
+// This is a copy of server-main.js (the parts we use), before it was converted
281+
+// to ESM. Directly importing it in code-server has proven difficult. We will
282+
+// need to to consider some new options going forward.
283+
+//
284+
+// 1. Convert code-server to ESM (best option?).
285+
+// 2. Do not import, fork a process, and communicate via IPC.
286+
+
287+
+// @ts-check
288+
+'use strict';
289+
+
290+
+/**
291+
+ * @import { INLSConfiguration } from './vs/nls'
292+
+ */
293+
+
294+
+// Keep bootstrap-amd.js from redefining 'fs'.
295+
+delete process.env['ELECTRON_RUN_AS_NODE'];
296+
+
297+
+const path = require('path');
298+
+const performance = require('perf_hooks').performance;
299+
+const bootstrapNode = require('./bootstrap-node');
300+
+const bootstrapAmd = require('./bootstrap-amd');
301+
+const { resolveNLSConfiguration } = require('./vs/base/node/nls');
302+
+const product = require('./bootstrap-meta').product;
303+
+const perf = require(`./vs/base/common/performance`);
304+
+
305+
+perf.mark('code/server/start');
306+
+// @ts-ignore
307+
+global.vscodeServerStartTime = performance.now();
308+
+
309+
+/**
310+
+ * @param {INLSConfiguration} nlsConfiguration
311+
+ * @returns { Promise<typeof import('./vs/server/node/server.main')> }
312+
+ */
313+
+function loadCode(nlsConfiguration) {
314+
+ return new Promise((resolve, reject) => {
315+
+
316+
+ /** @type {INLSConfiguration} */
317+
+ process.env['VSCODE_NLS_CONFIG'] = JSON.stringify(nlsConfiguration); // required for `bootstrap-amd` to pick up NLS messages
318+
+
319+
+ // See https://github.com/microsoft/vscode-remote-release/issues/6543
320+
+ // We would normally install a SIGPIPE listener in bootstrap-node.js
321+
+ // But in certain situations, the console itself can be in a broken pipe state
322+
+ // so logging SIGPIPE to the console will cause an infinite async loop
323+
+ process.env['VSCODE_HANDLES_SIGPIPE'] = 'true';
324+
+
325+
+ if (process.env['VSCODE_DEV']) {
326+
+ // When running out of sources, we need to load node modules from remote/node_modules,
327+
+ // which are compiled against nodejs, not electron
328+
+ process.env['VSCODE_DEV_INJECT_NODE_MODULE_LOOKUP_PATH'] = process.env['VSCODE_DEV_INJECT_NODE_MODULE_LOOKUP_PATH'] || path.join(__dirname, '..', 'remote', 'node_modules');
329+
+ bootstrapNode.devInjectNodeModuleLookupPath(process.env['VSCODE_DEV_INJECT_NODE_MODULE_LOOKUP_PATH']);
330+
+ } else {
331+
+ delete process.env['VSCODE_DEV_INJECT_NODE_MODULE_LOOKUP_PATH'];
332+
+ }
333+
+ bootstrapAmd.load('vs/server/node/server.main', resolve, reject);
334+
+ });
335+
+}
336+
+
337+
+/**
338+
+ * @returns { Promise<typeof import('./vs/server/node/server.main')> }
339+
+ */
284340
+async function loadCodeWithNls() {
285341
+ const nlsConfiguration = await resolveNLSConfiguration({ userLocale: 'en', osLocale: 'en', commit: product.commit, userDataPath: '', nlsMetadataPath: __dirname });
286342
+ return loadCode(nlsConfiguration);
287343
+}
288344
+
289345
+module.exports.loadCodeWithNls = loadCodeWithNls;
346+
Index: code-server/lib/vscode/build/gulpfile.reh.js
347+
===================================================================
348+
--- code-server.orig/lib/vscode/build/gulpfile.reh.js
349+
+++ code-server/lib/vscode/build/gulpfile.reh.js
350+
@@ -164,6 +164,7 @@ const serverWithWebEntryPoints = [
351+
352+
const commonJSEntryPoints = [
353+
'out-build/server-main.js',
354+
+ 'out-build/code-server.js',
355+
'out-build/server-cli.js',
356+
'out-build/bootstrap-fork.js',
357+
];

src/node/main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export interface OpenCommandPipeArgs {
4949
export const runCodeCli = async (args: DefaultedArgs): Promise<void> => {
5050
logger.debug("Running Code CLI")
5151
try {
52-
const mod = require(path.join(vsRootPath, "out/server-main")) as VSCodeModule
52+
const mod = require(path.join(vsRootPath, "out/code-server")) as VSCodeModule
5353
const serverModule = await mod.loadCodeWithNls()
5454
await serverModule.spawnCli(await toCodeArgs(args))
5555
// Rather than have the caller handle errors and exit, spawnCli will exit

src/node/routes/vscode.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,19 @@ export interface IVSCodeServerAPI {
4141
*/
4242
export type VSCodeModule = {
4343
// See ../../../lib/vscode/src/server-main.js:339.
44-
loadCodeWithNls(): {
44+
loadCodeWithNls(): Promise<{
4545
// See ../../../lib/vscode/src/vs/server/node/server.main.ts:72.
4646
createServer(address: string | net.AddressInfo | null, args: CodeArgs): Promise<IVSCodeServerAPI>
4747
// See ../../../lib/vscode/src/vs/server/node/server.main.ts:65.
4848
spawnCli(args: CodeArgs): Promise<void>
49-
}
49+
}>
5050
}
5151

5252
/**
5353
* Load then create the VS Code server.
5454
*/
5555
async function loadVSCode(req: express.Request): Promise<IVSCodeServerAPI> {
56-
const mod = require(path.join(vsRootPath, "out/server-main")) as VSCodeModule
56+
const mod = require(path.join(vsRootPath, "out/code-server")) as VSCodeModule
5757
const serverModule = await mod.loadCodeWithNls()
5858
return serverModule.createServer(null, {
5959
...(await toCodeArgs(req.args)),

tsconfig.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"compilerOptions": {
3-
"target": "es6",
4-
"lib": ["es2020", "dom", "dom.iterable"],
3+
"target": "es2022",
4+
"lib": ["es2022", "dom", "dom.iterable"],
55
"module": "commonjs",
66
"moduleResolution": "node",
77
"strict": true,

0 commit comments

Comments
 (0)