@next/codemod 15.0.0-canary.17 → 15.0.0-canary.170
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/bin/next-codemod.js +27 -3
- package/bin/transform.js +104 -0
- package/bin/upgrade.js +224 -0
- package/lib/codemods.js +103 -0
- package/lib/cra-to-next/global-css-transform.js +2 -3
- package/lib/cra-to-next/index-to-component.js +2 -3
- package/lib/handle-package.js +76 -0
- package/lib/install.js +2 -3
- package/lib/run-jscodeshift.js +9 -2
- package/lib/utils.js +92 -0
- package/package.json +8 -5
- package/transforms/add-missing-react-import.js +1 -1
- package/transforms/built-in-next-font.js +1 -1
- package/transforms/cra-to-next.js +238 -236
- package/transforms/lib/async-request-api/index.js +21 -0
- package/transforms/lib/async-request-api/next-async-dynamic-api.js +221 -0
- package/transforms/lib/async-request-api/next-async-dynamic-prop.js +345 -0
- package/transforms/lib/async-request-api/utils.js +198 -0
- package/transforms/metadata-to-viewport-export.js +1 -1
- package/transforms/name-default-component.js +3 -4
- package/transforms/new-link.js +5 -4
- package/transforms/next-async-request-api.js +9 -0
- package/transforms/next-dynamic-access-named-export.js +65 -0
- package/transforms/next-image-experimental.js +9 -13
- package/transforms/next-image-to-legacy-image.js +5 -7
- package/transforms/next-og-import.js +1 -1
- package/transforms/next-request-geo-ip.js +338 -0
- package/transforms/url-to-withrouter.js +1 -1
- package/transforms/withamp-to-config.js +1 -1
- package/bin/cli.js +0 -216
- package/lib/uninstall-package.js +0 -32
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TARGET_PROP_NAMES = exports.TARGET_NAMED_EXPORTS = void 0;
|
|
4
|
+
exports.isFunctionType = isFunctionType;
|
|
5
|
+
exports.isMatchedFunctionExported = isMatchedFunctionExported;
|
|
6
|
+
exports.determineClientDirective = determineClientDirective;
|
|
7
|
+
exports.isPromiseType = isPromiseType;
|
|
8
|
+
exports.turnFunctionReturnTypeToAsync = turnFunctionReturnTypeToAsync;
|
|
9
|
+
exports.insertReactUseImport = insertReactUseImport;
|
|
10
|
+
exports.generateUniqueIdentifier = generateUniqueIdentifier;
|
|
11
|
+
exports.TARGET_NAMED_EXPORTS = new Set([
|
|
12
|
+
// For custom route
|
|
13
|
+
'GET',
|
|
14
|
+
'HEAD',
|
|
15
|
+
'POST',
|
|
16
|
+
'PUT',
|
|
17
|
+
'DELETE',
|
|
18
|
+
'PATCH',
|
|
19
|
+
'OPTIONS',
|
|
20
|
+
// For page and layout
|
|
21
|
+
'generateMetadata',
|
|
22
|
+
]);
|
|
23
|
+
exports.TARGET_PROP_NAMES = new Set(['params', 'searchParams']);
|
|
24
|
+
function isFunctionType(type) {
|
|
25
|
+
return (type === 'FunctionDeclaration' ||
|
|
26
|
+
type === 'FunctionExpression' ||
|
|
27
|
+
type === 'ArrowFunctionExpression');
|
|
28
|
+
}
|
|
29
|
+
function isMatchedFunctionExported(path, j) {
|
|
30
|
+
const matchedFunctionNameFilter = (idName) => exports.TARGET_NAMED_EXPORTS.has(idName);
|
|
31
|
+
const directNamedExport = j(path).closest(j.ExportNamedDeclaration, {
|
|
32
|
+
declaration: {
|
|
33
|
+
type: 'FunctionDeclaration',
|
|
34
|
+
id: {
|
|
35
|
+
name: matchedFunctionNameFilter,
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
if (directNamedExport.size() > 0) {
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
// Check for default export (`export default function() {}`)
|
|
43
|
+
const isDefaultExport = j(path).closest(j.ExportDefaultDeclaration).size() > 0;
|
|
44
|
+
if (isDefaultExport) {
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
// Look for named export elsewhere in the file (`export { <named> }`)
|
|
48
|
+
const root = j(path).closestScope().closest(j.Program);
|
|
49
|
+
const isNamedExport = root
|
|
50
|
+
.find(j.ExportNamedDeclaration, {
|
|
51
|
+
specifiers: [
|
|
52
|
+
{
|
|
53
|
+
type: 'ExportSpecifier',
|
|
54
|
+
exported: {
|
|
55
|
+
name: matchedFunctionNameFilter,
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
})
|
|
60
|
+
.size() > 0;
|
|
61
|
+
// Look for variable export but still function, e.g. `export const <named> = function() {}`,
|
|
62
|
+
// also check if variable is a function or arrow function
|
|
63
|
+
const isVariableExport = root
|
|
64
|
+
.find(j.ExportNamedDeclaration, {
|
|
65
|
+
declaration: {
|
|
66
|
+
declarations: [
|
|
67
|
+
{
|
|
68
|
+
type: 'VariableDeclarator',
|
|
69
|
+
id: {
|
|
70
|
+
type: 'Identifier',
|
|
71
|
+
name: matchedFunctionNameFilter,
|
|
72
|
+
},
|
|
73
|
+
init: {
|
|
74
|
+
type: isFunctionType,
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
},
|
|
79
|
+
})
|
|
80
|
+
.size() > 0;
|
|
81
|
+
if (isVariableExport)
|
|
82
|
+
return true;
|
|
83
|
+
return isNamedExport;
|
|
84
|
+
}
|
|
85
|
+
function determineClientDirective(root, j, source) {
|
|
86
|
+
const hasStringDirective = root
|
|
87
|
+
.find(j.Literal)
|
|
88
|
+
.filter((path) => {
|
|
89
|
+
const expr = path.node;
|
|
90
|
+
return (expr.value === 'use client' && path.parentPath.node.type === 'Program');
|
|
91
|
+
})
|
|
92
|
+
.size() > 0;
|
|
93
|
+
// 'use client';
|
|
94
|
+
const hasStringDirectiveWithSemicolon = root
|
|
95
|
+
.find(j.StringLiteral)
|
|
96
|
+
.filter((path) => {
|
|
97
|
+
const expr = path.node;
|
|
98
|
+
return (expr.type === 'StringLiteral' &&
|
|
99
|
+
expr.value === 'use client' &&
|
|
100
|
+
path.parentPath.node.type === 'Program');
|
|
101
|
+
})
|
|
102
|
+
.size() > 0;
|
|
103
|
+
if (hasStringDirective || hasStringDirectiveWithSemicolon)
|
|
104
|
+
return true;
|
|
105
|
+
// Since the client detection is not reliable with AST in jscodeshift,
|
|
106
|
+
// determine if 'use client' or "use client" is leading in the source code.
|
|
107
|
+
const trimmedSource = source.trim();
|
|
108
|
+
const containsClientDirective = /^'use client'/.test(trimmedSource) || /^"use client"/g.test(trimmedSource);
|
|
109
|
+
return containsClientDirective;
|
|
110
|
+
}
|
|
111
|
+
function isPromiseType(typeAnnotation) {
|
|
112
|
+
return (typeAnnotation.type === 'TSTypeReference' &&
|
|
113
|
+
typeAnnotation.typeName.name === 'Promise');
|
|
114
|
+
}
|
|
115
|
+
function turnFunctionReturnTypeToAsync(node, j) {
|
|
116
|
+
if (j.FunctionDeclaration.check(node) ||
|
|
117
|
+
j.FunctionExpression.check(node) ||
|
|
118
|
+
j.ArrowFunctionExpression.check(node)) {
|
|
119
|
+
if (node.returnType) {
|
|
120
|
+
const returnTypeAnnotation = node.returnType.typeAnnotation;
|
|
121
|
+
const isReturnTypePromise = isPromiseType(returnTypeAnnotation);
|
|
122
|
+
// Turn <return type> to Promise<return type>
|
|
123
|
+
// e.g. () => { slug: string } to () => Promise<{ slug: string }>
|
|
124
|
+
// e.g. Anything to Promise<Anything>
|
|
125
|
+
if (!isReturnTypePromise) {
|
|
126
|
+
if (node.returnType &&
|
|
127
|
+
j.TSTypeAnnotation.check(node.returnType) &&
|
|
128
|
+
(j.TSTypeReference.check(node.returnType.typeAnnotation) ||
|
|
129
|
+
j.TSUnionType.check(node.returnType.typeAnnotation) ||
|
|
130
|
+
j.TSTypePredicate.check(node.returnType.typeAnnotation))) {
|
|
131
|
+
// Change the return type to Promise<void>
|
|
132
|
+
node.returnType.typeAnnotation = j.tsTypeReference(j.identifier('Promise'),
|
|
133
|
+
// @ts-ignore ignore the super strict type checking on the type annotation
|
|
134
|
+
j.tsTypeParameterInstantiation([returnTypeAnnotation]));
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
function insertReactUseImport(root, j) {
|
|
141
|
+
const hasReactUseImport = root
|
|
142
|
+
.find(j.ImportSpecifier, {
|
|
143
|
+
imported: {
|
|
144
|
+
type: 'Identifier',
|
|
145
|
+
name: 'use',
|
|
146
|
+
},
|
|
147
|
+
})
|
|
148
|
+
.size() > 0;
|
|
149
|
+
if (!hasReactUseImport) {
|
|
150
|
+
const reactImportDeclaration = root.find(j.ImportDeclaration, {
|
|
151
|
+
source: {
|
|
152
|
+
type: 'Literal',
|
|
153
|
+
value: 'react',
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
if (reactImportDeclaration.size() > 0) {
|
|
157
|
+
// Add 'use' to existing 'react' import declaration
|
|
158
|
+
reactImportDeclaration
|
|
159
|
+
.get()
|
|
160
|
+
.node.specifiers.push(j.importSpecifier(j.identifier('use')));
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
// Final all type imports to 'react'
|
|
164
|
+
const reactImport = root.find(j.ImportDeclaration, {
|
|
165
|
+
source: {
|
|
166
|
+
type: 'Literal',
|
|
167
|
+
value: 'react',
|
|
168
|
+
},
|
|
169
|
+
});
|
|
170
|
+
if (reactImport.size() > 0) {
|
|
171
|
+
reactImport
|
|
172
|
+
.get()
|
|
173
|
+
.node.specifiers.push(j.importSpecifier(j.identifier('use')));
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
// Add new import declaration for 'react' and 'use'
|
|
177
|
+
root
|
|
178
|
+
.get()
|
|
179
|
+
.node.program.body.unshift(j.importDeclaration([j.importSpecifier(j.identifier('use'))], j.literal('react')));
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
function findSubScopeArgumentIdentifier(path, j, argName) {
|
|
185
|
+
const defCount = j(path).find(j.Identifier, { name: argName }).size();
|
|
186
|
+
return defCount > 0;
|
|
187
|
+
}
|
|
188
|
+
function generateUniqueIdentifier(defaultIdName, path, j) {
|
|
189
|
+
let idName = defaultIdName;
|
|
190
|
+
let idNameSuffix = 0;
|
|
191
|
+
while (findSubScopeArgumentIdentifier(path, j, idName)) {
|
|
192
|
+
idName = defaultIdName + idNameSuffix;
|
|
193
|
+
idNameSuffix++;
|
|
194
|
+
}
|
|
195
|
+
const propsIdentifier = j.identifier(idName);
|
|
196
|
+
return propsIdentifier;
|
|
197
|
+
}
|
|
198
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = transformer;
|
|
3
4
|
function transformer(file, api) {
|
|
4
5
|
const j = api.jscodeshift;
|
|
5
6
|
const root = j(file.source);
|
|
@@ -56,5 +57,4 @@ function transformer(file, api) {
|
|
|
56
57
|
}
|
|
57
58
|
return root.toSource();
|
|
58
59
|
}
|
|
59
|
-
exports.default = transformer;
|
|
60
60
|
//# sourceMappingURL=metadata-to-viewport-export.js.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = transformer;
|
|
3
4
|
const path_1 = require("path");
|
|
4
5
|
const camelCase = (value) => {
|
|
5
6
|
const val = value.replace(/[-_\s.]+(.)?/g, (_match, chr) => chr ? chr.toUpperCase() : '');
|
|
@@ -14,11 +15,10 @@ function transformer(file, api, options) {
|
|
|
14
15
|
(node.type === 'BlockStatement' &&
|
|
15
16
|
j(node)
|
|
16
17
|
.find(j.ReturnStatement)
|
|
17
|
-
.some((path) =>
|
|
18
|
+
.some((path) => path.value.argument?.type === 'JSXElement'));
|
|
18
19
|
const hasRootAsParent = (path) => {
|
|
19
|
-
var _a;
|
|
20
20
|
const program = path.parentPath.parentPath.parentPath.parentPath.parentPath;
|
|
21
|
-
return !program ||
|
|
21
|
+
return !program || program?.value?.type === 'Program';
|
|
22
22
|
};
|
|
23
23
|
const nameFunctionComponent = (path) => {
|
|
24
24
|
const node = path.value;
|
|
@@ -62,5 +62,4 @@ function transformer(file, api, options) {
|
|
|
62
62
|
root.find(j.ExportDefaultDeclaration).forEach(nameFunctionComponent);
|
|
63
63
|
return hasModifications ? root.toSource(options) : null;
|
|
64
64
|
}
|
|
65
|
-
exports.default = transformer;
|
|
66
65
|
//# sourceMappingURL=name-default-component.js.map
|
package/transforms/new-link.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// It might insert extra parnes for JSX components
|
|
3
|
+
// x-ref: https://github.com/facebook/jscodeshift/issues/534
|
|
2
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.default = transformer;
|
|
3
6
|
function transformer(file, api) {
|
|
4
7
|
const j = api.jscodeshift.withParser('tsx');
|
|
5
8
|
const $j = j(file.source);
|
|
@@ -68,11 +71,10 @@ function transformer(file, api) {
|
|
|
68
71
|
// Add only unique props to <Link> (skip duplicate props)
|
|
69
72
|
const linkPropNames = $link
|
|
70
73
|
.get('attributes')
|
|
71
|
-
.value.map((linkProp) =>
|
|
74
|
+
.value.map((linkProp) => linkProp?.name?.name);
|
|
72
75
|
const uniqueProps = [];
|
|
73
76
|
props.forEach((anchorProp) => {
|
|
74
|
-
|
|
75
|
-
if (!linkPropNames.includes((_a = anchorProp === null || anchorProp === void 0 ? void 0 : anchorProp.name) === null || _a === void 0 ? void 0 : _a.name)) {
|
|
77
|
+
if (!linkPropNames.includes(anchorProp?.name?.name)) {
|
|
76
78
|
uniqueProps.push(anchorProp);
|
|
77
79
|
}
|
|
78
80
|
});
|
|
@@ -86,5 +88,4 @@ function transformer(file, api) {
|
|
|
86
88
|
})
|
|
87
89
|
.toSource();
|
|
88
90
|
}
|
|
89
|
-
exports.default = transformer;
|
|
90
91
|
//# sourceMappingURL=new-link.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var index_1 = require("./lib/async-request-api/index");
|
|
8
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(index_1).default; } });
|
|
9
|
+
//# sourceMappingURL=next-async-request-api.js.map
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = transformer;
|
|
4
|
+
function transformer(file, api) {
|
|
5
|
+
const j = api.jscodeshift;
|
|
6
|
+
const root = j(file.source);
|
|
7
|
+
// Find the import declaration for 'next/dynamic'
|
|
8
|
+
const dynamicImportDeclaration = root.find(j.ImportDeclaration, {
|
|
9
|
+
source: { value: 'next/dynamic' },
|
|
10
|
+
});
|
|
11
|
+
// If the import declaration is found
|
|
12
|
+
if (dynamicImportDeclaration.size() > 0) {
|
|
13
|
+
const importDecl = dynamicImportDeclaration.get(0).node;
|
|
14
|
+
const dynamicImportName = importDecl.specifiers?.[0]?.local?.name;
|
|
15
|
+
if (!dynamicImportName) {
|
|
16
|
+
return root.toSource();
|
|
17
|
+
}
|
|
18
|
+
// Find call expressions where the callee is the imported 'dynamic'
|
|
19
|
+
root
|
|
20
|
+
.find(j.CallExpression, {
|
|
21
|
+
callee: { name: dynamicImportName },
|
|
22
|
+
})
|
|
23
|
+
.forEach((path) => {
|
|
24
|
+
const arrowFunction = path.node.arguments[0];
|
|
25
|
+
// Ensure the argument is an ArrowFunctionExpression
|
|
26
|
+
if (arrowFunction && arrowFunction.type === 'ArrowFunctionExpression') {
|
|
27
|
+
const importCall = arrowFunction.body;
|
|
28
|
+
// Ensure the parent of the import call is a CallExpression with a .then
|
|
29
|
+
if (importCall &&
|
|
30
|
+
importCall.type === 'CallExpression' &&
|
|
31
|
+
importCall.callee.type === 'MemberExpression' &&
|
|
32
|
+
'name' in importCall.callee.property &&
|
|
33
|
+
importCall.callee.property.name === 'then') {
|
|
34
|
+
const thenFunction = importCall.arguments[0];
|
|
35
|
+
// handle case of block statement case `=> { return mod.Component }`
|
|
36
|
+
// transform to`=> { return { default: mod.Component } }`
|
|
37
|
+
if (thenFunction &&
|
|
38
|
+
thenFunction.type === 'ArrowFunctionExpression' &&
|
|
39
|
+
thenFunction.body.type === 'BlockStatement') {
|
|
40
|
+
const returnStatement = thenFunction.body.body[0];
|
|
41
|
+
// Ensure the body of the arrow function has a return statement with a MemberExpression
|
|
42
|
+
if (returnStatement &&
|
|
43
|
+
returnStatement.type === 'ReturnStatement' &&
|
|
44
|
+
returnStatement.argument?.type === 'MemberExpression') {
|
|
45
|
+
returnStatement.argument = j.objectExpression([
|
|
46
|
+
j.property('init', j.identifier('default'), returnStatement.argument),
|
|
47
|
+
]);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
// handle case `=> mod.Component`
|
|
51
|
+
// transform to`=> ({ default: mod.Component })`
|
|
52
|
+
if (thenFunction &&
|
|
53
|
+
thenFunction.type === 'ArrowFunctionExpression' &&
|
|
54
|
+
thenFunction.body.type === 'MemberExpression') {
|
|
55
|
+
thenFunction.body = j.objectExpression([
|
|
56
|
+
j.property('init', j.identifier('default'), thenFunction.body),
|
|
57
|
+
]);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return root.toSource();
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=next-dynamic-access-named-export.js.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = transformer;
|
|
3
4
|
const path_1 = require("path");
|
|
4
5
|
const fs_1 = require("fs");
|
|
5
6
|
function findAndReplaceProps(j, root, tagName) {
|
|
@@ -21,14 +22,12 @@ function findAndReplaceProps(j, root, tagName) {
|
|
|
21
22
|
el.value.openingElement.name.type === 'JSXIdentifier' &&
|
|
22
23
|
el.value.openingElement.name.name === tagName)
|
|
23
24
|
.forEach((el) => {
|
|
24
|
-
var _a;
|
|
25
25
|
let layout = 'intrinsic';
|
|
26
26
|
let objectFit = null;
|
|
27
27
|
let objectPosition = null;
|
|
28
28
|
let styleExpProps = [];
|
|
29
29
|
let sizesAttr = null;
|
|
30
|
-
const attributes =
|
|
31
|
-
var _a, _b;
|
|
30
|
+
const attributes = el.node.openingElement.attributes?.filter((a) => {
|
|
32
31
|
if (a.type !== 'JSXAttribute') {
|
|
33
32
|
return true;
|
|
34
33
|
}
|
|
@@ -51,11 +50,11 @@ function findAndReplaceProps(j, root, tagName) {
|
|
|
51
50
|
return false;
|
|
52
51
|
}
|
|
53
52
|
if (a.name.name === 'style') {
|
|
54
|
-
if (
|
|
53
|
+
if (a.value?.type === 'JSXExpressionContainer' &&
|
|
55
54
|
a.value.expression.type === 'ObjectExpression') {
|
|
56
55
|
styleExpProps = a.value.expression.properties;
|
|
57
56
|
}
|
|
58
|
-
else if (
|
|
57
|
+
else if (a.value?.type === 'JSXExpressionContainer' &&
|
|
59
58
|
a.value.expression.type === 'Identifier') {
|
|
60
59
|
styleExpProps = [
|
|
61
60
|
j.spreadElement(j.identifier(a.value.expression.name)),
|
|
@@ -208,9 +207,8 @@ function transformer(file, api, options) {
|
|
|
208
207
|
source: { value: 'next/legacy/image' },
|
|
209
208
|
})
|
|
210
209
|
.forEach((imageImport) => {
|
|
211
|
-
|
|
212
|
-
const
|
|
213
|
-
const tagName = (_b = defaultSpecifier === null || defaultSpecifier === void 0 ? void 0 : defaultSpecifier.local) === null || _b === void 0 ? void 0 : _b.name;
|
|
210
|
+
const defaultSpecifier = imageImport.node.specifiers?.find((node) => node.type === 'ImportDefaultSpecifier');
|
|
211
|
+
const tagName = defaultSpecifier?.local?.name;
|
|
214
212
|
imageImport.node.source = j.stringLiteral('next/image');
|
|
215
213
|
if (tagName) {
|
|
216
214
|
findAndReplaceProps(j, root, tagName);
|
|
@@ -220,7 +218,7 @@ function transformer(file, api, options) {
|
|
|
220
218
|
// After: const Image = await import("next/image")
|
|
221
219
|
root.find(j.AwaitExpression).forEach((awaitExp) => {
|
|
222
220
|
const arg = awaitExp.value.argument;
|
|
223
|
-
if (
|
|
221
|
+
if (arg?.type === 'CallExpression' && arg.callee.type === 'Import') {
|
|
224
222
|
if (arg.arguments[0].type === 'StringLiteral' &&
|
|
225
223
|
arg.arguments[0].value === 'next/legacy/image') {
|
|
226
224
|
arg.arguments[0] = j.stringLiteral('next/image');
|
|
@@ -230,14 +228,13 @@ function transformer(file, api, options) {
|
|
|
230
228
|
// Before: const Image = require("next/legacy/image")
|
|
231
229
|
// After: const Image = require("next/image")
|
|
232
230
|
root.find(j.CallExpression).forEach((requireExp) => {
|
|
233
|
-
|
|
234
|
-
if (((_b = (_a = requireExp === null || requireExp === void 0 ? void 0 : requireExp.value) === null || _a === void 0 ? void 0 : _a.callee) === null || _b === void 0 ? void 0 : _b.type) === 'Identifier' &&
|
|
231
|
+
if (requireExp?.value?.callee?.type === 'Identifier' &&
|
|
235
232
|
requireExp.value.callee.name === 'require') {
|
|
236
233
|
let firstArg = requireExp.value.arguments[0];
|
|
237
234
|
if (firstArg &&
|
|
238
235
|
firstArg.type === 'StringLiteral' &&
|
|
239
236
|
firstArg.value === 'next/legacy/image') {
|
|
240
|
-
const tagName =
|
|
237
|
+
const tagName = requireExp?.parentPath?.value?.id?.name;
|
|
241
238
|
if (tagName) {
|
|
242
239
|
requireExp.value.arguments[0] = j.stringLiteral('next/image');
|
|
243
240
|
findAndReplaceProps(j, root, tagName);
|
|
@@ -248,5 +245,4 @@ function transformer(file, api, options) {
|
|
|
248
245
|
// TODO: do the same transforms for dynamic imports
|
|
249
246
|
return root.toSource(options);
|
|
250
247
|
}
|
|
251
|
-
exports.default = transformer;
|
|
252
248
|
//# sourceMappingURL=next-image-experimental.js.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = transformer;
|
|
3
4
|
function transformer(file, api, options) {
|
|
4
5
|
const j = api.jscodeshift.withParser('tsx');
|
|
5
6
|
const root = j(file.source);
|
|
@@ -16,7 +17,7 @@ function transformer(file, api, options) {
|
|
|
16
17
|
// After: const Image = await import("next/legacy/image")
|
|
17
18
|
root.find(j.AwaitExpression).forEach((awaitExp) => {
|
|
18
19
|
const arg = awaitExp.value.argument;
|
|
19
|
-
if (
|
|
20
|
+
if (arg?.type === 'CallExpression' && arg.callee.type === 'Import') {
|
|
20
21
|
if (arg.arguments[0].type === 'StringLiteral' &&
|
|
21
22
|
arg.arguments[0].value === 'next/image') {
|
|
22
23
|
arg.arguments[0] = j.stringLiteral('next/legacy/image');
|
|
@@ -36,7 +37,7 @@ function transformer(file, api, options) {
|
|
|
36
37
|
// After: const Image = await import("next/image")
|
|
37
38
|
root.find(j.AwaitExpression).forEach((awaitExp) => {
|
|
38
39
|
const arg = awaitExp.value.argument;
|
|
39
|
-
if (
|
|
40
|
+
if (arg?.type === 'CallExpression' && arg.callee.type === 'Import') {
|
|
40
41
|
if (arg.arguments[0].type === 'StringLiteral' &&
|
|
41
42
|
arg.arguments[0].value === 'next/future/image') {
|
|
42
43
|
arg.arguments[0] = j.stringLiteral('next/image');
|
|
@@ -46,8 +47,7 @@ function transformer(file, api, options) {
|
|
|
46
47
|
// Before: const Image = require("next/image")
|
|
47
48
|
// After: const Image = require("next/legacy/image")
|
|
48
49
|
root.find(j.CallExpression).forEach((requireExp) => {
|
|
49
|
-
|
|
50
|
-
if (((_b = (_a = requireExp === null || requireExp === void 0 ? void 0 : requireExp.value) === null || _a === void 0 ? void 0 : _a.callee) === null || _b === void 0 ? void 0 : _b.type) === 'Identifier' &&
|
|
50
|
+
if (requireExp?.value?.callee?.type === 'Identifier' &&
|
|
51
51
|
requireExp.value.callee.name === 'require') {
|
|
52
52
|
let firstArg = requireExp.value.arguments[0];
|
|
53
53
|
if (firstArg &&
|
|
@@ -60,8 +60,7 @@ function transformer(file, api, options) {
|
|
|
60
60
|
// Before: const Image = require("next/future/image")
|
|
61
61
|
// After: const Image = require("next/image")
|
|
62
62
|
root.find(j.CallExpression).forEach((requireExp) => {
|
|
63
|
-
|
|
64
|
-
if (((_b = (_a = requireExp === null || requireExp === void 0 ? void 0 : requireExp.value) === null || _a === void 0 ? void 0 : _a.callee) === null || _b === void 0 ? void 0 : _b.type) === 'Identifier' &&
|
|
63
|
+
if (requireExp?.value?.callee?.type === 'Identifier' &&
|
|
65
64
|
requireExp.value.callee.name === 'require') {
|
|
66
65
|
let firstArg = requireExp.value.arguments[0];
|
|
67
66
|
if (firstArg &&
|
|
@@ -75,5 +74,4 @@ function transformer(file, api, options) {
|
|
|
75
74
|
// https://www.codeshiftcommunity.com/docs/import-manipulation/#replacerename-an-import-declaration
|
|
76
75
|
return root.toSource(options);
|
|
77
76
|
}
|
|
78
|
-
exports.default = transformer;
|
|
79
77
|
//# sourceMappingURL=next-image-to-legacy-image.js.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = transformer;
|
|
3
4
|
const importToChange = 'ImageResponse';
|
|
4
5
|
function transformer(file, api) {
|
|
5
6
|
const j = api.jscodeshift;
|
|
@@ -31,5 +32,4 @@ function transformer(file, api) {
|
|
|
31
32
|
.toSource();
|
|
32
33
|
return file.source;
|
|
33
34
|
}
|
|
34
|
-
exports.default = transformer;
|
|
35
35
|
//# sourceMappingURL=next-og-import.js.map
|