-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
CLI: Add "missing-storybook-dependencies" automigration #28579
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
Conversation
@@ -132,28 +132,28 @@ export class NPMProxy extends JsPackageManager { | |||
}); | |||
} | |||
|
|||
public async findInstallations(pattern: string[]) { |
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.
The idea of adding a depth option is because we want to try and get information over dependencies that are coming directly from package.json, but NOT as dependencies of dependencies. This needs further testing on all package managers
* So we first install the exact version, then run code again | ||
* to write to package.json to add the caret back, but without running install | ||
*/ | ||
await packageManager.addDependencies( |
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.
This really sucks, I hope the comment at the top explains why it's needed
☁️ Nx Cloud ReportCI is running/has finished running commands for commit e0a8106. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 1 targetSent with 💌 from NxCloud. |
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.
PR Summary
- Added
depth
parameter tofindInstallations
in/code/core/src/common/js-package-manager/JsPackageManager.ts
- Enhanced
findInstallations
in/code/core/src/common/js-package-manager/NPMProxy.ts
withdepth
parameter - Modified
findInstallations
in/code/core/src/common/js-package-manager/PNPMProxy.ts
to acceptdepth
parameter - Updated
findInstallations
in/code/core/src/common/js-package-manager/Yarn1Proxy.ts
and/code/core/src/common/js-package-manager/Yarn2Proxy.ts
withdepth
parameter - Introduced
missingStorybookDependencies
automigration in/code/lib/cli/src/automigrate/fixes/index.ts
and added corresponding tests in/code/lib/cli/src/automigrate/fixes/missing-storybook-dependencies.test.ts
8 file(s) reviewed, 5 comment(s)
Edit PR Review Bot Settings
code/lib/cli/src/automigrate/fixes/missing-storybook-dependencies.test.ts
Outdated
Show resolved
Hide resolved
code/lib/cli/src/automigrate/fixes/missing-storybook-dependencies.test.ts
Show resolved
Hide resolved
const content = await readFile(file, 'utf-8'); | ||
dependenciesToCheck.forEach((pkg) => { | ||
// match imports like @storybook/theming or @storybook/theming/create | ||
const regex = new RegExp(`['"]${pkg}(/[^'"]*)?['"]`); |
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.
🪶 style: The regex pattern could be more specific to avoid false positives.
`; | ||
}, | ||
|
||
async run({ result: { packageUsage }, dryRun, packageManager }) { |
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.
🪶 style: Consider adding a log statement for when the dry run is enabled to inform the user that no changes will be made.
// the dependency is directly installed, else they could come from other dependencies | ||
const promises = packages.map((pkg) => packageManager.findInstallations([pkg], { depth: 0 })); | ||
|
||
const analyses = await Promise.all(promises); |
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.
This unfortunately adds several seconds in the check, in contrast with just passing the entire array as a pattern. The reason I do this is because it's possible that in yarn, if you pass a package that does not exist, an error will be thrown. As a result, you get undefined
and then lose the information regarding all packages which is not great. Iterating through the packages instead fixes that, at the cost of slower times because then it does multiple requests instead.
HOWEVER it takes long mostly in Yarn 1, which is really slow in nature. For the other package managers it's actually OK (2-3s)
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.
How about we change it so the slow implementation is only in yarn1?
So we keep passing the array to packageManager.findInstallations
but then inside the yarn1 implementation we do the Promise.all
and split it over multiple processes?
That way all the other package managers perf are unaffected.
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.
The Promise.all solution was for both yarn 1 and 2! I didn’t test on npm and pnpm to know whether it would work there as well
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 see. 👍
@yannbf What do you think about this test failing: |
const packageJson = await packageManager.retrievePackageJson(); | ||
await packageManager.addDependencies( | ||
{ installAsDevDependencies: true, skipInstall: true, packageJson }, | ||
dependenciesToInstall.map((pkg) => `${pkg}@${versionToInstall}`) |
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.
we need to add a test to make sure that if the user has the modifiers (or lack thereof), they're kept:
- ~8.1.0
- ^8.1.0
- 8.1.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.
Tested in a few different scenarios & package managers. LGTM!
…s-automigration CLI: Add "missing-storybook-dependencies" automigration (cherry picked from commit 8dc43db)
Relates to #28566
What I did
This PR introduces a new automigration that checks whether the user is utilizing Storybook APIs from packages that are not directly installed, and then installs them as a solution.
Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!
@storybook/preview-api
,@storybook/manager-api
,@storybook/theming
for instance.storybook
Documentation
MIGRATION.MD
Checklist for Maintainers
When this PR is ready for testing, make sure to add
ci:normal
,ci:merged
orci:daily
GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found incode/lib/cli/src/sandbox-templates.ts
Make sure this PR contains one of the labels below:
Available labels
bug
: Internal changes that fixes incorrect behavior.maintenance
: User-facing maintenance tasks.dependencies
: Upgrading (sometimes downgrading) dependencies.build
: Internal-facing build tooling & test updates. Will not show up in release changelog.cleanup
: Minor cleanup style change. Will not show up in release changelog.documentation
: Documentation only changes. Will not show up in release changelog.feature request
: Introducing a new feature.BREAKING CHANGE
: Changes that break compatibility in some way with current major version.other
: Changes that don't fit in the above categories.🦋 Canary release
This pull request has been released as version
0.0.0-pr-28579-sha-08603e88
. Try it out in a new sandbox by runningnpx storybook@0.0.0-pr-28579-sha-08603e88 sandbox
or in an existing project withnpx storybook@0.0.0-pr-28579-sha-08603e88 upgrade
.More information
0.0.0-pr-28579-sha-08603e88
yann/missing-storybook-deps-automigration
08603e88
1720803823
)To request a new release of this pull request, mention the
@storybookjs/core
team.core team members can create a new canary release here or locally with
gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=28579