@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 +68 -12
- package/dist/cli/bin.js.map +1 -1
- package/dist/index.js +68 -12
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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
|
|
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
|
-
|
|
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(
|
|
1212
|
+
const match = source.match(SCRIPT_BLOCK2);
|
|
1208
1213
|
if (!match) return source;
|
|
1209
|
-
const
|
|
1210
|
-
const
|
|
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(
|
|
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
|
|
@@ -1251,6 +1258,54 @@ function stateEffectSyncToDerived(source) {
|
|
|
1251
1258
|
});
|
|
1252
1259
|
}
|
|
1253
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
|
+
|
|
1254
1309
|
// src/recipes/svelte-5/step-gotchas.ts
|
|
1255
1310
|
var SVELTE_GLOBS = ["src/**/*.svelte"];
|
|
1256
1311
|
var IGNORE2 = ["node_modules/**", ".svelte-kit/**", "build/**"];
|
|
@@ -1258,7 +1313,8 @@ var CODEMODS = [
|
|
|
1258
1313
|
onEventToHandler,
|
|
1259
1314
|
exportLetToProps,
|
|
1260
1315
|
removeDollarRestProps,
|
|
1261
|
-
stateEffectSyncToDerived
|
|
1316
|
+
stateEffectSyncToDerived,
|
|
1317
|
+
dollarPropsClass
|
|
1262
1318
|
];
|
|
1263
1319
|
async function planGotchaCodemods(cwd) {
|
|
1264
1320
|
const changes = [];
|