-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
React: Add manifests/components.html page #32905
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
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
f30520c
Create manifests/components.html page
kasperpeulen 3b1c417
Better error messages
kasperpeulen b361d37
Fix css
kasperpeulen b36905f
Look up index files as well for raw component paths
kasperpeulen f93f388
Improve error messages
kasperpeulen 6f33595
Improve component path calculation
kasperpeulen 303372a
Improve errror message
kasperpeulen 1d2ff16
Fix matchPath from tsconfig
kasperpeulen da371a0
Parse CSF2 args
kasperpeulen eb3381a
Cleanup manifest code
kasperpeulen 5c7725f
Improve error message
kasperpeulen 569fb1b
Greatly improve resolved path resolution
kasperpeulen 20049de
Typo
kasperpeulen 15b6805
Improve error
kasperpeulen 8f03c22
Group by errors
kasperpeulen 2d50a45
Remove dedent
kasperpeulen 074c9b5
Fix ids
kasperpeulen f09df14
Prefer js to make no breaking changes
kasperpeulen a7160e6
Fix unit tests
kasperpeulen 059bed1
Fix unit tests
kasperpeulen d65d0e7
Also build it static
kasperpeulen cf22079
Address review
kasperpeulen 813ff59
Merge branch '10.1-with-canary-release' into kasper/manifests.html
JReinhold 0338640
Merge pull request #32882 from storybookjs/kasper/manifests.html
kasperpeulen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,58 @@ | ||
| import { existsSync } from 'node:fs'; | ||
| import { extname } from 'node:path'; | ||
|
|
||
| import resolve from 'resolve'; | ||
|
|
||
| export const supportedExtensions = [ | ||
| '.js', | ||
| '.mjs', | ||
| '.cjs', | ||
| '.jsx', | ||
| '.ts', | ||
| '.jsx', | ||
| '.tsx', | ||
| '.mjs', | ||
| '.mts', | ||
| '.mtsx', | ||
| '.cjs', | ||
| '.cts', | ||
| '.tsx', | ||
| '.ctsx', | ||
| ] as const; | ||
|
|
||
| export function getInterpretedFile(pathToFile: string) { | ||
| return supportedExtensions | ||
| .map((ext) => (pathToFile.endsWith(ext) ? pathToFile : `${pathToFile}${ext}`)) | ||
| .find((candidate) => existsSync(candidate)); | ||
| } | ||
|
|
||
| export function resolveImport(id: string, options: resolve.SyncOpts): string { | ||
| const mergedOptions: resolve.SyncOpts = { | ||
| extensions: supportedExtensions, | ||
| packageFilter(pkg) { | ||
| // Prefer 'module' over 'main' if available | ||
| if (pkg.module) { | ||
| pkg.main = pkg.module; | ||
| } | ||
| return pkg; | ||
| }, | ||
| ...options, | ||
| }; | ||
|
|
||
| try { | ||
| return resolve.sync(id, { ...mergedOptions }); | ||
| } catch (error) { | ||
| const ext = extname(id); | ||
|
|
||
| // if we try to import a JavaScript file it might be that we are actually pointing to | ||
| // a TypeScript file. This can happen in ES modules as TypeScript requires to import other | ||
| // TypeScript files with .js extensions | ||
| // https://www.typescriptlang.org/docs/handbook/esm-node.html#type-in-packagejson-and-new-extensions | ||
| const newId = ['.js', '.mjs', '.cjs'].includes(ext) | ||
| ? `${id.slice(0, -2)}ts` | ||
| : ext === '.jsx' | ||
| ? `${id.slice(0, -3)}tsx` | ||
| : null; | ||
|
|
||
| if (!newId) { | ||
| throw error; | ||
| } | ||
| return resolve.sync(newId, { ...mergedOptions, extensions: [] }); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| // Object.groupBy polyfill | ||
| export const groupBy = <K extends PropertyKey, T>( | ||
| items: T[], | ||
| keySelector: (item: T, index: number) => K | ||
| ) => { | ||
| return items.reduce<Record<K, T[]>>( | ||
| (acc, item, index) => { | ||
| const key = keySelector(item, index); | ||
| acc[key] ??= []; | ||
| acc[key].push(item); | ||
| return acc; | ||
| }, | ||
| {} as Record<K, T[]> | ||
| ); | ||
| }; | ||
|
|
||
| // This invariant allows for lazy evaluation of the message, which we need to avoid excessive computation. | ||
| export function invariant( | ||
| condition: unknown, | ||
| message?: string | (() => string) | ||
| ): asserts condition { | ||
| if (condition) { | ||
| return; | ||
| } | ||
| throw new Error((typeof message === 'function' ? message() : message) ?? 'Invariant failed'); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix TypeScript ESM fallback for .tsx components
When stories follow the NodeNext/ESM guidance and import their component as
./Component.js, the source file is oftenComponent.tsx. The new fallback only tries*.ts, so resolution now fails and the component manifest ends up with “Component file could not be read”, which is a functional regression. Please expand the fallback to retry.tsx(or simply drop the extension and letsupportedExtensionstake over) so.tsxsources keep working.Apply this diff to cover both
.tsand.tsxbefore giving up:🤖 Prompt for AI Agents