Fix import of server-main.js

This commit is contained in:
Asher 2024-10-15 20:44:49 -08:00
parent 184800a94f
commit 97c561a713
No known key found for this signature in database
GPG Key ID: D63C1EF81242354A
3 changed files with 12 additions and 9 deletions

View File

@ -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;

View File

@ -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)),

View File

@ -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,