@bakers-build/addon-ports 0.8.0 → 0.8.1-next.10
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/dist/src/config.d.ts +3 -2
- package/dist/src/config.js +9 -8
- package/dist/src/deps-node.d.ts +1 -1
- package/dist/src/deps-node.js +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/preset.d.ts +1 -1
- package/dist/src/preset.js +3 -2
- package/dist/src/service-config.d.ts +6 -7
- package/dist/src/service-config.js +16 -65
- package/options.schema.json +64 -0
- package/package.json +10 -8
package/dist/src/config.d.ts
CHANGED
|
@@ -11,12 +11,13 @@ export interface PortsMachineConfig {
|
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
13
|
/** No ports addon entry (or one without a transport) in either scope. */
|
|
14
|
-
export declare const PORTS_NEEDS_ENTRY = "bakers ports needs '@bakers-build/addon-ports' in addons[] of ~/.bakers/machine.config.js or .bakers/
|
|
14
|
+
export declare const PORTS_NEEDS_ENTRY = "bakers ports needs '@bakers-build/addon-ports' in addons[] of ~/.bakers/machine.config.js or .bakers/project.config.js, with with.transport.use naming a transport package; see docs/addons/ports";
|
|
15
15
|
/** The retired top-level machine `ports` key. */
|
|
16
16
|
export declare const PORTS_RETIRED = "machine ports is retired: move it to addons: [{ use: '@bakers-build/addon-ports', with: { transport: \u2026 } }]";
|
|
17
17
|
/** Throw the remediation when the machine config still carries `ports`. */
|
|
18
18
|
export declare function assertNoMachinePorts(): Promise<void>;
|
|
19
|
-
/** `addons[@bakers-build/addon-ports].with.<key> <message>`
|
|
19
|
+
/** `addons[@bakers-build/addon-ports].with.<key> <message>` for the rule the
|
|
20
|
+
* options schema cannot express (a duplicate service key). */
|
|
20
21
|
export declare function withProblems(value: unknown): string[];
|
|
21
22
|
/** `portsSettings` plus the retired machine `ports` check — the transport
|
|
22
23
|
* path; discovery (`list`) reads settings without it. */
|
package/dist/src/config.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { realpathSync } from 'node:fs';
|
|
6
6
|
import { pathToFileURL } from 'node:url';
|
|
7
7
|
import { machineUiConfigPath, projectConductorConfigPath, readConfigAddons, readEffectiveAddon, readMachineContext, resolveModuleEslintStyle, } from '@bakers-build/core';
|
|
8
|
-
import {
|
|
8
|
+
import { duplicateServiceKey } from './service-config.js';
|
|
9
9
|
import { assertPortsTransport, InvalidTransportModuleError, } from './transport.js';
|
|
10
10
|
/**
|
|
11
11
|
* Resolution bases rooted at the running `bakers` HOST install, usable from
|
|
@@ -44,7 +44,7 @@ function hostInstallBases() {
|
|
|
44
44
|
return [entryUrl.href, new URL('../host/dist/src/host.js', entryUrl).href];
|
|
45
45
|
}
|
|
46
46
|
/** No ports addon entry (or one without a transport) in either scope. */
|
|
47
|
-
export const PORTS_NEEDS_ENTRY = "bakers ports needs '@bakers-build/addon-ports' in addons[] of ~/.bakers/machine.config.js or .bakers/
|
|
47
|
+
export const PORTS_NEEDS_ENTRY = "bakers ports needs '@bakers-build/addon-ports' in addons[] of ~/.bakers/machine.config.js or .bakers/project.config.js, with with.transport.use naming a transport package; see docs/addons/ports";
|
|
48
48
|
/** The retired top-level machine `ports` key. */
|
|
49
49
|
export const PORTS_RETIRED = "machine ports is retired: move it to addons: [{ use: '@bakers-build/addon-ports', with: { transport: … } }]";
|
|
50
50
|
/** Throw the remediation when the machine config still carries `ports`. */
|
|
@@ -54,9 +54,11 @@ export async function assertNoMachinePorts() {
|
|
|
54
54
|
throw new Error(PORTS_RETIRED);
|
|
55
55
|
}
|
|
56
56
|
const PORTS_SPEC = '@bakers-build/addon-ports';
|
|
57
|
-
/** `addons[@bakers-build/addon-ports].with.<key> <message>`
|
|
57
|
+
/** `addons[@bakers-build/addon-ports].with.<key> <message>` for the rule the
|
|
58
|
+
* options schema cannot express (a duplicate service key). */
|
|
58
59
|
export function withProblems(value) {
|
|
59
|
-
|
|
60
|
+
const problem = duplicateServiceKey(value);
|
|
61
|
+
return problem ? [`addons[${PORTS_SPEC}].with.${problem}`] : [];
|
|
60
62
|
}
|
|
61
63
|
/** Throw the first malformed ports `with` in the machine or project config,
|
|
62
64
|
* naming the file and key — a bad setting is never silently ignored. */
|
|
@@ -66,10 +68,9 @@ async function assertValidScopes(worktree) {
|
|
|
66
68
|
if (path === undefined)
|
|
67
69
|
continue;
|
|
68
70
|
for (const entry of await readConfigAddons(path)) {
|
|
69
|
-
if (typeof entry === 'string' ||
|
|
70
|
-
(entry?.use ?? entry?.name) !== PORTS_SPEC)
|
|
71
|
+
if (typeof entry === 'string' || entry?.use !== PORTS_SPEC)
|
|
71
72
|
continue;
|
|
72
|
-
const [problem] = withProblems(entry.with
|
|
73
|
+
const [problem] = withProblems(entry.with);
|
|
73
74
|
if (problem)
|
|
74
75
|
throw new Error(`${path}: ${problem}`);
|
|
75
76
|
}
|
|
@@ -94,7 +95,7 @@ export async function readPortsSettings(worktree) {
|
|
|
94
95
|
});
|
|
95
96
|
if (found === undefined || typeof found.entry === 'string')
|
|
96
97
|
return undefined;
|
|
97
|
-
return found.entry.with
|
|
98
|
+
return found.entry.with;
|
|
98
99
|
}
|
|
99
100
|
/** `home`, the running `bakers` host install, then `process.cwd()` — see
|
|
100
101
|
* `loadPortsTransport`. */
|
package/dist/src/deps-node.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export declare function processStartTime(pid: number): Promise<number | null>;
|
|
|
19
19
|
/**
|
|
20
20
|
* BB-681 Task 4 — a process whose cmdline carries ANY pluggable-transport
|
|
21
21
|
* package's own ownership marker: `addon-ports-cloudflare-quick`'s private
|
|
22
|
-
* per-route `--config <
|
|
22
|
+
* per-route `--config <BAKERS_HOME>/ports/quick/<hash>/gen-<n>/config.yaml`,
|
|
23
23
|
* or a Named Cloudflare connector's `tunnel run` invocation. This generic
|
|
24
24
|
* legacy-reap scan predates per-route managed processes (BB-676) and its
|
|
25
25
|
* only signal for "legacy" is `cmdline.includes('--url')` (see
|
package/dist/src/deps-node.js
CHANGED
|
@@ -115,7 +115,7 @@ export async function processStartTime(pid) {
|
|
|
115
115
|
/**
|
|
116
116
|
* BB-681 Task 4 — a process whose cmdline carries ANY pluggable-transport
|
|
117
117
|
* package's own ownership marker: `addon-ports-cloudflare-quick`'s private
|
|
118
|
-
* per-route `--config <
|
|
118
|
+
* per-route `--config <BAKERS_HOME>/ports/quick/<hash>/gen-<n>/config.yaml`,
|
|
119
119
|
* or a Named Cloudflare connector's `tunnel run` invocation. This generic
|
|
120
120
|
* legacy-reap scan predates per-route managed processes (BB-676) and its
|
|
121
121
|
* only signal for "legacy" is `cmdline.includes('--url')` (see
|
package/dist/src/index.js
CHANGED
|
@@ -286,7 +286,7 @@ export function quickTunnelNotice(url) {
|
|
|
286
286
|
return undefined;
|
|
287
287
|
return 'Quick Tunnel: no fixed name, no uptime guarantee, 200 in-flight request limit, no SSE';
|
|
288
288
|
}
|
|
289
|
-
const NO_CONDUCTOR = 'no running conductor for this checkout — the conductor is the only writer of the tunnel routes (start it with `bakers
|
|
289
|
+
const NO_CONDUCTOR = 'no running conductor for this checkout — the conductor is the only writer of the tunnel routes (start it with `bakers conductor start`)';
|
|
290
290
|
/** The live conductor endpoint whose workspace root holds `worktree`; the
|
|
291
291
|
* most specific root wins. A dead pid's leftover file does not count. */
|
|
292
292
|
function conductorEndpoint(worktree) {
|
package/dist/src/preset.d.ts
CHANGED
|
@@ -3,5 +3,5 @@ import type { BbPreset } from '@bakers-build/core';
|
|
|
3
3
|
export declare const commands: BbPreset['commands'];
|
|
4
4
|
export declare const inbox: Preset['inbox'];
|
|
5
5
|
export declare const scopes: BbPreset['scopes'];
|
|
6
|
-
export {
|
|
6
|
+
export { mergeWith } from './service-config.js';
|
|
7
7
|
export declare const tools: Preset['tools'];
|
package/dist/src/preset.js
CHANGED
|
@@ -28,8 +28,9 @@ export const inbox = {
|
|
|
28
28
|
};
|
|
29
29
|
// Configurable on either level; the machine entry's with wins.
|
|
30
30
|
export const scopes = ['machine', 'project'];
|
|
31
|
-
// Merge
|
|
32
|
-
|
|
31
|
+
// Merge the entry's own settings across scopes (services, all_node, transport);
|
|
32
|
+
// options.schema.json describes them.
|
|
33
|
+
export { mergeWith } from './service-config.js';
|
|
33
34
|
// Agent tools the conductor serves to every run (and the CLI calls through
|
|
34
35
|
// it): the conductor is the only writer of the tunnel routes.
|
|
35
36
|
export const tools = {
|
|
@@ -8,14 +8,13 @@ export interface ServiceRules {
|
|
|
8
8
|
readonly entries: readonly ServiceRule[];
|
|
9
9
|
readonly allNode: boolean;
|
|
10
10
|
}
|
|
11
|
-
export interface WithFinding {
|
|
12
|
-
/** Relative to the entry's `with`: `services[1].key`, `all_node`, `foo`. */
|
|
13
|
-
readonly key: string;
|
|
14
|
-
readonly message: string;
|
|
15
|
-
}
|
|
16
11
|
export declare const DEFAULT_STORYBOOK: ServiceRule;
|
|
17
|
-
/**
|
|
18
|
-
|
|
12
|
+
/**
|
|
13
|
+
* The one rule options.schema.json cannot express: two `services` entries
|
|
14
|
+
* with the same key. Returns `services[i].key duplicates '<key>'`, or
|
|
15
|
+
* undefined. Types, unknown keys and the label pattern are the schema's.
|
|
16
|
+
*/
|
|
17
|
+
export declare function duplicateServiceKey(value: unknown): string | undefined;
|
|
19
18
|
/**
|
|
20
19
|
* The ports addon in both scopes: the machine wins. `services` merge per key
|
|
21
20
|
* (machine entries first); every other key is taken whole from the machine
|
|
@@ -10,73 +10,24 @@ export const DEFAULT_STORYBOOK = {
|
|
|
10
10
|
key: 'storybook',
|
|
11
11
|
match: 'storybook',
|
|
12
12
|
};
|
|
13
|
-
const WITH_KEYS = new Set(['transport', 'services', 'all_node', 'claimers']);
|
|
14
|
-
const ENTRY_KEYS = new Set(['key', 'match']);
|
|
15
13
|
const isObject = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
16
|
-
/**
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
(!Array.isArray(claimers) ||
|
|
32
|
-
!claimers.every((c) => typeof c === 'string' && c !== '')))
|
|
33
|
-
out.push({ key: 'claimers', message: 'must be an array of package names' });
|
|
34
|
-
if (transport !== undefined) {
|
|
35
|
-
if (!isObject(transport))
|
|
36
|
-
out.push({ key: 'transport', message: 'must be an object' });
|
|
37
|
-
else if (typeof transport.use !== 'string' || transport.use === '')
|
|
38
|
-
out.push({
|
|
39
|
-
key: 'transport.use',
|
|
40
|
-
message: 'must name a transport package',
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
if (all_node !== undefined && typeof all_node !== 'boolean')
|
|
44
|
-
out.push({ key: 'all_node', message: 'must be true or false' });
|
|
45
|
-
if (services !== undefined) {
|
|
46
|
-
if (!Array.isArray(services))
|
|
47
|
-
out.push({ key: 'services', message: 'must be an array' });
|
|
48
|
-
else {
|
|
49
|
-
const seen = new Set();
|
|
50
|
-
services.forEach((entry, i) => {
|
|
51
|
-
const at = `services[${i}]`;
|
|
52
|
-
if (!isObject(entry)) {
|
|
53
|
-
out.push({ key: at, message: 'must be { key, match }' });
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
for (const k of Object.keys(entry))
|
|
57
|
-
if (!ENTRY_KEYS.has(k))
|
|
58
|
-
out.push({
|
|
59
|
-
key: `${at}.${k}`,
|
|
60
|
-
message: 'is not a service field (key, match)',
|
|
61
|
-
});
|
|
62
|
-
if (typeof entry.key !== 'string' || !LABEL_RE.test(entry.key))
|
|
63
|
-
out.push({
|
|
64
|
-
key: `${at}.key`,
|
|
65
|
-
message: 'must be a DNS-safe label (a-z, 0-9, -)',
|
|
66
|
-
});
|
|
67
|
-
else if (seen.has(entry.key))
|
|
68
|
-
out.push({ key: `${at}.key`, message: `duplicates '${entry.key}'` });
|
|
69
|
-
else
|
|
70
|
-
seen.add(entry.key);
|
|
71
|
-
if (typeof entry.match !== 'string' || entry.match === '')
|
|
72
|
-
out.push({
|
|
73
|
-
key: `${at}.match`,
|
|
74
|
-
message: 'must be a non-empty string',
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
}
|
|
14
|
+
/**
|
|
15
|
+
* The one rule options.schema.json cannot express: two `services` entries
|
|
16
|
+
* with the same key. Returns `services[i].key duplicates '<key>'`, or
|
|
17
|
+
* undefined. Types, unknown keys and the label pattern are the schema's.
|
|
18
|
+
*/
|
|
19
|
+
export function duplicateServiceKey(value) {
|
|
20
|
+
const services = isObject(value) ? value.services : undefined;
|
|
21
|
+
if (!Array.isArray(services))
|
|
22
|
+
return undefined;
|
|
23
|
+
const seen = new Set();
|
|
24
|
+
for (const [i, entry] of services.entries()) {
|
|
25
|
+
const key = isObject(entry) ? entry.key : undefined;
|
|
26
|
+
if (seen.has(key))
|
|
27
|
+
return `services[${i}].key duplicates '${key}'`;
|
|
28
|
+
seen.add(key);
|
|
78
29
|
}
|
|
79
|
-
return
|
|
30
|
+
return undefined;
|
|
80
31
|
}
|
|
81
32
|
/**
|
|
82
33
|
* The ports addon in both scopes: the machine wins. `services` merge per key
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://bakers.build/schema/addon-ports/options.schema.json",
|
|
4
|
+
"title": "@bakers-build/addon-ports options",
|
|
5
|
+
"description": "The ports addon entry's with. A duplicate services key is rejected at load by the addon itself.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"additionalProperties": false,
|
|
8
|
+
"properties": {
|
|
9
|
+
"transport": {
|
|
10
|
+
"type": "object",
|
|
11
|
+
"additionalProperties": false,
|
|
12
|
+
"required": [
|
|
13
|
+
"use"
|
|
14
|
+
],
|
|
15
|
+
"properties": {
|
|
16
|
+
"use": {
|
|
17
|
+
"type": "string",
|
|
18
|
+
"minLength": 1,
|
|
19
|
+
"description": "The transport package."
|
|
20
|
+
},
|
|
21
|
+
"with": {
|
|
22
|
+
"description": "The transport package's own settings, checked by that package's options.schema.json."
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"description": "The tunnel transport; required for `bakers ports up`, `down`, `reap` and the Share tunnels message."
|
|
26
|
+
},
|
|
27
|
+
"services": {
|
|
28
|
+
"type": "array",
|
|
29
|
+
"items": {
|
|
30
|
+
"type": "object",
|
|
31
|
+
"additionalProperties": false,
|
|
32
|
+
"required": [
|
|
33
|
+
"key",
|
|
34
|
+
"match"
|
|
35
|
+
],
|
|
36
|
+
"properties": {
|
|
37
|
+
"key": {
|
|
38
|
+
"type": "string",
|
|
39
|
+
"pattern": "^[a-z0-9]([a-z0-9-]*[a-z0-9])?$",
|
|
40
|
+
"description": "A DNS-safe label."
|
|
41
|
+
},
|
|
42
|
+
"match": {
|
|
43
|
+
"type": "string",
|
|
44
|
+
"minLength": 1,
|
|
45
|
+
"description": "A command-line substring of the process."
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"description": "Host processes shared as services; see Shared processes."
|
|
50
|
+
},
|
|
51
|
+
"all_node": {
|
|
52
|
+
"type": "boolean",
|
|
53
|
+
"description": "Share every Node process; see Shared processes."
|
|
54
|
+
},
|
|
55
|
+
"claimers": {
|
|
56
|
+
"type": "array",
|
|
57
|
+
"items": {
|
|
58
|
+
"type": "string",
|
|
59
|
+
"minLength": 1
|
|
60
|
+
},
|
|
61
|
+
"description": "Runtime claimer packages; see Shared processes."
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bakers-build/addon-ports",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.1-next.10",
|
|
4
4
|
"description": "bakers.build ports command plugin: discover a ticket worktree's running services (claimer packages' containers, Storybook, ad-hoc listeners) and bring shareable tunnels up and down. The command half of BB-475; usable without the cockpit half.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -9,10 +9,12 @@
|
|
|
9
9
|
"./preset": "./dist/src/preset.js",
|
|
10
10
|
"./core": "./dist/src/core.js",
|
|
11
11
|
"./transport": "./dist/src/transport-contract.js",
|
|
12
|
-
"./node": "./dist/src/deps-node.js"
|
|
12
|
+
"./node": "./dist/src/deps-node.js",
|
|
13
|
+
"./options.schema.json": "./options.schema.json"
|
|
13
14
|
},
|
|
14
15
|
"files": [
|
|
15
|
-
"dist/src"
|
|
16
|
+
"dist/src",
|
|
17
|
+
"options.schema.json"
|
|
16
18
|
],
|
|
17
19
|
"publishConfig": {
|
|
18
20
|
"access": "public"
|
|
@@ -23,15 +25,15 @@
|
|
|
23
25
|
"directory": "bakers-cli/addons/ports"
|
|
24
26
|
},
|
|
25
27
|
"dependencies": {
|
|
26
|
-
"@bakers-build/addon-docker-compose": "^0.8.
|
|
28
|
+
"@bakers-build/addon-docker-compose": "^0.8.1-next.10",
|
|
27
29
|
"commander": "^12.1.0"
|
|
28
30
|
},
|
|
29
31
|
"peerDependencies": {
|
|
30
|
-
"@bakers-build/conductor": "^0.8.
|
|
31
|
-
"@bakers-build/core": "^0.8.
|
|
32
|
+
"@bakers-build/conductor": "^0.8.1-next.10",
|
|
33
|
+
"@bakers-build/core": "^0.8.1-next.10"
|
|
32
34
|
},
|
|
33
35
|
"bakersBuild": {
|
|
34
|
-
"commit": "
|
|
35
|
-
"channel": "
|
|
36
|
+
"commit": "ceb44a12624feaa85cb2b0c9f84345399b38bf50",
|
|
37
|
+
"channel": "next"
|
|
36
38
|
}
|
|
37
39
|
}
|