@ebay-dt/bonfire-cli 0.3.0-alpha.0 → 0.3.0-alpha.2
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 +1 -1
- package/dist/branch-prepare.d.ts.map +1 -1
- package/dist/branch-prepare.js +63 -2
- package/dist/branch-prepare.js.map +1 -1
- package/dist/release-versions.d.ts +1 -1
- package/dist/release-versions.d.ts.map +1 -1
- package/dist/release-versions.js +1 -1
- package/dist/release-versions.js.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -99,6 +99,6 @@ preparation failures still exit nonzero; no other branch is silently used.
|
|
|
99
99
|
The command never starts interactive authentication or prints identity,
|
|
100
100
|
credentials, paths, or raw Git output.
|
|
101
101
|
|
|
102
|
-
Non-production branch preparation regenerates eligible ignored, untracked prototype context even in manual or deferred modes. On a ready identity branch it first makes at most one untrack commit for that login. Tracked
|
|
102
|
+
Non-production branch preparation regenerates eligible ignored, untracked prototype context even in manual or deferred modes. On a ready identity branch it first makes at most one untrack commit for that login. Tracked outputs are silently protected; unignored outputs are skipped with a warning; failures here are nonfatal. Production and fatal partial transitions do not regenerate. Missing canonical skill registrations trigger a recommendation to run `pnpm context:install`, not an automatic install. This check parses a literal `--app-id` from the `context:install` script and silently skips unsupported scripts or unreadable registry state.
|
|
103
103
|
|
|
104
104
|
Converted apps use `next dev` without a fixed port, and ignore `**/.next/` and the three generated outputs under the default prototype root. Custom runtime roots need corresponding ignore rules. Canonical skills include `prototype-controls`; users request its adoption explicitly.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"branch-prepare.d.ts","sourceRoot":"","sources":["../src/branch-prepare.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAOlE,OAAO,EAIL,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACxB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAEhE,MAAM,MAAM,oBAAoB,GAAG,CACjC,IAAI,EAAE,MAAM,KACT,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC;AAElD,MAAM,MAAM,yBAAyB,GAAG;IACtC,2BAA2B,CAAC,EAAE,OAAO,sBAAsB,CAAC;IAC5D,WAAW,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC;IAC3D,eAAe,CAAC,EAAE,oBAAoB,CAAC;IACvC,SAAS,CAAC,EAAE,mBAAmB,CAAC;IAChC,eAAe,CAAC,EAAE,CAAC,OAAO,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,KAAK,mBAAmB,CAAC;IACzE,SAAS,CAAC,EAAE,IAAI,CAAC,kBAAkB,EAAE,eAAe,GAAG,qBAAqB,CAAC,CAAC;IAC9E,mBAAmB,CAAC,EAAE,mBAAmB,CAAC;IAC1C,0BAA0B,CAAC,EAAE,WAAW,CACtC,kBAAkB,CAAC,4BAA4B,CAAC,CACjD,CAAC;IACF,uBAAuB,CAAC,EAAE,kBAAkB,CAAC,yBAAyB,CAAC,CAAC;CACzE,CAAC;AAEF,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,YAAY,OAAO,EAAE,MAAM,EAG1B;CACF;AAMD,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,2BAA2B,EACpC,YAAY,EAAE,yBAAyB,GACtC,OAAO,CAAC,MAAM,CAAC,CAiTjB","sourcesContent":["import { missingInstalledSkills } from \"@ebay-dt/bonfire-context\";\nimport nextEnv from \"@next/env\";\nimport {\n parseAutomaticBranchSwitchSetting,\n parseGitModeSetting,\n parseHostname,\n} from \"@ebay-dt/bonfire-core\";\nimport {\n GitHubCliClient,\n GitHubCliError,\n LocalPrototypeLifecycle,\n type DependencyInstaller,\n type GitHubCliClientLike,\n type PrototypeLifecycle,\n} from \"@ebay-dt/bonfire-node\";\nimport { isAbsolute, relative, resolve, sep } from \"node:path\";\nimport type { BranchPrepareCommandOptions } from \"./command.js\";\n\nexport type CliEnvironmentLoader = (\n root: string,\n) => Readonly<Record<string, string | undefined>>;\n\nexport type BranchPrepareDependencies = {\n checkMissingInstalledSkills?: typeof missingInstalledSkills;\n environment?: Readonly<Record<string, string | undefined>>;\n loadEnvironment?: CliEnvironmentLoader;\n githubCli?: GitHubCliClientLike;\n createGitHubCli?: (options: { hostname: string }) => GitHubCliClientLike;\n lifecycle?: Pick<PrototypeLifecycle, \"prepareBranch\" | \"prepareDependencies\">;\n installDependencies?: DependencyInstaller;\n regenerateGeneratedContext?: NonNullable<\n PrototypeLifecycle[\"regenerateGeneratedContext\"]\n >;\n untrackGeneratedContext?: PrototypeLifecycle[\"untrackGeneratedContext\"];\n};\n\nexport class BranchPrepareError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"BranchPrepareError\";\n }\n}\n\nfunction loadEnvironment(root: string) {\n return nextEnv.loadEnvConfig(root, true, undefined, false).combinedEnv;\n}\n\nexport async function runBranchPrepare(\n options: BranchPrepareCommandOptions,\n dependencies: BranchPrepareDependencies,\n): Promise<number> {\n const root = resolve(options.root);\n const environment =\n dependencies.environment ??\n dependencies.loadEnvironment?.(root) ??\n loadEnvironment(root);\n // This guard must precede marker reads, identity resolution, and all Git\n // collaborators. A direct production invocation must remain read-only even\n // when a previous development install left recovery state behind.\n if (environment.NODE_ENV === \"production\") {\n return 0;\n }\n\n const checkSkills = async () => {\n try {\n const missing = await (\n dependencies.checkMissingInstalledSkills ?? missingInstalledSkills\n )({ repositoryRoot: root });\n if (missing.length)\n console.warn(\n \"Canonical skills are not installed for this app; run pnpm context:install.\",\n );\n } catch {\n console.warn(\n \"Unable to check installed skills; continuing branch preparation.\",\n );\n }\n };\n\n const generatedLifecycle = () =>\n new LocalPrototypeLifecycle({\n repositoryRoot: root,\n prototypeRoot: options.prototypeRoot ?? environment.BF_PROTOTYPE_ROOT,\n remote: options.remote ?? environment.BF_GIT_REMOTE,\n primaryBranch:\n options.primaryBranch ?? environment.BF_PROTOTYPE_BASE_BRANCH,\n automaticBranchSwitch: parseAutomaticBranchSwitchSetting(\n environment.BF_DISABLE_AUTO_BRANCH_SWITCH,\n ),\n gitMode: parseGitModeSetting(environment.BF_GIT_MODE),\n });\n const ignoredPaths = new Set<string>();\n const configuredRoot =\n options.prototypeRoot ??\n environment.BF_PROTOTYPE_ROOT ??\n \"src/app/(prototypes)\";\n const relativeRoot = relative(root, resolve(root, configuredRoot));\n const safeRoot =\n relativeRoot &&\n relativeRoot !== \"..\" &&\n !relativeRoot.startsWith(`..${sep}`) &&\n !isAbsolute(relativeRoot) &&\n !configuredRoot.split(/[\\\\/]/u).includes(\"..\")\n ? relativeRoot\n .split(sep)\n .join(\"/\")\n .replace(/[\\\\*?[\\] ]/gu, \"\\\\$&\")\n : undefined;\n const regenerate = async () => {\n try {\n const result = await (\n dependencies.regenerateGeneratedContext ??\n (() => generatedLifecycle().regenerateGeneratedContext())\n )();\n if (!result.ok)\n console.warn(\n `Generated context regeneration skipped: ${result.error.code}.`,\n );\n else {\n for (const [reason, paths] of Object.entries(result.value.skipped)) {\n if (reason === \"not ignored\")\n paths.forEach((path) => ignoredPaths.add(path));\n else if (paths.length)\n console.warn(\n `Generated context regeneration skipped (${reason}): ${paths.join(\", \")}.`,\n );\n }\n }\n } catch {\n console.warn(\n \"Generated context regeneration failed; continuing branch preparation.\",\n );\n }\n if (ignoredPaths.size)\n console.warn(\n `Generated context skipped: ${[...ignoredPaths].join(\", \")}. ${\n safeRoot\n ? `Add these .gitignore patterns:\\n${[\"AGENTS.md\", \"CLAUDE.md\", \".claude/settings.json\"].map((file) => `/${safeRoot}/*/*/${file}`).join(\"\\n\")}`\n : \"Check the configured prototype root before adding .gitignore patterns.\"\n }`,\n );\n };\n const untrack = async (\n identity: Parameters<PrototypeLifecycle[\"untrackGeneratedContext\"]>[0],\n ) => {\n try {\n const result = await (\n dependencies.untrackGeneratedContext ??\n ((user) => generatedLifecycle().untrackGeneratedContext(user))\n )(identity);\n if (!result.ok)\n console.warn(\n `Generated context untrack skipped: ${result.error.code}.`,\n );\n else if (result.value.status === \"skipped\") {\n const { reason, paths } = result.value;\n if (\n reason === \"wrong-branch\" ||\n reason === \"HEAD is not the identity branch.\"\n )\n return;\n if (\n reason ===\n \"Generated context is not ignored; add the recommended ignore rules before untracking.\"\n )\n paths.forEach((path) => ignoredPaths.add(path));\n else\n console.warn(\n `Generated context untrack skipped: ${reason}${paths.length ? ` (${paths.join(\", \")})` : \"\"}`,\n );\n }\n } catch {\n console.warn(\n \"Generated context untrack failed; continuing branch preparation.\",\n );\n }\n };\n\n const mode = parseAutomaticBranchSwitchSetting(\n environment.BF_DISABLE_AUTO_BRANCH_SWITCH,\n );\n const gitMode = parseGitModeSetting(environment.BF_GIT_MODE);\n\n if (gitMode === \"manual\") {\n console.log(\"Git management is in manual mode.\");\n await regenerate();\n await checkSkills();\n return 0;\n }\n\n if (mode === \"disabled\") {\n console.log(\"Automatic branch switching is disabled.\");\n await regenerate();\n await checkSkills();\n return 0;\n }\n\n // Explicit --hostname wins. Generated scripts use --default-hostname so\n // Next-compatible .env.local loading can supply BF_GITHUB_HOSTNAME first.\n const hostname = parseHostname(\n options.hostname ??\n environment.BF_GITHUB_HOSTNAME ??\n options.defaultHostname,\n );\n const lifecycle =\n dependencies.lifecycle ??\n new LocalPrototypeLifecycle({\n repositoryRoot: root,\n prototypeRoot: options.prototypeRoot ?? environment.BF_PROTOTYPE_ROOT,\n remote: options.remote ?? environment.BF_GIT_REMOTE,\n primaryBranch:\n options.primaryBranch ?? environment.BF_PROTOTYPE_BASE_BRANCH,\n automaticBranchSwitch: mode,\n gitMode,\n installDependencies: dependencies.installDependencies,\n });\n const prepareDependencies = lifecycle.prepareDependencies;\n if (prepareDependencies !== undefined) {\n console.log(\"Checking pending dependency preparation...\");\n const pending = await prepareDependencies.call(\n lifecycle,\n [],\n dependencies.installDependencies,\n );\n if (!pending.ok) {\n throw new BranchPrepareError(\"Unable to prepare project dependencies.\");\n }\n if (pending.value.status === \"failed\") {\n throw new BranchPrepareError(\n \"Dependency preparation failed; the development server was not started.\",\n );\n }\n if (pending.value.status === \"prepared\") {\n console.log(\"Pending project dependencies prepared.\");\n }\n }\n\n const githubCli =\n dependencies.githubCli ??\n dependencies.createGitHubCli?.({ hostname }) ??\n new GitHubCliClient({ hostname });\n let identity;\n try {\n identity = await githubCli.getUser();\n } catch (error) {\n if (\n error instanceof GitHubCliError &&\n (error.reason === \"missing\" || error.reason === \"unauthenticated\")\n ) {\n console.log(\n \"Branch preparation deferred; GitHub CLI authentication is not available.\",\n );\n await regenerate();\n await checkSkills();\n return 0;\n }\n throw new BranchPrepareError(\"Unable to resolve GitHub CLI identity.\");\n }\n\n console.log(\"Synchronizing project platform...\");\n const result = await lifecycle.prepareBranch(identity);\n if (!result.ok) {\n throw new BranchPrepareError(\n `Branch preparation failed with ${result.error.code}.`,\n );\n }\n\n if (result.value.status === \"deferred\") {\n console.log(\n result.value.reason === \"dirty-worktree\"\n ? \"Branch preparation deferred: uncommitted changes outside the prototype folder; platform updates were not applied.\"\n : `Branch preparation deferred; repository attention: ${result.value.reason}.`,\n );\n // A dirty/offline check that made no changes is safe to leave for the\n // existing environment. Never launch after a partially applied update.\n if (\n result.value.effects.changed ||\n result.value.effects.pushed ||\n result.value.effects.reconciledPaths.length > 0 ||\n (result.value.effects.platformPaths?.length ?? 0) > 0 ||\n (result.value.effects.dependencyPaths?.length ?? 0) > 0 ||\n result.value.effects.preparationRequired === true ||\n result.value.effects.restartRequired\n ) {\n throw new BranchPrepareError(\n \"Branch preparation was only partially completed; the development server was not started.\",\n );\n }\n await regenerate();\n await checkSkills();\n return 0;\n }\n if (result.value.status === \"unsafe\") {\n console.log(\n `Branch preparation requires repository attention (${result.value.reason}).`,\n );\n const effects = result.value.effects;\n const actualContentTransition =\n effects.reconciledPaths.length > 0 ||\n (effects.platformPaths?.length ?? 0) > 0 ||\n (effects.dependencyPaths?.length ?? 0) > 0 ||\n effects.preparationRequired === true ||\n effects.restartRequired;\n // History-only checkpoints and other no-effect safety refusals do not\n // justify taking down startup. A partial checkout/platform/dependency\n // transition still does: the existing environment must not run against\n // an unsafe working tree.\n if (!actualContentTransition) {\n await regenerate();\n await checkSkills();\n return 0;\n }\n throw new BranchPrepareError(\n \"Branch preparation was only partially completed; the development server was not started.\",\n );\n }\n if (result.value.status === \"disabled\") {\n console.log(\n \"Branch preparation skipped; synchronization is disabled by configuration.\",\n );\n await regenerate();\n await checkSkills();\n return 0;\n }\n\n await untrack(identity);\n await regenerate();\n\n const dependencyPaths = result.value.effects.dependencyPaths ?? [];\n const managedPathChanged =\n dependencyPaths.length > 0 ||\n result.value.effects.preparationRequired === true;\n if (managedPathChanged) {\n console.log(\"Installing updated project dependencies...\");\n if (prepareDependencies !== undefined) {\n const preparation = await prepareDependencies.call(\n lifecycle,\n dependencyPaths,\n dependencies.installDependencies,\n );\n if (!preparation.ok || preparation.value.status === \"failed\") {\n throw new BranchPrepareError(\n \"Dependency preparation failed; the development server was not started.\",\n );\n }\n } else {\n throw new BranchPrepareError(\n \"This lifecycle does not support dependency preparation; the development server was not started.\",\n );\n }\n }\n\n await checkSkills();\n console.log(\"Branch preparation complete.\");\n return 0;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"branch-prepare.d.ts","sourceRoot":"","sources":["../src/branch-prepare.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAQlE,OAAO,EAIL,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACxB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAEhE,MAAM,MAAM,oBAAoB,GAAG,CACjC,IAAI,EAAE,MAAM,KACT,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC;AAElD,MAAM,MAAM,yBAAyB,GAAG;IACtC,2BAA2B,CAAC,EAAE,OAAO,sBAAsB,CAAC;IAC5D,WAAW,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC;IAC3D,eAAe,CAAC,EAAE,oBAAoB,CAAC;IACvC,SAAS,CAAC,EAAE,mBAAmB,CAAC;IAChC,eAAe,CAAC,EAAE,CAAC,OAAO,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,KAAK,mBAAmB,CAAC;IACzE,SAAS,CAAC,EAAE,IAAI,CAAC,kBAAkB,EAAE,eAAe,GAAG,qBAAqB,CAAC,CAAC;IAC9E,mBAAmB,CAAC,EAAE,mBAAmB,CAAC;IAC1C,0BAA0B,CAAC,EAAE,WAAW,CACtC,kBAAkB,CAAC,4BAA4B,CAAC,CACjD,CAAC;IACF,uBAAuB,CAAC,EAAE,kBAAkB,CAAC,yBAAyB,CAAC,CAAC;CACzE,CAAC;AAEF,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,YAAY,OAAO,EAAE,MAAM,EAG1B;CACF;AA+DD,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,2BAA2B,EACpC,YAAY,EAAE,yBAAyB,GACtC,OAAO,CAAC,MAAM,CAAC,CAgUjB","sourcesContent":["import { missingInstalledSkills } from \"@ebay-dt/bonfire-context\";\nimport nextEnv from \"@next/env\";\nimport {\n parseAutomaticBranchSwitchSetting,\n parseGitModeSetting,\n parseHostname,\n type BranchPreparationDiagnostic,\n} from \"@ebay-dt/bonfire-core\";\nimport {\n GitHubCliClient,\n GitHubCliError,\n LocalPrototypeLifecycle,\n type DependencyInstaller,\n type GitHubCliClientLike,\n type PrototypeLifecycle,\n} from \"@ebay-dt/bonfire-node\";\nimport { isAbsolute, relative, resolve, sep } from \"node:path\";\nimport { styleText } from \"node:util\";\nimport type { BranchPrepareCommandOptions } from \"./command.js\";\n\nexport type CliEnvironmentLoader = (\n root: string,\n) => Readonly<Record<string, string | undefined>>;\n\nexport type BranchPrepareDependencies = {\n checkMissingInstalledSkills?: typeof missingInstalledSkills;\n environment?: Readonly<Record<string, string | undefined>>;\n loadEnvironment?: CliEnvironmentLoader;\n githubCli?: GitHubCliClientLike;\n createGitHubCli?: (options: { hostname: string }) => GitHubCliClientLike;\n lifecycle?: Pick<PrototypeLifecycle, \"prepareBranch\" | \"prepareDependencies\">;\n installDependencies?: DependencyInstaller;\n regenerateGeneratedContext?: NonNullable<\n PrototypeLifecycle[\"regenerateGeneratedContext\"]\n >;\n untrackGeneratedContext?: PrototypeLifecycle[\"untrackGeneratedContext\"];\n};\n\nexport class BranchPrepareError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"BranchPrepareError\";\n }\n}\n\nconst diagnosticStages: Record<BranchPreparationDiagnostic[\"stage\"], string> = {\n \"checkout-identity-branch\": \"checking out the identity branch\",\n \"configure-identity-upstream\": \"configuring the identity upstream\",\n \"prepare-reconciliation\": \"preparing reconciliation\",\n \"compose-baseline-tree\": \"composing the baseline tree\",\n \"create-baseline-commit\": \"creating the baseline commit\",\n \"apply-platform-patch\": \"applying the platform patch\",\n \"update-identity-ref\": \"updating the identity reference\",\n \"verify-reconciliation\": \"verifying reconciliation\",\n \"rollback-platform-patch\": \"rolling back the platform patch\",\n};\n\nconst diagnosticReasons: Record<BranchPreparationDiagnostic[\"reason\"], string> =\n {\n \"index-locked\": \"the Git index is locked\",\n \"patch-does-not-apply\": \"the patch does not apply\",\n \"identity-missing\": \"Git identity is missing\",\n \"ref-changed\": \"the reference changed\",\n \"permission-denied\": \"permission was denied\",\n \"missing-path-or-object\": \"a path or object is missing\",\n \"worktree-obstruction\": \"the working tree obstructs the operation\",\n \"worktree-changed\": \"the working tree changed\",\n unknown: \"the cause is unknown\",\n };\n\nfunction printDiagnostic(\n label: string,\n diagnostic: BranchPreparationDiagnostic,\n) {\n const ownData = (key: string): unknown => {\n try {\n const descriptor = Object.getOwnPropertyDescriptor(diagnostic, key);\n return descriptor && \"value\" in descriptor ? descriptor.value : undefined;\n } catch {\n return undefined;\n }\n };\n const stageValue = ownData(\"stage\");\n const reasonValue = ownData(\"reason\");\n const exitValue = ownData(\"exitCode\");\n const stage =\n typeof stageValue === \"string\" &&\n Object.hasOwn(diagnosticStages, stageValue)\n ? diagnosticStages[stageValue as BranchPreparationDiagnostic[\"stage\"]]\n : \"an unknown stage\";\n const reason =\n typeof reasonValue === \"string\" &&\n Object.hasOwn(diagnosticReasons, reasonValue)\n ? diagnosticReasons[reasonValue as BranchPreparationDiagnostic[\"reason\"]]\n : diagnosticReasons.unknown;\n const exitCode =\n typeof exitValue === \"number\" && Number.isSafeInteger(exitValue)\n ? ` (exit code ${exitValue})`\n : \"\";\n console.log(`${label}: ${stage}: ${reason}${exitCode}.`);\n}\n\nfunction loadEnvironment(root: string) {\n return nextEnv.loadEnvConfig(root, true, undefined, false).combinedEnv;\n}\n\nexport async function runBranchPrepare(\n options: BranchPrepareCommandOptions,\n dependencies: BranchPrepareDependencies,\n): Promise<number> {\n const root = resolve(options.root);\n const environment =\n dependencies.environment ??\n dependencies.loadEnvironment?.(root) ??\n loadEnvironment(root);\n // This guard must precede marker reads, identity resolution, and all Git\n // collaborators. A direct production invocation must remain read-only even\n // when a previous development install left recovery state behind.\n if (environment.NODE_ENV === \"production\") {\n return 0;\n }\n\n const checkSkills = async () => {\n try {\n const missing = await (\n dependencies.checkMissingInstalledSkills ?? missingInstalledSkills\n )({ repositoryRoot: root });\n if (missing.length)\n console.warn(\n `\n${styleText([\"bold\", \"yellow\"], \"⚠ AGENT SKILLS SETUP NEEDED\", { stream: process.stderr })}\n\nStop the dev server, then run:\n\n pnpm context:install\n\nRestart with pnpm dev.\n`,\n );\n } catch {\n console.warn(\n \"Unable to check installed skills; continuing branch preparation.\",\n );\n }\n };\n\n const generatedLifecycle = () =>\n new LocalPrototypeLifecycle({\n repositoryRoot: root,\n prototypeRoot: options.prototypeRoot ?? environment.BF_PROTOTYPE_ROOT,\n remote: options.remote ?? environment.BF_GIT_REMOTE,\n primaryBranch:\n options.primaryBranch ?? environment.BF_PROTOTYPE_BASE_BRANCH,\n automaticBranchSwitch: parseAutomaticBranchSwitchSetting(\n environment.BF_DISABLE_AUTO_BRANCH_SWITCH,\n ),\n gitMode: parseGitModeSetting(environment.BF_GIT_MODE),\n });\n const ignoredPaths = new Set<string>();\n const configuredRoot =\n options.prototypeRoot ??\n environment.BF_PROTOTYPE_ROOT ??\n \"src/app/(prototypes)\";\n const relativeRoot = relative(root, resolve(root, configuredRoot));\n const safeRoot =\n relativeRoot &&\n relativeRoot !== \"..\" &&\n !relativeRoot.startsWith(`..${sep}`) &&\n !isAbsolute(relativeRoot) &&\n !configuredRoot.split(/[\\\\/]/u).includes(\"..\")\n ? relativeRoot\n .split(sep)\n .join(\"/\")\n .replace(/[\\\\*?[\\] ]/gu, \"\\\\$&\")\n : undefined;\n const regenerate = async () => {\n try {\n const result = await (\n dependencies.regenerateGeneratedContext ??\n (() => generatedLifecycle().regenerateGeneratedContext())\n )();\n if (!result.ok)\n console.warn(\n `Generated context regeneration skipped: ${result.error.code}.`,\n );\n else {\n for (const [reason, paths] of Object.entries(result.value.skipped)) {\n if (reason === \"not ignored\")\n paths.forEach((path) => ignoredPaths.add(path));\n else if (reason !== \"tracked\" && paths.length)\n console.warn(\n `Generated context regeneration skipped (${reason}): ${paths.join(\", \")}.`,\n );\n }\n }\n } catch {\n console.warn(\n \"Generated context regeneration failed; continuing branch preparation.\",\n );\n }\n if (ignoredPaths.size)\n console.warn(\n `Generated context skipped: ${[...ignoredPaths].join(\", \")}. ${\n safeRoot\n ? `Add these .gitignore patterns:\\n${[\"AGENTS.md\", \"CLAUDE.md\", \".claude/settings.json\"].map((file) => `/${safeRoot}/*/*/${file}`).join(\"\\n\")}`\n : \"Check the configured prototype root before adding .gitignore patterns.\"\n }`,\n );\n };\n const untrack = async (\n identity: Parameters<PrototypeLifecycle[\"untrackGeneratedContext\"]>[0],\n ) => {\n try {\n const result = await (\n dependencies.untrackGeneratedContext ??\n ((user) => generatedLifecycle().untrackGeneratedContext(user))\n )(identity);\n if (!result.ok)\n console.warn(\n `Generated context untrack skipped: ${result.error.code}.`,\n );\n else if (result.value.status === \"skipped\") {\n const { reason, paths } = result.value;\n if (\n reason === \"wrong-branch\" ||\n reason === \"HEAD is not the identity branch.\"\n )\n return;\n if (\n reason ===\n \"Generated context is not ignored; add the recommended ignore rules before untracking.\"\n )\n paths.forEach((path) => ignoredPaths.add(path));\n else\n console.warn(\n `Generated context untrack skipped: ${reason}${paths.length ? ` (${paths.join(\", \")})` : \"\"}`,\n );\n }\n } catch {\n console.warn(\n \"Generated context untrack failed; continuing branch preparation.\",\n );\n }\n };\n\n const mode = parseAutomaticBranchSwitchSetting(\n environment.BF_DISABLE_AUTO_BRANCH_SWITCH,\n );\n const gitMode = parseGitModeSetting(environment.BF_GIT_MODE);\n\n if (gitMode === \"manual\") {\n console.log(\"Git management is in manual mode.\");\n await regenerate();\n await checkSkills();\n return 0;\n }\n\n if (mode === \"disabled\") {\n console.log(\"Automatic branch switching is disabled.\");\n await regenerate();\n await checkSkills();\n return 0;\n }\n\n // Explicit --hostname wins. Generated scripts use --default-hostname so\n // Next-compatible .env.local loading can supply BF_GITHUB_HOSTNAME first.\n const hostname = parseHostname(\n options.hostname ??\n environment.BF_GITHUB_HOSTNAME ??\n options.defaultHostname,\n );\n const lifecycle =\n dependencies.lifecycle ??\n new LocalPrototypeLifecycle({\n repositoryRoot: root,\n prototypeRoot: options.prototypeRoot ?? environment.BF_PROTOTYPE_ROOT,\n remote: options.remote ?? environment.BF_GIT_REMOTE,\n primaryBranch:\n options.primaryBranch ?? environment.BF_PROTOTYPE_BASE_BRANCH,\n automaticBranchSwitch: mode,\n gitMode,\n installDependencies: dependencies.installDependencies,\n });\n const prepareDependencies = lifecycle.prepareDependencies;\n if (prepareDependencies !== undefined) {\n console.log(\"Checking pending dependency preparation...\");\n const pending = await prepareDependencies.call(\n lifecycle,\n [],\n dependencies.installDependencies,\n );\n if (!pending.ok) {\n throw new BranchPrepareError(\"Unable to prepare project dependencies.\");\n }\n if (pending.value.status === \"failed\") {\n throw new BranchPrepareError(\n \"Dependency preparation failed; the development server was not started.\",\n );\n }\n if (pending.value.status === \"prepared\") {\n console.log(\"Pending project dependencies prepared.\");\n }\n }\n\n const githubCli =\n dependencies.githubCli ??\n dependencies.createGitHubCli?.({ hostname }) ??\n new GitHubCliClient({ hostname });\n let identity;\n try {\n identity = await githubCli.getUser();\n } catch (error) {\n if (\n error instanceof GitHubCliError &&\n (error.reason === \"missing\" || error.reason === \"unauthenticated\")\n ) {\n console.log(\n \"Branch preparation deferred; GitHub CLI authentication is not available.\",\n );\n await regenerate();\n await checkSkills();\n return 0;\n }\n throw new BranchPrepareError(\"Unable to resolve GitHub CLI identity.\");\n }\n\n console.log(\"Synchronizing project platform...\");\n const result = await lifecycle.prepareBranch(identity);\n if (!result.ok) {\n throw new BranchPrepareError(\n `Branch preparation failed with ${result.error.code}.`,\n );\n }\n\n if (result.value.status === \"deferred\") {\n console.log(\n result.value.reason === \"dirty-worktree\"\n ? \"Branch preparation deferred: uncommitted changes outside the prototype folder; platform updates were not applied.\"\n : `Branch preparation deferred; repository attention: ${result.value.reason}.`,\n );\n // A dirty/offline check that made no changes is safe to leave for the\n // existing environment. Never launch after a partially applied update.\n if (\n result.value.effects.changed ||\n result.value.effects.pushed ||\n result.value.effects.reconciledPaths.length > 0 ||\n (result.value.effects.platformPaths?.length ?? 0) > 0 ||\n (result.value.effects.dependencyPaths?.length ?? 0) > 0 ||\n result.value.effects.preparationRequired === true ||\n result.value.effects.restartRequired\n ) {\n throw new BranchPrepareError(\n \"Branch preparation was only partially completed; the development server was not started.\",\n );\n }\n await regenerate();\n await checkSkills();\n return 0;\n }\n if (result.value.status === \"unsafe\") {\n console.log(\n `Branch preparation requires repository attention (${result.value.reason}).`,\n );\n if (result.value.diagnostic)\n printDiagnostic(\"Branch preparation diagnostic\", result.value.diagnostic);\n if (result.value.rollbackDiagnostic)\n printDiagnostic(\n \"Branch preparation rollback diagnostic\",\n result.value.rollbackDiagnostic,\n );\n const effects = result.value.effects;\n const actualContentTransition =\n effects.reconciledPaths.length > 0 ||\n (effects.platformPaths?.length ?? 0) > 0 ||\n (effects.dependencyPaths?.length ?? 0) > 0 ||\n effects.preparationRequired === true ||\n effects.restartRequired;\n // History-only checkpoints and other no-effect safety refusals do not\n // justify taking down startup. A partial checkout/platform/dependency\n // transition still does: the existing environment must not run against\n // an unsafe working tree.\n if (!actualContentTransition) {\n await regenerate();\n await checkSkills();\n return 0;\n }\n throw new BranchPrepareError(\n \"Branch preparation was only partially completed; the development server was not started.\",\n );\n }\n if (result.value.status === \"disabled\") {\n console.log(\n \"Branch preparation skipped; synchronization is disabled by configuration.\",\n );\n await regenerate();\n await checkSkills();\n return 0;\n }\n\n await untrack(identity);\n await regenerate();\n\n const dependencyPaths = result.value.effects.dependencyPaths ?? [];\n const managedPathChanged =\n dependencyPaths.length > 0 ||\n result.value.effects.preparationRequired === true;\n if (managedPathChanged) {\n console.log(\"Installing updated project dependencies...\");\n if (prepareDependencies !== undefined) {\n const preparation = await prepareDependencies.call(\n lifecycle,\n dependencyPaths,\n dependencies.installDependencies,\n );\n if (!preparation.ok || preparation.value.status === \"failed\") {\n throw new BranchPrepareError(\n \"Dependency preparation failed; the development server was not started.\",\n );\n }\n } else {\n throw new BranchPrepareError(\n \"This lifecycle does not support dependency preparation; the development server was not started.\",\n );\n }\n }\n\n await checkSkills();\n console.log(\"Branch preparation complete.\");\n return 0;\n}\n"]}
|
package/dist/branch-prepare.js
CHANGED
|
@@ -3,12 +3,61 @@ import nextEnv from "@next/env";
|
|
|
3
3
|
import { parseAutomaticBranchSwitchSetting, parseGitModeSetting, parseHostname, } from "@ebay-dt/bonfire-core";
|
|
4
4
|
import { GitHubCliClient, GitHubCliError, LocalPrototypeLifecycle, } from "@ebay-dt/bonfire-node";
|
|
5
5
|
import { isAbsolute, relative, resolve, sep } from "node:path";
|
|
6
|
+
import { styleText } from "node:util";
|
|
6
7
|
export class BranchPrepareError extends Error {
|
|
7
8
|
constructor(message) {
|
|
8
9
|
super(message);
|
|
9
10
|
this.name = "BranchPrepareError";
|
|
10
11
|
}
|
|
11
12
|
}
|
|
13
|
+
const diagnosticStages = {
|
|
14
|
+
"checkout-identity-branch": "checking out the identity branch",
|
|
15
|
+
"configure-identity-upstream": "configuring the identity upstream",
|
|
16
|
+
"prepare-reconciliation": "preparing reconciliation",
|
|
17
|
+
"compose-baseline-tree": "composing the baseline tree",
|
|
18
|
+
"create-baseline-commit": "creating the baseline commit",
|
|
19
|
+
"apply-platform-patch": "applying the platform patch",
|
|
20
|
+
"update-identity-ref": "updating the identity reference",
|
|
21
|
+
"verify-reconciliation": "verifying reconciliation",
|
|
22
|
+
"rollback-platform-patch": "rolling back the platform patch",
|
|
23
|
+
};
|
|
24
|
+
const diagnosticReasons = {
|
|
25
|
+
"index-locked": "the Git index is locked",
|
|
26
|
+
"patch-does-not-apply": "the patch does not apply",
|
|
27
|
+
"identity-missing": "Git identity is missing",
|
|
28
|
+
"ref-changed": "the reference changed",
|
|
29
|
+
"permission-denied": "permission was denied",
|
|
30
|
+
"missing-path-or-object": "a path or object is missing",
|
|
31
|
+
"worktree-obstruction": "the working tree obstructs the operation",
|
|
32
|
+
"worktree-changed": "the working tree changed",
|
|
33
|
+
unknown: "the cause is unknown",
|
|
34
|
+
};
|
|
35
|
+
function printDiagnostic(label, diagnostic) {
|
|
36
|
+
const ownData = (key) => {
|
|
37
|
+
try {
|
|
38
|
+
const descriptor = Object.getOwnPropertyDescriptor(diagnostic, key);
|
|
39
|
+
return descriptor && "value" in descriptor ? descriptor.value : undefined;
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const stageValue = ownData("stage");
|
|
46
|
+
const reasonValue = ownData("reason");
|
|
47
|
+
const exitValue = ownData("exitCode");
|
|
48
|
+
const stage = typeof stageValue === "string" &&
|
|
49
|
+
Object.hasOwn(diagnosticStages, stageValue)
|
|
50
|
+
? diagnosticStages[stageValue]
|
|
51
|
+
: "an unknown stage";
|
|
52
|
+
const reason = typeof reasonValue === "string" &&
|
|
53
|
+
Object.hasOwn(diagnosticReasons, reasonValue)
|
|
54
|
+
? diagnosticReasons[reasonValue]
|
|
55
|
+
: diagnosticReasons.unknown;
|
|
56
|
+
const exitCode = typeof exitValue === "number" && Number.isSafeInteger(exitValue)
|
|
57
|
+
? ` (exit code ${exitValue})`
|
|
58
|
+
: "";
|
|
59
|
+
console.log(`${label}: ${stage}: ${reason}${exitCode}.`);
|
|
60
|
+
}
|
|
12
61
|
function loadEnvironment(root) {
|
|
13
62
|
return nextEnv.loadEnvConfig(root, true, undefined, false).combinedEnv;
|
|
14
63
|
}
|
|
@@ -27,7 +76,15 @@ export async function runBranchPrepare(options, dependencies) {
|
|
|
27
76
|
try {
|
|
28
77
|
const missing = await (dependencies.checkMissingInstalledSkills ?? missingInstalledSkills)({ repositoryRoot: root });
|
|
29
78
|
if (missing.length)
|
|
30
|
-
console.warn(
|
|
79
|
+
console.warn(`
|
|
80
|
+
${styleText(["bold", "yellow"], "⚠ AGENT SKILLS SETUP NEEDED", { stream: process.stderr })}
|
|
81
|
+
|
|
82
|
+
Stop the dev server, then run:
|
|
83
|
+
|
|
84
|
+
pnpm context:install
|
|
85
|
+
|
|
86
|
+
Restart with pnpm dev.
|
|
87
|
+
`);
|
|
31
88
|
}
|
|
32
89
|
catch {
|
|
33
90
|
console.warn("Unable to check installed skills; continuing branch preparation.");
|
|
@@ -66,7 +123,7 @@ export async function runBranchPrepare(options, dependencies) {
|
|
|
66
123
|
for (const [reason, paths] of Object.entries(result.value.skipped)) {
|
|
67
124
|
if (reason === "not ignored")
|
|
68
125
|
paths.forEach((path) => ignoredPaths.add(path));
|
|
69
|
-
else if (paths.length)
|
|
126
|
+
else if (reason !== "tracked" && paths.length)
|
|
70
127
|
console.warn(`Generated context regeneration skipped (${reason}): ${paths.join(", ")}.`);
|
|
71
128
|
}
|
|
72
129
|
}
|
|
@@ -187,6 +244,10 @@ export async function runBranchPrepare(options, dependencies) {
|
|
|
187
244
|
}
|
|
188
245
|
if (result.value.status === "unsafe") {
|
|
189
246
|
console.log(`Branch preparation requires repository attention (${result.value.reason}).`);
|
|
247
|
+
if (result.value.diagnostic)
|
|
248
|
+
printDiagnostic("Branch preparation diagnostic", result.value.diagnostic);
|
|
249
|
+
if (result.value.rollbackDiagnostic)
|
|
250
|
+
printDiagnostic("Branch preparation rollback diagnostic", result.value.rollbackDiagnostic);
|
|
190
251
|
const effects = result.value.effects;
|
|
191
252
|
const actualContentTransition = effects.reconciledPaths.length > 0 ||
|
|
192
253
|
(effects.platformPaths?.length ?? 0) > 0 ||
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"branch-prepare.js","sourceRoot":"","sources":["../src/branch-prepare.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,OAAO,MAAM,WAAW,CAAC;AAChC,OAAO,EACL,iCAAiC,EACjC,mBAAmB,EACnB,aAAa,GACd,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,eAAe,EACf,cAAc,EACd,uBAAuB,GAIxB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAqB/D,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAC3C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACnC,CAAC;CACF;AAED,SAAS,eAAe,CAAC,IAAY;IACnC,OAAO,OAAO,CAAC,aAAa,CAAC,IA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CAAC;IAED,MAAM,OAAO,CAAC,QAAQ,CAAC,CAAC;IACxB,MAAM,UAAU,EAAE,CAAC;IAEnB,MAAM,eAAe,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,eAAe,IAAI,EAAE,CAAC;IACnE,MAAM,kBAAkB,GACtB,eAAe,CAAC,MAAM,GAAG,CAAC;QAC1B,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,mBAAmB,KAAK,IAAI,CAAC;IACpD,IAAI,kBAAkB,EAAE,CAAC;QACvB,OAAO,CAAC,GAAG,CAAC,4CAA4C,CAAC,CAAC;QAC1D,IAAI,mBAAmB,KAAK,SAAS,EAAE,CAAC;YACtC,MAAM,WAAW,GAAG,MAAM,mBAAmB,CAAC,IAAI,CAChD,SAAS,EACT,eAAe,EACf,YAAY,CAAC,mBAAmB,CACjC,CAAC;YACF,IAAI,CAAC,WAAW,CAAC,EAAE,IAAI,WAAW,CAAC,KAAK,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;gBAC7D,MAAM,IAAI,kBAAkB,CAC1B,wEAAwE,CACzE,CAAC;YACJ,CAAC;QACH,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,kBAAkB,CAC1B,iGAAiG,CAClG,CAAC;QACJ,CAAC;IACH,CAAC;IAED,MAAM,WAAW,EAAE,CAAC;IACpB,OAAO,CAAC,GAAG,CAAC,8BAA8B,CAAC,CAAC;IAC5C,OAAO,CAAC,CAAC;AACX,CAAC","sourcesContent":["import { missingInstalledSkills } from \"@ebay-dt/bonfire-context\";\nimport nextEnv from \"@next/env\";\nimport {\n parseAutomaticBranchSwitchSetting,\n parseGitModeSetting,\n parseHostname,\n} from \"@ebay-dt/bonfire-core\";\nimport {\n GitHubCliClient,\n GitHubCliError,\n LocalPrototypeLifecycle,\n type DependencyInstaller,\n type GitHubCliClientLike,\n type PrototypeLifecycle,\n} from \"@ebay-dt/bonfire-node\";\nimport { isAbsolute, relative, resolve, sep } from \"node:path\";\nimport type { BranchPrepareCommandOptions } from \"./command.js\";\n\nexport type CliEnvironmentLoader = (\n root: string,\n) => Readonly<Record<string, string | undefined>>;\n\nexport type BranchPrepareDependencies = {\n checkMissingInstalledSkills?: typeof missingInstalledSkills;\n environment?: Readonly<Record<string, string | undefined>>;\n loadEnvironment?: CliEnvironmentLoader;\n githubCli?: GitHubCliClientLike;\n createGitHubCli?: (options: { hostname: string }) => GitHubCliClientLike;\n lifecycle?: Pick<PrototypeLifecycle, \"prepareBranch\" | \"prepareDependencies\">;\n installDependencies?: DependencyInstaller;\n regenerateGeneratedContext?: NonNullable<\n PrototypeLifecycle[\"regenerateGeneratedContext\"]\n >;\n untrackGeneratedContext?: PrototypeLifecycle[\"untrackGeneratedContext\"];\n};\n\nexport class BranchPrepareError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"BranchPrepareError\";\n }\n}\n\nfunction loadEnvironment(root: string) {\n return nextEnv.loadEnvConfig(root, true, undefined, false).combinedEnv;\n}\n\nexport async function runBranchPrepare(\n options: BranchPrepareCommandOptions,\n dependencies: BranchPrepareDependencies,\n): Promise<number> {\n const root = resolve(options.root);\n const environment =\n dependencies.environment ??\n dependencies.loadEnvironment?.(root) ??\n loadEnvironment(root);\n // This guard must precede marker reads, identity resolution, and all Git\n // collaborators. A direct production invocation must remain read-only even\n // when a previous development install left recovery state behind.\n if (environment.NODE_ENV === \"production\") {\n return 0;\n }\n\n const checkSkills = async () => {\n try {\n const missing = await (\n dependencies.checkMissingInstalledSkills ?? missingInstalledSkills\n )({ repositoryRoot: root });\n if (missing.length)\n console.warn(\n \"Canonical skills are not installed for this app; run pnpm context:install.\",\n );\n } catch {\n console.warn(\n \"Unable to check installed skills; continuing branch preparation.\",\n );\n }\n };\n\n const generatedLifecycle = () =>\n new LocalPrototypeLifecycle({\n repositoryRoot: root,\n prototypeRoot: options.prototypeRoot ?? environment.BF_PROTOTYPE_ROOT,\n remote: options.remote ?? environment.BF_GIT_REMOTE,\n primaryBranch:\n options.primaryBranch ?? environment.BF_PROTOTYPE_BASE_BRANCH,\n automaticBranchSwitch: parseAutomaticBranchSwitchSetting(\n environment.BF_DISABLE_AUTO_BRANCH_SWITCH,\n ),\n gitMode: parseGitModeSetting(environment.BF_GIT_MODE),\n });\n const ignoredPaths = new Set<string>();\n const configuredRoot =\n options.prototypeRoot ??\n environment.BF_PROTOTYPE_ROOT ??\n \"src/app/(prototypes)\";\n const relativeRoot = relative(root, resolve(root, configuredRoot));\n const safeRoot =\n relativeRoot &&\n relativeRoot !== \"..\" &&\n !relativeRoot.startsWith(`..${sep}`) &&\n !isAbsolute(relativeRoot) &&\n !configuredRoot.split(/[\\\\/]/u).includes(\"..\")\n ? relativeRoot\n .split(sep)\n .join(\"/\")\n .replace(/[\\\\*?[\\] ]/gu, \"\\\\$&\")\n : undefined;\n const regenerate = async () => {\n try {\n const result = await (\n dependencies.regenerateGeneratedContext ??\n (() => generatedLifecycle().regenerateGeneratedContext())\n )();\n if (!result.ok)\n console.warn(\n `Generated context regeneration skipped: ${result.error.code}.`,\n );\n else {\n for (const [reason, paths] of Object.entries(result.value.skipped)) {\n if (reason === \"not ignored\")\n paths.forEach((path) => ignoredPaths.add(path));\n else if (paths.length)\n console.warn(\n `Generated context regeneration skipped (${reason}): ${paths.join(\", \")}.`,\n );\n }\n }\n } catch {\n console.warn(\n \"Generated context regeneration failed; continuing branch preparation.\",\n );\n }\n if (ignoredPaths.size)\n console.warn(\n `Generated context skipped: ${[...ignoredPaths].join(\", \")}. ${\n safeRoot\n ? `Add these .gitignore patterns:\\n${[\"AGENTS.md\", \"CLAUDE.md\", \".claude/settings.json\"].map((file) => `/${safeRoot}/*/*/${file}`).join(\"\\n\")}`\n : \"Check the configured prototype root before adding .gitignore patterns.\"\n }`,\n );\n };\n const untrack = async (\n identity: Parameters<PrototypeLifecycle[\"untrackGeneratedContext\"]>[0],\n ) => {\n try {\n const result = await (\n dependencies.untrackGeneratedContext ??\n ((user) => generatedLifecycle().untrackGeneratedContext(user))\n )(identity);\n if (!result.ok)\n console.warn(\n `Generated context untrack skipped: ${result.error.code}.`,\n );\n else if (result.value.status === \"skipped\") {\n const { reason, paths } = result.value;\n if (\n reason === \"wrong-branch\" ||\n reason === \"HEAD is not the identity branch.\"\n )\n return;\n if (\n reason ===\n \"Generated context is not ignored; add the recommended ignore rules before untracking.\"\n )\n paths.forEach((path) => ignoredPaths.add(path));\n else\n console.warn(\n `Generated context untrack skipped: ${reason}${paths.length ? ` (${paths.join(\", \")})` : \"\"}`,\n );\n }\n } catch {\n console.warn(\n \"Generated context untrack failed; continuing branch preparation.\",\n );\n }\n };\n\n const mode = parseAutomaticBranchSwitchSetting(\n environment.BF_DISABLE_AUTO_BRANCH_SWITCH,\n );\n const gitMode = parseGitModeSetting(environment.BF_GIT_MODE);\n\n if (gitMode === \"manual\") {\n console.log(\"Git management is in manual mode.\");\n await regenerate();\n await checkSkills();\n return 0;\n }\n\n if (mode === \"disabled\") {\n console.log(\"Automatic branch switching is disabled.\");\n await regenerate();\n await checkSkills();\n return 0;\n }\n\n // Explicit --hostname wins. Generated scripts use --default-hostname so\n // Next-compatible .env.local loading can supply BF_GITHUB_HOSTNAME first.\n const hostname = parseHostname(\n options.hostname ??\n environment.BF_GITHUB_HOSTNAME ??\n options.defaultHostname,\n );\n const lifecycle =\n dependencies.lifecycle ??\n new LocalPrototypeLifecycle({\n repositoryRoot: root,\n prototypeRoot: options.prototypeRoot ?? environment.BF_PROTOTYPE_ROOT,\n remote: options.remote ?? environment.BF_GIT_REMOTE,\n primaryBranch:\n options.primaryBranch ?? environment.BF_PROTOTYPE_BASE_BRANCH,\n automaticBranchSwitch: mode,\n gitMode,\n installDependencies: dependencies.installDependencies,\n });\n const prepareDependencies = lifecycle.prepareDependencies;\n if (prepareDependencies !== undefined) {\n console.log(\"Checking pending dependency preparation...\");\n const pending = await prepareDependencies.call(\n lifecycle,\n [],\n dependencies.installDependencies,\n );\n if (!pending.ok) {\n throw new BranchPrepareError(\"Unable to prepare project dependencies.\");\n }\n if (pending.value.status === \"failed\") {\n throw new BranchPrepareError(\n \"Dependency preparation failed; the development server was not started.\",\n );\n }\n if (pending.value.status === \"prepared\") {\n console.log(\"Pending project dependencies prepared.\");\n }\n }\n\n const githubCli =\n dependencies.githubCli ??\n dependencies.createGitHubCli?.({ hostname }) ??\n new GitHubCliClient({ hostname });\n let identity;\n try {\n identity = await githubCli.getUser();\n } catch (error) {\n if (\n error instanceof GitHubCliError &&\n (error.reason === \"missing\" || error.reason === \"unauthenticated\")\n ) {\n console.log(\n \"Branch preparation deferred; GitHub CLI authentication is not available.\",\n );\n await regenerate();\n await checkSkills();\n return 0;\n }\n throw new BranchPrepareError(\"Unable to resolve GitHub CLI identity.\");\n }\n\n console.log(\"Synchronizing project platform...\");\n const result = await lifecycle.prepareBranch(identity);\n if (!result.ok) {\n throw new BranchPrepareError(\n `Branch preparation failed with ${result.error.code}.`,\n );\n }\n\n if (result.value.status === \"deferred\") {\n console.log(\n result.value.reason === \"dirty-worktree\"\n ? \"Branch preparation deferred: uncommitted changes outside the prototype folder; platform updates were not applied.\"\n : `Branch preparation deferred; repository attention: ${result.value.reason}.`,\n );\n // A dirty/offline check that made no changes is safe to leave for the\n // existing environment. Never launch after a partially applied update.\n if (\n result.value.effects.changed ||\n result.value.effects.pushed ||\n result.value.effects.reconciledPaths.length > 0 ||\n (result.value.effects.platformPaths?.length ?? 0) > 0 ||\n (result.value.effects.dependencyPaths?.length ?? 0) > 0 ||\n result.value.effects.preparationRequired === true ||\n result.value.effects.restartRequired\n ) {\n throw new BranchPrepareError(\n \"Branch preparation was only partially completed; the development server was not started.\",\n );\n }\n await regenerate();\n await checkSkills();\n return 0;\n }\n if (result.value.status === \"unsafe\") {\n console.log(\n `Branch preparation requires repository attention (${result.value.reason}).`,\n );\n const effects = result.value.effects;\n const actualContentTransition =\n effects.reconciledPaths.length > 0 ||\n (effects.platformPaths?.length ?? 0) > 0 ||\n (effects.dependencyPaths?.length ?? 0) > 0 ||\n effects.preparationRequired === true ||\n effects.restartRequired;\n // History-only checkpoints and other no-effect safety refusals do not\n // justify taking down startup. A partial checkout/platform/dependency\n // transition still does: the existing environment must not run against\n // an unsafe working tree.\n if (!actualContentTransition) {\n await regenerate();\n await checkSkills();\n return 0;\n }\n throw new BranchPrepareError(\n \"Branch preparation was only partially completed; the development server was not started.\",\n );\n }\n if (result.value.status === \"disabled\") {\n console.log(\n \"Branch preparation skipped; synchronization is disabled by configuration.\",\n );\n await regenerate();\n await checkSkills();\n return 0;\n }\n\n await untrack(identity);\n await regenerate();\n\n const dependencyPaths = result.value.effects.dependencyPaths ?? [];\n const managedPathChanged =\n dependencyPaths.length > 0 ||\n result.value.effects.preparationRequired === true;\n if (managedPathChanged) {\n console.log(\"Installing updated project dependencies...\");\n if (prepareDependencies !== undefined) {\n const preparation = await prepareDependencies.call(\n lifecycle,\n dependencyPaths,\n dependencies.installDependencies,\n );\n if (!preparation.ok || preparation.value.status === \"failed\") {\n throw new BranchPrepareError(\n \"Dependency preparation failed; the development server was not started.\",\n );\n }\n } else {\n throw new BranchPrepareError(\n \"This lifecycle does not support dependency preparation; the development server was not started.\",\n );\n }\n }\n\n await checkSkills();\n console.log(\"Branch preparation complete.\");\n return 0;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"branch-prepare.js","sourceRoot":"","sources":["../src/branch-prepare.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,OAAO,MAAM,WAAW,CAAC;AAChC,OAAO,EACL,iCAAiC,EACjC,mBAAmB,EACnB,aAAa,GAEd,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,eAAe,EACf,cAAc,EACd,uBAAuB,GAIxB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAqBtC,MAAM,O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IAEnB,MAAM,eAAe,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,eAAe,IAAI,EAAE,CAAC;IACnE,MAAM,kBAAkB,GACtB,eAAe,CAAC,MAAM,GAAG,CAAC;QAC1B,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,mBAAmB,KAAK,IAAI,CAAC;IACpD,IAAI,kBAAkB,EAAE,CAAC;QACvB,OAAO,CAAC,GAAG,CAAC,4CAA4C,CAAC,CAAC;QAC1D,IAAI,mBAAmB,KAAK,SAAS,EAAE,CAAC;YACtC,MAAM,WAAW,GAAG,MAAM,mBAAmB,CAAC,IAAI,CAChD,SAAS,EACT,eAAe,EACf,YAAY,CAAC,mBAAmB,CACjC,CAAC;YACF,IAAI,CAAC,WAAW,CAAC,EAAE,IAAI,WAAW,CAAC,KAAK,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;gBAC7D,MAAM,IAAI,kBAAkB,CAC1B,wEAAwE,CACzE,CAAC;YACJ,CAAC;QACH,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,kBAAkB,CAC1B,iGAAiG,CAClG,CAAC;QACJ,CAAC;IACH,CAAC;IAED,MAAM,WAAW,EAAE,CAAC;IACpB,OAAO,CAAC,GAAG,CAAC,8BAA8B,CAAC,CAAC;IAC5C,OAAO,CAAC,CAAC;AACX,CAAC","sourcesContent":["import { missingInstalledSkills } from \"@ebay-dt/bonfire-context\";\nimport nextEnv from \"@next/env\";\nimport {\n parseAutomaticBranchSwitchSetting,\n parseGitModeSetting,\n parseHostname,\n type BranchPreparationDiagnostic,\n} from \"@ebay-dt/bonfire-core\";\nimport {\n GitHubCliClient,\n GitHubCliError,\n LocalPrototypeLifecycle,\n type DependencyInstaller,\n type GitHubCliClientLike,\n type PrototypeLifecycle,\n} from \"@ebay-dt/bonfire-node\";\nimport { isAbsolute, relative, resolve, sep } from \"node:path\";\nimport { styleText } from \"node:util\";\nimport type { BranchPrepareCommandOptions } from \"./command.js\";\n\nexport type CliEnvironmentLoader = (\n root: string,\n) => Readonly<Record<string, string | undefined>>;\n\nexport type BranchPrepareDependencies = {\n checkMissingInstalledSkills?: typeof missingInstalledSkills;\n environment?: Readonly<Record<string, string | undefined>>;\n loadEnvironment?: CliEnvironmentLoader;\n githubCli?: GitHubCliClientLike;\n createGitHubCli?: (options: { hostname: string }) => GitHubCliClientLike;\n lifecycle?: Pick<PrototypeLifecycle, \"prepareBranch\" | \"prepareDependencies\">;\n installDependencies?: DependencyInstaller;\n regenerateGeneratedContext?: NonNullable<\n PrototypeLifecycle[\"regenerateGeneratedContext\"]\n >;\n untrackGeneratedContext?: PrototypeLifecycle[\"untrackGeneratedContext\"];\n};\n\nexport class BranchPrepareError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"BranchPrepareError\";\n }\n}\n\nconst diagnosticStages: Record<BranchPreparationDiagnostic[\"stage\"], string> = {\n \"checkout-identity-branch\": \"checking out the identity branch\",\n \"configure-identity-upstream\": \"configuring the identity upstream\",\n \"prepare-reconciliation\": \"preparing reconciliation\",\n \"compose-baseline-tree\": \"composing the baseline tree\",\n \"create-baseline-commit\": \"creating the baseline commit\",\n \"apply-platform-patch\": \"applying the platform patch\",\n \"update-identity-ref\": \"updating the identity reference\",\n \"verify-reconciliation\": \"verifying reconciliation\",\n \"rollback-platform-patch\": \"rolling back the platform patch\",\n};\n\nconst diagnosticReasons: Record<BranchPreparationDiagnostic[\"reason\"], string> =\n {\n \"index-locked\": \"the Git index is locked\",\n \"patch-does-not-apply\": \"the patch does not apply\",\n \"identity-missing\": \"Git identity is missing\",\n \"ref-changed\": \"the reference changed\",\n \"permission-denied\": \"permission was denied\",\n \"missing-path-or-object\": \"a path or object is missing\",\n \"worktree-obstruction\": \"the working tree obstructs the operation\",\n \"worktree-changed\": \"the working tree changed\",\n unknown: \"the cause is unknown\",\n };\n\nfunction printDiagnostic(\n label: string,\n diagnostic: BranchPreparationDiagnostic,\n) {\n const ownData = (key: string): unknown => {\n try {\n const descriptor = Object.getOwnPropertyDescriptor(diagnostic, key);\n return descriptor && \"value\" in descriptor ? descriptor.value : undefined;\n } catch {\n return undefined;\n }\n };\n const stageValue = ownData(\"stage\");\n const reasonValue = ownData(\"reason\");\n const exitValue = ownData(\"exitCode\");\n const stage =\n typeof stageValue === \"string\" &&\n Object.hasOwn(diagnosticStages, stageValue)\n ? diagnosticStages[stageValue as BranchPreparationDiagnostic[\"stage\"]]\n : \"an unknown stage\";\n const reason =\n typeof reasonValue === \"string\" &&\n Object.hasOwn(diagnosticReasons, reasonValue)\n ? diagnosticReasons[reasonValue as BranchPreparationDiagnostic[\"reason\"]]\n : diagnosticReasons.unknown;\n const exitCode =\n typeof exitValue === \"number\" && Number.isSafeInteger(exitValue)\n ? ` (exit code ${exitValue})`\n : \"\";\n console.log(`${label}: ${stage}: ${reason}${exitCode}.`);\n}\n\nfunction loadEnvironment(root: string) {\n return nextEnv.loadEnvConfig(root, true, undefined, false).combinedEnv;\n}\n\nexport async function runBranchPrepare(\n options: BranchPrepareCommandOptions,\n dependencies: BranchPrepareDependencies,\n): Promise<number> {\n const root = resolve(options.root);\n const environment =\n dependencies.environment ??\n dependencies.loadEnvironment?.(root) ??\n loadEnvironment(root);\n // This guard must precede marker reads, identity resolution, and all Git\n // collaborators. A direct production invocation must remain read-only even\n // when a previous development install left recovery state behind.\n if (environment.NODE_ENV === \"production\") {\n return 0;\n }\n\n const checkSkills = async () => {\n try {\n const missing = await (\n dependencies.checkMissingInstalledSkills ?? missingInstalledSkills\n )({ repositoryRoot: root });\n if (missing.length)\n console.warn(\n `\n${styleText([\"bold\", \"yellow\"], \"⚠ AGENT SKILLS SETUP NEEDED\", { stream: process.stderr })}\n\nStop the dev server, then run:\n\n pnpm context:install\n\nRestart with pnpm dev.\n`,\n );\n } catch {\n console.warn(\n \"Unable to check installed skills; continuing branch preparation.\",\n );\n }\n };\n\n const generatedLifecycle = () =>\n new LocalPrototypeLifecycle({\n repositoryRoot: root,\n prototypeRoot: options.prototypeRoot ?? environment.BF_PROTOTYPE_ROOT,\n remote: options.remote ?? environment.BF_GIT_REMOTE,\n primaryBranch:\n options.primaryBranch ?? environment.BF_PROTOTYPE_BASE_BRANCH,\n automaticBranchSwitch: parseAutomaticBranchSwitchSetting(\n environment.BF_DISABLE_AUTO_BRANCH_SWITCH,\n ),\n gitMode: parseGitModeSetting(environment.BF_GIT_MODE),\n });\n const ignoredPaths = new Set<string>();\n const configuredRoot =\n options.prototypeRoot ??\n environment.BF_PROTOTYPE_ROOT ??\n \"src/app/(prototypes)\";\n const relativeRoot = relative(root, resolve(root, configuredRoot));\n const safeRoot =\n relativeRoot &&\n relativeRoot !== \"..\" &&\n !relativeRoot.startsWith(`..${sep}`) &&\n !isAbsolute(relativeRoot) &&\n !configuredRoot.split(/[\\\\/]/u).includes(\"..\")\n ? relativeRoot\n .split(sep)\n .join(\"/\")\n .replace(/[\\\\*?[\\] ]/gu, \"\\\\$&\")\n : undefined;\n const regenerate = async () => {\n try {\n const result = await (\n dependencies.regenerateGeneratedContext ??\n (() => generatedLifecycle().regenerateGeneratedContext())\n )();\n if (!result.ok)\n console.warn(\n `Generated context regeneration skipped: ${result.error.code}.`,\n );\n else {\n for (const [reason, paths] of Object.entries(result.value.skipped)) {\n if (reason === \"not ignored\")\n paths.forEach((path) => ignoredPaths.add(path));\n else if (reason !== \"tracked\" && paths.length)\n console.warn(\n `Generated context regeneration skipped (${reason}): ${paths.join(\", \")}.`,\n );\n }\n }\n } catch {\n console.warn(\n \"Generated context regeneration failed; continuing branch preparation.\",\n );\n }\n if (ignoredPaths.size)\n console.warn(\n `Generated context skipped: ${[...ignoredPaths].join(\", \")}. ${\n safeRoot\n ? `Add these .gitignore patterns:\\n${[\"AGENTS.md\", \"CLAUDE.md\", \".claude/settings.json\"].map((file) => `/${safeRoot}/*/*/${file}`).join(\"\\n\")}`\n : \"Check the configured prototype root before adding .gitignore patterns.\"\n }`,\n );\n };\n const untrack = async (\n identity: Parameters<PrototypeLifecycle[\"untrackGeneratedContext\"]>[0],\n ) => {\n try {\n const result = await (\n dependencies.untrackGeneratedContext ??\n ((user) => generatedLifecycle().untrackGeneratedContext(user))\n )(identity);\n if (!result.ok)\n console.warn(\n `Generated context untrack skipped: ${result.error.code}.`,\n );\n else if (result.value.status === \"skipped\") {\n const { reason, paths } = result.value;\n if (\n reason === \"wrong-branch\" ||\n reason === \"HEAD is not the identity branch.\"\n )\n return;\n if (\n reason ===\n \"Generated context is not ignored; add the recommended ignore rules before untracking.\"\n )\n paths.forEach((path) => ignoredPaths.add(path));\n else\n console.warn(\n `Generated context untrack skipped: ${reason}${paths.length ? ` (${paths.join(\", \")})` : \"\"}`,\n );\n }\n } catch {\n console.warn(\n \"Generated context untrack failed; continuing branch preparation.\",\n );\n }\n };\n\n const mode = parseAutomaticBranchSwitchSetting(\n environment.BF_DISABLE_AUTO_BRANCH_SWITCH,\n );\n const gitMode = parseGitModeSetting(environment.BF_GIT_MODE);\n\n if (gitMode === \"manual\") {\n console.log(\"Git management is in manual mode.\");\n await regenerate();\n await checkSkills();\n return 0;\n }\n\n if (mode === \"disabled\") {\n console.log(\"Automatic branch switching is disabled.\");\n await regenerate();\n await checkSkills();\n return 0;\n }\n\n // Explicit --hostname wins. Generated scripts use --default-hostname so\n // Next-compatible .env.local loading can supply BF_GITHUB_HOSTNAME first.\n const hostname = parseHostname(\n options.hostname ??\n environment.BF_GITHUB_HOSTNAME ??\n options.defaultHostname,\n );\n const lifecycle =\n dependencies.lifecycle ??\n new LocalPrototypeLifecycle({\n repositoryRoot: root,\n prototypeRoot: options.prototypeRoot ?? environment.BF_PROTOTYPE_ROOT,\n remote: options.remote ?? environment.BF_GIT_REMOTE,\n primaryBranch:\n options.primaryBranch ?? environment.BF_PROTOTYPE_BASE_BRANCH,\n automaticBranchSwitch: mode,\n gitMode,\n installDependencies: dependencies.installDependencies,\n });\n const prepareDependencies = lifecycle.prepareDependencies;\n if (prepareDependencies !== undefined) {\n console.log(\"Checking pending dependency preparation...\");\n const pending = await prepareDependencies.call(\n lifecycle,\n [],\n dependencies.installDependencies,\n );\n if (!pending.ok) {\n throw new BranchPrepareError(\"Unable to prepare project dependencies.\");\n }\n if (pending.value.status === \"failed\") {\n throw new BranchPrepareError(\n \"Dependency preparation failed; the development server was not started.\",\n );\n }\n if (pending.value.status === \"prepared\") {\n console.log(\"Pending project dependencies prepared.\");\n }\n }\n\n const githubCli =\n dependencies.githubCli ??\n dependencies.createGitHubCli?.({ hostname }) ??\n new GitHubCliClient({ hostname });\n let identity;\n try {\n identity = await githubCli.getUser();\n } catch (error) {\n if (\n error instanceof GitHubCliError &&\n (error.reason === \"missing\" || error.reason === \"unauthenticated\")\n ) {\n console.log(\n \"Branch preparation deferred; GitHub CLI authentication is not available.\",\n );\n await regenerate();\n await checkSkills();\n return 0;\n }\n throw new BranchPrepareError(\"Unable to resolve GitHub CLI identity.\");\n }\n\n console.log(\"Synchronizing project platform...\");\n const result = await lifecycle.prepareBranch(identity);\n if (!result.ok) {\n throw new BranchPrepareError(\n `Branch preparation failed with ${result.error.code}.`,\n );\n }\n\n if (result.value.status === \"deferred\") {\n console.log(\n result.value.reason === \"dirty-worktree\"\n ? \"Branch preparation deferred: uncommitted changes outside the prototype folder; platform updates were not applied.\"\n : `Branch preparation deferred; repository attention: ${result.value.reason}.`,\n );\n // A dirty/offline check that made no changes is safe to leave for the\n // existing environment. Never launch after a partially applied update.\n if (\n result.value.effects.changed ||\n result.value.effects.pushed ||\n result.value.effects.reconciledPaths.length > 0 ||\n (result.value.effects.platformPaths?.length ?? 0) > 0 ||\n (result.value.effects.dependencyPaths?.length ?? 0) > 0 ||\n result.value.effects.preparationRequired === true ||\n result.value.effects.restartRequired\n ) {\n throw new BranchPrepareError(\n \"Branch preparation was only partially completed; the development server was not started.\",\n );\n }\n await regenerate();\n await checkSkills();\n return 0;\n }\n if (result.value.status === \"unsafe\") {\n console.log(\n `Branch preparation requires repository attention (${result.value.reason}).`,\n );\n if (result.value.diagnostic)\n printDiagnostic(\"Branch preparation diagnostic\", result.value.diagnostic);\n if (result.value.rollbackDiagnostic)\n printDiagnostic(\n \"Branch preparation rollback diagnostic\",\n result.value.rollbackDiagnostic,\n );\n const effects = result.value.effects;\n const actualContentTransition =\n effects.reconciledPaths.length > 0 ||\n (effects.platformPaths?.length ?? 0) > 0 ||\n (effects.dependencyPaths?.length ?? 0) > 0 ||\n effects.preparationRequired === true ||\n effects.restartRequired;\n // History-only checkpoints and other no-effect safety refusals do not\n // justify taking down startup. A partial checkout/platform/dependency\n // transition still does: the existing environment must not run against\n // an unsafe working tree.\n if (!actualContentTransition) {\n await regenerate();\n await checkSkills();\n return 0;\n }\n throw new BranchPrepareError(\n \"Branch preparation was only partially completed; the development server was not started.\",\n );\n }\n if (result.value.status === \"disabled\") {\n console.log(\n \"Branch preparation skipped; synchronization is disabled by configuration.\",\n );\n await regenerate();\n await checkSkills();\n return 0;\n }\n\n await untrack(identity);\n await regenerate();\n\n const dependencyPaths = result.value.effects.dependencyPaths ?? [];\n const managedPathChanged =\n dependencyPaths.length > 0 ||\n result.value.effects.preparationRequired === true;\n if (managedPathChanged) {\n console.log(\"Installing updated project dependencies...\");\n if (prepareDependencies !== undefined) {\n const preparation = await prepareDependencies.call(\n lifecycle,\n dependencyPaths,\n dependencies.installDependencies,\n );\n if (!preparation.ok || preparation.value.status === \"failed\") {\n throw new BranchPrepareError(\n \"Dependency preparation failed; the development server was not started.\",\n );\n }\n } else {\n throw new BranchPrepareError(\n \"This lifecycle does not support dependency preparation; the development server was not started.\",\n );\n }\n }\n\n await checkSkills();\n console.log(\"Branch preparation complete.\");\n return 0;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"release-versions.d.ts","sourceRoot":"","sources":["../src/release-versions.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,eAAe,kBAAkB,CAAC;AAC/C,eAAO,MAAM,cAAc,UAAU,CAAC","sourcesContent":["// Generated by scripts/generate-release-versions.mjs during the package build.\nexport const BONFIRE_VERSION = \"0.3.0-alpha.
|
|
1
|
+
{"version":3,"file":"release-versions.d.ts","sourceRoot":"","sources":["../src/release-versions.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,eAAe,kBAAkB,CAAC;AAC/C,eAAO,MAAM,cAAc,UAAU,CAAC","sourcesContent":["// Generated by scripts/generate-release-versions.mjs during the package build.\nexport const BONFIRE_VERSION = \"0.3.0-alpha.2\";\nexport const PRESET_VERSION = \"0.1.0\";\n"]}
|
package/dist/release-versions.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"release-versions.js","sourceRoot":"","sources":["../src/release-versions.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,MAAM,CAAC,MAAM,eAAe,GAAG,eAAe,CAAC;AAC/C,MAAM,CAAC,MAAM,cAAc,GAAG,OAAO,CAAC","sourcesContent":["// Generated by scripts/generate-release-versions.mjs during the package build.\nexport const BONFIRE_VERSION = \"0.3.0-alpha.
|
|
1
|
+
{"version":3,"file":"release-versions.js","sourceRoot":"","sources":["../src/release-versions.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,MAAM,CAAC,MAAM,eAAe,GAAG,eAAe,CAAC;AAC/C,MAAM,CAAC,MAAM,cAAc,GAAG,OAAO,CAAC","sourcesContent":["// Generated by scripts/generate-release-versions.mjs during the package build.\nexport const BONFIRE_VERSION = \"0.3.0-alpha.2\";\nexport const PRESET_VERSION = \"0.1.0\";\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ebay-dt/bonfire-cli",
|
|
3
|
-
"version": "0.3.0-alpha.
|
|
3
|
+
"version": "0.3.0-alpha.2",
|
|
4
4
|
"description": "The Bonfire command-line tool.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -31,10 +31,10 @@
|
|
|
31
31
|
"access": "public"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@ebay-dt/bonfire-context": "0.3.0-alpha.
|
|
34
|
+
"@ebay-dt/bonfire-context": "0.3.0-alpha.2",
|
|
35
35
|
"@next/env": "16.3.4",
|
|
36
|
-
"@ebay-dt/bonfire-core": "0.3.0-alpha.
|
|
37
|
-
"@ebay-dt/bonfire-node": "0.3.0-alpha.
|
|
36
|
+
"@ebay-dt/bonfire-core": "0.3.0-alpha.2",
|
|
37
|
+
"@ebay-dt/bonfire-node": "0.3.0-alpha.2"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@repo/eslint-config": "0.0.0",
|