Skip to content

检查用的包管理器

如果你想让你的包使用者,只用yarn安装依赖,可以这样:

js
"scripts": {
    "preinstall": "node ./scripts/checkYarn.js",
  }
"scripts": {
    "preinstall": "node ./scripts/checkYarn.js",
  }
js
if (!/yarn\.js$/.test(process.env.npm_execpath || '')) {
  console.warn(
    '\u001b[33mThis repository requires Yarn 1.x for scripts to work properly.\u001b[39m\n'
  )
  process.exit(1)
}
if (!/yarn\.js$/.test(process.env.npm_execpath || '')) {
  console.warn(
    '\u001b[33mThis repository requires Yarn 1.x for scripts to work properly.\u001b[39m\n'
  )
  process.exit(1)
}