@whzxc/agent-design-gallery 0.9.0 → 0.10.0
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/README.md +16 -0
- package/package.json +4 -1
- package/src/cli-output.mjs +25 -1
- package/src/cli.mjs +40 -8
- package/src/toolkit/arch-git.mjs +19 -0
- package/src/toolkit/build-store.mjs +5 -3
- package/src/toolkit/build-worker.mjs +5 -2
- package/src/toolkit/build.mjs +11 -5
- package/src/toolkit/commands.mjs +26 -15
- package/src/toolkit/config.mjs +6 -5
- package/src/toolkit/diff-inputs.mjs +5 -5
- package/src/toolkit/diff.mjs +14 -10
- package/src/toolkit/frame-document.mjs +6 -0
- package/src/toolkit/impact-eligibility.mjs +136 -0
- package/src/toolkit/impact-inputs.mjs +71 -0
- package/src/toolkit/impact-output.mjs +46 -0
- package/src/toolkit/impact-proof.mjs +67 -0
- package/src/toolkit/impact-selection.mjs +96 -0
- package/src/toolkit/impact.mjs +403 -0
- package/src/toolkit/implementation-query.mjs +53 -0
- package/src/toolkit/owner.mjs +4 -41
- package/src/toolkit/project-index.mjs +79 -18
- package/src/toolkit/results.mjs +2 -2
- package/src/toolkit/token-reachability.mjs +71 -0
package/README.md
CHANGED
|
@@ -106,6 +106,12 @@ adg check --read-only
|
|
|
106
106
|
adg diff --base=HEAD --json
|
|
107
107
|
adg owner --file=ui/controls.tsx --symbol=Button --json
|
|
108
108
|
adg owner --text="Save changes" --locale=en --json
|
|
109
|
+
adg impact --source=design/components/badge.tsx --part=Badge --json
|
|
110
|
+
adg impact --token=--accent --json
|
|
111
|
+
adg impact --base=HEAD --json
|
|
112
|
+
adg render --impacted --base=HEAD --json
|
|
113
|
+
adg check --impacted --base=HEAD --read-only --json
|
|
114
|
+
adg diff --base=HEAD --impacted --json
|
|
109
115
|
```
|
|
110
116
|
|
|
111
117
|
`init` creates tokens, components/modules/surfaces, fixtures/art, editor configuration and ignore entries. A fresh library gets one `example.tsx` per production layer, composed downward with shared fixture data; existing libraries receive no demo sources. Existing authored files are preserved, declarations are refreshed, and missing ignore entries are appended. Starter configuration requires ADG 0.5.0 or newer. `check --read-only` skips declarations and build files for an audit. Projects do not install ADG as a dependency.
|
|
@@ -128,6 +134,16 @@ separate from computed paint. Both themes are searched by default. Broad color/t
|
|
|
128
134
|
answers can be around 100 KB; read `owners` first and narrow with `--theme`. See the
|
|
129
135
|
[owner JSON contract](docs/agent-interface.md#owner) for ranks, evidence and diagnostics.
|
|
130
136
|
|
|
137
|
+
`adg impact` lists conservative direct/transitive frame candidates from sources, parts, tokens,
|
|
138
|
+
implementation mappings or exact Git endpoints. It uses emitted provenance and lexical token
|
|
139
|
+
reachability, with compact optional `--explain` witnesses. Equal theme records and same-source frame records are grouped; noncandidates are counted.
|
|
140
|
+
Git queries freshly materialize both endpoints and prove equivalent closed rendering inputs for
|
|
141
|
+
this operation. Hypothetical queries remain candidate lookups. `render`, `check` and `diff` accept `--impacted --base=<rev>`;
|
|
142
|
+
check reports skipped evaluations as `not_checked` with partial coverage, while unqualified both-theme
|
|
143
|
+
diff counts fresh proofs. Query stdout cannot authorize a later skip. Architecture `render --base`
|
|
144
|
+
produces proposal overlays; `render --impacted --base` captures plain current frames. Zero-job runs
|
|
145
|
+
report zero work. See the [impact contract](docs/agent-interface.md#impact).
|
|
146
|
+
|
|
131
147
|
See the [toolkit contract](docs/design-toolkit.md) for source format and compare adapters, and the [changelog](CHANGELOG.md) for version changes. Node.js executes design modules at build time; open sources you trust.
|
|
132
148
|
|
|
133
149
|
## Architecture sources
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@whzxc/agent-design-gallery",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Local TSX design toolkit and SVG viewer",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -32,8 +32,11 @@
|
|
|
32
32
|
"prepack": "node tooling/package.mjs"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
+
"css-tree": "3.1.0",
|
|
36
|
+
"entities": "9.0.0",
|
|
35
37
|
"esbuild": "0.28.2",
|
|
36
38
|
"lucide": "1.70.0",
|
|
39
|
+
"parse5": "8.1.1",
|
|
37
40
|
"pele": "1.12.0",
|
|
38
41
|
"playwright": "1.64.1",
|
|
39
42
|
"tailwindcss": "4.3.4"
|
package/src/cli-output.mjs
CHANGED
|
@@ -20,6 +20,8 @@ export const errorCatalog = {
|
|
|
20
20
|
OWNER_INPUT_NOT_FOUND: [2, 'owner-help', 'Choose an existing in-project file or directory.'],
|
|
21
21
|
OWNER_UNSETTLED: [2, 'owner', 'Stabilize the named frame and resources before repeating the query.'],
|
|
22
22
|
OWNER_INDEX_CHANGED: [2, 'owner', 'Finish concurrent input edits before repeating the query.'],
|
|
23
|
+
IMPACT_INPUT_NOT_FOUND: [2, 'impact-help', 'Choose an existing design input, registered part or declared token.'],
|
|
24
|
+
IMPACT_INPUT_CHANGED: [2, 'impact', 'Finish concurrent input edits before repeating the query.'],
|
|
23
25
|
MIGRATION_REQUIRED: [2, 'migrate', 'Migrate the legacy project.'],
|
|
24
26
|
MIGRATION_CONFLICT: [2, 'migration', 'Inspect migration inputs before resolving the conflict.'],
|
|
25
27
|
VERSION_UNSATISFIED: [2, 'install', 'Install a version satisfying project requires.'],
|
|
@@ -74,7 +76,7 @@ export class CliError extends Error {
|
|
|
74
76
|
}
|
|
75
77
|
|
|
76
78
|
const canonicalCommands = new Set([
|
|
77
|
-
'open', 'link', 'serve', 'root', 'service', 'migrate', 'init', 'check', 'render', 'compare', 'diff', 'owner',
|
|
79
|
+
'open', 'link', 'serve', 'root', 'service', 'migrate', 'init', 'check', 'render', 'compare', 'diff', 'owner', 'impact',
|
|
78
80
|
'root add', 'root remove', 'root list', 'root scan',
|
|
79
81
|
'service install', 'service uninstall', 'service status', 'service logs', 'service migrate',
|
|
80
82
|
'help', 'version', 'adg',
|
|
@@ -110,6 +112,27 @@ export function nextActions(code, context = {}) {
|
|
|
110
112
|
case 'check-help': argv = helpArgv('check'); break;
|
|
111
113
|
case 'render-help': argv = helpArgv('render'); break;
|
|
112
114
|
case 'owner-help': argv = helpArgv('owner'); break;
|
|
115
|
+
case 'impact-help': argv = helpArgv('impact'); break;
|
|
116
|
+
case 'impact': {
|
|
117
|
+
if (['render', 'check', 'diff'].includes(context.command) && context.values?.impacted && typeof context.values.base === 'string') {
|
|
118
|
+
argv = ['adg', context.command, '--impacted'];
|
|
119
|
+
for (const key of ['base', 'frame', 'theme', 'scale', 'out-dir', 'state-dir']) if (typeof context.values[key] === 'string') argv.push(`--${key}=${context.values[key]}`);
|
|
120
|
+
if (context.values['read-only']) argv.push('--read-only');
|
|
121
|
+
if (context.values.explain) argv.push('--explain');
|
|
122
|
+
argv.push('--json');
|
|
123
|
+
if (context.positionals?.length) argv.push('--', ...context.positionals);
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
if (context.command !== 'impact') { argv = helpArgv('impact'); break; }
|
|
127
|
+
const values = context.values ?? {};
|
|
128
|
+
argv = ['adg', 'impact'];
|
|
129
|
+
for (const key of ['source', 'part', 'token', 'file', 'line', 'symbol', 'base', 'head', 'theme', 'state-dir']) {
|
|
130
|
+
const inputs = Array.isArray(values[key]) ? values[key] : typeof values[key] === 'string' ? [values[key]] : [];
|
|
131
|
+
for (const value of inputs) argv.push(`--${key}=${value}`);
|
|
132
|
+
}
|
|
133
|
+
if (values.explain) argv.push('--explain');
|
|
134
|
+
argv.push('--json'); break;
|
|
135
|
+
}
|
|
113
136
|
case 'owner': {
|
|
114
137
|
const values = context.values ?? {};
|
|
115
138
|
if (context.command !== 'owner' || !['file', 'text', 'color', 'token'].some(key => typeof values[key] === 'string' && values[key].trim())) { argv = helpArgv('owner'); break; }
|
|
@@ -139,6 +162,7 @@ export function nextActions(code, context = {}) {
|
|
|
139
162
|
for (const key of ['base', 'frame', 'theme', 'scale', 'out-dir']) {
|
|
140
163
|
if (typeof values[key] === 'string') argv.push(`--${key}=${values[key]}`);
|
|
141
164
|
}
|
|
165
|
+
if (values.impacted) argv.push('--impacted');
|
|
142
166
|
argv.push('--json');
|
|
143
167
|
if (context.positionals?.length) argv.push('--', ...context.positionals);
|
|
144
168
|
break;
|
package/src/cli.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import { realpathSync } from 'node:fs';
|
|
|
6
6
|
import { VERSION, loadConfig } from './toolkit/config.mjs';
|
|
7
7
|
import { CliError, createOutput, withHumanOutput } from './cli-output.mjs';
|
|
8
8
|
|
|
9
|
-
export const commands = ['open', 'link', 'serve', 'root', 'service', 'migrate', 'init', 'check', 'render', 'compare', 'diff', 'owner'];
|
|
9
|
+
export const commands = ['open', 'link', 'serve', 'root', 'service', 'migrate', 'init', 'check', 'render', 'compare', 'diff', 'owner', 'impact'];
|
|
10
10
|
const targetOptions = '[--asset=<path> [--frame=<name>] | --group=<name> | --layer=<name> | --tokens] [--mode=query|path] [--base=<rev>]';
|
|
11
11
|
const usage = {
|
|
12
12
|
open: `[directory] [--port=<n>] [--no-open] [--state-dir=<path>] ${targetOptions}`,
|
|
@@ -14,10 +14,11 @@ const usage = {
|
|
|
14
14
|
serve: '[--port=4310] [--state-dir=<path>] [--print-key | --rotate-key]',
|
|
15
15
|
service: 'install|uninstall|status|logs|migrate [--state-dir=<path>] [--port=4310]',
|
|
16
16
|
root: 'add <dir> [--depth=2] | remove <dir> | list | scan [dir] [--state-dir=<path>]',
|
|
17
|
-
migrate: '[project]', init: '', check: '[source...] [--read-only]', render: '[source...] [--frame=<name>] [--theme=both|light|dark] [--scale=2] [--out-dir=<path>] [--json] [--base=<rev>]',
|
|
17
|
+
migrate: '[project]', init: '', check: '[source...] [--read-only] [--impacted --base=<rev> [--frame=<name>] [--theme=both|light|dark] [--state-dir=<path>] [--explain]]', render: '[source...] [--frame=<name>] [--theme=both|light|dark] [--scale=2] [--out-dir=<path>] [--json] [--base=<rev>] [--impacted [--state-dir=<path>] [--explain]]',
|
|
18
18
|
compare: '<source> --frame=<name> [--fixture=<name>] [--region=<name> | --selector=<css> | --page] [--origin="<x> <y>"] [--click=<name>...] [--viewport=<w>x<h>] | --all',
|
|
19
|
-
diff: '[source...] --base=<rev> [--frame=<name>] [--theme=both|light|dark] [--scale=2] [--out-dir=<path>] [--json]',
|
|
19
|
+
diff: '[source...] --base=<rev> [--frame=<name>] [--theme=both|light|dark] [--scale=2] [--out-dir=<path>] [--json] [--impacted [--state-dir=<path>] [--explain]]',
|
|
20
20
|
owner: '(--file=<path|directory|glob> [--line=<n>] [--symbol=<name>] | --text=<text> [--contains] [--locale=<tag>] | --color=<css> | --token=<name>) [--theme=both|light|dark] [--state-dir=<path>] [--json]',
|
|
21
|
+
impact: '(--source=<path>... [--part=<name>] | --token=<name>... | --file=<path|directory|glob> [--line=<n>] [--symbol=<name>] | --base=<rev> [--head=<rev>]) [--theme=both|light|dark] [--explain] [--state-dir=<path>] [--json]',
|
|
21
22
|
};
|
|
22
23
|
const details = {
|
|
23
24
|
migrate: 'Rename a project configuration and runtime imports, update editor paths and ignore entries, remove old generated files and regenerate declarations. Refuses mixed config names; safe to run again.',
|
|
@@ -26,13 +27,20 @@ const details = {
|
|
|
26
27
|
root: 'Manage registered scan roots. add scans immediately. scan rescans registered roots only; depth is 0 through 3. Hidden directories, node_modules and Git worktrees are skipped.',
|
|
27
28
|
open: 'Browse TSX, Mermaid architecture sources and legacy SVG designs on an independent random-port server.', init: 'Create design sources, tokens and editor configuration without overwriting files.',
|
|
28
29
|
link: 'Print a clean ADG preview URL. Query mode isolates a target. Path mode locates it in the design hierarchy.',
|
|
29
|
-
check: 'Check import direction and every selected frame in both themes. --read-only skips generated types and build files.', render: 'Render selected frames as PNG. Defaults to both themes at 2×. --
|
|
30
|
+
check: 'Check import direction and every selected frame in both themes. --read-only skips generated types and build files. --impacted --base=<rev> evaluates scheduled current rows; proven rows remain not_checked with partial coverage.', render: 'Render selected frames as PNG. Defaults to both themes at 2×. --impacted --base=<rev> captures scheduled plain current frames and reports deletions, with operation-local proofs for skipped rows. Ordinary architecture --base produces proposal overlays; --impacted never does. --json prints completed captures and impact coverage, including zero-job runs.',
|
|
30
31
|
compare: 'Compare fixture text positions. Flags override Frame fixture and capture. --all writes a summary for every fixture frame.',
|
|
31
|
-
diff: 'Compare the Git base and working-tree source/frame union. Existing frames require exact pixels and CSS/device size; added Frame parent declarations enable structural part evidence under diff.thresholds. Defaults to both themes at 2× and <configured output>/diff. Writes before, after and difference PNGs plus report.json. A structural batch requires all existing frames in both themes; source/frame/theme restrictions report partial coverage. Exit 0 identical/structural, 1 changed, 2 incomplete.',
|
|
32
|
+
diff: 'Compare the Git base and working-tree source/frame union. Existing frames require exact pixels and CSS/device size; added Frame parent declarations enable structural part evidence under diff.thresholds. Defaults to both themes at 2× and <configured output>/diff. Writes before, after and difference PNGs plus report.json. --impacted captures only scheduled rows; unqualified both-theme runs count fresh proofs toward full coverage. Required parents/support always capture. A structural batch requires all existing frames in both themes; source/frame/theme restrictions report partial coverage. Exit 0 identical/structural, 1 changed, 2 incomplete.',
|
|
32
33
|
owner: 'Find owning design sources, parts, frames and tokens from an implementation path, rendered text, absolute CSS color or token name. Paths resolve from the project root; quote globs. --line returns the containing export/anchor region, including unmapped exports; non-exported helpers belong to the preceding export. Text is NFC/whitespace normalized and exact unless --contains; --locale filters exact Frame locale annotations without translation. Colors use 8-bit sRGB RGBA equality. Owner evidence is scoped to the query: mappings for files, text runs for text, computed paint for colors and authored references for tokens. Text authoredIn lists literal-search copy candidates; escaped or concatenated strings may be missed. Color evidence may include compact same-element/property references. Defaults to both themes. Broad color/token JSON can be around 100 KB; read owners first and narrow with --theme. Empty, stale and ambiguous results exit 0; invalid/incomplete requests exit 2.',
|
|
34
|
+
impact: 'Query direct/transitive candidates from sources, named parts, tokens or implementation mappings, or compare exact Git endpoints. --base includes staged, unstaged and untracked working files; --head selects another exact commit. Hypothetical selectors cannot prove skips; token candidates assume unchanged Tailwind classification. Git mode freshly executes both endpoint source sets and compares eligible materialized inputs. Closure or occurrence absence never proves safety. Groups merge equal theme and same-source frame records; noncandidate proofs remain counts. --explain samples witnesses/digests without splitting groups. No browser launch. Render/check/diff --impacted compute their own operation-local proofs. Exit 0 completed, including empty/stale mappings; 2 invalid/incomplete.',
|
|
35
|
+
};
|
|
36
|
+
const helpExamples = {
|
|
37
|
+
impact: 'adg impact --source=design/components/badge.tsx --part=Badge --json\nadg impact --token=--accent --json\nadg impact --base=HEAD --json',
|
|
38
|
+
render: 'adg render --impacted --base=HEAD --json\nadg render arch/catalog.mmd --base=HEAD --json',
|
|
39
|
+
check: 'adg check --impacted --base=HEAD --read-only --json\nadg check --read-only --json',
|
|
40
|
+
diff: 'adg diff --base=HEAD --impacted --json',
|
|
33
41
|
};
|
|
34
42
|
export function help(command) {
|
|
35
|
-
if (command) return `Usage: adg ${command} ${usage[command]}\n\n${details[command]}\n\n-h, --help Show help\nExit codes: 0 success, 1 check/compare/diff problems, 2 usage/configuration/environment error.`;
|
|
43
|
+
if (command) return `Usage: adg ${command} ${usage[command]}\n\n${details[command]}${helpExamples[command] ? `\n\nExamples:\n${helpExamples[command]}` : ''}\n\n-h, --help Show help\nExit codes: 0 success, 1 check/compare/diff problems, 2 usage/configuration/environment error.`;
|
|
36
44
|
return `Usage: adg [open] [directory] [options]\n\n${commands.map(name => ` adg ${name} ${usage[name]}`).join('\n')}\n\nAny first argument that is not a command opens a directory. Use adg open check for a directory named check.\nRun adg <command> --help for details. -v, --version prints the installed version.`;
|
|
37
45
|
}
|
|
38
46
|
export function parseCli(args) {
|
|
@@ -41,21 +49,44 @@ export function parseCli(args) {
|
|
|
41
49
|
const explicit = commands.includes(args[0]), command = explicit ? args[0] : 'open';
|
|
42
50
|
const options = { help: { type: 'boolean', short: 'h' }, version: { type: 'boolean', short: 'v' }, json: { type: 'boolean' } };
|
|
43
51
|
const locators = ['asset', 'frame', 'group', 'layer', 'mode', 'base'];
|
|
44
|
-
const strings = { open: ['port', 'state-dir', ...locators], link: locators, serve: ['port', 'state-dir'], root: ['depth', 'state-dir'], service: ['port', 'state-dir'], render: ['scale', 'frame', 'theme', 'out-dir', 'base'], diff: ['base', 'frame', 'theme', 'scale', 'out-dir'], compare: ['frame', 'fixture', 'region', 'selector', 'viewport', 'origin'], owner: ['file', 'text', 'color', 'token', 'line', 'symbol', 'locale', 'theme', 'state-dir'] };
|
|
52
|
+
const strings = { open: ['port', 'state-dir', ...locators], link: locators, serve: ['port', 'state-dir'], root: ['depth', 'state-dir'], service: ['port', 'state-dir'], check: ['base', 'frame', 'theme', 'state-dir'], render: ['scale', 'frame', 'theme', 'out-dir', 'base', 'state-dir'], diff: ['base', 'frame', 'theme', 'scale', 'out-dir', 'state-dir'], compare: ['frame', 'fixture', 'region', 'selector', 'viewport', 'origin'], owner: ['file', 'text', 'color', 'token', 'line', 'symbol', 'locale', 'theme', 'state-dir'], impact: ['source', 'part', 'token', 'file', 'line', 'symbol', 'base', 'head', 'theme', 'state-dir'] };
|
|
45
53
|
for (const name of strings[command] ?? []) options[name] = { type: 'string' };
|
|
46
54
|
if (command === 'serve') for (const name of ['print-key', 'rotate-key']) options[name] = { type: 'boolean' };
|
|
47
55
|
if (command === 'open') options['no-open'] = { type: 'boolean' };
|
|
48
56
|
if (command === 'open' || command === 'link') options.tokens = { type: 'boolean' };
|
|
49
57
|
if (command === 'check') options['read-only'] = { type: 'boolean' };
|
|
58
|
+
if (['render', 'check', 'diff'].includes(command)) { options.impacted = { type: 'boolean' }; options.explain = { type: 'boolean' }; }
|
|
50
59
|
if (command === 'owner') options.contains = { type: 'boolean' };
|
|
60
|
+
if (command === 'impact') {
|
|
61
|
+
options.explain = { type: 'boolean' };
|
|
62
|
+
for (const name of ['source', 'token']) options[name].multiple = true;
|
|
63
|
+
}
|
|
51
64
|
if (command === 'compare') { options.all = { type: 'boolean' }; options.page = { type: 'boolean' }; }
|
|
52
65
|
if (command === 'compare') options.click = { type: 'string', multiple: true };
|
|
53
66
|
let parsed;
|
|
54
|
-
try { parsed = parseArgs({ args: explicit ? args.slice(1) : args, options, allowPositionals: true, tokens: command === 'owner' }); }
|
|
67
|
+
try { parsed = parseArgs({ args: explicit ? args.slice(1) : args, options, allowPositionals: true, tokens: command === 'owner' || command === 'impact' }); }
|
|
55
68
|
catch (error) { throw new CliError('USAGE_INVALID', `${error.message}; run adg ${command} --help`); }
|
|
56
69
|
const { values, positionals } = parsed;
|
|
57
70
|
if (globalJson) values.json = true;
|
|
58
71
|
if (!values.help && !values.version) {
|
|
72
|
+
if (['render', 'check', 'diff'].includes(command)) {
|
|
73
|
+
if (!values.impacted && (values.explain !== undefined || values['state-dir'] !== undefined)) throw new CliError('USAGE_INVALID', '--explain and --state-dir require --impacted --base=<rev>.');
|
|
74
|
+
if (values.impacted && (typeof values.base !== 'string' || !values.base.trim())) throw new CliError('USAGE_INVALID', '--impacted requires --base=<rev>.');
|
|
75
|
+
if (command === 'check' && !values.impacted && ['base', 'frame', 'theme', 'state-dir', 'explain'].some(key => values[key] !== undefined)) throw new CliError('USAGE_INVALID', 'Check selection flags require --impacted --base=<rev>.');
|
|
76
|
+
}
|
|
77
|
+
if (command === 'impact') {
|
|
78
|
+
const kinds = ['source', 'token', 'file', 'base'].filter(key => values[key] !== undefined), seen = new Set();
|
|
79
|
+
for (const token of parsed.tokens) if (token.kind === 'option' && !['json', 'help', 'version', 'source', 'token'].includes(token.name)) {
|
|
80
|
+
if (seen.has(token.name)) throw new CliError('USAGE_INVALID', `Do not repeat --${token.name}; run adg impact --help.`);
|
|
81
|
+
seen.add(token.name);
|
|
82
|
+
}
|
|
83
|
+
if (positionals.length || kinds.length !== 1 || strings.impact.some(key => values[key] !== undefined && (Array.isArray(values[key]) ? values[key] : [values[key]]).some(value => !value.trim())) ||
|
|
84
|
+
values.theme !== undefined && !['both', 'light', 'dark'].includes(values.theme) ||
|
|
85
|
+
values.part !== undefined && (kinds[0] !== 'source' || values.source.length !== 1) ||
|
|
86
|
+
values.head !== undefined && kinds[0] !== 'base' ||
|
|
87
|
+
(values.line !== undefined || values.symbol !== undefined) && kinds[0] !== 'file' ||
|
|
88
|
+
values.line !== undefined && (!/^[1-9]\d*$/.test(values.line) || !Number.isSafeInteger(Number(values.line)))) throw new CliError('USAGE_INVALID', 'Choose one nonempty impact selector family and compatible options; run adg impact --help.');
|
|
89
|
+
}
|
|
59
90
|
if (command === 'owner') {
|
|
60
91
|
const kinds = ['file', 'text', 'color', 'token'].filter(key => values[key] !== undefined);
|
|
61
92
|
const seen = new Set();
|
|
@@ -136,6 +167,7 @@ async function dispatch({ command, values, positionals }, cwd, output, serviceOp
|
|
|
136
167
|
return {data:values['print-key'] ? {action:'print-key',stateDirectory,key} : {action:'rotate-key',stateDirectory,rotated:true}};
|
|
137
168
|
}
|
|
138
169
|
const config = await loadConfig(cwd);
|
|
170
|
+
if (command === 'impact') return (await import('./toolkit/impact.mjs')).impact(config, { ...values, ...(values['state-dir'] !== undefined ? { 'state-dir': path.resolve(cwd, values['state-dir']) } : {}) }, { log: output.log });
|
|
139
171
|
if (command === 'owner') return (await import('./toolkit/owner.mjs')).owner(config, { ...values, ...(values['state-dir'] !== undefined ? { 'state-dir': path.resolve(cwd, values['state-dir']) } : {}) }, { log: output.log });
|
|
140
172
|
if (command === 'init') return { data: (await import('./toolkit/project.mjs')).init(config, output.log) };
|
|
141
173
|
if (command === 'compare') return (await import('./toolkit/compare.mjs')).compare(config, positionals, values, {log:output.log});
|
package/src/toolkit/arch-git.mjs
CHANGED
|
@@ -150,6 +150,25 @@ export async function sourceRenames(base) {
|
|
|
150
150
|
}
|
|
151
151
|
return renames;
|
|
152
152
|
}
|
|
153
|
+
|
|
154
|
+
/** Actual endpoint changes; working-tree mode includes staged, unstaged and untracked paths. */
|
|
155
|
+
export async function revisionChanges(base, head = null) {
|
|
156
|
+
const fields = (await git(base.root, ['diff', '--name-status', '-z', '--find-renames', base.sha, ...(head ? [head.sha] : []), '--'])).split('\0');
|
|
157
|
+
const changes = [];
|
|
158
|
+
for (let i = 0; i < fields.length - 1;) {
|
|
159
|
+
const code = fields[i++], first = fields[i++];
|
|
160
|
+
if (code.startsWith('R') || code.startsWith('C')) {
|
|
161
|
+
const second = fields[i++];
|
|
162
|
+
changes.push(code.startsWith('R') ? { before: first, after: second, status: 'renamed' } : { before: null, after: second, status: 'added' });
|
|
163
|
+
} else changes.push({ before: code === 'A' ? null : first, after: code === 'D' ? null : first,
|
|
164
|
+
status: code === 'A' ? 'added' : code === 'D' ? 'deleted' : code === 'T' ? 'type_changed' : 'modified' });
|
|
165
|
+
}
|
|
166
|
+
if (!head) {
|
|
167
|
+
const names = (await git(base.root, ['ls-files', '--others', '--exclude-standard', '-z'])).split('\0').filter(Boolean);
|
|
168
|
+
for (const name of names) if (!changes.some(change => change.after === name)) changes.push({ before: null, after: name, status: 'added' });
|
|
169
|
+
}
|
|
170
|
+
return changes.sort((a, b) => (a.after ?? a.before) < (b.after ?? b.before) ? -1 : (a.after ?? a.before) > (b.after ?? b.before) ? 1 : 0);
|
|
171
|
+
}
|
|
153
172
|
export async function resolveBase(config, rev) {
|
|
154
173
|
if(typeof rev!=='string'||!rev.trim())throw new CliError('USAGE_INVALID', 'Set --base to a Git revision, for example HEAD.');
|
|
155
174
|
let root;
|
|
@@ -12,7 +12,7 @@ const aborted = () => Object.assign(new Error('Build superseded'), { name: 'Abor
|
|
|
12
12
|
const memoryLimit = 32 * 1024 * 1024, diskLimit = 256 * 1024 * 1024;
|
|
13
13
|
const workerLimit = 2, recycleAfter = 32;
|
|
14
14
|
|
|
15
|
-
class BuildPool {
|
|
15
|
+
export class BuildPool {
|
|
16
16
|
slots = new Set(); retiring = new Set(); queue = []; nextId = 0; closed = false;
|
|
17
17
|
counters = { attempts: 0, spawned: 0, recycled: 0, cancelled: 0 };
|
|
18
18
|
run(payload, signal) {
|
|
@@ -113,7 +113,7 @@ export async function createBuildStore({ config, cacheDirectory }) {
|
|
|
113
113
|
const workerConfig = { root: await realpath(config.root), design, output: config.output, sources: config.sources, arch:config.arch, check:config.check, ...(config.overlay?{overlay:config.overlay}:{}) };
|
|
114
114
|
const require = createRequire(import.meta.url);
|
|
115
115
|
const fingerprint = digest(Buffer.concat(await Promise.all([
|
|
116
|
-
...['../../package.json', './build.mjs', './runtime.mjs', './tokens.mjs', './text.mjs', './project.mjs', './build-worker.mjs', './build-store.mjs', './arch.mjs', './arch-browser.mjs', './browser.mjs'].map(file => new URL(file, import.meta.url)),
|
|
116
|
+
...['../../package.json', './build.mjs', './frame-document.mjs', './runtime.mjs', './tokens.mjs', './text.mjs', './project.mjs', './build-worker.mjs', './build-store.mjs', './arch.mjs', './arch-browser.mjs', './browser.mjs'].map(file => new URL(file, import.meta.url)),
|
|
117
117
|
...(config.overlay?['./arch-overlay.mjs','./arch-git.mjs'].map(file=>new URL(file,import.meta.url)):[]),
|
|
118
118
|
require.resolve('esbuild/package.json'), require.resolve('tailwindcss/package.json'),
|
|
119
119
|
].map(file => readFile(file)))));
|
|
@@ -238,7 +238,9 @@ export async function createBuildStore({ config, cacheDirectory }) {
|
|
|
238
238
|
const built = await pool.run({ config: workerConfig, name }, controller.signal); counters.builds++;
|
|
239
239
|
endQueue?.({frames: built.frames.length});
|
|
240
240
|
if (controller.signal.aborted || generation !== (generations.get(name) ?? 0)) throw aborted();
|
|
241
|
-
const payload = { frames: built.frames, parts: built.parts, css: built.css
|
|
241
|
+
const payload = { frames: built.frames, parts: built.parts, css: built.css,
|
|
242
|
+
...(built.tokenCss !== undefined ? { tokenCss: built.tokenCss, cssWithoutTokens: built.cssWithoutTokens,
|
|
243
|
+
cssBeforeTokens: built.cssBeforeTokens, cssAfterTokens: built.cssAfterTokens } : {}) };
|
|
242
244
|
const hash = digest(JSON.stringify({ path: name, component: !name.startsWith('surfaces/'), ...payload, ...(config.overlay?{base:config.overlay.sha,baseBlob:built.baseBlob}:{}), imports: built.imports }));
|
|
243
245
|
const entry = { path: name, hash, inputHash: inputHash(built.dependencyHashes,built.baseBlob), ...(config.overlay?{baseBlob:built.baseBlob}:{}), imports: built.imports, dependencies: built.dependencies, dependencyHashes: built.dependencyHashes,
|
|
244
246
|
parts: built.parts, frames: built.frames.map(({ html, ...frame }) => frame) };
|
|
@@ -17,7 +17,7 @@ parentPort.on('message', async ({ id, config, name, type }) => {
|
|
|
17
17
|
if (shuttingDown) return;
|
|
18
18
|
try {
|
|
19
19
|
const snapshot = new Map();
|
|
20
|
-
const build = async browser => config.overlay && name.endsWith('.mmd') ? (await import('./arch-overlay.mjs')).buildOverlay(config,path.join(config.root,name),{base:config.overlay,browser,snapshot}) : buildSource(config, path.join(name.endsWith('.mmd')?config.root:config.design, name), { write: false, snapshot, browser });
|
|
20
|
+
const build = async browser => config.overlay && name.endsWith('.mmd') ? (await import('./arch-overlay.mjs')).buildOverlay(config,path.join(config.root,name),{base:config.overlay,browser,snapshot}) : buildSource(config, path.join(name.endsWith('.mmd')?config.root:config.design, name), { write: false, snapshot, browser, allowLegacy: config.allowLegacy ?? true });
|
|
21
21
|
const built = await (name.endsWith('.mmd') ? archBrowser.run(build) : build());
|
|
22
22
|
const frames = JSON.parse(JSON.stringify(built.frames.map(({ document, ...frame }) => frame)));
|
|
23
23
|
const dependencies = [...new Set(built.dependencies.map(file => path.relative(config.design, file).split(path.sep).join('/')))].sort();
|
|
@@ -25,7 +25,10 @@ parentPort.on('message', async ({ id, config, name, type }) => {
|
|
|
25
25
|
const bytes=snapshot.get(path.join(config.design,name));
|
|
26
26
|
return [name,createHash('sha256').update(bytes===null?'missing\0':'present\0').update(bytes??'').digest('hex')];
|
|
27
27
|
}));
|
|
28
|
-
if (!shuttingDown) parentPort.postMessage({ id, result: { frames, parts: built.parts ?? [], css: built.css,
|
|
28
|
+
if (!shuttingDown) parentPort.postMessage({ id, result: { frames, parts: built.parts ?? [], css: built.css,
|
|
29
|
+
...(built.tokenCss !== undefined ? { tokenCss: built.tokenCss, cssWithoutTokens: built.cssWithoutTokens,
|
|
30
|
+
cssBeforeTokens: built.cssBeforeTokens, cssAfterTokens: built.cssAfterTokens } : {}),
|
|
31
|
+
...(config.overlay?{baseBlob:built.baseBlob}:{}), imports: built.imports, dependencies, dependencyHashes }, heapBytes: process.memoryUsage().heapUsed });
|
|
29
32
|
} catch (error) {
|
|
30
33
|
const diagnostics=error.errors ?? error.cause?.errors ?? [];
|
|
31
34
|
// esbuild's onLoad error keeps transform diagnostics under detail.errors.
|
package/src/toolkit/build.mjs
CHANGED
|
@@ -6,8 +6,9 @@ import path from 'node:path';
|
|
|
6
6
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
7
7
|
import { loadTokens, refreshTypes, rejectLegacy, relative, isSourcePath, sourceDirectories } from './project.mjs';
|
|
8
8
|
import { themeCss, parseTokens } from './tokens.mjs';
|
|
9
|
-
import {
|
|
9
|
+
import { componentOwner } from './runtime.mjs';
|
|
10
10
|
import { CliError, classifyError } from '../cli-output.mjs';
|
|
11
|
+
import { frameDocument } from './frame-document.mjs';
|
|
11
12
|
const require = createRequire(import.meta.url);
|
|
12
13
|
const runtime = fileURLToPath(new URL('./runtime.mjs', import.meta.url));
|
|
13
14
|
const tailwind = path.dirname(require.resolve('tailwindcss/package.json'));
|
|
@@ -17,6 +18,7 @@ const tailwind = path.dirname(require.resolve('tailwindcss/package.json'));
|
|
|
17
18
|
const sourceTransforms = new Map();
|
|
18
19
|
let transformBytes = 0;
|
|
19
20
|
const transformLimit = 8 * 1024 * 1024;
|
|
21
|
+
let evaluation = 0;
|
|
20
22
|
function forgetTransform(file) {
|
|
21
23
|
const entry = sourceTransforms.get(file);
|
|
22
24
|
if (entry) { transformBytes -= entry.bytes; sourceTransforms.delete(file); }
|
|
@@ -140,7 +142,7 @@ async function buildDesignSource(config, file, { write = true, allowLegacy = tru
|
|
|
140
142
|
// Retain esbuild's human diagnostics and details while carrying the owning boundary's code.
|
|
141
143
|
throw Object.assign(new CliError(typed.code, error.message, { cause: error, context: typed.context }), { errors: error.errors });
|
|
142
144
|
});
|
|
143
|
-
const mod = await import(`data:text/javascript;base64,${Buffer.from(result.outputFiles[0].text).toString('base64')}#${
|
|
145
|
+
const mod = await import(`data:text/javascript;base64,${Buffer.from(result.outputFiles[0].text).toString('base64')}#${++evaluation}`);
|
|
144
146
|
if (typeof mod.default !== 'function') throw Error(`${relative(config,file)}: export a default function returning Frames`);
|
|
145
147
|
const value = mod.default(), frames = (Array.isArray(value) ? value.flat(Infinity) : [value]).filter(v => v != null && v !== false);
|
|
146
148
|
if (!frames.length) throw Error(`${relative(config,file)}: default export must return at least one Frame`);
|
|
@@ -152,9 +154,11 @@ async function buildDesignSource(config, file, { write = true, allowLegacy = tru
|
|
|
152
154
|
const tokenSource = read(path.join(base,'tokens.css'),'utf8'), tokens = snapshot ? parseTokens(tokenSource) : loadTokens(config);
|
|
153
155
|
const compiler = await compile(`${readFileSync(path.join(tailwind,'theme.css'),'utf8')}\n${themeCss(tokens)}\n${readFileSync(path.join(tailwind,'preflight.css'),'utf8')}\n@custom-variant dark (&:where([data-theme=dark], [data-theme=dark] *));\n@tailwind utilities;`);
|
|
154
156
|
const classes = [...new Set(frames.flatMap(f => [...f.html.matchAll(/\bclass="([^"]*)"/g)].flatMap(m => m[1].split(/\s+/))))];
|
|
155
|
-
const
|
|
157
|
+
const utilities = compiler.build(classes);
|
|
158
|
+
const defaults = 'html,body{margin:0;font-family:var(--font-ui);color:var(--text);background:var(--canvas)}[data-adg-frame]{display:flex;align-items:flex-start;position:relative;background:var(--canvas)}[data-adg-frame]>*,svg{flex-shrink:0} @media(prefers-reduced-motion:reduce){*,*::before,*::after{animation:none!important;transition:none!important}}';
|
|
159
|
+
const css = `${utilities}\n${tokenSource}\n${defaults}`;
|
|
156
160
|
for (const frame of frames) {
|
|
157
|
-
frame.document = theme =>
|
|
161
|
+
frame.document = theme => frameDocument(frame, theme, css);
|
|
158
162
|
if (write) { const destination = path.join(config.output, path.relative(base,file).replace(/\.tsx$/, ''), `${encodeURIComponent(frame.name)}.html`); mkdirSync(path.dirname(destination),{recursive:true}); writeFileSync(destination,frame.document('light')); }
|
|
159
163
|
}
|
|
160
164
|
const sourceName = path.relative(base, file).split(path.sep).join('/');
|
|
@@ -162,5 +166,7 @@ async function buildDesignSource(config, file, { write = true, allowLegacy = tru
|
|
|
162
166
|
const owner = typeof mod[name] === 'function' && componentOwner(mod[name]);
|
|
163
167
|
return owner && owner.source === sourceName && owner.export === name;
|
|
164
168
|
}).sort();
|
|
165
|
-
return { frames, parts, dependencies: [...dependencies], imports: [...imports].sort(), css
|
|
169
|
+
return { frames, parts, dependencies: [...dependencies], imports: [...imports].sort(), css,
|
|
170
|
+
tokenCss: tokenSource, cssWithoutTokens: `${utilities}\n${defaults}`,
|
|
171
|
+
cssBeforeTokens: `${utilities}\n`, cssAfterTokens: `\n${defaults}` };
|
|
166
172
|
}
|
package/src/toolkit/commands.mjs
CHANGED
|
@@ -8,6 +8,7 @@ import { launch, loadFrame, browserTask } from './browser.mjs';
|
|
|
8
8
|
import { CliError, classifyError } from '../cli-output.mjs';
|
|
9
9
|
import { commandFailure, cleanup, emptySelection } from './results.mjs';
|
|
10
10
|
import { loadImplementationMap, validateImplementationMap } from './implementation-map.mjs';
|
|
11
|
+
import { withImpacted } from './impact-selection.mjs';
|
|
11
12
|
import { mappingFacts } from './source-facts.mjs';
|
|
12
13
|
export function inspectFrame(tokenNames) {
|
|
13
14
|
const frame = document.querySelector('[data-adg-frame]'), box = frame.getBoundingClientRect(), problems = new Map();
|
|
@@ -181,10 +182,12 @@ export function inspectFrame(tokenNames) {
|
|
|
181
182
|
}
|
|
182
183
|
return [...problems.values()];
|
|
183
184
|
}
|
|
184
|
-
export async function check(config, args = [], options = {}, log = console.log, error = console.error, { launchBrowser = launch } = {}) {
|
|
185
|
+
export async function check(config, args = [], options = {}, log = console.log, error = console.error, { launchBrowser = launch, session } = {}) {
|
|
186
|
+
if (options.impacted && !session) return withImpacted(config, args, options, 'check', selected =>
|
|
187
|
+
check(config, args, options, log, error, { launchBrowser, session: selected }));
|
|
185
188
|
const write = !options['read-only'];
|
|
186
189
|
/** @type {import('./results.mjs').CheckData} */
|
|
187
|
-
const data = { project: config.root, readOnly: !write, complete: false, sources: [], summary: { sources: 0, frames: 0, evaluations: 0, problems: 0 }, findings: [] };
|
|
190
|
+
const data = { project: config.root, readOnly: !write, complete: false, impact: session?.selection ?? null, sources: [], summary: { sources: 0, frames: 0, evaluations: 0, problems: 0 }, findings: [] };
|
|
188
191
|
const warnings = [], humanProblems = new Set(), findingKeys = new Set(), graph = {};
|
|
189
192
|
let browser, primary;
|
|
190
193
|
const add = (problem, file, frame = null, theme = null, source = relative(config, file)) => {
|
|
@@ -201,7 +204,7 @@ export async function check(config, args = [], options = {}, log = console.log,
|
|
|
201
204
|
};
|
|
202
205
|
try {
|
|
203
206
|
const mapping = await loadImplementationMap(config);
|
|
204
|
-
const files = selectSources(config, args, { write });
|
|
207
|
+
const files = session ? session.sources.map(source => path.join(config.root, source)).filter(existsSync) : selectSources(config, args, { write });
|
|
205
208
|
data.sources = files.map(file => relative(config, file));
|
|
206
209
|
data.summary.sources = files.length;
|
|
207
210
|
const tokens = files.length ? loadTokens(config) : null;
|
|
@@ -222,8 +225,9 @@ export async function check(config, args = [], options = {}, log = console.log,
|
|
|
222
225
|
let built;
|
|
223
226
|
try {
|
|
224
227
|
// Static architecture rejection is a completed rule evaluation and needs no browser.
|
|
225
|
-
|
|
226
|
-
|
|
228
|
+
if (session && !architecture) built = session.views[1].built.get(relative(config, file));
|
|
229
|
+
else if (session && !session.chosen.some(row => row.source === relative(config, file) && session.themes.some(theme => session.scheduled(row, theme)))) continue;
|
|
230
|
+
else { browser ??= await launchBrowser(); built = await buildSource(config, file, { allowLegacy: false, write: session ? false : write, browser }); }
|
|
227
231
|
} catch (cause) {
|
|
228
232
|
const legacy = cause.errors?.find(item => item.detail?.code === 'LEGACY_SOURCE');
|
|
229
233
|
if (legacy) throw legacy.detail;
|
|
@@ -236,7 +240,9 @@ export async function check(config, args = [], options = {}, log = console.log,
|
|
|
236
240
|
data.summary.frames += built.frames.length;
|
|
237
241
|
if (mapping.present && !architecture) builtSources.set(relative(config, file), mappingFacts(built));
|
|
238
242
|
graph[path.relative(config.design, file).split(path.sep).join('/')] = { uses: built.imports };
|
|
239
|
-
for (const frame of built.frames) for (const theme of ['light', 'dark']) {
|
|
243
|
+
for (const frame of built.frames) for (const theme of session?.themes ?? ['light', 'dark']) {
|
|
244
|
+
if (session && !session.scheduled({ source: relative(config, file), frame: frame.name }, theme)) continue;
|
|
245
|
+
browser ??= await launchBrowser();
|
|
240
246
|
try {
|
|
241
247
|
page ??= await browserTask(browser, () => browser.newPage());
|
|
242
248
|
await loadFrame(page, frame, theme);
|
|
@@ -256,7 +262,7 @@ export async function check(config, args = [], options = {}, log = console.log,
|
|
|
256
262
|
selected: args.length ? data.sources : undefined,
|
|
257
263
|
getBuild: source => {
|
|
258
264
|
if (failedSources.has(source)) throw failedSources.get(source);
|
|
259
|
-
if (!builtSources.has(source)) builtSources.set(source, buildSource(config, path.join(config.root, source), { write: false, allowLegacy: false }));
|
|
265
|
+
if (!builtSources.has(source)) builtSources.set(source, session?.views[1].built.get(source) ?? buildSource(config, path.join(config.root, source), { write: false, allowLegacy: false }));
|
|
260
266
|
return builtSources.get(source);
|
|
261
267
|
},
|
|
262
268
|
onFinding: ({ code, message, line, column, frame }) => add({ code, message, line, column }, mapping.file, frame),
|
|
@@ -281,10 +287,12 @@ export async function check(config, args = [], options = {}, log = console.log,
|
|
|
281
287
|
} finally { if (browser) await cleanup(() => browser.close(), primary); }
|
|
282
288
|
}
|
|
283
289
|
|
|
284
|
-
export async function render(config, args = [], options = {}, log = console.log, { launchBrowser = launch } = {}) {
|
|
290
|
+
export async function render(config, args = [], options = {}, log = console.log, { launchBrowser = launch, session } = {}) {
|
|
291
|
+
if (options.impacted && !session) return withImpacted(config, args, options, 'render', selected =>
|
|
292
|
+
render(config, args, options, log, { launchBrowser, session: selected }));
|
|
285
293
|
const output = options['out-dir'] ? path.resolve(config.root, options['out-dir']) : config.output;
|
|
286
294
|
/** @type {import('./results.mjs').RenderData} */
|
|
287
|
-
const data = { project: config.root, outputDirectory: output, complete: false, base: null, captures: [], deleted: [] };
|
|
295
|
+
const data = { project: config.root, outputDirectory: output, complete: false, impact: session?.selection ?? null, base: null, captures: [], deleted: [] };
|
|
288
296
|
const warnings = [], completed = [], failures = [];
|
|
289
297
|
let browser, primary;
|
|
290
298
|
try {
|
|
@@ -295,30 +303,33 @@ export async function render(config, args = [], options = {}, log = console.log,
|
|
|
295
303
|
if (options['out-dir'] === '') throw new CliError('USAGE_INVALID', 'Set --out-dir to a directory.');
|
|
296
304
|
const themes = themeOption === 'both' ? ['light', 'dark'] : [themeOption];
|
|
297
305
|
let base, additional = [];
|
|
298
|
-
if (options.base !== undefined && (!args.length || args.some(arg => arg.endsWith('.mmd')))) {
|
|
306
|
+
if (!session && options.base !== undefined && (!args.length || args.some(arg => arg.endsWith('.mmd')))) {
|
|
299
307
|
const git = await import('./arch-git.mjs');
|
|
300
308
|
base = await git.resolveBase(config, options.base);
|
|
301
309
|
additional = await git.baseArchFiles(config, base);
|
|
302
310
|
data.base = { rev: base.rev, sha: base.sha };
|
|
303
|
-
} else if (options.base !== undefined) warnings.push({ code: 'USAGE_INVALID', message: '--base applies only to architecture sources.', next: [] });
|
|
304
|
-
|
|
311
|
+
} else if (!session && options.base !== undefined) warnings.push({ code: 'USAGE_INVALID', message: '--base applies only to architecture sources.', next: [] });
|
|
312
|
+
if (session) data.base = { rev: session.selection.query.base.rev, sha: session.selection.query.base.sha };
|
|
313
|
+
if (session) data.deleted = [...new Set(session.chosen.filter(row => row.status === 'removed').map(row => row.source))];
|
|
314
|
+
const selected = session ? [...new Set(session.chosen.filter(row => row.after && themes.some(theme => session.scheduled(row, theme))).map(row => path.join(config.root, row.source)))] : selectSources(config, args, { additional });
|
|
305
315
|
const currentArchitecture = base ? new Set(archFiles(config.arch)) : null;
|
|
306
316
|
const files = selected.filter(file => {
|
|
307
317
|
if (!existsSync(file) || (base && file.endsWith('.mmd') && !currentArchitecture.has(file))) { data.deleted.push(relative(config, file)); return false; }
|
|
308
318
|
return true;
|
|
309
319
|
});
|
|
310
|
-
if (!selected.length) emptySelection(warnings);
|
|
320
|
+
if (!selected.length && (!session || !session.selection.coverage.expectedRows)) emptySelection(warnings);
|
|
311
321
|
if (files.length) browser = await launchBrowser();
|
|
312
322
|
const captures = [];
|
|
313
323
|
for (const file of files) {
|
|
314
|
-
const built = base && file.endsWith('.mmd') ? await (await import('./arch-overlay.mjs')).buildOverlay(config, file, { base, browser }) : await buildSource(config, file, { allowLegacy: false, browser });
|
|
324
|
+
const built = session?.views[1].built.get(relative(config, file)) ?? (base && file.endsWith('.mmd') ? await (await import('./arch-overlay.mjs')).buildOverlay(config, file, { base, browser }) : await buildSource(config, file, { allowLegacy: false, write: !session, browser }));
|
|
315
325
|
for (const frame of built.frames.filter(frame => !options.frame || frame.name === options.frame)) for (const theme of themes) {
|
|
326
|
+
if (session && !session.scheduled({ source: relative(config, file), frame: frame.name }, theme)) continue;
|
|
316
327
|
const outputSource = file.endsWith('.mmd') ? relative(config, file) : path.relative(config.design, file);
|
|
317
328
|
const target = path.join(output, outputSource.replace(/\.(?:tsx|mmd)$/, ''), `${encodeURIComponent(frame.name)}-${theme}.png`);
|
|
318
329
|
captures.push({ source: relative(config, file), frame, theme, target });
|
|
319
330
|
}
|
|
320
331
|
}
|
|
321
|
-
if (options.frame && !captures.length && !data.deleted.length) throw new CliError('FRAME_NOT_FOUND', `Unknown frame ${options.frame}; choose a declared frame`);
|
|
332
|
+
if (!session && options.frame && !captures.length && !data.deleted.length) throw new CliError('FRAME_NOT_FOUND', `Unknown frame ${options.frame}; choose a declared frame`);
|
|
322
333
|
let next = 0;
|
|
323
334
|
await Promise.allSettled(Array.from({ length: Math.min(4, availableParallelism(), captures.length) }, async () => {
|
|
324
335
|
while (next < captures.length) {
|
package/src/toolkit/config.mjs
CHANGED
|
@@ -87,10 +87,11 @@ export function viewport(value) {
|
|
|
87
87
|
if (!match) throw new CliError('CONFIG_INVALID', `Invalid viewport ${value}; use <width>x<height>, for example 1280x800`);
|
|
88
88
|
return { width: Number(match[1]), height: Number(match[2]) };
|
|
89
89
|
}
|
|
90
|
-
|
|
90
|
+
let configEvaluation = 0;
|
|
91
|
+
async function importConfig(file, fresh) {
|
|
91
92
|
if (!file.endsWith('.ts')) {
|
|
92
93
|
const info = statSync(file), url = pathToFileURL(file);
|
|
93
|
-
url.searchParams.set('revision', `${info.mtimeMs}-${info.size}`);
|
|
94
|
+
url.searchParams.set('revision', `${info.mtimeMs}-${info.size}${fresh ? `-${++configEvaluation}` : ''}`);
|
|
94
95
|
return (await import(url.href)).default;
|
|
95
96
|
}
|
|
96
97
|
const require = createRequire(pathToFileURL(file));
|
|
@@ -108,14 +109,14 @@ async function importConfig(file) {
|
|
|
108
109
|
}
|
|
109
110
|
});
|
|
110
111
|
}}] });
|
|
111
|
-
return (await import(`data:text/javascript;base64,${Buffer.from(result.outputFiles[0].text).toString('base64')}`)).default;
|
|
112
|
+
return (await import(`data:text/javascript;base64,${Buffer.from(result.outputFiles[0].text).toString('base64')}${fresh ? `#${++configEvaluation}` : ''}`)).default;
|
|
112
113
|
}
|
|
113
|
-
export async function loadConfig(cwd = process.cwd(), { checkVersion = true, discover = true } = {}) {
|
|
114
|
+
export async function loadConfig(cwd = process.cwd(), { checkVersion = true, discover = true, fresh = false } = {}) {
|
|
114
115
|
const root = discover ? discoverRoot(cwd) : path.resolve(cwd), file = configFile(root);
|
|
115
116
|
if (!discover) requireMigration(root);
|
|
116
117
|
let config = {};
|
|
117
118
|
if (file) {
|
|
118
|
-
try { config = await importConfig(file); }
|
|
119
|
+
try { config = await importConfig(file, fresh); }
|
|
119
120
|
catch (error) { throw new CliError('CONFIG_INVALID', `Cannot load ${file}: ${error.message}; fix ${path.basename(file)}`, { cause: error }); }
|
|
120
121
|
}
|
|
121
122
|
if (!config || typeof config !== 'object' || Array.isArray(config)) throw new CliError('CONFIG_INVALID', 'Export a default object from adg.config.mjs');
|
|
@@ -64,7 +64,7 @@ function inventory(config, repository) {
|
|
|
64
64
|
}));
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
async function selectedSources(config, beforeConfig, root, union, args) {
|
|
67
|
+
export async function selectedSources(config, beforeConfig, root, union, args) {
|
|
68
68
|
if (!args.length) return [...union].sort();
|
|
69
69
|
const previousDesign = path.resolve(root, path.relative(beforeConfig.root, beforeConfig.design));
|
|
70
70
|
const selected = [];
|
|
@@ -183,9 +183,9 @@ export async function prepareDiffInputs(config, args = [], options = {}) {
|
|
|
183
183
|
let closed = false;
|
|
184
184
|
return {
|
|
185
185
|
base, before, after, sources, warnings, translateDiagnostic: translate, environment: { configDependencies, baseMigration },
|
|
186
|
-
async buildFrames({ browser } = {}) {
|
|
186
|
+
async buildFrames({ browser, materialized, sources: requestedSources = sources, frame: requestedFrame = options.frame } = {}) {
|
|
187
187
|
if (closed) throw new CliError('SOURCE_BUILD_FAILED', 'Diff inputs are closed; prepare a new comparison.');
|
|
188
|
-
const built = [new Map(), new Map()], snapshots = [new Map(), new Map()];
|
|
188
|
+
const built = materialized ? materialized.map(values => new Map(values)) : [new Map(), new Map()], snapshots = [new Map(), new Map()];
|
|
189
189
|
const build = async (side, index, source) => {
|
|
190
190
|
if (built[index].has(source) || !side.sources.has(source)) return;
|
|
191
191
|
try {
|
|
@@ -197,11 +197,11 @@ export async function prepareDiffInputs(config, args = [], options = {}) {
|
|
|
197
197
|
throw failure;
|
|
198
198
|
}
|
|
199
199
|
};
|
|
200
|
-
for (const source of
|
|
200
|
+
for (const source of requestedSources) {
|
|
201
201
|
await build(before, 0, source);
|
|
202
202
|
await build(after, 1, source);
|
|
203
203
|
}
|
|
204
|
-
const frames = matchDiffFrames(
|
|
204
|
+
const frames = matchDiffFrames(requestedSources, built[0], built[1], renames, requestedFrame);
|
|
205
205
|
const support = [], parents = new Map();
|
|
206
206
|
const selected = new Map(frames.map(row => [frameKey(row), row]));
|
|
207
207
|
for (const row of frames.filter(row => row.status === 'added' && row.after.parent)) {
|