Skip to content

Commit fe6a577

Browse files
committed
fix: Generate shrinkwraps for the bundled vscode
1 parent c35bf13 commit fe6a577

File tree

5 files changed

+76
-174
lines changed

5 files changed

+76
-174
lines changed

ci/build/build-release.sh

-10
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,6 @@ EOF
5656
) > "$RELEASE_PATH/package.json"
5757
rsync yarn.lock "$RELEASE_PATH"
5858

59-
# To ensure deterministic dependency versions (even when code-server is installed with NPM), we seed
60-
# an npm-shrinkwrap file from our yarn lockfile and the current node-modules installed.
61-
synp --source-file yarn.lock
62-
npm shrinkwrap
63-
# HACK@edvincent: The shrinkwrap file will contain the devDependencies, which by default
64-
# are installed if present in a lockfile. To avoid every user having to specify --production
65-
# to skip them, we carefully remove them from the shrinkwrap file.
66-
json -f npm-shrinkwrap.json -I -e "Object.keys(this.dependencies).forEach(dependency => { if (this.dependencies[dependency].dev) { delete this.dependencies[dependency] } } )"
67-
mv npm-shrinkwrap.json "$RELEASE_PATH"
68-
6959
rsync ci/build/npm-postinstall.sh "$RELEASE_PATH/postinstall.sh"
7060

7161
if [ "$KEEP_MODULES" = 1 ]; then

ci/build/build-standalone-release.sh

+43
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,49 @@ main() {
2929

3030
cd "$RELEASE_PATH"
3131
yarn --production --frozen-lockfile
32+
33+
create_shrinkwraps
34+
}
35+
36+
create_production_shrinkwrap() {
37+
npm shrinkwrap
38+
39+
# HACK@edvincent: We create the shrinkwrap file from the installed node_modules folder.
40+
# Installing node-addon-api also creates an auto-generated folder under @parcel/node-addon-api for gyp,
41+
# but this actually does not have a package.json (nor it's a package that can be fetched from the repository).
42+
# Thus `npm shrinkwrap` doesn't know how to generate a lock entry for it, and leaves it empty - which then
43+
# breaks any subsequent install. We manually remove it, as on every install it will be auto-generated.
44+
case "$(uname)" in
45+
Darwin*)
46+
# NOTE@edouardv: The sed binary for MacOS requires an extra argument.
47+
sed -i '' '/"@parcel\/node-addon-api": {},/d' npm-shrinkwrap.json
48+
;;
49+
*)
50+
sed -i '/"@parcel\/node-addon-api": {},/d' npm-shrinkwrap.json
51+
;;
52+
esac
53+
}
54+
55+
create_shrinkwraps() {
56+
# yarn.lock or package-lock.json files (used to ensure deterministic versions of dependencies) are
57+
# not packaged when publishing to the NPM registry.
58+
# To ensure deterministic dependency versions (even when code-server is installed with NPM), we create
59+
# an npm-shrinkwrap.json file from the currently installed node_modules. This ensures the versions used
60+
# from development (that the yarn.lock guarantees) are also the ones installed by end-users.
61+
62+
# We first generate the shrinkwrap file for code-server itself - from being in $RELEASE_PATH
63+
create_production_shrinkwrap
64+
65+
# Then the shrinkwrap files for the bundled VSCode
66+
# We don't need to remove the devDependencies for these because we control how it's installed - and
67+
# as such we can force the --production flag
68+
cd lib/vscode/
69+
create_production_shrinkwrap
70+
71+
cd extensions/
72+
create_production_shrinkwrap
73+
74+
cd ../../
3275
}
3376

3477
main "$@"

ci/build/npm-postinstall.sh

+30-4
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ main() {
6666
echo "Failed to download cloud agent; --link will not work"
6767
fi
6868

69-
if ! vscode_yarn; then
69+
if ! vscode_install; then
7070
echo "You may not have the required dependencies to build the native modules."
7171
echo "Please see https://github.com/coder/code-server/blob/master/docs/npm.md"
7272
exit 1
@@ -89,15 +89,41 @@ symlink_asar() {
8989
fi
9090
}
9191

92-
vscode_yarn() {
92+
install_with_yarn_or_npm() {
93+
# NOTE@edvincent: We want to keep using the package manager that the end-user was using to install the package.
94+
# This also ensures that when *we* run `yarn` in the development process, the yarn.lock file is used.
95+
case "${npm_config_user_agent-}" in
96+
yarn*)
97+
yarn --production --frozen-lockfile
98+
;;
99+
npm*)
100+
if [ -f "yarn.lock" ]; then
101+
echo "yarn.lock file present, yarn should be used rather than npm"
102+
exit 1
103+
else
104+
# NOTE@edvincent: Ideally, this should use `npm ci --production` - which is the equivalent of a
105+
# frozen lockfile. NPM 6 doesn't deal well with `npm ci` and optionalDependencies (tries to install them
106+
# anyway) - which are used for some Windows-only packages - so until we can upgrade to a higher version
107+
# of NPM (along with Node), we rely on NPM's behavior to prefer what's on the lockfile and resolve what isn't.
108+
npm install --production
109+
fi
110+
;;
111+
*)
112+
echo "Could not determine which package manager is being used to install code-server"
113+
exit 1
114+
;;
115+
esac
116+
}
117+
118+
vscode_install() {
93119
echo 'Installing Code dependencies...'
94120
cd lib/vscode
95-
yarn --production --frozen-lockfile
121+
install_with_yarn_or_npm
96122

97123
symlink_asar
98124

99125
cd extensions
100-
yarn --production --frozen-lockfile
126+
install_with_yarn_or_npm
101127
}
102128

103129
main "$@"

package.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,11 @@
6060
"eslint-import-resolver-typescript": "^2.5.0",
6161
"eslint-plugin-import": "^2.18.2",
6262
"eslint-plugin-prettier": "^4.0.0",
63-
"json": "^11.0.0",
6463
"prettier": "^2.2.1",
6564
"prettier-plugin-sh": "^0.10.0",
6665
"shellcheck": "^1.0.0",
6766
"stylelint": "^13.0.0",
6867
"stylelint-config-recommended": "^5.0.0",
69-
"synp": "^1.9.10",
7068
"ts-node": "^10.0.0",
7169
"typescript": "^4.4.0-dev.20210528"
7270
},
@@ -107,8 +105,7 @@
107105
"semver": "^7.1.3",
108106
"split2": "^4.0.0",
109107
"ws": "^8.0.0",
110-
"xdg-basedir": "^4.0.0",
111-
"yarn": "^1.22.4"
108+
"xdg-basedir": "^4.0.0"
112109
},
113110
"bin": {
114111
"code-server": "out/node/entry.js"

0 commit comments

Comments
 (0)