-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
CLI: Handle package versions in package strings for generators #13774
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
CLI: Handle package versions in package strings for generators #13774
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM except for a corner case
| ) | ||
| packages.map(async (pkg) => { | ||
| const [packageName, packageVersion] = getPackageDetails(pkg); | ||
| return `${packageName}@${await this.getVersion(packageName, packageVersion)}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAICT this will fail when packageVersion is a literal version. getVersion calls satisfies and if it fails it uses the latest version. Consider the case where latest is 1.3.5 and we need version 1.2.0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this only fails if the version doesn't exist. I tested semver.satisfies('1.0.0', '1.0.0') and it returns true so as long as the literal version exists inside versions.reverse(), it should find one.
That being said, the latestVersion method could probably be hardened against a constraint not being satisfied by all versions on npm. Do you want me to do that as part of this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(current is only ever set for @storybook packages, so the versionToUse ternary only ever gets applied to those)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aha my bad
cb4d642 to
354fc79
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
Issue: N/A
What I did
Sometimes packages needed by generators might not be published on the
latesttag, so the wrong version would be added to the package.json when using a generator.An example of this is
vue-loader, which publishes v16 (with Vue 3 support) on thenexttag. Upon addingvue-loaderto a generator, it would add v15 to the package.json.This adds support for generators to request versions in the string, like so:
How to test
If your answer is yes to any of these, please make sure to include it in your PR.