diff --git a/package.json b/package.json index a99681dc49502..a0ae80509a707 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "Yuri Astrakhan " ], "scripts": { + "preinstall": "node ./preinstall_check", "kbn": "node scripts/kbn", "test": "grunt test", "test:dev": "grunt test:dev", diff --git a/preinstall_check.js b/preinstall_check.js new file mode 100644 index 0000000000000..9d1c89ceddc80 --- /dev/null +++ b/preinstall_check.js @@ -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 +} +