Skip to content
Open
6 changes: 6 additions & 0 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ jobs:
- name: Install bats-core
run: brew install bats-core

- name: Remove rust's cargo (if any)
run: |
if test -n "$(command -v cargo)"; then
rm -f $(command -v cargo)
fi

- name: Test plugin
run: |
asdf plugin-add deno $GITHUB_WORKSPACE
Expand Down
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
- git
- gunzip (for v0.35.0 or lower)
- unzip (for v0.36.0 or higher)
- To build from source, you will need these dependencies:
- cargo (you can install it through [asdf-rust](https://github.com/asdf-community/asdf-rust))

## Installation

Expand All @@ -25,6 +27,28 @@ asdf plugin-add deno https://github.com/asdf-community/asdf-deno.git
Check [asdf](https://github.com/asdf-vm/asdf) readme for instructions on how to
install & manage versions.

### Install from source

Rust's cargo is needed in order to install from the source.

#### Install specific version

To install specific version from source, use

```bash
asdf install deno ref:<version>
```

To install the latest version from source, run `asdf install deno ref:latest`

#### Install specific version by git commit

To install specific version by git commit from source, use

```bash
asdf install deno ref:<full-commit-hash>
```

## License

Licensed under the
Expand Down
105 changes: 67 additions & 38 deletions bin/install
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ set -Eeuo pipefail

trap cleanup SIGINT SIGTERM ERR

deno_git="https://github.com/denoland/deno"

cleanup() {
trap - SIGINT SIGTERM ERR
rm -rf "$ASDF_INSTALL_PATH"
Expand All @@ -18,13 +20,36 @@ fail() {
exit 1
}

install_from_archive() {
local source_path=$1
local download_url=$2
local uncompress_command=$3
curl --fail --silent --location --create-dirs --output "$source_path" "$download_url"
$uncompress_command "$source_path"
}

install_from_source() {
local install_path=$1
local ref=$2

if [ -z "$ref" ] || [ "$ref" == "latest" ]; then
cargo install --root "$install_path" deno --locked
elif [ "$(printf '%s' "$ref" | wc -c)" -eq 40 ]; then
cargo install --root "$install_path" --git "$deno_git" --rev "$ref" deno --locked
else
cargo install --root "$install_path" --version "$ref" deno --locked
fi
}

install_deno() {
local install_type=$1
local version=$2
local install_path=$3

if [ "$install_type" != "version" ]; then
fail "asdf-deno supports release installs only"
if [ -z "$(command -v cargo)" ] || ! cargo >/dev/null 2>&1; then
fail "build from source (${version:-latest}) require 'cargo' to be installed"
fi
fi

local platform
Expand All @@ -33,48 +58,52 @@ install_deno() {
local uncompress_command
local archive_file

if [[ $version > "0.35.0" ]]; then
case "$OSTYPE" in
darwin*) platform="apple-darwin" ;;
linux*) platform="unknown-linux-gnu" ;;
*) fail "Unsupported platform" ;;
esac

case "$(uname -m)" in
x86_64) architecture="x86_64" ;;
arm64) architecture="aarch64" ;;
*) fail "Unsupported architecture" ;;
esac

archive_format="zip"
archive_file="deno-${architecture}-${platform}.${archive_format}"
uncompress_command="unzip -d ${install_path}/bin"
if [ "$install_type" == "version" ]; then
if [[ $version > "0.35.0" ]]; then
case "$OSTYPE" in
darwin*) platform="apple-darwin" ;;
linux*) platform="unknown-linux-gnu" ;;
*) fail "Unsupported platform" ;;
esac

case "$(uname -m)" in
x86_64) architecture="x86_64" ;;
arm64) architecture="aarch64" ;;
*) fail "Unsupported architecture" ;;
esac

archive_format="zip"
archive_file="deno-${architecture}-${platform}.${archive_format}"
uncompress_command="unzip -d ${install_path}/bin"
else
case "$OSTYPE" in
darwin*) platform="osx" ;;
linux*) platform="linux" ;;
*) fail "Unsupported platform" ;;
esac

case "$(uname -m)" in
x86_64) architecture="x64" ;;
*) fail "Unsupported architecture" ;;
esac

archive_format="gz"
archive_file="deno_${platform}_${architecture}.${archive_format}"
uncompress_command="gunzip"
fi

local download_url="https://github.com/denoland/deno/releases/download/v${version}/${archive_file}"
local source_path="${install_path}/bin/deno.${archive_format}"
echo "* Downloading and installing deno..."
install_from_archive "$source_path" "$download_url" "$uncompress_command"
rm "$source_path"
else
case "$OSTYPE" in
darwin*) platform="osx" ;;
linux*) platform="linux" ;;
*) fail "Unsupported platform" ;;
esac

case "$(uname -m)" in
x86_64) architecture="x64" ;;
*) fail "Unsupported architecture" ;;
esac

archive_format="gz"
archive_file="deno_${platform}_${architecture}.${archive_format}"
uncompress_command="gunzip"
echo "* Building and installing deno..."
install_from_source "$install_path" "$version"
fi

local download_url="https://github.com/denoland/deno/releases/download/v${version}/${archive_file}"
local source_path="${install_path}/bin/deno.${archive_format}"

echo "* Downloading and installing deno..."
curl --fail --silent --location --create-dirs --output "$source_path" "$download_url"
$uncompress_command "$source_path"
chmod +x "${install_path}/bin/deno"
mkdir "${install_path}/.deno"
rm "$source_path"
echo "The installation was successful!"
}

Expand Down
4 changes: 2 additions & 2 deletions test/install.bats
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bats

@test "install command fails if the input is not version number" {
@test "install command fails if the input is a ref and cargo is not installed" {
run asdf install deno ref
[ "$status" -eq 1 ]
echo "$output" | grep "supports release installs only"
echo "$output" | grep "build from source (latest) require 'cargo' to be installed"
}