diff --git a/lib/core-common/package.json b/lib/core-common/package.json index aec7d8edbbad..2418de6cf9f8 100644 --- a/lib/core-common/package.json +++ b/lib/core-common/package.json @@ -63,7 +63,6 @@ "@babel/register": "^7.12.1", "@storybook/node-logger": "6.4.0-alpha.4", "@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", @@ -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", diff --git a/lib/core-common/src/utils/to-require-context.ts b/lib/core-common/src/utils/to-require-context.ts index f8f4976d67f0..179f4eb5754c 100644 --- a/lib/core-common/src/utils/to-require-context.ts +++ b/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( @@ -25,14 +25,25 @@ const detectBadGlob = (val: string) => { const isObject = (val: Record) => val != null && typeof val === 'object' && Array.isArray(val) === false; +const dirname = (pattern: string) => { + if (pattern.slice(-1) === '/') return pattern; + return path.dirname(pattern); +}; + 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.base : 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('^')) { @@ -40,6 +51,7 @@ export const toRequireContext = (input: any) => { // 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 }; } diff --git a/yarn.lock b/yarn.lock index 9f67b32a8649..c839d09e55e1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6729,7 +6729,6 @@ __metadata: "@storybook/node-logger": 6.4.0-alpha.4 "@storybook/react-docgen-typescript-plugin": 1.0.2-canary.3c70e01.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 @@ -6745,7 +6744,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 @@ -8595,13 +8593,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" @@ -22668,25 +22659,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" @@ -25089,13 +25061,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" @@ -25154,15 +25119,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"