| 425 | } |
| 426 | |
| 427 | class HarnessBuilderContext implements BuilderContext { |
| 428 | id = Math.trunc(Math.random() * 1000000); |
| 429 | logger = new logging.Logger(`builder-harness-${this.id}`); |
| 430 | workspaceRoot: string; |
| 431 | currentDirectory: string; |
| 432 | target?: Target; |
| 433 | |
| 434 | teardowns: (() => Promise<void> | void)[] = []; |
| 435 | |
| 436 | constructor( |
| 437 | public builder: BuilderInfo, |
| 438 | basePath: string, |
| 439 | private readonly contextHost: ContextHost, |
| 440 | public readonly signal: AbortSignal | undefined, |
| 441 | public readonly watcherFactory: BuilderWatcherFactory | undefined, |
| 442 | ) { |
| 443 | this.workspaceRoot = this.currentDirectory = basePath; |
| 444 | } |
| 445 | |
| 446 | addTeardown(teardown: () => Promise<void> | void): void { |
| 447 | this.teardowns.push(teardown); |
| 448 | } |
| 449 | |
| 450 | async getBuilderNameForTarget(target: Target): Promise<string> { |
| 451 | return this.contextHost.getBuilderName(target.project, target.target); |
| 452 | } |
| 453 | |
| 454 | async getProjectMetadata(targetOrName: Target | string): Promise<json.JsonObject> { |
| 455 | const project = typeof targetOrName === 'string' ? targetOrName : targetOrName.project; |
| 456 | |
| 457 | return this.contextHost.getMetadata(project); |
| 458 | } |
| 459 | |
| 460 | async getTargetOptions(target: Target): Promise<json.JsonObject> { |
| 461 | return this.contextHost.getOptions(target.project, target.target, target.configuration); |
| 462 | } |
| 463 | |
| 464 | // Unused by builders in this package |
| 465 | async scheduleBuilder( |
| 466 | builderName: string, |
| 467 | options?: json.JsonObject, |
| 468 | scheduleOptions?: ScheduleOptions, |
| 469 | ): Promise<BuilderRun> { |
| 470 | throw new Error('Not Implemented.'); |
| 471 | } |
| 472 | |
| 473 | async scheduleTarget( |
| 474 | target: Target, |
| 475 | overrides?: json.JsonObject, |
| 476 | scheduleOptions?: ScheduleOptions, |
| 477 | ): Promise<BuilderRun> { |
| 478 | const { info, handler } = await this.contextHost.findBuilderByTarget( |
| 479 | target.project, |
| 480 | target.target, |
| 481 | ); |
| 482 | const targetOptions = await this.validateOptions( |
| 483 | { |
| 484 | ...(await this.getTargetOptions(target)), |