@cmssy/codemod 11.9.0 → 12.1.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.
- package/dist/index.js +50 -7
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -292,24 +292,67 @@ function transform4(source) {
|
|
|
292
292
|
return notes.length > 0 ? { code, changed, notes } : { code, changed };
|
|
293
293
|
}
|
|
294
294
|
|
|
295
|
+
// src/v12.ts
|
|
296
|
+
var MEDIA_FIELD = /(\w+)\s*:\s*fields\s*\.\s*media\s*\(/g;
|
|
297
|
+
function mediaFieldNames(source) {
|
|
298
|
+
const names = /* @__PURE__ */ new Set();
|
|
299
|
+
MEDIA_FIELD.lastIndex = 0;
|
|
300
|
+
for (let match = MEDIA_FIELD.exec(source); match !== null; match = MEDIA_FIELD.exec(source)) {
|
|
301
|
+
if (match[1]) names.add(match[1]);
|
|
302
|
+
}
|
|
303
|
+
return [...names];
|
|
304
|
+
}
|
|
305
|
+
function usesOf(source, field) {
|
|
306
|
+
const uses = /* @__PURE__ */ new Set();
|
|
307
|
+
const reads = new RegExp(`\\b(\\w+)\\.${field}\\b`, "g");
|
|
308
|
+
for (let match = reads.exec(source); match !== null; match = reads.exec(source)) {
|
|
309
|
+
const line = source.slice(
|
|
310
|
+
source.lastIndexOf("\n", match.index) + 1,
|
|
311
|
+
(source.indexOf("\n", match.index) + 1 || source.length + 1) - 1
|
|
312
|
+
);
|
|
313
|
+
uses.add(line.trim());
|
|
314
|
+
}
|
|
315
|
+
return [...uses];
|
|
316
|
+
}
|
|
317
|
+
function transform5(source) {
|
|
318
|
+
const fields = mediaFieldNames(source);
|
|
319
|
+
if (fields.length === 0) return { code: source, changed: false };
|
|
320
|
+
const notes = [
|
|
321
|
+
`Media fields in this file: ${fields.join(", ")}.`,
|
|
322
|
+
"A media value is no longer the asset's URL. It reads back as { id, url, visibility, alt?, width?, height? }, and url is null for a private asset or one whose asset was deleted.",
|
|
323
|
+
"So `src={content.image}` becomes `src={content.image.url}` behind a null check, and a gallery is `content.gallery.map((one) => one.url)`.",
|
|
324
|
+
"alt arrives resolved for the locale being read - pass it to the img rather than writing your own."
|
|
325
|
+
];
|
|
326
|
+
for (const field of fields) {
|
|
327
|
+
const lines = usesOf(source, field);
|
|
328
|
+
if (lines.length > 0) {
|
|
329
|
+
notes.push(`Lines reading "${field}": ${lines.join(" | ")}`);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
return { code: source, changed: false, notes };
|
|
333
|
+
}
|
|
334
|
+
|
|
295
335
|
// src/index.ts
|
|
296
336
|
var TRANSFORMS = {
|
|
297
337
|
v5: transform,
|
|
298
338
|
v7: transform2,
|
|
299
339
|
v8: transform3,
|
|
300
|
-
v9: transform4
|
|
340
|
+
v9: transform4,
|
|
341
|
+
v12: transform5
|
|
301
342
|
};
|
|
302
343
|
var PREVIOUS_MAJOR = {
|
|
303
344
|
v5: "4.x",
|
|
304
345
|
v7: "6.x",
|
|
305
346
|
v8: "7.x",
|
|
306
|
-
v9: "8.x"
|
|
347
|
+
v9: "8.x",
|
|
348
|
+
v12: "11.x"
|
|
307
349
|
};
|
|
308
350
|
var MIGRATION_GUIDE = {
|
|
309
351
|
v5: "https://github.com/cmssy-io/cmssy-sdk/blob/main/docs/migrations/v4-to-v5.md",
|
|
310
352
|
v7: "https://github.com/cmssy-io/cmssy-sdk/blob/main/docs/migrations/v4-to-v5.md",
|
|
311
353
|
v8: "https://github.com/cmssy-io/cmssy-sdk/blob/main/docs/migrations/v7-to-v8.md",
|
|
312
|
-
v9: "https://github.com/cmssy-io/cmssy-sdk/blob/main/docs/migrations/v8-to-v9.md"
|
|
354
|
+
v9: "https://github.com/cmssy-io/cmssy-sdk/blob/main/docs/migrations/v8-to-v9.md",
|
|
355
|
+
v12: "https://github.com/cmssy-io/cmssy-sdk/blob/main/docs/migrations/v11-to-v12.md"
|
|
313
356
|
};
|
|
314
357
|
var SKIP = /* @__PURE__ */ new Set(["node_modules", "dist", "build", "out", "coverage"]);
|
|
315
358
|
var EXTENSIONS = [".ts", ".tsx", ".js", ".jsx", ".mjs"];
|
|
@@ -332,9 +375,9 @@ async function sourceFiles(dir) {
|
|
|
332
375
|
async function main() {
|
|
333
376
|
const args = process.argv.slice(2);
|
|
334
377
|
const version = args[0];
|
|
335
|
-
const
|
|
336
|
-
if (!
|
|
337
|
-
console.error("usage: cmssy-codemod v5|v7|v8|v9 [path] [--dry]");
|
|
378
|
+
const transform6 = TRANSFORMS[version];
|
|
379
|
+
if (!transform6) {
|
|
380
|
+
console.error("usage: cmssy-codemod v5|v7|v8|v9|v12 [path] [--dry]");
|
|
338
381
|
process.exitCode = 1;
|
|
339
382
|
return;
|
|
340
383
|
}
|
|
@@ -348,7 +391,7 @@ async function main() {
|
|
|
348
391
|
let needsCore = false;
|
|
349
392
|
for (const file of files) {
|
|
350
393
|
const source = await readFile(file, "utf8");
|
|
351
|
-
const { code, changed, notes } =
|
|
394
|
+
const { code, changed, notes } = transform6(source);
|
|
352
395
|
if (notes && notes.length > 0) manual.push({ file, notes });
|
|
353
396
|
if (!changed) continue;
|
|
354
397
|
touched.push(file);
|