From 9805375ead79d9fb482fe59e28dd391b350f4b0d Mon Sep 17 00:00:00 2001 From: Sirisak Lueangsaksri <1087399+spywhere@users.noreply.github.com> Date: Sat, 12 Feb 2022 16:18:15 +0700 Subject: [PATCH 01/13] Support build from source --- README.md | 2 ++ bin/install | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b6e7ae0..63a46d3 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/bin/install b/bin/install index c0699c8..73a8199 100755 --- a/bin/install +++ b/bin/install @@ -24,7 +24,12 @@ install_deno() { local install_path=$3 if [ "$install_type" != "version" ]; then - fail "asdf-deno supports release installs only" + if [ -n "$(command -v cargo)" ]; then + echo cargo install --root "$install_path" --version "$version" deno --locked + return + else + fail "build from source ($version) require 'cargo' to be installed" + fi fi local platform From 0ac032953df9567ef8b7d954542d97bef0ac5e74 Mon Sep 17 00:00:00 2001 From: Sirisak Lueangsaksri <1087399+spywhere@users.noreply.github.com> Date: Sat, 12 Feb 2022 16:34:53 +0700 Subject: [PATCH 02/13] Clean up and installation messages --- bin/install | 100 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 59 insertions(+), 41 deletions(-) diff --git a/bin/install b/bin/install index 73a8199..5a20a42 100755 --- a/bin/install +++ b/bin/install @@ -18,16 +18,27 @@ 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 version=$2 + cargo install --root "$1" --version "$2" deno --locked +} + install_deno() { local install_type=$1 local version=$2 local install_path=$3 if [ "$install_type" != "version" ]; then - if [ -n "$(command -v cargo)" ]; then - echo cargo install --root "$install_path" --version "$version" deno --locked - return - else + if [ -z "$(command -v cargo)" ]; then fail "build from source ($version) require 'cargo' to be installed" fi fi @@ -37,49 +48,56 @@ install_deno() { local archive_format local uncompress_command local archive_file + local source_path + + 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 - 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" + 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}" + source_path="${install_path}/bin/deno.${archive_format}" + echo "* Downloading and installing deno..." + install_from_archive "$source_path" "$download_url" "$uncompress_command" 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" + if [ -f "$source_path" ]; then + rm "$source_path" + fi echo "The installation was successful!" } From de71de2838926871de60ffb79cf66fcd322bacd8 Mon Sep 17 00:00:00 2001 From: Sirisak Lueangsaksri <1087399+spywhere@users.noreply.github.com> Date: Sat, 12 Feb 2022 16:44:56 +0700 Subject: [PATCH 03/13] Better cargo detection --- bin/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/install b/bin/install index 5a20a42..8e57c0d 100755 --- a/bin/install +++ b/bin/install @@ -38,7 +38,7 @@ install_deno() { local install_path=$3 if [ "$install_type" != "version" ]; then - if [ -z "$(command -v cargo)" ]; then + if [ -z "$(command -v cargo)" ] || ! cargo >/dev/null 2>&1; then fail "build from source ($version) require 'cargo' to be installed" fi fi From 11a111bddbd9325cf367b49afd8d6aea520850ee Mon Sep 17 00:00:00 2001 From: Sirisak Lueangsaksri <1087399+spywhere@users.noreply.github.com> Date: Sat, 12 Feb 2022 16:51:19 +0700 Subject: [PATCH 04/13] Optional version --- bin/install | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/bin/install b/bin/install index 8e57c0d..d69fbef 100755 --- a/bin/install +++ b/bin/install @@ -29,7 +29,12 @@ install_from_archive() { install_from_source() { local install_path=$1 local version=$2 - cargo install --root "$1" --version "$2" deno --locked + + if [ "$version" == "" ]; then + cargo install --root "$1" deno --locked + else + cargo install --root "$1" --version "$2" deno --locked + fi } install_deno() { @@ -39,7 +44,7 @@ install_deno() { if [ "$install_type" != "version" ]; then if [ -z "$(command -v cargo)" ] || ! cargo >/dev/null 2>&1; then - fail "build from source ($version) require 'cargo' to be installed" + fail "build from source (${version:-latest}) require 'cargo' to be installed" fi fi From 7a6c9df84c32c24c9072f9d055b63b1174a937a4 Mon Sep 17 00:00:00 2001 From: Sirisak Lueangsaksri <1087399+spywhere@users.noreply.github.com> Date: Sat, 12 Feb 2022 16:55:01 +0700 Subject: [PATCH 05/13] Update tests --- test/install.bats | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/install.bats b/test/install.bats index 1fa7bc3..60c9e65 100644 --- a/test/install.bats +++ b/test/install.bats @@ -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" } From 070d53d7aa62009a102f329c99505dcaa23aa751 Mon Sep 17 00:00:00 2001 From: Sirisak Lueangsaksri <1087399+spywhere@users.noreply.github.com> Date: Sat, 12 Feb 2022 16:57:23 +0700 Subject: [PATCH 06/13] Allow latest as a version --- bin/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/install b/bin/install index d69fbef..3f97ff8 100755 --- a/bin/install +++ b/bin/install @@ -30,7 +30,7 @@ install_from_source() { local install_path=$1 local version=$2 - if [ "$version" == "" ]; then + if [ "$version" == "" ] || [ "$version" == "latest" ]; then cargo install --root "$1" deno --locked else cargo install --root "$1" --version "$2" deno --locked From 1748f240acef5ac7bf83d62547f35d28549d1549 Mon Sep 17 00:00:00 2001 From: Sirisak Lueangsaksri <1087399+spywhere@users.noreply.github.com> Date: Sat, 12 Feb 2022 17:06:50 +0700 Subject: [PATCH 07/13] Refactor source path --- bin/install | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/bin/install b/bin/install index 3f97ff8..79af29d 100755 --- a/bin/install +++ b/bin/install @@ -53,7 +53,6 @@ install_deno() { local archive_format local uncompress_command local archive_file - local source_path if [ "$install_type" == "version" ]; then if [[ $version > "0.35.0" ]]; then @@ -90,9 +89,10 @@ install_deno() { fi local download_url="https://github.com/denoland/deno/releases/download/v${version}/${archive_file}" - source_path="${install_path}/bin/deno.${archive_format}" + 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 echo "* Building and installing deno..." install_from_source "$install_path" "$version" @@ -100,9 +100,6 @@ install_deno() { chmod +x "${install_path}/bin/deno" mkdir "${install_path}/.deno" - if [ -f "$source_path" ]; then - rm "$source_path" - fi echo "The installation was successful!" } From d10a4d15cbea9c8a092cd4bb909dd5fca82ce26d Mon Sep 17 00:00:00 2001 From: Sirisak Lueangsaksri <1087399+spywhere@users.noreply.github.com> Date: Sat, 12 Feb 2022 17:29:10 +0700 Subject: [PATCH 08/13] Remove cargo in test --- .github/workflows/workflow.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 9d6ec1b..81785b7 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -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 From 82bef5ea166ea40c79d3f66367b756316c4a0745 Mon Sep 17 00:00:00 2001 From: Sirisak Lueangsaksri <1087399+spywhere@users.noreply.github.com> Date: Fri, 11 Mar 2022 22:26:19 +0700 Subject: [PATCH 09/13] Support install from git commit hash --- bin/install | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/bin/install b/bin/install index 79af29d..2dc83ca 100755 --- a/bin/install +++ b/bin/install @@ -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" @@ -28,12 +30,14 @@ install_from_archive() { install_from_source() { local install_path=$1 - local version=$2 + local ref=$2 - if [ "$version" == "" ] || [ "$version" == "latest" ]; then - cargo install --root "$1" deno --locked + if [ -z "$ref" ] || [ "$ref" == "latest" ]; then + cargo install --root "$install_path" deno --locked + elif [ "$(wc -c "$ref")" -eq 40 ]; then + cargo install --root "$install_path" --git "$deno_git" --rev "$ref" deno --locked else - cargo install --root "$1" --version "$2" deno --locked + cargo install --root "$install_path" --version "$ref" deno --locked fi } From 8f1967852757f015e4616114f7b8d900d4df42bb Mon Sep 17 00:00:00 2001 From: Sirisak Lueangsaksri <1087399+spywhere@users.noreply.github.com> Date: Fri, 11 Mar 2022 22:26:33 +0700 Subject: [PATCH 10/13] Update readme on how to install specific version --- README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.md b/README.md index 63a46d3..c3fc42c 100644 --- a/README.md +++ b/README.md @@ -27,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: +``` + +To install the latest version, 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: +``` + ## License Licensed under the From 81f5571c65e36d12123f981920af45d2b4e05297 Mon Sep 17 00:00:00 2001 From: Sirisak Lueangsaksri <1087399+spywhere@users.noreply.github.com> Date: Fri, 11 Mar 2022 22:28:57 +0700 Subject: [PATCH 11/13] Clarify on the latest version --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c3fc42c..5ba7980 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ To install specific version from source, use asdf install deno ref: ``` -To install the latest version, run `asdf install deno ref:latest` +To install the latest version from source, run `asdf install deno ref:latest` #### Install specific version by git commit From 632b16ddc589988f6cc9c86b9eb78bc40742f4cf Mon Sep 17 00:00:00 2001 From: Sirisak Lueangsaksri <1087399+spywhere@users.noreply.github.com> Date: Fri, 11 Mar 2022 22:32:03 +0700 Subject: [PATCH 12/13] Fix string length calculation --- bin/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/install b/bin/install index 2dc83ca..e66c079 100755 --- a/bin/install +++ b/bin/install @@ -34,7 +34,7 @@ install_from_source() { if [ -z "$ref" ] || [ "$ref" == "latest" ]; then cargo install --root "$install_path" deno --locked - elif [ "$(wc -c "$ref")" -eq 40 ]; then + elif [ "$(printf "$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 From 9abe82eb9baaa93ad32d330fd6f9956539bbc367 Mon Sep 17 00:00:00 2001 From: Sirisak Lueangsaksri <1087399+spywhere@users.noreply.github.com> Date: Fri, 11 Mar 2022 23:14:02 +0700 Subject: [PATCH 13/13] Fix shellcheck issue on printf --- bin/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/install b/bin/install index e66c079..435907a 100755 --- a/bin/install +++ b/bin/install @@ -34,7 +34,7 @@ install_from_source() { if [ -z "$ref" ] || [ "$ref" == "latest" ]; then cargo install --root "$install_path" deno --locked - elif [ "$(printf "$ref" | wc -c)" -eq 40 ]; then + 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