@decocms/parity 0.17.8 → 0.18.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/AGENTS.md +1 -0
- package/CHANGELOG.md +21 -0
- package/README.md +4 -0
- package/dist/cli.js +2311 -322
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -7549,14 +7549,14 @@ class Tokenizer2 {
|
|
|
7549
7549
|
}
|
|
7550
7550
|
}
|
|
7551
7551
|
_emitEOFToken() {
|
|
7552
|
-
const
|
|
7553
|
-
if (
|
|
7554
|
-
|
|
7555
|
-
|
|
7556
|
-
|
|
7557
|
-
}
|
|
7558
|
-
this._emitCurrentCharacterToken(
|
|
7559
|
-
this.handler.onEof({ type: TokenType.EOF, location });
|
|
7552
|
+
const location2 = this.getCurrentLocation(0);
|
|
7553
|
+
if (location2) {
|
|
7554
|
+
location2.endLine = location2.startLine;
|
|
7555
|
+
location2.endCol = location2.startCol;
|
|
7556
|
+
location2.endOffset = location2.startOffset;
|
|
7557
|
+
}
|
|
7558
|
+
this._emitCurrentCharacterToken(location2);
|
|
7559
|
+
this.handler.onEof({ type: TokenType.EOF, location: location2 });
|
|
7560
7560
|
this.active = false;
|
|
7561
7561
|
}
|
|
7562
7562
|
_appendCharToCurrentCharacterToken(type, ch) {
|
|
@@ -10278,8 +10278,8 @@ var init_default = __esm(() => {
|
|
|
10278
10278
|
isElementNode(node2) {
|
|
10279
10279
|
return Object.prototype.hasOwnProperty.call(node2, "tagName");
|
|
10280
10280
|
},
|
|
10281
|
-
setNodeSourceCodeLocation(node2,
|
|
10282
|
-
node2.sourceCodeLocation =
|
|
10281
|
+
setNodeSourceCodeLocation(node2, location2) {
|
|
10282
|
+
node2.sourceCodeLocation = location2;
|
|
10283
10283
|
},
|
|
10284
10284
|
getNodeSourceCodeLocation(node2) {
|
|
10285
10285
|
return node2.sourceCodeLocation;
|
|
@@ -10796,11 +10796,11 @@ class Parser2 {
|
|
|
10796
10796
|
}
|
|
10797
10797
|
}
|
|
10798
10798
|
}
|
|
10799
|
-
_attachElementToTree(element,
|
|
10799
|
+
_attachElementToTree(element, location2) {
|
|
10800
10800
|
if (this.options.sourceCodeLocationInfo) {
|
|
10801
|
-
const loc =
|
|
10802
|
-
...
|
|
10803
|
-
startTag:
|
|
10801
|
+
const loc = location2 && {
|
|
10802
|
+
...location2,
|
|
10803
|
+
startTag: location2
|
|
10804
10804
|
};
|
|
10805
10805
|
this.treeAdapter.setNodeSourceCodeLocation(element, loc);
|
|
10806
10806
|
}
|
|
@@ -11084,11 +11084,11 @@ class Parser2 {
|
|
|
11084
11084
|
return { parent: this.openElements.items[0], beforeElement: null };
|
|
11085
11085
|
}
|
|
11086
11086
|
_fosterParentElement(element) {
|
|
11087
|
-
const
|
|
11088
|
-
if (
|
|
11089
|
-
this.treeAdapter.insertBefore(
|
|
11087
|
+
const location2 = this._findFosterParentingLocation();
|
|
11088
|
+
if (location2.beforeElement) {
|
|
11089
|
+
this.treeAdapter.insertBefore(location2.parent, element, location2.beforeElement);
|
|
11090
11090
|
} else {
|
|
11091
|
-
this.treeAdapter.appendChild(
|
|
11091
|
+
this.treeAdapter.appendChild(location2.parent, element);
|
|
11092
11092
|
}
|
|
11093
11093
|
}
|
|
11094
11094
|
_isSpecialElement(element, id) {
|
|
@@ -13940,12 +13940,12 @@ var init_dist2 = __esm(() => {
|
|
|
13940
13940
|
isDocumentTypeNode(node2) {
|
|
13941
13941
|
return isDirective(node2) && node2.name === "!doctype";
|
|
13942
13942
|
},
|
|
13943
|
-
setNodeSourceCodeLocation(node2,
|
|
13944
|
-
if (
|
|
13945
|
-
node2.startIndex =
|
|
13946
|
-
node2.endIndex =
|
|
13943
|
+
setNodeSourceCodeLocation(node2, location2) {
|
|
13944
|
+
if (location2) {
|
|
13945
|
+
node2.startIndex = location2.startOffset;
|
|
13946
|
+
node2.endIndex = location2.endOffset;
|
|
13947
13947
|
}
|
|
13948
|
-
node2.sourceCodeLocation =
|
|
13948
|
+
node2.sourceCodeLocation = location2;
|
|
13949
13949
|
},
|
|
13950
13950
|
getNodeSourceCodeLocation(node2) {
|
|
13951
13951
|
return node2.sourceCodeLocation;
|
|
@@ -18479,17 +18479,17 @@ var require_util2 = __commonJS((exports, module) => {
|
|
|
18479
18479
|
if (!redirectStatusSet.has(response.status)) {
|
|
18480
18480
|
return null;
|
|
18481
18481
|
}
|
|
18482
|
-
let
|
|
18483
|
-
if (
|
|
18484
|
-
if (!isValidEncodedURL(
|
|
18485
|
-
|
|
18482
|
+
let location2 = response.headersList.get("location", true);
|
|
18483
|
+
if (location2 !== null && isValidHeaderValue(location2)) {
|
|
18484
|
+
if (!isValidEncodedURL(location2)) {
|
|
18485
|
+
location2 = normalizeBinaryStringToUtf8(location2);
|
|
18486
18486
|
}
|
|
18487
|
-
|
|
18487
|
+
location2 = new URL(location2, responseURL(response));
|
|
18488
18488
|
}
|
|
18489
|
-
if (
|
|
18490
|
-
|
|
18489
|
+
if (location2 && !location2.hash) {
|
|
18490
|
+
location2.hash = requestFragment;
|
|
18491
18491
|
}
|
|
18492
|
-
return
|
|
18492
|
+
return location2;
|
|
18493
18493
|
}
|
|
18494
18494
|
function isValidEncodedURL(url) {
|
|
18495
18495
|
for (let i = 0;i < url.length; ++i) {
|
|
@@ -32547,9 +32547,9 @@ var require_fetch = __commonJS((exports, module) => {
|
|
|
32547
32547
|
headersList.append(nameStr, value.toString("latin1"), true);
|
|
32548
32548
|
}
|
|
32549
32549
|
}
|
|
32550
|
-
const
|
|
32550
|
+
const location2 = headersList.get("location", true);
|
|
32551
32551
|
this.body = new Readable({ read: resume });
|
|
32552
|
-
const willFollow =
|
|
32552
|
+
const willFollow = location2 && request.redirect === "follow" && redirectStatusSet.has(status);
|
|
32553
32553
|
const decoders = [];
|
|
32554
32554
|
if (request.method !== "HEAD" && request.method !== "CONNECT" && !nullBodyStatus.includes(status) && !willFollow) {
|
|
32555
32555
|
const contentEncoding = headersList.get("content-encoding", true);
|
|
@@ -37789,6 +37789,8 @@ function snapshotDom(html3) {
|
|
|
37789
37789
|
const looksLikeBanner = sectionName !== null || widthAttr !== null && widthAttr >= BANNER_WIDTH_THRESHOLD;
|
|
37790
37790
|
if (!looksLikeBanner)
|
|
37791
37791
|
return;
|
|
37792
|
+
if ($el.closest('[aria-hidden="true"], [data-slider-clone]').length > 0)
|
|
37793
|
+
return;
|
|
37792
37794
|
const src = $el.attr("src") ?? "";
|
|
37793
37795
|
if (!src)
|
|
37794
37796
|
return;
|
|
@@ -38720,6 +38722,13 @@ function missingBrowserError(cause) {
|
|
|
38720
38722
|
].join(`
|
|
38721
38723
|
`));
|
|
38722
38724
|
}
|
|
38725
|
+
async function disableHttpCache(page) {
|
|
38726
|
+
try {
|
|
38727
|
+
const cdp = await page.context().newCDPSession(page);
|
|
38728
|
+
await cdp.send("Network.enable");
|
|
38729
|
+
await cdp.send("Network.setCacheDisabled", { cacheDisabled: true });
|
|
38730
|
+
} catch {}
|
|
38731
|
+
}
|
|
38723
38732
|
async function newContext(browser, opts) {
|
|
38724
38733
|
const baseContext = VIEWPORT_PRESETS[opts.viewport];
|
|
38725
38734
|
const ctx = await browser.newContext({
|
|
@@ -38729,6 +38738,14 @@ async function newContext(browser, opts) {
|
|
|
38729
38738
|
ignoreHTTPSErrors: true,
|
|
38730
38739
|
extraHTTPHeaders: opts.noCache ? { "Cache-Control": "no-cache", Pragma: "no-cache" } : undefined
|
|
38731
38740
|
});
|
|
38741
|
+
if (opts.noCache) {
|
|
38742
|
+
const rawNewPage = ctx.newPage.bind(ctx);
|
|
38743
|
+
ctx.newPage = async () => {
|
|
38744
|
+
const page = await rawNewPage();
|
|
38745
|
+
await disableHttpCache(page);
|
|
38746
|
+
return page;
|
|
38747
|
+
};
|
|
38748
|
+
}
|
|
38732
38749
|
await ctx.addInitScript({
|
|
38733
38750
|
content: `
|
|
38734
38751
|
try {
|
|
@@ -38767,6 +38784,21 @@ function dlog(side, viewport, msg) {
|
|
|
38767
38784
|
process.stderr.write(`[+${elapsed}s ${viewport}/${side}] ${msg}
|
|
38768
38785
|
`);
|
|
38769
38786
|
}
|
|
38787
|
+
function clsWindowReducer(state, entry) {
|
|
38788
|
+
if (entry.hadRecentInput)
|
|
38789
|
+
return state;
|
|
38790
|
+
let { sessionValue, sessionStart, sessionLast, clsValue } = state;
|
|
38791
|
+
if (sessionValue && entry.startTime - sessionLast < 1000 && entry.startTime - sessionStart < 5000) {
|
|
38792
|
+
sessionValue += entry.value;
|
|
38793
|
+
} else {
|
|
38794
|
+
sessionValue = entry.value;
|
|
38795
|
+
sessionStart = entry.startTime;
|
|
38796
|
+
}
|
|
38797
|
+
sessionLast = entry.startTime;
|
|
38798
|
+
if (sessionValue > clsValue)
|
|
38799
|
+
clsValue = sessionValue;
|
|
38800
|
+
return { sessionValue, sessionStart, sessionLast, clsValue };
|
|
38801
|
+
}
|
|
38770
38802
|
var VITALS_INIT_SCRIPT = `
|
|
38771
38803
|
(function() {
|
|
38772
38804
|
if (window.__parity_vitals_installed) return;
|
|
@@ -38799,15 +38831,14 @@ var VITALS_INIT_SCRIPT = `
|
|
|
38799
38831
|
}).observe({ type: 'paint', buffered: true });
|
|
38800
38832
|
} catch (e) {}
|
|
38801
38833
|
|
|
38802
|
-
// CLS
|
|
38834
|
+
// CLS
|
|
38803
38835
|
try {
|
|
38804
|
-
|
|
38836
|
+
const clsWindowReducer = ${clsWindowReducer.toString()};
|
|
38837
|
+
let clsState = { sessionValue: 0, sessionStart: 0, sessionLast: 0, clsValue: 0 };
|
|
38805
38838
|
new PerformanceObserver(function(list) {
|
|
38806
38839
|
for (const entry of list.getEntries()) {
|
|
38807
|
-
|
|
38808
|
-
|
|
38809
|
-
window.__parity_vitals.cls = cls;
|
|
38810
|
-
}
|
|
38840
|
+
clsState = clsWindowReducer(clsState, entry);
|
|
38841
|
+
window.__parity_vitals.cls = clsState.clsValue;
|
|
38811
38842
|
}
|
|
38812
38843
|
}).observe({ type: 'layout-shift', buffered: true });
|
|
38813
38844
|
} catch (e) {}
|
|
@@ -38830,6 +38861,68 @@ var VITALS_INIT_SCRIPT = `
|
|
|
38830
38861
|
async function installVitalsCollector(ctx) {
|
|
38831
38862
|
await ctx.addInitScript({ content: VITALS_INIT_SCRIPT });
|
|
38832
38863
|
}
|
|
38864
|
+
async function captureVitalsSample(context, url, timeoutMs) {
|
|
38865
|
+
const page = await context.newPage();
|
|
38866
|
+
try {
|
|
38867
|
+
await page.goto(url, { waitUntil: "domcontentloaded", timeout: timeoutMs }).catch(() => {
|
|
38868
|
+
return;
|
|
38869
|
+
});
|
|
38870
|
+
await page.waitForLoadState("networkidle", { timeout: Math.min(4000, timeoutMs) }).catch(() => {
|
|
38871
|
+
return;
|
|
38872
|
+
});
|
|
38873
|
+
await page.waitForTimeout(300).catch(() => {
|
|
38874
|
+
return;
|
|
38875
|
+
});
|
|
38876
|
+
return await Promise.race([
|
|
38877
|
+
page.evaluate(() => window.__parity_vitals).catch(() => null),
|
|
38878
|
+
new Promise((resolve) => setTimeout(() => resolve(null), 3000))
|
|
38879
|
+
]) ?? null;
|
|
38880
|
+
} finally {
|
|
38881
|
+
await page.close().catch(() => {
|
|
38882
|
+
return;
|
|
38883
|
+
});
|
|
38884
|
+
}
|
|
38885
|
+
}
|
|
38886
|
+
var VITALS_METRICS = ["lcp", "cls", "fcp", "ttfb", "inp"];
|
|
38887
|
+
function aggregateVitalsSamples(samples) {
|
|
38888
|
+
const out = {};
|
|
38889
|
+
for (const metric of VITALS_METRICS) {
|
|
38890
|
+
const values = samples.map((s) => s[metric]).filter((v) => v != null);
|
|
38891
|
+
out[metric] = values.length > 0 ? statFor(values) : null;
|
|
38892
|
+
}
|
|
38893
|
+
return out;
|
|
38894
|
+
}
|
|
38895
|
+
function statFor(raw) {
|
|
38896
|
+
const sorted = [...raw].sort((a, b) => a - b);
|
|
38897
|
+
return {
|
|
38898
|
+
median: percentile(sorted, 50),
|
|
38899
|
+
p75: percentile(sorted, 75),
|
|
38900
|
+
min: sorted[0],
|
|
38901
|
+
max: sorted[sorted.length - 1],
|
|
38902
|
+
samples: raw
|
|
38903
|
+
};
|
|
38904
|
+
}
|
|
38905
|
+
function percentile(sorted, p) {
|
|
38906
|
+
if (sorted.length === 1)
|
|
38907
|
+
return sorted[0];
|
|
38908
|
+
const idx = p / 100 * (sorted.length - 1);
|
|
38909
|
+
const lo = Math.floor(idx);
|
|
38910
|
+
const hi = Math.ceil(idx);
|
|
38911
|
+
if (lo === hi)
|
|
38912
|
+
return sorted[lo];
|
|
38913
|
+
const frac = idx - lo;
|
|
38914
|
+
return sorted[lo] + (sorted[hi] - sorted[lo]) * frac;
|
|
38915
|
+
}
|
|
38916
|
+
async function readVitalsSnapshot(page) {
|
|
38917
|
+
return await page.evaluate(() => window.__parity_vitals).catch(() => null) ?? null;
|
|
38918
|
+
}
|
|
38919
|
+
function mergeInpSnapshot(vitals, snapshot) {
|
|
38920
|
+
if (snapshot?.inp == null)
|
|
38921
|
+
return vitals;
|
|
38922
|
+
if (vitals.inp != null && vitals.inp >= snapshot.inp)
|
|
38923
|
+
return vitals;
|
|
38924
|
+
return { ...vitals, inp: snapshot.inp };
|
|
38925
|
+
}
|
|
38833
38926
|
var CANCELLATION_ERROR_CODES = [
|
|
38834
38927
|
"net::ERR_ABORTED",
|
|
38835
38928
|
"net::ERR_NETWORK_CHANGED"
|
|
@@ -38907,7 +39000,8 @@ async function responseToEntry(resp) {
|
|
|
38907
39000
|
const req = resp.request();
|
|
38908
39001
|
const headers = resp.headers();
|
|
38909
39002
|
const timing = req.timing();
|
|
38910
|
-
const
|
|
39003
|
+
const contentLength = parseIntOrNull(headers["content-length"]);
|
|
39004
|
+
const bytes = contentLength ?? (isSmallTextResource(req.resourceType()) ? await safeBodySize(resp) : null);
|
|
38911
39005
|
return {
|
|
38912
39006
|
url: resp.url(),
|
|
38913
39007
|
method: req.method(),
|
|
@@ -38923,6 +39017,9 @@ async function responseToEntry(resp) {
|
|
|
38923
39017
|
decoSection: headers["x-deco-section"] ?? null
|
|
38924
39018
|
};
|
|
38925
39019
|
}
|
|
39020
|
+
function isSmallTextResource(resourceType) {
|
|
39021
|
+
return resourceType === "document" || resourceType === "script" || resourceType === "xhr" || resourceType === "fetch";
|
|
39022
|
+
}
|
|
38926
39023
|
async function safeBodySize(resp) {
|
|
38927
39024
|
try {
|
|
38928
39025
|
const buf = await Promise.race([
|
|
@@ -39015,7 +39112,8 @@ function isFromHttpCache(resp) {
|
|
|
39015
39112
|
async function capturePage(page, opts) {
|
|
39016
39113
|
const start = Date.now();
|
|
39017
39114
|
const state = attachCollectors(page);
|
|
39018
|
-
const
|
|
39115
|
+
const extraRunsBudgetMs = Math.max(0, (opts.runs ?? 1) - 1) * 8000;
|
|
39116
|
+
const overallBudgetMs = (opts.fast ? 25000 : 60000) + extraRunsBudgetMs;
|
|
39019
39117
|
const deadline = start + overallBudgetMs;
|
|
39020
39118
|
const remaining = () => Math.max(500, deadline - Date.now());
|
|
39021
39119
|
const buildPartial = () => ({
|
|
@@ -39027,6 +39125,8 @@ async function capturePage(page, opts) {
|
|
|
39027
39125
|
durationMs: Date.now() - start,
|
|
39028
39126
|
html: html3,
|
|
39029
39127
|
vitals: vitals ?? { lcp: null, cls: null, fcp: null, ttfb: null, inp: null },
|
|
39128
|
+
vitalsStats,
|
|
39129
|
+
vitalsFullPage: vitalsFullPage ?? undefined,
|
|
39030
39130
|
console: state.console,
|
|
39031
39131
|
network: state.network,
|
|
39032
39132
|
screenshotPath: opts.screenshotPath,
|
|
@@ -39038,7 +39138,16 @@ async function capturePage(page, opts) {
|
|
|
39038
39138
|
let finalUrl = opts.url;
|
|
39039
39139
|
let xRobotsTag = null;
|
|
39040
39140
|
let vitals = null;
|
|
39141
|
+
let vitalsStats;
|
|
39142
|
+
let vitalsFullPage = null;
|
|
39041
39143
|
let html3 = "";
|
|
39144
|
+
const readVitals = async () => {
|
|
39145
|
+
dlog(opts.side, opts.viewport, ` capturePage: vitals evaluate (cap=${Math.min(5000, remaining())}ms)`);
|
|
39146
|
+
return await Promise.race([
|
|
39147
|
+
page.evaluate(() => window.__parity_vitals).catch(() => null),
|
|
39148
|
+
new Promise((resolve) => setTimeout(() => resolve(null), Math.min(5000, remaining())))
|
|
39149
|
+
]) ?? null;
|
|
39150
|
+
};
|
|
39042
39151
|
let _resolveDisconnect;
|
|
39043
39152
|
const disconnectPromise = new Promise((r) => {
|
|
39044
39153
|
_resolveDisconnect = r;
|
|
@@ -39074,6 +39183,7 @@ async function capturePage(page, opts) {
|
|
|
39074
39183
|
});
|
|
39075
39184
|
}
|
|
39076
39185
|
await page.waitForTimeout(Math.min(opts.settleMs ?? 1200, remaining()));
|
|
39186
|
+
vitals = await readVitals();
|
|
39077
39187
|
} else {
|
|
39078
39188
|
dlog(opts.side, opts.viewport, ` capturePage: waitForLoadState('load') (cap=${Math.min(12000, remaining())}ms)`);
|
|
39079
39189
|
await page.waitForLoadState("load", { timeout: Math.min(12000, remaining()) }).catch(() => {
|
|
@@ -39087,6 +39197,7 @@ async function capturePage(page, opts) {
|
|
|
39087
39197
|
}
|
|
39088
39198
|
dlog(opts.side, opts.viewport, ` capturePage: settle (cap=${Math.min(opts.settleMs ?? 2000, remaining())}ms)`);
|
|
39089
39199
|
await page.waitForTimeout(Math.min(opts.settleMs ?? 2000, remaining()));
|
|
39200
|
+
vitals = await readVitals();
|
|
39090
39201
|
if (opts.scrollToLoad !== false && remaining() > 3000) {
|
|
39091
39202
|
const scrollBudget = Math.min(45000, remaining());
|
|
39092
39203
|
dlog(opts.side, opts.viewport, ` capturePage: scrollFullPage start (budget=${scrollBudget}ms, remaining=${remaining()}ms)`);
|
|
@@ -39109,6 +39220,7 @@ async function capturePage(page, opts) {
|
|
|
39109
39220
|
});
|
|
39110
39221
|
}
|
|
39111
39222
|
await page.waitForTimeout(Math.min(800, remaining()));
|
|
39223
|
+
vitalsFullPage = await readVitals();
|
|
39112
39224
|
}
|
|
39113
39225
|
}
|
|
39114
39226
|
} catch (err) {
|
|
@@ -39117,11 +39229,9 @@ async function capturePage(page, opts) {
|
|
|
39117
39229
|
text: `[navigation-error] ${err.message}`
|
|
39118
39230
|
});
|
|
39119
39231
|
}
|
|
39120
|
-
|
|
39121
|
-
|
|
39122
|
-
|
|
39123
|
-
new Promise((resolve) => setTimeout(() => resolve(null), Math.min(5000, remaining())))
|
|
39124
|
-
]) ?? null;
|
|
39232
|
+
if (vitals === null) {
|
|
39233
|
+
vitals = await readVitals();
|
|
39234
|
+
}
|
|
39125
39235
|
if (!opts.skipScreenshot) {
|
|
39126
39236
|
await Promise.race([
|
|
39127
39237
|
stabilizeCarousels(page).catch(() => {
|
|
@@ -39159,6 +39269,26 @@ async function capturePage(page, opts) {
|
|
|
39159
39269
|
]);
|
|
39160
39270
|
dlog(opts.side, opts.viewport, ` capturePage: flushCollectors (cap=${Math.min(3000, remaining())}ms)`);
|
|
39161
39271
|
await flushCollectors(state, Math.min(3000, remaining()));
|
|
39272
|
+
const extraRuns = Math.max(0, (opts.runs ?? 1) - 1);
|
|
39273
|
+
if (extraRuns > 0 && vitals) {
|
|
39274
|
+
dlog(opts.side, opts.viewport, ` capturePage: vitals repeat x${extraRuns} start`);
|
|
39275
|
+
const samples = [vitals];
|
|
39276
|
+
const ctx = page.context();
|
|
39277
|
+
for (let i = 0;i < extraRuns && remaining() > 4000; i++) {
|
|
39278
|
+
const sample = await captureVitalsSample(ctx, opts.url, Math.min(1e4, remaining()));
|
|
39279
|
+
if (sample)
|
|
39280
|
+
samples.push(sample);
|
|
39281
|
+
}
|
|
39282
|
+
vitalsStats = aggregateVitalsSamples(samples);
|
|
39283
|
+
vitals = {
|
|
39284
|
+
lcp: vitalsStats.lcp?.median ?? vitals.lcp,
|
|
39285
|
+
cls: vitalsStats.cls?.median ?? vitals.cls,
|
|
39286
|
+
fcp: vitalsStats.fcp?.median ?? vitals.fcp,
|
|
39287
|
+
ttfb: vitalsStats.ttfb?.median ?? vitals.ttfb,
|
|
39288
|
+
inp: vitalsStats.inp?.median ?? vitals.inp
|
|
39289
|
+
};
|
|
39290
|
+
dlog(opts.side, opts.viewport, ` capturePage: vitals repeat done samples=${samples.length}/${opts.runs}`);
|
|
39291
|
+
}
|
|
39162
39292
|
dlog(opts.side, opts.viewport, ` capturePage: inner done total=${Date.now() - start}ms`);
|
|
39163
39293
|
return buildPartial();
|
|
39164
39294
|
};
|
|
@@ -41102,6 +41232,20 @@ var WebVitals = z.object({
|
|
|
41102
41232
|
ttfb: z.number().nullable(),
|
|
41103
41233
|
inp: z.number().nullable()
|
|
41104
41234
|
});
|
|
41235
|
+
var WebVitalStat = z.object({
|
|
41236
|
+
median: z.number(),
|
|
41237
|
+
p75: z.number(),
|
|
41238
|
+
min: z.number(),
|
|
41239
|
+
max: z.number(),
|
|
41240
|
+
samples: z.array(z.number())
|
|
41241
|
+
});
|
|
41242
|
+
var WebVitalsStats = z.object({
|
|
41243
|
+
lcp: WebVitalStat.nullable(),
|
|
41244
|
+
cls: WebVitalStat.nullable(),
|
|
41245
|
+
fcp: WebVitalStat.nullable(),
|
|
41246
|
+
ttfb: WebVitalStat.nullable(),
|
|
41247
|
+
inp: WebVitalStat.nullable()
|
|
41248
|
+
});
|
|
41105
41249
|
var ConsoleEntry = z.object({
|
|
41106
41250
|
type: z.enum(["error", "warning", "log", "info", "debug"]),
|
|
41107
41251
|
text: z.string(),
|
|
@@ -41130,6 +41274,8 @@ var PageCapture = z.object({
|
|
|
41130
41274
|
durationMs: z.number(),
|
|
41131
41275
|
html: z.string(),
|
|
41132
41276
|
vitals: WebVitals,
|
|
41277
|
+
vitalsStats: WebVitalsStats.optional(),
|
|
41278
|
+
vitalsFullPage: WebVitals.optional(),
|
|
41133
41279
|
console: z.array(ConsoleEntry),
|
|
41134
41280
|
network: z.array(NetworkEntry),
|
|
41135
41281
|
screenshotPath: z.string(),
|
|
@@ -41691,7 +41837,8 @@ async function auditCommand(opts) {
|
|
|
41691
41837
|
settleMs: 1500,
|
|
41692
41838
|
timeoutMs: 30000,
|
|
41693
41839
|
fast: false,
|
|
41694
|
-
scrollToLoad: true
|
|
41840
|
+
scrollToLoad: true,
|
|
41841
|
+
runs: opts.runs
|
|
41695
41842
|
});
|
|
41696
41843
|
captures.push(cap);
|
|
41697
41844
|
} catch (err) {
|
|
@@ -43221,6 +43368,7 @@ function countFailedImageRequests(entries) {
|
|
|
43221
43368
|
|
|
43222
43369
|
// src/checks/lazy-sections.ts
|
|
43223
43370
|
var LAZY_URL_PATTERN = /\/(deco\/render|_loader)\b/;
|
|
43371
|
+
var RESERVED_FALLBACK_SEGMENTS = new Set(["render", "meta", "invoke"]);
|
|
43224
43372
|
var EAGER_RENDERING_MARKER = /data-deco-async-rendering=["']eager["']|<meta\s+name=["']parity:async-rendering["']\s+content=["']eager["']/i;
|
|
43225
43373
|
function lazySectionPresence(ctx) {
|
|
43226
43374
|
const start = Date.now();
|
|
@@ -43333,8 +43481,11 @@ function extractSectionIds(entries) {
|
|
|
43333
43481
|
try {
|
|
43334
43482
|
const u = new URL(e.url);
|
|
43335
43483
|
const seg = u.pathname.split("/").filter(Boolean).pop();
|
|
43336
|
-
if (seg)
|
|
43337
|
-
|
|
43484
|
+
if (seg) {
|
|
43485
|
+
const normalized = normalizeSectionId(seg);
|
|
43486
|
+
if (!RESERVED_FALLBACK_SEGMENTS.has(normalized))
|
|
43487
|
+
out.add(normalized);
|
|
43488
|
+
}
|
|
43338
43489
|
} catch {}
|
|
43339
43490
|
}
|
|
43340
43491
|
}
|
|
@@ -44276,6 +44427,34 @@ function withPage(url, n) {
|
|
|
44276
44427
|
return `${url}${sep}page=${n}`;
|
|
44277
44428
|
}
|
|
44278
44429
|
}
|
|
44430
|
+
function pickPlpFromHomeHtml(html3, homeUrl) {
|
|
44431
|
+
const candidates = new Set;
|
|
44432
|
+
const re = /href="([^"]+)"/gi;
|
|
44433
|
+
for (;; ) {
|
|
44434
|
+
const m = re.exec(html3);
|
|
44435
|
+
if (!m)
|
|
44436
|
+
break;
|
|
44437
|
+
const href = m[1];
|
|
44438
|
+
if (!href)
|
|
44439
|
+
continue;
|
|
44440
|
+
if (/^https?:\/\//.test(href) || href.startsWith("#") || href === "/" || /\/(p|cart|carrinho|checkout|account|conta|login|wishlist|favoritos)(\/|$|\?)/i.test(href) || /\.(jpg|png|webp|css|js|svg|ico|woff)/i.test(href)) {
|
|
44441
|
+
continue;
|
|
44442
|
+
}
|
|
44443
|
+
const segments = href.split("?")[0].split("/").filter(Boolean);
|
|
44444
|
+
if (segments.length === 0 || segments.length > 3)
|
|
44445
|
+
continue;
|
|
44446
|
+
candidates.add(href.split("?")[0]);
|
|
44447
|
+
}
|
|
44448
|
+
const sorted = Array.from(candidates).sort((a, b) => a.length - b.length);
|
|
44449
|
+
const pick = sorted[0];
|
|
44450
|
+
if (!pick)
|
|
44451
|
+
return null;
|
|
44452
|
+
try {
|
|
44453
|
+
return new URL(pick, new URL(homeUrl)).toString();
|
|
44454
|
+
} catch {
|
|
44455
|
+
return null;
|
|
44456
|
+
}
|
|
44457
|
+
}
|
|
44279
44458
|
async function discoverPlpFromHome(homeUrl) {
|
|
44280
44459
|
try {
|
|
44281
44460
|
const res = await fetch(homeUrl, {
|
|
@@ -44286,30 +44465,7 @@ async function discoverPlpFromHome(homeUrl) {
|
|
|
44286
44465
|
});
|
|
44287
44466
|
if (!res.ok)
|
|
44288
44467
|
return null;
|
|
44289
|
-
|
|
44290
|
-
const candidates = new Set;
|
|
44291
|
-
const re = /href="([^"]+)"/gi;
|
|
44292
|
-
for (;; ) {
|
|
44293
|
-
const m = re.exec(html3);
|
|
44294
|
-
if (!m)
|
|
44295
|
-
break;
|
|
44296
|
-
const href = m[1];
|
|
44297
|
-
if (!href)
|
|
44298
|
-
continue;
|
|
44299
|
-
if (/^https?:\/\//.test(href) || href.startsWith("#") || href === "/" || /\/(p|cart|carrinho|checkout|account|conta|login|wishlist|favoritos)(\/|$|\?)/i.test(href) || /\.(jpg|png|webp|css|js|svg|ico|woff)/i.test(href)) {
|
|
44300
|
-
continue;
|
|
44301
|
-
}
|
|
44302
|
-
const segments = href.split("?")[0].split("/").filter(Boolean);
|
|
44303
|
-
if (segments.length === 0 || segments.length > 3)
|
|
44304
|
-
continue;
|
|
44305
|
-
candidates.add(href.split("?")[0]);
|
|
44306
|
-
}
|
|
44307
|
-
const sorted = Array.from(candidates).sort((a, b) => a.length - b.length);
|
|
44308
|
-
const home = new URL(homeUrl);
|
|
44309
|
-
const pick = sorted[0];
|
|
44310
|
-
if (!pick)
|
|
44311
|
-
return null;
|
|
44312
|
-
return new URL(pick, home).toString();
|
|
44468
|
+
return pickPlpFromHomeHtml(await res.text(), homeUrl);
|
|
44313
44469
|
} catch {
|
|
44314
44470
|
return null;
|
|
44315
44471
|
}
|
|
@@ -45783,7 +45939,7 @@ init_client();
|
|
|
45783
45939
|
import { readFileSync as readFileSync4 } from "node:fs";
|
|
45784
45940
|
import { PNG as PNG2 } from "pngjs";
|
|
45785
45941
|
var MAX_HEIGHT = 8000;
|
|
45786
|
-
var LLM_PROMPT_VERSION = "
|
|
45942
|
+
var LLM_PROMPT_VERSION = "v4-text-caution";
|
|
45787
45943
|
var REPORT_VISUAL_DIFFS_TOOL = {
|
|
45788
45944
|
name: "report_visual_differences",
|
|
45789
45945
|
description: "Report semantic visual differences between prod and cand screenshots.",
|
|
@@ -45894,6 +46050,27 @@ REGRA DE MODAL/POPUP (importante — não confundir com rota-errada):
|
|
|
45894
46050
|
diferente (ex: prod tem modal de login sobre fundo de login, cand mostra a
|
|
45895
46051
|
home), reporte como \`missing-component\` \`critical\` — é o caso rota-errada.
|
|
45896
46052
|
|
|
46053
|
+
REGRA DE LEITURA DE TEXTO/NÚMEROS PEQUENOS (importante — evitar alucinação):
|
|
46054
|
+
- As screenshots enviadas a você podem ser reduzidas de tamanho pelo pipeline de
|
|
46055
|
+
ingestão de imagem antes de chegar até você. Texto pequeno — contagens de
|
|
46056
|
+
produtos ("42 produtos"), preços, números em badges — fica facilmente
|
|
46057
|
+
ilegível ou distorcido nesse processo, e um dígito lido errado (ex: "42"
|
|
46058
|
+
virar "142") pode parecer uma leitura confiante mesmo estando errado.
|
|
46059
|
+
- NÃO reporte uma diferença do tipo \`text-changed\` (ou qualquer diferença de
|
|
46060
|
+
contagem/número) baseada SÓ na sua leitura de um número ou texto pequeno na
|
|
46061
|
+
imagem. Antes de reportar, pergunte-se: "eu teria certeza desse dígito numa
|
|
46062
|
+
imagem menor?" Se não, não é uma diferença confiável pra reportar.
|
|
46063
|
+
- Se ainda assim decidir reportar uma diferença desse tipo (contagem, preço,
|
|
46064
|
+
texto pequeno em geral), o \`severity\` deve ser \`low\` no máximo — NUNCA
|
|
46065
|
+
\`critical\`, \`high\` ou \`medium\` — e o \`description\` DEVE deixar explícito
|
|
46066
|
+
que é uma leitura incerta, por exemplo: "contagem lida da imagem, pode ser
|
|
46067
|
+
leitura incorreta de texto pequeno — confirmar via DOM antes de tratar como
|
|
46068
|
+
regressão".
|
|
46069
|
+
- Essa regra NÃO se aplica a diferenças estruturais óbvias (section inteira
|
|
46070
|
+
faltando, componente com layout diferente, cor/imagem claramente trocada) —
|
|
46071
|
+
só se aplica quando o julgamento depende de ler corretamente dígitos ou
|
|
46072
|
+
texto pequeno.
|
|
46073
|
+
|
|
45897
46074
|
SEVERIDADE:
|
|
45898
46075
|
- critical: feature inteira faltando (header sumiu, carrinho não existe, busca quebrada visualmente), página renderizando rota errada
|
|
45899
46076
|
- high: section importante diferente ou faltando (hero errado, shelf principal vazio, footer cortado)
|
|
@@ -46225,6 +46402,28 @@ async function visualRegressionKeyframes(ctx) {
|
|
|
46225
46402
|
return b.pctDiff - a.pctDiff;
|
|
46226
46403
|
});
|
|
46227
46404
|
const llmTargets = new Set(useLlm ? llmCandidates.slice(0, maxLlmCalls) : []);
|
|
46405
|
+
const llmOutcomes = new Map;
|
|
46406
|
+
await Promise.all(prepared.filter((p) => !p.cacheHit && llmTargets.has(p)).map(async (p) => {
|
|
46407
|
+
try {
|
|
46408
|
+
const diffs = await visualSemanticDiff({
|
|
46409
|
+
prodPath: p.pair.prod.screenshotPath,
|
|
46410
|
+
candPath: p.pair.cand.screenshotPath,
|
|
46411
|
+
heatmapPath: p.heatmapWritten ? p.heatmapPath : undefined,
|
|
46412
|
+
pctDiff: p.pctDiff,
|
|
46413
|
+
pageContext: p.pair.key,
|
|
46414
|
+
viewport: p.pair.viewport,
|
|
46415
|
+
prodSections: p.prodSections,
|
|
46416
|
+
candSections: p.candSections,
|
|
46417
|
+
sectionsOnlyInProd: p.sectionsOnlyInProd,
|
|
46418
|
+
bothHaveCarousel: p.bothHaveCarousel,
|
|
46419
|
+
prodSkeletonCount: p.prodSkeletonCount,
|
|
46420
|
+
candSkeletonCount: p.candSkeletonCount
|
|
46421
|
+
});
|
|
46422
|
+
llmOutcomes.set(p, { differences: diffs ?? [] });
|
|
46423
|
+
} catch (err) {
|
|
46424
|
+
llmOutcomes.set(p, { error: err.message });
|
|
46425
|
+
}
|
|
46426
|
+
}));
|
|
46228
46427
|
const results = [];
|
|
46229
46428
|
let pagesFromCache = 0;
|
|
46230
46429
|
for (const p of prepared) {
|
|
@@ -46240,24 +46439,11 @@ async function visualRegressionKeyframes(ctx) {
|
|
|
46240
46439
|
} else if (llmTargets.has(p)) {
|
|
46241
46440
|
llmCallsUsed++;
|
|
46242
46441
|
llmCalled = true;
|
|
46243
|
-
|
|
46244
|
-
|
|
46245
|
-
|
|
46246
|
-
|
|
46247
|
-
|
|
46248
|
-
pctDiff: p.pctDiff,
|
|
46249
|
-
pageContext: p.pair.key,
|
|
46250
|
-
viewport: p.pair.viewport,
|
|
46251
|
-
prodSections: p.prodSections,
|
|
46252
|
-
candSections: p.candSections,
|
|
46253
|
-
sectionsOnlyInProd: p.sectionsOnlyInProd,
|
|
46254
|
-
bothHaveCarousel: p.bothHaveCarousel,
|
|
46255
|
-
prodSkeletonCount: p.prodSkeletonCount,
|
|
46256
|
-
candSkeletonCount: p.candSkeletonCount
|
|
46257
|
-
});
|
|
46258
|
-
differences = diffs ?? [];
|
|
46259
|
-
} catch (err) {
|
|
46260
|
-
llmError = err.message;
|
|
46442
|
+
const outcome = llmOutcomes.get(p);
|
|
46443
|
+
if (outcome?.error !== undefined) {
|
|
46444
|
+
llmError = outcome.error;
|
|
46445
|
+
} else {
|
|
46446
|
+
differences = outcome?.differences ?? [];
|
|
46261
46447
|
}
|
|
46262
46448
|
}
|
|
46263
46449
|
if (differences.length > 0) {
|
|
@@ -50231,6 +50417,9 @@ function isResolutionContext(v) {
|
|
|
50231
50417
|
}
|
|
50232
50418
|
|
|
50233
50419
|
// src/engine/flows/shared.ts
|
|
50420
|
+
async function captureInpSnapshot(page, cap) {
|
|
50421
|
+
cap.vitals = mergeInpSnapshot(cap.vitals, await readVitalsSnapshot(page));
|
|
50422
|
+
}
|
|
50234
50423
|
async function screenshotStable(page, opts) {
|
|
50235
50424
|
await Promise.race([
|
|
50236
50425
|
stabilizeCarousels(page).catch(() => {
|
|
@@ -52172,6 +52361,7 @@ async function flowPurchaseJourney(ctx) {
|
|
|
52172
52361
|
recoveredByLlm: miniRecovered || undefined
|
|
52173
52362
|
});
|
|
52174
52363
|
reportEnd(7, "open-minicart", step7Status, Date.now() - t7, step7QuirkNote ?? step7RevealFailureNote);
|
|
52364
|
+
await captureInpSnapshot(page, pdpCap);
|
|
52175
52365
|
if (isProdCartEmptyQuirk) {
|
|
52176
52366
|
const quirkNote = "cart-empty-prod-quirk: skipped (depende do cart que prod não persistiu)";
|
|
52177
52367
|
reportStart(8, "shipping-calc-cart");
|
|
@@ -52906,6 +53096,7 @@ async function flowCartInteractions(ctx) {
|
|
|
52906
53096
|
reportEnd(4, "read-baseline", "ok", Date.now() - t4);
|
|
52907
53097
|
reportStart(5, "verify-cart-persistence");
|
|
52908
53098
|
const t4b = Date.now();
|
|
53099
|
+
await captureInpSnapshot(page, pages[pages.length - 1]);
|
|
52909
53100
|
await page.reload({ waitUntil: "load" }).catch(() => {
|
|
52910
53101
|
return;
|
|
52911
53102
|
});
|
|
@@ -53321,6 +53512,7 @@ async function flowCartInteractions(ctx) {
|
|
|
53321
53512
|
});
|
|
53322
53513
|
await screenshotStable(page, { path: screenshotPath(ctx, "cart-9-empty") });
|
|
53323
53514
|
reportEnd(13, "verify-empty-state", emptyStatus, Date.now() - t9);
|
|
53515
|
+
await captureInpSnapshot(page, pages[pages.length - 1]);
|
|
53324
53516
|
} finally {
|
|
53325
53517
|
await page.close().catch(() => {
|
|
53326
53518
|
return;
|
|
@@ -53485,6 +53677,7 @@ async function flowLogin(ctx) {
|
|
|
53485
53677
|
});
|
|
53486
53678
|
await screenshotStable(page, { path: screenshotPath(ctx, "login-3-invalid") });
|
|
53487
53679
|
reportEnd(3, "submit-invalid", errorShown ? "ok" : "failed", Date.now() - t3);
|
|
53680
|
+
await captureInpSnapshot(page, homeCap);
|
|
53488
53681
|
reportStart(4, "submit-valid");
|
|
53489
53682
|
const t4 = Date.now();
|
|
53490
53683
|
const emailHit2 = await firstVisibleLocator(page, selFor(ctx, "loginEmailInput"));
|
|
@@ -54606,6 +54799,7 @@ async function flowSpaNavigation(ctx) {
|
|
|
54606
54799
|
const urlChanged = afterUrl !== beforeUrl;
|
|
54607
54800
|
const markerSurvived = await withCap(page.evaluate(() => window.__parity_nav_marker !== undefined).catch(() => false), 1500, false);
|
|
54608
54801
|
const navType = classifyNavigationType({ urlChanged, markerSurvived });
|
|
54802
|
+
await captureInpSnapshot(page, cap1);
|
|
54609
54803
|
const hydrationEntries = consoleDuringNav.filter((e) => e.type === "error" && classify(e) === "hydration");
|
|
54610
54804
|
const navScreenshot = screenshotPath(ctx, "spa-nav-after-click");
|
|
54611
54805
|
await screenshotStable(page, { path: navScreenshot });
|
|
@@ -55082,6 +55276,9 @@ function detectFromHeaders(headers) {
|
|
|
55082
55276
|
}
|
|
55083
55277
|
function detectFromHtml(html3) {
|
|
55084
55278
|
try {
|
|
55279
|
+
if (html3.includes("demandware.static") || html3.includes("/on/demandware.store/")) {
|
|
55280
|
+
return "salesforce-commerce";
|
|
55281
|
+
}
|
|
55085
55282
|
const $2 = load(html3);
|
|
55086
55283
|
const fsClasses = $2('[class*="fs-"], [data-fs-]').length;
|
|
55087
55284
|
if (fsClasses > 5)
|
|
@@ -55106,6 +55303,8 @@ function detectFromHtml(html3) {
|
|
|
55106
55303
|
return "vtex";
|
|
55107
55304
|
if (generator.includes("shopify"))
|
|
55108
55305
|
return "shopify";
|
|
55306
|
+
if (generator.includes("demandware") || generator.includes("salesforce"))
|
|
55307
|
+
return "salesforce-commerce";
|
|
55109
55308
|
if (generator.includes("deco"))
|
|
55110
55309
|
return "deco";
|
|
55111
55310
|
} catch {}
|
|
@@ -56004,9 +56203,14 @@ var SECTION_STYLE_KEYS = [
|
|
|
56004
56203
|
"border",
|
|
56005
56204
|
"font-size",
|
|
56006
56205
|
"font-weight",
|
|
56206
|
+
"line-height",
|
|
56207
|
+
"letter-spacing",
|
|
56208
|
+
"text-transform",
|
|
56007
56209
|
"color",
|
|
56008
56210
|
"background-color",
|
|
56009
56211
|
"background-image",
|
|
56212
|
+
"border-radius",
|
|
56213
|
+
"box-shadow",
|
|
56010
56214
|
"flex-direction",
|
|
56011
56215
|
"justify-content",
|
|
56012
56216
|
"align-items",
|
|
@@ -58212,74 +58416,42 @@ function listCommand(output) {
|
|
|
58212
58416
|
return 0;
|
|
58213
58417
|
}
|
|
58214
58418
|
|
|
58215
|
-
// src/commands/
|
|
58216
|
-
import { existsSync as
|
|
58217
|
-
import {
|
|
58218
|
-
import
|
|
58219
|
-
|
|
58220
|
-
// src/commands/run.ts
|
|
58221
|
-
import { existsSync as existsSync13, readFileSync as readFileSync14, unlinkSync as unlinkSync3 } from "node:fs";
|
|
58222
|
-
import { join as join18 } from "node:path";
|
|
58223
|
-
import chalk17 from "chalk";
|
|
58224
|
-
import ora6 from "ora";
|
|
58419
|
+
// src/commands/migrate.ts
|
|
58420
|
+
import { existsSync as existsSync11, mkdirSync as mkdirSync14, readFileSync as readFileSync13, writeFileSync as writeFileSync19 } from "node:fs";
|
|
58421
|
+
import { resolve as resolve3 } from "node:path";
|
|
58422
|
+
import chalk16 from "chalk";
|
|
58225
58423
|
|
|
58226
|
-
// src/
|
|
58227
|
-
|
|
58228
|
-
|
|
58229
|
-
|
|
58230
|
-
|
|
58231
|
-
|
|
58232
|
-
|
|
58233
|
-
|
|
58234
|
-
|
|
58235
|
-
|
|
58236
|
-
|
|
58237
|
-
|
|
58238
|
-
|
|
58239
|
-
|
|
58240
|
-
|
|
58241
|
-
return
|
|
58242
|
-
}
|
|
58243
|
-
|
|
58244
|
-
if (!trimmed)
|
|
58245
|
-
return ALL_MODULE_NAMES2;
|
|
58246
|
-
const uncheckIdx = new Set(trimmed.split(",").map((s) => Number.parseInt(s.trim(), 10)).filter((n) => Number.isInteger(n) && n >= 1 && n <= ALL_MODULE_NAMES2.length));
|
|
58247
|
-
const selected = ALL_MODULE_NAMES2.filter((_name, i) => !uncheckIdx.has(i + 1));
|
|
58248
|
-
if (selected.length === 0) {
|
|
58249
|
-
console.log(" (everything unchecked — running all modules instead)");
|
|
58250
|
-
return ALL_MODULE_NAMES2;
|
|
58424
|
+
// src/migrate/pdp-discovery.ts
|
|
58425
|
+
var PLATFORM_PATTERNS = {
|
|
58426
|
+
"salesforce-commerce": [
|
|
58427
|
+
/href="([^"]*-[A-Za-z]?\d{3,}\.html)"/gi,
|
|
58428
|
+
/href="([^"]*Product-(?:Show|Detail)[^"]*[?&]pid=[^"&]+[^"]*)"/gi
|
|
58429
|
+
],
|
|
58430
|
+
shopify: [/href="([^"]*\/products\/[^"]+)"/gi],
|
|
58431
|
+
vtex: [/href="([^"]*\/p(?:\?[^"]*|\/[^"]+|))"/gi],
|
|
58432
|
+
"vtex-fs": [/href="([^"]*\/p(?:\?[^"]*|\/[^"]+|))"/gi]
|
|
58433
|
+
};
|
|
58434
|
+
var ACTION_URL = /(Wishlist|Cart|MiniCart|Login|Account|Address|Order|Compare)-|add-?to-?/i;
|
|
58435
|
+
function acceptProductUrl(href, baseUrl) {
|
|
58436
|
+
if (ACTION_URL.test(href))
|
|
58437
|
+
return null;
|
|
58438
|
+
try {
|
|
58439
|
+
return new URL(href, baseUrl).toString();
|
|
58440
|
+
} catch {
|
|
58441
|
+
return null;
|
|
58251
58442
|
}
|
|
58252
|
-
console.log(` running: ${selected.join(", ")}`);
|
|
58253
|
-
return selected;
|
|
58254
|
-
}
|
|
58255
|
-
function readLine(prompt) {
|
|
58256
|
-
return new Promise((resolveLine) => {
|
|
58257
|
-
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
58258
|
-
rl.question(prompt, (ans) => {
|
|
58259
|
-
rl.close();
|
|
58260
|
-
resolveLine(ans);
|
|
58261
|
-
});
|
|
58262
|
-
rl.on("SIGINT", () => {
|
|
58263
|
-
rl.close();
|
|
58264
|
-
resolveLine(null);
|
|
58265
|
-
});
|
|
58266
|
-
});
|
|
58267
|
-
}
|
|
58268
|
-
|
|
58269
|
-
// src/engine/interactive-selector-prompt.ts
|
|
58270
|
-
init_client();
|
|
58271
|
-
var forceDisabled = false;
|
|
58272
|
-
function disableInteractive() {
|
|
58273
|
-
forceDisabled = true;
|
|
58274
58443
|
}
|
|
58275
|
-
function
|
|
58276
|
-
|
|
58277
|
-
|
|
58278
|
-
|
|
58279
|
-
|
|
58280
|
-
|
|
58281
|
-
|
|
58282
|
-
|
|
58444
|
+
function firstProductHref(html3, baseUrl, platform) {
|
|
58445
|
+
const patterns = platform ? PLATFORM_PATTERNS[platform] ?? [] : [];
|
|
58446
|
+
for (const re of patterns) {
|
|
58447
|
+
re.lastIndex = 0;
|
|
58448
|
+
for (let m = re.exec(html3);m; m = re.exec(html3)) {
|
|
58449
|
+
const url = m[1] ? acceptProductUrl(m[1], baseUrl) : null;
|
|
58450
|
+
if (url)
|
|
58451
|
+
return url;
|
|
58452
|
+
}
|
|
58453
|
+
}
|
|
58454
|
+
return firstProductHrefFromPlpHtml(html3, baseUrl);
|
|
58283
58455
|
}
|
|
58284
58456
|
|
|
58285
58457
|
// src/engine/sitemap-discover.ts
|
|
@@ -58361,6 +58533,1777 @@ async function discoverPagesFromSitemap(prodUrl, opts = {}) {
|
|
|
58361
58533
|
return result;
|
|
58362
58534
|
}
|
|
58363
58535
|
|
|
58536
|
+
// src/migrate/assets.ts
|
|
58537
|
+
import { mkdirSync as mkdirSync12, writeFileSync as writeFileSync16 } from "node:fs";
|
|
58538
|
+
import { join as join17 } from "node:path";
|
|
58539
|
+
function aggregateIcons(icons) {
|
|
58540
|
+
const byKey = new Map;
|
|
58541
|
+
for (const icon of icons) {
|
|
58542
|
+
const id = icon.id.trim();
|
|
58543
|
+
if (!id)
|
|
58544
|
+
continue;
|
|
58545
|
+
const key = `${icon.kind} ${id}`;
|
|
58546
|
+
const existing = byKey.get(key);
|
|
58547
|
+
if (existing)
|
|
58548
|
+
existing.count += icon.count;
|
|
58549
|
+
else
|
|
58550
|
+
byKey.set(key, { ...icon, id });
|
|
58551
|
+
}
|
|
58552
|
+
return [...byKey.values()].sort((a, b) => b.count - a.count);
|
|
58553
|
+
}
|
|
58554
|
+
async function collectSiteAssets(page) {
|
|
58555
|
+
const raw = await page.evaluate(() => {
|
|
58556
|
+
const abs = (href) => {
|
|
58557
|
+
if (!href)
|
|
58558
|
+
return null;
|
|
58559
|
+
try {
|
|
58560
|
+
return new URL(href, location.href).href;
|
|
58561
|
+
} catch {
|
|
58562
|
+
return null;
|
|
58563
|
+
}
|
|
58564
|
+
};
|
|
58565
|
+
const linkHref = (sel) => abs(document.querySelector(sel)?.getAttribute("href"));
|
|
58566
|
+
const favicon = linkHref("link[rel='icon']") || linkHref("link[rel='shortcut icon']") || abs("/favicon.ico");
|
|
58567
|
+
const appleTouchIcon = linkHref("link[rel='apple-touch-icon']");
|
|
58568
|
+
const manifest = linkHref("link[rel='manifest']");
|
|
58569
|
+
const ogImage = abs(document.querySelector("meta[property='og:image']")?.getAttribute("content"));
|
|
58570
|
+
const fonts = Array.from(document.querySelectorAll("link[rel='preload'][as='font']")).map((l) => abs(l.getAttribute("href"))).filter((u) => Boolean(u));
|
|
58571
|
+
const header = document.querySelector("header, [role='banner']") || document.body;
|
|
58572
|
+
let logo = null;
|
|
58573
|
+
if (header) {
|
|
58574
|
+
const hinted = Array.from(header.querySelectorAll("img, svg")).find((el2) => {
|
|
58575
|
+
const bag = `${el2.getAttribute("alt") ?? ""} ${el2.getAttribute("class") ?? ""} ${el2.getAttribute("aria-label") ?? ""} ${el2.closest("a")?.getAttribute("href") ?? ""}`.toLowerCase();
|
|
58576
|
+
return bag.includes("logo") || bag.includes("brand");
|
|
58577
|
+
});
|
|
58578
|
+
const el = hinted ?? header.querySelector("a[href='/'] img, a[href='/'] svg") ?? header.querySelector("img, svg");
|
|
58579
|
+
if (el) {
|
|
58580
|
+
if (el.tagName.toLowerCase() === "img") {
|
|
58581
|
+
const url = abs(el.getAttribute("src"));
|
|
58582
|
+
if (url)
|
|
58583
|
+
logo = { type: "img", url };
|
|
58584
|
+
} else {
|
|
58585
|
+
logo = { type: "svg", markup: el.outerHTML.slice(0, 20000) };
|
|
58586
|
+
}
|
|
58587
|
+
}
|
|
58588
|
+
}
|
|
58589
|
+
const icons = [];
|
|
58590
|
+
for (const use of Array.from(document.querySelectorAll("use"))) {
|
|
58591
|
+
const href = use.getAttribute("href") || use.getAttribute("xlink:href") || "";
|
|
58592
|
+
const id = href.startsWith("#") ? href.slice(1) : href.split("#")[1] || "";
|
|
58593
|
+
if (id)
|
|
58594
|
+
icons.push({ kind: "svg-use", id, count: 1 });
|
|
58595
|
+
}
|
|
58596
|
+
for (const svg of Array.from(document.querySelectorAll("svg"))) {
|
|
58597
|
+
if (svg.querySelector("use"))
|
|
58598
|
+
continue;
|
|
58599
|
+
const label = svg.getAttribute("aria-label") || svg.querySelector("title")?.textContent?.trim() || svg.getAttribute("class") || "unnamed";
|
|
58600
|
+
icons.push({ kind: "inline-svg", id: label.slice(0, 40), count: 1 });
|
|
58601
|
+
}
|
|
58602
|
+
const iconClassRe = /\b(icon(?![a-z])|fa-[a-z0-9-]+|material-icons|ph-[a-z0-9-]+|glyphicon-[a-z0-9-]+)\b/i;
|
|
58603
|
+
for (const el of Array.from(document.querySelectorAll("i, span"))) {
|
|
58604
|
+
const cls = el.getAttribute("class") ?? "";
|
|
58605
|
+
const m = cls.match(iconClassRe);
|
|
58606
|
+
if (m?.[1])
|
|
58607
|
+
icons.push({ kind: "icon-font", id: m[1], count: 1 });
|
|
58608
|
+
}
|
|
58609
|
+
return { favicon, appleTouchIcon, manifest, ogImage, fonts, logo, icons };
|
|
58610
|
+
});
|
|
58611
|
+
return { ...raw, icons: aggregateIcons(raw.icons) };
|
|
58612
|
+
}
|
|
58613
|
+
async function browserFetchBytes(page, url) {
|
|
58614
|
+
try {
|
|
58615
|
+
const r = await page.evaluate(async (u) => {
|
|
58616
|
+
const res = await fetch(u);
|
|
58617
|
+
if (!res.ok)
|
|
58618
|
+
return null;
|
|
58619
|
+
const bytes = new Uint8Array(await res.arrayBuffer());
|
|
58620
|
+
let binary = "";
|
|
58621
|
+
for (let i = 0;i < bytes.length; i++)
|
|
58622
|
+
binary += String.fromCharCode(bytes[i]);
|
|
58623
|
+
return { b64: btoa(binary), ct: res.headers.get("content-type") };
|
|
58624
|
+
}, url);
|
|
58625
|
+
if (!r)
|
|
58626
|
+
return null;
|
|
58627
|
+
return { buf: Buffer.from(r.b64, "base64"), contentType: r.ct };
|
|
58628
|
+
} catch {
|
|
58629
|
+
return null;
|
|
58630
|
+
}
|
|
58631
|
+
}
|
|
58632
|
+
async function nodeFetchBytes(url) {
|
|
58633
|
+
try {
|
|
58634
|
+
const res = await fetch(url, { signal: AbortSignal.timeout(15000) });
|
|
58635
|
+
if (!res.ok)
|
|
58636
|
+
return null;
|
|
58637
|
+
return { buf: Buffer.from(await res.arrayBuffer()), contentType: res.headers.get("content-type") };
|
|
58638
|
+
} catch {
|
|
58639
|
+
return null;
|
|
58640
|
+
}
|
|
58641
|
+
}
|
|
58642
|
+
async function downloadTo(url, dir, name, fetchBytes) {
|
|
58643
|
+
const got = await fetchBytes(url);
|
|
58644
|
+
if (!got)
|
|
58645
|
+
return null;
|
|
58646
|
+
const ext = extFromUrlOrType(url, got.contentType);
|
|
58647
|
+
const file = `${name}${ext}`;
|
|
58648
|
+
writeFileSync16(join17(dir, file), got.buf);
|
|
58649
|
+
return `assets/${file}`;
|
|
58650
|
+
}
|
|
58651
|
+
function extFromUrlOrType(url, contentType) {
|
|
58652
|
+
try {
|
|
58653
|
+
const m = new URL(url).pathname.match(/\.[a-z0-9]{2,5}$/i);
|
|
58654
|
+
if (m)
|
|
58655
|
+
return m[0];
|
|
58656
|
+
} catch {}
|
|
58657
|
+
if (contentType?.includes("svg"))
|
|
58658
|
+
return ".svg";
|
|
58659
|
+
if (contentType?.includes("png"))
|
|
58660
|
+
return ".png";
|
|
58661
|
+
if (contentType?.includes("jpeg"))
|
|
58662
|
+
return ".jpg";
|
|
58663
|
+
if (contentType?.includes("webp"))
|
|
58664
|
+
return ".webp";
|
|
58665
|
+
if (contentType?.includes("json"))
|
|
58666
|
+
return ".json";
|
|
58667
|
+
return "";
|
|
58668
|
+
}
|
|
58669
|
+
async function downloadSiteAssets(raw, runDir, fetchBytes) {
|
|
58670
|
+
const dir = join17(runDir, "assets");
|
|
58671
|
+
mkdirSync12(dir, { recursive: true });
|
|
58672
|
+
let logo = null;
|
|
58673
|
+
let logoSource = null;
|
|
58674
|
+
if (raw.logo?.type === "img") {
|
|
58675
|
+
logoSource = raw.logo.url;
|
|
58676
|
+
logo = await downloadTo(raw.logo.url, dir, "logo", fetchBytes);
|
|
58677
|
+
} else if (raw.logo?.type === "svg") {
|
|
58678
|
+
writeFileSync16(join17(dir, "logo.svg"), raw.logo.markup, "utf8");
|
|
58679
|
+
logo = "assets/logo.svg";
|
|
58680
|
+
logoSource = "inline-svg";
|
|
58681
|
+
}
|
|
58682
|
+
const [favicon, appleTouchIcon, ogImage] = await Promise.all([
|
|
58683
|
+
raw.favicon ? downloadTo(raw.favicon, dir, "favicon", fetchBytes) : Promise.resolve(null),
|
|
58684
|
+
raw.appleTouchIcon ? downloadTo(raw.appleTouchIcon, dir, "apple-touch-icon", fetchBytes) : Promise.resolve(null),
|
|
58685
|
+
raw.ogImage ? downloadTo(raw.ogImage, dir, "og-image", fetchBytes) : Promise.resolve(null)
|
|
58686
|
+
]);
|
|
58687
|
+
return {
|
|
58688
|
+
logo,
|
|
58689
|
+
logoSource,
|
|
58690
|
+
favicon,
|
|
58691
|
+
faviconSource: raw.favicon,
|
|
58692
|
+
appleTouchIcon,
|
|
58693
|
+
ogImage,
|
|
58694
|
+
manifest: raw.manifest,
|
|
58695
|
+
fonts: raw.fonts,
|
|
58696
|
+
icons: raw.icons
|
|
58697
|
+
};
|
|
58698
|
+
}
|
|
58699
|
+
|
|
58700
|
+
// src/migrate/browser-fetch.ts
|
|
58701
|
+
async function browserFetchText(page, url) {
|
|
58702
|
+
try {
|
|
58703
|
+
const text3 = await page.evaluate(async (u) => {
|
|
58704
|
+
const res = await fetch(u);
|
|
58705
|
+
if (!res.ok)
|
|
58706
|
+
return null;
|
|
58707
|
+
return res.text();
|
|
58708
|
+
}, url);
|
|
58709
|
+
if (text3 != null)
|
|
58710
|
+
return text3;
|
|
58711
|
+
} catch {}
|
|
58712
|
+
return nodeFetchText(url);
|
|
58713
|
+
}
|
|
58714
|
+
async function nodeFetchText(url) {
|
|
58715
|
+
try {
|
|
58716
|
+
const res = await fetch(url, {
|
|
58717
|
+
headers: {
|
|
58718
|
+
"User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 17_0) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Mobile/15E148 Safari/604.1"
|
|
58719
|
+
},
|
|
58720
|
+
signal: AbortSignal.timeout(15000)
|
|
58721
|
+
});
|
|
58722
|
+
if (!res.ok)
|
|
58723
|
+
return null;
|
|
58724
|
+
return await res.text();
|
|
58725
|
+
} catch {
|
|
58726
|
+
return null;
|
|
58727
|
+
}
|
|
58728
|
+
}
|
|
58729
|
+
|
|
58730
|
+
// src/migrate/bundle.ts
|
|
58731
|
+
init_esm10();
|
|
58732
|
+
init_html_compact();
|
|
58733
|
+
|
|
58734
|
+
// src/migrate/tailwind.ts
|
|
58735
|
+
var SPACING = {
|
|
58736
|
+
"0px": "0",
|
|
58737
|
+
"2px": "0.5",
|
|
58738
|
+
"4px": "1",
|
|
58739
|
+
"6px": "1.5",
|
|
58740
|
+
"8px": "2",
|
|
58741
|
+
"10px": "2.5",
|
|
58742
|
+
"12px": "3",
|
|
58743
|
+
"14px": "3.5",
|
|
58744
|
+
"16px": "4",
|
|
58745
|
+
"20px": "5",
|
|
58746
|
+
"24px": "6",
|
|
58747
|
+
"28px": "7",
|
|
58748
|
+
"32px": "8",
|
|
58749
|
+
"36px": "9",
|
|
58750
|
+
"40px": "10",
|
|
58751
|
+
"44px": "11",
|
|
58752
|
+
"48px": "12",
|
|
58753
|
+
"56px": "14",
|
|
58754
|
+
"64px": "16",
|
|
58755
|
+
"80px": "20",
|
|
58756
|
+
"96px": "24"
|
|
58757
|
+
};
|
|
58758
|
+
var FONT_SIZE = {
|
|
58759
|
+
"12px": "text-xs",
|
|
58760
|
+
"14px": "text-sm",
|
|
58761
|
+
"16px": "text-base",
|
|
58762
|
+
"18px": "text-lg",
|
|
58763
|
+
"20px": "text-xl",
|
|
58764
|
+
"24px": "text-2xl",
|
|
58765
|
+
"30px": "text-3xl",
|
|
58766
|
+
"36px": "text-4xl",
|
|
58767
|
+
"48px": "text-5xl",
|
|
58768
|
+
"60px": "text-6xl",
|
|
58769
|
+
"72px": "text-7xl",
|
|
58770
|
+
"96px": "text-8xl",
|
|
58771
|
+
"128px": "text-9xl"
|
|
58772
|
+
};
|
|
58773
|
+
var FONT_WEIGHT = {
|
|
58774
|
+
"100": "font-thin",
|
|
58775
|
+
"200": "font-extralight",
|
|
58776
|
+
"300": "font-light",
|
|
58777
|
+
"400": "font-normal",
|
|
58778
|
+
"500": "font-medium",
|
|
58779
|
+
"600": "font-semibold",
|
|
58780
|
+
"700": "font-bold",
|
|
58781
|
+
"800": "font-extrabold",
|
|
58782
|
+
"900": "font-black"
|
|
58783
|
+
};
|
|
58784
|
+
var RADIUS = {
|
|
58785
|
+
"0px": "rounded-none",
|
|
58786
|
+
"2px": "rounded-sm",
|
|
58787
|
+
"4px": "rounded",
|
|
58788
|
+
"6px": "rounded-md",
|
|
58789
|
+
"8px": "rounded-lg",
|
|
58790
|
+
"12px": "rounded-xl",
|
|
58791
|
+
"16px": "rounded-2xl",
|
|
58792
|
+
"24px": "rounded-3xl",
|
|
58793
|
+
"9999px": "rounded-full"
|
|
58794
|
+
};
|
|
58795
|
+
var DISPLAY = {
|
|
58796
|
+
flex: "flex",
|
|
58797
|
+
"inline-flex": "inline-flex",
|
|
58798
|
+
grid: "grid",
|
|
58799
|
+
"inline-grid": "inline-grid",
|
|
58800
|
+
block: "block",
|
|
58801
|
+
"inline-block": "inline-block",
|
|
58802
|
+
inline: "inline",
|
|
58803
|
+
none: "hidden"
|
|
58804
|
+
};
|
|
58805
|
+
var FLEX_DIR = {
|
|
58806
|
+
row: "flex-row",
|
|
58807
|
+
"row-reverse": "flex-row-reverse",
|
|
58808
|
+
column: "flex-col",
|
|
58809
|
+
"column-reverse": "flex-col-reverse"
|
|
58810
|
+
};
|
|
58811
|
+
var JUSTIFY = {
|
|
58812
|
+
"flex-start": "justify-start",
|
|
58813
|
+
"flex-end": "justify-end",
|
|
58814
|
+
center: "justify-center",
|
|
58815
|
+
"space-between": "justify-between",
|
|
58816
|
+
"space-around": "justify-around",
|
|
58817
|
+
"space-evenly": "justify-evenly"
|
|
58818
|
+
};
|
|
58819
|
+
var ALIGN = {
|
|
58820
|
+
"flex-start": "items-start",
|
|
58821
|
+
"flex-end": "items-end",
|
|
58822
|
+
center: "items-center",
|
|
58823
|
+
baseline: "items-baseline",
|
|
58824
|
+
stretch: "items-stretch"
|
|
58825
|
+
};
|
|
58826
|
+
var TEXT_TRANSFORM = {
|
|
58827
|
+
uppercase: "uppercase",
|
|
58828
|
+
lowercase: "lowercase",
|
|
58829
|
+
capitalize: "capitalize"
|
|
58830
|
+
};
|
|
58831
|
+
var POSITION = {
|
|
58832
|
+
relative: "relative",
|
|
58833
|
+
absolute: "absolute",
|
|
58834
|
+
fixed: "fixed",
|
|
58835
|
+
sticky: "sticky"
|
|
58836
|
+
};
|
|
58837
|
+
var OVERFLOW = {
|
|
58838
|
+
hidden: "overflow-hidden",
|
|
58839
|
+
auto: "overflow-auto",
|
|
58840
|
+
scroll: "overflow-scroll"
|
|
58841
|
+
};
|
|
58842
|
+
function normalizeColor(value) {
|
|
58843
|
+
return value.trim().replace(/\s+/g, "");
|
|
58844
|
+
}
|
|
58845
|
+
function spacingClass(prefix, value) {
|
|
58846
|
+
const step = SPACING[value.trim()];
|
|
58847
|
+
return step !== undefined ? `${prefix}-${step}` : `${prefix}-[${value.trim()}]`;
|
|
58848
|
+
}
|
|
58849
|
+
function boxSpacing(prop2, value) {
|
|
58850
|
+
const parts = value.trim().split(/\s+/);
|
|
58851
|
+
if (parts.length === 1 && parts[0])
|
|
58852
|
+
return [spacingClass(prop2, parts[0])];
|
|
58853
|
+
if (parts.length === 2 && parts[0] && parts[1]) {
|
|
58854
|
+
return [spacingClass(`${prop2}y`, parts[0]), spacingClass(`${prop2}x`, parts[1])];
|
|
58855
|
+
}
|
|
58856
|
+
return [];
|
|
58857
|
+
}
|
|
58858
|
+
function sizeClass(prefix, value) {
|
|
58859
|
+
const v = value.trim();
|
|
58860
|
+
if (v === "auto" || v === "")
|
|
58861
|
+
return null;
|
|
58862
|
+
if (v === "100%")
|
|
58863
|
+
return `${prefix}-full`;
|
|
58864
|
+
if (prefix === "w" && v === "100vw")
|
|
58865
|
+
return "w-screen";
|
|
58866
|
+
if (prefix === "h" && v === "100vh")
|
|
58867
|
+
return "h-screen";
|
|
58868
|
+
const step = SPACING[v];
|
|
58869
|
+
return step !== undefined ? `${prefix}-${step}` : `${prefix}-[${v}]`;
|
|
58870
|
+
}
|
|
58871
|
+
function colorClass(prefix, value, tokenByValue) {
|
|
58872
|
+
const v = value.trim();
|
|
58873
|
+
if (!v || v === "transparent" || v === "rgba(0, 0, 0, 0)" || v === "currentcolor")
|
|
58874
|
+
return null;
|
|
58875
|
+
const token = tokenByValue.get(v);
|
|
58876
|
+
if (token)
|
|
58877
|
+
return `${prefix}-${token}`;
|
|
58878
|
+
return `${prefix}-[${normalizeColor(v)}]`;
|
|
58879
|
+
}
|
|
58880
|
+
function stylesToTailwind(styles, themeTokens) {
|
|
58881
|
+
const tokenByValue = new Map;
|
|
58882
|
+
if (themeTokens) {
|
|
58883
|
+
for (const [token, value] of Object.entries(themeTokens)) {
|
|
58884
|
+
tokenByValue.set(value.trim(), token);
|
|
58885
|
+
}
|
|
58886
|
+
}
|
|
58887
|
+
const out = [];
|
|
58888
|
+
const push = (c) => {
|
|
58889
|
+
if (c && !out.includes(c))
|
|
58890
|
+
out.push(c);
|
|
58891
|
+
};
|
|
58892
|
+
const g = (k) => (styles[k] ?? "").trim();
|
|
58893
|
+
const display = g("display");
|
|
58894
|
+
push(DISPLAY[display]);
|
|
58895
|
+
if (display === "flex" || display === "inline-flex") {
|
|
58896
|
+
push(FLEX_DIR[g("flex-direction")]);
|
|
58897
|
+
}
|
|
58898
|
+
push(JUSTIFY[g("justify-content")]);
|
|
58899
|
+
push(ALIGN[g("align-items")]);
|
|
58900
|
+
const gap = g("gap");
|
|
58901
|
+
if (gap && gap !== "normal")
|
|
58902
|
+
push(spacingClass("gap", gap.split(/\s+/)[0] ?? gap));
|
|
58903
|
+
for (const c of boxSpacing("p", g("padding")))
|
|
58904
|
+
push(c);
|
|
58905
|
+
for (const c of boxSpacing("m", g("margin")))
|
|
58906
|
+
push(c);
|
|
58907
|
+
push(sizeClass("w", g("width")));
|
|
58908
|
+
push(sizeClass("h", g("height")));
|
|
58909
|
+
push(FONT_SIZE[g("font-size")] ?? (g("font-size") ? `text-[${g("font-size")}]` : null));
|
|
58910
|
+
push(FONT_WEIGHT[g("font-weight")]);
|
|
58911
|
+
push(TEXT_TRANSFORM[g("text-transform")]);
|
|
58912
|
+
push(colorClass("text", g("color"), tokenByValue));
|
|
58913
|
+
push(colorClass("bg", g("background-color"), tokenByValue));
|
|
58914
|
+
const radius = g("border-radius");
|
|
58915
|
+
if (radius)
|
|
58916
|
+
push(RADIUS[radius] ?? `rounded-[${radius}]`);
|
|
58917
|
+
const shadow = g("box-shadow");
|
|
58918
|
+
if (shadow && shadow !== "none")
|
|
58919
|
+
push("shadow");
|
|
58920
|
+
push(POSITION[g("position")]);
|
|
58921
|
+
push(OVERFLOW[g("overflow")]);
|
|
58922
|
+
return out;
|
|
58923
|
+
}
|
|
58924
|
+
|
|
58925
|
+
// src/migrate/bundle.ts
|
|
58926
|
+
var GLOBAL_ROLE_PREFIXES = ["header", "footer", "nav", "minicart"];
|
|
58927
|
+
function isGlobalRole(role) {
|
|
58928
|
+
const r = role.toLowerCase();
|
|
58929
|
+
return GLOBAL_ROLE_PREFIXES.some((p) => r === p || r.startsWith(`${p}-`));
|
|
58930
|
+
}
|
|
58931
|
+
function toMigratedComponent(c, interactions, scope, themeTokens, repeated) {
|
|
58932
|
+
return {
|
|
58933
|
+
...c,
|
|
58934
|
+
tailwind: stylesToTailwind(c.computedStyles ?? {}, themeTokens),
|
|
58935
|
+
interactions,
|
|
58936
|
+
scope,
|
|
58937
|
+
...repeated && repeated > 1 ? { repeated } : {}
|
|
58938
|
+
};
|
|
58939
|
+
}
|
|
58940
|
+
function planComponentDedup(items) {
|
|
58941
|
+
const firstAt = new Map;
|
|
58942
|
+
const plan = [];
|
|
58943
|
+
items.forEach((item, index2) => {
|
|
58944
|
+
const key = `${item.role}\x00${item.signature}`;
|
|
58945
|
+
const existing = firstAt.get(key);
|
|
58946
|
+
if (existing === undefined) {
|
|
58947
|
+
firstAt.set(key, plan.length);
|
|
58948
|
+
plan.push({ index: index2, repeated: 1 });
|
|
58949
|
+
} else {
|
|
58950
|
+
plan[existing].repeated += 1;
|
|
58951
|
+
}
|
|
58952
|
+
});
|
|
58953
|
+
return plan;
|
|
58954
|
+
}
|
|
58955
|
+
var COLLAPSE_THRESHOLD = 3;
|
|
58956
|
+
function dedupeRepeatedChildren(html3) {
|
|
58957
|
+
let collapsed = 0;
|
|
58958
|
+
try {
|
|
58959
|
+
const $2 = load(html3, null, false);
|
|
58960
|
+
$2("*").each((_, parent2) => {
|
|
58961
|
+
const children2 = $2(parent2).children().toArray();
|
|
58962
|
+
if (children2.length < COLLAPSE_THRESHOLD)
|
|
58963
|
+
return;
|
|
58964
|
+
const groups = new Map;
|
|
58965
|
+
for (const child of children2) {
|
|
58966
|
+
const fp = computeHtmlFingerprint($2.html(child) ?? "");
|
|
58967
|
+
const list = groups.get(fp) ?? [];
|
|
58968
|
+
list.push(child);
|
|
58969
|
+
groups.set(fp, list);
|
|
58970
|
+
}
|
|
58971
|
+
for (const list of groups.values()) {
|
|
58972
|
+
if (list.length < COLLAPSE_THRESHOLD)
|
|
58973
|
+
continue;
|
|
58974
|
+
const [first2, ...rest] = list;
|
|
58975
|
+
for (const el of rest)
|
|
58976
|
+
$2(el).remove();
|
|
58977
|
+
collapsed += rest.length;
|
|
58978
|
+
$2(first2).after(`<!-- ×${list.length} itens idênticos omitidos -->`);
|
|
58979
|
+
}
|
|
58980
|
+
});
|
|
58981
|
+
return { html: $2.html() ?? html3, collapsed };
|
|
58982
|
+
} catch {
|
|
58983
|
+
return { html: html3, collapsed: 0 };
|
|
58984
|
+
}
|
|
58985
|
+
}
|
|
58986
|
+
var COMPONENT_HTML_MAX_CHARS = 6000;
|
|
58987
|
+
function compactComponentHtml(html3, maxChars = COMPONENT_HTML_MAX_CHARS) {
|
|
58988
|
+
let stripped = html3;
|
|
58989
|
+
try {
|
|
58990
|
+
const $2 = load(html3);
|
|
58991
|
+
$2("script, style, noscript, svg, template, link[rel='stylesheet']").remove();
|
|
58992
|
+
$2("*").each((_, node2) => {
|
|
58993
|
+
const attrs = node2.attribs;
|
|
58994
|
+
if (!attrs)
|
|
58995
|
+
return;
|
|
58996
|
+
for (const name of Object.keys(attrs)) {
|
|
58997
|
+
if (name === "style") {
|
|
58998
|
+
delete attrs[name];
|
|
58999
|
+
continue;
|
|
59000
|
+
}
|
|
59001
|
+
if (/^data-(event|track|analytics)/.test(name) && (attrs[name]?.length ?? 0) > 100) {
|
|
59002
|
+
attrs[name] = "[…]";
|
|
59003
|
+
}
|
|
59004
|
+
if ((name === "src" || name === "srcset") && attrs[name]?.startsWith("data:")) {
|
|
59005
|
+
attrs[name] = "[data-uri]";
|
|
59006
|
+
}
|
|
59007
|
+
}
|
|
59008
|
+
if (attrs.class) {
|
|
59009
|
+
const kept = attrs.class.split(/\s+/).filter((t) => t && isSemanticClassToken(t));
|
|
59010
|
+
if (kept.length)
|
|
59011
|
+
attrs.class = kept.join(" ");
|
|
59012
|
+
else
|
|
59013
|
+
delete attrs.class;
|
|
59014
|
+
}
|
|
59015
|
+
});
|
|
59016
|
+
stripped = $2.html() ?? html3;
|
|
59017
|
+
} catch {}
|
|
59018
|
+
const { html: deduped, collapsed } = dedupeRepeatedChildren(stripped);
|
|
59019
|
+
const truncated = deduped.length > maxChars;
|
|
59020
|
+
return {
|
|
59021
|
+
html: truncated ? `${deduped.slice(0, maxChars)}
|
|
59022
|
+
<!-- TRUNCATED -->` : deduped,
|
|
59023
|
+
collapsed,
|
|
59024
|
+
truncated
|
|
59025
|
+
};
|
|
59026
|
+
}
|
|
59027
|
+
|
|
59028
|
+
// src/migrate/exporters/json.ts
|
|
59029
|
+
import { writeFileSync as writeFileSync17 } from "node:fs";
|
|
59030
|
+
import { join as join18 } from "node:path";
|
|
59031
|
+
var jsonExporter2 = {
|
|
59032
|
+
name: "json",
|
|
59033
|
+
async export(bundle, outDir) {
|
|
59034
|
+
writeFileSync17(join18(outDir, "manifest.json"), `${JSON.stringify(bundle, null, 2)}
|
|
59035
|
+
`, "utf8");
|
|
59036
|
+
}
|
|
59037
|
+
};
|
|
59038
|
+
|
|
59039
|
+
// src/migrate/exporters/markdown.ts
|
|
59040
|
+
import { mkdirSync as mkdirSync13, writeFileSync as writeFileSync18 } from "node:fs";
|
|
59041
|
+
import { join as join19 } from "node:path";
|
|
59042
|
+
var markdownExporter2 = {
|
|
59043
|
+
name: "markdown",
|
|
59044
|
+
async export(bundle, outDir) {
|
|
59045
|
+
const dirNames = bundle.components.map((c, i) => componentDirName(c.role, i + 1));
|
|
59046
|
+
const notes = [];
|
|
59047
|
+
bundle.components.forEach((component, i) => {
|
|
59048
|
+
const dirName = dirNames[i];
|
|
59049
|
+
const componentDir = join19(outDir, "components", dirName);
|
|
59050
|
+
mkdirSync13(componentDir, { recursive: true });
|
|
59051
|
+
const compact = compactComponentHtml(component.html);
|
|
59052
|
+
if (compact.collapsed > 0)
|
|
59053
|
+
notes.push(`\`${dirName}\`: collapsed ${compact.collapsed} repeated child element(s)`);
|
|
59054
|
+
if (compact.truncated)
|
|
59055
|
+
notes.push(`\`${dirName}\`: HTML truncated to fit the per-component token ceiling`);
|
|
59056
|
+
writeFileSync18(join19(componentDir, "README.md"), renderComponentReadme2(bundle.url, component, compact.html), "utf8");
|
|
59057
|
+
});
|
|
59058
|
+
writeFileSync18(join19(outDir, "index.md"), renderIndex2(bundle, dirNames, notes), "utf8");
|
|
59059
|
+
}
|
|
59060
|
+
};
|
|
59061
|
+
function renderIndex2(bundle, dirNames, notes) {
|
|
59062
|
+
const lines = [];
|
|
59063
|
+
const md = lines.push.bind(lines);
|
|
59064
|
+
md(`# Migration snapshot: ${bundle.url}`);
|
|
59065
|
+
md("");
|
|
59066
|
+
md("AI-ready, token-lean snapshot for migrating this storefront. Theme + component");
|
|
59067
|
+
md("map below; per-component detail (Tailwind, interactions, e2e selectors) lives in");
|
|
59068
|
+
md("each `components/<folder>/README.md`. Full raw HTML/CSS is in `manifest.json`.");
|
|
59069
|
+
md("");
|
|
59070
|
+
md("## Site");
|
|
59071
|
+
md("");
|
|
59072
|
+
md(`- **URL**: ${bundle.url}`);
|
|
59073
|
+
md(`- **Source platform**: ${bundle.platform}`);
|
|
59074
|
+
if (bundle.target)
|
|
59075
|
+
md(`- **Target**: ${bundle.target} (see MIGRATION_PROMPT.md)`);
|
|
59076
|
+
md(`- **Captured**: ${bundle.timestamp} (${bundle.viewport})`);
|
|
59077
|
+
md(`- **Pages**: ${bundle.pages.map((p) => `${p.kind} \`${p.path}\``).join(", ") || "—"}`);
|
|
59078
|
+
md("");
|
|
59079
|
+
if (bundle.screenshots?.length) {
|
|
59080
|
+
md("## Screenshots by viewport");
|
|
59081
|
+
md("");
|
|
59082
|
+
for (const s of bundle.screenshots)
|
|
59083
|
+
md(`- **${s.viewport}**: `);
|
|
59084
|
+
md("");
|
|
59085
|
+
}
|
|
59086
|
+
renderTheme(md, bundle.theme);
|
|
59087
|
+
renderAssets(md, bundle.assets);
|
|
59088
|
+
if (bundle.vtex) {
|
|
59089
|
+
md("## VTEX IO → FastStore blocks");
|
|
59090
|
+
md("");
|
|
59091
|
+
md(`_${bundle.vtex.blocks.length} block instances from the store runtime. \`custom-component\` = build from captured DOM/CSS; see component-map.json._`);
|
|
59092
|
+
md("");
|
|
59093
|
+
md("| VTEX block | → FastStore | confidence | count |");
|
|
59094
|
+
md("|---|---|---|---|");
|
|
59095
|
+
for (const m of bundle.vtex.map.slice(0, 40)) {
|
|
59096
|
+
md(`| \`${m.vtex}\` | ${m.faststore ? `\`${m.faststore}\`` : "_custom-component_"} | ${m.confidence || "—"} | ${m.count} |`);
|
|
59097
|
+
}
|
|
59098
|
+
md("");
|
|
59099
|
+
}
|
|
59100
|
+
md("## Components");
|
|
59101
|
+
md("");
|
|
59102
|
+
md("| Scope | Role | e2e keys | Folder |");
|
|
59103
|
+
md("|---|---|---|---|");
|
|
59104
|
+
bundle.components.forEach((c, i) => {
|
|
59105
|
+
const keys = c.interactions.map((x) => x.e2eKey).filter((k) => Boolean(k));
|
|
59106
|
+
const uniqueKeys = [...new Set(keys)];
|
|
59107
|
+
const roleCell = c.repeated && c.repeated > 1 ? `\`${c.role}\` ×${c.repeated}` : `\`${c.role}\``;
|
|
59108
|
+
md(`| ${c.scope} | ${roleCell} | ${uniqueKeys.length ? uniqueKeys.map((k) => `\`${k}\``).join(", ") : "—"} | [${dirNames[i]}](./components/${dirNames[i]}/README.md) |`);
|
|
59109
|
+
});
|
|
59110
|
+
md("");
|
|
59111
|
+
if (notes.length) {
|
|
59112
|
+
md("## Compaction notes");
|
|
59113
|
+
md("");
|
|
59114
|
+
md("_The lean artifact shrank these components; the full data is in `manifest.json`._");
|
|
59115
|
+
md("");
|
|
59116
|
+
for (const n of notes)
|
|
59117
|
+
md(`- ${n}`);
|
|
59118
|
+
md("");
|
|
59119
|
+
}
|
|
59120
|
+
return lines.join(`
|
|
59121
|
+
`);
|
|
59122
|
+
}
|
|
59123
|
+
function renderTheme(md, theme) {
|
|
59124
|
+
md("## Theme");
|
|
59125
|
+
md("");
|
|
59126
|
+
md("| Token | Value |");
|
|
59127
|
+
md("|---|---|");
|
|
59128
|
+
for (const [token, value] of Object.entries(theme.tokens)) {
|
|
59129
|
+
md(`| \`${token}\` | \`${value}\` |`);
|
|
59130
|
+
}
|
|
59131
|
+
md("");
|
|
59132
|
+
md(`- **Fonts**: ${listOrNone2(theme.typography.fontFamilies)}`);
|
|
59133
|
+
md(`- **Font sizes**: ${listOrNone2(theme.typography.sizeScale)}`);
|
|
59134
|
+
md(`- **Spacing scale**: ${listOrNone2(theme.spacingScale)}`);
|
|
59135
|
+
md(`- **Radii**: ${listOrNone2(theme.radii)}`);
|
|
59136
|
+
md(`- **Breakpoints**: ${listOrNone2(theme.breakpoints)}`);
|
|
59137
|
+
md(`- **Motion**: durations ${listOrNone2(theme.motion.durations)} · easings ${listOrNone2(theme.motion.easings)}`);
|
|
59138
|
+
md(`- **Shadows**: ${theme.shadows.length}`);
|
|
59139
|
+
md("");
|
|
59140
|
+
}
|
|
59141
|
+
function renderAssets(md, assets) {
|
|
59142
|
+
md("## Brand assets");
|
|
59143
|
+
md("");
|
|
59144
|
+
md(`- **Logo**: ${assets.logo ? `\`${assets.logo}\`${assets.logoSource ? ` (from ${assets.logoSource})` : ""}` : "_not found_"}`);
|
|
59145
|
+
md(`- **Favicon**: ${assets.favicon ? `\`${assets.favicon}\`` : "_not found_"}`);
|
|
59146
|
+
md(`- **Apple touch icon**: ${assets.appleTouchIcon ? `\`${assets.appleTouchIcon}\`` : "—"}`);
|
|
59147
|
+
md(`- **OG image**: ${assets.ogImage ? `\`${assets.ogImage}\`` : "—"}`);
|
|
59148
|
+
md(`- **Web app manifest**: ${assets.manifest ? assets.manifest : "—"}`);
|
|
59149
|
+
md(`- **Web fonts**: ${listOrNone2(assets.fonts)}`);
|
|
59150
|
+
md("");
|
|
59151
|
+
if (assets.icons.length) {
|
|
59152
|
+
md(`## Icons (${assets.icons.length})`);
|
|
59153
|
+
md("");
|
|
59154
|
+
md("_Map these to the target's icon set (e.g. FastStore uses Phosphor `<Icon>`)._");
|
|
59155
|
+
md("");
|
|
59156
|
+
md("| Kind | Id | Count |");
|
|
59157
|
+
md("|---|---|---|");
|
|
59158
|
+
for (const icon of assets.icons.slice(0, 60)) {
|
|
59159
|
+
md(`| ${icon.kind} | \`${escapePipes2(icon.id)}\` | ${icon.count} |`);
|
|
59160
|
+
}
|
|
59161
|
+
md("");
|
|
59162
|
+
}
|
|
59163
|
+
}
|
|
59164
|
+
function renderComponentReadme2(url, c, compactHtml) {
|
|
59165
|
+
const lines = [];
|
|
59166
|
+
const md = lines.push.bind(lines);
|
|
59167
|
+
md(`# Component: \`${c.role}\` (${c.scope})`);
|
|
59168
|
+
md("");
|
|
59169
|
+
if (c.repeated && c.repeated > 1) {
|
|
59170
|
+
md(`> ${c.repeated} structurally-identical instances on the page — one shown here.`);
|
|
59171
|
+
md("");
|
|
59172
|
+
}
|
|
59173
|
+
md(`- **Site**: ${url}`);
|
|
59174
|
+
md(`- **Selector**: \`${c.selector}\``);
|
|
59175
|
+
md(`- **Screenshot**: `);
|
|
59176
|
+
md("");
|
|
59177
|
+
md("## Tailwind (suggested)");
|
|
59178
|
+
md("");
|
|
59179
|
+
md(c.tailwind.length ? `\`\`\`
|
|
59180
|
+
${c.tailwind.join(" ")}
|
|
59181
|
+
\`\`\`` : "_none inferred_");
|
|
59182
|
+
md("");
|
|
59183
|
+
if (c.interactions.length) {
|
|
59184
|
+
md("## Interactions & e2e selectors");
|
|
59185
|
+
md("");
|
|
59186
|
+
md("| Selector | Kind | Label | e2e key | States |");
|
|
59187
|
+
md("|---|---|---|---|---|");
|
|
59188
|
+
for (const it of c.interactions) {
|
|
59189
|
+
const states = [
|
|
59190
|
+
it.hasHoverRule ? "hover" : "",
|
|
59191
|
+
it.hasFocusRule ? "focus" : "",
|
|
59192
|
+
it.animation ? "anim" : ""
|
|
59193
|
+
].filter(Boolean).join(", ");
|
|
59194
|
+
md(`| \`${escapePipes2(it.selector)}\` | ${it.kind} | ${escapePipes2(it.label) || "—"} | ${it.e2eKey ? `\`${it.e2eKey}\`` : "—"} | ${states || "—"} |`);
|
|
59195
|
+
}
|
|
59196
|
+
md("");
|
|
59197
|
+
}
|
|
59198
|
+
md("## Assets");
|
|
59199
|
+
md("");
|
|
59200
|
+
md(`- **Images** (${c.assets.images.length}): ${listOrNone2(c.assets.images)}`);
|
|
59201
|
+
md(`- **Fonts**: ${listOrNone2(c.assets.fonts)}`);
|
|
59202
|
+
md("");
|
|
59203
|
+
if (c.textContent.length) {
|
|
59204
|
+
md("## Notable text");
|
|
59205
|
+
md("");
|
|
59206
|
+
for (const t of c.textContent.slice(0, 15))
|
|
59207
|
+
md(`- ${t}`);
|
|
59208
|
+
md("");
|
|
59209
|
+
}
|
|
59210
|
+
md("## HTML (compacted)");
|
|
59211
|
+
md("");
|
|
59212
|
+
md("```html");
|
|
59213
|
+
md(compactHtml);
|
|
59214
|
+
md("```");
|
|
59215
|
+
md("");
|
|
59216
|
+
return lines.join(`
|
|
59217
|
+
`);
|
|
59218
|
+
}
|
|
59219
|
+
function listOrNone2(items) {
|
|
59220
|
+
if (items.length === 0)
|
|
59221
|
+
return "_none_";
|
|
59222
|
+
return items.slice(0, 10).map((i) => `\`${i}\``).join(", ");
|
|
59223
|
+
}
|
|
59224
|
+
function escapePipes2(s) {
|
|
59225
|
+
return s.replace(/\|/g, "\\|");
|
|
59226
|
+
}
|
|
59227
|
+
|
|
59228
|
+
// src/migrate/prompt.ts
|
|
59229
|
+
function buildMigrationPrompt(bundle, playbook) {
|
|
59230
|
+
const lines = [];
|
|
59231
|
+
const md = lines.push.bind(lines);
|
|
59232
|
+
md(`# Migration prompt: ${bundle.url}`);
|
|
59233
|
+
md("");
|
|
59234
|
+
md("You are migrating this storefront to a new framework. This folder is an");
|
|
59235
|
+
md("AI-ready snapshot of the live site — theme, page structure, and per-component");
|
|
59236
|
+
md("detail (suggested Tailwind classes, interaction hints, e2e selectors).");
|
|
59237
|
+
md("");
|
|
59238
|
+
md(`- **Source platform**: ${bundle.platform}`);
|
|
59239
|
+
md(`- **Captured**: ${bundle.timestamp} (${bundle.viewport})`);
|
|
59240
|
+
md(`- **Pages**: ${bundle.pages.map((p) => `${p.kind} (${p.path})`).join(", ") || "—"}`);
|
|
59241
|
+
md("");
|
|
59242
|
+
md("## How to work");
|
|
59243
|
+
md("");
|
|
59244
|
+
md("1. Read `index.md` for the theme tokens and the component map.");
|
|
59245
|
+
md("2. Start with **global** components (header/footer/minicart) — they appear on");
|
|
59246
|
+
md(" every page — then do page components per page kind (home → PLP → PDP).");
|
|
59247
|
+
md("3. For each component, open its `components/<folder>/README.md`: use the");
|
|
59248
|
+
md(" suggested Tailwind classes as the styling source of truth, keep the raw HTML");
|
|
59249
|
+
md(" only as a structure reference, and wire the listed e2e selectors.");
|
|
59250
|
+
md("4. Apply the theme tokens once, globally, then reference them (`bg-primary`).");
|
|
59251
|
+
md("");
|
|
59252
|
+
const globals = bundle.components.filter((c) => c.scope === "global");
|
|
59253
|
+
const pageComps = bundle.components.filter((c) => c.scope === "page");
|
|
59254
|
+
const row = (role, i) => `- \`${role}\` → components/${componentDirName(role, i + 1)}/README.md`;
|
|
59255
|
+
if (globals.length) {
|
|
59256
|
+
md("### Global components");
|
|
59257
|
+
bundle.components.forEach((c, i) => c.scope === "global" && md(row(c.role, i)));
|
|
59258
|
+
md("");
|
|
59259
|
+
}
|
|
59260
|
+
if (pageComps.length) {
|
|
59261
|
+
md("### Page components");
|
|
59262
|
+
bundle.components.forEach((c, i) => c.scope === "page" && md(row(c.role, i)));
|
|
59263
|
+
md("");
|
|
59264
|
+
}
|
|
59265
|
+
if (playbook) {
|
|
59266
|
+
md("---");
|
|
59267
|
+
md("");
|
|
59268
|
+
md(playbook);
|
|
59269
|
+
md("");
|
|
59270
|
+
}
|
|
59271
|
+
return lines.join(`
|
|
59272
|
+
`);
|
|
59273
|
+
}
|
|
59274
|
+
|
|
59275
|
+
// src/migrate/targets/faststore.ts
|
|
59276
|
+
function pickBreakpointTiers(breakpoints) {
|
|
59277
|
+
const px = breakpoints.map((b) => ({ raw: b, n: Number.parseFloat(b) })).filter((b) => Number.isFinite(b.n));
|
|
59278
|
+
const used = new Set;
|
|
59279
|
+
const nearest = (target) => {
|
|
59280
|
+
let best = null;
|
|
59281
|
+
for (const b of px) {
|
|
59282
|
+
if (used.has(b.raw))
|
|
59283
|
+
continue;
|
|
59284
|
+
const d = Math.abs(b.n - target);
|
|
59285
|
+
if (!best || d < best.d)
|
|
59286
|
+
best = { raw: b.raw, d };
|
|
59287
|
+
}
|
|
59288
|
+
if (best)
|
|
59289
|
+
used.add(best.raw);
|
|
59290
|
+
return best?.raw ?? null;
|
|
59291
|
+
};
|
|
59292
|
+
return {
|
|
59293
|
+
phone: nearest(480),
|
|
59294
|
+
tablet: nearest(768),
|
|
59295
|
+
notebook: nearest(1024),
|
|
59296
|
+
desktop: nearest(1280)
|
|
59297
|
+
};
|
|
59298
|
+
}
|
|
59299
|
+
function buildFastStoreTheme(theme) {
|
|
59300
|
+
const lines = [];
|
|
59301
|
+
const put = (token, value) => {
|
|
59302
|
+
if (value)
|
|
59303
|
+
lines.push(` ${token}: ${value};`);
|
|
59304
|
+
};
|
|
59305
|
+
const fonts = theme.typography.fontFamilies;
|
|
59306
|
+
const radii = theme.radii;
|
|
59307
|
+
const bp = theme.breakpoints;
|
|
59308
|
+
put("--fs-color-primary-bkg", theme.colors.primary);
|
|
59309
|
+
put("--fs-color-accent-0", theme.colors.secondary);
|
|
59310
|
+
put("--fs-color-text", theme.colors.text);
|
|
59311
|
+
put("--fs-color-body-bkg", theme.colors.background);
|
|
59312
|
+
put("--fs-text-face-body", fonts[0]);
|
|
59313
|
+
put("--fs-text-face-title", fonts[1] ?? fonts[0]);
|
|
59314
|
+
put("--fs-border-radius-medium", radii[Math.floor(radii.length / 2)]);
|
|
59315
|
+
put("--fs-shadow", theme.shadows[0]);
|
|
59316
|
+
const tiers = pickBreakpointTiers(bp);
|
|
59317
|
+
put("--fs-grid-breakpoint-phone", tiers.phone);
|
|
59318
|
+
put("--fs-grid-breakpoint-tablet", tiers.tablet);
|
|
59319
|
+
put("--fs-grid-breakpoint-notebook", tiers.notebook);
|
|
59320
|
+
put("--fs-grid-breakpoint-desktop", tiers.desktop);
|
|
59321
|
+
return [
|
|
59322
|
+
"// custom-theme.scss — starter generated by `parity migrate --target faststore`.",
|
|
59323
|
+
"// Brand tokens only; adjust and extend against @faststore/ui global tokens.",
|
|
59324
|
+
".theme {",
|
|
59325
|
+
...lines,
|
|
59326
|
+
"}",
|
|
59327
|
+
""
|
|
59328
|
+
].join(`
|
|
59329
|
+
`);
|
|
59330
|
+
}
|
|
59331
|
+
var faststore = `## Target: VTEX FastStore (v4)
|
|
59332
|
+
|
|
59333
|
+
Generate the migrated storefront as a FastStore v4 project. Do NOT hand-roll the
|
|
59334
|
+
scaffold — use the official CLI, then fill in sections from the components below.
|
|
59335
|
+
|
|
59336
|
+
### Setup (once)
|
|
59337
|
+
- Requirements + project setup: https://developers.vtex.com/docs/guides/faststore/getting-started-requirements
|
|
59338
|
+
- Project structure overview: https://developers.vtex.com/docs/guides/faststore/project-structure-overview
|
|
59339
|
+
- \`yarn install\` then \`yarn dev\` → dev store at http://localhost:3000
|
|
59340
|
+
|
|
59341
|
+
### CLI (@faststore/cli)
|
|
59342
|
+
- \`faststore dev\` — local dev server (localhost:3000)
|
|
59343
|
+
- \`faststore build\` — production build
|
|
59344
|
+
- \`faststore generate\` — regenerate schema + TS types after changes
|
|
59345
|
+
- \`faststore cms-sync\` — sync the \`cms/\` folder with the Headless CMS
|
|
59346
|
+
|
|
59347
|
+
### Styling — IMPORTANT: FastStore does NOT use Tailwind
|
|
59348
|
+
FastStore v4 styles with **SCSS design tokens + \`data-fs-*\` attributes**, not
|
|
59349
|
+
utility classes. The Tailwind classes in each component README are a convenience
|
|
59350
|
+
approximation — treat the **raw computed styles in manifest.json as the source
|
|
59351
|
+
of truth** for exact values. Package split: \`@faststore/components\` (structure/
|
|
59352
|
+
behavior, unstyled) · \`@faststore/ui\` (styles + design tokens) · \`@faststore/core\`
|
|
59353
|
+
(sections/pages).
|
|
59354
|
+
|
|
59355
|
+
- **Theme** → a starter \`custom-theme.scss\` was generated in this snapshot from
|
|
59356
|
+
the extracted brand tokens. Drop it in \`src/themes/\` and refine. Token map used:
|
|
59357
|
+
|
|
59358
|
+
| Extracted | FastStore global token |
|
|
59359
|
+
| --- | --- |
|
|
59360
|
+
| primary | \`--fs-color-primary-bkg\` |
|
|
59361
|
+
| secondary | \`--fs-color-accent-0\` |
|
|
59362
|
+
| text | \`--fs-color-text\` |
|
|
59363
|
+
| background | \`--fs-color-body-bkg\` |
|
|
59364
|
+
| font (body/title) | \`--fs-text-face-body\` / \`--fs-text-face-title\` |
|
|
59365
|
+
| radius | \`--fs-border-radius-medium\` |
|
|
59366
|
+
| shadow | \`--fs-shadow\` |
|
|
59367
|
+
| breakpoints | \`--fs-grid-breakpoint-phone|tablet|notebook|desktop\` |
|
|
59368
|
+
|
|
59369
|
+
Do NOT override \`--fs-spacing-*\`/\`--fs-text-size-*\` (structural scale).
|
|
59370
|
+
Global tokens: https://developers.vtex.com/docs/guides/faststore/global-tokens-overview
|
|
59371
|
+
- **Per-component styling** → override via each component's \`data-fs-*\` attribute
|
|
59372
|
+
in SCSS (e.g. \`[data-fs-product-shelf]\`), not utility classes.
|
|
59373
|
+
Styling a component: https://developers.vtex.com/docs/guides/faststore/using-themes-components
|
|
59374
|
+
|
|
59375
|
+
### Icons — Phosphor
|
|
59376
|
+
FastStore ships Phosphor icons via the \`<Icon>\` component (\`data-fs-icon\`, \`weight\`
|
|
59377
|
+
prop: thin|light|regular|bold). Map each entry in this snapshot's **icon inventory**
|
|
59378
|
+
to a Phosphor icon id; add any missing ones as custom icons.
|
|
59379
|
+
- Iconography: https://developers.vtex.com/docs/guides/faststore/reference-icons
|
|
59380
|
+
- Adding custom icons: https://developers.vtex.com/docs/guides/faststore/atoms-icon
|
|
59381
|
+
|
|
59382
|
+
### Brand assets
|
|
59383
|
+
- Logo + favicon (and apple-touch-icon / OG image) were downloaded to \`assets/\`
|
|
59384
|
+
in this snapshot — drop them into the FastStore project's \`public/\` and wire the
|
|
59385
|
+
logo into the Navbar/Header section.
|
|
59386
|
+
|
|
59387
|
+
### Where components go — section structure
|
|
59388
|
+
Each detected component → a FastStore section:
|
|
59389
|
+
- \`src/components/<SectionName>.tsx\` (the React section)
|
|
59390
|
+
- register it in \`src/components/index.tsx\` (the components entry)
|
|
59391
|
+
- add its schema to \`cms/faststore/sections.json\` (form editors use in the CMS)
|
|
59392
|
+
- **Global components** (header/footer/minicart) render on every page;
|
|
59393
|
+
**page components** (home/PLP/PDP) go into the matching page content type.
|
|
59394
|
+
- After adding/editing sections: \`faststore generate\` then \`faststore cms-sync\`.
|
|
59395
|
+
- Splitting a legacy CMS structure into components/content-types is supported by
|
|
59396
|
+
\`vtex content split-components\` and \`vtex content split-content-types\`.
|
|
59397
|
+
- Creating a section: https://developers.vtex.com/docs/guides/faststore/building-sections-creating-a-new-section
|
|
59398
|
+
- Headless CMS model: https://developers.vtex.com/docs/guides/faststore/headless-cms-overview
|
|
59399
|
+
- Creating sections: https://developers.vtex.com/docs/guides/faststore/creating-a-new-section-and-content-type
|
|
59400
|
+
|
|
59401
|
+
### e2e
|
|
59402
|
+
Use the suggested selectors (per component, mapped to known commerce keys) to
|
|
59403
|
+
seed Playwright/Cypress smoke tests on the migrated store.`;
|
|
59404
|
+
|
|
59405
|
+
// src/migrate/targets/index.ts
|
|
59406
|
+
var TARGETS = {
|
|
59407
|
+
faststore
|
|
59408
|
+
};
|
|
59409
|
+
function getTargetPlaybook(name) {
|
|
59410
|
+
return Object.hasOwn(TARGETS, name) ? TARGETS[name] : undefined;
|
|
59411
|
+
}
|
|
59412
|
+
var TARGET_NAMES = Object.keys(TARGETS);
|
|
59413
|
+
|
|
59414
|
+
// src/migrate/theme.ts
|
|
59415
|
+
var TRANSPARENT = new Set(["transparent", "rgba(0, 0, 0, 0)", "rgba(0,0,0,0)"]);
|
|
59416
|
+
function parseRgb(color) {
|
|
59417
|
+
const m = color.trim().match(/rgba?\(([^)]+)\)/i);
|
|
59418
|
+
if (!m || !m[1])
|
|
59419
|
+
return null;
|
|
59420
|
+
const parts = m[1].split(",").map((p) => Number.parseFloat(p.trim()));
|
|
59421
|
+
if (parts.length < 3 || parts.some((n) => Number.isNaN(n)))
|
|
59422
|
+
return null;
|
|
59423
|
+
return { r: parts[0], g: parts[1], b: parts[2], a: parts[3] ?? 1 };
|
|
59424
|
+
}
|
|
59425
|
+
function isNeutral(color) {
|
|
59426
|
+
const c = parseRgb(color);
|
|
59427
|
+
if (!c)
|
|
59428
|
+
return false;
|
|
59429
|
+
if (c.a < 0.1)
|
|
59430
|
+
return true;
|
|
59431
|
+
const max = Math.max(c.r, c.g, c.b);
|
|
59432
|
+
const min = Math.min(c.r, c.g, c.b);
|
|
59433
|
+
return max - min < 18;
|
|
59434
|
+
}
|
|
59435
|
+
function rank(values) {
|
|
59436
|
+
const counts = new Map;
|
|
59437
|
+
for (const v of values) {
|
|
59438
|
+
const key = v.trim();
|
|
59439
|
+
if (!key || TRANSPARENT.has(key))
|
|
59440
|
+
continue;
|
|
59441
|
+
counts.set(key, (counts.get(key) ?? 0) + 1);
|
|
59442
|
+
}
|
|
59443
|
+
return new Map([...counts.entries()].sort((a, b) => b[1] - a[1]));
|
|
59444
|
+
}
|
|
59445
|
+
function isPlausibleFontFamily(f) {
|
|
59446
|
+
const v = f.trim();
|
|
59447
|
+
return v.length > 0 && v.length < 120 && !v.includes("=") && !v.includes("&");
|
|
59448
|
+
}
|
|
59449
|
+
function sortByPx(values) {
|
|
59450
|
+
const uniq = [...new Set(values.map((v) => v.trim()).filter(Boolean))];
|
|
59451
|
+
return uniq.sort((a, b) => (Number.parseFloat(a) || 0) - (Number.parseFloat(b) || 0));
|
|
59452
|
+
}
|
|
59453
|
+
function mergeRawThemeSamples(list) {
|
|
59454
|
+
const first2 = list[0];
|
|
59455
|
+
const concat = (key) => list.flatMap((s) => s[key]);
|
|
59456
|
+
return {
|
|
59457
|
+
bodyBackground: first2.bodyBackground,
|
|
59458
|
+
bodyText: first2.bodyText,
|
|
59459
|
+
bodyFontFamily: first2.bodyFontFamily,
|
|
59460
|
+
colors: concat("colors"),
|
|
59461
|
+
backgrounds: concat("backgrounds"),
|
|
59462
|
+
interactiveBackgrounds: concat("interactiveBackgrounds"),
|
|
59463
|
+
fontFamilies: concat("fontFamilies"),
|
|
59464
|
+
fontSizes: concat("fontSizes"),
|
|
59465
|
+
radii: concat("radii"),
|
|
59466
|
+
shadows: concat("shadows"),
|
|
59467
|
+
spacings: concat("spacings"),
|
|
59468
|
+
breakpoints: concat("breakpoints"),
|
|
59469
|
+
motionDurations: concat("motionDurations"),
|
|
59470
|
+
motionEasings: concat("motionEasings")
|
|
59471
|
+
};
|
|
59472
|
+
}
|
|
59473
|
+
function aggregateTheme(raw) {
|
|
59474
|
+
const paletteRanked = rank([...raw.colors, ...raw.backgrounds]);
|
|
59475
|
+
const interactiveRanked = rank(raw.interactiveBackgrounds);
|
|
59476
|
+
const chromatic = [...interactiveRanked.keys()].filter((c) => !isNeutral(c));
|
|
59477
|
+
const primary = chromatic[0] ?? null;
|
|
59478
|
+
const secondary = chromatic.find((c) => c !== primary) ?? null;
|
|
59479
|
+
const tokens = {};
|
|
59480
|
+
if (primary)
|
|
59481
|
+
tokens.primary = primary;
|
|
59482
|
+
if (secondary)
|
|
59483
|
+
tokens.secondary = secondary;
|
|
59484
|
+
if (raw.bodyBackground && !TRANSPARENT.has(raw.bodyBackground.trim()))
|
|
59485
|
+
tokens.background = raw.bodyBackground.trim();
|
|
59486
|
+
if (raw.bodyText)
|
|
59487
|
+
tokens.text = raw.bodyText.trim();
|
|
59488
|
+
const palette = [...paletteRanked.entries()].map(([value, count]) => ({
|
|
59489
|
+
value,
|
|
59490
|
+
count,
|
|
59491
|
+
token: Object.entries(tokens).find(([, v]) => v === value)?.[0] ?? (isNeutral(value) ? "neutral" : "accent")
|
|
59492
|
+
}));
|
|
59493
|
+
return {
|
|
59494
|
+
colors: {
|
|
59495
|
+
primary,
|
|
59496
|
+
secondary,
|
|
59497
|
+
background: tokens.background ?? null,
|
|
59498
|
+
text: tokens.text ?? null,
|
|
59499
|
+
palette
|
|
59500
|
+
},
|
|
59501
|
+
typography: {
|
|
59502
|
+
fontFamilies: [...rank(raw.fontFamilies).keys()].filter(isPlausibleFontFamily),
|
|
59503
|
+
sizeScale: sortByPx(raw.fontSizes)
|
|
59504
|
+
},
|
|
59505
|
+
spacingScale: sortByPx(raw.spacings),
|
|
59506
|
+
radii: sortByPx(raw.radii).filter((r) => r !== "0px"),
|
|
59507
|
+
shadows: [...new Set(raw.shadows.map((s) => s.trim()))].filter((s) => s && s !== "none"),
|
|
59508
|
+
breakpoints: sortByPx(raw.breakpoints),
|
|
59509
|
+
motion: {
|
|
59510
|
+
durations: [...new Set(raw.motionDurations.map((d) => d.trim()))].filter((d) => d && d !== "0s" && d !== "0ms"),
|
|
59511
|
+
easings: [...new Set(raw.motionEasings.map((e) => e.trim()))].filter((e) => e && e !== "ease" && e !== "linear")
|
|
59512
|
+
},
|
|
59513
|
+
tokens
|
|
59514
|
+
};
|
|
59515
|
+
}
|
|
59516
|
+
async function scrapeThemeSamples(page) {
|
|
59517
|
+
return page.evaluate(() => {
|
|
59518
|
+
const cap = 2000;
|
|
59519
|
+
const els = Array.from(document.querySelectorAll("*")).slice(0, cap);
|
|
59520
|
+
const colors = [];
|
|
59521
|
+
const backgrounds = [];
|
|
59522
|
+
const interactiveBackgrounds = [];
|
|
59523
|
+
const fontFamilies = [];
|
|
59524
|
+
const fontSizes = [];
|
|
59525
|
+
const radii = [];
|
|
59526
|
+
const shadows = [];
|
|
59527
|
+
const spacings = [];
|
|
59528
|
+
const motionDurations = [];
|
|
59529
|
+
const motionEasings = [];
|
|
59530
|
+
const transparent = new Set(["transparent", "rgba(0, 0, 0, 0)"]);
|
|
59531
|
+
for (const el of els) {
|
|
59532
|
+
const cs = getComputedStyle(el);
|
|
59533
|
+
colors.push(cs.color);
|
|
59534
|
+
const bg = cs.backgroundColor;
|
|
59535
|
+
if (!transparent.has(bg))
|
|
59536
|
+
backgrounds.push(bg);
|
|
59537
|
+
fontFamilies.push(cs.fontFamily);
|
|
59538
|
+
fontSizes.push(cs.fontSize);
|
|
59539
|
+
if (cs.borderRadius)
|
|
59540
|
+
radii.push(cs.borderRadius);
|
|
59541
|
+
if (cs.boxShadow && cs.boxShadow !== "none")
|
|
59542
|
+
shadows.push(cs.boxShadow);
|
|
59543
|
+
if (cs.gap && cs.gap !== "normal")
|
|
59544
|
+
spacings.push(cs.gap.split(/\s+/)[0] ?? cs.gap);
|
|
59545
|
+
const pad = cs.padding.split(/\s+/);
|
|
59546
|
+
if (pad.length === 1 && pad[0] && pad[0] !== "0px")
|
|
59547
|
+
spacings.push(pad[0]);
|
|
59548
|
+
for (const d of cs.transitionDuration.split(","))
|
|
59549
|
+
if (d.trim())
|
|
59550
|
+
motionDurations.push(d.trim());
|
|
59551
|
+
for (const d of cs.animationDuration.split(","))
|
|
59552
|
+
if (d.trim())
|
|
59553
|
+
motionDurations.push(d.trim());
|
|
59554
|
+
for (const e of cs.transitionTimingFunction.split(","))
|
|
59555
|
+
if (e.trim())
|
|
59556
|
+
motionEasings.push(e.trim());
|
|
59557
|
+
const tag = el.tagName.toLowerCase();
|
|
59558
|
+
const role = el.getAttribute("role");
|
|
59559
|
+
const isInteractive = tag === "button" || tag === "a" || role === "button";
|
|
59560
|
+
if (isInteractive && !transparent.has(bg))
|
|
59561
|
+
interactiveBackgrounds.push(bg);
|
|
59562
|
+
}
|
|
59563
|
+
const breakpoints = [];
|
|
59564
|
+
for (const sheet of Array.from(document.styleSheets)) {
|
|
59565
|
+
let rules;
|
|
59566
|
+
try {
|
|
59567
|
+
rules = sheet.cssRules;
|
|
59568
|
+
} catch {
|
|
59569
|
+
continue;
|
|
59570
|
+
}
|
|
59571
|
+
for (const rule of Array.from(rules)) {
|
|
59572
|
+
const media = rule.media?.mediaText;
|
|
59573
|
+
if (!media)
|
|
59574
|
+
continue;
|
|
59575
|
+
const re = /(?:min|max)-width:\s*(\d+(?:\.\d+)?)px/g;
|
|
59576
|
+
let m;
|
|
59577
|
+
while ((m = re.exec(media)) !== null)
|
|
59578
|
+
breakpoints.push(`${m[1]}px`);
|
|
59579
|
+
}
|
|
59580
|
+
}
|
|
59581
|
+
const body = getComputedStyle(document.body);
|
|
59582
|
+
return {
|
|
59583
|
+
bodyBackground: getComputedStyle(document.documentElement).backgroundColor || body.backgroundColor,
|
|
59584
|
+
bodyText: body.color,
|
|
59585
|
+
bodyFontFamily: body.fontFamily,
|
|
59586
|
+
colors,
|
|
59587
|
+
backgrounds,
|
|
59588
|
+
interactiveBackgrounds,
|
|
59589
|
+
fontFamilies,
|
|
59590
|
+
fontSizes,
|
|
59591
|
+
radii,
|
|
59592
|
+
shadows,
|
|
59593
|
+
spacings,
|
|
59594
|
+
breakpoints,
|
|
59595
|
+
motionDurations,
|
|
59596
|
+
motionEasings
|
|
59597
|
+
};
|
|
59598
|
+
});
|
|
59599
|
+
}
|
|
59600
|
+
|
|
59601
|
+
// src/migrate/vtex/faststore-map.ts
|
|
59602
|
+
var TABLE = {
|
|
59603
|
+
"product-summary": { faststore: "ProductCard", confidence: 0.95 },
|
|
59604
|
+
shelf: { faststore: "ProductShelf", confidence: 0.9 },
|
|
59605
|
+
"product-shelf": { faststore: "ProductShelf", confidence: 0.92 },
|
|
59606
|
+
"flex-layout": { faststore: "FlexLayout", confidence: 0.9 },
|
|
59607
|
+
"rich-text": { faststore: "RichText", confidence: 0.97 },
|
|
59608
|
+
"responsive-layout": { faststore: "FlexLayout", confidence: 0.7 },
|
|
59609
|
+
image: { faststore: "Image", confidence: 0.9 },
|
|
59610
|
+
"list-context": { faststore: "ProductShelf", confidence: 0.6 },
|
|
59611
|
+
"slider-layout": { faststore: "Carousel", confidence: 0.85 },
|
|
59612
|
+
carousel: { faststore: "Carousel", confidence: 0.85 },
|
|
59613
|
+
"search-bar": { faststore: "SearchInput", confidence: 0.9 },
|
|
59614
|
+
"search-result": { faststore: "ProductGallery", confidence: 0.8 },
|
|
59615
|
+
minicart: { faststore: "Minicart", confidence: 0.9 },
|
|
59616
|
+
"add-to-cart-button": { faststore: "BuyButton", confidence: 0.9 },
|
|
59617
|
+
menu: { faststore: "Navbar", confidence: 0.7 },
|
|
59618
|
+
header: { faststore: "Navbar", confidence: 0.75 },
|
|
59619
|
+
footer: { faststore: "Footer", confidence: 0.9 },
|
|
59620
|
+
breadcrumb: { faststore: "Breadcrumb", confidence: 0.95 },
|
|
59621
|
+
"product-price": { faststore: "Price", confidence: 0.9 },
|
|
59622
|
+
"product-selling-price": { faststore: "Price", confidence: 0.85 },
|
|
59623
|
+
"product-list-price": { faststore: "Price", confidence: 0.85 },
|
|
59624
|
+
"product-images": { faststore: "ImageGallery", confidence: 0.85 },
|
|
59625
|
+
"sku-selector": { faststore: "SkuSelector", confidence: 0.85 },
|
|
59626
|
+
"product-name": { faststore: "ProductTitle", confidence: 0.85 }
|
|
59627
|
+
};
|
|
59628
|
+
function lookup(blockName) {
|
|
59629
|
+
if (TABLE[blockName])
|
|
59630
|
+
return TABLE[blockName];
|
|
59631
|
+
const head = blockName.split(".")[0];
|
|
59632
|
+
return TABLE[head] ?? null;
|
|
59633
|
+
}
|
|
59634
|
+
function mapVtexBlocksToFastStore(blocks) {
|
|
59635
|
+
const counts = new Map;
|
|
59636
|
+
for (const b of blocks)
|
|
59637
|
+
counts.set(b.blockName, (counts.get(b.blockName) ?? 0) + 1);
|
|
59638
|
+
const out = [];
|
|
59639
|
+
for (const [vtex, count] of counts) {
|
|
59640
|
+
const entry = lookup(vtex);
|
|
59641
|
+
if (entry) {
|
|
59642
|
+
out.push({ vtex, faststore: entry.faststore, confidence: entry.confidence, strategy: "mapped", count });
|
|
59643
|
+
} else {
|
|
59644
|
+
out.push({ vtex, faststore: null, confidence: 0, strategy: "custom-component", count });
|
|
59645
|
+
}
|
|
59646
|
+
}
|
|
59647
|
+
return out.sort((a, b) => b.count - a.count);
|
|
59648
|
+
}
|
|
59649
|
+
|
|
59650
|
+
// src/migrate/vtex/runtime.ts
|
|
59651
|
+
function blockNameFromTreePath(treePath) {
|
|
59652
|
+
const leaf = treePath.split("/").pop() ?? treePath;
|
|
59653
|
+
const noInstance = leaf.split("#")[0] ?? leaf;
|
|
59654
|
+
return noInstance.includes(":") ? noInstance.slice(noInstance.lastIndexOf(":") + 1) : noInstance;
|
|
59655
|
+
}
|
|
59656
|
+
function parentTreePath(treePath) {
|
|
59657
|
+
const i = treePath.lastIndexOf("/");
|
|
59658
|
+
return i > 0 ? treePath.slice(0, i) : null;
|
|
59659
|
+
}
|
|
59660
|
+
async function readVtexBlockTree(page) {
|
|
59661
|
+
let paths;
|
|
59662
|
+
try {
|
|
59663
|
+
paths = await page.evaluate(() => {
|
|
59664
|
+
const rt = window.__RUNTIME__;
|
|
59665
|
+
if (!rt || !rt.extensions || typeof rt.extensions !== "object")
|
|
59666
|
+
return null;
|
|
59667
|
+
return Object.entries(rt.extensions).map(([treePath, ext]) => ({
|
|
59668
|
+
treePath,
|
|
59669
|
+
component: ext && typeof ext === "object" && "component" in ext ? ext.component ?? null : null
|
|
59670
|
+
}));
|
|
59671
|
+
});
|
|
59672
|
+
} catch {
|
|
59673
|
+
return null;
|
|
59674
|
+
}
|
|
59675
|
+
if (!paths || paths.length === 0)
|
|
59676
|
+
return null;
|
|
59677
|
+
return paths.map((p) => ({
|
|
59678
|
+
treePath: p.treePath,
|
|
59679
|
+
blockName: blockNameFromTreePath(p.treePath),
|
|
59680
|
+
component: p.component,
|
|
59681
|
+
parent: parentTreePath(p.treePath)
|
|
59682
|
+
})).filter((b) => b.blockName.length > 0 && !b.blockName.startsWith("$"));
|
|
59683
|
+
}
|
|
59684
|
+
|
|
59685
|
+
// src/migrate/interactions.ts
|
|
59686
|
+
var MAX_INTERACTIONS = 40;
|
|
59687
|
+
function classifyE2eKey(hint, kind) {
|
|
59688
|
+
const h = hint.toLowerCase();
|
|
59689
|
+
const has2 = (...words) => words.some((w) => h.includes(w));
|
|
59690
|
+
if (has2("add to cart", "add-to-cart", "adicionar", "comprar", "buy"))
|
|
59691
|
+
return "buyButton";
|
|
59692
|
+
if (has2("checkout", "finalizar compra", "fechar pedido"))
|
|
59693
|
+
return "checkoutButton";
|
|
59694
|
+
if (kind === "input" && has2("search", "buscar", "pesquis", "q="))
|
|
59695
|
+
return "searchInput";
|
|
59696
|
+
if (has2("search", "buscar", "pesquis"))
|
|
59697
|
+
return "searchTrigger";
|
|
59698
|
+
if (has2("minicart", "mini-cart", "cart", "carrinho", "sacola", "bag", "basket"))
|
|
59699
|
+
return "minicartTrigger";
|
|
59700
|
+
if (kind === "input" && has2("email", "e-mail"))
|
|
59701
|
+
return "loginEmailInput";
|
|
59702
|
+
if (kind === "input" && has2("password", "senha"))
|
|
59703
|
+
return "loginPasswordInput";
|
|
59704
|
+
if (has2("login", "sign in", "entrar", "minha conta", "my account"))
|
|
59705
|
+
return "loginTrigger";
|
|
59706
|
+
if (has2("load more", "ver mais", "carregar mais", "show more"))
|
|
59707
|
+
return "loadMoreButton";
|
|
59708
|
+
if (has2("next", "próxima", "proxima", "próximo"))
|
|
59709
|
+
return "paginationNext";
|
|
59710
|
+
if (has2("increment", "increase", "aumentar", "qty-plus", "plus"))
|
|
59711
|
+
return "quantityIncrement";
|
|
59712
|
+
if (has2("remove", "remover", "excluir", "delete"))
|
|
59713
|
+
return "cartRemoveItem";
|
|
59714
|
+
if (has2("coupon", "cupom", "promo code"))
|
|
59715
|
+
return "cartCouponInput";
|
|
59716
|
+
return null;
|
|
59717
|
+
}
|
|
59718
|
+
async function captureInteractions(page, selector) {
|
|
59719
|
+
let raw;
|
|
59720
|
+
try {
|
|
59721
|
+
raw = await page.evaluate(({ sel, cap }) => {
|
|
59722
|
+
const root2 = document.querySelector(sel);
|
|
59723
|
+
if (!root2)
|
|
59724
|
+
return [];
|
|
59725
|
+
const hoverBases = [];
|
|
59726
|
+
const focusBases = [];
|
|
59727
|
+
const splitBases = (selectorText, pseudo, out) => {
|
|
59728
|
+
for (const part of selectorText.split(",")) {
|
|
59729
|
+
if (part.includes(pseudo)) {
|
|
59730
|
+
const base = part.split(pseudo)[0]?.trim();
|
|
59731
|
+
if (base)
|
|
59732
|
+
out.push(base);
|
|
59733
|
+
}
|
|
59734
|
+
}
|
|
59735
|
+
};
|
|
59736
|
+
for (const sheet of Array.from(document.styleSheets)) {
|
|
59737
|
+
let rules;
|
|
59738
|
+
try {
|
|
59739
|
+
rules = sheet.cssRules;
|
|
59740
|
+
} catch {
|
|
59741
|
+
continue;
|
|
59742
|
+
}
|
|
59743
|
+
for (const rule of Array.from(rules)) {
|
|
59744
|
+
const text3 = rule.selectorText;
|
|
59745
|
+
if (!text3)
|
|
59746
|
+
continue;
|
|
59747
|
+
if (text3.includes(":hover"))
|
|
59748
|
+
splitBases(text3, ":hover", hoverBases);
|
|
59749
|
+
if (text3.includes(":focus"))
|
|
59750
|
+
splitBases(text3, ":focus", focusBases);
|
|
59751
|
+
}
|
|
59752
|
+
}
|
|
59753
|
+
const matchesAny = (el, bases) => bases.some((b) => {
|
|
59754
|
+
try {
|
|
59755
|
+
return el.matches(b);
|
|
59756
|
+
} catch {
|
|
59757
|
+
return false;
|
|
59758
|
+
}
|
|
59759
|
+
});
|
|
59760
|
+
const cssEscape = (s) => window.CSS?.escape ? window.CSS.escape(s) : s.replace(/[^a-zA-Z0-9_-]/g, "\\$&");
|
|
59761
|
+
const suggestSelector = (el) => {
|
|
59762
|
+
const tag = el.tagName.toLowerCase();
|
|
59763
|
+
if (el.id)
|
|
59764
|
+
return `#${cssEscape(el.id)}`;
|
|
59765
|
+
const testid = el.getAttribute("data-testid");
|
|
59766
|
+
if (testid)
|
|
59767
|
+
return `[data-testid="${testid}"]`;
|
|
59768
|
+
for (const attr2 of Array.from(el.attributes)) {
|
|
59769
|
+
if (attr2.name.startsWith("data-") && attr2.value) {
|
|
59770
|
+
return `${tag}[${attr2.name}="${attr2.value}"]`;
|
|
59771
|
+
}
|
|
59772
|
+
}
|
|
59773
|
+
const aria = el.getAttribute("aria-label");
|
|
59774
|
+
if (aria)
|
|
59775
|
+
return `${tag}[aria-label="${aria}"]`;
|
|
59776
|
+
const semantic = Array.from(el.classList).find((c) => !/[:[\]/]/.test(c) && !/\d/.test(c) && c.length > 2);
|
|
59777
|
+
return semantic ? `${tag}.${cssEscape(semantic)}` : tag;
|
|
59778
|
+
};
|
|
59779
|
+
const nodes = Array.from(root2.querySelectorAll("a, button, input, select, [role='button'], [onclick]")).slice(0, cap);
|
|
59780
|
+
return nodes.map((el) => {
|
|
59781
|
+
const tag = el.tagName.toLowerCase();
|
|
59782
|
+
const role = el.getAttribute("role");
|
|
59783
|
+
const kind = tag === "input" ? "input" : tag === "select" ? "select" : tag === "a" ? "link" : tag === "button" || role === "button" ? "button" : "clickable";
|
|
59784
|
+
const cs = getComputedStyle(el);
|
|
59785
|
+
const transition = cs.transitionProperty && cs.transitionProperty !== "all" && cs.transitionProperty !== "none" ? `transition: ${cs.transitionProperty} ${cs.transitionDuration}` : cs.animationName && cs.animationName !== "none" ? `animation: ${cs.animationName} ${cs.animationDuration}` : null;
|
|
59786
|
+
const label = (el.getAttribute("aria-label") || (el.textContent ?? "").trim()).replace(/\s+/g, " ").slice(0, 80);
|
|
59787
|
+
const hint = [
|
|
59788
|
+
label,
|
|
59789
|
+
el.getAttribute("aria-label") ?? "",
|
|
59790
|
+
el.getAttribute("name") ?? "",
|
|
59791
|
+
el.getAttribute("placeholder") ?? "",
|
|
59792
|
+
el.getAttribute("type") ?? "",
|
|
59793
|
+
el.getAttribute("href") ?? "",
|
|
59794
|
+
el.className && typeof el.className === "string" ? el.className : ""
|
|
59795
|
+
].join(" ").toLowerCase();
|
|
59796
|
+
return {
|
|
59797
|
+
selector: suggestSelector(el),
|
|
59798
|
+
kind,
|
|
59799
|
+
label,
|
|
59800
|
+
animation: transition,
|
|
59801
|
+
hasHoverRule: matchesAny(el, hoverBases),
|
|
59802
|
+
hasFocusRule: matchesAny(el, focusBases),
|
|
59803
|
+
hint
|
|
59804
|
+
};
|
|
59805
|
+
});
|
|
59806
|
+
}, { sel: selector, cap: MAX_INTERACTIONS });
|
|
59807
|
+
} catch {
|
|
59808
|
+
return [];
|
|
59809
|
+
}
|
|
59810
|
+
return raw.map((r) => ({
|
|
59811
|
+
selector: r.selector,
|
|
59812
|
+
kind: r.kind,
|
|
59813
|
+
label: r.label,
|
|
59814
|
+
e2eKey: classifyE2eKey(r.hint, r.kind),
|
|
59815
|
+
animation: r.animation,
|
|
59816
|
+
hasHoverRule: r.hasHoverRule,
|
|
59817
|
+
hasFocusRule: r.hasFocusRule
|
|
59818
|
+
}));
|
|
59819
|
+
}
|
|
59820
|
+
|
|
59821
|
+
// src/commands/migrate.ts
|
|
59822
|
+
async function migrateCommand(opts) {
|
|
59823
|
+
const viewport = parseViewport3(opts.viewport);
|
|
59824
|
+
if (!viewport) {
|
|
59825
|
+
console.error(chalk16.red(`viewport inválido: ${opts.viewport} (use mobile|desktop|tablet)`));
|
|
59826
|
+
return 2;
|
|
59827
|
+
}
|
|
59828
|
+
const viewports = (opts.viewports ? opts.viewports.split(",") : [opts.viewport]).map((v) => parseViewport3(v.trim())).filter((v) => Boolean(v));
|
|
59829
|
+
if (viewports.length === 0) {
|
|
59830
|
+
console.error(chalk16.red(`--viewports inválido: ${opts.viewports}`));
|
|
59831
|
+
return 2;
|
|
59832
|
+
}
|
|
59833
|
+
const primaryViewport = viewports[0];
|
|
59834
|
+
if (!isValidUrl4(opts.url)) {
|
|
59835
|
+
console.error(chalk16.red(`--url inválido: ${opts.url}`));
|
|
59836
|
+
return 2;
|
|
59837
|
+
}
|
|
59838
|
+
const format = normalizeFormat2(opts.format);
|
|
59839
|
+
if (!format) {
|
|
59840
|
+
console.error(chalk16.red(`--format inválido: ${opts.format} (use md|json|both)`));
|
|
59841
|
+
return 2;
|
|
59842
|
+
}
|
|
59843
|
+
let playbook;
|
|
59844
|
+
if (opts.target) {
|
|
59845
|
+
playbook = getTargetPlaybook(opts.target);
|
|
59846
|
+
if (!playbook) {
|
|
59847
|
+
console.error(chalk16.red(`--target inválido: ${opts.target} (disponíveis: ${TARGET_NAMES.join(", ")})`));
|
|
59848
|
+
return 2;
|
|
59849
|
+
}
|
|
59850
|
+
}
|
|
59851
|
+
const allowlist = parseAllowlist2(opts.components);
|
|
59852
|
+
const host = safeHost5(opts.url);
|
|
59853
|
+
const runDir = resolve3(opts.outDir, host);
|
|
59854
|
+
mkdirSync14(runDir, { recursive: true });
|
|
59855
|
+
const browser = await launchBrowser({ headless: true });
|
|
59856
|
+
try {
|
|
59857
|
+
const themePath = resolve3(runDir, "theme.json");
|
|
59858
|
+
const assetsPath = resolve3(runDir, "assets.json");
|
|
59859
|
+
const blocksPath = resolve3(runDir, "blocks.json");
|
|
59860
|
+
let theme;
|
|
59861
|
+
let platform;
|
|
59862
|
+
let assets;
|
|
59863
|
+
let screenshots;
|
|
59864
|
+
let vtexBlocks = null;
|
|
59865
|
+
if (!opts.refresh && existsSync11(themePath) && existsSync11(assetsPath)) {
|
|
59866
|
+
theme = readJson(themePath);
|
|
59867
|
+
const meta = readJson(assetsPath);
|
|
59868
|
+
platform = meta.platform;
|
|
59869
|
+
assets = meta.assets;
|
|
59870
|
+
screenshots = meta.screenshots ?? [];
|
|
59871
|
+
if (existsSync11(blocksPath))
|
|
59872
|
+
vtexBlocks = readJson(blocksPath);
|
|
59873
|
+
console.log(chalk16.dim(" phase 1 theme+assets: cached"));
|
|
59874
|
+
} else {
|
|
59875
|
+
console.log(chalk16.dim(` phase 1 theme+assets: scraping (${viewports.join(", ")})…`));
|
|
59876
|
+
mkdirSync14(resolve3(runDir, "screenshots"), { recursive: true });
|
|
59877
|
+
const samples = [];
|
|
59878
|
+
screenshots = [];
|
|
59879
|
+
let platformSeen = null;
|
|
59880
|
+
let assetsResolved = null;
|
|
59881
|
+
for (const vp of viewports) {
|
|
59882
|
+
const ctx = await newContext(browser, { viewport: vp });
|
|
59883
|
+
const page = await ctx.newPage();
|
|
59884
|
+
try {
|
|
59885
|
+
await page.goto(opts.url, { waitUntil: "domcontentloaded", timeout: 30000 });
|
|
59886
|
+
await page.waitForLoadState("networkidle", { timeout: 8000 }).catch(() => {
|
|
59887
|
+
return;
|
|
59888
|
+
});
|
|
59889
|
+
samples.push(await scrapeThemeSamples(page));
|
|
59890
|
+
const shot = resolve3(runDir, "screenshots", `${vp}.png`);
|
|
59891
|
+
await page.screenshot({ path: shot, fullPage: true, animations: "disabled", timeout: 15000 }).then(() => screenshots.push({ viewport: vp, path: `screenshots/${vp}.png` })).catch(() => {
|
|
59892
|
+
return;
|
|
59893
|
+
});
|
|
59894
|
+
if (!assetsResolved) {
|
|
59895
|
+
platformSeen = detectPlatform({ url: opts.url, html: await page.content().catch(() => "") });
|
|
59896
|
+
const rawAssets = await collectSiteAssets(page);
|
|
59897
|
+
const fetchBytes = async (url) => await browserFetchBytes(page, url) ?? await nodeFetchBytes(url);
|
|
59898
|
+
assetsResolved = await downloadSiteAssets(rawAssets, runDir, fetchBytes);
|
|
59899
|
+
vtexBlocks = await readVtexBlockTree(page);
|
|
59900
|
+
}
|
|
59901
|
+
} finally {
|
|
59902
|
+
await page.close().catch(() => {
|
|
59903
|
+
return;
|
|
59904
|
+
});
|
|
59905
|
+
await ctx.close().catch(() => {
|
|
59906
|
+
return;
|
|
59907
|
+
});
|
|
59908
|
+
}
|
|
59909
|
+
}
|
|
59910
|
+
theme = aggregateTheme(mergeRawThemeSamples(samples));
|
|
59911
|
+
platform = platformSeen ?? "custom";
|
|
59912
|
+
assets = assetsResolved;
|
|
59913
|
+
writeFileSync19(themePath, `${JSON.stringify(theme, null, 2)}
|
|
59914
|
+
`, "utf8");
|
|
59915
|
+
writeFileSync19(assetsPath, `${JSON.stringify({ platform, assets, screenshots }, null, 2)}
|
|
59916
|
+
`, "utf8");
|
|
59917
|
+
if (vtexBlocks) {
|
|
59918
|
+
writeFileSync19(blocksPath, `${JSON.stringify(vtexBlocks, null, 2)}
|
|
59919
|
+
`, "utf8");
|
|
59920
|
+
console.log(chalk16.dim(` vtex io: ${vtexBlocks.length} blocks read from runtime`));
|
|
59921
|
+
}
|
|
59922
|
+
}
|
|
59923
|
+
const sitemapPath = resolve3(runDir, "sitemap.json");
|
|
59924
|
+
let resolvedPages;
|
|
59925
|
+
if (!opts.refresh && existsSync11(sitemapPath)) {
|
|
59926
|
+
resolvedPages = readJson(sitemapPath).pages;
|
|
59927
|
+
console.log(chalk16.dim(` phase 2 sitemap: cached (${resolvedPages.length} page(s))`));
|
|
59928
|
+
} else {
|
|
59929
|
+
console.log(chalk16.dim(" phase 2 sitemap: resolving pages…"));
|
|
59930
|
+
const ctx = await newContext(browser, { viewport: primaryViewport });
|
|
59931
|
+
const page = await ctx.newPage();
|
|
59932
|
+
let sitemapUrls = [];
|
|
59933
|
+
try {
|
|
59934
|
+
await page.goto(opts.url, { waitUntil: "domcontentloaded", timeout: 30000 });
|
|
59935
|
+
await page.waitForLoadState("networkidle", { timeout: 8000 }).catch(() => {
|
|
59936
|
+
return;
|
|
59937
|
+
});
|
|
59938
|
+
const homeHtml = await page.content().catch(() => "");
|
|
59939
|
+
resolvedPages = await resolvePages2(page, opts.url, opts.pages, homeHtml, platform);
|
|
59940
|
+
sitemapUrls = await discoverSitemapUrls(page, opts.url);
|
|
59941
|
+
} finally {
|
|
59942
|
+
await page.close().catch(() => {
|
|
59943
|
+
return;
|
|
59944
|
+
});
|
|
59945
|
+
await ctx.close().catch(() => {
|
|
59946
|
+
return;
|
|
59947
|
+
});
|
|
59948
|
+
}
|
|
59949
|
+
const classified = sitemapUrls.slice(0, 500).map((u) => ({ url: u, kind: kindOf(u) }));
|
|
59950
|
+
writeFileSync19(sitemapPath, `${JSON.stringify({ pages: resolvedPages, sitemapUrls: classified }, null, 2)}
|
|
59951
|
+
`, "utf8");
|
|
59952
|
+
}
|
|
59953
|
+
if (resolvedPages.length === 0) {
|
|
59954
|
+
console.error(chalk16.red("nenhuma página resolvida a partir de --pages"));
|
|
59955
|
+
return 1;
|
|
59956
|
+
}
|
|
59957
|
+
const capturePath = resolve3(runDir, "capture.json");
|
|
59958
|
+
let pages;
|
|
59959
|
+
let components;
|
|
59960
|
+
if (!opts.refresh && existsSync11(capturePath)) {
|
|
59961
|
+
const cached = readJson(capturePath);
|
|
59962
|
+
pages = cached.pages;
|
|
59963
|
+
components = cached.components;
|
|
59964
|
+
console.log(chalk16.dim(` phase 3 components: cached (${components.length})`));
|
|
59965
|
+
} else {
|
|
59966
|
+
console.log(chalk16.dim(" phase 3 components: capturing…"));
|
|
59967
|
+
({ pages, components } = await capturePages(browser, primaryViewport, resolvedPages, theme, {
|
|
59968
|
+
allowlist,
|
|
59969
|
+
llm: !opts.noLlm,
|
|
59970
|
+
runDir
|
|
59971
|
+
}));
|
|
59972
|
+
writeFileSync19(capturePath, `${JSON.stringify({ pages, components }, null, 2)}
|
|
59973
|
+
`, "utf8");
|
|
59974
|
+
}
|
|
59975
|
+
const bundle = {
|
|
59976
|
+
url: opts.url,
|
|
59977
|
+
timestamp: new Date().toISOString(),
|
|
59978
|
+
viewport: primaryViewport,
|
|
59979
|
+
viewports,
|
|
59980
|
+
screenshots,
|
|
59981
|
+
platform,
|
|
59982
|
+
target: opts.target,
|
|
59983
|
+
theme,
|
|
59984
|
+
assets,
|
|
59985
|
+
vtex: vtexBlocks ? { blocks: vtexBlocks, map: mapVtexBlocksToFastStore(vtexBlocks) } : undefined,
|
|
59986
|
+
pages,
|
|
59987
|
+
components
|
|
59988
|
+
};
|
|
59989
|
+
if (format === "json" || format === "both")
|
|
59990
|
+
await jsonExporter2.export(bundle, runDir);
|
|
59991
|
+
if (format === "md" || format === "both") {
|
|
59992
|
+
await markdownExporter2.export(bundle, runDir);
|
|
59993
|
+
writeFileSync19(resolve3(runDir, "MIGRATION_PROMPT.md"), buildMigrationPrompt(bundle, playbook), "utf8");
|
|
59994
|
+
}
|
|
59995
|
+
if (opts.target === "faststore") {
|
|
59996
|
+
writeFileSync19(resolve3(runDir, "custom-theme.scss"), buildFastStoreTheme(theme), "utf8");
|
|
59997
|
+
}
|
|
59998
|
+
if (bundle.vtex) {
|
|
59999
|
+
writeFileSync19(resolve3(runDir, "component-map.json"), `${JSON.stringify(bundle.vtex.map, null, 2)}
|
|
60000
|
+
`, "utf8");
|
|
60001
|
+
}
|
|
60002
|
+
if (opts.json) {
|
|
60003
|
+
console.log(JSON.stringify({ outDir: runDir, componentCount: components.length, bundle }));
|
|
60004
|
+
return 0;
|
|
60005
|
+
}
|
|
60006
|
+
printResults4(runDir, bundle);
|
|
60007
|
+
return 0;
|
|
60008
|
+
} finally {
|
|
60009
|
+
await browser.close().catch(() => {
|
|
60010
|
+
return;
|
|
60011
|
+
});
|
|
60012
|
+
}
|
|
60013
|
+
}
|
|
60014
|
+
async function capturePages(browser, viewport, resolvedPages, theme, cfg) {
|
|
60015
|
+
const pages = [];
|
|
60016
|
+
const components = [];
|
|
60017
|
+
const seenGlobalRoles = new Set;
|
|
60018
|
+
for (const target of resolvedPages) {
|
|
60019
|
+
const ctx = await newContext(browser, { viewport });
|
|
60020
|
+
const page = await ctx.newPage();
|
|
60021
|
+
const pageComponents = [];
|
|
60022
|
+
try {
|
|
60023
|
+
await page.goto(target.url, { waitUntil: "domcontentloaded", timeout: 30000 });
|
|
60024
|
+
await page.waitForLoadState("networkidle", { timeout: 8000 }).catch(() => {
|
|
60025
|
+
return;
|
|
60026
|
+
});
|
|
60027
|
+
await Promise.race([stabilizeCarousels(page).catch(() => {
|
|
60028
|
+
return;
|
|
60029
|
+
}), sleep2(3000)]);
|
|
60030
|
+
await Promise.race([scrollFullPage(page, 30000).catch(() => {
|
|
60031
|
+
return;
|
|
60032
|
+
}), sleep2(32000)]);
|
|
60033
|
+
await Promise.race([
|
|
60034
|
+
waitForSkeletonsToResolve(page, 5000).catch(() => {
|
|
60035
|
+
return;
|
|
60036
|
+
}),
|
|
60037
|
+
sleep2(5000)
|
|
60038
|
+
]);
|
|
60039
|
+
let detected = await detectComponents(page, { llm: cfg.llm });
|
|
60040
|
+
if (cfg.allowlist)
|
|
60041
|
+
detected = detected.filter((c) => matchesAllowlist2(c.role, cfg.allowlist));
|
|
60042
|
+
const signatures = await structuralSignatures(page, detected.map((d) => d.selector));
|
|
60043
|
+
const plan = planComponentDedup(detected.map((d, i) => ({ role: d.role, signature: signatures[i] ?? "" })));
|
|
60044
|
+
const pageScreenshot = await page.screenshot({ fullPage: true, animations: "disabled", timeout: 15000 }).catch(() => {
|
|
60045
|
+
return;
|
|
60046
|
+
});
|
|
60047
|
+
for (const { index: index2, repeated } of plan) {
|
|
60048
|
+
const component = detected[index2];
|
|
60049
|
+
const global = isGlobalRole(component.role);
|
|
60050
|
+
if (global && seenGlobalRoles.has(component.role))
|
|
60051
|
+
continue;
|
|
60052
|
+
if (global)
|
|
60053
|
+
seenGlobalRoles.add(component.role);
|
|
60054
|
+
const idx = components.length + 1;
|
|
60055
|
+
const componentDir = resolve3(cfg.runDir, "components", componentDirName(component.role, idx));
|
|
60056
|
+
const extracted = await extractComponent(page, component, {
|
|
60057
|
+
outDir: componentDir,
|
|
60058
|
+
index: idx,
|
|
60059
|
+
pageScreenshot
|
|
60060
|
+
});
|
|
60061
|
+
const interactions = await captureInteractions(page, component.selector);
|
|
60062
|
+
const migrated = toMigratedComponent(extracted, interactions, global ? "global" : "page", theme.tokens, repeated);
|
|
60063
|
+
components.push(migrated);
|
|
60064
|
+
if (!global)
|
|
60065
|
+
pageComponents.push(migrated);
|
|
60066
|
+
}
|
|
60067
|
+
pages.push({ url: target.url, path: target.path, kind: target.kind, components: pageComponents });
|
|
60068
|
+
} finally {
|
|
60069
|
+
await page.close().catch(() => {
|
|
60070
|
+
return;
|
|
60071
|
+
});
|
|
60072
|
+
await ctx.close().catch(() => {
|
|
60073
|
+
return;
|
|
60074
|
+
});
|
|
60075
|
+
}
|
|
60076
|
+
}
|
|
60077
|
+
return { pages, components };
|
|
60078
|
+
}
|
|
60079
|
+
async function resolvePages2(page, baseUrl, pagesSpec, homeHtml, platform) {
|
|
60080
|
+
const tokens = (pagesSpec ?? "/,category-auto,pdp-auto").split(",").map((s) => s.trim()).filter(Boolean);
|
|
60081
|
+
const out = [];
|
|
60082
|
+
const plp = pickPlpFromHomeHtml(homeHtml, baseUrl);
|
|
60083
|
+
for (const token of tokens) {
|
|
60084
|
+
if (token === "category-auto") {
|
|
60085
|
+
if (plp)
|
|
60086
|
+
out.push({ path: token, url: plp, kind: "plp" });
|
|
60087
|
+
else
|
|
60088
|
+
console.warn(chalk16.yellow(" ⚠ category-auto: nenhuma PLP descoberta na home"));
|
|
60089
|
+
continue;
|
|
60090
|
+
}
|
|
60091
|
+
if (token === "pdp-auto") {
|
|
60092
|
+
if (!plp) {
|
|
60093
|
+
console.warn(chalk16.yellow(" ⚠ pdp-auto: sem PLP pra derivar PDP"));
|
|
60094
|
+
continue;
|
|
60095
|
+
}
|
|
60096
|
+
let html3 = null;
|
|
60097
|
+
try {
|
|
60098
|
+
await page.goto(plp, { waitUntil: "domcontentloaded", timeout: 30000 });
|
|
60099
|
+
await page.waitForLoadState("networkidle", { timeout: 8000 }).catch(() => {
|
|
60100
|
+
return;
|
|
60101
|
+
});
|
|
60102
|
+
html3 = await page.content();
|
|
60103
|
+
} catch {
|
|
60104
|
+
html3 = await browserFetchText(page, plp);
|
|
60105
|
+
}
|
|
60106
|
+
const pdp = html3 ? firstProductHref(html3, plp, platform) : null;
|
|
60107
|
+
if (pdp)
|
|
60108
|
+
out.push({ path: token, url: pdp, kind: "pdp" });
|
|
60109
|
+
else
|
|
60110
|
+
console.warn(chalk16.yellow(" ⚠ pdp-auto: nenhum produto encontrado na PLP"));
|
|
60111
|
+
continue;
|
|
60112
|
+
}
|
|
60113
|
+
try {
|
|
60114
|
+
const url = new URL(token, baseUrl).toString();
|
|
60115
|
+
out.push({ path: token, url, kind: kindOf(url) });
|
|
60116
|
+
} catch {}
|
|
60117
|
+
}
|
|
60118
|
+
return out;
|
|
60119
|
+
}
|
|
60120
|
+
async function discoverSitemapUrls(page, baseUrl) {
|
|
60121
|
+
try {
|
|
60122
|
+
const origin = new URL(baseUrl).origin;
|
|
60123
|
+
const rootXml = await browserFetchText(page, `${origin}/sitemap.xml`);
|
|
60124
|
+
if (!rootXml)
|
|
60125
|
+
return [];
|
|
60126
|
+
const root2 = parseSitemap(rootXml);
|
|
60127
|
+
if (!root2.isIndex)
|
|
60128
|
+
return root2.urls;
|
|
60129
|
+
const urls = [];
|
|
60130
|
+
for (const child of root2.childSitemaps.slice(0, 5)) {
|
|
60131
|
+
const xml2 = await browserFetchText(page, child);
|
|
60132
|
+
if (xml2)
|
|
60133
|
+
urls.push(...parseSitemap(xml2).urls);
|
|
60134
|
+
if (urls.length >= 500)
|
|
60135
|
+
break;
|
|
60136
|
+
}
|
|
60137
|
+
return urls;
|
|
60138
|
+
} catch {
|
|
60139
|
+
return [];
|
|
60140
|
+
}
|
|
60141
|
+
}
|
|
60142
|
+
async function structuralSignatures(page, selectors) {
|
|
60143
|
+
try {
|
|
60144
|
+
return await page.evaluate((sels) => {
|
|
60145
|
+
return sels.map((s) => {
|
|
60146
|
+
let el = null;
|
|
60147
|
+
try {
|
|
60148
|
+
el = document.querySelector(s);
|
|
60149
|
+
} catch {
|
|
60150
|
+
return "";
|
|
60151
|
+
}
|
|
60152
|
+
if (!el)
|
|
60153
|
+
return "";
|
|
60154
|
+
const cls = Array.from(el.classList).filter((c) => !/\d/.test(c)).sort().join(".");
|
|
60155
|
+
return `${el.tagName}|${cls}|${el.children.length}`;
|
|
60156
|
+
});
|
|
60157
|
+
}, selectors);
|
|
60158
|
+
} catch {
|
|
60159
|
+
return selectors.map(() => "");
|
|
60160
|
+
}
|
|
60161
|
+
}
|
|
60162
|
+
function kindOf(url) {
|
|
60163
|
+
try {
|
|
60164
|
+
return classifyPath2(new URL(url).pathname);
|
|
60165
|
+
} catch {
|
|
60166
|
+
return "other";
|
|
60167
|
+
}
|
|
60168
|
+
}
|
|
60169
|
+
function printResults4(runDir, bundle) {
|
|
60170
|
+
console.log(chalk16.bold(`
|
|
60171
|
+
parity migrate`));
|
|
60172
|
+
console.log(chalk16.dim(` url: ${bundle.url}`));
|
|
60173
|
+
console.log(chalk16.dim(` platform: ${bundle.platform}${bundle.target ? ` → ${bundle.target}` : ""}`));
|
|
60174
|
+
console.log(chalk16.dim(` viewports:${(bundle.viewports ?? [bundle.viewport]).join(", ")}`));
|
|
60175
|
+
console.log(chalk16.dim(` theme: primary=${bundle.theme.colors.primary ?? "—"} text=${bundle.theme.colors.text ?? "—"}`));
|
|
60176
|
+
console.log(chalk16.dim(` assets: logo=${bundle.assets.logo ? "✓" : "✗"} favicon=${bundle.assets.favicon ? "✓" : "✗"} icons=${bundle.assets.icons.length}`));
|
|
60177
|
+
if (bundle.vtex) {
|
|
60178
|
+
const mapped = bundle.vtex.map.filter((m) => m.strategy === "mapped").length;
|
|
60179
|
+
console.log(chalk16.dim(` vtex io: ${bundle.vtex.blocks.length} blocks · ${mapped}/${bundle.vtex.map.length} block types mapped to FastStore`));
|
|
60180
|
+
}
|
|
60181
|
+
console.log(chalk16.dim(` pages: ${bundle.pages.map((p) => p.kind).join(", ") || "—"}`));
|
|
60182
|
+
console.log(chalk16.dim(` out: ${runDir}`));
|
|
60183
|
+
console.log("");
|
|
60184
|
+
console.log(chalk16.bold(` ${bundle.components.length} component(s):`));
|
|
60185
|
+
for (const c of bundle.components) {
|
|
60186
|
+
console.log(` ${chalk16.cyan(`${c.scope}/${c.role}`.padEnd(28))} ${chalk16.dim(`${c.tailwind.length} tw · ${c.interactions.length} interactions`)}`);
|
|
60187
|
+
}
|
|
60188
|
+
console.log("");
|
|
60189
|
+
}
|
|
60190
|
+
function readJson(path) {
|
|
60191
|
+
try {
|
|
60192
|
+
return JSON.parse(readFileSync13(path, "utf8"));
|
|
60193
|
+
} catch {
|
|
60194
|
+
return null;
|
|
60195
|
+
}
|
|
60196
|
+
}
|
|
60197
|
+
function parseAllowlist2(spec) {
|
|
60198
|
+
if (!spec || spec.trim().length === 0)
|
|
60199
|
+
return null;
|
|
60200
|
+
const set = new Set(spec.split(",").map((s) => s.trim().toLowerCase()).filter(Boolean));
|
|
60201
|
+
return set.size > 0 ? set : null;
|
|
60202
|
+
}
|
|
60203
|
+
function matchesAllowlist2(role, allowlist) {
|
|
60204
|
+
const lower = role.toLowerCase();
|
|
60205
|
+
if (allowlist.has(lower))
|
|
60206
|
+
return true;
|
|
60207
|
+
for (const name of allowlist) {
|
|
60208
|
+
if (lower.startsWith(`${name}-`))
|
|
60209
|
+
return true;
|
|
60210
|
+
}
|
|
60211
|
+
return false;
|
|
60212
|
+
}
|
|
60213
|
+
function normalizeFormat2(raw) {
|
|
60214
|
+
if (raw === "md" || raw === "json" || raw === "both")
|
|
60215
|
+
return raw;
|
|
60216
|
+
return null;
|
|
60217
|
+
}
|
|
60218
|
+
function safeHost5(url) {
|
|
60219
|
+
try {
|
|
60220
|
+
return new URL(url).host || "site";
|
|
60221
|
+
} catch {
|
|
60222
|
+
return "site";
|
|
60223
|
+
}
|
|
60224
|
+
}
|
|
60225
|
+
function isValidUrl4(s) {
|
|
60226
|
+
try {
|
|
60227
|
+
new URL(s);
|
|
60228
|
+
return true;
|
|
60229
|
+
} catch {
|
|
60230
|
+
return false;
|
|
60231
|
+
}
|
|
60232
|
+
}
|
|
60233
|
+
function sleep2(ms) {
|
|
60234
|
+
return new Promise((resolveTimeout) => setTimeout(resolveTimeout, ms));
|
|
60235
|
+
}
|
|
60236
|
+
|
|
60237
|
+
// src/commands/pr.ts
|
|
60238
|
+
import { existsSync as existsSync15, readFileSync as readFileSync16, writeFileSync as writeFileSync20 } from "node:fs";
|
|
60239
|
+
import { join as join22 } from "node:path";
|
|
60240
|
+
import chalk19 from "chalk";
|
|
60241
|
+
|
|
60242
|
+
// src/commands/run.ts
|
|
60243
|
+
import { existsSync as existsSync14, readFileSync as readFileSync15, unlinkSync as unlinkSync3 } from "node:fs";
|
|
60244
|
+
import { join as join21 } from "node:path";
|
|
60245
|
+
import chalk18 from "chalk";
|
|
60246
|
+
import ora6 from "ora";
|
|
60247
|
+
|
|
60248
|
+
// src/engine/interactive-module-prompt.ts
|
|
60249
|
+
import { createInterface } from "node:readline";
|
|
60250
|
+
var ALL_MODULE_NAMES2 = Object.keys(MODULES);
|
|
60251
|
+
async function promptForModuleSelection() {
|
|
60252
|
+
console.log("");
|
|
60253
|
+
console.log(" Select modules to run (all checked by default):");
|
|
60254
|
+
console.log("");
|
|
60255
|
+
ALL_MODULE_NAMES2.forEach((name, i) => {
|
|
60256
|
+
const def = MODULES[name];
|
|
60257
|
+
console.log(` [x] ${i + 1}. ${name.padEnd(8)} — ${def.description}`);
|
|
60258
|
+
});
|
|
60259
|
+
console.log("");
|
|
60260
|
+
const answer = await readLine(" Type numbers to UNCHECK (comma-separated), or press Enter to run all: ");
|
|
60261
|
+
if (answer === null) {
|
|
60262
|
+
console.log(" (aborted — running all modules)");
|
|
60263
|
+
return ALL_MODULE_NAMES2;
|
|
60264
|
+
}
|
|
60265
|
+
const trimmed = answer.trim();
|
|
60266
|
+
if (!trimmed)
|
|
60267
|
+
return ALL_MODULE_NAMES2;
|
|
60268
|
+
const uncheckIdx = new Set(trimmed.split(",").map((s) => Number.parseInt(s.trim(), 10)).filter((n) => Number.isInteger(n) && n >= 1 && n <= ALL_MODULE_NAMES2.length));
|
|
60269
|
+
const selected = ALL_MODULE_NAMES2.filter((_name, i) => !uncheckIdx.has(i + 1));
|
|
60270
|
+
if (selected.length === 0) {
|
|
60271
|
+
console.log(" (everything unchecked — running all modules instead)");
|
|
60272
|
+
return ALL_MODULE_NAMES2;
|
|
60273
|
+
}
|
|
60274
|
+
console.log(` running: ${selected.join(", ")}`);
|
|
60275
|
+
return selected;
|
|
60276
|
+
}
|
|
60277
|
+
function readLine(prompt) {
|
|
60278
|
+
return new Promise((resolveLine) => {
|
|
60279
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
60280
|
+
rl.question(prompt, (ans) => {
|
|
60281
|
+
rl.close();
|
|
60282
|
+
resolveLine(ans);
|
|
60283
|
+
});
|
|
60284
|
+
rl.on("SIGINT", () => {
|
|
60285
|
+
rl.close();
|
|
60286
|
+
resolveLine(null);
|
|
60287
|
+
});
|
|
60288
|
+
});
|
|
60289
|
+
}
|
|
60290
|
+
|
|
60291
|
+
// src/engine/interactive-selector-prompt.ts
|
|
60292
|
+
init_client();
|
|
60293
|
+
var forceDisabled = false;
|
|
60294
|
+
function disableInteractive() {
|
|
60295
|
+
forceDisabled = true;
|
|
60296
|
+
}
|
|
60297
|
+
function isInteractiveMode() {
|
|
60298
|
+
if (forceDisabled)
|
|
60299
|
+
return false;
|
|
60300
|
+
if (!process.stdout.isTTY || !process.stdin.isTTY)
|
|
60301
|
+
return false;
|
|
60302
|
+
if (isLlmAvailable())
|
|
60303
|
+
return false;
|
|
60304
|
+
return true;
|
|
60305
|
+
}
|
|
60306
|
+
|
|
58364
60307
|
// src/llm/aggregate-issues.ts
|
|
58365
60308
|
init_client();
|
|
58366
60309
|
var REPORT_ISSUES_TOOL = {
|
|
@@ -58774,13 +60717,13 @@ function formatMs(ms) {
|
|
|
58774
60717
|
}
|
|
58775
60718
|
|
|
58776
60719
|
// src/commands/serve.ts
|
|
58777
|
-
import { existsSync as
|
|
58778
|
-
import
|
|
60720
|
+
import { existsSync as existsSync13 } from "node:fs";
|
|
60721
|
+
import chalk17 from "chalk";
|
|
58779
60722
|
|
|
58780
60723
|
// src/server/proxy-server.ts
|
|
58781
|
-
import { existsSync as
|
|
60724
|
+
import { existsSync as existsSync12, readFileSync as readFileSync14, statSync } from "node:fs";
|
|
58782
60725
|
import { createServer } from "node:http";
|
|
58783
|
-
import { extname, join as
|
|
60726
|
+
import { extname, join as join20, normalize as normalize3, resolve as resolve4, sep } from "node:path";
|
|
58784
60727
|
var MIME = {
|
|
58785
60728
|
".html": "text/html; charset=utf-8",
|
|
58786
60729
|
".css": "text/css; charset=utf-8",
|
|
@@ -58816,8 +60759,8 @@ var STRIPPED_REQUEST_HEADERS = new Set([
|
|
|
58816
60759
|
"origin"
|
|
58817
60760
|
]);
|
|
58818
60761
|
async function startProxyServer(runDir, opts = {}) {
|
|
58819
|
-
const absRunDir =
|
|
58820
|
-
if (!
|
|
60762
|
+
const absRunDir = resolve4(runDir);
|
|
60763
|
+
if (!existsSync12(absRunDir)) {
|
|
58821
60764
|
throw new Error(`Run directory not found: ${runDir}`);
|
|
58822
60765
|
}
|
|
58823
60766
|
const server = createServer((req, res) => {
|
|
@@ -58828,9 +60771,9 @@ async function startProxyServer(runDir, opts = {}) {
|
|
|
58828
60771
|
} catch {}
|
|
58829
60772
|
});
|
|
58830
60773
|
});
|
|
58831
|
-
await new Promise((
|
|
60774
|
+
await new Promise((resolve5, reject) => {
|
|
58832
60775
|
server.once("error", reject);
|
|
58833
|
-
server.listen(opts.port ?? 0, opts.host ?? "127.0.0.1", () =>
|
|
60776
|
+
server.listen(opts.port ?? 0, opts.host ?? "127.0.0.1", () => resolve5());
|
|
58834
60777
|
});
|
|
58835
60778
|
const addr = server.address();
|
|
58836
60779
|
const port = typeof addr === "object" && addr ? addr.port : 0;
|
|
@@ -58838,13 +60781,13 @@ async function startProxyServer(runDir, opts = {}) {
|
|
|
58838
60781
|
return {
|
|
58839
60782
|
port,
|
|
58840
60783
|
url: `http://${host}:${port}/`,
|
|
58841
|
-
close: () => new Promise((
|
|
60784
|
+
close: () => new Promise((resolve5) => {
|
|
58842
60785
|
try {
|
|
58843
60786
|
server.closeAllConnections?.();
|
|
58844
60787
|
server.closeIdleConnections?.();
|
|
58845
60788
|
} catch {}
|
|
58846
|
-
server.close(() =>
|
|
58847
|
-
setTimeout(() =>
|
|
60789
|
+
server.close(() => resolve5());
|
|
60790
|
+
setTimeout(() => resolve5(), 1000);
|
|
58848
60791
|
})
|
|
58849
60792
|
};
|
|
58850
60793
|
}
|
|
@@ -58874,13 +60817,13 @@ async function handleRequest(req, res, runDir) {
|
|
|
58874
60817
|
return serveStatic(res, runDir, path);
|
|
58875
60818
|
}
|
|
58876
60819
|
function serveReportHtml(res, runDir) {
|
|
58877
|
-
const filePath =
|
|
58878
|
-
if (!
|
|
60820
|
+
const filePath = join20(runDir, "report.html");
|
|
60821
|
+
if (!existsSync12(filePath)) {
|
|
58879
60822
|
res.statusCode = 404;
|
|
58880
60823
|
res.end("report.html not found");
|
|
58881
60824
|
return;
|
|
58882
60825
|
}
|
|
58883
|
-
const html3 =
|
|
60826
|
+
const html3 = readFileSync14(filePath, "utf8");
|
|
58884
60827
|
const inject = `<script>window.__parity_proxy = "/proxy?url=";</script>`;
|
|
58885
60828
|
const out = html3.includes("</head>") ? html3.replace("</head>", `${inject}</head>`) : `${inject}${html3}`;
|
|
58886
60829
|
res.statusCode = 200;
|
|
@@ -58890,13 +60833,13 @@ function serveReportHtml(res, runDir) {
|
|
|
58890
60833
|
}
|
|
58891
60834
|
function serveStatic(res, runDir, path) {
|
|
58892
60835
|
const safePath2 = normalize3(path).replace(/^[/\\]+/, "");
|
|
58893
|
-
const filePath =
|
|
60836
|
+
const filePath = resolve4(runDir, safePath2);
|
|
58894
60837
|
if (!filePath.startsWith(runDir + sep) && filePath !== runDir) {
|
|
58895
60838
|
res.statusCode = 403;
|
|
58896
60839
|
res.end("forbidden");
|
|
58897
60840
|
return;
|
|
58898
60841
|
}
|
|
58899
|
-
if (!
|
|
60842
|
+
if (!existsSync12(filePath)) {
|
|
58900
60843
|
res.statusCode = 404;
|
|
58901
60844
|
res.end("not found");
|
|
58902
60845
|
return;
|
|
@@ -58911,7 +60854,7 @@ function serveStatic(res, runDir, path) {
|
|
|
58911
60854
|
res.statusCode = 200;
|
|
58912
60855
|
res.setHeader("content-type", MIME[ext] ?? "application/octet-stream");
|
|
58913
60856
|
res.setHeader("cache-control", "no-store");
|
|
58914
|
-
res.end(
|
|
60857
|
+
res.end(readFileSync14(filePath));
|
|
58915
60858
|
}
|
|
58916
60859
|
async function proxyRequest(req, res, targetUrl, opts = {}) {
|
|
58917
60860
|
let target;
|
|
@@ -59009,16 +60952,16 @@ async function serveRunAndBlock(runDir, opts = {}) {
|
|
|
59009
60952
|
try {
|
|
59010
60953
|
handle = await startProxyServer(runDir, { port: opts.port });
|
|
59011
60954
|
} catch (err) {
|
|
59012
|
-
console.error(
|
|
60955
|
+
console.error(chalk17.red(` ✖ Falha ao iniciar servidor: ${err.message}`));
|
|
59013
60956
|
return 2;
|
|
59014
60957
|
}
|
|
59015
60958
|
const label = opts.label ?? "parity serve";
|
|
59016
60959
|
console.log("");
|
|
59017
|
-
console.log(
|
|
59018
|
-
console.log(` ${
|
|
59019
|
-
console.log(
|
|
59020
|
-
console.log(
|
|
59021
|
-
console.log(
|
|
60960
|
+
console.log(chalk17.bold(` ${label}`));
|
|
60961
|
+
console.log(` ${chalk17.green("●")} ${handle.url}`);
|
|
60962
|
+
console.log(chalk17.dim(` Servindo: ${runDir}`));
|
|
60963
|
+
console.log(chalk17.dim(` Proxy de iframes: ${handle.url}proxy?url=<encoded>`));
|
|
60964
|
+
console.log(chalk17.dim(` Ctrl+C pra parar (2x pra forçar saída).
|
|
59022
60965
|
`));
|
|
59023
60966
|
if (opts.open !== false) {
|
|
59024
60967
|
const { default: open } = await import("open");
|
|
@@ -59050,12 +60993,12 @@ async function serveRunAndBlock(runDir, opts = {}) {
|
|
|
59050
60993
|
}
|
|
59051
60994
|
async function serveCommand(runId, opts) {
|
|
59052
60995
|
const paths = getRunPaths(opts.output, runId);
|
|
59053
|
-
if (!
|
|
59054
|
-
console.error(
|
|
60996
|
+
if (!existsSync13(paths.runDir)) {
|
|
60997
|
+
console.error(chalk17.red(`✖ Run não encontrado: ${runId} (em ${opts.output})`));
|
|
59055
60998
|
return 1;
|
|
59056
60999
|
}
|
|
59057
|
-
if (!
|
|
59058
|
-
console.error(
|
|
61000
|
+
if (!existsSync13(paths.reportHtml)) {
|
|
61001
|
+
console.error(chalk17.red(`✖ report.html não existe em ${paths.runDir}`));
|
|
59059
61002
|
return 1;
|
|
59060
61003
|
}
|
|
59061
61004
|
return serveRunAndBlock(paths.runDir, {
|
|
@@ -59089,9 +61032,18 @@ var PRESETS = {
|
|
|
59089
61032
|
only: "e2e,html,console"
|
|
59090
61033
|
}
|
|
59091
61034
|
};
|
|
61035
|
+
function pagesFlowsScopeWarning(opts, flows2) {
|
|
61036
|
+
if (!opts.pages && !opts.pagesFile)
|
|
61037
|
+
return null;
|
|
61038
|
+
if (flows2.length === 0)
|
|
61039
|
+
return null;
|
|
61040
|
+
return `--pages/--pages-file only scope the visual-diff/vitals passes — the flows crawl (${flows2.join(",")}) discovers its own pages; use --flows or .parityrc.json *UrlHint overrides to scope that.`;
|
|
61041
|
+
}
|
|
59092
61042
|
function applySmartDefaults(opts, llmAvailable) {
|
|
59093
61043
|
if (llmAvailable)
|
|
59094
61044
|
return opts;
|
|
61045
|
+
if (opts.pages || opts.pagesFile)
|
|
61046
|
+
return opts;
|
|
59095
61047
|
const merged = { ...opts };
|
|
59096
61048
|
const COMMANDER_DEFAULTS = {
|
|
59097
61049
|
visualPages: 5
|
|
@@ -59164,17 +61116,27 @@ function applyLlmOptions(opts) {
|
|
|
59164
61116
|
}
|
|
59165
61117
|
return null;
|
|
59166
61118
|
}
|
|
61119
|
+
function evaluateFailOnGate(allIssues, failOn) {
|
|
61120
|
+
const blocking = allIssues.filter((i) => failOn.includes(i.severity));
|
|
61121
|
+
if (blocking.length === 0)
|
|
61122
|
+
return { exitCode: 0 };
|
|
61123
|
+
return {
|
|
61124
|
+
exitCode: 1,
|
|
61125
|
+
message: `
|
|
61126
|
+
✖ ${blocking.length} issue(s) bloqueante(s) [${failOn.join(", ")}] — exit 1`
|
|
61127
|
+
};
|
|
61128
|
+
}
|
|
59167
61129
|
async function runCommand(rawOpts) {
|
|
59168
61130
|
if (!rawOpts.prod) {
|
|
59169
61131
|
const target = rawOpts.cand ?? "<url>";
|
|
59170
|
-
console.error(`${
|
|
59171
|
-
For one site, use: ${
|
|
61132
|
+
console.error(`${chalk18.yellow("Single-site run?")} \`parity run\` compares two URLs (prod↔cand).
|
|
61133
|
+
For one site, use: ${chalk18.cyan(`parity e2e --url ${target}`)}
|
|
59172
61134
|
(runs the functional flows + all checks in single-site mode — no prod baseline needed).`);
|
|
59173
61135
|
return 2;
|
|
59174
61136
|
}
|
|
59175
61137
|
let opts = applyPreset(rawOpts);
|
|
59176
61138
|
if (rawOpts.preset) {
|
|
59177
|
-
console.log(
|
|
61139
|
+
console.log(chalk18.dim(` preset: ${rawOpts.preset}`));
|
|
59178
61140
|
}
|
|
59179
61141
|
if (opts.pt)
|
|
59180
61142
|
setLlmLanguage("pt");
|
|
@@ -59182,14 +61144,14 @@ async function runCommand(rawOpts) {
|
|
|
59182
61144
|
disableInteractive();
|
|
59183
61145
|
const llmCfgErr = applyLlmOptions(opts);
|
|
59184
61146
|
if (llmCfgErr) {
|
|
59185
|
-
console.error(
|
|
61147
|
+
console.error(chalk18.red(` ${llmCfgErr}`));
|
|
59186
61148
|
return 2;
|
|
59187
61149
|
}
|
|
59188
61150
|
const llmStillAvailable = isLlmAvailable();
|
|
59189
61151
|
const preSmart = opts;
|
|
59190
61152
|
opts = applySmartDefaults(opts, llmStillAvailable);
|
|
59191
61153
|
if (!llmStillAvailable && opts.visualPages !== preSmart.visualPages) {
|
|
59192
|
-
console.log(
|
|
61154
|
+
console.log(chalk18.dim(" visual-pages auto-set to 0 (no LLM available — analysis layer would be skipped; opt in with --visual-pages N)"));
|
|
59193
61155
|
}
|
|
59194
61156
|
let interactivePromptShown = false;
|
|
59195
61157
|
if (!opts.only && !opts.skip && !rawOpts.preset) {
|
|
@@ -59203,10 +61165,10 @@ async function runCommand(rawOpts) {
|
|
|
59203
61165
|
}
|
|
59204
61166
|
const selection = resolveSelection({ only: opts.only, skip: opts.skip });
|
|
59205
61167
|
if (selection.errors.length > 0) {
|
|
59206
|
-
console.error(
|
|
61168
|
+
console.error(chalk18.red(" --only/--skip: invalid value(s):"));
|
|
59207
61169
|
for (const e of selection.errors)
|
|
59208
|
-
console.error(
|
|
59209
|
-
console.error(
|
|
61170
|
+
console.error(chalk18.red(` - ${e}`));
|
|
61171
|
+
console.error(chalk18.dim(`
|
|
59210
61172
|
valid modules: ${Object.keys(MODULES).join(", ")}`));
|
|
59211
61173
|
return 2;
|
|
59212
61174
|
}
|
|
@@ -59217,13 +61179,17 @@ async function runCommand(rawOpts) {
|
|
|
59217
61179
|
if (hasSelection) {
|
|
59218
61180
|
const explicitFlows = userSetFlows ? opts.flows.split(",").map((s) => s.trim()).filter(Boolean) : [];
|
|
59219
61181
|
flows2 = Array.from(new Set([...explicitFlows, ...selection.flows]));
|
|
59220
|
-
console.log(
|
|
61182
|
+
console.log(chalk18.dim(` modules: ${selection.modules.join(", ") || "(none)"} → flows: ${flows2.join(",")}`));
|
|
59221
61183
|
} else {
|
|
59222
61184
|
flows2 = opts.flows.split(",").map((s) => s.trim());
|
|
59223
61185
|
if (!interactivePromptShown) {
|
|
59224
|
-
console.log(
|
|
61186
|
+
console.log(chalk18.dim(" no --only/--skip given — running ALL modules; pass --only to scope the run for a lighter/faster result"));
|
|
59225
61187
|
}
|
|
59226
61188
|
}
|
|
61189
|
+
const pagesScopeWarning = pagesFlowsScopeWarning(opts, flows2);
|
|
61190
|
+
if (pagesScopeWarning) {
|
|
61191
|
+
console.log(chalk18.dim(` ${pagesScopeWarning}`));
|
|
61192
|
+
}
|
|
59227
61193
|
if (hasSelection) {
|
|
59228
61194
|
const needsSitemapPages = selection.modules.some((m) => MODULES[m].needsSitemapPages);
|
|
59229
61195
|
const needsLlmPass = selection.modules.some((m) => MODULES[m].needsLlm);
|
|
@@ -59231,12 +61197,12 @@ async function runCommand(rawOpts) {
|
|
|
59231
61197
|
const VISUAL_PAGES_DEFAULT = 5;
|
|
59232
61198
|
if (!needsSitemapPages && opts.vitalsPages === VITALS_PAGES_DEFAULT) {
|
|
59233
61199
|
opts.vitalsPages = 0;
|
|
59234
|
-
console.log(
|
|
61200
|
+
console.log(chalk18.dim(" vitals-pages auto-set to 0 (no selected module needs sitemap-page crawling)"));
|
|
59235
61201
|
}
|
|
59236
61202
|
if (!needsLlmPass && opts.visualPages === VISUAL_PAGES_DEFAULT) {
|
|
59237
61203
|
opts.visualPages = 0;
|
|
59238
61204
|
opts.noVisualDiff = true;
|
|
59239
|
-
console.log(
|
|
61205
|
+
console.log(chalk18.dim(" visual-pages auto-set to 0 (no selected module needs the visual-diff pass)"));
|
|
59240
61206
|
}
|
|
59241
61207
|
}
|
|
59242
61208
|
const viewports = opts.viewports.split(",").map((s) => s.trim());
|
|
@@ -59248,38 +61214,38 @@ async function runCommand(rawOpts) {
|
|
|
59248
61214
|
}
|
|
59249
61215
|
const ignore = loadParityIgnore();
|
|
59250
61216
|
if (opts.clearCache) {
|
|
59251
|
-
const cacheFile =
|
|
59252
|
-
if (
|
|
61217
|
+
const cacheFile = join21(opts.output, "cache", "verdicts.json");
|
|
61218
|
+
if (existsSync14(cacheFile)) {
|
|
59253
61219
|
try {
|
|
59254
61220
|
unlinkSync3(cacheFile);
|
|
59255
|
-
console.log(
|
|
61221
|
+
console.log(chalk18.dim(` cache wiped: ${cacheFile}`));
|
|
59256
61222
|
} catch (err) {
|
|
59257
|
-
console.log(
|
|
61223
|
+
console.log(chalk18.yellow(` cache wipe falhou: ${err.message}`));
|
|
59258
61224
|
}
|
|
59259
61225
|
}
|
|
59260
61226
|
}
|
|
59261
61227
|
const llmTimeoutRaw = opts.llmTimeout ?? 60;
|
|
59262
61228
|
if (!Number.isFinite(llmTimeoutRaw)) {
|
|
59263
|
-
console.error(
|
|
61229
|
+
console.error(chalk18.red(` --llm-timeout inválido: "${opts.llmTimeout}" não é um número`));
|
|
59264
61230
|
return 2;
|
|
59265
61231
|
}
|
|
59266
61232
|
const llmTimeoutSec = Math.max(5, Math.floor(llmTimeoutRaw));
|
|
59267
61233
|
if (isLlmAvailable()) {
|
|
59268
|
-
console.log(
|
|
61234
|
+
console.log(chalk18.dim(` llm: ${providerLabel()} (timeout=${llmTimeoutSec}s)`));
|
|
59269
61235
|
} else {
|
|
59270
|
-
console.log(
|
|
61236
|
+
console.log(chalk18.dim(" llm: offline (LLM keys ausentes — agregação heurística)"));
|
|
59271
61237
|
}
|
|
59272
61238
|
if (isInteractiveMode()) {
|
|
59273
|
-
console.log(
|
|
61239
|
+
console.log(chalk18.dim(" interactive: enabled — TTY + no LLM. Missing selectors will pause to prompt (disable with --no-interactive). Issue #72."));
|
|
59274
61240
|
}
|
|
59275
61241
|
const primaryViewport = viewports[0] ?? "mobile";
|
|
59276
61242
|
const preflight = await preflightCheck(opts.prod, opts.cand, primaryViewport);
|
|
59277
61243
|
if (!preflight.ok) {
|
|
59278
|
-
console.error(
|
|
61244
|
+
console.error(chalk18.red(`
|
|
59279
61245
|
✖ pre-flight falhou:`));
|
|
59280
61246
|
for (const err of preflight.errors)
|
|
59281
|
-
console.error(
|
|
59282
|
-
console.error(
|
|
61247
|
+
console.error(chalk18.red(` - ${err}`));
|
|
61248
|
+
console.error(chalk18.dim(`
|
|
59283
61249
|
dica: verifique se as URLs estão corretas e acessíveis`));
|
|
59284
61250
|
return 2;
|
|
59285
61251
|
}
|
|
@@ -59290,15 +61256,16 @@ async function runCommand(rawOpts) {
|
|
|
59290
61256
|
if (prodHomeHtml) {
|
|
59291
61257
|
platform = detectPlatform({ url: opts.prod, html: prodHomeHtml });
|
|
59292
61258
|
if (platform !== "custom") {
|
|
59293
|
-
console.log(
|
|
61259
|
+
console.log(chalk18.dim(` Detected platform: ${platform}`));
|
|
59294
61260
|
}
|
|
59295
61261
|
}
|
|
59296
61262
|
const prodHost = hostOf3(opts.prod);
|
|
59297
61263
|
let promotedCount = 0;
|
|
59298
61264
|
let deprecatedCount = 0;
|
|
59299
61265
|
const wantsAutoSelectors = opts.autoSelectors !== false && isLlmAvailable();
|
|
61266
|
+
let discoveryBrowser = null;
|
|
59300
61267
|
if (wantsAutoSelectors) {
|
|
59301
|
-
await runSelectorDiscoveryPass({
|
|
61268
|
+
discoveryBrowser = await runSelectorDiscoveryPass({
|
|
59302
61269
|
url: opts.prod,
|
|
59303
61270
|
viewport: primaryViewport,
|
|
59304
61271
|
rc,
|
|
@@ -59324,11 +61291,11 @@ async function runCommand(rawOpts) {
|
|
|
59324
61291
|
viewports,
|
|
59325
61292
|
timestamp
|
|
59326
61293
|
});
|
|
59327
|
-
console.log(
|
|
61294
|
+
console.log(chalk18.bold(`
|
|
59328
61295
|
parity run ${runId}`));
|
|
59329
|
-
console.log(
|
|
59330
|
-
console.log(
|
|
59331
|
-
console.log(
|
|
61296
|
+
console.log(chalk18.dim(` prod: ${opts.prod}`));
|
|
61297
|
+
console.log(chalk18.dim(` cand: ${opts.cand}`));
|
|
61298
|
+
console.log(chalk18.dim(` flows: ${flows2.join(", ")} · viewports: ${viewports.join(", ")} · CEP: ${rc.cep}
|
|
59332
61299
|
`));
|
|
59333
61300
|
const spinner = ora6("Launching browser…").start();
|
|
59334
61301
|
let browser = null;
|
|
@@ -59340,7 +61307,7 @@ async function runCommand(rawOpts) {
|
|
|
59340
61307
|
const min = Math.floor(elapsedSec / 60);
|
|
59341
61308
|
const sec = elapsedSec % 60;
|
|
59342
61309
|
const mmss = `${min.toString().padStart(2, "0")}:${sec.toString().padStart(2, "0")}`;
|
|
59343
|
-
spinner.text = `${
|
|
61310
|
+
spinner.text = `${chalk18.dim(`⏱ ${mmss} ·`)} ${currentSpinnerLabel}`;
|
|
59344
61311
|
};
|
|
59345
61312
|
const setSpinnerLabel = (label) => {
|
|
59346
61313
|
currentSpinnerLabel = label;
|
|
@@ -59358,7 +61325,17 @@ async function runCommand(rawOpts) {
|
|
|
59358
61325
|
let currentPhase = "launch";
|
|
59359
61326
|
let shuttingDown = false;
|
|
59360
61327
|
const partialChecks = [];
|
|
59361
|
-
const
|
|
61328
|
+
const forceCloseBrowser = async (b, capMs) => {
|
|
61329
|
+
if (!b)
|
|
61330
|
+
return;
|
|
61331
|
+
await Promise.race([
|
|
61332
|
+
b.close().catch(() => {
|
|
61333
|
+
return;
|
|
61334
|
+
}),
|
|
61335
|
+
new Promise((resolve5) => setTimeout(resolve5, capMs))
|
|
61336
|
+
]);
|
|
61337
|
+
};
|
|
61338
|
+
const shutdown = async (reason) => {
|
|
59362
61339
|
if (shuttingDown) {
|
|
59363
61340
|
process.stderr.write(`
|
|
59364
61341
|
segunda interrupção — forçando saída.
|
|
@@ -59399,11 +61376,7 @@ ${formatTimingsSummary(partialTimings, buildFlowBreakdown(allFlowCaptures))}
|
|
|
59399
61376
|
process.stderr.write(` falha escrevendo report parcial: ${err.message}
|
|
59400
61377
|
`);
|
|
59401
61378
|
}
|
|
59402
|
-
|
|
59403
|
-
browser.close().catch(() => {
|
|
59404
|
-
return;
|
|
59405
|
-
});
|
|
59406
|
-
}
|
|
61379
|
+
await forceCloseBrowser(browser, 3000);
|
|
59407
61380
|
process.exit(130);
|
|
59408
61381
|
};
|
|
59409
61382
|
const onSignal = (sig) => {
|
|
@@ -59417,7 +61390,7 @@ ${formatTimingsSummary(partialTimings, buildFlowBreakdown(allFlowCaptures))}
|
|
|
59417
61390
|
}, timeoutMinutes * 60000);
|
|
59418
61391
|
globalTimeoutTimer.unref?.();
|
|
59419
61392
|
try {
|
|
59420
|
-
browser = await launchBrowser({ headless: true });
|
|
61393
|
+
browser = discoveryBrowser ?? await launchBrowser({ headless: true });
|
|
59421
61394
|
if (opts.warmup) {
|
|
59422
61395
|
const warmupSpinner = ora6("Warmup: bustando cache em prod + cand…").start();
|
|
59423
61396
|
const result = await warmupTargets({
|
|
@@ -59435,14 +61408,15 @@ ${formatTimingsSummary(partialTimings, buildFlowBreakdown(allFlowCaptures))}
|
|
|
59435
61408
|
warmupSpinner.fail(`Warmup falhou — 0/${result.attempted} requests ok. Cache pode estar stale. Primeira falha: ${firstReason}`);
|
|
59436
61409
|
}
|
|
59437
61410
|
}
|
|
61411
|
+
const traceEnabled = process.env.PARITY_TRACE === "1";
|
|
59438
61412
|
const runOneSide = async (viewport, side) => {
|
|
59439
61413
|
const baseUrl = side === "prod" ? opts.prod : opts.cand;
|
|
59440
|
-
const harPath =
|
|
59441
|
-
const tracePath =
|
|
61414
|
+
const harPath = join21(paths.harDir, `${viewport}-${side}.har`);
|
|
61415
|
+
const tracePath = traceEnabled ? join21(paths.tracesDir, `${viewport}-${side}.zip`) : null;
|
|
59442
61416
|
const ctx = await newContext(browser, {
|
|
59443
61417
|
viewport,
|
|
59444
61418
|
harPath,
|
|
59445
|
-
tracesDir: paths.tracesDir,
|
|
61419
|
+
tracesDir: traceEnabled ? paths.tracesDir : undefined,
|
|
59446
61420
|
cohortCookieValue: "control",
|
|
59447
61421
|
noCache: opts.bypassCache
|
|
59448
61422
|
});
|
|
@@ -59453,8 +61427,8 @@ ${formatTimingsSummary(partialTimings, buildFlowBreakdown(allFlowCaptures))}
|
|
|
59453
61427
|
for (const flow of flows2) {
|
|
59454
61428
|
const flowStart = Date.now();
|
|
59455
61429
|
let lastStepTotal = 0;
|
|
59456
|
-
const sideTag = side === "prod" ?
|
|
59457
|
-
const prefix = `${
|
|
61430
|
+
const sideTag = side === "prod" ? chalk18.cyan("prod") : chalk18.magenta("cand");
|
|
61431
|
+
const prefix = `${chalk18.dim(`[${viewport}/`)}${sideTag}${chalk18.dim("]")}`;
|
|
59458
61432
|
setSpinnerLabel(`${prefix} ${flow}: starting…`);
|
|
59459
61433
|
const cap = await runFlow(flow, {
|
|
59460
61434
|
baseUrl,
|
|
@@ -59471,7 +61445,7 @@ ${formatTimingsSummary(partialTimings, buildFlowBreakdown(allFlowCaptures))}
|
|
|
59471
61445
|
onStep: (event) => {
|
|
59472
61446
|
if (event.phase === "start") {
|
|
59473
61447
|
lastStepTotal = event.total;
|
|
59474
|
-
setSpinnerLabel(`${prefix} ${flow} ${
|
|
61448
|
+
setSpinnerLabel(`${prefix} ${flow} ${chalk18.dim(`${event.index}/${event.total}`)} ${event.name}…`);
|
|
59475
61449
|
}
|
|
59476
61450
|
}
|
|
59477
61451
|
});
|
|
@@ -59480,18 +61454,18 @@ ${formatTimingsSummary(partialTimings, buildFlowBreakdown(allFlowCaptures))}
|
|
|
59480
61454
|
const target = lastStepTotal || recorded;
|
|
59481
61455
|
const failed = cap.steps?.find((s) => s.status === "failed");
|
|
59482
61456
|
const lastStep = cap.steps?.[cap.steps.length - 1];
|
|
59483
|
-
const elapsedDim =
|
|
59484
|
-
const counts = target > 0 ?
|
|
61457
|
+
const elapsedDim = chalk18.dim(`${((Date.now() - flowStart) / 1000).toFixed(1)}s`);
|
|
61458
|
+
const counts = target > 0 ? chalk18.dim(`${okSteps}/${target}`) : "";
|
|
59485
61459
|
let glyph;
|
|
59486
61460
|
let detail;
|
|
59487
61461
|
if (failed) {
|
|
59488
|
-
glyph =
|
|
59489
|
-
detail = `stopped at ${
|
|
61462
|
+
glyph = chalk18.red("✗");
|
|
61463
|
+
detail = `stopped at ${chalk18.yellow(failed.name)}`;
|
|
59490
61464
|
} else if (target > 0 && okSteps < target) {
|
|
59491
|
-
glyph =
|
|
59492
|
-
detail = lastStep ? `ended at ${
|
|
61465
|
+
glyph = chalk18.yellow("▴");
|
|
61466
|
+
detail = lastStep ? `ended at ${chalk18.dim(lastStep.name)}` : "incomplete";
|
|
59493
61467
|
} else {
|
|
59494
|
-
glyph =
|
|
61468
|
+
glyph = chalk18.green("✓");
|
|
59495
61469
|
detail = "";
|
|
59496
61470
|
}
|
|
59497
61471
|
const summary = `${glyph} ${prefix} ${flow} ${counts} ${detail} ${elapsedDim}`.replace(/\s+/g, " ").trim();
|
|
@@ -59503,9 +61477,10 @@ ${formatTimingsSummary(partialTimings, buildFlowBreakdown(allFlowCaptures))}
|
|
|
59503
61477
|
pages.push(p);
|
|
59504
61478
|
}
|
|
59505
61479
|
} finally {
|
|
59506
|
-
|
|
59507
|
-
|
|
59508
|
-
|
|
61480
|
+
if (tracePath)
|
|
61481
|
+
await stopTracing(ctx, tracePath).catch(() => {
|
|
61482
|
+
return;
|
|
61483
|
+
});
|
|
59509
61484
|
await ctx.close();
|
|
59510
61485
|
}
|
|
59511
61486
|
return { captures, pages };
|
|
@@ -59550,8 +61525,9 @@ ${formatTimingsSummary(partialTimings, buildFlowBreakdown(allFlowCaptures))}
|
|
|
59550
61525
|
const candIsDevServer = isLocalhost(opts.cand);
|
|
59551
61526
|
const vitalsPagesDefault = candIsDevServer ? 3 : 10;
|
|
59552
61527
|
const vitalsPagesLimit = opts.vitalsPages ?? vitalsPagesDefault;
|
|
61528
|
+
const vitalsRuns = Math.max(1, Number.parseInt(opts.runs, 10) || 1);
|
|
59553
61529
|
if (candIsDevServer && vitalsPagesLimit > 0) {
|
|
59554
|
-
console.log(
|
|
61530
|
+
console.log(chalk18.dim(` cand=localhost detectado — vitals-pages=${vitalsPagesLimit}, networkidle desabilitado (issue #55)`));
|
|
59555
61531
|
}
|
|
59556
61532
|
if (browser && vitalsPagesLimit > 0) {
|
|
59557
61533
|
currentPhase = "vitals-pages";
|
|
@@ -59608,7 +61584,7 @@ ${formatTimingsSummary(partialTimings, buildFlowBreakdown(allFlowCaptures))}
|
|
|
59608
61584
|
const baseUrl = task.side === "prod" ? opts.prod : opts.cand;
|
|
59609
61585
|
const fullUrl = new URL(task.path, baseUrl).toString();
|
|
59610
61586
|
const targetIsDevServer = isLocalhost(baseUrl);
|
|
59611
|
-
const PER_TASK_WALLCLOCK_MS = 35000;
|
|
61587
|
+
const PER_TASK_WALLCLOCK_MS = 35000 + Math.max(0, vitalsRuns - 1) * 8000;
|
|
59612
61588
|
try {
|
|
59613
61589
|
const ctx = await newContext(browser, {
|
|
59614
61590
|
viewport: task.viewport,
|
|
@@ -59629,10 +61605,11 @@ ${formatTimingsSummary(partialTimings, buildFlowBreakdown(allFlowCaptures))}
|
|
|
59629
61605
|
fast: true,
|
|
59630
61606
|
scrollToLoad: false,
|
|
59631
61607
|
skipScreenshot: true,
|
|
59632
|
-
noNetworkIdle: targetIsDevServer
|
|
61608
|
+
noNetworkIdle: targetIsDevServer,
|
|
61609
|
+
runs: vitalsRuns
|
|
59633
61610
|
}),
|
|
59634
|
-
new Promise((
|
|
59635
|
-
const t = setTimeout(() =>
|
|
61611
|
+
new Promise((resolve5) => {
|
|
61612
|
+
const t = setTimeout(() => resolve5(null), PER_TASK_WALLCLOCK_MS);
|
|
59636
61613
|
t.unref?.();
|
|
59637
61614
|
})
|
|
59638
61615
|
]);
|
|
@@ -59751,7 +61728,7 @@ ${formatTimingsSummary(partialTimings, buildFlowBreakdown(allFlowCaptures))}
|
|
|
59751
61728
|
setSpinnerLabel("Rodando checks…");
|
|
59752
61729
|
spinner.start();
|
|
59753
61730
|
const checksHb = attachSpinnerHeartbeat(spinner, { baseText: "Rodando checks…" });
|
|
59754
|
-
const cacheDir =
|
|
61731
|
+
const cacheDir = join21(opts.output, "cache");
|
|
59755
61732
|
const checkCtx = {
|
|
59756
61733
|
prodPages: allPageCaptures.filter((p) => p.side === "prod"),
|
|
59757
61734
|
candPages: allPageCaptures.filter((p) => p.side === "cand"),
|
|
@@ -59871,13 +61848,10 @@ ${formatTimingsSummary(partialTimings, buildFlowBreakdown(allFlowCaptures))}
|
|
|
59871
61848
|
printSummary5(run, paths.reportHtml, { promotedCount, deprecatedCount, platform });
|
|
59872
61849
|
console.log(`
|
|
59873
61850
|
${formatTimingsSummary(runTimings, buildFlowBreakdown(allFlowCaptures))}`);
|
|
59874
|
-
|
|
59875
|
-
|
|
59876
|
-
|
|
59877
|
-
|
|
59878
|
-
✖ ${blocking.length} issue(s) bloqueante(s) [${failOn.join(", ")}] — exit 1`));
|
|
59879
|
-
return 1;
|
|
59880
|
-
}
|
|
61851
|
+
const failOnGate = evaluateFailOnGate(allIssues, failOn);
|
|
61852
|
+
if (failOnGate.exitCode === 1) {
|
|
61853
|
+
console.log(chalk18.red(failOnGate.message));
|
|
61854
|
+
return 1;
|
|
59881
61855
|
}
|
|
59882
61856
|
if (opts.open) {
|
|
59883
61857
|
if (browser) {
|
|
@@ -59936,10 +61910,10 @@ function buildPartialRun(args) {
|
|
|
59936
61910
|
}
|
|
59937
61911
|
function resolveExplicitPages(pagesFile, pagesList) {
|
|
59938
61912
|
if (pagesFile) {
|
|
59939
|
-
if (!
|
|
61913
|
+
if (!existsSync14(pagesFile)) {
|
|
59940
61914
|
throw new Error(`--pages-file não encontrado: ${pagesFile}`);
|
|
59941
61915
|
}
|
|
59942
|
-
const raw =
|
|
61916
|
+
const raw = readFileSync15(pagesFile, "utf-8");
|
|
59943
61917
|
const lines = raw.split(/\r?\n/).map((l) => l.trim()).filter((l) => l.length > 0 && !l.startsWith("#"));
|
|
59944
61918
|
return lines.map(normalizePath);
|
|
59945
61919
|
}
|
|
@@ -60090,44 +62064,44 @@ function hostOf3(url) {
|
|
|
60090
62064
|
}
|
|
60091
62065
|
function printSummary5(run, htmlPath, meta) {
|
|
60092
62066
|
const { verdict: verdict2 } = run;
|
|
60093
|
-
const emoji = verdict2.status === "pass" ?
|
|
60094
|
-
const score = verdict2.status === "pass" ?
|
|
62067
|
+
const emoji = verdict2.status === "pass" ? chalk18.green("✔") : verdict2.status === "warn" ? chalk18.yellow("⚠") : chalk18.red("✖");
|
|
62068
|
+
const score = verdict2.status === "pass" ? chalk18.green(verdict2.score) : verdict2.status === "warn" ? chalk18.yellow(verdict2.score) : chalk18.red(verdict2.score);
|
|
60095
62069
|
const prev2 = run.previousRun;
|
|
60096
|
-
const scoreDelta = !prev2 ?
|
|
62070
|
+
const scoreDelta = !prev2 ? chalk18.dim(" (sem run anterior comparável)") : prev2.scoreDelta > 0 ? chalk18.green(` (+${prev2.scoreDelta} vs run anterior: ${prev2.score})`) : prev2.scoreDelta < 0 ? chalk18.red(` (${prev2.scoreDelta} vs run anterior: ${prev2.score})`) : chalk18.dim(` (= run anterior: ${prev2.score})`);
|
|
60097
62071
|
console.log("");
|
|
60098
62072
|
console.log(` ${emoji} parity ${verdict2.status.toUpperCase()} · score ${score}/100${scoreDelta}`);
|
|
60099
|
-
console.log(` checks: ${
|
|
60100
|
-
console.log(` issues: ${
|
|
62073
|
+
console.log(` checks: ${chalk18.green(verdict2.checksPassed)} pass · ${chalk18.red(verdict2.checksFailed)} fail · ${chalk18.dim(`${verdict2.checksSkipped} skipped`)}`);
|
|
62074
|
+
console.log(` issues: ${chalk18.red(verdict2.critical)} critical · ${chalk18.yellow(verdict2.high)} high · ${verdict2.medium} medium · ${chalk18.dim(`${verdict2.low} low`)}`);
|
|
60101
62075
|
if (run.moduleVerdicts && run.moduleVerdicts.length > 0) {
|
|
60102
62076
|
const perModule = run.moduleVerdicts.map((mv) => {
|
|
60103
|
-
const colored = mv.status === "pass" ?
|
|
62077
|
+
const colored = mv.status === "pass" ? chalk18.green(mv.score) : mv.status === "warn" ? chalk18.yellow(mv.score) : chalk18.red(mv.score);
|
|
60104
62078
|
return `${mv.module} ${colored}`;
|
|
60105
62079
|
}).join(" · ");
|
|
60106
62080
|
console.log(` modules: ${perModule} → composite ${score}`);
|
|
60107
62081
|
}
|
|
60108
62082
|
if (run.visualDiff) {
|
|
60109
62083
|
const vd = run.visualDiff;
|
|
60110
|
-
const parityIcon = vd.parityOk ?
|
|
60111
|
-
const parityLabel = vd.parityOk ?
|
|
60112
|
-
const cacheNote = vd.pagesFromCache > 0 ?
|
|
60113
|
-
console.log(` visual: ${parityIcon} parityOk=${parityLabel} · ${vd.pagesChecked} pages · ${
|
|
62084
|
+
const parityIcon = vd.parityOk ? chalk18.green("✔") : chalk18.red("✖");
|
|
62085
|
+
const parityLabel = vd.parityOk ? chalk18.green("OK") : chalk18.red("DIFFS");
|
|
62086
|
+
const cacheNote = vd.pagesFromCache > 0 ? chalk18.dim(` · ${vd.pagesFromCache} cached`) : "";
|
|
62087
|
+
console.log(` visual: ${parityIcon} parityOk=${parityLabel} · ${vd.pagesChecked} pages · ${chalk18.red(vd.pagesWithDiffs)} diffs · ${chalk18.green(vd.pagesPassed)} pass${cacheNote}`);
|
|
60114
62088
|
}
|
|
60115
62089
|
if (run.topIssues.length > 0) {
|
|
60116
62090
|
console.log("");
|
|
60117
|
-
console.log(
|
|
62091
|
+
console.log(chalk18.bold(" Top issues:"));
|
|
60118
62092
|
for (const g of groupIssues(run.topIssues).slice(0, 5)) {
|
|
60119
62093
|
const i = g.sample;
|
|
60120
|
-
const sev = i.severity === "critical" ?
|
|
60121
|
-
const pagesNote = g.pages.length > 1 ?
|
|
62094
|
+
const sev = i.severity === "critical" ? chalk18.red(`[${i.severity}]`) : i.severity === "high" ? chalk18.yellow(`[${i.severity}]`) : chalk18.dim(`[${i.severity}]`);
|
|
62095
|
+
const pagesNote = g.pages.length > 1 ? chalk18.dim(` (${g.pages.length} páginas)`) : "";
|
|
60122
62096
|
console.log(` ${sev} ${i.summary}${pagesNote}`);
|
|
60123
62097
|
}
|
|
60124
62098
|
}
|
|
60125
62099
|
if (meta.promotedCount > 0 || meta.deprecatedCount > 0) {
|
|
60126
62100
|
console.log("");
|
|
60127
|
-
console.log(
|
|
62101
|
+
console.log(chalk18.dim(` \uD83D\uDCDA learned-selectors [${meta.platform}]: ${chalk18.green(`+${meta.promotedCount}`)} promoted · ${chalk18.yellow(meta.deprecatedCount)} deprecated`));
|
|
60128
62102
|
}
|
|
60129
62103
|
console.log("");
|
|
60130
|
-
console.log(
|
|
62104
|
+
console.log(chalk18.dim(` → ${htmlPath}`));
|
|
60131
62105
|
console.log("");
|
|
60132
62106
|
}
|
|
60133
62107
|
|
|
@@ -60147,31 +62121,30 @@ async function prCommand(opts) {
|
|
|
60147
62121
|
cep: "01310-100",
|
|
60148
62122
|
runs: "1",
|
|
60149
62123
|
output: opts.output,
|
|
60150
|
-
ci: true,
|
|
60151
62124
|
failOn: "critical,high",
|
|
60152
62125
|
preset: opts.preset ?? "ci",
|
|
60153
62126
|
open: false
|
|
60154
62127
|
};
|
|
60155
|
-
console.log(
|
|
60156
|
-
console.log(
|
|
62128
|
+
console.log(chalk19.dim(` prod : ${opts.prod}`));
|
|
62129
|
+
console.log(chalk19.dim(` preview : ${opts.preview}`));
|
|
60157
62130
|
console.log("");
|
|
60158
62131
|
const runCode = await runCommand(runOpts);
|
|
60159
62132
|
const runs = listRuns(opts.output);
|
|
60160
62133
|
if (runs.length === 0) {
|
|
60161
|
-
console.error(
|
|
62134
|
+
console.error(chalk19.red("no run was produced — cannot build PR comment"));
|
|
60162
62135
|
return runCode || 1;
|
|
60163
62136
|
}
|
|
60164
62137
|
const latest = runs[0];
|
|
60165
|
-
const reportJsonPath =
|
|
60166
|
-
if (!
|
|
60167
|
-
console.error(
|
|
62138
|
+
const reportJsonPath = join22(opts.output, "runs", latest.id, "report.json");
|
|
62139
|
+
if (!existsSync15(reportJsonPath)) {
|
|
62140
|
+
console.error(chalk19.red(`report.json not found at ${reportJsonPath}`));
|
|
60168
62141
|
return runCode || 1;
|
|
60169
62142
|
}
|
|
60170
|
-
const run = JSON.parse(
|
|
62143
|
+
const run = JSON.parse(readFileSync16(reportJsonPath, "utf8"));
|
|
60171
62144
|
const markdown = buildPrComment(run, opts);
|
|
60172
62145
|
if (opts.out) {
|
|
60173
|
-
|
|
60174
|
-
console.log(
|
|
62146
|
+
writeFileSync20(opts.out, markdown, "utf8");
|
|
62147
|
+
console.log(chalk19.dim(` wrote PR comment: ${opts.out}`));
|
|
60175
62148
|
} else {
|
|
60176
62149
|
process.stdout.write(`
|
|
60177
62150
|
${markdown}
|
|
@@ -60179,9 +62152,9 @@ ${markdown}
|
|
|
60179
62152
|
}
|
|
60180
62153
|
if (opts.github && process.env.GITHUB_STEP_SUMMARY) {
|
|
60181
62154
|
try {
|
|
60182
|
-
|
|
62155
|
+
writeFileSync20(process.env.GITHUB_STEP_SUMMARY, markdown, { flag: "a" });
|
|
60183
62156
|
} catch (err) {
|
|
60184
|
-
console.error(
|
|
62157
|
+
console.error(chalk19.yellow(`failed to write GITHUB_STEP_SUMMARY: ${err.message}`));
|
|
60185
62158
|
}
|
|
60186
62159
|
}
|
|
60187
62160
|
return runCode;
|
|
@@ -60240,14 +62213,14 @@ function buildPrComment(run, opts) {
|
|
|
60240
62213
|
}
|
|
60241
62214
|
|
|
60242
62215
|
// src/commands/prompt.ts
|
|
60243
|
-
import { existsSync as
|
|
60244
|
-
import
|
|
62216
|
+
import { existsSync as existsSync16, writeFileSync as writeFileSync21 } from "node:fs";
|
|
62217
|
+
import chalk20 from "chalk";
|
|
60245
62218
|
function promptCommand(runId, opts) {
|
|
60246
62219
|
let run;
|
|
60247
62220
|
try {
|
|
60248
62221
|
run = loadRun(opts.output, runId);
|
|
60249
62222
|
} catch (err) {
|
|
60250
|
-
console.error(
|
|
62223
|
+
console.error(chalk20.red(`✖ ${err.message}`));
|
|
60251
62224
|
return 1;
|
|
60252
62225
|
}
|
|
60253
62226
|
const md = buildLlmPrompt(run, {
|
|
@@ -60255,11 +62228,11 @@ function promptCommand(runId, opts) {
|
|
|
60255
62228
|
limit: opts.limit
|
|
60256
62229
|
});
|
|
60257
62230
|
if (opts.out) {
|
|
60258
|
-
|
|
60259
|
-
console.log(
|
|
60260
|
-
if (
|
|
62231
|
+
writeFileSync21(opts.out, md, "utf8");
|
|
62232
|
+
console.log(chalk20.green(`✔ prompt salvo em ${opts.out}`));
|
|
62233
|
+
if (existsSync16(opts.out)) {
|
|
60261
62234
|
const sizeKb = (md.length / 1024).toFixed(1);
|
|
60262
|
-
console.log(
|
|
62235
|
+
console.log(chalk20.dim(` ${md.length} chars (${sizeKb} KB)`));
|
|
60263
62236
|
}
|
|
60264
62237
|
} else {
|
|
60265
62238
|
process.stdout.write(md);
|
|
@@ -60268,8 +62241,8 @@ function promptCommand(runId, opts) {
|
|
|
60268
62241
|
}
|
|
60269
62242
|
|
|
60270
62243
|
// src/commands/report.ts
|
|
60271
|
-
import { existsSync as
|
|
60272
|
-
import
|
|
62244
|
+
import { existsSync as existsSync17, readFileSync as readFileSync17 } from "node:fs";
|
|
62245
|
+
import chalk21 from "chalk";
|
|
60273
62246
|
import open from "open";
|
|
60274
62247
|
|
|
60275
62248
|
// src/report/extract-section.ts
|
|
@@ -60343,7 +62316,7 @@ function extractVitalsSlice(run) {
|
|
|
60343
62316
|
if (!p.vitals)
|
|
60344
62317
|
continue;
|
|
60345
62318
|
const k = `${p.side}::${p.viewport}::${pathOf4(p.url)}`;
|
|
60346
|
-
out[k] = p.vitals;
|
|
62319
|
+
out[k] = p.vitalsFullPage ? { ...p.vitals, fullPage: p.vitalsFullPage } : p.vitals;
|
|
60347
62320
|
}
|
|
60348
62321
|
}
|
|
60349
62322
|
return out;
|
|
@@ -60418,41 +62391,41 @@ async function reportCommand(runId, opts) {
|
|
|
60418
62391
|
const run = loadRun(opts.output, runId);
|
|
60419
62392
|
const payload = extractReportSection({ kind: "json", section: opts.section, run });
|
|
60420
62393
|
if (payload === null) {
|
|
60421
|
-
console.error(
|
|
62394
|
+
console.error(chalk21.red(`section "${opts.section}" not present in this run`));
|
|
60422
62395
|
return 1;
|
|
60423
62396
|
}
|
|
60424
62397
|
process.stdout.write(`${JSON.stringify(payload, null, 2)}
|
|
60425
62398
|
`);
|
|
60426
62399
|
return 0;
|
|
60427
62400
|
} catch (err) {
|
|
60428
|
-
console.error(
|
|
62401
|
+
console.error(chalk21.red(`failed to load run: ${err.message}`));
|
|
60429
62402
|
return 1;
|
|
60430
62403
|
}
|
|
60431
62404
|
}
|
|
60432
|
-
if (!
|
|
60433
|
-
console.error(
|
|
62405
|
+
if (!existsSync17(paths.reportHtml)) {
|
|
62406
|
+
console.error(chalk21.red(`report.html not found at ${paths.reportHtml}`));
|
|
60434
62407
|
return 1;
|
|
60435
62408
|
}
|
|
60436
|
-
const html3 =
|
|
62409
|
+
const html3 = readFileSync17(paths.reportHtml, "utf8");
|
|
60437
62410
|
const slice2 = extractReportSection({ kind: "html", section: opts.section, html: html3 });
|
|
60438
62411
|
if (slice2 === null) {
|
|
60439
|
-
console.error(
|
|
62412
|
+
console.error(chalk21.red(`section "${opts.section}" not present in this report`));
|
|
60440
62413
|
return 1;
|
|
60441
62414
|
}
|
|
60442
62415
|
process.stdout.write(slice2);
|
|
60443
62416
|
return 0;
|
|
60444
62417
|
}
|
|
60445
|
-
console.log(
|
|
62418
|
+
console.log(chalk21.dim(`opening ${paths.reportHtml}`));
|
|
60446
62419
|
await open(paths.reportHtml).catch((err) => {
|
|
60447
|
-
console.error(
|
|
62420
|
+
console.error(chalk21.red(`failed to open: ${err.message}`));
|
|
60448
62421
|
});
|
|
60449
62422
|
return 0;
|
|
60450
62423
|
}
|
|
60451
62424
|
|
|
60452
62425
|
// src/commands/vitals.ts
|
|
60453
|
-
import { existsSync as
|
|
60454
|
-
import { join as
|
|
60455
|
-
import
|
|
62426
|
+
import { existsSync as existsSync18, readFileSync as readFileSync18, writeFileSync as writeFileSync22 } from "node:fs";
|
|
62427
|
+
import { join as join23 } from "node:path";
|
|
62428
|
+
import chalk22 from "chalk";
|
|
60456
62429
|
import ora7 from "ora";
|
|
60457
62430
|
async function vitalsCommand(opts) {
|
|
60458
62431
|
const viewports = opts.viewports.split(",").map((s) => s.trim()).filter((s) => s === "mobile" || s === "desktop");
|
|
@@ -60460,10 +62433,10 @@ async function vitalsCommand(opts) {
|
|
|
60460
62433
|
const runId = newRunId();
|
|
60461
62434
|
const paths = createRunDir(opts.output, runId);
|
|
60462
62435
|
const t0 = Date.now();
|
|
60463
|
-
console.log(
|
|
62436
|
+
console.log(chalk22.bold(`
|
|
60464
62437
|
parity vitals ${runId}`));
|
|
60465
|
-
console.log(
|
|
60466
|
-
console.log(
|
|
62438
|
+
console.log(chalk22.dim(` prod: ${opts.prod}`));
|
|
62439
|
+
console.log(chalk22.dim(` cand: ${opts.cand}`));
|
|
60467
62440
|
const discoverSpinner = ora7("Descobrindo páginas…").start();
|
|
60468
62441
|
const pagePaths = await discoverPagePaths2(opts.prod, opts);
|
|
60469
62442
|
if (pagePaths.length === 0) {
|
|
@@ -60488,14 +62461,14 @@ async function vitalsCommand(opts) {
|
|
|
60488
62461
|
await runWithConcurrency3(tasks, concurrency, async (task) => {
|
|
60489
62462
|
const url = new URL(task.path, task.side === "prod" ? opts.prod : opts.cand).toString();
|
|
60490
62463
|
try {
|
|
60491
|
-
task.capture = await captureVitalsPage(browser, task.viewport, task.side, url, paths.screenshotsDir);
|
|
62464
|
+
task.capture = await captureVitalsPage(browser, task.viewport, task.side, url, paths.screenshotsDir, opts.runs);
|
|
60492
62465
|
} catch (err) {
|
|
60493
62466
|
task.error = err.message;
|
|
60494
62467
|
} finally {
|
|
60495
62468
|
completed++;
|
|
60496
62469
|
const elapsed = ((Date.now() - t0) / 1000).toFixed(0);
|
|
60497
62470
|
const etaSec = completed > 0 ? Math.round((Date.now() - t0) / completed * (total - completed) / 1000) : 0;
|
|
60498
|
-
progress.text = `${completed}/${total} · ${elapsed}s · ETA ${etaSec}s · ${task.side === "prod" ?
|
|
62471
|
+
progress.text = `${completed}/${total} · ${elapsed}s · ETA ${etaSec}s · ${task.side === "prod" ? chalk22.cyan("prod") : chalk22.magenta("cand")} ${task.path} (${task.viewport})`;
|
|
60499
62472
|
}
|
|
60500
62473
|
});
|
|
60501
62474
|
progress.succeed(`${total} capture(s) em ${((Date.now() - t0) / 1000).toFixed(1)}s`);
|
|
@@ -60559,7 +62532,7 @@ async function vitalsCommand(opts) {
|
|
|
60559
62532
|
writeRunReportJson(paths.runDir, run);
|
|
60560
62533
|
const html3 = renderHtmlReport(run, paths.runDir);
|
|
60561
62534
|
writeRunReportHtml(paths.runDir, html3);
|
|
60562
|
-
|
|
62535
|
+
writeFileSync22(join23(paths.runDir, "vitals.json"), `${JSON.stringify({
|
|
60563
62536
|
schemaVersion: "0.1",
|
|
60564
62537
|
prodUrl: opts.prod,
|
|
60565
62538
|
candUrl: opts.cand,
|
|
@@ -60570,8 +62543,8 @@ async function vitalsCommand(opts) {
|
|
|
60570
62543
|
`, "utf8");
|
|
60571
62544
|
printSummary6(vitalsResult, cacheResult);
|
|
60572
62545
|
console.log("");
|
|
60573
|
-
console.log(
|
|
60574
|
-
console.log(
|
|
62546
|
+
console.log(chalk22.dim(` → ${paths.reportHtml}`));
|
|
62547
|
+
console.log(chalk22.dim(` \uD83D\uDCA1 use 'parity serve ${runId}' pra preview iframe`));
|
|
60575
62548
|
console.log("");
|
|
60576
62549
|
if (opts.open) {
|
|
60577
62550
|
const { default: open2 } = await import("open");
|
|
@@ -60591,7 +62564,7 @@ async function vitalsCommand(opts) {
|
|
|
60591
62564
|
});
|
|
60592
62565
|
}
|
|
60593
62566
|
}
|
|
60594
|
-
async function captureVitalsPage(browser, viewport, side, url, screenshotsDir) {
|
|
62567
|
+
async function captureVitalsPage(browser, viewport, side, url, screenshotsDir, runs) {
|
|
60595
62568
|
const ctx = await newContext(browser, { viewport, cohortCookieValue: "control" });
|
|
60596
62569
|
await installVitalsCollector(ctx);
|
|
60597
62570
|
const page = await ctx.newPage();
|
|
@@ -60606,7 +62579,8 @@ async function captureVitalsPage(browser, viewport, side, url, screenshotsDir) {
|
|
|
60606
62579
|
timeoutMs: 20000,
|
|
60607
62580
|
scrollToLoad: false,
|
|
60608
62581
|
skipScreenshot: true,
|
|
60609
|
-
fast: true
|
|
62582
|
+
fast: true,
|
|
62583
|
+
runs
|
|
60610
62584
|
});
|
|
60611
62585
|
} finally {
|
|
60612
62586
|
await page.close().catch(() => {
|
|
@@ -60657,8 +62631,8 @@ async function discoverPagePaths2(prodUrl, opts) {
|
|
|
60657
62631
|
function parseUrlList(input) {
|
|
60658
62632
|
if (input.startsWith("file:") || input.endsWith(".txt") || input.endsWith(".list")) {
|
|
60659
62633
|
const path = input.replace(/^file:\/\//, "");
|
|
60660
|
-
if (
|
|
60661
|
-
return
|
|
62634
|
+
if (existsSync18(path)) {
|
|
62635
|
+
return readFileSync18(path, "utf8").split(/\r?\n/).map((s) => s.trim()).filter((s) => s && !s.startsWith("#")).map((s) => s.startsWith("/") ? s : `/${s}`);
|
|
60662
62636
|
}
|
|
60663
62637
|
}
|
|
60664
62638
|
return input.split(",").map((s) => s.trim()).filter(Boolean).map((s) => s.startsWith("/") || s.startsWith("http") ? s : `/${s}`);
|
|
@@ -60676,22 +62650,22 @@ async function runWithConcurrency3(items, workers, fn) {
|
|
|
60676
62650
|
}
|
|
60677
62651
|
function printSummary6(vitals, cache) {
|
|
60678
62652
|
console.log("");
|
|
60679
|
-
console.log(
|
|
62653
|
+
console.log(chalk22.bold(" Summary:"));
|
|
60680
62654
|
console.log(` ${vitals.summary}`);
|
|
60681
62655
|
console.log(` ${cache.summary}`);
|
|
60682
62656
|
}
|
|
60683
62657
|
|
|
60684
62658
|
// src/util/version.ts
|
|
60685
|
-
import { readFileSync as
|
|
60686
|
-
import { dirname as dirname5, resolve as
|
|
62659
|
+
import { readFileSync as readFileSync19 } from "node:fs";
|
|
62660
|
+
import { dirname as dirname5, resolve as resolve5 } from "node:path";
|
|
60687
62661
|
import { fileURLToPath } from "node:url";
|
|
60688
62662
|
function getPackageVersion() {
|
|
60689
62663
|
try {
|
|
60690
62664
|
const here = dirname5(fileURLToPath(import.meta.url));
|
|
60691
62665
|
for (const up of ["..", "../..", "../../.."]) {
|
|
60692
62666
|
try {
|
|
60693
|
-
const pkgPath =
|
|
60694
|
-
const raw =
|
|
62667
|
+
const pkgPath = resolve5(here, up, "package.json");
|
|
62668
|
+
const raw = readFileSync19(pkgPath, "utf8");
|
|
60695
62669
|
const parsed = JSON.parse(raw);
|
|
60696
62670
|
if (parsed.name === "@decocms/parity" && typeof parsed.version === "string") {
|
|
60697
62671
|
return parsed.version;
|
|
@@ -60704,7 +62678,7 @@ function getPackageVersion() {
|
|
|
60704
62678
|
|
|
60705
62679
|
// src/cli.ts
|
|
60706
62680
|
var program = new Command;
|
|
60707
|
-
program.name("parity").description("E2E parity validator
|
|
62681
|
+
program.name("parity").description("E2E parity validator + migration capture for site migrations").version(getPackageVersion());
|
|
60708
62682
|
program.command("run").description([
|
|
60709
62683
|
"Compare two URLs and produce a parity report.",
|
|
60710
62684
|
"",
|
|
@@ -60716,16 +62690,16 @@ program.command("run").description([
|
|
|
60716
62690
|
" flows=purchase-journey, viewports=mobile,desktop, vitals-pages=10,",
|
|
60717
62691
|
" visual-pages=5 (auto-zeroed when no LLM provider available),",
|
|
60718
62692
|
" auto-selectors=ON (if LLM), learn=ON, cache=ON, visual-diff=ON,",
|
|
60719
|
-
" warmup=OFF, bypass-cache=OFF,
|
|
62693
|
+
" warmup=OFF, bypass-cache=OFF, fail-on=critical (exit 1 if hit)."
|
|
60720
62694
|
].join(`
|
|
60721
|
-
`)).option("--prod <url>", "Production URL (source of truth, e.g. Fresh site). Omit for a single site — the run will point you to `parity e2e` (issue #141).").requiredOption("--cand <url>", "Candidate URL (migrated site, e.g. TanStack)").option("--preset <name>", "Bundle of defaults: smoke (fast, ~30s, no LLM) | full (deep audit) | ci (CI-tuned)").option("--flows <list>", "Comma-separated flows: homepage,plp,pdp,purchase-journey", "purchase-journey").option("--viewports <list>", "Comma-separated viewports: mobile,desktop", "mobile,desktop").option("--cep <cep>", "CEP for shipping calculation", "01310-100").option("--add-to-cart-timeout <ms>", "How long (ms) the add-to-cart step polls for a success signal before failing. Default 3000. Raise/lower to match your site's success-toast lifetime (issue #143).", (v) => Number(v)).option("--runs <n>", "Repeat each measurement N times (median)", "1").option("--baseline <name>", "Compare against a saved baseline").option("--output <dir>", "Output directory", "./parity-output").option("--
|
|
62695
|
+
`)).option("--prod <url>", "Production URL (source of truth, e.g. Fresh site). Omit for a single site — the run will point you to `parity e2e` (issue #141).").requiredOption("--cand <url>", "Candidate URL (migrated site, e.g. TanStack)").option("--preset <name>", "Bundle of defaults: smoke (fast, ~30s, no LLM) | full (deep audit) | ci (CI-tuned)").option("--flows <list>", "Comma-separated flows: homepage,plp,pdp,purchase-journey", "purchase-journey").option("--viewports <list>", "Comma-separated viewports: mobile,desktop", "mobile,desktop").option("--cep <cep>", "CEP for shipping calculation", "01310-100").option("--add-to-cart-timeout <ms>", "How long (ms) the add-to-cart step polls for a success signal before failing. Default 3000. Raise/lower to match your site's success-toast lifetime (issue #143).", (v) => Number(v)).option("--runs <n>", "Repeat each measurement N times (median)", "1").option("--baseline <name>", "Compare against a saved baseline").option("--output <dir>", "Output directory", "./parity-output").option("--fail-on <severities>", "Comma-separated severities that cause exit 1 (default: critical)", "critical").option("--open", "Open the HTML report after the run completes", false).option("--no-auto-selectors", "Disable LLM-based selector discovery (uses defaults instead)").option("--refresh-selectors", "Bypass selector cache and re-run discovery", false).option("--no-learn", "Don't write to learned-selectors.json (read-only mode)").option("--vitals-pages <n>", "Extra pages from sitemap to crawl for Vitals coverage, beyond what --flows/--pages already cover (default 10). These are auto-sampled and can add significant unrelated noise to findings — pass 0 to scope the run to only the pages you explicitly requested.", (v) => Number(v), 10).option("--max-viewport-concurrency <n>", "How many viewports run concurrently during collect (default 2: mobile+desktop together). Set to 1 if you hit OOM with many viewports.", (v) => Number(v), 2).option("--visual-pages <n>", "Pages to compare visually via LLM (home + sampled PLPs/PDPs from sitemap, default 5)", (v) => Number(v), 5).option("--pages <list>", 'Comma-separated paths to compare visually (overrides sitemap discovery). E.g. "/,/account,/p/some-product". Use this when you want deterministic coverage instead of sampled. Scopes the visual-diff + vitals-extra-pages passes ONLY — the flows crawl (--flows, default purchase-journey) discovers its own target pages independently and ignores this flag. To scope which page(s) a flow visits, use --flows to pick a lighter flow and/or set the matching *UrlHint (e.g. plpUrlHint) in .parityrc.json. Issue #178.').option("--pages-file <path>", "Read paths to compare visually from a text file (one path per line). Lines starting with # are ignored. Overrides --pages when both are present. Same visual-diff/vitals-only scope as --pages — see that flag's help. Issue #178.").option("--no-visual-diff", "Skip the visual diff capture pass entirely").option("--no-cache", "Disable the cross-run visual-diff cache (forces a fresh LLM judgment on every page).").option("--clear-cache", "Wipe the visual-diff verdict cache (parity-output/cache/verdicts.json) before the run.", false).option("--bypass-cache", "Bypass CDN/edge caches AND the browser's own HTTP cache (CDP cache-disable), forcing a cold-visit fetch. Use right after a deploy to avoid false failures from stale CF edge content, or to approximate Lighthouse/CrUX-comparable TTFB/FCP/LCP numbers — without this flag, parity's vitals are a warm-connection/cache-enabled ('repeat visit') measurement, not a cold first-visit one, so they aren't directly comparable 1:1 to Lighthouse.", false).option("--warmup", "Before measurement, hit each target URL once (per viewport) with a cache-buster so the Worker serves a fresh response. Recommended after deploys.", false).option("--accept-prod-quirks", "Demote prod-side cart-empty journey failures (VTEX session quirk) from failed to skipped. The cart-reveal-mode-divergence check still emits critical if prod/cand markup intents differ, so this flag never masks a real regression. See issue #12.", false).option("--llm-timeout <seconds>", "Hard timeout for the LLM aggregation call (seconds). The run completes in offline mode if the LLM hangs past this. Default: 60.", (v) => Number(v), 60).option("--timeout <minutes>", "Hard wall-clock cap for the whole run (minutes). On expiry, parity writes a partial report and exits 130. Default: 30. Issue #56.", (v) => Number(v), 30).option("--flow <name>", "Alias for --flows when running a single flow (e.g. --flow cart). Issue #53.").option("--json <path|->", "Emit JSON-Lines (one line per check) to the given file path, or '-' for stdout. Schema versioned via leading metadata line. Issue #53.").option("--pt", "Tell the LLM to respond in Brazilian Portuguese. Only affects LLM-generated content (issues, explain, prompts) — the static HTML report stays in English. Issue #67.").option("--llm <provider>", "Force LLM provider: anthropic | openrouter | claude-code | none. Default: auto-detect (anthropic key → openrouter key → local claude CLI → none). Issue #66.").option("--llm-model <overrides>", "Per-feature model override, e.g. visual-diff=claude-opus-4-7,explain=claude-opus-4-7. Features: selector-discovery, step-recovery, search-terms, plp-matching, pdp-matching, section-understanding, visual-diff, issue-aggregation, explain, component-detection. Issue #66.").option("--llm-tier-default <tier>", "Override the default tier (haiku | sonnet | opus) for every feature that doesn't have a per-feature override. Issue #66.").option("--llm-model-default <model>", "Force every LLM call to use this exact model ID, ignoring per-feature defaults. Issue #66.").option("--no-interactive", "Disable the interactive selector prompt that auto-fires in a TTY without an LLM provider. Use in scripts and CI where stdin is technically a TTY but you don't want to pause. Issue #72.").option("--only <modules>", "Scope the run to these modules and/or single checks (comma-separated). Module names: e2e, seo, visual, vitals, cache, console, html, network. Single-check granularity via `check:<name>`, e.g. `--only e2e,check:cache-coverage`. Run `parity list modules` for the full check/flow mapping. Default: all modules. M3 module selection.").option("--skip <modules>", "Subtract these modules and/or single checks (comma-separated, same syntax as --only) from whatever base set was chosen (all modules, or --only's set if both are given). M3 module selection.").option("--why <text>", "Free-text reason for this run's scope, stored in report.json as `selectionReason`. Purely informational. M3 module selection.").action(async (opts) => {
|
|
60722
62696
|
if (opts.flow) {
|
|
60723
62697
|
opts.flows = opts.flow;
|
|
60724
62698
|
}
|
|
60725
62699
|
const code = await runCommand(opts);
|
|
60726
62700
|
process.exit(code);
|
|
60727
62701
|
});
|
|
60728
|
-
program.command("audit").description("Single-site absolute audit. Runs console + vitals + network + images + SEO checks on ONE URL (no prod×cand comparison) and outputs a focused HTML report. Use for pre-launch or post-deploy 'what's broken right now' verification.").requiredOption("--url <url>", "Base URL (e.g. https://miess-tanstack.deco-cx.workers.dev)").option("--viewport <viewport>", "mobile | desktop | tablet", "mobile").option("--pages <list>", "Comma-separated paths to audit (default: /)", "/").option("--output <dir>", "Output directory", "./parity-output").option("--open", "Open the HTML report after the run completes", false).option("--json", "Emit one-line JSON instead of pretty text", false).option("--fail-on <severities>", "Comma-separated severities that cause exit 1 (default: critical,high)", "critical,high").option("--pt", "Tell the LLM to respond in Brazilian Portuguese. Issue #67.").action(async (opts) => {
|
|
62702
|
+
program.command("audit").description("Single-site absolute audit. Runs console + vitals + network + images + SEO checks on ONE URL (no prod×cand comparison) and outputs a focused HTML report. Use for pre-launch or post-deploy 'what's broken right now' verification.").requiredOption("--url <url>", "Base URL (e.g. https://miess-tanstack.deco-cx.workers.dev)").option("--viewport <viewport>", "mobile | desktop | tablet", "mobile").option("--pages <list>", "Comma-separated paths to audit (default: /)", "/").option("--output <dir>", "Output directory", "./parity-output").option("--open", "Open the HTML report after the run completes", false).option("--json", "Emit one-line JSON instead of pretty text", false).option("--fail-on <severities>", "Comma-separated severities that cause exit 1 (default: critical,high)", "critical,high").option("--runs <n>", "Repeat the Web Vitals navigation N times per page and audit against the median (reduces run-to-run jitter false positives). Default 1 (no repeat). Issue #179.", (v) => Number(v), 1).option("--pt", "Tell the LLM to respond in Brazilian Portuguese. Issue #67.").action(async (opts) => {
|
|
60729
62703
|
if (opts.pt) {
|
|
60730
62704
|
const { setLlmLanguage: setLlmLanguage2 } = await Promise.resolve().then(() => (init_client(), exports_client));
|
|
60731
62705
|
setLlmLanguage2("pt");
|
|
@@ -60777,7 +62751,7 @@ program.command("pr").description("CI/CD entry point: compare a PR preview URL a
|
|
|
60777
62751
|
program.command("cache").description("Cache analysis focused on cand. Crawls N pages (lighter than `vitals`: no screenshots, no vitals, no scroll), groups requests by category, lists MISS-asset opportunities.").requiredOption("--prod <url>", "Production URL (optional reference)").requiredOption("--cand <url>", "Candidate URL (foco)").option("--urls <list-or-file>", "Comma-separated paths or .txt file (1/line). Overrides sitemap.").option("--pages <n>", "Max pages to crawl from sitemap", (v) => Number(v), 30).option("--viewports <list>", "mobile,desktop", "mobile").option("--concurrency <n>", "Parallel workers (1-8)", (v) => Number(v), 6).option("--cand-only", "Skip prod entirely (faster, no comparison)", false).option("--output <dir>", "Output directory", "./parity-output").option("--open", "Open the HTML report when done", false).action(async (opts) => {
|
|
60778
62752
|
process.exit(await cacheCommand(opts));
|
|
60779
62753
|
});
|
|
60780
|
-
program.command("vitals").description("Crawls multiple pages (via sitemap.xml or --urls) and compares Web Vitals prod vs cand on each. HTML output with the top worst/best expanded.").requiredOption("--prod <url>", "Production URL (base)").requiredOption("--cand <url>", "Candidate URL (base)").option("--urls <list-or-file>", "Comma-separated paths or .txt file (1/line). Overrides sitemap discovery.").option("--limit <n>", "Max pages discovered from sitemap.xml", (v) => Number(v), 20).option("--viewports <list>", "mobile,desktop", "mobile").option("--concurrency <n>", "Parallel workers (1-8)", (v) => Number(v), 4).option("--output <dir>", "Output directory", "./parity-output").option("--open", "Open the HTML report when done", false).action(async (opts) => {
|
|
62754
|
+
program.command("vitals").description("Crawls multiple pages (via sitemap.xml or --urls) and compares Web Vitals prod vs cand on each. HTML output with the top worst/best expanded.").requiredOption("--prod <url>", "Production URL (base)").requiredOption("--cand <url>", "Candidate URL (base)").option("--urls <list-or-file>", "Comma-separated paths or .txt file (1/line). Overrides sitemap discovery.").option("--limit <n>", "Max pages discovered from sitemap.xml", (v) => Number(v), 20).option("--viewports <list>", "mobile,desktop", "mobile").option("--concurrency <n>", "Parallel workers (1-8)", (v) => Number(v), 4).option("--runs <n>", "Repeat each page's vitals navigation N times and compare against the median (reduces run-to-run jitter false positives). Default 1 (no repeat). Issue #179.", (v) => Number(v), 1).option("--output <dir>", "Output directory", "./parity-output").option("--open", "Open the HTML report when done", false).action(async (opts) => {
|
|
60781
62755
|
process.exit(await vitalsCommand(opts));
|
|
60782
62756
|
});
|
|
60783
62757
|
program.command("journey").description("CI-friendly: runs only the purchase journey (home → PLP → PDP → shipping → cart → cart shipping → checkout) and compares prod vs cand step by step.").requiredOption("--prod <url>", "Production URL").requiredOption("--cand <url>", "Candidate URL").option("--viewports <list>", "mobile,desktop", "mobile").option("--cep <cep>", "CEP for shipping calc", "01310-100").option("--output <dir>", "Output directory for runs/<id>/", "./parity-output").option("--junit <file>", "Write JUnit XML to this path").option("--github", "Emit GitHub Actions annotations (::error, ::warning) for failures").option("--json", "Emit a one-line JSON status object to stdout (machine-readable)").option("--no-report", "Skip writing report.html / report.json").option("--no-auto-selectors", "Skip LLM-based selector discovery").option("--accept-prod-quirks", "Demote prod-side cart-empty journey failures (VTEX session quirk) from failed to skipped. The cart-reveal-mode-divergence check still emits critical if prod/cand markup intents differ, so this flag never masks a real regression. See issue #12.", false).option("--pt", "Tell the LLM to respond in Brazilian Portuguese. Issue #67.").action(async (opts) => {
|
|
@@ -60876,6 +62850,21 @@ program.command("extract").description("Single-site AI-ready component extractio
|
|
|
60876
62850
|
json: opts.json
|
|
60877
62851
|
}));
|
|
60878
62852
|
});
|
|
62853
|
+
program.command("migrate").description("Single-site, phased migration capture (theme → sitemap → components). No prod×cand comparison — produces a target-agnostic, token-lean bundle + prompt for a migration agent: site theme (colors/typography/spacing as Tailwind tokens), classified pages, and per-component detail (suggested Tailwind classes, interaction hints, e2e selectors). Works whether or not the source code exists. Pass --target faststore to append a target playbook. Resumable: re-runs skip a completed phase unless --refresh.").requiredOption("--url <url>", "Site to migrate from").option("--pages <list>", 'Comma-separated pages: literal paths/URLs, and/or "category-auto"/"pdp-auto". Default: "/,category-auto,pdp-auto" (home + a PLP + a PDP).').option("--components <list>", "Comma-separated role allowlist, e.g. header,footer,nav,shelf,minicart. Default: all detected.").option("--target <name>", "Target playbook to append to the prompt (e.g. faststore)").option("--viewport <viewport>", "Primary viewport for component capture: mobile | desktop | tablet", "mobile").option("--viewports <list>", "Comma-separated viewports for theme + site screenshots (e.g. mobile,desktop). Default: --viewport only.").option("--format <fmt>", "md | json | both", "both").option("--out <dir>", "Output directory (stable per host, for resume)", "./parity-migrate").option("--refresh", "Re-run all phases even if cached artifacts exist", false).option("--no-llm", "Skip the optional LLM component-relabeling pass (heuristic detection always runs regardless).").option("--json", "Emit one-line JSON instead of pretty text", false).action(async (opts) => {
|
|
62854
|
+
process.exit(await migrateCommand({
|
|
62855
|
+
url: opts.url,
|
|
62856
|
+
pages: opts.pages,
|
|
62857
|
+
components: opts.components,
|
|
62858
|
+
target: opts.target,
|
|
62859
|
+
viewport: opts.viewport,
|
|
62860
|
+
viewports: opts.viewports,
|
|
62861
|
+
format: opts.format,
|
|
62862
|
+
outDir: opts.out,
|
|
62863
|
+
refresh: opts.refresh,
|
|
62864
|
+
noLlm: !opts.llm,
|
|
62865
|
+
json: opts.json
|
|
62866
|
+
}));
|
|
62867
|
+
});
|
|
60879
62868
|
program.command("learned").description("Inspect the learned-selectors library").addCommand(new Command("stats").description("Print learned-selectors stats per platform").action(() => {
|
|
60880
62869
|
process.exit(learnedStats());
|
|
60881
62870
|
})).addCommand(new Command("validate").description("Debug: run selector discovery + live-validation against a single URL and print a table (not part of `parity run`)").requiredOption("--url <url>", "URL to fetch + discover + validate").action(async (opts) => {
|