Skip to content

Commit 97c561a

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

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

patches/integration.diff

+2-4
Original file line numberDiff line numberDiff line change
@@ -276,14 +276,12 @@ Index: code-server/lib/vscode/src/server-main.js
276276
===================================================================
277277
--- code-server.orig/lib/vscode/src/server-main.js
278278
+++ code-server/lib/vscode/src/server-main.js
279-
@@ -339,4 +339,9 @@ function prompt(question) {
279+
@@ -339,4 +339,7 @@ function prompt(question) {
280280
});
281281
}
282282

283283
-start();
284-
+async function loadCodeWithNls() {
284+
+export async function loadCodeWithNls() {
285285
+ const nlsConfiguration = await resolveNLSConfiguration({ userLocale: 'en', osLocale: 'en', commit: product.commit, userDataPath: '', nlsMetadataPath: __dirname });
286286
+ return loadCode(nlsConfiguration);
287287
+}
288-
+
289-
+module.exports.loadCodeWithNls = loadCodeWithNls;

src/node/routes/vscode.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,24 @@ 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+
// TypeScript transpiles `import` into `require`, and this is not valid for
57+
// ESM, which server-main.js is. Ideally we convert to ESM, but doing so has
58+
// been an endless pit of misery and despair so I am shelving the conversion
59+
// and will try again later. For now, jank it with `eval`.
60+
const modulePath = path.join(vsRootPath, "out/server-main.js")
61+
const mod = await eval(`import("${modulePath}")`)
5762
const serverModule = await mod.loadCodeWithNls()
5863
return serverModule.createServer(null, {
5964
...(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)