Skip to content

Commit 7ee5044

Browse files
code-asherjsjoeio
authored andcommitted
Symlink node_modules.asar to node_modules in lib/vscode
Closes #2197.
1 parent f256f32 commit 7ee5044

File tree

7 files changed

+50
-4
lines changed

7 files changed

+50
-4
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ release-packages/
99
release-gcp/
1010
release-images/
1111
node_modules
12+
node_modules.asar
1213
node-*
1314
/plugins
1415
/lib/coder-cloud-agent

ci/build/build-release.sh

+4
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ EOF
9696
# yarn to fetch node_modules if necessary without build scripts running.
9797
# We cannot use --no-scripts because we still want dependent package scripts to run.
9898
jq 'del(.scripts)' < "$VSCODE_SRC_PATH/package.json" > "$VSCODE_OUT_PATH/package.json"
99+
100+
pushd "$VSCODE_OUT_PATH"
101+
symlink_asar
102+
popd
99103
}
100104

101105
main "$@"

ci/build/npm-postinstall.sh

+13
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,19 @@ main() {
4141
vscode_yarn() {
4242
cd lib/vscode
4343
yarn --production --frozen-lockfile
44+
45+
# VS Code needs a node_modules.asar but that's just a duplicate of stuff we
46+
# already have in node_modules.
47+
if [ ! -e node_modules.asar ]; then
48+
if [ "${WINDIR-}" ]; then
49+
# mklink takes the link name first.
50+
mklink /J node_modules.asar node_modules
51+
else
52+
# ln takes the link name second.
53+
ln -s node_modules node_modules.asar
54+
fi
55+
fi
56+
4457
cd extensions
4558
yarn --production --frozen-lockfile
4659
for ext in */; do

ci/dev/postinstall.sh

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
main() {
5+
cd "$(dirname "$0")/../.."
6+
source ./ci/lib.sh
7+
8+
cd lib/vscode
9+
yarn ${CI+--frozen-lockfile}
10+
11+
symlink_asar
12+
}
13+
14+
main "$@"

ci/lib.sh

+15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env bash
2+
set -euo pipefail
23

34
pushd() {
45
builtin pushd "$@" > /dev/null
@@ -93,3 +94,17 @@ export OS
9394
# RELEASE_PATH is the destination directory for the release from the root.
9495
# Defaults to release
9596
RELEASE_PATH="${RELEASE_PATH-release}"
97+
98+
# Symlink node_modules.asar to node_modules. VS Code needs a node_modules.asar
99+
# but that's just a duplicate of stuff we already have in node_modules.
100+
symlink_asar() {
101+
if [ ! -e node_modules.asar ]; then
102+
if [ "${WINDIR-}" ]; then
103+
# mklink takes the link name first.
104+
mklink /J node_modules.asar node_modules
105+
else
106+
# ln takes the link name second.
107+
ln -s node_modules node_modules.asar
108+
fi
109+
fi
110+
}

lib/vscode/src/vs/workbench/services/extensions/node/extensionHostProcessSetup.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,12 @@ const args = minimist(process.argv.slice(2), {
5858
const Module = require.__$__nodeRequire('module') as any;
5959
const originalLoad = Module._load;
6060

61-
Module._load = function (request: string, parent: object, isMain: boolean) {
61+
Module._load = function (request: string) {
6262
if (request === 'natives') {
6363
throw new Error('Either the extension or a NPM dependency is using the "natives" node module which is unsupported as it can cause a crash of the extension host. Click [here](https://go.microsoft.com/fwlink/?linkid=871887) to find out more');
6464
}
6565

66-
// NOTE@coder: Map node_module.asar requests to regular node_modules.
67-
return originalLoad.apply(this, [request.replace(/node_modules\.asar(\.unpacked)?/, 'node_modules'), parent, isMain]);
66+
return originalLoad.apply(this, arguments);
6867
};
6968
})();
7069

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"release:github-assets": "./ci/build/release-github-assets.sh",
2020
"test:standalone-release": "./ci/build/test-standalone-release.sh",
2121
"package": "./ci/build/build-packages.sh",
22-
"postinstall": "cd lib/vscode && yarn ${CI+--frozen-lockfile}",
22+
"postinstall": "./ci/dev/postinstall.sh",
2323
"_____": "",
2424
"fmt": "./ci/dev/fmt.sh",
2525
"lint": "./ci/dev/lint.sh",

0 commit comments

Comments
 (0)