Bundle VS Code node_modules to avoid yarn dependency

Many random bizarre issues otherwise.

Also includes misc improvements to docs and scripts.
This commit is contained in:
Anmol Sethi 2020-05-13 02:35:11 -04:00
parent a346c6d565
commit 1739b21600
No known key found for this signature in database
GPG Key ID: 8CEF1878FF10ADEB
8 changed files with 64 additions and 25 deletions

View File

@ -65,7 +65,7 @@ all file system operations occur as your user outside the container.
### Self contained releases ### Self contained releases
We publish self contained archives for every release on [github](https://github.com/cdr/code-server/releases). We publish self contained archives for every release on [github](https://github.com/cdr/code-server/releases).
They bundle the node binary and node_modules. They bundle the node binary and compiled native modules.
1. Download the latest release archive for your system from [github](https://github.com/cdr/code-server/releases) 1. Download the latest release archive for your system from [github](https://github.com/cdr/code-server/releases)
2. Unpack the release 2. Unpack the release

View File

@ -39,7 +39,11 @@ This directory contains scripts used for the development of code-server.
- [./dev/test.sh](./dev/test.sh) (`yarn test`) - [./dev/test.sh](./dev/test.sh) (`yarn test`)
- Runs tests - Runs tests
- [./dev/vscode.sh](./dev/vscode.sh) (`yarn vscode`) - [./dev/vscode.sh](./dev/vscode.sh) (`yarn vscode`)
- Ensures `lib/vscode` is cloned, patched and dependencies are installed - Ensures [../lib/vscode](../lib/vscode) is cloned, patched and dependencies are installed
- [./dev/patch-vscode.sh](./dev/patch-vscode.sh) (`yarn vscode:patch`)
- Applies [./dev/vscode.patch](./dev/vscode.patch) to [../lib/vscode](../lib/vscode)
- [./dev/diff-vscode.sh](./dev/diff-vscode.sh) (`yarn vscode:diff`)
- Diffs [../lib/vscode](../lib/vscode) into [./dev/vscode.patch](./dev/vscode.patch)
- [./dev/vscode.patch](./dev/vscode.patch) - [./dev/vscode.patch](./dev/vscode.patch)
- Our patch of VS Code to enable remote browser access - Our patch of VS Code to enable remote browser access
- Generate it with `yarn vscode:diff` and apply with `yarn vscode:patch` - Generate it with `yarn vscode:diff` and apply with `yarn vscode:patch`
@ -62,11 +66,11 @@ You can disable minification by setting `MINIFY=`.
- Bundles the output of the above two scripts into a single node module at `./release`. - Bundles the output of the above two scripts into a single node module at `./release`.
- [./build/build-static-release.sh](./build/build-static-release.sh) (`yarn release:static`) - [./build/build-static-release.sh](./build/build-static-release.sh) (`yarn release:static`)
- Requires a release already built in `./release`. - Requires a release already built in `./release`.
- Will build a static release with node and node_modules into `./release-static` - Will build a static release with node bundled into `./release-static`
- [./build/clean.sh](./build/clean.sh) (`yarn clean`) - [./build/clean.sh](./build/clean.sh) (`yarn clean`)
- Removes all git ignored files like build artifacts. - Removes all build artifacts
- Will also `git reset --hard lib/vscode` - Will also `git reset --hard lib/vscode`
- Useful to do a clean build. - Useful to do a clean build
- [./build/code-server.sh](./build/code-server.sh) - [./build/code-server.sh](./build/code-server.sh)
- Copied into static releases to run code-server with the bundled node binary. - Copied into static releases to run code-server with the bundled node binary.
- [./build/test-static-release.sh](./build/test-static-release.sh) (`yarn test:static-release`) - [./build/test-static-release.sh](./build/test-static-release.sh) (`yarn test:static-release`)

View File

@ -40,7 +40,7 @@ bundle_code_server() {
{ {
"commit": "$(git rev-parse HEAD)", "commit": "$(git rev-parse HEAD)",
"scripts": { "scripts": {
"postinstall": "cd lib/vscode && yarn --production && cd extensions && yarn --production" "postinstall": "cd lib/vscode && npm rebuild # Builds native modules"
} }
} }
EOF EOF
@ -49,18 +49,15 @@ EOF
bundle_vscode() { bundle_vscode() {
mkdir -p "$VSCODE_OUT_PATH" mkdir -p "$VSCODE_OUT_PATH"
rsync "$VSCODE_SRC_PATH/package.json" "$VSCODE_OUT_PATH"
rsync "$VSCODE_SRC_PATH/yarn.lock" "$VSCODE_OUT_PATH"
rsync "$VSCODE_SRC_PATH/node_modules" "$VSCODE_OUT_PATH"
rsync "$VSCODE_SRC_PATH/out-vscode${MINIFY+-min}/" "$VSCODE_OUT_PATH/out" rsync "$VSCODE_SRC_PATH/out-vscode${MINIFY+-min}/" "$VSCODE_OUT_PATH/out"
rsync "$VSCODE_SRC_PATH/.build/extensions/" "$VSCODE_OUT_PATH/extensions" rsync "$VSCODE_SRC_PATH/.build/extensions/" "$VSCODE_OUT_PATH/extensions"
rm -Rf "$VSCODE_OUT_PATH/extensions/node_modules"
rsync "$VSCODE_SRC_PATH/extensions/package.json" "$VSCODE_OUT_PATH/extensions"
rsync "$VSCODE_SRC_PATH/extensions/yarn.lock" "$VSCODE_OUT_PATH/extensions"
rsync "$VSCODE_SRC_PATH/extensions/postinstall.js" "$VSCODE_OUT_PATH/extensions"
mkdir -p "$VSCODE_OUT_PATH/resources/linux" mkdir -p "$VSCODE_OUT_PATH/resources/linux"
rsync "$VSCODE_SRC_PATH/resources/linux/code.png" "$VSCODE_OUT_PATH/resources/linux/code.png" rsync "$VSCODE_SRC_PATH/resources/linux/code.png" "$VSCODE_OUT_PATH/resources/linux/code.png"
rsync "$VSCODE_SRC_PATH/yarn.lock" "$VSCODE_OUT_PATH"
# Adds the commit and date to product.json # Adds the commit and date to product.json
jq --slurp '.[0] * .[1]' "$VSCODE_SRC_PATH/product.json" <( jq --slurp '.[0] * .[1]' "$VSCODE_SRC_PATH/product.json" <(
cat << EOF cat << EOF
@ -71,12 +68,17 @@ bundle_vscode() {
EOF EOF
) > "$VSCODE_OUT_PATH/product.json" ) > "$VSCODE_OUT_PATH/product.json"
# We remove the scripts field so that later on we can run pushd "$VSCODE_OUT_PATH"
# yarn to fetch node_modules if necessary without build scripts yarn --production --ignore-scripts
# being ran. popd
# We cannot use --no-scripts because we still want dependant package scripts to run
# for native modules to be rebuilt. # Now we clear any native module builds.
jq 'del(.scripts)' < "$VSCODE_SRC_PATH/package.json" > "$VSCODE_OUT_PATH/package.json" local nativeModules
mapfile -t nativeModules < <(find "$VSCODE_OUT_PATH/node_modules" -name "binding.gyp" -exec dirname {} \;)
local nm
for nm in "${nativeModules[@]}"; do
rm -R "$nm/build"
done
} }
main "$@" main "$@"

View File

@ -3,10 +3,22 @@ set -euo pipefail
main() { main() {
cd "$(dirname "${0}")/../.." cd "$(dirname "${0}")/../.."
source ./ci/lib.sh
git clean -Xffd rm -Rf \
git submodule foreach --recursive git clean -xffd out \
git submodule foreach --recursive git reset --hard release \
release-static \
release-packages \
release-gcp \
dist \
.tsbuildinfo \
.cache/out.tsbuildinfo
pushd lib/vscode
git clean -xffd
git reset --hard
popd
} }
main "$@" main "$@"

11
ci/dev/diff-vscode.sh Executable file
View File

@ -0,0 +1,11 @@
#!/usr/bin/env bash
set -euo pipefail
main() {
cd "$(dirname "$0")/../.."
cd ./lib/vscode
git diff HEAD > ../../ci/dev/vscode.patch
}
main "$@"

11
ci/dev/patch-vscode.sh Executable file
View File

@ -0,0 +1,11 @@
#!/usr/bin/env bash
set -euo pipefail
main() {
cd "$(dirname "$0")/../.."
cd ./lib/vscode
git apply ../../ci/dev/vscode.patch
}
main "$@"

View File

@ -59,5 +59,4 @@ yarn test:static-release
yarn package yarn package
``` ```
The static release will be in `./release-static` and the release packages The static release will be in `./release-static` and .deb, .rpm and self-contained release in `./release-packages`.
(.deb, .rpm, self contained release) in `./release-packages`.

View File

@ -11,8 +11,8 @@
"scripts": { "scripts": {
"clean": "./ci/build/clean.sh", "clean": "./ci/build/clean.sh",
"vscode": "./ci/dev/vscode.sh", "vscode": "./ci/dev/vscode.sh",
"vscode:patch": "cd ./lib/vscode && git apply ../../ci/dev/vscode.patch", "vscode:patch": "./ci/dev/patch-vscode.sh",
"vscode:diff": "cd ./lib/vscode && git diff HEAD > ../../ci/dev/vscode.patch", "vscode:diff": "./ci/dev/diff-vscode.sh",
"build": "./ci/build/build-code-server.sh", "build": "./ci/build/build-code-server.sh",
"build:vscode": "./ci/build/build-vscode.sh", "build:vscode": "./ci/build/build-vscode.sh",
"release": "./ci/build/build-release.sh", "release": "./ci/build/build-release.sh",