Deno 升级: deno upgrade

deno upgrade 命令用来升级 Deno 的版本。

概述

详细命令介绍为:

$ deno upgrade -h             
deno-upgrade 
Upgrade deno executable to the given version.
Defaults to latest.

The version is downloaded from
https://github.com/denoland/deno/releases
and is used to replace the current executable.

USAGE:
    deno upgrade [OPTIONS]

OPTIONS:
        --dry-run                  Perform all checks without replacing old exe
    -f, --force                    Replace current exe even if not out-of-date
    -h, --help                     Prints help information
    -L, --log-level <log-level>    Set log level [possible values: debug, info]
    -q, --quiet                    Suppress diagnostic output
        --version <version>        The version to upgrade to

默认会升级到 Deno 的最新版本。

此命令会从 https://github.com/denoland/deno/releases 获取最新版本,并替换到当前版本。

命令行参数

--dry-run

尝试升级,但不是真正的升级,只是做了一些升级需要的检查。

如果当前不是最新版,则会升级到最新版。

$ deno upgrade --dry-run
Checking for latest version
Version has been found
Deno is upgrading to version 1.0.5
downloading https://github.com/denoland/deno/releases/download/v1.0.5/deno-x86_64-apple-darwin.zip
downloading https://github-production-release-asset-2e65be.s3.amazonaws.com/133442384/6d099280-a5bc-11ea-8293-3999a307e39a?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20200611%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20200611T061000Z&X-Amz-Expires=300&X-Amz-Signature=def71e38584bf02e3558a93265ce160105d857c23bbab4301328076129eedef4&X-Amz-SignedHeaders=host&actor_id=0&repo_id=133442384&response-content-disposition=attachment%3B%20filename%3Ddeno-x86_64-apple-darwin.zip&response-content-type=application%2Foctet-stream
Archive:  /var/folders/r1/nrr55q9j51v7h3tkk3y4dmf80000gn/T/.tmpUWFyGR/deno.zip
  inflating: deno                    
Upgrade done successfully

如果当前版本已经是最新版本,则输出:

$ deno upgrade --dry-run
Checking for latest version
Local deno version 1.0.5 is the most recent release

如果升级到一个不存在的版本,则会提示错误:

$ deno upgrade --dry-run --version 2.0.0
Version has been found
Deno is upgrading to version 2.0.0
downloading https://github.com/denoland/deno/releases/download/v2.0.0/deno-x86_64-apple-darwin.zip
error: Import 'https://github.com/denoland/deno/releases/download/v2.0.0/deno-x86_64-apple-darwin.zip' failed: 404 Not Found

:关于 --version 参数下面有解释。

--force

强制升级,即使当前版本已经已经是最新版。

使用 --force 参数时,Deno 会忽略对于版本的检查。

$ deno upgrade --force  
Checking for latest version
Version has been found
Deno is upgrading to version 1.0.5
downloading https://github.com/denoland/deno/releases/download/v1.0.5/deno-x86_64-apple-darwin.zip
downloading https://github-production-release-asset-2e65be.s3.amazonaws.com/133442384/6d099280-a5bc-11ea-8293-3999a307e39a?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20200611%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20200611T061213Z&X-Amz-Expires=300&X-Amz-Signature=7983a542595a1aea53fc355f4c378c911752158be8f8e0e0391e72b0aa1bf39c&X-Amz-SignedHeaders=host&actor_id=0&repo_id=133442384&response-content-disposition=attachment%3B%20filename%3Ddeno-x86_64-apple-darwin.zip&response-content-type=application%2Foctet-stream
Archive:  /var/folders/r1/nrr55q9j51v7h3tkk3y4dmf80000gn/T/.tmpWCYuzY/deno.zip
  inflating: deno                    
Upgrade done successfully

--version

升级到特定版本。

此参数使用语义化版本,如果不是,则抛出错误,并停止升级。

$ deno upgrade --version 2.0 
Invalid semver passed

此命令名虽然是 upgrade,但是不仅仅可以升级,也可以降级。

2赞

前文说到了,此命令会从 https://github.com/denoland/deno/releases 下载可执行的二进制文件 zip 压缩包,而 github release 的文件使用的是 aws,在国内访问不稳定。

可以使用 Deno install 国内镜像重新安装 Deno 以达到升级的目的。

curl -fsSL https://x.deno.js.cn/install.sh | sh