@reqvire-org/ads 0.3.52 → 0.4.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 +10 -9
- package/dist/assets.mjs +16 -2
- package/dist/behaviors.mjs +6 -5
- package/dist/boundaries.mjs +5 -5
- package/dist/browser-audit/first-render.mjs +22 -0
- package/dist/browser-audit/image-shape.mjs +36 -0
- package/dist/browser-audit/render-states.mjs +61 -35
- package/dist/browser-audit/worker.mjs +47 -12
- package/dist/browser-audit.mjs +75 -12
- package/dist/bun-compiler.mjs +14 -7
- package/dist/check-service.mjs +83 -0
- package/dist/check.mjs +20 -18
- package/dist/cli.mjs +5 -3
- package/dist/config.mjs +20 -41
- package/dist/contracts.d.mts +9 -0
- package/dist/finding-rules.mjs +8 -1
- package/dist/font-rules.mjs +103 -0
- package/dist/fonts-generated.mjs +32 -12
- package/dist/generated-entries.mjs +131 -0
- package/dist/icons.mjs +1 -1
- package/dist/init.mjs +11 -32
- package/dist/layers.mjs +7 -3
- package/dist/lint-config.mjs +4 -2
- package/dist/mcp/catalog.mjs +2 -1
- package/dist/mcp/context.mjs +3 -3
- package/dist/mcp/drafts.mjs +136 -121
- package/dist/mcp/mutations.mjs +65 -19
- package/dist/mcp/preview-watch.mjs +31 -5
- package/dist/mcp/preview-widget.bundle.js +50 -47
- package/dist/mcp/project-widget.bundle.js +45 -42
- package/dist/mcp/prompts.mjs +1 -1
- package/dist/mcp/server.mjs +81 -40
- package/dist/mcp/showcase-host.mjs +20 -7
- package/dist/mcp/widget.bundle.js +49 -46
- package/dist/oxlint.mjs +3 -2
- package/dist/program-cache.mjs +36 -0
- package/dist/public-api.mjs +2 -1
- package/dist/scenarios-compiler.mjs +82 -14
- package/dist/scenarios-vite.mjs +1 -1
- package/dist/scenarios.mjs +4 -3
- package/dist/showcase/client.bundle.js +27 -27
- package/dist/showcase/index.html +2 -2
- package/dist/skills/ads-break-ui/SKILL.md +25 -28
- package/dist/skills/ads-break-ui/references/behaviors.md +7 -6
- package/dist/skills/ads-break-ui/references/captures.md +7 -32
- package/dist/skills/ads-break-ui/references/contracts.md +58 -25
- package/dist/skills/ads-break-ui/references/drafts.md +59 -43
- package/dist/skills/ads-break-ui/references/evidence.md +1 -1
- package/dist/skills/ads-break-ui/references/guarded-editing.md +58 -47
- package/dist/skills/ads-break-ui/references/review.md +9 -8
- package/dist/skills/ads-break-ui/references/scenarios.md +1 -1
- package/dist/skills/ads-break-ui/references/validation.md +8 -4
- package/dist/skills/ads-break-ui/references/workflows.md +15 -8
- package/dist/skills/ads-designer/SKILL.md +30 -31
- package/dist/skills/ads-designer/references/accessibility.md +9 -5
- package/dist/skills/ads-designer/references/behaviors.md +7 -6
- package/dist/skills/ads-designer/references/branding.md +2 -2
- package/dist/skills/ads-designer/references/captures.md +7 -32
- package/dist/skills/ads-designer/references/cli.md +5 -1
- package/dist/skills/ads-designer/references/contracts.md +58 -25
- package/dist/skills/ads-designer/references/drafts.md +59 -43
- package/dist/skills/ads-designer/references/evidence.md +1 -1
- package/dist/skills/ads-designer/references/guarded-editing.md +58 -47
- package/dist/skills/ads-designer/references/performance.md +57 -6
- package/dist/skills/ads-designer/references/review.md +9 -8
- package/dist/skills/ads-designer/references/scenarios.md +1 -1
- package/dist/skills/ads-designer/references/validation.md +8 -4
- package/dist/skills/ads-designer/references/workflows.md +15 -8
- package/dist/skills/ads-import/SKILL.md +25 -28
- package/dist/skills/ads-import/references/behaviors.md +7 -6
- package/dist/skills/ads-import/references/captures.md +7 -32
- package/dist/skills/ads-import/references/cli.md +5 -1
- package/dist/skills/ads-import/references/contracts.md +58 -25
- package/dist/skills/ads-import/references/drafts.md +59 -43
- package/dist/skills/ads-import/references/evidence.md +1 -1
- package/dist/skills/ads-import/references/guarded-editing.md +58 -47
- package/dist/skills/ads-import/references/review.md +9 -8
- package/dist/skills/ads-import/references/scenarios.md +1 -1
- package/dist/skills/ads-import/references/validation.md +8 -4
- package/dist/skills/ads-import/references/workflows.md +15 -8
- package/dist/skills/ads-motion/SKILL.md +25 -28
- package/dist/skills/ads-motion/references/behaviors.md +7 -6
- package/dist/skills/ads-motion/references/captures.md +7 -32
- package/dist/skills/ads-motion/references/contracts.md +58 -25
- package/dist/skills/ads-motion/references/drafts.md +59 -43
- package/dist/skills/ads-motion/references/evidence.md +1 -1
- package/dist/skills/ads-motion/references/guarded-editing.md +58 -47
- package/dist/skills/ads-motion/references/review.md +9 -8
- package/dist/skills/ads-motion/references/scenarios.md +1 -1
- package/dist/skills/ads-motion/references/validation.md +8 -4
- package/dist/skills/ads-motion/references/workflows.md +15 -8
- package/dist/skills/ads-port/SKILL.md +25 -28
- package/dist/skills/ads-port/references/behaviors.md +7 -6
- package/dist/skills/ads-port/references/captures.md +7 -32
- package/dist/skills/ads-port/references/cli.md +5 -1
- package/dist/skills/ads-port/references/contracts.md +58 -25
- package/dist/skills/ads-port/references/drafts.md +59 -43
- package/dist/skills/ads-port/references/evidence.md +1 -1
- package/dist/skills/ads-port/references/guarded-editing.md +58 -47
- package/dist/skills/ads-port/references/native-implementation.md +6 -6
- package/dist/skills/ads-port/references/review.md +9 -8
- package/dist/skills/ads-port/references/scenarios.md +1 -1
- package/dist/skills/ads-port/references/validation.md +8 -4
- package/dist/skills/ads-port/references/workflows.md +15 -8
- package/dist/starters/preact/design-system/components/Layout/Grid/Grid.ads.contract.ts +6 -0
- package/dist/starters/preact/design-system/review/token-preview/TokenPreview.ads.contract.ts +6 -0
- package/dist/starters/preact/ds.config.json +0 -14
- package/dist/starters/react/README.md +9 -5
- package/dist/starters/react/design-system/brand/Icons/AppIcon/AppIcon.ads.fixture.ts +1 -1
- package/dist/starters/react/design-system/brand/Identity/Logo/Logo.ads.fixture.ts +2 -2
- package/dist/starters/react/design-system/components/Actions/Button/Button.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/components/Actions/IconButton/IconButton.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/components/Content/Icon/Icon.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/components/Content/Image/Image.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/components/Content/Logo/Logo.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/components/Content/Logo/Logo.tsx +2 -2
- package/dist/starters/react/design-system/components/Forms/TextField/TextField.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/components/Layout/Grid/Grid.ads.contract.ts +6 -0
- package/dist/starters/react/design-system/components/Layout/Grid/Grid.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/controllers/Palette/Palette.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/index.ts +3 -7
- package/dist/starters/react/design-system/patterns/Search/SearchBar/SearchBar.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/review/brand-preview/BrandPreview.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/review/demo-frame/DemoFrame.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/review/grid-cell/GridCell.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/review/index.ts +4 -3
- package/dist/starters/react/design-system/review/screen-frame/ScreenFrame.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/review/token-preview/TokenPreview.ads.contract.ts +6 -0
- package/dist/starters/react/design-system/review/token-preview/TokenPreview.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/styles.css +1 -0
- package/dist/starters/react/ds.config.json +0 -14
- package/dist/style-boundaries.mjs +7 -6
- package/dist/test-boundaries.mjs +2 -2
- package/dist/themes-watch.mjs +9 -3
- package/dist/token-fixtures.mjs +1 -1
- package/dist/unit-contracts.mjs +38 -4
- package/dist/units.mjs +16 -91
- package/dist/validation-checks.mjs +7 -1
- package/docs/ADS.md +10 -10
- package/docs/ARCHITECTURE.md +104 -44
- package/docs/BEHAVIORS.md +8 -7
- package/docs/CACHING.md +15 -6
- package/docs/CHANGELOG.md +107 -12
- package/docs/COMPARISON.md +1 -1
- package/docs/CONTRACTS.md +10 -25
- package/docs/GUIDE.md +98 -57
- package/docs/MCP.md +116 -151
- package/package.json +7 -7
- package/dist/contract-migration.mjs +0 -110
- package/dist/mcp/draft-exports.mjs +0 -40
- package/dist/mcp/edit-preparation.mjs +0 -115
package/dist/oxlint.mjs
CHANGED
|
@@ -73,10 +73,11 @@ export default {
|
|
|
73
73
|
},
|
|
74
74
|
},
|
|
75
75
|
"no-inline-style": {
|
|
76
|
-
meta: { type: "problem", schema, messages: { inline: "Own visual styles in component/pattern Linaria. Put demo-only sizing and framing in a development-only review/ helper. Reserve
|
|
76
|
+
meta: { type: "problem", schema, messages: { inline: "Own visual styles in component/pattern Linaria. Put demo-only sizing and framing in a development-only review/ helper. Reserve the owner contract's styles.inline for documented measured geometry; add component props for deliberate product API needs." } },
|
|
77
77
|
create(context) {
|
|
78
78
|
const { root, config } = options(context);
|
|
79
|
-
|
|
79
|
+
// generateLintConfig lists the files owner contracts grant (styles.inline).
|
|
80
|
+
const allowed = (config.inlineStyleFiles ?? []).some((file) => path.resolve(root, file) === path.resolve(context.getFilename()));
|
|
80
81
|
return {
|
|
81
82
|
JSXAttribute(node) {
|
|
82
83
|
if (!allowed && node.name.type === "JSXIdentifier" && node.name.name === "style") context.report({ node, messageId: "inline" });
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
// TypeScript programs for ADS checks, reused within a long-lived process (the MCP server's
|
|
4
|
+
// check worker, the preview compiler, the registry inspector). Each purpose keeps its previous
|
|
5
|
+
// program and parsed source files, keyed by its root and compiler settings, so an unchanged file
|
|
6
|
+
// is never parsed again and the next program reuses the old structure. Files are compared by
|
|
7
|
+
// their text, so an edit always produces a fresh SourceFile. A one-shot process builds once.
|
|
8
|
+
// Candidate checks run in short-lived copies, so only the most recently used caches are kept.
|
|
9
|
+
const caches = new Map(), limit = 8;
|
|
10
|
+
|
|
11
|
+
export function cachedProgram(purpose, rootNames, compilerOptions) {
|
|
12
|
+
const signature = `${purpose}\0${JSON.stringify(compilerOptions)}`;
|
|
13
|
+
let cache = caches.get(signature);
|
|
14
|
+
if (cache) caches.delete(signature);
|
|
15
|
+
else cache = { previous: undefined, sources: new Map() };
|
|
16
|
+
caches.set(signature, cache);
|
|
17
|
+
while (caches.size > limit) caches.delete(caches.keys().next().value);
|
|
18
|
+
const host = ts.createCompilerHost(compilerOptions, true), load = host.getSourceFile.bind(host);
|
|
19
|
+
// New, deleted or changed modules must resolve again; reused trees never keep stale lookups.
|
|
20
|
+
host.hasInvalidatedResolutions = () => true;
|
|
21
|
+
host.getSourceFile = (file, languageVersion, onError, force) => {
|
|
22
|
+
const text = host.readFile(file), mode = JSON.stringify(languageVersion), cached = cache.sources.get(file);
|
|
23
|
+
if (!force && cached && cached.text === text && cached.mode === mode) return cached.source;
|
|
24
|
+
const source = load(file, languageVersion, onError, force);
|
|
25
|
+
if (source) cache.sources.set(file, { text, mode, source }); else cache.sources.delete(file);
|
|
26
|
+
return source;
|
|
27
|
+
};
|
|
28
|
+
const program = ts.createProgram({ rootNames, options: compilerOptions, host, oldProgram: cache.previous });
|
|
29
|
+
cache.previous = program;
|
|
30
|
+
const retained = new Set(program.getSourceFiles().map(file => file.fileName));
|
|
31
|
+
for (const file of cache.sources.keys()) if (!retained.has(file)) cache.sources.delete(file);
|
|
32
|
+
return program;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Forget every retained program, for tests and configuration changes. */
|
|
36
|
+
export function clearProgramCache() { caches.clear(); }
|
package/dist/public-api.mjs
CHANGED
|
@@ -3,6 +3,7 @@ import ts from "typescript";
|
|
|
3
3
|
import { isDevelopmentFile, isInside, isReviewFile } from "./config.mjs";
|
|
4
4
|
import { uiOperation } from "./ui-framework.mjs";
|
|
5
5
|
import { projectCompilerOptions } from "./boundaries.mjs";
|
|
6
|
+
import { cachedProgram } from "./program-cache.mjs";
|
|
6
7
|
|
|
7
8
|
const resolvedCallables = new WeakMap();
|
|
8
9
|
|
|
@@ -14,7 +15,7 @@ function resolvedCallable(program, options, name) {
|
|
|
14
15
|
const { dsRoot, config } = options;
|
|
15
16
|
const entryFile = path.join(dsRoot, config.publicEntry);
|
|
16
17
|
const compiler = projectCompilerOptions(options);
|
|
17
|
-
const semantic =
|
|
18
|
+
const semantic = cachedProgram(`public-api:${options.root}`, [entryFile], {
|
|
18
19
|
...compiler, allowJs: true,
|
|
19
20
|
paths: { ...compiler.paths, [config.publicAlias]: [entryFile] },
|
|
20
21
|
types: compiler.types ?? [],
|
|
@@ -221,14 +221,71 @@ export async function restoreCompiledPreviews(options, compilerFiles) {
|
|
|
221
221
|
return {restored:true,revision:publication.revision,scenarios:entries.length};
|
|
222
222
|
}
|
|
223
223
|
|
|
224
|
-
/**
|
|
225
|
-
|
|
224
|
+
/** One compile at a time in a process: the viewed draft first, then the project's view, then
|
|
225
|
+
* the project's other requests, then drafts' background work. */
|
|
226
|
+
function createScheduler() {
|
|
227
|
+
const queue = []; let running = false, order = 0;
|
|
228
|
+
function pump() {
|
|
229
|
+
if (running || !queue.length) return;
|
|
230
|
+
queue.sort((a, b) => a.priority - b.priority || a.order - b.order);
|
|
231
|
+
const job = queue.shift(); running = true;
|
|
232
|
+
Promise.resolve().then(job.run).then(job.resolve, job.reject).finally(() => { running = false; pump(); });
|
|
233
|
+
}
|
|
234
|
+
return kind => (run, { foreground = false } = {}) => new Promise((resolve, reject) => {
|
|
235
|
+
queue.push({ run, resolve, reject, order: order++, priority: foreground ? (kind === "draft" ? 0 : 1) : (kind === "draft" ? 3 : 2) });
|
|
236
|
+
pump();
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* The draft workspaces the MCP server lists in its control file compile in this process, each
|
|
242
|
+
* with the options setup(root) gives for its own root and a builder of its own. Compiler options
|
|
243
|
+
* fixed to one root cannot build a draft; each draft then reports that instead of waiting.
|
|
244
|
+
*/
|
|
245
|
+
function hostDrafts(file, setup, schedule) {
|
|
246
|
+
const instances = new Map();
|
|
247
|
+
async function reconcile() {
|
|
248
|
+
let wanted = [];
|
|
249
|
+
try { wanted = JSON.parse(readFileSync(file, "utf8")).drafts ?? []; } catch { /* No drafts yet. */ }
|
|
250
|
+
const sessions = new Set(wanted.map(entry => entry.session));
|
|
251
|
+
for (const [session, instance] of instances) if (!sessions.has(session)) { instances.delete(session); (await instance)?.stop(); }
|
|
252
|
+
for (const entry of wanted) {
|
|
253
|
+
if (instances.has(entry.session) || !isDraftPreviewWorkspace(entry.root)) continue;
|
|
254
|
+
const context = { session: entry.session, requestFile: entry.requestFile, statusFile: entry.statusFile, prewarm: false, schedule: schedule("draft") };
|
|
255
|
+
if (!setup) {
|
|
256
|
+
instances.set(entry.session, Promise.resolve(null));
|
|
257
|
+
createBuildReporter(entry.root, { apps: [], session: entry.session, file: entry.statusFile })
|
|
258
|
+
.failure(scopedPreviewFailure(new Error("This project's preview compiler passes runScenarioCompiler options for one root, so it cannot build drafts. Pass a function of the root that returns the options instead."), "project", "discovery"));
|
|
259
|
+
continue;
|
|
260
|
+
}
|
|
261
|
+
instances.set(entry.session, runScenarioCompiler(entry.root, draftRoot => ({ ...setup(draftRoot), watched: true, context }))
|
|
262
|
+
.catch(error => { console.error(error); instances.delete(entry.session); }));
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
void reconcile();
|
|
266
|
+
let timer;
|
|
267
|
+
const watcher = watch(path.dirname(file), (_event, name) => { if (String(name) === path.basename(file)) { clearTimeout(timer); timer = setTimeout(() => void reconcile(), 16); } });
|
|
268
|
+
return { async stop() { watcher.close(); clearTimeout(timer); for (const instance of instances.values()) (await instance)?.stop(); instances.clear(); } };
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* One project's compiler; the project supplies its own React/Preact build. `setup` is the
|
|
273
|
+
* options, or a function of the project root that returns them. A process may host several
|
|
274
|
+
* watched instances, the project and its draft workspaces, each with its own session, request
|
|
275
|
+
* and status file: the project instance hosts the drafts the MCP server lists, building each
|
|
276
|
+
* from setup(draftRoot), so it needs the function form.
|
|
277
|
+
*/
|
|
278
|
+
export async function runScenarioCompiler(directory, setup) {
|
|
226
279
|
const root = path.resolve(directory);
|
|
227
|
-
|
|
280
|
+
const { watched = false, validate, build, buildGraph, compilerFiles = [], context = {} } = typeof setup === "function" ? setup(root) : setup;
|
|
281
|
+
const control = process.env.ADS_MCP_DRAFT_CONTROL, hosting = watched && !context.session && control && existsSync(path.dirname(control));
|
|
282
|
+
const scheduler = hosting ? createScheduler() : null;
|
|
283
|
+
const { session: buildSession = process.env.ADS_MCP_BUILD_SESSION, requestFile = process.env.ADS_MCP_REQUEST_FILE, statusFile = process.env.ADS_MCP_BUILD_STATUS, prewarm: prewarmViews = process.env.ADS_MCP_PREWARM_VIEWS === "1", schedule = scheduler ? scheduler("project") : run => run() } = context;
|
|
284
|
+
let options = withPreviewSession(loadConfig(root), buildSession);
|
|
228
285
|
if (buildGraph && (!options.config.mcp.previewManifest || !options.config.framework)) throw new Error("Resource preview builds require an explicit framework and mcp.previewManifest in ds.config.json.");
|
|
229
286
|
const cache = createPreviewCache(options, compilerFiles);
|
|
230
287
|
function registry() {
|
|
231
|
-
options = withPreviewSession(loadConfig(root),
|
|
288
|
+
options = withPreviewSession(loadConfig(root), buildSession);
|
|
232
289
|
const result = discoverScenarioRegistry(options);
|
|
233
290
|
if (result.diagnostics.length) throw Object.assign(new Error(result.diagnostics.map(item => `${item.file}: ${item.message}`).join("\n")), { scenarios: result.scenarios });
|
|
234
291
|
mkdirSync(path.join(root, ".ds/scenarios"), { recursive: true });
|
|
@@ -243,11 +300,11 @@ export async function runScenarioCompiler(directory, { watched = false, validate
|
|
|
243
300
|
}
|
|
244
301
|
finally { if (watched && buildGraph) releaseScenarioRegistry(root); }
|
|
245
302
|
const buildApps = () => entries.map(entry => ({ id: entry.id, file: previewArtifactPath(options, entry.artifact) }));
|
|
246
|
-
const reporter = createBuildReporter(root, { apps: buildApps() });
|
|
303
|
+
const reporter = createBuildReporter(root, { apps: buildApps(), ...(buildSession ? { session: buildSession } : {}), ...(statusFile ? { file: statusFile } : {}) });
|
|
247
304
|
const requested = new Set();
|
|
248
305
|
const pending = new Set();
|
|
249
306
|
let active;
|
|
250
|
-
const prewarm = watched &&
|
|
307
|
+
const prewarm = watched && prewarmViews;
|
|
251
308
|
const warmed = new Set(), warmFailures = new Set();
|
|
252
309
|
let preferred, warming;
|
|
253
310
|
if(prewarm)try{preferred=JSON.parse(readFileSync(path.join(root,".ds/last-preview.json"),"utf8")).scenario;}catch{/* First startup warms the first view. */}
|
|
@@ -270,10 +327,14 @@ export async function runScenarioCompiler(directory, { watched = false, validate
|
|
|
270
327
|
let observedSourceRevision = previewSourceRevision(options);
|
|
271
328
|
let invalidation;
|
|
272
329
|
let fullRequest, completedFull;
|
|
273
|
-
|
|
330
|
+
// Keep the registry inspector warm while previews are in use: a cold TypeScript program costs ~1.7 s per edit.
|
|
331
|
+
const inspector = watched && buildGraph ? createScenarioInspector(root, { idleMs: 10 * 60 * 1000 }) : null;
|
|
274
332
|
let discovering, unknownRevision;
|
|
275
333
|
let liveCandidate, verifying = false;
|
|
334
|
+
let handle;
|
|
276
335
|
function failure(error) {
|
|
336
|
+
// A retired draft workspace is deleted while its instance stops: nothing left to report.
|
|
337
|
+
if (watched && !existsSync(root)) { handle?.stop(); return; }
|
|
277
338
|
try { reporter.failure(scopedPreviewFailure(error,"project","discovery")); } catch (reportError) { console.error(reportError); }
|
|
278
339
|
console.error(error);
|
|
279
340
|
if (!watched) process.exitCode = 1;
|
|
@@ -589,7 +650,8 @@ export async function runScenarioCompiler(directory, { watched = false, validate
|
|
|
589
650
|
const id = pending.has(active) ? active : pending.values().next().value;
|
|
590
651
|
pending.delete(id);
|
|
591
652
|
const entry = entries.find(entry => entry.id === id);
|
|
592
|
-
|
|
653
|
+
// Instances in one process take turns: the viewed draft, then the project, then warming.
|
|
654
|
+
if (entry) {warming=id;warmProgress();try{await schedule(() => compile(entry), { foreground: id === active });}finally{warming=undefined;warmProgress();}}
|
|
593
655
|
}
|
|
594
656
|
} catch (error) { failure(error); }
|
|
595
657
|
finally { compiling = false; }
|
|
@@ -612,11 +674,11 @@ export async function runScenarioCompiler(directory, { watched = false, validate
|
|
|
612
674
|
}).catch(error => { if (!stopped) failure(error); }).finally(() => { discovering = undefined; });
|
|
613
675
|
}
|
|
614
676
|
function request(startBuild = true) {
|
|
615
|
-
const file =
|
|
677
|
+
const file = requestFile;
|
|
616
678
|
if (!file || !existsSync(file)) return;
|
|
617
679
|
try {
|
|
618
680
|
const value = JSON.parse(readFileSync(file, "utf8"));
|
|
619
|
-
if (value.session !==
|
|
681
|
+
if (value.session !== buildSession) return;
|
|
620
682
|
if (typeof value.full === "string" && /^[\w-]{1,100}$/.test(value.full)) fullRequest = value.full;
|
|
621
683
|
if (value.invalidation !== invalidation) {
|
|
622
684
|
invalidation = value.invalidation;
|
|
@@ -658,7 +720,7 @@ export async function runScenarioCompiler(directory, { watched = false, validate
|
|
|
658
720
|
try {
|
|
659
721
|
// Registry inspection for live graphs runs in the verification worker.
|
|
660
722
|
// Existing entry identities can compile immediately while it checks.
|
|
661
|
-
if (buildGraph) options = withPreviewSession(loadConfig(root),
|
|
723
|
+
if (buildGraph) options = withPreviewSession(loadConfig(root), buildSession);
|
|
662
724
|
else entries = registry();
|
|
663
725
|
observedSourceRevision = previewSourceRevision(options);
|
|
664
726
|
registryFailure = undefined;
|
|
@@ -708,7 +770,7 @@ export async function runScenarioCompiler(directory, { watched = false, validate
|
|
|
708
770
|
if (addWatch(directory, (event, file, topology) => sourceChanged(event, file && path.join(relative, file), topology)) && !initial) sourceChanged("rename", relative, true);
|
|
709
771
|
}
|
|
710
772
|
mkdirSync(path.join(root, ".ds"), { recursive: true });
|
|
711
|
-
addWatch(path.join(root, ".ds"), (_event, file) => { if (file === path.basename(
|
|
773
|
+
addWatch(path.join(root, ".ds"), (_event, file) => { if (file === path.basename(requestFile ?? "")) request(); });
|
|
712
774
|
for (const [directory, { watcher }] of watchers) if (!wanted.has(directory) || !existsSync(directory)) {
|
|
713
775
|
watcher.close(); watchers.delete(directory);
|
|
714
776
|
if (!initial && directory !== root && directory !== path.join(root, ".ds")) sourceChanged("rename", path.relative(root, directory), true);
|
|
@@ -717,6 +779,8 @@ export async function runScenarioCompiler(directory, { watched = false, validate
|
|
|
717
779
|
}
|
|
718
780
|
reconcileWatches(true);
|
|
719
781
|
const reconcileTimer = setInterval(() => {
|
|
782
|
+
// A retired draft workspace disappears before its host stops this instance.
|
|
783
|
+
if (!existsSync(root)) { handle.stop(); return; }
|
|
720
784
|
reconcileWatches();
|
|
721
785
|
try {
|
|
722
786
|
const current = previewSourceRevision(options);
|
|
@@ -730,9 +794,13 @@ export async function runScenarioCompiler(directory, { watched = false, validate
|
|
|
730
794
|
request();
|
|
731
795
|
if(prewarm)void drain();
|
|
732
796
|
console.log(`Scenario compiler ready: ${entries.length} entries; ${prewarm?"sequential background warming enabled":"builds are requested on demand"}.`);
|
|
733
|
-
|
|
797
|
+
const drafts = hosting ? hostDrafts(control, typeof setup === "function" ? setup : null, scheduler) : null;
|
|
798
|
+
handle = { stop() {
|
|
799
|
+
if (stopped) return;
|
|
734
800
|
stopped = true; clearTimeout(timer); clearInterval(reconcileTimer); for (const { watcher } of watchers.values()) watcher.close();
|
|
801
|
+
void drafts?.stop();
|
|
735
802
|
void inspector?.close();
|
|
736
803
|
void buildGraph?.close?.();
|
|
737
|
-
}
|
|
804
|
+
} };
|
|
805
|
+
return handle;
|
|
738
806
|
}
|
package/dist/scenarios-vite.mjs
CHANGED
|
@@ -28,7 +28,7 @@ export function scenarioRegistryPlugin(directory = process.cwd()) {
|
|
|
28
28
|
},
|
|
29
29
|
configureServer(server) {
|
|
30
30
|
const changed = (file) => {
|
|
31
|
-
if (!isInside(options.dsRoot, file) || !/\.
|
|
31
|
+
if (!isInside(options.dsRoot, file) || !/\.[jt]sx?$/.test(file)) return;
|
|
32
32
|
const module = server.moduleGraph.getModuleById(resolved);
|
|
33
33
|
if (module) { server.moduleGraph.invalidateModule(module); server.ws.send({ type: "full-reload" }); }
|
|
34
34
|
};
|
package/dist/scenarios.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import ts from "typescript";
|
|
|
4
4
|
import { publicApi, scenarioApi } from "./public-api.mjs";
|
|
5
5
|
import { uiOperation } from "./ui-framework.mjs";
|
|
6
6
|
import { isDevelopmentFile, isInside, isScenarioFile, scenarioIdentity, sourceFiles } from "./config.mjs";
|
|
7
|
+
import { cachedProgram } from "./program-cache.mjs";
|
|
7
8
|
import { projectCompilerOptions } from "./boundaries.mjs";
|
|
8
9
|
import { inspectTokens } from "./tokens.mjs";
|
|
9
10
|
import { isSharedToken } from "./token-policy.mjs";
|
|
@@ -44,7 +45,7 @@ export function inspectScenarios(options, suppliedProgram) {
|
|
|
44
45
|
const { root, dsRoot } = options;
|
|
45
46
|
const files = sourceFiles(dsRoot).filter(isScenarioFile);
|
|
46
47
|
const contracts = inspectUnitContracts(options, suppliedProgram);
|
|
47
|
-
const program = suppliedProgram ?? contracts.program ??
|
|
48
|
+
const program = suppliedProgram ?? contracts.program ?? cachedProgram(`scenarios:${options.root}`, [path.join(dsRoot, options.config.publicEntry), path.join(dsRoot, options.config.reviewEntry), ...files], { ...projectCompilerOptions(options), allowJs: true });
|
|
48
49
|
const apis = scenarioApi(program, options);
|
|
49
50
|
const duplicate = apis.find((item, index) => apis.some((other, otherIndex) => index !== otherIndex && item.name === other.name));
|
|
50
51
|
const known = new Map(apis.filter(item => item.kind !== "controllers").map((item) => [item.name, item]));
|
|
@@ -106,9 +107,9 @@ export function inspectScenarios(options, suppliedProgram) {
|
|
|
106
107
|
if (props && !optional && checker.getTypeOfSymbolAtLocation(props, source).getProperties().some(item => !(item.flags & ts.SymbolFlags.Optional))) report(file, "Scenario entrypoints cannot require caller props. Supply required inputs in the colocated fixture adapter.");
|
|
107
108
|
}
|
|
108
109
|
}
|
|
109
|
-
const fixtureBase =
|
|
110
|
+
const fixtureBase = file.replace(/\.ads\.scenario\.[^.]+$/, ".ads.fixture");
|
|
110
111
|
const fixture = [".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs", ".json"].map(extension => fixtureBase + extension).find(existsSync);
|
|
111
|
-
if (!fixture) report(file, "Keep this scenario's inputs beside it
|
|
112
|
+
if (!fixture) report(file, "Keep this scenario's inputs beside it in <Owner>.ads.fixture.ts. An empty fixture is valid for a component without inputs.");
|
|
112
113
|
function entryNode(field, index) {
|
|
113
114
|
let value = metadataExpression;
|
|
114
115
|
const seen = new Set();
|