MCPcopy Create free account
hub / github.com/code-pushup/cli / importModule

Function importModule

packages/utils/src/lib/import-module.ts:5–23  ·  view source on GitHub ↗
(options: Options)

Source from the content-addressed store, hash-verified

3import { settlePromise } from './promises.js';
4
5export 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}

Callers 2

readRcByPathFunction · 0.90

Calls 1

settlePromiseFunction · 0.85

Tested by

no test coverage detected