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

Use curl instead of iwr on Windows #153

Closed
MarkTiedemann opened this issue Jun 25, 2020 · 4 comments
Closed

Use curl instead of iwr on Windows #153

MarkTiedemann opened this issue Jun 25, 2020 · 4 comments

Comments

@MarkTiedemann
Copy link
Contributor

MarkTiedemann commented Jun 25, 2020

Since early 2018, curl is available as %SystemRoot%\System32\curl.exe on Windows (see: https://devblogs.microsoft.com/commandline/tar-and-curl-come-to-windows/). So instead of Invoke-WebRequest we could use curl some day in the future, once we decide to no longer support older Windows versions.

This would allow us to harmonize the output of the Shell and the PowerShell installer.

On a side note, this may allow us to drop the requirement of powershell.exe in favor of cmd.exe: The main reason that powershell.exe is used for our Windows installer rather than cmd is that cmd has no built-in utilities for making HTTP requests and no utilities for extracting archives (though, similar to curl.exe, tar.exe is a built-in utility on Windows now, too).

On yet another note, curl is a few seconds faster for downloading the deno.zip compared to iwr from my limited testing.

@MarkTiedemann
Copy link
Contributor Author

MarkTiedemann commented Jun 25, 2020

Download latest Deno version using cmd + curl in one line:

C:\>for /f "delims=/ tokens=6" %v in ('"curl -s https://github.com/denoland/deno/releases | findstr \/denoland/deno/releases/download/.*/deno-x86_64-pc-windows-msvc.zip | findstr /n . | findstr ^1:"') do @curl -LO https://github.com/denoland/deno/releases/download/%v/deno-x86_64-pc-windows-msvc.zip

Explanation:
  • Download the HTML from the release page: curl -s https://github.com/denoland/deno/releases
  • Find all lines that contain a Windows download link: | findstr \/denoland/deno/releases/download/.*/deno-x86_64-pc-windows-msvc.zip
  • Number those lines: | findstr /n .
  • Keep only the first line: | findstr ^1:
  • Split the download link with the character / and only keep the substring number 6, which is the version number: for /f "delims=/ tokens=6" %v in ...
  • Knowing the version number %v, download the latest Deno .zip file: curl -LO https://github.com/denoland/deno/releases/download/%v/deno-x86_64-pc-windows-msvc.zip

Note that, in order to run this batch script from a install.cmd file downloaded from a URL, the install command would have to be something like this:

curl -O https://deno.land/x/install/install.cmd & install & del install.cmd

e.g. download a temp file, run it, delete it. As far as I know, there's no eval for cmd.exe.

PS: If anyone reading this is interested in using cmd for managing Deno, please check out: https://github.com/MarkTiedemann/dvm.cmd, a Deno Version Manager I wrote.

@MarkTiedemann
Copy link
Contributor Author

MarkTiedemann commented Jun 25, 2020

On yet another random note, there's the possibility to write the Deno installer for Windows in JavaScript, uh, JScript, which is installed on Windows by default as part of the Windows Script Host:

C:\>echo WSH.Echo("Hello, world!") > hello.js
C:\>cscript //e:jscript //nologo hello.js
Hello, world!

@MarkTiedemann
Copy link
Contributor Author

MarkTiedemann commented Jun 29, 2020

Download, extract, and run latest Deno version in one line of batch:

C:\>for /f "delims=/ tokens=6" %v in ('"curl -s https://github.com/denoland/deno/releases | findstr \/denoland/deno/releases/download/.*/deno-x86_64-pc-windows-msvc.zip | findstr /n . | findstr ^1:"') do @curl -Lo deno.zip https://github.com/denoland/deno/releases/download/%v/deno-x86_64-pc-windows-msvc.zip& @tar xf deno.zip& @.\deno -V
deno 1.1.2

@MarkTiedemann
Copy link
Contributor Author

Closing in favor of #154.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant