简体   繁体   中英

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. Eg recursively list all .js files in test directory using the pattern ./test/**/*.js . However, npm will run scripts with older bash version (version 3).

Is it possible to make npm uses the updated bash version?

(I'm not sure, but I guess npm uses /bin/bash instead of /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", .

尝试用单引号将“ 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 : The shell to use for scripts run with the npm run command.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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