@ebay-dt/bonfire-node 0.2.0-alpha.10 → 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.
- package/README.md +18 -5
- package/dist/deployment-provider.d.ts +1 -1
- package/dist/deployment-provider.d.ts.map +1 -1
- package/dist/deployment-provider.js +1 -1
- package/dist/deployment-provider.js.map +1 -1
- package/dist/duplicate.d.ts.map +1 -1
- package/dist/duplicate.js +103 -47
- package/dist/duplicate.js.map +1 -1
- package/dist/git-repository.d.ts +14 -1
- package/dist/git-repository.d.ts.map +1 -1
- package/dist/git-repository.js +99 -3
- package/dist/git-repository.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/internal/prototype-templates.d.ts +0 -1
- package/dist/internal/prototype-templates.d.ts.map +1 -1
- package/dist/internal/prototype-templates.js +0 -5
- package/dist/internal/prototype-templates.js.map +1 -1
- package/dist/lifecycle/deployment-worktree.d.ts +5 -4
- package/dist/lifecycle/deployment-worktree.d.ts.map +1 -1
- package/dist/lifecycle/deployment-worktree.js +269 -68
- package/dist/lifecycle/deployment-worktree.js.map +1 -1
- package/dist/lifecycle/local-prototype-lifecycle.d.ts +13 -1
- package/dist/lifecycle/local-prototype-lifecycle.d.ts.map +1 -1
- package/dist/lifecycle/local-prototype-lifecycle.js +634 -110
- package/dist/lifecycle/local-prototype-lifecycle.js.map +1 -1
- package/dist/lifecycle/preparation-marker.d.ts +12 -0
- package/dist/lifecycle/preparation-marker.d.ts.map +1 -0
- package/dist/lifecycle/preparation-marker.js +76 -0
- package/dist/lifecycle/preparation-marker.js.map +1 -0
- package/dist/lifecycle/prototype-path-policy.d.ts +18 -0
- package/dist/lifecycle/prototype-path-policy.d.ts.map +1 -0
- package/dist/lifecycle/prototype-path-policy.js +429 -0
- package/dist/lifecycle/prototype-path-policy.js.map +1 -0
- package/dist/lifecycle/repository-summary.d.ts +5 -1
- package/dist/lifecycle/repository-summary.d.ts.map +1 -1
- package/dist/lifecycle/repository-summary.js +6 -0
- package/dist/lifecycle/repository-summary.js.map +1 -1
- package/dist/lifecycle/repository-synchronization.d.ts +13 -9
- package/dist/lifecycle/repository-synchronization.d.ts.map +1 -1
- package/dist/lifecycle/repository-synchronization.js +670 -173
- package/dist/lifecycle/repository-synchronization.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"git-repository.js","sourceRoot":"","sources":["../src/git-repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EACL,SAAS,EACT,gBAAgB,EAChB,iBAAiB,EACjB,QAAQ,GACT,MAAM,qBAAqB,CAAC;AAE7B,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAClC,MAAM,gCAAgC,GAAG,CAAC,CAAC;AAC3C,MAAM,uBAAuB,GAAG;IAC9B,IAAI,EAAE,SAAS;IACf,KAAK,EAAE,mBAAmB;CAC3B,CAAC;AACF,MAAM,0BAA0B,GAAG;IACjC,mBAAmB;IACnB,yBAAyB;CAC1B,CAAC;AA4DF,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAClC,IAAI,CAAyB;IAC7B,SAAS,CAAS;IAE3B,YAAY,IAA4B,EAAE,SAAiB;QACzD,KAAK,CAAC,yBAAyB,SAAS,EAAE,CAAC,CAAC;QAC5C,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;QACjC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;CACF;AA2BD,SAAS,aAAa,CAAC,KAAc;IACnC,IAAI,KAAK,YAAY,kBAAkB;QAAE,OAAO,KAAK,CAAC,IAAI,CAAC;IAE3D,MAAM,OAAO,GAAG,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AAgB,EAAE,EAAE,CAAC,gBAAgB,CAAC,IAAI,KAAK,MAAM,CACvD,CAAC;IACF,IAAI,CAAC,SAAS;QAAE,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,CAAC;IAEtD,MAAM,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,gBAAgB,CAAC,CAAC,CAAC;IAC1D,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,mBAAmB,CACjC,OAA6B;IAE7B,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,CAAC;QACxC,MAAM,IAAI,kBAAkB,CAAC,uBAAuB,EAAE,iBAAiB,CAAC,CAAC;IAC3E,CAAC;IAED,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,kBAAkB,CAAC;IAC1D,MAAM,sBAAsB,GAC1B,OAAO,CAAC,sBAAsB,IAAI,gCAAgC,CAAC;IACrE,MAAM,cAAc,GAAG,OAAO,CAAC,cAAc,IAAI,uBAAuB,CAAC;IAEzE,0BAA0B,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IACjD,0BAA0B,CACxB,sBAAsB,EACtB,0BAA0B,CAC3B,CAAC;IAEF,OAAO,IAAI,mBAAmB,CAAC;QAC7B,cAAc,EAAE,OAAO,CAAC,cAAc;QACtC,SAAS;QACT,sBAAsB;QACtB,cAAc;KACf,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { isAbsolute } from \"node:path\";\nimport { simpleGit } from \"simple-git\";\nimport {\n asFailure,\n isNonEmptyString,\n isPositiveInteger,\n isRecord,\n} from \"./internal/utils.js\";\n\nconst DEFAULT_TIMEOUT_MS = 30_000;\nconst DEFAULT_MAX_CONCURRENT_PROCESSES = 1;\nconst DEFAULT_COMMIT_IDENTITY = {\n name: \"Bonfire\",\n email: \"bonfire@localhost\",\n};\nconst NOTHING_TO_COMMIT_MESSAGES = [\n \"nothing to commit\",\n \"nothing added to commit\",\n];\n\nexport type GitCommitIdentity = {\n name: string;\n email: string;\n};\n\nexport type GitRepositoryOptions = {\n repositoryRoot: string;\n timeoutMs?: number;\n maxConcurrentProcesses?: number;\n commitIdentity?: GitCommitIdentity;\n};\n\nexport type GitStatusFile = {\n path: string;\n index: string;\n workingDirectory: string;\n from?: string;\n};\n\nexport type GitStatusSnapshot = {\n current: string | null;\n files: readonly GitStatusFile[];\n clean: boolean;\n};\n\nexport type GitRemoteSnapshot = {\n name: string;\n fetchUrl: string | null;\n pushUrl: string | null;\n};\n\nexport type GitBranchSnapshot = {\n current: string | null;\n all: readonly string[];\n};\n\nexport type GitCommitSnapshot = {\n branch: string;\n commit: string;\n root: boolean;\n};\n\nexport type GitCommitResult = GitCommitSnapshot | null;\n\nexport type GitPushResult = {\n remoteStatus: \"pushed\" | \"local-only\";\n};\n\nexport type GitRepositoryErrorKind =\n | \"missing-git\"\n | \"timeout\"\n | \"conflict\"\n | \"non-fast-forward\"\n | \"command-failure\"\n | \"malformed-output\"\n | \"invalid-configuration\"\n | \"unexpected\";\n\nexport class GitRepositoryError extends Error {\n readonly kind: GitRepositoryErrorKind;\n readonly operation: string;\n\n constructor(kind: GitRepositoryErrorKind, operation: string) {\n super(`Git operation failed: ${operation}`);\n this.name = \"GitRepositoryError\";\n this.kind = kind;\n this.operation = operation;\n }\n}\n\nexport interface GitRepository {\n readonly repositoryRoot: string;\n currentBranch(): Promise<string>;\n status(pathspecs?: readonly string[]): Promise<GitStatusSnapshot>;\n remotes(): Promise<readonly GitRemoteSnapshot[]>;\n branches(): Promise<GitBranchSnapshot>;\n fetch(remote: string, branch?: string): Promise<void>;\n checkout(args: readonly string[]): Promise<void>;\n checkoutLocalBranch(branch: string): Promise<void>;\n merge(args: readonly string[]): Promise<void>;\n add(pathspecs: readonly string[]): Promise<void>;\n commit(\n message: string,\n pathspecs?: readonly string[],\n ): Promise<GitCommitResult>;\n push(\n remote: string,\n branch: string,\n options?: readonly string[],\n ): Promise<void>;\n restore(pathspecs: readonly string[]): Promise<void>;\n clean(mode: string, pathspecs: readonly string[]): Promise<void>;\n raw(args: readonly string[]): Promise<string>;\n}\n\nfunction classifyError(error: unknown): GitRepositoryErrorKind {\n if (error instanceof GitRepositoryError) return error.kind;\n\n const failure = asFailure(error);\n const message = typeof failure.message === \"string\" ? failure.message : \"\";\n const normalized = message.toLowerCase();\n\n if (failure.code === \"ENOENT\" || normalized.includes(\"enoent\")) {\n return \"missing-git\";\n }\n\n if (\n failure.code === \"ETIMEDOUT\" ||\n failure.killed === true ||\n failure.signal === \"SIGTERM\" ||\n normalized.includes(\"timed out\") ||\n normalized.includes(\"timeout\")\n ) {\n return \"timeout\";\n }\n\n if (\n normalized.includes(\"conflict\") ||\n normalized.includes(\"would be overwritten\") ||\n normalized.includes(\"unmerged paths\")\n ) {\n return \"conflict\";\n }\n\n if (\n normalized.includes(\"non-fast-forward\") ||\n normalized.includes(\"fetch first\") ||\n normalized.includes(\"stale info\")\n ) {\n return \"non-fast-forward\";\n }\n\n if (isRecord(error) || error instanceof Error) return \"command-failure\";\n return \"unexpected\";\n}\n\nfunction normalizeError(operation: string, error: unknown) {\n if (error instanceof GitRepositoryError) return error;\n return new GitRepositoryError(classifyError(error), operation);\n}\n\nfunction assertValidPositiveInteger(value: number, option: string) {\n if (!isPositiveInteger(value)) {\n throw new GitRepositoryError(\"invalid-configuration\", option);\n }\n}\n\nfunction assertValidBranchName(value: string, option: string) {\n if (\n !isNonEmptyString(value) ||\n value.startsWith(\"-\") ||\n value.includes(\"\\0\") ||\n /\\s/u.test(value) ||\n value.includes(\"@{\") ||\n value.split(/[\\\\/]/u).some((segment) => segment === \"..\")\n ) {\n throw new GitRepositoryError(\"invalid-configuration\", option);\n }\n}\n\nfunction assertValidPathspec(pathspec: string) {\n if (\n !isNonEmptyString(pathspec) ||\n isAbsolute(pathspec) ||\n /^[A-Za-z]:[\\\\/]/u.test(pathspec) ||\n pathspec.startsWith(\"\\\\\") ||\n pathspec.startsWith(\"-\") ||\n pathspec.startsWith(\":\") ||\n pathspec.includes(\"\\0\") ||\n pathspec.includes(\"*\") ||\n pathspec.includes(\"?\") ||\n pathspec.includes(\"[\") ||\n pathspec.includes(\"]\") ||\n pathspec === \".\" ||\n pathspec.split(/[\\\\/]/u).some((segment) => segment === \"..\")\n ) {\n throw new GitRepositoryError(\"invalid-configuration\", \"pathspec\");\n }\n}\n\nfunction assertValidPathspecs(pathspecs: readonly string[]) {\n if (pathspecs.length === 0) {\n throw new GitRepositoryError(\"invalid-configuration\", \"pathspec\");\n }\n for (const pathspec of pathspecs) assertValidPathspec(pathspec);\n return [...pathspecs];\n}\n\nfunction assertValidArguments(args: readonly string[], operation: string) {\n if (\n args.some(\n (argument) => !isNonEmptyString(argument) || argument.includes(\"\\0\"),\n )\n ) {\n throw new GitRepositoryError(\"invalid-configuration\", operation);\n }\n return [...args];\n}\n\nfunction isNothingToCommit(error: unknown) {\n const failure = asFailure(error);\n const message = typeof failure.message === \"string\" ? failure.message : \"\";\n return NOTHING_TO_COMMIT_MESSAGES.some((needle) =>\n message.toLowerCase().includes(needle),\n );\n}\n\nclass SimpleGitRepository implements GitRepository {\n readonly repositoryRoot: string;\n readonly #git;\n\n constructor(options: Required<GitRepositoryOptions>) {\n this.repositoryRoot = options.repositoryRoot;\n this.#git = simpleGit(options.repositoryRoot, {\n baseDir: options.repositoryRoot,\n maxConcurrentProcesses: options.maxConcurrentProcesses,\n config: [\n `user.name=${options.commitIdentity.name}`,\n `user.email=${options.commitIdentity.email}`,\n ],\n timeout: { block: options.timeoutMs },\n });\n }\n\n async #execute<Value>(operation: string, action: () => Promise<Value>) {\n try {\n return await action();\n } catch (error) {\n throw normalizeError(operation, error);\n }\n }\n\n async currentBranch() {\n const result = await this.#execute(\"current-branch\", () =>\n this.#git.revparse([\"--abbrev-ref\", \"HEAD\"]),\n );\n if (!isNonEmptyString(result) || result.trim().length === 0) {\n throw new GitRepositoryError(\"malformed-output\", \"current-branch\");\n }\n return result.trim();\n }\n\n async status(pathspecs?: readonly string[]) {\n const validatedPathspecs =\n pathspecs === undefined ? undefined : assertValidPathspecs(pathspecs);\n const result = await this.#execute(\"status\", () =>\n validatedPathspecs === undefined\n ? this.#git.status()\n : this.#git.status([\"--\", ...validatedPathspecs]),\n );\n\n if (\n !isRecord(result) ||\n !Array.isArray(result.files) ||\n (typeof result.current !== \"string\" && result.current !== null) ||\n typeof result.isClean !== \"function\"\n ) {\n throw new GitRepositoryError(\"malformed-output\", \"status\");\n }\n\n const files: GitStatusFile[] = [];\n for (const file of result.files) {\n if (!isRecord(file)) {\n throw new GitRepositoryError(\"malformed-output\", \"status\");\n }\n if (\n typeof file.path !== \"string\" ||\n typeof file.index !== \"string\" ||\n typeof file.working_dir !== \"string\"\n ) {\n throw new GitRepositoryError(\"malformed-output\", \"status\");\n }\n\n files.push({\n path: file.path,\n index: file.index,\n workingDirectory: file.working_dir,\n ...(typeof file.from === \"string\" ? { from: file.from } : {}),\n });\n }\n\n let clean: boolean;\n try {\n clean = result.isClean();\n } catch {\n throw new GitRepositoryError(\"malformed-output\", \"status\");\n }\n if (typeof clean !== \"boolean\") {\n throw new GitRepositoryError(\"malformed-output\", \"status\");\n }\n\n return {\n current: result.current,\n files,\n clean,\n } satisfies GitStatusSnapshot;\n }\n\n async remotes() {\n const result = await this.#execute(\"remotes\", () =>\n this.#git.getRemotes(true),\n );\n if (!Array.isArray(result)) {\n throw new GitRepositoryError(\"malformed-output\", \"remotes\");\n }\n\n const remotes: GitRemoteSnapshot[] = [];\n for (const remote of result) {\n if (!isRecord(remote) || typeof remote.name !== \"string\") {\n throw new GitRepositoryError(\"malformed-output\", \"remotes\");\n }\n const refs = remote.refs;\n if (!isRecord(refs)) {\n throw new GitRepositoryError(\"malformed-output\", \"remotes\");\n }\n if (typeof refs.fetch !== \"string\" || typeof refs.push !== \"string\") {\n throw new GitRepositoryError(\"malformed-output\", \"remotes\");\n }\n\n remotes.push({\n name: remote.name,\n fetchUrl: refs.fetch,\n pushUrl: refs.push,\n });\n }\n return remotes;\n }\n\n async branches() {\n const result = await this.#execute(\"branches\", () =>\n this.#git.branch([\"-a\"]),\n );\n if (\n !isRecord(result) ||\n !Array.isArray(result.all) ||\n (typeof result.current !== \"string\" && result.current !== null) ||\n !result.all.every((branch) => typeof branch === \"string\")\n ) {\n throw new GitRepositoryError(\"malformed-output\", \"branches\");\n }\n\n return {\n current: result.current,\n all: [...result.all],\n } satisfies GitBranchSnapshot;\n }\n\n async fetch(remote: string, branch?: string) {\n assertValidBranchName(remote, \"remote\");\n if (branch !== undefined) assertValidBranchName(branch, \"branch\");\n await this.#execute(\"fetch\", () =>\n branch === undefined\n ? this.#git.fetch(remote)\n : this.#git.fetch(remote, branch),\n );\n }\n\n async checkout(args: readonly string[]) {\n const validatedArgs = assertValidArguments(args, \"checkout\");\n await this.#execute(\"checkout\", () => this.#git.checkout(validatedArgs));\n }\n\n async checkoutLocalBranch(branch: string) {\n assertValidBranchName(branch, \"branch\");\n await this.#execute(\"checkout-local-branch\", () =>\n this.#git.checkoutLocalBranch(branch),\n );\n }\n\n async merge(args: readonly string[]) {\n const validatedArgs = assertValidArguments(args, \"merge\");\n await this.#execute(\"merge\", () => this.#git.merge(validatedArgs));\n }\n\n async add(pathspecs: readonly string[]) {\n const validatedPathspecs = assertValidPathspecs(pathspecs);\n await this.#execute(\"add\", () => this.#git.add(validatedPathspecs));\n }\n\n async commit(message: string, pathspecs?: readonly string[]) {\n if (!isNonEmptyString(message)) {\n throw new GitRepositoryError(\"invalid-configuration\", \"commit-message\");\n }\n const validatedPathspecs =\n pathspecs === undefined ? undefined : assertValidPathspecs(pathspecs);\n\n let result: unknown;\n try {\n result =\n validatedPathspecs === undefined\n ? await this.#git.commit(message)\n : await this.#git.commit(message, [...validatedPathspecs]);\n } catch (error) {\n if (isNothingToCommit(error)) return null;\n throw normalizeError(\"commit\", error);\n }\n if (\n !isRecord(result) ||\n typeof result.branch !== \"string\" ||\n typeof result.commit !== \"string\" ||\n typeof result.root !== \"boolean\"\n ) {\n throw new GitRepositoryError(\"malformed-output\", \"commit\");\n }\n\n return {\n branch: result.branch,\n commit: result.commit,\n root: result.root,\n } satisfies GitCommitSnapshot;\n }\n\n async push(remote: string, branch: string, options: readonly string[] = []) {\n assertValidBranchName(remote, \"remote\");\n assertValidBranchName(branch, \"branch\");\n const validatedOptions = assertValidArguments(options, \"push\");\n await this.#execute(\"push\", () =>\n this.#git.push(remote, branch, validatedOptions),\n );\n }\n\n async restore(pathspecs: readonly string[]) {\n const validatedPathspecs = assertValidPathspecs(pathspecs);\n await this.#execute(\"restore\", () =>\n this.#git.checkout([\"--\", ...validatedPathspecs]),\n );\n }\n\n async clean(mode: string, pathspecs: readonly string[]) {\n if (!/^[a-z]+$/u.test(mode)) {\n throw new GitRepositoryError(\"invalid-configuration\", \"clean-mode\");\n }\n const validatedPathspecs = assertValidPathspecs(pathspecs);\n await this.#execute(\"clean\", () =>\n this.#git.clean(mode, validatedPathspecs),\n );\n }\n\n async raw(args: readonly string[]) {\n const validatedArgs = assertValidArguments(args, \"raw\");\n const result = await this.#execute(\"raw\", () =>\n this.#git.raw(validatedArgs),\n );\n if (typeof result !== \"string\") {\n throw new GitRepositoryError(\"malformed-output\", \"raw\");\n }\n return result;\n }\n}\n\nexport type PrepareIdentityBranchOptions = {\n identityBranch: string;\n primaryBranch: string;\n remote: string;\n};\n\nexport async function prepareIdentityBranch(\n repository: GitRepository,\n options: PrepareIdentityBranchOptions,\n): Promise<void> {\n assertValidBranchName(options.identityBranch, \"identity-branch\");\n assertValidBranchName(options.primaryBranch, \"primary-branch\");\n assertValidBranchName(options.remote, \"remote\");\n\n const currentBranch = await repository.currentBranch();\n if (currentBranch === options.identityBranch) return;\n\n const status = await repository.status();\n if (!status.clean) {\n throw new GitRepositoryError(\"conflict\", \"prepare-identity-branch\");\n }\n\n const remotes = await repository.remotes();\n const configuredRemote = remotes.some(\n (remote) => remote.name === options.remote,\n );\n if (configuredRemote) {\n await repository.fetch(options.remote, options.primaryBranch);\n }\n\n const branches = await repository.branches();\n const hasLocalPrimary = branches.all.includes(options.primaryBranch);\n const remotePrimary = `remotes/${options.remote}/${options.primaryBranch}`;\n const hasRemotePrimary =\n configuredRemote && branches.all.includes(remotePrimary);\n if (!hasLocalPrimary && !hasRemotePrimary) {\n throw new GitRepositoryError(\"command-failure\", \"primary-branch\");\n }\n\n if (hasLocalPrimary) {\n await repository.checkout([options.primaryBranch]);\n } else {\n await repository.checkout([\n \"-b\",\n options.primaryBranch,\n \"--track\",\n `${options.remote}/${options.primaryBranch}`,\n ]);\n }\n if (configuredRemote) {\n await repository.merge([\n `${options.remote}/${options.primaryBranch}`,\n \"--ff-only\",\n ]);\n }\n\n if (branches.all.includes(options.identityBranch)) {\n await repository.checkout([options.identityBranch]);\n return;\n }\n\n const remoteBranch = `remotes/${options.remote}/${options.identityBranch}`;\n if (branches.all.includes(remoteBranch)) {\n await repository.checkout([\n \"-b\",\n options.identityBranch,\n \"--track\",\n `${options.remote}/${options.identityBranch}`,\n ]);\n return;\n }\n\n await repository.checkoutLocalBranch(options.identityBranch);\n}\n\nexport async function commitPath(\n repository: GitRepository,\n pathspec: string,\n message: string,\n): Promise<GitCommitResult> {\n const validatedPathspecs = assertValidPathspecs([pathspec]);\n await repository.add(validatedPathspecs);\n return repository.commit(message, validatedPathspecs);\n}\n\nexport async function discardPath(\n repository: GitRepository,\n pathspec: string,\n): Promise<void> {\n const validatedPathspec = assertValidPathspecs([pathspec])[0]!;\n await repository.raw([\"reset\", \"HEAD\", \"--\", validatedPathspec]);\n await repository.restore([validatedPathspec]);\n await repository.clean(\"fd\", [validatedPathspec]);\n}\n\nexport async function restorePathFromRef(\n repository: GitRepository,\n ref: string,\n pathspec: string,\n): Promise<void> {\n assertValidArguments([ref], \"restore-ref\");\n const validatedPathspec = assertValidPathspecs([pathspec])[0]!;\n await repository.raw([\n \"restore\",\n \"--source\",\n ref,\n \"--staged\",\n \"--worktree\",\n \"--\",\n validatedPathspec,\n ]);\n}\n\nexport async function pushCommitToBranch(\n repository: GitRepository,\n remote: string,\n commit: string,\n branch: string,\n): Promise<GitPushResult> {\n assertValidBranchName(remote, \"remote\");\n assertValidBranchName(branch, \"branch\");\n if (!/^[0-9a-f]{40,64}$/iu.test(commit)) {\n throw new GitRepositoryError(\"invalid-configuration\", \"commit\");\n }\n\n const hasRemote = (await repository.remotes()).some(\n (configuredRemote) => configuredRemote.name === remote,\n );\n if (!hasRemote) return { remoteStatus: \"local-only\" };\n\n await repository.raw([\"push\", remote, `${commit}:refs/heads/${branch}`]);\n return { remoteStatus: \"pushed\" };\n}\n\nexport async function pushBranch(\n repository: GitRepository,\n remote: string,\n branch: string,\n): Promise<GitPushResult> {\n assertValidBranchName(remote, \"remote\");\n assertValidBranchName(branch, \"branch\");\n\n const hasRemote = (await repository.remotes()).some(\n (configuredRemote) => configuredRemote.name === remote,\n );\n if (!hasRemote) return { remoteStatus: \"local-only\" };\n\n await repository.push(remote, branch, [\"--set-upstream\"]);\n return { remoteStatus: \"pushed\" };\n}\n\nexport function createGitRepository(\n options: GitRepositoryOptions,\n): GitRepository {\n if (!isAbsolute(options.repositoryRoot)) {\n throw new GitRepositoryError(\"invalid-configuration\", \"repository-root\");\n }\n\n const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;\n const maxConcurrentProcesses =\n options.maxConcurrentProcesses ?? DEFAULT_MAX_CONCURRENT_PROCESSES;\n const commitIdentity = options.commitIdentity ?? DEFAULT_COMMIT_IDENTITY;\n\n assertValidPositiveInteger(timeoutMs, \"timeout\");\n assertValidPositiveInteger(\n maxConcurrentProcesses,\n \"max-concurrent-processes\",\n );\n\n return new SimpleGitRepository({\n repositoryRoot: options.repositoryRoot,\n timeoutMs,\n maxConcurrentProcesses,\n commitIdentity,\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"git-repository.js","sourceRoot":"","sources":["../src/git-repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAA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C1D,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,mBAAmB,CACjC,OAA6B;IAE7B,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,CAAC;QACxC,MAAM,IAAI,kBAAkB,CAAC,uBAAuB,EAAE,iBAAiB,CAAC,CAAC;IAC3E,CAAC;IAED,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,kBAAkB,CAAC;IAC1D,MAAM,sBAAsB,GAC1B,OAAO,CAAC,sBAAsB,IAAI,gCAAgC,CAAC;IACrE,MAAM,cAAc,GAAG,OAAO,CAAC,cAAc,IAAI,uBAAuB,CAAC;IAEzE,0BAA0B,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IACjD,0BAA0B,CACxB,sBAAsB,EACtB,0BAA0B,CAC3B,CAAC;IAEF,OAAO,IAAI,mBAAmB,CAAC;QAC7B,cAAc,EAAE,OAAO,CAAC,cAAc;QACtC,SAAS;QACT,sBAAsB;QACtB,cAAc;KACf,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { isAbsolute } from \"node:path\";\nimport { simpleGit } from \"simple-git\";\nimport {\n asFailure,\n isNonEmptyString,\n isPositiveInteger,\n isRecord,\n} from \"./internal/utils.js\";\n\nconst DEFAULT_TIMEOUT_MS = 30_000;\nexport const UPLOAD_INACTIVITY_TIMEOUT_MS = 5 * 60_000;\nexport const UPLOAD_WALL_TIMEOUT_MS = 30 * 60_000;\nconst DEFAULT_MAX_CONCURRENT_PROCESSES = 1;\nconst DEFAULT_COMMIT_IDENTITY = {\n name: \"Bonfire\",\n email: \"bonfire@localhost\",\n};\nconst NOTHING_TO_COMMIT_MESSAGES = [\n \"nothing to commit\",\n \"nothing added to commit\",\n];\n\nexport type GitCommitIdentity = {\n name: string;\n email: string;\n};\n\nexport type GitRepositoryOptions = {\n repositoryRoot: string;\n timeoutMs?: number;\n maxConcurrentProcesses?: number;\n commitIdentity?: GitCommitIdentity;\n};\n\nexport type GitStatusFile = {\n path: string;\n index: string;\n workingDirectory: string;\n from?: string;\n};\n\nexport type GitStatusSnapshot = {\n current: string | null;\n files: readonly GitStatusFile[];\n clean: boolean;\n};\n\nexport type GitRemoteSnapshot = {\n name: string;\n fetchUrl: string | null;\n pushUrl: string | null;\n};\n\nexport type GitBranchSnapshot = {\n current: string | null;\n all: readonly string[];\n};\n\nexport type GitCommitSnapshot = {\n branch: string;\n commit: string;\n root: boolean;\n};\n\nexport type GitCommitResult = GitCommitSnapshot | null;\n\nexport type GitPushResult = {\n remoteStatus: \"pushed\" | \"local-only\";\n};\n\nexport type GitUploadProgress = {\n stage: string;\n progress: number;\n processed: number;\n total: number;\n};\n\nexport type GitRepositoryErrorKind =\n | \"missing-git\"\n | \"timeout\"\n | \"conflict\"\n | \"non-fast-forward\"\n | \"command-failure\"\n | \"malformed-output\"\n | \"invalid-configuration\"\n | \"unexpected\";\n\nexport class GitRepositoryError extends Error {\n readonly kind: GitRepositoryErrorKind;\n readonly operation: string;\n\n constructor(kind: GitRepositoryErrorKind, operation: string) {\n super(`Git operation failed: ${operation}`);\n this.name = \"GitRepositoryError\";\n this.kind = kind;\n this.operation = operation;\n }\n}\n\nexport interface GitRepository {\n readonly repositoryRoot: string;\n currentBranch(): Promise<string>;\n status(pathspecs?: readonly string[]): Promise<GitStatusSnapshot>;\n remotes(): Promise<readonly GitRemoteSnapshot[]>;\n branches(): Promise<GitBranchSnapshot>;\n fetch(remote: string, branch?: string): Promise<void>;\n checkout(args: readonly string[]): Promise<void>;\n checkoutLocalBranch(branch: string): Promise<void>;\n merge(args: readonly string[]): Promise<void>;\n add(pathspecs: readonly string[]): Promise<void>;\n commit(\n message: string,\n pathspecs?: readonly string[],\n ): Promise<GitCommitResult>;\n push(\n remote: string,\n branch: string,\n options?: readonly string[],\n ): Promise<void>;\n /** Push using the bounded, upload-specific timeout policy. */\n pushUpload?(\n remote: string,\n branch: string,\n options?: readonly string[],\n onProgress?: (progress: GitUploadProgress) => void,\n ): Promise<void>;\n restore(pathspecs: readonly string[]): Promise<void>;\n clean(mode: string, pathspecs: readonly string[]): Promise<void>;\n raw(args: readonly string[]): Promise<string>;\n /** Execute a read/write Git command with a private environment. */\n rawWithEnv?(\n args: readonly string[],\n environment: Readonly<Record<string, string>>,\n ): Promise<string>;\n}\n\nfunction classifyError(error: unknown): GitRepositoryErrorKind {\n if (error instanceof GitRepositoryError) return error.kind;\n\n const failure = asFailure(error);\n const message = typeof failure.message === \"string\" ? failure.message : \"\";\n const normalized = message.toLowerCase();\n\n if (failure.code === \"ENOENT\" || normalized.includes(\"enoent\")) {\n return \"missing-git\";\n }\n\n if (\n failure.code === \"ETIMEDOUT\" ||\n failure.killed === true ||\n failure.signal === \"SIGTERM\" ||\n normalized.includes(\"timed out\") ||\n normalized.includes(\"timeout\")\n ) {\n return \"timeout\";\n }\n\n if (\n normalized.includes(\"conflict\") ||\n normalized.includes(\"would be overwritten\") ||\n normalized.includes(\"unmerged paths\")\n ) {\n return \"conflict\";\n }\n\n if (\n normalized.includes(\"non-fast-forward\") ||\n normalized.includes(\"fetch first\") ||\n normalized.includes(\"stale info\")\n ) {\n return \"non-fast-forward\";\n }\n\n if (isRecord(error) || error instanceof Error) return \"command-failure\";\n return \"unexpected\";\n}\n\nfunction normalizeError(operation: string, error: unknown) {\n if (error instanceof GitRepositoryError) return error;\n return new GitRepositoryError(classifyError(error), operation);\n}\n\nfunction assertValidPositiveInteger(value: number, option: string) {\n if (!isPositiveInteger(value)) {\n throw new GitRepositoryError(\"invalid-configuration\", option);\n }\n}\n\nfunction assertValidBranchName(value: string, option: string) {\n if (\n !isNonEmptyString(value) ||\n value.startsWith(\"-\") ||\n value.includes(\"\\0\") ||\n /\\s/u.test(value) ||\n value.includes(\"@{\") ||\n value.split(/[\\\\/]/u).some((segment) => segment === \"..\")\n ) {\n throw new GitRepositoryError(\"invalid-configuration\", option);\n }\n}\n\nfunction assertValidPathspec(pathspec: string) {\n if (\n !isNonEmptyString(pathspec) ||\n isAbsolute(pathspec) ||\n /^[A-Za-z]:[\\\\/]/u.test(pathspec) ||\n pathspec.startsWith(\"\\\\\") ||\n pathspec.startsWith(\"-\") ||\n pathspec.startsWith(\":\") ||\n pathspec.includes(\"\\0\") ||\n pathspec.includes(\"*\") ||\n pathspec.includes(\"?\") ||\n pathspec.includes(\"[\") ||\n pathspec.includes(\"]\") ||\n pathspec === \".\" ||\n pathspec.split(/[\\\\/]/u).some((segment) => segment === \"..\")\n ) {\n throw new GitRepositoryError(\"invalid-configuration\", \"pathspec\");\n }\n}\n\nfunction assertValidPathspecs(pathspecs: readonly string[]) {\n if (pathspecs.length === 0) {\n throw new GitRepositoryError(\"invalid-configuration\", \"pathspec\");\n }\n for (const pathspec of pathspecs) assertValidPathspec(pathspec);\n return [...pathspecs];\n}\n\nfunction assertValidArguments(args: readonly string[], operation: string) {\n if (\n args.some(\n (argument) => !isNonEmptyString(argument) || argument.includes(\"\\0\"),\n )\n ) {\n throw new GitRepositoryError(\"invalid-configuration\", operation);\n }\n return [...args];\n}\n\nfunction isNothingToCommit(error: unknown) {\n const failure = asFailure(error);\n const message = typeof failure.message === \"string\" ? failure.message : \"\";\n return NOTHING_TO_COMMIT_MESSAGES.some((needle) =>\n message.toLowerCase().includes(needle),\n );\n}\n\nclass SimpleGitRepository implements GitRepository {\n readonly repositoryRoot: string;\n readonly #git;\n readonly #gitOptions;\n\n constructor(options: Required<GitRepositoryOptions>) {\n this.repositoryRoot = options.repositoryRoot;\n this.#gitOptions = {\n baseDir: options.repositoryRoot,\n maxConcurrentProcesses: options.maxConcurrentProcesses,\n config: [\n `user.name=${options.commitIdentity.name}`,\n `user.email=${options.commitIdentity.email}`,\n ],\n };\n this.#git = simpleGit(options.repositoryRoot, {\n ...this.#gitOptions,\n timeout: { block: options.timeoutMs },\n });\n }\n\n async #execute<Value>(operation: string, action: () => Promise<Value>) {\n try {\n return await action();\n } catch (error) {\n throw normalizeError(operation, error);\n }\n }\n\n async currentBranch() {\n const result = await this.#execute(\"current-branch\", () =>\n this.#git.revparse([\"--abbrev-ref\", \"HEAD\"]),\n );\n if (!isNonEmptyString(result) || result.trim().length === 0) {\n throw new GitRepositoryError(\"malformed-output\", \"current-branch\");\n }\n return result.trim();\n }\n\n async status(pathspecs?: readonly string[]) {\n const validatedPathspecs =\n pathspecs === undefined ? undefined : assertValidPathspecs(pathspecs);\n const result = await this.#execute(\"status\", () =>\n validatedPathspecs === undefined\n ? this.#git.status()\n : this.#git.status([\"--\", ...validatedPathspecs]),\n );\n\n if (\n !isRecord(result) ||\n !Array.isArray(result.files) ||\n (typeof result.current !== \"string\" && result.current !== null) ||\n typeof result.isClean !== \"function\"\n ) {\n throw new GitRepositoryError(\"malformed-output\", \"status\");\n }\n\n const files: GitStatusFile[] = [];\n for (const file of result.files) {\n if (!isRecord(file)) {\n throw new GitRepositoryError(\"malformed-output\", \"status\");\n }\n if (\n typeof file.path !== \"string\" ||\n typeof file.index !== \"string\" ||\n typeof file.working_dir !== \"string\"\n ) {\n throw new GitRepositoryError(\"malformed-output\", \"status\");\n }\n\n files.push({\n path: file.path,\n index: file.index,\n workingDirectory: file.working_dir,\n ...(typeof file.from === \"string\" ? { from: file.from } : {}),\n });\n }\n\n let clean: boolean;\n try {\n clean = result.isClean();\n } catch {\n throw new GitRepositoryError(\"malformed-output\", \"status\");\n }\n if (typeof clean !== \"boolean\") {\n throw new GitRepositoryError(\"malformed-output\", \"status\");\n }\n\n return {\n current: result.current,\n files,\n clean,\n } satisfies GitStatusSnapshot;\n }\n\n async remotes() {\n const result = await this.#execute(\"remotes\", () =>\n this.#git.getRemotes(true),\n );\n if (!Array.isArray(result)) {\n throw new GitRepositoryError(\"malformed-output\", \"remotes\");\n }\n\n const remotes: GitRemoteSnapshot[] = [];\n for (const remote of result) {\n if (!isRecord(remote) || typeof remote.name !== \"string\") {\n throw new GitRepositoryError(\"malformed-output\", \"remotes\");\n }\n const refs = remote.refs;\n if (!isRecord(refs)) {\n throw new GitRepositoryError(\"malformed-output\", \"remotes\");\n }\n if (typeof refs.fetch !== \"string\" || typeof refs.push !== \"string\") {\n throw new GitRepositoryError(\"malformed-output\", \"remotes\");\n }\n\n remotes.push({\n name: remote.name,\n fetchUrl: refs.fetch,\n pushUrl: refs.push,\n });\n }\n return remotes;\n }\n\n async branches() {\n const result = await this.#execute(\"branches\", () =>\n this.#git.branch([\"-a\"]),\n );\n if (\n !isRecord(result) ||\n !Array.isArray(result.all) ||\n (typeof result.current !== \"string\" && result.current !== null) ||\n !result.all.every((branch) => typeof branch === \"string\")\n ) {\n throw new GitRepositoryError(\"malformed-output\", \"branches\");\n }\n\n return {\n current: result.current,\n all: [...result.all],\n } satisfies GitBranchSnapshot;\n }\n\n async fetch(remote: string, branch?: string) {\n assertValidBranchName(remote, \"remote\");\n if (branch !== undefined) assertValidBranchName(branch, \"branch\");\n await this.#execute(\"fetch\", () =>\n branch === undefined\n ? this.#git.fetch(remote)\n : this.#git.fetch(remote, branch),\n );\n }\n\n async checkout(args: readonly string[]) {\n const validatedArgs = assertValidArguments(args, \"checkout\");\n await this.#execute(\"checkout\", () => this.#git.checkout(validatedArgs));\n }\n\n async checkoutLocalBranch(branch: string) {\n assertValidBranchName(branch, \"branch\");\n await this.#execute(\"checkout-local-branch\", () =>\n this.#git.checkoutLocalBranch(branch),\n );\n }\n\n async merge(args: readonly string[]) {\n const validatedArgs = assertValidArguments(args, \"merge\");\n await this.#execute(\"merge\", () => this.#git.merge(validatedArgs));\n }\n\n async add(pathspecs: readonly string[]) {\n const validatedPathspecs = assertValidPathspecs(pathspecs);\n await this.#execute(\"add\", () => this.#git.add(validatedPathspecs));\n }\n\n async commit(message: string, pathspecs?: readonly string[]) {\n if (!isNonEmptyString(message)) {\n throw new GitRepositoryError(\"invalid-configuration\", \"commit-message\");\n }\n const validatedPathspecs =\n pathspecs === undefined ? undefined : assertValidPathspecs(pathspecs);\n\n let result: unknown;\n try {\n result =\n validatedPathspecs === undefined\n ? await this.#git.commit(message)\n : await this.#git.commit(message, [...validatedPathspecs]);\n } catch (error) {\n if (isNothingToCommit(error)) return null;\n throw normalizeError(\"commit\", error);\n }\n if (\n !isRecord(result) ||\n typeof result.branch !== \"string\" ||\n typeof result.commit !== \"string\" ||\n typeof result.root !== \"boolean\"\n ) {\n throw new GitRepositoryError(\"malformed-output\", \"commit\");\n }\n\n return {\n branch: result.branch,\n commit: result.commit,\n root: result.root,\n } satisfies GitCommitSnapshot;\n }\n\n async push(remote: string, branch: string, options: readonly string[] = []) {\n assertValidBranchName(remote, \"remote\");\n assertValidBranchName(branch, \"branch\");\n const validatedOptions = assertValidArguments(options, \"push\");\n await this.#execute(\"push\", () =>\n this.#git.push(remote, branch, validatedOptions),\n );\n }\n\n async pushUpload(\n remote: string,\n branch: string,\n options: readonly string[] = [],\n onProgress?: (progress: GitUploadProgress) => void,\n ) {\n assertValidBranchName(remote, \"remote\");\n assertValidBranchName(branch, \"branch\");\n const validatedOptions = assertValidArguments(options, \"push\");\n const abort = new AbortController();\n const git = simpleGit(this.#gitOptions.baseDir, {\n ...this.#gitOptions,\n abort: abort.signal,\n progress:\n onProgress === undefined\n ? undefined\n : (progress) =>\n onProgress({\n stage: progress.stage,\n progress: progress.progress,\n processed: progress.processed,\n total: progress.total,\n }),\n timeout: { block: UPLOAD_INACTIVITY_TIMEOUT_MS },\n });\n let wallTimer: ReturnType<typeof setTimeout> | undefined;\n const push = git.push(remote, branch, validatedOptions);\n try {\n await Promise.race([\n push,\n new Promise<never>((_, reject) => {\n wallTimer = setTimeout(() => {\n abort.abort();\n reject(new GitRepositoryError(\"timeout\", \"upload\"));\n }, UPLOAD_WALL_TIMEOUT_MS);\n }),\n ]);\n } catch (error) {\n throw normalizeError(\"upload\", error);\n } finally {\n if (wallTimer !== undefined) clearTimeout(wallTimer);\n }\n }\n\n async restore(pathspecs: readonly string[]) {\n const validatedPathspecs = assertValidPathspecs(pathspecs);\n await this.#execute(\"restore\", () =>\n this.#git.checkout([\"--\", ...validatedPathspecs]),\n );\n }\n\n async clean(mode: string, pathspecs: readonly string[]) {\n if (!/^[a-z]+$/u.test(mode)) {\n throw new GitRepositoryError(\"invalid-configuration\", \"clean-mode\");\n }\n const validatedPathspecs = assertValidPathspecs(pathspecs);\n await this.#execute(\"clean\", () =>\n this.#git.clean(mode, validatedPathspecs),\n );\n }\n\n async raw(args: readonly string[]) {\n const validatedArgs = assertValidArguments(args, \"raw\");\n const result = await this.#execute(\"raw\", () =>\n this.#git.raw(validatedArgs),\n );\n if (typeof result !== \"string\") {\n throw new GitRepositoryError(\"malformed-output\", \"raw\");\n }\n return result;\n }\n\n async rawWithEnv(\n args: readonly string[],\n environment: Readonly<Record<string, string>>,\n ) {\n const validatedArgs = assertValidArguments(args, \"raw\");\n if (\n Object.keys(environment).some(\n (key) =>\n !/^[A-Z_][A-Z0-9_]*$/u.test(key) || environment[key] === undefined,\n )\n ) {\n throw new GitRepositoryError(\"invalid-configuration\", \"raw-environment\");\n }\n const git = simpleGit(this.#gitOptions.baseDir, {\n ...this.#gitOptions,\n timeout: { block: DEFAULT_TIMEOUT_MS },\n }).env(environment);\n const result = await this.#execute(\"raw\", () => git.raw(validatedArgs));\n if (typeof result !== \"string\") {\n throw new GitRepositoryError(\"malformed-output\", \"raw\");\n }\n return result;\n }\n}\n\nexport type PrepareIdentityBranchOptions = {\n identityBranch: string;\n primaryBranch: string;\n remote: string;\n};\n\nexport async function prepareIdentityBranch(\n repository: GitRepository,\n options: PrepareIdentityBranchOptions,\n): Promise<void> {\n assertValidBranchName(options.identityBranch, \"identity-branch\");\n assertValidBranchName(options.primaryBranch, \"primary-branch\");\n assertValidBranchName(options.remote, \"remote\");\n\n const currentBranch = await repository.currentBranch();\n if (currentBranch === options.identityBranch) return;\n\n const status = await repository.status();\n if (!status.clean) {\n throw new GitRepositoryError(\"conflict\", \"prepare-identity-branch\");\n }\n\n const remotes = await repository.remotes();\n const configuredRemote = remotes.some(\n (remote) => remote.name === options.remote,\n );\n if (configuredRemote) {\n await repository.fetch(options.remote, options.primaryBranch);\n }\n\n const branches = await repository.branches();\n const hasLocalPrimary = branches.all.includes(options.primaryBranch);\n const remotePrimary = `remotes/${options.remote}/${options.primaryBranch}`;\n const hasRemotePrimary =\n configuredRemote && branches.all.includes(remotePrimary);\n if (!hasLocalPrimary && !hasRemotePrimary) {\n throw new GitRepositoryError(\"command-failure\", \"primary-branch\");\n }\n\n if (hasLocalPrimary) {\n await repository.checkout([options.primaryBranch]);\n } else {\n await repository.checkout([\n \"-b\",\n options.primaryBranch,\n \"--track\",\n `${options.remote}/${options.primaryBranch}`,\n ]);\n }\n if (configuredRemote) {\n await repository.merge([\n `${options.remote}/${options.primaryBranch}`,\n \"--ff-only\",\n ]);\n }\n\n if (branches.all.includes(options.identityBranch)) {\n await repository.checkout([options.identityBranch]);\n return;\n }\n\n const remoteBranch = `remotes/${options.remote}/${options.identityBranch}`;\n if (branches.all.includes(remoteBranch)) {\n await repository.checkout([\n \"-b\",\n options.identityBranch,\n \"--track\",\n `${options.remote}/${options.identityBranch}`,\n ]);\n return;\n }\n\n await repository.checkoutLocalBranch(options.identityBranch);\n}\n\nexport async function commitPath(\n repository: GitRepository,\n pathspec: string,\n message: string,\n): Promise<GitCommitResult> {\n const validatedPathspecs = assertValidPathspecs([pathspec]);\n await repository.add(validatedPathspecs);\n return repository.commit(message, validatedPathspecs);\n}\n\nexport async function discardPath(\n repository: GitRepository,\n pathspec: string,\n): Promise<void> {\n const validatedPathspec = assertValidPathspecs([pathspec])[0]!;\n await repository.raw([\"reset\", \"HEAD\", \"--\", validatedPathspec]);\n await repository.restore([validatedPathspec]);\n await repository.clean(\"fd\", [validatedPathspec]);\n}\n\nexport async function restorePathFromRef(\n repository: GitRepository,\n ref: string,\n pathspec: string,\n): Promise<void> {\n assertValidArguments([ref], \"restore-ref\");\n const validatedPathspec = assertValidPathspecs([pathspec])[0]!;\n await repository.raw([\n \"restore\",\n \"--source\",\n ref,\n \"--staged\",\n \"--worktree\",\n \"--\",\n validatedPathspec,\n ]);\n}\n\nexport async function remoteBranchCommit(\n repository: GitRepository,\n remote: string,\n branch: string,\n) {\n const output = await repository.raw([\n \"ls-remote\",\n remote,\n `refs/heads/${branch}`,\n ]);\n const value = output.trim().split(/\\s+/u)[0];\n return value !== undefined && /^[0-9a-f]{40,64}$/iu.test(value)\n ? value.toLowerCase()\n : null;\n}\n\nexport async function pushCommitToBranch(\n repository: GitRepository,\n remote: string,\n commit: string,\n branch: string,\n upload = false,\n): Promise<GitPushResult> {\n assertValidBranchName(remote, \"remote\");\n assertValidBranchName(branch, \"branch\");\n if (!/^[0-9a-f]{40,64}$/iu.test(commit)) {\n throw new GitRepositoryError(\"invalid-configuration\", \"commit\");\n }\n\n const hasRemote = (await repository.remotes()).some(\n (configuredRemote) => configuredRemote.name === remote,\n );\n if (!hasRemote) return { remoteStatus: \"local-only\" };\n\n try {\n const canUseUploadPolicy = upload && repository.pushUpload !== undefined;\n if (canUseUploadPolicy) {\n await repository.pushUpload!(remote, `${commit}:refs/heads/${branch}`);\n } else {\n await repository.raw([\"push\", remote, `${commit}:refs/heads/${branch}`]);\n }\n } catch (error) {\n try {\n if (\n (await remoteBranchCommit(repository, remote, branch)) ===\n commit.toLowerCase()\n ) {\n return { remoteStatus: \"pushed\" };\n }\n } catch {\n // Preserve the original push classification when confirmation is also\n // unavailable. The caller can surface this as upload-unconfirmed.\n }\n throw error;\n }\n\n if (\n (await remoteBranchCommit(repository, remote, branch)) !==\n commit.toLowerCase()\n ) {\n throw new GitRepositoryError(\"conflict\", \"source-confirmation\");\n }\n return { remoteStatus: \"pushed\" };\n}\n\nexport async function pushBranch(\n repository: GitRepository,\n remote: string,\n branch: string,\n): Promise<GitPushResult> {\n assertValidBranchName(remote, \"remote\");\n assertValidBranchName(branch, \"branch\");\n\n const hasRemote = (await repository.remotes()).some(\n (configuredRemote) => configuredRemote.name === remote,\n );\n if (!hasRemote) return { remoteStatus: \"local-only\" };\n\n await repository.push(remote, branch, [\"--set-upstream\"]);\n return { remoteStatus: \"pushed\" };\n}\n\nexport function createGitRepository(\n options: GitRepositoryOptions,\n): GitRepository {\n if (!isAbsolute(options.repositoryRoot)) {\n throw new GitRepositoryError(\"invalid-configuration\", \"repository-root\");\n }\n\n const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;\n const maxConcurrentProcesses =\n options.maxConcurrentProcesses ?? DEFAULT_MAX_CONCURRENT_PROCESSES;\n const commitIdentity = options.commitIdentity ?? DEFAULT_COMMIT_IDENTITY;\n\n assertValidPositiveInteger(timeoutMs, \"timeout\");\n assertValidPositiveInteger(\n maxConcurrentProcesses,\n \"max-concurrent-processes\",\n );\n\n return new SimpleGitRepository({\n repositoryRoot: options.repositoryRoot,\n timeoutMs,\n maxConcurrentProcesses,\n commitIdentity,\n });\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -12,4 +12,5 @@ export type { PreparePrototypeFiles, PreparePrototypeFilesRequest, } from "./pre
|
|
|
12
12
|
export { LocalPrototypeLifecycle, type LocalPrototypeLifecycleOptions, type PrototypeLifecycle, } from "./lifecycle/local-prototype-lifecycle.js";
|
|
13
13
|
export { assertIdentityBranchReady, hasUnresolvedRepositoryOperation, synchronizeIdentityBranch, type RepositorySynchronizationResult, type SynchronizationDeferredReason, type SynchronizationUnsafeReason, type SynchronizeIdentityBranchOptions, } from "./lifecycle/repository-synchronization.js";
|
|
14
14
|
export { getRepositorySummary, type RepositorySummaryOptions, } from "./lifecycle/repository-summary.js";
|
|
15
|
+
export { clearPreparationMarker, hasPreparationMarker, preparationMarkerPath, readPreparationMarker, writePreparationMarker, type DependencyInstaller, } from "./lifecycle/preparation-marker.js";
|
|
15
16
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,uBAAuB,EACvB,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kB,CAAC;AAC1B,YAAY,EACV,qBAAqB,EACrB,4BAA4B,GAC7B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,uBAAuB,EACvB,KAAK,8BAA8B,EACnC,KAAK,kBAAkB,GACxB,MAAM,0CAA0C,CAAC;AAClD,OAAO,EACL,yBAAyB,EACzB,gCAAgC,EAChC,yBAAyB,EACzB,KAAK,+BAA+B,EACpC,KAAK,6BAA6B,EAClC,KAAK,2BAA2B,EAChC,KAAK,gCAAgC,GACtC,MAAM,2CAA2C,CAAC;AACnD,OAAO,EACL,oBAAoB,EACpB,KAAK,wBAAwB,GAC9B,MAAM,mCAAmC,CAAC","sourcesContent":["export {\n createDeploymentProvider,\n DeploymentProviderError,\n type CreateDeploymentProviderOptions,\n type DeploymentProvider,\n type DeploymentProviderErrorKind,\n type DeploymentProviderResult,\n} from \"./deployment-provider.js\";\nexport {\n GitHubCliClient,\n GitHubCliError,\n type GitHubCliClientLike,\n type GitHubCliClientOptions,\n type GitHubCliErrorReason,\n type GitHubCliWebLogin,\n} from \"./github-cli.js\";\nexport type {\n GitHubCliChildProcess,\n GitHubCliExecOptions,\n GitHubCliExecResult,\n GitHubCliOutputStream,\n GitHubCliProcessRunner,\n GitHubCliSpawnOptions,\n} from \"./process-runner.js\";\nexport {\n PrototypeCatalog,\n type PrototypeCatalogLike,\n} from \"./prototype-catalog.js\";\nexport {\n resolvePrototypeCatalogPaths,\n type PrototypeCatalogOptions,\n type ResolvedPrototypeCatalogPaths,\n} from \"./prototype-paths.js\";\nexport {\n PrototypeAgentService,\n type PrototypeAgentServiceLike,\n type PrototypeAgentServiceOptions,\n} from \"./agent-service.js\";\nexport {\n ClaudeCodeLauncher,\n buildClaudeCodeAppleScript,\n type ClaudeCodeExecOptions,\n type ClaudeCodeExecResult,\n type ClaudeCodeLauncherLike,\n type ClaudeCodeLauncherOptions,\n type ClaudeCodePreflightResult,\n type ClaudeCodePreflightValue,\n type ClaudeCodeProcessRunner,\n} from \"./claude.js\";\nexport {\n CursorLauncher,\n type CursorChildProcess,\n type CursorLauncherLike,\n type CursorLauncherOptions,\n type CursorSpawn,\n type CursorSpawnOptions,\n} from \"./cursor.js\";\nexport {\n PathExecutableResolver,\n type ExecutableAccess,\n type ExecutableResolverLike,\n type ExecutableResolverOptions,\n} from \"./executable.js\";\nexport {\n PrototypePreferences,\n PrototypePreferencesError,\n type PrototypePreferencesErrorCode,\n type PrototypePreferencesLike,\n type PrototypePreferencesOptions,\n} from \"./preferences.js\";\nexport type {\n PreparePrototypeFiles,\n PreparePrototypeFilesRequest,\n} from \"./prepare-prototype-files.js\";\nexport {\n LocalPrototypeLifecycle,\n type LocalPrototypeLifecycleOptions,\n type PrototypeLifecycle,\n} from \"./lifecycle/local-prototype-lifecycle.js\";\nexport {\n assertIdentityBranchReady,\n hasUnresolvedRepositoryOperation,\n synchronizeIdentityBranch,\n type RepositorySynchronizationResult,\n type SynchronizationDeferredReason,\n type SynchronizationUnsafeReason,\n type SynchronizeIdentityBranchOptions,\n} from \"./lifecycle/repository-synchronization.js\";\nexport {\n getRepositorySummary,\n type RepositorySummaryOptions,\n} from \"./lifecycle/repository-summary.js\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,uBAAuB,EACvB,KAAK,+BAA+B,EACpC,KAAK,kBAAkB,EACvB,KAAK,2BAA2B,EAChC,KAAK,wBAAwB,GAC9B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,eAAe,EACf,cAAc,EACd,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,EAC3B,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,GACvB,MAAM,iBAAiB,CAAC;AACzB,YAAY,EACV,qBAAqB,EACrB,oBAAoB,EACpB,mBAAmB,EACnB,qBAAqB,EACrB,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,gBAA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mCAAmC,CAAC;AAC3C,OAAO,EACL,sBAAsB,EACtB,oBAAoB,EACpB,qBAAqB,EACrB,qBAAqB,EACrB,sBAAsB,EACtB,KAAK,mBAAmB,GACzB,MAAM,mCAAmC,CAAC","sourcesContent":["export {\n createDeploymentProvider,\n DeploymentProviderError,\n type CreateDeploymentProviderOptions,\n type DeploymentProvider,\n type DeploymentProviderErrorKind,\n type DeploymentProviderResult,\n} from \"./deployment-provider.js\";\nexport {\n GitHubCliClient,\n GitHubCliError,\n type GitHubCliClientLike,\n type GitHubCliClientOptions,\n type GitHubCliErrorReason,\n type GitHubCliWebLogin,\n} from \"./github-cli.js\";\nexport type {\n GitHubCliChildProcess,\n GitHubCliExecOptions,\n GitHubCliExecResult,\n GitHubCliOutputStream,\n GitHubCliProcessRunner,\n GitHubCliSpawnOptions,\n} from \"./process-runner.js\";\nexport {\n PrototypeCatalog,\n type PrototypeCatalogLike,\n} from \"./prototype-catalog.js\";\nexport {\n resolvePrototypeCatalogPaths,\n type PrototypeCatalogOptions,\n type ResolvedPrototypeCatalogPaths,\n} from \"./prototype-paths.js\";\nexport {\n PrototypeAgentService,\n type PrototypeAgentServiceLike,\n type PrototypeAgentServiceOptions,\n} from \"./agent-service.js\";\nexport {\n ClaudeCodeLauncher,\n buildClaudeCodeAppleScript,\n type ClaudeCodeExecOptions,\n type ClaudeCodeExecResult,\n type ClaudeCodeLauncherLike,\n type ClaudeCodeLauncherOptions,\n type ClaudeCodePreflightResult,\n type ClaudeCodePreflightValue,\n type ClaudeCodeProcessRunner,\n} from \"./claude.js\";\nexport {\n CursorLauncher,\n type CursorChildProcess,\n type CursorLauncherLike,\n type CursorLauncherOptions,\n type CursorSpawn,\n type CursorSpawnOptions,\n} from \"./cursor.js\";\nexport {\n PathExecutableResolver,\n type ExecutableAccess,\n type ExecutableResolverLike,\n type ExecutableResolverOptions,\n} from \"./executable.js\";\nexport {\n PrototypePreferences,\n PrototypePreferencesError,\n type PrototypePreferencesErrorCode,\n type PrototypePreferencesLike,\n type PrototypePreferencesOptions,\n} from \"./preferences.js\";\nexport type {\n PreparePrototypeFiles,\n PreparePrototypeFilesRequest,\n} from \"./prepare-prototype-files.js\";\nexport {\n LocalPrototypeLifecycle,\n type LocalPrototypeLifecycleOptions,\n type PrototypeLifecycle,\n} from \"./lifecycle/local-prototype-lifecycle.js\";\nexport {\n assertIdentityBranchReady,\n hasUnresolvedRepositoryOperation,\n synchronizeIdentityBranch,\n type RepositorySynchronizationResult,\n type SynchronizationDeferredReason,\n type SynchronizationUnsafeReason,\n type SynchronizeIdentityBranchOptions,\n} from \"./lifecycle/repository-synchronization.js\";\nexport {\n getRepositorySummary,\n type RepositorySummaryOptions,\n} from \"./lifecycle/repository-summary.js\";\nexport {\n clearPreparationMarker,\n hasPreparationMarker,\n preparationMarkerPath,\n readPreparationMarker,\n writePreparationMarker,\n type DependencyInstaller,\n} from \"./lifecycle/preparation-marker.js\";\n"]}
|
package/dist/index.js
CHANGED
|
@@ -10,4 +10,5 @@ export { PrototypePreferences, PrototypePreferencesError, } from "./preferences.
|
|
|
10
10
|
export { LocalPrototypeLifecycle, } from "./lifecycle/local-prototype-lifecycle.js";
|
|
11
11
|
export { assertIdentityBranchReady, hasUnresolvedRepositoryOperation, synchronizeIdentityBranch, } from "./lifecycle/repository-synchronization.js";
|
|
12
12
|
export { getRepositorySummary, } from "./lifecycle/repository-summary.js";
|
|
13
|
+
export { clearPreparationMarker, hasPreparationMarker, preparationMarkerPath, readPreparationMarker, writePreparationMarker, } from "./lifecycle/preparation-marker.js";
|
|
13
14
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,uBAAuB,GAKxB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,eAAe,EACf,cAAc,GAKf,MAAM,iBAAiB,CAAC;AASzB,OAAO,EACL,gBAAgB,GAEjB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,4BAA4B,GAG7B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,qBAAqB,GAGtB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,kBAAkB,EAClB,0BAA0B,GAQ3B,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,cAAc,GAMf,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,sBAAsB,GAIvB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,oBAAoB,EACpB,yBAAyB,GAI1B,MAAM,kBAAkB,CAAC;AAK1B,OAAO,EACL,uBAAuB,GAGxB,MAAM,0CAA0C,CAAC;AAClD,OAAO,EACL,yBAAyB,EACzB,gCAAgC,EAChC,yBAAyB,GAK1B,MAAM,2CAA2C,CAAC;AACnD,OAAO,EACL,oBAAoB,GAErB,MAAM,mCAAmC,CAAC","sourcesContent":["export {\n createDeploymentProvider,\n DeploymentProviderError,\n type CreateDeploymentProviderOptions,\n type DeploymentProvider,\n type DeploymentProviderErrorKind,\n type DeploymentProviderResult,\n} from \"./deployment-provider.js\";\nexport {\n GitHubCliClient,\n GitHubCliError,\n type GitHubCliClientLike,\n type GitHubCliClientOptions,\n type GitHubCliErrorReason,\n type GitHubCliWebLogin,\n} from \"./github-cli.js\";\nexport type {\n GitHubCliChildProcess,\n GitHubCliExecOptions,\n GitHubCliExecResult,\n GitHubCliOutputStream,\n GitHubCliProcessRunner,\n GitHubCliSpawnOptions,\n} from \"./process-runner.js\";\nexport {\n PrototypeCatalog,\n type PrototypeCatalogLike,\n} from \"./prototype-catalog.js\";\nexport {\n resolvePrototypeCatalogPaths,\n type PrototypeCatalogOptions,\n type ResolvedPrototypeCatalogPaths,\n} from \"./prototype-paths.js\";\nexport {\n PrototypeAgentService,\n type PrototypeAgentServiceLike,\n type PrototypeAgentServiceOptions,\n} from \"./agent-service.js\";\nexport {\n ClaudeCodeLauncher,\n buildClaudeCodeAppleScript,\n type ClaudeCodeExecOptions,\n type ClaudeCodeExecResult,\n type ClaudeCodeLauncherLike,\n type ClaudeCodeLauncherOptions,\n type ClaudeCodePreflightResult,\n type ClaudeCodePreflightValue,\n type ClaudeCodeProcessRunner,\n} from \"./claude.js\";\nexport {\n CursorLauncher,\n type CursorChildProcess,\n type CursorLauncherLike,\n type CursorLauncherOptions,\n type CursorSpawn,\n type CursorSpawnOptions,\n} from \"./cursor.js\";\nexport {\n PathExecutableResolver,\n type ExecutableAccess,\n type ExecutableResolverLike,\n type ExecutableResolverOptions,\n} from \"./executable.js\";\nexport {\n PrototypePreferences,\n PrototypePreferencesError,\n type PrototypePreferencesErrorCode,\n type PrototypePreferencesLike,\n type PrototypePreferencesOptions,\n} from \"./preferences.js\";\nexport type {\n PreparePrototypeFiles,\n PreparePrototypeFilesRequest,\n} from \"./prepare-prototype-files.js\";\nexport {\n LocalPrototypeLifecycle,\n type LocalPrototypeLifecycleOptions,\n type PrototypeLifecycle,\n} from \"./lifecycle/local-prototype-lifecycle.js\";\nexport {\n assertIdentityBranchReady,\n hasUnresolvedRepositoryOperation,\n synchronizeIdentityBranch,\n type RepositorySynchronizationResult,\n type SynchronizationDeferredReason,\n type SynchronizationUnsafeReason,\n type SynchronizeIdentityBranchOptions,\n} from \"./lifecycle/repository-synchronization.js\";\nexport {\n getRepositorySummary,\n type RepositorySummaryOptions,\n} from \"./lifecycle/repository-summary.js\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,uBAAuB,GAKxB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,eAAe,EACf,cAAc,GAKf,MAAM,iBAAiB,CAAC;AASzB,OAAO,EACL,gBAAgB,GAEjB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,4BAA4B,GAG7B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,qBAAqB,GAGtB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,kBAAkB,EAClB,0BAA0B,GAQ3B,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,cAAc,GAMf,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,sBAAsB,GAIvB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,oBAAoB,EACpB,yBAAyB,GAI1B,MAAM,kBAAkB,CAAC;AAK1B,OAAO,EACL,uBAAuB,GAGxB,MAAM,0CAA0C,CAAC;AAClD,OAAO,EACL,yBAAyB,EACzB,gCAAgC,EAChC,yBAAyB,GAK1B,MAAM,2CAA2C,CAAC;AACnD,OAAO,EACL,oBAAoB,GAErB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,sBAAsB,EACtB,oBAAoB,EACpB,qBAAqB,EACrB,qBAAqB,EACrB,sBAAsB,GAEvB,MAAM,mCAAmC,CAAC","sourcesContent":["export {\n createDeploymentProvider,\n DeploymentProviderError,\n type CreateDeploymentProviderOptions,\n type DeploymentProvider,\n type DeploymentProviderErrorKind,\n type DeploymentProviderResult,\n} from \"./deployment-provider.js\";\nexport {\n GitHubCliClient,\n GitHubCliError,\n type GitHubCliClientLike,\n type GitHubCliClientOptions,\n type GitHubCliErrorReason,\n type GitHubCliWebLogin,\n} from \"./github-cli.js\";\nexport type {\n GitHubCliChildProcess,\n GitHubCliExecOptions,\n GitHubCliExecResult,\n GitHubCliOutputStream,\n GitHubCliProcessRunner,\n GitHubCliSpawnOptions,\n} from \"./process-runner.js\";\nexport {\n PrototypeCatalog,\n type PrototypeCatalogLike,\n} from \"./prototype-catalog.js\";\nexport {\n resolvePrototypeCatalogPaths,\n type PrototypeCatalogOptions,\n type ResolvedPrototypeCatalogPaths,\n} from \"./prototype-paths.js\";\nexport {\n PrototypeAgentService,\n type PrototypeAgentServiceLike,\n type PrototypeAgentServiceOptions,\n} from \"./agent-service.js\";\nexport {\n ClaudeCodeLauncher,\n buildClaudeCodeAppleScript,\n type ClaudeCodeExecOptions,\n type ClaudeCodeExecResult,\n type ClaudeCodeLauncherLike,\n type ClaudeCodeLauncherOptions,\n type ClaudeCodePreflightResult,\n type ClaudeCodePreflightValue,\n type ClaudeCodeProcessRunner,\n} from \"./claude.js\";\nexport {\n CursorLauncher,\n type CursorChildProcess,\n type CursorLauncherLike,\n type CursorLauncherOptions,\n type CursorSpawn,\n type CursorSpawnOptions,\n} from \"./cursor.js\";\nexport {\n PathExecutableResolver,\n type ExecutableAccess,\n type ExecutableResolverLike,\n type ExecutableResolverOptions,\n} from \"./executable.js\";\nexport {\n PrototypePreferences,\n PrototypePreferencesError,\n type PrototypePreferencesErrorCode,\n type PrototypePreferencesLike,\n type PrototypePreferencesOptions,\n} from \"./preferences.js\";\nexport type {\n PreparePrototypeFiles,\n PreparePrototypeFilesRequest,\n} from \"./prepare-prototype-files.js\";\nexport {\n LocalPrototypeLifecycle,\n type LocalPrototypeLifecycleOptions,\n type PrototypeLifecycle,\n} from \"./lifecycle/local-prototype-lifecycle.js\";\nexport {\n assertIdentityBranchReady,\n hasUnresolvedRepositoryOperation,\n synchronizeIdentityBranch,\n type RepositorySynchronizationResult,\n type SynchronizationDeferredReason,\n type SynchronizationUnsafeReason,\n type SynchronizeIdentityBranchOptions,\n} from \"./lifecycle/repository-synchronization.js\";\nexport {\n getRepositorySummary,\n type RepositorySummaryOptions,\n} from \"./lifecycle/repository-summary.js\";\nexport {\n clearPreparationMarker,\n hasPreparationMarker,\n preparationMarkerPath,\n readPreparationMarker,\n writePreparationMarker,\n type DependencyInstaller,\n} from \"./lifecycle/preparation-marker.js\";\n"]}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { PrototypeMetadata, PrototypeRef } from "@ebay-dt/bonfire-core";
|
|
2
2
|
export declare const GENERATED_FILES: readonly ["page.tsx", "app.tsx", "app.module.css", "components/.gitkeep", "metadata.json", "tsconfig.json", "css-modules.d.ts"];
|
|
3
|
-
export declare const COPYABLE_IMPLEMENTATION_FILES: readonly ["page.tsx", "app.tsx", "app.module.css"];
|
|
4
3
|
export declare function buildPageTsx(): string;
|
|
5
4
|
export declare function buildAppTsx(title: string, description: string | null, ref: PrototypeRef): string;
|
|
6
5
|
export declare function buildAppCss(): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prototype-templates.d.ts","sourceRoot":"","sources":["../../src/internal/prototype-templates.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAE7E,eAAO,MAAM,eAAe,YAC1B,UAAU,EACV,SAAS,EACT,gBAAgB,EAChB,qBAAqB,EACrB,eAAe,EACf,eAAe,EACf,kBAAkB,CACV,CAAC;AAEX,
|
|
1
|
+
{"version":3,"file":"prototype-templates.d.ts","sourceRoot":"","sources":["../../src/internal/prototype-templates.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAE7E,eAAO,MAAM,eAAe,YAC1B,UAAU,EACV,SAAS,EACT,gBAAgB,EAChB,qBAAqB,EACrB,eAAe,EACf,eAAe,EACf,kBAAkB,CACV,CAAC;AAEX,wBAAgB,YAAY,WAO3B;AAED,wBAAgB,WAAW,CACzB,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,GAAG,IAAI,EAC1B,GAAG,EAAE,YAAY,UAsBlB;AAED,wBAAgB,WAAW,WAS1B;AAED,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,GAAG,IAAI,EAC1B,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,GAAG,IAAI,EACzB,SAAS,EAAE,MAAM,EACjB,KAAK,CAAC,EAAE,iBAAiB,CAAC,OAAO,CAAC,UAanC;AAED,wBAAgB,aAAa,CAAC,cAAc,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,UAMxE;AAED,wBAAgB,0BAA0B,WAMzC","sourcesContent":["import { join, relative, sep } from \"node:path\";\nimport type { PrototypeMetadata, PrototypeRef } from \"@ebay-dt/bonfire-core\";\n\nexport const GENERATED_FILES = [\n \"page.tsx\",\n \"app.tsx\",\n \"app.module.css\",\n \"components/.gitkeep\",\n \"metadata.json\",\n \"tsconfig.json\",\n \"css-modules.d.ts\",\n] as const;\n\nexport function buildPageTsx() {\n return `import App from \"./app\";\n\nexport default function Page() {\n return <App />;\n}\n`;\n}\n\nexport function buildAppTsx(\n title: string,\n description: string | null,\n ref: PrototypeRef,\n) {\n return `\"use client\";\n\nimport { PrototypeOnboardingCard } from \"@ebay-dt/bonfire-react\";\nimport styles from \"./app.module.css\";\n\nexport default function App() {\n return (\n <main className={styles.container}>\n <PrototypeOnboardingCard\n title={${JSON.stringify(title)}}\n description={${JSON.stringify(description)}}\n prototypeRef={{\n login: ${JSON.stringify(ref.login)},\n slug: ${JSON.stringify(ref.slug)},\n }}\n />\n </main>\n );\n}\n`;\n}\n\nexport function buildAppCss() {\n return `.container {\n display: grid;\n gap: 1rem;\n min-block-size: calc(100svh - var(--app-header-block-size, 0));\n place-content: center;\n padding: 2rem;\n}\n`;\n}\n\nexport function buildMetadataJson(\n title: string,\n description: string | null,\n authorLogin: string,\n authorName: string | null,\n timestamp: string,\n theme?: PrototypeMetadata[\"theme\"],\n) {\n const metadata: PrototypeMetadata = {\n title,\n description,\n authorLogin,\n authorName,\n createdAt: timestamp,\n updatedAt: timestamp,\n previewUrl: null,\n ...(theme === undefined ? {} : { theme }),\n };\n return `${JSON.stringify(metadata, null, 2)}\\n`;\n}\n\nexport function buildTsConfig(repositoryRoot: string, destination: string) {\n const relativeRepositoryRoot = relative(destination, repositoryRoot);\n const extension = join(relativeRepositoryRoot, \"tsconfig.json\")\n .split(sep)\n .join(\"/\");\n return `${JSON.stringify({ extends: extension }, null, 2)}\\n`;\n}\n\nexport function buildCssModulesDeclaration() {\n return `declare module \"*.module.css\" {\n const classes: Record<string, string>;\n export default classes;\n}\n`;\n}\n"]}
|
|
@@ -8,11 +8,6 @@ export const GENERATED_FILES = [
|
|
|
8
8
|
"tsconfig.json",
|
|
9
9
|
"css-modules.d.ts",
|
|
10
10
|
];
|
|
11
|
-
export const COPYABLE_IMPLEMENTATION_FILES = [
|
|
12
|
-
"page.tsx",
|
|
13
|
-
"app.tsx",
|
|
14
|
-
"app.module.css",
|
|
15
|
-
];
|
|
16
11
|
export function buildPageTsx() {
|
|
17
12
|
return `import App from "./app";
|
|
18
13
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prototype-templates.js","sourceRoot":"","sources":["../../src/internal/prototype-templates.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAGhD,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,UAAU;IACV,SAAS;IACT,gBAAgB;IAChB,qBAAqB;IACrB,eAAe;IACf,eAAe;IACf,kBAAkB;CACV,CAAC;AAEX,MAAM,
|
|
1
|
+
{"version":3,"file":"prototype-templates.js","sourceRoot":"","sources":["../../src/internal/prototype-templates.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAGhD,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,UAAU;IACV,SAAS;IACT,gBAAgB;IAChB,qBAAqB;IACrB,eAAe;IACf,eAAe;IACf,kBAAkB;CACV,CAAC;AAEX,MAAM,UAAU,YAAY;IAC1B,OAAO;;;;;CAKR,CAAC;AACF,CAAC;AAED,MAAM,UAAU,WAAW,CACzB,KAAa,EACb,WAA0B,EAC1B,GAAiB;IAEjB,OAAO;;;;;;;;;iBASQ,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;uBACf,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC;;mBAE/B,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC;kBAC1B,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC;;;;;;CAMzC,CAAC;AACF,CAAC;AAED,MAAM,UAAU,WAAW;IACzB,OAAO;;;;;;;CAOR,CAAC;AACF,CAAC;AAED,MAAM,UAAU,iBAAiB,CAC/B,KAAa,EACb,WAA0B,EAC1B,WAAmB,EACnB,UAAyB,EACzB,SAAiB,EACjB,KAAkC;IAElC,MAAM,QAAQ,GAAsB;QAClC,KAAK;QACL,WAAW;QACX,WAAW;QACX,UAAU;QACV,SAAS,EAAE,SAAS;QACpB,SAAS,EAAE,SAAS;QACpB,UAAU,EAAE,IAAI;QAChB,GAAG,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC;KAC1C,CAAC;IACF,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC;AAClD,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,cAAsB,EAAE,WAAmB;IACvE,MAAM,sBAAsB,GAAG,QAAQ,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;IACrE,MAAM,SAAS,GAAG,IAAI,CAAC,sBAAsB,EAAE,eAAe,CAAC;SAC5D,KAAK,CAAC,GAAG,CAAC;SACV,IAAI,CAAC,GAAG,CAAC,CAAC;IACb,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC;AAChE,CAAC;AAED,MAAM,UAAU,0BAA0B;IACxC,OAAO;;;;CAIR,CAAC;AACF,CAAC","sourcesContent":["import { join, relative, sep } from \"node:path\";\nimport type { PrototypeMetadata, PrototypeRef } from \"@ebay-dt/bonfire-core\";\n\nexport const GENERATED_FILES = [\n \"page.tsx\",\n \"app.tsx\",\n \"app.module.css\",\n \"components/.gitkeep\",\n \"metadata.json\",\n \"tsconfig.json\",\n \"css-modules.d.ts\",\n] as const;\n\nexport function buildPageTsx() {\n return `import App from \"./app\";\n\nexport default function Page() {\n return <App />;\n}\n`;\n}\n\nexport function buildAppTsx(\n title: string,\n description: string | null,\n ref: PrototypeRef,\n) {\n return `\"use client\";\n\nimport { PrototypeOnboardingCard } from \"@ebay-dt/bonfire-react\";\nimport styles from \"./app.module.css\";\n\nexport default function App() {\n return (\n <main className={styles.container}>\n <PrototypeOnboardingCard\n title={${JSON.stringify(title)}}\n description={${JSON.stringify(description)}}\n prototypeRef={{\n login: ${JSON.stringify(ref.login)},\n slug: ${JSON.stringify(ref.slug)},\n }}\n />\n </main>\n );\n}\n`;\n}\n\nexport function buildAppCss() {\n return `.container {\n display: grid;\n gap: 1rem;\n min-block-size: calc(100svh - var(--app-header-block-size, 0));\n place-content: center;\n padding: 2rem;\n}\n`;\n}\n\nexport function buildMetadataJson(\n title: string,\n description: string | null,\n authorLogin: string,\n authorName: string | null,\n timestamp: string,\n theme?: PrototypeMetadata[\"theme\"],\n) {\n const metadata: PrototypeMetadata = {\n title,\n description,\n authorLogin,\n authorName,\n createdAt: timestamp,\n updatedAt: timestamp,\n previewUrl: null,\n ...(theme === undefined ? {} : { theme }),\n };\n return `${JSON.stringify(metadata, null, 2)}\\n`;\n}\n\nexport function buildTsConfig(repositoryRoot: string, destination: string) {\n const relativeRepositoryRoot = relative(destination, repositoryRoot);\n const extension = join(relativeRepositoryRoot, \"tsconfig.json\")\n .split(sep)\n .join(\"/\");\n return `${JSON.stringify({ extends: extension }, null, 2)}\\n`;\n}\n\nexport function buildCssModulesDeclaration() {\n return `declare module \"*.module.css\" {\n const classes: Record<string, string>;\n export default classes;\n}\n`;\n}\n"]}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { type GitCommitIdentity, type GitRepository } from "../git-repository.js";
|
|
2
|
+
type DeploymentPhase = "publication";
|
|
3
|
+
type DeploymentStep = "fetch" | "directory" | "marker" | "worktree-add" | "source-verify" | "namespace-read" | "namespace-write" | "namespace-commit" | "metadata-read" | "metadata-write" | "metadata-commit" | "push" | "remote-confirm" | "cleanup";
|
|
2
4
|
export type DeploymentWorktreeOptions = {
|
|
3
5
|
remote: string;
|
|
4
6
|
primaryBranch: string;
|
|
5
7
|
sourceSha: string;
|
|
8
|
+
namespacePath: string;
|
|
6
9
|
timeoutMs?: number;
|
|
7
10
|
commitIdentity?: GitCommitIdentity;
|
|
8
11
|
};
|
|
9
|
-
export type DeploymentWorktreeErrorKind = "invalid-source" | "
|
|
10
|
-
type DeploymentPhase = "preflight" | "publication";
|
|
11
|
-
type DeploymentStep = "fetch" | "directory" | "marker" | "worktree-add" | "source-verify" | "merge" | "metadata-read" | "metadata-write" | "metadata-commit" | "push" | "cleanup";
|
|
12
|
+
export type DeploymentWorktreeErrorKind = "invalid-source" | "protected-path" | "metadata-failure" | "publication-rejected" | "publication-failure" | "cleanup-failure";
|
|
12
13
|
/** Log only finite classifications; Git/OS messages may contain paths or credentials. */
|
|
13
14
|
export declare function reportDeploymentIssue(phase: DeploymentPhase, step: DeploymentStep, error: unknown): void;
|
|
14
15
|
export declare class DeploymentWorktreeError extends Error {
|
|
@@ -21,10 +22,10 @@ export declare class DeploymentWorktreeError extends Error {
|
|
|
21
22
|
operationError?: unknown;
|
|
22
23
|
});
|
|
23
24
|
}
|
|
24
|
-
export declare function preflightDeploymentSource(repository: GitRepository, options: DeploymentWorktreeOptions): Promise<void>;
|
|
25
25
|
export type DeploymentPublicationResult = {
|
|
26
26
|
attempts: 1 | 2;
|
|
27
27
|
cleanupFailed: boolean;
|
|
28
|
+
publicationSha: string;
|
|
28
29
|
};
|
|
29
30
|
export declare function publishDeploymentSource(repository: GitRepository, options: DeploymentWorktreeOptions, prepare: (workspace: {
|
|
30
31
|
path: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deployment-worktree.d.ts","sourceRoot":"","sources":["../../src/lifecycle/deployment-worktree.ts"],"names":[],"mappings":"AAGA,OAAO,EAGL,KAAK,iBA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G,CAAC,CAAC;IAChB,aAAa,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF,wBAAsB,uBAAuB,CAC3C,UAAU,EAAE,aAAa,EACzB,OAAO,EAAE,yBAAyB,EAClC,OAAO,EAAE,CAAC,SAAS,EAAE;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,aAAa,CAAC;CAC3B,KAAK,OAAO,CAAC,IAAI,CAAC,GAClB,OAAO,CAAC,2BAA2B,CAAC,CAgEtC;AAED,wBAAgB,8BAA8B,CAC5C,cAAc,EAAE,MAAM,EACtB,aAAa,EAAE,MAAM,UAGtB","sourcesContent":["import { lstat, mkdtemp, readFile, rm, writeFile } from \"node:fs/promises\";\nimport { tmpdir } from \"node:os\";\nimport { join, relative, sep } from \"node:path\";\nimport {\n createGitRepository,\n GitRepositoryError,\n type GitCommitIdentity,\n type GitRepository,\n} from \"../git-repository.js\";\n\nconst OWNERSHIP_MARKER = \"bonfire deployment workspace\\n\";\nconst SOURCE_SHA_PATTERN = /^[0-9a-f]{40,64}$/u;\n\nexport type DeploymentWorktreeOptions = {\n remote: string;\n primaryBranch: string;\n sourceSha: string;\n timeoutMs?: number;\n commitIdentity?: GitCommitIdentity;\n};\n\nexport type DeploymentWorktreeErrorKind =\n | \"invalid-source\"\n | \"preflight-conflict\"\n | \"preflight-failure\"\n | \"publication-conflict\"\n | \"publication-rejected\"\n | \"publication-failure\"\n | \"cleanup-failure\";\n\ntype DeploymentPhase = \"preflight\" | \"publication\";\ntype DeploymentStep =\n | \"fetch\"\n | \"directory\"\n | \"marker\"\n | \"worktree-add\"\n | \"source-verify\"\n | \"merge\"\n | \"metadata-read\"\n | \"metadata-write\"\n | \"metadata-commit\"\n | \"push\"\n | \"cleanup\";\n\n/** Log only finite classifications; Git/OS messages may contain paths or credentials. */\nexport function reportDeploymentIssue(\n phase: DeploymentPhase,\n step: DeploymentStep,\n error: unknown,\n) {\n const kind =\n error instanceof GitRepositoryError\n ? error.kind\n : error instanceof DeploymentWorktreeError\n ? error.kind\n : step.startsWith(\"metadata-\") ||\n step === \"directory\" ||\n step === \"marker\"\n ? \"filesystem-failure\"\n : \"unexpected\";\n console.warn(\"[bonfire] Deployment workspace attention\", {\n phase,\n step,\n kind,\n });\n}\n\nexport class DeploymentWorktreeError extends Error {\n readonly kind: DeploymentWorktreeErrorKind;\n readonly cleanupFailed: boolean;\n readonly operationError: unknown;\n readonly cause: unknown;\n\n constructor(\n kind: DeploymentWorktreeErrorKind,\n options: { cleanupFailed?: boolean; operationError?: unknown } = {},\n ) {\n super(`Deployment workspace operation failed: ${kind}`);\n this.name = \"DeploymentWorktreeError\";\n this.kind = kind;\n this.cleanupFailed = options.cleanupFailed ?? false;\n this.operationError = options.operationError;\n this.cause = options.operationError;\n }\n}\n\nfunction withCleanupFailure(error: unknown): DeploymentWorktreeError {\n if (error instanceof DeploymentWorktreeError) {\n return new DeploymentWorktreeError(error.kind, {\n cleanupFailed: true,\n operationError: error.operationError ?? error,\n });\n }\n return new DeploymentWorktreeError(\"cleanup-failure\", {\n cleanupFailed: true,\n operationError: error,\n });\n}\n\ntype DeploymentWorktree = {\n path: string;\n repository: GitRepository;\n cleanup(): Promise<void>;\n};\n\ntype DeploymentWorkspaceOperation<Value> = (\n workspace: DeploymentWorktree,\n) => Promise<Value>;\n\nfunction assertBranchName(value: string, option: string) {\n if (\n value.length === 0 ||\n value.startsWith(\"-\") ||\n value.includes(\"\\0\") ||\n /\\s/u.test(value) ||\n value.includes(\"@{\") ||\n value.split(/[\\\\/]/u).some((segment) => segment === \"..\")\n ) {\n throw new TypeError(`Invalid ${option}`);\n }\n}\n\nfunction assertSourceSha(sourceSha: string) {\n if (!SOURCE_SHA_PATTERN.test(sourceSha)) {\n throw new DeploymentWorktreeError(\"invalid-source\");\n }\n}\n\nfunction remotePrimaryRef(options: DeploymentWorktreeOptions) {\n return `refs/remotes/${options.remote}/${options.primaryBranch}`;\n}\n\nfunction mapMergeError(\n error: unknown,\n phase: \"preflight\" | \"publication\",\n): unknown {\n if (!(error instanceof GitRepositoryError)) return error;\n if (error.kind === \"conflict\") {\n return new DeploymentWorktreeError(`${phase}-conflict`);\n }\n if (phase === \"publication\") {\n if (error.kind === \"non-fast-forward\") {\n return new DeploymentWorktreeError(\"publication-rejected\");\n }\n return new DeploymentWorktreeError(\"publication-failure\");\n }\n return error;\n}\n\nasync function createDeploymentWorktree(\n repository: GitRepository,\n options: DeploymentWorktreeOptions,\n phase: DeploymentPhase,\n): Promise<DeploymentWorktree> {\n assertBranchName(options.remote, \"remote\");\n assertBranchName(options.primaryBranch, \"primary branch\");\n assertSourceSha(options.sourceSha);\n\n try {\n await repository.fetch(options.remote, options.primaryBranch);\n } catch (error) {\n reportDeploymentIssue(phase, \"fetch\", error);\n throw new DeploymentWorktreeError(`${phase}-failure`, {\n operationError: error,\n });\n }\n let operationDirectory: string;\n try {\n operationDirectory = await mkdtemp(join(tmpdir(), \"bonfire-deployment-\"));\n } catch (error) {\n reportDeploymentIssue(phase, \"directory\", error);\n throw new DeploymentWorktreeError(`${phase}-failure`, {\n operationError: error,\n });\n }\n const workspacePath = join(operationDirectory, \"workspace\");\n const markerPath = join(operationDirectory, \"OWNER\");\n\n let worktreeAdded = false;\n let step: DeploymentStep = \"marker\";\n try {\n await writeFile(markerPath, OWNERSHIP_MARKER, { flag: \"wx\" });\n step = \"worktree-add\";\n await repository.raw([\n \"worktree\",\n \"add\",\n \"--detach\",\n workspacePath,\n remotePrimaryRef(options),\n ]);\n worktreeAdded = true;\n\n const workspaceRepository = createGitRepository({\n repositoryRoot: workspacePath,\n timeoutMs: options.timeoutMs,\n commitIdentity: options.commitIdentity,\n });\n\n step = \"source-verify\";\n await workspaceRepository.raw([\n \"cat-file\",\n \"-e\",\n `${options.sourceSha}^{commit}`,\n ]);\n\n return {\n path: workspacePath,\n repository: workspaceRepository,\n async cleanup() {\n try {\n const marker = await readFile(markerPath, \"utf8\");\n const stats = await lstat(workspacePath);\n if (marker !== OWNERSHIP_MARKER || stats.isSymbolicLink()) {\n throw new DeploymentWorktreeError(\"cleanup-failure\");\n }\n await repository.raw([\n \"worktree\",\n \"remove\",\n \"--force\",\n workspacePath,\n ]);\n await rm(operationDirectory, { recursive: true, force: false });\n } catch (error) {\n reportDeploymentIssue(phase, \"cleanup\", error);\n if (error instanceof DeploymentWorktreeError) throw error;\n throw new DeploymentWorktreeError(\"cleanup-failure\", {\n operationError: error,\n });\n }\n },\n };\n } catch (error) {\n reportDeploymentIssue(phase, step, error);\n let cleanupFailed = false;\n if (worktreeAdded) {\n try {\n await repository.raw([\"worktree\", \"remove\", \"--force\", workspacePath]);\n } catch (cleanupError) {\n cleanupFailed = true;\n reportDeploymentIssue(phase, \"cleanup\", cleanupError);\n }\n }\n try {\n await rm(operationDirectory, { recursive: true, force: true });\n } catch (cleanupError) {\n cleanupFailed = true;\n reportDeploymentIssue(phase, \"cleanup\", cleanupError);\n }\n throw new DeploymentWorktreeError(`${phase}-failure`, {\n cleanupFailed,\n operationError: error,\n });\n }\n}\n\nasync function mergeSource(\n workspace: DeploymentWorktree,\n sourceSha: string,\n phase: \"preflight\" | \"publication\",\n) {\n try {\n await workspace.repository.merge([\n sourceSha,\n \"--no-ff\",\n \"-m\",\n `merge: deploy ${sourceSha.slice(0, 12)}`,\n ]);\n } catch (error) {\n reportDeploymentIssue(phase, \"merge\", error);\n const mapped = mapMergeError(error, phase);\n throw mapped instanceof DeploymentWorktreeError\n ? mapped\n : new DeploymentWorktreeError(`${phase}-failure`, {\n operationError: error,\n });\n }\n}\n\nasync function withDeploymentWorktree<Value>(\n repository: GitRepository,\n options: DeploymentWorktreeOptions,\n operation: DeploymentWorkspaceOperation<Value>,\n phase: DeploymentPhase,\n): Promise<{ value: Value; cleanupFailed: boolean }> {\n const workspace = await createDeploymentWorktree(repository, options, phase);\n let value: Value;\n try {\n value = await operation(workspace);\n } catch (error) {\n // Preserve the operation's failure while making cleanup attention\n // observable to callers.\n try {\n await workspace.cleanup();\n } catch {\n throw withCleanupFailure(error);\n }\n throw error;\n }\n\n try {\n await workspace.cleanup();\n return { value, cleanupFailed: false };\n } catch {\n return { value, cleanupFailed: true };\n }\n}\n\nexport async function preflightDeploymentSource(\n repository: GitRepository,\n options: DeploymentWorktreeOptions,\n): Promise<void> {\n const result = await withDeploymentWorktree(\n repository,\n options,\n async (workspace) => {\n await mergeSource(workspace, options.sourceSha, \"preflight\");\n },\n \"preflight\",\n );\n if (result.cleanupFailed) {\n throw new DeploymentWorktreeError(\"cleanup-failure\", {\n cleanupFailed: true,\n });\n }\n}\n\nexport type DeploymentPublicationResult = {\n attempts: 1 | 2;\n cleanupFailed: boolean;\n};\n\nexport async function publishDeploymentSource(\n repository: GitRepository,\n options: DeploymentWorktreeOptions,\n prepare: (workspace: {\n path: string;\n repository: GitRepository;\n }) => Promise<void>,\n): Promise<DeploymentPublicationResult> {\n let cleanupFailed = false;\n for (const attempt of [1, 2] as const) {\n try {\n const result = await withDeploymentWorktree(\n repository,\n options,\n async (workspace) => {\n await mergeSource(workspace, options.sourceSha, \"publication\");\n await prepare({\n path: workspace.path,\n repository: workspace.repository,\n });\n try {\n await workspace.repository.raw([\n \"push\",\n options.remote,\n `HEAD:refs/heads/${options.primaryBranch}`,\n ]);\n } catch (error) {\n reportDeploymentIssue(\"publication\", \"push\", error);\n const mapped = mapMergeError(error, \"publication\");\n throw mapped instanceof DeploymentWorktreeError\n ? mapped\n : new DeploymentWorktreeError(\"publication-failure\", {\n operationError: error,\n });\n }\n },\n \"publication\",\n );\n cleanupFailed ||= result.cleanupFailed;\n return { attempts: attempt, cleanupFailed };\n } catch (error) {\n cleanupFailed ||=\n error instanceof DeploymentWorktreeError && error.cleanupFailed;\n if (\n !(error instanceof DeploymentWorktreeError) ||\n error.kind !== \"publication-rejected\" ||\n attempt === 2\n ) {\n if (cleanupFailed) {\n if (error instanceof DeploymentWorktreeError) {\n if (!error.cleanupFailed) {\n throw new DeploymentWorktreeError(error.kind, {\n cleanupFailed: true,\n operationError: error.operationError ?? error,\n });\n }\n } else {\n throw new DeploymentWorktreeError(\"publication-failure\", {\n cleanupFailed: true,\n operationError: error,\n });\n }\n }\n throw error;\n }\n }\n }\n\n throw new DeploymentWorktreeError(\"publication-rejected\", {\n cleanupFailed,\n });\n}\n\nexport function deploymentWorktreeRelativePath(\n repositoryRoot: string,\n workspacePath: string,\n) {\n return relative(repositoryRoot, workspacePath).split(sep).join(\"/\");\n}\n"]}
|
|
1
|
+
{"version":3,"file":"deployment-worktree.d.ts","sourceRoot":"","sources":["../../src/lifecycle/deployment-worktree.ts"],"names":[],"mappings":"AAGA,OAAO,EAGL,KAAK,iBAAiB,EACtB,KAAK,aAAa,EACnB,MAAM,sBAAsB,CAAC;AAS9B,KAAK,eAAe,GAAG,aAAa,CAAC;AACrC,KAAK,cAAc,GACf,OAAO,GACP,WAAW,GACX,QAAQ,GACR,cAAc,GACd,eAAe,GACf,gBAAgB,GAChB,iBAAiB,GACjB,kBAAkB,GAClB,eAAe,GACf,gBAAgB,GAChB,iBAAiB,GACjB,MAAM,GACN,gBAAgB,GAChB,SAAS,CAAC;AAEd,MAAM,MAAM,yBAAyB,GAAG;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,iBAAiB,CAAC;CACpC,CAAC;AAEF,MAAM,MAAM,2BAA2B,GACnC,gBAAgB,GAChB,gBAAgB,GAChB,kBAAkB,GAClB,sBAAsB,GACtB,qBAAqB,GACrB,iBAAiB,CAAC;AAEtB,yFAAyF;AACzF,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,eAAe,EACtB,IAAI,EAAE,cAAc,EACpB,KAAK,EAAE,OAAO,QAkBf;AAED,qBAAa,uBAAwB,SAAQ,KAAK;IAChD,QAAQ,CAAC,IAAI,EAAE,2BAA2B,CAAC;IAC3C,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAC;IAChC,QAAQ,CAAC,cAAc,EAAE,OAAO,CAAC;IACjC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IAExB,YACE,IAAI,EAAE,2BAA2B,EACjC,OAAO,GAAE;QAAE,aAAa,CAAC,EAAE,OAAO,CAAC;QAAC,cAAc,CAAC,EAAE,OAAO,CAAA;KAAO,EAQpE;CACF;AAkdD,MAAM,MAAM,2BAA2B,GAAG;IACxC,QAAQ,EAAE,CAAC,GAAG,CAAC,CAAC;IAChB,aAAa,EAAE,OAAO,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,wBAAsB,uBAAuB,CAC3C,UAAU,EAAE,aAAa,EACzB,OAAO,EAAE,yBAAyB,EAClC,OAAO,EAAE,CAAC,SAAS,EAAE;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,aAAa,CAAC;CAC3B,KAAK,OAAO,CAAC,IAAI,CAAC,GAClB,OAAO,CAAC,2BAA2B,CAAC,CA8FtC;AAED,wBAAgB,8BAA8B,CAC5C,cAAc,EAAE,MAAM,EACtB,aAAa,EAAE,MAAM,UAGtB","sourcesContent":["import { lstat, mkdtemp, readFile, rm, writeFile } from \"node:fs/promises\";\nimport { tmpdir } from \"node:os\";\nimport { isAbsolute, join, relative, sep } from \"node:path\";\nimport {\n createGitRepository,\n GitRepositoryError,\n type GitCommitIdentity,\n type GitRepository,\n} from \"../git-repository.js\";\nimport {\n isProtectedPrototypePath,\n isRegularPrototypeMode,\n} from \"./prototype-path-policy.js\";\n\nconst OWNERSHIP_MARKER = \"bonfire deployment workspace\\n\";\nconst SOURCE_SHA_PATTERN = /^[0-9a-f]{40,64}$/u;\n\ntype DeploymentPhase = \"publication\";\ntype DeploymentStep =\n | \"fetch\"\n | \"directory\"\n | \"marker\"\n | \"worktree-add\"\n | \"source-verify\"\n | \"namespace-read\"\n | \"namespace-write\"\n | \"namespace-commit\"\n | \"metadata-read\"\n | \"metadata-write\"\n | \"metadata-commit\"\n | \"push\"\n | \"remote-confirm\"\n | \"cleanup\";\n\nexport type DeploymentWorktreeOptions = {\n remote: string;\n primaryBranch: string;\n sourceSha: string;\n namespacePath: string;\n timeoutMs?: number;\n commitIdentity?: GitCommitIdentity;\n};\n\nexport type DeploymentWorktreeErrorKind =\n | \"invalid-source\"\n | \"protected-path\"\n | \"metadata-failure\"\n | \"publication-rejected\"\n | \"publication-failure\"\n | \"cleanup-failure\";\n\n/** Log only finite classifications; Git/OS messages may contain paths or credentials. */\nexport function reportDeploymentIssue(\n phase: DeploymentPhase,\n step: DeploymentStep,\n error: unknown,\n) {\n const kind =\n step.startsWith(\"metadata-\") ||\n step.startsWith(\"namespace-\") ||\n step === \"directory\" ||\n step === \"marker\"\n ? \"filesystem-failure\"\n : error instanceof GitRepositoryError\n ? error.kind\n : error instanceof DeploymentWorktreeError\n ? error.kind\n : \"unexpected\";\n console.warn(\"[bonfire] Deployment workspace attention\", {\n phase,\n step,\n kind,\n });\n}\n\nexport class DeploymentWorktreeError extends Error {\n readonly kind: DeploymentWorktreeErrorKind;\n readonly cleanupFailed: boolean;\n readonly operationError: unknown;\n readonly cause: unknown;\n\n constructor(\n kind: DeploymentWorktreeErrorKind,\n options: { cleanupFailed?: boolean; operationError?: unknown } = {},\n ) {\n super(`Deployment workspace operation failed: ${kind}`);\n this.name = \"DeploymentWorktreeError\";\n this.kind = kind;\n this.cleanupFailed = options.cleanupFailed ?? false;\n this.operationError = options.operationError;\n this.cause = options.operationError;\n }\n}\n\nfunction withCleanupFailure(error: unknown): DeploymentWorktreeError {\n if (error instanceof DeploymentWorktreeError) {\n return new DeploymentWorktreeError(error.kind, {\n cleanupFailed: true,\n operationError: error.operationError ?? error,\n });\n }\n return new DeploymentWorktreeError(\"cleanup-failure\", {\n cleanupFailed: true,\n operationError: error,\n });\n}\n\ntype DeploymentWorktree = {\n path: string;\n repository: GitRepository;\n cleanup(): Promise<void>;\n};\n\ntype DeploymentWorkspaceOperation<Value> = (\n workspace: DeploymentWorktree,\n) => Promise<Value>;\n\ntype TreeEntry = {\n path: string;\n mode: string;\n};\n\nfunction assertBranchName(value: string, option: string) {\n if (\n value.length === 0 ||\n value.startsWith(\"-\") ||\n value.includes(\"\\0\") ||\n /\\s/u.test(value) ||\n value.includes(\"@{\") ||\n value.split(/[\\\\/]/u).some((segment) => segment === \"..\")\n ) {\n throw new TypeError(`Invalid ${option}`);\n }\n}\n\nfunction assertSourceSha(sourceSha: string) {\n if (!SOURCE_SHA_PATTERN.test(sourceSha)) {\n throw new DeploymentWorktreeError(\"invalid-source\");\n }\n}\n\nfunction assertNamespacePath(namespacePath: string) {\n if (\n namespacePath.length === 0 ||\n namespacePath === \".\" ||\n isAbsolute(namespacePath) ||\n namespacePath.startsWith(\"-\") ||\n namespacePath.includes(\"\\0\") ||\n namespacePath.includes(\"\\\\\") ||\n namespacePath.includes(\":\") ||\n /[*?\\[\\]]/u.test(namespacePath) ||\n namespacePath\n .split(\"/\")\n .some((segment) => segment.length === 0 || segment === \"..\")\n ) {\n throw new DeploymentWorktreeError(\"protected-path\");\n }\n}\n\nfunction remotePrimaryRef(options: DeploymentWorktreeOptions) {\n return `refs/remotes/${options.remote}/${options.primaryBranch}`;\n}\n\nfunction parseTreeEntries(output: string): TreeEntry[] {\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 = entry.slice(tab + 1).replaceAll(\"\\\\\", \"/\");\n if (mode === undefined || path.length === 0) return [];\n return [{ mode, path }];\n });\n}\n\nasync function readTreeEntries(\n repository: GitRepository,\n ref: string,\n namespacePath: string,\n) {\n const output = await repository.raw([\n \"ls-tree\",\n \"-r\",\n \"-z\",\n \"--full-tree\",\n ref,\n \"--\",\n namespacePath,\n ]);\n return parseTreeEntries(output);\n}\n\nfunction pathIsWithin(path: string, parent: string) {\n return path === parent || path.startsWith(`${parent}/`);\n}\n\nfunction isPrototypeRootMetadataPath(path: string, namespacePath: string) {\n if (!path.endsWith(\"/metadata.json\") || !pathIsWithin(path, namespacePath)) {\n return false;\n }\n const relativePath = path.slice(namespacePath.length + 1);\n return relativePath.split(\"/\").length === 2;\n}\n\nfunction assertSafeTree(entries: readonly TreeEntry[], namespacePath: string) {\n for (const entry of entries) {\n if (\n !pathIsWithin(entry.path, namespacePath) ||\n isProtectedPrototypePath(entry.path) ||\n !isRegularPrototypeMode(entry.mode) ||\n entry.mode.startsWith(\"120000\")\n ) {\n throw new DeploymentWorktreeError(\"protected-path\");\n }\n }\n}\n\nfunction parseObject(source: string): Record<string, unknown> | null {\n try {\n const value: unknown = JSON.parse(source);\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n return null;\n }\n return { ...(value as Record<string, unknown>) };\n } catch {\n return null;\n }\n}\n\nfunction safePreviewValue(document: Record<string, unknown>) {\n if (!Object.hasOwn(document, \"previewUrl\")) return null;\n const value = document.previewUrl;\n return value === null || typeof value === \"string\" ? value : undefined;\n}\n\nasync function capturePreviewOverlays(\n repository: GitRepository,\n sourceSha: string,\n namespacePath: string,\n sourceEntries: readonly TreeEntry[],\n primaryEntries: readonly TreeEntry[],\n) {\n const primaryPaths = new Set(primaryEntries.map((entry) => entry.path));\n const overlays: Array<{\n path: string;\n source: Record<string, unknown>;\n preview: string | null;\n }> = [];\n for (const entry of sourceEntries) {\n if (\n !isPrototypeRootMetadataPath(entry.path, namespacePath) ||\n !primaryPaths.has(entry.path)\n ) {\n continue;\n }\n const primarySource = await repository.raw([\"show\", `HEAD:${entry.path}`]);\n const primaryDocument = parseObject(primarySource);\n if (primaryDocument === null) {\n throw new DeploymentWorktreeError(\"publication-failure\");\n }\n const preview = safePreviewValue(primaryDocument);\n if (preview === undefined) {\n throw new DeploymentWorktreeError(\"publication-failure\");\n }\n const source = parseObject(\n await repository.raw([\"show\", `${sourceSha}:${entry.path}`]),\n );\n if (source === null) {\n throw new DeploymentWorktreeError(\"publication-failure\");\n }\n if (!pathIsWithin(entry.path, namespacePath)) {\n throw new DeploymentWorktreeError(\"protected-path\");\n }\n overlays.push({ path: entry.path, source, preview });\n }\n return overlays;\n}\n\nasync function composeOwnedNamespace(\n workspace: DeploymentWorktree,\n options: DeploymentWorktreeOptions,\n) {\n const step = \"namespace-read\" as const;\n let sourceEntries: TreeEntry[];\n let primaryEntries: TreeEntry[];\n try {\n sourceEntries = await readTreeEntries(\n workspace.repository,\n options.sourceSha,\n options.namespacePath,\n );\n primaryEntries = await readTreeEntries(\n workspace.repository,\n \"HEAD\",\n options.namespacePath,\n );\n assertSafeTree(sourceEntries, options.namespacePath);\n assertSafeTree(primaryEntries, options.namespacePath);\n } catch (error) {\n reportDeploymentIssue(\"publication\", step, error);\n if (error instanceof DeploymentWorktreeError) throw error;\n throw new DeploymentWorktreeError(\"publication-failure\", {\n operationError: error,\n });\n }\n\n let overlays: Awaited<ReturnType<typeof capturePreviewOverlays>>;\n try {\n overlays = await capturePreviewOverlays(\n workspace.repository,\n options.sourceSha,\n options.namespacePath,\n sourceEntries,\n primaryEntries,\n );\n } catch (error) {\n reportDeploymentIssue(\"publication\", \"metadata-read\", error);\n if (error instanceof DeploymentWorktreeError) {\n if (error.kind === \"publication-failure\") {\n throw new DeploymentWorktreeError(\"metadata-failure\", {\n operationError: error,\n });\n }\n throw error;\n }\n throw new DeploymentWorktreeError(\"metadata-failure\", {\n operationError: error,\n });\n }\n\n try {\n await workspace.repository.raw([\n \"rm\",\n \"-r\",\n \"--ignore-unmatch\",\n \"--\",\n options.namespacePath,\n ]);\n if (sourceEntries.length > 0) {\n await workspace.repository.raw([\n \"checkout\",\n options.sourceSha,\n \"--\",\n options.namespacePath,\n ]);\n }\n\n const overlayPaths: string[] = [];\n for (const overlay of overlays) {\n const absolutePath = join(workspace.path, overlay.path);\n const currentSource = await readFile(absolutePath, \"utf8\");\n const currentDocument = parseObject(currentSource);\n if (currentDocument === null) {\n throw new DeploymentWorktreeError(\"publication-failure\");\n }\n await writeFile(\n absolutePath,\n `${JSON.stringify({ ...currentDocument, previewUrl: overlay.preview }, null, 2)}\\n`,\n );\n overlayPaths.push(overlay.path);\n }\n if (overlayPaths.length > 0) {\n await workspace.repository.add(overlayPaths);\n }\n } catch (error) {\n reportDeploymentIssue(\"publication\", \"namespace-write\", error);\n if (error instanceof DeploymentWorktreeError) throw error;\n throw new DeploymentWorktreeError(\"publication-failure\", {\n operationError: error,\n });\n }\n}\n\nasync function createDeploymentWorktree(\n repository: GitRepository,\n options: DeploymentWorktreeOptions,\n): Promise<DeploymentWorktree> {\n assertBranchName(options.remote, \"remote\");\n assertBranchName(options.primaryBranch, \"primary branch\");\n assertSourceSha(options.sourceSha);\n assertNamespacePath(options.namespacePath);\n\n try {\n await repository.fetch(options.remote, options.primaryBranch);\n } catch (error) {\n reportDeploymentIssue(\"publication\", \"fetch\", error);\n throw new DeploymentWorktreeError(\"publication-failure\", {\n operationError: error,\n });\n }\n let operationDirectory: string;\n try {\n operationDirectory = await mkdtemp(join(tmpdir(), \"bonfire-deployment-\"));\n } catch (error) {\n reportDeploymentIssue(\"publication\", \"directory\", error);\n throw new DeploymentWorktreeError(\"publication-failure\", {\n operationError: error,\n });\n }\n const workspacePath = join(operationDirectory, \"workspace\");\n const markerPath = join(operationDirectory, \"OWNER\");\n\n let worktreeAdded = false;\n let step: DeploymentStep = \"marker\";\n try {\n await writeFile(markerPath, OWNERSHIP_MARKER, { flag: \"wx\" });\n step = \"worktree-add\";\n await repository.raw([\n \"worktree\",\n \"add\",\n \"--detach\",\n workspacePath,\n remotePrimaryRef(options),\n ]);\n worktreeAdded = true;\n\n const workspaceRepository = createGitRepository({\n repositoryRoot: workspacePath,\n timeoutMs: options.timeoutMs,\n commitIdentity: options.commitIdentity,\n });\n\n step = \"source-verify\";\n await workspaceRepository.raw([\n \"cat-file\",\n \"-e\",\n `${options.sourceSha}^{commit}`,\n ]);\n\n return {\n path: workspacePath,\n repository: workspaceRepository,\n async cleanup() {\n try {\n const marker = await readFile(markerPath, \"utf8\");\n const stats = await lstat(workspacePath);\n if (marker !== OWNERSHIP_MARKER || stats.isSymbolicLink()) {\n throw new DeploymentWorktreeError(\"cleanup-failure\");\n }\n await repository.raw([\n \"worktree\",\n \"remove\",\n \"--force\",\n workspacePath,\n ]);\n await rm(operationDirectory, { recursive: true, force: false });\n } catch (error) {\n reportDeploymentIssue(\"publication\", \"cleanup\", error);\n if (error instanceof DeploymentWorktreeError) throw error;\n throw new DeploymentWorktreeError(\"cleanup-failure\", {\n operationError: error,\n });\n }\n },\n };\n } catch (error) {\n reportDeploymentIssue(\"publication\", step, error);\n let cleanupFailed = false;\n if (worktreeAdded) {\n try {\n await repository.raw([\"worktree\", \"remove\", \"--force\", workspacePath]);\n } catch (cleanupError) {\n cleanupFailed = true;\n reportDeploymentIssue(\"publication\", \"cleanup\", cleanupError);\n }\n }\n try {\n await rm(operationDirectory, { recursive: true, force: true });\n } catch (cleanupError) {\n cleanupFailed = true;\n reportDeploymentIssue(\"publication\", \"cleanup\", cleanupError);\n }\n throw new DeploymentWorktreeError(\"publication-failure\", {\n cleanupFailed,\n operationError: error,\n });\n }\n}\n\nasync function withDeploymentWorktree<Value>(\n repository: GitRepository,\n options: DeploymentWorktreeOptions,\n operation: DeploymentWorkspaceOperation<Value>,\n): Promise<{ value: Value; cleanupFailed: boolean }> {\n const workspace = await createDeploymentWorktree(repository, options);\n let value: Value;\n try {\n value = await operation(workspace);\n } catch (error) {\n try {\n await workspace.cleanup();\n } catch {\n throw withCleanupFailure(error);\n }\n throw error;\n }\n\n try {\n await workspace.cleanup();\n return { value, cleanupFailed: false };\n } catch {\n return { value, cleanupFailed: true };\n }\n}\n\nfunction mapPushError(error: unknown) {\n if (error instanceof DeploymentWorktreeError) return error;\n if (\n error instanceof GitRepositoryError &&\n error.kind === \"non-fast-forward\"\n ) {\n return new DeploymentWorktreeError(\"publication-rejected\");\n }\n return new DeploymentWorktreeError(\"publication-failure\", {\n operationError: error,\n });\n}\n\nasync function remoteCommit(\n repository: GitRepository,\n options: DeploymentWorktreeOptions,\n) {\n const output = await repository.raw([\n \"ls-remote\",\n options.remote,\n `refs/heads/${options.primaryBranch}`,\n ]);\n const commit = output.trim().split(/\\s+/u)[0];\n return commit !== undefined && SOURCE_SHA_PATTERN.test(commit)\n ? commit.toLowerCase()\n : null;\n}\n\nasync function remoteContainsPublication(\n repository: GitRepository,\n options: DeploymentWorktreeOptions,\n publicationSha: string,\n) {\n const remoteSha = await remoteCommit(repository, options);\n if (remoteSha === publicationSha) return true;\n if (remoteSha === null) return false;\n try {\n // Fetch only updates the repository's remote-tracking ref; it does not\n // modify the active checkout. This recognizes an accepted push followed\n // by a primary descendant without repeating publication work.\n await repository.fetch(options.remote, options.primaryBranch);\n const mergeBase = (\n await repository.raw([\"merge-base\", publicationSha, remoteSha])\n ).trim();\n return mergeBase === publicationSha;\n } catch {\n return false;\n }\n}\n\nexport type DeploymentPublicationResult = {\n attempts: 1 | 2;\n cleanupFailed: boolean;\n publicationSha: string;\n};\n\nexport async function publishDeploymentSource(\n repository: GitRepository,\n options: DeploymentWorktreeOptions,\n prepare: (workspace: {\n path: string;\n repository: GitRepository;\n }) => Promise<void>,\n): Promise<DeploymentPublicationResult> {\n let cleanupFailed = false;\n for (const attempt of [1, 2] as const) {\n try {\n const result = await withDeploymentWorktree(\n repository,\n options,\n async (workspace) => {\n await composeOwnedNamespace(workspace, options);\n await prepare({\n path: workspace.path,\n repository: workspace.repository,\n });\n try {\n await workspace.repository.commit(\n `deploy: publish ${options.sourceSha.slice(0, 12)}`,\n );\n } catch (error) {\n reportDeploymentIssue(\"publication\", \"namespace-commit\", error);\n throw new DeploymentWorktreeError(\"publication-failure\", {\n operationError: error,\n });\n }\n\n const publicationSha = (\n await workspace.repository.raw([\"rev-parse\", \"HEAD\"])\n ).trim();\n try {\n await workspace.repository.raw([\n \"push\",\n options.remote,\n `HEAD:refs/heads/${options.primaryBranch}`,\n ]);\n } catch (error) {\n reportDeploymentIssue(\"publication\", \"push\", error);\n try {\n if (\n await remoteContainsPublication(\n repository,\n options,\n publicationSha,\n )\n ) {\n return { publicationSha };\n }\n } catch (confirmationError) {\n reportDeploymentIssue(\n \"publication\",\n \"remote-confirm\",\n confirmationError,\n );\n }\n throw mapPushError(error);\n }\n return { publicationSha };\n },\n );\n cleanupFailed ||= result.cleanupFailed;\n return {\n attempts: attempt,\n cleanupFailed,\n publicationSha: result.value.publicationSha,\n };\n } catch (error) {\n cleanupFailed ||=\n error instanceof DeploymentWorktreeError && error.cleanupFailed;\n if (\n !(error instanceof DeploymentWorktreeError) ||\n error.kind !== \"publication-rejected\" ||\n attempt === 2\n ) {\n if (cleanupFailed) {\n if (error instanceof DeploymentWorktreeError) {\n if (!error.cleanupFailed) {\n throw new DeploymentWorktreeError(error.kind, {\n cleanupFailed: true,\n operationError: error.operationError ?? error,\n });\n }\n } else {\n throw new DeploymentWorktreeError(\"publication-failure\", {\n cleanupFailed: true,\n operationError: error,\n });\n }\n }\n throw error;\n }\n }\n }\n\n throw new DeploymentWorktreeError(\"publication-rejected\", {\n cleanupFailed,\n });\n}\n\nexport function deploymentWorktreeRelativePath(\n repositoryRoot: string,\n workspacePath: string,\n) {\n return relative(repositoryRoot, workspacePath).split(sep).join(\"/\");\n}\n"]}
|