@decocms/parity 0.26.5 → 0.26.7

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.
Files changed (2) hide show
  1. package/dist/cli.js +242 -12
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -63117,6 +63117,9 @@ function buildMigrationPrompt(bundle, playbook, source) {
63117
63117
  // src/migrate/plan.ts
63118
63118
  import { existsSync as existsSync11, readFileSync as readFileSync16, writeFileSync as writeFileSync22 } from "node:fs";
63119
63119
  import { join as join24 } from "node:path";
63120
+ function dedupe(names) {
63121
+ return [...new Set(names)];
63122
+ }
63120
63123
  function key(name) {
63121
63124
  return name.toLowerCase().replace(/[\s_/-]+/g, "");
63122
63125
  }
@@ -63124,7 +63127,7 @@ function buildMigrationPlan(input) {
63124
63127
  const { bundle, source, inventory } = input;
63125
63128
  const liveByKey = new Map;
63126
63129
  for (const c of bundle.components) {
63127
- liveByKey.set(key(c.role), { role: c.role, scope: c.scope });
63130
+ liveByKey.set(key(c.role), { role: c.role, scope: c.scope, selector: c.selector });
63128
63131
  }
63129
63132
  const srcByKey = new Map;
63130
63133
  for (const c of inventory.components)
@@ -63137,7 +63140,10 @@ function buildMigrationPlan(input) {
63137
63140
  scope: c.scope,
63138
63141
  origin: liveByKey.has(k) ? "both" : "source-only",
63139
63142
  status: "pending",
63140
- file: c.file
63143
+ file: c.file,
63144
+ selector: liveByKey.get(k)?.selector ?? null,
63145
+ reference: null,
63146
+ verified: null
63141
63147
  });
63142
63148
  }
63143
63149
  for (const [k, c] of liveByKey) {
@@ -63149,7 +63155,10 @@ function buildMigrationPlan(input) {
63149
63155
  scope: c.scope,
63150
63156
  origin: "live-only",
63151
63157
  status: "pending",
63152
- file: null
63158
+ file: null,
63159
+ selector: c.selector,
63160
+ reference: null,
63161
+ verified: null
63153
63162
  });
63154
63163
  }
63155
63164
  return {
@@ -63157,11 +63166,17 @@ function buildMigrationPlan(input) {
63157
63166
  timestamp: bundle.timestamp,
63158
63167
  source: { kind: source.kind, label: source.label, dir: source.dir, notes: inventory.notes },
63159
63168
  target: { name: bundle.target ?? null },
63160
- pages: bundle.pages.map((p) => ({ path: p.path, kind: p.kind, status: "pending" })),
63169
+ pages: bundle.pages.map((p) => ({
63170
+ path: p.path,
63171
+ kind: p.kind,
63172
+ status: "pending",
63173
+ components: dedupe((p.components ?? []).map((c) => components.find((row) => key(row.name) === key(c.role))?.name ?? c.role))
63174
+ })),
63161
63175
  components
63162
63176
  };
63163
63177
  }
63164
63178
  var PLAN_FILE = "migration-plan.json";
63179
+ var SETTLED = new Set(["done", "as-is", "upgrade", "skipped"]);
63165
63180
  function loadPlan(dir) {
63166
63181
  const p = join24(dir, PLAN_FILE);
63167
63182
  if (!existsSync11(p))
@@ -63181,26 +63196,36 @@ function setComponentStatus(plan, name, status) {
63181
63196
  return component;
63182
63197
  }
63183
63198
  function setPageStatus(plan, path, status) {
63184
- const norm = (p) => `/${p.trim().replace(/^\/+|\/+$/g, "")}` || "/";
63185
- const target = norm(path);
63186
- const page = plan.pages.find((p) => p.path === path) ?? plan.pages.find((p) => norm(p.path) === target);
63199
+ const page = findPage(plan, path);
63187
63200
  if (!page)
63188
63201
  return null;
63189
63202
  page.status = status;
63190
63203
  return page;
63191
63204
  }
63205
+ function findPage(plan, path) {
63206
+ const norm = (p) => `/${p.trim().replace(/^\/+|\/+$/g, "")}` || "/";
63207
+ const target = norm(path);
63208
+ return plan.pages.find((p) => p.path === path) ?? plan.pages.find((p) => norm(p.path) === target) ?? null;
63209
+ }
63192
63210
  function planProgress(plan) {
63193
63211
  const compByStatus = {
63194
63212
  pending: 0,
63195
63213
  partial: 0,
63196
63214
  done: 0,
63215
+ "as-is": 0,
63216
+ upgrade: 0,
63197
63217
  skipped: 0
63198
63218
  };
63199
63219
  const settled = [];
63220
+ const accepted = { asIs: [], upgrade: [] };
63200
63221
  const remaining = [];
63201
63222
  for (const c of plan.components) {
63202
63223
  compByStatus[c.status] = (compByStatus[c.status] ?? 0) + 1;
63203
- if (c.status === "done" || c.status === "skipped")
63224
+ if (c.status === "as-is")
63225
+ accepted.asIs.push(c.name);
63226
+ if (c.status === "upgrade")
63227
+ accepted.upgrade.push(c.name);
63228
+ if (SETTLED.has(c.status))
63204
63229
  settled.push(c.name);
63205
63230
  else
63206
63231
  remaining.push({
@@ -63223,7 +63248,13 @@ function planProgress(plan) {
63223
63248
  }
63224
63249
  }
63225
63250
  return {
63226
- components: { total: plan.components.length, byStatus: compByStatus, settled, remaining },
63251
+ components: {
63252
+ total: plan.components.length,
63253
+ byStatus: compByStatus,
63254
+ settled,
63255
+ accepted,
63256
+ remaining
63257
+ },
63227
63258
  pages: {
63228
63259
  total: plan.pages.length,
63229
63260
  byStatus: pageByStatus,
@@ -63232,6 +63263,88 @@ function planProgress(plan) {
63232
63263
  }
63233
63264
  };
63234
63265
  }
63266
+ function joinUrl(base, path) {
63267
+ return `${base.replace(/\/+$/, "")}/${path.replace(/^\/+/, "")}`.replace(/\/$/, "") || base;
63268
+ }
63269
+ function shellQuote(value) {
63270
+ return /^[\w./:=-]+$/.test(value) ? value : `'${value.replace(/'/g, "'\\''")}'`;
63271
+ }
63272
+ function disposition(c) {
63273
+ if (c.status === "pending" || c.status === "partial")
63274
+ return "build";
63275
+ if (c.status === "skipped")
63276
+ return "settled";
63277
+ if (c.status === "as-is")
63278
+ return "as-is";
63279
+ if (c.verified)
63280
+ return "settled";
63281
+ if (c.status === "upgrade")
63282
+ return c.reference ? "validate" : "upgrade";
63283
+ return "validate";
63284
+ }
63285
+ function pagePlan(plan, path, candUrl) {
63286
+ const page = findPage(plan, path);
63287
+ if (!page)
63288
+ return null;
63289
+ const counts = {
63290
+ build: 0,
63291
+ validate: 0,
63292
+ upgrade: 0,
63293
+ "as-is": 0,
63294
+ settled: 0
63295
+ };
63296
+ let tasks = null;
63297
+ if (page.components) {
63298
+ tasks = [];
63299
+ for (const name of page.components) {
63300
+ const c = plan.components.find((row) => key(row.name) === key(name));
63301
+ if (!c)
63302
+ continue;
63303
+ const d = disposition(c);
63304
+ counts[d] += 1;
63305
+ const selector = c.reference?.selector ?? c.selector ?? null;
63306
+ const refUrl = c.reference?.url ?? plan.url;
63307
+ const kind = c.reference ? "reference" : "prod";
63308
+ const checkable = d === "validate" && Boolean(selector) && Boolean(candUrl);
63309
+ tasks.push({
63310
+ name: c.name,
63311
+ disposition: d,
63312
+ status: c.status,
63313
+ scope: c.scope ?? "page",
63314
+ origin: c.origin,
63315
+ selector,
63316
+ against: d === "validate" ? { url: refUrl, kind } : null,
63317
+ command: checkable && candUrl && selector ? `parity section --prod ${shellQuote(joinUrl(refUrl, page.path))} --cand ${shellQuote(joinUrl(candUrl, page.path))} --selector ${shellQuote(selector)}` : null,
63318
+ note: c.reference?.note ?? null
63319
+ });
63320
+ }
63321
+ }
63322
+ return {
63323
+ path: page.path,
63324
+ kind: page.kind,
63325
+ status: page.status ?? "pending",
63326
+ tasks,
63327
+ counts,
63328
+ ready: counts.build === 0 && counts.validate === 0
63329
+ };
63330
+ }
63331
+ function setComponentVerified(plan, name, verdict2, at, note) {
63332
+ const k = key(name);
63333
+ const component = plan.components.find((c) => key(c.name) === k);
63334
+ if (!component)
63335
+ return null;
63336
+ const against = component.reference ? "reference" : "prod";
63337
+ component.verified = { at, verdict: verdict2, against, ...note ? { note } : {} };
63338
+ return component;
63339
+ }
63340
+ function setComponentReference(plan, name, reference) {
63341
+ const k = key(name);
63342
+ const component = plan.components.find((c) => key(c.name) === k);
63343
+ if (!component)
63344
+ return null;
63345
+ component.reference = reference;
63346
+ return component;
63347
+ }
63235
63348
  function syntheticSourceComponents(plan) {
63236
63349
  return plan.components.filter((c) => c.origin === "source-only").map((c) => ({
63237
63350
  role: c.name,
@@ -64757,7 +64870,7 @@ function sleep2(ms) {
64757
64870
 
64758
64871
  // src/commands/plan.ts
64759
64872
  import chalk18 from "chalk";
64760
- var STATUSES = ["pending", "partial", "done", "skipped"];
64873
+ var STATUSES = ["pending", "partial", "done", "as-is", "upgrade", "skipped"];
64761
64874
  var PAGE_STATUSES = ["pending", "code", "done", "skipped"];
64762
64875
  function planSetStatusCommand(dir, name, status) {
64763
64876
  if (!STATUSES.includes(status)) {
@@ -64776,6 +64889,9 @@ function planSetStatusCommand(dir, name, status) {
64776
64889
  }
64777
64890
  savePlan(dir, plan);
64778
64891
  console.log(`${chalk18.green("✓")} ${component.name} → ${status}`);
64892
+ if ((status === "upgrade" || status === "as-is") && !component.reference) {
64893
+ console.log(chalk18.yellow(` no reason recorded — run \`parity plan set-reference ${component.name} --note "<why>"${status === "upgrade" ? " --url <reference site>" : ""}\``));
64894
+ }
64779
64895
  return 0;
64780
64896
  }
64781
64897
  function planSetPageStatusCommand(dir, path, status) {
@@ -64797,6 +64913,104 @@ function planSetPageStatusCommand(dir, path, status) {
64797
64913
  console.log(`${chalk18.green("✓")} ${page.path} → ${status}`);
64798
64914
  return 0;
64799
64915
  }
64916
+ var DISPOSITION_STYLE = {
64917
+ build: chalk18.red,
64918
+ validate: chalk18.yellow,
64919
+ upgrade: chalk18.cyan,
64920
+ "as-is": chalk18.gray,
64921
+ settled: chalk18.green
64922
+ };
64923
+ function planSetReferenceCommand(dir, name, opts) {
64924
+ const plan = loadPlan(dir);
64925
+ if (!plan) {
64926
+ console.error(chalk18.red(`No migration-plan.json found in ${dir}`));
64927
+ return 1;
64928
+ }
64929
+ const component = setComponentReference(plan, name, {
64930
+ url: opts.url ?? plan.url,
64931
+ selector: opts.selector ?? null,
64932
+ note: opts.note
64933
+ });
64934
+ if (!component) {
64935
+ console.error(chalk18.red(`No component matching "${name}" in the plan`));
64936
+ return 1;
64937
+ }
64938
+ savePlan(dir, plan);
64939
+ console.log(`${chalk18.green("✓")} ${component.name} → reference ${component.reference?.url}`);
64940
+ return 0;
64941
+ }
64942
+ function planVerifyCommand(dir, name, verdict2, opts) {
64943
+ if (verdict2 !== "pass" && verdict2 !== "fail") {
64944
+ console.error(chalk18.red(`Invalid verdict "${verdict2}". Use pass or fail.`));
64945
+ return 1;
64946
+ }
64947
+ const plan = loadPlan(dir);
64948
+ if (!plan) {
64949
+ console.error(chalk18.red(`No migration-plan.json found in ${dir}`));
64950
+ return 1;
64951
+ }
64952
+ const component = setComponentVerified(plan, name, verdict2, opts.at ?? new Date().toISOString(), opts.note);
64953
+ if (!component) {
64954
+ console.error(chalk18.red(`No component matching "${name}" in the plan`));
64955
+ return 1;
64956
+ }
64957
+ savePlan(dir, plan);
64958
+ const mark = verdict2 === "pass" ? chalk18.green("✓") : chalk18.red("✗");
64959
+ console.log(`${mark} ${component.name} → ${verdict2} (against ${component.verified?.against})`);
64960
+ return 0;
64961
+ }
64962
+ function planPageCommand(dir, path, opts) {
64963
+ const plan = loadPlan(dir);
64964
+ if (!plan) {
64965
+ console.error(chalk18.red(`No migration-plan.json found in ${dir}`));
64966
+ return 1;
64967
+ }
64968
+ const page = pagePlan(plan, path, opts.cand);
64969
+ if (!page) {
64970
+ console.error(chalk18.red(`No page matching "${path}" in the plan`));
64971
+ console.error(chalk18.gray(` known pages: ${plan.pages.map((p) => p.path).join(", ")}`));
64972
+ return 1;
64973
+ }
64974
+ if (opts.json) {
64975
+ console.log(JSON.stringify(page, null, 2));
64976
+ return 0;
64977
+ }
64978
+ console.log(chalk18.bold(`
64979
+ ${page.path} ${chalk18.gray(`(${page.kind})`)} — ${page.status}`) + (page.ready ? chalk18.green(" ready") : ""));
64980
+ if (page.tasks === null) {
64981
+ console.log(chalk18.yellow("\n This plan has no page/component edges — it predates them. Re-run `parity migrate` to get per-page work.\n"));
64982
+ return 0;
64983
+ }
64984
+ if (page.tasks.length === 0) {
64985
+ console.log(chalk18.gray(`
64986
+ The capture saw no components on this page.
64987
+ `));
64988
+ return 0;
64989
+ }
64990
+ const order = ["build", "validate", "upgrade", "as-is", "settled"];
64991
+ for (const d of order) {
64992
+ const rows = page.tasks.filter((t) => t.disposition === d);
64993
+ if (!rows.length)
64994
+ continue;
64995
+ console.log(`
64996
+ ${DISPOSITION_STYLE[d](chalk18.bold(d))} (${rows.length})`);
64997
+ for (const t of rows) {
64998
+ console.log(` ${t.name} ${chalk18.gray(`(${t.scope}, ${t.origin}, ${t.status})`)}`);
64999
+ if (t.note)
65000
+ console.log(chalk18.gray(` why: ${t.note}`));
65001
+ if (t.against?.kind === "reference") {
65002
+ console.log(chalk18.cyan(` reference: ${t.against.url}`));
65003
+ }
65004
+ if (t.command)
65005
+ console.log(chalk18.gray(` $ ${t.command}`));
65006
+ }
65007
+ }
65008
+ if (page.counts.validate > 0 && !opts.cand) {
65009
+ console.log(chalk18.yellow("\n Pass --cand <url> to get runnable `parity section` commands."));
65010
+ }
65011
+ console.log("");
65012
+ return 0;
65013
+ }
64800
65014
  function planStatusCommand(dir, asJson) {
64801
65015
  const plan = loadPlan(dir);
64802
65016
  if (!plan) {
@@ -64813,7 +65027,13 @@ function planStatusCommand(dir, asJson) {
64813
65027
  console.log(chalk18.bold(`
64814
65028
  Migration plan — ${plan.url}${plan.target.name ? ` → ${plan.target.name}` : ""}`));
64815
65029
  console.log(`
64816
- ${chalk18.bold("Components")} (${c.total}): ` + `${chalk18.green(`${c.byStatus.done} done`)}, ` + `${chalk18.yellow(`${c.byStatus.partial} partial`)}, ` + `${chalk18.red(`${c.byStatus.pending} pending`)}, ` + `${chalk18.gray(`${c.byStatus.skipped} skipped`)}`);
65030
+ ${chalk18.bold("Components")} (${c.total}): ` + `${chalk18.green(`${c.byStatus.done} done`)}, ` + `${chalk18.yellow(`${c.byStatus.partial} partial`)}, ` + `${chalk18.red(`${c.byStatus.pending} pending`)}, ` + `${chalk18.cyan(`${c.byStatus.upgrade} upgrade`)}, ` + `${chalk18.gray(`${c.byStatus["as-is"]} as-is`)}, ` + `${chalk18.gray(`${c.byStatus.skipped} skipped`)}`);
65031
+ if (c.accepted.upgrade.length) {
65032
+ console.log(chalk18.cyan(` deliberately ahead of prod: ${c.accepted.upgrade.join(", ")}`));
65033
+ }
65034
+ if (c.accepted.asIs.length) {
65035
+ console.log(chalk18.gray(` divergence accepted: ${c.accepted.asIs.join(", ")}`));
65036
+ }
64817
65037
  if (c.settled.length) {
64818
65038
  console.log(chalk18.gray(` no work needed: ${c.settled.join(", ")}`));
64819
65039
  }
@@ -67604,12 +67824,22 @@ program.command("list").description("List saved runs").option("--output <dir>",
67604
67824
  }).addCommand(new Command("modules").description("List the 8 selectable check modules (M3 module selection) with their descriptions, checks, and flows — see --only/--skip on `parity run`.").option("--json", "Emit structured JSON instead of human-readable text", false).action((opts) => {
67605
67825
  process.exit(listModulesCommand(Boolean(opts.json)));
67606
67826
  }));
67607
- program.command("plan").description("Inspect/update the migration-plan.json component contract").addCommand(new Command("set-status").description("Mark a component pending|partial|done|skipped as the orchestrator ports it").argument("<name>", "Component name (case- and separator-insensitive)").argument("<status>", "pending | partial | done | skipped").option("--dir <path>", "Directory holding migration-plan.json (default: the target repo's .parity/)", ".parity").action((name, status, opts) => {
67827
+ program.command("plan").description("Inspect/update the migration-plan.json component contract").addCommand(new Command("set-status").description("Mark a component's outcome as the orchestrator works. `as-is` = divergence accepted (prod is still the reference); `upgrade` = the target is deliberately ahead, so prod is NOT the reference — pair it with `plan set-reference`.").argument("<name>", "Component name (case- and separator-insensitive)").argument("<status>", "pending | partial | done | as-is | upgrade | skipped").option("--dir <path>", "Directory holding migration-plan.json (default: the target repo's .parity/)", ".parity").action((name, status, opts) => {
67608
67828
  process.exit(planSetStatusCommand(opts.dir, name, status));
67609
67829
  })).addCommand(new Command("set-page-status").description("Mark a page pending|code|done|skipped (code = route built, content missing)").argument("<path>", "Page path, e.g. / or /refrigeracion").argument("<status>", "pending | code | done | skipped").option("--dir <path>", "Directory holding migration-plan.json (default: the target repo's .parity/)", ".parity").action((path, status, opts) => {
67610
67830
  process.exit(planSetPageStatusCommand(opts.dir, path, status));
67611
67831
  })).addCommand(new Command("status").description("Migration inventory: components settled vs remaining, pages done vs awaiting CMS content").option("--dir <path>", "Directory holding migration-plan.json (default: the target repo's .parity/)", ".parity").option("--json", "Emit structured JSON instead of human-readable text", false).action((opts) => {
67612
67832
  process.exit(planStatusCommand(opts.dir, Boolean(opts.json)));
67833
+ })).addCommand(new Command("page").description("Per-page worksheet: every component the capture saw on this page, what to do about it (build | validate | upgrade | as-is | settled), and a runnable `parity section` command for the checkable ones. The unit of work a migration closes is a page, not a global queue.").argument("<path>", "Page path, e.g. / or /refrigeracion").option("--dir <path>", "Directory holding migration-plan.json (default: the target repo's .parity/)", ".parity").option("--cand <url>", "Candidate base URL — required for runnable validation commands").option("--json", "Emit structured JSON instead of human-readable text", false).action((path, opts) => {
67834
+ process.exit(planPageCommand(opts.dir, path, { cand: opts.cand, json: Boolean(opts.json) }));
67835
+ })).addCommand(new Command("set-reference").description("Point a component's comparison at something other than prod (a site the better component came from), and record WHY it diverges. Without this, an intentional improvement is reported as a defect on every run.").argument("<name>", "Component name (case- and separator-insensitive)").requiredOption("--note <why>", "Why this component diverges — required, not decoration").option("--url <url>", "Reference site base URL (default: the plan's prod URL)").option("--selector <sel>", "Selector on the reference site, when it differs").option("--dir <path>", "Directory holding migration-plan.json (default: the target repo's .parity/)", ".parity").action((name, opts) => {
67836
+ process.exit(planSetReferenceCommand(opts.dir, name, {
67837
+ url: opts.url,
67838
+ selector: opts.selector,
67839
+ note: opts.note
67840
+ }));
67841
+ })).addCommand(new Command("verify").description("Record that a component was actually compared against its reference. A `done` row with no verification only means the code exists.").argument("<name>", "Component name (case- and separator-insensitive)").argument("<verdict>", "pass | fail").option("--note <text>", "What was seen").option("--at <iso>", "Timestamp (default: now)").option("--dir <path>", "Directory holding migration-plan.json (default: the target repo's .parity/)", ".parity").action((name, verdict2, opts) => {
67842
+ process.exit(planVerifyCommand(opts.dir, name, verdict2, { note: opts.note, at: opts.at }));
67613
67843
  }));
67614
67844
  program.command("serve").argument("<runId>", "Run ID to serve").description("Spawns a local HTTP server that serves the report and proxies external iframes (strips X-Frame-Options/CSP), making the Side-by-side tab functional for any site.").option("--output <dir>", "Output directory where runs live", "./parity-output").option("--port <n>", "Fixed port (default: auto-pick free port)", (v) => Number(v)).option("--no-open", "Don't open the browser automatically").action(async (runId, opts) => {
67615
67845
  process.exit(await serveCommand(runId, opts));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decocms/parity",
3
- "version": "0.26.5",
3
+ "version": "0.26.7",
4
4
  "description": "E2E parity validator for site migrations. Compares prod vs cand and reports UI, functional, SEO, visual, and Web Vitals deltas with an LLM-ranked HTML report.",
5
5
  "type": "module",
6
6
  "license": "MIT",