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 17, 2024
1 parent 184800a commit e4ceeab
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 24 deletions.
14 changes: 7 additions & 7 deletions ci/build/build-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,17 @@ bundle_vscode() {

rsync "${rsync_opts[@]}" ./lib/vscode-reh-web-*/ "$VSCODE_OUT_PATH"

# Use the package.json for the web/remote server. It does not have the right
# version though so pull that from the main package.json.
jq --slurp '.[0] * {version: .[1].version}' \
# Merge the package.json for the web/remote server so we can include
# dependencies, since we want to ship this via NPM.
jq --slurp '.[0] * .[1]' \
"$VSCODE_SRC_PATH/remote/package.json" \
"$VSCODE_SRC_PATH/package.json" > "$VSCODE_OUT_PATH/package.json"

mv "$VSCODE_SRC_PATH/remote/npm-shrinkwrap.json" "$VSCODE_OUT_PATH/npm-shrinkwrap.json"
"$VSCODE_OUT_PATH/package.json" > "$VSCODE_OUT_PATH/package.json.merged"
mv "$VSCODE_OUT_PATH/package.json.merged" "$VSCODE_OUT_PATH/package.json"
cp "$VSCODE_SRC_PATH/remote/npm-shrinkwrap.json" "$VSCODE_OUT_PATH/npm-shrinkwrap.json"

# Include global extension dependencies as well.
rsync "$VSCODE_SRC_PATH/extensions/package.json" "$VSCODE_OUT_PATH/extensions/package.json"
mv "$VSCODE_SRC_PATH/extensions/npm-shrinkwrap.json" "$VSCODE_OUT_PATH/extensions/npm-shrinkwrap.json"
cp "$VSCODE_SRC_PATH/extensions/npm-shrinkwrap.json" "$VSCODE_OUT_PATH/extensions/npm-shrinkwrap.json"
rsync "$VSCODE_SRC_PATH/extensions/postinstall.mjs" "$VSCODE_OUT_PATH/extensions/postinstall.mjs"
}

Expand Down
17 changes: 7 additions & 10 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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 default async function loadCodeWithNls() {
+ const nlsConfiguration = await resolveNLSConfiguration({ userLocale: 'en', osLocale: 'en', commit: product.commit, userDataPath: '', nlsMetadataPath: __dirname });
+ return loadCode(nlsConfiguration);
+}
+
+module.exports.loadCodeWithNls = loadCodeWithNls;
12 changes: 9 additions & 3 deletions src/node/routes/vscode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,25 @@ 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
// Since server-main.js is an ES module, we have to use `import`. However,
// tsc will transpile this to `require` unless we change our module type,
// which will also require that we switch to ESM, since a hybrid approach
// breaks importing `rotating-file-stream` for some reason. To work around
// this, use `eval` for now, but we should consider switching to ESM.
const modPath = path.join(vsRootPath, "out/server-main.js")
const mod = await eval(`import("${modPath}")`) as VSCodeModule
const serverModule = await mod.loadCodeWithNls()
return serverModule.createServer(null, {
...(await toCodeArgs(req.args)),
Expand Down

0 comments on commit e4ceeab

Please sign in to comment.