only-allow is a tool that enforces developers to use a specific package manager on their project.
Problems
The standard package manager for JavaScript is NPM, however there are other popular package managers such as Yarn and PNPM.
Between the package managers, there are some incompatibilities. For example, npm and yarn lock the versions of the installed packages in a different way. NPM saves it in package-lock.json, Yarn does in yarn.lock.
To use the same one package manager among the developers is important. This is to prevent unexpected incompatibilities.
Solutions
Documentation
The simplest way to employ the one same package manager in the team is to call a developer's attention by documentation. For example, you can write about it on README.md like:
"Please use Yarn to set up this project!"
However, this way sometimes fails. Some developers don't read it. There is no force in documentation.
"only-allow"
The better way to enforce the developers to use a specific package manager is to employ only-allow. It enforces developers to use a specific package manager on their project.
If a developer tries to use NPM in a Yarn-only-allowed project, the process will fail. only-allow
will tell s/he to use Yarn instead of NPM:
How to set up "only-allow"
To set up only-allow
is quite simple. Just adds a preinstall
script to the package.json
:
{
"scripts": {
"preinstall": "npx only-allow yarn"
}
}
It does't need to install only-allow
.
Conclusion
- To use a same package manager among developers in a project is important.
- Documentation sometimes can't force the developers to use the same package manager.
-
only-allow
is useful to force to use the same package manager in a project.
Top comments (0)