fix(workspace): attribute files to nearest package.json, not glob-matched intermediate dirs#854
Draft
BartWaardenburg wants to merge 1 commit into
Draft
Conversation
…ched intermediate dirs Fixes #842
80238bc to
c7ad12f
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.
Summary
Adds
owning_workspace_rootandnearest_undeclared_package_json_depshelpers incrates/core/src/analyze/unused_deps.rs. When a source file lives inside a glob-matched intermediate workspace (e.g.packages/themes) but is closer to its ownpackage.json(e.g.packages/themes/my-theme/package.json) that was not expanded by the shallow glob (e.g../packages/*),is_package_listed_for_filenow walks upward from the file to find that nearer manifest and uses its declared dependencies instead of the intermediate workspace's deps. This eliminates falseunlisted-dependencyfindings for packages correctly declared in nested manifests that a shallow glob never discovers as workspace entries.Review
Verdict: FIX
Concerns from review:
-D warningslints):clippy::doc_link_with_quotesatunlisted_deps.rs:939: the doc-comment line(workspaces: ["./packages/*"])is parsed as an intra-doc link; wrap in backticks.clippy::redundant_cloneatunlisted_deps.rs:991:themes_dir.clone()is redundant becausethemes_diris dropped after; drop the.clone().packages/themeshas NOpackage.json(a phantom glob match).expand_workspace_globalready skips dirs without apackage.json(seeGlobMatchedNoPackageJsondiagnostic). This fix instead handles the case wherepackages/themesHAS apackage.jsonbut a deeper non-workspacepackages/themes/my-theme/package.jsonwas missed by the shallow glob. That is a real scenario, but should be confirmed against the actual reporter's repo before merge.ws_dep_map) exists; the realfind_unlisted_dependencies+ workspace-discovery pipeline has not been validated against the targeted layout.nearest_undeclared_package_json_depsreads and parsespackage.jsonfrom disk per ancestor on every(package, file)call with no caching, and runs inside the perf-priorityaudit/unlisted loop. Worth a comment or memoization note.ws_dep_map.iter().any(...) breakatunlisted_deps.rs:85is effectively dead sinceowning_workspace_rootalready returns the deepest tracked workspace. Harmless but slightly misleading.Closes #842