Skip to content

Commit

Permalink
fix for webpack as well!
Browse files Browse the repository at this point in the history
  • Loading branch information
ndelangen committed Feb 29, 2024
1 parent 6a6e4cf commit cea2827
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions code/presets/react-webpack/src/loaders/react-docgen-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
parse,
builtinResolvers as docgenResolver,
builtinHandlers as docgenHandlers,
builtinImporters as docgenImporters,
makeFsImporter,
ERROR_CODES,
utils,
} from 'react-docgen';
Expand All @@ -11,6 +11,11 @@ import type { LoaderContext } from 'webpack';
import type { Handler, NodePath, babelTypes as t, Documentation } from 'react-docgen';
import { logger } from '@storybook/node-logger';

import {
ReactDocgenResolveError,
defaultLookupModule,
} from '../../../../frameworks/react-vite/src/plugins/docgen-resolver';

const { getNameOrValue, isReactForwardRefCall } = utils;

const actualNameHandler: Handler = function actualNameHandler(documentation, componentDefinition) {
Expand Down Expand Up @@ -54,7 +59,6 @@ type DocObj = Documentation & { actualName: string };

const defaultHandlers = Object.values(docgenHandlers).map((handler) => handler);
const defaultResolver = new docgenResolver.FindExportedDefinitionsResolver();
const defaultImporter = docgenImporters.fsImporter;
const handlers = [...defaultHandlers, actualNameHandler];

export default async function reactDocgenLoader(
Expand All @@ -71,7 +75,15 @@ export default async function reactDocgenLoader(
filename: this.resourcePath,
resolver: defaultResolver,
handlers,
importer: defaultImporter,
importer: makeFsImporter((filename, basedir) => {
const result = defaultLookupModule(filename, basedir);

if (!result.match(/\.(mjs|tsx?|jsx?)$/)) {
throw new ReactDocgenResolveError(filename);
}

return result;
}),
babelOptions: {
babelrc: false,
configFile: false,
Expand Down

0 comments on commit cea2827

Please sign in to comment.