Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install specific version of deno #11

Merged
merged 2 commits into from
Nov 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,25 @@ Downloads the latest Deno binary into `$HOME/.deno/bin`.
**Install with Python:**

```
curl -sSf https://raw.githubusercontent.com/denoland/deno_install/master/install.py | python
curl -L https://deno.land/x/install/install.py | python
```

**Install with PowerShell:**

```powershell
iex (iwr https://raw.githubusercontent.com/denoland/deno_install/master/install.ps1)
iex (iwr https://deno.land/x/install/install.ps1)
```

_Note: Depending on your security settings, you may have to run `Set-ExecutionPolicy RemoteSigned -Scope CurrentUser` first to allow downloaded scripts to be executed._

## Install other versions

If you need to install specific version of deno, use the following commands:

**Install with Python:**

```
curl -L https://deno.land/x/install/install.py | python - v0.2.0
```

(PowerShell version is not available yet)
17 changes: 13 additions & 4 deletions install.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
except ImportError:
from urllib2 import urlopen

RELEASES_URL = "https://github.com/denoland/deno/releases/latest"
DENO_REPO_URL = "https://github.com/denoland/deno"
LATEST_RELEASE_URL = DENO_REPO_URL + "/releases/latest"
TAG_URL = DENO_REPO_URL + "/releases/tag/"
FILENAME_LOOKUP = {
"darwin": "deno_osx_x64.gz",
"linux": "deno_linux_x64.gz", # python3
Expand All @@ -28,14 +30,21 @@
}


def release_url(platform):
def release_url(platform, tag):
try:
filename = FILENAME_LOOKUP[platform]
except KeyError:
print("Unable to locate appropriate filename for", platform)
sys.exit(1)

html = urlopen(RELEASES_URL).read().decode('utf-8')
url = TAG_URL + tag if tag else LATEST_RELEASE_URL

try:
html = urlopen(url).read().decode('utf-8')
except:
print("Unable to find release page for", tag)
sys.exit(1)

urls = re.findall(r'href=[\'"]?([^\'" >]+)', html)
matching = [u for u in urls if filename in u]

Expand All @@ -50,7 +59,7 @@ def main():
bin_dir = deno_bin_dir()
exe_fn = os.path.join(bin_dir, "deno")

url = release_url(sys.platform)
url = release_url(sys.platform, sys.argv[1] if len(sys.argv) > 1 else None)
print("Downloading", url)
compressed = urlopen(url).read()

Expand Down
31 changes: 28 additions & 3 deletions install_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@
this_dir = os.path.dirname(os.path.realpath(__file__))


def main():
def bin_dir():
home = os.path.expanduser("~")
return os.path.join(home, ".deno", "bin")


def test_install():
os.chdir(this_dir)
PATTERN = "DENO_EXE: "
home = os.path.expanduser("~")
expected_bin_dir = os.path.join(home, ".deno", "bin")
expected_bin_dir = bin_dir()
print("Testing install.py ... Expect deno installed to ", expected_bin_dir)
if os.path.exists(expected_bin_dir):
shutil.rmtree(expected_bin_dir)
Expand All @@ -33,5 +37,26 @@ def main():
assert os.path.exists(actual_fn)


def test_tag_install():
print(
"Testing install.py [tag_name] ... Expect specified version of deno installed"
)
cmd = [sys.executable, "install.py", "v0.1.11"]
out = subprocess.check_output(cmd, universal_newlines=True)

bin_path = os.path.join(bin_dir(), "deno")
cmd = [bin_path, "-v"]
out = subprocess.check_output(cmd, universal_newlines=True)

assert "deno: 0.1.11" in out, "installed deno version is not 0.1.11"
assert "v8: 7.1.302.4" in out, "v8 version is not 7.1.302.4"
assert "typescript: 3.1.3" in out, "typescript version is not 3.1.3"


def main():
test_install()
test_tag_install()


if __name__ == '__main__':
main()