@reqvire-org/ads 0.3.27 → 0.3.28
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/dist/bootstrap-ds/scripts/build-mcp-previews.mjs +6 -7
- package/dist/mcp/preview-widget.bundle.js +6 -6
- package/dist/mcp/project-widget.bundle.js +13 -13
- package/dist/mcp/resource-loader.js +10 -1
- package/dist/mcp/server.mjs +7 -3
- package/dist/preview-builder.mjs +108 -0
- package/dist/preview-inputs.mjs +8 -1
- package/dist/scenario-groups.mjs +47 -0
- package/dist/scenarios-compiler.mjs +4 -3
- package/dist/scenarios-vite.mjs +13 -5
- package/dist/scenarios.mjs +4 -1
- package/dist/showcase/client.bundle.js +21 -21
- package/dist/showcase/navigation.js +13 -0
- package/dist/showcase/style.css +1 -0
- package/dist/skills/ads-break-ui/SKILL.md +1 -1
- package/dist/skills/ads-break-ui/references/runtimes.md +17 -0
- package/dist/skills/ads-break-ui/references/scenarios.md +19 -0
- package/dist/skills/ads-designer/SKILL.md +1 -1
- package/dist/skills/ads-designer/assets/bootstrap-ds/scripts/build-mcp-previews.mjs +6 -7
- package/dist/skills/ads-designer/references/runtimes.md +17 -0
- package/dist/skills/ads-designer/references/scenarios.md +19 -0
- package/dist/skills/ads-import/SKILL.md +1 -1
- package/dist/skills/ads-import/references/runtimes.md +17 -0
- package/dist/skills/ads-import/references/scenarios.md +19 -0
- package/dist/skills/ads-motion/SKILL.md +1 -1
- package/dist/skills/ads-motion/references/runtimes.md +17 -0
- package/dist/skills/ads-motion/references/scenarios.md +19 -0
- package/dist/skills/ads-port/SKILL.md +1 -1
- package/dist/skills/ads-port/references/runtimes.md +17 -0
- package/dist/skills/ads-port/references/scenarios.md +19 -0
- package/docs/ADS.md +12 -2
- package/docs/ARCHITECTURE.md +66 -3
- package/docs/BEHAVIORS.md +7 -0
- package/docs/CHANGELOG.md +17 -0
- package/docs/GUIDE.md +31 -0
- package/docs/MCP.md +60 -8
- package/package.json +1 -1
|
@@ -115,9 +115,16 @@ export class PreviewResourceLoader {
|
|
|
115
115
|
this.register(manifest);
|
|
116
116
|
const scenario = manifest.scenarios.find(entry => entry.id === id);
|
|
117
117
|
if (!scenario) throw new Error("The selected scenario is no longer registered.");
|
|
118
|
+
const signature = JSON.stringify(this.closure(scenario.module).map(uri => [uri, this.records.get(uri)]));
|
|
119
|
+
// A successful global graph revision may only affect another scenario.
|
|
120
|
+
// Retain this view's form/scroll state, then let the caller rerun its audits.
|
|
121
|
+
if (this.mounted?.id === id && this.mounted.container === container && this.mounted.signature === signature) return true;
|
|
118
122
|
const module = await this.importModule(scenario.module);
|
|
119
123
|
if (generation !== this.generation) return false;
|
|
120
|
-
|
|
124
|
+
const unmount = this.unmount;
|
|
125
|
+
this.unmount = undefined;
|
|
126
|
+
this.mounted = undefined;
|
|
127
|
+
await unmount?.();
|
|
121
128
|
if (generation !== this.generation || this.closed) return false;
|
|
122
129
|
container.replaceChildren();
|
|
123
130
|
const keep = new Set(this.closure(scenario.module));
|
|
@@ -126,6 +133,7 @@ export class PreviewResourceLoader {
|
|
|
126
133
|
if (typeof module.mount !== "function") throw new Error("The compiled scenario has no mount adapter.");
|
|
127
134
|
this.unmount = module.mount(container);
|
|
128
135
|
if (typeof this.unmount !== "function") throw new Error("The scenario mount adapter must return an unmount callback.");
|
|
136
|
+
this.mounted = { id, container, signature };
|
|
129
137
|
return true;
|
|
130
138
|
}
|
|
131
139
|
async dispose() {
|
|
@@ -133,6 +141,7 @@ export class PreviewResourceLoader {
|
|
|
133
141
|
this.closed = true;
|
|
134
142
|
++this.generation;
|
|
135
143
|
await this.unmount?.();
|
|
144
|
+
this.mounted = undefined;
|
|
136
145
|
for (const style of this.styles.values()) style.remove();
|
|
137
146
|
for (const url of this.urls.values()) URL.revokeObjectURL(url);
|
|
138
147
|
this.styles.clear(); this.styleReady.clear(); this.urls.clear(); this.bytes.clear(); this.records.clear();
|
package/dist/mcp/server.mjs
CHANGED
|
@@ -10,6 +10,7 @@ import { INVESTIGATIONS_URI, investigationIndex, investigationPage, investigatio
|
|
|
10
10
|
import { failure } from "../evidence.mjs";
|
|
11
11
|
import { inspectTokens } from "../tokens.mjs";
|
|
12
12
|
import { inspectScenarios } from "../scenarios.mjs";
|
|
13
|
+
import { scenarioGroupFingerprint } from "../scenario-groups.mjs";
|
|
13
14
|
import { startShowcaseHost } from "./showcase-host.mjs";
|
|
14
15
|
import { createSkillStore, page, SKILLS_EXTENSION } from "./skills.mjs";
|
|
15
16
|
import { inspectCatalog, projectDocuments, PROJECT_URI, readProjectDocument } from "./catalog.mjs";
|
|
@@ -294,8 +295,8 @@ export function createAdsMcp(directory, { era = "legacy", skillDirectory, pollIn
|
|
|
294
295
|
const units = edits.units();
|
|
295
296
|
return json({ total: matches.length, items: matches.slice(0, limit).map(item => ({ ...item, unit: units.find(unit => unit.files.includes(item.file))?.id ?? null })), resourceUri: `${PROJECT_URI}/catalog` });
|
|
296
297
|
} },
|
|
297
|
-
{ name: "ads_scenarios", description: "Find an independently mountable token, component, pattern or composition preview. IDs derive from source filenames; covers lists rendered public UI, exercises lists behavioral APIs and tokens lists the real token inputs. Use ads_show_scenario with an exact returned id. Showcase and MCP use this same registry.", schema: query.extend({ kind: z.enum(["tokens", "components", "patterns", "composition"]).optional(), offset: z.number().int().min(0).default(0) }), call: ({ query: search = "", limit, kind, offset }) => {
|
|
298
|
-
const matches = getRegistry().scenarios.filter(item => (!kind || item.kind === kind) && `${item.id} ${item.title} ${item.covers.join(" ")} ${(item.exercises ?? []).join(" ")} ${item.tokens.join(" ")}`.toLowerCase().includes(search.toLowerCase()));
|
|
298
|
+
{ name: "ads_scenarios", description: "Find an independently mountable token, component, pattern or composition preview. IDs derive from source filenames. Optional group labels are derived from folder names and searchable; group is discovery output, never scenario metadata. covers lists rendered public UI, exercises lists behavioral APIs and tokens lists the real token inputs. Use ads_show_scenario with an exact returned id. Showcase and MCP use this same registry.", schema: query.extend({ kind: z.enum(["tokens", "components", "patterns", "composition"]).optional(), offset: z.number().int().min(0).default(0) }), call: ({ query: search = "", limit, kind, offset }) => {
|
|
299
|
+
const matches = getRegistry().scenarios.filter(item => (!kind || item.kind === kind) && `${item.id} ${item.title} ${item.group ?? ""} ${item.covers.join(" ")} ${(item.exercises ?? []).join(" ")} ${item.tokens.join(" ")}`.toLowerCase().includes(search.toLowerCase()));
|
|
299
300
|
const units = edits.units();
|
|
300
301
|
return json({ total: matches.length, scenarios: matches.slice(offset, offset + limit).map(item => ({ ...item, unit: units.find(unit => unit.files.includes(item.file))?.id ?? null })), ...(offset + limit < matches.length ? { nextOffset: offset + limit } : {}), diagnostics: getRegistry().diagnostics, resourceUri: `${PROJECT_URI}/scenarios` });
|
|
301
302
|
} },
|
|
@@ -447,7 +448,10 @@ export function createAdsMcp(directory, { era = "legacy", skillDirectory, pollIn
|
|
|
447
448
|
try { const stat = statSync(file); return `${file}:${stat.mtimeMs}:${stat.size}`; } catch { return `${file}:missing`; }
|
|
448
449
|
}).join("\n");
|
|
449
450
|
}
|
|
450
|
-
const fingerprint = () =>
|
|
451
|
+
const fingerprint = () => {
|
|
452
|
+
const sources = sourceFiles(options.dsRoot);
|
|
453
|
+
return `${fileFingerprint([...sources, ...getDocuments().map(doc => doc.file), path.join(root, "ds.config.json"), path.join(root, "package.json"), path.join(root, ".ds/behavior-results.json")])}\n${scenarioGroupFingerprint(options, sources)}`;
|
|
454
|
+
};
|
|
451
455
|
const artifactFingerprint = () => fileFingerprint(allApps().map(app => path.resolve(root, previewArtifactPath(previewOptions(), app.file))));
|
|
452
456
|
const assetFingerprint = () => resourceAssets().map(asset => asset.uri).sort().join("\n");
|
|
453
457
|
let previous = fingerprint();
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { mkdirSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { previewSourceRevision } from "./preview-inputs.mjs";
|
|
5
|
+
import { createPreviewResources } from "./preview-resources.mjs";
|
|
6
|
+
|
|
7
|
+
/** Project-owned Vite plugins/configuration, with a persistent development graph.
|
|
8
|
+
* Watch output is private scratch data; only the compiler may publish it after
|
|
9
|
+
* validation and its source/generation checks. Existing buildGraph adapters work
|
|
10
|
+
* unchanged; opt in by passing this function as buildGraph. */
|
|
11
|
+
export function createVitePreviewBuilder({ build, configure }) {
|
|
12
|
+
let graph;
|
|
13
|
+
async function close() {
|
|
14
|
+
const previous = graph;
|
|
15
|
+
graph = undefined;
|
|
16
|
+
if (!previous) return;
|
|
17
|
+
previous.closed = true;
|
|
18
|
+
previous.notify();
|
|
19
|
+
try { await previous.watcher?.close(); }
|
|
20
|
+
finally { rmSync(previous.directory, { recursive: true, force: true }); }
|
|
21
|
+
}
|
|
22
|
+
const builder = async (entries, options, track, { watched = false } = {}) => {
|
|
23
|
+
if (!watched) {
|
|
24
|
+
const config = await configure(entries, options);
|
|
25
|
+
const output = await build({ ...config, plugins: [...config.plugins ?? [], track], build: { ...config.build, write: false, watch: null } });
|
|
26
|
+
return createPreviewResources(output, options, entries);
|
|
27
|
+
}
|
|
28
|
+
// Metadata changes do not change virtual module identities. A changed entry
|
|
29
|
+
// list or project configuration does require a fresh configured graph.
|
|
30
|
+
const key = JSON.stringify([options.root, options.config, entries.map(entry => [entry.id, entry.file])]);
|
|
31
|
+
if (graph?.key !== key) {
|
|
32
|
+
await close();
|
|
33
|
+
const directory = path.join(options.root, ".ds/incremental", randomUUID());
|
|
34
|
+
mkdirSync(directory, { recursive: true });
|
|
35
|
+
const trigger = path.join(directory, "trigger");
|
|
36
|
+
writeFileSync(trigger, "0");
|
|
37
|
+
const listeners = new Set();
|
|
38
|
+
const current = { key, directory, closed: false, building: true, serial: 0,
|
|
39
|
+
notify() { for (const resolve of listeners) resolve(); listeners.clear(); },
|
|
40
|
+
wait(reconcile) { return new Promise(resolve => {
|
|
41
|
+
const done = () => { clearTimeout(timer); listeners.delete(done); resolve(); };
|
|
42
|
+
// Watch subscriptions can still be settling after END. Reconcile a
|
|
43
|
+
// missed scratch-file event rather than leave an idle request stuck.
|
|
44
|
+
const timer = reconcile ? setTimeout(done, 100) : undefined;
|
|
45
|
+
listeners.add(done);
|
|
46
|
+
}); },
|
|
47
|
+
};
|
|
48
|
+
graph = current;
|
|
49
|
+
let started;
|
|
50
|
+
let candidate;
|
|
51
|
+
const capture = { name: "ads-incremental-preview", enforce: "post",
|
|
52
|
+
buildStart() { started = previewSourceRevision(options); this.addWatchFile(trigger); },
|
|
53
|
+
writeBundle(_output, bundle) {
|
|
54
|
+
candidate = { source: started, output: { output: Object.values(bundle) }, modules: [...this.getModuleIds()] };
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
try {
|
|
58
|
+
const config = await configure(entries, options);
|
|
59
|
+
const output = config.build?.rollupOptions?.output;
|
|
60
|
+
if (Array.isArray(output) || output?.file) throw new Error("Incremental preview builds require one module output without output.file.");
|
|
61
|
+
current.watcher = await build({ ...config, plugins: [...config.plugins ?? [], capture],
|
|
62
|
+
build: { ...config.build, write: true, outDir: path.join(directory, "output"), emptyOutDir: true,
|
|
63
|
+
rollupOptions: { ...config.build?.rollupOptions, output: { ...output, dir: path.join(directory, "output") } },
|
|
64
|
+
watch: { ...config.build?.watch, skipWrite: false,
|
|
65
|
+
// Bun's native fs-watch reattachment can miss rapid subsequent
|
|
66
|
+
// edits on Linux. Poll only this compiler's dependency watches.
|
|
67
|
+
chokidar: { ...(process.versions.bun ? { usePolling: true, interval: 100 } : {}), ...config.build?.watch?.chokidar },
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
if (current.closed) {
|
|
72
|
+
await current.watcher.close();
|
|
73
|
+
rmSync(directory, { recursive: true, force: true });
|
|
74
|
+
throw new Error("Preview builder was closed.");
|
|
75
|
+
}
|
|
76
|
+
current.watcher.on("event", event => {
|
|
77
|
+
if (event.code === "START") { current.building = true; current.error = undefined; candidate = undefined; }
|
|
78
|
+
if (event.code === "ERROR") {
|
|
79
|
+
current.error = { source: started, value: event.error }; current.building = false; current.notify();
|
|
80
|
+
}
|
|
81
|
+
if (event.code === "END") {
|
|
82
|
+
if (candidate) current.snapshot = candidate;
|
|
83
|
+
current.building = false; current.notify();
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
} catch (error) { await close(); throw error; }
|
|
87
|
+
}
|
|
88
|
+
const current = graph;
|
|
89
|
+
const source = previewSourceRevision(options);
|
|
90
|
+
while (!current.closed) {
|
|
91
|
+
if (!current.building) {
|
|
92
|
+
if (previewSourceRevision(options) !== source) throw new Error("Sources changed during incremental compilation. Waiting for the current build.");
|
|
93
|
+
if (current.error?.source === source) throw current.error.value;
|
|
94
|
+
if (current.snapshot?.source === source) {
|
|
95
|
+
track.generateBundle.call({ getModuleIds: () => current.snapshot.modules });
|
|
96
|
+
return createPreviewResources(current.snapshot.output, options, entries);
|
|
97
|
+
}
|
|
98
|
+
// Metadata/policy/assets outside Rollup's module graph still require a
|
|
99
|
+
// current build. A watched scratch file requests it without touching UI.
|
|
100
|
+
writeFileSync(path.join(current.directory, "trigger"), String(++current.serial));
|
|
101
|
+
}
|
|
102
|
+
await current.wait(!current.building);
|
|
103
|
+
}
|
|
104
|
+
throw new Error("Preview builder was closed.");
|
|
105
|
+
};
|
|
106
|
+
builder.close = close;
|
|
107
|
+
return builder;
|
|
108
|
+
}
|
package/dist/preview-inputs.mjs
CHANGED
|
@@ -2,11 +2,14 @@ import { createHash } from "node:crypto";
|
|
|
2
2
|
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { previewFileIgnored } from "./preview-files.mjs";
|
|
5
|
+
import { isScenarioFile } from "./config.mjs";
|
|
6
|
+
import { scenarioGroupFingerprint } from "./scenario-groups.mjs";
|
|
5
7
|
|
|
6
8
|
/** Shared source evidence for compilation, watch recovery and status reads. */
|
|
7
9
|
export function previewSourceRevision(options, apps = options.config.mcp.apps ?? []) {
|
|
8
10
|
const {root} = options;
|
|
9
11
|
const rows = [];
|
|
12
|
+
const scenarios = [];
|
|
10
13
|
const outputs = new Set(apps.map(app => path.resolve(root,app.file)));
|
|
11
14
|
function digest(file) { return createHash("sha256").update(readFileSync(file)).digest("hex"); }
|
|
12
15
|
function visit(directory) {
|
|
@@ -15,10 +18,14 @@ export function previewSourceRevision(options, apps = options.config.mcp.apps ??
|
|
|
15
18
|
const file = path.join(directory,entry.name);
|
|
16
19
|
if (outputs.has(file) || previewFileIgnored(options,file)) continue;
|
|
17
20
|
if (entry.isDirectory()) visit(file);
|
|
18
|
-
else if (entry.isFile() && /\.(?:[cm]?[jt]sx?|css|html|json|md|svg|png|jpe?g|webp|gif|woff2?|ttf|otf|lock|lockb)$/.test(file))
|
|
21
|
+
else if (entry.isFile() && /\.(?:[cm]?[jt]sx?|css|html|json|md|svg|png|jpe?g|webp|gif|woff2?|ttf|otf|lock|lockb)$/.test(file)) {
|
|
22
|
+
rows.push([path.relative(root,file),digest(file)]);
|
|
23
|
+
if (isScenarioFile(file)) scenarios.push(file);
|
|
24
|
+
}
|
|
19
25
|
}
|
|
20
26
|
}
|
|
21
27
|
visit(root);
|
|
28
|
+
rows.push(["scenario-group-structure",scenarioGroupFingerprint(options,scenarios)]);
|
|
22
29
|
const installed = path.join(root,"node_modules/.package-lock.json");
|
|
23
30
|
rows.push(["installed-packages",existsSync(installed) ? digest(installed) : null]);
|
|
24
31
|
return createHash("sha256").update(JSON.stringify(rows.sort((a,b)=>a[0].localeCompare(b[0])))).digest("hex");
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { readdirSync, statSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { isInside, isScenarioFile, sourceFiles } from "./config.mjs";
|
|
4
|
+
|
|
5
|
+
const children = directory => readdirSync(directory, { withFileTypes: true }).filter(entry => !entry.name.startsWith("."));
|
|
6
|
+
|
|
7
|
+
/** Grouping depends on directory entries, including files outside source globs. */
|
|
8
|
+
export function scenarioGroupFingerprint(options, files) {
|
|
9
|
+
const dsRoot = options.dsRoot ?? path.resolve(options.root, options.config.dsDir);
|
|
10
|
+
const directories = new Set();
|
|
11
|
+
for (const file of (files ?? sourceFiles(dsRoot)).filter(isScenarioFile)) {
|
|
12
|
+
const layer = path.relative(dsRoot, file).split(path.sep)[0];
|
|
13
|
+
if (!["components", "patterns", "composition"].includes(layer)) continue;
|
|
14
|
+
const boundary = path.join(dsRoot, layer);
|
|
15
|
+
for (let directory = path.dirname(file); directory !== boundary && isInside(boundary, directory); directory = path.dirname(directory)) directories.add(directory);
|
|
16
|
+
}
|
|
17
|
+
return JSON.stringify([...directories].sort().map(directory => [path.relative(dsRoot, directory), children(directory)
|
|
18
|
+
.map(entry => [entry.name, entry.isDirectory() ? "directory" : entry.isSymbolicLink() ? "symlink" : "file"])
|
|
19
|
+
.sort(([left], [right]) => left.localeCompare(right))]));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Group containers organize owners; an owner's own directory is never a group. */
|
|
23
|
+
export function createScenarioGroups({ dsRoot }) {
|
|
24
|
+
const containers = new Map();
|
|
25
|
+
function container(directory) {
|
|
26
|
+
if (!containers.has(directory)) {
|
|
27
|
+
try {
|
|
28
|
+
const entries = children(directory);
|
|
29
|
+
containers.set(directory, entries.length > 0 && entries.every(entry => entry.isDirectory() && !entry.isSymbolicLink()));
|
|
30
|
+
} catch { containers.set(directory, false); }
|
|
31
|
+
}
|
|
32
|
+
return containers.get(directory);
|
|
33
|
+
}
|
|
34
|
+
return (file, owner) => {
|
|
35
|
+
const relative = path.relative(dsRoot, file), layer = relative.split(path.sep)[0];
|
|
36
|
+
if (!["components", "patterns", "composition"].includes(layer)) return undefined;
|
|
37
|
+
const boundary = path.join(dsRoot, layer);
|
|
38
|
+
let directory = owner ? path.join(dsRoot, owner) : path.dirname(file);
|
|
39
|
+
try { if (!statSync(directory).isDirectory()) directory = path.dirname(directory); }
|
|
40
|
+
catch { directory = path.dirname(directory); }
|
|
41
|
+
const groups = [];
|
|
42
|
+
for (directory = path.dirname(directory); directory !== boundary && isInside(boundary, directory); directory = path.dirname(directory)) {
|
|
43
|
+
if (container(directory)) groups.unshift(path.basename(directory));
|
|
44
|
+
}
|
|
45
|
+
return groups.length ? groups.join(" / ") : undefined;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
@@ -16,7 +16,7 @@ const fileDigest = file => { try { return digest(readFileSync(file)); } catch {
|
|
|
16
16
|
* Cache state is development output, never proof that a failed build is current. */
|
|
17
17
|
export function createPreviewCache(options, compilerFiles = []) {
|
|
18
18
|
const { root } = options;
|
|
19
|
-
const adapterFiles = [import.meta.filename, ...["preview-files.mjs", "preview-inputs.mjs", "preview-resources.mjs", "preview-scope.mjs", "scenarios-vite.mjs", "linaria.mjs", "linaria/atomic-css.cjs", "linaria/atomic-styled.cjs", "linaria/preserve-values.cjs"].map(file => path.join(import.meta.dirname, file)), ...compilerFiles,
|
|
19
|
+
const adapterFiles = [import.meta.filename, ...["preview-builder.mjs", "preview-files.mjs", "preview-inputs.mjs", "preview-resources.mjs", "preview-scope.mjs", "scenario-groups.mjs", "scenarios-vite.mjs", "linaria.mjs", "linaria/atomic-css.cjs", "linaria/atomic-styled.cjs", "linaria/preserve-values.cjs"].map(file => path.join(import.meta.dirname, file)), ...compilerFiles,
|
|
20
20
|
...["package.json", "package-lock.json", "bun.lock", "bun.lockb", "node_modules/.package-lock.json"].map(file => path.join(root, file))];
|
|
21
21
|
const adapterDigest = () => digest(JSON.stringify(adapterFiles.map(file => [file, fileDigest(file)])));
|
|
22
22
|
const loadedAdapter = adapterDigest();
|
|
@@ -206,7 +206,7 @@ export async function runScenarioCompiler(directory, { watched = false, validate
|
|
|
206
206
|
try { readPreviewManifest(options, { verify: true }); }
|
|
207
207
|
catch { reusable = false; }
|
|
208
208
|
}
|
|
209
|
-
const outcomes = await checkedBuild(stamp, () => reusable ? null : buildGraph(entries, options, track));
|
|
209
|
+
const outcomes = await checkedBuild(stamp, () => reusable ? null : buildGraph(entries, options, track, { watched }));
|
|
210
210
|
const failure = outcomes.find(outcome => outcome.status === "rejected");
|
|
211
211
|
if (failure) throw failure.reason;
|
|
212
212
|
cache.assertCompiler();
|
|
@@ -266,7 +266,7 @@ export async function runScenarioCompiler(directory, { watched = false, validate
|
|
|
266
266
|
}
|
|
267
267
|
if (!watched) {
|
|
268
268
|
for (const entry of entries) pending.add(entry.id);
|
|
269
|
-
await drain();
|
|
269
|
+
try { await drain(); } finally { await buildGraph?.close?.(); }
|
|
270
270
|
return;
|
|
271
271
|
}
|
|
272
272
|
let timer;
|
|
@@ -355,5 +355,6 @@ export async function runScenarioCompiler(directory, { watched = false, validate
|
|
|
355
355
|
console.log(`Scenario compiler ready: ${entries.length} entries; builds are requested on demand.`);
|
|
356
356
|
for (const signal of ["SIGINT", "SIGTERM"]) process.once(signal, () => {
|
|
357
357
|
stopped = true; clearTimeout(timer); clearInterval(reconcileTimer); for (const { watcher } of watchers.values()) watcher.close();
|
|
358
|
+
void buildGraph?.close?.();
|
|
358
359
|
});
|
|
359
360
|
}
|
package/dist/scenarios-vite.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import { loadConfig, isInside } from "./config.mjs";
|
|
|
4
4
|
import { inspectScenarios } from "./scenarios.mjs";
|
|
5
5
|
import { configureReviewAlias } from "./preview-resources.mjs";
|
|
6
6
|
export { createPreviewResources, previewEntriesPlugin } from "./preview-resources.mjs";
|
|
7
|
+
export { createVitePreviewBuilder } from "./preview-builder.mjs";
|
|
7
8
|
|
|
8
9
|
/** Project-owned rendering; this plugin supplies only discoverable module entries. */
|
|
9
10
|
export function scenarioRegistryPlugin(directory = process.cwd()) {
|
|
@@ -57,11 +58,18 @@ export function inlineScenarioHtml() {
|
|
|
57
58
|
}
|
|
58
59
|
for (const asset of Object.values(bundle)) {
|
|
59
60
|
if (asset.type !== "asset" || !asset.fileName.endsWith(".html")) continue;
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
// Match whole script elements so HTML-looking framework strings inside
|
|
62
|
+
// inlined JavaScript are never mistaken for document stylesheet links.
|
|
63
|
+
asset.source = asset.source.toString().replace(/<script\b[^>]*>[\s\S]*?<\/script>|<link\b[^>]*>/g, tag => {
|
|
64
|
+
if (tag.startsWith("<script")) {
|
|
65
|
+
const src = tag.match(/^<script\b[^>]*\bsrc="([^"]+)"/)?.[1];
|
|
66
|
+
if (!src) return tag;
|
|
67
|
+
const chunk = bundle[src.replace(/^\.\//, "").replace(/^\//, "")];
|
|
68
|
+
if (!chunk || chunk.type !== "chunk") throw new Error(`Cannot inline scenario module: ${src}`);
|
|
69
|
+
return `<script type="module">${chunk.code.replaceAll("</script", "<\\/script")}</script>`;
|
|
70
|
+
}
|
|
71
|
+
const href = tag.match(/\bhref="([^"]+)"/)?.[1];
|
|
72
|
+
if (!href) return tag;
|
|
65
73
|
const style = bundle[href.replace(/^\.\//, "").replace(/^\//, "")];
|
|
66
74
|
if (!style || style.type !== "asset" || !style.fileName.endsWith(".css")) throw new Error(`Cannot inline scenario style: ${href}`);
|
|
67
75
|
return `<style>${style.source.toString().replaceAll("</style", "<\\/style")}</style>`;
|
package/dist/scenarios.mjs
CHANGED
|
@@ -13,6 +13,7 @@ import { createScenarioTrace } from "./scenario-trace.mjs";
|
|
|
13
13
|
import { inspectRuntimeContracts } from "./runtime-contracts.mjs";
|
|
14
14
|
import { inspectUnitContracts } from "./unit-contracts.mjs";
|
|
15
15
|
import { inspectPaintContracts } from "./paint-contracts.mjs";
|
|
16
|
+
import { createScenarioGroups } from "./scenario-groups.mjs";
|
|
16
17
|
|
|
17
18
|
export const scenarioArtifact = (root, id) => path.join(root, ".ds/scenarios", id, "index.html");
|
|
18
19
|
|
|
@@ -52,6 +53,7 @@ export function inspectScenarios(options, suppliedProgram) {
|
|
|
52
53
|
const tokenInventory = inspectTokens(root, options);
|
|
53
54
|
const tokenNames = new Set(tokenInventory.tokens.map(token => token.name));
|
|
54
55
|
const units = inspectUnits(options);
|
|
56
|
+
const scenarioGroup = createScenarioGroups(options);
|
|
55
57
|
const scenarios = [];
|
|
56
58
|
const diagnostics = [...inspectUnitContracts(options).diagnostics,...inspectRuntimeContracts(options,program).diagnostics,...inspectPaintContracts(options).diagnostics];
|
|
57
59
|
const ids = new Set();
|
|
@@ -121,6 +123,7 @@ export function inspectScenarios(options, suppliedProgram) {
|
|
|
121
123
|
continue;
|
|
122
124
|
}
|
|
123
125
|
for(const field of Object.keys(metadata))if(!["id","title","kind","covers","exercises","tokens","samples","captureTargets"].includes(field))report(file,`Unknown scenario field ${field}.`,entryNode(field),{entry:field});
|
|
126
|
+
const group = scenarioGroup(file, units.owner(relative));
|
|
124
127
|
if(typeof metadata.title!=="string"||!metadata.title.trim()) {
|
|
125
128
|
report(file,"Scenario title must be a nonempty static string; independent render evidence is retained.",entryNode("title"),{entry:"title"});
|
|
126
129
|
metadata.title=id;
|
|
@@ -172,7 +175,7 @@ export function inspectScenarios(options, suppliedProgram) {
|
|
|
172
175
|
if(bindingTrace) findBindings(source);
|
|
173
176
|
const paintBindings = inspectRuntimeContracts(options,program).bindings.filter(binding=>reachable.has(binding.scope.apiName)).map(binding=>({owner:binding.unit,name:binding.name,scope:binding.scope.selector,prefix:binding.prefix,suffix:binding.suffix,tokens:tokenInventory.tokens.filter(token=>!token.owner||token.owner==="tokens"||token.owner===binding.unit).map(token=>token.name)}));
|
|
174
177
|
const paintAudit=contractDeclarations.some(contract=>contract.paintInputs?.some(input=>reachable.has(input.apiName)));
|
|
175
|
-
scenarios.push({ id, kind, title: metadata.title, ...(fixture ? { fixture: path.relative(root, fixture).replaceAll("\\", "/") } : {}), covers: [...new Set(metadata.covers)], ...(captureTargets ? { captureTargets } : {}), ...(Object.hasOwn(metadata, "exercises") ? { exercises: [...new Set(exercises)] } : {}), tokens, ...(metadata.samples ? { samples: metadata.samples } : {}), ...(paintBindings.length?{paintBindings}:{}), ...(paintAudit?{paintAudit:true}:{}), file: path.relative(root, file).replaceAll("\\", "/"), artifact: path.relative(root, scenarioArtifact(root, id)).replaceAll("\\", "/") });
|
|
178
|
+
scenarios.push({ id, kind, title: metadata.title, ...(group ? { group } : {}), ...(fixture ? { fixture: path.relative(root, fixture).replaceAll("\\", "/") } : {}), covers: [...new Set(metadata.covers)], ...(captureTargets ? { captureTargets } : {}), ...(Object.hasOwn(metadata, "exercises") ? { exercises: [...new Set(exercises)] } : {}), tokens, ...(metadata.samples ? { samples: metadata.samples } : {}), ...(paintBindings.length?{paintBindings}:{}), ...(paintAudit?{paintAudit:true}:{}), file: path.relative(root, file).replaceAll("\\", "/"), artifact: path.relative(root, scenarioArtifact(root, id)).replaceAll("\\", "/") });
|
|
176
179
|
}
|
|
177
180
|
return { scenarios: scenarios.sort((a, b) => a.id.localeCompare(b.id)), diagnostics };
|
|
178
181
|
}
|