@next/codemod 16.0.0-canary.8 → 16.0.0
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
|
@@ -164,7 +164,8 @@ async function runUpgrade(revision, options) {
|
|
|
164
164
|
const targetReactVersion = shouldStayOnReact18
|
|
165
165
|
? '18.3.1'
|
|
166
166
|
: await loadHighestNPMVersionMatching(`react@${targetNextPackageJson.peerDependencies['react']}`);
|
|
167
|
-
if ((0, semver_1.compare)(targetNextVersion, '15.0.0-canary') >= 0
|
|
167
|
+
if ((0, semver_1.compare)(targetNextVersion, '15.0.0-canary') >= 0 &&
|
|
168
|
+
(0, semver_1.compare)(targetNextVersion, '16.0.0-canary') < 0) {
|
|
168
169
|
await suggestTurbopack(appPackageJson, targetNextVersion);
|
|
169
170
|
}
|
|
170
171
|
const codemods = await suggestCodemods(installedNextVersion, targetNextVersion);
|
package/lib/utils.js
CHANGED
|
@@ -122,5 +122,15 @@ exports.TRANSFORMER_INQUIRER_CHOICES = [
|
|
|
122
122
|
value: 'middleware-to-proxy',
|
|
123
123
|
version: '15.6.0-canary.54',
|
|
124
124
|
},
|
|
125
|
+
{
|
|
126
|
+
title: 'Remove `unstable_` prefix from stabilized API',
|
|
127
|
+
value: 'remove-unstable-prefix',
|
|
128
|
+
version: '16.0.0-canary.10',
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
title: 'Remove `experimental_ppr` Route Segment Config from App Router pages and layouts',
|
|
132
|
+
value: 'remove-experimental-ppr',
|
|
133
|
+
version: '16.0.0-canary.11',
|
|
134
|
+
},
|
|
125
135
|
];
|
|
126
136
|
//# sourceMappingURL=utils.js.map
|
package/package.json
CHANGED
|
@@ -45,6 +45,9 @@ function transformer(file) {
|
|
|
45
45
|
if (isMiddlewareFile) {
|
|
46
46
|
const middlewareChanges = transformMiddlewareFunction(root, j);
|
|
47
47
|
hasChanges = hasChanges || middlewareChanges.hasChanges;
|
|
48
|
+
// Remove runtime segment config
|
|
49
|
+
const runtimeChanges = removeRuntimeConfig(root, j);
|
|
50
|
+
hasChanges = hasChanges || runtimeChanges;
|
|
48
51
|
}
|
|
49
52
|
if (isNextConfig) {
|
|
50
53
|
const { hasConfigChanges } = transformNextConfig(root, j);
|
|
@@ -602,4 +605,123 @@ function extractObjectsFromCallExpression(callExpr, configObjects, exportedNames
|
|
|
602
605
|
});
|
|
603
606
|
}
|
|
604
607
|
}
|
|
608
|
+
function removeRuntimeConfig(root, j) {
|
|
609
|
+
let hasChanges = false;
|
|
610
|
+
// Remove export const runtime = 'string'
|
|
611
|
+
const directRuntimeExports = root.find(j.ExportNamedDeclaration, {
|
|
612
|
+
declaration: {
|
|
613
|
+
type: 'VariableDeclaration',
|
|
614
|
+
declarations: [
|
|
615
|
+
{
|
|
616
|
+
id: { name: 'runtime' },
|
|
617
|
+
},
|
|
618
|
+
],
|
|
619
|
+
},
|
|
620
|
+
});
|
|
621
|
+
if (directRuntimeExports.size() > 0) {
|
|
622
|
+
directRuntimeExports.remove();
|
|
623
|
+
hasChanges = true;
|
|
624
|
+
}
|
|
625
|
+
// Remove const runtime = 'string' declarations
|
|
626
|
+
const runtimeVariableDeclarations = root
|
|
627
|
+
.find(j.VariableDeclaration)
|
|
628
|
+
.filter((path) => path.node.declarations.some((decl) => {
|
|
629
|
+
if (j.VariableDeclarator.check(decl) && j.Identifier.check(decl.id)) {
|
|
630
|
+
return decl.id.name === 'runtime';
|
|
631
|
+
}
|
|
632
|
+
return false;
|
|
633
|
+
}));
|
|
634
|
+
if (runtimeVariableDeclarations.size() > 0) {
|
|
635
|
+
runtimeVariableDeclarations.forEach((path) => {
|
|
636
|
+
const originalDeclarations = path.node.declarations;
|
|
637
|
+
const filteredDeclarations = originalDeclarations.filter((decl) => {
|
|
638
|
+
if (j.VariableDeclarator.check(decl) && j.Identifier.check(decl.id)) {
|
|
639
|
+
return decl.id.name !== 'runtime';
|
|
640
|
+
}
|
|
641
|
+
return true;
|
|
642
|
+
});
|
|
643
|
+
// If we filtered out some declarations, update the node
|
|
644
|
+
if (filteredDeclarations.length !== originalDeclarations.length) {
|
|
645
|
+
// Remove the entire declaration only if no declarators left
|
|
646
|
+
if (filteredDeclarations.length === 0) {
|
|
647
|
+
j(path).remove();
|
|
648
|
+
}
|
|
649
|
+
else {
|
|
650
|
+
path.node.declarations = filteredDeclarations;
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
});
|
|
654
|
+
hasChanges = true;
|
|
655
|
+
}
|
|
656
|
+
// Handle export { runtime } and export { runtime, other }
|
|
657
|
+
const namedExports = root
|
|
658
|
+
.find(j.ExportNamedDeclaration)
|
|
659
|
+
.filter((path) => path.node.specifiers && path.node.specifiers.length > 0);
|
|
660
|
+
namedExports.forEach((path) => {
|
|
661
|
+
const specifiers = path.node.specifiers;
|
|
662
|
+
if (!specifiers)
|
|
663
|
+
return;
|
|
664
|
+
const filteredSpecifiers = specifiers.filter((spec) => {
|
|
665
|
+
if (j.ExportSpecifier.check(spec) && j.Identifier.check(spec.local)) {
|
|
666
|
+
return spec.local.name !== 'runtime';
|
|
667
|
+
}
|
|
668
|
+
return true;
|
|
669
|
+
});
|
|
670
|
+
// If we removed any specifiers
|
|
671
|
+
if (filteredSpecifiers.length !== specifiers.length) {
|
|
672
|
+
hasChanges = true;
|
|
673
|
+
// If no specifiers left, remove the entire export statement
|
|
674
|
+
if (filteredSpecifiers.length === 0) {
|
|
675
|
+
j(path).remove();
|
|
676
|
+
}
|
|
677
|
+
else {
|
|
678
|
+
// Update the specifiers array
|
|
679
|
+
path.node.specifiers = filteredSpecifiers;
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
});
|
|
683
|
+
// Handle runtime property in config objects
|
|
684
|
+
const configExports = root.find(j.ExportNamedDeclaration, {
|
|
685
|
+
declaration: {
|
|
686
|
+
type: 'VariableDeclaration',
|
|
687
|
+
declarations: [
|
|
688
|
+
{
|
|
689
|
+
id: { name: 'config' },
|
|
690
|
+
},
|
|
691
|
+
],
|
|
692
|
+
},
|
|
693
|
+
});
|
|
694
|
+
configExports.forEach((path) => {
|
|
695
|
+
const declaration = path.node.declaration;
|
|
696
|
+
if (j.VariableDeclaration.check(declaration)) {
|
|
697
|
+
declaration.declarations.forEach((decl) => {
|
|
698
|
+
if (j.VariableDeclarator.check(decl) &&
|
|
699
|
+
j.Identifier.check(decl.id) &&
|
|
700
|
+
decl.id.name === 'config' &&
|
|
701
|
+
j.ObjectExpression.check(decl.init)) {
|
|
702
|
+
const objExpr = decl.init;
|
|
703
|
+
const initialLength = objExpr.properties.length;
|
|
704
|
+
// Filter out runtime property
|
|
705
|
+
objExpr.properties = objExpr.properties.filter((prop) => {
|
|
706
|
+
if (isStaticProperty(prop) &&
|
|
707
|
+
prop.key &&
|
|
708
|
+
prop.key.type === 'Identifier') {
|
|
709
|
+
return prop.key.name !== 'runtime';
|
|
710
|
+
}
|
|
711
|
+
return true;
|
|
712
|
+
});
|
|
713
|
+
// If we removed any properties
|
|
714
|
+
if (objExpr.properties.length !== initialLength) {
|
|
715
|
+
hasChanges = true;
|
|
716
|
+
// If no properties left, remove the entire config export
|
|
717
|
+
if (objExpr.properties.length === 0) {
|
|
718
|
+
j(path).remove();
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
});
|
|
723
|
+
}
|
|
724
|
+
});
|
|
725
|
+
return hasChanges;
|
|
726
|
+
}
|
|
605
727
|
//# sourceMappingURL=middleware-to-proxy.js.map
|