小编Mir*_*rCZ的帖子

如何检测脚本是使用 npm 还是 yarn 运行?

我需要为 npm 和 yarn 编写通用脚本。

npm 的 package.json:

{
  "scripts": {
    "build:clean": "rim-raf dist",
    "test:clean": "rim-raf coverage",
    "clean": "npm run build:clean; npm run test:clean"
  }
}
Run Code Online (Sandbox Code Playgroud)

纱线的 package.json:

{
  "scripts": {
    "build:clean": "rim-raf dist",
    "test:clean": "rim-raf coverage",
    "clean": "yarn run build:clean; yarn run test:clean"
  }
}
Run Code Online (Sandbox Code Playgroud)

用于 npm 和 yarn 的 package.json:

我通常使用小技巧:***$_***
{
  "scripts": {
    "build:clean": "rim-raf dist",
    "test:clean": "rim-raf coverage",
    "clean": "$_ run build:clean; $_ run test:clean"
  }
}
Run Code Online (Sandbox Code Playgroud)

但有时它不能正常工作。

存在一些合法的方法来做到这一点?

node.js npm npm-scripts yarnpkg

6
推荐指数
1
解决办法
2447
查看次数

标签 统计

node.js ×1

npm ×1

npm-scripts ×1

yarnpkg ×1