@next/codemod 13.5.6 → 13.5.7-canary.11
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,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
|