How I Evaluate a Dependency Before Adding It
Adding a dependency takes one command. Removing it later can take a week. So before a new package goes into the dependencies of something I publish, I spend about fifteen minutes on a routine. It is not a scoring system and it will not catch everything, but it reliably catches the obvious problems.
Step one: do I need it at all?
The first question is whether the job can be done with the standard library or a few lines of my own code. If what I need is one small, well-understood function, I usually write it and add tests. Dependencies earn their place when they encapsulate something genuinely hard: parsing a complex format, cryptography, timezone rules, protocol implementations. Those are areas where a maintained library is far safer than my own attempt.
Step two: who maintains it, and how?
I look at the repository rather than the registry page, and I look for signs of an active, responsive project rather than a particular number:
- Are issues answered, even if the answer is "won't fix"?
- Are there recent releases, and do they come with changelog entries?
- Is there more than one person with publish rights, or a clear succession plan?
- Does the project have a security policy explaining how to report vulnerabilities?
A quiet project is not automatically bad. Some small libraries are simply finished. What worries me is a project with open security reports and no response. The OpenSSF Scorecard project automates several of these checks and is a useful second opinion.
Step three: what does it bring with it?
A package's own code is only part of what I would be adding. I check:
- Transitive dependencies. A small helper with a deep tree is not small.
- Install scripts. Lifecycle scripts such as
postinstallrun code on every user's machine during install. I want to know what they do. - Licence. Is it declared with a recognised SPDX identifier, and is it compatible with my package's licence and my users' likely use?
- Runtime support. Does its supported runtime range match or exceed mine?
- Module format and types. Does it work in the module systems I support, and does it ship type declarations if my users expect them?
Step four: what would leaving cost?
This is the step people skip. I ask how much of my public API would be shaped by this dependency. If I only call it internally, swapping it later is a private refactor. If my functions return its objects or re-export its types, it becomes part of my contract, and replacing it becomes a breaking change. When a dependency must be used, I prefer to wrap it behind my own small interface.
Writing it down
For a library with several maintainers, I keep a short note in the pull request that adds the dependency, covering why it is needed, the alternatives considered and the licence. An illustrative template:
Dependency: example-dateparse ^2.3.0
Why: parsing RFC 2822 dates; stdlib lacks lenient parsing
Alternatives: own parser (rejected: edge cases), none smaller
Licence: MIT (SPDX) Install scripts: none
Exposed in our API: no (wrapped in src/internal/dates.js)
Future maintainers will thank you for that note when they do their own audit. Related terms are collected in the glossary.