Skip to content

Conversation

owlstronaut
Copy link
Contributor

@owlstronaut owlstronaut commented Mar 26, 2025

… but keep them 'in the tree'

This PR was authored by @zkat

Fixes: #4828
Fixes: #7961
Replaces: #8127
Replaces: #8077

When optional dependencies fail, we don't want to install them, for whatever reason. The way this "uninstallation" is done right now is by simply removing the dependencies from the ideal tree during reification.

Unfortunately, this means that what gets saved to the "hidden lockfile" is the edited ideal tree as well, and when npm runs next, it'll use that when regenerating the "real" package-lock.

This PR tags failed optional deps such that they're still added to the "trash list" (and thus have their directories cleaned up by the reifier), but prevents Arborist from removing them altogether from the ideal tree (which is usually done by setting their parent to null, making them unreachable, and letting them get GC'd).

PS: It's Friday, this is what I managed to get done together. I'm making this a draft PR for now so folks can look at it, but I want to make sure both reifiers work well, fix some messaging issues, and clean stuff up (I'm pretty sure I'm guarding ideallyInert in more places than I need to, because I was trying to find the right spot). Still, feel free to talk about the approach. I'll get back to this on Monday.

PPS: also hi

@owlstronaut owlstronaut changed the title fix(arborist): omit failed optional dependencies from installed deps, but keep them 'in the tree' fix(arborist): omit failed optional dependencies from installed deps Mar 27, 2025
@owlstronaut
Copy link
Contributor Author

@zkat I did what I could here. Had a couple of comments/lack of my own clarity in things I changed - see above.

@owlstronaut owlstronaut marked this pull request as ready for review March 31, 2025 14:45
@owlstronaut owlstronaut requested a review from a team as a code owner March 31, 2025 14:45
@wraithgar
Copy link
Member

Other than the comment we really really should re-use the exceptional description from #8177, either by copying it into this issue now or when we merge. Probably easier to do now. I'll do it now.

const set = optionalSet(node)
for (const node of set) {
node.parent = null
node.ideallyInert = true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been thinking about this, and maybe it's better to just call it inert instead of ideallyInert. I think putting the ideally in there is probably a bit too much clever inside baseball and it's more verbose to boot. :)

Some other name would be good, too, as long as it communicates that this is in the tree, but we don't physically install it.

@paulrutter
Copy link

Thanks for pulling this work forward, much appreciated @zkat @owlstronaut @wraithgar.
Happy to see this is almost ready to get merged.

… but keep them 'in the tree'

Fixes: #4828
Fixes: #7961
Replaces: #8127
Replaces: #8077

When optional dependencies fail, we don't want to install them, for whatever reason. The way
this "uninstallation" is done right now is by simply removing the dependencies from the ideal tree
during reification.

Unfortunately, this means that what gets saved to the "hidden lockfile" is the edited ideal tree
as well, and when NPM runs next, it'll use that when regenerating the "real" package-lock.

This PR tags failed optional deps such that they're still added to the "trash list" (and thus have
their directories cleaned up by the reifier), but prevents Arborist from removing them altogether
from the ideal tree (which is usually done by setting their parent to `null`, making them unreachable,
and letting them get GC'd).
@owlstronaut owlstronaut force-pushed the owlstronaut/optionals-in-tree branch from f635c97 to 68a8d05 Compare April 1, 2025 21:17
@owlstronaut owlstronaut merged commit a96d8f6 into latest Apr 3, 2025
16 checks passed
@owlstronaut owlstronaut deleted the owlstronaut/optionals-in-tree branch April 3, 2025 15:45
@github-actions github-actions bot mentioned this pull request Apr 3, 2025
@jakebailey
Copy link

Amazing, I'm so excited for this to be fixed. Thank you @zkat @owlstronaut @wraithgar 🎉

@JounQin
Copy link

JounQin commented Apr 20, 2025

@jakebailey Can this be back ported into old versions?

@wraithgar
Copy link
Member

This is not going to be backported.

Andrew-Chen-Wang added a commit to Andrew-Chen-Wang/template-nextjs that referenced this pull request Apr 22, 2025
npm version 11.3.0 includes a fix (see: npm/cli#8184) that was pointed out in tailwindlabs/tailwindcss#15806 (comment) where it should resolve properly. See this thread for my own investigation parcel-bundler/lightningcss#956 (comment)
robodoo pushed a commit to odoo/o-spreadsheet that referenced this pull request Sep 17, 2025
Release commit 8c68f3d has been done with
Node.js v22.19.0 and NPM v10.9.3.
But in the meantime, NPM had an issue that affected the package-lock.json
by pruning OS optional dependencies (See npm/cli#7961).
The issue has been fixed (npm/cli#8184) in NPM v11.3
but not backported.

During the release process, we ran `npm install`, and so the package-lock.json
was updated to remove the optional dependencies for swc binaries.
Which caused issues for users each time they run `npm install` as they
were not present anymore in the package-lock.json.

This commit adds the swc binaries to the optional dependencies of this
project to avoid them being pruned again in the future.

closes #7147

Task: 0
Signed-off-by: Lucas Lefèvre (lul) <[email protected]>
fw-bot pushed a commit to odoo/o-spreadsheet that referenced this pull request Sep 17, 2025
Release commit 8c68f3d has been done with
Node.js v22.19.0 and NPM v10.9.3.
But in the meantime, NPM had an issue that affected the package-lock.json
by pruning OS optional dependencies (See npm/cli#7961).
The issue has been fixed (npm/cli#8184) in NPM v11.3
but not backported.

During the release process, we ran `npm install`, and so the package-lock.json
was updated to remove the optional dependencies for swc binaries.
Which caused issues for users each time they run `npm install` as they
were not present anymore in the package-lock.json.

This commit adds the swc binaries to the optional dependencies of this
project to avoid them being pruned again in the future.

Task: 0
X-original-commit: 2612a12
pro-odoo added a commit to odoo/o-spreadsheet that referenced this pull request Sep 17, 2025
Release commit 8c68f3d has been done with
Node.js v22.19.0 and NPM v10.9.3.
But in the meantime, NPM had an issue that affected the package-lock.json
by pruning OS optional dependencies (See npm/cli#7961).
The issue has been fixed (npm/cli#8184) in NPM v11.3
but not backported.

During the release process, we ran `npm install`, and so the package-lock.json
was updated to remove the optional dependencies for swc binaries.
Which caused issues for users each time they run `npm install` as they
were not present anymore in the package-lock.json.

This commit adds the swc binaries to the optional dependencies of this
project to avoid them being pruned again in the future.

Task: 0
X-original-commit: 2612a12
robodoo pushed a commit to odoo/o-spreadsheet that referenced this pull request Sep 17, 2025
Release commit 8c68f3d has been done with
Node.js v22.19.0 and NPM v10.9.3.
But in the meantime, NPM had an issue that affected the package-lock.json
by pruning OS optional dependencies (See npm/cli#7961).
The issue has been fixed (npm/cli#8184) in NPM v11.3
but not backported.

During the release process, we ran `npm install`, and so the package-lock.json
was updated to remove the optional dependencies for swc binaries.
Which caused issues for users each time they run `npm install` as they
were not present anymore in the package-lock.json.

This commit adds the swc binaries to the optional dependencies of this
project to avoid them being pruned again in the future.

closes #7148

Task: 0
X-original-commit: 2612a12
Signed-off-by: Lucas Lefèvre (lul) <[email protected]>
Signed-off-by: Pierre Rousseau (pro) <[email protected]>
fw-bot pushed a commit to odoo/o-spreadsheet that referenced this pull request Sep 17, 2025
Release commit 8c68f3d has been done with
Node.js v22.19.0 and NPM v10.9.3.
But in the meantime, NPM had an issue that affected the package-lock.json
by pruning OS optional dependencies (See npm/cli#7961).
The issue has been fixed (npm/cli#8184) in NPM v11.3
but not backported.

During the release process, we ran `npm install`, and so the package-lock.json
was updated to remove the optional dependencies for swc binaries.
Which caused issues for users each time they run `npm install` as they
were not present anymore in the package-lock.json.

This commit adds the swc binaries to the optional dependencies of this
project to avoid them being pruned again in the future.

Task: 0
X-original-commit: 6cc703f
pro-odoo added a commit to odoo/o-spreadsheet that referenced this pull request Sep 17, 2025
Release commit 8c68f3d has been done with
Node.js v22.19.0 and NPM v10.9.3.
But in the meantime, NPM had an issue that affected the package-lock.json
by pruning OS optional dependencies (See npm/cli#7961).
The issue has been fixed (npm/cli#8184) in NPM v11.3
but not backported.

During the release process, we ran `npm install`, and so the package-lock.json
was updated to remove the optional dependencies for swc binaries.
Which caused issues for users each time they run `npm install` as they
were not present anymore in the package-lock.json.

This commit adds the swc binaries to the optional dependencies of this
project to avoid them being pruned again in the future.

Task: 0
X-original-commit: 6cc703f
pro-odoo added a commit to odoo/o-spreadsheet that referenced this pull request Sep 17, 2025
Release commit 8c68f3d has been done with
Node.js v22.19.0 and NPM v10.9.3.
But in the meantime, NPM had an issue that affected the package-lock.json
by pruning OS optional dependencies (See npm/cli#7961).
The issue has been fixed (npm/cli#8184) in NPM v11.3
but not backported.

During the release process, we ran `npm install`, and so the package-lock.json
was updated to remove the optional dependencies for swc binaries.
Which caused issues for users each time they run `npm install` as they
were not present anymore in the package-lock.json.

This commit adds the swc binaries to the optional dependencies of this
project to avoid them being pruned again in the future.

Task: 0
X-original-commit: 6cc703f
robodoo pushed a commit to odoo/o-spreadsheet that referenced this pull request Sep 17, 2025
Release commit 8c68f3d has been done with
Node.js v22.19.0 and NPM v10.9.3.
But in the meantime, NPM had an issue that affected the package-lock.json
by pruning OS optional dependencies (See npm/cli#7961).
The issue has been fixed (npm/cli#8184) in NPM v11.3
but not backported.

During the release process, we ran `npm install`, and so the package-lock.json
was updated to remove the optional dependencies for swc binaries.
Which caused issues for users each time they run `npm install` as they
were not present anymore in the package-lock.json.

This commit adds the swc binaries to the optional dependencies of this
project to avoid them being pruned again in the future.

closes #7151

Task: 0
X-original-commit: 6cc703f
Signed-off-by: Lucas Lefèvre (lul) <[email protected]>
Signed-off-by: Pierre Rousseau (pro) <[email protected]>
fw-bot pushed a commit to odoo/o-spreadsheet that referenced this pull request Sep 17, 2025
Release commit 8c68f3d has been done with
Node.js v22.19.0 and NPM v10.9.3.
But in the meantime, NPM had an issue that affected the package-lock.json
by pruning OS optional dependencies (See npm/cli#7961).
The issue has been fixed (npm/cli#8184) in NPM v11.3
but not backported.

During the release process, we ran `npm install`, and so the package-lock.json
was updated to remove the optional dependencies for swc binaries.
Which caused issues for users each time they run `npm install` as they
were not present anymore in the package-lock.json.

This commit adds the swc binaries to the optional dependencies of this
project to avoid them being pruned again in the future.

Task: 0
X-original-commit: 724f762
pro-odoo added a commit to odoo/o-spreadsheet that referenced this pull request Sep 17, 2025
Release commit 8c68f3d has been done with
Node.js v22.19.0 and NPM v10.9.3.
But in the meantime, NPM had an issue that affected the package-lock.json
by pruning OS optional dependencies (See npm/cli#7961).
The issue has been fixed (npm/cli#8184) in NPM v11.3
but not backported.

During the release process, we ran `npm install`, and so the package-lock.json
was updated to remove the optional dependencies for swc binaries.
Which caused issues for users each time they run `npm install` as they
were not present anymore in the package-lock.json.

This commit adds the swc binaries to the optional dependencies of this
project to avoid them being pruned again in the future.

Task: 0
X-original-commit: 724f762
robodoo pushed a commit to odoo/o-spreadsheet that referenced this pull request Sep 17, 2025
Release commit 8c68f3d has been done with
Node.js v22.19.0 and NPM v10.9.3.
But in the meantime, NPM had an issue that affected the package-lock.json
by pruning OS optional dependencies (See npm/cli#7961).
The issue has been fixed (npm/cli#8184) in NPM v11.3
but not backported.

During the release process, we ran `npm install`, and so the package-lock.json
was updated to remove the optional dependencies for swc binaries.
Which caused issues for users each time they run `npm install` as they
were not present anymore in the package-lock.json.

This commit adds the swc binaries to the optional dependencies of this
project to avoid them being pruned again in the future.

closes #7153

Task: 0
X-original-commit: 724f762
Signed-off-by: Lucas Lefèvre (lul) <[email protected]>
Signed-off-by: Pierre Rousseau (pro) <[email protected]>
fw-bot pushed a commit to odoo/o-spreadsheet that referenced this pull request Sep 17, 2025
Release commit 8c68f3d has been done with
Node.js v22.19.0 and NPM v10.9.3.
But in the meantime, NPM had an issue that affected the package-lock.json
by pruning OS optional dependencies (See npm/cli#7961).
The issue has been fixed (npm/cli#8184) in NPM v11.3
but not backported.

During the release process, we ran `npm install`, and so the package-lock.json
was updated to remove the optional dependencies for swc binaries.
Which caused issues for users each time they run `npm install` as they
were not present anymore in the package-lock.json.

This commit adds the swc binaries to the optional dependencies of this
project to avoid them being pruned again in the future.

Task: 0
X-original-commit: b1dc674
fw-bot pushed a commit to odoo/o-spreadsheet that referenced this pull request Sep 17, 2025
Release commit 8c68f3d has been done with
Node.js v22.19.0 and NPM v10.9.3.
But in the meantime, NPM had an issue that affected the package-lock.json
by pruning OS optional dependencies (See npm/cli#7961).
The issue has been fixed (npm/cli#8184) in NPM v11.3
but not backported.

During the release process, we ran `npm install`, and so the package-lock.json
was updated to remove the optional dependencies for swc binaries.
Which caused issues for users each time they run `npm install` as they
were not present anymore in the package-lock.json.

This commit adds the swc binaries to the optional dependencies of this
project to avoid them being pruned again in the future.

Task: 0
X-original-commit: b1dc674
fw-bot pushed a commit to odoo/o-spreadsheet that referenced this pull request Sep 17, 2025
Release commit 8c68f3d has been done with
Node.js v22.19.0 and NPM v10.9.3.
But in the meantime, NPM had an issue that affected the package-lock.json
by pruning OS optional dependencies (See npm/cli#7961).
The issue has been fixed (npm/cli#8184) in NPM v11.3
but not backported.

During the release process, we ran `npm install`, and so the package-lock.json
was updated to remove the optional dependencies for swc binaries.
Which caused issues for users each time they run `npm install` as they
were not present anymore in the package-lock.json.

This commit adds the swc binaries to the optional dependencies of this
project to avoid them being pruned again in the future.

Task: 0
X-original-commit: b1dc674
fw-bot pushed a commit to odoo/o-spreadsheet that referenced this pull request Sep 17, 2025
Release commit 8c68f3d has been done with
Node.js v22.19.0 and NPM v10.9.3.
But in the meantime, NPM had an issue that affected the package-lock.json
by pruning OS optional dependencies (See npm/cli#7961).
The issue has been fixed (npm/cli#8184) in NPM v11.3
but not backported.

During the release process, we ran `npm install`, and so the package-lock.json
was updated to remove the optional dependencies for swc binaries.
Which caused issues for users each time they run `npm install` as they
were not present anymore in the package-lock.json.

This commit adds the swc binaries to the optional dependencies of this
project to avoid them being pruned again in the future.

Task: 0
X-original-commit: b1dc674
robodoo pushed a commit to odoo/o-spreadsheet that referenced this pull request Sep 17, 2025
Release commit 8c68f3d has been done with
Node.js v22.19.0 and NPM v10.9.3.
But in the meantime, NPM had an issue that affected the package-lock.json
by pruning OS optional dependencies (See npm/cli#7961).
The issue has been fixed (npm/cli#8184) in NPM v11.3
but not backported.

During the release process, we ran `npm install`, and so the package-lock.json
was updated to remove the optional dependencies for swc binaries.
Which caused issues for users each time they run `npm install` as they
were not present anymore in the package-lock.json.

This commit adds the swc binaries to the optional dependencies of this
project to avoid them being pruned again in the future.

closes #7157

Task: 0
X-original-commit: b1dc674
Signed-off-by: Lucas Lefèvre (lul) <[email protected]>
Signed-off-by: Pierre Rousseau (pro) <[email protected]>
robodoo pushed a commit to odoo/o-spreadsheet that referenced this pull request Sep 17, 2025
Release commit 8c68f3d has been done with
Node.js v22.19.0 and NPM v10.9.3.
But in the meantime, NPM had an issue that affected the package-lock.json
by pruning OS optional dependencies (See npm/cli#7961).
The issue has been fixed (npm/cli#8184) in NPM v11.3
but not backported.

During the release process, we ran `npm install`, and so the package-lock.json
was updated to remove the optional dependencies for swc binaries.
Which caused issues for users each time they run `npm install` as they
were not present anymore in the package-lock.json.

This commit adds the swc binaries to the optional dependencies of this
project to avoid them being pruned again in the future.

closes #7156

Task: 0
X-original-commit: b1dc674
Signed-off-by: Lucas Lefèvre (lul) <[email protected]>
Signed-off-by: Pierre Rousseau (pro) <[email protected]>
robodoo pushed a commit to odoo/o-spreadsheet that referenced this pull request Sep 17, 2025
Release commit 8c68f3d has been done with
Node.js v22.19.0 and NPM v10.9.3.
But in the meantime, NPM had an issue that affected the package-lock.json
by pruning OS optional dependencies (See npm/cli#7961).
The issue has been fixed (npm/cli#8184) in NPM v11.3
but not backported.

During the release process, we ran `npm install`, and so the package-lock.json
was updated to remove the optional dependencies for swc binaries.
Which caused issues for users each time they run `npm install` as they
were not present anymore in the package-lock.json.

This commit adds the swc binaries to the optional dependencies of this
project to avoid them being pruned again in the future.

closes #7155

Task: 0
X-original-commit: b1dc674
Signed-off-by: Lucas Lefèvre (lul) <[email protected]>
Signed-off-by: Pierre Rousseau (pro) <[email protected]>
robodoo pushed a commit to odoo/o-spreadsheet that referenced this pull request Sep 17, 2025
Release commit 8c68f3d has been done with
Node.js v22.19.0 and NPM v10.9.3.
But in the meantime, NPM had an issue that affected the package-lock.json
by pruning OS optional dependencies (See npm/cli#7961).
The issue has been fixed (npm/cli#8184) in NPM v11.3
but not backported.

During the release process, we ran `npm install`, and so the package-lock.json
was updated to remove the optional dependencies for swc binaries.
Which caused issues for users each time they run `npm install` as they
were not present anymore in the package-lock.json.

This commit adds the swc binaries to the optional dependencies of this
project to avoid them being pruned again in the future.

closes #7154

Task: 0
X-original-commit: b1dc674
Signed-off-by: Lucas Lefèvre (lul) <[email protected]>
Signed-off-by: Pierre Rousseau (pro) <[email protected]>
wraithgar pushed a commit that referenced this pull request Sep 30, 2025
Discovered while investigating
#8535 (comment)

Similar to #8566, relates to
#8184

Moves `inert` (uninstallable optional) calculation into `buildIdealTree`
so it can be used in diff.

Also removes most of #8184 in favor of a
[simpler
fix](https://github.com/npm/cli/pull/8602/files#diff-02626074e1a4a170693607e4a3a69dfc08ee52067734717833b22cf162923e07R354),
see PR comments for the journey.

Improvements:

* we don't see uninstallable packages as "installed" in CLI output
* `createSparseTree` no longer creates dirs that will only be cleaned
later

For the example in the linked issue, it changes output from `added 156
packages` to `added 12 packages` and combined with
#8537 it changes to `added 6 packages`,
the expected result.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

7 participants