Skip to content

Commit 1739b21

Browse files
committed
Bundle VS Code node_modules to avoid yarn dependency
Many random bizarre issues otherwise. Also includes misc improvements to docs and scripts.
1 parent a346c6d commit 1739b21

File tree

8 files changed

+64
-25
lines changed

8 files changed

+64
-25
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ all file system operations occur as your user outside the container.
6565
### Self contained releases
6666

6767
We publish self contained archives for every release on [github](https://github.com/cdr/code-server/releases).
68-
They bundle the node binary and node_modules.
68+
They bundle the node binary and compiled native modules.
6969

7070
1. Download the latest release archive for your system from [github](https://github.com/cdr/code-server/releases)
7171
2. Unpack the release

ci/README.md

+8-4
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ This directory contains scripts used for the development of code-server.
3939
- [./dev/test.sh](./dev/test.sh) (`yarn test`)
4040
- Runs tests
4141
- [./dev/vscode.sh](./dev/vscode.sh) (`yarn vscode`)
42-
- Ensures `lib/vscode` is cloned, patched and dependencies are installed
42+
- Ensures [../lib/vscode](../lib/vscode) is cloned, patched and dependencies are installed
43+
- [./dev/patch-vscode.sh](./dev/patch-vscode.sh) (`yarn vscode:patch`)
44+
- Applies [./dev/vscode.patch](./dev/vscode.patch) to [../lib/vscode](../lib/vscode)
45+
- [./dev/diff-vscode.sh](./dev/diff-vscode.sh) (`yarn vscode:diff`)
46+
- Diffs [../lib/vscode](../lib/vscode) into [./dev/vscode.patch](./dev/vscode.patch)
4347
- [./dev/vscode.patch](./dev/vscode.patch)
4448
- Our patch of VS Code to enable remote browser access
4549
- Generate it with `yarn vscode:diff` and apply with `yarn vscode:patch`
@@ -62,11 +66,11 @@ You can disable minification by setting `MINIFY=`.
6266
- Bundles the output of the above two scripts into a single node module at `./release`.
6367
- [./build/build-static-release.sh](./build/build-static-release.sh) (`yarn release:static`)
6468
- Requires a release already built in `./release`.
65-
- Will build a static release with node and node_modules into `./release-static`
69+
- Will build a static release with node bundled into `./release-static`
6670
- [./build/clean.sh](./build/clean.sh) (`yarn clean`)
67-
- Removes all git ignored files like build artifacts.
71+
- Removes all build artifacts
6872
- Will also `git reset --hard lib/vscode`
69-
- Useful to do a clean build.
73+
- Useful to do a clean build
7074
- [./build/code-server.sh](./build/code-server.sh)
7175
- Copied into static releases to run code-server with the bundled node binary.
7276
- [./build/test-static-release.sh](./build/test-static-release.sh) (`yarn test:static-release`)

ci/build/build-release.sh

+15-13
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ bundle_code_server() {
4040
{
4141
"commit": "$(git rev-parse HEAD)",
4242
"scripts": {
43-
"postinstall": "cd lib/vscode && yarn --production && cd extensions && yarn --production"
43+
"postinstall": "cd lib/vscode && npm rebuild # Builds native modules"
4444
}
4545
}
4646
EOF
@@ -49,18 +49,15 @@ EOF
4949

5050
bundle_vscode() {
5151
mkdir -p "$VSCODE_OUT_PATH"
52+
rsync "$VSCODE_SRC_PATH/package.json" "$VSCODE_OUT_PATH"
53+
rsync "$VSCODE_SRC_PATH/yarn.lock" "$VSCODE_OUT_PATH"
54+
rsync "$VSCODE_SRC_PATH/node_modules" "$VSCODE_OUT_PATH"
5255
rsync "$VSCODE_SRC_PATH/out-vscode${MINIFY+-min}/" "$VSCODE_OUT_PATH/out"
5356
rsync "$VSCODE_SRC_PATH/.build/extensions/" "$VSCODE_OUT_PATH/extensions"
54-
rm -Rf "$VSCODE_OUT_PATH/extensions/node_modules"
55-
rsync "$VSCODE_SRC_PATH/extensions/package.json" "$VSCODE_OUT_PATH/extensions"
56-
rsync "$VSCODE_SRC_PATH/extensions/yarn.lock" "$VSCODE_OUT_PATH/extensions"
57-
rsync "$VSCODE_SRC_PATH/extensions/postinstall.js" "$VSCODE_OUT_PATH/extensions"
5857

5958
mkdir -p "$VSCODE_OUT_PATH/resources/linux"
6059
rsync "$VSCODE_SRC_PATH/resources/linux/code.png" "$VSCODE_OUT_PATH/resources/linux/code.png"
6160

62-
rsync "$VSCODE_SRC_PATH/yarn.lock" "$VSCODE_OUT_PATH"
63-
6461
# Adds the commit and date to product.json
6562
jq --slurp '.[0] * .[1]' "$VSCODE_SRC_PATH/product.json" <(
6663
cat << EOF
@@ -71,12 +68,17 @@ bundle_vscode() {
7168
EOF
7269
) > "$VSCODE_OUT_PATH/product.json"
7370

74-
# We remove the scripts field so that later on we can run
75-
# yarn to fetch node_modules if necessary without build scripts
76-
# being ran.
77-
# We cannot use --no-scripts because we still want dependant package scripts to run
78-
# for native modules to be rebuilt.
79-
jq 'del(.scripts)' < "$VSCODE_SRC_PATH/package.json" > "$VSCODE_OUT_PATH/package.json"
71+
pushd "$VSCODE_OUT_PATH"
72+
yarn --production --ignore-scripts
73+
popd
74+
75+
# Now we clear any native module builds.
76+
local nativeModules
77+
mapfile -t nativeModules < <(find "$VSCODE_OUT_PATH/node_modules" -name "binding.gyp" -exec dirname {} \;)
78+
local nm
79+
for nm in "${nativeModules[@]}"; do
80+
rm -R "$nm/build"
81+
done
8082
}
8183

8284
main "$@"

ci/build/clean.sh

+15-3
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,22 @@ set -euo pipefail
33

44
main() {
55
cd "$(dirname "${0}")/../.."
6+
source ./ci/lib.sh
67

7-
git clean -Xffd
8-
git submodule foreach --recursive git clean -xffd
9-
git submodule foreach --recursive git reset --hard
8+
rm -Rf \
9+
out \
10+
release \
11+
release-static \
12+
release-packages \
13+
release-gcp \
14+
dist \
15+
.tsbuildinfo \
16+
.cache/out.tsbuildinfo
17+
18+
pushd lib/vscode
19+
git clean -xffd
20+
git reset --hard
21+
popd
1022
}
1123

1224
main "$@"

ci/dev/diff-vscode.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
main() {
5+
cd "$(dirname "$0")/../.."
6+
7+
cd ./lib/vscode
8+
git diff HEAD > ../../ci/dev/vscode.patch
9+
}
10+
11+
main "$@"

ci/dev/patch-vscode.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
main() {
5+
cd "$(dirname "$0")/../.."
6+
7+
cd ./lib/vscode
8+
git apply ../../ci/dev/vscode.patch
9+
}
10+
11+
main "$@"

doc/CONTRIBUTING.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,4 @@ yarn test:static-release
5959
yarn package
6060
```
6161

62-
The static release will be in `./release-static` and the release packages
63-
(.deb, .rpm, self contained release) in `./release-packages`.
62+
The static release will be in `./release-static` and .deb, .rpm and self-contained release in `./release-packages`.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
"scripts": {
1212
"clean": "./ci/build/clean.sh",
1313
"vscode": "./ci/dev/vscode.sh",
14-
"vscode:patch": "cd ./lib/vscode && git apply ../../ci/dev/vscode.patch",
15-
"vscode:diff": "cd ./lib/vscode && git diff HEAD > ../../ci/dev/vscode.patch",
14+
"vscode:patch": "./ci/dev/patch-vscode.sh",
15+
"vscode:diff": "./ci/dev/diff-vscode.sh",
1616
"build": "./ci/build/build-code-server.sh",
1717
"build:vscode": "./ci/build/build-vscode.sh",
1818
"release": "./ci/build/build-release.sh",

0 commit comments

Comments
 (0)