|
1
|
import { isFileDisabled, MEDUSA_SKIP_FILE } from "./define-file-config" |
|
2
|
import { resolveExports } from "./resolve-exports" |
|
3
|
|
|
4
|
/** |
|
5
|
* Utility that should be used instead of either await import() or require() |
|
6
|
* to avoid bundling issues. That way we have a single place |
|
7
|
* where we manage the strategy to dynamically import a module. |
|
8
|
* |
|
9
|
* This issue arise from migration to Node16 or NodeNext module resolution as well |
|
10
|
* as ts-node not being maintained anymore and throwing deprecation warnings. |
|
11
|
* all over the place. |
|
12
|
* |
|
13
|
* @param path |
|
14
|
*/ |
|
15
|
export async function dynamicImport(path: string): Promise<any> { |
|
16
|
const module = require(path) |
|
17
|
|
|
18
|
const exported = resolveExports(module) |
|
19
|
|
|
20
|
if (isFileDisabled(path)) { |
|
21
|
exported[MEDUSA_SKIP_FILE] = true |
|
22
|
} |
|
23
|
|
|
24
|
return exported |
|
25
|
} |