( match: BuildMatch, envConfigs: EnvConfigs, workPath: string )
| 169 | } |
| 170 | |
| 171 | async function createBuildProcess( |
| 172 | match: BuildMatch, |
| 173 | envConfigs: EnvConfigs, |
| 174 | workPath: string |
| 175 | ): Promise<ChildProcess> { |
| 176 | output.debug(`Creating build process for "${match.entrypoint}"`); |
| 177 | |
| 178 | const builderWorkerPath = join(__dirname, 'builder-worker.cjs'); |
| 179 | |
| 180 | // Ensure that `node` is in the builder's `PATH` |
| 181 | const PATH = `${dirname(process.execPath)}${delimiter}${process.env.PATH}`; |
| 182 | |
| 183 | const env: Env = { |
| 184 | ...process.env, |
| 185 | PATH, |
| 186 | ...envConfigs.allEnv, |
| 187 | }; |
| 188 | |
| 189 | const buildProcess = fork(builderWorkerPath, [], { |
| 190 | cwd: workPath, |
| 191 | execArgv: [], |
| 192 | env, |
| 193 | }); |
| 194 | match.buildProcess = buildProcess; |
| 195 | |
| 196 | buildProcess.on('close', (code, signal) => { |
| 197 | output.debug( |
| 198 | `Build process for "${match.entrypoint}" exited with ${signal || code}` |
| 199 | ); |
| 200 | match.buildProcess = undefined; |
| 201 | }); |
| 202 | |
| 203 | return new Promise((resolve, reject) => { |
| 204 | // The first message that the builder process sends is the `ready` event |
| 205 | buildProcess.once('message', data => { |
| 206 | if ( |
| 207 | data !== null && |
| 208 | typeof data === 'object' && |
| 209 | (data as { type: string }).type !== 'ready' |
| 210 | ) { |
| 211 | reject(new Error('Did not get "ready" event from builder')); |
| 212 | } else { |
| 213 | resolve(buildProcess); |
| 214 | } |
| 215 | }); |
| 216 | }); |
| 217 | } |
| 218 | |
| 219 | export async function executeBuild( |
| 220 | vercelConfig: VercelConfig, |
no test coverage detected