@next/codemod 15.0.0-canary.166 → 15.0.0-canary.168
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 +180 -202
- package/lib/cra-to-next/global-css-transform.js +1 -2
- package/lib/cra-to-next/index-to-component.js +1 -2
- package/lib/handle-package.js +5 -5
- package/lib/install.js +1 -1
- package/lib/run-jscodeshift.js +8 -1
- package/lib/utils.js +92 -0
- package/package.json +2 -3
- package/transforms/cra-to-next.js +237 -235
- package/transforms/lib/async-request-api/next-async-dynamic-api.js +3 -4
- package/transforms/lib/async-request-api/next-async-dynamic-prop.js +5 -7
- package/transforms/name-default-component.js +2 -3
- package/transforms/new-link.js +2 -3
- package/transforms/next-dynamic-access-named-export.js +2 -4
- package/transforms/next-image-experimental.js +8 -12
- package/transforms/next-image-to-legacy-image.js +4 -6
- package/transforms/next-request-geo-ip.js +10 -6
- package/bin/cli.js +0 -237
package/bin/next-codemod.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
2
3
|
/**
|
|
3
4
|
* Copyright 2015-present, Facebook, Inc.
|
|
4
5
|
*
|
|
@@ -6,7 +7,30 @@
|
|
|
6
7
|
* LICENSE file in the root directory of this source tree.
|
|
7
8
|
*
|
|
8
9
|
*/
|
|
9
|
-
// Based on https://github.com/reactjs/react-codemod/blob/dd8671c9a470a2c342b221ec903c574cf31e9f57/bin/
|
|
10
|
-
// next
|
|
11
|
-
|
|
10
|
+
// Based on https://github.com/reactjs/react-codemod/blob/dd8671c9a470a2c342b221ec903c574cf31e9f57/bin/cli.js
|
|
11
|
+
// @next/codemod optional-name-of-transform optional/path/to/src [...options]
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
const commander_1 = require("commander");
|
|
14
|
+
const upgrade_1 = require("./upgrade");
|
|
15
|
+
const transform_1 = require("./transform");
|
|
16
|
+
const packageJson = require('../package.json');
|
|
17
|
+
const program = new commander_1.Command(packageJson.name)
|
|
18
|
+
.description('Codemods for updating Next.js apps.')
|
|
19
|
+
.version(packageJson.version, '-v, --version', 'Output the current version of @next/codemod.')
|
|
20
|
+
.argument('[codemod]', 'Codemod slug to run. See "https://github.com/vercel/next.js/tree/canary/packages/next-codemod".')
|
|
21
|
+
.argument('[source]', 'Path to source files or directory to transform including glob patterns.')
|
|
22
|
+
.usage('[codemod] [source] [options]')
|
|
23
|
+
.helpOption('-h, --help', 'Display this help message.')
|
|
24
|
+
.option('-f, --force', 'Bypass Git safety checks and forcibly run codemods')
|
|
25
|
+
.option('-d, --dry', 'Dry run (no changes are made to files)')
|
|
26
|
+
.option('-p, --print', 'Print transformed files to your terminal')
|
|
27
|
+
.option('-j, --jscodeshift', '(Advanced) Pass options directly to jscodeshift')
|
|
28
|
+
.action(transform_1.runTransform)
|
|
29
|
+
.allowUnknownOption();
|
|
30
|
+
program
|
|
31
|
+
.command('upgrade')
|
|
32
|
+
.description('Upgrade Next.js apps to desired versions with a single command.')
|
|
33
|
+
.usage('[options]')
|
|
34
|
+
.action(upgrade_1.runUpgrade);
|
|
35
|
+
program.parse(process.argv);
|
|
12
36
|
//# sourceMappingURL=next-codemod.js.map
|
package/bin/transform.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
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.transformerDirectory = exports.jscodeshiftExecutable = void 0;
|
|
7
|
+
exports.runTransform = runTransform;
|
|
8
|
+
const execa_1 = __importDefault(require("execa"));
|
|
9
|
+
const globby_1 = __importDefault(require("globby"));
|
|
10
|
+
const prompts_1 = __importDefault(require("prompts"));
|
|
11
|
+
const node_path_1 = require("node:path");
|
|
12
|
+
const handle_package_1 = require("../lib/handle-package");
|
|
13
|
+
const utils_1 = require("../lib/utils");
|
|
14
|
+
function expandFilePathsIfNeeded(filesBeforeExpansion) {
|
|
15
|
+
const shouldExpandFiles = filesBeforeExpansion.some((file) => file.includes('*'));
|
|
16
|
+
return shouldExpandFiles
|
|
17
|
+
? globby_1.default.sync(filesBeforeExpansion)
|
|
18
|
+
: filesBeforeExpansion;
|
|
19
|
+
}
|
|
20
|
+
exports.jscodeshiftExecutable = require.resolve('.bin/jscodeshift');
|
|
21
|
+
exports.transformerDirectory = (0, node_path_1.join)(__dirname, '../', 'transforms');
|
|
22
|
+
async function runTransform(transform, path, options) {
|
|
23
|
+
let transformer = transform;
|
|
24
|
+
let directory = path;
|
|
25
|
+
if (!options.dry) {
|
|
26
|
+
(0, utils_1.checkGitStatus)(options.force);
|
|
27
|
+
}
|
|
28
|
+
if (transform &&
|
|
29
|
+
!utils_1.TRANSFORMER_INQUIRER_CHOICES.find((x) => x.value === transform)) {
|
|
30
|
+
console.error('Invalid transform choice, pick one of:');
|
|
31
|
+
console.error(utils_1.TRANSFORMER_INQUIRER_CHOICES.map((x) => '- ' + x.value).join('\n'));
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
if (!path) {
|
|
35
|
+
const res = await (0, prompts_1.default)({
|
|
36
|
+
type: 'text',
|
|
37
|
+
name: 'path',
|
|
38
|
+
message: 'On which files or directory should the codemods be applied?',
|
|
39
|
+
default: '.',
|
|
40
|
+
});
|
|
41
|
+
directory = res.path;
|
|
42
|
+
}
|
|
43
|
+
if (!transform) {
|
|
44
|
+
const res = await (0, prompts_1.default)({
|
|
45
|
+
type: 'select',
|
|
46
|
+
name: 'transformer',
|
|
47
|
+
message: 'Which transform would you like to apply?',
|
|
48
|
+
choices: utils_1.TRANSFORMER_INQUIRER_CHOICES,
|
|
49
|
+
});
|
|
50
|
+
transformer = res.transformer;
|
|
51
|
+
}
|
|
52
|
+
const filesExpanded = expandFilePathsIfNeeded([directory]);
|
|
53
|
+
if (!filesExpanded.length) {
|
|
54
|
+
console.log(`No files found matching "${directory}"`);
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
const transformerPath = (0, node_path_1.join)(exports.transformerDirectory, `${transformer}.js`);
|
|
58
|
+
if (transformer === 'cra-to-next') {
|
|
59
|
+
// cra-to-next transform doesn't use jscodeshift directly
|
|
60
|
+
return require(transformerPath).default(filesExpanded, options);
|
|
61
|
+
}
|
|
62
|
+
let args = [];
|
|
63
|
+
const { dry, print, runInBand, jscodeshift } = options;
|
|
64
|
+
if (dry) {
|
|
65
|
+
args.push('--dry');
|
|
66
|
+
}
|
|
67
|
+
if (print) {
|
|
68
|
+
args.push('--print');
|
|
69
|
+
}
|
|
70
|
+
if (runInBand) {
|
|
71
|
+
args.push('--run-in-band');
|
|
72
|
+
}
|
|
73
|
+
args.push('--verbose=2');
|
|
74
|
+
args.push('--ignore-pattern=**/node_modules/**');
|
|
75
|
+
args.push('--ignore-pattern=**/.next/**');
|
|
76
|
+
args.push('--extensions=tsx,ts,jsx,js');
|
|
77
|
+
args = args.concat(['--transform', transformerPath]);
|
|
78
|
+
if (jscodeshift) {
|
|
79
|
+
args = args.concat(jscodeshift);
|
|
80
|
+
}
|
|
81
|
+
args = args.concat(filesExpanded);
|
|
82
|
+
console.log(`Executing command: jscodeshift ${args.join(' ')}`);
|
|
83
|
+
const result = execa_1.default.sync(exports.jscodeshiftExecutable, args, {
|
|
84
|
+
stdio: 'inherit',
|
|
85
|
+
stripFinalNewline: false,
|
|
86
|
+
});
|
|
87
|
+
if (result.failed) {
|
|
88
|
+
throw new Error(`jscodeshift exited with code ${result.exitCode}`);
|
|
89
|
+
}
|
|
90
|
+
if (!dry && transformer === 'built-in-next-font') {
|
|
91
|
+
console.log('Uninstalling `@next/font`');
|
|
92
|
+
try {
|
|
93
|
+
(0, handle_package_1.uninstallPackage)('@next/font');
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
console.error("Couldn't uninstall `@next/font`, please uninstall it manually");
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (!dry && transformer === 'next-request-geo-ip') {
|
|
100
|
+
console.log('Installing `@vercel/functions`...');
|
|
101
|
+
(0, handle_package_1.installPackage)('@vercel/functions');
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=transform.js.map
|
package/bin/upgrade.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -21,142 +12,133 @@ const compare_versions_1 = require("compare-versions");
|
|
|
21
12
|
const chalk_1 = __importDefault(require("chalk"));
|
|
22
13
|
const codemods_1 = require("../lib/codemods");
|
|
23
14
|
const handle_package_1 = require("../lib/handle-package");
|
|
24
|
-
function runUpgrade() {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
if (
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
15
|
+
async function runUpgrade() {
|
|
16
|
+
const appPackageJsonPath = path_1.default.resolve(process.cwd(), 'package.json');
|
|
17
|
+
let appPackageJson = JSON.parse(fs_1.default.readFileSync(appPackageJsonPath, 'utf8'));
|
|
18
|
+
await detectWorkspace(appPackageJson);
|
|
19
|
+
let targetNextPackageJson;
|
|
20
|
+
let targetVersionSpecifier = '';
|
|
21
|
+
const shortcutVersion = process.argv[2]?.replace('@', '');
|
|
22
|
+
if (shortcutVersion) {
|
|
23
|
+
const res = await fetch(`https://registry.npmjs.org/next/${shortcutVersion}`);
|
|
24
|
+
if (res.status === 200) {
|
|
25
|
+
targetNextPackageJson = await res.json();
|
|
26
|
+
targetVersionSpecifier = targetNextPackageJson.version;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
console.error(`${chalk_1.default.yellow('Next.js ' + shortcutVersion)} does not exist. Check available versions at ${chalk_1.default.underline('https://www.npmjs.com/package/next?activeTab=versions')}, or choose one from below\n`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const installedNextVersion = await getInstalledNextVersion();
|
|
33
|
+
if (!targetNextPackageJson) {
|
|
34
|
+
let nextPackageJson = {};
|
|
35
|
+
try {
|
|
36
|
+
const resCanary = await fetch(`https://registry.npmjs.org/next/canary`);
|
|
37
|
+
nextPackageJson['canary'] = await resCanary.json();
|
|
38
|
+
const resRc = await fetch(`https://registry.npmjs.org/next/rc`);
|
|
39
|
+
nextPackageJson['rc'] = await resRc.json();
|
|
40
|
+
const resLatest = await fetch(`https://registry.npmjs.org/next/latest`);
|
|
41
|
+
nextPackageJson['latest'] = await resLatest.json();
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
console.error('Failed to fetch versions from npm registry.');
|
|
45
|
+
return;
|
|
42
46
|
}
|
|
43
|
-
|
|
44
|
-
if (
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
nextPackageJson['
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
let showRc = true;
|
|
59
|
-
if (nextPackageJson['latest'].version && nextPackageJson['rc'].version) {
|
|
60
|
-
showRc =
|
|
61
|
-
(0, compare_versions_1.compareVersions)(nextPackageJson['rc'].version, nextPackageJson['latest'].version) === 1;
|
|
62
|
-
}
|
|
63
|
-
const choices = [
|
|
64
|
-
{
|
|
65
|
-
title: 'Canary',
|
|
66
|
-
value: 'canary',
|
|
67
|
-
description: `Experimental version with latest features (${nextPackageJson['canary'].version})`,
|
|
68
|
-
},
|
|
69
|
-
];
|
|
70
|
-
if (showRc) {
|
|
71
|
-
choices.push({
|
|
72
|
-
title: 'Release Candidate',
|
|
73
|
-
value: 'rc',
|
|
74
|
-
description: `Pre-release version for final testing (${nextPackageJson['rc'].version})`,
|
|
75
|
-
});
|
|
76
|
-
}
|
|
47
|
+
let showRc = true;
|
|
48
|
+
if (nextPackageJson['latest'].version && nextPackageJson['rc'].version) {
|
|
49
|
+
showRc =
|
|
50
|
+
(0, compare_versions_1.compareVersions)(nextPackageJson['rc'].version, nextPackageJson['latest'].version) === 1;
|
|
51
|
+
}
|
|
52
|
+
const choices = [
|
|
53
|
+
{
|
|
54
|
+
title: 'Canary',
|
|
55
|
+
value: 'canary',
|
|
56
|
+
description: `Experimental version with latest features (${nextPackageJson['canary'].version})`,
|
|
57
|
+
},
|
|
58
|
+
];
|
|
59
|
+
if (showRc) {
|
|
77
60
|
choices.push({
|
|
78
|
-
title: '
|
|
79
|
-
value: '
|
|
80
|
-
description: `
|
|
61
|
+
title: 'Release Candidate',
|
|
62
|
+
value: 'rc',
|
|
63
|
+
description: `Pre-release version for final testing (${nextPackageJson['rc'].version})`,
|
|
81
64
|
});
|
|
82
|
-
if (installedNextVersion) {
|
|
83
|
-
console.log(`You are currently using ${chalk_1.default.blue('Next.js ' + installedNextVersion)}`);
|
|
84
|
-
}
|
|
85
|
-
const initialVersionSpecifierIdx = yield getVersionSpecifierIdx(installedNextVersion, showRc);
|
|
86
|
-
const response = yield (0, prompts_1.default)({
|
|
87
|
-
type: 'select',
|
|
88
|
-
name: 'version',
|
|
89
|
-
message: 'What Next.js version do you want to upgrade to?',
|
|
90
|
-
choices: choices,
|
|
91
|
-
initial: initialVersionSpecifierIdx,
|
|
92
|
-
}, { onCancel: () => process.exit(0) });
|
|
93
|
-
targetNextPackageJson = nextPackageJson[response.version];
|
|
94
|
-
targetVersionSpecifier = response.version;
|
|
95
65
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
66
|
+
choices.push({
|
|
67
|
+
title: 'Stable',
|
|
68
|
+
value: 'latest',
|
|
69
|
+
description: `Production-ready release (${nextPackageJson['latest'].version})`,
|
|
70
|
+
});
|
|
71
|
+
if (installedNextVersion) {
|
|
72
|
+
console.log(`You are currently using ${chalk_1.default.blue('Next.js ' + installedNextVersion)}`);
|
|
100
73
|
}
|
|
101
|
-
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
`@types/react-dom@${targetNextPackageJson.devDependencies['@types/react-dom']}`,
|
|
109
|
-
];
|
|
110
|
-
(0, handle_package_1.installPackage)([nextDependency, ...reactDependencies], packageManager);
|
|
111
|
-
console.log(`Upgrading your project to ${chalk_1.default.blue('Next.js ' + targetVersionSpecifier)}...\n`);
|
|
112
|
-
yield suggestCodemods(installedNextVersion, targetNextVersion);
|
|
113
|
-
console.log(`\n${chalk_1.default.green('✔')} Your Next.js project has been upgraded successfully. ${chalk_1.default.bold('Time to ship! 🚢')}`);
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
function detectWorkspace(appPackageJson) {
|
|
117
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
118
|
-
let isWorkspace = appPackageJson.workspaces ||
|
|
119
|
-
fs_1.default.existsSync(path_1.default.resolve(process.cwd(), 'pnpm-workspace.yaml'));
|
|
120
|
-
if (!isWorkspace)
|
|
121
|
-
return;
|
|
122
|
-
console.log(`${chalk_1.default.red('⚠️')} You seem to be in the root of a monorepo. ${chalk_1.default.blue('@next/upgrade')} should be run in a specific app directory within the monorepo.`);
|
|
123
|
-
const response = yield (0, prompts_1.default)({
|
|
124
|
-
type: 'confirm',
|
|
125
|
-
name: 'value',
|
|
126
|
-
message: 'Do you still want to continue?',
|
|
127
|
-
initial: false,
|
|
74
|
+
const initialVersionSpecifierIdx = await getVersionSpecifierIdx(installedNextVersion, showRc);
|
|
75
|
+
const response = await (0, prompts_1.default)({
|
|
76
|
+
type: 'select',
|
|
77
|
+
name: 'version',
|
|
78
|
+
message: 'What Next.js version do you want to upgrade to?',
|
|
79
|
+
choices: choices,
|
|
80
|
+
initial: initialVersionSpecifierIdx,
|
|
128
81
|
}, { onCancel: () => process.exit(0) });
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
82
|
+
targetNextPackageJson = nextPackageJson[response.version];
|
|
83
|
+
targetVersionSpecifier = response.version;
|
|
84
|
+
}
|
|
85
|
+
const targetNextVersion = targetNextPackageJson.version;
|
|
86
|
+
if (targetNextVersion &&
|
|
87
|
+
(0, compare_versions_1.compareVersions)(targetNextVersion, '15.0.0-canary') >= 0) {
|
|
88
|
+
await suggestTurbopack(appPackageJson);
|
|
89
|
+
}
|
|
90
|
+
fs_1.default.writeFileSync(appPackageJsonPath, JSON.stringify(appPackageJson, null, 2));
|
|
91
|
+
const packageManager = (0, handle_package_1.getPkgManager)(process.cwd());
|
|
92
|
+
const nextDependency = `next@${targetNextVersion}`;
|
|
93
|
+
const reactDependencies = [
|
|
94
|
+
`react@${targetNextPackageJson.peerDependencies['react']}`,
|
|
95
|
+
`@types/react@${targetNextPackageJson.devDependencies['@types/react']}`,
|
|
96
|
+
`react-dom@${targetNextPackageJson.peerDependencies['react-dom']}`,
|
|
97
|
+
`@types/react-dom@${targetNextPackageJson.devDependencies['@types/react-dom']}`,
|
|
98
|
+
];
|
|
99
|
+
(0, handle_package_1.installPackage)([nextDependency, ...reactDependencies], packageManager);
|
|
100
|
+
console.log(`Upgrading your project to ${chalk_1.default.blue('Next.js ' + targetVersionSpecifier)}...\n`);
|
|
101
|
+
await suggestCodemods(installedNextVersion, targetNextVersion);
|
|
102
|
+
console.log(`\n${chalk_1.default.green('✔')} Your Next.js project has been upgraded successfully. ${chalk_1.default.bold('Time to ship! 🚢')}`);
|
|
133
103
|
}
|
|
134
|
-
function
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
104
|
+
async function detectWorkspace(appPackageJson) {
|
|
105
|
+
let isWorkspace = appPackageJson.workspaces ||
|
|
106
|
+
fs_1.default.existsSync(path_1.default.resolve(process.cwd(), 'pnpm-workspace.yaml'));
|
|
107
|
+
if (!isWorkspace)
|
|
108
|
+
return;
|
|
109
|
+
console.log(`${chalk_1.default.red('⚠️')} You seem to be in the root of a monorepo. ${chalk_1.default.blue('@next/upgrade')} should be run in a specific app directory within the monorepo.`);
|
|
110
|
+
const response = await (0, prompts_1.default)({
|
|
111
|
+
type: 'confirm',
|
|
112
|
+
name: 'value',
|
|
113
|
+
message: 'Do you still want to continue?',
|
|
114
|
+
initial: false,
|
|
115
|
+
}, { onCancel: () => process.exit(0) });
|
|
116
|
+
if (!response.value) {
|
|
117
|
+
process.exit(0);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
async function getInstalledNextVersion() {
|
|
121
|
+
const installedNextPackageJsonDir = require.resolve('next/package.json', {
|
|
122
|
+
paths: [process.cwd()],
|
|
141
123
|
});
|
|
124
|
+
const installedNextPackageJson = JSON.parse(fs_1.default.readFileSync(installedNextPackageJsonDir, 'utf8'));
|
|
125
|
+
return installedNextPackageJson.version;
|
|
142
126
|
}
|
|
143
127
|
/*
|
|
144
128
|
* Returns the index of the current version's specifier in the
|
|
145
129
|
* array ['canary', 'rc', 'latest'] or ['canary', 'latest']
|
|
146
130
|
*/
|
|
147
|
-
function getVersionSpecifierIdx(installedNextVersion, showRc) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
return showRc ? 2 : 1;
|
|
159
|
-
});
|
|
131
|
+
async function getVersionSpecifierIdx(installedNextVersion, showRc) {
|
|
132
|
+
if (installedNextVersion == null) {
|
|
133
|
+
return 0;
|
|
134
|
+
}
|
|
135
|
+
if (installedNextVersion.includes('canary')) {
|
|
136
|
+
return 0;
|
|
137
|
+
}
|
|
138
|
+
if (installedNextVersion.includes('rc')) {
|
|
139
|
+
return 1;
|
|
140
|
+
}
|
|
141
|
+
return showRc ? 2 : 1;
|
|
160
142
|
}
|
|
161
143
|
/*
|
|
162
144
|
* Heuristics are used to determine whether to Turbopack is enabled or not and
|
|
@@ -169,78 +151,74 @@ function getVersionSpecifierIdx(installedNextVersion, showRc) {
|
|
|
169
151
|
* 3. Otherwise, we ask the user to manually add `--turbo` to their dev command,
|
|
170
152
|
* showing the current dev command as the initial value.
|
|
171
153
|
*/
|
|
172
|
-
function suggestTurbopack(packageJson) {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
initial: devScript,
|
|
199
|
-
});
|
|
200
|
-
packageJson.scripts['dev'] =
|
|
201
|
-
responseCustomDevScript.customDevScript || devScript;
|
|
154
|
+
async function suggestTurbopack(packageJson) {
|
|
155
|
+
const devScript = packageJson.scripts['dev'];
|
|
156
|
+
if (devScript.includes('--turbo'))
|
|
157
|
+
return;
|
|
158
|
+
const responseTurbopack = await (0, prompts_1.default)({
|
|
159
|
+
type: 'confirm',
|
|
160
|
+
name: 'enable',
|
|
161
|
+
message: 'Turbopack is now the stable default for dev mode. Enable it?',
|
|
162
|
+
initial: true,
|
|
163
|
+
}, {
|
|
164
|
+
onCancel: () => {
|
|
165
|
+
process.exit(0);
|
|
166
|
+
},
|
|
167
|
+
});
|
|
168
|
+
if (!responseTurbopack.enable) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
if (devScript.includes('next dev')) {
|
|
172
|
+
packageJson.scripts['dev'] = devScript.replace('next dev', 'next dev --turbo');
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
const responseCustomDevScript = await (0, prompts_1.default)({
|
|
176
|
+
type: 'text',
|
|
177
|
+
name: 'customDevScript',
|
|
178
|
+
message: 'Please add `--turbo` to your dev command:',
|
|
179
|
+
initial: devScript,
|
|
202
180
|
});
|
|
181
|
+
packageJson.scripts['dev'] =
|
|
182
|
+
responseCustomDevScript.customDevScript || devScript;
|
|
203
183
|
}
|
|
204
|
-
function suggestCodemods(initialNextVersion, targetNextVersion) {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
codemodsString += `\n- ${codemod.title} ${chalk_1.default.gray(`(${codemod.value})`)}`;
|
|
223
|
-
});
|
|
224
|
-
codemodsString += '\n';
|
|
225
|
-
console.log(codemodsString);
|
|
226
|
-
const responseCodemods = yield (0, prompts_1.default)({
|
|
227
|
-
type: 'confirm',
|
|
228
|
-
name: 'apply',
|
|
229
|
-
message: `Do you want to apply these codemods?`,
|
|
230
|
-
initial: true,
|
|
231
|
-
}, {
|
|
232
|
-
onCancel: () => {
|
|
233
|
-
process.exit(0);
|
|
234
|
-
},
|
|
235
|
-
});
|
|
236
|
-
if (!responseCodemods.apply) {
|
|
237
|
-
return;
|
|
238
|
-
}
|
|
239
|
-
for (const codemod of relevantCodemods) {
|
|
240
|
-
(0, child_process_1.execSync)(`npx @next/codemod@latest ${codemod.value} ${process.cwd()} --force`, {
|
|
241
|
-
stdio: 'inherit',
|
|
242
|
-
});
|
|
243
|
-
}
|
|
184
|
+
async function suggestCodemods(initialNextVersion, targetNextVersion) {
|
|
185
|
+
const initialVersionIndex = codemods_1.availableCodemods.findIndex((versionCodemods) => (0, compare_versions_1.compareVersions)(versionCodemods.version, initialNextVersion) > 0);
|
|
186
|
+
if (initialVersionIndex === -1) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
let targetVersionIndex = codemods_1.availableCodemods.findIndex((versionCodemods) => (0, compare_versions_1.compareVersions)(versionCodemods.version, targetNextVersion) > 0);
|
|
190
|
+
if (targetVersionIndex === -1) {
|
|
191
|
+
targetVersionIndex = codemods_1.availableCodemods.length;
|
|
192
|
+
}
|
|
193
|
+
const relevantCodemods = codemods_1.availableCodemods
|
|
194
|
+
.slice(initialVersionIndex, targetVersionIndex)
|
|
195
|
+
.flatMap((versionCodemods) => versionCodemods.codemods);
|
|
196
|
+
if (relevantCodemods.length === 0) {
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
let codemodsString = `\nThe following ${chalk_1.default.blue('codemods')} are available for your upgrade:`;
|
|
200
|
+
relevantCodemods.forEach((codemod) => {
|
|
201
|
+
codemodsString += `\n- ${codemod.title} ${chalk_1.default.gray(`(${codemod.value})`)}`;
|
|
244
202
|
});
|
|
203
|
+
codemodsString += '\n';
|
|
204
|
+
console.log(codemodsString);
|
|
205
|
+
const responseCodemods = await (0, prompts_1.default)({
|
|
206
|
+
type: 'confirm',
|
|
207
|
+
name: 'apply',
|
|
208
|
+
message: `Do you want to apply these codemods?`,
|
|
209
|
+
initial: true,
|
|
210
|
+
}, {
|
|
211
|
+
onCancel: () => {
|
|
212
|
+
process.exit(0);
|
|
213
|
+
},
|
|
214
|
+
});
|
|
215
|
+
if (!responseCodemods.apply) {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
for (const codemod of relevantCodemods) {
|
|
219
|
+
(0, child_process_1.execSync)(`npx @next/codemod@latest ${codemod.value} ${process.cwd()} --force`, {
|
|
220
|
+
stdio: 'inherit',
|
|
221
|
+
});
|
|
222
|
+
}
|
|
245
223
|
}
|
|
246
224
|
//# sourceMappingURL=upgrade.js.map
|
|
@@ -38,8 +38,7 @@ function transformer(file, api, options) {
|
|
|
38
38
|
}
|
|
39
39
|
else if (value.endsWith('.svg')) {
|
|
40
40
|
const isComponentImport = path.node.specifiers.some((specifier) => {
|
|
41
|
-
|
|
42
|
-
return ((_a = specifier.imported) === null || _a === void 0 ? void 0 : _a.name) === 'ReactComponent';
|
|
41
|
+
return specifier.imported?.name === 'ReactComponent';
|
|
43
42
|
});
|
|
44
43
|
if (isComponentImport) {
|
|
45
44
|
exports.globalCssContext.reactSvgImports.add(file.path);
|
|
@@ -29,7 +29,6 @@ function transformer(file, api, options) {
|
|
|
29
29
|
root
|
|
30
30
|
.find(j.CallExpression)
|
|
31
31
|
.filter((path) => {
|
|
32
|
-
var _a, _b;
|
|
33
32
|
const { node } = path;
|
|
34
33
|
let found = false;
|
|
35
34
|
if (defaultReactDomImport &&
|
|
@@ -44,7 +43,7 @@ function transformer(file, api, options) {
|
|
|
44
43
|
if (found) {
|
|
45
44
|
foundReactRender++;
|
|
46
45
|
hasModifications = true;
|
|
47
|
-
if (!Array.isArray(
|
|
46
|
+
if (!Array.isArray(path.parentPath?.parentPath?.value)) {
|
|
48
47
|
exports.indexContext.nestedRender = true;
|
|
49
48
|
return false;
|
|
50
49
|
}
|
package/lib/handle-package.js
CHANGED
|
@@ -34,23 +34,23 @@ function getPkgManager(baseDir) {
|
|
|
34
34
|
execa_1.default.sync('yarn --version', { stdio: 'ignore' });
|
|
35
35
|
return 'yarn';
|
|
36
36
|
}
|
|
37
|
-
catch
|
|
37
|
+
catch {
|
|
38
38
|
try {
|
|
39
39
|
execa_1.default.sync('pnpm --version', { stdio: 'ignore' });
|
|
40
40
|
return 'pnpm';
|
|
41
41
|
}
|
|
42
|
-
catch
|
|
42
|
+
catch {
|
|
43
43
|
execa_1.default.sync('bun --version', { stdio: 'ignore' });
|
|
44
44
|
return 'bun';
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
-
catch
|
|
48
|
+
catch {
|
|
49
49
|
return 'npm';
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
function uninstallPackage(packageToUninstall, pkgManager) {
|
|
53
|
-
pkgManager
|
|
53
|
+
pkgManager ??= getPkgManager(process.cwd());
|
|
54
54
|
if (!pkgManager)
|
|
55
55
|
throw new Error('Failed to find package manager');
|
|
56
56
|
let command = 'uninstall';
|
|
@@ -60,7 +60,7 @@ function uninstallPackage(packageToUninstall, pkgManager) {
|
|
|
60
60
|
execa_1.default.sync(pkgManager, [command, packageToUninstall], { stdio: 'inherit' });
|
|
61
61
|
}
|
|
62
62
|
function installPackage(packageToInstall, pkgManager) {
|
|
63
|
-
pkgManager
|
|
63
|
+
pkgManager ??= getPkgManager(process.cwd());
|
|
64
64
|
if (!pkgManager)
|
|
65
65
|
throw new Error('Failed to find package manager');
|
|
66
66
|
if (Array.isArray(packageToInstall)) {
|
package/lib/install.js
CHANGED
|
@@ -84,7 +84,7 @@ function install(root, dependencies, { useYarn, isOnline, devDependencies }) {
|
|
|
84
84
|
*/
|
|
85
85
|
const child = (0, cross_spawn_1.default)(command, args, {
|
|
86
86
|
stdio: 'inherit',
|
|
87
|
-
env:
|
|
87
|
+
env: { ...process.env, ADBLOCK: '1', DISABLE_OPENCOLLECTIVE: '1' },
|
|
88
88
|
});
|
|
89
89
|
child.on('close', (code) => {
|
|
90
90
|
if (code !== 0) {
|