Preinstall check that mentions 'yarn kbn' (#16572) (#16600)

This commit is contained in:
Kim Joar Bekkelund 2018-02-08 14:32:26 +01:00 committed by GitHub
parent 6dd14be2dd
commit 8bb9b8bf58
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 0 deletions

View file

@ -41,6 +41,7 @@
"Yuri Astrakhan <yuri@elastic.co>"
],
"scripts": {
"preinstall": "node ./preinstall_check",
"kbn": "node scripts/kbn",
"test": "grunt test",
"test:dev": "grunt test:dev",

32
preinstall_check.js Normal file
View file

@ -0,0 +1,32 @@
const isUsingNpm = process.env.npm_config_git !== undefined;
if (isUsingNpm) {
throw "Use Yarn instead of npm, see Kibana's contributing guidelines";
}
// The value of the `npm_config_argv` env for each command:
//
// - `npm install`: '{"remain":[],"cooked":["install"],"original":[]}'
// - `yarn`: '{"remain":[],"cooked":["install"],"original":[]}'
// - `yarn kbn bootstrap`: '{"remain":[],"cooked":["run","kbn"],"original":["kbn","bootstrap"]}'
const rawArgv = process.env.npm_config_argv;
if (rawArgv === undefined) {
return;
}
try {
const argv = JSON.parse(rawArgv);
if (argv.cooked.includes('kbn')) {
// all good, trying to install deps using `kbn`
return;
}
if (argv.cooked.includes('install')) {
console.log('\nWARNING: When installing dependencies, prefer `yarn kbn bootstrap`\n');
}
} catch (e) {
// if it fails we do nothing, as this is just intended to be a helpful message
}