Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating "ComponentFilePaths" list of Yarn's Workspace Dependencies. #565

Conversation

siyadava-sindhu
Copy link
Contributor

Issue

  • currenlty for "Yarn ecosystem" for identified workspace dependencies ., "locationsFoundAt" is coming only as parent 'Yarn.lock' (semantic version resolver of yarn-ecosystem), eventhough actual dependency usage in codebase is at respective workspace's Package.json entry.

Issue information with 1JS repo usecase

"""""
"@graphql-codegen/add 3.2.1 -Npm:[
{
"filePath":/s/midgard/.store/@graphql-codegen-add@3.2.1-9682c5a89873a23a208f/node_modules/@graphql-codegen/add/package.json
},
{
"filePath":/s/midgard/.store/@graphql-codegen-import-types-preset@2.2.3-1725db1442e85dd3e793/node_modules/@graphql-codegen/add/package.json
},
{
"filePath":"/s/midgard/yarn.lock"
}
],
""""""""""

Reason and fix
-->currenlty for 'Yarn Ecosystem' summarized logic of parsing is that:
(1) YarnLockComponentDetector gets triggered when any 'yarn.lock' file gets found
(2) Inside 'YarnLockComponentDetector' class, "GetWorkspaceDependencies" API gets called to identify all "package.json" file's dependencies ,in workspace folder to which #1 yarn.lock is acting as semver-resolver..
-->in above steps, during execution of #2 step, (which gets spawned because of #1),No extra logic to add respective package.json's filelocation exists, and since source-trigger file of #2's package.json file is also #1's yarn.lock file
only "Location to which corresponding component belongs to" is added as Yarn.lock.
-->In this PR added extra logic at step-#2 to add respective package.json filepath also to LocationsFoundAt list, since actual usage of dependency is found at corresponding package.json.

why we are updating LocationsPath to add package.json data too

  • Currently we are using "LocationsPath" of component in DependencyManagement project as real source of truth w.r.t where
    component is identified, and further using ownership-extension (with filepath) to know owner of respective filepath.
  • since in this usecase , as actual package.json filepath didn't got added to "LocationsPath" list, for all packages of yarn ecosystem repo(especially in monorepo scenarios where each package.json file is owned by different teams), owner is coming to be same person who owned common "Yarn.lock", instead of respective package.json.

Validations
-->By parsing 1Js repo validated locally that along with yarn.lock filepath, respective package.json path is also showing up in locationsFoundAt list for workspaceDependency entries,

@siyadava-sindhu siyadava-sindhu requested a review from a team as a code owner May 12, 2023 17:48
@JamieMagee
Copy link
Member

Can you add new tests to validate the behaviour?

@siyadava-sindhu
Copy link
Contributor Author

Can you add new tests to validate the behaviour?

Added 'WellFormedYarnLockV1WithWorkspace_CheckFilePathsAsync' test in YarnLockDetectorTests to validate Workspace's filepath functionality.

@melotic
Copy link
Member

melotic commented Jun 2, 2023

@JamieMagee This looks good to me, but I'm not too knowledgeable in the yarn ecosystem to be 100% confident.

Addressing iteration-2 comments, and using FluentAssertions
…Path logic to check Package.json entry existence alone.
@grvillic grvillic merged commit 9e988bb into microsoft:main Jun 19, 2023
@github-actions
Copy link

👋 Hi! It looks like you modified some files in the Detectors folder.
You may need to bump the detector versions if any of the following scenarios apply:

  • The detector detects more or fewer components than before
  • The detector generates different parent/child graph relationships than before
  • The detector generates different devDependencies values than before

If none of the above scenarios apply, feel free to ignore this comment 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants