agentlane 0.0.0 → 0.4.0-rc.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/CHANGELOG.md +118 -0
- package/LICENSE +27 -0
- package/README.md +167 -2
- package/dist/agents/claude-plugin.js +79 -0
- package/dist/agents/cli.js +258 -0
- package/dist/agents/detect.js +88 -0
- package/dist/agents/init.js +251 -0
- package/dist/agents/launcher.js +32 -0
- package/dist/agents/package.js +119 -0
- package/dist/agents/skills.js +59 -0
- package/dist/agents/toml.js +325 -0
- package/dist/agents/wiring-check.js +117 -0
- package/dist/agents/wiring.js +374 -0
- package/dist/bench/host.js +104 -0
- package/dist/bench/live.js +511 -0
- package/dist/bench/mcp-client.js +91 -0
- package/dist/bench/model.js +15 -0
- package/dist/bench/report.js +162 -0
- package/dist/bench/run.js +121 -0
- package/dist/bench/schedule.js +140 -0
- package/dist/bench/stats.js +59 -0
- package/dist/bench-cli.js +167 -0
- package/dist/browser/aria.js +184 -0
- package/dist/browser/control.js +203 -0
- package/dist/browser/env.js +118 -0
- package/dist/browser/evidence.js +44 -0
- package/dist/browser/install.js +361 -0
- package/dist/browser/kinds.js +10 -0
- package/dist/browser/lane-browser.js +224 -0
- package/dist/browser/libraries.js +56 -0
- package/dist/browser/paths.js +29 -0
- package/dist/browser/release.js +121 -0
- package/dist/browser/screen.js +19 -0
- package/dist/browser/signin.js +154 -0
- package/dist/browser/stop.js +163 -0
- package/dist/browser/tools.js +25 -0
- package/dist/cache/build.js +154 -0
- package/dist/cache/config.js +186 -0
- package/dist/cache/index.js +4 -0
- package/dist/cache/key.js +196 -0
- package/dist/cache/store.js +303 -0
- package/dist/cli.js +178 -0
- package/dist/clock.js +4 -0
- package/dist/devices/adb.js +160 -0
- package/dist/devices/android.js +214 -0
- package/dist/devices/backend.js +7 -0
- package/dist/devices/bundler.js +46 -0
- package/dist/devices/common.js +51 -0
- package/dist/devices/controls.js +65 -0
- package/dist/devices/dial.js +56 -0
- package/dist/devices/emulator.js +396 -0
- package/dist/devices/hygiene.js +202 -0
- package/dist/devices/index.js +5 -0
- package/dist/devices/launch.js +76 -0
- package/dist/devices/simctl.js +119 -0
- package/dist/devices/tools.js +1 -0
- package/dist/devices/variant.js +99 -0
- package/dist/devices/xcrun.js +265 -0
- package/dist/driver/absence.js +54 -0
- package/dist/driver/caller.js +51 -0
- package/dist/driver/client.js +312 -0
- package/dist/driver/diff.js +180 -0
- package/dist/driver/elements.js +70 -0
- package/dist/driver/engine-main.js +13 -0
- package/dist/driver/engine.js +499 -0
- package/dist/driver/errors.js +11 -0
- package/dist/driver/exec.js +66 -0
- package/dist/driver/failure.js +156 -0
- package/dist/driver/flow.js +94 -0
- package/dist/driver/idle.js +100 -0
- package/dist/driver/images.js +68 -0
- package/dist/driver/install.js +272 -0
- package/dist/driver/lock.js +101 -0
- package/dist/driver/look.js +223 -0
- package/dist/driver/maestro-child.js +194 -0
- package/dist/driver/maestro-runs.js +46 -0
- package/dist/driver/paths.js +105 -0
- package/dist/driver/pixels.js +144 -0
- package/dist/driver/plan.js +108 -0
- package/dist/driver/release.js +7 -0
- package/dist/driver/runner.js +42 -0
- package/dist/driver/selector.js +91 -0
- package/dist/driver/session.js +474 -0
- package/dist/driver/suggest.js +86 -0
- package/dist/driver/supervisor.js +251 -0
- package/dist/driver/tree.js +426 -0
- package/dist/driver-cli.js +865 -0
- package/dist/evidence/device.js +177 -0
- package/dist/evidence/evidence.js +304 -0
- package/dist/evidence/files.js +92 -0
- package/dist/hooks/env.js +81 -0
- package/dist/hooks/run.js +101 -0
- package/dist/mcp/server.js +69 -0
- package/dist/mcp/tools.js +246 -0
- package/dist/name.js +22 -0
- package/dist/plugin/aims.js +465 -0
- package/dist/plugin/conventions.js +73 -0
- package/dist/plugin/guard.js +163 -0
- package/dist/plugin/hook-cli.js +216 -0
- package/dist/plugin/session-name.js +28 -0
- package/dist/plugin/shell.js +254 -0
- package/dist/processes.js +77 -0
- package/dist/project/config.js +316 -0
- package/dist/project/schema.js +335 -0
- package/dist/project/validate.js +224 -0
- package/dist/registry/config.js +142 -0
- package/dist/registry/format.js +22 -0
- package/dist/registry/owner.js +265 -0
- package/dist/registry/paths.js +50 -0
- package/dist/registry/ports.js +26 -0
- package/dist/registry/prune.js +160 -0
- package/dist/registry/refusal.js +53 -0
- package/dist/registry/registry.js +1027 -0
- package/dist/registry/resources.js +117 -0
- package/dist/registry/rows.js +115 -0
- package/dist/registry/status.js +85 -0
- package/dist/registry/store.js +274 -0
- package/dist/registry/types.js +1 -0
- package/dist/registry-cli.js +544 -0
- package/dist/services/services.js +268 -0
- package/dist/services/system.js +189 -0
- package/dist/up/deps.js +1 -0
- package/dist/up/doctor.js +424 -0
- package/dist/up/exec.js +133 -0
- package/dist/up/lane-files.js +75 -0
- package/dist/up/lane-services.js +38 -0
- package/dist/up/maestro-env.js +172 -0
- package/dist/up/preflight.js +232 -0
- package/dist/up/release.js +148 -0
- package/dist/up/resources.js +178 -0
- package/dist/up/restart.js +87 -0
- package/dist/up/setup.js +28 -0
- package/dist/up/up.js +610 -0
- package/dist/up-cli.js +258 -0
- package/dist/usage.js +16 -0
- package/package.json +58 -3
- package/schema/agentlane.schema.json +675 -0
- package/skills/create-verification-skill/LICENSE +21 -0
- package/skills/create-verification-skill/SKILL.md +88 -0
- package/skills/dev-loop/LICENSE +21 -0
- package/skills/dev-loop/SKILL.md +61 -0
- package/skills/device/SKILL.md +8 -0
- package/skills/drive/SKILL.md +64 -0
- package/skills/maintain-verification-skill/LICENSE +21 -0
- package/skills/maintain-verification-skill/SKILL.md +42 -0
- package/skills/setup/SKILL.md +80 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
const LSTART = String.raw `[A-Z][a-z]{2} [A-Z][a-z]{2} +\d{1,2} \d{2}:\d{2}:\d{2} \d{4}`;
|
|
4
|
+
const START_LINE = new RegExp(String.raw `^\s*(\d+)\s+(${LSTART})\s*$`);
|
|
5
|
+
const INFO_LINE = new RegExp(String.raw `^\s*(\d+)\s+(\d+)\s+(${LSTART})\s?(.*)$`);
|
|
6
|
+
function normalizeStart(lstart) {
|
|
7
|
+
return lstart.replace(/\s+/g, ' ');
|
|
8
|
+
}
|
|
9
|
+
export function describeStart(start) {
|
|
10
|
+
return `${start} UTC`;
|
|
11
|
+
}
|
|
12
|
+
function ps(columns, pids) {
|
|
13
|
+
const result = spawnSync('ps', ['-o', columns, '-p', pids.join(',')], {
|
|
14
|
+
encoding: 'utf8',
|
|
15
|
+
env: { PATH: `${process.env.PATH ?? ''}:/bin:/usr/bin`, LC_ALL: 'C', TZ: 'UTC' },
|
|
16
|
+
timeout: 10_000,
|
|
17
|
+
});
|
|
18
|
+
if (result.error)
|
|
19
|
+
return undefined;
|
|
20
|
+
const lines = result.stdout.split('\n').filter(line => line.trim() !== '');
|
|
21
|
+
if (result.status === 0)
|
|
22
|
+
return lines;
|
|
23
|
+
if (result.status === 1 && lines.length === 0 && result.stderr.trim() === '')
|
|
24
|
+
return [];
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
function lsofCwd(pid) {
|
|
28
|
+
const result = spawnSync('lsof', ['-a', '-p', String(pid), '-d', 'cwd', '-Fn'], {
|
|
29
|
+
encoding: 'utf8',
|
|
30
|
+
env: { PATH: `${process.env.PATH ?? ''}:/usr/sbin:/usr/bin`, LC_ALL: 'C' },
|
|
31
|
+
timeout: 10_000,
|
|
32
|
+
});
|
|
33
|
+
if (result.error || result.status !== 0)
|
|
34
|
+
return undefined;
|
|
35
|
+
const line = result.stdout.split('\n').find(l => l.startsWith('n'));
|
|
36
|
+
return line?.slice(1);
|
|
37
|
+
}
|
|
38
|
+
export const systemProcesses = {
|
|
39
|
+
startTimes(pids) {
|
|
40
|
+
const wanted = [...new Set(pids)].filter(pid => Number.isInteger(pid) && pid > 0);
|
|
41
|
+
if (wanted.length === 0)
|
|
42
|
+
return new Map();
|
|
43
|
+
const lines = ps('pid=,lstart=', wanted);
|
|
44
|
+
if (!lines)
|
|
45
|
+
return undefined;
|
|
46
|
+
const table = new Map();
|
|
47
|
+
for (const line of lines) {
|
|
48
|
+
const m = START_LINE.exec(line);
|
|
49
|
+
if (!m?.[1] || !m[2])
|
|
50
|
+
return undefined;
|
|
51
|
+
table.set(Number(m[1]), normalizeStart(m[2]));
|
|
52
|
+
}
|
|
53
|
+
return table;
|
|
54
|
+
},
|
|
55
|
+
info(pid) {
|
|
56
|
+
const lines = ps('pid=,ppid=,lstart=,args=', [pid]);
|
|
57
|
+
const m = lines?.[0] ? INFO_LINE.exec(lines[0]) : null;
|
|
58
|
+
if (!m?.[1] || !m[2] || !m[3])
|
|
59
|
+
return undefined;
|
|
60
|
+
return { pid: Number(m[1]), ppid: Number(m[2]), start: normalizeStart(m[3]), command: m[4] ?? '' };
|
|
61
|
+
},
|
|
62
|
+
cwd(pid) {
|
|
63
|
+
if (process.platform === 'linux') {
|
|
64
|
+
try {
|
|
65
|
+
return fs.readlinkSync(`/proc/${String(pid)}/cwd`);
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return lsofCwd(pid);
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
export function identityOf(table, pid) {
|
|
75
|
+
const start = table.startTimes([pid])?.get(pid);
|
|
76
|
+
return start === undefined ? undefined : { pid, start };
|
|
77
|
+
}
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { BROWSER_SERVICES, DEFAULT_BROWSER_DRIVER } from "../browser/kinds.js";
|
|
5
|
+
import { AGENT_BROWSER_RELEASE } from "../browser/release.js";
|
|
6
|
+
import { parseBuildCacheConfig } from "../cache/config.js";
|
|
7
|
+
import { CLI, CONFIG_FILE, ENV_PREFIX, FORMER, SCHEMA_FILE, TOOL } from "../name.js";
|
|
8
|
+
import { UsageError } from "../registry/refusal.js";
|
|
9
|
+
import { BUILT_IN_SERVICE_TYPES, DEFAULT_DIAL_VALUE, DEFAULT_READY_HOST, DEFAULT_READY_SECONDS, DEFAULT_TEARDOWN_SECONDS, DEFAULT_VARIANT, DEFAULT_WEB_PATH, projectSchema, WEB_PLATFORM, } from "./schema.js";
|
|
10
|
+
import { SchemaValidator } from "./validate.js";
|
|
11
|
+
export function asMobile(config) {
|
|
12
|
+
const { app, platform } = config;
|
|
13
|
+
return app !== null && platform !== WEB_PLATFORM ? { ...config, app, platform } : null;
|
|
14
|
+
}
|
|
15
|
+
export class ProjectConfigError extends Error {
|
|
16
|
+
file;
|
|
17
|
+
problems;
|
|
18
|
+
constructor(file, problems) {
|
|
19
|
+
const shown = problems.slice(0, 6).map(p => ` ${p.path || '/'} ${p.message}\n (schema: ${p.schemaPath})`);
|
|
20
|
+
const more = problems.length > shown.length ? [` ... and ${String(problems.length - shown.length)} more`] : [];
|
|
21
|
+
super(`${file} is not a valid ${CONFIG_FILE}:\n${[...shown, ...more].join('\n')}`);
|
|
22
|
+
this.name = 'ProjectConfigError';
|
|
23
|
+
this.file = file;
|
|
24
|
+
this.problems = problems;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const validator = new SchemaValidator(projectSchema);
|
|
28
|
+
function problem(pathText, message) {
|
|
29
|
+
return { path: pathText, schemaPath: '(cross-field rule)', message };
|
|
30
|
+
}
|
|
31
|
+
const RESERVED_EXPORTS = new Set(['LANG', 'LC_ALL']);
|
|
32
|
+
function appProblems(raw, services) {
|
|
33
|
+
const problems = [];
|
|
34
|
+
const launchHook = raw.hooks?.launch;
|
|
35
|
+
if (!raw.app) {
|
|
36
|
+
if (launchHook !== undefined)
|
|
37
|
+
problems.push(problem('/hooks/launch', 'launches the mobile app, and there is no app'));
|
|
38
|
+
return problems;
|
|
39
|
+
}
|
|
40
|
+
const { launch, bundler } = raw.app;
|
|
41
|
+
if (launch === 'hook' && launchHook === undefined) {
|
|
42
|
+
problems.push(problem('/hooks/launch', 'is required when app.launch is "hook"'));
|
|
43
|
+
}
|
|
44
|
+
if (launch !== 'hook' && launchHook !== undefined) {
|
|
45
|
+
problems.push(problem('/hooks/launch', `is not used when app.launch is "${launch}"; remove it, or set app.launch to "hook"`));
|
|
46
|
+
}
|
|
47
|
+
const bundlerService = services.find(([name, s]) => (bundler === undefined ? s.type === 'metro' : name === bundler));
|
|
48
|
+
const missing = bundlerService?.[1].platforms?.filter(p => p === 'ios' || p === 'android') ?? null;
|
|
49
|
+
if (bundlerService && missing !== null && !missing.includes(raw.app.platform)) {
|
|
50
|
+
problems.push(problem(`/services/${bundlerService[0]}/platforms`, `leaves out ${raw.app.platform}, and the app loads its JavaScript from ${bundlerService[0]} there; add "${raw.app.platform}"`));
|
|
51
|
+
}
|
|
52
|
+
if (bundler !== undefined && !services.some(([name]) => name === bundler)) {
|
|
53
|
+
problems.push(problem('/app/bundler', `names no service; the services are: ${services.map(([n]) => n).join(', ') || 'none'}`));
|
|
54
|
+
}
|
|
55
|
+
if (launch !== 'hook' && bundler === undefined) {
|
|
56
|
+
const metro = services.filter(([, s]) => s.type === 'metro');
|
|
57
|
+
if (metro.length !== 1) {
|
|
58
|
+
problems.push(problem('/app/bundler', `is required: app.launch "${launch}" loads the app from a bundler, and ${String(metro.length)} services have type metro; name one in app.bundler`));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return problems;
|
|
62
|
+
}
|
|
63
|
+
function webProblems(raw, services) {
|
|
64
|
+
if (!raw.web)
|
|
65
|
+
return [];
|
|
66
|
+
const named = raw.web.service;
|
|
67
|
+
const serving = services.find(([name, s]) => (named === undefined ? s.type === 'web' : name === named));
|
|
68
|
+
if (serving?.[1].platforms && !serving[1].platforms.includes(WEB_PLATFORM)) {
|
|
69
|
+
return [problem(`/services/${serving[0]}/platforms`, `leaves out web, and ${serving[0]} serves the web app; add "web"`)];
|
|
70
|
+
}
|
|
71
|
+
if (named !== undefined) {
|
|
72
|
+
return services.some(([name]) => name === named)
|
|
73
|
+
? []
|
|
74
|
+
: [problem('/web/service', `names no service; the services are: ${services.map(([n]) => n).join(', ') || 'none'}`)];
|
|
75
|
+
}
|
|
76
|
+
const web = services.filter(([, s]) => s.type === 'web');
|
|
77
|
+
return web.length === 1
|
|
78
|
+
? []
|
|
79
|
+
: [
|
|
80
|
+
problem('/web/service', `is required: ${String(web.length)} services have type web, and the web app is served by one; name it in web.service`),
|
|
81
|
+
];
|
|
82
|
+
}
|
|
83
|
+
function browserProblems(raw) {
|
|
84
|
+
const browser = raw.web?.browser;
|
|
85
|
+
if (browser?.driver !== 'agent-browser' || browser.headed !== true)
|
|
86
|
+
return [];
|
|
87
|
+
return [
|
|
88
|
+
problem('/web/browser/headed', `can't be true with driver agent-browser: agent-browser ${AGENT_BROWSER_RELEASE.version} runs a window only on full Chrome, which it can't start on the lane's own debugging port; use driver playwright to watch the browser`),
|
|
89
|
+
];
|
|
90
|
+
}
|
|
91
|
+
function resourceProblems(raw) {
|
|
92
|
+
const problems = [];
|
|
93
|
+
const exporter = new Map();
|
|
94
|
+
for (const [name, resource] of Object.entries(raw.resources ?? {})) {
|
|
95
|
+
(resource.exports ?? []).forEach((variable, i) => {
|
|
96
|
+
const at = `/resources/${name}/exports/${String(i)}`;
|
|
97
|
+
if (variable.startsWith(`${ENV_PREFIX}_`) || RESERVED_EXPORTS.has(variable)) {
|
|
98
|
+
problems.push(problem(at, `${variable} is set by ${TOOL} itself; export it under another name`));
|
|
99
|
+
}
|
|
100
|
+
const first = exporter.get(variable);
|
|
101
|
+
if (first !== undefined)
|
|
102
|
+
problems.push(problem(at, `${variable} is exported by resource ${first} too; export it from one`));
|
|
103
|
+
else
|
|
104
|
+
exporter.set(variable, name);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
return problems;
|
|
108
|
+
}
|
|
109
|
+
function crossFieldProblems(raw) {
|
|
110
|
+
const services = Object.entries(raw.services ?? {});
|
|
111
|
+
const problems = [];
|
|
112
|
+
if (!raw.app && !raw.web) {
|
|
113
|
+
problems.push(problem('', 'declares no app: add app (a mobile app), web (a web app), or both'));
|
|
114
|
+
}
|
|
115
|
+
problems.push(...appProblems(raw, services), ...webProblems(raw, services), ...browserProblems(raw), ...resourceProblems(raw));
|
|
116
|
+
for (const [name, service] of services) {
|
|
117
|
+
if (BROWSER_SERVICES.includes(name)) {
|
|
118
|
+
problems.push(problem(`/services/${name}`, `${name} is the name of the lane's browser ports; name the service otherwise`));
|
|
119
|
+
}
|
|
120
|
+
const builtIn = BUILT_IN_SERVICE_TYPES.includes(service.type);
|
|
121
|
+
if (builtIn && service.ports !== undefined) {
|
|
122
|
+
problems.push(problem(`/services/${name}/ports`, `is not allowed for type ${service.type}, which uses the Mac's ${service.type} block`));
|
|
123
|
+
}
|
|
124
|
+
if (!builtIn && service.ports === undefined) {
|
|
125
|
+
problems.push(problem(`/services/${name}/ports`, `is required for type ${service.type}, which has no built-in port block`));
|
|
126
|
+
}
|
|
127
|
+
if (service.ports && service.ports[0] > service.ports[1]) {
|
|
128
|
+
problems.push(problem(`/services/${name}/ports`, 'must be [first, last] with first <= last'));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return problems;
|
|
132
|
+
}
|
|
133
|
+
function normalize(raw, file) {
|
|
134
|
+
const dir = path.dirname(file);
|
|
135
|
+
const services = Object.entries(raw.services ?? {}).map(([name, s]) => {
|
|
136
|
+
const host = s.ready.host ?? DEFAULT_READY_HOST;
|
|
137
|
+
return {
|
|
138
|
+
name,
|
|
139
|
+
type: s.type,
|
|
140
|
+
ports: s.ports ?? null,
|
|
141
|
+
start: s.start,
|
|
142
|
+
cwd: path.resolve(dir, s.cwd ?? '.'),
|
|
143
|
+
ready: s.ready.kind === 'http'
|
|
144
|
+
? { kind: 'http', host, path: s.ready.path, status: s.ready.status ?? 200, body: s.ready.body ?? null }
|
|
145
|
+
: { kind: 'tcp', host },
|
|
146
|
+
timeoutMs: (s.timeoutSeconds ?? DEFAULT_READY_SECONDS) * 1000,
|
|
147
|
+
dial: s.dial ? { argument: s.dial.argument, value: s.dial.value ?? DEFAULT_DIAL_VALUE } : null,
|
|
148
|
+
platforms: s.platforms ?? null,
|
|
149
|
+
};
|
|
150
|
+
});
|
|
151
|
+
const { app } = raw;
|
|
152
|
+
const baseApp = app
|
|
153
|
+
? {
|
|
154
|
+
platform: app.platform,
|
|
155
|
+
bundleId: app.bundleId,
|
|
156
|
+
scheme: app.scheme ?? null,
|
|
157
|
+
launch: app.launch,
|
|
158
|
+
bundler: app.bundler ?? services.find(s => s.type === 'metro')?.name ?? null,
|
|
159
|
+
variant: app.variant ?? DEFAULT_VARIANT,
|
|
160
|
+
output: app.output ?? null,
|
|
161
|
+
device: deviceOf(app.device),
|
|
162
|
+
}
|
|
163
|
+
: null;
|
|
164
|
+
const platformApps = {};
|
|
165
|
+
if (app?.ios)
|
|
166
|
+
platformApps.ios = app.ios;
|
|
167
|
+
if (app?.android)
|
|
168
|
+
platformApps.android = app.android;
|
|
169
|
+
const web = raw.web
|
|
170
|
+
? {
|
|
171
|
+
service: raw.web.service ?? services.find(s => s.type === 'web')?.name ?? '',
|
|
172
|
+
path: raw.web.path ?? DEFAULT_WEB_PATH,
|
|
173
|
+
browser: {
|
|
174
|
+
driver: raw.web.browser?.driver ?? DEFAULT_BROWSER_DRIVER,
|
|
175
|
+
headed: raw.web.browser?.headed ?? false,
|
|
176
|
+
},
|
|
177
|
+
}
|
|
178
|
+
: null;
|
|
179
|
+
const platform = baseApp?.platform ?? WEB_PLATFORM;
|
|
180
|
+
return {
|
|
181
|
+
file,
|
|
182
|
+
dir,
|
|
183
|
+
platform,
|
|
184
|
+
app: baseApp && resolveApp(baseApp, platformApps, baseApp.platform),
|
|
185
|
+
platformApps,
|
|
186
|
+
baseApp,
|
|
187
|
+
web,
|
|
188
|
+
services: servicesFor(services, platform),
|
|
189
|
+
allServices: services,
|
|
190
|
+
resources: Object.entries(raw.resources ?? {}).map(([name, r]) => ({
|
|
191
|
+
name,
|
|
192
|
+
create: r.create,
|
|
193
|
+
exports: r.exports ?? [],
|
|
194
|
+
teardown: r.teardown,
|
|
195
|
+
cwd: path.resolve(dir, r.cwd ?? '.'),
|
|
196
|
+
teardownTimeoutMs: (r.teardownTimeoutSeconds ?? DEFAULT_TEARDOWN_SECONDS) * 1000,
|
|
197
|
+
})),
|
|
198
|
+
hooks: { ...raw.hooks },
|
|
199
|
+
preconditions: (raw.preconditions ?? []).map(p => ({
|
|
200
|
+
name: p.name,
|
|
201
|
+
run: p.run,
|
|
202
|
+
fix: p.fix,
|
|
203
|
+
before: p.before ?? 'claim',
|
|
204
|
+
platforms: p.platforms ?? null,
|
|
205
|
+
})),
|
|
206
|
+
hygiene: { ...raw.hygiene },
|
|
207
|
+
buildCache: raw.buildCache === undefined ? null : parseBuildCacheConfig(raw.buildCache),
|
|
208
|
+
driver: raw.driver ? { flows: raw.driver.flows ?? null } : null,
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
function deviceOf(raw) {
|
|
212
|
+
const device = {};
|
|
213
|
+
if (raw?.type !== undefined)
|
|
214
|
+
device.type = raw.type;
|
|
215
|
+
if (raw?.runtime !== undefined)
|
|
216
|
+
device.runtime = raw.runtime;
|
|
217
|
+
if (raw?.strict !== undefined)
|
|
218
|
+
device.strict = raw.strict;
|
|
219
|
+
return device;
|
|
220
|
+
}
|
|
221
|
+
function resolveApp(base, platformApps, platform) {
|
|
222
|
+
const own = platformApps[platform];
|
|
223
|
+
return {
|
|
224
|
+
...base,
|
|
225
|
+
platform,
|
|
226
|
+
bundleId: own?.bundleId ?? base.bundleId,
|
|
227
|
+
output: own?.output ?? base.output,
|
|
228
|
+
device: own?.device ? deviceOf(own.device) : base.device,
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
export function servicesFor(services, platform) {
|
|
232
|
+
return services.filter(s => s.platforms === null || s.platforms.includes(platform));
|
|
233
|
+
}
|
|
234
|
+
export function declaredPlatforms(config) {
|
|
235
|
+
const mobile = config.baseApp ? ['ios', 'android'] : [];
|
|
236
|
+
return config.web ? [...mobile, WEB_PLATFORM] : mobile;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* The config as `up` sees it for one platform: app.ios or app.android replace the app's fields they name. A platform
|
|
240
|
+
* the config declares no app for is refused.
|
|
241
|
+
*/
|
|
242
|
+
export function forPlatform(config, platform) {
|
|
243
|
+
if (platform === WEB_PLATFORM) {
|
|
244
|
+
if (!config.web) {
|
|
245
|
+
throw new UsageError(`${config.file} declares no web app`, `add a web block naming the service that serves it, or run ${CLI} up --platform ${config.baseApp?.platform ?? 'ios'}`);
|
|
246
|
+
}
|
|
247
|
+
return { ...config, platform, app: null, services: servicesFor(config.allServices, platform) };
|
|
248
|
+
}
|
|
249
|
+
if (!config.baseApp) {
|
|
250
|
+
throw new UsageError(`${config.file} declares no mobile app, only a web app`, `run ${CLI} up --platform ${WEB_PLATFORM}, or add an app block for ${platform}`);
|
|
251
|
+
}
|
|
252
|
+
const services = servicesFor(config.allServices, platform);
|
|
253
|
+
const { bundler } = config.baseApp;
|
|
254
|
+
if (bundler !== null && !services.some(s => s.name === bundler)) {
|
|
255
|
+
throw new UsageError(`the app loads its JavaScript from ${bundler}, and ${bundler}'s platforms in ${config.file} leave out ${platform}`, `add "${platform}" to services.${bundler}.platforms, or run ${CLI} up --platform ${config.baseApp.platform}`);
|
|
256
|
+
}
|
|
257
|
+
return { ...config, platform, app: resolveApp(config.baseApp, config.platformApps, platform), services };
|
|
258
|
+
}
|
|
259
|
+
/** The config a lane was brought up with: for its platform, while the config still declares that platform. */
|
|
260
|
+
export function loadLaneConfig(file, platform) {
|
|
261
|
+
const loaded = loadProjectConfig(file);
|
|
262
|
+
return platform !== undefined && declaredPlatforms(loaded).includes(platform) ? forPlatform(loaded, platform) : loaded;
|
|
263
|
+
}
|
|
264
|
+
export function parseProjectConfig(raw, file) {
|
|
265
|
+
const problems = validator.validate(raw);
|
|
266
|
+
if (problems.length > 0)
|
|
267
|
+
throw new ProjectConfigError(file, problems);
|
|
268
|
+
const typed = raw;
|
|
269
|
+
const crossField = crossFieldProblems(typed);
|
|
270
|
+
if (crossField.length > 0)
|
|
271
|
+
throw new ProjectConfigError(file, crossField);
|
|
272
|
+
return normalize(typed, file);
|
|
273
|
+
}
|
|
274
|
+
export function loadProjectConfig(file) {
|
|
275
|
+
if (path.basename(file) === FORMER.configFile)
|
|
276
|
+
throw formerConfigError(file);
|
|
277
|
+
const text = fs.readFileSync(file, 'utf8');
|
|
278
|
+
let raw;
|
|
279
|
+
try {
|
|
280
|
+
raw = JSON.parse(text);
|
|
281
|
+
}
|
|
282
|
+
catch (error) {
|
|
283
|
+
throw new ProjectConfigError(file, [{ path: '', schemaPath: '(JSON syntax)', message: error.message }]);
|
|
284
|
+
}
|
|
285
|
+
return parseProjectConfig(raw, file);
|
|
286
|
+
}
|
|
287
|
+
function gitTop(dir) {
|
|
288
|
+
const result = spawnSync('git', ['-C', dir, 'rev-parse', '--show-toplevel'], { encoding: 'utf8' });
|
|
289
|
+
return result.status === 0 ? fs.realpathSync(result.stdout.trim()) : null;
|
|
290
|
+
}
|
|
291
|
+
/** The nearest config at or above `start`, under this version's name or 0.2.x's, within the git worktree. */
|
|
292
|
+
export function findConfigFile(start) {
|
|
293
|
+
let dir = fs.realpathSync(start);
|
|
294
|
+
const stop = gitTop(dir);
|
|
295
|
+
for (;;) {
|
|
296
|
+
for (const name of [CONFIG_FILE, FORMER.configFile]) {
|
|
297
|
+
const candidate = path.join(dir, name);
|
|
298
|
+
if (fs.existsSync(candidate))
|
|
299
|
+
return candidate;
|
|
300
|
+
}
|
|
301
|
+
const parent = path.dirname(dir);
|
|
302
|
+
if (dir === stop || parent === dir)
|
|
303
|
+
return null;
|
|
304
|
+
dir = parent;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
export function formerConfigError(file) {
|
|
308
|
+
return new UsageError(`${file} is a 0.2.x config; ${TOOL} reads ${CONFIG_FILE}`, `rename it to ${CONFIG_FILE}, point its "$schema" at ${SCHEMA_FILE}, and rename the ${FORMER.envPrefix}_ variables in it and in the scripts it runs to ${ENV_PREFIX}_ (${FORMER.envPrefix}_CLAIM is ${ENV_PREFIX}_LANE now); the CHANGELOG's 0.3.0 section lists every rename`);
|
|
309
|
+
}
|
|
310
|
+
/** The nearest config at or above `start`; 0.2.x's config there is refused with the renames it needs. */
|
|
311
|
+
export function findProjectConfig(start) {
|
|
312
|
+
const found = findConfigFile(start);
|
|
313
|
+
if (found !== null && path.basename(found) === FORMER.configFile)
|
|
314
|
+
throw formerConfigError(found);
|
|
315
|
+
return found;
|
|
316
|
+
}
|