( transform: string | Function | undefined, )
| 38 | * @returns The loaded function, or the original value if not a file:// reference |
| 39 | */ |
| 40 | export async function loadTransformModule( |
| 41 | transform: string | Function | undefined, |
| 42 | ): Promise<string | Function | undefined> { |
| 43 | if (!transform) { |
| 44 | return transform; |
| 45 | } |
| 46 | if (typeof transform === 'function') { |
| 47 | return transform; |
| 48 | } |
| 49 | if (typeof transform === 'string' && transform.startsWith('file://')) { |
| 50 | const { filename, functionName } = parseFileTransformReference(transform); |
| 51 | const requiredModule = await importModule( |
| 52 | path.resolve(cliState.basePath || '', filename), |
| 53 | functionName, |
| 54 | ); |
| 55 | if (typeof requiredModule === 'function') { |
| 56 | return requiredModule; |
| 57 | } |
| 58 | throw new Error( |
| 59 | `Transform module malformed: ${filename} must export a function or have a default export as a function`, |
| 60 | ); |
| 61 | } |
| 62 | return transform; |
| 63 | } |
no test coverage detected
searching dependent graphs…