Forcing use of Yarn, instead of npm install

Everyone knows if there’s a package.json, then you need to npm install to install dependencies for the project.

Unless there’s a yarn.lock! When sharing a project around a team this will happen over and over.

Share project -> team mate ignores instructions -> generates & checks in a package-lock.json. Packages are resolved differently, different bugs are seen, lock files are not honored.

Adding a preinstall command to force the user to use ‘yarn’ puts a hard roadblock in front of unsuspecting npm installers.

"scripts": {
  ...
  "preinstall": "node -e \"if(process.env.npm_execpath.indexOf('yarn') === -1) throw new Error('You must use Yarn to install, not NPM')"
  ...
}

Now, npm i yields:

Error: You must use Yarn to install, not NPM