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

feat(core): add package manager parsers and stringifiers #11953

Merged
merged 17 commits into from
Sep 20, 2022

Conversation

meeroslav
Copy link
Contributor

@meeroslav meeroslav commented Sep 9, 2022

This PR adds parseLockFile and writeLockFile functions to nx necessary for future pruning functionality and dependency tracking during tasks.

Current Behavior

Expected Behavior

Related Issue(s)

Related to #9761

@vercel
Copy link

vercel bot commented Sep 9, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
nx-dev ✅ Ready (Inspect) Visit Preview Sep 20, 2022 at 6:25PM (UTC)

@@ -24,7 +24,7 @@ function checkLockFiles() {
}
try {
require('child_process').execSync(
'yarn lockfile-lint -s -n -p yarn.lock -a hosts yarn npm',
'yarn lockfile-lint -s -p yarn.lock -a hosts yarn npm',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We disable this explicitly, because of pnpm's package name hacks.

@vsavkin
Copy link
Member

vsavkin commented Sep 18, 2022

I think the pair of parseLockFIle/writeLockFile is a good interface.

Some notes and questions:

  1. Should parseLockFIle be generic?
    LockFileData is generic, but that type parameter is not used in the parseLockFile/writeLockFile functions, and I don't think we would use it.

After all, we want to write lock-file-oriented code in a polymorphic way. E.g., if we want to prune the lock file, we would want to write that code without any specific yarn, npm etc stuff. If it is possible, the parse/write functions cannot be generic. If it is not possible, then I don't think hose functions are needed because the if statement you have inside will have to outside. Does it make sense?

We use generics in the same way when creating a project graph. The generic parameter there is not used.

  1. Should parseLockFIle take parameters?

I don't think it should cause I imagine all the unit testing will be done around package-specific functions (you will test npm,yarn,pnpm versions directly).

  1. I don't think the tests should be in the lockfile-test folder. All unit tests should be based on parsing and serializing strings. We need at least some unit tests for each package manager.

Copy link
Member

@vsavkin vsavkin left a comment

Choose a reason for hiding this comment

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

Left some comments.

@meeroslav
Copy link
Contributor Author

Thank you for checking the PR.

I'll check if we can get rid of generics without making code too messy. But generally, all callers of parse, stringify (and future prune) should be agnostic of package manager (and lock file generic type).

Regarding the lock files in script folder, all of that will be gone. It was more convenient while debugging, but I'll drop that entire folder and add tests with fixtures. This would also make the working directory param obsolete.

Once I add tests, the PR will be ready for full review.

@meeroslav meeroslav marked this pull request as ready for review September 19, 2022 15:30
@meeroslav meeroslav changed the title feat(core): add package manager parsers and stringifiers WIP feat(core): add package manager parsers and stringifiers Sep 19, 2022
@meeroslav meeroslav requested a review from vsavkin September 19, 2022 15:40
@Nikamura
Copy link

Hey guys, why was @zkochan/js-yaml added as dependency instead of using js-yaml ?

https://www.npmjs.com/package/@zkochan/js-yaml/v/0.0.6
https://www.npmjs.com/package/js-yaml

@meeroslav meeroslav deleted the parse-lock-file branch November 8, 2022 15:34
@meeroslav
Copy link
Contributor Author

@Nikamura Because of the lock file pruning. The @zkochan/js-yaml adds additional functionality on top of js-yaml, which unfortunately is necessary to properly construct pnpm-lock.yaml.

@github-actions
Copy link

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
scope: core core nx functionality type: feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants