@next/codemod 15.0.0 → 15.0.1-canary.1
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/transform.js +64 -19
- package/bin/upgrade.js +0 -1
- package/package.json +3 -2
package/bin/transform.js
CHANGED
|
@@ -8,6 +8,7 @@ exports.runTransform = runTransform;
|
|
|
8
8
|
const execa_1 = __importDefault(require("execa"));
|
|
9
9
|
const globby_1 = __importDefault(require("globby"));
|
|
10
10
|
const prompts_1 = __importDefault(require("prompts"));
|
|
11
|
+
const strip_ansi_1 = __importDefault(require("strip-ansi"));
|
|
11
12
|
const node_path_1 = require("node:path");
|
|
12
13
|
const handle_package_1 = require("../lib/handle-package");
|
|
13
14
|
const utils_1 = require("../lib/utils");
|
|
@@ -55,6 +56,18 @@ async function runTransform(transform, path, options) {
|
|
|
55
56
|
}, { onCancel: utils_1.onCancel });
|
|
56
57
|
transformer = res.transformer;
|
|
57
58
|
}
|
|
59
|
+
if (transformer === 'next-request-geo-ip') {
|
|
60
|
+
const { isAppDeployedToVercel } = await (0, prompts_1.default)({
|
|
61
|
+
type: 'confirm',
|
|
62
|
+
name: 'isAppDeployedToVercel',
|
|
63
|
+
message: 'Is your app deployed to Vercel? (Required to apply the selected codemod)',
|
|
64
|
+
initial: true,
|
|
65
|
+
}, { onCancel: utils_1.onCancel });
|
|
66
|
+
if (!isAppDeployedToVercel) {
|
|
67
|
+
console.log('Skipping codemod "next-request-geo-ip" as your app is not deployed to Vercel.');
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
58
71
|
const filesExpanded = expandFilePathsIfNeeded([directory]);
|
|
59
72
|
if (!filesExpanded.length) {
|
|
60
73
|
console.log(`No files found matching "${directory}"`);
|
|
@@ -89,36 +102,68 @@ async function runTransform(transform, path, options) {
|
|
|
89
102
|
}
|
|
90
103
|
args = args.concat(filesExpanded);
|
|
91
104
|
console.log(`Executing command: jscodeshift ${args.join(' ')}`);
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
105
|
+
const execaChildProcess = (0, execa_1.default)(exports.jscodeshiftExecutable, args, {
|
|
106
|
+
// include ANSI color codes
|
|
107
|
+
// Note: execa merges env with existing env by default.
|
|
108
|
+
env: process.stdout.isTTY ? { FORCE_COLOR: 'true' } : {},
|
|
95
109
|
});
|
|
96
|
-
|
|
97
|
-
|
|
110
|
+
// "\n" + "a\n" + "b\n"
|
|
111
|
+
let lastThreeLineBreaks = '';
|
|
112
|
+
if (execaChildProcess.stdout) {
|
|
113
|
+
execaChildProcess.stdout.pipe(process.stdout);
|
|
114
|
+
execaChildProcess.stderr.pipe(process.stderr);
|
|
115
|
+
// The last two lines contain the successful transformation count as "N ok".
|
|
116
|
+
// To save memory, we "slide the window" to keep only the last three line breaks.
|
|
117
|
+
// We save three line breaks because the EOL is always "\n".
|
|
118
|
+
execaChildProcess.stdout.on('data', (chunk) => {
|
|
119
|
+
lastThreeLineBreaks += chunk.toString('utf-8');
|
|
120
|
+
let cutoff = lastThreeLineBreaks.length;
|
|
121
|
+
// Note: the stdout ends with "\n".
|
|
122
|
+
// "foo\n" + "bar\n" + "baz\n" -> "\nbar\nbaz\n"
|
|
123
|
+
// "\n" + "foo\n" + "bar\n" -> "\nfoo\nbar\n"
|
|
124
|
+
for (let i = 0; i < 3; i++) {
|
|
125
|
+
cutoff = lastThreeLineBreaks.lastIndexOf('\n', cutoff) - 1;
|
|
126
|
+
}
|
|
127
|
+
if (cutoff > 0 && cutoff < lastThreeLineBreaks.length) {
|
|
128
|
+
lastThreeLineBreaks = lastThreeLineBreaks.slice(cutoff + 1);
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
try {
|
|
133
|
+
const result = await execaChildProcess;
|
|
134
|
+
if (result.failed) {
|
|
135
|
+
throw new Error(`jscodeshift exited with code ${result.exitCode}`);
|
|
136
|
+
}
|
|
98
137
|
}
|
|
99
|
-
|
|
138
|
+
catch (error) {
|
|
139
|
+
throw error;
|
|
140
|
+
}
|
|
141
|
+
// With ANSI color codes, it will be "\x1B[39m\x1B[32m0 ok".
|
|
142
|
+
// Without, it will be "0 ok".
|
|
143
|
+
const targetOkLine = lastThreeLineBreaks.split('\n').at(-3);
|
|
144
|
+
if (!targetOkLine.endsWith('ok')) {
|
|
145
|
+
throw new Error(`Failed to parse the successful transformation count "${targetOkLine}". This is a bug in the codemod tool.`);
|
|
146
|
+
}
|
|
147
|
+
const stripped = (0, strip_ansi_1.default)(targetOkLine);
|
|
148
|
+
// "N ok" -> "N"
|
|
149
|
+
const parsedNum = parseInt(stripped.split(' ')[0], 10);
|
|
150
|
+
const hasChanges = parsedNum > 0;
|
|
151
|
+
if (!dry && transformer === 'built-in-next-font' && hasChanges) {
|
|
100
152
|
const { uninstallNextFont } = await (0, prompts_1.default)({
|
|
101
153
|
type: 'confirm',
|
|
102
154
|
name: 'uninstallNextFont',
|
|
103
|
-
message: 'Do you want to uninstall `@next/font`?',
|
|
155
|
+
message: '`built-in-next-font` should have removed all usages of `@next/font`. Do you want to uninstall `@next/font`?',
|
|
104
156
|
initial: true,
|
|
105
|
-
});
|
|
157
|
+
}, { onCancel: utils_1.onCancel });
|
|
106
158
|
if (uninstallNextFont) {
|
|
107
159
|
console.log('Uninstalling `@next/font`');
|
|
108
160
|
(0, handle_package_1.uninstallPackage)('@next/font');
|
|
109
161
|
}
|
|
110
162
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
message: 'Do you want to install `@vercel/functions`?',
|
|
116
|
-
initial: true,
|
|
117
|
-
});
|
|
118
|
-
if (installVercelFunctions) {
|
|
119
|
-
console.log('Installing `@vercel/functions`...');
|
|
120
|
-
(0, handle_package_1.installPackages)(['@vercel/functions']);
|
|
121
|
-
}
|
|
163
|
+
// When has changes, it requires `@vercel/functions`, so skip prompt.
|
|
164
|
+
if (!dry && transformer === 'next-request-geo-ip' && hasChanges) {
|
|
165
|
+
console.log('Installing `@vercel/functions` because the `next-request-geo-ip` made changes.');
|
|
166
|
+
(0, handle_package_1.installPackages)(['@vercel/functions']);
|
|
122
167
|
}
|
|
123
168
|
}
|
|
124
169
|
//# sourceMappingURL=transform.js.map
|
package/bin/upgrade.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@next/codemod",
|
|
3
|
-
"version": "15.0.
|
|
3
|
+
"version": "15.0.1-canary.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
"jscodeshift": "17.0.0",
|
|
18
18
|
"picocolors": "1.0.0",
|
|
19
19
|
"prompts": "2.4.2",
|
|
20
|
-
"semver": "7.6.3"
|
|
20
|
+
"semver": "7.6.3",
|
|
21
|
+
"strip-ansi": "6.0.0"
|
|
21
22
|
},
|
|
22
23
|
"files": [
|
|
23
24
|
"transforms/*.js",
|