ReactNative: Add true entrypoint generation#34663
Conversation
Adds a self-contained generator that creates the `.rnstorybook/index.{ts,js}`
entry point for React Native projects, copying it from a static template and
choosing the file extension based on the project's language preference
(TypeScript vs JavaScript).
The entry point template registers a root component via
`AppRegistry.registerComponent` and configures `getStorybookUI` with storage,
producing a user-editable file.
Files added:
- `src/generators/REACT_NATIVE/generateEntrypoint.ts` — the generator
- `src/generators/REACT_NATIVE/generateEntrypoint.test.ts` — full coverage
- `templates/react-native/index.js` — the static template
This module is intentionally not yet wired into the React Native generator;
that orchestration arrives in M3.
Split out of #34333 (M2). Tracking issue: #34276.
Made-with: Cursor
There was a problem hiding this comment.
Pull request overview
Adds a new React Native-specific generator in create-storybook to generate a .rnstorybook/index.(ts|js) entrypoint file from a static template, intended for later orchestration work (M3) in the RN init overhaul.
Changes:
- Added a static React Native entrypoint template (
templates/react-native/index.js). - Added
generateReactNativeEntrypoint()to write.rnstorybook/index.ts|jsbased onSupportedLanguage. - Added unit tests covering entrypoint generation behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
code/lib/create-storybook/templates/react-native/index.js |
New static entrypoint template used as the source for generated .rnstorybook/index.*. |
code/lib/create-storybook/src/generators/REACT_NATIVE/generateEntrypoint.ts |
New generator that resolves the template path and writes the entrypoint into .rnstorybook. |
code/lib/create-storybook/src/generators/REACT_NATIVE/generateEntrypoint.test.ts |
Unit tests validating file generation for TS/JS and rerun behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds a React Native Storybook entrypoint generator, two entrypoint templates (default and Expo), template-variant detection integrated into the RN generator flow, file-writing helpers, and Vitest tests validating generated output, idempotency, and sibling-file preservation. ChangesReact Native Entrypoint Generator & Templates
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
✨ Finishing Touches📝 Generate docstrings
Review rate limit: 2/5 reviews remaining, refill in 29 minutes and 46 seconds. Comment |
- Added `getEntrypointTemplatePath` function to resolve template paths based on the variant (default or expo). - Implemented `detectReactNativeEntrypointTemplateVariant` to determine the template variant based on dependencies. - Introduced tests for Expo-specific entrypoint generation and template path resolution. - Created new Expo template file for React Native Storybook integration. - Updated existing entrypoint generation logic to accommodate the new template variant.
…tegration - Moved AsyncStorage import to the top of the `index.expo.js` file for better visibility. - Updated `index.js` to use `shouldPersistSelection` instead of `enableWebsockets` for storage configuration. - Added a user-editable comment in `index.expo.js` to clarify usage for developers.
…pshots - Replaced direct value assertions with inline snapshots for better readability and maintainability. - Ensured that the tests accurately reflect the expected output for various entrypoint scenarios. - Improved test coverage for the generated output paths and content checks.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@code/lib/create-storybook/src/generators/REACT_NATIVE/generateEntrypoint.test.ts`:
- Around line 15-17: Add a normalizePath helper that replaces OS-specific
separators with '/' (e.g., normalizePath = (s) => s.replaceAll(path.sep, '/'))
and use it in the failing assertions: call
normalizePath(templatePath).endsWith('templates/react-native/index.expo.js') and
normalizePath(path.relative(cwd, result.targetPath)) for the other assertions
referencing path.relative; update assertions at the locations that currently use
templatePath and path.relative so they compare normalized strings.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 3cb100ed-f704-4cc6-85ba-bbc401729dd2
📒 Files selected for processing (1)
code/lib/create-storybook/src/generators/REACT_NATIVE/generateEntrypoint.test.ts
…ne snapshots - Updated assertions to use inline snapshots for improved clarity and maintainability. - Ensured the tests accurately reflect the expected output structure and content for various entrypoint scenarios. - Enhanced test coverage for the generated output, including imports and component registration.
Split out of #34333 (M2). Tracking issue: #34276.
What I did
Adds a self-contained generator that creates the
.rnstorybook/index.{ts,js}entry point for React Native projects, copying it from a static template and choosing the file extension based on the project's language preference (TypeScript vs JavaScript).The entry point template registers a root component via
AppRegistry.registerComponentand configuresgetStorybookUIwith storage, producing a user-editable file.Files added:
src/generators/REACT_NATIVE/generateEntrypoint.ts— the generatorsrc/generators/REACT_NATIVE/generateEntrypoint.test.ts— full coveragetemplates/react-native/index.js— the static templateThis module is intentionally not yet wired into the React Native generator; that orchestration arrives in M3.
Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
I manually tested this part as part of the bigger whole, before splitting the large PR into reviewable chunks.
Documentation
MIGRATION.MD
Checklist for Maintainers
When this PR is ready for testing, make sure to add
ci:normal,ci:mergedorci:dailyGH 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.tsMake 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/coreteam here.core team members can create a canary release here or locally with
gh workflow run --repo storybookjs/storybook publish.yml --field pr=<PR_NUMBER>Summary by CodeRabbit
New Features
Tests