In the last two posts I took apart what a dependency bump did to our pnpm audit and what our four overrides do. The first ended with three advisories that no override reaches, and one of them names an esbuild version that nothing in our project imports.
This is the post about that version, and about a thing I did not expect to learn from it: a single line in package.json that changes what the audit calls production.
Counting duplicates
The lockfile lists every package as name@version. Group by name, keep the names with more than one version:
import re, collections txt = open('pnpm-lock.yaml').read() sec = txt.split('\npackages:\n', 1)[1].split('\nsnapshots:\n', 1)[0] keys = re.findall(r"^ '?((?:@[^/@\s']+/)?[^@\s']+)@([^:'\s]+)'?:\s*$", sec, re.M) by = collections.defaultdict(set) for name, version in keys: by[name].add(version) multi = {n: v for n, v in by.items() if len(v) > 1} The result for the lockfile at HEAD:
Entries in the packages section | 842 |
| Distinct package names | 761 |
| Names that appear in more than one version | 57 |
| Extra copies (versions beyond the first) | 81 |
57 names out of 761 is 7.5 per cent, which sounds like normal tree wear. The distribution is not normal. Take away one family and the picture changes:
| names | extra copies | |
|---|---|---|
esbuild and its @esbuild/* platform packages | 27 | 50 |
| everything else | 30 | 31 |
One tool accounts for 62 per cent of our duplicates. It has three versions in the lockfile, 0.18.20, 0.25.12 and 0.28.2, and because esbuild ships its native binary as one separate package per platform (26 of them), each version drags up to 26 near-identical entries behind it. Seventy-seven of the 842 entries, 9 per cent of the whole lockfile, are esbuild.
The 31 extra copies in the rest are the ordinary kind: minimatch in three majors, ajv 6 and 8, brace-expansion 1 and 5, the eslint-scope and estraverse pairs that every linter tree carries. They are the usual price of a package that was written before its dependents agreed on a version.
Who asks for esbuild
pnpm why answers it in one command:
pnpm why esbuild esbuild@0.18.20 └─┬ @esbuild-kit/core-utils@3.3.2 └─┬ @esbuild-kit/esm-loader@2.6.5 └─┬ drizzle-kit@0.31.11 esbuild@0.25.12 └─┬ drizzle-kit@0.31.11 esbuild@0.28.2 ├─┬ terser-webpack-plugin (via the Sentry bundler plugin) ├─┬ tsx@4.23.15 │ ├─┬ drizzle-kit@0.31.11 │ └── nextjs (devDependencies) └── vite@8.4.0 (via the test runner) Three versions, three owners. Our own tsx, the test runner's vite and the error-reporting bundler plugin share the newest. And drizzle-kit is the single package responsible for both of the other two: it depends on one esbuild directly and on an older one through @esbuild-kit, a loader its maintainers have deprecated. A plain pnpm install says so on every run:
WARN 3 deprecated subdependencies found: @esbuild-kit/core-utils@3.3.2, @esbuild-kit/esm-loader@2.6.5, @opentelemetry/sdk-trace-base@2.12.0 The 0.18.20 version is the one with our remaining esbuild advisory, a development-server one, and it is installed because a database migration CLI loads a TypeScript config file.
The line that matters
Here is drizzle-kit in our package.json:
"dependencies": { ... "drizzle-kit": "^0.31.11", It is under dependencies, not devDependencies. I went and looked at what actually uses it, because I assumed something in the app did:
grep -rn "drizzle-kit" --include='*.ts' --include='*.tsx' --include='*.mjs' --include='*.json' . | grep -v node_modules # drizzle.config.ts:1:import { defineConfig } from "drizzle-kit"; # package.json:12: "db:generate": "drizzle-kit generate", # package.json:13: "db:migrate": "drizzle-kit migrate", # package.json:14: "db:push": "drizzle-kit push", # package.json:15: "db:studio": "drizzle-kit studio", A config file and four scripts you type by hand. Nothing in a page, an action or a route imports it, and the build command stopped running a migration in October. So it is a command line tool that happens to sit in the list that tooling treats as the product's runtime.
That list matters because pnpm audit has a flag for it:
pnpm audit --prod Run on the two lockfiles from the last post:
advisories with --prod | critical | high | |
|---|---|---|---|
| before the bump | 70 | 6 | 28 |
| after the bump | 3 | 0 | 0 |
The three left are the same three, because as far as the audit can tell, drizzle-kit is part of what we ship.
I tested the alternative in a scratch directory, the same way as in the previous post: copy the package files, move one line from dependencies to devDependencies, re-resolve with pnpm install --lockfile-only, and audit:
drizzle-kit under dependencies --prod: 3 advisories esbuild, minimatch, glob drizzle-kit under devDependencies --prod: 2 advisories minimatch, glob Nothing else changed. The resolved versions are the same, the lockfile is the same size, and the esbuild advisory goes from "production" to "development" because that is the only thing it was ever about. It is a labelling change and I want to be honest that it is only that: it removes no code and fixes no bug. What it changes is whether the next person to run pnpm audit --prod in CI sees a failure caused by a tool that a database administrator runs by hand.
I have not made the change. I expect the hosting build installs development dependencies anyway to run the compiler, so no effect on the deploy, but "I expect" is not a test, and I would build a preview before moving a line in a manifest I do not fully own.
Two smaller points
The deprecation warning is the better audit. pnpm audit found 86 things. pnpm install printed the same three "deprecated subdependencies" on every run I did today, and two of them are the esbuild-kit loader that causes this whole post. A warning that never changes is the easiest kind to stop reading.
Duplicates are not a defect. Three versions of esbuild is correct behaviour for a package manager that gives each dependent the version it asked for. The cost is disk and install time, and in our case roughly 77 entries in a lockfile that I now know how to explain. The risk is the third one, the old version nobody chose, and that is the part to watch rather than the count.
The one-line version
pnpm why esbuild # who owns each copy pnpm audit --prod --json # what is called production Run both on your own project before you decide whether a number is large. Mine was 81 and 50 of them were one tool.
If you run a quiz night and want something that does not need any of this, the free tools work in the browser with no account, and the homepage is the product they sit next to.
