@ebay-dt/bonfire-cli 0.2.0-alpha.18 → 0.2.0-alpha.19

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.
@@ -1 +1 @@
1
- {"version":3,"file":"branch-prepare.d.ts","sourceRoot":"","sources":["../src/branch-prepare.ts"],"names":[],"mappings":"AAMA,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,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;CAC3C,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,CA4JjB","sourcesContent":["import 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 { resolve } 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 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};\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 console.log(\"Branch preparation is disabled in production.\");\n return 0;\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 return 0;\n }\n\n if (mode === \"disabled\") {\n console.log(\"Automatic branch switching is disabled.\");\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 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 `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 return 0;\n }\n if (result.value.status === \"unsafe\") {\n throw new BranchPrepareError(\n `Branch preparation requires repository attention (${result.value.reason}); 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 return 0;\n }\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 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":"AAMA,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,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;CAC3C,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,CA2KjB","sourcesContent":["import 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 { resolve } 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 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};\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 console.log(\"Branch preparation is disabled in production.\");\n return 0;\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 return 0;\n }\n\n if (mode === \"disabled\") {\n console.log(\"Automatic branch switching is disabled.\");\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 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 `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 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) return 0;\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 return 0;\n }\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 console.log(\"Branch preparation complete.\");\n return 0;\n}\n"]}
@@ -63,8 +63,8 @@ export async function runBranchPrepare(options, dependencies) {
63
63
  }
64
64
  }
65
65
  const githubCli = dependencies.githubCli ??
66
- (dependencies.createGitHubCli?.({ hostname }) ??
67
- new GitHubCliClient({ hostname }));
66
+ dependencies.createGitHubCli?.({ hostname }) ??
67
+ new GitHubCliClient({ hostname });
68
68
  let identity;
69
69
  try {
70
70
  identity = await githubCli.getUser();
@@ -98,7 +98,20 @@ export async function runBranchPrepare(options, dependencies) {
98
98
  return 0;
99
99
  }
100
100
  if (result.value.status === "unsafe") {
101
- throw new BranchPrepareError(`Branch preparation requires repository attention (${result.value.reason}); the development server was not started.`);
101
+ console.log(`Branch preparation requires repository attention (${result.value.reason}).`);
102
+ const effects = result.value.effects;
103
+ const actualContentTransition = effects.reconciledPaths.length > 0 ||
104
+ (effects.platformPaths?.length ?? 0) > 0 ||
105
+ (effects.dependencyPaths?.length ?? 0) > 0 ||
106
+ effects.preparationRequired === true ||
107
+ effects.restartRequired;
108
+ // History-only checkpoints and other no-effect safety refusals do not
109
+ // justify taking down startup. A partial checkout/platform/dependency
110
+ // transition still does: the existing environment must not run against
111
+ // an unsafe working tree.
112
+ if (!actualContentTransition)
113
+ return 0;
114
+ throw new BranchPrepareError("Branch preparation was only partially completed; the development server was not started.");
102
115
  }
103
116
  if (result.value.status === "disabled") {
104
117
  console.log("Branch preparation skipped; synchronization is disabled by configuration.");
@@ -1 +1 @@
1
- {"version":3,"file":"branch-prepare.js","sourceRoot":"","sources":["../src/branch-prepare.ts"],"names":[],"mappings":"AAAA,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,OAAO,EAAE,MAAM,WAAW,CAAC;AAgBpC,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,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC,WAAW,CAAC;AACzE,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,OAAoC,EACpC,YAAuC;IAEvC,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACnC,MAAM,WAAW,GACf,YAAY,CAAC,WAAW;QACxB,YAAY,CAAC,eAAe,EAAE,CAAC,IAAI,CAAC;QACpC,eAAe,CAAC,IAAI,CAAC,CAAC;IACxB,yEAAyE;IACzE,2EAA2E;IAC3E,kEAAkE;IAClE,IAAI,WAAW,CAAC,QAAQ,KAAK,YAAY,EAAE,CAAC;QAC1C,OAAO,CAAC,GAAG,CAAC,+CAA+C,CAAC,CAAC;QAC7D,OAAO,CAAC,CAAC;IACX,CAAC;IAED,MAAM,IAAI,GAAG,iCAAiC,CAC5C,WAAW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,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,OAAO,CAAC,GAAG,CAAC,8BAA8B,CAAC,CAAC;IAC5C,OAAO,CAAC,CAAC;AACX,CAAC","sourcesContent":["import 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 { resolve } 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 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};\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 console.log(\"Branch preparation is disabled in production.\");\n return 0;\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 return 0;\n }\n\n if (mode === \"disabled\") {\n console.log(\"Automatic branch switching is disabled.\");\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 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 `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 return 0;\n }\n if (result.value.status === \"unsafe\") {\n throw new BranchPrepareError(\n `Branch preparation requires repository attention (${result.value.reason}); 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 return 0;\n }\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 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,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,OAAO,EAAE,MAAM,WAAW,CAAC;AAgBpC,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,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC,WAAW,CAAC;AACzE,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,OAAoC,EACpC,YAAuC;IAEvC,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACnC,MAAM,WAAW,GACf,YAAY,CAAC,WAAW;QACxB,YAAY,CAAC,eAAe,EAAE,CAAC,IAAI,CAAC;QACpC,eAAe,CAAC,IAAI,CAAC,CAAC;IACxB,yEAAyE;IACzE,2EAA2E;IAC3E,kEAAkE;IAClE,IAAI,WAAW,CAAC,QAAQ,KAAK,YAAY,EAAE,CAAC;QAC1C,OAAO,CAAC,GAAG,CAAC,+CAA+C,CAAC,CAAC;QAC7D,OAAO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C;QAC1B,sEAAsE;QACtE,sEAAsE;QACtE,uEAAuE;QACvE,0BAA0B;QAC1B,IAAI,CAAC,uBAAuB;YAAE,OAAO,CAAC,CAAC;QACvC,MAAM,IAAI,kBAAkB,CAC1B,0FAA0F,CAC3F,CAAC;IACJ,CAAC;IACD,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;QACvC,OAAO,CAAC,GAAG,CACT,2EAA2E,CAC5E,CAAC;QACF,OAAO,CAAC,CAAC;IACX,CAAC;IAED,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,OAAO,CAAC,GAAG,CAAC,8BAA8B,CAAC,CAAC;IAC5C,OAAO,CAAC,CAAC;AACX,CAAC","sourcesContent":["import 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 { resolve } 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 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};\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 console.log(\"Branch preparation is disabled in production.\");\n return 0;\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 return 0;\n }\n\n if (mode === \"disabled\") {\n console.log(\"Automatic branch switching is disabled.\");\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 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 `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 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) return 0;\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 return 0;\n }\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 console.log(\"Branch preparation complete.\");\n return 0;\n}\n"]}
@@ -1,3 +1,3 @@
1
- export declare const BONFIRE_VERSION = "0.2.0-alpha.18";
1
+ export declare const BONFIRE_VERSION = "0.2.0-alpha.19";
2
2
  export declare const PRESET_VERSION = "0.1.0";
3
3
  //# sourceMappingURL=release-versions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"release-versions.d.ts","sourceRoot":"","sources":["../src/release-versions.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,eAAe,mBAAmB,CAAC;AAChD,eAAO,MAAM,cAAc,UAAU,CAAC","sourcesContent":["// Generated by scripts/generate-release-versions.mjs during the package build.\nexport const BONFIRE_VERSION = \"0.2.0-alpha.18\";\nexport const PRESET_VERSION = \"0.1.0\";\n"]}
1
+ {"version":3,"file":"release-versions.d.ts","sourceRoot":"","sources":["../src/release-versions.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,eAAe,mBAAmB,CAAC;AAChD,eAAO,MAAM,cAAc,UAAU,CAAC","sourcesContent":["// Generated by scripts/generate-release-versions.mjs during the package build.\nexport const BONFIRE_VERSION = \"0.2.0-alpha.19\";\nexport const PRESET_VERSION = \"0.1.0\";\n"]}
@@ -1,4 +1,4 @@
1
1
  // Generated by scripts/generate-release-versions.mjs during the package build.
2
- export const BONFIRE_VERSION = "0.2.0-alpha.18";
2
+ export const BONFIRE_VERSION = "0.2.0-alpha.19";
3
3
  export const PRESET_VERSION = "0.1.0";
4
4
  //# sourceMappingURL=release-versions.js.map
@@ -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,gBAAgB,CAAC;AAChD,MAAM,CAAC,MAAM,cAAc,GAAG,OAAO,CAAC","sourcesContent":["// Generated by scripts/generate-release-versions.mjs during the package build.\nexport const BONFIRE_VERSION = \"0.2.0-alpha.18\";\nexport const PRESET_VERSION = \"0.1.0\";\n"]}
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,gBAAgB,CAAC;AAChD,MAAM,CAAC,MAAM,cAAc,GAAG,OAAO,CAAC","sourcesContent":["// Generated by scripts/generate-release-versions.mjs during the package build.\nexport const BONFIRE_VERSION = \"0.2.0-alpha.19\";\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.2.0-alpha.18",
3
+ "version": "0.2.0-alpha.19",
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.2.0-alpha.18",
34
+ "@ebay-dt/bonfire-context": "0.2.0-alpha.19",
35
35
  "@next/env": "16.3.4",
36
- "@ebay-dt/bonfire-core": "0.2.0-alpha.18",
37
- "@ebay-dt/bonfire-node": "0.2.0-alpha.18"
36
+ "@ebay-dt/bonfire-core": "0.2.0-alpha.19",
37
+ "@ebay-dt/bonfire-node": "0.2.0-alpha.19"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@repo/eslint-config": "0.0.0",