Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
50 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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 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 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,46 @@ | ||
import globBase from 'glob-base'; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
import { makeRe } from 'micromatch'; | ||
import dedent from 'ts-dedent'; | ||
|
||
import type { NormalizedStoriesEntry } from '../types'; | ||
|
||
export function toImportFnPart(entry: NormalizedStoriesEntry) { | ||
const { base } = globBase(entry.glob); | ||
const regex = makeRe(entry.glob, { fastpaths: false, noglobstar: false, bash: false }); | ||
|
||
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)) { | ||
return; | ||
} | ||
const remainder = path.substring(${base.length - 1}); | ||
return import( | ||
/* webpackInclude: ${webpackIncludeRegex} */ | ||
'${base}/' + remainder | ||
); | ||
} | ||
`; | ||
} | ||
|
||
export function toImportFn(stories: NormalizedStoriesEntry[]) { | ||
return dedent` | ||
const importers = [ | ||
${stories.map(toImportFnPart).join(',\n')} | ||
]; | ||
export async function importFn(path) { | ||
for (let i = 0; i < importers.length; i++) { | ||
This comment has been minimized.
Sorry, something went wrong.
shilman
Member
|
||
const moduleExports = await importers[i](path); | ||
if (moduleExports) { | ||
return moduleExports; | ||
} | ||
} | ||
} | ||
`; | ||
} |
we just removed glob-base here #15399