@expofp/utils 3.28.2 → 3.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -2,7 +2,15 @@ export async function importNodeModule(moduleName) {
|
|
|
2
2
|
if (typeof process === 'undefined' || !process.versions?.node) {
|
|
3
3
|
throw new Error('importNodeModule can only be used in Node.js environments');
|
|
4
4
|
}
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
try {
|
|
6
|
+
// prevents every bundler (Vite, Rollup, webpack alike) from analyzing the specifier
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-implied-eval, @typescript-eslint/no-unsafe-call
|
|
8
|
+
return (await new Function('moduleName', 'return import(moduleName)')(moduleName));
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
// A `new Function` scope has no dynamic-import callback under module
|
|
12
|
+
// runners like vitest's — fall back to a literal import, hidden from
|
|
13
|
+
// bundlers by the magic comments instead.
|
|
14
|
+
return (await import(/* @vite-ignore */ /* webpackIgnore: true */ moduleName));
|
|
15
|
+
}
|
|
8
16
|
}
|