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
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)
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`)
- Runs tests
- [./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)
- Our patch of VS Code to enable remote browser access
- 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`.
- [./build/build-static-release.sh](./build/build-static-release.sh) (`yarn release:static`)
- 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`)
- Removes all git ignored files like build artifacts.
- Removes all build artifacts
- 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)
- 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`)

View File

@ -40,7 +40,7 @@ bundle_code_server() {
{
"commit": "$(git rev-parse HEAD)",
"scripts": {
"postinstall": "cd lib/vscode && yarn --production && cd extensions && yarn --production"
"postinstall": "cd lib/vscode && npm rebuild # Builds native modules"
}
}
EOF
@ -49,18 +49,15 @@ EOF
bundle_vscode() {
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/.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"
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
jq --slurp '.[0] * .[1]' "$VSCODE_SRC_PATH/product.json" <(
cat << EOF
@ -71,12 +68,17 @@ bundle_vscode() {
EOF
) > "$VSCODE_OUT_PATH/product.json"
# We remove the scripts field so that later on we can run
# yarn to fetch node_modules if necessary without build scripts
# being ran.
# We cannot use --no-scripts because we still want dependant package scripts to run
# for native modules to be rebuilt.
jq 'del(.scripts)' < "$VSCODE_SRC_PATH/package.json" > "$VSCODE_OUT_PATH/package.json"
pushd "$VSCODE_OUT_PATH"
yarn --production --ignore-scripts
popd
# Now we clear any native module builds.
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 "$@"

View File

@ -3,10 +3,22 @@ set -euo pipefail
main() {
cd "$(dirname "${0}")/../.."
source ./ci/lib.sh
git clean -Xffd
git submodule foreach --recursive git clean -xffd
git submodule foreach --recursive git reset --hard
rm -Rf \
out \
release \
release-static \
release-packages \
release-gcp \
dist \
.tsbuildinfo \
.cache/out.tsbuildinfo
pushd lib/vscode
git clean -xffd
git reset --hard
popd
}
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
```
The static release will be in `./release-static` and the release packages
(.deb, .rpm, self contained release) in `./release-packages`.
The static release will be in `./release-static` and .deb, .rpm and self-contained release in `./release-packages`.

View File

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