@decocms/parity 0.33.30 → 0.33.32
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 +927 -62
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -65597,7 +65597,7 @@ function listCommand(output) {
|
|
|
65597
65597
|
}
|
|
65598
65598
|
|
|
65599
65599
|
// src/commands/migrate.ts
|
|
65600
|
-
import { existsSync as
|
|
65600
|
+
import { existsSync as existsSync21, mkdirSync as mkdirSync17, readFileSync as readFileSync26, writeFileSync as writeFileSync26 } from "node:fs";
|
|
65601
65601
|
import { resolve as resolve6 } from "node:path";
|
|
65602
65602
|
import chalk20 from "chalk";
|
|
65603
65603
|
import open from "open";
|
|
@@ -66541,7 +66541,8 @@ function buildMigrationPlan(input) {
|
|
|
66541
66541
|
label: source.label,
|
|
66542
66542
|
dir: source.dir,
|
|
66543
66543
|
notes: inventory.notes,
|
|
66544
|
-
...input.searched ? { searched: input.searched } : {}
|
|
66544
|
+
...input.searched ? { searched: input.searched } : {},
|
|
66545
|
+
...input.project ? { project: input.project } : {}
|
|
66545
66546
|
},
|
|
66546
66547
|
target: { name: bundle.target ?? null },
|
|
66547
66548
|
pages: bundle.pages.map((p) => ({
|
|
@@ -67150,6 +67151,186 @@ function formatSourceHunt(result) {
|
|
|
67150
67151
|
return lines.join(`
|
|
67151
67152
|
`);
|
|
67152
67153
|
}
|
|
67154
|
+
// src/migrate/sources/project.ts
|
|
67155
|
+
import { existsSync as existsSync20, readFileSync as readFileSync25, readdirSync as readdirSync6 } from "node:fs";
|
|
67156
|
+
import { join as join34 } from "node:path";
|
|
67157
|
+
var MAX_PROPS_CHARS = 4000;
|
|
67158
|
+
var MAX_PAGES = 60;
|
|
67159
|
+
var MAX_SECTIONS_PER_PAGE = 40;
|
|
67160
|
+
function extractPropsBlock(source) {
|
|
67161
|
+
const m = /export\s+(?:interface|type)\s+Props\b/.exec(source);
|
|
67162
|
+
if (!m)
|
|
67163
|
+
return { block: null, truncated: false };
|
|
67164
|
+
const start = m.index;
|
|
67165
|
+
const open = source.indexOf("{", start);
|
|
67166
|
+
if (open === -1)
|
|
67167
|
+
return { block: null, truncated: false };
|
|
67168
|
+
let depth = 0;
|
|
67169
|
+
for (let i = open;i < source.length; i++) {
|
|
67170
|
+
const ch = source[i];
|
|
67171
|
+
if (ch === "{")
|
|
67172
|
+
depth++;
|
|
67173
|
+
else if (ch === "}") {
|
|
67174
|
+
depth--;
|
|
67175
|
+
if (depth === 0) {
|
|
67176
|
+
const block = source.slice(start, i + 1);
|
|
67177
|
+
return block.length > MAX_PROPS_CHARS ? { block: block.slice(0, MAX_PROPS_CHARS), truncated: true } : { block, truncated: false };
|
|
67178
|
+
}
|
|
67179
|
+
}
|
|
67180
|
+
}
|
|
67181
|
+
const rest = source.slice(start, start + MAX_PROPS_CHARS);
|
|
67182
|
+
return { block: rest, truncated: true };
|
|
67183
|
+
}
|
|
67184
|
+
var LOCAL_PREFIXES = [
|
|
67185
|
+
[/^\$store\//, ""],
|
|
67186
|
+
[/^site\//, ""],
|
|
67187
|
+
[/^\$live\//, ""]
|
|
67188
|
+
];
|
|
67189
|
+
function classifyImports(source, fromFile) {
|
|
67190
|
+
const specs = new Set;
|
|
67191
|
+
for (const re of [/from\s+["']([^"']+)["']/g, /import\s+["']([^"']+)["']/g]) {
|
|
67192
|
+
for (const m of source.matchAll(re))
|
|
67193
|
+
if (m[1])
|
|
67194
|
+
specs.add(m[1]);
|
|
67195
|
+
}
|
|
67196
|
+
const dir = fromFile.includes("/") ? fromFile.slice(0, fromFile.lastIndexOf("/")) : "";
|
|
67197
|
+
const imports = new Set;
|
|
67198
|
+
const external = new Set;
|
|
67199
|
+
for (const spec of specs) {
|
|
67200
|
+
if (spec.startsWith("./") || spec.startsWith("../")) {
|
|
67201
|
+
const parts = [...dir.split("/").filter(Boolean), ...spec.split("/")];
|
|
67202
|
+
const stack = [];
|
|
67203
|
+
for (const part of parts) {
|
|
67204
|
+
if (part === "." || part === "")
|
|
67205
|
+
continue;
|
|
67206
|
+
if (part === "..")
|
|
67207
|
+
stack.pop();
|
|
67208
|
+
else
|
|
67209
|
+
stack.push(part);
|
|
67210
|
+
}
|
|
67211
|
+
imports.add(stack.join("/"));
|
|
67212
|
+
continue;
|
|
67213
|
+
}
|
|
67214
|
+
const local = LOCAL_PREFIXES.find(([re]) => re.test(spec));
|
|
67215
|
+
if (local) {
|
|
67216
|
+
imports.add(spec.replace(local[0], local[1]));
|
|
67217
|
+
continue;
|
|
67218
|
+
}
|
|
67219
|
+
external.add(spec);
|
|
67220
|
+
}
|
|
67221
|
+
return {
|
|
67222
|
+
imports: [...imports].sort(),
|
|
67223
|
+
externalImports: [...external].sort()
|
|
67224
|
+
};
|
|
67225
|
+
}
|
|
67226
|
+
function readComponentDetail(repoDir, file) {
|
|
67227
|
+
const abs = join34(repoDir, file);
|
|
67228
|
+
let source;
|
|
67229
|
+
try {
|
|
67230
|
+
source = readFileSync25(abs, "utf8");
|
|
67231
|
+
} catch {
|
|
67232
|
+
return null;
|
|
67233
|
+
}
|
|
67234
|
+
const props = extractPropsBlock(source);
|
|
67235
|
+
const { imports, externalImports } = classifyImports(source, file);
|
|
67236
|
+
return {
|
|
67237
|
+
file,
|
|
67238
|
+
propsBlock: props.block,
|
|
67239
|
+
propsTruncated: props.truncated,
|
|
67240
|
+
imports,
|
|
67241
|
+
externalImports
|
|
67242
|
+
};
|
|
67243
|
+
}
|
|
67244
|
+
var TOKEN_CANDIDATES = [
|
|
67245
|
+
"tailwind.config.ts",
|
|
67246
|
+
"tailwind.config.js",
|
|
67247
|
+
"tailwind.css",
|
|
67248
|
+
"static/tailwind.css",
|
|
67249
|
+
"styles/configs/typography.json",
|
|
67250
|
+
"styles/configs/color.json"
|
|
67251
|
+
];
|
|
67252
|
+
function findTokenFiles(repoDir) {
|
|
67253
|
+
return TOKEN_CANDIDATES.filter((f) => existsSync20(join34(repoDir, f)));
|
|
67254
|
+
}
|
|
67255
|
+
function readDecoPages(repoDir) {
|
|
67256
|
+
const blocksDir = join34(repoDir, ".deco", "blocks");
|
|
67257
|
+
if (!existsSync20(blocksDir))
|
|
67258
|
+
return { pages: [], total: 0 };
|
|
67259
|
+
let files;
|
|
67260
|
+
try {
|
|
67261
|
+
files = readdirSync6(blocksDir).filter((f) => f.startsWith("pages-") && f.endsWith(".json"));
|
|
67262
|
+
} catch {
|
|
67263
|
+
return { pages: [], total: 0 };
|
|
67264
|
+
}
|
|
67265
|
+
const pages = [];
|
|
67266
|
+
for (const file of files.sort()) {
|
|
67267
|
+
if (pages.length >= MAX_PAGES)
|
|
67268
|
+
break;
|
|
67269
|
+
let parsed;
|
|
67270
|
+
try {
|
|
67271
|
+
parsed = JSON.parse(readFileSync25(join34(blocksDir, file), "utf8"));
|
|
67272
|
+
} catch {
|
|
67273
|
+
continue;
|
|
67274
|
+
}
|
|
67275
|
+
if (typeof parsed !== "object" || parsed === null)
|
|
67276
|
+
continue;
|
|
67277
|
+
const entry = parsed;
|
|
67278
|
+
if (typeof entry.path !== "string" || !Array.isArray(entry.sections))
|
|
67279
|
+
continue;
|
|
67280
|
+
const sections = [];
|
|
67281
|
+
for (const raw of entry.sections) {
|
|
67282
|
+
if (sections.length >= MAX_SECTIONS_PER_PAGE)
|
|
67283
|
+
break;
|
|
67284
|
+
if (typeof raw !== "object" || raw === null)
|
|
67285
|
+
continue;
|
|
67286
|
+
const sec = raw;
|
|
67287
|
+
const type = typeof sec.__resolveType === "string" ? sec.__resolveType : "(unknown)";
|
|
67288
|
+
const propKeys = Object.keys(sec).filter((k) => k !== "__resolveType");
|
|
67289
|
+
sections.push({ type, propKeys });
|
|
67290
|
+
}
|
|
67291
|
+
pages.push({
|
|
67292
|
+
path: entry.path,
|
|
67293
|
+
name: typeof entry.name === "string" ? entry.name : entry.path,
|
|
67294
|
+
file: `.deco/blocks/${file}`,
|
|
67295
|
+
sections,
|
|
67296
|
+
sectionsTruncated: entry.sections.length > sections.length
|
|
67297
|
+
});
|
|
67298
|
+
}
|
|
67299
|
+
return { pages, total: files.length };
|
|
67300
|
+
}
|
|
67301
|
+
function readSourceProject(repoDir, components) {
|
|
67302
|
+
const detail = {};
|
|
67303
|
+
for (const c of components) {
|
|
67304
|
+
if (!c.file)
|
|
67305
|
+
continue;
|
|
67306
|
+
const d = readComponentDetail(repoDir, c.file);
|
|
67307
|
+
if (d)
|
|
67308
|
+
detail[c.name] = d;
|
|
67309
|
+
}
|
|
67310
|
+
const tokenFiles = findTokenFiles(repoDir);
|
|
67311
|
+
const { pages, total: pageTotal } = readDecoPages(repoDir);
|
|
67312
|
+
const notes = [];
|
|
67313
|
+
if (tokenFiles.length > 0) {
|
|
67314
|
+
notes.push(`Design tokens live in ${tokenFiles.join(", ")} — translate these rather than the theme elected from the capture.`);
|
|
67315
|
+
}
|
|
67316
|
+
if (pageTotal > 0) {
|
|
67317
|
+
notes.push(`${pageTotal} published CMS page(s) on disk under .deco/blocks/. Each one's section order and prop keys are recorded here; the prop VALUES move with \`parity cms\`.`);
|
|
67318
|
+
}
|
|
67319
|
+
if (pageTotal > pages.length) {
|
|
67320
|
+
notes.push(`Only the first ${pages.length} pages are recorded (cap) — absence here is not proof.`);
|
|
67321
|
+
}
|
|
67322
|
+
const withProps = Object.values(detail).filter((d) => d.propsBlock).length;
|
|
67323
|
+
if (withProps > 0) {
|
|
67324
|
+
notes.push(`${withProps} component(s) export a Props interface. That IS the CMS schema — translate it, do not redesign it.`);
|
|
67325
|
+
}
|
|
67326
|
+
return {
|
|
67327
|
+
components: detail,
|
|
67328
|
+
tokenFiles,
|
|
67329
|
+
pages,
|
|
67330
|
+
totals: { components: Object.keys(detail).length, pages: pageTotal },
|
|
67331
|
+
notes
|
|
67332
|
+
};
|
|
67333
|
+
}
|
|
67153
67334
|
|
|
67154
67335
|
// src/migrate/sources/index.ts
|
|
67155
67336
|
var SOURCES = [decoFresh, vtexIo];
|
|
@@ -67685,8 +67866,9 @@ async function migrateCommand(opts) {
|
|
|
67685
67866
|
source = s;
|
|
67686
67867
|
}
|
|
67687
67868
|
let sourceHunt = null;
|
|
67869
|
+
let sourceProject = null;
|
|
67688
67870
|
if (opts.source) {
|
|
67689
|
-
if (!
|
|
67871
|
+
if (!existsSync21(opts.source)) {
|
|
67690
67872
|
console.error(chalk20.red(`--source não encontrado: ${opts.source}`));
|
|
67691
67873
|
return 2;
|
|
67692
67874
|
}
|
|
@@ -67694,6 +67876,9 @@ async function migrateCommand(opts) {
|
|
|
67694
67876
|
source = detectSource(opts.source);
|
|
67695
67877
|
sourceInventory = source.inventory(opts.source);
|
|
67696
67878
|
console.log(chalk20.dim(` source: ${source.label} — ${sourceInventory.components.length} component(s) from code`));
|
|
67879
|
+
sourceProject = readSourceProject(opts.source, sourceInventory.components);
|
|
67880
|
+
for (const note of sourceProject.notes)
|
|
67881
|
+
console.log(chalk20.dim(` ${note}`));
|
|
67697
67882
|
} else if (!opts.noSourceHunt) {
|
|
67698
67883
|
sourceHunt = findSourceCandidates({
|
|
67699
67884
|
url: opts.url,
|
|
@@ -67717,7 +67902,7 @@ async function migrateCommand(opts) {
|
|
|
67717
67902
|
let screenshots;
|
|
67718
67903
|
let vtexBlocks = null;
|
|
67719
67904
|
let contentMap = {};
|
|
67720
|
-
if (!opts.refresh &&
|
|
67905
|
+
if (!opts.refresh && existsSync21(themePath) && existsSync21(assetsPath)) {
|
|
67721
67906
|
theme = readJson(themePath);
|
|
67722
67907
|
const meta = readJson(assetsPath);
|
|
67723
67908
|
platform = meta.platform;
|
|
@@ -67798,7 +67983,7 @@ async function migrateCommand(opts) {
|
|
|
67798
67983
|
}
|
|
67799
67984
|
const sitemapPath = resolve6(runDir, "sitemap.json");
|
|
67800
67985
|
let resolvedPages;
|
|
67801
|
-
if (!opts.refresh &&
|
|
67986
|
+
if (!opts.refresh && existsSync21(sitemapPath)) {
|
|
67802
67987
|
resolvedPages = readJson(sitemapPath).pages;
|
|
67803
67988
|
console.log(chalk20.dim(` phase 2 sitemap: cached (${resolvedPages.length} page(s))`));
|
|
67804
67989
|
} else {
|
|
@@ -67824,7 +68009,7 @@ async function migrateCommand(opts) {
|
|
|
67824
68009
|
}
|
|
67825
68010
|
const classified = sitemapUrls.slice(0, 500).map((u) => ({ url: u, kind: kindOf(u) }));
|
|
67826
68011
|
const sampled = sampleFromSitemap(classified, parseSample(opts.sample), resolvedPages);
|
|
67827
|
-
resolvedPages = [...resolvedPages, ...sampled].slice(0,
|
|
68012
|
+
resolvedPages = [...resolvedPages, ...sampled].slice(0, MAX_PAGES2);
|
|
67828
68013
|
if (sampled.length) {
|
|
67829
68014
|
const byKind = sampled.reduce((a, p) => {
|
|
67830
68015
|
a[p.kind] = (a[p.kind] ?? 0) + 1;
|
|
@@ -67842,7 +68027,7 @@ async function migrateCommand(opts) {
|
|
|
67842
68027
|
const capturePath = resolve6(runDir, "capture.json");
|
|
67843
68028
|
let pages;
|
|
67844
68029
|
let components;
|
|
67845
|
-
if (!opts.refresh &&
|
|
68030
|
+
if (!opts.refresh && existsSync21(capturePath)) {
|
|
67846
68031
|
const cached = readJson(capturePath);
|
|
67847
68032
|
pages = cached.pages;
|
|
67848
68033
|
components = cached.components;
|
|
@@ -67896,10 +68081,25 @@ async function migrateCommand(opts) {
|
|
|
67896
68081
|
why: c.why
|
|
67897
68082
|
}))
|
|
67898
68083
|
}
|
|
68084
|
+
} : {},
|
|
68085
|
+
...sourceProject ? {
|
|
68086
|
+
project: {
|
|
68087
|
+
file: "source-project.json",
|
|
68088
|
+
components: sourceProject.totals.components,
|
|
68089
|
+
pages: sourceProject.totals.pages,
|
|
68090
|
+
tokenFiles: sourceProject.tokenFiles,
|
|
68091
|
+
withPropsSchema: Object.values(sourceProject.components).filter((d) => d.propsBlock).length
|
|
68092
|
+
}
|
|
67899
68093
|
} : {}
|
|
67900
68094
|
}), loadPlan(runDir));
|
|
67901
68095
|
const plan = merged.plan;
|
|
67902
68096
|
savePlan(runDir, plan);
|
|
68097
|
+
if (sourceProject) {
|
|
68098
|
+
const projectPath = resolve6(runDir, "source-project.json");
|
|
68099
|
+
writeFileSync26(projectPath, `${JSON.stringify(sourceProject, null, 2)}
|
|
68100
|
+
`, "utf8");
|
|
68101
|
+
console.log(chalk20.dim(` source-project.json — ${sourceProject.totals.components} component detail(s), ${sourceProject.totals.pages} CMS page(s), ${sourceProject.tokenFiles.length} token file(s)`));
|
|
68102
|
+
}
|
|
67903
68103
|
if (merged.carried.length) {
|
|
67904
68104
|
console.log(chalk20.gray(` plan: carried ${merged.carried.length} recorded decision(s) forward`));
|
|
67905
68105
|
}
|
|
@@ -68094,7 +68294,7 @@ async function discoverSitemapUrls(page, baseUrl) {
|
|
|
68094
68294
|
}
|
|
68095
68295
|
}
|
|
68096
68296
|
var DEFAULT_SAMPLE = "plp=2,pdp=2,other=3,search=1";
|
|
68097
|
-
var
|
|
68297
|
+
var MAX_PAGES2 = 15;
|
|
68098
68298
|
var INSTITUTIONAL_URL = /(sobre|about|institucional|quem-somos|contato|contact|ajuda|help|faq|blog|trabalhe|careers|carreiras|politica|policy|privacidade|privacy|termos|terms|troca|devolu|garantia|warranty|lojas|stores|imprensa|press|sustentab|acessibilidade|cookies)/i;
|
|
68099
68299
|
function parseSample(spec) {
|
|
68100
68300
|
const out = {};
|
|
@@ -68179,7 +68379,7 @@ function printResults4(runDir, bundle) {
|
|
|
68179
68379
|
}
|
|
68180
68380
|
function readJson(path) {
|
|
68181
68381
|
try {
|
|
68182
|
-
return JSON.parse(
|
|
68382
|
+
return JSON.parse(readFileSync26(path, "utf8"));
|
|
68183
68383
|
} catch {
|
|
68184
68384
|
return null;
|
|
68185
68385
|
}
|
|
@@ -68225,7 +68425,7 @@ function sleep3(ms) {
|
|
|
68225
68425
|
}
|
|
68226
68426
|
|
|
68227
68427
|
// src/commands/plan.ts
|
|
68228
|
-
import { readFileSync as
|
|
68428
|
+
import { readFileSync as readFileSync27 } from "node:fs";
|
|
68229
68429
|
import chalk21 from "chalk";
|
|
68230
68430
|
|
|
68231
68431
|
// src/board/studio.ts
|
|
@@ -68649,7 +68849,7 @@ ${chalk21.bold("no page")} ${chalk21.gray("(in the code, not seen on any sampled
|
|
|
68649
68849
|
return 0;
|
|
68650
68850
|
}
|
|
68651
68851
|
try {
|
|
68652
|
-
const fixes = opts.fixes ? JSON.parse(
|
|
68852
|
+
const fixes = opts.fixes ? JSON.parse(readFileSync27(opts.fixes, "utf8")) : undefined;
|
|
68653
68853
|
const synced = await syncBoardToStudio(board, cfg, { repo: opts.repo, fixes });
|
|
68654
68854
|
let stored = 0;
|
|
68655
68855
|
for (const [path, id] of Object.entries(synced.ids)) {
|
|
@@ -68718,13 +68918,13 @@ Client notes (${notes.length})`));
|
|
|
68718
68918
|
}
|
|
68719
68919
|
|
|
68720
68920
|
// src/commands/pr.ts
|
|
68721
|
-
import { existsSync as
|
|
68722
|
-
import { join as
|
|
68921
|
+
import { existsSync as existsSync25, readFileSync as readFileSync30, writeFileSync as writeFileSync27 } from "node:fs";
|
|
68922
|
+
import { join as join37 } from "node:path";
|
|
68723
68923
|
import chalk24 from "chalk";
|
|
68724
68924
|
|
|
68725
68925
|
// src/commands/run.ts
|
|
68726
|
-
import { existsSync as
|
|
68727
|
-
import { join as
|
|
68926
|
+
import { existsSync as existsSync24, readFileSync as readFileSync29, unlinkSync as unlinkSync3 } from "node:fs";
|
|
68927
|
+
import { join as join36 } from "node:path";
|
|
68728
68928
|
import chalk23 from "chalk";
|
|
68729
68929
|
import ora8 from "ora";
|
|
68730
68930
|
|
|
@@ -69262,13 +69462,13 @@ function formatMs(ms) {
|
|
|
69262
69462
|
}
|
|
69263
69463
|
|
|
69264
69464
|
// src/commands/serve.ts
|
|
69265
|
-
import { existsSync as
|
|
69465
|
+
import { existsSync as existsSync23 } from "node:fs";
|
|
69266
69466
|
import chalk22 from "chalk";
|
|
69267
69467
|
|
|
69268
69468
|
// src/server/proxy-server.ts
|
|
69269
|
-
import { existsSync as
|
|
69469
|
+
import { existsSync as existsSync22, readFileSync as readFileSync28, statSync as statSync2 } from "node:fs";
|
|
69270
69470
|
import { createServer } from "node:http";
|
|
69271
|
-
import { extname, join as
|
|
69471
|
+
import { extname, join as join35, normalize as normalize3, resolve as resolve7, sep } from "node:path";
|
|
69272
69472
|
var MIME3 = {
|
|
69273
69473
|
".html": "text/html; charset=utf-8",
|
|
69274
69474
|
".css": "text/css; charset=utf-8",
|
|
@@ -69305,7 +69505,7 @@ var STRIPPED_REQUEST_HEADERS = new Set([
|
|
|
69305
69505
|
]);
|
|
69306
69506
|
async function startProxyServer(runDir, opts = {}) {
|
|
69307
69507
|
const absRunDir = resolve7(runDir);
|
|
69308
|
-
if (!
|
|
69508
|
+
if (!existsSync22(absRunDir)) {
|
|
69309
69509
|
throw new Error(`Run directory not found: ${runDir}`);
|
|
69310
69510
|
}
|
|
69311
69511
|
const server = createServer((req, res) => {
|
|
@@ -69362,13 +69562,13 @@ async function handleRequest(req, res, runDir) {
|
|
|
69362
69562
|
return serveStatic(res, runDir, path);
|
|
69363
69563
|
}
|
|
69364
69564
|
function serveReportHtml(res, runDir) {
|
|
69365
|
-
const filePath =
|
|
69366
|
-
if (!
|
|
69565
|
+
const filePath = join35(runDir, "report.html");
|
|
69566
|
+
if (!existsSync22(filePath)) {
|
|
69367
69567
|
res.statusCode = 404;
|
|
69368
69568
|
res.end("report.html not found");
|
|
69369
69569
|
return;
|
|
69370
69570
|
}
|
|
69371
|
-
const html =
|
|
69571
|
+
const html = readFileSync28(filePath, "utf8");
|
|
69372
69572
|
const inject = `<script>window.__parity_proxy = "/proxy?url=";</script>`;
|
|
69373
69573
|
const out = html.includes("</head>") ? html.replace("</head>", `${inject}</head>`) : `${inject}${html}`;
|
|
69374
69574
|
res.statusCode = 200;
|
|
@@ -69384,7 +69584,7 @@ function serveStatic(res, runDir, path) {
|
|
|
69384
69584
|
res.end("forbidden");
|
|
69385
69585
|
return;
|
|
69386
69586
|
}
|
|
69387
|
-
if (!
|
|
69587
|
+
if (!existsSync22(filePath)) {
|
|
69388
69588
|
res.statusCode = 404;
|
|
69389
69589
|
res.end("not found");
|
|
69390
69590
|
return;
|
|
@@ -69399,7 +69599,7 @@ function serveStatic(res, runDir, path) {
|
|
|
69399
69599
|
res.statusCode = 200;
|
|
69400
69600
|
res.setHeader("content-type", MIME3[ext] ?? "application/octet-stream");
|
|
69401
69601
|
res.setHeader("cache-control", "no-store");
|
|
69402
|
-
res.end(
|
|
69602
|
+
res.end(readFileSync28(filePath));
|
|
69403
69603
|
}
|
|
69404
69604
|
async function proxyRequest(req, res, targetUrl, opts = {}) {
|
|
69405
69605
|
let target;
|
|
@@ -69538,11 +69738,11 @@ async function serveRunAndBlock(runDir, opts = {}) {
|
|
|
69538
69738
|
}
|
|
69539
69739
|
async function serveCommand(runId, opts) {
|
|
69540
69740
|
const paths = getRunPaths(opts.output, runId);
|
|
69541
|
-
if (!
|
|
69741
|
+
if (!existsSync23(paths.runDir)) {
|
|
69542
69742
|
console.error(chalk22.red(`✖ Run não encontrado: ${runId} (em ${opts.output})`));
|
|
69543
69743
|
return 1;
|
|
69544
69744
|
}
|
|
69545
|
-
if (!
|
|
69745
|
+
if (!existsSync23(paths.reportHtml)) {
|
|
69546
69746
|
console.error(chalk22.red(`✖ report.html não existe em ${paths.runDir}`));
|
|
69547
69747
|
return 1;
|
|
69548
69748
|
}
|
|
@@ -69808,8 +70008,8 @@ async function runCommand(rawOpts) {
|
|
|
69808
70008
|
}
|
|
69809
70009
|
const ignore = loadParityIgnore();
|
|
69810
70010
|
if (opts.clearCache) {
|
|
69811
|
-
const cacheFile =
|
|
69812
|
-
if (
|
|
70011
|
+
const cacheFile = join36(opts.output, "cache", "verdicts.json");
|
|
70012
|
+
if (existsSync24(cacheFile)) {
|
|
69813
70013
|
try {
|
|
69814
70014
|
unlinkSync3(cacheFile);
|
|
69815
70015
|
console.log(chalk23.dim(` cache wiped: ${cacheFile}`));
|
|
@@ -70005,8 +70205,8 @@ ${formatTimingsSummary(partialTimings, buildFlowBreakdown(allFlowCaptures))}
|
|
|
70005
70205
|
const traceEnabled = process.env.PARITY_TRACE === "1";
|
|
70006
70206
|
const runOneSide = async (viewport, side) => {
|
|
70007
70207
|
const baseUrl = side === "prod" ? opts.prod : opts.cand;
|
|
70008
|
-
const harPath =
|
|
70009
|
-
const tracePath = traceEnabled ?
|
|
70208
|
+
const harPath = join36(paths.harDir, `${viewport}-${side}.har`);
|
|
70209
|
+
const tracePath = traceEnabled ? join36(paths.tracesDir, `${viewport}-${side}.zip`) : null;
|
|
70010
70210
|
const ctx = await newContext(browser, {
|
|
70011
70211
|
viewport,
|
|
70012
70212
|
harPath,
|
|
@@ -70328,7 +70528,7 @@ ${formatTimingsSummary(partialTimings, buildFlowBreakdown(allFlowCaptures))}
|
|
|
70328
70528
|
setSpinnerLabel("Rodando checks…");
|
|
70329
70529
|
spinner.start();
|
|
70330
70530
|
const checksHb = attachSpinnerHeartbeat(spinner, { baseText: "Rodando checks…" });
|
|
70331
|
-
const cacheDir =
|
|
70531
|
+
const cacheDir = join36(opts.output, "cache");
|
|
70332
70532
|
const checkCtx = {
|
|
70333
70533
|
prodPages: allPageCaptures.filter((p) => p.side === "prod"),
|
|
70334
70534
|
candPages: allPageCaptures.filter((p) => p.side === "cand"),
|
|
@@ -70531,10 +70731,10 @@ function parsePagePair(entry) {
|
|
|
70531
70731
|
}
|
|
70532
70732
|
function resolveExplicitPages(pagesFile, pagesList) {
|
|
70533
70733
|
if (pagesFile) {
|
|
70534
|
-
if (!
|
|
70734
|
+
if (!existsSync24(pagesFile)) {
|
|
70535
70735
|
throw new Error(`--pages-file não encontrado: ${pagesFile}`);
|
|
70536
70736
|
}
|
|
70537
|
-
const raw =
|
|
70737
|
+
const raw = readFileSync29(pagesFile, "utf-8");
|
|
70538
70738
|
const lines = raw.split(/\r?\n/).map((l) => l.trim()).filter((l) => l.length > 0 && !l.startsWith("#"));
|
|
70539
70739
|
for (const line of lines)
|
|
70540
70740
|
validatePageEntry(line, [], true);
|
|
@@ -70767,12 +70967,12 @@ async function prCommand(opts) {
|
|
|
70767
70967
|
return runCode || 1;
|
|
70768
70968
|
}
|
|
70769
70969
|
const latest = runs[0];
|
|
70770
|
-
const reportJsonPath =
|
|
70771
|
-
if (!
|
|
70970
|
+
const reportJsonPath = join37(opts.output, "runs", latest.id, "report.json");
|
|
70971
|
+
if (!existsSync25(reportJsonPath)) {
|
|
70772
70972
|
console.error(chalk24.red(`report.json not found at ${reportJsonPath}`));
|
|
70773
70973
|
return runCode || 1;
|
|
70774
70974
|
}
|
|
70775
|
-
const run = JSON.parse(
|
|
70975
|
+
const run = JSON.parse(readFileSync30(reportJsonPath, "utf8"));
|
|
70776
70976
|
const markdown = buildPrComment(run, opts);
|
|
70777
70977
|
if (opts.out) {
|
|
70778
70978
|
writeFileSync27(opts.out, markdown, "utf8");
|
|
@@ -70846,7 +71046,7 @@ function buildPrComment(run, opts) {
|
|
|
70846
71046
|
}
|
|
70847
71047
|
|
|
70848
71048
|
// src/commands/prompt.ts
|
|
70849
|
-
import { existsSync as
|
|
71049
|
+
import { existsSync as existsSync26, writeFileSync as writeFileSync28 } from "node:fs";
|
|
70850
71050
|
import chalk25 from "chalk";
|
|
70851
71051
|
function promptCommand(runId, opts) {
|
|
70852
71052
|
let run;
|
|
@@ -70863,7 +71063,7 @@ function promptCommand(runId, opts) {
|
|
|
70863
71063
|
if (opts.out) {
|
|
70864
71064
|
writeFileSync28(opts.out, md, "utf8");
|
|
70865
71065
|
console.log(chalk25.green(`✔ prompt salvo em ${opts.out}`));
|
|
70866
|
-
if (
|
|
71066
|
+
if (existsSync26(opts.out)) {
|
|
70867
71067
|
const sizeKb = (md.length / 1024).toFixed(1);
|
|
70868
71068
|
console.log(chalk25.dim(` ${md.length} chars (${sizeKb} KB)`));
|
|
70869
71069
|
}
|
|
@@ -70874,8 +71074,8 @@ function promptCommand(runId, opts) {
|
|
|
70874
71074
|
}
|
|
70875
71075
|
|
|
70876
71076
|
// src/commands/report.ts
|
|
70877
|
-
import { existsSync as
|
|
70878
|
-
import { join as
|
|
71077
|
+
import { existsSync as existsSync27, readFileSync as readFileSync31, writeFileSync as writeFileSync29 } from "node:fs";
|
|
71078
|
+
import { join as join38 } from "node:path";
|
|
70879
71079
|
import chalk26 from "chalk";
|
|
70880
71080
|
import open2 from "open";
|
|
70881
71081
|
|
|
@@ -71472,7 +71672,7 @@ async function reportCommand(runId, opts) {
|
|
|
71472
71672
|
return 1;
|
|
71473
71673
|
}
|
|
71474
71674
|
const html = renderDeckHtml(buildDeckModel(run), opts.lang ?? "en");
|
|
71475
|
-
const dest = opts.out ??
|
|
71675
|
+
const dest = opts.out ?? join38(paths.runDir, "deck.html");
|
|
71476
71676
|
writeFileSync29(dest, html, "utf8");
|
|
71477
71677
|
console.log(`${chalk26.green("✓")} deck → ${dest}`);
|
|
71478
71678
|
if (opts.open) {
|
|
@@ -71504,11 +71704,11 @@ async function reportCommand(runId, opts) {
|
|
|
71504
71704
|
return 1;
|
|
71505
71705
|
}
|
|
71506
71706
|
}
|
|
71507
|
-
if (!
|
|
71707
|
+
if (!existsSync27(paths.reportHtml)) {
|
|
71508
71708
|
console.error(chalk26.red(`report.html not found at ${paths.reportHtml}`));
|
|
71509
71709
|
return 1;
|
|
71510
71710
|
}
|
|
71511
|
-
const html =
|
|
71711
|
+
const html = readFileSync31(paths.reportHtml, "utf8");
|
|
71512
71712
|
const slice = extractReportSection({ kind: "html", section: opts.section, html });
|
|
71513
71713
|
if (slice === null) {
|
|
71514
71714
|
console.error(chalk26.red(`section "${opts.section}" not present in this report`));
|
|
@@ -71524,11 +71724,648 @@ async function reportCommand(runId, opts) {
|
|
|
71524
71724
|
return 0;
|
|
71525
71725
|
}
|
|
71526
71726
|
|
|
71727
|
+
// src/commands/bench.ts
|
|
71728
|
+
import { existsSync as existsSync28, mkdirSync as mkdirSync18, readFileSync as readFileSync32, writeFileSync as writeFileSync30 } from "node:fs";
|
|
71729
|
+
import { resolve as resolve8 } from "node:path";
|
|
71730
|
+
import chalk27 from "chalk";
|
|
71731
|
+
|
|
71732
|
+
// src/diff/motion.ts
|
|
71733
|
+
var WEIGHT = {
|
|
71734
|
+
"missing-transition": 100,
|
|
71735
|
+
"missing-animation": 100,
|
|
71736
|
+
"extra-transition": 70,
|
|
71737
|
+
"extra-animation": 70,
|
|
71738
|
+
keyframes: 60,
|
|
71739
|
+
"property-set": 50,
|
|
71740
|
+
"only-in-prod": 40,
|
|
71741
|
+
"only-in-cand": 30,
|
|
71742
|
+
duration: 20,
|
|
71743
|
+
easing: 15,
|
|
71744
|
+
delay: 10
|
|
71745
|
+
};
|
|
71746
|
+
function finding(node, kind, detail) {
|
|
71747
|
+
return { key: node.key, label: node.label, kind, detail, weight: WEIGHT[kind] };
|
|
71748
|
+
}
|
|
71749
|
+
function sameSet(a, b) {
|
|
71750
|
+
if (a.length !== b.length)
|
|
71751
|
+
return false;
|
|
71752
|
+
const sa = [...a].sort();
|
|
71753
|
+
const sb = [...b].sort();
|
|
71754
|
+
return sa.every((v, i) => v === sb[i]);
|
|
71755
|
+
}
|
|
71756
|
+
var list = (v) => v.length ? v.join(", ") : "none";
|
|
71757
|
+
function diffTransitions(p, c) {
|
|
71758
|
+
const out = [];
|
|
71759
|
+
const pOn = p.transition.properties.length > 0 && p.transition.durationsMs.some((d) => d > 0);
|
|
71760
|
+
const cOn = c.transition.properties.length > 0 && c.transition.durationsMs.some((d) => d > 0);
|
|
71761
|
+
if (pOn && !cOn) {
|
|
71762
|
+
out.push(finding(p, "missing-transition", `prod transitions ${list(p.transition.properties)} over ${Math.max(...p.transition.durationsMs)}ms; cand has no transition (the change is instant)`));
|
|
71763
|
+
return out;
|
|
71764
|
+
}
|
|
71765
|
+
if (!pOn && cOn) {
|
|
71766
|
+
out.push(finding(p, "extra-transition", `cand transitions ${list(c.transition.properties)}; prod does not (the migration added motion)`));
|
|
71767
|
+
return out;
|
|
71768
|
+
}
|
|
71769
|
+
if (!pOn && !cOn)
|
|
71770
|
+
return out;
|
|
71771
|
+
if (!sameSet(p.transition.properties, c.transition.properties)) {
|
|
71772
|
+
out.push(finding(p, "property-set", `transitioned properties differ: prod [${list(p.transition.properties)}] vs cand [${list(c.transition.properties)}]`));
|
|
71773
|
+
}
|
|
71774
|
+
const pd = Math.max(...p.transition.durationsMs);
|
|
71775
|
+
const cd = Math.max(...c.transition.durationsMs);
|
|
71776
|
+
if (pd !== cd) {
|
|
71777
|
+
out.push(finding(p, "duration", `transition duration ${pd}ms → ${cd}ms`));
|
|
71778
|
+
}
|
|
71779
|
+
if (!sameSet(p.transition.easings, c.transition.easings)) {
|
|
71780
|
+
out.push(finding(p, "easing", `transition easing [${list(p.transition.easings)}] → [${list(c.transition.easings)}]`));
|
|
71781
|
+
}
|
|
71782
|
+
const pdel = Math.max(0, ...p.transition.delaysMs);
|
|
71783
|
+
const cdel = Math.max(0, ...c.transition.delaysMs);
|
|
71784
|
+
if (pdel !== cdel) {
|
|
71785
|
+
out.push(finding(p, "delay", `transition delay ${pdel}ms → ${cdel}ms`));
|
|
71786
|
+
}
|
|
71787
|
+
return out;
|
|
71788
|
+
}
|
|
71789
|
+
function keyframesFingerprint(k) {
|
|
71790
|
+
return k.steps.map((s) => `${s.offset}:${Object.entries(s.declarations).sort().map(([a, b]) => `${a}=${b}`).join(";")}`).join("|");
|
|
71791
|
+
}
|
|
71792
|
+
function diffAnimations(p, c) {
|
|
71793
|
+
const out = [];
|
|
71794
|
+
const pNames = p.animation.names.filter((n) => n && n !== "none");
|
|
71795
|
+
const cNames = c.animation.names.filter((n) => n && n !== "none");
|
|
71796
|
+
if (pNames.length > 0 && cNames.length === 0) {
|
|
71797
|
+
out.push(finding(p, "missing-animation", `prod animates [${list(pNames)}]; cand has no animation`));
|
|
71798
|
+
return out;
|
|
71799
|
+
}
|
|
71800
|
+
if (pNames.length === 0 && cNames.length > 0) {
|
|
71801
|
+
out.push(finding(p, "extra-animation", `cand animates [${list(cNames)}]; prod does not`));
|
|
71802
|
+
return out;
|
|
71803
|
+
}
|
|
71804
|
+
if (pNames.length === 0)
|
|
71805
|
+
return out;
|
|
71806
|
+
const pd = Math.max(...p.animation.durationsMs);
|
|
71807
|
+
const cd = Math.max(...c.animation.durationsMs);
|
|
71808
|
+
if (pd !== cd)
|
|
71809
|
+
out.push(finding(p, "duration", `animation duration ${pd}ms → ${cd}ms`));
|
|
71810
|
+
for (const [i, name] of pNames.entries()) {
|
|
71811
|
+
const pk = p.keyframes[name];
|
|
71812
|
+
const cname = cNames[i];
|
|
71813
|
+
const ck = cname ? c.keyframes[cname] : undefined;
|
|
71814
|
+
if (!pk)
|
|
71815
|
+
continue;
|
|
71816
|
+
if (!ck) {
|
|
71817
|
+
out.push(finding(p, "keyframes", `prod's @keyframes ${name} has no counterpart on the cand side`));
|
|
71818
|
+
continue;
|
|
71819
|
+
}
|
|
71820
|
+
if (keyframesFingerprint(pk) !== keyframesFingerprint(ck)) {
|
|
71821
|
+
out.push(finding(p, "keyframes", `@keyframes differ (prod ${name}: ${pk.steps.length} steps, cand ${cname}: ${ck.steps.length} steps)`));
|
|
71822
|
+
}
|
|
71823
|
+
}
|
|
71824
|
+
return out;
|
|
71825
|
+
}
|
|
71826
|
+
function diffMotion(prod, cand, opts = {}) {
|
|
71827
|
+
const byKey = new Map(cand.nodes.map((n) => [n.key, n]));
|
|
71828
|
+
const labelSeen = new Map;
|
|
71829
|
+
for (const n of cand.nodes) {
|
|
71830
|
+
if (!n.label)
|
|
71831
|
+
continue;
|
|
71832
|
+
labelSeen.set(n.label, labelSeen.has(n.label) ? null : n);
|
|
71833
|
+
}
|
|
71834
|
+
const byLabel = new Map;
|
|
71835
|
+
for (const [k, v] of labelSeen)
|
|
71836
|
+
if (v)
|
|
71837
|
+
byLabel.set(k, v);
|
|
71838
|
+
const findings = [];
|
|
71839
|
+
const used = new Set;
|
|
71840
|
+
let matched = 0;
|
|
71841
|
+
for (const p of prod.nodes) {
|
|
71842
|
+
const c = byKey.get(p.key) ?? (p.label ? byLabel.get(p.label) : undefined);
|
|
71843
|
+
if (!c || used.has(c)) {
|
|
71844
|
+
findings.push(finding(p, "only-in-prod", `${p.tag}${p.label ? ` (${p.label})` : ""} has no counterpart`));
|
|
71845
|
+
continue;
|
|
71846
|
+
}
|
|
71847
|
+
used.add(c);
|
|
71848
|
+
matched++;
|
|
71849
|
+
findings.push(...diffTransitions(p, c), ...diffAnimations(p, c));
|
|
71850
|
+
}
|
|
71851
|
+
findings.sort((a, b) => b.weight - a.weight || a.key.localeCompare(b.key) || a.kind.localeCompare(b.kind));
|
|
71852
|
+
return {
|
|
71853
|
+
matched,
|
|
71854
|
+
findings: findings.slice(0, opts.maxFindings ?? 100),
|
|
71855
|
+
truncated: opts.truncated ?? (prod.truncated || cand.truncated)
|
|
71856
|
+
};
|
|
71857
|
+
}
|
|
71858
|
+
function isMotionClean(diff) {
|
|
71859
|
+
return diff.findings.length === 0;
|
|
71860
|
+
}
|
|
71861
|
+
function formatMotionDiff(diff, opts = {}) {
|
|
71862
|
+
if (isMotionClean(diff)) {
|
|
71863
|
+
return `motion: clean (${diff.matched} interactive elements matched)${diff.truncated ? " — TRUNCATED" : ""}`;
|
|
71864
|
+
}
|
|
71865
|
+
const limit = opts.limit ?? 30;
|
|
71866
|
+
const shown = diff.findings.slice(0, limit);
|
|
71867
|
+
const keyW = Math.max(4, ...shown.map((f) => f.key.length));
|
|
71868
|
+
const lines = shown.map((f) => `${f.key.padEnd(keyW)} ${f.kind.padEnd(20)} ${f.detail}`);
|
|
71869
|
+
if (diff.findings.length > shown.length) {
|
|
71870
|
+
lines.push(`… ${diff.findings.length - shown.length} more`);
|
|
71871
|
+
}
|
|
71872
|
+
if (diff.truncated)
|
|
71873
|
+
lines.push("TRUNCATED — element cap hit; absence of a finding is not proof");
|
|
71874
|
+
return lines.join(`
|
|
71875
|
+
`);
|
|
71876
|
+
}
|
|
71877
|
+
|
|
71878
|
+
// src/engine/motion.ts
|
|
71879
|
+
var LABEL_ATTRS2 = ["data-section", "data-testid", "data-fs-section", "data-manifest-key", "id"];
|
|
71880
|
+
async function readMotion(page, selector, opts = {}) {
|
|
71881
|
+
const maxNodes = opts.maxNodes ?? 80;
|
|
71882
|
+
const maxDepth = opts.maxDepth ?? 12;
|
|
71883
|
+
let exists = false;
|
|
71884
|
+
try {
|
|
71885
|
+
exists = await page.locator(selector).count() > 0;
|
|
71886
|
+
} catch (err) {
|
|
71887
|
+
return { found: false, error: `seletor inválido: ${err.message}` };
|
|
71888
|
+
}
|
|
71889
|
+
if (!exists) {
|
|
71890
|
+
return { found: false, error: `seletor '${selector}' não casou nenhum elemento` };
|
|
71891
|
+
}
|
|
71892
|
+
let got;
|
|
71893
|
+
try {
|
|
71894
|
+
got = await page.evaluate(({ sel, maxNodes, maxDepth, labelAttrs }) => {
|
|
71895
|
+
try {
|
|
71896
|
+
const root = document.querySelector(sel);
|
|
71897
|
+
if (!root || !(root instanceof HTMLElement)) {
|
|
71898
|
+
return { ok: false, reason: "querySelector retornou null ou non-HTMLElement" };
|
|
71899
|
+
}
|
|
71900
|
+
const ms = (v) => {
|
|
71901
|
+
const t = v.trim();
|
|
71902
|
+
if (t.endsWith("ms"))
|
|
71903
|
+
return Number.parseFloat(t) || 0;
|
|
71904
|
+
if (t.endsWith("s"))
|
|
71905
|
+
return (Number.parseFloat(t) || 0) * 1000;
|
|
71906
|
+
return 0;
|
|
71907
|
+
};
|
|
71908
|
+
const split = (v) => v.split(",").map((x) => x.trim()).filter(Boolean);
|
|
71909
|
+
const allKeyframes = {};
|
|
71910
|
+
const collect = (rules) => {
|
|
71911
|
+
for (const rule of Array.from(rules)) {
|
|
71912
|
+
if (rule instanceof CSSKeyframesRule) {
|
|
71913
|
+
const steps = [];
|
|
71914
|
+
for (const kf of Array.from(rule.cssRules)) {
|
|
71915
|
+
if (!(kf instanceof CSSKeyframeRule))
|
|
71916
|
+
continue;
|
|
71917
|
+
const declarations = {};
|
|
71918
|
+
const style = kf.style;
|
|
71919
|
+
for (let i = 0;i < style.length; i++) {
|
|
71920
|
+
const prop = style.item(i);
|
|
71921
|
+
if (prop)
|
|
71922
|
+
declarations[prop] = style.getPropertyValue(prop).trim();
|
|
71923
|
+
}
|
|
71924
|
+
const offset = kf.keyText.replace(/\bfrom\b/g, "0%").replace(/\bto\b/g, "100%").trim();
|
|
71925
|
+
steps.push({ offset, declarations });
|
|
71926
|
+
}
|
|
71927
|
+
steps.sort((a, b) => Number.parseFloat(a.offset) - Number.parseFloat(b.offset));
|
|
71928
|
+
allKeyframes[rule.name] = { name: rule.name, steps };
|
|
71929
|
+
} else if (rule instanceof CSSMediaRule || rule instanceof CSSSupportsRule) {
|
|
71930
|
+
collect(rule.cssRules);
|
|
71931
|
+
}
|
|
71932
|
+
}
|
|
71933
|
+
};
|
|
71934
|
+
for (const sheet of Array.from(document.styleSheets)) {
|
|
71935
|
+
try {
|
|
71936
|
+
collect(sheet.cssRules);
|
|
71937
|
+
} catch {}
|
|
71938
|
+
}
|
|
71939
|
+
const labelOf = (el) => {
|
|
71940
|
+
for (const a of labelAttrs) {
|
|
71941
|
+
const v = el.getAttribute(a);
|
|
71942
|
+
if (v)
|
|
71943
|
+
return v;
|
|
71944
|
+
}
|
|
71945
|
+
return null;
|
|
71946
|
+
};
|
|
71947
|
+
const INTERACTIVE = "a,button,input,select,textarea,summary,[role],[tabindex],label";
|
|
71948
|
+
const nodes = [];
|
|
71949
|
+
let truncated = false;
|
|
71950
|
+
const visit = (el, path, depth) => {
|
|
71951
|
+
if (nodes.length >= maxNodes) {
|
|
71952
|
+
truncated = true;
|
|
71953
|
+
return;
|
|
71954
|
+
}
|
|
71955
|
+
const cs = window.getComputedStyle(el);
|
|
71956
|
+
const transitionProps = split(cs.transitionProperty).filter((p) => p !== "none");
|
|
71957
|
+
const animationNames = split(cs.animationName).filter((n) => n !== "none");
|
|
71958
|
+
const interactive = el.matches(INTERACTIVE);
|
|
71959
|
+
const declaresMotion = transitionProps.length > 0 || animationNames.length > 0;
|
|
71960
|
+
if (interactive || declaresMotion) {
|
|
71961
|
+
const keyframes = {};
|
|
71962
|
+
for (const n of animationNames) {
|
|
71963
|
+
const k = allKeyframes[n];
|
|
71964
|
+
if (k)
|
|
71965
|
+
keyframes[n] = k;
|
|
71966
|
+
}
|
|
71967
|
+
nodes.push({
|
|
71968
|
+
key: path,
|
|
71969
|
+
tag: el.tagName.toLowerCase(),
|
|
71970
|
+
label: labelOf(el),
|
|
71971
|
+
reason: interactive ? "interactive" : "declares-motion",
|
|
71972
|
+
transition: {
|
|
71973
|
+
properties: transitionProps,
|
|
71974
|
+
durationsMs: split(cs.transitionDuration).map(ms),
|
|
71975
|
+
delaysMs: split(cs.transitionDelay).map(ms),
|
|
71976
|
+
easings: split(cs.transitionTimingFunction)
|
|
71977
|
+
},
|
|
71978
|
+
animation: {
|
|
71979
|
+
names: animationNames,
|
|
71980
|
+
durationsMs: split(cs.animationDuration).map(ms),
|
|
71981
|
+
delaysMs: split(cs.animationDelay).map(ms),
|
|
71982
|
+
easings: split(cs.animationTimingFunction),
|
|
71983
|
+
iterationCounts: split(cs.animationIterationCount)
|
|
71984
|
+
},
|
|
71985
|
+
keyframes
|
|
71986
|
+
});
|
|
71987
|
+
}
|
|
71988
|
+
if (depth >= maxDepth) {
|
|
71989
|
+
if (el.children.length > 0)
|
|
71990
|
+
truncated = true;
|
|
71991
|
+
return;
|
|
71992
|
+
}
|
|
71993
|
+
const perTag = {};
|
|
71994
|
+
for (const child of Array.from(el.children)) {
|
|
71995
|
+
const t = child.tagName.toLowerCase();
|
|
71996
|
+
const i = perTag[t] ?? 0;
|
|
71997
|
+
perTag[t] = i + 1;
|
|
71998
|
+
visit(child, `${path}>${t}[${i}]`, depth + 1);
|
|
71999
|
+
}
|
|
72000
|
+
};
|
|
72001
|
+
visit(root, root.tagName.toLowerCase(), 0);
|
|
72002
|
+
return { ok: true, nodes, truncated };
|
|
72003
|
+
} catch (err) {
|
|
72004
|
+
return {
|
|
72005
|
+
ok: false,
|
|
72006
|
+
reason: `leitura de motion falhou em '${sel}': ${err.message ?? "unknown"}`
|
|
72007
|
+
};
|
|
72008
|
+
}
|
|
72009
|
+
}, { sel: selector, maxNodes, maxDepth, labelAttrs: LABEL_ATTRS2 });
|
|
72010
|
+
} catch (err) {
|
|
72011
|
+
return {
|
|
72012
|
+
found: false,
|
|
72013
|
+
error: `falha no page.evaluate de '${selector}': ${err.message ?? "unknown"}. Se o seletor usa sintaxe Playwright-only (text=..., :visible, xpath=...), use um seletor CSS puro.`
|
|
72014
|
+
};
|
|
72015
|
+
}
|
|
72016
|
+
if (!got.ok)
|
|
72017
|
+
return { found: false, error: got.reason };
|
|
72018
|
+
return { found: true, nodes: got.nodes, truncated: got.truncated };
|
|
72019
|
+
}
|
|
72020
|
+
|
|
72021
|
+
// src/commands/bench.ts
|
|
72022
|
+
var BENCH_ROUTE = "/__parity/bench";
|
|
72023
|
+
var BENCH_SELECTOR = "[data-parity-bench]";
|
|
72024
|
+
function benchUrl(base, component, props) {
|
|
72025
|
+
const u = new URL(BENCH_ROUTE, base);
|
|
72026
|
+
u.searchParams.set("component", component);
|
|
72027
|
+
if (props !== undefined) {
|
|
72028
|
+
u.searchParams.set("props", Buffer.from(JSON.stringify(props), "utf8").toString("base64"));
|
|
72029
|
+
}
|
|
72030
|
+
return u.toString();
|
|
72031
|
+
}
|
|
72032
|
+
function isHarnessSide(explicitSelector) {
|
|
72033
|
+
return !explicitSelector;
|
|
72034
|
+
}
|
|
72035
|
+
async function gatherBenchSide(browser, opts) {
|
|
72036
|
+
const ctx = await newContext(browser, { viewport: opts.viewport });
|
|
72037
|
+
const page = await ctx.newPage();
|
|
72038
|
+
const side = {
|
|
72039
|
+
url: opts.url,
|
|
72040
|
+
selector: opts.selector,
|
|
72041
|
+
boxNodes: { found: false, error: "not read" },
|
|
72042
|
+
motion: { found: false, error: "not read" }
|
|
72043
|
+
};
|
|
72044
|
+
try {
|
|
72045
|
+
const res = await page.goto(opts.url, { waitUntil: "domcontentloaded", timeout: 30000 });
|
|
72046
|
+
if (res && res.status() >= 400) {
|
|
72047
|
+
side.error = `HTTP ${res.status()} — is the harness route mounted at ${BENCH_ROUTE}?`;
|
|
72048
|
+
return side;
|
|
72049
|
+
}
|
|
72050
|
+
await page.waitForLoadState("networkidle", { timeout: 8000 }).catch(() => {
|
|
72051
|
+
return;
|
|
72052
|
+
});
|
|
72053
|
+
if (opts.waitMs > 0)
|
|
72054
|
+
await page.waitForTimeout(opts.waitMs);
|
|
72055
|
+
side.boxNodes = await readBoxTree(page, opts.selector);
|
|
72056
|
+
side.motion = await readMotion(page, opts.selector);
|
|
72057
|
+
if (opts.screenshotPath && side.boxNodes.found) {
|
|
72058
|
+
const loc = page.locator(opts.selector).first();
|
|
72059
|
+
await loc.screenshot({ path: opts.screenshotPath, animations: "disabled", timeout: 1e4 }).then(() => {
|
|
72060
|
+
side.screenshotPath = opts.screenshotPath;
|
|
72061
|
+
}).catch(() => {
|
|
72062
|
+
return;
|
|
72063
|
+
});
|
|
72064
|
+
}
|
|
72065
|
+
} catch (err) {
|
|
72066
|
+
side.error = err.message;
|
|
72067
|
+
} finally {
|
|
72068
|
+
await page.close().catch(() => {
|
|
72069
|
+
return;
|
|
72070
|
+
});
|
|
72071
|
+
await ctx.close().catch(() => {
|
|
72072
|
+
return;
|
|
72073
|
+
});
|
|
72074
|
+
}
|
|
72075
|
+
return side;
|
|
72076
|
+
}
|
|
72077
|
+
async function benchCommand(opts) {
|
|
72078
|
+
const viewport = parseViewport3(opts.viewport);
|
|
72079
|
+
if (!viewport) {
|
|
72080
|
+
console.error(chalk27.red(`--viewport inválido: ${opts.viewport}`));
|
|
72081
|
+
return 2;
|
|
72082
|
+
}
|
|
72083
|
+
const waitMs = Number.parseInt(opts.wait, 10) || 0;
|
|
72084
|
+
let props;
|
|
72085
|
+
if (opts.props) {
|
|
72086
|
+
if (!existsSync28(opts.props)) {
|
|
72087
|
+
console.error(chalk27.red(`--props não encontrado: ${opts.props}`));
|
|
72088
|
+
return 2;
|
|
72089
|
+
}
|
|
72090
|
+
try {
|
|
72091
|
+
props = JSON.parse(readFileSync32(opts.props, "utf8"));
|
|
72092
|
+
} catch (err) {
|
|
72093
|
+
console.error(chalk27.red(`--props não é JSON válido: ${err.message}`));
|
|
72094
|
+
return 2;
|
|
72095
|
+
}
|
|
72096
|
+
}
|
|
72097
|
+
const prodIsHarness = isHarnessSide(opts.prodSelector);
|
|
72098
|
+
const candIsHarness = isHarnessSide(opts.candSelector);
|
|
72099
|
+
const prodUrl = prodIsHarness ? benchUrl(opts.prod, opts.component, props) : opts.prod;
|
|
72100
|
+
const candUrl = candIsHarness ? benchUrl(opts.cand, opts.component, props) : opts.cand;
|
|
72101
|
+
const prodSelector = opts.prodSelector ?? opts.selector ?? BENCH_SELECTOR;
|
|
72102
|
+
const candSelector = opts.candSelector ?? opts.selector ?? BENCH_SELECTOR;
|
|
72103
|
+
mkdirSync18(opts.outDir, { recursive: true });
|
|
72104
|
+
const slug = opts.component.replace(/[^a-zA-Z0-9]+/g, "-").toLowerCase();
|
|
72105
|
+
const prefix = `bench-${slug}-${viewport}`;
|
|
72106
|
+
const browser = await launchBrowser({ headless: true });
|
|
72107
|
+
try {
|
|
72108
|
+
const [prodSide, candSide] = await Promise.all([
|
|
72109
|
+
gatherBenchSide(browser, {
|
|
72110
|
+
url: prodUrl,
|
|
72111
|
+
selector: prodSelector,
|
|
72112
|
+
viewport,
|
|
72113
|
+
waitMs,
|
|
72114
|
+
screenshotPath: resolve8(opts.outDir, `${prefix}-prod.png`)
|
|
72115
|
+
}),
|
|
72116
|
+
gatherBenchSide(browser, {
|
|
72117
|
+
url: candUrl,
|
|
72118
|
+
selector: candSelector,
|
|
72119
|
+
viewport,
|
|
72120
|
+
waitMs,
|
|
72121
|
+
screenshotPath: resolve8(opts.outDir, `${prefix}-cand.png`)
|
|
72122
|
+
})
|
|
72123
|
+
]);
|
|
72124
|
+
const readErr = prodSide.error ?? candSide.error ?? (!prodSide.boxNodes.found ? `prod: ${prodSide.boxNodes.error}` : undefined) ?? (!candSide.boxNodes.found ? `cand: ${candSide.boxNodes.error}` : undefined);
|
|
72125
|
+
if (readErr || !prodSide.boxNodes.found || !candSide.boxNodes.found) {
|
|
72126
|
+
const payload = { component: opts.component, prodUrl, candUrl, error: readErr };
|
|
72127
|
+
if (opts.json)
|
|
72128
|
+
console.log(JSON.stringify(payload));
|
|
72129
|
+
else
|
|
72130
|
+
console.error(chalk27.red(` bench falhou — ${readErr}`));
|
|
72131
|
+
return 2;
|
|
72132
|
+
}
|
|
72133
|
+
const geometry = diffBoxTrees(prodSide.boxNodes.nodes, candSide.boxNodes.nodes, {
|
|
72134
|
+
truncated: prodSide.boxNodes.truncated || candSide.boxNodes.truncated
|
|
72135
|
+
});
|
|
72136
|
+
const motion = prodSide.motion.found && candSide.motion.found ? diffMotion(prodSide.motion, candSide.motion) : null;
|
|
72137
|
+
const clean = isGeometryClean(geometry) && (motion?.findings.length ?? 0) === 0;
|
|
72138
|
+
const result = {
|
|
72139
|
+
component: opts.component,
|
|
72140
|
+
viewport,
|
|
72141
|
+
prodUrl,
|
|
72142
|
+
candUrl,
|
|
72143
|
+
propsFile: opts.props ?? null,
|
|
72144
|
+
clean,
|
|
72145
|
+
geometry,
|
|
72146
|
+
motion,
|
|
72147
|
+
screenshots: { prod: prodSide.screenshotPath ?? null, cand: candSide.screenshotPath ?? null }
|
|
72148
|
+
};
|
|
72149
|
+
const resultPath = resolve8(opts.outDir, `${prefix}.json`);
|
|
72150
|
+
writeFileSync30(resultPath, `${JSON.stringify(result, null, 2)}
|
|
72151
|
+
`, "utf8");
|
|
72152
|
+
if (opts.json) {
|
|
72153
|
+
console.log(JSON.stringify(result));
|
|
72154
|
+
} else {
|
|
72155
|
+
console.log("");
|
|
72156
|
+
console.log(chalk27.bold(` ${opts.component} — isolated (${viewport})`));
|
|
72157
|
+
console.log(chalk27.dim(` prod ${prodUrl}`));
|
|
72158
|
+
console.log(chalk27.dim(` cand ${candUrl}`));
|
|
72159
|
+
console.log("");
|
|
72160
|
+
for (const line of formatBoxTreeDiff(geometry).split(`
|
|
72161
|
+
`))
|
|
72162
|
+
console.log(` ${line}`);
|
|
72163
|
+
if (motion) {
|
|
72164
|
+
console.log("");
|
|
72165
|
+
for (const line of formatMotionDiff(motion).split(`
|
|
72166
|
+
`))
|
|
72167
|
+
console.log(` ${line}`);
|
|
72168
|
+
}
|
|
72169
|
+
console.log("");
|
|
72170
|
+
console.log(chalk27.dim(` ${resultPath}`));
|
|
72171
|
+
}
|
|
72172
|
+
return clean || !opts.failOnDiff ? 0 : 1;
|
|
72173
|
+
} finally {
|
|
72174
|
+
await browser.close().catch(() => {
|
|
72175
|
+
return;
|
|
72176
|
+
});
|
|
72177
|
+
}
|
|
72178
|
+
}
|
|
72179
|
+
|
|
72180
|
+
// src/commands/states.ts
|
|
72181
|
+
import chalk28 from "chalk";
|
|
72182
|
+
var HOVERABLE = "a,button,summary,[role='button'],[role='menuitem'],label";
|
|
72183
|
+
async function readStateEffects(page, selector, base, max) {
|
|
72184
|
+
const root = page.locator(selector).first();
|
|
72185
|
+
const targets = root.locator(HOVERABLE);
|
|
72186
|
+
const total = await targets.count().catch(() => 0);
|
|
72187
|
+
const take = Math.min(total, max);
|
|
72188
|
+
const effects = [];
|
|
72189
|
+
for (let i = 0;i < take; i++) {
|
|
72190
|
+
const el = targets.nth(i);
|
|
72191
|
+
const meta = await el.evaluate((node) => {
|
|
72192
|
+
const parts = [];
|
|
72193
|
+
let cur = node;
|
|
72194
|
+
while (cur?.parentElement) {
|
|
72195
|
+
const t = cur.tagName.toLowerCase();
|
|
72196
|
+
let idx = 0;
|
|
72197
|
+
for (const sib of Array.from(cur.parentElement.children)) {
|
|
72198
|
+
if (sib === cur)
|
|
72199
|
+
break;
|
|
72200
|
+
if (sib.tagName.toLowerCase() === t)
|
|
72201
|
+
idx++;
|
|
72202
|
+
}
|
|
72203
|
+
parts.unshift(`${t}[${idx}]`);
|
|
72204
|
+
cur = cur.parentElement;
|
|
72205
|
+
}
|
|
72206
|
+
return {
|
|
72207
|
+
path: parts.join(">"),
|
|
72208
|
+
label: node.getAttribute("data-testid") ?? node.getAttribute("aria-label") ?? ((node.textContent ?? "").replace(/\s+/g, " ").trim().slice(0, 30) || null)
|
|
72209
|
+
};
|
|
72210
|
+
}).catch(() => null);
|
|
72211
|
+
if (!meta)
|
|
72212
|
+
continue;
|
|
72213
|
+
const hovered = await el.hover({ timeout: 2000 }).then(() => true).catch(() => false);
|
|
72214
|
+
if (!hovered)
|
|
72215
|
+
continue;
|
|
72216
|
+
await page.waitForTimeout(60);
|
|
72217
|
+
const after = await readBoxTree(page, selector);
|
|
72218
|
+
await page.mouse.move(0, 0).catch(() => {
|
|
72219
|
+
return;
|
|
72220
|
+
});
|
|
72221
|
+
if (!after.found)
|
|
72222
|
+
continue;
|
|
72223
|
+
const delta = diffBoxTrees(base, after.nodes, { tolerancePx: 0 });
|
|
72224
|
+
if (delta.deltas.length === 0)
|
|
72225
|
+
continue;
|
|
72226
|
+
effects.push({
|
|
72227
|
+
target: meta.path,
|
|
72228
|
+
label: meta.label,
|
|
72229
|
+
changedProps: delta.deltas.length,
|
|
72230
|
+
properties: [...new Set(delta.deltas.map((d) => d.prop))].sort()
|
|
72231
|
+
});
|
|
72232
|
+
}
|
|
72233
|
+
return { effects, truncated: total > take };
|
|
72234
|
+
}
|
|
72235
|
+
async function gatherStates(browser, opts) {
|
|
72236
|
+
const ctx = await newContext(browser, { viewport: opts.viewport });
|
|
72237
|
+
const page = await ctx.newPage();
|
|
72238
|
+
const out = { motion: { found: false, error: "not read" }, base: null, effects: [], truncated: false };
|
|
72239
|
+
try {
|
|
72240
|
+
await page.goto(opts.url, { waitUntil: "domcontentloaded", timeout: 30000 });
|
|
72241
|
+
await page.waitForLoadState("networkidle", { timeout: 8000 }).catch(() => {
|
|
72242
|
+
return;
|
|
72243
|
+
});
|
|
72244
|
+
if (opts.waitMs > 0)
|
|
72245
|
+
await page.waitForTimeout(opts.waitMs);
|
|
72246
|
+
await Promise.race([
|
|
72247
|
+
stabilizeCarousels(page).catch(() => {
|
|
72248
|
+
return;
|
|
72249
|
+
}),
|
|
72250
|
+
new Promise((r) => setTimeout(r, 3000))
|
|
72251
|
+
]);
|
|
72252
|
+
out.motion = await readMotion(page, opts.selector);
|
|
72253
|
+
const base = await readBoxTree(page, opts.selector);
|
|
72254
|
+
if (!base.found) {
|
|
72255
|
+
out.baseError = base.error;
|
|
72256
|
+
return out;
|
|
72257
|
+
}
|
|
72258
|
+
out.base = base.nodes;
|
|
72259
|
+
const { effects, truncated } = await readStateEffects(page, opts.selector, base.nodes, opts.maxStates);
|
|
72260
|
+
out.effects = effects;
|
|
72261
|
+
out.truncated = truncated || base.truncated;
|
|
72262
|
+
} finally {
|
|
72263
|
+
await page.close().catch(() => {
|
|
72264
|
+
return;
|
|
72265
|
+
});
|
|
72266
|
+
await ctx.close().catch(() => {
|
|
72267
|
+
return;
|
|
72268
|
+
});
|
|
72269
|
+
}
|
|
72270
|
+
return out;
|
|
72271
|
+
}
|
|
72272
|
+
function diffEffects(prod, cand) {
|
|
72273
|
+
const byTarget = new Map(cand.map((e) => [e.target, e]));
|
|
72274
|
+
const lost = [];
|
|
72275
|
+
const changed = [];
|
|
72276
|
+
const seen = new Set;
|
|
72277
|
+
for (const p of prod) {
|
|
72278
|
+
const c = byTarget.get(p.target);
|
|
72279
|
+
if (!c) {
|
|
72280
|
+
lost.push(p);
|
|
72281
|
+
continue;
|
|
72282
|
+
}
|
|
72283
|
+
seen.add(p.target);
|
|
72284
|
+
if (p.properties.join(",") !== c.properties.join(","))
|
|
72285
|
+
changed.push({ prod: p, cand: c });
|
|
72286
|
+
}
|
|
72287
|
+
return { lost, added: cand.filter((c) => !seen.has(c.target)), changed };
|
|
72288
|
+
}
|
|
72289
|
+
async function statesCommand(opts) {
|
|
72290
|
+
const viewport = parseViewport3(opts.viewport);
|
|
72291
|
+
if (!viewport) {
|
|
72292
|
+
console.error(chalk28.red(`--viewport inválido: ${opts.viewport}`));
|
|
72293
|
+
return 2;
|
|
72294
|
+
}
|
|
72295
|
+
const waitMs = Number.parseInt(opts.wait, 10) || 0;
|
|
72296
|
+
const maxStates = Math.max(1, Number.parseInt(opts.maxStates ?? "12", 10) || 12);
|
|
72297
|
+
const candSelector = opts.candSelector?.trim() || opts.selector;
|
|
72298
|
+
const browser = await launchBrowser({ headless: true });
|
|
72299
|
+
try {
|
|
72300
|
+
const [prodSide, candSide] = await Promise.all([
|
|
72301
|
+
gatherStates(browser, { url: opts.prod, selector: opts.selector, viewport, waitMs, maxStates }),
|
|
72302
|
+
gatherStates(browser, { url: opts.cand, selector: candSelector, viewport, waitMs, maxStates })
|
|
72303
|
+
]);
|
|
72304
|
+
if (prodSide.baseError || candSide.baseError) {
|
|
72305
|
+
const which = prodSide.baseError ? `prod: ${prodSide.baseError}` : `cand: ${candSide.baseError}`;
|
|
72306
|
+
console.error(chalk28.red(` não foi possível ler o componente — ${which}`));
|
|
72307
|
+
return 2;
|
|
72308
|
+
}
|
|
72309
|
+
const motion = prodSide.motion.found && candSide.motion.found ? diffMotion(prodSide.motion, candSide.motion, {
|
|
72310
|
+
truncated: prodSide.truncated || candSide.truncated
|
|
72311
|
+
}) : null;
|
|
72312
|
+
const effects = diffEffects(prodSide.effects, candSide.effects);
|
|
72313
|
+
if (opts.json) {
|
|
72314
|
+
console.log(JSON.stringify({
|
|
72315
|
+
prod: opts.prod,
|
|
72316
|
+
cand: opts.cand,
|
|
72317
|
+
selector: opts.selector,
|
|
72318
|
+
candSelector,
|
|
72319
|
+
viewport,
|
|
72320
|
+
motion,
|
|
72321
|
+
motionError: prodSide.motion.found ? undefined : prodSide.motion.error,
|
|
72322
|
+
effects,
|
|
72323
|
+
prodEffects: prodSide.effects,
|
|
72324
|
+
candEffects: candSide.effects,
|
|
72325
|
+
truncated: prodSide.truncated || candSide.truncated
|
|
72326
|
+
}));
|
|
72327
|
+
return effects.lost.length > 0 || (motion?.findings.length ?? 0) > 0 ? 1 : 0;
|
|
72328
|
+
}
|
|
72329
|
+
console.log("");
|
|
72330
|
+
console.log(chalk28.bold(" Declared motion"));
|
|
72331
|
+
if (!motion) {
|
|
72332
|
+
const err = prodSide.motion.found ? candSide.motion : prodSide.motion;
|
|
72333
|
+
console.log(chalk28.yellow(` não foi possível comparar — ${"error" in err ? err.error : "?"}`));
|
|
72334
|
+
} else {
|
|
72335
|
+
for (const line of formatMotionDiff(motion).split(`
|
|
72336
|
+
`))
|
|
72337
|
+
console.log(` ${line}`);
|
|
72338
|
+
}
|
|
72339
|
+
console.log("");
|
|
72340
|
+
console.log(chalk28.bold(` Hover effects (${prodSide.effects.length} prod / ${candSide.effects.length} cand)`));
|
|
72341
|
+
if (effects.lost.length === 0 && effects.changed.length === 0 && effects.added.length === 0) {
|
|
72342
|
+
console.log(" clean — every hover that changes something in prod changes the same in cand");
|
|
72343
|
+
}
|
|
72344
|
+
for (const e of effects.lost) {
|
|
72345
|
+
console.log(chalk28.red(` LOST ${e.target}${e.label ? ` (${e.label})` : ""} — prod moves [${e.properties.join(", ")}] on hover; cand moves nothing`));
|
|
72346
|
+
}
|
|
72347
|
+
for (const { prod, cand } of effects.changed) {
|
|
72348
|
+
console.log(` DIFFERS ${prod.target} — prod [${prod.properties.join(", ")}] vs cand [${cand.properties.join(", ")}]`);
|
|
72349
|
+
}
|
|
72350
|
+
for (const e of effects.added) {
|
|
72351
|
+
console.log(` ADDED ${e.target} — cand moves [${e.properties.join(", ")}]; prod does not`);
|
|
72352
|
+
}
|
|
72353
|
+
if (prodSide.truncated || candSide.truncated) {
|
|
72354
|
+
console.log(chalk28.dim(" TRUNCATED — element cap hit; absence of a finding is not proof"));
|
|
72355
|
+
}
|
|
72356
|
+
return effects.lost.length > 0 || (motion?.findings.length ?? 0) > 0 ? 1 : 0;
|
|
72357
|
+
} finally {
|
|
72358
|
+
await browser.close().catch(() => {
|
|
72359
|
+
return;
|
|
72360
|
+
});
|
|
72361
|
+
}
|
|
72362
|
+
}
|
|
72363
|
+
|
|
71527
72364
|
// src/commands/vitals.ts
|
|
71528
|
-
import { existsSync as
|
|
72365
|
+
import { existsSync as existsSync29, readFileSync as readFileSync33, writeFileSync as writeFileSync31 } from "node:fs";
|
|
71529
72366
|
import { availableParallelism } from "node:os";
|
|
71530
|
-
import { join as
|
|
71531
|
-
import
|
|
72367
|
+
import { join as join39 } from "node:path";
|
|
72368
|
+
import chalk29 from "chalk";
|
|
71532
72369
|
import ora9 from "ora";
|
|
71533
72370
|
|
|
71534
72371
|
// src/checks/agentic-nav.ts
|
|
@@ -71826,10 +72663,10 @@ async function vitalsCommand(opts) {
|
|
|
71826
72663
|
const runId = newRunId();
|
|
71827
72664
|
const paths = createRunDir(opts.output, runId);
|
|
71828
72665
|
const t0 = Date.now();
|
|
71829
|
-
console.log(
|
|
72666
|
+
console.log(chalk29.bold(`
|
|
71830
72667
|
parity vitals ${runId}`));
|
|
71831
|
-
console.log(
|
|
71832
|
-
console.log(
|
|
72668
|
+
console.log(chalk29.dim(` prod: ${opts.prod}`));
|
|
72669
|
+
console.log(chalk29.dim(` cand: ${opts.cand}`));
|
|
71833
72670
|
const discoverSpinner = ora9("Descobrindo páginas…").start();
|
|
71834
72671
|
const pagePaths = await discoverPagePaths2(opts.prod, opts);
|
|
71835
72672
|
if (pagePaths.length === 0) {
|
|
@@ -71861,12 +72698,12 @@ async function vitalsCommand(opts) {
|
|
|
71861
72698
|
completed++;
|
|
71862
72699
|
const elapsed = ((Date.now() - t0) / 1000).toFixed(0);
|
|
71863
72700
|
const etaSec = completed > 0 ? Math.round((Date.now() - t0) / completed * (total - completed) / 1000) : 0;
|
|
71864
|
-
progress.text = `${completed}/${total} · ${elapsed}s · ETA ${etaSec}s · ${task.side === "prod" ?
|
|
72701
|
+
progress.text = `${completed}/${total} · ${elapsed}s · ETA ${etaSec}s · ${task.side === "prod" ? chalk29.cyan("prod") : chalk29.magenta("cand")} ${task.path} (${task.viewport})`;
|
|
71865
72702
|
}
|
|
71866
72703
|
});
|
|
71867
72704
|
progress.succeed(`${total} capture(s) em ${((Date.now() - t0) / 1000).toFixed(1)}s`);
|
|
71868
72705
|
if (opts.lighthouse !== false) {
|
|
71869
|
-
const lhDir =
|
|
72706
|
+
const lhDir = join39(paths.runDir, "lighthouse");
|
|
71870
72707
|
const lhCap = opts.lighthouseConcurrency ?? Math.max(1, Math.min(2, Math.floor(availableParallelism() / 2)));
|
|
71871
72708
|
const done = tasks.filter((t) => !!t.capture);
|
|
71872
72709
|
const lhT0 = Date.now();
|
|
@@ -71890,7 +72727,7 @@ async function vitalsCommand(opts) {
|
|
|
71890
72727
|
}
|
|
71891
72728
|
lhCompleted++;
|
|
71892
72729
|
const elapsed = ((Date.now() - lhT0) / 1000).toFixed(0);
|
|
71893
|
-
lhProgress.text = `Lighthouse ${lhCompleted}/${done.length} · ${elapsed}s · ${task.side === "prod" ?
|
|
72730
|
+
lhProgress.text = `Lighthouse ${lhCompleted}/${done.length} · ${elapsed}s · ${task.side === "prod" ? chalk29.cyan("prod") : chalk29.magenta("cand")} ${task.path} (${task.viewport})`;
|
|
71894
72731
|
});
|
|
71895
72732
|
lhProgress.succeed(`Lighthouse ${done.length} página(s) em ${((Date.now() - lhT0) / 1000).toFixed(1)}s`);
|
|
71896
72733
|
}
|
|
@@ -71955,7 +72792,7 @@ async function vitalsCommand(opts) {
|
|
|
71955
72792
|
writeRunReportJson(paths.runDir, run);
|
|
71956
72793
|
const html = renderHtmlReport(run, paths.runDir);
|
|
71957
72794
|
writeRunReportHtml(paths.runDir, html);
|
|
71958
|
-
|
|
72795
|
+
writeFileSync31(join39(paths.runDir, "vitals.json"), `${JSON.stringify({
|
|
71959
72796
|
schemaVersion: "0.1",
|
|
71960
72797
|
prodUrl: opts.prod,
|
|
71961
72798
|
candUrl: opts.cand,
|
|
@@ -71968,8 +72805,8 @@ async function vitalsCommand(opts) {
|
|
|
71968
72805
|
`, "utf8");
|
|
71969
72806
|
printSummary8(vitalsResult, cacheResult, scoresResult, oppsResult, agenticResult);
|
|
71970
72807
|
console.log("");
|
|
71971
|
-
console.log(
|
|
71972
|
-
console.log(
|
|
72808
|
+
console.log(chalk29.dim(` → ${paths.reportHtml}`));
|
|
72809
|
+
console.log(chalk29.dim(` \uD83D\uDCA1 use 'parity serve ${runId}' pra preview iframe`));
|
|
71973
72810
|
console.log("");
|
|
71974
72811
|
if (opts.open) {
|
|
71975
72812
|
const { default: open } = await import("open");
|
|
@@ -72059,15 +72896,15 @@ async function discoverPagePaths2(prodUrl, opts) {
|
|
|
72059
72896
|
function parseUrlList(input) {
|
|
72060
72897
|
if (input.startsWith("file:") || input.endsWith(".txt") || input.endsWith(".list")) {
|
|
72061
72898
|
const path = input.replace(/^file:\/\//, "");
|
|
72062
|
-
if (
|
|
72063
|
-
return
|
|
72899
|
+
if (existsSync29(path)) {
|
|
72900
|
+
return readFileSync33(path, "utf8").split(/\r?\n/).map((s) => s.trim()).filter((s) => s && !s.startsWith("#")).map((s) => s.startsWith("/") ? s : `/${s}`);
|
|
72064
72901
|
}
|
|
72065
72902
|
}
|
|
72066
72903
|
return input.split(",").map((s) => s.trim()).filter(Boolean).map((s) => s.startsWith("/") || s.startsWith("http") ? s : `/${s}`);
|
|
72067
72904
|
}
|
|
72068
72905
|
function printSummary8(vitals, cache, scores, opportunities, agentic) {
|
|
72069
72906
|
console.log("");
|
|
72070
|
-
console.log(
|
|
72907
|
+
console.log(chalk29.bold(" Summary:"));
|
|
72071
72908
|
console.log(` ${vitals.summary}`);
|
|
72072
72909
|
console.log(` ${cache.summary}`);
|
|
72073
72910
|
if (scores.status !== "skipped")
|
|
@@ -72079,16 +72916,16 @@ function printSummary8(vitals, cache, scores, opportunities, agentic) {
|
|
|
72079
72916
|
}
|
|
72080
72917
|
|
|
72081
72918
|
// src/util/version.ts
|
|
72082
|
-
import { readFileSync as
|
|
72083
|
-
import { dirname as dirname6, resolve as
|
|
72919
|
+
import { readFileSync as readFileSync34 } from "node:fs";
|
|
72920
|
+
import { dirname as dirname6, resolve as resolve9 } from "node:path";
|
|
72084
72921
|
import { fileURLToPath } from "node:url";
|
|
72085
72922
|
function getPackageVersion() {
|
|
72086
72923
|
try {
|
|
72087
72924
|
const here = dirname6(fileURLToPath(import.meta.url));
|
|
72088
72925
|
for (const up of ["..", "../..", "../../.."]) {
|
|
72089
72926
|
try {
|
|
72090
|
-
const pkgPath =
|
|
72091
|
-
const raw =
|
|
72927
|
+
const pkgPath = resolve9(here, up, "package.json");
|
|
72928
|
+
const raw = readFileSync34(pkgPath, "utf8");
|
|
72092
72929
|
const parsed = JSON.parse(raw);
|
|
72093
72930
|
if (parsed.name === "@decocms/parity" && typeof parsed.version === "string") {
|
|
72094
72931
|
return parsed.version;
|
|
@@ -72394,6 +73231,34 @@ program.command("section").description("Focused prod×cand comparison of one sec
|
|
|
72394
73231
|
json: opts.json
|
|
72395
73232
|
}));
|
|
72396
73233
|
});
|
|
73234
|
+
program.command("bench").description("Compare ONE component in ISOLATION. Both sides mount it at a harness route (/__parity/bench?component=X&props=<base64>) with the same props, so the page stops being a confounder: no lazy-load timing, no carousel position, no cookie banner, no A/B flag. Seconds per run instead of a full-page capture, so many components can converge concurrently. Pass --prod-selector to compare against a live page instead of a second harness.").requiredOption("--component <name>", "Component name the harness route resolves").requiredOption("--cand <url>", "Candidate harness base URL (e.g. http://localhost:3000)").requiredOption("--prod <url>", "Reference: a second harness base (the source repo's dev server), or a live page when --prod-selector is given").option("--props <file>", "JSON file of props to mount with. Prefer the real values from the source CMS over invented ones — a component fed placeholder content converges on placeholder layout.").option("--selector <sel>", "Component root inside the harness", "[data-parity-bench]").option("--prod-selector <sel>", "Treat --prod as a live PAGE and find the component at this selector. Use before a source dev server exists.").option("--cand-selector <sel>", "Same, for the candidate side").option("--viewport <viewport>", "mobile | desktop | tablet", "desktop").option("--wait <ms>", "Extra ms after networkidle so hydration settles", "1000").option("--out-dir <dir>", "Where to write screenshots + the result JSON", "./parity-output/bench").option("--fail-on-diff", "Exit 1 when geometry or motion is not clean (for a convergence loop)", false).option("--json", "Emit one-line JSON instead of pretty text", false).action(async (opts) => {
|
|
73235
|
+
process.exit(await benchCommand({
|
|
73236
|
+
component: opts.component,
|
|
73237
|
+
prod: opts.prod,
|
|
73238
|
+
cand: opts.cand,
|
|
73239
|
+
props: opts.props,
|
|
73240
|
+
selector: opts.selector,
|
|
73241
|
+
prodSelector: opts.prodSelector,
|
|
73242
|
+
candSelector: opts.candSelector,
|
|
73243
|
+
viewport: opts.viewport,
|
|
73244
|
+
wait: opts.wait,
|
|
73245
|
+
outDir: opts.outDir,
|
|
73246
|
+
failOnDiff: opts.failOnDiff,
|
|
73247
|
+
json: opts.json
|
|
73248
|
+
}));
|
|
73249
|
+
});
|
|
73250
|
+
program.command("states").description("Compare a component's INTERACTIVE states, not just its resting frame. Two deterministic signals: declared motion (transitions, animations and the @keyframes bodies they point at, per interactive element) and hover effects (hover each element in turn, re-read the box tree, and report which effects prod has that cand lost). This is the instrument behind 'the hover effects are not the same' — no LLM, no screenshots to eyeball.").requiredOption("--prod <url>", "Production URL (source of truth)").requiredOption("--cand <url>", "Candidate URL (migrated)").requiredOption("--selector <sel>", "CSS selector for the component to compare").option("--cand-selector <sel>", "CSS selector on the CANDIDATE side, when the ported component no longer matches --selector. Defaults to --selector.").option("--max-states <n>", "How many interactive elements to hover per side. A mega-nav has hundreds of links sharing one hover rule; N distinct effects is the signal.", "12").option("--viewport <viewport>", "mobile | desktop | tablet", "desktop").option("--wait <ms>", "Extra ms after networkidle so hydration settles", "2000").option("--json", "Emit one-line JSON instead of pretty text", false).action(async (opts) => {
|
|
73251
|
+
process.exit(await statesCommand({
|
|
73252
|
+
prod: opts.prod,
|
|
73253
|
+
cand: opts.cand,
|
|
73254
|
+
selector: opts.selector,
|
|
73255
|
+
candSelector: opts.candSelector,
|
|
73256
|
+
maxStates: opts.maxStates,
|
|
73257
|
+
viewport: opts.viewport,
|
|
73258
|
+
wait: opts.wait,
|
|
73259
|
+
json: opts.json
|
|
73260
|
+
}));
|
|
73261
|
+
});
|
|
72397
73262
|
program.command("fix").description("[deprecated: use `parity section --all`] Pixel-perfect debug shortcut: run `parity section` with ALL signals on (HTML + screenshot + computed-styles + box-tree + heatmap + CSS source) and emit an LLM-ready Markdown bundle. When ANTHROPIC_API_KEY is set, also prints a 1-paragraph summary of what Claude understood from the signals — does NOT generate a patch (you ask for that in a follow-up turn).").requiredOption("--prod <url>", "Production URL (source of truth)").requiredOption("--cand <url>", "Candidate URL (migrated)").requiredOption("--selector <sel>", "CSS selector for the section to fix").option("--cand-selector <sel>", "CSS selector on the CANDIDATE side, when the ported component no longer matches --selector. Defaults to --selector.").option("--viewport <viewport>", "mobile | desktop | tablet", "mobile").option("--wait <ms>", "Extra ms after networkidle so hydration settles", "2000").option("--out-dir <dir>", "Where to write the bundle + screenshots", "./parity-output/sections").option("--json", "Emit one-line JSON instead of pretty text", false).option("--no-llm", "Skip the LLM call (still writes the markdown bundle). Use when offline or to avoid API costs.").option("--pt", "Tell the LLM to respond in Brazilian Portuguese. Issue #67.").action(async (opts) => {
|
|
72398
73263
|
deprecatedNotice("fix", "section --all");
|
|
72399
73264
|
if (opts.pt) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decocms/parity",
|
|
3
|
-
"version": "0.33.
|
|
3
|
+
"version": "0.33.32",
|
|
4
4
|
"description": "E2E parity validator for site migrations. Compares prod vs cand and reports UI, functional, SEO, visual, and Web Vitals deltas with an LLM-ranked HTML report.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|