Description
What / Why
If reifying with { omit: ['optional'], add: ['optional-dep'] }
, then optional-dep
(and its transitive dependencies) should be added, even though they are optional.
When
$ cat package.json
{
"optionalDependencies": {
"abbrev": ""
}
}
$ cat .npmrc
optional=false
$ npm i abbrev --no-save
up to date, audited 1 package in 392ms
found 0 vulnerabilities
$ npm ls
install-optional@ /Users/isaacs/dev/npm/cli/fixtures/install-optional
└── UNMET OPTIONAL DEPENDENCY abbrev@
Via: @JamesMGreene
Slack discussion:
that's.... a tiny bit tricky, but it's a legit bug. workaround, of course, is install esm with --include=optional --include=dev --include=peer just to be on the safe side, probably?
the "tiny bit tricky" part is that we apply requests and omissions at two different points. when we apply requests, it's a modification to the effective manifest/edges from the root node (or workspace node(s) if specified).
We process omissions later, by knocking out everything with the omitted flag, so any node marked optional: true will be removed before reifying.
Since the explicit request might have some deps which also have the flag, we have to build out the subtree of any explicitly requested nodes, and protect all of those from omission.
I'll write this up in a bug.