()
| 385 | let firstBuild = true; |
| 386 | |
| 387 | async function runBuild() { |
| 388 | if (ctx) { |
| 389 | // This will stop the watching |
| 390 | await ctx.dispose(); |
| 391 | } |
| 392 | |
| 393 | let latestWorkerContentHash: string | undefined; |
| 394 | |
| 395 | const taskFiles = await gatherTaskFiles(config); |
| 396 | |
| 397 | const workerFacadePath = join(cliRootPath(), "workers", "dev", "worker-facade.js"); |
| 398 | const workerFacade = readFileSync(workerFacadePath, "utf-8"); |
| 399 | |
| 400 | const workerSetupPath = join(cliRootPath(), "workers", "dev", "worker-setup.js"); |
| 401 | |
| 402 | let entryPointContents = workerFacade |
| 403 | .replace("__TASKS__", createTaskFileImports(taskFiles)) |
| 404 | .replace( |
| 405 | "__WORKER_SETUP__", |
| 406 | `import { tracingSDK, otelTracer, otelLogger, sender } from "${escapeImportPath( |
| 407 | workerSetupPath |
| 408 | )}";` |
| 409 | ); |
| 410 | |
| 411 | if (configPath) { |
| 412 | configPath = normalize(configPath); |
| 413 | logger.debug("Importing project config from", { configPath }); |
| 414 | |
| 415 | entryPointContents = entryPointContents.replace( |
| 416 | "__IMPORTED_PROJECT_CONFIG__", |
| 417 | `import * as importedConfigExports from "${escapeImportPath( |
| 418 | configPath |
| 419 | )}"; const importedConfig = importedConfigExports.config; const handleError = importedConfigExports.handleError;` |
| 420 | ); |
| 421 | } else { |
| 422 | entryPointContents = entryPointContents.replace( |
| 423 | "__IMPORTED_PROJECT_CONFIG__", |
| 424 | `const importedConfig = undefined; const handleError = undefined;` |
| 425 | ); |
| 426 | } |
| 427 | |
| 428 | logger.log(chalkGrey("○ Building background worker…")); |
| 429 | |
| 430 | ctx = await context({ |
| 431 | stdin: { |
| 432 | contents: entryPointContents, |
| 433 | resolveDir: process.cwd(), |
| 434 | sourcefile: "__entryPoint.ts", |
| 435 | }, |
| 436 | banner: { |
| 437 | js: `process.on("uncaughtException", function(error, origin) { if (error instanceof Error) { process.send && process.send({ type: "UNCAUGHT_EXCEPTION", payload: { error: { name: error.name, message: error.message, stack: error.stack }, origin }, version: "v1" }); } else { process.send && process.send({ type: "UNCAUGHT_EXCEPTION", payload: { error: { name: "Error", message: typeof error === "string" ? error : JSON.stringify(error) }, origin }, version: "v1" }); } });`, |
| 438 | }, |
| 439 | bundle: true, |
| 440 | metafile: true, |
| 441 | write: false, |
| 442 | minify: false, |
| 443 | sourcemap: "external", // does not set the //# sourceMappingURL= comment in the file, we handle it ourselves |
| 444 | logLevel: "error", |
nothing calls this directly
no test coverage detected
searching dependent graphs…