【发布时间】:2020-02-07 11:31:40
【问题描述】:
我在package.json 中定义了一个脚本:
"scripts": {
"prettierCheck": "./node_modules/.bin/prettier --check ./app/javascript/**/*.js"
}
如果我使用yarn run prettierCheck 运行此脚本,Prettier 不会发现我的文件有任何格式问题。但是,如果我直接运行 Prettier 命令,它会发现违规文件。
yarn run prettierCheck 的输出:
~/Projects/tome $ yarn run prettierCheck
yarn run v1.19.0
$ ./node_modules/.bin/prettier --check ./app/javascript/**/*.js
Checking formatting...
All matched files use Prettier code style!
Done in 0.20s
./node_modules/.bin/prettier --check ./app/javascript/**/*.js的输出:
~/Projects/tome $ ./node_modules/.bin/prettier --check ./app/javascript/**/*.js
Checking formatting...
{... several files listed here ...}
Code style issues found in the above file(s). Forgot to run Prettier?
为什么会这样?直接运行命令与通过 Yarn 脚本运行有什么区别?
【问题讨论】:
-
你用什么命令直接检查?
-
@AnshuKumar 和
prettierCheck脚本一模一样,只是在提示符下直接执行。 -
你能把两次执行的输出都包括进来吗?纱线是否有可能认为它正在从不同的目录执行,因此找不到传入的文件?如果您从命令中删除
./node_modules/.bin/前缀(这是多余的),会有什么变化吗? -
@Soc 是否删除前缀没有区别。用两次运行的输出更新了我的问题。
标签: npm yarnpkg npm-scripts prettier