Skip to content

fix(update): stop downgrading prereleases#7466

Merged
zkochan merged 29 commits intomainfrom
update-latest-overrides-alpha-7436
Jan 27, 2024
Merged

fix(update): stop downgrading prereleases#7466
zkochan merged 29 commits intomainfrom
update-latest-overrides-alpha-7436

Conversation

@KSXGitHub
Copy link
Copy Markdown
Contributor

Fixes #7436

Comment thread .changeset/big-planes-smell.md Outdated
Copy link
Copy Markdown
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.

You could write the tests before the changes. You can add a test for the CLI in the pnpm project tests.

unsafePerm: boolean
registries: Registries
tag: string
cmdFullName?: string
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Don't pass the command name. The installation engine doesn't need to have direct knowledge about the CLI. Add a boolean called updateIfNewer.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have renamed it to preventDowngrade.

Comment on lines 36 to 42
case 'tag':
version = meta['dist-tags'][spec.fetchSpec]
if (cmdFullName === 'update' && preferredVersionSelectors && spec.fetchSpec === 'latest') {
version = pickLatestVersionToUpdate(meta, preferredVersionSelectors)
} else {
version = meta['dist-tags'][spec.fetchSpec]
}
break
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Don't change this only for tag. Change it for all types of selectors. Maybe it can be moved outside of this function then.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have changed it so that the version would be reverted as long as preventDowngrade is true.

@KSXGitHub KSXGitHub marked this pull request as ready for review January 2, 2024 07:08
@KSXGitHub KSXGitHub requested a review from gluxon as a code owner January 2, 2024 07:08
@KSXGitHub KSXGitHub requested a review from zkochan January 2, 2024 07:08
}

function pickVersionWithoutDowngrade (meta: PackageMeta, fetchSpec: string, preferredVersionSelectors: VersionSelectors, otherVersion: string): string {
const preferredVersions = prioritizePreferredVersions(meta, fetchSpec, preferredVersionSelectors)[0]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I am not sure using preferredVersionSelectors is a reliable way to get the current version specifier from package.json

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Does the version specified in the project package.json always have the highest priority?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, it will have weight set to 1000. However, it can be a direct dependency of another workspace package.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So if workspace package foo has outdated stable prettier and workspace package bar has alpha release prettier, prettier in foo won't be updated?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

But if it was the case, then how could the function pickPackageFromMeta picks multiple versions when it only return a single version?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So if workspace package foo has outdated stable prettier and workspace package bar has alpha release prettier, prettier in foo won't be updated?

Yes, I think so. But it would depend on the order in which their version selectors are added to the array.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@zkochan I have added two more tests for the workspace use case in b2dca2b, let me know if it's insufficient to emulate the scenario we are worrying about. If these tests are sufficient, then I believe this is a non-issue.

@KSXGitHub KSXGitHub requested a review from zkochan January 2, 2024 16:23
@zkochan
Copy link
Copy Markdown
Member

zkochan commented Jan 20, 2024

After thinking about it more I have realized that the reason it is so hard to implement it is that the pnpm update --latest command is fundamentally wrong at the moment.

Right now, pnpm update foo --latest is basically converted to pnpm update foo@latest under the hood. However, we don't want to change the behaviour of pnpm update foo@latest. We only want to change how pnpm update foo --latest works.

Hence, we need to change how the --latest option works. We can pass down the latest option to npm-resolver and inside npm-resolver I think it should be easy to resolve both the existing range, latest, then pick the bigger from the two.

@KSXGitHub
Copy link
Copy Markdown
Contributor Author

@zkochan How should pnpm update foo@latest --latest work? If foo is at prerelease, should foo be downgraded to latest stable or be ignored?

@KSXGitHub KSXGitHub requested a review from weyert as a code owner January 22, 2024 11:29
@zkochan
Copy link
Copy Markdown
Member

zkochan commented Jan 23, 2024

I think pnpm update foo@latest --latest should not work at all. An error should be thrown. If the --latest flag is used, only package names are allowed as arguments, without version specs.

@KSXGitHub
Copy link
Copy Markdown
Contributor Author

I think pnpm update foo@latest --latest should not work at all.

If that's the case then everything becomes simple. We no longer need to refactor the code, only add more code on top of this existing code to throw an error.

@KSXGitHub
Copy link
Copy Markdown
Contributor Author

@zkochan The change at 134c06d should address your concern, unless you want to refactor it completely to do it "the right way".

@zkochan
Copy link
Copy Markdown
Member

zkochan commented Jan 23, 2024

I am not sure you understood what I meant. The update --latest command is currently adding the latest tag to the deps. That should not be the case.

See related code:

if (opts.update && opts.latest) {
if (!params || (params.length === 0)) {
params = updateToLatestSpecsFromManifest(manifest, includeDirect)
} else {
params = createLatestSpecs(params, manifest)
}
}

It should be reimplemented with an option that is passed down to npm-resolver.

@KSXGitHub KSXGitHub force-pushed the update-latest-overrides-alpha-7436 branch from f4e02c0 to c757fff Compare January 25, 2024 17:41
@zkochan
Copy link
Copy Markdown
Member

zkochan commented Jan 25, 2024

The tests don't pass after your last commit.

@KSXGitHub
Copy link
Copy Markdown
Contributor Author

The tests don't pass after your last commit.

It's the recursive ones after I tried to remove the functions that appends @latest. They are necessary somehow and I don't know what to replace them with.

@KSXGitHub
Copy link
Copy Markdown
Contributor Author

The failed test for bfa18c0 is named update only the packages that were requested to be updated when hoisting is on

@zkochan
Copy link
Copy Markdown
Member

zkochan commented Jan 27, 2024

The changes in toResolveImporter.ts are ugly but I didn't find a way to do it better without a huge refactoring. We can rewrite it one day but it is not in priority.

@zkochan zkochan merged commit 0ec0a44 into main Jan 27, 2024
@zkochan zkochan deleted the update-latest-overrides-alpha-7436 branch January 27, 2024 13:41
zkochan added a commit that referenced this pull request Jan 27, 2024
close #7436

---------

Co-authored-by: Zoltan Kochan <z@kochan.io>
KSXGitHub added a commit to pnpm/pnpm.io that referenced this pull request Jan 27, 2024
zkochan pushed a commit to pnpm/pnpm.io that referenced this pull request Jan 27, 2024
* docs(cli): correct `--latest` to follow merged PR

pnpm/pnpm#7466

* docs(cli): tweak wording
@cpojer
Copy link
Copy Markdown
Contributor

cpojer commented Jan 28, 2024

Thanks for this change @KSXGitHub. I can confirm it works in 8.15 and this behavior makes a lot more sense.

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.

pnpm up -r --latest overrides alpha versions that are not yet tagged as latest

3 participants