From 121a520447ff902e1eb95dcedc7e3ce87a2989f0 Mon Sep 17 00:00:00 2001 From: Asher Date: Thu, 17 Dec 2020 15:16:04 -0600 Subject: [PATCH 1/3] Symlink node_modules.asar to node_modules in lib/vscode Closes #2197. --- .gitignore | 1 + ci/build/build-release.sh | 4 ++++ ci/build/npm-postinstall.sh | 13 +++++++++++++ ci/dev/postinstall.sh | 14 ++++++++++++++ ci/lib.sh | 15 +++++++++++++++ .../extensions/node/extensionHostProcessSetup.ts | 5 ++--- package.json | 2 +- 7 files changed, 50 insertions(+), 4 deletions(-) create mode 100755 ci/dev/postinstall.sh diff --git a/.gitignore b/.gitignore index 4929c46f..dc3aaf79 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ release-packages/ release-gcp/ release-images/ node_modules +node_modules.asar node-* /plugins /lib/coder-cloud-agent diff --git a/ci/build/build-release.sh b/ci/build/build-release.sh index 3b88ed7e..c87645d3 100755 --- a/ci/build/build-release.sh +++ b/ci/build/build-release.sh @@ -96,6 +96,10 @@ EOF # yarn to fetch node_modules if necessary without build scripts running. # We cannot use --no-scripts because we still want dependent package scripts to run. jq 'del(.scripts)' < "$VSCODE_SRC_PATH/package.json" > "$VSCODE_OUT_PATH/package.json" + + pushd "$VSCODE_OUT_PATH" + symlink_asar + popd } main "$@" diff --git a/ci/build/npm-postinstall.sh b/ci/build/npm-postinstall.sh index 743b549f..d4d30233 100755 --- a/ci/build/npm-postinstall.sh +++ b/ci/build/npm-postinstall.sh @@ -41,6 +41,19 @@ main() { vscode_yarn() { cd lib/vscode yarn --production --frozen-lockfile + + # VS Code needs a node_modules.asar but that's just a duplicate of stuff we + # already have in node_modules. + if [ ! -e node_modules.asar ]; then + if [ "${WINDIR-}" ]; then + # mklink takes the link name first. + mklink /J node_modules.asar node_modules + else + # ln takes the link name second. + ln -s node_modules node_modules.asar + fi + fi + cd extensions yarn --production --frozen-lockfile for ext in */; do diff --git a/ci/dev/postinstall.sh b/ci/dev/postinstall.sh new file mode 100755 index 00000000..2ca2e059 --- /dev/null +++ b/ci/dev/postinstall.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +set -euo pipefail + +main() { + cd "$(dirname "$0")/../.." + source ./ci/lib.sh + + cd lib/vscode + yarn ${CI+--frozen-lockfile} + + symlink_asar +} + +main "$@" diff --git a/ci/lib.sh b/ci/lib.sh index d58c29cb..dae06c6d 100755 --- a/ci/lib.sh +++ b/ci/lib.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -euo pipefail pushd() { builtin pushd "$@" > /dev/null @@ -93,3 +94,17 @@ export OS # RELEASE_PATH is the destination directory for the release from the root. # Defaults to release RELEASE_PATH="${RELEASE_PATH-release}" + +# Symlink node_modules.asar to node_modules. VS Code needs a node_modules.asar +# but that's just a duplicate of stuff we already have in node_modules. +symlink_asar() { + if [ ! -e node_modules.asar ]; then + if [ "${WINDIR-}" ]; then + # mklink takes the link name first. + mklink /J node_modules.asar node_modules + else + # ln takes the link name second. + ln -s node_modules node_modules.asar + fi + fi +} diff --git a/lib/vscode/src/vs/workbench/services/extensions/node/extensionHostProcessSetup.ts b/lib/vscode/src/vs/workbench/services/extensions/node/extensionHostProcessSetup.ts index 5529222b..98c59ef1 100644 --- a/lib/vscode/src/vs/workbench/services/extensions/node/extensionHostProcessSetup.ts +++ b/lib/vscode/src/vs/workbench/services/extensions/node/extensionHostProcessSetup.ts @@ -58,13 +58,12 @@ const args = minimist(process.argv.slice(2), { const Module = require.__$__nodeRequire('module') as any; const originalLoad = Module._load; - Module._load = function (request: string, parent: object, isMain: boolean) { + Module._load = function (request: string) { if (request === 'natives') { 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'); } - // NOTE@coder: Map node_module.asar requests to regular node_modules. - return originalLoad.apply(this, [request.replace(/node_modules\.asar(\.unpacked)?/, 'node_modules'), parent, isMain]); + return originalLoad.apply(this, arguments); }; })(); diff --git a/package.json b/package.json index bb25d9da..92173f0a 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "release:github-assets": "./ci/build/release-github-assets.sh", "test:standalone-release": "./ci/build/test-standalone-release.sh", "package": "./ci/build/build-packages.sh", - "postinstall": "cd lib/vscode && yarn ${CI+--frozen-lockfile}", + "postinstall": "./ci/dev/postinstall.sh", "_____": "", "fmt": "./ci/dev/fmt.sh", "lint": "./ci/dev/lint.sh", From 3aa4ae4539ec0dd41ed51090eab8aa5284d6a254 Mon Sep 17 00:00:00 2001 From: Asher Date: Fri, 18 Dec 2020 10:59:15 -0600 Subject: [PATCH 2/3] Clarify why we need node_modules.asar --- ci/build/npm-postinstall.sh | 5 +---- ci/lib.sh | 9 +++++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/ci/build/npm-postinstall.sh b/ci/build/npm-postinstall.sh index d4d30233..b12d9a86 100755 --- a/ci/build/npm-postinstall.sh +++ b/ci/build/npm-postinstall.sh @@ -42,14 +42,11 @@ vscode_yarn() { cd lib/vscode yarn --production --frozen-lockfile - # VS Code needs a node_modules.asar but that's just a duplicate of stuff we - # already have in node_modules. + # This is a copy of symlink_asar in ../lib.sh. Look there for details. if [ ! -e node_modules.asar ]; then if [ "${WINDIR-}" ]; then - # mklink takes the link name first. mklink /J node_modules.asar node_modules else - # ln takes the link name second. ln -s node_modules node_modules.asar fi fi diff --git a/ci/lib.sh b/ci/lib.sh index dae06c6d..197aff7b 100755 --- a/ci/lib.sh +++ b/ci/lib.sh @@ -95,8 +95,13 @@ export OS # Defaults to release RELEASE_PATH="${RELEASE_PATH-release}" -# Symlink node_modules.asar to node_modules. VS Code needs a node_modules.asar -# but that's just a duplicate of stuff we already have in node_modules. +# VS Code bundles some modules into an asar which is an archive format that +# works like tar. It then seems to get unpacked into node_modules.asar. +# +# I don't know why they do this but all the dependencies they bundle already +# exist in node_modules so just symlink it. We have to do this since not only VS +# Code itself but also extensions will look specifically in this directory for +# files (like the ripgrep binary or the oniguruma wasm). symlink_asar() { if [ ! -e node_modules.asar ]; then if [ "${WINDIR-}" ]; then From 4255f9c15208cedfc8ac344afdbb34397d826ed4 Mon Sep 17 00:00:00 2001 From: Asher Date: Fri, 18 Dec 2020 09:01:27 -0800 Subject: [PATCH 3/3] Use full path for ignoring node_modules.asar Co-authored-by: Anmol Sethi --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index dc3aaf79..1a0d00ef 100644 --- a/.gitignore +++ b/.gitignore @@ -9,7 +9,7 @@ release-packages/ release-gcp/ release-images/ node_modules -node_modules.asar +/lib/vscode/node_modules.asar node-* /plugins /lib/coder-cloud-agent