@ebay-dt/bonfire-node 0.2.0-alpha.0 → 0.2.0-alpha.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/README.md +18 -5
  2. package/dist/deployment-provider.d.ts +2 -1
  3. package/dist/deployment-provider.d.ts.map +1 -1
  4. package/dist/deployment-provider.js +2 -1
  5. package/dist/deployment-provider.js.map +1 -1
  6. package/dist/duplicate.d.ts.map +1 -1
  7. package/dist/duplicate.js +103 -47
  8. package/dist/duplicate.js.map +1 -1
  9. package/dist/git-repository.d.ts +16 -1
  10. package/dist/git-repository.d.ts.map +1 -1
  11. package/dist/git-repository.js +127 -1
  12. package/dist/git-repository.js.map +1 -1
  13. package/dist/github-cli.d.ts.map +1 -1
  14. package/dist/github-cli.js +3 -1
  15. package/dist/github-cli.js.map +1 -1
  16. package/dist/index.d.ts +1 -0
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +1 -0
  19. package/dist/index.js.map +1 -1
  20. package/dist/internal/prototype-templates.d.ts +0 -1
  21. package/dist/internal/prototype-templates.d.ts.map +1 -1
  22. package/dist/internal/prototype-templates.js +0 -5
  23. package/dist/internal/prototype-templates.js.map +1 -1
  24. package/dist/lifecycle/deployment-worktree.d.ts +36 -0
  25. package/dist/lifecycle/deployment-worktree.d.ts.map +1 -0
  26. package/dist/lifecycle/deployment-worktree.js +503 -0
  27. package/dist/lifecycle/deployment-worktree.js.map +1 -0
  28. package/dist/lifecycle/local-prototype-lifecycle.d.ts +15 -1
  29. package/dist/lifecycle/local-prototype-lifecycle.d.ts.map +1 -1
  30. package/dist/lifecycle/local-prototype-lifecycle.js +738 -98
  31. package/dist/lifecycle/local-prototype-lifecycle.js.map +1 -1
  32. package/dist/lifecycle/preparation-marker.d.ts +12 -0
  33. package/dist/lifecycle/preparation-marker.d.ts.map +1 -0
  34. package/dist/lifecycle/preparation-marker.js +76 -0
  35. package/dist/lifecycle/preparation-marker.js.map +1 -0
  36. package/dist/lifecycle/prototype-path-policy.d.ts +18 -0
  37. package/dist/lifecycle/prototype-path-policy.d.ts.map +1 -0
  38. package/dist/lifecycle/prototype-path-policy.js +429 -0
  39. package/dist/lifecycle/prototype-path-policy.js.map +1 -0
  40. package/dist/lifecycle/repository-summary.d.ts +7 -1
  41. package/dist/lifecycle/repository-summary.d.ts.map +1 -1
  42. package/dist/lifecycle/repository-summary.js +20 -4
  43. package/dist/lifecycle/repository-summary.js.map +1 -1
  44. package/dist/lifecycle/repository-synchronization.d.ts +13 -8
  45. package/dist/lifecycle/repository-synchronization.d.ts.map +1 -1
  46. package/dist/lifecycle/repository-synchronization.js +680 -139
  47. package/dist/lifecycle/repository-synchronization.js.map +1 -1
  48. package/dist/lifecycle/runtime-context.d.ts +2 -0
  49. package/dist/lifecycle/runtime-context.d.ts.map +1 -1
  50. package/dist/lifecycle/runtime-context.js +5 -1
  51. package/dist/lifecycle/runtime-context.js.map +1 -1
  52. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"local-prototype-lifecycle.js","sourceRoot":"","sources":["../../src/lifecycle/local-prototype-lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,mBAAmB,EACnB,gBAAgB,EAChB,gBAAgB,EAChB,yBAAyB,EACzB,4BAA4B,EAC5B,uBAAuB,EACvB,oBAAoB,EACpB,0BAA0B,EAC1B,sBAAsB,EACtB,qBAAqB,EACrB,iBAAiB,EAajB,mBAAmB,GASpB,MAAM,uBAAuB,CA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BACF,MAAM,IAAI,GAAG,MAAM,UAAU,CAC3B,IAAI,CAAC,WAAW,EAChB,IAAI,CAAC,QAAQ,CAAC,MAAM,EACpB,MAAM,CACP,CAAC;gBAEF,OAAO;oBACL,GAAG;oBACH,GAAG,EAAE,eAAe,CAAC,GAAG,CAAC;oBACzB,YAAY,EAAE,IAAI,CAAC,YAAY;iBACE,CAAC;YACtC,CAAC,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { constants } from \"node:fs\";\nimport { lstat, open, rename, rm, writeFile } from \"node:fs/promises\";\nimport { randomUUID } from \"node:crypto\";\nimport { join, relative, sep } from \"node:path\";\nimport {\n definePrototypeRef,\n getPrototypeUrl,\n LifecycleInputError,\n lifecycleFailure,\n lifecycleSuccess,\n parseCreatePrototypeInput,\n parseDuplicatePrototypeInput,\n parseEditPrototypeInput,\n parseBonfireIdentity,\n parsePrototypeCommandInput,\n parsePrototypeMetadata,\n slugifyPrototypeTitle,\n PrototypeRefError,\n type BranchPreparationValue,\n type CreatePrototypeInput,\n type CreatePrototypeValue,\n type DeletePrototypeValue,\n type DeploymentValue,\n type DeploymentWarningCode,\n type DirtyObservationValue,\n type DiscardPrototypeValue,\n type DuplicatePrototypeInput,\n type DuplicatePrototypeValue,\n type EditPrototypeInput,\n type EditPrototypeValue,\n parseGitModeSetting,\n type GitMode,\n type LifecycleErrorCode,\n type LifecycleResult,\n type BonfireIdentity,\n type PrototypeCommandInput,\n type SavePrototypeValue,\n type RepositorySummary,\n type ThemeRegistry,\n} from \"@ebay-dt/bonfire-core\";\nimport {\n commitPath,\n discardPath,\n GitRepositoryError,\n pushBranch,\n type GitRepository,\n} from \"../git-repository.js\";\nimport { duplicatePrototype, PrototypeDuplicateError } from \"../duplicate.js\";\nimport {\n PrototypeCatalog,\n type PrototypeCatalogLike,\n} from \"../prototype-catalog.js\";\nimport { PrototypeScaffoldError, scaffoldPrototype } from \"../scaffold.js\";\nimport {\n createPrototypeLifecycleRuntime,\n type PrototypeLifecycleRuntimeContext,\n} from \"./runtime-context.js\";\nimport type {\n PreparePrototypeFiles,\n PreparePrototypeFilesRequest,\n} from \"../prepare-prototype-files.js\";\nimport {\n cleanupOwnedDestination,\n validateOwnedDestination,\n type OwnedDestinationReceipt,\n} from \"../internal/owned-destination.js\";\nimport {\n RepositoryBusyError,\n withRepositoryOperation,\n} from \"./operation-gate.js\";\nimport {\n DeploymentProviderError,\n type DeploymentProvider,\n} from \"../deployment-provider.js\";\nimport {\n assertIdentityBranchReady,\n synchronizeIdentityBranch,\n} from \"./repository-synchronization.js\";\nimport { getRepositorySummary } from \"./repository-summary.js\";\n\ntype LifecycleMethod<Input, Value> = (\n identity: BonfireIdentity,\n input: Input,\n) => Promise<LifecycleResult<Value>>;\n\nexport type PrototypeLifecycle = {\n /** Declares whether this lifecycle enforces the selected Git mode. */\n readonly gitMode?: GitMode;\n prepareBranch(\n identity: BonfireIdentity,\n ): Promise<LifecycleResult<BranchPreparationValue>>;\n create: LifecycleMethod<CreatePrototypeInput, CreatePrototypeValue>;\n duplicate: LifecycleMethod<DuplicatePrototypeInput, DuplicatePrototypeValue>;\n edit: LifecycleMethod<EditPrototypeInput, EditPrototypeValue>;\n delete: LifecycleMethod<PrototypeCommandInput, DeletePrototypeValue>;\n getDirtyState: LifecycleMethod<PrototypeCommandInput, DirtyObservationValue>;\n getRepositorySummary(\n identity: BonfireIdentity,\n ): Promise<LifecycleResult<RepositorySummary>>;\n checkRepositorySummary(\n identity: BonfireIdentity,\n ): Promise<LifecycleResult<RepositorySummary>>;\n save: LifecycleMethod<PrototypeCommandInput, SavePrototypeValue>;\n discard: LifecycleMethod<PrototypeCommandInput, DiscardPrototypeValue>;\n deploy: LifecycleMethod<PrototypeCommandInput, DeploymentValue>;\n};\n\nexport type LocalPrototypeLifecycleOptions = {\n repositoryRoot: string;\n prototypeRoot?: string;\n remote?: string;\n primaryBranch?: string;\n automaticBranchSwitch?: \"enabled\" | \"disabled\";\n gitMode?: GitMode;\n commitIdentity?: {\n name: string;\n email: string;\n };\n catalog?: PrototypeCatalogLike;\n preparePrototypeFiles?: PreparePrototypeFiles;\n deploymentProvider?: DeploymentProvider;\n applicationId?: string;\n themeRegistry?: ThemeRegistry;\n};\n\ntype InternalLocalPrototypeLifecycleOptions = LocalPrototypeLifecycleOptions & {\n runtime?: PrototypeLifecycleRuntimeContext;\n};\n\nfunction repositoryRelativePath(\n runtime: PrototypeLifecycleRuntimeContext,\n ref: { login: string; slug: string },\n) {\n const absolutePath = join(runtime.prototypeRoot, ref.login, ref.slug);\n return relative(runtime.repositoryRoot, absolutePath).split(sep).join(\"/\");\n}\n\nfunction destinationRef(identity: BonfireIdentity, title: string) {\n const slug = slugifyPrototypeTitle(title);\n if (slug === null)\n throw new PrototypeRefError(\"title\", \"must produce a slug\");\n return definePrototypeRef({ login: identity.login, slug });\n}\n\nclass PrototypeNotFoundError extends Error {}\nclass PrototypeOwnershipError extends Error {}\nclass PrototypeMetadataFileError extends Error {}\nclass DeploymentUnavailableError extends Error {}\n\nfunction metadataPath(\n runtime: PrototypeLifecycleRuntimeContext,\n ref: { login: string; slug: string },\n) {\n return join(runtime.prototypeRoot, ref.login, ref.slug, \"metadata.json\");\n}\n\nasync function assertPrototypeDirectory(\n runtime: PrototypeLifecycleRuntimeContext,\n ref: { login: string; slug: string },\n) {\n const paths = [\n runtime.prototypeRoot,\n join(runtime.prototypeRoot, ref.login),\n join(runtime.prototypeRoot, ref.login, ref.slug),\n ];\n\n try {\n for (const path of paths) {\n const stats = await lstat(path);\n if (stats.isSymbolicLink() || !stats.isDirectory()) {\n throw new PrototypeMetadataFileError();\n }\n }\n } catch (error) {\n if (error instanceof PrototypeMetadataFileError) throw error;\n throw new PrototypeMetadataFileError();\n }\n}\n\nasync function readMetadataDocument(\n runtime: PrototypeLifecycleRuntimeContext,\n ref: { login: string; slug: string },\n themeRegistry?: ThemeRegistry,\n) {\n const path = metadataPath(runtime, ref);\n try {\n const file = await open(\n path,\n constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0),\n );\n try {\n const source = await file.readFile(\"utf8\");\n const document: unknown = JSON.parse(source);\n parsePrototypeMetadata(document, { themeRegistry });\n if (\n typeof document !== \"object\" ||\n document === null ||\n Array.isArray(document)\n ) {\n throw new PrototypeMetadataFileError();\n }\n return { ...(document as Record<string, unknown>) };\n } finally {\n await file.close();\n }\n } catch (error) {\n if (error instanceof PrototypeMetadataFileError) throw error;\n throw new PrototypeMetadataFileError();\n }\n}\n\nasync function removePrototypeDirectory(\n runtime: PrototypeLifecycleRuntimeContext,\n ref: { login: string; slug: string },\n) {\n await assertPrototypeDirectory(runtime, ref);\n try {\n await rm(join(runtime.prototypeRoot, ref.login, ref.slug), {\n force: false,\n recursive: true,\n });\n } catch {\n throw new PrototypeMetadataFileError();\n }\n}\n\nasync function writeMetadataDocument(\n runtime: PrototypeLifecycleRuntimeContext,\n ref: { login: string; slug: string },\n document: Record<string, unknown>,\n) {\n const path = metadataPath(runtime, ref);\n const temporaryPath = `${path}.${randomUUID()}.tmp`;\n\n try {\n const stats = await lstat(path);\n if (stats.isSymbolicLink() || !stats.isFile()) {\n throw new PrototypeMetadataFileError();\n }\n await writeFile(temporaryPath, `${JSON.stringify(document, null, 2)}\\n`, {\n encoding: \"utf8\",\n flag: \"wx\",\n });\n await rename(temporaryPath, path);\n } catch (error) {\n if (error instanceof PrototypeMetadataFileError) throw error;\n throw new PrototypeMetadataFileError();\n } finally {\n await rm(temporaryPath, { force: true }).catch(() => undefined);\n }\n}\n\nasync function mergeIdentityBranchToPrimary(\n repository: GitRepository,\n options: {\n branch: string;\n primaryBranch: string;\n remote: string;\n },\n) {\n if (options.branch === options.primaryBranch) return;\n\n const hasRemote = (await repository.remotes()).some(\n (remote) => remote.name === options.remote,\n );\n if (!hasRemote) return;\n\n await repository.checkout([options.primaryBranch]);\n try {\n await repository.merge([\n options.branch,\n \"--no-ff\",\n \"-m\",\n `merge: ${options.branch}`,\n ]);\n await repository.push(options.remote, options.primaryBranch);\n } finally {\n await repository.checkout([options.branch]);\n }\n}\n\nfunction mapError(error: unknown): LifecycleErrorCode {\n if (error instanceof PrototypeNotFoundError) return \"not-found\";\n if (error instanceof PrototypeOwnershipError) return \"forbidden\";\n if (error instanceof PrototypeMetadataFileError) return \"filesystem-failure\";\n if (error instanceof RepositoryBusyError) return \"repository-busy\";\n if (\n error instanceof PrototypeRefError ||\n error instanceof LifecycleInputError\n ) {\n return \"invalid-input\";\n }\n if (error instanceof GitRepositoryError) {\n if (error.kind === \"timeout\") return \"timeout\";\n if (error.kind === \"conflict\") return \"working-tree-conflict\";\n if (error.kind === \"invalid-configuration\") return \"unexpected-failure\";\n return \"git-failure\";\n }\n if (error instanceof PrototypeScaffoldError) {\n if (error.kind === \"collision\") return \"already-exists\";\n if (error.kind === \"invalid-input\") return \"invalid-input\";\n return \"filesystem-failure\";\n }\n if (error instanceof PrototypeDuplicateError) {\n if (error.kind === \"source-not-found\") return \"not-found\";\n if (error.kind === \"collision\") return \"already-exists\";\n if (error.kind === \"invalid-source\") return \"invalid-input\";\n return \"filesystem-failure\";\n }\n if (error instanceof DeploymentUnavailableError) {\n return \"deployment-unavailable\";\n }\n if (error instanceof DeploymentProviderError) {\n return error.kind === \"timeout\" ? \"timeout\" : \"deployment-failure\";\n }\n return \"unexpected-failure\";\n}\n\nfunction resultFrom<Value>(\n operation: () => Promise<Value>,\n): Promise<LifecycleResult<Value>> {\n return operation()\n .then(lifecycleSuccess)\n .catch((error: unknown) => lifecycleFailure(mapError(error)));\n}\n\nexport class LocalPrototypeLifecycle implements PrototypeLifecycle {\n readonly #runtime: PrototypeLifecycleRuntimeContext;\n readonly gitMode: GitMode;\n readonly #catalog: PrototypeCatalogLike;\n readonly #repository: GitRepository;\n readonly #preparePrototypeFiles: PreparePrototypeFiles;\n readonly #deploymentProvider?: DeploymentProvider;\n readonly #applicationId?: string;\n readonly #themeRegistry?: ThemeRegistry;\n\n constructor(options: LocalPrototypeLifecycleOptions) {\n const internalOptions = options as InternalLocalPrototypeLifecycleOptions;\n const runtime =\n internalOptions.runtime ?? createPrototypeLifecycleRuntime(internalOptions);\n this.#runtime = {\n ...runtime,\n gitMode: parseGitModeSetting(runtime.gitMode),\n };\n this.gitMode = this.#runtime.gitMode;\n this.#themeRegistry = options.themeRegistry;\n this.#catalog =\n internalOptions.catalog ??\n new PrototypeCatalog({\n ...this.#runtime,\n themeRegistry: this.#themeRegistry,\n });\n this.#repository = this.#runtime.gitRepository;\n this.#preparePrototypeFiles =\n internalOptions.preparePrototypeFiles ?? (() => undefined);\n this.#deploymentProvider = internalOptions.deploymentProvider;\n this.#applicationId = internalOptions.applicationId;\n if (\n this.#deploymentProvider &&\n (typeof this.#applicationId !== \"string\" ||\n this.#applicationId.length === 0)\n ) {\n throw new TypeError(\n \"applicationId must be provided when deploymentProvider is configured\",\n );\n }\n }\n\n async #verifiedIdentity(identity: BonfireIdentity) {\n return parseBonfireIdentity(identity);\n }\n\n async #currentBranch() {\n const branch = await this.#repository.currentBranch();\n if (branch === \"HEAD\" || branch.length === 0) {\n throw new GitRepositoryError(\"conflict\", \"current-branch\");\n }\n return branch;\n }\n\n async #ownedPrototype(\n identity: BonfireIdentity,\n input: PrototypeCommandInput,\n ) {\n const verifiedIdentity = await this.#verifiedIdentity(identity);\n const normalizedInput = parsePrototypeCommandInput(input);\n if (normalizedInput.ref.login !== verifiedIdentity.login) {\n throw new PrototypeOwnershipError();\n }\n const summary = await this.#catalog.getSummary(normalizedInput.ref);\n if (!summary) {\n throw new PrototypeNotFoundError();\n }\n\n return {\n ref: normalizedInput.ref,\n path: repositoryRelativePath(this.#runtime, normalizedInput.ref),\n summary,\n };\n }\n\n async #prepareMutationBranch(login: string) {\n await assertIdentityBranchReady(this.#repository, login);\n return login;\n }\n\n async #prepareDestination(\n receipt: OwnedDestinationReceipt,\n expectedFiles: readonly string[],\n request: PreparePrototypeFilesRequest,\n ) {\n try {\n const frozenRequest = Object.freeze({\n ...request,\n ref: Object.freeze({ ...request.ref }),\n identity: Object.freeze({ ...request.identity }),\n ...(request.operation === \"duplicate\"\n ? { source: Object.freeze({ ...request.source }) }\n : {}),\n }) as PreparePrototypeFilesRequest;\n await this.#preparePrototypeFiles(frozenRequest);\n await validateOwnedDestination(\n receipt,\n expectedFiles,\n request.ref,\n this.#themeRegistry,\n );\n } catch {\n try {\n await cleanupOwnedDestination(receipt);\n } catch {\n // The failure remains a finite filesystem failure without retrying cleanup.\n }\n throw new PrototypeScaffoldError(\"filesystem\");\n }\n }\n\n async prepareBranch(\n identity: BonfireIdentity,\n ): Promise<LifecycleResult<BranchPreparationValue>> {\n return resultFrom(async () => {\n const verifiedIdentity = await this.#verifiedIdentity(identity);\n return withRepositoryOperation(\n this.#runtime.repositoryRealPath,\n async () => {\n if (\n this.#runtime.gitMode === \"manual\" ||\n this.#runtime.automaticBranchSwitch === \"disabled\"\n ) {\n await this.#currentBranch();\n return { status: \"disabled\" } satisfies BranchPreparationValue;\n }\n\n const synchronization = await synchronizeIdentityBranch(\n this.#repository,\n {\n identityBranch: verifiedIdentity.login,\n primaryBranch: this.#runtime.primaryBranch,\n remote: this.#runtime.remote,\n },\n );\n if (synchronization.status !== \"synchronized\") {\n return {\n status: synchronization.status,\n reason: synchronization.reason,\n ...(synchronization.affectedPaths.length > 0\n ? { affectedPaths: synchronization.affectedPaths }\n : {}),\n } satisfies BranchPreparationValue;\n }\n return { status: \"ready\" } satisfies BranchPreparationValue;\n },\n );\n });\n }\n\n async create(\n identity: BonfireIdentity,\n input: CreatePrototypeInput,\n ): Promise<LifecycleResult<CreatePrototypeValue>> {\n return resultFrom(async () => {\n const verifiedIdentity = await this.#verifiedIdentity(identity);\n const normalizedInput = parseCreatePrototypeInput(\n input,\n this.#themeRegistry,\n );\n const ref = destinationRef(verifiedIdentity, normalizedInput.title);\n\n return withRepositoryOperation(\n this.#runtime.repositoryRealPath,\n async () => {\n if (await this.#catalog.getSummary(ref)) {\n throw new PrototypeScaffoldError(\"collision\");\n }\n\n const branch =\n this.#runtime.gitMode === \"managed\"\n ? await this.#prepareMutationBranch(verifiedIdentity.login)\n : undefined;\n const prepared = await scaffoldPrototype({\n paths: this.#runtime,\n ref,\n title: normalizedInput.title,\n description: normalizedInput.description,\n authorName: verifiedIdentity.name,\n theme: normalizedInput.theme,\n themeRegistry: this.#themeRegistry,\n });\n await this.#prepareDestination(\n prepared.receipt,\n prepared.expectedFiles,\n {\n operation: \"create\",\n repositoryRoot: this.#runtime.repositoryRoot,\n prototypeRoot: this.#runtime.prototypeRoot,\n prototypePath: prepared.destination,\n ref,\n identity: verifiedIdentity,\n title: normalizedInput.title,\n description: normalizedInput.description,\n },\n );\n if (branch === undefined) {\n return {\n ref,\n url: getPrototypeUrl(ref),\n remoteStatus: \"manual\",\n } satisfies CreatePrototypeValue;\n }\n\n await commitPath(\n this.#repository,\n repositoryRelativePath(this.#runtime, ref),\n `init: ${ref.slug}`,\n );\n const push = await pushBranch(\n this.#repository,\n this.#runtime.remote,\n branch,\n );\n\n return {\n ref,\n url: getPrototypeUrl(ref),\n remoteStatus: push.remoteStatus,\n } satisfies CreatePrototypeValue;\n },\n );\n });\n }\n\n async edit(\n identity: BonfireIdentity,\n input: EditPrototypeInput,\n ): Promise<LifecycleResult<EditPrototypeValue>> {\n return resultFrom(async () => {\n const verifiedIdentity = await this.#verifiedIdentity(identity);\n const normalizedInput = parseEditPrototypeInput(\n input,\n this.#themeRegistry,\n );\n\n return withRepositoryOperation(\n this.#runtime.repositoryRealPath,\n async () => {\n const { ref, path } = await this.#ownedPrototype(verifiedIdentity, {\n ref: normalizedInput.ref,\n });\n const branch =\n this.#runtime.gitMode === \"managed\"\n ? await this.#prepareMutationBranch(verifiedIdentity.login)\n : undefined;\n await assertPrototypeDirectory(this.#runtime, ref);\n const document = await readMetadataDocument(\n this.#runtime,\n ref,\n this.#themeRegistry,\n );\n const metadata = parsePrototypeMetadata(document, {\n themeRegistry: this.#themeRegistry,\n });\n if (metadata.authorLogin !== ref.login) {\n throw new PrototypeNotFoundError();\n }\n\n await writeMetadataDocument(this.#runtime, ref, {\n ...document,\n title: normalizedInput.title,\n description: normalizedInput.description,\n updatedAt: new Date().toISOString(),\n ...(normalizedInput.theme === undefined\n ? {}\n : { theme: normalizedInput.theme }),\n });\n if (branch !== undefined) {\n await commitPath(this.#repository, path, `edit: ${ref.slug}`);\n await pushBranch(this.#repository, this.#runtime.remote, branch);\n }\n\n return { edited: true, ref } satisfies EditPrototypeValue;\n },\n );\n });\n }\n\n async delete(\n identity: BonfireIdentity,\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeletePrototypeValue>> {\n return resultFrom(async () => {\n const verifiedIdentity = await this.#verifiedIdentity(identity);\n const normalizedInput = parsePrototypeCommandInput(input);\n\n return withRepositoryOperation(\n this.#runtime.repositoryRealPath,\n async () => {\n const { ref, path } = await this.#ownedPrototype(\n verifiedIdentity,\n normalizedInput,\n );\n const branch =\n this.#runtime.gitMode === \"managed\"\n ? await this.#prepareMutationBranch(verifiedIdentity.login)\n : undefined;\n await removePrototypeDirectory(this.#runtime, ref);\n if (branch !== undefined) {\n await commitPath(this.#repository, path, `delete: ${ref.slug}`);\n await pushBranch(this.#repository, this.#runtime.remote, branch);\n }\n\n return { deleted: true, ref } satisfies DeletePrototypeValue;\n },\n );\n });\n }\n\n async getDirtyState(\n identity: BonfireIdentity,\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DirtyObservationValue>> {\n return resultFrom(async () => {\n const { path, summary } = await this.#ownedPrototype(identity, input);\n const status = await this.#repository.status([path]);\n return {\n status: status.files.length > 0 ? \"dirty\" : \"clean\",\n ...(summary.previewUrl !== undefined\n ? { previewUrl: summary.previewUrl }\n : {}),\n } satisfies DirtyObservationValue;\n });\n }\n\n async getRepositorySummary(\n identity: BonfireIdentity,\n ): Promise<LifecycleResult<RepositorySummary>> {\n return resultFrom(async () => {\n const verifiedIdentity = await this.#verifiedIdentity(identity);\n return getRepositorySummary({\n repository: this.#repository,\n catalog: this.#catalog,\n repositoryRoot: this.#runtime.repositoryRoot,\n prototypeRoot: this.#runtime.prototypeRoot,\n identity: verifiedIdentity,\n mode: this.#runtime.gitMode,\n remote: this.#runtime.remote,\n primaryBranch: this.#runtime.primaryBranch,\n });\n });\n }\n\n async checkRepositorySummary(\n identity: BonfireIdentity,\n ): Promise<LifecycleResult<RepositorySummary>> {\n return resultFrom(async () => {\n const verifiedIdentity = await this.#verifiedIdentity(identity);\n return getRepositorySummary({\n repository: this.#repository,\n catalog: this.#catalog,\n repositoryRoot: this.#runtime.repositoryRoot,\n prototypeRoot: this.#runtime.prototypeRoot,\n identity: verifiedIdentity,\n mode: this.#runtime.gitMode,\n remote: this.#runtime.remote,\n primaryBranch: this.#runtime.primaryBranch,\n refresh: true,\n });\n });\n }\n\n async deploy(\n identity: BonfireIdentity,\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeploymentValue>> {\n if (this.#runtime.gitMode === \"manual\") {\n return lifecycleFailure(\"forbidden\");\n }\n\n return resultFrom(async () => {\n const verifiedIdentity = await this.#verifiedIdentity(identity);\n const normalizedInput = parsePrototypeCommandInput(input);\n if (!this.#deploymentProvider) {\n throw new DeploymentUnavailableError();\n }\n\n return withRepositoryOperation(\n this.#runtime.repositoryRealPath,\n async () => {\n const { ref, path } = await this.#ownedPrototype(\n verifiedIdentity,\n normalizedInput,\n );\n const branch = await this.#prepareMutationBranch(\n verifiedIdentity.login,\n );\n await assertPrototypeDirectory(this.#runtime, ref);\n const document = await readMetadataDocument(\n this.#runtime,\n ref,\n this.#themeRegistry,\n );\n const metadata = parsePrototypeMetadata(document, {\n themeRegistry: this.#themeRegistry,\n });\n if (metadata.authorLogin !== ref.login) {\n throw new PrototypeNotFoundError();\n }\n await commitPath(this.#repository, path, `deploy: ${ref.slug}`);\n await pushBranch(this.#repository, this.#runtime.remote, branch);\n\n const deployment = await this.#deploymentProvider!.deploy({\n applicationId: this.#applicationId!,\n login: verifiedIdentity.login,\n });\n const previewUrl = new URL(\n getPrototypeUrl(ref).slice(1),\n `${deployment.url.replace(/\\/+$/, \"\")}/`,\n ).toString();\n\n let warning: DeploymentWarningCode | undefined;\n try {\n await writeMetadataDocument(this.#runtime, ref, {\n ...document,\n previewUrl,\n updatedAt: new Date().toISOString(),\n });\n await commitPath(\n this.#repository,\n path,\n `deploy: ${ref.slug} (metadata)`,\n );\n await pushBranch(this.#repository, this.#runtime.remote, branch);\n } catch {\n warning = \"metadata-persistence-failed\";\n }\n\n if (warning === undefined) {\n try {\n await mergeIdentityBranchToPrimary(this.#repository, {\n branch,\n primaryBranch: this.#runtime.primaryBranch,\n remote: this.#runtime.remote,\n });\n } catch {\n warning = \"primary-merge-failed\";\n }\n }\n\n return {\n deployed: true,\n ref,\n previewUrl,\n deploymentId: deployment.deploymentId,\n readyState: deployment.readyState,\n warning,\n } satisfies DeploymentValue;\n },\n );\n });\n }\n\n async save(\n identity: BonfireIdentity,\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<SavePrototypeValue>> {\n if (this.#runtime.gitMode === \"manual\") {\n return lifecycleFailure(\"forbidden\");\n }\n\n return resultFrom(async () => {\n const verifiedIdentity = await this.#verifiedIdentity(identity);\n const { ref, path } = await this.#ownedPrototype(\n verifiedIdentity,\n input,\n );\n return withRepositoryOperation(\n this.#runtime.repositoryRealPath,\n async () => {\n await this.#prepareMutationBranch(verifiedIdentity.login);\n await commitPath(this.#repository, path, `save: ${ref.slug}`);\n await pushBranch(\n this.#repository,\n this.#runtime.remote,\n verifiedIdentity.login,\n );\n return { saved: true } satisfies SavePrototypeValue;\n },\n );\n });\n }\n\n async discard(\n identity: BonfireIdentity,\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DiscardPrototypeValue>> {\n if (this.#runtime.gitMode === \"manual\") {\n return lifecycleFailure(\"forbidden\");\n }\n\n return resultFrom(async () => {\n const verifiedIdentity = await this.#verifiedIdentity(identity);\n const { path } = await this.#ownedPrototype(\n verifiedIdentity,\n input,\n );\n return withRepositoryOperation(\n this.#runtime.repositoryRealPath,\n async () => {\n await this.#prepareMutationBranch(verifiedIdentity.login);\n await discardPath(this.#repository, path);\n return { discarded: true } satisfies DiscardPrototypeValue;\n },\n );\n });\n }\n\n async duplicate(\n identity: BonfireIdentity,\n input: DuplicatePrototypeInput,\n ): Promise<LifecycleResult<DuplicatePrototypeValue>> {\n return resultFrom(async () => {\n const verifiedIdentity = await this.#verifiedIdentity(identity);\n const normalizedInput = parseDuplicatePrototypeInput(input);\n if (!(await this.#catalog.getSummary(normalizedInput.source))) {\n throw new PrototypeDuplicateError(\"source-not-found\");\n }\n const ref = destinationRef(verifiedIdentity, normalizedInput.title);\n\n return withRepositoryOperation(\n this.#runtime.repositoryRealPath,\n async () => {\n if (await this.#catalog.getSummary(ref)) {\n throw new PrototypeDuplicateError(\"collision\");\n }\n\n const branch =\n this.#runtime.gitMode === \"managed\"\n ? await this.#prepareMutationBranch(verifiedIdentity.login)\n : undefined;\n const prepared = await duplicatePrototype({\n paths: this.#runtime,\n source: normalizedInput.source,\n destination: ref,\n title: normalizedInput.title,\n description: normalizedInput.description,\n authorName: verifiedIdentity.name,\n themeRegistry: this.#themeRegistry,\n });\n await this.#prepareDestination(\n prepared.receipt,\n prepared.expectedFiles,\n {\n operation: \"duplicate\",\n repositoryRoot: this.#runtime.repositoryRoot,\n prototypeRoot: this.#runtime.prototypeRoot,\n prototypePath: prepared.destination,\n ref,\n source: normalizedInput.source,\n identity: verifiedIdentity,\n title: normalizedInput.title,\n description: normalizedInput.description,\n },\n );\n if (branch === undefined) {\n return {\n ref,\n url: getPrototypeUrl(ref),\n remoteStatus: \"manual\",\n } satisfies DuplicatePrototypeValue;\n }\n\n await commitPath(\n this.#repository,\n repositoryRelativePath(this.#runtime, ref),\n `init: ${ref.slug}`,\n );\n const push = await pushBranch(\n this.#repository,\n this.#runtime.remote,\n branch,\n );\n\n return {\n ref,\n url: getPrototypeUrl(ref),\n remoteStatus: push.remoteStatus,\n } satisfies DuplicatePrototypeValue;\n },\n );\n });\n }\n}\n"]}
1
+ {"version":3,"file":"local-prototype-lifecycle.js","sourceRoot":"","sources":["../../src/lifecycle/local-prototype-lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,QAAQ,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,mBAAmB,EACnB,gBAAgB,EAChB,gBAAgB,EAChB,yBAAyB,EACzB,4BAA4B,EAC5B,uBAAuB,EACvB,oBAAoB,EACpB,0BAA0B,EAC1B,sBAAsB,EACtB,qBAAqB,EACrB,iBAAiB,EAmBjB,mBAAmB,GASpB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,UAAU,EACV,kBAAkB,EAClB,UAAU,EACV,kBAAkB,EAClB,kBAAkB,GAEnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAC9E,OAAO,EACL,gBAAgB,GAEjB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAC3E,OAAO,EACL,+BAA+B,GAEhC,MAAM,sBAAsB,CAAC;AAK9B,OAAO,EACL,uBAAuB,EACvB,wBAAwB,GAEzB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,qBAAqB,CAAC;AAC7B,OAAO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B,QAAQ,EAAE,gBAAgB;oBAC1B,KAAK,EAAE,eAAe,CAAC,KAAK;oBAC5B,WAAW,EAAE,eAAe,CAAC,WAAW;iBACzC,CACF,CAAC;gBACF,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;oBACzB,OAAO;wBACL,GAAG;wBACH,GAAG,EAAE,eAAe,CAAC,GAAG,CAAC;wBACzB,YAAY,EAAE,QAAQ;qBACW,CAAC;gBACtC,CAAC;gBAED,MAAM,UAAU,CACd,IAAI,CAAC,WAAW,EAChB,sBAAsB,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,EAC1C,SAAS,GAAG,CAAC,IAAI,EAAE,CACpB,CAAC;gBACF,MAAM,IAAI,GAAG,MAAM,UAAU,CAC3B,IAAI,CAAC,WAAW,EAChB,IAAI,CAAC,QAAQ,CAAC,MAAM,EACpB,MAAM,CACP,CAAC;gBAEF,OAAO;oBACL,GAAG;oBACH,GAAG,EAAE,eAAe,CAAC,GAAG,CAAC;oBACzB,YAAY,EAAE,IAAI,CAAC,YAAY;iBACE,CAAC;YACtC,CAAC,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { constants } from \"node:fs\";\nimport { execFile as execFileCallback } from \"node:child_process\";\nimport { lstat, open, rename, rm, writeFile } from \"node:fs/promises\";\nimport { randomUUID } from \"node:crypto\";\nimport { promisify } from \"node:util\";\nimport { join, relative, sep } from \"node:path\";\nimport {\n definePrototypeRef,\n getPrototypeUrl,\n LifecycleInputError,\n lifecycleFailure,\n lifecycleSuccess,\n parseCreatePrototypeInput,\n parseDuplicatePrototypeInput,\n parseEditPrototypeInput,\n parseBonfireIdentity,\n parsePrototypeCommandInput,\n parsePrototypeMetadata,\n slugifyPrototypeTitle,\n PrototypeRefError,\n type BranchPreparationAttention,\n type BranchPreparationValue,\n type CreatePrototypeInput,\n type DependencyPreparationValue,\n type CreatePrototypeValue,\n type DeletePrototypeValue,\n type DeploymentValue,\n type DeploymentWarningCode,\n type LifecycleOperationOutcome,\n type LifecycleRecoveryKind,\n type LifecycleRecoveryOperation,\n type LifecycleRecoveryValue,\n type DirtyObservationValue,\n type DiscardPrototypeValue,\n type DuplicatePrototypeInput,\n type DuplicatePrototypeValue,\n type EditPrototypeInput,\n type EditPrototypeValue,\n parseGitModeSetting,\n type GitMode,\n type LifecycleErrorCode,\n type LifecycleResult,\n type BonfireIdentity,\n type PrototypeCommandInput,\n type SavePrototypeValue,\n type RepositorySummary,\n type ThemeRegistry,\n} from \"@ebay-dt/bonfire-core\";\nimport {\n commitPath,\n GitRepositoryError,\n pushBranch,\n pushCommitToBranch,\n remoteBranchCommit,\n type GitRepository,\n} from \"../git-repository.js\";\nimport { duplicatePrototype, PrototypeDuplicateError } from \"../duplicate.js\";\nimport {\n PrototypeCatalog,\n type PrototypeCatalogLike,\n} from \"../prototype-catalog.js\";\nimport { PrototypeScaffoldError, scaffoldPrototype } from \"../scaffold.js\";\nimport {\n createPrototypeLifecycleRuntime,\n type PrototypeLifecycleRuntimeContext,\n} from \"./runtime-context.js\";\nimport type {\n PreparePrototypeFiles,\n PreparePrototypeFilesRequest,\n} from \"../prepare-prototype-files.js\";\nimport {\n cleanupOwnedDestination,\n validateOwnedDestination,\n type OwnedDestinationReceipt,\n} from \"../internal/owned-destination.js\";\nimport {\n RepositoryBusyError,\n withRepositoryOperation,\n} from \"./operation-gate.js\";\nimport {\n DeploymentProviderError,\n type DeploymentProvider,\n} from \"../deployment-provider.js\";\nimport {\n assertIdentityBranchReady,\n synchronizeIdentityBranch,\n} from \"./repository-synchronization.js\";\nimport { getRepositorySummary } from \"./repository-summary.js\";\nimport {\n DeploymentWorktreeError,\n publishDeploymentSource,\n reportDeploymentIssue,\n} from \"./deployment-worktree.js\";\nimport {\n commitPrototypePath,\n deletePrototypePath,\n discardPrototypePath,\n} from \"./prototype-path-policy.js\";\nimport {\n clearPreparationMarker,\n readPreparationMarker,\n writePreparationMarker,\n type DependencyInstaller,\n} from \"./preparation-marker.js\";\n\nconst execFile = promisify(execFileCallback);\n\ntype LifecycleMethod<Input, Value> = (\n identity: BonfireIdentity,\n input: Input,\n) => Promise<LifecycleResult<Value>>;\n\nexport type PrototypeLifecycle = {\n /** Declares whether this lifecycle enforces the selected Git mode. */\n readonly gitMode?: GitMode;\n prepareBranch(\n identity: BonfireIdentity,\n ): Promise<LifecycleResult<BranchPreparationValue>>;\n prepareDependencies?(\n dependencyPaths?: readonly string[],\n installer?: DependencyInstaller,\n ): Promise<LifecycleResult<DependencyPreparationValue>>;\n create: LifecycleMethod<CreatePrototypeInput, CreatePrototypeValue>;\n duplicate: LifecycleMethod<DuplicatePrototypeInput, DuplicatePrototypeValue>;\n edit: LifecycleMethod<EditPrototypeInput, EditPrototypeValue>;\n delete: LifecycleMethod<PrototypeCommandInput, DeletePrototypeValue>;\n getDirtyState: LifecycleMethod<PrototypeCommandInput, DirtyObservationValue>;\n getRepositorySummary(\n identity: BonfireIdentity,\n ): Promise<LifecycleResult<RepositorySummary>>;\n checkRepositorySummary(\n identity: BonfireIdentity,\n ): Promise<LifecycleResult<RepositorySummary>>;\n save: LifecycleMethod<PrototypeCommandInput, SavePrototypeValue>;\n discard: LifecycleMethod<PrototypeCommandInput, DiscardPrototypeValue>;\n deploy: LifecycleMethod<PrototypeCommandInput, DeploymentValue>;\n retryPublish?: LifecycleMethod<PrototypeCommandInput, DeploymentValue>;\n getPendingRecovery?(\n identity: BonfireIdentity,\n ): Promise<LifecycleResult<LifecycleRecoveryValue | null>>;\n retryPendingPublication?(\n identity: BonfireIdentity,\n recoveryId: string,\n ): Promise<LifecycleResult<LifecycleRecoveryValue>>;\n};\n\nexport type LocalPrototypeLifecycleOptions = {\n repositoryRoot: string;\n prototypeRoot?: string;\n remote?: string;\n primaryBranch?: string;\n automaticBranchSwitch?: \"enabled\" | \"disabled\";\n gitMode?: GitMode;\n commitIdentity?: {\n name: string;\n email: string;\n };\n catalog?: PrototypeCatalogLike;\n preparePrototypeFiles?: PreparePrototypeFiles;\n deploymentProvider?: DeploymentProvider;\n applicationId?: string;\n themeRegistry?: ThemeRegistry;\n publishDeploymentSource?: typeof publishDeploymentSource | null;\n /** Test/host seam for the existing package-manager installation step. */\n installDependencies?: DependencyInstaller;\n};\n\ntype InternalLocalPrototypeLifecycleOptions = LocalPrototypeLifecycleOptions & {\n runtime?: PrototypeLifecycleRuntimeContext;\n};\n\nfunction repositoryRelativePath(\n runtime: PrototypeLifecycleRuntimeContext,\n ref: { login: string; slug: string },\n) {\n const absolutePath = join(runtime.prototypeRoot, ref.login, ref.slug);\n return relative(runtime.repositoryRoot, absolutePath).split(sep).join(\"/\");\n}\n\nfunction namespaceRelativePath(\n runtime: PrototypeLifecycleRuntimeContext,\n login: string,\n) {\n return relative(runtime.repositoryRoot, join(runtime.prototypeRoot, login))\n .split(sep)\n .join(\"/\");\n}\n\nfunction destinationRef(identity: BonfireIdentity, title: string) {\n const slug = slugifyPrototypeTitle(title);\n if (slug === null)\n throw new PrototypeRefError(\"title\", \"must produce a slug\");\n return definePrototypeRef({ login: identity.login, slug });\n}\n\nclass PrototypeNotFoundError extends Error {}\nclass PrototypeOwnershipError extends Error {}\nclass PrototypeMetadataFileError extends Error {}\nclass DeploymentUnavailableError extends Error {}\nclass DeploymentSourcePushError extends Error {}\nclass DeploymentNotAcceptedError extends Error {}\n\ntype PendingPublication = {\n recoveryId: string;\n operation: LifecycleRecoveryOperation;\n kind: LifecycleRecoveryKind;\n identity: BonfireIdentity;\n ref: { login: string; slug: string };\n path: string;\n sourceSha: string;\n previewUrl?: string;\n deploymentId?: string;\n acceptedAt?: string;\n readyState?: DeploymentValue[\"readyState\"];\n};\n\nconst pendingPublications = new Map<string, PendingPublication>();\n\nfunction pendingPublicationKey(repositoryRoot: string, login: string) {\n return `${repositoryRoot}\\0${login}`;\n}\n\nfunction metadataPath(\n runtime: PrototypeLifecycleRuntimeContext,\n ref: { login: string; slug: string },\n) {\n return join(runtime.prototypeRoot, ref.login, ref.slug, \"metadata.json\");\n}\n\ntype PrototypeDirectorySnapshotEntry = {\n path: string;\n kind: \"missing\" | \"directory\" | \"symlink\" | \"other\";\n dev?: number;\n ino?: number;\n};\ntype PrototypeDirectorySnapshot = readonly PrototypeDirectorySnapshotEntry[];\n\nfunction prototypeDirectoryPaths(\n runtime: PrototypeLifecycleRuntimeContext,\n ref: { login: string; slug: string },\n) {\n return [\n runtime.prototypeRoot,\n join(runtime.prototypeRoot, ref.login),\n join(runtime.prototypeRoot, ref.login, ref.slug),\n ];\n}\n\nasync function capturePrototypeDirectory(\n runtime: PrototypeLifecycleRuntimeContext,\n ref: { login: string; slug: string },\n): Promise<PrototypeDirectorySnapshot> {\n const entries: PrototypeDirectorySnapshotEntry[] = [];\n for (const path of prototypeDirectoryPaths(runtime, ref)) {\n try {\n const stats = await lstat(path);\n entries.push({\n path,\n kind: stats.isSymbolicLink()\n ? \"symlink\"\n : stats.isDirectory()\n ? \"directory\"\n : \"other\",\n dev: stats.dev,\n ino: stats.ino,\n });\n } catch (error) {\n if (\n error &&\n typeof error === \"object\" &&\n \"code\" in error &&\n error.code === \"ENOENT\"\n ) {\n entries.push({ path, kind: \"missing\" });\n continue;\n }\n throw new PrototypeMetadataFileError();\n }\n }\n return entries;\n}\n\nfunction samePrototypeDirectorySnapshot(\n expected: PrototypeDirectorySnapshot,\n actual: PrototypeDirectorySnapshot,\n) {\n return expected.every((entry, index) => {\n const current = actual[index];\n return (\n current !== undefined &&\n current.path === entry.path &&\n current.kind === entry.kind &&\n current.dev === entry.dev &&\n current.ino === entry.ino\n );\n });\n}\n\nasync function assertPrototypeDirectory(\n runtime: PrototypeLifecycleRuntimeContext,\n ref: { login: string; slug: string },\n expected?: PrototypeDirectorySnapshot,\n) {\n try {\n const actual = await capturePrototypeDirectory(runtime, ref);\n if (\n expected !== undefined &&\n !samePrototypeDirectorySnapshot(expected, actual)\n ) {\n throw new PrototypeMetadataFileError();\n }\n if (actual.some((entry) => entry.kind !== \"directory\")) {\n throw new PrototypeMetadataFileError();\n }\n } catch (error) {\n if (error instanceof PrototypeMetadataFileError) throw error;\n throw new PrototypeMetadataFileError();\n }\n}\n\nasync function readMetadataDocument(\n runtime: PrototypeLifecycleRuntimeContext,\n ref: { login: string; slug: string },\n themeRegistry?: ThemeRegistry,\n) {\n const path = metadataPath(runtime, ref);\n try {\n const file = await open(\n path,\n constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0),\n );\n try {\n const source = await file.readFile(\"utf8\");\n const document: unknown = JSON.parse(source);\n parsePrototypeMetadata(document, { themeRegistry });\n if (\n typeof document !== \"object\" ||\n document === null ||\n Array.isArray(document)\n ) {\n throw new PrototypeMetadataFileError();\n }\n return { ...(document as Record<string, unknown>) };\n } finally {\n await file.close();\n }\n } catch (error) {\n if (error instanceof PrototypeMetadataFileError) throw error;\n throw new PrototypeMetadataFileError();\n }\n}\n\nasync function writeMetadataDocument(\n runtime: PrototypeLifecycleRuntimeContext,\n ref: { login: string; slug: string },\n document: Record<string, unknown>,\n) {\n const path = metadataPath(runtime, ref);\n const temporaryPath = `${path}.${randomUUID()}.tmp`;\n\n try {\n const stats = await lstat(path);\n if (stats.isSymbolicLink() || !stats.isFile()) {\n throw new PrototypeMetadataFileError();\n }\n await writeFile(temporaryPath, `${JSON.stringify(document, null, 2)}\\n`, {\n encoding: \"utf8\",\n flag: \"wx\",\n });\n await rename(temporaryPath, path);\n } catch (error) {\n if (error instanceof PrototypeMetadataFileError) throw error;\n throw new PrototypeMetadataFileError();\n } finally {\n await rm(temporaryPath, { force: true }).catch(() => undefined);\n }\n}\n\nfunction mapError(error: unknown): LifecycleErrorCode {\n if (error instanceof PrototypeNotFoundError) return \"not-found\";\n if (error instanceof PrototypeOwnershipError) return \"forbidden\";\n if (error instanceof PrototypeMetadataFileError) return \"filesystem-failure\";\n if (error instanceof RepositoryBusyError) return \"repository-busy\";\n if (\n error instanceof PrototypeRefError ||\n error instanceof LifecycleInputError\n ) {\n return \"invalid-input\";\n }\n if (error instanceof GitRepositoryError) {\n if (error.kind === \"timeout\") return \"timeout\";\n if (error.kind === \"conflict\") return \"working-tree-conflict\";\n if (error.kind === \"invalid-configuration\") return \"unexpected-failure\";\n return \"git-failure\";\n }\n if (error instanceof PrototypeScaffoldError) {\n if (error.kind === \"collision\") return \"already-exists\";\n if (error.kind === \"invalid-input\") return \"invalid-input\";\n return \"filesystem-failure\";\n }\n if (error instanceof PrototypeDuplicateError) {\n if (error.kind === \"source-not-found\") return \"not-found\";\n if (error.kind === \"collision\") return \"already-exists\";\n if (error.kind === \"invalid-source\") return \"invalid-input\";\n return \"filesystem-failure\";\n }\n if (error instanceof DeploymentUnavailableError) {\n return \"deployment-unavailable\";\n }\n if (\n error instanceof DeploymentSourcePushError ||\n error instanceof DeploymentNotAcceptedError ||\n error instanceof DeploymentWorktreeError\n ) {\n return \"deployment-failure\";\n }\n if (error instanceof DeploymentProviderError) {\n return error.kind === \"timeout\" ? \"timeout\" : \"deployment-failure\";\n }\n return \"unexpected-failure\";\n}\n\nfunction resultFrom<Value>(\n operation: () => Promise<Value>,\n): Promise<LifecycleResult<Value>> {\n return operation()\n .then(lifecycleSuccess)\n .catch((error: unknown) => lifecycleFailure(mapError(error)));\n}\n\nasync function diagnoseMetadataStep<Value>(\n step: \"metadata-read\" | \"metadata-write\" | \"metadata-commit\",\n operation: () => Promise<Value>,\n): Promise<Value> {\n try {\n return await operation();\n } catch (error) {\n reportDeploymentIssue(\"publication\", step, error);\n throw error;\n }\n}\n\nexport class LocalPrototypeLifecycle implements PrototypeLifecycle {\n readonly #runtime: PrototypeLifecycleRuntimeContext;\n readonly gitMode: GitMode;\n readonly #catalog: PrototypeCatalogLike;\n readonly #repository: GitRepository;\n readonly #preparePrototypeFiles: PreparePrototypeFiles;\n readonly #deploymentProvider?: DeploymentProvider;\n readonly #applicationId?: string;\n readonly #themeRegistry?: ThemeRegistry;\n readonly #publishDeploymentSource: typeof publishDeploymentSource | null;\n readonly #installDependencies?: DependencyInstaller;\n #restartRequired = false;\n readonly #preparationAttention = new Map<\n string,\n BranchPreparationAttention\n >();\n\n constructor(options: LocalPrototypeLifecycleOptions) {\n const internalOptions = options as InternalLocalPrototypeLifecycleOptions;\n const runtime =\n internalOptions.runtime ??\n createPrototypeLifecycleRuntime(internalOptions);\n this.#runtime = {\n ...runtime,\n gitMode: parseGitModeSetting(runtime.gitMode),\n };\n this.gitMode = this.#runtime.gitMode;\n this.#themeRegistry = options.themeRegistry;\n this.#catalog =\n internalOptions.catalog ??\n new PrototypeCatalog({\n ...this.#runtime,\n themeRegistry: this.#themeRegistry,\n });\n this.#repository = this.#runtime.gitRepository;\n this.#preparePrototypeFiles =\n internalOptions.preparePrototypeFiles ?? (() => undefined);\n this.#deploymentProvider = internalOptions.deploymentProvider;\n this.#applicationId = internalOptions.applicationId;\n this.#publishDeploymentSource =\n internalOptions.publishDeploymentSource === null\n ? null\n : (internalOptions.publishDeploymentSource ?? publishDeploymentSource);\n this.#installDependencies = options.installDependencies;\n if (\n this.#deploymentProvider &&\n (typeof this.#applicationId !== \"string\" ||\n this.#applicationId.length === 0)\n ) {\n throw new TypeError(\n \"applicationId must be provided when deploymentProvider is configured\",\n );\n }\n }\n\n async #verifiedIdentity(identity: BonfireIdentity) {\n return parseBonfireIdentity(identity);\n }\n\n async #currentBranch() {\n const branch = await this.#repository.currentBranch();\n if (branch === \"HEAD\" || branch.length === 0) {\n throw new GitRepositoryError(\"conflict\", \"current-branch\");\n }\n return branch;\n }\n\n async #authorizedPrototype(\n identity: BonfireIdentity,\n input: PrototypeCommandInput,\n ) {\n const verifiedIdentity = await this.#verifiedIdentity(identity);\n const normalizedInput = parsePrototypeCommandInput(input);\n if (normalizedInput.ref.login !== verifiedIdentity.login) {\n throw new PrototypeOwnershipError();\n }\n const directorySnapshot = await capturePrototypeDirectory(\n this.#runtime,\n normalizedInput.ref,\n );\n return {\n ref: normalizedInput.ref,\n path: repositoryRelativePath(this.#runtime, normalizedInput.ref),\n directorySnapshot,\n };\n }\n\n async #ownedPrototype(\n identity: BonfireIdentity,\n input: PrototypeCommandInput,\n ) {\n const authorized = await this.#authorizedPrototype(identity, input);\n const summary = await this.#catalog.getSummary(authorized.ref);\n if (!summary) {\n throw new PrototypeNotFoundError();\n }\n\n return { ...authorized, summary };\n }\n\n async #prepareMutationBranch(login: string) {\n await assertIdentityBranchReady(this.#repository, login);\n return login;\n }\n\n async #prepareDestination(\n receipt: OwnedDestinationReceipt,\n expectedFiles: readonly string[],\n request: PreparePrototypeFilesRequest,\n ) {\n try {\n const frozenRequest = Object.freeze({\n ...request,\n ref: Object.freeze({ ...request.ref }),\n identity: Object.freeze({ ...request.identity }),\n ...(request.operation === \"duplicate\"\n ? { source: Object.freeze({ ...request.source }) }\n : {}),\n }) as PreparePrototypeFilesRequest;\n await this.#preparePrototypeFiles(frozenRequest);\n await validateOwnedDestination(\n receipt,\n expectedFiles,\n request.ref,\n this.#themeRegistry,\n );\n } catch {\n try {\n await cleanupOwnedDestination(receipt);\n } catch {\n // The failure remains a finite filesystem failure without retrying cleanup.\n }\n throw new PrototypeScaffoldError(\"filesystem\");\n }\n }\n\n async prepareBranch(\n identity: BonfireIdentity,\n ): Promise<LifecycleResult<BranchPreparationValue>> {\n return resultFrom(async () => {\n const verifiedIdentity = await this.#verifiedIdentity(identity);\n return withRepositoryOperation(\n this.#runtime.repositoryRealPath,\n async () => {\n if (\n this.#runtime.gitMode === \"manual\" ||\n this.#runtime.automaticBranchSwitch === \"disabled\"\n ) {\n await this.#currentBranch();\n const disabled = {\n status: \"disabled\",\n effects: {\n changed: false,\n pushed: false,\n reconciledPaths: [],\n restartRequired: false,\n },\n } satisfies BranchPreparationValue;\n this.#preparationAttention.set(verifiedIdentity.login, disabled);\n return disabled;\n }\n\n const synchronization = await synchronizeIdentityBranch(\n this.#repository,\n {\n identityBranch: verifiedIdentity.login,\n primaryBranch: this.#runtime.primaryBranch,\n remote: this.#runtime.remote,\n prototypeRoot: relative(\n this.#runtime.repositoryRoot,\n this.#runtime.prototypeRoot,\n )\n .split(sep)\n .join(\"/\"),\n },\n );\n const reconciledPaths =\n synchronization.status === \"synchronized\" &&\n synchronization.platformPaths.length === 0\n ? synchronization.affectedPaths.filter((path) =>\n this.#runtime.managedRepositoryPaths.includes(path),\n )\n : synchronization.platformPaths;\n const effects = {\n changed: synchronization.changed,\n pushed: synchronization.pushed,\n reconciledPaths,\n restartRequired:\n synchronization.status === \"synchronized\" &&\n synchronization.platformPaths.length === 0\n ? reconciledPaths.length > 0\n : synchronization.restartRequired,\n ...(synchronization.platformPaths.length > 0\n ? { platformPaths: synchronization.platformPaths }\n : {}),\n ...(synchronization.dependencyPaths.length > 0\n ? { dependencyPaths: synchronization.dependencyPaths }\n : {}),\n ...(synchronization.preparationRequired\n ? { preparationRequired: true }\n : {}),\n };\n if (effects.restartRequired) this.#restartRequired = true;\n if (effects.preparationRequired) {\n await writePreparationMarker(\n this.#repository,\n this.#runtime.repositoryRoot,\n effects.dependencyPaths ?? [],\n );\n }\n if (synchronization.status === \"deferred\") {\n const attention = {\n status: \"deferred\",\n reason: synchronization.reason,\n effects,\n ...(synchronization.affectedPaths.length > 0\n ? { affectedPaths: synchronization.affectedPaths }\n : {}),\n } satisfies BranchPreparationAttention;\n this.#preparationAttention.set(verifiedIdentity.login, attention);\n return attention;\n }\n if (synchronization.status === \"unsafe\") {\n const attention = {\n status: \"unsafe\",\n reason: synchronization.reason,\n effects,\n ...(synchronization.affectedPaths.length > 0\n ? { affectedPaths: synchronization.affectedPaths }\n : {}),\n } satisfies BranchPreparationAttention;\n this.#preparationAttention.set(verifiedIdentity.login, attention);\n return attention;\n }\n const ready = {\n status: \"ready\",\n effects,\n ...(synchronization.affectedPaths.length > 0\n ? { affectedPaths: synchronization.affectedPaths }\n : {}),\n } satisfies BranchPreparationValue;\n this.#preparationAttention.delete(verifiedIdentity.login);\n return ready;\n },\n );\n });\n }\n\n async prepareDependencies(\n dependencyPaths: readonly string[] = [],\n installer?: DependencyInstaller,\n ): Promise<LifecycleResult<DependencyPreparationValue>> {\n return resultFrom(async () =>\n withRepositoryOperation(this.#runtime.repositoryRealPath, async () => {\n let pending: readonly string[] | null = null;\n try {\n pending = await readPreparationMarker(\n this.#repository,\n this.#runtime.repositoryRoot,\n );\n } catch {\n // A retained/corrupt marker is recovery truth. Restricted modes must\n // preserve it without attempting installation; managed mode must\n // report not-ready rather than guessing what to install.\n if (\n this.#runtime.gitMode === \"manual\" ||\n this.#runtime.automaticBranchSwitch === \"disabled\"\n ) {\n return {\n status: \"skipped\",\n dependencyPaths: [...dependencyPaths],\n pending: true,\n restartRequired: false,\n } satisfies DependencyPreparationValue;\n }\n return {\n status: \"failed\",\n dependencyPaths: [...dependencyPaths],\n pending: true,\n restartRequired: true,\n } satisfies DependencyPreparationValue;\n }\n const paths = [...new Set([...(pending ?? []), ...dependencyPaths])];\n if (\n this.#runtime.gitMode === \"manual\" ||\n this.#runtime.automaticBranchSwitch === \"disabled\"\n ) {\n return {\n status: \"skipped\",\n dependencyPaths: paths,\n pending: pending !== null,\n restartRequired: false,\n } satisfies DependencyPreparationValue;\n }\n // An empty path list is still an obligation when the marker exists.\n // Do not reinterpret a retained marker as \"not required\".\n if (paths.length === 0 && pending === null) {\n return {\n status: \"not-required\",\n dependencyPaths: [],\n pending: false,\n restartRequired: false,\n } satisfies DependencyPreparationValue;\n }\n await writePreparationMarker(\n this.#repository,\n this.#runtime.repositoryRoot,\n paths,\n );\n try {\n await (\n installer ??\n this.#installDependencies ??\n (async (root) => {\n await execFile(\"pnpm\", [\"install\"], { cwd: root });\n })\n )(this.#runtime.repositoryRoot);\n } catch {\n return {\n status: \"failed\",\n dependencyPaths: paths,\n pending: true,\n restartRequired: true,\n } satisfies DependencyPreparationValue;\n }\n await clearPreparationMarker(\n this.#repository,\n this.#runtime.repositoryRoot,\n );\n return {\n status: \"prepared\",\n dependencyPaths: paths,\n pending: false,\n restartRequired: true,\n } satisfies DependencyPreparationValue;\n }),\n );\n }\n\n async create(\n identity: BonfireIdentity,\n input: CreatePrototypeInput,\n ): Promise<LifecycleResult<CreatePrototypeValue>> {\n return resultFrom(async () => {\n const verifiedIdentity = await this.#verifiedIdentity(identity);\n const normalizedInput = parseCreatePrototypeInput(\n input,\n this.#themeRegistry,\n );\n const ref = destinationRef(verifiedIdentity, normalizedInput.title);\n\n return withRepositoryOperation(\n this.#runtime.repositoryRealPath,\n async () => {\n if (await this.#catalog.getSummary(ref)) {\n throw new PrototypeScaffoldError(\"collision\");\n }\n\n const branch =\n this.#runtime.gitMode === \"managed\"\n ? await this.#prepareMutationBranch(verifiedIdentity.login)\n : undefined;\n const prepared = await scaffoldPrototype({\n paths: this.#runtime,\n ref,\n title: normalizedInput.title,\n description: normalizedInput.description,\n authorName: verifiedIdentity.name,\n theme: normalizedInput.theme,\n themeRegistry: this.#themeRegistry,\n });\n await this.#prepareDestination(\n prepared.receipt,\n prepared.expectedFiles,\n {\n operation: \"create\",\n repositoryRoot: this.#runtime.repositoryRoot,\n prototypeRoot: this.#runtime.prototypeRoot,\n prototypePath: prepared.destination,\n ref,\n identity: verifiedIdentity,\n title: normalizedInput.title,\n description: normalizedInput.description,\n },\n );\n if (branch === undefined) {\n return {\n ref,\n url: getPrototypeUrl(ref),\n remoteStatus: \"manual\",\n } satisfies CreatePrototypeValue;\n }\n\n await commitPath(\n this.#repository,\n repositoryRelativePath(this.#runtime, ref),\n `init: ${ref.slug}`,\n );\n const sourceSha = await this.#headCommit();\n const outcome = await this.#publishOrdinaryNamespace(\n verifiedIdentity,\n \"create\",\n ref,\n repositoryRelativePath(this.#runtime, ref),\n sourceSha,\n );\n return {\n ref,\n url: getPrototypeUrl(ref),\n remoteStatus: \"local-only\",\n outcome,\n } satisfies CreatePrototypeValue;\n },\n );\n });\n }\n\n async edit(\n identity: BonfireIdentity,\n input: EditPrototypeInput,\n ): Promise<LifecycleResult<EditPrototypeValue>> {\n return resultFrom(async () => {\n const verifiedIdentity = await this.#verifiedIdentity(identity);\n const normalizedInput = parseEditPrototypeInput(\n input,\n this.#themeRegistry,\n );\n\n return withRepositoryOperation(\n this.#runtime.repositoryRealPath,\n async () => {\n const { ref, path } = await this.#ownedPrototype(verifiedIdentity, {\n ref: normalizedInput.ref,\n });\n const branch =\n this.#runtime.gitMode === \"managed\"\n ? await this.#prepareMutationBranch(verifiedIdentity.login)\n : undefined;\n await assertPrototypeDirectory(this.#runtime, ref);\n const document = await readMetadataDocument(\n this.#runtime,\n ref,\n this.#themeRegistry,\n );\n const metadata = parsePrototypeMetadata(document, {\n themeRegistry: this.#themeRegistry,\n });\n if (metadata.authorLogin !== ref.login) {\n throw new PrototypeNotFoundError();\n }\n\n await writeMetadataDocument(this.#runtime, ref, {\n ...document,\n title: normalizedInput.title,\n description: normalizedInput.description,\n updatedAt: new Date().toISOString(),\n ...(normalizedInput.theme === undefined\n ? {}\n : { theme: normalizedInput.theme }),\n });\n if (branch !== undefined) {\n await commitPath(this.#repository, path, `edit: ${ref.slug}`);\n await pushBranch(this.#repository, this.#runtime.remote, branch);\n }\n\n return { edited: true, ref } satisfies EditPrototypeValue;\n },\n );\n });\n }\n\n async delete(\n identity: BonfireIdentity,\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeletePrototypeValue>> {\n return resultFrom(async () => {\n const verifiedIdentity = await this.#verifiedIdentity(identity);\n const normalizedInput = parsePrototypeCommandInput(input);\n\n return withRepositoryOperation(\n this.#runtime.repositoryRealPath,\n async () => {\n const { ref, path, directorySnapshot } =\n await this.#authorizedPrototype(verifiedIdentity, normalizedInput);\n if (directorySnapshot.at(-1)?.kind === \"missing\") {\n throw new PrototypeNotFoundError();\n }\n const branch =\n this.#runtime.gitMode === \"managed\"\n ? await this.#prepareMutationBranch(verifiedIdentity.login)\n : undefined;\n await assertPrototypeDirectory(this.#runtime, ref, directorySnapshot);\n await deletePrototypePath(\n this.#repository,\n path,\n branch === undefined ? undefined : `delete: ${ref.slug}`,\n );\n if (branch !== undefined) {\n const sourceSha = await this.#headCommit();\n const outcome = await this.#publishOrdinaryNamespace(\n verifiedIdentity,\n \"delete\",\n ref,\n path,\n sourceSha,\n );\n return {\n deleted: true,\n ref,\n outcome,\n } satisfies DeletePrototypeValue;\n }\n\n return {\n deleted: true,\n ref,\n outcome: {\n local: { status: \"completed\" },\n upload: { status: \"not-attempted\" },\n preview: { status: \"not-attempted\" },\n publication: { status: \"not-attempted\" },\n },\n } satisfies DeletePrototypeValue;\n },\n );\n });\n }\n\n async getDirtyState(\n identity: BonfireIdentity,\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DirtyObservationValue>> {\n return resultFrom(async () => {\n const { path, summary } = await this.#ownedPrototype(identity, input);\n const status = await this.#repository.status([path]);\n return {\n status: status.files.length > 0 ? \"dirty\" : \"clean\",\n ...(summary.previewUrl !== undefined\n ? { previewUrl: summary.previewUrl }\n : {}),\n } satisfies DirtyObservationValue;\n });\n }\n\n async getRepositorySummary(\n identity: BonfireIdentity,\n ): Promise<LifecycleResult<RepositorySummary>> {\n return resultFrom(async () => {\n const verifiedIdentity = await this.#verifiedIdentity(identity);\n return withRepositoryOperation(\n this.#runtime.repositoryRealPath,\n async () =>\n getRepositorySummary({\n repository: this.#repository,\n catalog: this.#catalog,\n repositoryRoot: this.#runtime.repositoryRoot,\n prototypeRoot: this.#runtime.prototypeRoot,\n identity: verifiedIdentity,\n mode: this.#runtime.gitMode,\n remote: this.#runtime.remote,\n primaryBranch: this.#runtime.primaryBranch,\n restartRequired: this.#restartRequired,\n preparationAttention: this.#preparationAttention.get(\n verifiedIdentity.login,\n ),\n preparationPending:\n (await readPreparationMarker(\n this.#repository,\n this.#runtime.repositoryRoot,\n )) !== null,\n }),\n );\n });\n }\n\n async checkRepositorySummary(\n identity: BonfireIdentity,\n ): Promise<LifecycleResult<RepositorySummary>> {\n return resultFrom(async () => {\n const verifiedIdentity = await this.#verifiedIdentity(identity);\n return withRepositoryOperation(\n this.#runtime.repositoryRealPath,\n async () =>\n getRepositorySummary({\n repository: this.#repository,\n catalog: this.#catalog,\n repositoryRoot: this.#runtime.repositoryRoot,\n prototypeRoot: this.#runtime.prototypeRoot,\n identity: verifiedIdentity,\n mode: this.#runtime.gitMode,\n remote: this.#runtime.remote,\n primaryBranch: this.#runtime.primaryBranch,\n restartRequired: this.#restartRequired,\n preparationAttention: this.#preparationAttention.get(\n verifiedIdentity.login,\n ),\n preparationPending:\n (await readPreparationMarker(\n this.#repository,\n this.#runtime.repositoryRoot,\n )) !== null,\n refresh: true,\n }),\n );\n });\n }\n\n async #headCommit() {\n const commit = (await this.#repository.raw([\"rev-parse\", \"HEAD\"])).trim();\n if (!/^[0-9a-f]{40,64}$/iu.test(commit)) {\n throw new GitRepositoryError(\"malformed-output\", \"head-commit\");\n }\n return commit.toLowerCase();\n }\n\n #workspaceRuntime(\n workspacePath: string,\n workspaceRepository: GitRepository,\n ): PrototypeLifecycleRuntimeContext {\n return {\n ...this.#runtime,\n repositoryRoot: workspacePath,\n repositoryRealPath: workspacePath,\n prototypeRoot: join(\n workspacePath,\n relative(this.#runtime.repositoryRoot, this.#runtime.prototypeRoot),\n ),\n gitRepository: workspaceRepository,\n };\n }\n\n #pendingKey(login: string) {\n return pendingPublicationKey(this.#runtime.repositoryRoot, login);\n }\n\n #rememberPending(pending: PendingPublication) {\n pendingPublications.set(this.#pendingKey(pending.identity.login), pending);\n }\n\n #clearPending(login: string) {\n pendingPublications.delete(this.#pendingKey(login));\n }\n\n #recoveryValue(\n pending: PendingPublication,\n outcome: LifecycleOperationOutcome,\n ): LifecycleRecoveryValue {\n return {\n recoveryId: pending.recoveryId,\n operation: pending.operation,\n kind: pending.kind,\n ref: pending.ref,\n sourceSha: pending.sourceSha,\n ...(pending.previewUrl === undefined\n ? {}\n : { previewUrl: pending.previewUrl }),\n ...(pending.deploymentId === undefined\n ? {}\n : { deploymentId: pending.deploymentId }),\n ...(pending.readyState === undefined\n ? {}\n : { readyState: pending.readyState }),\n ...(pending.acceptedAt === undefined\n ? {}\n : { acceptedAt: pending.acceptedAt }),\n outcome,\n };\n }\n\n async #publishCommittedNamespace(\n identity: BonfireIdentity,\n sourceSha: string,\n ) {\n if (this.#publishDeploymentSource === null) {\n throw new DeploymentUnavailableError();\n }\n return this.#publishDeploymentSource(\n this.#repository,\n {\n remote: this.#runtime.remote,\n primaryBranch: this.#runtime.primaryBranch,\n sourceSha,\n namespacePath: namespaceRelativePath(this.#runtime, identity.login),\n commitIdentity: this.#runtime.commitIdentity,\n },\n async () => undefined,\n );\n }\n\n async #publishOrdinaryNamespace(\n identity: BonfireIdentity,\n operation: \"create\" | \"delete\",\n ref: { login: string; slug: string },\n path: string,\n sourceSha: string,\n ): Promise<LifecycleOperationOutcome> {\n const baseOutcome: LifecycleOperationOutcome = {\n local: { status: \"completed\", checkpointSha: sourceSha },\n upload: { status: \"not-attempted\", sourceSha },\n preview: { status: \"not-attempted\" },\n publication: {\n status:\n this.#publishDeploymentSource === null ? \"not-attempted\" : \"pending\",\n },\n };\n if (this.#publishDeploymentSource === null) return baseOutcome;\n\n try {\n const publication = await this.#publishCommittedNamespace(\n identity,\n sourceSha,\n );\n this.#clearPending(identity.login);\n return {\n ...baseOutcome,\n publication: {\n status: \"confirmed\",\n revision: publication.publicationSha,\n },\n };\n } catch {\n const pending: PendingPublication = {\n recoveryId: randomUUID(),\n operation,\n kind: \"ordinary-publication\",\n identity,\n ref,\n path,\n sourceSha,\n };\n this.#rememberPending(pending);\n return {\n ...baseOutcome,\n publication: {\n status: \"failed\",\n recoveryId: pending.recoveryId,\n },\n };\n }\n }\n\n async #publishDeploymentMetadata(pending: PendingPublication) {\n if (this.#publishDeploymentSource === null) {\n throw new DeploymentUnavailableError();\n }\n return this.#publishDeploymentSource(\n this.#repository,\n {\n remote: this.#runtime.remote,\n primaryBranch: this.#runtime.primaryBranch,\n sourceSha: pending.sourceSha,\n namespacePath: namespaceRelativePath(\n this.#runtime,\n pending.identity.login,\n ),\n commitIdentity: this.#runtime.commitIdentity,\n },\n async ({ path, repository }) => {\n const workspaceRuntime = this.#workspaceRuntime(path, repository);\n const mergedDocument = await diagnoseMetadataStep(\"metadata-read\", () =>\n readMetadataDocument(\n workspaceRuntime,\n pending.ref,\n this.#themeRegistry,\n ),\n );\n await diagnoseMetadataStep(\"metadata-write\", () =>\n writeMetadataDocument(workspaceRuntime, pending.ref, {\n ...mergedDocument,\n previewUrl: pending.previewUrl,\n updatedAt: pending.acceptedAt,\n }),\n );\n await diagnoseMetadataStep(\"metadata-commit\", () =>\n commitPath(\n repository,\n pending.path,\n `deploy: ${pending.ref.slug} (metadata)`,\n ),\n );\n },\n );\n }\n\n async #deploymentValue(\n pending: PendingPublication,\n publicationWarnings: readonly DeploymentWarningCode[] = [],\n outcome?: LifecycleOperationOutcome,\n ): Promise<DeploymentValue> {\n const warnings = [...publicationWarnings];\n return {\n deployed: true,\n ref: pending.ref,\n previewUrl: pending.previewUrl!,\n deploymentId: pending.deploymentId!,\n sourceSha: pending.sourceSha,\n readyState: pending.readyState!,\n ...(outcome === undefined ? {} : { outcome }),\n warning: publicationWarnings[0],\n ...(warnings.length === 0 ? {} : { warnings }),\n };\n }\n\n async deploy(\n identity: BonfireIdentity,\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeploymentValue>> {\n if (this.#runtime.gitMode === \"manual\") {\n return lifecycleFailure(\"forbidden\");\n }\n\n return resultFrom(async () => {\n const verifiedIdentity = await this.#verifiedIdentity(identity);\n const normalizedInput = parsePrototypeCommandInput(input);\n if (!this.#deploymentProvider) {\n throw new DeploymentUnavailableError();\n }\n return withRepositoryOperation(\n this.#runtime.repositoryRealPath,\n async () => {\n const { ref, path } = await this.#ownedPrototype(\n verifiedIdentity,\n normalizedInput,\n );\n await assertIdentityBranchReady(\n this.#repository,\n verifiedIdentity.login,\n );\n await assertPrototypeDirectory(this.#runtime, ref);\n const document = await readMetadataDocument(\n this.#runtime,\n ref,\n this.#themeRegistry,\n );\n const metadata = parsePrototypeMetadata(document, {\n themeRegistry: this.#themeRegistry,\n });\n if (metadata.authorLogin !== ref.login) {\n throw new PrototypeNotFoundError();\n }\n\n await commitPrototypePath(\n this.#repository,\n path,\n `deploy: ${ref.slug}`,\n );\n const sourceSha = await this.#headCommit();\n let sourcePush;\n try {\n sourcePush = await pushCommitToBranch(\n this.#repository,\n this.#runtime.remote,\n sourceSha,\n verifiedIdentity.login,\n true,\n );\n } catch (error) {\n if (error instanceof GitRepositoryError) {\n const pending: PendingPublication = {\n recoveryId: randomUUID(),\n operation: \"deploy\",\n kind: \"deployment-upload\",\n identity: verifiedIdentity,\n ref,\n path,\n sourceSha,\n };\n this.#rememberPending(pending);\n return {\n deployed: false,\n ref,\n sourceSha,\n warning: \"upload-unconfirmed\",\n outcome: {\n local: { status: \"completed\", checkpointSha: sourceSha },\n upload: {\n status: \"unconfirmed\",\n sourceSha,\n },\n preview: { status: \"not-attempted\" },\n publication: {\n status: \"pending\",\n recoveryId: pending.recoveryId,\n },\n },\n } satisfies DeploymentValue;\n }\n throw error;\n }\n if (sourcePush.remoteStatus !== \"pushed\") {\n throw new DeploymentSourcePushError();\n }\n\n let deployment;\n try {\n deployment = await this.#deploymentProvider!.deploy({\n applicationId: this.#applicationId!,\n login: verifiedIdentity.login,\n });\n } catch (error) {\n if (\n error instanceof DeploymentProviderError &&\n [\n \"timeout\",\n \"transport-failure\",\n \"invalid-response\",\n \"invalid-url\",\n ].includes(error.kind)\n ) {\n const pending: PendingPublication = {\n recoveryId: randomUUID(),\n operation: \"deploy\",\n kind: \"deployment-preview-unconfirmed\",\n identity: verifiedIdentity,\n ref,\n path,\n sourceSha,\n };\n this.#rememberPending(pending);\n return {\n deployed: false,\n ref,\n sourceSha,\n warning: \"preview-unconfirmed\",\n outcome: {\n local: { status: \"completed\", checkpointSha: sourceSha },\n upload: { status: \"confirmed\", sourceSha },\n preview: { status: \"unconfirmed\" },\n publication: { status: \"not-attempted\" },\n },\n } satisfies DeploymentValue;\n }\n throw error;\n }\n if (\n deployment.commitSha.toLowerCase() !== sourceSha ||\n ![\"READY\", \"QUEUED\", \"INITIALIZING\", \"BUILDING\"].includes(\n deployment.readyState,\n )\n ) {\n throw new DeploymentNotAcceptedError();\n }\n const previewUrl = new URL(\n getPrototypeUrl(ref).slice(1),\n `${deployment.url.replace(/\\/+$/, \"\")}/`,\n ).toString();\n const pending: PendingPublication = {\n recoveryId: randomUUID(),\n operation: \"deploy\",\n kind: \"deployment-publication\",\n identity: verifiedIdentity,\n ref,\n path,\n previewUrl,\n deploymentId: deployment.deploymentId,\n sourceSha,\n acceptedAt: new Date().toISOString(),\n readyState: deployment.readyState,\n };\n const acceptedOutcome: LifecycleOperationOutcome = {\n local: { status: \"completed\", checkpointSha: sourceSha },\n upload: { status: \"confirmed\", sourceSha },\n preview: {\n status: \"accepted\",\n previewUrl,\n deploymentId: deployment.deploymentId,\n },\n publication: { status: \"pending\" },\n };\n\n try {\n const publication = await this.#publishDeploymentMetadata(pending);\n this.#clearPending(verifiedIdentity.login);\n return this.#deploymentValue(\n pending,\n publication.cleanupFailed ? [\"publication-cleanup-failed\"] : [],\n {\n ...acceptedOutcome,\n publication: {\n status: \"confirmed\",\n revision: publication.publicationSha,\n },\n },\n );\n } catch (error) {\n // Keep the accepted deployment retryable for every publication\n // failure, including metadata preparation failures.\n this.#rememberPending(pending);\n return this.#deploymentValue(\n pending,\n [\n error instanceof DeploymentWorktreeError &&\n error.kind !== \"cleanup-failure\" &&\n error.kind !== \"metadata-failure\"\n ? \"primary-merge-failed\"\n : \"metadata-persistence-failed\",\n ...(error instanceof DeploymentWorktreeError &&\n error.cleanupFailed\n ? [\"publication-cleanup-failed\" as const]\n : []),\n ],\n {\n ...acceptedOutcome,\n publication: {\n status: \"failed\",\n recoveryId: pending.recoveryId,\n },\n },\n );\n }\n },\n );\n });\n }\n\n async getPendingRecovery(\n identity: BonfireIdentity,\n ): Promise<LifecycleResult<LifecycleRecoveryValue | null>> {\n return resultFrom(async () => {\n const verifiedIdentity = await this.#verifiedIdentity(identity);\n const pending = pendingPublications.get(\n this.#pendingKey(verifiedIdentity.login),\n );\n if (pending === undefined) return null;\n return this.#recoveryValue(pending, {\n local: { status: \"completed\", checkpointSha: pending.sourceSha },\n upload: {\n status:\n pending.kind === \"deployment-upload\" ? \"unconfirmed\" : \"confirmed\",\n sourceSha: pending.sourceSha,\n },\n preview:\n pending.kind === \"deployment-publication\"\n ? {\n status: \"accepted\",\n previewUrl: pending.previewUrl!,\n deploymentId: pending.deploymentId!,\n }\n : pending.kind === \"deployment-preview-unconfirmed\"\n ? { status: \"unconfirmed\" }\n : { status: \"not-attempted\" },\n publication: {\n status:\n pending.kind === \"deployment-upload\"\n ? \"pending\"\n : pending.kind === \"deployment-preview-unconfirmed\"\n ? \"not-attempted\"\n : \"failed\",\n ...(pending.kind === \"deployment-preview-unconfirmed\"\n ? {}\n : { recoveryId: pending.recoveryId }),\n },\n });\n });\n }\n\n async retryPendingPublication(\n identity: BonfireIdentity,\n recoveryId: string,\n ): Promise<LifecycleResult<LifecycleRecoveryValue>> {\n if (this.#runtime.gitMode === \"manual\") {\n return lifecycleFailure(\"forbidden\");\n }\n\n return resultFrom(async () => {\n const verifiedIdentity = await this.#verifiedIdentity(identity);\n const pending = pendingPublications.get(\n this.#pendingKey(verifiedIdentity.login),\n );\n if (pending === undefined || pending.recoveryId !== recoveryId) {\n throw new DeploymentUnavailableError();\n }\n\n return withRepositoryOperation(\n this.#runtime.repositoryRealPath,\n async () => {\n await assertIdentityBranchReady(\n this.#repository,\n verifiedIdentity.login,\n );\n if (pending.kind === \"deployment-preview-unconfirmed\") {\n throw new DeploymentUnavailableError();\n }\n let deploymentPending = pending;\n if (pending.kind === \"ordinary-publication\") {\n deploymentPending = {\n ...pending,\n sourceSha: await this.#headCommit(),\n };\n this.#rememberPending(deploymentPending);\n }\n if (pending.kind === \"deployment-upload\") {\n const remoteSource = await remoteBranchCommit(\n this.#repository,\n this.#runtime.remote,\n verifiedIdentity.login,\n );\n if (remoteSource !== pending.sourceSha) {\n const upload = await pushCommitToBranch(\n this.#repository,\n this.#runtime.remote,\n pending.sourceSha,\n verifiedIdentity.login,\n true,\n );\n if (upload.remoteStatus !== \"pushed\") {\n throw new DeploymentSourcePushError();\n }\n }\n if (!this.#deploymentProvider) {\n throw new DeploymentUnavailableError();\n }\n let deployment;\n try {\n deployment = await this.#deploymentProvider.deploy({\n applicationId: this.#applicationId!,\n login: verifiedIdentity.login,\n });\n } catch (error) {\n if (\n error instanceof DeploymentProviderError &&\n [\n \"timeout\",\n \"transport-failure\",\n \"invalid-response\",\n \"invalid-url\",\n ].includes(error.kind)\n ) {\n const uncertain = {\n ...pending,\n kind: \"deployment-preview-unconfirmed\" as const,\n };\n this.#rememberPending(uncertain);\n return this.#recoveryValue(uncertain, {\n local: {\n status: \"completed\",\n checkpointSha: pending.sourceSha,\n },\n upload: {\n status: \"confirmed\",\n sourceSha: pending.sourceSha,\n },\n preview: { status: \"unconfirmed\" },\n publication: { status: \"not-attempted\" },\n });\n }\n throw error;\n }\n if (\n deployment.commitSha.toLowerCase() !== pending.sourceSha ||\n ![\"READY\", \"QUEUED\", \"INITIALIZING\", \"BUILDING\"].includes(\n deployment.readyState,\n )\n ) {\n throw new DeploymentNotAcceptedError();\n }\n deploymentPending = {\n ...pending,\n kind: \"deployment-publication\",\n previewUrl: new URL(\n getPrototypeUrl(pending.ref).slice(1),\n `${deployment.url.replace(/\\/+$/, \"\")}/`,\n ).toString(),\n deploymentId: deployment.deploymentId,\n acceptedAt: new Date().toISOString(),\n readyState: deployment.readyState,\n };\n this.#rememberPending(deploymentPending);\n }\n const publication =\n deploymentPending.kind === \"deployment-publication\"\n ? await this.#publishDeploymentMetadata(deploymentPending)\n : await this.#publishCommittedNamespace(\n verifiedIdentity,\n deploymentPending.sourceSha,\n );\n this.#clearPending(verifiedIdentity.login);\n return this.#recoveryValue(deploymentPending, {\n local: {\n status: \"completed\",\n checkpointSha: deploymentPending.sourceSha,\n },\n upload: {\n status: \"confirmed\",\n sourceSha: deploymentPending.sourceSha,\n },\n preview:\n deploymentPending.kind === \"deployment-publication\"\n ? {\n status: \"accepted\",\n previewUrl: deploymentPending.previewUrl!,\n deploymentId: deploymentPending.deploymentId!,\n }\n : { status: \"not-attempted\" },\n publication: {\n status: \"confirmed\",\n revision: publication.publicationSha,\n },\n });\n },\n );\n });\n }\n\n /** Compatibility wrapper; recovery-ID retry is the implementation. */\n async retryPublish(\n identity: BonfireIdentity,\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeploymentValue>> {\n if (this.#runtime.gitMode === \"manual\") {\n return lifecycleFailure(\"forbidden\");\n }\n let normalizedInput: PrototypeCommandInput;\n try {\n normalizedInput = parsePrototypeCommandInput(input);\n } catch {\n return lifecycleFailure(\"invalid-input\");\n }\n const pending = pendingPublications.get(this.#pendingKey(identity.login));\n if (\n pending === undefined ||\n pending.kind !== \"deployment-publication\" ||\n pending.ref.login !== normalizedInput.ref.login ||\n pending.ref.slug !== normalizedInput.ref.slug\n ) {\n return lifecycleFailure(\"deployment-unavailable\");\n }\n const result = await this.retryPendingPublication(\n identity,\n pending.recoveryId,\n );\n if (!result.ok) return result;\n const current = pendingPublications.get(this.#pendingKey(identity.login));\n const completed = {\n ...pending,\n ...(current ?? {}),\n sourceSha: result.value.sourceSha,\n ...(result.value.previewUrl === undefined\n ? {}\n : { previewUrl: result.value.previewUrl }),\n ...(result.value.deploymentId === undefined\n ? {}\n : { deploymentId: result.value.deploymentId }),\n };\n return lifecycleSuccess(\n await this.#deploymentValue(completed, [], result.value.outcome),\n );\n }\n\n async save(\n identity: BonfireIdentity,\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<SavePrototypeValue>> {\n if (this.#runtime.gitMode === \"manual\") {\n return lifecycleFailure(\"forbidden\");\n }\n\n return resultFrom(async () => {\n const verifiedIdentity = await this.#verifiedIdentity(identity);\n return withRepositoryOperation(\n this.#runtime.repositoryRealPath,\n async () => {\n await this.#prepareMutationBranch(verifiedIdentity.login);\n const { ref, path, directorySnapshot } =\n await this.#authorizedPrototype(verifiedIdentity, input);\n await assertPrototypeDirectory(this.#runtime, ref, directorySnapshot);\n await commitPrototypePath(\n this.#repository,\n path,\n `save: ${ref.slug}`,\n );\n return { saved: true } satisfies SavePrototypeValue;\n },\n );\n });\n }\n\n async discard(\n identity: BonfireIdentity,\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DiscardPrototypeValue>> {\n if (this.#runtime.gitMode === \"manual\") {\n return lifecycleFailure(\"forbidden\");\n }\n\n return resultFrom(async () => {\n const verifiedIdentity = await this.#verifiedIdentity(identity);\n return withRepositoryOperation(\n this.#runtime.repositoryRealPath,\n async () => {\n await this.#prepareMutationBranch(verifiedIdentity.login);\n const { ref, path, directorySnapshot } =\n await this.#authorizedPrototype(verifiedIdentity, input);\n await assertPrototypeDirectory(this.#runtime, ref, directorySnapshot);\n await discardPrototypePath(this.#repository, path);\n return { discarded: true } satisfies DiscardPrototypeValue;\n },\n );\n });\n }\n\n async duplicate(\n identity: BonfireIdentity,\n input: DuplicatePrototypeInput,\n ): Promise<LifecycleResult<DuplicatePrototypeValue>> {\n return resultFrom(async () => {\n const verifiedIdentity = await this.#verifiedIdentity(identity);\n const normalizedInput = parseDuplicatePrototypeInput(input);\n if (!(await this.#catalog.getSummary(normalizedInput.source))) {\n throw new PrototypeDuplicateError(\"source-not-found\");\n }\n const ref = destinationRef(verifiedIdentity, normalizedInput.title);\n\n return withRepositoryOperation(\n this.#runtime.repositoryRealPath,\n async () => {\n if (await this.#catalog.getSummary(ref)) {\n throw new PrototypeDuplicateError(\"collision\");\n }\n\n const branch =\n this.#runtime.gitMode === \"managed\"\n ? await this.#prepareMutationBranch(verifiedIdentity.login)\n : undefined;\n const prepared = await duplicatePrototype({\n paths: this.#runtime,\n source: normalizedInput.source,\n destination: ref,\n title: normalizedInput.title,\n description: normalizedInput.description,\n authorName: verifiedIdentity.name,\n themeRegistry: this.#themeRegistry,\n });\n await this.#prepareDestination(\n prepared.receipt,\n prepared.expectedFiles,\n {\n operation: \"duplicate\",\n repositoryRoot: this.#runtime.repositoryRoot,\n prototypeRoot: this.#runtime.prototypeRoot,\n prototypePath: prepared.destination,\n ref,\n source: normalizedInput.source,\n identity: verifiedIdentity,\n title: normalizedInput.title,\n description: normalizedInput.description,\n },\n );\n if (branch === undefined) {\n return {\n ref,\n url: getPrototypeUrl(ref),\n remoteStatus: \"manual\",\n } satisfies DuplicatePrototypeValue;\n }\n\n await commitPath(\n this.#repository,\n repositoryRelativePath(this.#runtime, ref),\n `init: ${ref.slug}`,\n );\n const push = await pushBranch(\n this.#repository,\n this.#runtime.remote,\n branch,\n );\n\n return {\n ref,\n url: getPrototypeUrl(ref),\n remoteStatus: push.remoteStatus,\n } satisfies DuplicatePrototypeValue;\n },\n );\n });\n }\n}\n"]}
@@ -0,0 +1,12 @@
1
+ import type { DependencyPreparationValue } from "@ebay-dt/bonfire-core";
2
+ import type { GitRepository } from "../git-repository.js";
3
+ /** Resolve the marker through Git so worktrees and git-file repositories are safe. */
4
+ export declare function preparationMarkerPath(repository: GitRepository, repositoryRoot: string): Promise<string>;
5
+ export declare function readPreparationMarker(repository: GitRepository, repositoryRoot: string): Promise<readonly string[] | null>;
6
+ /** Write before installation; rename makes the marker visible atomically. */
7
+ export declare function writePreparationMarker(repository: GitRepository, repositoryRoot: string, dependencyPaths: readonly string[]): Promise<void>;
8
+ export declare function clearPreparationMarker(repository: GitRepository, repositoryRoot: string): Promise<void>;
9
+ export declare function hasPreparationMarker(repository: GitRepository, repositoryRoot: string): Promise<boolean>;
10
+ export type DependencyInstaller = (repositoryRoot: string) => Promise<void>;
11
+ export type DependencyPreparationResult = DependencyPreparationValue;
12
+ //# sourceMappingURL=preparation-marker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preparation-marker.d.ts","sourceRoot":"","sources":["../../src/lifecycle/preparation-marker.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAC;AACxE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAS1D,sFAAsF;AACtF,wBAAsB,qBAAqB,CACzC,UAAU,EAAE,aAAa,EACzB,cAAc,EAAE,MAAM,mBAQvB;AAED,wBAAsB,qBAAqB,CACzC,UAAU,EAAE,aAAa,EACzB,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,SAAS,MAAM,EAAE,GAAG,IAAI,CAAC,CAuBnC;AAED,6EAA6E;AAC7E,wBAAsB,sBAAsB,CAC1C,UAAU,EAAE,aAAa,EACzB,cAAc,EAAE,MAAM,EACtB,eAAe,EAAE,SAAS,MAAM,EAAE,iBAqBnC;AAED,wBAAsB,sBAAsB,CAC1C,UAAU,EAAE,aAAa,EACzB,cAAc,EAAE,MAAM,iBAIvB;AAED,wBAAsB,oBAAoB,CACxC,UAAU,EAAE,aAAa,EACzB,cAAc,EAAE,MAAM,oBAiBvB;AAED,MAAM,MAAM,mBAAmB,GAAG,CAAC,cAAc,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAC5E,MAAM,MAAM,2BAA2B,GAAG,0BAA0B,CAAC","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport {\n lstat,\n mkdir,\n readFile,\n rename,\n rm,\n writeFile,\n} from \"node:fs/promises\";\nimport { isAbsolute, join, resolve } from \"node:path\";\nimport type { DependencyPreparationValue } from \"@ebay-dt/bonfire-core\";\nimport type { GitRepository } from \"../git-repository.js\";\n\nconst MARKER_NAME = \"bonfire-preparation-pending\";\ntype Marker = { version: 1; dependencyPaths: readonly string[] };\n\nfunction markerPath(repositoryRoot: string, gitPath: string) {\n return isAbsolute(gitPath) ? gitPath : resolve(repositoryRoot, gitPath);\n}\n\n/** Resolve the marker through Git so worktrees and git-file repositories are safe. */\nexport async function preparationMarkerPath(\n repository: GitRepository,\n repositoryRoot: string,\n) {\n const path = (\n await repository.raw([\"rev-parse\", \"--git-path\", MARKER_NAME])\n ).trim();\n if (path.length === 0)\n throw new Error(\"Git returned an empty preparation marker path\");\n return markerPath(repositoryRoot, path);\n}\n\nexport async function readPreparationMarker(\n repository: GitRepository,\n repositoryRoot: string,\n): Promise<readonly string[] | null> {\n const path = await preparationMarkerPath(repository, repositoryRoot);\n try {\n const value = JSON.parse(await readFile(path, \"utf8\")) as Partial<Marker>;\n if (\n value.version !== 1 ||\n !Array.isArray(value.dependencyPaths) ||\n value.dependencyPaths.some((entry) => typeof entry !== \"string\")\n ) {\n throw new Error(\"Invalid preparation marker\");\n }\n return [...new Set(value.dependencyPaths)];\n } catch (error) {\n if (\n error !== null &&\n typeof error === \"object\" &&\n \"code\" in error &&\n error.code === \"ENOENT\"\n ) {\n return null;\n }\n throw error;\n }\n}\n\n/** Write before installation; rename makes the marker visible atomically. */\nexport async function writePreparationMarker(\n repository: GitRepository,\n repositoryRoot: string,\n dependencyPaths: readonly string[],\n) {\n const path = await preparationMarkerPath(repository, repositoryRoot);\n await mkdir(resolve(path, \"..\"), { recursive: true });\n const temporary = join(\n resolve(path, \"..\"),\n `.${MARKER_NAME}.${randomUUID()}.tmp`,\n );\n const marker: Marker = {\n version: 1,\n dependencyPaths: [...new Set(dependencyPaths)].sort(),\n };\n try {\n await writeFile(temporary, `${JSON.stringify(marker)}\\n`, {\n encoding: \"utf8\",\n mode: 0o600,\n });\n await rename(temporary, path);\n } finally {\n await rm(temporary, { force: true }).catch(() => undefined);\n }\n}\n\nexport async function clearPreparationMarker(\n repository: GitRepository,\n repositoryRoot: string,\n) {\n const path = await preparationMarkerPath(repository, repositoryRoot);\n await rm(path, { force: true });\n}\n\nexport async function hasPreparationMarker(\n repository: GitRepository,\n repositoryRoot: string,\n) {\n const path = await preparationMarkerPath(repository, repositoryRoot);\n try {\n await lstat(path);\n return true;\n } catch (error) {\n if (\n error !== null &&\n typeof error === \"object\" &&\n \"code\" in error &&\n error.code === \"ENOENT\"\n ) {\n return false;\n }\n throw error;\n }\n}\n\nexport type DependencyInstaller = (repositoryRoot: string) => Promise<void>;\nexport type DependencyPreparationResult = DependencyPreparationValue;\n"]}
@@ -0,0 +1,76 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { lstat, mkdir, readFile, rename, rm, writeFile, } from "node:fs/promises";
3
+ import { isAbsolute, join, resolve } from "node:path";
4
+ const MARKER_NAME = "bonfire-preparation-pending";
5
+ function markerPath(repositoryRoot, gitPath) {
6
+ return isAbsolute(gitPath) ? gitPath : resolve(repositoryRoot, gitPath);
7
+ }
8
+ /** Resolve the marker through Git so worktrees and git-file repositories are safe. */
9
+ export async function preparationMarkerPath(repository, repositoryRoot) {
10
+ const path = (await repository.raw(["rev-parse", "--git-path", MARKER_NAME])).trim();
11
+ if (path.length === 0)
12
+ throw new Error("Git returned an empty preparation marker path");
13
+ return markerPath(repositoryRoot, path);
14
+ }
15
+ export async function readPreparationMarker(repository, repositoryRoot) {
16
+ const path = await preparationMarkerPath(repository, repositoryRoot);
17
+ try {
18
+ const value = JSON.parse(await readFile(path, "utf8"));
19
+ if (value.version !== 1 ||
20
+ !Array.isArray(value.dependencyPaths) ||
21
+ value.dependencyPaths.some((entry) => typeof entry !== "string")) {
22
+ throw new Error("Invalid preparation marker");
23
+ }
24
+ return [...new Set(value.dependencyPaths)];
25
+ }
26
+ catch (error) {
27
+ if (error !== null &&
28
+ typeof error === "object" &&
29
+ "code" in error &&
30
+ error.code === "ENOENT") {
31
+ return null;
32
+ }
33
+ throw error;
34
+ }
35
+ }
36
+ /** Write before installation; rename makes the marker visible atomically. */
37
+ export async function writePreparationMarker(repository, repositoryRoot, dependencyPaths) {
38
+ const path = await preparationMarkerPath(repository, repositoryRoot);
39
+ await mkdir(resolve(path, ".."), { recursive: true });
40
+ const temporary = join(resolve(path, ".."), `.${MARKER_NAME}.${randomUUID()}.tmp`);
41
+ const marker = {
42
+ version: 1,
43
+ dependencyPaths: [...new Set(dependencyPaths)].sort(),
44
+ };
45
+ try {
46
+ await writeFile(temporary, `${JSON.stringify(marker)}\n`, {
47
+ encoding: "utf8",
48
+ mode: 0o600,
49
+ });
50
+ await rename(temporary, path);
51
+ }
52
+ finally {
53
+ await rm(temporary, { force: true }).catch(() => undefined);
54
+ }
55
+ }
56
+ export async function clearPreparationMarker(repository, repositoryRoot) {
57
+ const path = await preparationMarkerPath(repository, repositoryRoot);
58
+ await rm(path, { force: true });
59
+ }
60
+ export async function hasPreparationMarker(repository, repositoryRoot) {
61
+ const path = await preparationMarkerPath(repository, repositoryRoot);
62
+ try {
63
+ await lstat(path);
64
+ return true;
65
+ }
66
+ catch (error) {
67
+ if (error !== null &&
68
+ typeof error === "object" &&
69
+ "code" in error &&
70
+ error.code === "ENOENT") {
71
+ return false;
72
+ }
73
+ throw error;
74
+ }
75
+ }
76
+ //# sourceMappingURL=preparation-marker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preparation-marker.js","sourceRoot":"","sources":["../../src/lifecycle/preparation-marker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EACL,KAAK,EACL,KAAK,EACL,QAAQ,EACR,MAAM,EACN,EAAE,EACF,SAAS,GACV,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAItD,MAAM,WAAW,GAAG,6BAA6B,CAAC;AAGlD,SAAS,UAAU,CAAC,cAAsB,EAAE,OAAe;IACzD,OAAO,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;AAC1E,CAAC;AAED,sFAAsF;AACtF,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,UAAyB,EACzB,cAAsB;IAEtB,MAAM,IAAI,GAAG,CACX,MAAM,UAAU,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,YAAY,EAAE,WAAW,CAAC,CAAC,CAC/D,CAAC,IAAI,EAAE,CAAC;IACT,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QACnB,MAAM,IA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AQ;YACzB,MAAM,IAAI,KAAK;YACf,KAAK,CAAC,IAAI,KAAK,QAAQ,EACvB,CAAC;YACD,OAAO,KAAK,CAAC;QACf,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport {\n lstat,\n mkdir,\n readFile,\n rename,\n rm,\n writeFile,\n} from \"node:fs/promises\";\nimport { isAbsolute, join, resolve } from \"node:path\";\nimport type { DependencyPreparationValue } from \"@ebay-dt/bonfire-core\";\nimport type { GitRepository } from \"../git-repository.js\";\n\nconst MARKER_NAME = \"bonfire-preparation-pending\";\ntype Marker = { version: 1; dependencyPaths: readonly string[] };\n\nfunction markerPath(repositoryRoot: string, gitPath: string) {\n return isAbsolute(gitPath) ? gitPath : resolve(repositoryRoot, gitPath);\n}\n\n/** Resolve the marker through Git so worktrees and git-file repositories are safe. */\nexport async function preparationMarkerPath(\n repository: GitRepository,\n repositoryRoot: string,\n) {\n const path = (\n await repository.raw([\"rev-parse\", \"--git-path\", MARKER_NAME])\n ).trim();\n if (path.length === 0)\n throw new Error(\"Git returned an empty preparation marker path\");\n return markerPath(repositoryRoot, path);\n}\n\nexport async function readPreparationMarker(\n repository: GitRepository,\n repositoryRoot: string,\n): Promise<readonly string[] | null> {\n const path = await preparationMarkerPath(repository, repositoryRoot);\n try {\n const value = JSON.parse(await readFile(path, \"utf8\")) as Partial<Marker>;\n if (\n value.version !== 1 ||\n !Array.isArray(value.dependencyPaths) ||\n value.dependencyPaths.some((entry) => typeof entry !== \"string\")\n ) {\n throw new Error(\"Invalid preparation marker\");\n }\n return [...new Set(value.dependencyPaths)];\n } catch (error) {\n if (\n error !== null &&\n typeof error === \"object\" &&\n \"code\" in error &&\n error.code === \"ENOENT\"\n ) {\n return null;\n }\n throw error;\n }\n}\n\n/** Write before installation; rename makes the marker visible atomically. */\nexport async function writePreparationMarker(\n repository: GitRepository,\n repositoryRoot: string,\n dependencyPaths: readonly string[],\n) {\n const path = await preparationMarkerPath(repository, repositoryRoot);\n await mkdir(resolve(path, \"..\"), { recursive: true });\n const temporary = join(\n resolve(path, \"..\"),\n `.${MARKER_NAME}.${randomUUID()}.tmp`,\n );\n const marker: Marker = {\n version: 1,\n dependencyPaths: [...new Set(dependencyPaths)].sort(),\n };\n try {\n await writeFile(temporary, `${JSON.stringify(marker)}\\n`, {\n encoding: \"utf8\",\n mode: 0o600,\n });\n await rename(temporary, path);\n } finally {\n await rm(temporary, { force: true }).catch(() => undefined);\n }\n}\n\nexport async function clearPreparationMarker(\n repository: GitRepository,\n repositoryRoot: string,\n) {\n const path = await preparationMarkerPath(repository, repositoryRoot);\n await rm(path, { force: true });\n}\n\nexport async function hasPreparationMarker(\n repository: GitRepository,\n repositoryRoot: string,\n) {\n const path = await preparationMarkerPath(repository, repositoryRoot);\n try {\n await lstat(path);\n return true;\n } catch (error) {\n if (\n error !== null &&\n typeof error === \"object\" &&\n \"code\" in error &&\n error.code === \"ENOENT\"\n ) {\n return false;\n }\n throw error;\n }\n}\n\nexport type DependencyInstaller = (repositoryRoot: string) => Promise<void>;\nexport type DependencyPreparationResult = DependencyPreparationValue;\n"]}
@@ -0,0 +1,18 @@
1
+ import { type GitRepository } from "../git-repository.js";
2
+ export type PrototypePathPlan = {
3
+ eligiblePaths: readonly string[];
4
+ trackedEligiblePaths: readonly string[];
5
+ changedEligiblePaths: readonly string[];
6
+ newEligiblePaths: readonly string[];
7
+ stagedEligiblePaths: readonly string[];
8
+ existingEligiblePaths: readonly string[];
9
+ protectedPaths: readonly string[];
10
+ trackedProtectedPaths: readonly string[];
11
+ };
12
+ export declare function isProtectedPrototypePath(path: string): boolean;
13
+ export declare function isRegularPrototypeMode(mode: string | undefined): boolean;
14
+ export declare function inspectPrototypePath(repository: GitRepository, pathspec: string): Promise<PrototypePathPlan>;
15
+ export declare function commitPrototypePath(repository: GitRepository, pathspec: string, message: string): Promise<import("../git-repository.js").GitCommitResult>;
16
+ export declare function discardPrototypePath(repository: GitRepository, pathspec: string): Promise<void>;
17
+ export declare function deletePrototypePath(repository: GitRepository, pathspec: string, message?: string): Promise<import("../git-repository.js").GitCommitResult>;
18
+ //# sourceMappingURL=prototype-path-policy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prototype-path-policy.d.ts","sourceRoot":"","sources":["../../src/lifecycle/prototype-path-policy.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,aAAa,EAEnB,MAAM,sBAAsB,CAAC;AAsC9B,MAAM,MAAM,iBAAiB,GAAG;IAC9B,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,oBAAoB,EAAE,SAAS,MAAM,EAAE,CAAC;IACxC,oBAAoB,EAAE,SAAS,MAAM,EAAE,CAAC;IACxC,gBAAgB,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,mBAAmB,EAAE,SAAS,MAAM,EAAE,CAAC;IACvC,qBAAqB,EAAE,SAAS,MAAM,EAAE,CAAC;IACzC,cAAc,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,qBAAqB,EAAE,SAAS,MAAM,EAAE,CAAC;CAC1C,CAAC;AAqHF,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,WAYpD;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,WAE9D;AAoED,wBAAsB,oBAAoB,CACxC,UAAU,EAAE,aAAa,EACzB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,iBAAiB,CAAC,CAyI5B;AAED,wBAAsB,mBAAmB,CACvC,UAAU,EAAE,aAAa,EACzB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,2DAOhB;AAgFD,wBAAsB,oBAAoB,CACxC,UAAU,EAAE,aAAa,EACzB,QAAQ,EAAE,MAAM,iBAuBjB;AAED,wBAAsB,mBAAmB,CACvC,UAAU,EAAE,aAAa,EACzB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,MAAM,2DA0BjB","sourcesContent":["import { lstat, readdir, rmdir, unlink } from \"node:fs/promises\";\nimport { isAbsolute, join, relative, resolve, sep } from \"node:path\";\nimport {\n GitRepositoryError,\n type GitRepository,\n type GitStatusFile,\n} from \"../git-repository.js\";\n\nconst PROTECTED_DIRECTORY_NAMES = new Set([\n \".git\",\n \".next\",\n \".turbo\",\n \".vercel\",\n \"build\",\n \"coverage\",\n \"dist\",\n \"node_modules\",\n \"out\",\n]);\n\nconst PROTECTED_FILE_NAMES = new Set([\n \".env\",\n \"preferences.json\",\n \"id_rsa\",\n \"id_ed25519\",\n \"id_ecdsa\",\n \"id_dsa\",\n]);\n\nconst PROTECTED_FILE_EXTENSIONS = new Set([\".key\", \".pem\", \".p12\", \".pfx\"]);\n\nconst SYMLINK_MODE = \"120000\";\nconst REGULAR_MODE_PREFIX = \"100\";\n\ntype GitIndexEntry = {\n path: string;\n mode: string;\n};\n\ntype FilesystemEntry = {\n path: string;\n kind: \"directory\" | \"file\" | \"symlink\" | \"special\";\n};\n\nexport type PrototypePathPlan = {\n eligiblePaths: readonly string[];\n trackedEligiblePaths: readonly string[];\n changedEligiblePaths: readonly string[];\n newEligiblePaths: readonly string[];\n stagedEligiblePaths: readonly string[];\n existingEligiblePaths: readonly string[];\n protectedPaths: readonly string[];\n trackedProtectedPaths: readonly string[];\n};\n\nfunction assertPathspec(pathspec: string) {\n if (\n pathspec.length === 0 ||\n isAbsolute(pathspec) ||\n pathspec.startsWith(\"-\") ||\n pathspec.startsWith(\".\") ||\n pathspec.includes(\"\\\\\") ||\n pathspec.includes(\"\\0\") ||\n pathspec\n .split(\"/\")\n .some((segment) => segment.length === 0 || segment === \"..\")\n ) {\n throw new GitRepositoryError(\"invalid-configuration\", \"pathspec\");\n }\n}\n\nfunction normalizePath(path: string) {\n return path.replaceAll(\"\\\\\", \"/\").replace(/\\/+$/u, \"\");\n}\n\nfunction pathIsWithin(path: string, parent: string) {\n return path === parent || path.startsWith(`${parent}/`);\n}\n\nfunction statusPaths(file: GitStatusFile) {\n return [file.path, ...(file.from === undefined ? [] : [file.from])].map(\n normalizePath,\n );\n}\n\nfunction pathsOverlap(left: string, right: string) {\n return (\n left === right || pathIsWithin(left, right) || pathIsWithin(right, left)\n );\n}\n\nfunction parseNulPaths(output: string) {\n return output\n .split(\"\\0\")\n .filter(Boolean)\n .map((entry) => {\n const tab = entry.indexOf(\"\\t\");\n return normalizePath(tab < 0 ? entry : entry.slice(tab + 1));\n });\n}\n\nfunction parseIndexEntries(output: string): GitIndexEntry[] {\n return output\n .split(\"\\0\")\n .filter(Boolean)\n .flatMap((entry) => {\n const tab = entry.indexOf(\"\\t\");\n if (tab < 0) return [];\n const header = entry.slice(0, tab).split(/\\s+/u);\n const mode = header[0];\n const path = normalizePath(entry.slice(tab + 1));\n if (mode === undefined || path.length === 0) return [];\n return [{ mode, path }];\n });\n}\n\nfunction parseTreeEntries(output: string): GitIndexEntry[] {\n return output\n .split(\"\\0\")\n .filter(Boolean)\n .flatMap((entry) => {\n const tab = entry.indexOf(\"\\t\");\n if (tab < 0) return [];\n const header = entry.slice(0, tab).split(/\\s+/u);\n const mode = header[0];\n const path = normalizePath(entry.slice(tab + 1));\n if (mode === undefined || path.length === 0) return [];\n return [{ mode, path }];\n });\n}\n\nasync function gitPaths(\n repository: GitRepository,\n args: readonly string[],\n): Promise<string[]> {\n const output = await repository.raw([...args]);\n return parseNulPaths(output);\n}\n\nasync function gitIndexEntries(\n repository: GitRepository,\n pathspec: string,\n): Promise<GitIndexEntry[]> {\n return parseIndexEntries(\n await repository.raw([\"ls-files\", \"-s\", \"-z\", \"--\", pathspec]),\n );\n}\n\nasync function gitTreeEntries(\n repository: GitRepository,\n pathspec: string,\n): Promise<GitIndexEntry[]> {\n return parseTreeEntries(\n await repository.raw([\n \"ls-tree\",\n \"-r\",\n \"-z\",\n \"--full-tree\",\n \"HEAD\",\n \"--\",\n pathspec,\n ]),\n );\n}\n\nfunction basename(path: string) {\n const separator = path.lastIndexOf(\"/\");\n return separator < 0 ? path : path.slice(separator + 1);\n}\n\nexport function isProtectedPrototypePath(path: string) {\n const segments = path.split(\"/\");\n if (segments.some((segment) => PROTECTED_DIRECTORY_NAMES.has(segment))) {\n return true;\n }\n\n const name = basename(path);\n if (PROTECTED_FILE_NAMES.has(name)) return true;\n if (name.startsWith(\".env\") && !name.endsWith(\".example\")) return true;\n if (name.endsWith(\".local.json\")) return true;\n const extension = name.slice(name.lastIndexOf(\".\")).toLowerCase();\n return PROTECTED_FILE_EXTENSIONS.has(extension);\n}\n\nexport function isRegularPrototypeMode(mode: string | undefined) {\n return mode !== undefined && mode.startsWith(REGULAR_MODE_PREFIX);\n}\n\nconst isProtectedPath = isProtectedPrototypePath;\nconst isRegularMode = isRegularPrototypeMode;\n\nasync function walkFilesystem(\n root: string,\n pathspec: string,\n): Promise<FilesystemEntry[]> {\n const entries: FilesystemEntry[] = [];\n const absoluteRoot = resolve(root, ...pathspec.split(\"/\"));\n const rootRelative = relative(root, absoluteRoot).split(sep).join(\"/\");\n const visit = async (absolutePath: string, relativePath: string) => {\n let stats;\n try {\n stats = await lstat(absolutePath);\n } catch (error) {\n if (\n error &&\n typeof error === \"object\" &&\n \"code\" in error &&\n error.code === \"ENOENT\"\n ) {\n return;\n }\n throw error;\n }\n\n if (stats.isSymbolicLink()) {\n entries.push({ path: relativePath, kind: \"symlink\" });\n return;\n }\n if (stats.isDirectory()) {\n entries.push({ path: relativePath, kind: \"directory\" });\n if (relativePath !== rootRelative && isProtectedPath(relativePath))\n return;\n for (const entry of await readdir(absolutePath)) {\n const childPath = `${relativePath}/${entry}`;\n await visit(join(absolutePath, entry), childPath);\n }\n return;\n }\n entries.push({\n path: relativePath,\n kind: stats.isFile() ? \"file\" : \"special\",\n });\n };\n\n await visit(absoluteRoot, rootRelative);\n return entries;\n}\n\nfunction throwProtected(paths: readonly string[]) {\n if (paths.length > 0) {\n throw new GitRepositoryError(\"conflict\", \"protected-prototype-path\");\n }\n}\n\nfunction changedPaths(\n files: readonly GitStatusFile[],\n eligiblePaths: readonly string[],\n) {\n const status = files.flatMap(statusPaths);\n return eligiblePaths.filter((path) =>\n status.some((statusPath) => pathsOverlap(path, statusPath)),\n );\n}\n\nexport async function inspectPrototypePath(\n repository: GitRepository,\n pathspec: string,\n): Promise<PrototypePathPlan> {\n assertPathspec(pathspec);\n const normalizedPath = normalizePath(pathspec);\n const [status, indexEntries, treeEntries, untrackedPaths, filesystem] =\n await Promise.all([\n repository.status([normalizedPath]),\n gitIndexEntries(repository, normalizedPath),\n gitTreeEntries(repository, normalizedPath),\n gitPaths(repository, [\n \"ls-files\",\n \"--others\",\n \"--exclude-standard\",\n \"-z\",\n \"--\",\n normalizedPath,\n ]),\n walkFilesystem(repository.repositoryRoot, normalizedPath),\n ]);\n\n const indexModes = new Map(\n indexEntries.map((entry) => [entry.path, entry.mode]),\n );\n const treeModes = new Map(\n treeEntries.map((entry) => [entry.path, entry.mode]),\n );\n const filesystemEntries = new Map(\n filesystem.map((entry) => [entry.path, entry]),\n );\n const trackedPaths = new Set([...treeModes.keys(), ...indexModes.keys()]);\n const untracked = new Set(untrackedPaths);\n const eligible = new Set<string>();\n const trackedEligible = new Set<string>();\n const newPaths = new Set<string>();\n const stagedPaths = new Set<string>();\n const existing = new Set<string>();\n const protectedPaths = new Set<string>();\n const trackedProtectedPaths = new Set<string>();\n\n const classifyTracked = (path: string) => {\n const indexMode = indexModes.get(path);\n const treeMode = treeModes.get(path);\n if (\n isProtectedPath(path) ||\n (indexMode !== undefined && !isRegularMode(indexMode)) ||\n (treeMode !== undefined && !isRegularMode(treeMode))\n ) {\n protectedPaths.add(path);\n trackedProtectedPaths.add(path);\n return;\n }\n const filesystemEntry = filesystemEntries.get(path);\n if (filesystemEntry !== undefined && filesystemEntry.kind !== \"file\") {\n protectedPaths.add(path);\n trackedProtectedPaths.add(path);\n return;\n }\n eligible.add(path);\n trackedEligible.add(path);\n };\n\n for (const path of treeModes.keys()) classifyTracked(path);\n for (const path of indexModes.keys()) {\n if (treeModes.has(path)) {\n classifyTracked(path);\n } else if (\n isProtectedPath(path) ||\n !isRegularMode(indexModes.get(path)) ||\n (filesystemEntries.get(path) !== undefined &&\n filesystemEntries.get(path)?.kind !== \"file\")\n ) {\n protectedPaths.add(path);\n trackedProtectedPaths.add(path);\n } else {\n eligible.add(path);\n newPaths.add(path);\n stagedPaths.add(path);\n }\n }\n\n for (const entry of filesystem) {\n const path = entry.path;\n if (entry.kind === \"directory\") {\n if (path !== normalizedPath && isProtectedPath(path)) {\n protectedPaths.add(path);\n }\n continue;\n }\n if (entry.kind !== \"file\") {\n protectedPaths.add(path);\n if (trackedPaths.has(path)) trackedProtectedPaths.add(path);\n continue;\n }\n\n if (trackedPaths.has(path)) {\n if (isProtectedPath(path)) {\n protectedPaths.add(path);\n trackedProtectedPaths.add(path);\n } else if (\n !isRegularMode(indexModes.get(path) ?? treeModes.get(path)) ||\n indexModes.get(path) === SYMLINK_MODE ||\n treeModes.get(path) === SYMLINK_MODE\n ) {\n protectedPaths.add(path);\n trackedProtectedPaths.add(path);\n } else {\n eligible.add(path);\n existing.add(path);\n }\n continue;\n }\n\n // Files absent from --exclude-standard are ignored content. Leave them\n // alone without making Delete fail on them.\n if (!untracked.has(path)) {\n if (isProtectedPath(path)) protectedPaths.add(path);\n continue;\n }\n if (isProtectedPath(path)) {\n protectedPaths.add(path);\n } else {\n eligible.add(path);\n newPaths.add(path);\n existing.add(path);\n }\n }\n\n const eligiblePaths = [...eligible].sort();\n return {\n eligiblePaths,\n trackedEligiblePaths: [...trackedEligible].sort(),\n changedEligiblePaths: changedPaths(status.files, eligiblePaths),\n newEligiblePaths: [...newPaths].sort(),\n stagedEligiblePaths: [...stagedPaths].sort(),\n existingEligiblePaths: [...existing].sort(),\n protectedPaths: [...protectedPaths].sort(),\n trackedProtectedPaths: [...trackedProtectedPaths].sort(),\n };\n}\n\nexport async function commitPrototypePath(\n repository: GitRepository,\n pathspec: string,\n message: string,\n) {\n const plan = await inspectPrototypePath(repository, pathspec);\n throwProtected(plan.trackedProtectedPaths);\n if (plan.changedEligiblePaths.length === 0) return null;\n await repository.add(plan.changedEligiblePaths);\n return repository.commit(message, plan.changedEligiblePaths);\n}\n\nasync function assertSafeParents(\n repository: GitRepository,\n absolutePath: string,\n) {\n const relativePath = relative(repository.repositoryRoot, absolutePath);\n const segments = relativePath.split(sep);\n let current = repository.repositoryRoot;\n for (const segment of segments.slice(0, -1)) {\n current = join(current, segment);\n const stats = await lstat(current);\n if (stats.isSymbolicLink() || !stats.isDirectory()) {\n throw new GitRepositoryError(\"conflict\", \"prototype-path-changed\");\n }\n }\n}\n\nasync function removeFiles(\n repository: GitRepository,\n paths: readonly string[],\n) {\n for (const path of paths) {\n const absolutePath = resolve(repository.repositoryRoot, ...path.split(\"/\"));\n await assertSafeParents(repository, absolutePath);\n let stats;\n try {\n stats = await lstat(absolutePath);\n } catch (error) {\n if (\n error &&\n typeof error === \"object\" &&\n \"code\" in error &&\n error.code === \"ENOENT\"\n ) {\n continue;\n }\n throw error;\n }\n if (!stats.isFile() || stats.isSymbolicLink()) {\n throw new GitRepositoryError(\"conflict\", \"prototype-path-changed\");\n }\n await unlink(absolutePath);\n }\n}\n\nasync function removeEmptyDirectories(\n repository: GitRepository,\n pathspec: string,\n) {\n const root = resolve(repository.repositoryRoot, ...pathspec.split(\"/\"));\n const directories: string[] = [];\n const visit = async (absolutePath: string) => {\n let stats;\n try {\n stats = await lstat(absolutePath);\n } catch {\n return;\n }\n if (stats.isSymbolicLink() || !stats.isDirectory()) return;\n const relativePath = relative(repository.repositoryRoot, absolutePath)\n .split(sep)\n .join(\"/\");\n if (relativePath !== pathspec && isProtectedPath(relativePath)) return;\n for (const entry of await readdir(absolutePath)) {\n await visit(join(absolutePath, entry));\n }\n directories.push(absolutePath);\n };\n await visit(root);\n for (const directory of directories) {\n try {\n await assertSafeParents(repository, directory);\n await rmdir(directory);\n } catch {\n // Non-empty directories contain protected or unrelated content.\n }\n }\n}\n\nexport async function discardPrototypePath(\n repository: GitRepository,\n pathspec: string,\n) {\n const plan = await inspectPrototypePath(repository, pathspec);\n if (\n plan.changedEligiblePaths.length === 0 &&\n plan.newEligiblePaths.length === 0\n ) {\n return;\n }\n\n const trackedChanged = plan.changedEligiblePaths.filter((path) =>\n plan.trackedEligiblePaths.includes(path),\n );\n const stagedAdditions = plan.stagedEligiblePaths;\n if (stagedAdditions.length > 0) {\n await repository.raw([\"reset\", \"HEAD\", \"--\", ...stagedAdditions]);\n }\n if (trackedChanged.length > 0) {\n await repository.raw([\"reset\", \"HEAD\", \"--\", ...trackedChanged]);\n await repository.restore(trackedChanged);\n }\n await removeFiles(repository, plan.newEligiblePaths);\n await removeEmptyDirectories(repository, pathspec);\n}\n\nexport async function deletePrototypePath(\n repository: GitRepository,\n pathspec: string,\n message?: string,\n) {\n const before = await inspectPrototypePath(repository, pathspec);\n // Untracked excluded files can safely remain in place while ordinary\n // prototype content is deleted. Tracked exclusions still block because\n // staging their surrounding type/deletion could silently alter protected\n // repository state.\n throwProtected(before.trackedProtectedPaths);\n if (before.stagedEligiblePaths.length > 0) {\n await repository.raw([\n \"reset\",\n \"HEAD\",\n \"--\",\n ...before.stagedEligiblePaths,\n ]);\n }\n await removeFiles(repository, before.existingEligiblePaths);\n await removeEmptyDirectories(repository, pathspec);\n\n const after = await inspectPrototypePath(repository, pathspec);\n throwProtected(after.trackedProtectedPaths);\n if (message === undefined || after.trackedEligiblePaths.length === 0) {\n return null;\n }\n await repository.add(after.trackedEligiblePaths);\n return repository.commit(message, after.trackedEligiblePaths);\n}\n"]}