Skip to content

Commit e4ceeab

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

File tree

4 files changed

+25
-24
lines changed

4 files changed

+25
-24
lines changed

ci/build/build-release.sh

+7-7
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,17 @@ bundle_vscode() {
9191

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

94-
# Use the package.json for the web/remote server. It does not have the right
95-
# version though so pull that from the main package.json.
96-
jq --slurp '.[0] * {version: .[1].version}' \
94+
# Merge the package.json for the web/remote server so we can include
95+
# dependencies, since we want to ship this via NPM.
96+
jq --slurp '.[0] * .[1]' \
9797
"$VSCODE_SRC_PATH/remote/package.json" \
98-
"$VSCODE_SRC_PATH/package.json" > "$VSCODE_OUT_PATH/package.json"
99-
100-
mv "$VSCODE_SRC_PATH/remote/npm-shrinkwrap.json" "$VSCODE_OUT_PATH/npm-shrinkwrap.json"
98+
"$VSCODE_OUT_PATH/package.json" > "$VSCODE_OUT_PATH/package.json.merged"
99+
mv "$VSCODE_OUT_PATH/package.json.merged" "$VSCODE_OUT_PATH/package.json"
100+
cp "$VSCODE_SRC_PATH/remote/npm-shrinkwrap.json" "$VSCODE_OUT_PATH/npm-shrinkwrap.json"
101101

102102
# Include global extension dependencies as well.
103103
rsync "$VSCODE_SRC_PATH/extensions/package.json" "$VSCODE_OUT_PATH/extensions/package.json"
104-
mv "$VSCODE_SRC_PATH/extensions/npm-shrinkwrap.json" "$VSCODE_OUT_PATH/extensions/npm-shrinkwrap.json"
104+
cp "$VSCODE_SRC_PATH/extensions/npm-shrinkwrap.json" "$VSCODE_OUT_PATH/extensions/npm-shrinkwrap.json"
105105
rsync "$VSCODE_SRC_PATH/extensions/postinstall.mjs" "$VSCODE_OUT_PATH/extensions/postinstall.mjs"
106106
}
107107

flake.lock

+7-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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 default 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

+9-3
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,25 @@ 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+
// Since server-main.js is an ES module, we have to use `import`. However,
57+
// tsc will transpile this to `require` unless we change our module type,
58+
// which will also require that we switch to ESM, since a hybrid approach
59+
// breaks importing `rotating-file-stream` for some reason. To work around
60+
// this, use `eval` for now, but we should consider switching to ESM.
61+
const modPath = path.join(vsRootPath, "out/server-main.js")
62+
const mod = await eval(`import("${modPath}")`) as VSCodeModule
5763
const serverModule = await mod.loadCodeWithNls()
5864
return serverModule.createServer(null, {
5965
...(await toCodeArgs(req.args)),

0 commit comments

Comments
 (0)