(options: Options)
| 3 | import { settlePromise } from './promises.js'; |
| 4 | |
| 5 | export async function importModule<T = unknown>(options: Options): Promise<T> { |
| 6 | const resolvedStats = await settlePromise(stat(options.filepath)); |
| 7 | if (resolvedStats.status === 'rejected') { |
| 8 | throw new Error(`File '${options.filepath}' does not exist`); |
| 9 | } |
| 10 | if (!resolvedStats.value.isFile()) { |
| 11 | throw new Error(`Expected '${options.filepath}' to be a file`); |
| 12 | } |
| 13 | |
| 14 | const { mod } = await bundleRequire<object>({ |
| 15 | format: 'esm', |
| 16 | ...options, |
| 17 | }); |
| 18 | |
| 19 | if (typeof mod === 'object' && 'default' in mod) { |
| 20 | return mod.default as T; |
| 21 | } |
| 22 | return mod as T; |
| 23 | } |
no test coverage detected