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

Core: Move CSF to monorepo #30488

Merged
merged 187 commits into from
Feb 7, 2025
Merged

Core: Move CSF to monorepo #30488

merged 187 commits into from
Feb 7, 2025

Conversation

kasperpeulen
Copy link
Contributor

@kasperpeulen kasperpeulen commented Feb 6, 2025

Closes #

What I did

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/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>

name before after diff z %
createSize 0 B 0 B 0 B - -
generateSize 80.4 MB 80.4 MB 319 B 2.34 0%
initSize 80.4 MB 80.4 MB 319 B -1.31 0%
diffSize 97 B 97 B 0 B -1.36 0%
buildSize 7.25 MB 7.24 MB -3.81 kB 1.56 -0.1%
buildSbAddonsSize 1.87 MB 1.87 MB -1.18 kB 0.95 -0.1%
buildSbCommonSize 195 kB 195 kB 0 B - 0%
buildSbManagerSize 1.88 MB 1.88 MB -2.93 kB 0.69 -0.2%
buildSbPreviewSize 0 B 0 B 0 B - -
buildStaticSize 0 B 0 B 0 B - -
buildPrebuildSize 3.94 MB 3.94 MB -4.11 kB 0.85 -0.1%
buildPreviewSize 3.3 MB 3.3 MB 296 B 2.29 0%
testBuildSize 0 B 0 B 0 B - -
testBuildSbAddonsSize 0 B 0 B 0 B - -
testBuildSbCommonSize 0 B 0 B 0 B - -
testBuildSbManagerSize 0 B 0 B 0 B - -
testBuildSbPreviewSize 0 B 0 B 0 B - -
testBuildStaticSize 0 B 0 B 0 B - -
testBuildPrebuildSize 0 B 0 B 0 B - -
testBuildPreviewSize 0 B 0 B 0 B - -
name before after diff z %
createTime 22s 27.8s 5.8s 0.85 20.9%
generateTime 19s 17.2s -1s -808ms -1.43 🔰-10.5%
initTime 4.7s 4.1s -616ms -1.4 🔰-14.9%
buildTime 8.3s 7.6s -611ms -1.33 🔰-7.9%
testBuildTime 0ms 0ms 0ms - -
devPreviewResponsive 6s 5.2s -869ms -0.4 -16.7%
devManagerResponsive 4.4s 3.7s -661ms -0.68 -17.5%
devManagerHeaderVisible 966ms 682ms -284ms -1.08 -41.6%
devManagerIndexVisible 1s 689ms -311ms -1.4 🔰-45.1%
devStoryVisibleUncached 4.4s 4.1s -206ms 0.52 -4.9%
devStoryVisible 1s 771ms -229ms -0.74 -29.7%
devAutodocsVisible 924ms 817ms -107ms 0.5 -13.1%
devMDXVisible 879ms 730ms -149ms -0.13 -20.4%
buildManagerHeaderVisible 791ms 743ms -48ms -0.34 -6.5%
buildManagerIndexVisible 955ms 764ms -191ms -0.49 -25%
buildStoryVisible 768ms 730ms -38ms -0.29 -5.2%
buildAutodocsVisible 727ms 617ms -110ms -0.26 -17.8%
buildMDXVisible 710ms 665ms -45ms -0.02 -6.8%

Greptile Summary

Moving CSF (Component Story Format) to a monorepo structure with significant changes across the codebase to consolidate and standardize CSF functionality.

  • Added new /csf directory in core package with key files like SBType.ts, story.ts, and includeConditionalArg.ts for type definitions and core functionality
  • Updated import paths across codebase from @storybook/csf to @storybook/core/csf or @storybook/internal/csf
  • Added new CSF exports in package.json files with proper type definitions and module formats
  • Added comprehensive test coverage for CSF functionality including story composition, type validation, and conditional arguments
  • Introduced new utility functions and types while maintaining backward compatibility with existing CSF implementations

@kasperpeulen kasperpeulen added build Internal-facing build tooling & test updates maintenance User-facing maintenance tasks and removed build Internal-facing build tooling & test updates labels Feb 6, 2025
Copy link

nx-cloud bot commented Feb 6, 2025

View your CI Pipeline Execution ↗ for commit 43f0399.

Command Status Duration Result
nx run-many -t build --parallel=3 ✅ Succeeded 1m 49s View ↗

☁️ Nx Cloud last updated this comment at 2025-02-07 15:07:56 UTC

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

60 file(s) reviewed, 17 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines +1 to +4
interface SBBaseType {
required?: boolean;
raw?: string;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

style: SBBaseType interface should be exported since it's used by other exported types

Suggested change
interface SBBaseType {
required?: boolean;
raw?: string;
}
export interface SBBaseType {
required?: boolean;
raw?: string;
}

code/core/src/csf/includeConditionalArg.test.ts Outdated Show resolved Hide resolved
code/core/src/csf/includeConditionalArg.test.ts Outdated Show resolved Hide resolved
Comment on lines 39 to 40
['object true', { eq: { x: 1 } }, { x: 1 }, true],
['object true', { eq: { x: 1 } }, { x: 2 }, false],
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Duplicate test case name 'object true' may cause confusion when debugging failures

const count = (vals: any[]) => vals.map((v) => typeof v !== 'undefined').filter(Boolean).length;

export const testValue = (cond: Omit<Conditional, 'arg' | 'global'>, value: any) => {
const { exists, eq, neq, truthy } = cond as any;
Copy link
Contributor

Choose a reason for hiding this comment

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

style: casting to 'any' loses type safety - consider using a more specific type for destructured values

Comment on lines +189 to +195
expectTypeOf<ArgsFromMeta<XRenderer, typeof meta>>().toEqualTypeOf<{
theme: string;
decoratorArg: string;
decoratorArg2: string;
loaderArg: number;
loaderArg2: number;
}>();
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: ArgsFromMeta type test doesn't verify that the 'disabled' property from meta.args is included in the inferred type

Comment on lines +408 to +410
/** @deprecated Project `globals` renamed to `initiaGlobals` */
globals?: Globals;
initialGlobals?: Globals;
Copy link
Contributor

Choose a reason for hiding this comment

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

syntax: typo in deprecation message - 'initiaGlobals' should be 'initialGlobals'

Suggested change
/** @deprecated Project `globals` renamed to `initiaGlobals` */
globals?: Globals;
initialGlobals?: Globals;
/** @deprecated Project `globals` renamed to `initialGlobals` */
globals?: Globals;
initialGlobals?: Globals;

.toLowerCase()

.replace(/[ ’–—―′¿'`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, '-')
.replace(/-+/g, '-')
Copy link
Contributor

Choose a reason for hiding this comment

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

style: regex pattern includes redundant escape characters for characters that don't need escaping in character class

@@ -3,7 +3,7 @@ import { useEffect, useState } from 'react';
import { GLOBALS_UPDATED } from 'storybook/internal/core-events';
import type { DocsContextProps, PreparedStory } from 'storybook/internal/types';

import type { Globals } from '@storybook/csf';
import type { Globals } from '@storybook/internal/csf';

export const useGlobals = (story: PreparedStory, context: DocsContextProps): [Globals] => {
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Consider adding return type documentation since this hook returns a tuple with a single element. The type signature could be clearer as [Globals, void] or just Globals.

@@ -0,0 +1,2 @@
export * from '@storybook/core/csf';
export type * from '@storybook/core/csf';
Copy link
Contributor

Choose a reason for hiding this comment

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

syntax: The export type * syntax is incorrect. TypeScript uses export type { ... } with explicit type names. Consider using export * as type or listing specific types to export.

Suggested change
export type * from '@storybook/core/csf';
export * as type from '@storybook/core/csf';

@kasperpeulen kasperpeulen changed the title Move CSF to monorepo Core: Move CSF to monorepo Feb 6, 2025
@storybook-pr-benchmarking
Copy link

storybook-pr-benchmarking bot commented Feb 6, 2025

Package Benchmarks

Commit: 43f0399, ran on 7 February 2025 at 15:15:27 UTC

The following packages have significant changes to their size or dependencies:

@storybook/addon-a11y

Before After Difference
Dependency count 56 54 🎉 -2 🎉
Self size 332 KB 332 KB 0 B
Dependency size 12.71 MB 12.46 MB 🎉 -252 KB 🎉
Bundle Size Analyzer Link Link

@storybook/addon-docs

Before After Difference
Dependency count 15 13 🎉 -2 🎉
Self size 2.26 MB 2.26 MB 0 B
Dependency size 9.66 MB 9.41 MB 🎉 -252 KB 🎉
Bundle Size Analyzer Link Link

@storybook/addon-essentials

Before After Difference
Dependency count 34 32 🎉 -2 🎉
Self size 12 KB 12 KB 0 B
Dependency size 15.68 MB 15.43 MB 🎉 -255 KB 🎉
Bundle Size Analyzer Link Link

@storybook/addon-interactions

Before After Difference
Dependency count 56 54 🎉 -2 🎉
Self size 128 KB 128 KB 0 B
Dependency size 12.74 MB 12.48 MB 🎉 -252 KB 🎉
Bundle Size Analyzer Link Link

@storybook/addon-links

Before After Difference
Dependency count 4 2 🎉 -2 🎉
Self size 19 KB 19 KB 🚨 +8 B 🚨
Dependency size 284 KB 32 KB 🎉 -252 KB 🎉
Bundle Size Analyzer Link Link

@storybook/addon-storysource

Before After Difference
Dependency count 7 5 🎉 -2 🎉
Self size 1.89 MB 1.89 MB 0 B
Dependency size 10.80 MB 10.55 MB 🎉 -252 KB 🎉
Bundle Size Analyzer Link Link

@storybook/experimental-addon-test

Before After Difference
Dependency count 60 58 🎉 -2 🎉
Self size 831 KB 831 KB 🎉 -32 B 🎉
Dependency size 14.19 MB 13.94 MB 🎉 -252 KB 🎉
Bundle Size Analyzer Link Link

@storybook/core

Before After Difference
Dependency count 54 52 🎉 -2 🎉
Self size 19.22 MB 19.26 MB 🚨 +40 KB 🚨
Dependency size 14.44 MB 14.19 MB 🎉 -253 KB 🎉
Bundle Size Analyzer Link Link

@storybook/experimental-nextjs-vite

Before After Difference
Dependency count 188 186 🎉 -2 🎉
Self size 232 KB 232 KB 0 B
Dependency size 48.25 MB 47.99 MB 🎉 -252 KB 🎉
Bundle Size Analyzer Link Link

@storybook/nextjs

Before After Difference
Dependency count 592 591 🎉 -1 🎉
Self size 472 KB 472 KB 0 B
Dependency size 83.46 MB 83.41 MB 🎉 -50 KB 🎉
Bundle Size Analyzer Link Link

@storybook/server-webpack5

Before After Difference
Dependency count 255 253 🎉 -2 🎉
Self size 14 KB 14 KB 0 B
Dependency size 32.69 MB 32.44 MB 🎉 -252 KB 🎉
Bundle Size Analyzer Link Link

@storybook/svelte-vite

Before After Difference
Dependency count 134 135 🚨 +1 🚨
Self size 22 KB 22 KB 0 B
Dependency size 36.38 MB 36.43 MB 🚨 +50 KB 🚨
Bundle Size Analyzer Link Link

@storybook/svelte-webpack5

Before After Difference
Dependency count 310 311 🚨 +1 🚨
Self size 6 KB 6 KB 0 B
Dependency size 39.28 MB 39.33 MB 🚨 +50 KB 🚨
Bundle Size Analyzer Link Link

@storybook/sveltekit

Before After Difference
Dependency count 142 143 🚨 +1 🚨
Self size 47 KB 47 KB 0 B
Dependency size 39.68 MB 39.73 MB 🚨 +50 KB 🚨
Bundle Size Analyzer Link Link

@storybook/blocks

Before After Difference
Dependency count 4 2 🎉 -2 🎉
Self size 607 KB 607 KB 🎉 -8 B 🎉
Dependency size 1.53 MB 1.28 MB 🎉 -252 KB 🎉
Bundle Size Analyzer Link Link

storybook

Before After Difference
Dependency count 55 53 🎉 -2 🎉
Self size 22 KB 23 KB 🚨 +380 B 🚨
Dependency size 33.66 MB 33.45 MB 🎉 -213 KB 🎉
Bundle Size Analyzer Link Link

sb

Before After Difference
Dependency count 56 54 🎉 -2 🎉
Self size 1 KB 1 KB 0 B
Dependency size 33.68 MB 33.47 MB 🎉 -213 KB 🎉
Bundle Size Analyzer Link Link

@storybook/cli

Before After Difference
Dependency count 388 386 🎉 -2 🎉
Self size 503 KB 503 KB 0 B
Dependency size 75.54 MB 75.33 MB 🎉 -213 KB 🎉
Bundle Size Analyzer Link Link

@storybook/codemod

Before After Difference
Dependency count 277 275 🎉 -2 🎉
Self size 617 KB 617 KB 🚨 +130 B 🚨
Dependency size 65.62 MB 65.41 MB 🎉 -213 KB 🎉
Bundle Size Analyzer Link Link

create-storybook

Before After Difference
Dependency count 113 111 🎉 -2 🎉
Self size 1.11 MB 1.11 MB 0 B
Dependency size 42.79 MB 42.58 MB 🎉 -213 KB 🎉
Bundle Size Analyzer Link Link

@storybook/source-loader

Before After Difference
Dependency count 5 3 🎉 -2 🎉
Self size 41 KB 41 KB 0 B
Dependency size 10.75 MB 10.49 MB 🎉 -252 KB 🎉
Bundle Size Analyzer Link Link

@storybook/test

Before After Difference
Dependency count 53 51 🎉 -2 🎉
Self size 1.82 MB 1.82 MB 🎉 -27 B 🎉
Dependency size 8.09 MB 7.84 MB 🎉 -252 KB 🎉
Bundle Size Analyzer Link Link

@storybook/preset-server-webpack

Before After Difference
Dependency count 18 16 🎉 -2 🎉
Self size 10 KB 10 KB 0 B
Dependency size 1.48 MB 1.23 MB 🎉 -252 KB 🎉
Bundle Size Analyzer Link Link

@storybook/server

Before After Difference
Dependency count 9 7 🎉 -2 🎉
Self size 13 KB 13 KB 🎉 -32 B 🎉
Dependency size 974 KB 722 KB 🎉 -252 KB 🎉
Bundle Size Analyzer Link Link

@storybook/svelte

Before After Difference
Dependency count 106 107 🚨 +1 🚨
Self size 96 KB 96 KB 🚨 +32 B 🚨
Dependency size 10.59 MB 10.64 MB 🚨 +50 KB 🚨
Bundle Size Analyzer Link Link

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

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

Looks good!

@kasperpeulen kasperpeulen force-pushed the kasper/csf-in-monorepo branch from efc364c to 43f0399 Compare February 7, 2025 15:01
@kasperpeulen kasperpeulen merged commit 856aeb4 into next Feb 7, 2025
57 of 58 checks passed
@kasperpeulen kasperpeulen deleted the kasper/csf-in-monorepo branch February 7, 2025 15:43
@github-actions github-actions bot mentioned this pull request Feb 7, 2025
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci:normal maintenance User-facing maintenance tasks
Projects
None yet
Development

Successfully merging this pull request may close these issues.