mirror of
https://github.com/storybookjs/storybook.git
synced 2025-03-18 05:02:24 +08:00
FIX
This commit is contained in:
parent
a4fa665ec2
commit
fb91781632
@ -6,9 +6,20 @@ export const toRequireContext = (input) => {
|
||||
switch (true) {
|
||||
case typeof input === 'string': {
|
||||
const { base, glob } = globBase(input);
|
||||
const regex = makeRe(glob);
|
||||
|
||||
return { path: base, recursive: glob.startsWith('**'), match: regex };
|
||||
const recursive = glob.startsWith('**');
|
||||
const indicator = glob.replace(/^(\*\*\/)*/, '');
|
||||
const regex = makeRe(indicator, { fastpaths: false, noglobstar: false, bash: true });
|
||||
const { source } = regex;
|
||||
|
||||
if (source.startsWith('^')) {
|
||||
// prepended '^' char causes webpack require.context to fail
|
||||
const match = source.substring(1);
|
||||
|
||||
return { path: base, recursive, match };
|
||||
}
|
||||
|
||||
throw new Error(`Invalid glob: >> ${input} >> ${regex}`);
|
||||
}
|
||||
case isObject(input): {
|
||||
return input;
|
||||
@ -22,5 +33,8 @@ export const toRequireContext = (input) => {
|
||||
|
||||
export const toRequireContextString = (input) => {
|
||||
const { path: p, recursive: r, match: m } = toRequireContext(input);
|
||||
return `require.context('${p}', ${r}, ${m})`;
|
||||
|
||||
const result = `console.log('HERE') || require.context('${p}', ${r}, /${m}/)`;
|
||||
// process.exit(0);
|
||||
return result;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user