@next/codemod 16.3.0-canary.5 → 16.3.0-canary.51
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/upgrade.js
CHANGED
|
@@ -500,6 +500,16 @@ function writeOverridesField(packageJson, packageManager, overrides) {
|
|
|
500
500
|
}
|
|
501
501
|
}
|
|
502
502
|
else if (packageManager === 'pnpm') {
|
|
503
|
+
// pnpm v11 silently ignores `pnpm.overrides` in package.json. The
|
|
504
|
+
// canonical location moved to `pnpm-workspace.yaml#overrides`.
|
|
505
|
+
// See https://pnpm.io/settings and https://github.com/pnpm/pnpm/issues/11536.
|
|
506
|
+
// When the version cannot be detected, assume the current (v11+) layout
|
|
507
|
+
// since that's the surface where silently-dropped overrides hurt most.
|
|
508
|
+
const pnpmMajorVersion = (0, handle_package_1.getPnpmMajorVersion)();
|
|
509
|
+
if (pnpmMajorVersion === null || pnpmMajorVersion >= 11) {
|
|
510
|
+
writePnpmWorkspaceOverrides(overrides);
|
|
511
|
+
return;
|
|
512
|
+
}
|
|
503
513
|
// pnpm supports pnpm.overrides and pnpm.resolutions
|
|
504
514
|
if (packageJson.resolutions) {
|
|
505
515
|
for (const [key, value] of entries) {
|
|
@@ -545,6 +555,28 @@ function writeOverridesField(packageJson, packageManager, overrides) {
|
|
|
545
555
|
}
|
|
546
556
|
}
|
|
547
557
|
}
|
|
558
|
+
function writePnpmWorkspaceOverrides(overrides) {
|
|
559
|
+
// Deferred require so `js-yaml` is only loaded when we hit the pnpm v11+
|
|
560
|
+
// branch (i.e. not for npm/yarn/bun/pnpm-v10 upgrades). The package is CJS,
|
|
561
|
+
// so a sync `require()` keeps this function synchronous.
|
|
562
|
+
const yaml = require('js-yaml');
|
|
563
|
+
const filePath = path_1.default.join(cwd, 'pnpm-workspace.yaml');
|
|
564
|
+
let doc = {};
|
|
565
|
+
if (fs_1.default.existsSync(filePath)) {
|
|
566
|
+
const existing = fs_1.default.readFileSync(filePath, 'utf8');
|
|
567
|
+
const parsed = yaml.load(existing);
|
|
568
|
+
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
569
|
+
doc = parsed;
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
if (!doc.overrides || typeof doc.overrides !== 'object') {
|
|
573
|
+
doc.overrides = {};
|
|
574
|
+
}
|
|
575
|
+
for (const [key, value] of Object.entries(overrides)) {
|
|
576
|
+
doc.overrides[key] = value;
|
|
577
|
+
}
|
|
578
|
+
fs_1.default.writeFileSync(filePath, yaml.dump(doc));
|
|
579
|
+
}
|
|
548
580
|
function warnDependenciesOutOfRange(appPackageJson, versionMapping) {
|
|
549
581
|
const allDirectDependencies = {
|
|
550
582
|
...appPackageJson.dependencies,
|
package/lib/handle-package.js
CHANGED
|
@@ -3,6 +3,8 @@ 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.getPackageManagerVersion = getPackageManagerVersion;
|
|
7
|
+
exports.getPnpmMajorVersion = getPnpmMajorVersion;
|
|
6
8
|
exports.getPkgManager = getPkgManager;
|
|
7
9
|
exports.uninstallPackage = uninstallPackage;
|
|
8
10
|
exports.installPackages = installPackages;
|
|
@@ -10,7 +12,49 @@ exports.runInstallation = runInstallation;
|
|
|
10
12
|
exports.addPackageDependency = addPackageDependency;
|
|
11
13
|
const find_up_1 = __importDefault(require("find-up"));
|
|
12
14
|
const execa_1 = __importDefault(require("execa"));
|
|
15
|
+
const node_child_process_1 = require("node:child_process");
|
|
13
16
|
const node_path_1 = require("node:path");
|
|
17
|
+
/**
|
|
18
|
+
* Get the full version string for the given package manager.
|
|
19
|
+
*
|
|
20
|
+
* First tries to parse from `npm_config_user_agent` (e.g., "pnpm/9.13.2 npm/? ..."),
|
|
21
|
+
* then falls back to spawning `<packageManager> --version`.
|
|
22
|
+
*
|
|
23
|
+
* Returns null if unable to determine the version.
|
|
24
|
+
*
|
|
25
|
+
* Mirrors `packages/create-next-app/helpers/get-pkg-manager.ts`.
|
|
26
|
+
*/
|
|
27
|
+
function getPackageManagerVersion(packageManager) {
|
|
28
|
+
const userAgent = process.env.npm_config_user_agent || '';
|
|
29
|
+
const userAgentMatch = userAgent.match(new RegExp(`${packageManager}/([\\d.]+[\\w.-]*)`));
|
|
30
|
+
if (userAgentMatch) {
|
|
31
|
+
return userAgentMatch[1];
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
const version = (0, node_child_process_1.execSync)(`${packageManager} --version`, {
|
|
35
|
+
encoding: 'utf8',
|
|
36
|
+
stdio: ['pipe', 'pipe', 'ignore'],
|
|
37
|
+
}).trim();
|
|
38
|
+
if (/^\d+\.\d+\.\d+/.test(version)) {
|
|
39
|
+
return version;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
// package manager not available or failed to run
|
|
44
|
+
}
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Get the major version of pnpm being used.
|
|
49
|
+
* Returns null if unable to determine the version.
|
|
50
|
+
*/
|
|
51
|
+
function getPnpmMajorVersion() {
|
|
52
|
+
const version = getPackageManagerVersion('pnpm');
|
|
53
|
+
if (!version)
|
|
54
|
+
return null;
|
|
55
|
+
const major = parseInt(version.split('.')[0], 10);
|
|
56
|
+
return Number.isNaN(major) ? null : major;
|
|
57
|
+
}
|
|
14
58
|
function getPkgManager(baseDir) {
|
|
15
59
|
try {
|
|
16
60
|
const lockFile = find_up_1.default.sync([
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@next/codemod",
|
|
3
|
-
"version": "16.3.0-canary.
|
|
3
|
+
"version": "16.3.0-canary.51",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"find-up": "4.1.0",
|
|
15
15
|
"globby": "11.0.1",
|
|
16
16
|
"is-git-clean": "1.1.0",
|
|
17
|
+
"js-yaml": "4.2.0",
|
|
17
18
|
"jscodeshift": "17.0.0",
|
|
18
19
|
"picocolors": "1.0.0",
|
|
19
20
|
"prompts": "2.4.2",
|
|
@@ -37,6 +38,7 @@
|
|
|
37
38
|
"bin": "./bin/next-codemod.js",
|
|
38
39
|
"devDependencies": {
|
|
39
40
|
"@types/find-up": "4.0.0",
|
|
41
|
+
"@types/js-yaml": "4.0.9",
|
|
40
42
|
"@types/jscodeshift": "0.11.0",
|
|
41
43
|
"@types/prompts": "2.4.2",
|
|
42
44
|
"@types/semver": "7.3.1",
|
|
@@ -4,8 +4,12 @@
|
|
|
4
4
|
* the new top-level `turbopack` configuration.
|
|
5
5
|
*
|
|
6
6
|
* It moves most properties from experimental.turbo to the top-level turbopack
|
|
7
|
-
* property, with special handling for certain properties like
|
|
7
|
+
* property, with special handling for certain properties like minify,
|
|
8
8
|
* treeShaking, and sourceMaps which become experimental.turbopack* properties instead.
|
|
9
|
+
*
|
|
10
|
+
* The `memoryLimit` option is no longer supported, so it is removed entirely in
|
|
11
|
+
* both its old location (`experimental.turbo.memoryLimit`) and the location the
|
|
12
|
+
* previous version of this codemod produced (`experimental.turbopackMemoryLimit`).
|
|
9
13
|
*/
|
|
10
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
15
|
exports.default = transformer;
|
|
@@ -13,11 +17,15 @@ const parser_1 = require("../lib/parser");
|
|
|
13
17
|
const utils_1 = require("./lib/utils");
|
|
14
18
|
// Properties that need to be moved to experimental.turbopack*
|
|
15
19
|
const RENAMED_EXPERIMENTAL_PROPERTIES = {
|
|
16
|
-
memoryLimit: 'turbopackMemoryLimit',
|
|
17
20
|
minify: 'turbopackMinify',
|
|
18
21
|
treeShaking: 'turbopackTreeShaking',
|
|
19
22
|
sourceMaps: 'turbopackSourceMaps',
|
|
20
23
|
};
|
|
24
|
+
// `memoryLimit` is no longer supported and is removed entirely. We drop it under
|
|
25
|
+
// both its old `experimental.turbo.*` name and the `experimental.*` name produced
|
|
26
|
+
// by the previous version of this codemod.
|
|
27
|
+
const REMOVED_TURBO_PROPERTY = 'memoryLimit';
|
|
28
|
+
const REMOVED_EXPERIMENTAL_PROPERTY = 'turbopackMemoryLimit';
|
|
21
29
|
function transformer(file, _api, options) {
|
|
22
30
|
const j = (0, parser_1.createParserFromPath)(file.path);
|
|
23
31
|
const root = j(file.source);
|
|
@@ -56,6 +64,13 @@ function transformer(file, _api, options) {
|
|
|
56
64
|
const regularProps = [];
|
|
57
65
|
const specialProps = [];
|
|
58
66
|
turboObj.properties.forEach((prop) => {
|
|
67
|
+
if (isStaticProperty(prop) &&
|
|
68
|
+
prop.key &&
|
|
69
|
+
prop.key.type === 'Identifier' &&
|
|
70
|
+
prop.key.name === REMOVED_TURBO_PROPERTY) {
|
|
71
|
+
// Drop: `memoryLimit` is no longer supported.
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
59
74
|
if (isStaticProperty(prop) &&
|
|
60
75
|
prop.key &&
|
|
61
76
|
prop.key.type === 'Identifier' &&
|
|
@@ -71,7 +86,10 @@ function transformer(file, _api, options) {
|
|
|
71
86
|
const existingProps = experimentalObj.properties.filter((prop) => !(isStaticProperty(prop) &&
|
|
72
87
|
prop.key &&
|
|
73
88
|
prop.key.type === 'Identifier' &&
|
|
74
|
-
|
|
89
|
+
// Drop the `turbo` object (moved above) and a pre-existing
|
|
90
|
+
// `turbopackMemoryLimit` (no longer supported).
|
|
91
|
+
(prop.key.name === 'turbo' ||
|
|
92
|
+
prop.key.name === REMOVED_EXPERIMENTAL_PROPERTY)));
|
|
75
93
|
experimentalObj.properties = [...existingProps, ...specialProps];
|
|
76
94
|
// If experimental has no properties, remove it
|
|
77
95
|
if (experimentalObj.properties.length === 0) {
|
|
@@ -132,7 +150,13 @@ function transformer(file, _api, options) {
|
|
|
132
150
|
else {
|
|
133
151
|
return;
|
|
134
152
|
}
|
|
135
|
-
//
|
|
153
|
+
// `memoryLimit` is no longer supported: remove the assignment entirely.
|
|
154
|
+
if (propName === REMOVED_TURBO_PROPERTY) {
|
|
155
|
+
j(path).remove();
|
|
156
|
+
hasChanges = true;
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
// For special properties like minify, treeShaking, etc.
|
|
136
160
|
if (propName && RENAMED_EXPERIMENTAL_PROPERTIES[propName]) {
|
|
137
161
|
const newAssignment = j.assignmentExpression('=', j.memberExpression(j.memberExpression(j.identifier(varName), j.identifier('experimental')), j.identifier(RENAMED_EXPERIMENTAL_PROPERTIES[propName])), path.node.right);
|
|
138
162
|
j(path).replaceWith(newAssignment);
|
|
@@ -195,6 +219,26 @@ function transformer(file, _api, options) {
|
|
|
195
219
|
hasChanges = true;
|
|
196
220
|
}
|
|
197
221
|
});
|
|
222
|
+
// Remove `config.experimental.turbopackMemoryLimit = value` assignments left
|
|
223
|
+
// behind by the previous version of this codemod (no longer supported).
|
|
224
|
+
root
|
|
225
|
+
.find(j.AssignmentExpression, {
|
|
226
|
+
left: {
|
|
227
|
+
type: 'MemberExpression',
|
|
228
|
+
object: {
|
|
229
|
+
type: 'MemberExpression',
|
|
230
|
+
property: { type: 'Identifier', name: 'experimental' },
|
|
231
|
+
},
|
|
232
|
+
property: {
|
|
233
|
+
type: 'Identifier',
|
|
234
|
+
name: REMOVED_EXPERIMENTAL_PROPERTY,
|
|
235
|
+
},
|
|
236
|
+
},
|
|
237
|
+
})
|
|
238
|
+
.forEach((path) => {
|
|
239
|
+
j(path).remove();
|
|
240
|
+
hasChanges = true;
|
|
241
|
+
});
|
|
198
242
|
// Only return a string if we changed the AST, otherwise return the original source
|
|
199
243
|
return hasChanges ? root.toSource(options) : file.source;
|
|
200
244
|
}
|