Skip to content

Commit

Permalink
feat: Add a shrinkwrap file to the NPM release
Browse files Browse the repository at this point in the history
  • Loading branch information
edvincent committed Mar 23, 2022
1 parent ba1ddbd commit 58e518f
Show file tree
Hide file tree
Showing 10 changed files with 204 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ body:
id: logs
attributes:
label: Logs
description: Run code-server with the --verbose flag and then paste any relevant logs from the server, from the browser console and/or the browser network tab. For issues with installation, include installation logs (i.e. output of `yarn global add code-server`).
description: Run code-server with the --verbose flag and then paste any relevant logs from the server, from the browser console and/or the browser network tab. For issues with installation, include installation logs (i.e. output of `npm install -g code-server`).
- type: textarea
attributes:
label: Screenshot/Video
Expand Down
11 changes: 11 additions & 0 deletions ci/build/build-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ bundle_code_server() {
EOF
) > "$RELEASE_PATH/package.json"
rsync yarn.lock "$RELEASE_PATH"

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

rsync ci/build/npm-postinstall.sh "$RELEASE_PATH/postinstall.sh"

if [ "$KEEP_MODULES" = 1 ]; then
Expand Down
12 changes: 6 additions & 6 deletions ci/steps/publish-npm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ main() {
# This string is used to determine how we should tag the npm release.
# Environment can be one of three choices:
# "development" - this means we tag with the PR number, allowing
# a developer to install this version with `yarn add code-server@<pr-number>`
# a developer to install this version with `npm install code-server@<pr-number>`
# "staging" - this means we tag with `beta`, allowing
# a developer to install this version with `yarn add code-server@beta`
# a developer to install this version with `npm install code-server@beta`
# "production" - this means we tag with `latest` (default), allowing
# a developer to install this version with `yarn add code-server@latest`
# a developer to install this version with `npm install code-server@latest`
if ! is_env_var_set "NPM_ENVIRONMENT"; then
echo "NPM_ENVIRONMENT is not set. Determining in script based on GITHUB environment variables."

Expand Down Expand Up @@ -96,7 +96,7 @@ main() {
if [[ "$NPM_ENVIRONMENT" == "production" ]]; then
NPM_VERSION="$VERSION"
# This means the npm version will be published as "stable"
# and installed when a user runs `yarn install code-server`
# and installed when a user runs `npm install code-server`
NPM_TAG="latest"
else
COMMIT_SHA="$GITHUB_SHA"
Expand All @@ -107,7 +107,7 @@ main() {
if [[ "$NPM_ENVIRONMENT" == "staging" ]]; then
NPM_VERSION="$VERSION-beta-$COMMIT_SHA"
# This means the npm version will be tagged with "beta"
# and installed when a user runs `yarn install code-server@beta`
# and installed when a user runs `npm install code-server@beta`
NPM_TAG="beta"
fi

Expand All @@ -117,7 +117,7 @@ main() {
NPM_VERSION="$VERSION-$PR_NUMBER-$COMMIT_SHA"
PACKAGE_NAME="@coder/code-server-pr"
# This means the npm version will be tagged with "<pr number>"
# and installed when a user runs `yarn install code-server@<pr number>`
# and installed when a user runs `npm install code-server@<pr number>`
NPM_TAG="$PR_NUMBER"
fi

Expand Down
2 changes: 1 addition & 1 deletion docs/android.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
1. Install UserLAnd from [Google Play](https://play.google.com/store/apps/details?id=tech.ula&hl=en_US&gl=US)
2. Install an Ubuntu VM
3. Start app
4. Install Node.js, `curl` and `yarn` using `sudo apt install nodejs npm yarn curl -y`
4. Install Node.js, `curl` and `npm` using `sudo apt install nodejs npm curl -y`
5. Install `nvm`:

```shell
Expand Down
38 changes: 15 additions & 23 deletions docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

- [install.sh](#installsh)
- [Detection reference](#detection-reference)
- [yarn, npm](#yarn-npm)
- [npm](#npm)
- [Standalone releases](#standalone-releases)
- [Debian, Ubuntu](#debian-ubuntu)
- [Fedora, CentOS, RHEL, SUSE](#fedora-centos-rhel-suse)
Expand All @@ -19,7 +19,7 @@
- [Uninstall](#uninstall)
- [install.sh](#installsh-1)
- [Homebrew](#homebrew)
- [yarn, npm](#yarn-npm-1)
- [npm](#npm-1)
- [Debian, Ubuntu](#debian-ubuntu-1)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->
Expand Down Expand Up @@ -87,17 +87,16 @@ _exact_ same commands presented in the rest of this document.

- Ensure that you add `~/.local/bin` to your `$PATH` to run code-server.

- For FreeBSD, code-server will install the [npm package](#yarn-npm) with `yarn`
or `npm`.
- For FreeBSD, code-server will install the [npm package](#npm) with `npm`.

- If you're installing code-server onto architecture with no releases,
code-server will install the [npm package](#yarn-npm) with `yarn` or `npm`
code-server will install the [npm package](#npm) with `npm`
- We currently offer releases for amd64 and arm64.
- The [npm package](#yarn-npm) builds the native modules on post-install.
- The [npm package](#npm) builds the native modules on post-install.

## yarn, npm
## npm

We recommend installing with `yarn` or `npm` when:
We recommend installing with `npm` when:

1. You aren't using a machine with `amd64` or `arm64`.
1. You are installing code-server on Windows
Expand All @@ -107,17 +106,17 @@ We recommend installing with `yarn` or `npm` when:
[#1430](https://github.com/coder/code-server/issues/1430#issuecomment-629883198)
for more information.

Installing code-server with `yarn` or `npm` builds native modules on install.
Installing code-server with `npm` builds native modules on install.

This process requires C dependencies; see our guide on [installing with yarn and npm][./npm.md](./npm.md) for more information.
This process requires C dependencies; see our guide on [installing with `npm`][./npm.md](./npm.md) for more information.

## Standalone releases

We publish self-contained `.tar.gz` archives for every release on
[GitHub](https://github.com/coder/code-server/releases). The archives bundle the
node binary and node modules.

We create the standalone releases using the [npm package](#yarn-npm), and we
We create the standalone releases using the [npm package](#npm), and we
then create the remaining releases using the standalone version.

The only requirement to use the standalone release is `glibc` >= 2.17 and
Expand Down Expand Up @@ -151,7 +150,7 @@ code-server
## Debian, Ubuntu

> The standalone arm64 .deb does not support Ubuntu 16.04 or earlier. Please
> upgrade or [build with yarn](#yarn-npm).
> upgrade or [build with `npm`](#npm).
```bash
curl -fOL https://github.com/coder/code-server/releases/download/v$VERSION/code-server_$VERSION_amd64.deb
Expand All @@ -163,7 +162,7 @@ sudo systemctl enable --now code-server@$USER
## Fedora, CentOS, RHEL, SUSE

> The standalone arm64 .rpm does not support CentOS 7. Please upgrade or [build
> with yarn](#yarn-npm).
> with `npm`](#npm).
```bash
curl -fOL https://github.com/coder/code-server/releases/download/v$VERSION/code-server-$VERSION-amd64.rpm
Expand Down Expand Up @@ -228,14 +227,13 @@ You can install code-server using the [Helm package manager](https://coder.com/d

## Windows

We currently [do not publish Windows releases](https://github.com/coder/code-server/issues/1397). We recommend installing code-server onto Windows with [`yarn` or `npm`](#yarn-npm).
We currently [do not publish Windows releases](https://github.com/coder/code-server/issues/1397). We recommend installing code-server onto Windows with [ `npm`](#npm).

> Note: You will also need to [build coder/cloud-agent manually](https://github.com/coder/cloud-agent/issues/17) if you would like to use `code-server --link` on Windows.
## Raspberry Pi

We recommend installing code-server onto Raspberry Pi with [`yarn` or
`npm`](#yarn-npm).
We recommend installing code-server onto Raspberry Pi with [`npm`](#npm).

## Termux

Expand Down Expand Up @@ -277,16 +275,10 @@ brew remove code-server
brew uninstall code-server
```

### yarn, npm
### npm

To remove the code-server global module, run:

```shell
yarn global remove code-server
```

or

```shell
npm uninstall -g code-server
```
Expand Down
2 changes: 1 addition & 1 deletion docs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"children": [
{
"title": "npm",
"description": "How to install code-server using npm or yarn",
"description": "How to install code-server using npm",
"path": "./npm.md"
},
{
Expand Down
20 changes: 11 additions & 9 deletions docs/npm.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ If you're installing code-server via `npm`, you'll need to install additional
dependencies required to build the native modules used by VS Code. This article
includes installing instructions based on your operating system.

> **WARNING**: Do not use `yarn` to install code-server. Unlike `npm`, it does not respect
> lockfiles for distributed applications. It will instead use the latest version
> available at installation time - which might not be the one used for a given
> code-server release, and [might lead to unexpected behavior](https://github.com/coder/code-server/issues/4927).
## Node.js version

We use the same major version of Node.js shipped with VSCode's Electron,
Expand Down Expand Up @@ -72,7 +77,7 @@ Proceed to [installing](#installing)
## FreeBSD

```sh
pkg install -y git python npm-node14 yarn-node14 pkgconf
pkg install -y git python npm-node14 pkgconf
pkg install -y libinotify
```

Expand All @@ -85,8 +90,7 @@ Installing code-server requires all of the [prerequisites for VS Code developmen
Next, install code-server with:

```bash
yarn global add code-server
# Or: npm install -g code-server
npm install -g code-server
code-server
# Now visit http://127.0.0.1:8080. Your password is in ~/.config/code-server/config.yaml
```
Expand All @@ -96,8 +100,7 @@ A `postinstall.sh` script will attempt to run. Select your terminal (e.g., Git b
If the `code-server` command is not found, you'll need to [add a directory to your PATH](https://www.architectryan.com/2018/03/17/add-to-the-path-on-windows-10/). To find the directory, use the following command:

```shell
yarn global bin
# Or: npm config get prefix
npm config get prefix
```

For help and additional troubleshooting, see [#1397](https://github.com/coder/code-server/issues/1397).
Expand All @@ -107,8 +110,7 @@ For help and additional troubleshooting, see [#1397](https://github.com/coder/co
After adding the dependencies for your OS, install the code-server package globally:

```bash
yarn global add code-server
# Or: npm install -g code-server
npm install -g code-server
code-server
# Now visit http://127.0.0.1:8080. Your password is in ~/.config/code-server/config.yaml
```
Expand All @@ -122,7 +124,7 @@ page](https://github.com/coder/code-server/discussions).

Occasionally, you may run into issues with Node.js.

If you install code-server using `yarn` or `npm`, and you upgrade your Node.js
If you install code-server using `npm`, and you upgrade your Node.js
version, you may need to reinstall code-server to recompile native modules.
Sometimes, you can get around this by navigating into code-server's `lib/vscode`
directory and running `npm rebuild` to recompile the modules.
Expand All @@ -136,7 +138,7 @@ A step-by-step example of how you might do this is:

### Debugging install issues with npm

`yarn` suppresses logs when running `yarn global add`, so to debug installation issues, install with `npm` instead:
To debug installation issues:

```shell
# Uninstall
Expand Down
20 changes: 5 additions & 15 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ The detection method works as follows:
- Debian, Ubuntu, Raspbian: install the deb package from GitHub.
- Fedora, CentOS, RHEL, openSUSE: install the rpm package from GitHub.
- Arch Linux: install from the AUR (which pulls releases from GitHub).
- FreeBSD, Alpine: install from yarn/npm.
- FreeBSD, Alpine: install from npm.
- macOS: install using Homebrew if installed otherwise install from GitHub.
- All others: install the release from GitHub.
Expand Down Expand Up @@ -419,19 +419,9 @@ install_npm() {
echoh "Installing latest from npm."
echoh

YARN_PATH="${YARN_PATH-yarn}"
NPM_PATH="${YARN_PATH-npm}"
if command_exists "$YARN_PATH"; then
sh_c="sh_c"
if [ ! "${DRY_RUN-}" ] && [ ! -w "$($YARN_PATH global bin)" ]; then
sh_c="sudo_sh_c"
fi
echoh "Installing with yarn."
echoh
"$sh_c" "$YARN_PATH" global add code-server --unsafe-perm
NPM_BIN_DIR="\$($YARN_PATH global bin)" echo_npm_postinstall
return
elif command_exists "$NPM_PATH"; then

if command_exists "$NPM_PATH"; then
sh_c="sh_c"
if [ ! "${DRY_RUN-}" ] && [ ! -w "$(NPM_PATH config get prefix)" ]; then
sh_c="sudo_sh_c"
Expand All @@ -442,9 +432,9 @@ install_npm() {
NPM_BIN_DIR="\$($NPM_PATH bin -g)" echo_npm_postinstall
return
fi
echoerr "Please install npm or yarn to install code-server!"
echoerr "Please install npm to install code-server!"
echoerr "You will need at least node v12 and a few C dependencies."
echoerr "See the docs https://coder.com/docs/code-server/latest/install#yarn-npm"
echoerr "See the docs https://coder.com/docs/code-server/latest/install#npm"

exit 1
}
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,13 @@
"eslint-import-resolver-typescript": "^2.5.0",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-prettier": "^4.0.0",
"json": "^11.0.0",
"prettier": "^2.2.1",
"prettier-plugin-sh": "^0.8.0",
"shellcheck": "^1.0.0",
"stylelint": "^13.0.0",
"stylelint-config-recommended": "^5.0.0",
"synp": "^1.9.10",
"ts-node": "^10.0.0",
"typescript": "^4.4.0-dev.20210528"
},
Expand Down
Loading

0 comments on commit 58e518f

Please sign in to comment.