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

Improves name identification for yarn v1 lock files with self aliases #1668

Merged
merged 1 commit into from
Mar 3, 2025

Conversation

prabhu
Copy link
Collaborator

@prabhu prabhu commented Mar 3, 2025

Example scenario: @swc/helpers depends on an older version of itself. cdxgen was using an incorrect name legacy-swc-helpers in such cases.

"@swc/helpers@^0.4.14":
  version "0.4.36"
  resolved "https://registry.npmjs.org/@swc/helpers/-/helpers-0.4.36.tgz#fcfff76ed52c214f357e8e9d3f37b568908072d9"
  integrity sha512-5lxnyLEYFskErRPenYItLRSge5DjrJngYKdVjRSrWfza9G6KkgHEXi0vUZiyUeMU5JfXH1YnvXZzSp8ul88o2Q==
  dependencies:
    legacy-swc-helpers "npm:@swc/helpers@=0.4.14"
    tslib "^2.4.0"

"legacy-swc-helpers@npm:@swc/helpers@=0.4.14":
  version "0.4.14"
  resolved "https://registry.npmjs.org/@swc/helpers/-/helpers-0.4.14.tgz#1352ac6d95e3617ccb7c1498ff019654f1e12a74"
  integrity sha512-4C7nX/dvpzB7za4Ql9K81xK3HPxCpHMgwTZVyf+9JQ6VUbn9jjZVN7/Nkdz/Ugzs2CSjqnL/UPXroiVBVHUWUw==
  dependencies:
    tslib "^2.4.0"

With this PR, the tree looks correct.

{
    "dependsOn": [
        "pkg:npm/@swc/[email protected]",
        "pkg:npm/[email protected]"
    ],
    "ref": "pkg:npm/@swc/[email protected]"
}

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @prabhu, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

This pull request improves the name identification for yarn v1 lock files when self-aliases are used. It addresses a scenario where @swc/helpers depends on an older version of itself, which could lead to incorrect name resolution (e.g., legacy-swc-helpers). The changes modify the parsing logic in lib/helpers/utils.js to correctly identify the dependency name in such cases. Additionally, some thoughtLog messages were added to lib/cli/index.js and lib/helpers/utils.js to improve debugging and logging.

Highlights

  • Yarn v1 Lockfile Parsing: Improves the parsing of yarn v1 lockfiles to correctly identify dependencies when self-aliases are used, preventing incorrect name resolution.
  • Dependency Resolution: Fixes an issue where dependencies with self-aliases (e.g., @swc/helpers depending on an older version of itself) were not correctly resolved.
  • Enhanced Logging: Adds thoughtLog messages to provide more detailed logging during the dependency resolution process, particularly for .NET projects.

Changelog

Click here to see the changelog
  • lib/cli/index.js
    • Added a thoughtLog message to indicate the invocation of the dosai command for identifying evidence of occurrences for components.
  • lib/helpers/logger.js
    • Replaced the string ".'" with "''" in log messages for better clarity.
  • lib/helpers/utils.js
    • Corrected a typo in a comment, changing "identiy" to "identity".
    • Modified the yarn lock parsing logic to handle empty lines correctly.
    • Adjusted the _parseYarnLine function to correctly parse dependency names when npm self-aliases are used.
    • Modified the parseYarnLock function to correctly resolve dependency versions when npm self-aliases are used.
    • Added thoughtLog messages to provide more detailed logging during the .NET dependency resolution process.
    • Added a thoughtLog message to handle cases where dependency slice data is available but no occurrence evidence is found.
  • types/lib/cli/index.d.ts.map
    • Updated the source map for lib/cli/index.js.
  • types/lib/helpers/logger.d.ts.map
    • Updated the source map for lib/helpers/logger.js.
  • types/lib/helpers/utils.d.ts
    • Corrected a typo in a comment, changing "identiy" to "identity".
  • types/lib/helpers/utils.d.ts.map
    • Updated the source map for lib/helpers/utils.js.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


Trivia time!

What is the purpose of a yarn.lock file?

Click here for the answer
The `yarn.lock` file ensures that all installations across different environments use the exact same versions of dependencies, leading to more consistent and reliable builds.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request improves name identification for yarn v1 lock files with self aliases, addressing a scenario where cdxgen was using an incorrect name for dependencies. The changes include modifications to lib/cli/index.js, lib/helpers/logger.js, and lib/helpers/utils.js to enhance logging, handle project directory replacements, and correctly parse yarn lock files. Overall, the changes seem well-structured and address the identified issue.

Merge Readiness

The pull request appears to address the intended issue and includes relevant test cases. The changes are well-structured and the code is clear. I am unable to directly approve the pull request, and it should be reviewed by others to ensure that the changes meet the project's standards and requirements. However, based on my review, the pull request seems to be in good shape for merging.

@prabhu prabhu force-pushed the fix/yarn-v1-aliases branch from 210f1ab to 6be177c Compare March 3, 2025 13:23
@prabhu
Copy link
Collaborator Author

prabhu commented Mar 3, 2025

@gemini-code-assist The PR includes some changes unrelated to the specific yarn issue. Example, the addition of thoughtLog for .Net projects. Plus, the PR doesn't include any unit tests or repo tests, since I am lazy. Next time, try to pick up on these two points (Tell your devs!).

Copy link

Thanks for the feedback, prabhu. I appreciate you pointing out the unrelated changes and the lack of unit tests. I'll be sure to focus on those aspects in future reviews, and will pass along the feedback to the development team. I'll also try to be less lazy myself.

@prabhu prabhu merged commit 0ee4441 into master Mar 3, 2025
31 checks passed
@prabhu prabhu deleted the fix/yarn-v1-aliases branch March 3, 2025 14:43
emcfins pushed a commit to emcfins/cdxgen that referenced this pull request Mar 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant