-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] "license" key in lockfile is never populated #5532
Comments
I can confirm this issue. When I issue |
Hey @fritzy is there some way I can chase this up? It seems like a pretty huge bug if my understanding is correct, but I'm unsure. I'd love to know if this is really as broken as it seems or if I'm misunderstanding the usage |
I was trying to investigate when has
I've also tried node 16 and npm 7.0.0, 7.10, 7.20. Still the lockfile after I have no idea why the license fields used to be populated (I clearly have them in my repo history) or why they no longer are. |
@amw Yeah, we have similar fixture data in Syft and cannot recreate it. I was really hoping someone from the npm side would be able to drop by and fill in the details here, but its been nearly 3 months so it doesn't sound like this is high priority. Maybe it was only in a particular npm version by accident. |
I am very confused by this finding which may be a workaround: I have added "npm" as a (normal) dependency into my Then, In my (in my tests I removed both I do not understand why this is happening. Can anyone else reproduce this workaround? |
TL;DR: there is a bug in the npm install cli. Sometimes the licenses are written into the The problematic part is that the Yesterday, the workaround one posting back was working like 100%. Now, it does not anymore. After several times doing My current hypotheses is that this may be an effect of cached IO and Promises not waited for. So, I tried with a removed I hope these descriptions are helping someone with code knowledge to formulate a better hypotheses on what is actually happening. |
Using https://www.baeldung.com/linux/empty-buffer-cache I could reproduce it (from my current point of view - hey loving timing!): rm ../pl-first.json ../pl-second.json
rm -rf node_modules/* && rm package-lock.json
sudo bash -c "free && sync && echo 3 > /proc/sys/vm/drop_caches && free"
npm install
cp package-lock.json ../pl-first.json
rm -rf node_modules/.package-lock.json && rm package-lock.json
npm install
cp package-lock.json ../pl-second.json
meld ../pl-first.json ../pl-second.json Another thing which might help in the bug search is the actual difference which tells that "resolved" and "integrity" is replaced with the "license", so we need to find the place where this is done. 4748,4749d4034
< "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz",
< "integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==",
4750a4036
> "license": "MIT",
4760,4761c4046
< "resolved": "https://registry.npmjs.org/zrender/-/zrender-5.4.4.tgz",
< "integrity": "sha512-0VxCNJ7AGOMCWeHVyTrGzUgrK4asT4ml9PEkeGirAkKNYXYzoPJCLvmyfdoOXcjTHPs10OZVMfD1Rwg16AZyYw==",
---
> "license": "BSD-3-Clause", |
I have tried the script above on a very small What is happening:
If I remove the two lock files, then this happens:
Why did the npm dependency help with the sub-dependencies?
What was happening with your mumbling about IO cache, timing etc?
Conclusion: We need to find out, why the license field is not found/used if loaded from the registry. |
TL;DR: Real Workaround included in last line! Ok, I have found the culprit: npmcli is using // Corgis are cute. 🐕🐶
const corgiDoc = 'application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8, */*'
const fullDoc = 'application/json' EDIT: the corgi mime type declares "v1" which seems to resolve into manifest version 1 which is possibly filtered server-side to suffice this format. If I put v7, I get a transformed format including the "license" metadata. This is influenced by two options: https://github.com/npm/pacote/blob/53cf17e02f54cb620de013081be063f24573d6ce/lib/fetcher.js#L93 According to that, we need one of the options # rm package-lock.json node_modules/.package-lock.json
# so that resolve/integrity are stored in the lock file:
# rm -r node_modules/*
npm install --before=2050-01-01 |
The following are the reproduction steps for NPM:
The easiest fix locally in npmcli is setting "fullMetadata" for any pacote call. However, this results into way more data to be downloaded from @fritzy This probably needs a decision/discussion within npm, can you please point the correct persons to this? |
Thanks for the investigation and workaround @HeikoStudt Unfortunately it doesn't seem like the npm folks have much interest in acknowledging this issue 😞 |
Does this still occur in npm v9 and v10? |
EDIT: English (ups :)) However, the steps 8 & 9, i.e. the workaround utilizing the npmcli parameter "--before" does not work in this version: I still get resolved+integrity but not the license. I checked back using NPM 8.5.1 and the workaround is working there. I checked in pacote source (GitHub |
I'm so sorry @ljharb I totally missed your reply. Yes, it still occurs in the latest versions of npm. Its unclear to me if it was ever supposed to work, but nobody has had the time to acknowledge or discuss it. |
This is fixed by effe910 which will be in the next |
Is there an existing issue for this?
This issue exists in the latest npm version
Current Behavior
npm v8.19.2 does not populate the "license" key in a v3
package-lock.json
, which appears to be documented here: https://docs.npmjs.com/cli/v8/configuring-npm/package-lock-json#packagesIt's unclear to me whether that key is specific to the root package (under the
""
key), or whether it should be populated for all keys.Expected Behavior
I'd expect to the see npm's license information, judging by the docs
Steps To Reproduce
MacOS, Node 18.9.0, npm 8.19.2
package.json
package-lock.json
Environment
The text was updated successfully, but these errors were encountered: