简体   繁体   English

如何使软件包管理器npm在Mac OS X上使用bash 4?

[英]How to make the package manager npm use bash 4 on Mac OS X?

I've updated bash to version 4 on Mac OS X Yosemite using homebrew , in order to make it possible to use "globstar" in my npm scripts. 我已经使用homebrew在Mac OS X Yosemite上将bash更新到了版本4 ,以便可以在我的npm脚本中使用“ globstar”。 Eg recursively list all .js files in test directory using the pattern ./test/**/*.js . 例如,使用模式./test/**/*.js递归列出test目录中的所有.js文件。 However, npm will run scripts with older bash version (version 3). 但是,npm将运行具有较旧bash版本(版本3)的脚本。

Is it possible to make npm uses the updated bash version? 是否可以使npm使用更新的bash版本?

(I'm not sure, but I guess npm uses /bin/bash instead of /usr/local/bin/bash) (我不确定,但是我猜npm使用/ bin / bash而不是/ usr / local / bin / bash)

UPDATE: My particular use case is to investigate the possibilities to use npm as a build tool, and for instance bundle all test specs with browserify using a npm script such as "build:test:scripts": "browserify ./test/**/*.js -o /build/test-bundle.js", . 更新:我的特殊用例是研究使用npm作为构建工具的可能性,例如,使用npm脚本(例如"build:test:scripts": "browserify ./test/**/*.js -o /build/test-bundle.js",所有测试规范与"build:test:scripts": "browserify ./test/**/*.js -o /build/test-bundle.js",

尝试用单引号将“ globstar”包装起来:

"build:test:scripts": "browserify './test/**/*.js' -o /build/test-bundle.js",

Simply set the script-shell config key to the path of your Bash 4 installation. 只需将script-shell config键设置为Bash 4安装路径。

script-shell : The shell to use for scripts run with the npm run command. script-shell用于通过npm run命令运行的脚本的shell

# local
npm config set script-shell "/usr/local/bin/bash"

# global
npm config set -g script-shell "/usr/local/bin/bash"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM