fix: Change dependency collection to parse from root #9260
Merged
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.
This resolves an issue I was seeing when using a yarn 4 monorepo, where is appeared that
npm list
disagreed with the layout on disk and produced a tree with deduplications that resulted in a bunch of packages to go missing.For my project, the output of the
npm list
command was: https://gist.github.com/Julusian/b4f5fe20db4f211753fa0ef8292901c8.Looking at this output, the bits worth noting are the locations of
balanced-match
andbrace-expansion
. There are 2 of each of them, one wherebrace-expansion
has a_dependencies
containingbalanced-match
but nodependencies
, and the other where it hasbalanced-match
in both.The one where it is in both is apparently a child of
cacache
being a dependency of the workspace root, but according to yarn and the yarn.lock thatcacache
dependency should be a few layers deep as a child of something. It is also worth noting here that npm complains"extraneous: [email protected] /home/julus/Projects/companion/companion/node_modules/cacache"
, so it looks to me that npm got rather confused about where this belongs and so dumped it at the root level.Because it was at the root level, collectAllDependencies would never see the proper
brace-expansion
, only the one with deduplicated dependencies, resulting in it not knowing thatbalanced-match
should be packaged and it would be missing at runtime.I am not sure if this is the best fix, but it resolves my issue. I suspect that this approach is ok as this is simply building the tree of what dependencies there are installed within the workspace, but it isnt doing anything with them at this stage; the later step of actually extracting the production dependency graph is still using the package/project root.
While debugging this, my script for testing was:
If you want to try it yourself, it should be enough to clone and run
yarn install
for the commit https://github.com/bitfocus/companion/tree/91d92c5d6d324e86ce032bec8a92212a042267b6, then run that script against it with the corrected path, and make sure that the console.log logs that it found the packages being verified.My testing was with electron-builder/app-builder-lib 26.0.19, node 22.18.0, yarn 4.9.2 and npm 10.9.3