@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
|
@@ -1,13 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { existsSync, statSync } from 'node:fs';
|
|
2
|
+
import { lstat, readFile } from 'node:fs/promises';
|
|
2
3
|
import { createRequire } from 'node:module';
|
|
3
|
-
import { dirname, extname, join, relative, resolve } from 'node:path';
|
|
4
|
-
import { version } from 'esbuild';
|
|
4
|
+
import { dirname, extname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
5
|
+
import { transform, version } from 'esbuild';
|
|
6
|
+
import { withoutComments } from './milestone-manifests.js';
|
|
5
7
|
import { codeReferences } from './milestone-references.js';
|
|
6
8
|
import { bundleSurface, catalogInput, loaders, virtualInput, } from './snapshot-bundle.js';
|
|
7
9
|
import { sha256 } from './snapshot-hashes.js';
|
|
8
10
|
export const dependencyVersion = version;
|
|
9
11
|
const CODE_LOADERS = new Set(['ts', 'tsx', 'js', 'jsx']);
|
|
10
|
-
const slash = (path) => path.replaceAll('\\', '/');
|
|
12
|
+
export const slash = (path) => path.replaceAll('\\', '/');
|
|
13
|
+
export function pathIn(root, file) {
|
|
14
|
+
const name = relative(root, file);
|
|
15
|
+
return !isAbsolute(name) && name !== '..' && !name.startsWith(`..${sep}`);
|
|
16
|
+
}
|
|
11
17
|
const assetLiteral = (url) => url.startsWith('data:') || url.startsWith('#');
|
|
12
18
|
// This loader mounts host-supplied Studio parts outside the scene. The module still contributes
|
|
13
19
|
// its bytes and ordinary imports. All other unresolved warnings fail the walk.
|
|
@@ -24,7 +30,6 @@ function hostPartLoader(dir) {
|
|
|
24
30
|
}
|
|
25
31
|
function selectedInputs(meta) {
|
|
26
32
|
const outputs = Object.entries(meta.outputs);
|
|
27
|
-
// The output imports omit external edges that were only used as TS types.
|
|
28
33
|
if (outputs.some(([, output]) => output.imports.some(({ path, external, kind }) => external && !(kind === 'url-token' && assetLiteral(path)))))
|
|
29
34
|
return;
|
|
30
35
|
const selected = new Set(outputs
|
|
@@ -32,7 +37,6 @@ function selectedInputs(meta) {
|
|
|
32
37
|
.flatMap(([, output]) => Object.entries(output.inputs)
|
|
33
38
|
.filter(([, input]) => input.bytesInOutput > 0)
|
|
34
39
|
.map(([file]) => file)));
|
|
35
|
-
// An unused JS import can emit an asset, while a used stylesheet can have a zero-byte URL edge.
|
|
36
40
|
for (const file of selected)
|
|
37
41
|
for (const edge of meta.inputs[file]?.imports ?? [])
|
|
38
42
|
if (edge.kind === 'url-token' && !edge.external)
|
|
@@ -47,17 +51,35 @@ function unresolved(root, warning, selected, ignored) {
|
|
|
47
51
|
return false;
|
|
48
52
|
return warning.id !== 'unsupported-dynamic-import' || resolve(root, file) !== ignored;
|
|
49
53
|
}
|
|
54
|
+
async function fileState(path) {
|
|
55
|
+
try {
|
|
56
|
+
return { bytes: await readFile(path) };
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
const code = error.code;
|
|
60
|
+
if (!code || !['EBUSY', 'EPERM', 'EACCES'].includes(code))
|
|
61
|
+
throw error;
|
|
62
|
+
const file = await lstat(path);
|
|
63
|
+
if (!file.isFile())
|
|
64
|
+
throw error;
|
|
65
|
+
const lock = JSON.stringify([code, file.ino, file.size, file.mtimeMs, file.ctimeMs]);
|
|
66
|
+
return { error, lock };
|
|
67
|
+
}
|
|
68
|
+
}
|
|
50
69
|
function cachedFiles() {
|
|
51
70
|
const files = new Map();
|
|
52
71
|
const digests = new Map();
|
|
53
|
-
function read(file) {
|
|
72
|
+
async function read(file) {
|
|
54
73
|
const key = resolve(file);
|
|
55
74
|
let contents = files.get(key);
|
|
56
75
|
if (!contents) {
|
|
57
|
-
contents =
|
|
76
|
+
contents = fileState(key);
|
|
58
77
|
files.set(key, contents);
|
|
59
78
|
}
|
|
60
|
-
|
|
79
|
+
const state = await contents;
|
|
80
|
+
if ('bytes' in state)
|
|
81
|
+
return state.bytes;
|
|
82
|
+
throw state.error;
|
|
61
83
|
}
|
|
62
84
|
async function digest(file) {
|
|
63
85
|
const key = resolve(file);
|
|
@@ -66,10 +88,86 @@ function cachedFiles() {
|
|
|
66
88
|
return hash;
|
|
67
89
|
}
|
|
68
90
|
async function same() {
|
|
69
|
-
|
|
91
|
+
const matches = await Promise.all([...files].map(async ([file, original]) => {
|
|
92
|
+
try {
|
|
93
|
+
const start = await original;
|
|
94
|
+
const end = await fileState(file);
|
|
95
|
+
if ('bytes' in start && 'bytes' in end)
|
|
96
|
+
return start.bytes.equals(end.bytes);
|
|
97
|
+
return 'lock' in start && 'lock' in end && start.lock === end.lock;
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
}));
|
|
103
|
+
return matches.every(Boolean);
|
|
70
104
|
}
|
|
71
105
|
return { read, digest, same, has: (file) => files.has(file) };
|
|
72
106
|
}
|
|
107
|
+
/** The resolver reads manifests and config even though they need not be bundle inputs. */
|
|
108
|
+
export async function resolutionSettings(root, files, deps) {
|
|
109
|
+
const checked = new Set();
|
|
110
|
+
const manifests = new Set();
|
|
111
|
+
for (const file of files) {
|
|
112
|
+
for (let dir = dirname(file); pathIn(root, dir) && !checked.has(dir); dir = dirname(dir)) {
|
|
113
|
+
checked.add(dir);
|
|
114
|
+
for (const name of ['package.json', 'tsconfig.json', 'jsconfig.json']) {
|
|
115
|
+
const path = join(dir, name);
|
|
116
|
+
if (existsSync(path))
|
|
117
|
+
manifests.add(path);
|
|
118
|
+
}
|
|
119
|
+
if (dir === root)
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
const resolveConfig = createRequire(join(root, 'package.json'));
|
|
124
|
+
for (const file of manifests) {
|
|
125
|
+
if (file.endsWith('package.json'))
|
|
126
|
+
continue;
|
|
127
|
+
const config = JSON.parse(withoutComments((await deps.read(file)).toString('utf8')));
|
|
128
|
+
const extendsList = [config.extends ?? []].flat();
|
|
129
|
+
for (const name of extendsList) {
|
|
130
|
+
if (typeof name !== 'string')
|
|
131
|
+
throw new Error();
|
|
132
|
+
const extension = name.startsWith('.')
|
|
133
|
+
? [resolve(dirname(file), name), resolve(dirname(file), `${name}.json`)].find((path) => statSync(path, { throwIfNoEntry: false })?.isFile())
|
|
134
|
+
: resolveConfig.resolve(name, { paths: [dirname(file)] });
|
|
135
|
+
if (!extension)
|
|
136
|
+
throw new Error();
|
|
137
|
+
if (manifests.size >= 2000)
|
|
138
|
+
throw new Error();
|
|
139
|
+
manifests.add(extension);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return Promise.all([...manifests]
|
|
143
|
+
.sort()
|
|
144
|
+
.map(async (file) => [slash(relative(root, file)), await deps.digest(file)]));
|
|
145
|
+
}
|
|
146
|
+
const EXTENSIONS = ['mjs', 'js', 'mts', 'ts', 'jsx', 'tsx', 'cjs', 'cts', 'json', 'css'];
|
|
147
|
+
/** Include competing paths if the stock bundlers may prioritize them differently. */
|
|
148
|
+
export function resolutionAlternatives(importer, spec, target) {
|
|
149
|
+
const ext = extname(target).slice(1);
|
|
150
|
+
if (!EXTENSIONS.includes(ext))
|
|
151
|
+
return [];
|
|
152
|
+
const address = spec?.startsWith('.') ? resolve(dirname(importer), spec) : undefined;
|
|
153
|
+
if (address === target)
|
|
154
|
+
return [];
|
|
155
|
+
const base = address ?? target.slice(0, -ext.length - 1);
|
|
156
|
+
const stem = base.replace(/\.(?:web|native)$/, '');
|
|
157
|
+
return [stem, join(stem, 'index')]
|
|
158
|
+
.flatMap((path) => EXTENSIONS.flatMap((extension) => ['', '.web', '.native'].map((platform) => `${path + platform}.${extension}`)))
|
|
159
|
+
.concat(join(stem, 'package.json'))
|
|
160
|
+
.filter((path) => path !== target && statSync(path, { throwIfNoEntry: false })?.isFile());
|
|
161
|
+
}
|
|
162
|
+
/** esbuild's input graph can list external TS type imports even though no JS loads them. */
|
|
163
|
+
export async function runtimeExternal(path, specifiers, read) {
|
|
164
|
+
const loader = loaders[extname(path).toLowerCase()];
|
|
165
|
+
if (loader !== 'ts' && loader !== 'tsx')
|
|
166
|
+
return true;
|
|
167
|
+
const source = (await read(path)).toString('utf8');
|
|
168
|
+
const { code } = await transform(source, { loader, jsx: 'automatic' });
|
|
169
|
+
return specifiers.some((name) => !/^[\w@/.\-:#]+$/.test(name) || code.includes(JSON.stringify(name)));
|
|
170
|
+
}
|
|
73
171
|
function collectDependencies(root, catalog, files) {
|
|
74
172
|
const assets = new Map();
|
|
75
173
|
function assetPaths(path) {
|
|
@@ -85,7 +183,7 @@ function collectDependencies(root, catalog, files) {
|
|
|
85
183
|
}
|
|
86
184
|
return cached;
|
|
87
185
|
}
|
|
88
|
-
|
|
186
|
+
const broad = async (entry, selected, unproven) => {
|
|
89
187
|
// The registry and roots count even when their output has zero bytes.
|
|
90
188
|
const dependencies = new Set([entry.registry, ...entry.roots]);
|
|
91
189
|
if (files.has(catalog))
|
|
@@ -107,8 +205,8 @@ function collectDependencies(root, catalog, files) {
|
|
|
107
205
|
.sort()
|
|
108
206
|
.map(async (file) => [slash(relative(root, file)), await files.digest(file)]));
|
|
109
207
|
};
|
|
208
|
+
return { broad, assetPaths };
|
|
110
209
|
}
|
|
111
|
-
/** Hash the same bytes esbuild reads, sharing file reads across surfaces. */
|
|
112
210
|
export function snapshotDependencies(root, catalog) {
|
|
113
211
|
const files = cachedFiles();
|
|
114
212
|
const collect = collectDependencies(root, catalog, files);
|
|
@@ -121,14 +219,22 @@ export function snapshotDependencies(root, catalog) {
|
|
|
121
219
|
if (!selected ||
|
|
122
220
|
result.warnings.some((warning) => unresolved(root, warning, selected, ignored)))
|
|
123
221
|
return;
|
|
124
|
-
|
|
222
|
+
const hashes = await collect.broad(entry, selected, unproven);
|
|
223
|
+
if (hashes && result.metafile)
|
|
224
|
+
return { files: hashes, meta: result.metafile, selected, unproven };
|
|
125
225
|
}
|
|
126
226
|
catch {
|
|
127
227
|
// esbuild could not establish this surface's inputs. Draw its scenes.
|
|
128
228
|
return;
|
|
129
229
|
}
|
|
130
230
|
}
|
|
131
|
-
return {
|
|
231
|
+
return {
|
|
232
|
+
read: files.read,
|
|
233
|
+
digest: files.digest,
|
|
234
|
+
same: files.same,
|
|
235
|
+
walk,
|
|
236
|
+
assets: collect.assetPaths,
|
|
237
|
+
};
|
|
132
238
|
}
|
|
133
239
|
/** esbuild does not expand bundler-specific loaders or read files named by new URL(). */
|
|
134
240
|
function runtimeAssets(source, loader) {
|
|
@@ -2,3 +2,10 @@ export declare const sha256: (value: string | Buffer) => string;
|
|
|
2
2
|
export declare const sha256Pattern: RegExp;
|
|
3
3
|
/** Only values that survive a JSON round trip can identify results from an earlier run. */
|
|
4
4
|
export declare function plainData(value: unknown, ancestors?: Set<object>): boolean;
|
|
5
|
+
/**
|
|
6
|
+
* A scene as data for the progress journal: each function in it stands for its source text, which
|
|
7
|
+
* the journal's pinned source tree already holds (a handler such as `onPress` is never called while
|
|
8
|
+
* a picture is drawn). Anything else that is not plain (a class instance, an accessor, a cycle) is
|
|
9
|
+
* left as it is, so `plainData` still refuses it; so is a bound or built-in function.
|
|
10
|
+
*/
|
|
11
|
+
export declare function sceneData(value: unknown, ancestors?: Set<object>): unknown;
|
|
@@ -25,3 +25,31 @@ export function plainData(value, ancestors = new Set()) {
|
|
|
25
25
|
ancestors.delete(value);
|
|
26
26
|
return plain;
|
|
27
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* A scene as data for the progress journal: each function in it stands for its source text, which
|
|
30
|
+
* the journal's pinned source tree already holds (a handler such as `onPress` is never called while
|
|
31
|
+
* a picture is drawn). Anything else that is not plain (a class instance, an accessor, a cycle) is
|
|
32
|
+
* left as it is, so `plainData` still refuses it; so is a bound or built-in function.
|
|
33
|
+
*/
|
|
34
|
+
export function sceneData(value, ancestors = new Set()) {
|
|
35
|
+
if (typeof value === 'function') {
|
|
36
|
+
const source = String(value);
|
|
37
|
+
// A bound or built-in function has no source to tell two apart.
|
|
38
|
+
return source.includes('[native code]') ? value : { function: source };
|
|
39
|
+
}
|
|
40
|
+
if (typeof value !== 'object' || value === null || ancestors.has(value))
|
|
41
|
+
return value;
|
|
42
|
+
const array = Array.isArray(value);
|
|
43
|
+
if (Object.getPrototypeOf(value) !== (array ? Array.prototype : Object.prototype))
|
|
44
|
+
return value;
|
|
45
|
+
const fields = Object.getOwnPropertyDescriptors(value);
|
|
46
|
+
const keys = Reflect.ownKeys(fields).filter((key) => !array || key !== 'length');
|
|
47
|
+
if (keys.some((key) => typeof key !== 'string' || !fields[key]?.enumerable || !('value' in fields[key])))
|
|
48
|
+
return value;
|
|
49
|
+
ancestors.add(value);
|
|
50
|
+
const copy = array
|
|
51
|
+
? value.map((item) => sceneData(item, ancestors))
|
|
52
|
+
: Object.fromEntries(keys.map((key) => [key, sceneData(fields[key]?.value, ancestors)]));
|
|
53
|
+
ancestors.delete(value);
|
|
54
|
+
return copy;
|
|
55
|
+
}
|
|
@@ -1,11 +1,20 @@
|
|
|
1
|
-
import type { Scene } from '@buffcore/config';
|
|
1
|
+
import type { Scene, Surface } from '@buffcore/config';
|
|
2
2
|
import type { Run } from './scene.ts';
|
|
3
|
+
import type { RequestCoverage } from './snapshot-requests.ts';
|
|
3
4
|
export interface SnapshotInputs {
|
|
5
|
+
/** Broad binding for completing or resuming the same run. */
|
|
4
6
|
fingerprints: ReadonlyMap<string, string>;
|
|
7
|
+
/** Each scene's own fingerprint: the files its view imports and the shared parts (F113d). */
|
|
8
|
+
reuse: ReadonlyMap<string, string>;
|
|
9
|
+
/** What every scene's picture depends on beyond its own surface (public values, settings, tools). */
|
|
10
|
+
shared?: string;
|
|
11
|
+
/** The inputs every scene shares (F113c), once compared: a change draws the full matrix. */
|
|
12
|
+
parts?(): string | undefined;
|
|
13
|
+
/** Each readable surface's own inputs: its settings and the files its views load. */
|
|
14
|
+
surfaces?: ReadonlyMap<Surface, string>;
|
|
5
15
|
same(): Promise<boolean>;
|
|
6
|
-
|
|
16
|
+
coversRequest: RequestCoverage;
|
|
17
|
+
prepare: (launch?: (scenes: readonly Scene[]) => Promise<void>) => Promise<void>;
|
|
18
|
+
runtime(force?: boolean, surface?: Surface): string | undefined;
|
|
7
19
|
}
|
|
8
|
-
|
|
9
|
-
export declare function snapshotInputs(root: string, scenes: readonly Scene[], run: Run, browser: () => Promise<string>, design?: string,
|
|
10
|
-
/** What the fingerprint reads public values from: the process's, or a linked run's own. */
|
|
11
|
-
environment?: Record<string, string | undefined>): Promise<SnapshotInputs>;
|
|
20
|
+
export declare function snapshotInputs(root: string, scenes: readonly Scene[], run: Run, browser: () => Promise<string>, design?: string, environment?: Record<string, string | undefined>): Promise<SnapshotInputs>;
|
|
@@ -1,216 +1,171 @@
|
|
|
1
|
-
import { existsSync
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { SURFACES } from '@buffcore/config';
|
|
5
|
-
import { pageOptions } from './browser.js';
|
|
6
|
-
import { surfaceDir } from './export.js';
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { dirname, join, resolve } from 'node:path';
|
|
3
|
+
import { SURFACES, sceneUrl } from '@buffcore/config';
|
|
7
4
|
import { locale } from './messages.js';
|
|
8
|
-
import {
|
|
9
|
-
import { isStock } from './milestone-stock.js';
|
|
10
|
-
import { loaders } from './snapshot-bundle.js';
|
|
11
|
-
import { dependencyVersion, snapshotDependencies } from './snapshot-dependencies.js';
|
|
5
|
+
import { dependencyVersion, pathIn, snapshotDependencies } from './snapshot-dependencies.js';
|
|
12
6
|
import { plainData, sha256 } from './snapshot-hashes.js';
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
'full-shot',
|
|
19
|
-
'measure',
|
|
20
|
-
'media-ready',
|
|
21
|
-
'module-errors',
|
|
22
|
-
'readable',
|
|
23
|
-
'scene',
|
|
24
|
-
'scene-check',
|
|
25
|
-
'scene-load',
|
|
26
|
-
'scene-look',
|
|
27
|
-
'scene-ready',
|
|
28
|
-
'scene-render',
|
|
29
|
-
'snapshot-recovery',
|
|
30
|
-
'snapshot-requests',
|
|
31
|
-
'snapshot-themes',
|
|
32
|
-
];
|
|
33
|
-
const SURFACE_ROOTS = {
|
|
34
|
-
admin: ['src/main.tsx', 'src/prototype/index.tsx'],
|
|
35
|
-
app: ['src/app/_scene.tsx', 'src/app/_layout.tsx', 'src/prototype/scene.tsx', 'src/fonts.ts'],
|
|
36
|
-
};
|
|
37
|
-
const SETTINGS = [
|
|
38
|
-
'package.json',
|
|
39
|
-
'tsconfig.json',
|
|
40
|
-
'jsconfig.json',
|
|
41
|
-
'app.json',
|
|
42
|
-
'index.html',
|
|
43
|
-
'public/console.json',
|
|
44
|
-
'.env',
|
|
45
|
-
'.env.local',
|
|
46
|
-
'.env.development',
|
|
47
|
-
'.env.development.local',
|
|
48
|
-
];
|
|
49
|
-
const existing = (dir, paths) => paths.map((path) => join(dir, path)).filter(existsSync);
|
|
50
|
-
const TOOLCHAINS = ['vite.config', 'metro.config', 'babel.config', 'postcss.config', 'app.config']
|
|
51
|
-
.flatMap((name) => ['ts', 'js', 'mts', 'mjs', 'cts', 'cjs'].map((ext) => `${name}.${ext}`))
|
|
52
|
-
.concat(['.babelrc', '.babelrc.json', '.postcssrc', '.postcssrc.json']);
|
|
53
|
-
// The in-repository dev configs use the same resolvers as the product templates.
|
|
54
|
-
const BUNDLED_TOOLCHAINS = {
|
|
55
|
-
'apps/admin/vite.config.ts': '0fe0ec6d310d92e37ab052f230ecb6b9ff7a19241061300eebf85920018a6638',
|
|
56
|
-
'apps/app/metro.config.js': 'd2261b4852313fdf42fa63d97d162c691cc89757df4de8ecdff1d8bac939b117',
|
|
57
|
-
'apps/app/babel.config.js': '51ba161016afa8ae07b41bb4305f1c6e71ff30d007e58fbebe0cf383bbce67c0',
|
|
58
|
-
};
|
|
59
|
-
/** esbuild can model the shipped surface configuration. A product loader may resolve differently. */
|
|
60
|
-
async function toolchains(dir, surface, read) {
|
|
61
|
-
try {
|
|
62
|
-
const files = existing(dir, TOOLCHAINS);
|
|
63
|
-
for (const file of files) {
|
|
64
|
-
const name = `apps/${surface}/${relative(dir, file)}`;
|
|
65
|
-
const text = (await read(file)).toString('utf8').replaceAll('\r\n', '\n');
|
|
66
|
-
if (!isStock(name, text) && BUNDLED_TOOLCHAINS[name] !== sha256(text))
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
return files;
|
|
70
|
-
}
|
|
71
|
-
catch {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
/** A product inside a workspace uses the enclosing lockfile when it has none of its own. */
|
|
76
|
-
function lockfile(root) {
|
|
77
|
-
for (let dir = root;; dir = dirname(dir)) {
|
|
78
|
-
const files = existing(dir, ['pnpm-lock.yaml', 'package-lock.json', 'yarn.lock']);
|
|
79
|
-
if (files.length || dirname(dir) === dir)
|
|
80
|
-
return files;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
const publicEnvironment = (env) => Object.entries(env)
|
|
84
|
-
.filter(([key]) => /^(VITE_|EXPO_PUBLIC_)/.test(key))
|
|
85
|
-
.sort();
|
|
86
|
-
async function settingHashes(root, files, dependencies) {
|
|
87
|
-
return Promise.all(files.map(async (file) => {
|
|
88
|
-
const name = relative(root, file);
|
|
89
|
-
if (!/^\.env(?:\.|$)/.test(basename(file)))
|
|
90
|
-
return [name, await dependencies.digest(file)];
|
|
91
|
-
await dependencies.digest(file);
|
|
92
|
-
const environment = publicEnvironment(parseEnv((await dependencies.read(file)).toString('utf8')));
|
|
93
|
-
if (environment.some(([, value]) => value?.includes('$')))
|
|
94
|
-
throw new Error();
|
|
95
|
-
return [name, sha256(JSON.stringify(environment))];
|
|
96
|
-
}));
|
|
97
|
-
}
|
|
98
|
-
/** The design system's font files the console serves under `_fonts/`, as its Vite plugin lists them. */
|
|
99
|
-
function designFonts(root) {
|
|
100
|
-
const dir = join(root, 'design', 'fonts');
|
|
101
|
-
try {
|
|
102
|
-
return readdirSync(dir, { withFileTypes: true })
|
|
103
|
-
.filter((entry) => entry.isFile() && /\.(?:woff2?|ttf|otf)$/i.test(entry.name))
|
|
104
|
-
.map((entry) => join(dir, entry.name))
|
|
105
|
-
.sort();
|
|
106
|
-
}
|
|
107
|
-
catch {
|
|
108
|
-
return [];
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
/** The HTML can load public fonts or images without a JavaScript import. */
|
|
112
|
-
async function pageAssets(dir, read) {
|
|
113
|
-
const page = join(dir, 'index.html');
|
|
114
|
-
if (!existsSync(page))
|
|
115
|
-
return [];
|
|
116
|
-
const links = references('page', (await read(page)).toString('utf8'), page);
|
|
117
|
-
if (typeof links === 'string')
|
|
118
|
-
throw new Error();
|
|
119
|
-
const publicDir = join(dir, 'public');
|
|
120
|
-
return links.flatMap(([kind, url]) => {
|
|
121
|
-
if (kind !== 'page' || /^(?:[\w+.-]+:|\/\/|#)/.test(url))
|
|
122
|
-
return [];
|
|
123
|
-
const file = resolve(publicDir, decodeURIComponent(url.split(/[?#]/, 1)[0] ?? '').replace(/^\//, ''));
|
|
124
|
-
const path = relative(publicDir, file);
|
|
125
|
-
if (isAbsolute(path) || path === '..' || path.startsWith(`..${sep}`))
|
|
126
|
-
return [];
|
|
127
|
-
return loaders[extname(file).toLowerCase()] === 'file' && existsSync(file) ? [file] : [];
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
async function surfaceEntry(root, surface, dependencies) {
|
|
131
|
-
const dir = surfaceDir(root, surface);
|
|
132
|
-
const registry = dir && join(dir, 'src', 'prototype', 'views.ts');
|
|
133
|
-
if (!dir || !registry || !existsSync(registry))
|
|
134
|
-
return;
|
|
135
|
-
const configuration = await toolchains(dir, surface, dependencies.read);
|
|
136
|
-
if (!configuration)
|
|
137
|
-
return;
|
|
138
|
-
const page = await pageAssets(dir, dependencies.read).catch(() => undefined);
|
|
139
|
-
if (!page)
|
|
140
|
-
return;
|
|
141
|
-
const assets = [...page, ...(surface === 'admin' ? designFonts(root) : [])];
|
|
142
|
-
const entry = {
|
|
143
|
-
surface,
|
|
144
|
-
dir,
|
|
145
|
-
registry,
|
|
146
|
-
roots: [...existing(dir, SURFACE_ROOTS[surface]), ...existing(root, ['design/theme.ts'])],
|
|
147
|
-
};
|
|
148
|
-
const settings = await settingHashes(root, [...existing(dir, SETTINGS), ...configuration, ...assets], dependencies).catch(() => undefined);
|
|
149
|
-
if (settings)
|
|
150
|
-
return { entry, settings, assets };
|
|
151
|
-
}
|
|
152
|
-
function hasSurfaceAsset(surface, url) {
|
|
153
|
-
if (!surface)
|
|
154
|
-
return false;
|
|
155
|
-
const path = decodeURIComponent(url.pathname);
|
|
156
|
-
const { fonts } = surface;
|
|
157
|
-
if (fonts && path.startsWith(fonts.path))
|
|
158
|
-
return surface.assets.has(join(fonts.dir, path.slice(fonts.path.length)));
|
|
159
|
-
if (path.startsWith('/@fs/'))
|
|
160
|
-
return surface.assets.has(resolve(path.slice(5)));
|
|
161
|
-
const metroAsset = url.searchParams.get('unstable_path');
|
|
162
|
-
if (path === '/assets/' && metroAsset)
|
|
163
|
-
return surface.assets.has(resolve(surface.dir, metroAsset));
|
|
164
|
-
return (surface.assets.has(resolve(surface.dir, `.${path}`)) ||
|
|
165
|
-
surface.assets.has(resolve(surface.dir, 'public', `.${path}`)));
|
|
166
|
-
}
|
|
7
|
+
import { metroInputs } from './snapshot-metro-inputs.js';
|
|
8
|
+
import { sceneCandidates, sceneGraph, scenePage } from './snapshot-scene-inputs.js';
|
|
9
|
+
import { matchesBytes } from './snapshot-served-inputs.js';
|
|
10
|
+
import { designFont, lockfile, publicEnvironment, sharedSettings, surfaceEntry, } from './snapshot-surface-inputs.js';
|
|
11
|
+
import { surfaceFile, viteRequests } from './snapshot-vite-inputs.js';
|
|
167
12
|
/** The console's `_fonts/` under the base its address names (`/`, or `/s/abc/`). */
|
|
168
13
|
function fontPath(address) {
|
|
169
14
|
const base = decodeURIComponent(URL.parse(address)?.pathname ?? '/');
|
|
170
15
|
return `${base.endsWith('/') ? base : `${base}/`}_fonts/`;
|
|
171
16
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
const
|
|
17
|
+
export async function snapshotInputs(root, scenes, run, browser, design, environment = process.env) {
|
|
18
|
+
let version;
|
|
19
|
+
const browserVersion = async () => (version ??= await browser());
|
|
20
|
+
const read = () => readInputs(root, scenes, run, browserVersion, design, environment);
|
|
21
|
+
const start = await read();
|
|
22
|
+
return {
|
|
23
|
+
...start,
|
|
24
|
+
async same() {
|
|
25
|
+
// A fresh walk sees added resolution candidates and settings that were absent at the start.
|
|
26
|
+
return (await start.same()) && start.signature() === (await read()).signature();
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
async function readInputs(root, scenes, run, browser, design, environment) {
|
|
31
|
+
const catalog = join(root, 'prototype', 'scenes.ts');
|
|
32
|
+
const dependencies = snapshotDependencies(root, catalog);
|
|
33
|
+
const catalogBytes = existsSync(catalog) && (await dependencies.digest(catalog));
|
|
177
34
|
const inputs = new Map();
|
|
178
35
|
const fingerprints = new Map();
|
|
36
|
+
const surfaces = new Map();
|
|
37
|
+
const candidates = sceneCandidates(root, scenes, run, dependencies);
|
|
38
|
+
let metro;
|
|
39
|
+
const probes = [];
|
|
179
40
|
const result = {
|
|
180
41
|
fingerprints,
|
|
181
|
-
|
|
182
|
-
|
|
42
|
+
surfaces,
|
|
43
|
+
reuse: candidates.reuse,
|
|
44
|
+
parts: () => candidates.parts,
|
|
45
|
+
signature: () => JSON.stringify([[...fingerprints], candidates.signature, catalogBytes]),
|
|
46
|
+
same: async () => (await dependencies.same()) &&
|
|
47
|
+
(await metro?.same()) !== false &&
|
|
48
|
+
(await inputs.get('admin')?.vite?.same()) !== false,
|
|
49
|
+
runtime: (force, surface) => {
|
|
50
|
+
const app = metro?.hash();
|
|
51
|
+
if (surface === 'app')
|
|
52
|
+
return app;
|
|
53
|
+
const vite = inputs.get('admin')?.vite?.hash(force);
|
|
54
|
+
if (surface === 'admin')
|
|
55
|
+
return vite;
|
|
56
|
+
return app ? sha256(JSON.stringify([vite, app])) : vite;
|
|
57
|
+
},
|
|
58
|
+
coversRequest: (async (scene, url, kind, response) => {
|
|
59
|
+
const surface = inputs.get(scene.surface);
|
|
60
|
+
const assets = candidates.assets.get(scene.key);
|
|
61
|
+
if (!surface || !assets)
|
|
62
|
+
return false;
|
|
63
|
+
if (scene.surface === 'app' && metro && ['document', 'websocket'].includes(kind))
|
|
64
|
+
return metro.covers(url, kind, response);
|
|
65
|
+
if (kind === 'document') {
|
|
66
|
+
if (url.pathname !== '/_scene')
|
|
67
|
+
return false;
|
|
68
|
+
return (surface.vite?.tracks(url, kind, response) ?? matchesBytes(surface.document, response));
|
|
69
|
+
}
|
|
70
|
+
if (metro && scene.surface === 'app' && url.pathname === '/assets/') {
|
|
71
|
+
const path = url.searchParams.get('unstable_path');
|
|
72
|
+
const file = path && resolve(surface.dir, path);
|
|
73
|
+
if (!file || url.searchParams.size !== 1 || !assets.has(file))
|
|
74
|
+
return false;
|
|
75
|
+
return matchesBytes(await dependencies.digest(file), response);
|
|
76
|
+
}
|
|
77
|
+
const font = surface.fonts && designFont(root, surface.fonts, url, assets);
|
|
78
|
+
if (font)
|
|
79
|
+
return matchesBytes(await dependencies.digest(font), response);
|
|
80
|
+
const file = kind !== 'websocket' && surfaceFile(surface.dir, url, assets);
|
|
81
|
+
if (file) {
|
|
82
|
+
if (surface.vite &&
|
|
83
|
+
['script', 'stylesheet'].includes(kind) &&
|
|
84
|
+
!pathIn(join(surface.dir, 'public'), file))
|
|
85
|
+
return !!response?.ok();
|
|
86
|
+
return matchesBytes(await dependencies.digest(file), response);
|
|
87
|
+
}
|
|
88
|
+
if (scene.surface === 'app')
|
|
89
|
+
return metro?.covers(url, kind, response) ?? false;
|
|
90
|
+
if (kind === 'script' && !response?.ok())
|
|
91
|
+
return false;
|
|
92
|
+
return surface.vite?.tracks(url, kind, response) ?? false;
|
|
93
|
+
}),
|
|
94
|
+
async prepare(launch) {
|
|
95
|
+
if (!probes.length)
|
|
96
|
+
return;
|
|
97
|
+
await launch?.(probes.map(({ scene }) => scene));
|
|
98
|
+
await Promise.all(probes.map(async ({ scene, read, hash }) => {
|
|
99
|
+
await read();
|
|
100
|
+
if (!hash())
|
|
101
|
+
for (const candidate of scenes)
|
|
102
|
+
if (candidate.surface === scene.surface)
|
|
103
|
+
candidates.reuse.delete(candidate.key);
|
|
104
|
+
}));
|
|
105
|
+
},
|
|
183
106
|
};
|
|
184
107
|
for (const surface of new Set(scenes.map((scene) => scene.surface))) {
|
|
108
|
+
if (surface === 'app' && environment.EXPO_METRO_NO_MAIN_FIELD_OVERRIDE)
|
|
109
|
+
continue;
|
|
185
110
|
const setup = await surfaceEntry(root, surface, dependencies);
|
|
186
111
|
if (!setup)
|
|
187
112
|
continue;
|
|
188
|
-
const
|
|
189
|
-
if (
|
|
113
|
+
const walked = await dependencies.walk(setup.entry);
|
|
114
|
+
if (walked) {
|
|
115
|
+
const graph = await sceneGraph(root, catalog, setup.entry, walked, dependencies, run.locales, !!setup.vite);
|
|
116
|
+
const first = scenes.find((scene) => scene.surface === surface);
|
|
117
|
+
// An owned server fills its address during launch, after the graph is resolved.
|
|
118
|
+
const page = new URL('http://127.0.0.1');
|
|
119
|
+
const readAfterLaunch = (read) => async () => {
|
|
120
|
+
if (!first)
|
|
121
|
+
return;
|
|
122
|
+
page.href = sceneUrl(run.urls[surface], first.key, {
|
|
123
|
+
theme: run.product,
|
|
124
|
+
mode: 'light',
|
|
125
|
+
locale: run.first,
|
|
126
|
+
});
|
|
127
|
+
return read();
|
|
128
|
+
};
|
|
129
|
+
const vite = setup.vite &&
|
|
130
|
+
graph &&
|
|
131
|
+
viteRequests(setup.entry.dir, setup.vite.runtime, new Set(graph.setup.map(([file]) => resolve(root, file))), new Set(setup.assets), setup.vite.files, page);
|
|
190
132
|
inputs.set(surface, {
|
|
191
133
|
dir: setup.entry.dir,
|
|
192
|
-
hash: sha256(JSON.stringify([setup.settings, files])),
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
134
|
+
hash: sha256(JSON.stringify([setup.settings, walked.files])),
|
|
135
|
+
graph,
|
|
136
|
+
vite,
|
|
137
|
+
whole: setup.metro,
|
|
138
|
+
document: setup.document,
|
|
139
|
+
settings: setup.settings,
|
|
140
|
+
pageAssets: setup.assets,
|
|
141
|
+
...(surface === 'admin' && { fonts: fontPath(run.urls.admin) }),
|
|
197
142
|
});
|
|
143
|
+
if (first && vite)
|
|
144
|
+
probes.push({ scene: first, read: readAfterLaunch(vite.prepare), hash: vite.proof });
|
|
145
|
+
if (setup.metro && graph && first) {
|
|
146
|
+
metro = metroInputs(setup.entry.dir, dirname(lockfile(root)[0] ?? join(root, 'package.json')), page);
|
|
147
|
+
probes.push({ scene: first, read: readAfterLaunch(metro.prepare), hash: metro.hash });
|
|
148
|
+
}
|
|
149
|
+
}
|
|
198
150
|
}
|
|
199
|
-
|
|
151
|
+
for (const [surface, { hash }] of inputs)
|
|
152
|
+
surfaces.set(surface, hash);
|
|
153
|
+
if (!scenes.length)
|
|
200
154
|
return result;
|
|
201
155
|
const common = await sharedSettings(root, dependencies).catch(() => undefined);
|
|
202
156
|
if (!common)
|
|
203
157
|
return result;
|
|
204
158
|
const shared = sharedFingerprint(run, await browser(), common, design, environment);
|
|
159
|
+
result.shared = shared;
|
|
160
|
+
if (!inputs.size)
|
|
161
|
+
return result;
|
|
162
|
+
await candidates.compare(inputs, shared);
|
|
205
163
|
for (const scene of scenes) {
|
|
206
164
|
const surface = inputs.get(scene.surface);
|
|
207
165
|
if (!surface || typeof scene.view !== 'string' || !plainData(scene))
|
|
208
166
|
continue;
|
|
209
|
-
// Each scene holds its own frame's size
|
|
210
|
-
|
|
211
|
-
const { width, height } = run.frames[scene.frame];
|
|
212
|
-
const page = pageOptions({ width, height });
|
|
213
|
-
fingerprints.set(scene.key, sha256(JSON.stringify([shared, surface.hash, scene, page])));
|
|
167
|
+
// Each scene holds its own frame's size: a new desktop frame re-shoots only its scenes.
|
|
168
|
+
fingerprints.set(scene.key, sha256(JSON.stringify([shared, surface.hash, scene, scenePage(run, scene)])));
|
|
214
169
|
}
|
|
215
170
|
return result;
|
|
216
171
|
}
|
|
@@ -220,7 +175,7 @@ environment = process.env) {
|
|
|
220
175
|
*/
|
|
221
176
|
function sharedFingerprint(run, browser, common, design, environment) {
|
|
222
177
|
return sha256(JSON.stringify([
|
|
223
|
-
'snapshot-inputs-
|
|
178
|
+
'snapshot-inputs-v5',
|
|
224
179
|
dependencyVersion,
|
|
225
180
|
browser,
|
|
226
181
|
run.looks,
|
|
@@ -236,15 +191,3 @@ function sharedFingerprint(run, browser, common, design, environment) {
|
|
|
236
191
|
common,
|
|
237
192
|
]));
|
|
238
193
|
}
|
|
239
|
-
async function sharedSettings(root, dependencies) {
|
|
240
|
-
const ext = import.meta.url.endsWith('.ts') ? '.ts' : '.js';
|
|
241
|
-
const checks = [...CHECKS.map((name) => name + ext), 'drawn-text.js'];
|
|
242
|
-
// The root `.env` is not a file input: `loadEnv` puts its values into the environment the
|
|
243
|
-
// fingerprint reads, so main (which has one) and a worktree (which has none) agree.
|
|
244
|
-
const settings = SETTINGS.filter((name) => !name.startsWith('.env'));
|
|
245
|
-
const files = [...existing(root, [...settings, 'buffcore.config.ts']), ...lockfile(root)];
|
|
246
|
-
return Promise.all([
|
|
247
|
-
Promise.all(checks.map((file) => dependencies.digest(resolve(import.meta.dirname, file)))),
|
|
248
|
-
settingHashes(root, files, dependencies),
|
|
249
|
-
]);
|
|
250
|
-
}
|