Babel 构建程序正在破坏 NPM bin 脚本的权限
Babel build program is breaking permission of NPM bin script
我有一个带有 bin
属性 link 脚本的 NPM 包,例如
/foo/package.json
{
"name": "foo",
"bin": "./dist/index.js"
}
/foo/src/index.js
#! /usr/bin/env node
console.log('Hello, World!');
我使用 npm link
创建一个全局安装的符号 link of foo
包。
然后我使用:
node ./node_modules/.bin/babel\
--watch ./src\
--out-dir ./dist
接下来,我有一个bar
包。
package.json
{
"name": "bar",
"scripts": {
"test-foo": "foo"
}
}
我使用 npm link foo
从本地 node_modules
文件夹创建一个 symlink 到全局 symlink.
然后我尝试执行 npm run test-foo
。我希望收到 "Hello, World!" 消息。相反,我收到以下错误消息:
npm run test-foo
> bar@0.0.0 test-foo /bar
> foo
sh: /Users/gajus/bar/node_modules/.bin/foo: Permission denied
npm ERR! Darwin 15.2.0
npm ERR! argv "/Users/gajus/.nvm/versions/node/v5.3.0/bin/node" "/Users/gajus/.nvm/versions/node/v5.3.0/bin/npm" "run" "test-foo"
npm ERR! node v5.3.0
npm ERR! npm v3.5.2
npm ERR! code ELIFECYCLE
npm ERR! bar@3.7.3 test-foo: `foo`
npm ERR! Exit status 126
npm ERR!
npm ERR! Failed at the table@3.7.3 test-foo script 'foo'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the table package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! foo
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs table
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls table
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /Users/gajus/Documents/dev/gajus/table/npm-debug.log
这基本上是在抱怨当前用户没有执行 /Users/gajus/bar/node_modules/.bin/foo
文件的权限。
我可以解决这个问题:
chmod +x /Users/gajus/bar/node_modules/.bin/foo
但是我一开始就不明白这个文件没有权限执行是什么原因。我是 运行 babel
程序作为同一个用户。
NPM 设置全局符号的方式似乎有问题link(设置一次。当babel --watch
创建新文件时,它不再存在)。
让 +x
坚持 npm link
的解决方案是什么?
解决方案非常简单:授予执行源文件的权限,即
chmod +x /foo/src/index.js
当Babel程序复制文件时,它也会复制该文件的权限。这也适用于 --watch
。
我有一个带有 bin
属性 link 脚本的 NPM 包,例如
/foo/package.json
{
"name": "foo",
"bin": "./dist/index.js"
}
/foo/src/index.js
#! /usr/bin/env node
console.log('Hello, World!');
我使用 npm link
创建一个全局安装的符号 link of foo
包。
然后我使用:
node ./node_modules/.bin/babel\
--watch ./src\
--out-dir ./dist
接下来,我有一个bar
包。
package.json
{
"name": "bar",
"scripts": {
"test-foo": "foo"
}
}
我使用 npm link foo
从本地 node_modules
文件夹创建一个 symlink 到全局 symlink.
然后我尝试执行 npm run test-foo
。我希望收到 "Hello, World!" 消息。相反,我收到以下错误消息:
npm run test-foo
> bar@0.0.0 test-foo /bar
> foo
sh: /Users/gajus/bar/node_modules/.bin/foo: Permission denied
npm ERR! Darwin 15.2.0
npm ERR! argv "/Users/gajus/.nvm/versions/node/v5.3.0/bin/node" "/Users/gajus/.nvm/versions/node/v5.3.0/bin/npm" "run" "test-foo"
npm ERR! node v5.3.0
npm ERR! npm v3.5.2
npm ERR! code ELIFECYCLE
npm ERR! bar@3.7.3 test-foo: `foo`
npm ERR! Exit status 126
npm ERR!
npm ERR! Failed at the table@3.7.3 test-foo script 'foo'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the table package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! foo
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs table
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls table
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /Users/gajus/Documents/dev/gajus/table/npm-debug.log
这基本上是在抱怨当前用户没有执行 /Users/gajus/bar/node_modules/.bin/foo
文件的权限。
我可以解决这个问题:
chmod +x /Users/gajus/bar/node_modules/.bin/foo
但是我一开始就不明白这个文件没有权限执行是什么原因。我是 运行 babel
程序作为同一个用户。
NPM 设置全局符号的方式似乎有问题link(设置一次。当babel --watch
创建新文件时,它不再存在)。
让 +x
坚持 npm link
的解决方案是什么?
解决方案非常简单:授予执行源文件的权限,即
chmod +x /foo/src/index.js
当Babel程序复制文件时,它也会复制该文件的权限。这也适用于 --watch
。