Skip to content

Commit c7baf5d

Browse files
authored
Merge pull request #2482 from cdr/asar
Symlink node_modules.asar to node_modules in lib/vscode
2 parents 7c6b132 + 4255f9c commit c7baf5d

File tree

7 files changed

+52
-4
lines changed

7 files changed

+52
-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+
/lib/vscode/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

+10
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ main() {
4141
vscode_yarn() {
4242
cd lib/vscode
4343
yarn --production --frozen-lockfile
44+
45+
# This is a copy of symlink_asar in ../lib.sh. Look there for details.
46+
if [ ! -e node_modules.asar ]; then
47+
if [ "${WINDIR-}" ]; then
48+
mklink /J node_modules.asar node_modules
49+
else
50+
ln -s node_modules node_modules.asar
51+
fi
52+
fi
53+
4454
cd extensions
4555
yarn --production --frozen-lockfile
4656
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

+20
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,22 @@ 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+
# VS Code bundles some modules into an asar which is an archive format that
99+
# works like tar. It then seems to get unpacked into node_modules.asar.
100+
#
101+
# I don't know why they do this but all the dependencies they bundle already
102+
# exist in node_modules so just symlink it. We have to do this since not only VS
103+
# Code itself but also extensions will look specifically in this directory for
104+
# files (like the ripgrep binary or the oniguruma wasm).
105+
symlink_asar() {
106+
if [ ! -e node_modules.asar ]; then
107+
if [ "${WINDIR-}" ]; then
108+
# mklink takes the link name first.
109+
mklink /J node_modules.asar node_modules
110+
else
111+
# ln takes the link name second.
112+
ln -s node_modules node_modules.asar
113+
fi
114+
fi
115+
}

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)