@buffcore/cli 0.8.45 → 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 +63 -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/browser.d.ts +4 -24
- package/dist/commands/prototype/browser.js +13 -76
- 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/loaded-garbage.d.ts +10 -0
- package/dist/commands/prototype/loaded-garbage.js +20 -0
- package/dist/commands/prototype/media-ready.d.ts +9 -3
- package/dist/commands/prototype/media-ready.js +9 -4
- package/dist/commands/prototype/messages.en.d.ts +15 -0
- package/dist/commands/prototype/messages.en.js +15 -0
- package/dist/commands/prototype/messages.js +15 -0
- 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-check.d.ts +37 -0
- package/dist/commands/prototype/scene-check.js +68 -0
- package/dist/commands/prototype/scene-layout.d.ts +17 -0
- package/dist/commands/prototype/scene-layout.js +57 -0
- package/dist/commands/prototype/scene-look.d.ts +14 -0
- package/dist/commands/prototype/scene-look.js +89 -0
- package/dist/commands/prototype/scene-ready.d.ts +46 -0
- package/dist/commands/prototype/scene-ready.js +122 -0
- package/dist/commands/prototype/scene.d.ts +37 -3
- package/dist/commands/prototype/scene.js +103 -36
- 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 +23 -10
- 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 -190
- 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 +54 -4
- 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 +6 -0
- package/dist/commands/prototype/snapshot.js +73 -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
- package/templates/product/apps/app/app.json +3 -0
|
@@ -1,16 +1,52 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { lstat, readdir, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { join, resolve } from 'node:path';
|
|
3
4
|
import { checkTheme } from '@buffcore/tokens';
|
|
4
5
|
import { HOST_GIT_MAX_BUFFER } from '../safe-git.js';
|
|
5
6
|
import { t } from './messages.js';
|
|
7
|
+
import { withoutComments } from './milestone-tokens.js';
|
|
6
8
|
import { ownFirst } from './own-scenes.js';
|
|
7
9
|
import { sceneSelection } from './scene-selection.js';
|
|
8
10
|
import { SnapshotCheckoutChanged } from './snapshot-checkout.js';
|
|
9
|
-
import { inputsFingerprint, keptScenes, partialReason, stagePreviousFiles, } from './snapshot-completion.js';
|
|
11
|
+
import { inputsFingerprint, keptScenes, partialReason, reuseFingerprint, runtimeHash, stagePreviousFiles, } from './snapshot-completion.js';
|
|
10
12
|
import { identicalProblems } from './snapshot-identical.js';
|
|
11
13
|
import { reuseScenes, sceneFacts } from './snapshot-reuse.js';
|
|
12
14
|
import { snapAll } from './snapshot-runner.js';
|
|
13
15
|
import { hashShots } from './snapshot-shots.js';
|
|
16
|
+
export async function snapshotFiles(folder) {
|
|
17
|
+
if (!existsSync(folder))
|
|
18
|
+
return [];
|
|
19
|
+
if (!(await lstat(folder)).isDirectory())
|
|
20
|
+
throw new Error();
|
|
21
|
+
const paths = [];
|
|
22
|
+
for (const file of await readdir(folder, { recursive: true, withFileTypes: true })) {
|
|
23
|
+
if (file.isDirectory())
|
|
24
|
+
continue;
|
|
25
|
+
if (!file.isFile())
|
|
26
|
+
throw new Error();
|
|
27
|
+
paths.push(join(file.parentPath, file.name));
|
|
28
|
+
}
|
|
29
|
+
return paths.sort();
|
|
30
|
+
}
|
|
31
|
+
/** Expo Router discovers these modules even though nobody imports them by name. */
|
|
32
|
+
export async function expoRoutes(dir) {
|
|
33
|
+
const paths = await Promise.all(['app', 'src/app'].map((folder) => snapshotFiles(join(dir, folder))));
|
|
34
|
+
return paths.flat().filter((file) => /\.[jt]sx?$/.test(file) && !/\+api\.[jt]sx?$/.test(file));
|
|
35
|
+
}
|
|
36
|
+
export async function appBootstrap(dir, read) {
|
|
37
|
+
const manifest = await read(resolve(dir, 'package.json'));
|
|
38
|
+
const { main } = JSON.parse(manifest.toString('utf8'));
|
|
39
|
+
if (main === undefined || main === 'expo-router/entry')
|
|
40
|
+
return;
|
|
41
|
+
if (main !== 'index.ts' && main !== './index.ts')
|
|
42
|
+
throw new Error();
|
|
43
|
+
const boot = resolve(dir, main);
|
|
44
|
+
const source = withoutComments((await read(boot)).toString('utf8'), false)?.trim();
|
|
45
|
+
const stock = /^import ['"]\.\/src\/themes\.ts['"];?\s*import ['"]expo-router\/entry['"];?$/;
|
|
46
|
+
if (!source || !stock.test(source))
|
|
47
|
+
throw new Error();
|
|
48
|
+
return boot;
|
|
49
|
+
}
|
|
14
50
|
export async function writeSnapshot(options, run, picked, remaining, progress, inputs, previous) {
|
|
15
51
|
// Everything that needs no page runs first: a run that will fail on it fails before a server
|
|
16
52
|
// starts. The problems are listed where they always were, after the scenes'.
|
|
@@ -25,7 +61,10 @@ export async function writeSnapshot(options, run, picked, remaining, progress, i
|
|
|
25
61
|
const kept = keptScenes(previous?.report, selected);
|
|
26
62
|
await stagePreviousFiles(previous, run, selected);
|
|
27
63
|
const draw = await drawResults(options, run, picked, remaining, themeProblems.length > 0, progress, inputs);
|
|
28
|
-
const
|
|
64
|
+
const runtime = runtimeHash(inputs, run);
|
|
65
|
+
if (runtime !== draw.runtime && (draw.reuse?.scenes.size || remaining.length < picked.length))
|
|
66
|
+
throw new SnapshotCheckoutChanged(run.commit, run.commit);
|
|
67
|
+
const { scenes, problems, hints } = await collectScenes(run, picked, draw, kept, inputs);
|
|
29
68
|
problems.push(...themeProblems);
|
|
30
69
|
const all = options.scenes.scenes;
|
|
31
70
|
const dirty = options.dirty?.() !== false;
|
|
@@ -35,6 +74,13 @@ export async function writeSnapshot(options, run, picked, remaining, progress, i
|
|
|
35
74
|
? undefined
|
|
36
75
|
: await partialReason(previous?.report, run, selected, all, { dirty, design: options.design, inputsFingerprint: fingerprint }, inputs);
|
|
37
76
|
if (selection !== undefined && reason === undefined) {
|
|
77
|
+
// Local completion can retain pictures for the terminal report. Only a full run can
|
|
78
|
+
// supply new reuse evidence, so keep the broad binding on its locally retained entries.
|
|
79
|
+
for (const scene of scenes) {
|
|
80
|
+
const broad = inputs?.fingerprints.get(scene.key);
|
|
81
|
+
if (!scene.reusedFrom && scene.fingerprint && broad)
|
|
82
|
+
scene.fingerprint = broad;
|
|
83
|
+
}
|
|
38
84
|
const order = new Map(all.map(({ key }, index) => [key, index]));
|
|
39
85
|
scenes.sort((a, b) => (order.get(a.key) ?? 0) - (order.get(b.key) ?? 0));
|
|
40
86
|
}
|
|
@@ -52,6 +98,10 @@ export async function writeSnapshot(options, run, picked, remaining, progress, i
|
|
|
52
98
|
dirty: dirty || (!!kept?.scenes.length && previous?.report?.dirty !== false),
|
|
53
99
|
themes: run.looks.map((t) => t.key),
|
|
54
100
|
locales: run.locales,
|
|
101
|
+
matrix: run.matrix ?? 'full',
|
|
102
|
+
...(run.matrixReason ? { matrixReason: run.matrixReason } : {}),
|
|
103
|
+
...(run.fullInputs ? { fullInputs: run.fullInputs } : {}),
|
|
104
|
+
...(run.selector ? { selector: run.selector } : {}),
|
|
55
105
|
scenes,
|
|
56
106
|
problems,
|
|
57
107
|
...(hints.length ? { hints } : {}),
|
|
@@ -59,17 +109,21 @@ export async function writeSnapshot(options, run, picked, remaining, progress, i
|
|
|
59
109
|
const reuseReport = draw.reuse?.ancestor?.ref ?? previous?.report?.reuseReport;
|
|
60
110
|
if (reuseReport && scenes.some((scene) => scene.reusedFrom))
|
|
61
111
|
report.reuseReport = reuseReport;
|
|
62
|
-
if (inputs?.fingerprints.size && !(await inputs.same()))
|
|
63
|
-
throw new SnapshotCheckoutChanged(run.commit, run.commit);
|
|
64
112
|
await options.beforeReport?.();
|
|
65
113
|
await writeReport(run.out, report, run.checkCheckout);
|
|
66
114
|
for (const [name, value] of Object.entries(options.artifacts ?? {}))
|
|
67
115
|
await writeFile(join(run.out, name), `${JSON.stringify(value, null, 2)}\n`);
|
|
116
|
+
if (inputs && (!(await inputs.same()) || runtime !== runtimeHash(inputs, run)))
|
|
117
|
+
throw new SnapshotCheckoutChanged(run.commit, run.commit);
|
|
68
118
|
return report;
|
|
69
119
|
}
|
|
70
120
|
async function drawResults(options, run, picked, remaining, themeFailed, progress, inputs) {
|
|
71
|
-
const
|
|
72
|
-
|
|
121
|
+
const runtime = runtimeHash(inputs, run);
|
|
122
|
+
const reuse = options.scene === undefined && inputs?.reuse.size && options.root
|
|
123
|
+
? await reuseScenes(options.root, run, picked, remaining, new Map(picked.flatMap((scene) => {
|
|
124
|
+
const fingerprint = reuseFingerprint(inputs, scene);
|
|
125
|
+
return fingerprint ? [[scene.key, fingerprint]] : [];
|
|
126
|
+
})))
|
|
73
127
|
: undefined;
|
|
74
128
|
// The change's own scenes are drawn first when the run names them; the report keeps its order.
|
|
75
129
|
const own = options.ownScenes;
|
|
@@ -81,16 +135,21 @@ async function drawResults(options, run, picked, remaining, themeFailed, progres
|
|
|
81
135
|
const warmScenes = new Set(firstOnSurface.values());
|
|
82
136
|
if (themeFailed) {
|
|
83
137
|
console.log(t('prototype.noRender'));
|
|
84
|
-
return { reuse, results: new Map() };
|
|
138
|
+
return { reuse, runtime, results: new Map(), fresh: new Set() };
|
|
85
139
|
}
|
|
86
140
|
await options.prepare?.(drawing);
|
|
87
141
|
const drawn = await snapAll(drawing, options.scene === undefined ? { ...run, warmScenes } : run, undefined, { pages: options.pages });
|
|
88
142
|
const order = progress ? uncopied : drawing;
|
|
89
143
|
const snapped = progress ? await progress.collect(order, run) : drawn;
|
|
90
144
|
// Each result belongs to the scene it was drawn for, whatever order the scenes were drawn in.
|
|
91
|
-
return {
|
|
145
|
+
return {
|
|
146
|
+
reuse,
|
|
147
|
+
runtime,
|
|
148
|
+
results: new Map(order.map(({ key }, i) => [key, snapped[i]])),
|
|
149
|
+
fresh: new Set(options.scene === undefined ? drawing.map(({ key }) => key) : []),
|
|
150
|
+
};
|
|
92
151
|
}
|
|
93
|
-
async function collectScenes(run, picked, { reuse, results }, kept,
|
|
152
|
+
async function collectScenes(run, picked, { reuse, results, fresh }, kept, inputs) {
|
|
94
153
|
const hints = [...(kept?.hints ?? [])];
|
|
95
154
|
const problems = [...(kept?.problems ?? [])];
|
|
96
155
|
const scenes = [...(kept?.scenes ?? [])];
|
|
@@ -115,6 +174,11 @@ async function collectScenes(run, picked, { reuse, results }, kept, fingerprints
|
|
|
115
174
|
};
|
|
116
175
|
if (result.cut?.length)
|
|
117
176
|
scene.cut = result.cut;
|
|
177
|
+
if (run.matrix === 'floor')
|
|
178
|
+
scene.matrix = 'floor';
|
|
179
|
+
const extra = run.matrix === 'floor' ? run.extraLooks?.get(key) : undefined;
|
|
180
|
+
if (extra?.size)
|
|
181
|
+
scene.extraLooks = [...extra];
|
|
118
182
|
if (typeof result.apiCalls === 'boolean')
|
|
119
183
|
scene.apiCalls = result.apiCalls;
|
|
120
184
|
if (result.retried)
|
|
@@ -128,7 +192,8 @@ async function collectScenes(run, picked, { reuse, results }, kept, fingerprints
|
|
|
128
192
|
const hashes = await hashShots(run.out, run.commit, scene);
|
|
129
193
|
if (hashes)
|
|
130
194
|
scene.screenshotHashes = hashes;
|
|
131
|
-
const
|
|
195
|
+
const candidate = fresh.has(key) && reuseFingerprint(inputs, scene);
|
|
196
|
+
const fingerprint = candidate || inputs?.fingerprints.get(key);
|
|
132
197
|
if (hashes && fingerprint && result.untrackedRequests === false)
|
|
133
198
|
scene.fingerprint = fingerprint;
|
|
134
199
|
scenes.push(scene);
|
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
import type { Scene } from '@buffcore/config';
|
|
2
|
-
import type { Page } from 'playwright-core';
|
|
2
|
+
import type { Page, Response } from 'playwright-core';
|
|
3
3
|
import type { Run } from './scene.ts';
|
|
4
4
|
export interface SceneRequestFacts {
|
|
5
5
|
apiCalls: boolean;
|
|
6
6
|
untrackedRequests: boolean;
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
export type RequestCoverage = (scene: Scene, url: URL, kind: string, response?: Response) => boolean | Promise<boolean>;
|
|
9
|
+
/** Wait for the coverage of every load that added to these facts, failed loads included. */
|
|
10
|
+
export declare function settleRequests(facts: SceneRequestFacts): Promise<void>;
|
|
11
|
+
/**
|
|
12
|
+
* Context requests include iframes, workers and requests that fail before receiving a response.
|
|
13
|
+
* `look()` starts a look: more than one navigation of the page within a look is not tracked.
|
|
14
|
+
*/
|
|
15
|
+
export declare function sceneRequests(page: Page, { urls, coversRequest, requests: found, }: Pick<Run, 'urls' | 'coversRequest' | 'requests'>, scene: Scene): {
|
|
16
|
+
facts: SceneRequestFacts;
|
|
17
|
+
finish: () => Promise<void>;
|
|
18
|
+
look: () => void;
|
|
19
|
+
};
|
|
@@ -3,16 +3,34 @@ const origin = (url) => {
|
|
|
3
3
|
? 'localhost'
|
|
4
4
|
: url.hostname;
|
|
5
5
|
const secure = ['https:', 'wss:'].includes(url.protocol);
|
|
6
|
-
return [host, url.port || (secure ? '443' : '80')].join(':');
|
|
6
|
+
return [host, url.port || (secure ? '443' : '80'), secure].join(':');
|
|
7
7
|
};
|
|
8
8
|
const apiPath = (url) => /^\/api(?:\/|$)/i.test(url.pathname);
|
|
9
|
-
/**
|
|
10
|
-
|
|
9
|
+
/** Every load's coverage check, by the facts it adds to: a scene's facts are a union over its loads. */
|
|
10
|
+
const loads = new WeakMap();
|
|
11
|
+
/** Wait for the coverage of every load that added to these facts, failed loads included. */
|
|
12
|
+
export async function settleRequests(facts) {
|
|
13
|
+
for (const finish of loads.get(facts) ?? [])
|
|
14
|
+
await finish();
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Context requests include iframes, workers and requests that fail before receiving a response.
|
|
18
|
+
* `look()` starts a look: more than one navigation of the page within a look is not tracked.
|
|
19
|
+
*/
|
|
20
|
+
export function sceneRequests(page, { urls, coversRequest, requests: found = { apiCalls: false, untrackedRequests: false }, }, scene) {
|
|
11
21
|
const api = urls.api ? origin(new URL(urls.api)) : undefined;
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
22
|
+
const surface = origin(new URL(urls[scene.surface]));
|
|
23
|
+
const pending = new Map();
|
|
24
|
+
const validated = new Map();
|
|
25
|
+
const sockets = [];
|
|
26
|
+
const known = async (url, kind, response) => {
|
|
27
|
+
try {
|
|
28
|
+
return (await coversRequest?.(scene, url, kind, response)) === true;
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
16
34
|
const request = (sent) => {
|
|
17
35
|
const url = new URL(sent.url());
|
|
18
36
|
const host = origin(url);
|
|
@@ -20,43 +38,63 @@ export function sceneRequests(page, { urls, hasAsset, requests: found = { apiCal
|
|
|
20
38
|
if (host === api || apiPath(url))
|
|
21
39
|
found.apiCalls = true;
|
|
22
40
|
// The console reads its own static startup settings. Its public copy is a shared input.
|
|
23
|
-
const settings =
|
|
41
|
+
const settings = host === surface &&
|
|
42
|
+
url.pathname === '/console.json' &&
|
|
43
|
+
!url.search &&
|
|
44
|
+
sent.method() === 'GET';
|
|
24
45
|
if (['fetch', 'xhr', 'eventsource', 'ping'].includes(resource) && !settings)
|
|
25
46
|
found.apiCalls = true;
|
|
26
|
-
if (host
|
|
47
|
+
if (host === api)
|
|
48
|
+
return;
|
|
49
|
+
if (host !== surface ||
|
|
50
|
+
sent.method() !== 'GET' ||
|
|
51
|
+
!['http:', 'https:'].includes(url.protocol)) {
|
|
27
52
|
found.untrackedRequests = true;
|
|
28
|
-
if (host !== api &&
|
|
29
|
-
hasAsset &&
|
|
30
|
-
['http:', 'https:'].includes(url.protocol) &&
|
|
31
|
-
(['image', 'font', 'media', 'stylesheet'].includes(resource) ||
|
|
32
|
-
(resource === 'script' &&
|
|
33
|
-
(/\.css$/i.test(url.pathname) || /^\/[^/]+\.[cm]?js$/.test(url.pathname))))) {
|
|
34
|
-
try {
|
|
35
|
-
if (!hasAsset(scene, url))
|
|
36
|
-
found.untrackedRequests = true;
|
|
37
|
-
}
|
|
38
|
-
catch {
|
|
39
|
-
found.untrackedRequests = true;
|
|
40
|
-
}
|
|
41
53
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
found.untrackedRequests = true;
|
|
54
|
+
else
|
|
55
|
+
pending.set(sent, undefined);
|
|
45
56
|
};
|
|
46
57
|
const socket = (opened) => {
|
|
47
58
|
const url = new URL(opened.url());
|
|
48
59
|
const host = origin(url);
|
|
49
60
|
if (host === api || apiPath(url))
|
|
50
61
|
found.apiCalls = true;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
if (host !== api && (!surfaces.has(host) || !hmr))
|
|
54
|
-
found.untrackedRequests = true;
|
|
62
|
+
if (host !== api)
|
|
63
|
+
sockets.push(host === surface ? known(url, 'websocket') : Promise.resolve(false));
|
|
55
64
|
};
|
|
56
65
|
page.context().on('request', request);
|
|
66
|
+
page.context().on('response', (response) => {
|
|
67
|
+
const sent = response.request();
|
|
68
|
+
if (!pending.has(sent))
|
|
69
|
+
return;
|
|
70
|
+
const url = new URL(sent.url());
|
|
71
|
+
const key = `${sent.resourceType()} ${url.href}`;
|
|
72
|
+
const covered = response.status() === 304 ? validated.get(key) : known(url, sent.resourceType(), response);
|
|
73
|
+
pending.set(sent, covered);
|
|
74
|
+
if (covered)
|
|
75
|
+
validated.set(key, covered);
|
|
76
|
+
});
|
|
57
77
|
page.on('websocket', socket);
|
|
78
|
+
let navigations = 0;
|
|
79
|
+
page.on('request', (sent) => {
|
|
80
|
+
if (sent.isNavigationRequest() && ++navigations > 1)
|
|
81
|
+
found.untrackedRequests = true;
|
|
82
|
+
});
|
|
58
83
|
page.on('frameattached', () => {
|
|
59
84
|
found.untrackedRequests = true;
|
|
60
85
|
});
|
|
61
|
-
|
|
86
|
+
const finish = async () => {
|
|
87
|
+
const total = pending.size + sockets.length;
|
|
88
|
+
const checks = await Promise.all([...pending.values(), ...sockets]);
|
|
89
|
+
if (total !== pending.size + sockets.length || checks.some((covered) => !covered))
|
|
90
|
+
found.untrackedRequests = true;
|
|
91
|
+
};
|
|
92
|
+
loads.set(found, [...(loads.get(found) ?? []), finish]);
|
|
93
|
+
return {
|
|
94
|
+
facts: found,
|
|
95
|
+
finish,
|
|
96
|
+
look: () => {
|
|
97
|
+
navigations = 0;
|
|
98
|
+
},
|
|
99
|
+
};
|
|
62
100
|
}
|
|
@@ -2,6 +2,7 @@ import type { Scene } from '@buffcore/config';
|
|
|
2
2
|
import { type GitRead, type SnapshotReport } from './report.ts';
|
|
3
3
|
import type { Run } from './scene.ts';
|
|
4
4
|
import { type Ancestor } from './snapshot-ancestor.ts';
|
|
5
|
+
import { type Matrix } from './snapshot-matrix.ts';
|
|
5
6
|
/** Report-level findings are run again against the mixed set of scenes. */
|
|
6
7
|
export declare const sceneFacts: (report: SnapshotReport, key: string) => {
|
|
7
8
|
problems: {
|
|
@@ -14,7 +15,7 @@ export declare const sceneFacts: (report: SnapshotReport, key: string) => {
|
|
|
14
15
|
}[];
|
|
15
16
|
hints: import("./report.ts").SnapshotHint[];
|
|
16
17
|
};
|
|
17
|
-
export declare function reuseScenes(root: string, run: Run, picked: readonly Scene[], remaining: readonly Scene[],
|
|
18
|
+
export declare function reuseScenes(root: string, run: Run, picked: readonly Scene[], remaining: readonly Scene[], candidates: ReadonlyMap<string, string>): Promise<{
|
|
18
19
|
scenes: Map<string, {
|
|
19
20
|
key: string;
|
|
20
21
|
title: string;
|
|
@@ -30,6 +31,8 @@ export declare function reuseScenes(root: string, run: Run, picked: readonly Sce
|
|
|
30
31
|
loadFailure?: import("./scene-errors.ts").LoadFailure;
|
|
31
32
|
scriptError?: import("./scene-errors.ts").LoadFailure;
|
|
32
33
|
reusedFrom?: string;
|
|
34
|
+
matrix?: Matrix;
|
|
35
|
+
extraLooks?: string[];
|
|
33
36
|
}>;
|
|
34
37
|
ancestor: undefined;
|
|
35
38
|
} | {
|
|
@@ -48,6 +51,8 @@ export declare function reuseScenes(root: string, run: Run, picked: readonly Sce
|
|
|
48
51
|
loadFailure?: import("./scene-errors.ts").LoadFailure;
|
|
49
52
|
scriptError?: import("./scene-errors.ts").LoadFailure;
|
|
50
53
|
reusedFrom?: string;
|
|
54
|
+
matrix?: Matrix;
|
|
55
|
+
extraLooks?: string[];
|
|
51
56
|
}>;
|
|
52
57
|
ancestor: Ancestor;
|
|
53
58
|
}>;
|
|
@@ -3,6 +3,7 @@ import { t } from './messages.js';
|
|
|
3
3
|
import { snapshotsDir } from './report.js';
|
|
4
4
|
import { findAncestor, readAncestor } from './snapshot-ancestor.js';
|
|
5
5
|
import { sha256Pattern } from './snapshot-hashes.js';
|
|
6
|
+
import { covers, drawnLooks } from './snapshot-matrix.js';
|
|
6
7
|
import { shotSources } from './snapshot-shared-shots.js';
|
|
7
8
|
import { boundShots, copyShots, shotStem, shotsMatch } from './snapshot-shots.js';
|
|
8
9
|
import { lookKey, photographed } from './snapshot-themes.js';
|
|
@@ -17,9 +18,12 @@ const eligible = (scene, fingerprint) => !!scene &&
|
|
|
17
18
|
!!fingerprint &&
|
|
18
19
|
sha256Pattern.test(fingerprint) &&
|
|
19
20
|
scene.fingerprint === fingerprint;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
/** The looks a scene drawn in `matrix` was photographed in. */
|
|
22
|
+
const photoLooks = (run, matrix) => [
|
|
23
|
+
...new Set(drawnLooks({ ...run, matrix })
|
|
24
|
+
.filter(({ theme, mode }) => photographed(theme.key, mode, run.product))
|
|
25
|
+
.map(({ theme, mode }) => lookKey(theme.key, mode))),
|
|
26
|
+
];
|
|
23
27
|
function copiedScene(scene, commit, from) {
|
|
24
28
|
const copied = {
|
|
25
29
|
...scene,
|
|
@@ -33,20 +37,26 @@ function copiedScene(scene, commit, from) {
|
|
|
33
37
|
delete copied.retryError;
|
|
34
38
|
return copied;
|
|
35
39
|
}
|
|
36
|
-
export async function reuseScenes(root, run, picked, remaining,
|
|
40
|
+
export async function reuseScenes(root, run, picked, remaining, candidates) {
|
|
37
41
|
const scenes = new Map();
|
|
38
|
-
const ancestor =
|
|
42
|
+
const ancestor = candidates.size && remaining.length ? findAncestor(root, run.commit) : undefined;
|
|
39
43
|
if (!ancestor)
|
|
40
44
|
return { scenes, ancestor };
|
|
41
45
|
const from = ancestor.report.commit;
|
|
42
46
|
const old = new Map(ancestor.report.scenes.map((scene) => [scene.key, scene]));
|
|
43
|
-
const looks = photoLooks(run);
|
|
44
47
|
const sources = shotSources(root, from, ancestor.hash);
|
|
45
48
|
const stems = picked.map((scene) => shotStem(scene.key).toLowerCase());
|
|
46
49
|
for (const scene of remaining) {
|
|
50
|
+
// A scene the selector picked is drawn again, never copied.
|
|
51
|
+
if (run.redraw?.has(scene.key))
|
|
52
|
+
continue;
|
|
47
53
|
const candidate = old.get(scene.key);
|
|
48
|
-
if (!candidate || !eligible(candidate,
|
|
54
|
+
if (!candidate || !eligible(candidate, candidates.get(scene.key)))
|
|
55
|
+
continue;
|
|
56
|
+
// A floor scene serves a floor run only; a full one serves either.
|
|
57
|
+
if (!covers(candidate.matrix, run.matrix))
|
|
49
58
|
continue;
|
|
59
|
+
const looks = photoLooks(run, candidate.matrix ?? 'full');
|
|
50
60
|
if (candidate.title !== scene.title ||
|
|
51
61
|
candidate.surface !== scene.surface ||
|
|
52
62
|
candidate.frame !== scene.frame ||
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Scene, Surface } from '@buffcore/config';
|
|
2
|
+
import type { Run } from './scene.ts';
|
|
3
|
+
import { type SurfaceEntry } from './snapshot-bundle.ts';
|
|
4
|
+
import { type snapshotDependencies } from './snapshot-dependencies.ts';
|
|
5
|
+
type Dependencies = ReturnType<typeof snapshotDependencies>;
|
|
6
|
+
type Walk = NonNullable<Awaited<ReturnType<Dependencies['walk']>>>;
|
|
7
|
+
type Digests = readonly (readonly [string, string])[];
|
|
8
|
+
/** The page a scene is drawn in: its own frame's size, in one key order. */
|
|
9
|
+
export declare function scenePage(run: Run, scene: Scene): import("playwright-core").BrowserContextOptions;
|
|
10
|
+
export interface SceneGraph {
|
|
11
|
+
topology: unknown;
|
|
12
|
+
files: Digests;
|
|
13
|
+
setup: Digests;
|
|
14
|
+
view(name: string): Digests | undefined;
|
|
15
|
+
}
|
|
16
|
+
export declare function sceneCandidates(root: string, scenes: readonly Scene[], run: Run, deps: Dependencies): {
|
|
17
|
+
reuse: Map<string, string>;
|
|
18
|
+
assets: Map<string, ReadonlySet<string>>;
|
|
19
|
+
signature: string;
|
|
20
|
+
/** F113c's shared inputs: public values and tools, the theme, `design/`, each shell's own parts. */
|
|
21
|
+
parts: string | undefined;
|
|
22
|
+
compare(inputs: ReadonlyMap<Surface, {
|
|
23
|
+
graph: SceneGraph | undefined;
|
|
24
|
+
settings: unknown;
|
|
25
|
+
pageAssets: string[];
|
|
26
|
+
whole?: boolean;
|
|
27
|
+
}>, shared: string): Promise<void>;
|
|
28
|
+
};
|
|
29
|
+
export declare function sceneGraph(root: string, catalog: string, entry: SurfaceEntry, walk: Walk, deps: Dependencies, locales: readonly string[], eager: boolean): Promise<SceneGraph | undefined>;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { dirname, extname, relative, resolve } from 'node:path';
|
|
2
|
+
import { pageOptions } from './browser.js';
|
|
3
|
+
import { catalogInput, loaders, moduleEffects, virtualInput, } from './snapshot-bundle.js';
|
|
4
|
+
import { pathIn, resolutionAlternatives, resolutionSettings, runtimeExternal, slash, } from './snapshot-dependencies.js';
|
|
5
|
+
import { plainData, sha256 } from './snapshot-hashes.js';
|
|
6
|
+
import { knownDeferred, registry, registryConsumer } from './snapshot-registry.js';
|
|
7
|
+
import { appBootstrap, snapshotFiles } from './snapshot-report.js';
|
|
8
|
+
const CODE = new Set(['ts', 'tsx', 'js', 'jsx']);
|
|
9
|
+
const editable = (root, file) => pathIn(root, file) && !slash(file).includes('/node_modules/');
|
|
10
|
+
const sharedName = /(?:^|\/)(?:design\/|(?:global|styles|setup|store|shell|rail)(?:[./-]|$))/i;
|
|
11
|
+
function walkFrom(edges, starts) {
|
|
12
|
+
const visited = new Set();
|
|
13
|
+
const pending = [...starts];
|
|
14
|
+
for (const file of pending) {
|
|
15
|
+
if (visited.has(file))
|
|
16
|
+
continue;
|
|
17
|
+
visited.add(file);
|
|
18
|
+
for (const path of edges.get(file) ?? [])
|
|
19
|
+
pending.push(path);
|
|
20
|
+
}
|
|
21
|
+
return visited;
|
|
22
|
+
}
|
|
23
|
+
/** The page a scene is drawn in: its own frame's size, in one key order. */
|
|
24
|
+
export function scenePage(run, scene) {
|
|
25
|
+
const { width, height } = run.frames[scene.frame];
|
|
26
|
+
return pageOptions({ width, height });
|
|
27
|
+
}
|
|
28
|
+
export function sceneCandidates(root, scenes, run, deps) {
|
|
29
|
+
const reuse = new Map();
|
|
30
|
+
const assets = new Map();
|
|
31
|
+
const surfaces = new Set(scenes.map(({ surface }) => surface));
|
|
32
|
+
return {
|
|
33
|
+
reuse,
|
|
34
|
+
assets,
|
|
35
|
+
signature: '',
|
|
36
|
+
/** F113c's shared inputs: public values and tools, the theme, `design/`, each shell's own parts. */
|
|
37
|
+
parts: undefined,
|
|
38
|
+
async compare(inputs, shared) {
|
|
39
|
+
const graphs = [...inputs].flatMap(([name, { graph, settings }]) => graph ? [[name, settings, graph]] : []);
|
|
40
|
+
const design = await snapshotFiles(resolve(root, 'design'))
|
|
41
|
+
.then((files) => Promise.all(files.map(async (file) => [slash(relative(root, file)), await deps.digest(file)])))
|
|
42
|
+
.catch(() => undefined);
|
|
43
|
+
if (!design || graphs.length !== surfaces.size)
|
|
44
|
+
return;
|
|
45
|
+
const setup = sha256(JSON.stringify([
|
|
46
|
+
'snapshot-scene-inputs-v3',
|
|
47
|
+
shared,
|
|
48
|
+
design,
|
|
49
|
+
run.product,
|
|
50
|
+
scenes.map(({ key, surface, view, frame }) => [key, surface, view, frame]),
|
|
51
|
+
graphs.map(([name, settings, graph]) => [name, settings, graph.topology, graph.setup]),
|
|
52
|
+
]));
|
|
53
|
+
const whole = sha256(JSON.stringify(['whole-graphs', setup, graphs.map(([, , g]) => g.files)]));
|
|
54
|
+
this.signature = whole;
|
|
55
|
+
this.parts = sha256(JSON.stringify([shared, design, run.product, graphs.map(([n, s, g]) => [n, s, g.setup])]));
|
|
56
|
+
const commonAssets = graphs.flatMap(([, , graph]) => graph.setup.map(([file]) => resolve(root, file)));
|
|
57
|
+
const viewAssets = new Map();
|
|
58
|
+
for (const scene of scenes) {
|
|
59
|
+
const input = inputs.get(scene.surface);
|
|
60
|
+
if (!input || typeof scene.view !== 'string')
|
|
61
|
+
continue;
|
|
62
|
+
const files = input.whole ? input.graph?.files : input.graph?.view(scene.view);
|
|
63
|
+
const binding = files ? ['view', setup, files] : ['coarse', whole];
|
|
64
|
+
// A scene whose props hold code (handlers) is never reused across commits: a function's
|
|
65
|
+
// text can stay the same while its helpers change. Its requests are still proven for the
|
|
66
|
+
// journal, which keeps a finished scene only for a run of the same source.
|
|
67
|
+
if (plainData(scene))
|
|
68
|
+
reuse.set(scene.key, sha256(JSON.stringify([binding, scene, scenePage(run, scene)])));
|
|
69
|
+
if (!input.graph)
|
|
70
|
+
continue;
|
|
71
|
+
const covered = files ?? input.graph.files;
|
|
72
|
+
const known = viewAssets.get(covered) ??
|
|
73
|
+
new Set([
|
|
74
|
+
...commonAssets,
|
|
75
|
+
...input.pageAssets,
|
|
76
|
+
...covered.map(([file]) => resolve(root, file)),
|
|
77
|
+
]);
|
|
78
|
+
viewAssets.set(covered, known);
|
|
79
|
+
assets.set(scene.key, known);
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
export async function sceneGraph(root, catalog, entry, walk, deps, locales, eager) {
|
|
85
|
+
try {
|
|
86
|
+
return await readGraph(root, catalog, entry, walk, deps, locales, eager);
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
async function readGraph(root, catalog, entry, walk, deps, locales, eager) {
|
|
93
|
+
const inputs = Object.entries(walk.meta.inputs);
|
|
94
|
+
const names = new Set(inputs.map(([name]) => name));
|
|
95
|
+
const nameOf = (file) => slash(relative(root, file));
|
|
96
|
+
const fileOf = (name) => (name === catalogInput ? catalog : resolve(root, name));
|
|
97
|
+
const registryName = nameOf(entry.registry);
|
|
98
|
+
const importing = inputs.filter(([name, { imports }]) => name !== '<stdin>' && imports.some(({ path }) => path === registryName));
|
|
99
|
+
const routing = await registry(entry.registry, walk.meta.inputs[registryName]?.imports ?? [], deps, eager);
|
|
100
|
+
const consumers = await Promise.all(importing.map(([name, { imports }]) => registryConsumer(entry, fileOf(name), imports, deps)));
|
|
101
|
+
const split = routing && consumers.every(Boolean);
|
|
102
|
+
const full = new Map();
|
|
103
|
+
const common = new Map();
|
|
104
|
+
const onLoad = new Set([registryName, ...entry.roots.map(nameOf)]);
|
|
105
|
+
const routes = new Set(entry.routes.map(nameOf));
|
|
106
|
+
const reexports = new Map();
|
|
107
|
+
const files = new Map();
|
|
108
|
+
const addFile = async (name, file) => {
|
|
109
|
+
files.set(name, [nameOf(file), await deps.digest(file)]);
|
|
110
|
+
};
|
|
111
|
+
if (entry.surface === 'app') {
|
|
112
|
+
const boot = await appBootstrap(entry.dir, deps.read);
|
|
113
|
+
if (boot) {
|
|
114
|
+
onLoad.add(nameOf(boot));
|
|
115
|
+
await addFile(nameOf(boot), boot);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const safe = await Promise.all(inputs.map(async ([name, input]) => {
|
|
119
|
+
const file = fileOf(name);
|
|
120
|
+
const imports = input.imports;
|
|
121
|
+
const virtual = virtualInput(name);
|
|
122
|
+
const local = !virtual && editable(root, file);
|
|
123
|
+
if (imports.some((edge) => !edge.external && !names.has(edge.path)))
|
|
124
|
+
return false;
|
|
125
|
+
const external = imports
|
|
126
|
+
.filter(({ external, kind, path }) => external &&
|
|
127
|
+
!(kind === 'url-token' && /^(data:|#)/.test(path)) &&
|
|
128
|
+
!imports.some((edge) => !edge.external && edge.original === path))
|
|
129
|
+
.map(({ path }) => path);
|
|
130
|
+
if (external.length && (await runtimeExternal(file, external, deps.read)))
|
|
131
|
+
return false;
|
|
132
|
+
const deferred = imports.filter(({ kind }) => kind === 'dynamic-import');
|
|
133
|
+
const planned = name === registryName &&
|
|
134
|
+
deferred.every(({ original }) => original && routing?.lazy.has(original));
|
|
135
|
+
if (local &&
|
|
136
|
+
deferred.length &&
|
|
137
|
+
!planned &&
|
|
138
|
+
!(await knownDeferred(entry, file, deferred, locales, deps)))
|
|
139
|
+
return false;
|
|
140
|
+
const assets = virtual ? [] : await deps.assets(file);
|
|
141
|
+
if (!assets)
|
|
142
|
+
return false;
|
|
143
|
+
const paths = (edges) => edges
|
|
144
|
+
.filter(({ external }) => !external)
|
|
145
|
+
.map(({ path }) => path)
|
|
146
|
+
.concat(assets.map((asset) => nameOf(resolve(dirname(file), asset))));
|
|
147
|
+
full.set(name, paths(imports));
|
|
148
|
+
common.set(name, paths(split && name === registryName ? routing.setup : imports).filter((target) => !split || target !== registryName));
|
|
149
|
+
if (!virtual) {
|
|
150
|
+
if (walk.unproven.has(file))
|
|
151
|
+
return false;
|
|
152
|
+
const loader = loaders[extname(file).toLowerCase()];
|
|
153
|
+
if (local) {
|
|
154
|
+
for (const edge of imports) {
|
|
155
|
+
if (edge.external || virtualInput(edge.path) || edge.path === catalogInput)
|
|
156
|
+
continue;
|
|
157
|
+
const target = fileOf(edge.path);
|
|
158
|
+
if (!editable(root, target))
|
|
159
|
+
continue;
|
|
160
|
+
if (resolutionAlternatives(file, edge.original, target).length)
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
for (const asset of assets) {
|
|
165
|
+
const path = resolve(dirname(file), asset);
|
|
166
|
+
await addFile(nameOf(path), path);
|
|
167
|
+
}
|
|
168
|
+
// Bind the original scene catalog if esbuild retains its initialization.
|
|
169
|
+
if (name !== catalogInput || eager || walk.selected.has(name))
|
|
170
|
+
await addFile(name, file);
|
|
171
|
+
if (name === catalogInput || !local || loader === 'css' || sharedName.test(name)) {
|
|
172
|
+
onLoad.add(name);
|
|
173
|
+
}
|
|
174
|
+
else if (name !== registryName && loader && CODE.has(loader)) {
|
|
175
|
+
const effects = await moduleEffects(file, deps);
|
|
176
|
+
if (!effects || effects.initializes || (routes.has(name) && !effects.defaultOnly))
|
|
177
|
+
onLoad.add(name);
|
|
178
|
+
if (effects?.exports.length)
|
|
179
|
+
reexports.set(name, effects.exports);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return true;
|
|
183
|
+
}));
|
|
184
|
+
if (safe.includes(false))
|
|
185
|
+
return;
|
|
186
|
+
const entries = [...files].sort(([a], [b]) => a.localeCompare(b));
|
|
187
|
+
const digests = (selected, omit) => entries.flatMap(([name, digest]) => !omit?.has(name) && (!selected || selected.has(name)) ? [digest] : []);
|
|
188
|
+
const shared = walkFrom(common, onLoad);
|
|
189
|
+
for (const route of routes)
|
|
190
|
+
shared.add(route);
|
|
191
|
+
const views = new Map();
|
|
192
|
+
return {
|
|
193
|
+
topology: [
|
|
194
|
+
await resolutionSettings(root, [...files.keys()].map(fileOf), deps),
|
|
195
|
+
inputs
|
|
196
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
197
|
+
.map(([name, { imports }]) => [name, imports, full.get(name), reexports.get(name)]),
|
|
198
|
+
],
|
|
199
|
+
files: digests(),
|
|
200
|
+
setup: digests(shared),
|
|
201
|
+
view(name) {
|
|
202
|
+
const file = split && routing.named.get(name);
|
|
203
|
+
if (!file)
|
|
204
|
+
return;
|
|
205
|
+
const matched = views.get(file) ?? digests(walkFrom(full, [file]), shared);
|
|
206
|
+
views.set(file, matched);
|
|
207
|
+
return matched;
|
|
208
|
+
},
|
|
209
|
+
};
|
|
210
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { Response } from 'playwright-core';
|
|
2
|
+
export declare function servedBytes(url: URL, mime: string, timeout?: number): Promise<Buffer<ArrayBuffer> | undefined>;
|
|
3
|
+
export declare function matchesBytes(hash: string | undefined, response?: Response): Promise<boolean>;
|