@bakers-build/addon-forge 0.19.1-next.3 → 0.19.1-next.5

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,5 +1,6 @@
1
+ import type { AddonEnv } from '@bakers-build/core';
1
2
  import type { GitAuth } from './git.js';
2
- export type { GitAuth };
3
+ export type { AddonEnv, GitAuth };
3
4
  export interface ForgePr {
4
5
  /** GitHub PR number, GitLab MR iid. */
5
6
  readonly number: number;
@@ -102,10 +103,15 @@ export interface LogTail {
102
103
  readonly bytes: number;
103
104
  readonly truncated: boolean;
104
105
  }
105
- export type ForgeBackendFactory = (settings: unknown, context: {
106
+ export interface ForgeBackendContext {
106
107
  readonly home: string;
108
+ /** The `*_env` names of the forge options, resolved by core; a backend reads no other env. */
109
+ readonly env?: AddonEnv;
107
110
  readonly fetch?: typeof fetch;
108
- }) => Promise<ForgeBackend>;
111
+ }
112
+ export type ForgeBackendFactory = (settings: unknown, context: ForgeBackendContext) => Promise<ForgeBackend>;
113
+ /** The value core resolved for `option`'s variable `name`; the error names the sources searched, never a value. */
114
+ export declare function envCredential(context: ForgeBackendContext, option: string, name: string): string;
109
115
  /** Reject a factory result that is not a `ForgeBackend`. */
110
116
  export declare function assertForgeBackend(value: unknown, spec: string): asserts value is ForgeBackend;
111
117
  /**
@@ -3,6 +3,13 @@
3
3
  // `ForgeBackendFactory`; the forge tools know only this shape, never a
4
4
  // service's API. Ownership, titles and merge gates stay with the tools.
5
5
  import { execFile } from 'node:child_process';
6
+ /** The value core resolved for `option`'s variable `name`; the error names the sources searched, never a value. */
7
+ export function envCredential(context, option, name) {
8
+ const value = context.env?.values[name];
9
+ if (value)
10
+ return value;
11
+ throw new Error(`${option} names ${name}, which is set in none of: ${context.env?.searched.join(', ') || 'shell'}`);
12
+ }
6
13
  const METHODS = [
7
14
  'secrets',
8
15
  'gitAuth',
@@ -1,4 +1,4 @@
1
- import { type ForgeBackend } from './backend.js';
1
+ import { type AddonEnv, type ForgeBackend } from './backend.js';
2
2
  export declare const FORGE_SPEC = "@bakers-build/addon-forge";
3
3
  export declare const FORGE_NEEDS_BACKEND = "addons[@bakers-build/addon-forge].with.backend.use must name a forge backend ('@bakers-build/addon-forge-github' or '@bakers-build/addon-forge-gitlab') in ~/.bakers/machine.config.js or .bakers/project.config.js; see docs/addons/forge";
4
4
  export interface MergeRule {
@@ -10,4 +10,4 @@ export declare function mergeWith(project: unknown, machine: unknown): unknown;
10
10
  /** The rule for merging into `base`: `merge[base]`, else `merge['*']`, else squash and delete. */
11
11
  export declare function mergeRule(settings: unknown, base: string): MergeRule;
12
12
  /** Resolve, load and construct the configured backend. */
13
- export declare function loadForgeBackend(settings: unknown, home: string): Promise<ForgeBackend>;
13
+ export declare function loadForgeBackend(settings: unknown, home: string, env?: AddonEnv): Promise<ForgeBackend>;
@@ -38,7 +38,7 @@ function hostInstallBases() {
38
38
  return [entryUrl.href, new URL('../host/dist/src/host.js', entryUrl).href];
39
39
  }
40
40
  /** Resolve, load and construct the configured backend. */
41
- export async function loadForgeBackend(settings, home) {
41
+ export async function loadForgeBackend(settings, home, env) {
42
42
  const backend = isObject(settings) ? settings.backend : undefined;
43
43
  if (!isObject(backend) ||
44
44
  typeof backend.use !== 'string' ||
@@ -57,7 +57,10 @@ export async function loadForgeBackend(settings, home) {
57
57
  throw new Error(`forge backend '${spec}' has no default export factory`);
58
58
  let made;
59
59
  try {
60
- made = await factory(backend.with, { home });
60
+ made = await factory(backend.with, {
61
+ home,
62
+ ...(env ? { env } : {}),
63
+ });
61
64
  }
62
65
  catch (err) {
63
66
  throw new Error(`forge backend '${spec}' rejected its settings: ${err instanceof Error ? err.message : String(err)}`);
@@ -9,5 +9,5 @@ export { mergeWith } from './config.js';
9
9
  export const tools = {
10
10
  contract: 1,
11
11
  tools: FORGE_TOOL_DEFINITIONS,
12
- handlers: (options) => import('./tools.js').then((m) => m.toolsFor(options)),
12
+ handlers: (options, host) => import('./tools.js').then((m) => m.toolsFor(options, host?.env)),
13
13
  };
@@ -1,5 +1,5 @@
1
1
  import type { ToolHandler } from '@bakers-build/conductor/contract';
2
- import type { ForgeBackend, ForgeCheck } from './backend.js';
2
+ import type { AddonEnv, ForgeBackend, ForgeCheck } from './backend.js';
3
3
  export declare const FORGE_NEEDS_RUN = "forge tools act only for an agent run: the call carries no ticket branch_name and base_branch (an operator delivers by hand)";
4
4
  export declare const FORGE_NEEDS_ORIGIN = "forge_issue_update acts only on the run ticket's origin issue, and this ticket has none";
5
5
  export interface ForgeToolDeps {
@@ -16,4 +16,4 @@ export declare const isRequired: (c: ForgeCheck) => boolean;
16
16
  export declare function overall(checks: readonly ForgeCheck[]): Overall;
17
17
  export declare function forgeTools(deps: ForgeToolDeps): Record<string, ToolHandler>;
18
18
  /** The live tools for the conductor's effective forge entry `with`. */
19
- export declare function toolsFor(options: unknown): Record<string, ToolHandler>;
19
+ export declare function toolsFor(options: unknown, env?: () => AddonEnv): Record<string, ToolHandler>;
package/dist/src/tools.js CHANGED
@@ -395,7 +395,7 @@ export function forgeTools(deps) {
395
395
  return Object.fromEntries(Object.entries(tools).map(([n, h]) => [n, guarded(h)]));
396
396
  }
397
397
  /** The live tools for the conductor's effective forge entry `with`. */
398
- export function toolsFor(options) {
398
+ export function toolsFor(options, env) {
399
399
  const backend = options
400
400
  ?.backend;
401
401
  // Fail closed: a forge entry without a backend stops the conductor's start.
@@ -405,7 +405,7 @@ export function toolsFor(options) {
405
405
  return forgeTools({
406
406
  settings: options,
407
407
  backend: () => {
408
- loaded ??= loadForgeBackend(options, homeBbDir()).catch((err) => {
408
+ loaded ??= loadForgeBackend(options, homeBbDir(), env?.()).catch((err) => {
409
409
  loaded = undefined;
410
410
  throw err;
411
411
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bakers-build/addon-forge",
3
- "version": "0.19.1-next.3",
3
+ "version": "0.19.1-next.5",
4
4
  "description": "bakers.build forge tools: a sandboxed run fetches, pushes its own branches, opens its PR/MR, reads checks and merges through the conductor, which holds the token. Backends implement the ForgeBackend contract (./backend).",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -16,17 +16,18 @@
16
16
  "publishConfig": {
17
17
  "access": "public"
18
18
  },
19
+ "homepage": "https://bakers.build",
19
20
  "repository": {
20
21
  "type": "git",
21
22
  "url": "git+https://github.com/bakers-build/bakers-build.git",
22
23
  "directory": "bakers-cli/addons/forge"
23
24
  },
24
25
  "peerDependencies": {
25
- "@bakers-build/conductor": "^0.19.1-next.3",
26
- "@bakers-build/core": "^0.19.1-next.3"
26
+ "@bakers-build/conductor": "^0.19.1-next.5",
27
+ "@bakers-build/core": "^0.19.1-next.5"
27
28
  },
28
29
  "bakersBuild": {
29
- "commit": "81f2970d26d8cf6b4367eb513b68032c8aabe616",
30
+ "commit": "56715034b78f52be0c88ef037b9dc099572bbd06",
30
31
  "channel": "next"
31
32
  }
32
33
  }