* Resolve an extensionless entrypoint to an actual file path. * Tries common JS extensions in order, returning the first match.
(name)
| 53 | * Tries common JS extensions in order, returning the first match. |
| 54 | */ |
| 55 | function resolveEntrypoint(name) { |
| 56 | const base = resolve('./' + name); |
| 57 | for (const ext of ['.js', '.cjs', '.mjs']) { |
| 58 | const p = base + ext; |
| 59 | if (existsSync(p)) return p; |
| 60 | } |
| 61 | // If base is a directory, look for index files inside it |
| 62 | if (existsSync(base)) { |
| 63 | for (const ext of ['.js', '.cjs', '.mjs']) { |
| 64 | const p = resolve(base, 'index' + ext); |
| 65 | if (existsSync(p)) return p; |
| 66 | } |
| 67 | } |
| 68 | return null; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Load a module via dynamic import(). Works for both CJS and ESM regardless |
no test coverage detected