-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
WIP: Codemods and refactorings #30292
Conversation
Co-authored-by: Michael Shilman <[email protected]>
…utomigration Move csf factory codemod to automigrations
View your CI Pipeline Execution ↗ for commit 2ec88ee.
☁️ Nx Cloud last updated this comment at |
Package BenchmarksCommit: The following packages have significant changes to their size or dependencies:
|
Before | After | Difference | |
---|---|---|---|
Dependency count | 13 | 13 | 0 |
Self size | 6 KB | 6 KB | 🚨 +616 B 🚨 |
Dependency size | 1.31 MB | 1.31 MB | 🎉 -12 B 🎉 |
Bundle Size Analyzer | Link | Link |
@storybook/react-webpack5
Before | After | Difference | |
---|---|---|---|
Dependency count | 323 | 323 | 0 |
Self size | 6 KB | 7 KB | 🚨 +662 B 🚨 |
Dependency size | 42.87 MB | 42.88 MB | 🚨 +4 KB 🚨 |
Bundle Size Analyzer | Link | Link |
@storybook/cli
Before | After | Difference | |
---|---|---|---|
Dependency count | 398 | 400 | 🚨 +2 🚨 |
Self size | 503 KB | 531 KB | 🚨 +28 KB 🚨 |
Dependency size | 75.57 MB | 75.59 MB | 🚨 +15 KB 🚨 |
Bundle Size Analyzer | Link | Link |
Core: Add defineConfig helper for main.js
…demods ConfigFile: Support pnp wrapped names
f75b007
to
80c80ac
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.
78 file(s) reviewed, 29 comment(s)
Edit PR Review Bot Settings | Greptile
@@ -1,12 +1,12 @@ | |||
import { join } from 'node:path'; | |||
|
|||
import type { StorybookConfig } from '../frameworks/react-vite'; | |||
import { defineMain } from '../frameworks/react-vite'; | |||
|
|||
const componentsPath = join(__dirname, '../core/src/components'); | |||
const managerApiPath = join(__dirname, '../core/src/manager-api'); | |||
const imageContextPath = join(__dirname, '..//frameworks/nextjs/src/image-context.ts'); |
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.
syntax: extra forward slash in path '..//frameworks/nextjs/src/image-context.ts'
const isCsfFactory = | ||
t.isCallExpression(storyExport) && | ||
t.isMemberExpression(storyExport.callee) && | ||
t.isIdentifier(storyExport.callee.object) && | ||
storyExport.callee.object.name === 'meta'; |
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.
logic: This factory detection could miss edge cases where meta is imported under a different name. Consider making this more robust by checking the call signature rather than just the name.
export function defineMain(config: StorybookConfig) { | ||
return config; | ||
} |
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: this identity function provides type checking but no runtime validation - consider adding runtime validation of the config object structure
export function defineMain(config: StorybookConfig) { | ||
return config; | ||
} |
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 marking this function as readonly to prevent accidental mutation of the config object
export function defineMain(config: StorybookConfig) { | ||
return config; | ||
} |
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.
logic: this function provides no runtime validation or transformation of the config object, which could lead to invalid configurations being accepted silently
if (addon === '@storybook/addon-essentials') { | ||
data.importPath = '@storybook/addon-essentials/entry-preview'; | ||
} else { | ||
require.resolve(path.join(addon, 'preview')); |
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: require.resolve
result is unused. Consider storing the resolved path in data.importPath
* This goes through all mainConfig.addons, read their package.json and check whether they have an | ||
* exports map called preview, if so add to the array | ||
*/ | ||
addons.forEach(async (addon) => { |
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.
logic: forEach with async operations won't work as expected - use Promise.all with map instead
mainConfig: StorybookConfigRaw, | ||
previewConfigPath: string | ||
) { | ||
const previewConfig = await readConfig(previewConfigPath!); |
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.
logic: dangerous non-null assertion on previewConfigPath could cause runtime errors if undefined
]; | ||
programNode.body = cleanupTypeImports(programNode, disallowList); | ||
|
||
// Remove unused type aliases e.g. `type Story = StoryObj<typeof meta>;` |
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.
logic: removing type aliases during array iteration can cause index misalignment if multiple types need to be removed
hasArgument: true, | ||
description: 'Run automigrations', | ||
icon: '🤖', | ||
options: createOptions({}), |
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: empty options object suggests no configuration control - verify if automigrate should have any configurable options like dry-run or specific migration targets
Closes #30243
Closes #30239
Closes #30240
Closes #30316
What I did
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!
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-storybook/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 PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the
@storybookjs/core
team here.core team members can create a canary release here or locally with
gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=<PR_NUMBER>
Greptile Summary
This PR implements significant changes to Storybook's configuration system, introducing new type-safe helpers for defining configurations and improving addon synchronization across frameworks.
defineMain
anddefinePreview
type helpers across all framework packages to replacedefineConfig
code/lib/cli-storybook/src/codemod/
for transforming stories to CSF4 formatgetStorybookData
helper in CLI tools to consolidate configuration loadingcsf-3-to-4
transform from@storybook/codemod
package in favor of new implementation