Skip to content

Commit

Permalink
add a shell script that downloads esbuild directly
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Dec 6, 2022
1 parent 157860b commit 055f9e3
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -27,6 +27,7 @@
/require/*/demo/
/scripts/.*/
/validate/
/www
bin
esbuild.exe
node_modules/
16 changes: 16 additions & 0 deletions CHANGELOG.md
Expand Up @@ -38,6 +38,22 @@

This change was not made with performance in mind. But as a bonus, installing esbuild with npm may potentially happen faster now. This is because npm's package installation protocol is inefficient: it always downloads metadata for all past versions of each package even when it only needs metadata about a single version. This makes npm package downloads O(n) in the number of published versions, which penalizes packages like esbuild that are updated regularly. Since most of esbuild's package names have now changed, npm will now need to download much less data when installing esbuild (8.72mb of package manifests before this change → 0.06mb of package manifests after this change). However, this is only a temporary improvement. Installing esbuild will gradually get slower again as further versions of esbuild are published.

* Publish a shell script that downloads esbuild directly

In addition to all of the existing ways to install esbuild, you can now also download esbuild directly like this:

```sh
curl -fsSL https://esbuild.github.io/dl/latest | sh
```

This runs a small shell script that downloads the latest `esbuild` binary executable to the current directory. This can be convenient on systems that don't have `npm` installed or when you just want to get a copy of esbuild quickly without any extra steps. If you want a specific version of esbuild (starting with this version onward), you can provide that version in the URL instead of `latest`:

```sh
curl -fsSL https://esbuild.github.io/dl/v0.16.0 | sh
```

Note that the download script needs to be able to access registry.npmjs.org to be able to complete the download. This download script doesn't yet support all of the platforms that esbuild supports because I lack the necessary testing environments. If the download script doesn't work for you because you're on an unsupported platform, please file an issue on the esbuild repo so we can add support for it.

* Fix some parameter names for the Go API

This release changes some parameter names for the Go API to be consistent with the JavaScript and CLI APIs:
Expand Down
12 changes: 11 additions & 1 deletion Makefile
Expand Up @@ -434,7 +434,8 @@ publish-all: check-go-version
@read OTP && OTP="$$OTP" $(MAKE) --no-print-directory -j4 \
publish-neutral \
publish-deno \
publish-wasm
publish-wasm \
publish-dl

git push origin main "v$(ESBUILD_VERSION)"

Expand Down Expand Up @@ -519,6 +520,15 @@ publish-deno:
cd deno && git tag "v$(ESBUILD_VERSION)"
cd deno && git push origin main "v$(ESBUILD_VERSION)"

publish-dl:
test -d www/.git || (rm -fr www && git clone git@github.com:esbuild/esbuild.github.io.git www)
cd www && git fetch && git checkout gh-pages && git reset --hard origin/gh-pages
cd www && cat ../dl.sh | sed 's/$$ESBUILD_VERSION/$(ESBUILD_VERSION)/' > dl/latest
cd www && cat ../dl.sh | sed 's/$$ESBUILD_VERSION/$(ESBUILD_VERSION)/' > "dl/v$(ESBUILD_VERSION)"
cd www && git add dl/latest "dl/v$(ESBUILD_VERSION)"
cd www && git commit -m "publish download script for $(ESBUILD_VERSION)"
cd www && git push origin gh-pages

validate-build:
@test -n "$(TARGET)" || (echo "The environment variable TARGET must be provided" && false)
@test -n "$(PACKAGE)" || (echo "The environment variable PACKAGE must be provided" && false)
Expand Down
21 changes: 21 additions & 0 deletions dl.sh
@@ -0,0 +1,21 @@
#!/bin/sh
set -eu
dir=$(mktemp -d)
platform=$(uname -ms)
tgz="$dir/esbuild-$ESBUILD_VERSION.tgz"

# Download the binary executable for the current platform
case $platform in
'Darwin arm64') curl -fo "$tgz" "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-$ESBUILD_VERSION.tgz";;
'Darwin x86_64') curl -fo "$tgz" "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-$ESBUILD_VERSION.tgz";;
'Linux arm64' | 'Linux aarch64') curl -fo "$tgz" "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-$ESBUILD_VERSION.tgz";;
'Linux x86_64') curl -fo "$tgz" "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-$ESBUILD_VERSION.tgz";;
'NetBSD amd64') curl -fo "$tgz" "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-$ESBUILD_VERSION.tgz";;
'OpenBSD amd64') curl -fo "$tgz" "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-$ESBUILD_VERSION.tgz";;
*) echo "error: Unsupported platform: $platform"; exit 1
esac

# Extract the binary executable to the current directory
tar -xzf "$tgz" -C "$dir" package/bin/esbuild
mv "$dir/package/bin/esbuild" .
rm "$tgz"

0 comments on commit 055f9e3

Please sign in to comment.