Skip to content

Commit

Permalink
Merge pull request #15775 from lkuechler/fix-glob-pattern-detection
Browse files Browse the repository at this point in the history
Core: Fix main.js glob resolution for direct paths in stories
  • Loading branch information
shilman committed Aug 7, 2021
2 parents c3c131d + e54a662 commit 1143d69
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions lib/core-common/src/utils/__tests__/to-require-context.test.ts
Expand Up @@ -142,6 +142,23 @@ const testCases = [
'../src/stories/components/Icon/Icon.mdx',
],
},
{
glob: '../src/stories/components/Icon.stories.js',
recursive: false,
validPaths: ['../src/stories/components/Icon.stories.js'],
invalidPaths: [
'../src/Icon.stories.mdx',
'../src/stories/components/Icon.stories/Icon.stories.mdx',
'../src/stories/components/Icon/Icon.mdx',
'../src/stories/components/Icon/Icon.stories.js',
'../src/stories/components/Icon/Icon.stories.ts',
'../src/stories/Icon.stories.js',
'../src/stories/Icon.stories.mdx',
'./Icon.stories.js',
'./src/stories/Icon.stories.js',
'./stories.js',
],
},
// DUMB GLOB
{
glob: '../src/stories/**/*.stories.[tj]sx',
Expand Down
2 changes: 1 addition & 1 deletion lib/core-common/src/utils/to-require-context.ts
Expand Up @@ -33,7 +33,7 @@ export const toRequireContext = (input: any) => {
const base = globResult.isGlob
? globResult.prefix + globResult.base
: path.dirname(fixedInput);
const globFallback = base !== '.' ? fixedInput.substr(base.length) : fixedInput;
const globFallback = base !== '.' ? fixedInput.substr(base.length + 1) : fixedInput;
const glob = globResult.isGlob ? globResult.glob : globFallback;

const regex = makeRe(glob, {
Expand Down

0 comments on commit 1143d69

Please sign in to comment.