Skip to content

Commit

Permalink
Fix import of server-main.js
Browse files Browse the repository at this point in the history
  • Loading branch information
code-asher committed Oct 16, 2024
1 parent 184800a commit 97c561a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
6 changes: 2 additions & 4 deletions patches/integration.diff
Original file line number Diff line number Diff line change
Expand Up @@ -276,14 +276,12 @@ Index: code-server/lib/vscode/src/server-main.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) {
@@ -339,4 +339,7 @@ function prompt(question) {
});
}

-start();
+async function loadCodeWithNls() {
+export async function loadCodeWithNls() {
+ const nlsConfiguration = await resolveNLSConfiguration({ userLocale: 'en', osLocale: 'en', commit: product.commit, userDataPath: '', nlsMetadataPath: __dirname });
+ return loadCode(nlsConfiguration);
+}
+
+module.exports.loadCodeWithNls = loadCodeWithNls;
11 changes: 8 additions & 3 deletions src/node/routes/vscode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,24 @@ 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<IVSCodeServerAPI>
// See ../../../lib/vscode/src/vs/server/node/server.main.ts:65.
spawnCli(args: CodeArgs): Promise<void>
}
}>
}

/**
* Load then create the VS Code server.
*/
async function loadVSCode(req: express.Request): Promise<IVSCodeServerAPI> {
const mod = require(path.join(vsRootPath, "out/server-main")) as VSCodeModule
// TypeScript transpiles `import` into `require`, and this is not valid for
// ESM, which server-main.js is. Ideally we convert to ESM, but doing so has
// been an endless pit of misery and despair so I am shelving the conversion
// and will try again later. For now, jank it with `eval`.
const modulePath = path.join(vsRootPath, "out/server-main.js")
const mod = await eval(`import("${modulePath}")`)
const serverModule = await mod.loadCodeWithNls()
return serverModule.createServer(null, {
...(await toCodeArgs(req.args)),
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -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,
Expand Down

0 comments on commit 97c561a

Please sign in to comment.