@cmssy/codemod 14.2.0 → 16.0.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.
Files changed (2) hide show
  1. package/dist/index.js +61 -7
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -337,27 +337,81 @@ function transform5(source) {
337
337
  return { code: source, changed: false, notes };
338
338
  }
339
339
 
340
+ // src/v15.ts
341
+ var SLOT_COMPONENTS = [
342
+ "CmssyLayoutSlot",
343
+ "CmssyServerLayout",
344
+ "CmssyEditableLayout",
345
+ "CmssyLazyLayout"
346
+ ];
347
+ function renameSlotAttributes(source, component) {
348
+ const open = new RegExp(`<${component}\\b`, "g");
349
+ let out = "";
350
+ let last = 0;
351
+ for (let m = open.exec(source); m !== null; m = open.exec(source)) {
352
+ let i = m.index;
353
+ let depth = 0;
354
+ let quote = null;
355
+ let tag = "";
356
+ while (i < source.length) {
357
+ const ch = source[i];
358
+ if (quote) {
359
+ if (ch === quote) quote = null;
360
+ } else if (ch === '"' || ch === "'" || ch === "`") {
361
+ quote = ch;
362
+ } else if (ch === "{") {
363
+ depth += 1;
364
+ } else if (ch === "}") {
365
+ depth -= 1;
366
+ } else if (depth === 0) {
367
+ if (ch === ">") break;
368
+ if (source.startsWith("position=", i) && !/[\w$]/.test(source[i - 1] ?? "")) {
369
+ tag += "region=";
370
+ i += "position=".length;
371
+ continue;
372
+ }
373
+ }
374
+ tag += ch;
375
+ i += 1;
376
+ }
377
+ out += source.slice(last, m.index) + tag;
378
+ last = i;
379
+ open.lastIndex = i;
380
+ }
381
+ return out + source.slice(last);
382
+ }
383
+ function transform6(source) {
384
+ let code = source.replace(/\blayoutPositions\b/g, "layoutRegions");
385
+ for (const component of SLOT_COMPONENTS) {
386
+ code = renameSlotAttributes(code, component);
387
+ }
388
+ return { code, changed: code !== source };
389
+ }
390
+
340
391
  // src/index.ts
341
392
  var TRANSFORMS = {
342
393
  v5: transform,
343
394
  v7: transform2,
344
395
  v8: transform3,
345
396
  v9: transform4,
346
- v12: transform5
397
+ v12: transform5,
398
+ v15: transform6
347
399
  };
348
400
  var PREVIOUS_MAJOR = {
349
401
  v5: "4.x",
350
402
  v7: "6.x",
351
403
  v8: "7.x",
352
404
  v9: "8.x",
353
- v12: "11.x"
405
+ v12: "11.x",
406
+ v15: "14.x"
354
407
  };
355
408
  var MIGRATION_GUIDE = {
356
409
  v5: "https://github.com/cmssy-io/cmssy-sdk/blob/main/docs/migrations/v4-to-v5.md",
357
410
  v7: "https://github.com/cmssy-io/cmssy-sdk/blob/main/docs/migrations/v4-to-v5.md",
358
411
  v8: "https://github.com/cmssy-io/cmssy-sdk/blob/main/docs/migrations/v7-to-v8.md",
359
412
  v9: "https://github.com/cmssy-io/cmssy-sdk/blob/main/docs/migrations/v8-to-v9.md",
360
- v12: "https://github.com/cmssy-io/cmssy-sdk/blob/main/docs/migrations/v11-to-v12.md"
413
+ v12: "https://github.com/cmssy-io/cmssy-sdk/blob/main/docs/migrations/v11-to-v12.md",
414
+ v15: "https://github.com/cmssy-io/cmssy-sdk/blob/main/docs/migrations/v14-to-v15.md"
361
415
  };
362
416
  var SKIP = /* @__PURE__ */ new Set(["node_modules", "dist", "build", "out", "coverage"]);
363
417
  var EXTENSIONS = [".ts", ".tsx", ".js", ".jsx", ".mjs"];
@@ -380,9 +434,9 @@ async function sourceFiles(dir) {
380
434
  async function main() {
381
435
  const args = process.argv.slice(2);
382
436
  const version = args[0];
383
- const transform6 = TRANSFORMS[version];
384
- if (!transform6) {
385
- console.error("usage: cmssy-codemod v5|v7|v8|v9|v12 [path] [--dry]");
437
+ const transform7 = TRANSFORMS[version];
438
+ if (!transform7) {
439
+ console.error("usage: cmssy-codemod v5|v7|v8|v9|v12|v15 [path] [--dry]");
386
440
  process.exitCode = 1;
387
441
  return;
388
442
  }
@@ -396,7 +450,7 @@ async function main() {
396
450
  let needsCore = false;
397
451
  for (const file of files) {
398
452
  const source = await readFile(file, "utf8");
399
- const { code, changed, notes } = transform6(source);
453
+ const { code, changed, notes } = transform7(source);
400
454
  if (notes && notes.length > 0) manual.push({ file, notes });
401
455
  if (!changed) continue;
402
456
  touched.push(file);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmssy/codemod",
3
- "version": "14.2.0",
3
+ "version": "16.0.0",
4
4
  "description": "Rewrites cmssy imports across major versions, so a breaking release costs minutes instead of an afternoon.",
5
5
  "keywords": [
6
6
  "cmssy",