Skip to content

ReactNative: Add true entrypoint generation#34663

Merged
ndelangen merged 11 commits into
nextfrom
norbert/m2-entrypoint-generation
May 4, 2026
Merged

ReactNative: Add true entrypoint generation#34663
ndelangen merged 11 commits into
nextfrom
norbert/m2-entrypoint-generation

Conversation

@ndelangen
Copy link
Copy Markdown
Member

@ndelangen ndelangen commented Apr 30, 2026

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.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.

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

I manually tested this part as part of the bigger whole, before splitting the large PR into reviewable chunks.

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 publish.yml --field pr=<PR_NUMBER>

Summary by CodeRabbit

  • New Features

    • Adds React Native Storybook entrypoint generation (TypeScript/JavaScript) with an Expo-aware variant, persistent selection state storage, and automatic app-root registration for the Storybook UI to simplify customization.
  • Tests

    • Adds test coverage for template variant detection, generated file contents and formats, overwrite/idempotency behavior, and preservation of existing project files.

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
Copilot AI review requested due to automatic review settings April 30, 2026 08:27
@ndelangen ndelangen self-assigned this Apr 30, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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|js based on SupportedLanguage.
  • 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.

Comment thread code/lib/create-storybook/templates/react-native/index.js Outdated
Comment thread code/lib/create-storybook/templates/react-native/index.js
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 30, 2026

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e1a0c603-6aba-4e98-a0eb-bffdbade7d4e

📥 Commits

Reviewing files that changed from the base of the PR and between 854d505 and be238db.

📒 Files selected for processing (1)
  • code/lib/create-storybook/src/generators/REACT_NATIVE/generateEntrypoint.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • code/lib/create-storybook/src/generators/REACT_NATIVE/generateEntrypoint.test.ts

📝 Walkthrough

Walkthrough

Adds 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.

Changes

React Native Entrypoint Generator & Templates

Layer / File(s) Summary
Templates
code/lib/create-storybook/templates/react-native/*
Adds index.js (default) and index.expo.js (expo) templates that build StorybookUIRoot via view.getStorybookUI, configure persistence using AsyncStorage, register the app/root (AppRegistry.registerComponent or registerRootComponent), and export the UI root.
Data / Helpers
code/lib/create-storybook/src/generators/REACT_NATIVE/generateEntrypoint.ts
Introduces ReactNativeEntrypointTemplateVariant type, getEntrypointExtension(language), getEntrypointTemplatePath(templateVariant), and computes ENTRYPOINT_TEMPLATE_DIR from the package location.
Core Implementation
code/lib/create-storybook/src/generators/REACT_NATIVE/generateEntrypoint.ts
Adds generateReactNativeEntrypoint({ language, templateVariant?, cwd? }) which selects a template file, ensures the .rnstorybook directory exists, writes `index.{ts
Integration / Generator Flow
code/lib/create-storybook/src/generators/REACT_NATIVE/index.ts
Adds and exports detectReactNativeEntrypointTemplateVariant(allDependencies) (returns 'expo' when expo or expo-router present, otherwise 'default') and updates generator configure to compute templateVariant from packageManager.getAllDependencies() and invoke generateReactNativeEntrypoint.
Tests
code/lib/create-storybook/src/generators/REACT_NATIVE/*test.ts
Adds index.test.ts (variant detection) and generateEntrypoint.test.ts which runs generation in isolated temp dirs (TS/JS/expo), asserts generated .rnstorybook/index.{ts,js} contents (AppRegistry vs Expo wiring, AsyncStorage persistence, view import), verifies overwrite/idempotency, sibling-file preservation, and that an existing storybook.requires.ts is unchanged.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Review rate limit: 2/5 reviews remaining, refill in 29 minutes and 46 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

@ndelangen ndelangen mentioned this pull request Apr 30, 2026
6 tasks
@ndelangen ndelangen requested review from JReinhold, dannyhw, shilman and valentinpalkovic and removed request for valentinpalkovic April 30, 2026 11:51
Comment thread code/lib/create-storybook/templates/react-native/index.js
ndelangen added 7 commits May 4, 2026 12:15
- 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.
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between e501c33 and 854d505.

📒 Files selected for processing (1)
  • code/lib/create-storybook/src/generators/REACT_NATIVE/generateEntrypoint.test.ts

Comment thread code/lib/create-storybook/src/generators/REACT_NATIVE/generateEntrypoint.test.ts Outdated
…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.
@ndelangen ndelangen merged commit bfb2660 into next May 4, 2026
123 checks passed
@ndelangen ndelangen deleted the norbert/m2-entrypoint-generation branch May 4, 2026 14:48
@coderabbitai coderabbitai Bot mentioned this pull request May 4, 2026
20 tasks
@github-actions github-actions Bot mentioned this pull request May 4, 2026
14 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants