@agent-scope/cli 1.12.0 → 1.13.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/dist/cli.js +518 -37
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +478 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +478 -4
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -205,9 +205,9 @@ function createRL() {
|
|
|
205
205
|
});
|
|
206
206
|
}
|
|
207
207
|
async function ask(rl, question) {
|
|
208
|
-
return new Promise((
|
|
208
|
+
return new Promise((resolve12) => {
|
|
209
209
|
rl.question(question, (answer) => {
|
|
210
|
-
|
|
210
|
+
resolve12(answer.trim());
|
|
211
211
|
});
|
|
212
212
|
});
|
|
213
213
|
}
|
|
@@ -3143,12 +3143,12 @@ async function runBaseline(options = {}) {
|
|
|
3143
3143
|
mkdirSync(rendersDir, { recursive: true });
|
|
3144
3144
|
let manifest;
|
|
3145
3145
|
if (manifestPath !== void 0) {
|
|
3146
|
-
const { readFileSync:
|
|
3146
|
+
const { readFileSync: readFileSync9 } = await import('fs');
|
|
3147
3147
|
const absPath = resolve(rootDir, manifestPath);
|
|
3148
3148
|
if (!existsSync(absPath)) {
|
|
3149
3149
|
throw new Error(`Manifest not found at ${absPath}.`);
|
|
3150
3150
|
}
|
|
3151
|
-
manifest = JSON.parse(
|
|
3151
|
+
manifest = JSON.parse(readFileSync9(absPath, "utf-8"));
|
|
3152
3152
|
process.stderr.write(`Loaded manifest from ${manifestPath}
|
|
3153
3153
|
`);
|
|
3154
3154
|
} else {
|
|
@@ -3309,6 +3309,479 @@ function registerBaselineSubCommand(reportCmd) {
|
|
|
3309
3309
|
}
|
|
3310
3310
|
);
|
|
3311
3311
|
}
|
|
3312
|
+
var DEFAULT_BASELINE_DIR2 = ".reactscope/baseline";
|
|
3313
|
+
function loadBaselineCompliance(baselineDir) {
|
|
3314
|
+
const compliancePath = resolve(baselineDir, "compliance.json");
|
|
3315
|
+
if (!existsSync(compliancePath)) return null;
|
|
3316
|
+
const raw = JSON.parse(readFileSync(compliancePath, "utf-8"));
|
|
3317
|
+
return raw;
|
|
3318
|
+
}
|
|
3319
|
+
function loadBaselineRenderJson(baselineDir, componentName) {
|
|
3320
|
+
const jsonPath = resolve(baselineDir, "renders", `${componentName}.json`);
|
|
3321
|
+
if (!existsSync(jsonPath)) return null;
|
|
3322
|
+
return JSON.parse(readFileSync(jsonPath, "utf-8"));
|
|
3323
|
+
}
|
|
3324
|
+
var _pool5 = null;
|
|
3325
|
+
async function getPool5(viewportWidth, viewportHeight) {
|
|
3326
|
+
if (_pool5 === null) {
|
|
3327
|
+
_pool5 = new BrowserPool({
|
|
3328
|
+
size: { browsers: 1, pagesPerBrowser: 4 },
|
|
3329
|
+
viewportWidth,
|
|
3330
|
+
viewportHeight
|
|
3331
|
+
});
|
|
3332
|
+
await _pool5.init();
|
|
3333
|
+
}
|
|
3334
|
+
return _pool5;
|
|
3335
|
+
}
|
|
3336
|
+
async function shutdownPool5() {
|
|
3337
|
+
if (_pool5 !== null) {
|
|
3338
|
+
await _pool5.close();
|
|
3339
|
+
_pool5 = null;
|
|
3340
|
+
}
|
|
3341
|
+
}
|
|
3342
|
+
async function renderComponent2(filePath, componentName, props, viewportWidth, viewportHeight) {
|
|
3343
|
+
const pool = await getPool5(viewportWidth, viewportHeight);
|
|
3344
|
+
const htmlHarness = await buildComponentHarness(filePath, componentName, props, viewportWidth);
|
|
3345
|
+
const slot = await pool.acquire();
|
|
3346
|
+
const { page } = slot;
|
|
3347
|
+
try {
|
|
3348
|
+
await page.setContent(htmlHarness, { waitUntil: "load" });
|
|
3349
|
+
await page.waitForFunction(
|
|
3350
|
+
() => {
|
|
3351
|
+
const w = window;
|
|
3352
|
+
return w.__SCOPE_RENDER_COMPLETE__ === true;
|
|
3353
|
+
},
|
|
3354
|
+
{ timeout: 15e3 }
|
|
3355
|
+
);
|
|
3356
|
+
const renderError = await page.evaluate(() => {
|
|
3357
|
+
return window.__SCOPE_RENDER_ERROR__ ?? null;
|
|
3358
|
+
});
|
|
3359
|
+
if (renderError !== null) {
|
|
3360
|
+
throw new Error(`Component render error: ${renderError}`);
|
|
3361
|
+
}
|
|
3362
|
+
const rootDir = process.cwd();
|
|
3363
|
+
const classes = await page.evaluate(() => {
|
|
3364
|
+
const set = /* @__PURE__ */ new Set();
|
|
3365
|
+
document.querySelectorAll("[class]").forEach((el) => {
|
|
3366
|
+
for (const c of el.className.split(/\s+/)) {
|
|
3367
|
+
if (c) set.add(c);
|
|
3368
|
+
}
|
|
3369
|
+
});
|
|
3370
|
+
return [...set];
|
|
3371
|
+
});
|
|
3372
|
+
const projectCss = await getCompiledCssForClasses(rootDir, classes);
|
|
3373
|
+
if (projectCss != null && projectCss.length > 0) {
|
|
3374
|
+
await page.addStyleTag({ content: projectCss });
|
|
3375
|
+
}
|
|
3376
|
+
const startMs = performance.now();
|
|
3377
|
+
const rootLocator = page.locator("[data-reactscope-root]");
|
|
3378
|
+
const boundingBox = await rootLocator.boundingBox();
|
|
3379
|
+
if (boundingBox === null || boundingBox.width === 0 || boundingBox.height === 0) {
|
|
3380
|
+
throw new Error(
|
|
3381
|
+
`Component "${componentName}" rendered with zero bounding box \u2014 it may be invisible or not mounted`
|
|
3382
|
+
);
|
|
3383
|
+
}
|
|
3384
|
+
const PAD = 24;
|
|
3385
|
+
const MIN_W = 320;
|
|
3386
|
+
const MIN_H = 200;
|
|
3387
|
+
const clipX = Math.max(0, boundingBox.x - PAD);
|
|
3388
|
+
const clipY = Math.max(0, boundingBox.y - PAD);
|
|
3389
|
+
const rawW = boundingBox.width + PAD * 2;
|
|
3390
|
+
const rawH = boundingBox.height + PAD * 2;
|
|
3391
|
+
const clipW = Math.max(rawW, MIN_W);
|
|
3392
|
+
const clipH = Math.max(rawH, MIN_H);
|
|
3393
|
+
const safeW = Math.min(clipW, viewportWidth - clipX);
|
|
3394
|
+
const safeH = Math.min(clipH, viewportHeight - clipY);
|
|
3395
|
+
const screenshot = await page.screenshot({
|
|
3396
|
+
clip: { x: clipX, y: clipY, width: safeW, height: safeH },
|
|
3397
|
+
type: "png"
|
|
3398
|
+
});
|
|
3399
|
+
const computedStylesRaw = {};
|
|
3400
|
+
const styles = await page.evaluate((sel) => {
|
|
3401
|
+
const el = document.querySelector(sel);
|
|
3402
|
+
if (el === null) return {};
|
|
3403
|
+
const computed = window.getComputedStyle(el);
|
|
3404
|
+
const out = {};
|
|
3405
|
+
for (const prop of [
|
|
3406
|
+
"display",
|
|
3407
|
+
"width",
|
|
3408
|
+
"height",
|
|
3409
|
+
"color",
|
|
3410
|
+
"backgroundColor",
|
|
3411
|
+
"fontSize",
|
|
3412
|
+
"fontFamily",
|
|
3413
|
+
"padding",
|
|
3414
|
+
"margin"
|
|
3415
|
+
]) {
|
|
3416
|
+
out[prop] = computed.getPropertyValue(prop);
|
|
3417
|
+
}
|
|
3418
|
+
return out;
|
|
3419
|
+
}, "[data-reactscope-root] > *");
|
|
3420
|
+
computedStylesRaw["[data-reactscope-root] > *"] = styles;
|
|
3421
|
+
const renderTimeMs = performance.now() - startMs;
|
|
3422
|
+
return {
|
|
3423
|
+
screenshot,
|
|
3424
|
+
width: Math.round(safeW),
|
|
3425
|
+
height: Math.round(safeH),
|
|
3426
|
+
renderTimeMs,
|
|
3427
|
+
computedStyles: computedStylesRaw
|
|
3428
|
+
};
|
|
3429
|
+
} finally {
|
|
3430
|
+
pool.release(slot);
|
|
3431
|
+
}
|
|
3432
|
+
}
|
|
3433
|
+
function extractComputedStyles2(computedStylesRaw) {
|
|
3434
|
+
const flat = {};
|
|
3435
|
+
for (const styles of Object.values(computedStylesRaw)) {
|
|
3436
|
+
Object.assign(flat, styles);
|
|
3437
|
+
}
|
|
3438
|
+
const colors = {};
|
|
3439
|
+
const spacing = {};
|
|
3440
|
+
const typography = {};
|
|
3441
|
+
const borders = {};
|
|
3442
|
+
const shadows = {};
|
|
3443
|
+
for (const [prop, value] of Object.entries(flat)) {
|
|
3444
|
+
if (prop === "color" || prop === "backgroundColor") {
|
|
3445
|
+
colors[prop] = value;
|
|
3446
|
+
} else if (prop === "padding" || prop === "margin") {
|
|
3447
|
+
spacing[prop] = value;
|
|
3448
|
+
} else if (prop === "fontSize" || prop === "fontFamily" || prop === "fontWeight" || prop === "lineHeight") {
|
|
3449
|
+
typography[prop] = value;
|
|
3450
|
+
} else if (prop === "borderRadius" || prop === "borderWidth") {
|
|
3451
|
+
borders[prop] = value;
|
|
3452
|
+
} else if (prop === "boxShadow") {
|
|
3453
|
+
shadows[prop] = value;
|
|
3454
|
+
}
|
|
3455
|
+
}
|
|
3456
|
+
return { colors, spacing, typography, borders, shadows };
|
|
3457
|
+
}
|
|
3458
|
+
function classifyComponent(entry, regressionThreshold) {
|
|
3459
|
+
if (entry.renderFailed) return "unchanged";
|
|
3460
|
+
if (entry.baselineCompliance === null && entry.currentCompliance !== null) {
|
|
3461
|
+
return "added";
|
|
3462
|
+
}
|
|
3463
|
+
if (entry.baselineCompliance !== null && entry.currentCompliance === null) {
|
|
3464
|
+
return "removed";
|
|
3465
|
+
}
|
|
3466
|
+
const delta = entry.complianceDelta;
|
|
3467
|
+
if (delta !== null) {
|
|
3468
|
+
if (delta <= -regressionThreshold) return "compliance_regressed";
|
|
3469
|
+
if (delta >= regressionThreshold) return "compliance_improved";
|
|
3470
|
+
}
|
|
3471
|
+
if (entry.baselineDimensions !== null && entry.currentDimensions !== null) {
|
|
3472
|
+
const dw = Math.abs(entry.currentDimensions.width - entry.baselineDimensions.width);
|
|
3473
|
+
const dh = Math.abs(entry.currentDimensions.height - entry.baselineDimensions.height);
|
|
3474
|
+
if (dw > 10 || dh > 10) return "size_changed";
|
|
3475
|
+
}
|
|
3476
|
+
return "unchanged";
|
|
3477
|
+
}
|
|
3478
|
+
async function runDiff(options = {}) {
|
|
3479
|
+
const {
|
|
3480
|
+
baselineDir: baselineDirRaw = DEFAULT_BASELINE_DIR2,
|
|
3481
|
+
componentsGlob,
|
|
3482
|
+
manifestPath,
|
|
3483
|
+
viewportWidth = 375,
|
|
3484
|
+
viewportHeight = 812,
|
|
3485
|
+
regressionThreshold = 0.01
|
|
3486
|
+
} = options;
|
|
3487
|
+
const startTime = performance.now();
|
|
3488
|
+
const rootDir = process.cwd();
|
|
3489
|
+
const baselineDir = resolve(rootDir, baselineDirRaw);
|
|
3490
|
+
if (!existsSync(baselineDir)) {
|
|
3491
|
+
throw new Error(
|
|
3492
|
+
`Baseline directory not found at "${baselineDir}". Run \`scope report baseline\` first to create a baseline snapshot.`
|
|
3493
|
+
);
|
|
3494
|
+
}
|
|
3495
|
+
const baselineManifestPath = resolve(baselineDir, "manifest.json");
|
|
3496
|
+
if (!existsSync(baselineManifestPath)) {
|
|
3497
|
+
throw new Error(
|
|
3498
|
+
`Baseline manifest.json not found at "${baselineManifestPath}". The baseline directory may be incomplete \u2014 re-run \`scope report baseline\`.`
|
|
3499
|
+
);
|
|
3500
|
+
}
|
|
3501
|
+
const baselineManifest = JSON.parse(readFileSync(baselineManifestPath, "utf-8"));
|
|
3502
|
+
const baselineCompliance = loadBaselineCompliance(baselineDir);
|
|
3503
|
+
const baselineComponentNames = new Set(Object.keys(baselineManifest.components));
|
|
3504
|
+
process.stderr.write(
|
|
3505
|
+
`Comparing against baseline at ${baselineDir} (${baselineComponentNames.size} components)
|
|
3506
|
+
`
|
|
3507
|
+
);
|
|
3508
|
+
let currentManifest;
|
|
3509
|
+
if (manifestPath !== void 0) {
|
|
3510
|
+
const absPath = resolve(rootDir, manifestPath);
|
|
3511
|
+
if (!existsSync(absPath)) {
|
|
3512
|
+
throw new Error(`Manifest not found at "${absPath}".`);
|
|
3513
|
+
}
|
|
3514
|
+
currentManifest = JSON.parse(readFileSync(absPath, "utf-8"));
|
|
3515
|
+
process.stderr.write(`Loaded manifest from ${manifestPath}
|
|
3516
|
+
`);
|
|
3517
|
+
} else {
|
|
3518
|
+
process.stderr.write("Scanning for React components\u2026\n");
|
|
3519
|
+
currentManifest = await generateManifest({ rootDir });
|
|
3520
|
+
const count = Object.keys(currentManifest.components).length;
|
|
3521
|
+
process.stderr.write(`Found ${count} components.
|
|
3522
|
+
`);
|
|
3523
|
+
}
|
|
3524
|
+
let componentNames = Object.keys(currentManifest.components);
|
|
3525
|
+
if (componentsGlob !== void 0) {
|
|
3526
|
+
componentNames = componentNames.filter((name) => matchGlob(componentsGlob, name));
|
|
3527
|
+
process.stderr.write(
|
|
3528
|
+
`Filtered to ${componentNames.length} components matching "${componentsGlob}".
|
|
3529
|
+
`
|
|
3530
|
+
);
|
|
3531
|
+
}
|
|
3532
|
+
const removedNames = [...baselineComponentNames].filter(
|
|
3533
|
+
(name) => !currentManifest.components[name] && (componentsGlob === void 0 || matchGlob(componentsGlob, name))
|
|
3534
|
+
);
|
|
3535
|
+
const total = componentNames.length;
|
|
3536
|
+
process.stderr.write(`Rendering ${total} components for diff\u2026
|
|
3537
|
+
`);
|
|
3538
|
+
const computedStylesMap = /* @__PURE__ */ new Map();
|
|
3539
|
+
const currentRenderMeta = /* @__PURE__ */ new Map();
|
|
3540
|
+
const renderFailures = /* @__PURE__ */ new Set();
|
|
3541
|
+
let completed = 0;
|
|
3542
|
+
const CONCURRENCY = 4;
|
|
3543
|
+
let nextIdx = 0;
|
|
3544
|
+
const renderOne = async (name) => {
|
|
3545
|
+
const descriptor = currentManifest.components[name];
|
|
3546
|
+
if (descriptor === void 0) return;
|
|
3547
|
+
const filePath = resolve(rootDir, descriptor.filePath);
|
|
3548
|
+
const outcome = await safeRender(
|
|
3549
|
+
() => renderComponent2(filePath, name, {}, viewportWidth, viewportHeight),
|
|
3550
|
+
{
|
|
3551
|
+
props: {},
|
|
3552
|
+
sourceLocation: {
|
|
3553
|
+
file: descriptor.filePath,
|
|
3554
|
+
line: descriptor.loc.start,
|
|
3555
|
+
column: 0
|
|
3556
|
+
}
|
|
3557
|
+
}
|
|
3558
|
+
);
|
|
3559
|
+
completed++;
|
|
3560
|
+
const pct = Math.round(completed / total * 100);
|
|
3561
|
+
if (isTTY()) {
|
|
3562
|
+
process.stderr.write(`${renderProgressBar(completed, total, name, pct)}\r`);
|
|
3563
|
+
}
|
|
3564
|
+
if (outcome.crashed) {
|
|
3565
|
+
renderFailures.add(name);
|
|
3566
|
+
return;
|
|
3567
|
+
}
|
|
3568
|
+
const result = outcome.result;
|
|
3569
|
+
currentRenderMeta.set(name, {
|
|
3570
|
+
width: result.width,
|
|
3571
|
+
height: result.height,
|
|
3572
|
+
renderTimeMs: result.renderTimeMs
|
|
3573
|
+
});
|
|
3574
|
+
computedStylesMap.set(name, extractComputedStyles2(result.computedStyles));
|
|
3575
|
+
};
|
|
3576
|
+
if (total > 0) {
|
|
3577
|
+
const worker = async () => {
|
|
3578
|
+
while (nextIdx < componentNames.length) {
|
|
3579
|
+
const i = nextIdx++;
|
|
3580
|
+
const name = componentNames[i];
|
|
3581
|
+
if (name !== void 0) {
|
|
3582
|
+
await renderOne(name);
|
|
3583
|
+
}
|
|
3584
|
+
}
|
|
3585
|
+
};
|
|
3586
|
+
const workers = [];
|
|
3587
|
+
for (let w = 0; w < Math.min(CONCURRENCY, total); w++) {
|
|
3588
|
+
workers.push(worker());
|
|
3589
|
+
}
|
|
3590
|
+
await Promise.all(workers);
|
|
3591
|
+
}
|
|
3592
|
+
await shutdownPool5();
|
|
3593
|
+
if (isTTY() && total > 0) {
|
|
3594
|
+
process.stderr.write("\n");
|
|
3595
|
+
}
|
|
3596
|
+
const resolver = new TokenResolver([]);
|
|
3597
|
+
const engine = new ComplianceEngine(resolver);
|
|
3598
|
+
const currentBatchReport = engine.auditBatch(computedStylesMap);
|
|
3599
|
+
const entries = [];
|
|
3600
|
+
for (const name of componentNames) {
|
|
3601
|
+
const baselineComp = baselineCompliance?.components[name] ?? null;
|
|
3602
|
+
const currentComp = currentBatchReport.components[name] ?? null;
|
|
3603
|
+
const baselineMeta = loadBaselineRenderJson(baselineDir, name);
|
|
3604
|
+
const currentMeta = currentRenderMeta.get(name) ?? null;
|
|
3605
|
+
const failed = renderFailures.has(name);
|
|
3606
|
+
const baselineComplianceScore = baselineComp?.aggregateCompliance ?? null;
|
|
3607
|
+
const currentComplianceScore = currentComp?.compliance ?? null;
|
|
3608
|
+
const delta = baselineComplianceScore !== null && currentComplianceScore !== null ? currentComplianceScore - baselineComplianceScore : null;
|
|
3609
|
+
const partial = {
|
|
3610
|
+
name,
|
|
3611
|
+
baselineCompliance: baselineComplianceScore,
|
|
3612
|
+
currentCompliance: currentComplianceScore,
|
|
3613
|
+
complianceDelta: delta,
|
|
3614
|
+
baselineDimensions: baselineMeta !== null ? { width: baselineMeta.width, height: baselineMeta.height } : null,
|
|
3615
|
+
currentDimensions: currentMeta !== null ? { width: currentMeta.width, height: currentMeta.height } : null,
|
|
3616
|
+
renderTimeMs: currentMeta?.renderTimeMs ?? null,
|
|
3617
|
+
renderFailed: failed
|
|
3618
|
+
};
|
|
3619
|
+
entries.push({ ...partial, status: classifyComponent(partial, regressionThreshold) });
|
|
3620
|
+
}
|
|
3621
|
+
for (const name of removedNames) {
|
|
3622
|
+
const baselineComp = baselineCompliance?.components[name] ?? null;
|
|
3623
|
+
const baselineMeta = loadBaselineRenderJson(baselineDir, name);
|
|
3624
|
+
entries.push({
|
|
3625
|
+
name,
|
|
3626
|
+
status: "removed",
|
|
3627
|
+
baselineCompliance: baselineComp?.aggregateCompliance ?? null,
|
|
3628
|
+
currentCompliance: null,
|
|
3629
|
+
complianceDelta: null,
|
|
3630
|
+
baselineDimensions: baselineMeta !== null ? { width: baselineMeta.width, height: baselineMeta.height } : null,
|
|
3631
|
+
currentDimensions: null,
|
|
3632
|
+
renderTimeMs: null,
|
|
3633
|
+
renderFailed: false
|
|
3634
|
+
});
|
|
3635
|
+
}
|
|
3636
|
+
const summary = {
|
|
3637
|
+
total: entries.length,
|
|
3638
|
+
added: entries.filter((e) => e.status === "added").length,
|
|
3639
|
+
removed: entries.filter((e) => e.status === "removed").length,
|
|
3640
|
+
unchanged: entries.filter((e) => e.status === "unchanged").length,
|
|
3641
|
+
complianceRegressed: entries.filter((e) => e.status === "compliance_regressed").length,
|
|
3642
|
+
complianceImproved: entries.filter((e) => e.status === "compliance_improved").length,
|
|
3643
|
+
sizeChanged: entries.filter((e) => e.status === "size_changed").length,
|
|
3644
|
+
renderFailed: entries.filter((e) => e.renderFailed).length
|
|
3645
|
+
};
|
|
3646
|
+
const hasRegressions = summary.complianceRegressed > 0 || summary.removed > 0 || summary.renderFailed > 0;
|
|
3647
|
+
const wallClockMs = performance.now() - startTime;
|
|
3648
|
+
return {
|
|
3649
|
+
diffedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3650
|
+
baselineDir,
|
|
3651
|
+
summary,
|
|
3652
|
+
components: entries,
|
|
3653
|
+
baselineAggregateCompliance: baselineCompliance?.aggregateCompliance ?? 0,
|
|
3654
|
+
currentAggregateCompliance: currentBatchReport.aggregateCompliance,
|
|
3655
|
+
hasRegressions,
|
|
3656
|
+
wallClockMs
|
|
3657
|
+
};
|
|
3658
|
+
}
|
|
3659
|
+
var STATUS_ICON = {
|
|
3660
|
+
added: "+",
|
|
3661
|
+
removed: "-",
|
|
3662
|
+
unchanged: " ",
|
|
3663
|
+
compliance_regressed: "\u2193",
|
|
3664
|
+
compliance_improved: "\u2191",
|
|
3665
|
+
size_changed: "~"
|
|
3666
|
+
};
|
|
3667
|
+
var STATUS_LABEL = {
|
|
3668
|
+
added: "added",
|
|
3669
|
+
removed: "removed",
|
|
3670
|
+
unchanged: "ok",
|
|
3671
|
+
compliance_regressed: "regressed",
|
|
3672
|
+
compliance_improved: "improved",
|
|
3673
|
+
size_changed: "size changed"
|
|
3674
|
+
};
|
|
3675
|
+
function formatDiffReport(result) {
|
|
3676
|
+
const lines = [];
|
|
3677
|
+
const title = "Scope Report Diff";
|
|
3678
|
+
const rule2 = "\u2501".repeat(Math.max(title.length, 40));
|
|
3679
|
+
lines.push(title, rule2);
|
|
3680
|
+
const complianceDelta = result.currentAggregateCompliance - result.baselineAggregateCompliance;
|
|
3681
|
+
const complianceSign = complianceDelta >= 0 ? "+" : "";
|
|
3682
|
+
lines.push(
|
|
3683
|
+
`Baseline compliance: ${(result.baselineAggregateCompliance * 100).toFixed(1)}%`,
|
|
3684
|
+
`Current compliance: ${(result.currentAggregateCompliance * 100).toFixed(1)}%`,
|
|
3685
|
+
`Delta: ${complianceSign}${(complianceDelta * 100).toFixed(1)}%`,
|
|
3686
|
+
""
|
|
3687
|
+
);
|
|
3688
|
+
const s = result.summary;
|
|
3689
|
+
lines.push(
|
|
3690
|
+
`Components: ${s.total} total ` + [
|
|
3691
|
+
s.added > 0 ? `${s.added} added` : "",
|
|
3692
|
+
s.removed > 0 ? `${s.removed} removed` : "",
|
|
3693
|
+
s.complianceRegressed > 0 ? `${s.complianceRegressed} regressed` : "",
|
|
3694
|
+
s.complianceImproved > 0 ? `${s.complianceImproved} improved` : "",
|
|
3695
|
+
s.sizeChanged > 0 ? `${s.sizeChanged} size changed` : "",
|
|
3696
|
+
s.renderFailed > 0 ? `${s.renderFailed} failed` : ""
|
|
3697
|
+
].filter(Boolean).join(" "),
|
|
3698
|
+
""
|
|
3699
|
+
);
|
|
3700
|
+
const notable = result.components.filter((e) => e.status !== "unchanged");
|
|
3701
|
+
if (notable.length === 0) {
|
|
3702
|
+
lines.push(" No changes detected.");
|
|
3703
|
+
} else {
|
|
3704
|
+
const nameWidth = Math.max(9, ...notable.map((e) => e.name.length));
|
|
3705
|
+
const header = `${"COMPONENT".padEnd(nameWidth)} ${"STATUS".padEnd(13)} ${"COMPLIANCE \u0394".padEnd(13)} DIMENSIONS`;
|
|
3706
|
+
const divider = "-".repeat(header.length);
|
|
3707
|
+
lines.push(header, divider);
|
|
3708
|
+
for (const entry of notable) {
|
|
3709
|
+
const icon = STATUS_ICON[entry.status];
|
|
3710
|
+
const label = STATUS_LABEL[entry.status].padEnd(13);
|
|
3711
|
+
const name = entry.name.padEnd(nameWidth);
|
|
3712
|
+
let complianceStr = "\u2014".padEnd(13);
|
|
3713
|
+
if (entry.complianceDelta !== null) {
|
|
3714
|
+
const sign = entry.complianceDelta >= 0 ? "+" : "";
|
|
3715
|
+
complianceStr = `${sign}${(entry.complianceDelta * 100).toFixed(1)}%`.padEnd(13);
|
|
3716
|
+
}
|
|
3717
|
+
let dimStr = "\u2014";
|
|
3718
|
+
if (entry.baselineDimensions !== null && entry.currentDimensions !== null) {
|
|
3719
|
+
const b = entry.baselineDimensions;
|
|
3720
|
+
const c = entry.currentDimensions;
|
|
3721
|
+
if (b.width !== c.width || b.height !== c.height) {
|
|
3722
|
+
dimStr = `${b.width}\xD7${b.height} \u2192 ${c.width}\xD7${c.height}`;
|
|
3723
|
+
} else {
|
|
3724
|
+
dimStr = `${c.width}\xD7${c.height}`;
|
|
3725
|
+
}
|
|
3726
|
+
} else if (entry.currentDimensions !== null) {
|
|
3727
|
+
dimStr = `${entry.currentDimensions.width}\xD7${entry.currentDimensions.height}`;
|
|
3728
|
+
} else if (entry.baselineDimensions !== null) {
|
|
3729
|
+
dimStr = `${entry.baselineDimensions.width}\xD7${entry.baselineDimensions.height} (removed)`;
|
|
3730
|
+
}
|
|
3731
|
+
if (entry.renderFailed) {
|
|
3732
|
+
dimStr = "render failed";
|
|
3733
|
+
}
|
|
3734
|
+
lines.push(`${icon} ${name} ${label} ${complianceStr} ${dimStr}`);
|
|
3735
|
+
}
|
|
3736
|
+
}
|
|
3737
|
+
lines.push(
|
|
3738
|
+
"",
|
|
3739
|
+
rule2,
|
|
3740
|
+
result.hasRegressions ? `Diff complete: ${result.summary.complianceRegressed + result.summary.renderFailed} regression(s) detected in ${(result.wallClockMs / 1e3).toFixed(1)}s` : `Diff complete: no regressions in ${(result.wallClockMs / 1e3).toFixed(1)}s`
|
|
3741
|
+
);
|
|
3742
|
+
return lines.join("\n");
|
|
3743
|
+
}
|
|
3744
|
+
function registerDiffSubCommand(reportCmd) {
|
|
3745
|
+
reportCmd.command("diff").description("Compare the current component library against a saved baseline snapshot").option("-b, --baseline <dir>", "Baseline directory to compare against", DEFAULT_BASELINE_DIR2).option("--components <glob>", "Glob pattern to diff a subset of components").option("--manifest <path>", "Path to an existing manifest.json to use instead of regenerating").option("--viewport <WxH>", "Viewport size, e.g. 1280x720", "375x812").option("--json", "Output diff as JSON instead of human-readable text", false).option("-o, --output <path>", "Write the diff JSON to a file").option(
|
|
3746
|
+
"--regression-threshold <n>",
|
|
3747
|
+
"Minimum compliance drop (0\u20131) to classify as a regression",
|
|
3748
|
+
"0.01"
|
|
3749
|
+
).action(
|
|
3750
|
+
async (opts) => {
|
|
3751
|
+
try {
|
|
3752
|
+
const [wStr, hStr] = opts.viewport.split("x");
|
|
3753
|
+
const viewportWidth = Number.parseInt(wStr ?? "375", 10);
|
|
3754
|
+
const viewportHeight = Number.parseInt(hStr ?? "812", 10);
|
|
3755
|
+
const regressionThreshold = Number.parseFloat(opts.regressionThreshold);
|
|
3756
|
+
const result = await runDiff({
|
|
3757
|
+
baselineDir: opts.baseline,
|
|
3758
|
+
componentsGlob: opts.components,
|
|
3759
|
+
manifestPath: opts.manifest,
|
|
3760
|
+
viewportWidth,
|
|
3761
|
+
viewportHeight,
|
|
3762
|
+
regressionThreshold
|
|
3763
|
+
});
|
|
3764
|
+
if (opts.output !== void 0) {
|
|
3765
|
+
writeFileSync(opts.output, JSON.stringify(result, null, 2), "utf-8");
|
|
3766
|
+
process.stderr.write(`Diff written to ${opts.output}
|
|
3767
|
+
`);
|
|
3768
|
+
}
|
|
3769
|
+
if (opts.json) {
|
|
3770
|
+
process.stdout.write(`${JSON.stringify(result, null, 2)}
|
|
3771
|
+
`);
|
|
3772
|
+
} else {
|
|
3773
|
+
process.stdout.write(`${formatDiffReport(result)}
|
|
3774
|
+
`);
|
|
3775
|
+
}
|
|
3776
|
+
process.exit(result.hasRegressions ? 1 : 0);
|
|
3777
|
+
} catch (err) {
|
|
3778
|
+
process.stderr.write(`Error: ${err instanceof Error ? err.message : String(err)}
|
|
3779
|
+
`);
|
|
3780
|
+
process.exit(2);
|
|
3781
|
+
}
|
|
3782
|
+
}
|
|
3783
|
+
);
|
|
3784
|
+
}
|
|
3312
3785
|
|
|
3313
3786
|
// src/tree-formatter.ts
|
|
3314
3787
|
var BRANCH2 = "\u251C\u2500\u2500 ";
|
|
@@ -4126,6 +4599,7 @@ function createProgram(options = {}) {
|
|
|
4126
4599
|
const existingReportCmd = program.commands.find((c) => c.name() === "report");
|
|
4127
4600
|
if (existingReportCmd !== void 0) {
|
|
4128
4601
|
registerBaselineSubCommand(existingReportCmd);
|
|
4602
|
+
registerDiffSubCommand(existingReportCmd);
|
|
4129
4603
|
}
|
|
4130
4604
|
return program;
|
|
4131
4605
|
}
|