@buffcore/cli 0.8.46 → 0.8.47
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 +56 -0
- package/dist/commands/change-merge-remove.d.ts +9 -2
- package/dist/commands/change-merge-remove.js +27 -15
- package/dist/commands/design/check.d.ts +1 -1
- package/dist/commands/design/check.js +2 -1
- package/dist/commands/design/contract-size.d.ts +7 -0
- package/dist/commands/design/contract-size.js +47 -0
- package/dist/commands/design/tells.en.d.ts +2 -0
- package/dist/commands/design/tells.en.js +2 -0
- package/dist/commands/design/tells.es.js +2 -0
- package/dist/commands/extension/places-approval.d.ts +4 -0
- package/dist/commands/process-paths.d.ts +14 -0
- package/dist/commands/process-paths.js +90 -0
- package/dist/commands/prototype/ai-approval.d.ts +27 -0
- package/dist/commands/prototype/ai-approval.js +60 -0
- package/dist/commands/prototype/approver.d.ts +71 -0
- package/dist/commands/prototype/approver.js +168 -0
- package/dist/commands/prototype/critique-gate.d.ts +14 -0
- package/dist/commands/prototype/critique-gate.js +48 -0
- package/dist/commands/prototype/fence.d.ts +1 -0
- package/dist/commands/prototype/fence.js +12 -0
- package/dist/commands/prototype/final-approval-grant.js +18 -0
- package/dist/commands/prototype/final-approval.js +4 -1
- package/dist/commands/prototype/index.js +3 -0
- package/dist/commands/prototype/layout-hints.d.ts +34 -0
- package/dist/commands/prototype/layout-hints.js +194 -0
- package/dist/commands/prototype/layout-measure.d.ts +39 -0
- package/dist/commands/prototype/layout-measure.js +97 -0
- package/dist/commands/prototype/layout-words.d.ts +2 -0
- package/dist/commands/prototype/layout-words.js +11 -0
- package/dist/commands/prototype/layout.en.d.ts +6 -0
- package/dist/commands/prototype/layout.en.js +7 -0
- package/dist/commands/prototype/load-location.js +2 -3
- package/dist/commands/prototype/messages.en.d.ts +14 -0
- package/dist/commands/prototype/messages.en.js +15 -1
- package/dist/commands/prototype/messages.js +15 -1
- package/dist/commands/prototype/milestone-versions.d.ts +4 -0
- package/dist/commands/prototype/prune-command.d.ts +5 -0
- package/dist/commands/prototype/prune-command.js +25 -0
- package/dist/commands/prototype/prune-words.d.ts +1 -0
- package/dist/commands/prototype/prune-words.js +7 -0
- package/dist/commands/prototype/prune.d.ts +16 -0
- package/dist/commands/prototype/prune.en.d.ts +9 -0
- package/dist/commands/prototype/prune.en.js +9 -0
- package/dist/commands/prototype/prune.es.d.ts +2 -0
- package/dist/commands/prototype/prune.es.js +9 -0
- package/dist/commands/prototype/prune.js +140 -0
- package/dist/commands/prototype/reopen-messages.d.ts +9 -0
- package/dist/commands/prototype/reopen-messages.js +19 -0
- package/dist/commands/prototype/report.d.ts +14 -0
- package/dist/commands/prototype/report.js +5 -1
- package/dist/commands/prototype/scene-layout.d.ts +17 -0
- package/dist/commands/prototype/scene-layout.js +57 -0
- package/dist/commands/prototype/scene-ready.js +8 -2
- package/dist/commands/prototype/scene.d.ts +15 -2
- package/dist/commands/prototype/scene.js +54 -42
- package/dist/commands/prototype/selector-answer.d.ts +43 -0
- package/dist/commands/prototype/selector-answer.js +73 -0
- package/dist/commands/prototype/selector-misses.d.ts +19 -0
- package/dist/commands/prototype/selector-misses.js +78 -0
- package/dist/commands/prototype/selector-prompt.d.ts +23 -0
- package/dist/commands/prototype/selector-prompt.js +32 -0
- package/dist/commands/prototype/selector-run.d.ts +13 -0
- package/dist/commands/prototype/selector-run.js +113 -0
- package/dist/commands/prototype/selector.d.ts +54 -0
- package/dist/commands/prototype/selector.js +96 -0
- package/dist/commands/prototype/snapshot-ancestor.js +2 -0
- package/dist/commands/prototype/snapshot-bundle.d.ts +17 -3
- package/dist/commands/prototype/snapshot-bundle.js +69 -7
- package/dist/commands/prototype/snapshot-check-files.d.ts +2 -0
- package/dist/commands/prototype/snapshot-check-files.js +41 -0
- package/dist/commands/prototype/snapshot-command.d.ts +2 -0
- package/dist/commands/prototype/snapshot-command.js +3 -0
- package/dist/commands/prototype/snapshot-completion.d.ts +4 -0
- package/dist/commands/prototype/snapshot-completion.js +30 -2
- package/dist/commands/prototype/snapshot-dependencies.d.ts +23 -2
- package/dist/commands/prototype/snapshot-dependencies.js +120 -14
- package/dist/commands/prototype/snapshot-hashes.d.ts +7 -0
- package/dist/commands/prototype/snapshot-hashes.js +28 -0
- package/dist/commands/prototype/snapshot-inputs.d.ts +15 -6
- package/dist/commands/prototype/snapshot-inputs.js +140 -197
- package/dist/commands/prototype/snapshot-matrix.d.ts +58 -0
- package/dist/commands/prototype/snapshot-matrix.js +95 -0
- package/dist/commands/prototype/snapshot-metro-inputs.d.ts +8 -0
- package/dist/commands/prototype/snapshot-metro-inputs.js +81 -0
- package/dist/commands/prototype/snapshot-owners.d.ts +6 -2
- package/dist/commands/prototype/snapshot-owners.js +12 -3
- package/dist/commands/prototype/snapshot-progress-entry.d.ts +14 -0
- package/dist/commands/prototype/snapshot-progress-entry.js +85 -0
- package/dist/commands/prototype/snapshot-progress.d.ts +19 -2
- package/dist/commands/prototype/snapshot-progress.js +54 -102
- package/dist/commands/prototype/snapshot-registry.d.ts +14 -0
- package/dist/commands/prototype/snapshot-registry.js +121 -0
- package/dist/commands/prototype/snapshot-report.d.ts +4 -0
- package/dist/commands/prototype/snapshot-report.js +77 -12
- package/dist/commands/prototype/snapshot-requests.d.ts +13 -3
- package/dist/commands/prototype/snapshot-requests.js +68 -30
- package/dist/commands/prototype/snapshot-reuse.d.ts +6 -1
- package/dist/commands/prototype/snapshot-reuse.js +17 -7
- package/dist/commands/prototype/snapshot-scene-inputs.d.ts +30 -0
- package/dist/commands/prototype/snapshot-scene-inputs.js +210 -0
- package/dist/commands/prototype/snapshot-served-inputs.d.ts +3 -0
- package/dist/commands/prototype/snapshot-served-inputs.js +12 -0
- package/dist/commands/prototype/snapshot-server-record.d.ts +26 -0
- package/dist/commands/prototype/snapshot-server-record.js +135 -0
- package/dist/commands/prototype/snapshot-servers.d.ts +3 -1
- package/dist/commands/prototype/snapshot-servers.js +50 -2
- package/dist/commands/prototype/snapshot-setup.d.ts +3 -1
- package/dist/commands/prototype/snapshot-setup.js +2 -1
- package/dist/commands/prototype/snapshot-surface-inputs.d.ts +23 -0
- package/dist/commands/prototype/snapshot-surface-inputs.js +161 -0
- package/dist/commands/prototype/snapshot-vite-inputs.d.ts +22 -0
- package/dist/commands/prototype/snapshot-vite-inputs.js +209 -0
- package/dist/commands/prototype/snapshot.d.ts +5 -0
- package/dist/commands/prototype/snapshot.js +72 -10
- package/dist/commands/prototype/version-commands.d.ts +4 -0
- package/dist/commands/prototype/version-commands.js +36 -8
- package/dist/commands/prototype/versions.d.ts +28 -2
- package/dist/commands/prototype/versions.js +25 -1
- package/dist/commands/prototype/vite-fs-path.d.ts +4 -0
- package/dist/commands/prototype/vite-fs-path.js +15 -0
- package/dist/commands/remove-links.d.ts +6 -0
- package/dist/commands/remove-links.js +17 -0
- package/dist/commands/size-docs.d.ts +9 -0
- package/dist/commands/size-docs.en.d.ts +6 -0
- package/dist/commands/size-docs.en.js +6 -0
- package/dist/commands/size-docs.es.d.ts +2 -0
- package/dist/commands/size-docs.es.js +6 -0
- package/dist/commands/size-docs.js +28 -0
- package/dist/commands/size.d.ts +5 -2
- package/dist/commands/size.js +27 -9
- package/dist/commands/ui/approval-authority.d.ts +10 -2
- package/dist/commands/ui/approval-authority.js +1 -0
- package/dist/commands/ui/autopilot-ai-approve.d.ts +18 -0
- package/dist/commands/ui/autopilot-ai-approve.js +68 -0
- package/dist/commands/ui/autopilot-loop.js +5 -6
- package/dist/commands/ui/autopilot-merge.js +3 -0
- package/dist/commands/ui/autopilot.en.d.ts +23 -0
- package/dist/commands/ui/autopilot.en.js +23 -0
- package/dist/commands/ui/autopilot.es.d.ts +23 -0
- package/dist/commands/ui/autopilot.es.js +23 -0
- package/dist/commands/ui/chat/find.d.ts +2 -0
- package/dist/commands/ui/chat/find.js +13 -0
- package/dist/commands/ui/chat/fresh-codex.d.ts +39 -0
- package/dist/commands/ui/chat/fresh-codex.js +175 -0
- package/dist/commands/ui/chat/fresh-critique.js +13 -5
- package/dist/commands/ui/chat/fresh-launch.d.ts +19 -0
- package/dist/commands/ui/chat/fresh-launch.js +67 -11
- package/dist/commands/ui/chat/fresh-prompts.d.ts +2 -0
- package/dist/commands/ui/chat/fresh-prompts.js +2 -0
- package/dist/commands/ui/chat/fresh-secrets.d.ts +6 -0
- package/dist/commands/ui/chat/fresh-secrets.js +172 -0
- package/dist/commands/ui/chat/fresh.en.d.ts +1 -0
- package/dist/commands/ui/chat/fresh.en.js +2 -1
- package/dist/commands/ui/chat/fresh.es.d.ts +1 -0
- package/dist/commands/ui/chat/fresh.es.js +2 -1
- package/dist/commands/ui/chat/worktree.js +25 -5
- package/dist/commands/ui/index.js +3 -0
- package/dist/commands/ui/loop-approve.d.ts +30 -1
- package/dist/commands/ui/loop-approve.js +2 -2
- package/dist/commands/ui/merge-route.js +3 -0
- package/dist/commands/ui/places-change.d.ts +4 -0
- package/dist/commands/ui/prototype-main.d.ts +4 -0
- package/dist/commands/ui/reopen-route.d.ts +117 -0
- package/dist/commands/ui/reopen-route.js +97 -0
- package/dist/commands/ui/save-route.d.ts +2 -0
- package/dist/commands/ui/save-route.js +4 -0
- package/dist/commands/ui/studio-routes.js +2 -0
- package/dist/commands/ui/studio-state.d.ts +33 -0
- package/dist/commands/ui/studio-versions.d.ts +24 -0
- package/dist/commands/ui/worktrees.d.ts +1 -1
- package/dist/commands/ui/worktrees.js +19 -3
- package/dist/commands/worktree-sweep.d.ts +45 -0
- package/dist/commands/worktree-sweep.js +188 -0
- package/dist/commands/worktrees-command.d.ts +32 -0
- package/dist/commands/worktrees-command.en.d.ts +25 -0
- package/dist/commands/worktrees-command.en.js +55 -0
- package/dist/commands/worktrees-command.js +96 -0
- package/dist/main.js +2 -0
- package/dist/ui/page.js +82 -82
- package/docs/PROTOTYPE.md +6 -3
- package/docs/WORKBENCH.md +11 -6
- package/package.json +11 -11
- package/skills/ape-critique/SKILL.md +41 -6
- package/skills/ape-design-system/SKILL.md +3 -0
- package/skills/ape-plan-change/SKILL.md +6 -0
- package/skills/ape-prototype/SKILL.md +8 -4
|
@@ -14,8 +14,12 @@ import { t } from './messages.js';
|
|
|
14
14
|
import { portOwner, systemOwners } from './snapshot-owners.js';
|
|
15
15
|
import { serverDown } from './snapshot-recovery.js';
|
|
16
16
|
import { SnapshotAccessRefused, SnapshotRefused } from './snapshot-refused.js';
|
|
17
|
+
import { forgetServers, processTable, reapServers, recordServers, serverTrees, } from './snapshot-server-record.js';
|
|
18
|
+
import { gitFolders } from './snapshot-slots.js';
|
|
17
19
|
/** A cold Metro start is the slow one. */
|
|
18
20
|
const READY_MS = 180_000;
|
|
21
|
+
/** How often the servers' trees are recorded again while they start. */
|
|
22
|
+
const STARTING_MS = 2_000;
|
|
19
23
|
const LOOPBACK = '127.0.0.1';
|
|
20
24
|
const portFailure = (error) => accessDenied(error)
|
|
21
25
|
? new SnapshotAccessRefused('prototype.portAccess')
|
|
@@ -72,7 +76,31 @@ function installFiles(root) {
|
|
|
72
76
|
}
|
|
73
77
|
}
|
|
74
78
|
const bytes = (files) => files.map((file) => readFileSync(file).toString('base64'));
|
|
75
|
-
|
|
79
|
+
/** The record beside the worktree's lock, or none outside Git. */
|
|
80
|
+
function recordFile(root) {
|
|
81
|
+
try {
|
|
82
|
+
return join(gitFolders(root).worktree, 'ape-snapshot-servers.json');
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
export function snapshotServers(root, environment, urls, { owners = systemOwners, listen, readyMs = READY_MS, record = recordFile(root), } = {}) {
|
|
89
|
+
let beat;
|
|
90
|
+
// Each server's whole tree, written again with the heartbeat: a hard kill cannot stop them.
|
|
91
|
+
// One write at a time, in order: an older process table never replaces a newer one.
|
|
92
|
+
let recording = Promise.resolve();
|
|
93
|
+
let stopped = false;
|
|
94
|
+
const write = async () => {
|
|
95
|
+
if (!record || stopped)
|
|
96
|
+
return;
|
|
97
|
+
const roots = [...children.values()].flatMap((child) => (child.pid ? [child.pid] : []));
|
|
98
|
+
const table = await processTable().catch(() => undefined);
|
|
99
|
+
// Once stopped, the record is forgotten and stays so.
|
|
100
|
+
if (table && !stopped)
|
|
101
|
+
recordServers(record, serverTrees(table, roots));
|
|
102
|
+
};
|
|
103
|
+
const remember = () => (recording = recording.then(write, write));
|
|
76
104
|
const children = new Map();
|
|
77
105
|
const exits = new Map();
|
|
78
106
|
let api;
|
|
@@ -90,6 +118,9 @@ export function snapshotServers(root, environment, urls, { owners = systemOwners
|
|
|
90
118
|
return serverDown(scene, server, { root, serverExit: (name) => exits.get(name) });
|
|
91
119
|
};
|
|
92
120
|
async function begin() {
|
|
121
|
+
// The worktree's lock is held: what an earlier run recorded is left over from a hard kill.
|
|
122
|
+
if (record)
|
|
123
|
+
await reapServers(record, root).catch(() => { });
|
|
93
124
|
installFilesRead = installFiles(root);
|
|
94
125
|
installed = bytes(installFilesRead);
|
|
95
126
|
api = await standIn();
|
|
@@ -170,7 +201,20 @@ export function snapshotServers(root, environment, urls, { owners = systemOwners
|
|
|
170
201
|
const need = SURFACES.filter((surface) => !children.has(surface) && uiFolder(root, surface));
|
|
171
202
|
for (const surface of need)
|
|
172
203
|
launch(surface);
|
|
173
|
-
|
|
204
|
+
// Recorded at once and every few seconds while they start (a kill during a cold start leaves
|
|
205
|
+
// them too; a shell's children may not exist yet at once), then again when ready.
|
|
206
|
+
await remember().catch(() => { });
|
|
207
|
+
beat ??= setInterval(() => void remember().catch(() => { }), 60_000);
|
|
208
|
+
beat.unref();
|
|
209
|
+
const starting = setInterval(() => void remember().catch(() => { }), STARTING_MS);
|
|
210
|
+
starting.unref();
|
|
211
|
+
try {
|
|
212
|
+
await Promise.all(need.map(ready));
|
|
213
|
+
}
|
|
214
|
+
finally {
|
|
215
|
+
clearInterval(starting);
|
|
216
|
+
}
|
|
217
|
+
await remember().catch(() => { });
|
|
174
218
|
},
|
|
175
219
|
check() {
|
|
176
220
|
for (const server of children.keys())
|
|
@@ -188,9 +232,13 @@ export function snapshotServers(root, environment, urls, { owners = systemOwners
|
|
|
188
232
|
kill,
|
|
189
233
|
exit: (server) => exits.get(server),
|
|
190
234
|
async stop() {
|
|
235
|
+
stopped = true;
|
|
191
236
|
process.removeListener('exit', kill);
|
|
237
|
+
clearInterval(beat);
|
|
192
238
|
for (const child of children.values())
|
|
193
239
|
stopTree(child, process.platform !== 'win32');
|
|
240
|
+
if (record)
|
|
241
|
+
forgetServers(record);
|
|
194
242
|
await api?.close();
|
|
195
243
|
},
|
|
196
244
|
};
|
|
@@ -16,6 +16,8 @@ export interface SetupFlags {
|
|
|
16
16
|
sceneTimeout?: number;
|
|
17
17
|
remake?: boolean;
|
|
18
18
|
pages?: number;
|
|
19
|
+
/** `--full`: the full matrix. */
|
|
20
|
+
full?: boolean;
|
|
19
21
|
}
|
|
20
22
|
export interface Setup {
|
|
21
23
|
root: string;
|
|
@@ -30,7 +32,7 @@ export interface Setup {
|
|
|
30
32
|
progress: SnapshotProgressSource | undefined;
|
|
31
33
|
urls: SnapshotOptions['urls'];
|
|
32
34
|
dir: string;
|
|
33
|
-
options: Pick<SnapshotOptions, 'scenes' | 'locales' | 'frames' | 'urls' | 'dir' | 'scene' | 'sceneTimeout' | 'root' | 'pages' | 'ownScenes'>;
|
|
35
|
+
options: Pick<SnapshotOptions, 'scenes' | 'locales' | 'frames' | 'urls' | 'dir' | 'scene' | 'sceneTimeout' | 'root' | 'pages' | 'full' | 'ownScenes'>;
|
|
34
36
|
seconds(): number;
|
|
35
37
|
}
|
|
36
38
|
export type Servers = {
|
|
@@ -73,7 +73,7 @@ export async function setup(flags, servers) {
|
|
|
73
73
|
const checkout = flags.remake ? undefined : pinSnapshotCheckout(root);
|
|
74
74
|
const [product, all] = await Promise.all([loadProduct(root), loadScenes(root)]);
|
|
75
75
|
const { comp, scenes } = runScenes(root, all, scene);
|
|
76
|
-
const progress =
|
|
76
|
+
const progress = comp ? undefined : checkout?.progress();
|
|
77
77
|
// A linked worktree's addresses are the run's own: they are filled in when its servers start.
|
|
78
78
|
const urls = own
|
|
79
79
|
? {}
|
|
@@ -120,6 +120,7 @@ export async function setup(flags, servers) {
|
|
|
120
120
|
sceneTimeout,
|
|
121
121
|
root,
|
|
122
122
|
pages: flags.pages,
|
|
123
|
+
full: flags.full,
|
|
123
124
|
ownScenes,
|
|
124
125
|
},
|
|
125
126
|
seconds: () => Math.round((performance.now() - started) / 1000),
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Surface } from '@buffcore/config';
|
|
2
|
+
import type { SurfaceEntry } from './snapshot-bundle.ts';
|
|
3
|
+
import type { snapshotDependencies } from './snapshot-dependencies.ts';
|
|
4
|
+
type Dependencies = ReturnType<typeof snapshotDependencies>;
|
|
5
|
+
/** A product inside a workspace uses the enclosing lockfile when it has none of its own. */
|
|
6
|
+
export declare function lockfile(root: string): string[];
|
|
7
|
+
export declare const publicEnvironment: (env: Record<string, string | undefined>) => [string, string | undefined][];
|
|
8
|
+
/** The design font a console request under its `_fonts/` path names, when the scene knows it. */
|
|
9
|
+
export declare function designFont(root: string, base: string, url: URL, assets: ReadonlySet<string>): string | undefined;
|
|
10
|
+
export declare function surfaceEntry(root: string, surface: Surface, dependencies: Dependencies): Promise<{
|
|
11
|
+
entry: SurfaceEntry;
|
|
12
|
+
settings: (string[][] | undefined)[];
|
|
13
|
+
assets: string[];
|
|
14
|
+
vite: {
|
|
15
|
+
runtime: Set<string>;
|
|
16
|
+
settings: string[][];
|
|
17
|
+
files: string[];
|
|
18
|
+
} | undefined;
|
|
19
|
+
metro: boolean;
|
|
20
|
+
document: string | undefined;
|
|
21
|
+
} | undefined>;
|
|
22
|
+
export declare function sharedSettings(root: string, dependencies: ReturnType<typeof snapshotDependencies>): Promise<[string[], string[][]]>;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { existsSync, readdirSync } from 'node:fs';
|
|
2
|
+
import { basename, dirname, join, relative } from 'node:path';
|
|
3
|
+
import { parseEnv } from 'node:util';
|
|
4
|
+
import { surfaceDir } from './export.js';
|
|
5
|
+
import { isStock } from './milestone-stock.js';
|
|
6
|
+
import { sceneCheckFiles } from './snapshot-check-files.js';
|
|
7
|
+
import { sha256 } from './snapshot-hashes.js';
|
|
8
|
+
import { expoRoutes, snapshotFiles } from './snapshot-report.js';
|
|
9
|
+
import { pageInputs, viteFiles } from './snapshot-vite-inputs.js';
|
|
10
|
+
const SURFACE_ROOTS = {
|
|
11
|
+
admin: ['src/main.tsx', 'src/prototype/index.tsx', 'src/setup.ts'],
|
|
12
|
+
app: [
|
|
13
|
+
'src/app/_scene.tsx',
|
|
14
|
+
'src/app/_scene.web.tsx',
|
|
15
|
+
'src/app/_layout.tsx',
|
|
16
|
+
'src/app/_layout.web.tsx',
|
|
17
|
+
'src/prototype/scene.tsx',
|
|
18
|
+
'src/fonts.ts',
|
|
19
|
+
'src/themes.ts',
|
|
20
|
+
],
|
|
21
|
+
};
|
|
22
|
+
const SHARED_ROOTS = [
|
|
23
|
+
'design/theme.ts',
|
|
24
|
+
'prototype/setup.ts',
|
|
25
|
+
'prototype/store.ts',
|
|
26
|
+
'prototype/store.tsx',
|
|
27
|
+
];
|
|
28
|
+
const SETTINGS = [
|
|
29
|
+
'package.json',
|
|
30
|
+
'tsconfig.json',
|
|
31
|
+
'jsconfig.json',
|
|
32
|
+
'app.json',
|
|
33
|
+
'index.html',
|
|
34
|
+
'.env',
|
|
35
|
+
'.env.local',
|
|
36
|
+
'.env.development',
|
|
37
|
+
'.env.development.local',
|
|
38
|
+
];
|
|
39
|
+
const existing = (dir, paths) => paths.map((path) => join(dir, path)).filter(existsSync);
|
|
40
|
+
const TOOLCHAINS = ['vite.config', 'metro.config', 'babel.config', 'postcss.config', 'app.config']
|
|
41
|
+
.flatMap((name) => ['ts', 'js', 'mts', 'mjs', 'cts', 'cjs'].map((ext) => `${name}.${ext}`))
|
|
42
|
+
.concat(['.babelrc', '.babelrc.json', '.postcssrc', '.postcssrc.json']);
|
|
43
|
+
// The in-repository dev configs use the same resolvers as the product templates.
|
|
44
|
+
const BUNDLED_TOOLCHAINS = {
|
|
45
|
+
'apps/admin/vite.config.ts': '0fe0ec6d310d92e37ab052f230ecb6b9ff7a19241061300eebf85920018a6638',
|
|
46
|
+
'apps/app/metro.config.js': 'd2261b4852313fdf42fa63d97d162c691cc89757df4de8ecdff1d8bac939b117',
|
|
47
|
+
'apps/app/babel.config.js': '51ba161016afa8ae07b41bb4305f1c6e71ff30d007e58fbebe0cf383bbce67c0',
|
|
48
|
+
};
|
|
49
|
+
/** esbuild can model the shipped surface configuration. A product loader may resolve differently. */
|
|
50
|
+
async function toolchains(dir, surface, read) {
|
|
51
|
+
try {
|
|
52
|
+
const files = existing(dir, TOOLCHAINS);
|
|
53
|
+
for (const file of files) {
|
|
54
|
+
const name = `apps/${surface}/${relative(dir, file)}`;
|
|
55
|
+
const text = (await read(file)).toString('utf8').replaceAll('\r\n', '\n');
|
|
56
|
+
if (!isStock(name, text) && BUNDLED_TOOLCHAINS[name] !== sha256(text))
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
return files;
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/** A product inside a workspace uses the enclosing lockfile when it has none of its own. */
|
|
66
|
+
export function lockfile(root) {
|
|
67
|
+
for (let dir = root;; dir = dirname(dir)) {
|
|
68
|
+
const files = existing(dir, ['pnpm-lock.yaml', 'package-lock.json', 'yarn.lock']);
|
|
69
|
+
if (files.length || dirname(dir) === dir)
|
|
70
|
+
return files;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
export const publicEnvironment = (env) => Object.entries(env)
|
|
74
|
+
.filter(([key]) => /^(VITE_|EXPO_PUBLIC_)/.test(key))
|
|
75
|
+
.sort();
|
|
76
|
+
async function settingHashes(root, files, dependencies) {
|
|
77
|
+
return Promise.all(files.map(async (file) => {
|
|
78
|
+
const name = relative(root, file);
|
|
79
|
+
if (!/^\.env(?:\.|$)/.test(basename(file)))
|
|
80
|
+
return [name, await dependencies.digest(file)];
|
|
81
|
+
await dependencies.digest(file);
|
|
82
|
+
const environment = publicEnvironment(parseEnv((await dependencies.read(file)).toString('utf8')));
|
|
83
|
+
if (environment.some(([, value]) => value?.includes('$')))
|
|
84
|
+
throw new Error();
|
|
85
|
+
return [name, sha256(JSON.stringify(environment))];
|
|
86
|
+
}));
|
|
87
|
+
}
|
|
88
|
+
/** The design system's font files the console serves under `_fonts/`, as its Vite plugin lists them. */
|
|
89
|
+
function designFonts(root) {
|
|
90
|
+
const dir = join(root, 'design', 'fonts');
|
|
91
|
+
try {
|
|
92
|
+
return readdirSync(dir, { withFileTypes: true })
|
|
93
|
+
.filter((entry) => entry.isFile() && /\.(?:woff2?|ttf|otf)$/i.test(entry.name))
|
|
94
|
+
.map((entry) => join(dir, entry.name))
|
|
95
|
+
.sort();
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
return [];
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/** The design font a console request under its `_fonts/` path names, when the scene knows it. */
|
|
102
|
+
export function designFont(root, base, url, assets) {
|
|
103
|
+
const path = decodeURIComponent(url.pathname);
|
|
104
|
+
if (url.search || !path.startsWith(base))
|
|
105
|
+
return;
|
|
106
|
+
const file = join(root, 'design', 'fonts', path.slice(base.length));
|
|
107
|
+
return assets.has(file) ? file : undefined;
|
|
108
|
+
}
|
|
109
|
+
export async function surfaceEntry(root, surface, dependencies) {
|
|
110
|
+
const dir = surfaceDir(root, surface);
|
|
111
|
+
const registry = dir && join(dir, 'src', 'prototype', 'views.ts');
|
|
112
|
+
if (!dir || !registry || !existsSync(registry))
|
|
113
|
+
return;
|
|
114
|
+
const configuration = await toolchains(dir, surface, dependencies.read);
|
|
115
|
+
if (!configuration)
|
|
116
|
+
return;
|
|
117
|
+
const page = await pageInputs(dir, dependencies.read).catch(() => undefined);
|
|
118
|
+
const routes = surface === 'app' ? await expoRoutes(dir).catch(() => undefined) : [];
|
|
119
|
+
const publicFiles = await snapshotFiles(join(dir, 'public')).catch(() => undefined);
|
|
120
|
+
if (!page || !routes || !publicFiles)
|
|
121
|
+
return;
|
|
122
|
+
const fonts = surface === 'admin' ? designFonts(root) : [];
|
|
123
|
+
const assets = [...new Set([...page.assets, ...publicFiles, ...fonts])];
|
|
124
|
+
const entry = {
|
|
125
|
+
surface,
|
|
126
|
+
dir,
|
|
127
|
+
registry,
|
|
128
|
+
routes,
|
|
129
|
+
roots: [
|
|
130
|
+
...new Set([
|
|
131
|
+
...existing(dir, SURFACE_ROOTS[surface]),
|
|
132
|
+
...existing(root, SHARED_ROOTS),
|
|
133
|
+
...page.roots,
|
|
134
|
+
]),
|
|
135
|
+
],
|
|
136
|
+
};
|
|
137
|
+
if (assets.some((file) => /^\.env(?:\.|$)/.test(basename(file))))
|
|
138
|
+
return;
|
|
139
|
+
const settings = await settingHashes(root, [...existing(dir, SETTINGS), ...configuration, ...assets], dependencies).catch(() => undefined);
|
|
140
|
+
const vite = surface === 'admin' && configuration.some((file) => basename(file) === 'vite.config.ts')
|
|
141
|
+
? await viteFiles(dir, dependencies).catch(() => undefined)
|
|
142
|
+
: undefined;
|
|
143
|
+
const metro = surface === 'app' &&
|
|
144
|
+
configuration.some((file) => /^metro\.config\./.test(basename(file))) &&
|
|
145
|
+
existsSync(join(dir, 'index.ts'));
|
|
146
|
+
if (settings) {
|
|
147
|
+
const index = join(dir, 'index.html');
|
|
148
|
+
const document = existsSync(index) ? await dependencies.digest(index) : undefined;
|
|
149
|
+
return { entry, settings: [settings, vite?.settings], assets, vite, metro, document };
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
export async function sharedSettings(root, dependencies) {
|
|
153
|
+
// The root `.env` is not a file input: `loadEnv` puts its values into the environment the
|
|
154
|
+
// fingerprint reads, so main (which has one) and a worktree (which has none) agree.
|
|
155
|
+
const settings = SETTINGS.filter((name) => !name.startsWith('.env'));
|
|
156
|
+
const files = [...existing(root, [...settings, 'buffcore.config.ts']), ...lockfile(root)];
|
|
157
|
+
return Promise.all([
|
|
158
|
+
Promise.all(sceneCheckFiles().map(dependencies.digest)),
|
|
159
|
+
settingHashes(root, files, dependencies),
|
|
160
|
+
]);
|
|
161
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Response } from 'playwright-core';
|
|
2
|
+
import { type snapshotDependencies } from './snapshot-dependencies.ts';
|
|
3
|
+
type Dependencies = ReturnType<typeof snapshotDependencies>;
|
|
4
|
+
export declare function pageInputs(dir: string, read: Dependencies['read']): Promise<{
|
|
5
|
+
assets: string[];
|
|
6
|
+
roots: string[];
|
|
7
|
+
}>;
|
|
8
|
+
export declare function surfaceFile(dir: string, url: URL, assets: ReadonlySet<string>): string | undefined;
|
|
9
|
+
export declare function viteFiles(dir: string, deps: Dependencies): Promise<{
|
|
10
|
+
runtime: Set<string>;
|
|
11
|
+
settings: string[][];
|
|
12
|
+
files: string[];
|
|
13
|
+
}>;
|
|
14
|
+
/** Bind the scripts that Vite actually serves, including the bytes of its generated output. */
|
|
15
|
+
export declare function viteRequests(dir: string, runtime: ReadonlySet<string>, modules: ReadonlySet<string>, assets: ReadonlySet<string>, runtimeFiles?: readonly string[], page?: URL): {
|
|
16
|
+
prepare(): Promise<void>;
|
|
17
|
+
proof: () => string | undefined;
|
|
18
|
+
same(): Promise<boolean>;
|
|
19
|
+
hash(force?: boolean): string | undefined;
|
|
20
|
+
tracks(url: URL, kind: string | undefined, response?: Response): boolean | Promise<boolean>;
|
|
21
|
+
};
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { existsSync, lstatSync, readFileSync, statSync } from 'node:fs';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import { basename, dirname, extname, join, relative, resolve } from 'node:path';
|
|
4
|
+
import { references } from './milestone-references.js';
|
|
5
|
+
import { loaders } from './snapshot-bundle.js';
|
|
6
|
+
import { pathIn } from './snapshot-dependencies.js';
|
|
7
|
+
import { sha256 } from './snapshot-hashes.js';
|
|
8
|
+
import { matchesBytes, servedBytes } from './snapshot-served-inputs.js';
|
|
9
|
+
import { viteFsFile, viteFsPath } from './vite-fs-path.js';
|
|
10
|
+
export async function pageInputs(dir, read) {
|
|
11
|
+
const page = join(dir, 'index.html');
|
|
12
|
+
const assets = [];
|
|
13
|
+
const roots = [];
|
|
14
|
+
if (!existsSync(page))
|
|
15
|
+
return { assets, roots };
|
|
16
|
+
const links = references('page', (await read(page)).toString('utf8'), page);
|
|
17
|
+
if (typeof links === 'string')
|
|
18
|
+
throw new Error();
|
|
19
|
+
for (const [kind, url] of links) {
|
|
20
|
+
if (/^(?:[\w+.-]+:|\/\/|#)/.test(url))
|
|
21
|
+
continue;
|
|
22
|
+
const name = decodeURIComponent(url.split(/[?#]/, 1)[0] ?? '').replace(/^\//, '');
|
|
23
|
+
const file = resolve(dir, name);
|
|
24
|
+
if (!pathIn(dir, file))
|
|
25
|
+
throw new Error();
|
|
26
|
+
const loader = loaders[extname(file).toLowerCase()];
|
|
27
|
+
const found = [file, join(dir, 'public', name)].filter(existsSync);
|
|
28
|
+
if (kind === 'page' && loader === 'file')
|
|
29
|
+
assets.push(...found);
|
|
30
|
+
else if (loader || kind === 'module') {
|
|
31
|
+
const [root] = found;
|
|
32
|
+
if (!root || found.length !== 1 || !loader)
|
|
33
|
+
throw new Error();
|
|
34
|
+
roots.push(root);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return { assets, roots };
|
|
38
|
+
}
|
|
39
|
+
export function surfaceFile(dir, url, assets) {
|
|
40
|
+
const path = decodeURIComponent(url.pathname);
|
|
41
|
+
// Vite marks JS asset imports and gives refreshed URLs a numeric cache stamp.
|
|
42
|
+
if (url.search && !/^\?(?:import(?:&t=\d+)?|t=\d+)$/.test(url.search))
|
|
43
|
+
return;
|
|
44
|
+
const outside = viteFsFile(path);
|
|
45
|
+
const files = outside
|
|
46
|
+
? [outside]
|
|
47
|
+
: [resolve(dir, `.${path}`), resolve(dir, 'public', `.${path}`)];
|
|
48
|
+
const found = files.filter((file) => assets.has(file));
|
|
49
|
+
return found.length === 1 ? found[0] : undefined;
|
|
50
|
+
}
|
|
51
|
+
export async function viteFiles(dir, deps) {
|
|
52
|
+
const require = createRequire(join(dir, 'package.json'));
|
|
53
|
+
const client = join(dirname(require.resolve('vite/package.json')), 'dist/client');
|
|
54
|
+
const react = require.resolve('@vitejs/plugin-react');
|
|
55
|
+
const runtime = {
|
|
56
|
+
'/@vite/client': join(client, 'client.mjs'),
|
|
57
|
+
'/@vite/env': join(client, 'env.mjs'),
|
|
58
|
+
'/@react-refresh': join(dirname(react), 'refresh-runtime.js'),
|
|
59
|
+
};
|
|
60
|
+
const settings = await Promise.all([...Object.values(runtime), require.resolve('vite'), react].map(async (file) => [
|
|
61
|
+
relative(dir, file),
|
|
62
|
+
await deps.digest(file),
|
|
63
|
+
]));
|
|
64
|
+
return {
|
|
65
|
+
runtime: new Set(Object.keys(runtime)),
|
|
66
|
+
settings,
|
|
67
|
+
files: [runtime['/@vite/env']],
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
const OPTIMIZED = '/node_modules/.vite/deps/';
|
|
71
|
+
const outputName = /^[a-zA-Z0-9_@.-]+\.js$/;
|
|
72
|
+
function readCache(folder, files) {
|
|
73
|
+
const metadata = readFileSync(join(folder, '_metadata.json'));
|
|
74
|
+
const data = JSON.parse(metadata.toString('utf8'));
|
|
75
|
+
if (!data.optimized || !data.chunks)
|
|
76
|
+
throw new Error();
|
|
77
|
+
const outputs = new Map();
|
|
78
|
+
const verified = new Set();
|
|
79
|
+
function add(entry) {
|
|
80
|
+
const name = entry.file;
|
|
81
|
+
if (typeof name !== 'string' || !outputName.test(name) || basename(name) !== name)
|
|
82
|
+
throw new Error();
|
|
83
|
+
const file = join(folder, name);
|
|
84
|
+
if (!lstatSync(file).isFile())
|
|
85
|
+
throw new Error();
|
|
86
|
+
outputs.set(name, sha256(readFileSync(file)));
|
|
87
|
+
return name;
|
|
88
|
+
}
|
|
89
|
+
for (const entry of Object.values(data.optimized)) {
|
|
90
|
+
const name = add(entry);
|
|
91
|
+
if (typeof entry.src === 'string' && files.has(resolve(folder, entry.src)))
|
|
92
|
+
verified.add(name);
|
|
93
|
+
}
|
|
94
|
+
for (const entry of Object.values(data.chunks))
|
|
95
|
+
verified.add(add(entry));
|
|
96
|
+
return {
|
|
97
|
+
outputs,
|
|
98
|
+
verified,
|
|
99
|
+
hash: sha256(JSON.stringify([sha256(metadata), [...outputs].sort()])),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/** Bind the scripts that Vite actually serves, including the bytes of its generated output. */
|
|
103
|
+
export function viteRequests(dir, runtime, modules, assets, runtimeFiles = [], page) {
|
|
104
|
+
const folder = join(dir, OPTIMIZED);
|
|
105
|
+
const paths = [...runtime, ...runtimeFiles.map(viteFsPath)];
|
|
106
|
+
async function readRuntime() {
|
|
107
|
+
if (!page)
|
|
108
|
+
return;
|
|
109
|
+
const html = await servedBytes(page, 'html', 15_000);
|
|
110
|
+
if (!html)
|
|
111
|
+
return;
|
|
112
|
+
const helpers = new Map();
|
|
113
|
+
let client;
|
|
114
|
+
let token;
|
|
115
|
+
await Promise.all(paths.map(async (path) => {
|
|
116
|
+
const script = await servedBytes(new URL(path, page), 'javascript', 15_000).catch(() => undefined);
|
|
117
|
+
if (!script)
|
|
118
|
+
return;
|
|
119
|
+
helpers.set(path, sha256(script));
|
|
120
|
+
if (path === '/@vite/client') {
|
|
121
|
+
client = script.toString('utf8');
|
|
122
|
+
token = /^const wsToken = "([\w-]+)";$/m.exec(client)?.[1];
|
|
123
|
+
}
|
|
124
|
+
}));
|
|
125
|
+
if (!token || !client || !helpers.has('/@react-refresh'))
|
|
126
|
+
return;
|
|
127
|
+
// Keep byte equality within a capture. Across runs, Vite's stamped entry and HMR
|
|
128
|
+
// connection values still name the same verified files and transport.
|
|
129
|
+
const stablePage = html
|
|
130
|
+
.toString('utf8')
|
|
131
|
+
.replace(/(<script type="module" src=")(\/[^"?]+)\?t=\d+("\s*><\/script>)/g, (tag, before, path, after) => surfaceFile(dir, new URL(path, page), modules) ? `${before}${path}${after}` : tag);
|
|
132
|
+
const stableClient = sha256(client
|
|
133
|
+
.replace(/^const wsToken = "[\w-]+";$/m, 'const wsToken = "";')
|
|
134
|
+
.replace(/^(const (?:serverHost|directSocketHost) = )"(?:localhost|127\.0\.0\.1|\[::1\]):\d+\/";$/gm, '$1"";')
|
|
135
|
+
.replace(/\n\/\/# sourceMappingURL=data:application\/json;base64,[\w+/=]+\s*$/, ''));
|
|
136
|
+
const stableHelpers = [...helpers].map(([path, digest]) => [
|
|
137
|
+
path,
|
|
138
|
+
path === '/@vite/client' ? stableClient : digest,
|
|
139
|
+
]);
|
|
140
|
+
return {
|
|
141
|
+
html: sha256(html),
|
|
142
|
+
helpers,
|
|
143
|
+
token,
|
|
144
|
+
actual: sha256(JSON.stringify([sha256(html), [...helpers].sort()])),
|
|
145
|
+
key: sha256(JSON.stringify([sha256(stablePage), stableHelpers.sort()])),
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
const safeRuntime = () => readRuntime().catch(() => undefined);
|
|
149
|
+
let reference;
|
|
150
|
+
const observed = new Map();
|
|
151
|
+
let stamp;
|
|
152
|
+
let cache;
|
|
153
|
+
function load(force = false) {
|
|
154
|
+
try {
|
|
155
|
+
const time = statSync(join(folder, '_metadata.json')).mtimeMs;
|
|
156
|
+
if (force || time !== stamp)
|
|
157
|
+
cache = readCache(folder, modules);
|
|
158
|
+
stamp = time;
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
stamp = undefined;
|
|
162
|
+
cache = undefined;
|
|
163
|
+
}
|
|
164
|
+
return cache;
|
|
165
|
+
}
|
|
166
|
+
return {
|
|
167
|
+
async prepare() {
|
|
168
|
+
reference = await safeRuntime();
|
|
169
|
+
},
|
|
170
|
+
proof: () => reference?.key,
|
|
171
|
+
async same() {
|
|
172
|
+
return !reference || reference.actual === (await safeRuntime())?.actual;
|
|
173
|
+
},
|
|
174
|
+
hash(force = false) {
|
|
175
|
+
const result = load(force);
|
|
176
|
+
if ([...observed].some(([name, hash]) => result?.outputs.get(name) !== hash))
|
|
177
|
+
throw new Error();
|
|
178
|
+
return reference ? sha256(JSON.stringify([reference.key, result?.hash])) : result?.hash;
|
|
179
|
+
},
|
|
180
|
+
tracks(url, kind, response) {
|
|
181
|
+
const path = decodeURIComponent(url.pathname);
|
|
182
|
+
if (assets.has(resolve(dir, 'public', `.${path}`)))
|
|
183
|
+
return false;
|
|
184
|
+
if (kind === 'document')
|
|
185
|
+
return path === '/_scene' && matchesBytes(reference?.html, response);
|
|
186
|
+
if (kind === 'websocket')
|
|
187
|
+
return path === '/' && !!reference?.token && url.search === `?token=${reference.token}`;
|
|
188
|
+
if (kind === 'fetch' && path === '/console.json' && !url.search)
|
|
189
|
+
return matchesBytes(reference?.html, response);
|
|
190
|
+
if (kind !== 'script')
|
|
191
|
+
return false;
|
|
192
|
+
if (paths.includes(path))
|
|
193
|
+
return !url.search && matchesBytes(reference?.helpers.get(path), response);
|
|
194
|
+
if (!path.startsWith(OPTIMIZED) || !/^\?v=[a-f0-9]+$/.test(url.search))
|
|
195
|
+
return false;
|
|
196
|
+
const name = path.slice(OPTIMIZED.length);
|
|
197
|
+
const result = load();
|
|
198
|
+
const hash = result?.outputs.get(name);
|
|
199
|
+
if (!hash || !result?.verified.has(name))
|
|
200
|
+
return false;
|
|
201
|
+
if (!observed.has(name)) {
|
|
202
|
+
if (sha256(readFileSync(join(folder, name))) !== hash)
|
|
203
|
+
return false;
|
|
204
|
+
observed.set(name, hash);
|
|
205
|
+
}
|
|
206
|
+
return observed.get(name) === hash;
|
|
207
|
+
},
|
|
208
|
+
};
|
|
209
|
+
}
|
|
@@ -2,6 +2,7 @@ import { type Scene, type Scenes } from '@buffcore/config';
|
|
|
2
2
|
import { type SnapshotReport } from './report.ts';
|
|
3
3
|
import type { Run } from './scene.ts';
|
|
4
4
|
import { type SceneSelection } from './scene-selection.ts';
|
|
5
|
+
import { type Selector } from './selector-run.ts';
|
|
5
6
|
import { type SnapshotProgressSource } from './snapshot-progress.ts';
|
|
6
7
|
export { pickScenes } from './scene-selection.ts';
|
|
7
8
|
export { snapAll } from './snapshot-runner.ts';
|
|
@@ -16,6 +17,10 @@ export interface SnapshotOptions {
|
|
|
16
17
|
commit: string;
|
|
17
18
|
/** `prototype/snapshots/`: the screenshots go in `<commit>/` there. */
|
|
18
19
|
dir: string;
|
|
20
|
+
/** `--full`: every theme, mode and pseudo-locale; else the floor unless a shared input changed. */
|
|
21
|
+
full?: boolean | undefined;
|
|
22
|
+
/** The selector (S3c): the CLI passes its real turns, a test a fake; unset, none is asked. */
|
|
23
|
+
selector?: Selector | undefined;
|
|
19
24
|
/** Scene keys or prefix patterns to snapshot; undefined selects every scene. */
|
|
20
25
|
scene?: SceneSelection | undefined;
|
|
21
26
|
sceneTimeout?: number | undefined;
|