@@ -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
3474main " $@ "
0 commit comments