什么是`curl -L https://unpkg.com/@pnpm/self-installer |的PowerShell等价物|节点?

时间:2019-02-05 15:23:01

标签: powershell curl continuous-integration gitlab-ci-runner

我将GitLab.com与Windows OS运行程序一起使用,因此我们通常使用PowerShell代替Bash来在控制台中执行脚本步骤。我正在尝试使用pnpm,他们给出的示例建议了以下

$ curl -L https://unpkg.com/@pnpm/self-installer | node
$ install pnpm

通过上述node传递的curl请求的PowerShell版本是什么?

我一直在尝试Invoke-RestMethod并在PowerShell中使用curl别名,例如

PS> curl https://unpkg.com/@pnpm/self-installer | node

但是得到一直得到

  

SyntaxError:无效或意外的令牌

另外,根据curl文档,我知道需要--location

1 个答案:

答案 0 :(得分:1)

作为脚本中的最佳实践,我建议显式建议使用参数名称并传递正确的类型,而不是让解释器强制执行(Uri需使用System.Uri和{{1} }默认导入到PowerShell中):

System

语法错误的原因? $uri = [Uri]'https://unpkg.com/@pnpm/self-installer' $js = Invoke-RestMethod -Uri $uri 符号在PowerShell中是特殊的,称为Splatting。

运行上述命令时,它会将@脚本的内容吐出到控制台。然后可以假设js采用cli和管道输入,并且位于您的PATH中:

node

另一个假设是您的PATH中有一个$js | node 或脚本创建了某种交互式终端:

install

$ install pnpm 此处不是必需的,因为默认情况下,--location将进行最多5跳的重定向(可以使用Invoke-RestMethod进行配置)。