fix: make omit flags work properly with workspaces #6549
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.

I am encountering an issue in using work-spaces whereby if i have a dev dependency at the root of my project with some version v1 and the same dependency inside one of the work-spaces which is a sub-folder in the project root with version v2 also as dev dependency that conflicts with v1 and try to do
npm ci --omit=devit skips installing the v1 dependency which was at project root but still installs the v2 dependency that was in the child workspace. I would expect that v2 should also not be installed. I have raised an issue for it here #6441 which also includes a link to minimum reproducible example.In reify under arborist I found a filter condition which runs through the idealTree inventory to see which packages needed to be filtered out when omit dev or omit peer options etc are passed. Along with checking which flag is enabled and which packages is which type it also includes a condition of
node.top.isProjectRoot. I don't fully understand the purpose of the last condition but am guessing, it is there so that the package is only filtered out if it is going to be directly under the root node_modules folder and not if it is going to be under the node_modules of some package which is under the actual root node_modules folder. I have extended the condition so that it is also filtered out if its top is a workspace which i think would translate to, that it should also be filtered out if its directly under the node_modules of a workspace folder.References
Fixes #6441
PS: It is my first time contributing to open source please excuse me if i have not followed proper procedure or otherwise missed something,