feat: explain why a dependency was installed on resolution errors#9581
Open
everett1992 wants to merge 1 commit into
Open
feat: explain why a dependency was installed on resolution errors#9581everett1992 wants to merge 1 commit into
everett1992 wants to merge 1 commit into
Conversation
Attach a structured dependency explanation (the same shape ERESOLVE errors carry) to install errors that target a specific dependency, and render it in the CLI using the `npm explain` format. This shows users which path pulled a package in, since removing that path is how they avoid the error. Covered errors: - ETARGET, EALLOWREMOTE/EALLOWGIT, tarball/network, EINCOMPLETEMANIFEST (resolution phase, via build-ideal-tree #failureNode/#pruneFailedOptional) - EALLOWREMOTE/EALLOWGIT, tarball/network, integrity (reify fetch phase, via #extractOrLink) - EBADENGINE, EBADPLATFORM (engine/platform checks) - ESTRICTALLOWSCRIPTS (install preflight uses the shared arborist helper so it carries explanations too) New lib/utils/explain-dep-error.js formats the explanation (edge- or node-shaped) via the existing explain-dep formatters; error-message.js appends it and writes a full report file, mirroring explain-eresolve. The explanation is computed lazily and best-effort via a shared attachExplanation(err, compute) helper: the graph walk only runs when a failure is actually fatal (optional/dropped load failures skip it), it never overwrites an existing explanation, and it never masks the original error. For ESTRICTALLOWSCRIPTS the explanation is omitted entirely if a node lacks explain(). Full 100% test coverage.
78c0b6a to
6134eb4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Attach a structured dependency explanation (the same shape ERESOLVE errors carry) to install errors that target a specific dependency, and render it in the CLI using the
npm explainformat. This shows users which path pulled a package in, since removing that path is how they avoid the error - if it's not transient.Covered errors:
New lib/utils/explain-dep-error.js formats the explanation (edge- or node-shaped) via the existing explain-dep formatters; error-message.js appends it and writes a full report file, mirroring explain-eresolve.
The explanation is computed lazily and best-effort via a shared attachExplanation(err, compute) helper: the graph walk only runs when a failure is actually fatal (optional/dropped load failures skip it), it never overwrites an existing explanation, and it never masks the original error. For ESTRICTALLOWSCRIPTS the explanation is omitted entirely if a node lacks explain().
npm explainrequires a populated node_modules, so it can't help diagnose EALLOWREMOTE, ETARGET ect errors that prevent creation of node_modules. This includes a partial explanation along with the errors.