* Retrieves a transform function from a file, supporting both JavaScript and Python. * @param filePath - The path to the file, including the 'file://' prefix. * @returns A Promise resolving to the requested function. * @throws Error if the file format is unsupported.
(filePath: string)
| 113 | * @throws Error if the file format is unsupported. |
| 114 | */ |
| 115 | async function getFileTransformFunction(filePath: string): Promise<Function> { |
| 116 | const [actualFilePath, functionName] = parseFilePathAndFunctionName( |
| 117 | filePath.slice('file://'.length), |
| 118 | ); |
| 119 | |
| 120 | const fullPath = safeJoin(cliState.basePath || '', actualFilePath); |
| 121 | |
| 122 | if (isJavascriptFile(fullPath)) { |
| 123 | return getJavascriptTransformFunction(fullPath, functionName); |
| 124 | } else if (fullPath.endsWith('.py')) { |
| 125 | return getPythonTransformFunction(fullPath, functionName); |
| 126 | } |
| 127 | throw new Error(`Unsupported transform file format: file://${actualFilePath}`); |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * Creates a function from inline JavaScript code. |
no test coverage detected
searching dependent graphs…