@bakers-build/core 0.17.1-next.1 → 0.18.0
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.
|
@@ -7,3 +7,23 @@ export declare function parseSecretsFile(text: string): Record<string, string>;
|
|
|
7
7
|
export declare function loadSecretsFile(path?: string): Record<string, string>;
|
|
8
8
|
/** The declared `names` a run gets: a non-empty shell value wins over the file. */
|
|
9
9
|
export declare function pickSecrets(names: readonly string[], file: Secrets, env?: Readonly<Record<string, string | undefined>>): Record<string, string>;
|
|
10
|
+
/** A run's layer keys: its project name, runtime alias, agent harness id and agent alias. */
|
|
11
|
+
export interface EnvKey {
|
|
12
|
+
project: string;
|
|
13
|
+
runtime: string;
|
|
14
|
+
harness: string;
|
|
15
|
+
alias: string;
|
|
16
|
+
}
|
|
17
|
+
/** Every loaded env file's values, by path. */
|
|
18
|
+
export type EnvFiles = Readonly<Record<string, Secrets>>;
|
|
19
|
+
/** `~/.bakers/envs`, home of the project, runtime and agent env files. */
|
|
20
|
+
export declare function envsDir(home?: string): string;
|
|
21
|
+
/** The run's env files from general to specific; a later file wins per variable. */
|
|
22
|
+
export declare function envLayerPaths(key: EnvKey, home?: string): string[];
|
|
23
|
+
/** The machine file and every `.bakers-*.env` under `envs/`; throws on the first bad file. */
|
|
24
|
+
export declare function loadEnvFiles(home?: string): EnvFiles;
|
|
25
|
+
/** A run's values over its layers, and per name the path of the file it came from. */
|
|
26
|
+
export declare function layeredEnv(key: EnvKey, files: EnvFiles, home?: string): {
|
|
27
|
+
values: Record<string, string>;
|
|
28
|
+
sources: Record<string, string>;
|
|
29
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// The machine's secrets file: `KEY=value` lines a conductor reads at start
|
|
2
2
|
// and hands to a run only for names an agent declares. Parsed, never sourced.
|
|
3
|
-
import { readFileSync, statSync } from 'node:fs';
|
|
3
|
+
import { readdirSync, readFileSync, statSync } from 'node:fs';
|
|
4
4
|
import { join } from 'node:path';
|
|
5
5
|
import { homeBbDir } from '../cli/bakers-dir.js';
|
|
6
6
|
/** `~/.bakers/.bakers.env`, beside `machine.config.js`; `BAKERS_HOME` applies. */
|
|
@@ -60,3 +60,60 @@ export function pickSecrets(names, file, env = process.env) {
|
|
|
60
60
|
}
|
|
61
61
|
return picked;
|
|
62
62
|
}
|
|
63
|
+
const LEVELS = ['project', 'runtime', 'agent'];
|
|
64
|
+
/** `~/.bakers/envs`, home of the project, runtime and agent env files. */
|
|
65
|
+
export function envsDir(home) {
|
|
66
|
+
return join(homeBbDir(home), 'envs');
|
|
67
|
+
}
|
|
68
|
+
/** The run's env files from general to specific; a later file wins per variable. */
|
|
69
|
+
export function envLayerPaths(key, home) {
|
|
70
|
+
const dir = envsDir(home);
|
|
71
|
+
const file = (level, name) => name && !/[/\\]/.test(name)
|
|
72
|
+
? [join(dir, level, `.bakers-${name}.env`)]
|
|
73
|
+
: [];
|
|
74
|
+
const paths = [
|
|
75
|
+
secretsFilePath(home),
|
|
76
|
+
...file('project', key.project),
|
|
77
|
+
...file('runtime', key.runtime),
|
|
78
|
+
...file('agent', key.harness),
|
|
79
|
+
...file('agent', key.alias),
|
|
80
|
+
];
|
|
81
|
+
return [...new Set(paths)];
|
|
82
|
+
}
|
|
83
|
+
/** The machine file and every `.bakers-*.env` under `envs/`; throws on the first bad file. */
|
|
84
|
+
export function loadEnvFiles(home) {
|
|
85
|
+
const files = {};
|
|
86
|
+
const add = (path) => {
|
|
87
|
+
const values = loadSecretsFile(path);
|
|
88
|
+
if (Object.keys(values).length)
|
|
89
|
+
files[path] = values;
|
|
90
|
+
};
|
|
91
|
+
add(secretsFilePath(home));
|
|
92
|
+
for (const level of LEVELS) {
|
|
93
|
+
const dir = join(envsDir(home), level);
|
|
94
|
+
let names;
|
|
95
|
+
try {
|
|
96
|
+
names = readdirSync(dir);
|
|
97
|
+
}
|
|
98
|
+
catch (err) {
|
|
99
|
+
if (err.code === 'ENOENT')
|
|
100
|
+
continue;
|
|
101
|
+
throw err;
|
|
102
|
+
}
|
|
103
|
+
for (const name of names.sort())
|
|
104
|
+
if (/^\.bakers-.+\.env$/.test(name))
|
|
105
|
+
add(join(dir, name));
|
|
106
|
+
}
|
|
107
|
+
return files;
|
|
108
|
+
}
|
|
109
|
+
/** A run's values over its layers, and per name the path of the file it came from. */
|
|
110
|
+
export function layeredEnv(key, files, home) {
|
|
111
|
+
const values = {};
|
|
112
|
+
const sources = {};
|
|
113
|
+
for (const path of envLayerPaths(key, home))
|
|
114
|
+
for (const [name, value] of Object.entries(files[path] ?? {})) {
|
|
115
|
+
values[name] = value;
|
|
116
|
+
sources[name] = path;
|
|
117
|
+
}
|
|
118
|
+
return { values, sources };
|
|
119
|
+
}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -29,7 +29,7 @@ export { protectedProjectPaths } from './core/protected-project-paths.js';
|
|
|
29
29
|
export { normalizeRepoUrl } from './core/repo-url.js';
|
|
30
30
|
export { createRunClone, loadRunClone, type RunClone, type RunCloneOptions, registerRunCloneWorktree, removeRunClone, runCloneGitDir, saveRunClone, } from './core/run-clone.js';
|
|
31
31
|
export { cliRootOf } from './core/runtime-paths.js';
|
|
32
|
-
export { loadSecretsFile, parseSecretsFile, pickSecrets, type Secrets, secretsFilePath, } from './core/secrets-file.js';
|
|
32
|
+
export { type EnvFiles, type EnvKey, envLayerPaths, envsDir, layeredEnv, loadEnvFiles, loadSecretsFile, parseSecretsFile, pickSecrets, type Secrets, secretsFilePath, } from './core/secrets-file.js';
|
|
33
33
|
export { shellQuote } from './core/shell.js';
|
|
34
34
|
export { DEFAULT_SLUG_MAX_LENGTH, slugify } from './core/slug.js';
|
|
35
35
|
export { bumpUiRefresh, UI_REFRESH_FILE } from './core/ui-refresh.js';
|
package/dist/src/index.js
CHANGED
|
@@ -30,7 +30,7 @@ export { protectedProjectPaths } from './core/protected-project-paths.js';
|
|
|
30
30
|
export { normalizeRepoUrl } from './core/repo-url.js';
|
|
31
31
|
export { createRunClone, loadRunClone, registerRunCloneWorktree, removeRunClone, runCloneGitDir, saveRunClone, } from './core/run-clone.js';
|
|
32
32
|
export { cliRootOf } from './core/runtime-paths.js';
|
|
33
|
-
export { loadSecretsFile, parseSecretsFile, pickSecrets, secretsFilePath, } from './core/secrets-file.js';
|
|
33
|
+
export { envLayerPaths, envsDir, layeredEnv, loadEnvFiles, loadSecretsFile, parseSecretsFile, pickSecrets, secretsFilePath, } from './core/secrets-file.js';
|
|
34
34
|
export { shellQuote } from './core/shell.js';
|
|
35
35
|
export { DEFAULT_SLUG_MAX_LENGTH, slugify } from './core/slug.js';
|
|
36
36
|
export { bumpUiRefresh, UI_REFRESH_FILE } from './core/ui-refresh.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bakers-build/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"description": "bakers.build surface-agnostic kernel: host contract, split-config helpers, addon preset/discovery machinery, shared primitives.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"yaml": "^2.7.0"
|
|
41
41
|
},
|
|
42
42
|
"bakersBuild": {
|
|
43
|
-
"commit": "
|
|
44
|
-
"channel": "
|
|
43
|
+
"commit": "035506c7ccbdf8641f605a5dcb07d50ccf42d72d",
|
|
44
|
+
"channel": "latest"
|
|
45
45
|
}
|
|
46
46
|
}
|