Skip to content

Commit e04ec27

Browse files
committed
fix: Generate shrinkwraps for the bundled vscode
1 parent dea6a40 commit e04ec27

File tree

5 files changed

+79
-169
lines changed

5 files changed

+79
-169
lines changed

ci/build/build-release.sh

Lines changed: 0 additions & 10 deletions
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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,46 @@ 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: The shrinkwrap file will contain the devDependencies, which by default
40+
# are installed if present in a lockfile. To avoid every user having to specify --production
41+
# to skip them, we carefully remove them from the shrinkwrap file.
42+
json -f npm-shrinkwrap.json -I -e "Object.keys(this.dependencies).forEach(dependency => { if (this.dependencies[dependency].dev) { delete this.dependencies[dependency] } } )"
43+
44+
# HACK@edvincent: We create the shrinkwrap file from the installed node_modules folder.
45+
# Installing node-addon-api also creates an auto-generated folder under @parcel/node-addon-api for gyp,
46+
# but this actually does not have a package.json (nor it's a package that can be fetched from the repository).
47+
# Thus `npm shrinkwrap` doesn't know how to generate a lock entry for it, and leaves it empty - which then
48+
# breaks any subsequent install. We manually remove it, as on every install it will be auto-generated.
49+
json -f npm-shrinkwrap.json -I -e "if (this.dependencies['@parcel/node-addon-api'] == {}) { delete this.dependencies['@parcel/node-addon-api'] }"
50+
}
51+
52+
create_shrinkwraps() {
53+
# yarn.lock or package-lock.json files (used to ensure deterministic versions of dependencies) are
54+
# not packaged when publishing to the NPM registry.
55+
# To ensure deterministic dependency versions (even when code-server is installed with NPM), we create
56+
# an npm-shrinkwrap.json file from the currently installed node_modules. This ensures the versions used
57+
# from development (that the yarn.lock guarantees) are also the ones installed by end-users.
58+
59+
# We first generate the shrinkwrap file for code-server itself - from being in $RELEASE_PATH
60+
create_production_shrinkwrap
61+
62+
# Then the shrinkwrap files for the bundled VSCode
63+
# We don't need to remove the devDependencies for these because we control how it's installed - and
64+
# as such we can force the --production flag
65+
cd lib/vscode/
66+
create_production_shrinkwrap
67+
68+
cd extensions/
69+
create_production_shrinkwrap
70+
71+
cd ../../
3272
}
3373

3474
main "$@"

ci/build/npm-postinstall.sh

Lines changed: 30 additions & 4 deletions
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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,18 @@
6161
"eslint-plugin-import": "^2.18.2",
6262
"eslint-plugin-prettier": "^4.0.0",
6363
"json": "^11.0.0",
64+
"minimist": "npm:[email protected]",
65+
"normalize-package-data": "^4.0.0",
66+
"postcss": "^8.2.1",
6467
"prettier": "^2.2.1",
6568
"prettier-plugin-sh": "^0.10.0",
6669
"shellcheck": "^1.0.0",
6770
"stylelint": "^13.0.0",
6871
"stylelint-config-recommended": "^5.0.0",
69-
"synp": "^1.9.10",
72+
"trim": "^1.0.0",
7073
"ts-node": "^10.0.0",
71-
"typescript": "^4.4.0-dev.20210528"
74+
"typescript": "^4.4.0-dev.20210528",
75+
"underscore": "^1.13.1"
7276
},
7377
"resolutions": {
7478
"ansi-regex": "^5.0.1",
@@ -107,8 +111,7 @@
107111
"semver": "^7.1.3",
108112
"split2": "^4.0.0",
109113
"ws": "^8.0.0",
110-
"xdg-basedir": "^4.0.0",
111-
"yarn": "^1.22.4"
114+
"xdg-basedir": "^4.0.0"
112115
},
113116
"bin": {
114117
"code-server": "out/node/entry.js"

0 commit comments

Comments
 (0)