@reddoorla/maintenance 0.6.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli/bin.js CHANGED
@@ -1443,9 +1443,9 @@ function onEventToHandler(source) {
1443
1443
  }
1444
1444
 
1445
1445
  // src/recipes/svelte-5/codemods/dollar-props.ts
1446
- var SCRIPT_TS = /<script\b[^>]*lang=["']ts["'][^>]*>([\s\S]*?)<\/script>/;
1446
+ var SCRIPT_BLOCK2 = /<script\b([^>]*)>([\s\S]*?)<\/script>/;
1447
1447
  var EXPORT_LET = /^\s*export\s+let\s+(\w+)\s*(?::\s*([^=;\n]+))?\s*(?:=\s*([^;\n]+))?;?\s*$/gm;
1448
- function transformScript(scriptBody) {
1448
+ function transformScript(scriptBody, isTs) {
1449
1449
  const props = [];
1450
1450
  const cleaned = scriptBody.replace(
1451
1451
  EXPORT_LET,
@@ -1459,23 +1459,30 @@ function transformScript(scriptBody) {
1459
1459
  }
1460
1460
  );
1461
1461
  if (props.length === 0) return { body: scriptBody, changed: false };
1462
- const typeSig = props.map((p) => {
1463
- const optional = p.defaultExpr ? "?" : "";
1464
- return `${p.name}${optional}: ${p.type ?? "unknown"}`;
1465
- }).join("; ");
1466
1462
  const destructured = props.map((p) => p.defaultExpr ? `${p.name} = ${p.defaultExpr}` : p.name).join(", ");
1467
- const decl = ` let { ${destructured} }: { ${typeSig} } = $props();`;
1463
+ let decl;
1464
+ if (isTs) {
1465
+ const typeSig = props.map((p) => {
1466
+ const optional = p.defaultExpr ? "?" : "";
1467
+ return `${p.name}${optional}: ${p.type ?? "unknown"}`;
1468
+ }).join("; ");
1469
+ decl = ` let { ${destructured} }: { ${typeSig} } = $props();`;
1470
+ } else {
1471
+ decl = ` let { ${destructured} } = $props();`;
1472
+ }
1468
1473
  const next = cleaned.replace(/^(\s*)/, (m) => `${m}${decl}
1469
1474
  `);
1470
1475
  return { body: next, changed: true };
1471
1476
  }
1472
1477
  function exportLetToProps(source) {
1473
- const match = source.match(SCRIPT_TS);
1478
+ const match = source.match(SCRIPT_BLOCK2);
1474
1479
  if (!match) return source;
1475
- const inner = match[1] ?? "";
1476
- const { body, changed } = transformScript(inner);
1480
+ const attrs = match[1] ?? "";
1481
+ const inner = match[2] ?? "";
1482
+ const isTs = /\blang=["']ts["']/.test(attrs);
1483
+ const { body, changed } = transformScript(inner, isTs);
1477
1484
  if (!changed) return source;
1478
- return source.replace(SCRIPT_TS, (full) => full.replace(inner, body));
1485
+ return source.replace(SCRIPT_BLOCK2, (full) => full.replace(inner, body));
1479
1486
  }
1480
1487
 
1481
1488
  // src/recipes/svelte-5/codemods/dollar-restprops.ts
@@ -1517,6 +1524,54 @@ function stateEffectSyncToDerived(source) {
1517
1524
  });
1518
1525
  }
1519
1526
 
1527
+ // src/recipes/svelte-5/codemods/dollar-props-class.ts
1528
+ var PROPS_DESTRUCTURE = /let\s*\{([\s\S]*?)\}(\s*:\s*\{([\s\S]*?)\})?\s*=\s*\$props\(\)/;
1529
+ var DOLLAR_PROPS_CLASS = /\$\$props\.class\b/g;
1530
+ var DOLLAR_PROPS_ANY = /\$\$props\b/;
1531
+ var SCRIPT_BLOCK3 = /<script\b[^>]*>[\s\S]*?<\/script>/g;
1532
+ var MIGRATION_TASK = /^<!--\s*@migration-task[\s\S]*?-->\s*\n?/gm;
1533
+ var IDENT = "className";
1534
+ function maskScripts(source) {
1535
+ const blocks = [];
1536
+ const masked = source.replace(SCRIPT_BLOCK3, (m) => {
1537
+ blocks.push(m);
1538
+ return `__SCRIPT_${blocks.length - 1}__`;
1539
+ });
1540
+ return { masked, blocks };
1541
+ }
1542
+ function restoreScripts(masked, blocks) {
1543
+ let out = masked;
1544
+ blocks.forEach((blk, i) => {
1545
+ out = out.replace(`__SCRIPT_${i}__`, blk);
1546
+ });
1547
+ return out;
1548
+ }
1549
+ function dollarPropsClass(source) {
1550
+ const { masked } = maskScripts(source);
1551
+ if (!DOLLAR_PROPS_CLASS.test(masked)) return source;
1552
+ DOLLAR_PROPS_CLASS.lastIndex = 0;
1553
+ if (!PROPS_DESTRUCTURE.test(source)) return source;
1554
+ let updated = source.replace(PROPS_DESTRUCTURE, (full, body, typeAnno, typeBody) => {
1555
+ if (/\bclass\s*:/.test(body)) return full;
1556
+ const cleanBody = body.trim().replace(/,\s*$/, "").trim();
1557
+ const newBody = cleanBody ? `${cleanBody}, class: ${IDENT} = ""` : `class: ${IDENT} = ""`;
1558
+ if (typeAnno) {
1559
+ const cleanType = (typeBody ?? "").trim().replace(/;\s*$/, "").trim();
1560
+ const newType = cleanType ? `${cleanType}; class?: string` : `class?: string`;
1561
+ return `let { ${newBody} }: { ${newType} } = $props()`;
1562
+ }
1563
+ return `let { ${newBody} } = $props()`;
1564
+ });
1565
+ const reMasked = maskScripts(updated);
1566
+ const templateRewritten = reMasked.masked.replace(DOLLAR_PROPS_CLASS, IDENT);
1567
+ updated = restoreScripts(templateRewritten, reMasked.blocks);
1568
+ const stripped = updated.replace(MIGRATION_TASK, "");
1569
+ if (!DOLLAR_PROPS_ANY.test(stripped)) {
1570
+ updated = stripped;
1571
+ }
1572
+ return updated;
1573
+ }
1574
+
1520
1575
  // src/recipes/svelte-5/step-gotchas.ts
1521
1576
  var SVELTE_GLOBS = ["src/**/*.svelte"];
1522
1577
  var IGNORE2 = ["node_modules/**", ".svelte-kit/**", "build/**"];
@@ -1524,7 +1579,8 @@ var CODEMODS = [
1524
1579
  onEventToHandler,
1525
1580
  exportLetToProps,
1526
1581
  removeDollarRestProps,
1527
- stateEffectSyncToDerived
1582
+ stateEffectSyncToDerived,
1583
+ dollarPropsClass
1528
1584
  ];
1529
1585
  async function planGotchaCodemods(cwd) {
1530
1586
  const changes = [];