(patterns, dynamicRequireRoot)
| 33 | } |
| 34 | |
| 35 | export function getDynamicRequireModules(patterns, dynamicRequireRoot) { |
| 36 | const dynamicRequireModules = new Map(); |
| 37 | const dirNames = new Set(); |
| 38 | for (const pattern of !patterns || Array.isArray(patterns) ? patterns || [] : [patterns]) { |
| 39 | const isNegated = pattern.startsWith('!'); |
| 40 | const modifyMap = (targetPath, resolvedPath) => |
| 41 | isNegated |
| 42 | ? dynamicRequireModules.delete(targetPath) |
| 43 | : dynamicRequireModules.set(targetPath, resolvedPath); |
| 44 | // eslint-disable-next-line new-cap |
| 45 | for (const path of new fdir() |
| 46 | .withBasePath() |
| 47 | .withDirs() |
| 48 | .glob(isNegated ? pattern.substr(1) : pattern) |
| 49 | .crawl(relative('.', dynamicRequireRoot)) |
| 50 | .sync() |
| 51 | .sort((a, b) => a.localeCompare(b, 'en'))) { |
| 52 | const resolvedPath = resolve(path); |
| 53 | const requirePath = normalizePathSlashes(resolvedPath); |
| 54 | if (isDirectory(resolvedPath)) { |
| 55 | dirNames.add(resolvedPath); |
| 56 | const modulePath = resolve(join(resolvedPath, getPackageEntryPoint(path))); |
| 57 | modifyMap(requirePath, modulePath); |
| 58 | modifyMap(normalizePathSlashes(modulePath), modulePath); |
| 59 | } else { |
| 60 | dirNames.add(dirname(resolvedPath)); |
| 61 | modifyMap(requirePath, resolvedPath); |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | return { |
| 66 | commonDir: dirNames.size ? getCommonDir([...dirNames, dynamicRequireRoot]) : null, |
| 67 | dynamicRequireModules |
| 68 | }; |
| 69 | } |
| 70 | |
| 71 | const FAILED_REQUIRE_ERROR = `throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');`; |
| 72 |
no test coverage detected