-
-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Clean up webpack framework presets for #20885 #34608
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
base: next
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import { extname } from 'node:path'; | ||
|
|
||
| import resolve from 'resolve'; | ||
|
|
||
| export class ReactDocgenResolveError extends Error { | ||
| readonly code = 'MODULE_NOT_FOUND'; | ||
|
|
||
| constructor(filename: string) { | ||
| super(`'${filename}' was ignored by react-docgen.`); | ||
| } | ||
| } | ||
|
|
||
| // These extensions are sorted by priority. | ||
| export const RESOLVE_EXTENSIONS = [ | ||
| '.js', | ||
| '.cts', | ||
| '.mts', | ||
| '.ctsx', | ||
| '.mtsx', | ||
| '.ts', | ||
| '.tsx', | ||
| '.mjs', | ||
| '.cjs', | ||
| '.mts', | ||
| '.cts', | ||
| '.jsx', | ||
| ]; | ||
|
|
||
| export function defaultLookupModule(filename: string, basedir: string): string { | ||
| const resolveOptions = { | ||
| basedir, | ||
| extensions: RESOLVE_EXTENSIONS, | ||
| includeCoreModules: false, | ||
| }; | ||
|
|
||
| try { | ||
| return resolve.sync(filename, resolveOptions); | ||
| } catch (error) { | ||
| const ext = extname(filename); | ||
| let newFilename: string; | ||
|
|
||
| switch (ext) { | ||
| case '.js': | ||
| case '.mjs': | ||
| case '.cjs': { | ||
| const base = filename.slice(0, -2); | ||
| try { | ||
| return resolve.sync(`${base}ts`, { ...resolveOptions, extensions: [] }); | ||
| } catch { | ||
| newFilename = `${base}tsx`; | ||
| } | ||
| break; | ||
| } | ||
|
|
||
| case '.jsx': | ||
| newFilename = `${filename.slice(0, -3)}tsx`; | ||
| break; | ||
| default: | ||
| throw error; | ||
| } | ||
|
|
||
| return resolve.sync(newFilename, { | ||
| ...resolveOptions, | ||
| extensions: [], | ||
| }); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,10 +2,8 @@ import { compileCsfModule } from './lib/compiler/index.ts'; | |||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| export default (content: string) => { | ||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||
| const after = compileCsfModule(JSON.parse(content)); | ||||||||||||||||||||||||||||
| return after; | ||||||||||||||||||||||||||||
| return compileCsfModule(JSON.parse(content)); | ||||||||||||||||||||||||||||
| } catch (e) { | ||||||||||||||||||||||||||||
| // for debugging | ||||||||||||||||||||||||||||
| console.log(content, e); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| return content; | ||||||||||||||||||||||||||||
|
Comment on lines
3
to
9
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fail the loader instead of swallowing compile errors. If Proposed fix export default (content: string) => {
- try {
- return compileCsfModule(JSON.parse(content));
- } catch (e) {
- console.log(content, e);
- }
- return content;
+ return compileCsfModule(JSON.parse(content));
};As per coding guidelines, “Use Storybook loggers instead of raw console.* in normal code paths: use 'storybook/internal/node-logger' for server-side code and 'storybook/internal/client-logger' for client-side code”. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
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.
Re-export the webpack5
BuilderResultto preservestats.Line 15 now exports the core result type, but
@storybook/builder-webpack5extends it withstats?: Stats. Since this framework uses the webpack5 builder, consumers importingBuilderResultfrom@storybook/react-webpack5lose that webpack-specific field.🐛 Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents