@next/codemod 15.0.0-canary.165 → 15.0.0-canary.166
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/cli.js +5 -0
- package/bin/upgrade.js +246 -0
- package/lib/codemods.js +103 -0
- package/lib/handle-package.js +44 -11
- package/package.json +5 -2
package/bin/cli.js
CHANGED
|
@@ -24,6 +24,7 @@ const execa_1 = __importDefault(require("execa"));
|
|
|
24
24
|
const picocolors_1 = require("picocolors");
|
|
25
25
|
const is_git_clean_1 = __importDefault(require("is-git-clean"));
|
|
26
26
|
const handle_package_1 = require("../lib/handle-package");
|
|
27
|
+
const upgrade_1 = require("./upgrade");
|
|
27
28
|
exports.jscodeshiftExecutable = require.resolve('.bin/jscodeshift');
|
|
28
29
|
exports.transformerDirectory = path_1.default.join(__dirname, '../', 'transforms');
|
|
29
30
|
function checkGitStatus(force) {
|
|
@@ -187,6 +188,10 @@ function run() {
|
|
|
187
188
|
if (!cli.flags.dry) {
|
|
188
189
|
checkGitStatus(cli.flags.force);
|
|
189
190
|
}
|
|
191
|
+
const isUpgrade = cli.input[0] === 'upgrade' || cli.input[0] === 'up';
|
|
192
|
+
if (isUpgrade) {
|
|
193
|
+
return (0, upgrade_1.runUpgrade)().catch(console.error);
|
|
194
|
+
}
|
|
190
195
|
if (cli.input[0] &&
|
|
191
196
|
!TRANSFORMER_INQUIRER_CHOICES.find((x) => x.value === cli.input[0])) {
|
|
192
197
|
console.error('Invalid transform choice, pick one of:');
|
package/bin/upgrade.js
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.runUpgrade = runUpgrade;
|
|
16
|
+
const prompts_1 = __importDefault(require("prompts"));
|
|
17
|
+
const fs_1 = __importDefault(require("fs"));
|
|
18
|
+
const child_process_1 = require("child_process");
|
|
19
|
+
const path_1 = __importDefault(require("path"));
|
|
20
|
+
const compare_versions_1 = require("compare-versions");
|
|
21
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
22
|
+
const codemods_1 = require("../lib/codemods");
|
|
23
|
+
const handle_package_1 = require("../lib/handle-package");
|
|
24
|
+
function runUpgrade() {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
var _a;
|
|
27
|
+
const appPackageJsonPath = path_1.default.resolve(process.cwd(), 'package.json');
|
|
28
|
+
let appPackageJson = JSON.parse(fs_1.default.readFileSync(appPackageJsonPath, 'utf8'));
|
|
29
|
+
yield detectWorkspace(appPackageJson);
|
|
30
|
+
let targetNextPackageJson;
|
|
31
|
+
let targetVersionSpecifier = '';
|
|
32
|
+
const shortcutVersion = (_a = process.argv[2]) === null || _a === void 0 ? void 0 : _a.replace('@', '');
|
|
33
|
+
if (shortcutVersion) {
|
|
34
|
+
const res = yield fetch(`https://registry.npmjs.org/next/${shortcutVersion}`);
|
|
35
|
+
if (res.status === 200) {
|
|
36
|
+
targetNextPackageJson = yield res.json();
|
|
37
|
+
targetVersionSpecifier = targetNextPackageJson.version;
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
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`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const installedNextVersion = yield getInstalledNextVersion();
|
|
44
|
+
if (!targetNextPackageJson) {
|
|
45
|
+
let nextPackageJson = {};
|
|
46
|
+
try {
|
|
47
|
+
const resCanary = yield fetch(`https://registry.npmjs.org/next/canary`);
|
|
48
|
+
nextPackageJson['canary'] = yield resCanary.json();
|
|
49
|
+
const resRc = yield fetch(`https://registry.npmjs.org/next/rc`);
|
|
50
|
+
nextPackageJson['rc'] = yield resRc.json();
|
|
51
|
+
const resLatest = yield fetch(`https://registry.npmjs.org/next/latest`);
|
|
52
|
+
nextPackageJson['latest'] = yield resLatest.json();
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
console.error('Failed to fetch versions from npm registry.');
|
|
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
|
+
}
|
|
77
|
+
choices.push({
|
|
78
|
+
title: 'Stable',
|
|
79
|
+
value: 'latest',
|
|
80
|
+
description: `Production-ready release (${nextPackageJson['latest'].version})`,
|
|
81
|
+
});
|
|
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
|
+
}
|
|
96
|
+
const targetNextVersion = targetNextPackageJson.version;
|
|
97
|
+
if (targetNextVersion &&
|
|
98
|
+
(0, compare_versions_1.compareVersions)(targetNextVersion, '15.0.0-canary') >= 0) {
|
|
99
|
+
yield suggestTurbopack(appPackageJson);
|
|
100
|
+
}
|
|
101
|
+
fs_1.default.writeFileSync(appPackageJsonPath, JSON.stringify(appPackageJson, null, 2));
|
|
102
|
+
const packageManager = (0, handle_package_1.getPkgManager)(process.cwd());
|
|
103
|
+
const nextDependency = `next@${targetNextVersion}`;
|
|
104
|
+
const reactDependencies = [
|
|
105
|
+
`react@${targetNextPackageJson.peerDependencies['react']}`,
|
|
106
|
+
`@types/react@${targetNextPackageJson.devDependencies['@types/react']}`,
|
|
107
|
+
`react-dom@${targetNextPackageJson.peerDependencies['react-dom']}`,
|
|
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,
|
|
128
|
+
}, { onCancel: () => process.exit(0) });
|
|
129
|
+
if (!response.value) {
|
|
130
|
+
process.exit(0);
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
function getInstalledNextVersion() {
|
|
135
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
136
|
+
const installedNextPackageJsonDir = require.resolve('next/package.json', {
|
|
137
|
+
paths: [process.cwd()],
|
|
138
|
+
});
|
|
139
|
+
const installedNextPackageJson = JSON.parse(fs_1.default.readFileSync(installedNextPackageJsonDir, 'utf8'));
|
|
140
|
+
return installedNextPackageJson.version;
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
/*
|
|
144
|
+
* Returns the index of the current version's specifier in the
|
|
145
|
+
* array ['canary', 'rc', 'latest'] or ['canary', 'latest']
|
|
146
|
+
*/
|
|
147
|
+
function getVersionSpecifierIdx(installedNextVersion, showRc) {
|
|
148
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
149
|
+
if (installedNextVersion == null) {
|
|
150
|
+
return 0;
|
|
151
|
+
}
|
|
152
|
+
if (installedNextVersion.includes('canary')) {
|
|
153
|
+
return 0;
|
|
154
|
+
}
|
|
155
|
+
if (installedNextVersion.includes('rc')) {
|
|
156
|
+
return 1;
|
|
157
|
+
}
|
|
158
|
+
return showRc ? 2 : 1;
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
/*
|
|
162
|
+
* Heuristics are used to determine whether to Turbopack is enabled or not and
|
|
163
|
+
* to determine how to update the dev script.
|
|
164
|
+
*
|
|
165
|
+
* 1. If the dev script contains `--turbo` option, we assume that Turbopack is
|
|
166
|
+
* already enabled.
|
|
167
|
+
* 2. If the dev script contains the string `next dev`, we replace it to
|
|
168
|
+
* `next dev --turbo`.
|
|
169
|
+
* 3. Otherwise, we ask the user to manually add `--turbo` to their dev command,
|
|
170
|
+
* showing the current dev command as the initial value.
|
|
171
|
+
*/
|
|
172
|
+
function suggestTurbopack(packageJson) {
|
|
173
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
174
|
+
const devScript = packageJson.scripts['dev'];
|
|
175
|
+
if (devScript.includes('--turbo'))
|
|
176
|
+
return;
|
|
177
|
+
const responseTurbopack = yield (0, prompts_1.default)({
|
|
178
|
+
type: 'confirm',
|
|
179
|
+
name: 'enable',
|
|
180
|
+
message: 'Turbopack is now the stable default for dev mode. Enable it?',
|
|
181
|
+
initial: true,
|
|
182
|
+
}, {
|
|
183
|
+
onCancel: () => {
|
|
184
|
+
process.exit(0);
|
|
185
|
+
},
|
|
186
|
+
});
|
|
187
|
+
if (!responseTurbopack.enable) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
if (devScript.includes('next dev')) {
|
|
191
|
+
packageJson.scripts['dev'] = devScript.replace('next dev', 'next dev --turbo');
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
const responseCustomDevScript = yield (0, prompts_1.default)({
|
|
195
|
+
type: 'text',
|
|
196
|
+
name: 'customDevScript',
|
|
197
|
+
message: 'Please add `--turbo` to your dev command:',
|
|
198
|
+
initial: devScript,
|
|
199
|
+
});
|
|
200
|
+
packageJson.scripts['dev'] =
|
|
201
|
+
responseCustomDevScript.customDevScript || devScript;
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
function suggestCodemods(initialNextVersion, targetNextVersion) {
|
|
205
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
206
|
+
const initialVersionIndex = codemods_1.availableCodemods.findIndex((versionCodemods) => (0, compare_versions_1.compareVersions)(versionCodemods.version, initialNextVersion) > 0);
|
|
207
|
+
if (initialVersionIndex === -1) {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
let targetVersionIndex = codemods_1.availableCodemods.findIndex((versionCodemods) => (0, compare_versions_1.compareVersions)(versionCodemods.version, targetNextVersion) > 0);
|
|
211
|
+
if (targetVersionIndex === -1) {
|
|
212
|
+
targetVersionIndex = codemods_1.availableCodemods.length;
|
|
213
|
+
}
|
|
214
|
+
const relevantCodemods = codemods_1.availableCodemods
|
|
215
|
+
.slice(initialVersionIndex, targetVersionIndex)
|
|
216
|
+
.flatMap((versionCodemods) => versionCodemods.codemods);
|
|
217
|
+
if (relevantCodemods.length === 0) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
let codemodsString = `\nThe following ${chalk_1.default.blue('codemods')} are available for your upgrade:`;
|
|
221
|
+
relevantCodemods.forEach((codemod) => {
|
|
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
|
+
}
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
//# sourceMappingURL=upgrade.js.map
|
package/lib/codemods.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.availableCodemods = void 0;
|
|
4
|
+
exports.availableCodemods = [
|
|
5
|
+
{
|
|
6
|
+
version: '6',
|
|
7
|
+
codemods: [
|
|
8
|
+
{
|
|
9
|
+
title: 'Use withRouter',
|
|
10
|
+
value: 'url-to-withrouter',
|
|
11
|
+
},
|
|
12
|
+
],
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
version: '8',
|
|
16
|
+
codemods: [
|
|
17
|
+
{
|
|
18
|
+
title: 'Transform AMP HOC into page config',
|
|
19
|
+
value: 'withamp-to-config',
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
version: '9',
|
|
25
|
+
codemods: [
|
|
26
|
+
{
|
|
27
|
+
title: 'Transform Anonymous Components into Named Components',
|
|
28
|
+
value: 'name-default-component',
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
version: '10',
|
|
34
|
+
codemods: [
|
|
35
|
+
{
|
|
36
|
+
title: 'Add React Import',
|
|
37
|
+
value: 'add-missing-react-import',
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
version: '11',
|
|
43
|
+
codemods: [
|
|
44
|
+
{
|
|
45
|
+
title: 'Migrate from CRA',
|
|
46
|
+
value: 'cra-to-next',
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
version: '13.0',
|
|
52
|
+
codemods: [
|
|
53
|
+
{
|
|
54
|
+
title: 'Remove <a> Tags From Link Components',
|
|
55
|
+
value: 'new-link',
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
title: 'Migrate to the New Image Component',
|
|
59
|
+
value: 'next-image-experimental',
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
title: 'Rename Next Image Imports',
|
|
63
|
+
value: 'next-image-to-legacy-image',
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
version: '13.2',
|
|
69
|
+
codemods: [
|
|
70
|
+
{
|
|
71
|
+
title: 'Use Built-in Font',
|
|
72
|
+
value: 'built-in-next-font',
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
version: '14.0',
|
|
78
|
+
codemods: [
|
|
79
|
+
{
|
|
80
|
+
title: 'Migrate ImageResponse imports',
|
|
81
|
+
value: 'next-og-import',
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
title: 'Use viewport export',
|
|
85
|
+
value: 'metadata-to-viewport-export',
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
version: '15.0',
|
|
91
|
+
codemods: [
|
|
92
|
+
{
|
|
93
|
+
title: 'Transforms usage of Next.js async Request APIs',
|
|
94
|
+
value: 'next-async-request-api',
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
title: 'Migrate `geo` and `ip` properties on `NextRequest`',
|
|
98
|
+
value: 'next-request-geo-ip',
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
},
|
|
102
|
+
];
|
|
103
|
+
//# sourceMappingURL=codemods.js.map
|
package/lib/handle-package.js
CHANGED
|
@@ -3,24 +3,54 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getPkgManager = getPkgManager;
|
|
6
7
|
exports.uninstallPackage = uninstallPackage;
|
|
7
8
|
exports.installPackage = installPackage;
|
|
8
9
|
const fs_1 = __importDefault(require("fs"));
|
|
9
10
|
const path_1 = __importDefault(require("path"));
|
|
10
11
|
const execa_1 = __importDefault(require("execa"));
|
|
11
12
|
function getPkgManager(baseDir) {
|
|
12
|
-
|
|
13
|
-
{ lockFile
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
try {
|
|
14
|
+
for (const { lockFile, packageManager } of [
|
|
15
|
+
{ lockFile: 'yarn.lock', packageManager: 'yarn' },
|
|
16
|
+
{ lockFile: 'pnpm-lock.yaml', packageManager: 'pnpm' },
|
|
17
|
+
{ lockFile: 'package-lock.json', packageManager: 'npm' },
|
|
18
|
+
{ lockFile: 'bun.lockb', packageManager: 'bun' },
|
|
19
|
+
]) {
|
|
20
|
+
if (fs_1.default.existsSync(path_1.default.join(baseDir, lockFile))) {
|
|
21
|
+
return packageManager;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const userAgent = process.env.npm_config_user_agent;
|
|
25
|
+
if (userAgent) {
|
|
26
|
+
if (userAgent.startsWith('yarn')) {
|
|
27
|
+
return 'yarn';
|
|
28
|
+
}
|
|
29
|
+
else if (userAgent.startsWith('pnpm')) {
|
|
30
|
+
return 'pnpm';
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
execa_1.default.sync('yarn --version', { stdio: 'ignore' });
|
|
35
|
+
return 'yarn';
|
|
19
36
|
}
|
|
37
|
+
catch (_a) {
|
|
38
|
+
try {
|
|
39
|
+
execa_1.default.sync('pnpm --version', { stdio: 'ignore' });
|
|
40
|
+
return 'pnpm';
|
|
41
|
+
}
|
|
42
|
+
catch (_b) {
|
|
43
|
+
execa_1.default.sync('bun --version', { stdio: 'ignore' });
|
|
44
|
+
return 'bun';
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
catch (_c) {
|
|
49
|
+
return 'npm';
|
|
20
50
|
}
|
|
21
51
|
}
|
|
22
|
-
function uninstallPackage(packageToUninstall) {
|
|
23
|
-
|
|
52
|
+
function uninstallPackage(packageToUninstall, pkgManager) {
|
|
53
|
+
pkgManager !== null && pkgManager !== void 0 ? pkgManager : (pkgManager = getPkgManager(process.cwd()));
|
|
24
54
|
if (!pkgManager)
|
|
25
55
|
throw new Error('Failed to find package manager');
|
|
26
56
|
let command = 'uninstall';
|
|
@@ -29,10 +59,13 @@ function uninstallPackage(packageToUninstall) {
|
|
|
29
59
|
}
|
|
30
60
|
execa_1.default.sync(pkgManager, [command, packageToUninstall], { stdio: 'inherit' });
|
|
31
61
|
}
|
|
32
|
-
function installPackage(packageToInstall) {
|
|
33
|
-
|
|
62
|
+
function installPackage(packageToInstall, pkgManager) {
|
|
63
|
+
pkgManager !== null && pkgManager !== void 0 ? pkgManager : (pkgManager = getPkgManager(process.cwd()));
|
|
34
64
|
if (!pkgManager)
|
|
35
65
|
throw new Error('Failed to find package manager');
|
|
66
|
+
if (Array.isArray(packageToInstall)) {
|
|
67
|
+
packageToInstall = packageToInstall.join(' ');
|
|
68
|
+
}
|
|
36
69
|
try {
|
|
37
70
|
execa_1.default.sync(pkgManager, ['add', packageToInstall], { stdio: 'inherit' });
|
|
38
71
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@next/codemod",
|
|
3
|
-
"version": "15.0.0-canary.
|
|
3
|
+
"version": "15.0.0-canary.166",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -8,14 +8,17 @@
|
|
|
8
8
|
"directory": "packages/next-codemod"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
+
"chalk": "4.1.2",
|
|
11
12
|
"cheerio": "1.0.0-rc.9",
|
|
13
|
+
"compare-versions": "6.1.1",
|
|
12
14
|
"execa": "4.0.3",
|
|
13
15
|
"globby": "11.0.1",
|
|
14
16
|
"inquirer": "7.3.3",
|
|
15
17
|
"is-git-clean": "1.1.0",
|
|
16
18
|
"jscodeshift": "17.0.0",
|
|
17
19
|
"meow": "7.0.1",
|
|
18
|
-
"picocolors": "1.0.0"
|
|
20
|
+
"picocolors": "1.0.0",
|
|
21
|
+
"prompts": "2.4.2"
|
|
19
22
|
},
|
|
20
23
|
"files": [
|
|
21
24
|
"transforms/*.js",
|