-
-
Notifications
You must be signed in to change notification settings - Fork 590
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(commonjs): support dynamic require (#206)
* Implemented support for dynamic requires (transferred PR) Moved from rollup/rollup-plugin-commonjs#331 * Only add dynamic loader code when dynamic feature is enabled * test(commonjs): update snapshots for easier diffing * Automatically remove user paths * test(commonjs): Prepare tests to support code-splitting * test(commonjs): Try to add a code-splitting test * Fixed code-splitting support * Cleanup: avoid importing commonjs-proxy when we only need to register * Fixed test * Updated pnpm-lock * Updated snapshots * Satisfy linter Co-authored-by: Lukas Taegert-Atkinson <lukas.taegert-atkinson@tngtech.com>
- Loading branch information
1 parent
1bee4e9
commit cbc341d
Showing
83 changed files
with
3,900 additions
and
748 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { statSync } from 'fs'; | ||
import glob from 'glob'; | ||
import { resolve } from 'path'; | ||
import { normalizePathSlashes } from './transform'; | ||
|
||
export default function getDynamicRequirePaths(patterns) { | ||
const dynamicRequireModuleSet = new Set(); | ||
for (const pattern of (!patterns || Array.isArray(patterns)) ? patterns || [] : [patterns]) { | ||
const isNegated = pattern.startsWith('!'); | ||
const modifySet = Set.prototype[isNegated ? 'delete' : 'add'].bind( | ||
dynamicRequireModuleSet | ||
); | ||
for (const path of glob.sync(isNegated ? pattern.substr(1) : pattern)) { | ||
modifySet(normalizePathSlashes(resolve(path))); | ||
} | ||
} | ||
const dynamicRequireModuleDirPaths = Array.from(dynamicRequireModuleSet.values()).filter(path => { | ||
try { | ||
if (statSync(path).isDirectory()) | ||
return true; | ||
} catch (ignored) { | ||
// Nothing to do here | ||
} | ||
return false; | ||
}); | ||
return { dynamicRequireModuleSet, dynamicRequireModuleDirPaths }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.