Windows的NPM软件包"bin"脚本 [英] NPM package 'bin' script for Windows

查看:178
本文介绍了Windows的NPM软件包"bin"脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Cucumber.js提供了一个命令行二进制文件",它是一个简单的.js文件,其中包含 shebang 指令:

Cucumber.js is supplying a command-line "binary" which is a simple .js file containing a shebang instruction:

#!/usr/bin/env node
var Cucumber = require('../lib/cucumber');
// ...

package.json中使用"bin"配置键指定了二进制文件:

The binary is specified in package.json with the "bin" configuration key:

{ "name" : "cucumber"
, "description" : "The official JavaScript implementation of Cucumber."
// ...
, "bin": { "cucumber.js": "./bin/cucumber.js" }
// ...

这一切在POSIX系统上都能很好地工作.有人报告了在Windows上运行Cucumber.js时一个问题.

This all works well on POSIX systems. Someone reported an issue when running Cucumber.js on Windows.

基本上,.js文件似乎是通过Windows的JScript解释器(不是Node.js)执行的,并且由于shebang指令而引发语法错误.

Basically, the .js file seems to be executed through the JScript interpreter of Windows (not Node.js) and it throws a syntax error because of the shebang instruction.

我的问题是:设置在UNIX和Windows系统上都可以使用的二进制"脚本的推荐方法是什么?

My question is: what is the recommended way of setting up a "binary" script that works on both UNIX and Windows systems?

谢谢.

推荐答案

Windows忽略shebang行#!/usr/bin/env node并将根据.js文件关联执行它.明确使用节点调用脚本

Windows ignores the shebang line #!/usr/bin/env node and will execute it according to the .js file association. Be explicit about calling your script with node

node hello.js

ps. Pedantry:POSIX标准中的 are n't 无效,但是大多数* nix系统都支持它们.

ps. Pedantry: shebangs aren't in the POSIX standard but they are supported by most *nix system.

如果您将项目打包为Npm,请使用 package.json中的'bin'字段.然后在Windows上,Npm将在脚本旁边安装.cmd包装器,以便用户可以从命令行执行它

If you package your project for Npm, use the 'bin' field in package.json. Then on Windows, Npm will install a .cmd wrapper along side your script so users can execute it from the command-line

hello

要使npm创建填充权,脚本必须具有射手线 #!/usr/bin/env node

For npm to create the shim right, the script must have the shebang line #!/usr/bin/env node

这篇关于Windows的NPM软件包"bin"脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆