Skip to content

Maintenance: Centralize supported file extension lists#34844

Open
valentinpalkovic wants to merge 2 commits into
nextfrom
valentin/centralize-supported-extensions
Open

Maintenance: Centralize supported file extension lists#34844
valentinpalkovic wants to merge 2 commits into
nextfrom
valentin/centralize-supported-extensions

Conversation

@valentinpalkovic
Copy link
Copy Markdown
Contributor

@valentinpalkovic valentinpalkovic commented May 20, 2026

What I did

Follow-up to #34692. Addresses @Sidnioulz's review feedback that the codebase had several inline extension lists with subtle drift between similar tasks.

Introduces code/core/src/shared/constants/extensions.ts with four task-named constants:

Constant Purpose Extensions
jsModuleExtensions JS-only module loading .mjs .js .cjs
jsTsSourceExtensions JS/TS source files for parsers/bundlers .ts .tsx .js .jsx .mjs .cjs
storybookConfigExtensions Storybook config files (main, preview, manager) .js .ts .jsx .tsx .mjs .mts .mtsx .cjs .cts .ctsx
userModuleExtensions User code for sb.mock() (incl. JSON, SFC) .js .mjs .cjs .ts .tsx .jsx .json .vue .svelte

Migrates five consumers to import from the central module:

  • common/utils/interpret-files.tsstorybookConfigExtensions (keeps the public supportedExtensions re-export used by the React renderer's component manifest)
  • mocking-utils/resolve.tsuserModuleExtensions
  • common/utils/validate-config.tsjsModuleExtensions
  • shared/utils/module.tsjsModuleExtensions
  • core-server/change-detection/parser-registry/builtins.tsjsTsSourceExtensions

Three lists were intentionally left inline because they serve different tasks with subtle behavioral coupling:

  • bin/loader.ts — runtime ESM/CJS hook loader uses a narrower set (no .mtsx/.ctsx)
  • builder-manager/index.ts — esbuild bundler config, changing it would alter what esbuild resolves in the manager bundle
  • telemetry/get-application-file-count.ts — git ls-files glob using a no-dot format

No behavioral changes; pure deduplication.

Why now

Reviewer-requested follow-up to #34692 (resolve → oxc-resolver migration). Doing it as a separate PR keeps the dependency migration focused and the refactor reviewable on its own.

Stacking

This PR is stacked on top of #34692. Once #34692 merges, this auto-rebases against 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

Existing tests cover all five migrated consumers. The refactor is a pure substitution (each new constant equals the inline list it replaces, byte-for-byte).

Manual testing

yarn nx check core and yarn nx check react both pass. Lint clean on all touched files.

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: cleanup or maintenance.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
    • Centralized file-extension handling across tooling and config resolution for more consistent behavior.
    • Broader file-type support (including .astro) for module, mock and config resolution.
    • Expect fewer resolution/validation errors and more reliable loading of frameworks, imports, and mocks.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 20, 2026

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: 62fff131-9c53-4557-9dcb-a117530a3038

📥 Commits

Reviewing files that changed from the base of the PR and between f692fe6 and 4514507.

📒 Files selected for processing (1)
  • code/core/src/shared/constants/extensions.ts
✅ Files skipped from review due to trivial changes (1)
  • code/core/src/shared/constants/extensions.ts

📝 Walkthrough

Walkthrough

Centralizes multiple hardcoded file-extension lists into a new shared constants module and updates module resolution, Storybook config detection, import parsing, and mock resolution to use those shared extension arrays.

Changes

Extension Consolidation

Layer / File(s) Summary
Shared extension constants foundation
code/core/src/shared/constants/extensions.ts
New module exports four as const extension lists: jsModuleExtensions, jsTsSourceExtensions, storybookConfigExtensions, and userModuleExtensions.
Module resolution with shared constants
code/core/src/shared/utils/module.ts, code/core/src/common/utils/validate-config.ts
safeResolveModule and framework preset resolution now default to jsModuleExtensions instead of local hardcoded arrays.
Storybook config file interpretation
code/core/src/common/utils/interpret-files.ts
supportedExtensions now references storybookConfigExtensions rather than a file-local hardcoded list.
Import parser extension configuration
code/core/src/core-server/change-detection/parser-registry/builtins.ts
oxcImportParser.extensions switches to jsTsSourceExtensions for JS/TS source detection during import analysis.
Mock path resolution with user extensions
code/core/src/mocking-utils/resolve.ts
externalResolver and resolveWithExtensions iterate over userModuleExtensions to include JSON and component file types when resolving mocks.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • storybookjs/storybook#32905: Also touches interpret-files.ts and extension-based resolution, overlapping with changes to where supported extensions are defined.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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

Base automatically changed from valentin/replace-resolve-with-oxc-resolver to next May 20, 2026 13:04
@Sidnioulz Sidnioulz added maintenance User-facing maintenance tasks ci:normal labels May 21, 2026
@Sidnioulz Sidnioulz self-assigned this May 21, 2026
@Sidnioulz Sidnioulz self-requested a review May 21, 2026 15:44
Address @Sidnioulz's review feedback (PR #34692). Inline extension lists
were scattered across code/core with subtle drift between similar tasks.

Introduces `code/core/src/shared/constants/extensions.ts` with four
task-named constants:
- `jsModuleExtensions`         — .mjs/.js/.cjs only
- `jsTsSourceExtensions`       — JS/TS family incl. JSX/TSX
- `storybookConfigExtensions`  — main/preview/manager config files
- `userModuleExtensions`       — user code incl. JSON, .vue, .svelte

Migrates five consumers:
- common/utils/interpret-files.ts  → storybookConfigExtensions
  (keeps the public `supportedExtensions` re-export used by the
   react renderer's component manifest)
- mocking-utils/resolve.ts         → userModuleExtensions
- common/utils/validate-config.ts  → jsModuleExtensions
- shared/utils/module.ts           → jsModuleExtensions
- core-server/change-detection/parser-registry/builtins.ts
                                   → jsTsSourceExtensions

Left intentionally inline (different task / subtle behavior):
- bin/loader.ts                 — runtime ESM/CJS loader, narrower set
- builder-manager/index.ts      — esbuild bundler config
- telemetry/get-application-file-count.ts — git ls-files glob (no dots)

No behavioral changes; pure deduplication.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@Sidnioulz Sidnioulz force-pushed the valentin/centralize-supported-extensions branch from e3d9256 to f692fe6 Compare May 21, 2026 15:47
Comment on lines +31 to +43
* Module file extensions for user-code resolution (e.g. `sb.mock()`). Covers JS/TS plus JSON and
* common single-file-component types (`.vue`, `.svelte`).
*/
export const userModuleExtensions = [
'.js',
'.mjs',
'.cjs',
'.ts',
'.tsx',
'.jsx',
'.json',
'.vue',
'.svelte',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks so much for that!

WDYT about my suggestion on the other PR to also add e.g. Solid or Astro? Like Vue and Svelte, these are supported when the relevant framework is used.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Has Solid its own file extension and DSL? I'm okay with adding astro for sure!

@storybook-app-bot
Copy link
Copy Markdown

storybook-app-bot Bot commented May 21, 2026

Package Benchmarks

Commit: 4514507, ran on 22 May 2026 at 11:03:49 UTC

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

@storybook/builder-webpack5

Before After Difference
Dependency count 184 184 0
Self size 79 KB 79 KB 0 B
Dependency size 33.35 MB 33.36 MB 🚨 +16 KB 🚨
Bundle Size Analyzer Link Link

@storybook/angular

Before After Difference
Dependency count 185 185 0
Self size 160 KB 160 KB 🎉 -54 B 🎉
Dependency size 30.73 MB 30.75 MB 🚨 +16 KB 🚨
Bundle Size Analyzer Link Link

@storybook/ember

Before After Difference
Dependency count 188 188 0
Self size 15 KB 15 KB 🚨 +18 B 🚨
Dependency size 30.07 MB 30.08 MB 🚨 +16 KB 🚨
Bundle Size Analyzer Link Link

@storybook/nextjs

Before After Difference
Dependency count 534 534 0
Self size 662 KB 662 KB 🎉 -120 B 🎉
Dependency size 61.51 MB 61.52 MB 🚨 +16 KB 🚨
Bundle Size Analyzer Link Link

@storybook/react-webpack5

Before After Difference
Dependency count 271 271 0
Self size 23 KB 23 KB 🎉 -12 B 🎉
Dependency size 46.05 MB 46.06 MB 🚨 +16 KB 🚨
Bundle Size Analyzer Link Link

@storybook/server-webpack5

Before After Difference
Dependency count 196 196 0
Self size 16 KB 16 KB 0 B
Dependency size 34.61 MB 34.63 MB 🚨 +16 KB 🚨
Bundle Size Analyzer Link Link

@storybook/preset-react-webpack

Before After Difference
Dependency count 164 164 0
Self size 18 KB 18 KB 0 B
Dependency size 32.35 MB 32.37 MB 🚨 +16 KB 🚨
Bundle Size Analyzer Link Link

Comment thread code/core/src/shared/constants/extensions.ts
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.

2 participants