mirror of
https://github.com/storybookjs/storybook.git
synced 2025-03-31 05:03:21 +08:00
Merge pull request #16078 from storybookjs/fix/16069-repair-to-importFn
Core: Fix issue with more complex `stories` paths.
This commit is contained in:
commit
15e5b782f7
@ -8,18 +8,20 @@ export function toImportFnPart(entry: NormalizedStoriesEntry) {
|
||||
|
||||
const webpackIncludeRegex = new RegExp(regex.source.substring(1));
|
||||
|
||||
// NOTE: `base` looks like './src' but `path`, (and what micromatch expects)
|
||||
// is something that starts with `src/`. So to strip off base from path, we
|
||||
// need to drop `base.length - 1` chars.
|
||||
return dedent`
|
||||
async (path) => {
|
||||
if (!${regex}.exec(path)) {
|
||||
const pathBase = path.substring(0, ${base.length + 1});
|
||||
if (pathBase !== '${base}/') {
|
||||
return;
|
||||
}
|
||||
|
||||
const pathRemainder = path.substring(${base.length + 1});
|
||||
if (!${regex}.exec(pathRemainder)) {
|
||||
return;
|
||||
}
|
||||
const remainder = path.substring(${base.length - 1});
|
||||
return import(
|
||||
/* webpackInclude: ${webpackIncludeRegex} */
|
||||
'${base}/' + remainder
|
||||
'${base}/' + pathRemainder
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ async function extractStories(storiesGlobs: string[], configDir: string) {
|
||||
stories[id] = {
|
||||
title: csf.meta.title,
|
||||
name,
|
||||
importPath: relativePath,
|
||||
importPath: relativePath[0] === '.' ? relativePath : `./${relativePath}`,
|
||||
};
|
||||
});
|
||||
} catch (err) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user