From 1739b21600dd826ad88840f7aa3ed9a6cc625de8 Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Wed, 13 May 2020 02:35:11 -0400 Subject: [PATCH] Bundle VS Code node_modules to avoid yarn dependency Many random bizarre issues otherwise. Also includes misc improvements to docs and scripts. --- README.md | 2 +- ci/README.md | 12 ++++++++---- ci/build/build-release.sh | 28 +++++++++++++++------------- ci/build/clean.sh | 18 +++++++++++++++--- ci/dev/diff-vscode.sh | 11 +++++++++++ ci/dev/patch-vscode.sh | 11 +++++++++++ doc/CONTRIBUTING.md | 3 +-- package.json | 4 ++-- 8 files changed, 64 insertions(+), 25 deletions(-) create mode 100755 ci/dev/diff-vscode.sh create mode 100755 ci/dev/patch-vscode.sh diff --git a/README.md b/README.md index d99076a7..d0a95abc 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/ci/README.md b/ci/README.md index be08b7bf..dc3e0da5 100644 --- a/ci/README.md +++ b/ci/README.md @@ -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`) diff --git a/ci/build/build-release.sh b/ci/build/build-release.sh index d96a466d..0c1117e4 100755 --- a/ci/build/build-release.sh +++ b/ci/build/build-release.sh @@ -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 "$@" diff --git a/ci/build/clean.sh b/ci/build/clean.sh index df8da6de..c57e0b43 100755 --- a/ci/build/clean.sh +++ b/ci/build/clean.sh @@ -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 "$@" diff --git a/ci/dev/diff-vscode.sh b/ci/dev/diff-vscode.sh new file mode 100755 index 00000000..a1c1f027 --- /dev/null +++ b/ci/dev/diff-vscode.sh @@ -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 "$@" diff --git a/ci/dev/patch-vscode.sh b/ci/dev/patch-vscode.sh new file mode 100755 index 00000000..cdc2691a --- /dev/null +++ b/ci/dev/patch-vscode.sh @@ -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 "$@" diff --git a/doc/CONTRIBUTING.md b/doc/CONTRIBUTING.md index def3df0f..2eeefc47 100644 --- a/doc/CONTRIBUTING.md +++ b/doc/CONTRIBUTING.md @@ -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`. diff --git a/package.json b/package.json index 87696289..246db4c7 100644 --- a/package.json +++ b/package.json @@ -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",