(build)
| 467 | { |
| 468 | name: "trigger.dev v3", |
| 469 | setup(build) { |
| 470 | build.onEnd(async (result) => { |
| 471 | if (result.errors.length > 0) return; |
| 472 | if (!result || !result.outputFiles) { |
| 473 | logger.error("Build failed: no result"); |
| 474 | return; |
| 475 | } |
| 476 | |
| 477 | if (!firstBuild) { |
| 478 | logger.log(chalkGrey("○ Building background worker…")); |
| 479 | } |
| 480 | |
| 481 | const metaOutputKey = join("out", `stdin.js`).replace(/\\/g, "/"); |
| 482 | |
| 483 | const metaOutput = result.metafile!.outputs[metaOutputKey]; |
| 484 | |
| 485 | if (!metaOutput) { |
| 486 | throw new Error(`Could not find metafile`); |
| 487 | } |
| 488 | |
| 489 | const outputFileKey = join(config.projectDir, metaOutputKey); |
| 490 | const outputFile = result.outputFiles.find((file) => file.path === outputFileKey); |
| 491 | |
| 492 | if (!outputFile) { |
| 493 | throw new Error( |
| 494 | `Could not find output file for entry point ${metaOutput.entryPoint}` |
| 495 | ); |
| 496 | } |
| 497 | |
| 498 | const sourceMapFileKey = join(config.projectDir, `${metaOutputKey}.map`); |
| 499 | const sourceMapFile = result.outputFiles.find( |
| 500 | (file) => file.path === sourceMapFileKey |
| 501 | ); |
| 502 | |
| 503 | const md5Hasher = createHash("md5"); |
| 504 | md5Hasher.update(Buffer.from(outputFile.contents.buffer)); |
| 505 | |
| 506 | const contentHash = md5Hasher.digest("hex"); |
| 507 | |
| 508 | if (latestWorkerContentHash === contentHash) { |
| 509 | logger.log(chalkGrey("○ No changes detected, skipping build…")); |
| 510 | |
| 511 | return; |
| 512 | } |
| 513 | |
| 514 | // Create a file at join(dir, ".trigger", path) with the fileContents |
| 515 | const fullPath = join(config.projectDir, ".trigger", `${contentHash}.js`); |
| 516 | const sourceMapPath = `${fullPath}.map`; |
| 517 | |
| 518 | const outputFileWithSourceMap = `${ |
| 519 | outputFile.text |
| 520 | }\n//# sourceMappingURL=${basename(sourceMapPath)}`; |
| 521 | |
| 522 | await fs.promises.mkdir(dirname(fullPath), { recursive: true }); |
| 523 | await fs.promises.writeFile(fullPath, outputFileWithSourceMap); |
| 524 | |
| 525 | logger.debug(`Wrote background worker to ${fullPath}`); |
| 526 |
nothing calls this directly
no test coverage detected
searching dependent graphs…