DEV Community

Pacharapol Withayasakpunt
Pacharapol Withayasakpunt

Posted on

Avoiding having both `yarn.lock` and `package-lock.json`

This is possible with pre-install script to check for yarn.lock and package.json.

The closest I can find for this is,

GitHub logo sindresorhus / is-npm

Check if your code is running as an npm or yarn script

Now, I did ask the author to make CLI for me, but he didn't do exactly what I needed, so I made one myself.

GitHub logo patarapolw / check-npm-yarn

CLI to check NPM or Yarn if specified, or look for package-lock.json or yarn.lock

Now, there is still an extra step. "preinstall": "npx check-npm-yarn" alone might not be enough. To avoid npx and installing every time, I make it,

  "scripts": {
    "preinstall": "if command -v check-npm-yarn > /dev/null; then check-npm-yarn; fi"
Enter fullscreen mode Exit fullscreen mode

An issue with NPM -- preinstall npm hook doesn’t execute when installing a specific package

I created nsi script for this.

nsi packageA packageB packageC ...
// Or nsi packageA packageB packageC ... --dev
Enter fullscreen mode Exit fullscreen mode

Related Topic

Top comments (2)

sebbdk profile image
Sebastian Vargr • Edited

What are your thoughts on checking this in CI or with a git hook?

I am thinking there might be edge cases where one would want to install with the other manager to temporarily test something out.

Edit: And the pre-install can technically be omitted, although that would imply, someone wanting' to omit the rules.

patarapolw profile image
Pacharapol Withayasakpunt • Edited

I made bugs. I tested, so should be fixed now.