(rawCustomFunctionModulePath: string)
| 41 | } |
| 42 | |
| 43 | export function createCustomFunctionCall(rawCustomFunctionModulePath: string): BuildStepFunction { |
| 44 | return async (ctx, { env, inputs, outputs }) => { |
| 45 | let customFunctionModulePath = rawCustomFunctionModulePath; |
| 46 | if (!(await fs.exists(ctx.global.projectSourceDirectory))) { |
| 47 | const relative = path.relative( |
| 48 | path.resolve(ctx.global.projectSourceDirectory), |
| 49 | customFunctionModulePath |
| 50 | ); |
| 51 | customFunctionModulePath = path.resolve( |
| 52 | path.join(ctx.global.projectTargetDirectory, relative) |
| 53 | ); |
| 54 | } |
| 55 | const serializedArguments: SerializedCustomBuildFunctionArguments = { |
| 56 | env, |
| 57 | inputs: serializeInputs(inputs), |
| 58 | outputs: Object.fromEntries( |
| 59 | Object.entries(outputs).map(([id, output]) => [id, output.serialize()]) |
| 60 | ), |
| 61 | ctx: ctx.serialize(), |
| 62 | }; |
| 63 | try { |
| 64 | await spawnAsync( |
| 65 | 'node', |
| 66 | [ |
| 67 | path.join(SCRIPTS_PATH, 'runCustomFunction.js'), |
| 68 | customFunctionModulePath, |
| 69 | JSON.stringify(serializedArguments), |
| 70 | ], |
| 71 | { |
| 72 | logger: ctx.logger, |
| 73 | cwd: ctx.workingDirectory, |
| 74 | env, |
| 75 | stdio: 'pipe', |
| 76 | } |
| 77 | ); |
| 78 | } catch { |
| 79 | throw new Error(`Custom function exited with non-zero exit code.`); |
| 80 | } |
| 81 | }; |
| 82 | } |
no test coverage detected
searching dependent graphs…