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

CLI: Add "intents" question & auto-install test addon & improve test-addon compatibility #30202

Open
wants to merge 161 commits into
base: next
Choose a base branch
from

Conversation

ndelangen
Copy link
Member

@ndelangen ndelangen commented Jan 7, 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 pull request has been released as version 0.0.0-pr-30202-sha-0063c5e6. Try it out in a new sandbox by running npx [email protected] sandbox or in an existing project with npx [email protected] upgrade.

More information
Published version 0.0.0-pr-30202-sha-0063c5e6
Triggered by @ndelangen
Repository storybookjs/storybook
Branch norbert/cli-with-ink
Commit 0063c5e6
Datetime Fri Jan 31 16:20:38 UTC 2025 (1738340438)
Workflow run 13076628714

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=30202

name before after diff z %
createSize 0 B 0 B 0 B - -
generateSize 77.9 MB 77.9 MB 0 B 0.72 0%
initSize 131 MB 162 MB 31.4 MB 895.16 🔺19.3%
diffSize 53 MB 84.4 MB 31.4 MB 1156.17 🔺37.2%
buildSize 7.17 MB 7.19 MB 18.1 kB 1.98 0.3%
buildSbAddonsSize 1.85 MB 1.87 MB 17.9 kB 65.21 1%
buildSbCommonSize 195 kB 195 kB 0 B - 0%
buildSbManagerSize 1.86 MB 1.86 MB 0 B -0.58 0%
buildSbPreviewSize 0 B 0 B 0 B - -
buildStaticSize 0 B 0 B 0 B - -
buildPrebuildSize 3.91 MB 3.92 MB 17.9 kB 8.48 0.5%
buildPreviewSize 3.27 MB 3.27 MB 146 B -0.42 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 23.5s 8.9s -14s -529ms -1.3 🔰-161.5%
generateTime 18.3s 18.6s 281ms -1.02 1.5%
initTime 11.7s 54.6s 42.9s 18.63 🔺78.6%
buildTime 7.8s 8.4s 522ms -0.79 6.2%
testBuildTime 0ms 0ms 0ms - -
devPreviewResponsive 5.5s 5.7s 222ms 0.17 3.9%
devManagerResponsive 4s 4.1s 177ms 0.2 4.2%
devManagerHeaderVisible 820ms 997ms 177ms 2.06 🔺17.8%
devManagerIndexVisible 909ms 1s 157ms 2.12 🔺14.7%
devStoryVisibleUncached 1.9s 3.3s 1.3s 0.66 41%
devStoryVisible 909ms 1s 157ms 2.07 🔺14.7%
devAutodocsVisible 741ms 881ms 140ms 1.55 🔺15.9%
devMDXVisible 697ms 822ms 125ms 1.31 🔺15.2%
buildManagerHeaderVisible 759ms 865ms 106ms 0.44 12.3%
buildManagerIndexVisible 866ms 961ms 95ms 0.4 9.9%
buildStoryVisible 692ms 846ms 154ms 0.45 18.2%
buildAutodocsVisible 607ms 671ms 64ms -0.13 9.5%
buildMDXVisible 597ms 614ms 17ms 0.38 2.8%

Greptile Summary

This PR significantly enhances the Storybook CLI with new features for test addon integration and improved framework compatibility checks.

  • Added new "intents" question during initialization to determine if users plan to use Storybook for development, documentation, or testing in code/lib/create-storybook/src/initiate.ts
  • Implemented framework compatibility checks for test addon in code/lib/create-storybook/src/ink/steps/checks/frameworkTest.tsx
  • Added Vitest configuration validation and auto-setup in code/lib/create-storybook/src/ink/steps/checks/vitestConfigFiles.tsx
  • Modernized CLI architecture with Zod validation and TypeScript improvements in code/lib/create-storybook/src/bin/modernInputs.ts
  • Switched from CommonJS to ESM modules across CLI packages with proper error handling

The changes look comprehensive but the commented-out render functions in several new files suggest some UI components may not be fully implemented yet.

Copy link

nx-cloud bot commented Jan 7, 2025

View your CI Pipeline Execution ↗ for commit 0063c5e.

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

☁️ Nx Cloud last updated this comment at 2025-01-31 16:22:39 UTC

@storybook-pr-benchmarking
Copy link

storybook-pr-benchmarking bot commented Jan 7, 2025

Package Benchmarks

Commit: 0063c5e, ran on 31 January 2025 at 16:28:39 UTC

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

@storybook/core

Before After Difference
Dependency count 54 54 0
Self size 19.05 MB 18.98 MB 🎉 -74 KB 🎉
Dependency size 14.44 MB 14.44 MB 0 B
Bundle Size Analyzer Link Link

storybook

Before After Difference
Dependency count 55 55 0
Self size 22 KB 24 KB 🚨 +1 KB 🚨
Dependency size 33.49 MB 33.42 MB 🎉 -74 KB 🎉
Bundle Size Analyzer Link Link

sb

Before After Difference
Dependency count 56 56 0
Self size 1 KB 1 KB 0 B
Dependency size 33.52 MB 33.44 MB 🎉 -73 KB 🎉
Bundle Size Analyzer Link Link

@storybook/cli

Before After Difference
Dependency count 388 359 🎉 -29 🎉
Self size 503 KB 248 KB 🎉 -255 KB 🎉
Dependency size 75.35 MB 74.90 MB 🎉 -451 KB 🎉
Bundle Size Analyzer Link Link

@storybook/codemod

Before After Difference
Dependency count 277 277 0
Self size 617 KB 617 KB 0 B
Dependency size 65.43 MB 65.36 MB 🎉 -74 KB 🎉
Bundle Size Analyzer Link Link

create-storybook

Before After Difference
Dependency count 113 55 🎉 -58 🎉
Self size 1.11 MB 1.34 MB 🚨 +234 KB 🚨
Dependency size 42.63 MB 33.42 MB 🎉 -9.21 MB 🎉
Bundle Size Analyzer Link Link

@ndelangen ndelangen self-assigned this Jan 8, 2025
@ndelangen ndelangen changed the title CLI: Use ink in CLI CLI: Add "intents" question & auto-install test addon & improve test-addon compatibility Jan 31, 2025
@ndelangen ndelangen marked this pull request as ready for review January 31, 2025 12:02
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.

48 file(s) reviewed, 31 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines +61 to +70
files: [
'*.js',
'*.jsx',
'*.json',
'*.html',
'**/.storybook/*.ts',
'**/.storybook/*.tsx',
'**/.storybook/**/*.ts',
'**/.storybook/**/*.tsx',
],
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 using a more concise glob pattern like '/.storybook//*.{ts,tsx}' instead of separate patterns

Comment on lines 7 to +11
if (['dev', 'build'].includes(args[0])) {
require('@storybook/core/cli/bin');
import('@storybook/core/cli/bin').catch((e) => {
console.error('Failed to load @storybook/core/cli/bin', e);
process.exit(1);
});
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 await to ensure the import completes before any other code runs

@@ -23,4 +23,7 @@ process.once('uncaughtException', (error) => {
throw error;
});

require('../dist/bin/index.cjs');
import('../dist/bin/index.js').catch((error) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Using dynamic import() with .js extension may cause issues if the file is actually .cjs - verify the correct extension is being used


createStorybookProgram
.action(async (options) => {
// const d = modernInputs.safeParse(options);
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Commented-out code should be removed before merging

options.debug = options.debug ?? false;
options.dev = options.dev ?? (IS_NON_CI && IS_NON_STORYBOOK_SANDBOX);

await initiate(options as CommandOptions).catch(() => process.exit(1));
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Type assertion to CommandOptions could be unsafe - consider validating options shape before assertion

@@ -0,0 +1 @@
declare var CLI_APP_INSTANCE: ReturnType<typeof render> | undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: The render function type is used but not imported or defined in this file, which could cause TypeScript compilation errors if the type is not available in the global scope

@@ -0,0 +1 @@
declare var CLI_APP_INSTANCE: ReturnType<typeof render> | undefined;
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 JSDoc comments to document the purpose and usage of this global variable

Comment on lines 16 to 17
const reactAct =
// @ts-expect-error act might not be available in some versions of React
typeof clonedReact.act === 'function' ? clonedReact.act : DeprecatedReactTestUtils.act;
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 a type assertion here to explicitly handle the case where act might not exist on clonedReact

scripts/prepare/bundle.ts Show resolved Hide resolved
Comment on lines 41 to 46
function getTSDiagnostics(program: ts.Program, cwd: string, host: ts.CompilerHost): any {
return ts.formatDiagnosticsWithColorAndContext(
ts.getPreEmitDiagnostics(program).filter((d) => d.file.fileName.startsWith(cwd)),
ts.getPreEmitDiagnostics(program).filter((d) => d.file && d.file.fileName.startsWith(cwd)),
host
);
}
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 a return type annotation instead of using 'any'

Suggested change
function getTSDiagnostics(program: ts.Program, cwd: string, host: ts.CompilerHost): any {
return ts.formatDiagnosticsWithColorAndContext(
ts.getPreEmitDiagnostics(program).filter((d) => d.file.fileName.startsWith(cwd)),
ts.getPreEmitDiagnostics(program).filter((d) => d.file && d.file.fileName.startsWith(cwd)),
host
);
}
function getTSDiagnostics(program: ts.Program, cwd: string, host: ts.CompilerHost): string {
return ts.formatDiagnosticsWithColorAndContext(
ts.getPreEmitDiagnostics(program).filter((d) => d.file && d.file.fileName.startsWith(cwd)),
host
);
}

@ndelangen ndelangen requested a review from ghengeveld January 31, 2025 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants