从shell运行'npm install'也运行'prepublish'脚本

时间:2016-09-06 11:06:39

标签: node.js npm package.json

这是一个SSCCE。 给出以下<form accept-charset="utf-8" method="post" enctype="multipart/form-data" id="basic_form_validation" novalidate="novalidate" class="form-horizontal" action="#users/businesses/background"> <div style="display:none;"><input type="hidden" value="POST" name="_method"></div> <div class="item in"> <div class="change-background"> <label> Change Background : </label> <input type="file" value="" id="background" name="background"> <input type="hidden" value="20015" name="userid"> </div> </div> <input type="submit" name="change" value="Change"> 文件:

package.json

从shell运行:{ "name": "foo", "version": "1.0.0", "description": "", "scripts": { "prepublish": "echo \"pre-publish script called\"" }, "devDependencies": { }, "dependencies": { "lodash": "^4.10.0" } } ,导致npm install脚本也被执行:

prepublish

如果将$ npm install > foo@1.0.0 prepublish /tmp/so > echo "pre-publish script called" pre-publish script called npm WARN foo@1.0.0 No description npm WARN foo@1.0.0 No repository field. npm WARN foo@1.0.0 No license field. 脚本重命名为例如prepublish不再使用prepublis执行该操作。问题是,我需要npm install脚本,因为我通常在发布到npm之前执行静态类型分析和Mocha测试。

这是一个错误或功能,我该如何解决它?当我只想安装prepublish依赖项时,不需要运行我的Mocha测试。

我的环境是:

package.json

1 个答案:

答案 0 :(得分:2)

正如我所说,这不是一个错误(虽然每个人都希望修复此功能),但有一个解决方案。查看https://www.npmjs.com/package/in-publish以了解这种情况。

解决方案摘要

(来自发布中的包页面)

 npm install --save in-publish

然后在package.json中:

  "scripts": {
    "prepublish": "in-publish && thing-I-dont-want-on-dev-install || not-in-publish"
  }

您还可以使用not-in-installin-install代替in-publish

  "scripts": {
    "prepublish": "not-in-install && thing-I-dont-want-on-dev-install || in-install"
  }