@next/codemod 13.5.7-canary.9 → 14.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.
package/package.json
CHANGED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function transformer(file, api) {
|
|
4
|
+
const j = api.jscodeshift;
|
|
5
|
+
const root = j(file.source);
|
|
6
|
+
// Find the metadata export
|
|
7
|
+
const metadataExport = root.find(j.ExportNamedDeclaration, {
|
|
8
|
+
declaration: {
|
|
9
|
+
type: 'VariableDeclaration',
|
|
10
|
+
declarations: [
|
|
11
|
+
{
|
|
12
|
+
id: { name: 'metadata' },
|
|
13
|
+
},
|
|
14
|
+
],
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
if (metadataExport.size() !== 1) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const metadataObject = metadataExport.find(j.ObjectExpression).get(0).node;
|
|
21
|
+
if (!metadataObject) {
|
|
22
|
+
console.error('Could not find metadata object');
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
let metadataProperties = metadataObject.properties;
|
|
26
|
+
let viewportProperties;
|
|
27
|
+
const viewport = metadataProperties.find((prop) => prop.key.name === 'viewport');
|
|
28
|
+
if (viewport) {
|
|
29
|
+
viewportProperties = viewport.value.properties;
|
|
30
|
+
metadataProperties = metadataProperties.filter((prop) => prop.key.name !== 'viewport');
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
viewportProperties = [];
|
|
34
|
+
}
|
|
35
|
+
const colorScheme = metadataProperties.find((prop) => prop.key.name === 'colorScheme');
|
|
36
|
+
if (colorScheme) {
|
|
37
|
+
viewportProperties.push(colorScheme);
|
|
38
|
+
metadataProperties = metadataProperties.filter((prop) => prop.key.name !== 'colorScheme');
|
|
39
|
+
}
|
|
40
|
+
const themeColor = metadataProperties.find((prop) => prop.key.name === 'themeColor');
|
|
41
|
+
if (themeColor) {
|
|
42
|
+
viewportProperties.push(themeColor);
|
|
43
|
+
metadataProperties = metadataProperties.filter((prop) => prop.key.name !== 'themeColor');
|
|
44
|
+
}
|
|
45
|
+
// Update the metadata export
|
|
46
|
+
metadataExport
|
|
47
|
+
.find(j.ObjectExpression)
|
|
48
|
+
.replaceWith(j.objectExpression(metadataProperties));
|
|
49
|
+
// Create the new viewport object
|
|
50
|
+
const viewportExport = j.exportNamedDeclaration(j.variableDeclaration('const', [
|
|
51
|
+
j.variableDeclarator(j.identifier('viewport'), j.objectExpression(viewportProperties)),
|
|
52
|
+
]));
|
|
53
|
+
// Append the viewport export to the body of the program
|
|
54
|
+
if (viewportProperties.length) {
|
|
55
|
+
root.get().node.program.body.push(viewportExport);
|
|
56
|
+
}
|
|
57
|
+
return root.toSource();
|
|
58
|
+
}
|
|
59
|
+
exports.default = transformer;
|
|
60
|
+
//# sourceMappingURL=metadata-to-viewport-export.js.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const importToChange = 'ImageResponse';
|
|
4
|
+
function transformer(file, api) {
|
|
5
|
+
const j = api.jscodeshift;
|
|
6
|
+
// Find import declarations that match the pattern
|
|
7
|
+
file.source = j(file.source)
|
|
8
|
+
.find(j.ImportDeclaration, {
|
|
9
|
+
source: {
|
|
10
|
+
value: 'next/server',
|
|
11
|
+
},
|
|
12
|
+
})
|
|
13
|
+
.forEach((path) => {
|
|
14
|
+
const importSpecifiers = path.node.specifiers;
|
|
15
|
+
const importNamesToChange = importSpecifiers.filter((specifier) => specifier.local.name === importToChange);
|
|
16
|
+
const importsNamesRemained = importSpecifiers.filter((specifier) => specifier.local.name !== importToChange);
|
|
17
|
+
// If the import includes the specified import name, create a new import for it from 'next/og'
|
|
18
|
+
if (importNamesToChange.length > 0) {
|
|
19
|
+
// Replace the original import with the remaining specifiers
|
|
20
|
+
// path.node.specifiers = remainingSpecifiers
|
|
21
|
+
const newImportStatement = j.importDeclaration(importNamesToChange, j.stringLiteral('next/og'));
|
|
22
|
+
path.insertBefore(newImportStatement);
|
|
23
|
+
}
|
|
24
|
+
if (importsNamesRemained.length > 0) {
|
|
25
|
+
const remainingSpecifiers = importSpecifiers.filter((specifier) => specifier.local.name !== importToChange);
|
|
26
|
+
const nextServerRemainImportsStatement = j.importDeclaration(remainingSpecifiers, j.stringLiteral('next/server'));
|
|
27
|
+
path.insertBefore(nextServerRemainImportsStatement);
|
|
28
|
+
}
|
|
29
|
+
j(path).remove();
|
|
30
|
+
})
|
|
31
|
+
.toSource();
|
|
32
|
+
return file.source;
|
|
33
|
+
}
|
|
34
|
+
exports.default = transformer;
|
|
35
|
+
//# sourceMappingURL=next-og-import.js.map
|