Merge pull request #16078 from storybookjs/fix/16069-repair-to-importFn

Core: Fix issue with more complex `stories` paths.
This commit is contained in:
Michael Shilman 2021-09-16 18:23:36 +08:00 committed by GitHub
commit 15e5b782f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 7 deletions

View File

@ -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
);
}

View File

@ -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) {