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

fix: --lockfile-only and readPackage hook modifying workspace packages #5678

Merged
merged 3 commits into from Nov 26, 2022

Conversation

Silic0nS0ldier
Copy link
Sponsor Contributor

Resolves #5670

Recursive installation will now defer to originalManifest when checking if workspace package.json need to be updated, if available.

Note that this fix applies to the scenario where pnpm-lock.yaml exists, odds are that when generating from scratch, one of the following codepaths are used instead.

@welcome
Copy link

welcome bot commented Nov 24, 2022

💖 Thanks for opening this pull request! 💖
Please be patient and we will get back to you as soon as we can.

@Silic0nS0ldier
Copy link
Sponsor Contributor Author

Ah. Right. fs.promises.rm is a new API. I'll get that flipped to the backward compatible unlink.

@@ -257,7 +257,7 @@ export async function recursive (
if (opts.save !== false) {
await Promise.all(
mutatedPkgs
.map(async ({ manifest }, index) => writeProjectManifests[index](manifest))
.map(async ({ originalManifest, manifest }, index) => writeProjectManifests[index](originalManifest ?? manifest))
Copy link
Member

Choose a reason for hiding this comment

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

It doesn't seem right to me.

First of all, why do you write the original manifest at all? If it is the original one, then it is already the one that is saved in the file system.

Secondly, this means that the file will not be updated when opts.save is true. It doesn't make sense.

Maybe what you need to do is changing line 257 to:

if (opts.save !== false && !opts.lockfileOnly) {

Copy link
Sponsor Contributor Author

Choose a reason for hiding this comment

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

My proposed fix may well be wrong, but I'll add some context around how I got here.

Elsewhere in the repo I noticed .manifest and .originalManifest are both modified to apply changes like removing dependencies and something in @pnpm/resolve-dependencies that I assume handles adding and upgrading.

  • Removing, replaces manifest object properties.
    project.manifest = await _removeDeps(project.manifest)
    if (project.originalManifest != null) {
    project.originalManifest = await _removeDeps(project.originalManifest)
    }
  • Adding and upgrading (I think), mutates input manifest objects.
    const hookedManifest = await updateProjectManifestObject(
    importer.rootDir,
    importer.manifest,
    specsToUpsert
    )
    const originalManifest = (importer.originalManifest != null)
    ? await updateProjectManifestObject(
    importer.rootDir,
    importer.originalManifest,
    specsToUpsert
    )
    : undefined
    return [hookedManifest, originalManifest]

Interpretation as such was "originalManifest must mean the manifest without mutations from the readPackage hook".

Copy link
Member

Choose a reason for hiding this comment

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

The original manifest is modified, sure. If I remember correctly, original manifest is only not modified by changes done by the hooks.

Copy link
Member

Choose a reason for hiding this comment

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

actually, you might be right. This is what you had to change. The names of variables are confusing.

Copy link
Member

@zkochan zkochan left a comment

Choose a reason for hiding this comment

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

Please add a changeset that describes your changes.

@zkochan zkochan merged commit 868f2fb into pnpm:main Nov 26, 2022
@welcome
Copy link

welcome bot commented Nov 26, 2022

Congrats on merging your first pull request! 🎉🎉🎉

@Silic0nS0ldier
Copy link
Sponsor Contributor Author

Thanks for adding the changeset file. I'll keep it in mind for next time.

@Silic0nS0ldier Silic0nS0ldier deleted the pkg-mutation-bug branch November 28, 2022 23:39
@zkochan zkochan added this to the v7.17 milestone Dec 1, 2022
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.

Local package.json are altered when --lockfile-only and readPackage are used together
2 participants