@reddoorla/maintenance 0.5.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/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { S as Site, a as AuditResult, A as AuditName, b as RecipeResult, R as RecipeName, I as InventoryProvider } from './sync-configs-CW3nKS_N.js';
2
- export { C as ConfigName, c as SyncConfigsOptions, s as syncConfigs } from './sync-configs-CW3nKS_N.js';
1
+ import { S as Site, a as AuditResult, A as AuditName, b as RecipeResult, R as RecipeName, I as InventoryProvider } from './sync-configs-DRmSAnfV.js';
2
+ export { C as ConfigName, c as SyncConfigsOptions, s as syncConfigs } from './sync-configs-DRmSAnfV.js';
3
3
 
4
4
  type SpawnResult = {
5
5
  code: number;
package/dist/index.js CHANGED
@@ -1177,9 +1177,9 @@ function onEventToHandler(source) {
1177
1177
  }
1178
1178
 
1179
1179
  // src/recipes/svelte-5/codemods/dollar-props.ts
1180
- var SCRIPT_TS = /<script\b[^>]*lang=["']ts["'][^>]*>([\s\S]*?)<\/script>/;
1180
+ var SCRIPT_BLOCK2 = /<script\b([^>]*)>([\s\S]*?)<\/script>/;
1181
1181
  var EXPORT_LET = /^\s*export\s+let\s+(\w+)\s*(?::\s*([^=;\n]+))?\s*(?:=\s*([^;\n]+))?;?\s*$/gm;
1182
- function transformScript(scriptBody) {
1182
+ function transformScript(scriptBody, isTs) {
1183
1183
  const props = [];
1184
1184
  const cleaned = scriptBody.replace(
1185
1185
  EXPORT_LET,
@@ -1193,23 +1193,30 @@ function transformScript(scriptBody) {
1193
1193
  }
1194
1194
  );
1195
1195
  if (props.length === 0) return { body: scriptBody, changed: false };
1196
- const typeSig = props.map((p) => {
1197
- const optional = p.defaultExpr ? "?" : "";
1198
- return `${p.name}${optional}: ${p.type ?? "unknown"}`;
1199
- }).join("; ");
1200
1196
  const destructured = props.map((p) => p.defaultExpr ? `${p.name} = ${p.defaultExpr}` : p.name).join(", ");
1201
- const decl = ` let { ${destructured} }: { ${typeSig} } = $props();`;
1197
+ let decl;
1198
+ if (isTs) {
1199
+ const typeSig = props.map((p) => {
1200
+ const optional = p.defaultExpr ? "?" : "";
1201
+ return `${p.name}${optional}: ${p.type ?? "unknown"}`;
1202
+ }).join("; ");
1203
+ decl = ` let { ${destructured} }: { ${typeSig} } = $props();`;
1204
+ } else {
1205
+ decl = ` let { ${destructured} } = $props();`;
1206
+ }
1202
1207
  const next = cleaned.replace(/^(\s*)/, (m) => `${m}${decl}
1203
1208
  `);
1204
1209
  return { body: next, changed: true };
1205
1210
  }
1206
1211
  function exportLetToProps(source) {
1207
- const match = source.match(SCRIPT_TS);
1212
+ const match = source.match(SCRIPT_BLOCK2);
1208
1213
  if (!match) return source;
1209
- const inner = match[1] ?? "";
1210
- const { body, changed } = transformScript(inner);
1214
+ const attrs = match[1] ?? "";
1215
+ const inner = match[2] ?? "";
1216
+ const isTs = /\blang=["']ts["']/.test(attrs);
1217
+ const { body, changed } = transformScript(inner, isTs);
1211
1218
  if (!changed) return source;
1212
- return source.replace(SCRIPT_TS, (full) => full.replace(inner, body));
1219
+ return source.replace(SCRIPT_BLOCK2, (full) => full.replace(inner, body));
1213
1220
  }
1214
1221
 
1215
1222
  // src/recipes/svelte-5/codemods/dollar-restprops.ts
@@ -1242,23 +1249,90 @@ function removeDollarRestProps(source) {
1242
1249
  return next;
1243
1250
  }
1244
1251
 
1252
+ // src/recipes/svelte-5/codemods/state-effect-sync.ts
1253
+ var PATTERN = /let\s+(\w+)\s*=\s*\$state\(\s*([^)]+?)\s*\)\s*;[ \t\r\n]*\$effect\(\s*\(\s*\)\s*=>\s*\{\s*\w+\s*;\s*\1\s*=\s*([^;}]+?)\s*\}\s*\)\s*;?/g;
1254
+ function stateEffectSyncToDerived(source) {
1255
+ return source.replace(PATTERN, (full, name, initExpr, effectExpr) => {
1256
+ if (initExpr.trim() !== effectExpr.trim()) return full;
1257
+ return `let ${name} = $derived(${initExpr.trim()});`;
1258
+ });
1259
+ }
1260
+
1261
+ // src/recipes/svelte-5/codemods/dollar-props-class.ts
1262
+ var PROPS_DESTRUCTURE = /let\s*\{([\s\S]*?)\}(\s*:\s*\{([\s\S]*?)\})?\s*=\s*\$props\(\)/;
1263
+ var DOLLAR_PROPS_CLASS = /\$\$props\.class\b/g;
1264
+ var DOLLAR_PROPS_ANY = /\$\$props\b/;
1265
+ var SCRIPT_BLOCK3 = /<script\b[^>]*>[\s\S]*?<\/script>/g;
1266
+ var MIGRATION_TASK = /^<!--\s*@migration-task[\s\S]*?-->\s*\n?/gm;
1267
+ var IDENT = "className";
1268
+ function maskScripts(source) {
1269
+ const blocks = [];
1270
+ const masked = source.replace(SCRIPT_BLOCK3, (m) => {
1271
+ blocks.push(m);
1272
+ return `__SCRIPT_${blocks.length - 1}__`;
1273
+ });
1274
+ return { masked, blocks };
1275
+ }
1276
+ function restoreScripts(masked, blocks) {
1277
+ let out = masked;
1278
+ blocks.forEach((blk, i) => {
1279
+ out = out.replace(`__SCRIPT_${i}__`, blk);
1280
+ });
1281
+ return out;
1282
+ }
1283
+ function dollarPropsClass(source) {
1284
+ const { masked } = maskScripts(source);
1285
+ if (!DOLLAR_PROPS_CLASS.test(masked)) return source;
1286
+ DOLLAR_PROPS_CLASS.lastIndex = 0;
1287
+ if (!PROPS_DESTRUCTURE.test(source)) return source;
1288
+ let updated = source.replace(PROPS_DESTRUCTURE, (full, body, typeAnno, typeBody) => {
1289
+ if (/\bclass\s*:/.test(body)) return full;
1290
+ const cleanBody = body.trim().replace(/,\s*$/, "").trim();
1291
+ const newBody = cleanBody ? `${cleanBody}, class: ${IDENT} = ""` : `class: ${IDENT} = ""`;
1292
+ if (typeAnno) {
1293
+ const cleanType = (typeBody ?? "").trim().replace(/;\s*$/, "").trim();
1294
+ const newType = cleanType ? `${cleanType}; class?: string` : `class?: string`;
1295
+ return `let { ${newBody} }: { ${newType} } = $props()`;
1296
+ }
1297
+ return `let { ${newBody} } = $props()`;
1298
+ });
1299
+ const reMasked = maskScripts(updated);
1300
+ const templateRewritten = reMasked.masked.replace(DOLLAR_PROPS_CLASS, IDENT);
1301
+ updated = restoreScripts(templateRewritten, reMasked.blocks);
1302
+ const stripped = updated.replace(MIGRATION_TASK, "");
1303
+ if (!DOLLAR_PROPS_ANY.test(stripped)) {
1304
+ updated = stripped;
1305
+ }
1306
+ return updated;
1307
+ }
1308
+
1245
1309
  // src/recipes/svelte-5/step-gotchas.ts
1246
1310
  var SVELTE_GLOBS = ["src/**/*.svelte"];
1247
1311
  var IGNORE2 = ["node_modules/**", ".svelte-kit/**", "build/**"];
1248
- var CODEMODS = [onEventToHandler, exportLetToProps, removeDollarRestProps];
1249
- async function applyGotchaCodemods(cwd) {
1250
- let filesChanged = 0;
1312
+ var CODEMODS = [
1313
+ onEventToHandler,
1314
+ exportLetToProps,
1315
+ removeDollarRestProps,
1316
+ stateEffectSyncToDerived,
1317
+ dollarPropsClass
1318
+ ];
1319
+ async function planGotchaCodemods(cwd) {
1320
+ const changes = [];
1251
1321
  const relPaths = await glob2(SVELTE_GLOBS, { cwd, ignore: IGNORE2, absolute: false });
1252
1322
  for (const rel of relPaths) {
1253
1323
  const path = join9(cwd, rel);
1254
1324
  const before = await readFile8(path, "utf-8");
1255
1325
  const after = CODEMODS.reduce((s, fn) => fn(s), before);
1256
- if (after !== before) {
1257
- await writeFile6(path, after, "utf-8");
1258
- filesChanged += 1;
1259
- }
1326
+ if (after !== before) changes.push({ rel, after });
1327
+ }
1328
+ return changes;
1329
+ }
1330
+ async function applyGotchaCodemods(cwd) {
1331
+ const changes = await planGotchaCodemods(cwd);
1332
+ for (const c of changes) {
1333
+ await writeFile6(join9(cwd, c.rel), c.after, "utf-8");
1260
1334
  }
1261
- return { filesChanged };
1335
+ return { filesChanged: changes.length };
1262
1336
  }
1263
1337
 
1264
1338
  // src/recipes/svelte-5/step-verify.ts