Skip to content

CLI: Find main.mts and main.cts configs in automigrations - #36538

Merged
ndelangen merged 1 commit into
nextfrom
fix/cli-find-config-file-mts
Oct 2, 2026
Merged

ndelangen merged 1 commit into
nextfrom
fix/cli-find-config-file-mts

Conversation

@valentinpalkovic

Copy link
Copy Markdown
Contributor

Closes #

What I did

Automigrations that edit the main config silently skip projects whose config is main.mts or main.cts.
This PR makes the CLI find those configs the same way Storybook itself loads them.

findConfigFile kept its own extension list (ts, js, tsx, jsx, mjs, cjs), while Storybook loads configs with the shared storybookConfigExtensions, which also includes .mts, .cts, .mtsx, and .ctsx.
For a main.mts project getStorybookData returned no mainConfigPath, so every automigration that edits main treated the project as having none.
In dxos, 127 of 131 configs are main.mts.

-const validConfigExtensions = ['ts', 'js', 'tsx', 'jsx', 'mjs', 'cjs'];
-
 export const findConfigFile = (prefix: string, configDir: string) => {
   const filePrefix = join(configDir, prefix);
-  const extension = validConfigExtensions.find((ext: string) => existsSync(`${filePrefix}.${ext}`));
-  return extension ? `${filePrefix}.${extension}` : null;
+  const extension = storybookConfigExtensions.find((ext) => existsSync(`${filePrefix}${ext}`));
+  return extension ? `${filePrefix}${extension}` : null;
 };

The lookup order now also matches the loader's.

Split out of #36476, which collected the bugs that running storybook upgrade against ten open-source Storybook 10 monorepos turned up on next.

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

Caution

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

  1. In a project whose config is .storybook/main.mts, run npx storybook@<canary> automigrate --yes.
  2. Confirm that migrations that edit main (for example enable-experimental-review --yes) now update main.mts instead of skipping the project.

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

  • Declare whether manual QA will be needed for this PR during the next release, through qa:needed or qa:skip

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

🤖 Generated with Claude Code

findConfigFile kept its own extension list, so for a main.mts project
getStorybookData returned no mainConfigPath and every automigration that
edits main skipped it. Use the shared storybookConfigExtensions, which also
matches the loader's lookup order.
@valentinpalkovic valentinpalkovic self-assigned this Oct 1, 2026
@valentinpalkovic valentinpalkovic added the ci:normal Run our default set of CI jobs (choose this for most PRs). label Oct 1, 2026
@valentinpalkovic
valentinpalkovic marked this pull request as ready for review October 1, 2026 14:02
@coderabbitai

coderabbitai Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

🧰 Additional context used
📚 Code guidelines (1)
.cursor/rules/spy-mocking.mdc — auto-discovered

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 5f6f5b10-3dcd-45a9-b1b7-b853b65f7cf1

📥 Commits

Reviewing files that changed from the base of the PR and between 9e4f791 and b255701.

📒 Files selected for processing (2)
  • code/core/src/common/utils/get-storybook-info.test.ts
  • code/core/src/common/utils/get-storybook-info.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.


Walkthrough

findConfigFile now uses the shared Storybook configuration extensions to locate main configuration files. Tests cover .mts, .cts, .ts, and .js files, and confirm that preview.ts does not match.

Changes

Storybook config lookup

Layer / File(s) Summary
Update config lookup and verify supported files
code/core/src/common/utils/get-storybook-info.ts, code/core/src/common/utils/get-storybook-info.test.ts
findConfigFile uses the shared extension list to check candidate filenames. Tests cover four supported main extensions and verify that preview.ts does not match.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to b2557

Automigrations can now discover main.mts and main.cts alongside other supported main configs. No material merge risk remains in the supplied changes.

✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@ndelangen ndelangen added the qa:skip Pull Requests that do not need any QA. (e.g. documentation) label Oct 2, 2026
@ndelangen
ndelangen merged commit b908530 into next Oct 2, 2026
174 of 178 checks passed
@ndelangen
ndelangen deleted the fix/cli-find-config-file-mts branch October 2, 2026 11:23
@github-actions github-actions Bot mentioned this pull request Oct 2, 2026
2 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug ci:normal Run our default set of CI jobs (choose this for most PRs). qa:skip Pull Requests that do not need any QA. (e.g. documentation)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants