Skip to content

Commit

Permalink
Merge pull request #15399 from lkuechler/remove-glob-base-dependency
Browse files Browse the repository at this point in the history
remove glob-base dependency
  • Loading branch information
shilman committed Jul 23, 2021
2 parents c1befe4 + 852174e commit 9f676f7
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 51 deletions.
2 changes: 0 additions & 2 deletions lib/core-common/package.json
Expand Up @@ -63,7 +63,6 @@
"@babel/register": "^7.12.1",
"@storybook/node-logger": "6.4.0-alpha.19",
"@storybook/semver": "^7.3.2",
"@types/glob-base": "^0.3.0",
"@types/micromatch": "^4.0.1",
"@types/node": "^14.0.10",
"@types/pretty-hrtime": "^1.0.0",
Expand All @@ -77,7 +76,6 @@
"find-up": "^5.0.0",
"fork-ts-checker-webpack-plugin": "^6.0.4",
"glob": "^7.1.6",
"glob-base": "^0.3.0",
"interpret": "^2.2.0",
"json5": "^2.1.3",
"lazy-universal-dotenv": "^3.0.1",
Expand Down
35 changes: 35 additions & 0 deletions lib/core-common/src/utils/__tests__/to-require-context.test.ts
Expand Up @@ -21,6 +21,41 @@ const testCases = [
'./src/components/Icon.stories.js',
],
},
{
glob: 'src',
recursive: false,
validPaths: [],
invalidPaths: [
'./Icon.stories.tsx',
'./src/Icon.stories.tsx',
'./src/components/Icon.stories.tsx',
'./src/components/Icon.stories/Icon.stories.tsx',
'./stories.tsx',
'./Icon.stories.ts',
'./Icon.stories.js',
'./src/components/stories.tsx',
'./src/components/Icon.stories/stories.tsx',
'./src/components/Icon.stories.ts',
'./src/components/Icon.stories.js',
],
},
{
glob: 'src/*',
recursive: false,
validPaths: ['./src/Icon.stories.tsx'],
invalidPaths: [
'./Icon.stories.tsx',
'./src/components/Icon.stories.tsx',
'./src/components/Icon.stories/Icon.stories.tsx',
'./stories.tsx',
'./Icon.stories.ts',
'./Icon.stories.js',
'./src/components/stories.tsx',
'./src/components/Icon.stories/stories.tsx',
'./src/components/Icon.stories.ts',
'./src/components/Icon.stories.js',
],
},
// INVALID GLOB
{
glob: '../src/stories/**/*.stories.(js|mdx)',
Expand Down
19 changes: 14 additions & 5 deletions lib/core-common/src/utils/to-require-context.ts
@@ -1,7 +1,7 @@
import globBase from 'glob-base';
import { makeRe } from 'micromatch';
import { makeRe, scan } from 'micromatch';
import deprecate from 'util-deprecate';
import dedent from 'ts-dedent';
import path from 'path';

// LEGACY support for bad glob patterns we had in SB 5 - remove in SB7
const fixBadGlob = deprecate(
Expand Down Expand Up @@ -29,17 +29,26 @@ export const toRequireContext = (input: any) => {
const fixedInput = detectBadGlob(input);
switch (true) {
case typeof input === 'string': {
const { base, glob } = globBase(fixedInput);
const globResult = scan(fixedInput);
const base = globResult.isGlob
? globResult.prefix + globResult.base
: path.dirname(fixedInput);
const globFallback = base !== '.' ? fixedInput.substr(base.length) : fixedInput;
const glob = globResult.isGlob ? globResult.glob : globFallback;

const recursive = glob.includes('**') || glob.split('/').length > 1;
const regex = makeRe(glob, { fastpaths: false, noglobstar: false, bash: false });
const regex = makeRe(glob, {
fastpaths: false,
noglobstar: false,
bash: false,
});
const { source } = regex;

if (source.startsWith('^')) {
// 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('');
const recursive = glob.includes('**') || glob.split('/').length > 1;

return { path: base, recursive, match };
}
Expand Down
44 changes: 0 additions & 44 deletions yarn.lock
Expand Up @@ -6652,7 +6652,6 @@ __metadata:
"@storybook/node-logger": 6.4.0-alpha.19
"@storybook/react-docgen-typescript-plugin": 1.0.2-canary.253f8c1.0
"@storybook/semver": ^7.3.2
"@types/glob-base": ^0.3.0
"@types/interpret": ^1.1.1
"@types/micromatch": ^4.0.1
"@types/mock-fs": ^4.13.0
Expand All @@ -6668,7 +6667,6 @@ __metadata:
find-up: ^5.0.0
fork-ts-checker-webpack-plugin: ^6.0.4
glob: ^7.1.6
glob-base: ^0.3.0
interpret: ^2.2.0
json5: ^2.1.3
lazy-universal-dotenv: ^3.0.1
Expand Down Expand Up @@ -8480,13 +8478,6 @@ __metadata:
languageName: node
linkType: hard

"@types/glob-base@npm:^0.3.0":
version: 0.3.0
resolution: "@types/glob-base@npm:0.3.0"
checksum: 2c0cb3b7bb7c8661b9421194c0fd90a36e1c786a4124375749df9dc1dd8ade536c8eb2ac93b217db24ed3a427755def9a54bc86c2b6bf64a81fb82e7e6f44cc7
languageName: node
linkType: hard

"@types/glob@npm:*, @types/glob@npm:^7.1.1, @types/glob@npm:^7.1.3":
version: 7.1.3
resolution: "@types/glob@npm:7.1.3"
Expand Down Expand Up @@ -22554,25 +22545,6 @@ fsevents@^1.2.7:
languageName: node
linkType: hard

"glob-base@npm:^0.3.0":
version: 0.3.0
resolution: "glob-base@npm:0.3.0"
dependencies:
glob-parent: ^2.0.0
is-glob: ^2.0.0
checksum: 4ce785c1dac2ff1e4660c010fa43ed2f1b38993dfd004023a3e7080b20bc61f29fbfe5d265b7e64cc84096ecf44e8ca876c7c1aad8f1f995d4c0f33034f3ae8c
languageName: node
linkType: hard

"glob-parent@npm:^2.0.0":
version: 2.0.0
resolution: "glob-parent@npm:2.0.0"
dependencies:
is-glob: ^2.0.0
checksum: b9d59dc532d47aaaa4841046ff631b325a707f738445300b83b7a1ee603dd060c041a378e8a195c887d479bb703685cee4725c8f54b8dacef65355375f57d32a
languageName: node
linkType: hard

"glob-parent@npm:^3.1.0":
version: 3.1.0
resolution: "glob-parent@npm:3.1.0"
Expand Down Expand Up @@ -24975,13 +24947,6 @@ fsevents@^1.2.7:
languageName: node
linkType: hard

"is-extglob@npm:^1.0.0":
version: 1.0.0
resolution: "is-extglob@npm:1.0.0"
checksum: 1ce5366d19958f36069a45ca996c1e51ab607f42a01eb0505f0ccffe8f9c91f5bcba6e971605efd8b4d4dfd0111afa3c8df3e1746db5b85b9a8f933f5e7286b7
languageName: node
linkType: hard

"is-extglob@npm:^2.1.0, is-extglob@npm:^2.1.1":
version: 2.1.1
resolution: "is-extglob@npm:2.1.1"
Expand Down Expand Up @@ -25040,15 +25005,6 @@ fsevents@^1.2.7:
languageName: node
linkType: hard

"is-glob@npm:^2.0.0":
version: 2.0.1
resolution: "is-glob@npm:2.0.1"
dependencies:
is-extglob: ^1.0.0
checksum: ef156806af0924983325c9218a8b8a838fa50e1a104ed2a11fe94829a5b27c1b05a4c8cf98d96cb3a7fea539c21f14ae2081e1a248f3d5a9eea62f2d4e9f8b0c
languageName: node
linkType: hard

"is-glob@npm:^3.0.0, is-glob@npm:^3.1.0":
version: 3.1.0
resolution: "is-glob@npm:3.1.0"
Expand Down

0 comments on commit 9f676f7

Please sign in to comment.