mirror of
https://github.com/storybookjs/storybook.git
synced 2025-03-31 05:03:21 +08:00
Merge pull request #11531 from daniel-ac-martin/expose-globbing-failure
Core: Improve translation of globs for main.js stories
This commit is contained in:
commit
c17294b027
@ -120,6 +120,32 @@ const testCases = [
|
||||
'../src/stories/components/Icon/Icon.tsx',
|
||||
],
|
||||
},
|
||||
{
|
||||
glob: '../components/*/*.stories.js',
|
||||
validPaths: ['../components/icon/Icon.stories.js'],
|
||||
invalidPaths: [
|
||||
'../components/icon/node_modules/icon/Icon.stories.js',
|
||||
'./stories.js',
|
||||
'./src/stories/Icon.stories.js',
|
||||
'./Icon.stories.js',
|
||||
'../src/Icon.stories.mdx',
|
||||
'../src/stories/components/Icon/Icon.stories.ts',
|
||||
'../src/stories/components/Icon/Icon.mdx',
|
||||
],
|
||||
},
|
||||
{
|
||||
glob: '../components/*/stories/*.js',
|
||||
validPaths: ['../components/icon/stories/Icon.js'],
|
||||
invalidPaths: [
|
||||
'../components/icon/node_modules/icon/stories/Icon.js',
|
||||
'./stories.js',
|
||||
'./src/stories/Icon.stories.js',
|
||||
'./Icon.stories.js',
|
||||
'../src/Icon.stories.mdx',
|
||||
'../src/stories/components/Icon/Icon.stories.ts',
|
||||
'../src/stories/components/Icon/Icon.mdx',
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
describe('toRequireContext', () => {
|
||||
@ -138,10 +164,10 @@ describe('toRequireContext', () => {
|
||||
return baseIncluded && matched;
|
||||
}
|
||||
|
||||
const isMatchedForValidPaths = validPaths.filter((filePath) => !isMatched(filePath));
|
||||
const isNotMatchedForValidPaths = validPaths.filter((filePath) => !isMatched(filePath));
|
||||
const isMatchedForInvalidPaths = invalidPaths.filter((filePath) => !!isMatched(filePath));
|
||||
|
||||
expect(isMatchedForValidPaths).toEqual([]);
|
||||
expect(isNotMatchedForValidPaths).toEqual([]);
|
||||
expect(isMatchedForInvalidPaths).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
@ -31,14 +31,15 @@ export const toRequireContext = (input: any) => {
|
||||
case typeof input === 'string': {
|
||||
const { base, glob } = globBase(fixedInput);
|
||||
|
||||
const recursive = glob.startsWith('**');
|
||||
const indicator = glob.replace(/^(\*\*\/)*/, '');
|
||||
const regex = makeRe(indicator, { fastpaths: false, noglobstar: false, bash: true });
|
||||
const recursive = glob.includes('**') || glob.split('/').length > 2;
|
||||
const regex = makeRe(glob, { fastpaths: false, noglobstar: false, bash: false });
|
||||
const { source } = regex;
|
||||
|
||||
if (source.startsWith('^')) {
|
||||
// prepended '^' char causes webpack require.context to fail
|
||||
const match = source.substring(1);
|
||||
// webpack's require.context matches against paths starting `./`
|
||||
// Globs starting `**` require special treatment due to the regex they
|
||||
// produce, specifically a negative look-ahead
|
||||
const match = ['^\\.', glob.startsWith('**') ? '' : '\\/', source.substring(1)].join('');
|
||||
|
||||
return { path: base, recursive, match };
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user