MCPcopy Index your code
hub / github.com/rollup/plugins / getDynamicRequireModules

Function getDynamicRequireModules

packages/commonjs/src/dynamic-modules.js:35–69  ·  view source on GitHub ↗
(patterns, dynamicRequireRoot)

Source from the content-addressed store, hash-verified

33}
34
35export 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
71const 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

Callers 1

commonjsFunction · 0.90

Calls 5

normalizePathSlashesFunction · 0.90
isDirectoryFunction · 0.85
getPackageEntryPointFunction · 0.85
modifyMapFunction · 0.85
resolveFunction · 0.50

Tested by

no test coverage detected