Open silverwind opened 1 year ago
Do you mean, it downloads it from github a second time? I don't think packages from github can ever be cached, so they're always fetched fresh.
No, these are normal npm registry packages. The only difference in the log of the unexpected reinstallation is the moves
object being popuplated and mark retired
is shown. E.g. with the repro:
npm sill reify mark retired [ '/Users/silverwind/git/nano-npm/node_modules/nano-memoize' ]
npm sill reify moves {
npm sill reify '/Users/silverwind/git/nano-npm/node_modules/nano-memoize': '/Users/silverwind/git/nano-npm/node_modules/.nano-memoize-mSgVARDY'
npm sill reify }
With a different package that does not have the issue:
npm sill reify moves {}
Some more observations:
node_modules
is not touch
ed.ah my bad, i misread your OP, sorry.
Empty engines
is not the reason. I've published the package without it, the issue persists. Will debug further.
Checking further, it seems Arborist sees below diff. Only difference is that actual
does not have a resolved
property in the second run, despite it being present and matching below ideal
in the first run after the ADD
action.
actual: ArboristNode {
name: '@silverwind/nano-memoize',
version: 'v3.0.11',
location: 'node_modules/@silverwind/nano-memoize',
path: '/Users/silverwind/git/nano-npm/node_modules/@silverwind/nano-memoize',
edgesIn: Set(1) { { "" prod @silverwind/nano-memoize@3.0.11 } }
},
ideal: ArboristNode {
name: '@silverwind/nano-memoize',
version: '3.0.11',
location: 'node_modules/@silverwind/nano-memoize',
path: '/Users/silverwind/git/nano-npm/node_modules/@silverwind/nano-memoize',
resolved: 'https://registry.npmjs.org/@silverwind/nano-memoize/-/nano-memoize-3.0.11.tgz',
edgesIn: Set(1) { { "" prod @silverwind/nano-memoize@3.0.11 } }
},
action: 'CHANGE',
Found the root cause, the package has a v
prefix in package.json's version
field which then triggers the bug in arborist that leads to arborist incorrectly retiring the package:
@silverwind/nano-memoize@3.0.16
is the last version with prefix@silverwind/nano-memoize@3.0.17
is the first version without itI'm surprised a package with a v in that field would be accepted to be published by the registry. If that's the case, even for historical packages, then arborist may need to allow it.
Docs say it must be parsable by semver
which happily does it. So I guess it's not strictly invalid, but to avoid this bug and similar, it might be good that npm publish
forbids it, I suppose.
> require("semver").parse("v1.2.3")
SemVer {
options: {},
loose: false,
includePrerelease: false,
raw: 'v1.2.3',
major: 1,
minor: 2,
patch: 3,
prerelease: [],
build: [],
version: '1.2.3'
}
I opened https://github.com/anywhichway/nano-memoize/pull/57 to work around the issue. Maybe later I'll check where arborist exactly goes wrong here.
As per semver spec, a "v" prefix is invalid. But the semver
package apparently does not honor that spec and strips the prefix.
Edit: found https://github.com/npm/node-semver/issues/376 about that.
Found another affected package: https://github.com/BackendStack21/0http/blob/1934ce50b67cd5f89b482e3a60e615583875eb68/package.json#L3, so it looks it's not that uncommon that packages have this "v" prefix in their version field. Will file a PR there as well.
Is there an existing issue for this?
This issue exists in the latest npm version
Current Behavior
On some rare packages, npm seems to incorrectly re-install them when the timestamp of
node_modules
is updated and the second installation does not print "up to date" but "changed 1 package". The issue seems to be very specific tonano-memoize
and I suspect their emptyengines
might have something to do with it.Expected Behavior
Clone reproduction repo and try it:
It should print
but it actually prints
In the verbose log it can be seen that in the second run, there is a "retired":
Steps To Reproduce
See above
Environment
See log output above.