| 26 | } |
| 27 | |
| 28 | export class MultiProjectRuntime implements Runtime { |
| 29 | readonly createFlags?: RuntimeCreateFlags; |
| 30 | readonly finalizeConfig?: ( |
| 31 | finalBranchName: string, |
| 32 | config: RuntimeConfig |
| 33 | ) => Promise<Result<RuntimeConfig, string>>; |
| 34 | readonly validateBeforePersist?: ( |
| 35 | finalBranchName: string, |
| 36 | config: RuntimeConfig |
| 37 | ) => Promise<Result<void, string>>; |
| 38 | readonly postCreateSetup?: (params: WorkspaceInitParams) => Promise<void>; |
| 39 | |
| 40 | public envResolver?: (projectPath: string) => Promise<Record<string, string> | undefined>; |
| 41 | |
| 42 | private readonly primaryRuntime: Runtime; |
| 43 | private readonly containerPath: string; |
| 44 | |
| 45 | constructor( |
| 46 | private readonly containerManager: ContainerManager, |
| 47 | private readonly projectRuntimes: MultiProjectRuntimeEntry[], |
| 48 | workspaceName: string |
| 49 | ) { |
| 50 | assert(projectRuntimes.length > 0, "MultiProjectRuntime requires at least one project runtime"); |
| 51 | |
| 52 | this.primaryRuntime = projectRuntimes[0].runtime; |
| 53 | this.containerPath = containerManager.getContainerPath(workspaceName); |
| 54 | this.createFlags = this.primaryRuntime.createFlags; |
| 55 | |
| 56 | this.finalizeConfig = this.primaryRuntime.finalizeConfig?.bind(this.primaryRuntime); |
| 57 | this.validateBeforePersist = this.primaryRuntime.validateBeforePersist?.bind( |
| 58 | this.primaryRuntime |
| 59 | ); |
| 60 | this.postCreateSetup = this.primaryRuntime.postCreateSetup?.bind(this.primaryRuntime); |
| 61 | } |
| 62 | |
| 63 | async ensureReady(options?: EnsureReadyOptions): Promise<EnsureReadyResult> { |
| 64 | for (const projectRuntime of this.projectRuntimes) { |
| 65 | const readyResult = await projectRuntime.runtime.ensureReady(options); |
| 66 | if (!readyResult.ready) { |
| 67 | return readyResult; |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | return { ready: true }; |
| 72 | } |
| 73 | |
| 74 | async createWorkspace(params: WorkspaceCreationParams): Promise<WorkspaceCreationResult> { |
| 75 | const workspaceName = params.directoryName; |
| 76 | const createdRuntimes: MultiProjectRuntimeEntry[] = []; |
| 77 | const projectWorkspaces: ProjectWorkspaceEntry[] = []; |
| 78 | |
| 79 | for (const projectRuntime of this.projectRuntimes) { |
| 80 | const createResult = await projectRuntime.runtime.createWorkspace({ |
| 81 | ...params, |
| 82 | projectPath: projectRuntime.projectPath, |
| 83 | }); |
| 84 | |
| 85 | if (!createResult.success) { |
nothing calls this directly
no outgoing calls
no test coverage detected