@react-spectrum/codemods 0.1.1 → 0.1.2-nightly.5030
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.
|
@@ -42,6 +42,23 @@ exports.changes = {
|
|
|
42
42
|
}
|
|
43
43
|
]
|
|
44
44
|
},
|
|
45
|
+
Badge: {
|
|
46
|
+
changes: [
|
|
47
|
+
{
|
|
48
|
+
description: "Change variant='info' to variant='informative'",
|
|
49
|
+
reason: 'Updated naming convention',
|
|
50
|
+
function: {
|
|
51
|
+
name: 'updatePropNameAndValue',
|
|
52
|
+
args: {
|
|
53
|
+
oldProp: 'variant',
|
|
54
|
+
oldValue: 'info',
|
|
55
|
+
newProp: 'variant',
|
|
56
|
+
newValue: 'informative'
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
]
|
|
61
|
+
},
|
|
45
62
|
Breadcrumbs: {
|
|
46
63
|
changes: [
|
|
47
64
|
{
|
|
@@ -332,18 +349,6 @@ exports.changes = {
|
|
|
332
349
|
}
|
|
333
350
|
]
|
|
334
351
|
},
|
|
335
|
-
Flex: {
|
|
336
|
-
changes: [
|
|
337
|
-
{
|
|
338
|
-
description: 'Update Flex to be a div and apply flex styles using the style macro',
|
|
339
|
-
reason: 'Updated API',
|
|
340
|
-
function: {
|
|
341
|
-
name: 'updateToNewComponent',
|
|
342
|
-
args: { newComponent: 'div' }
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
]
|
|
346
|
-
},
|
|
347
352
|
Form: {
|
|
348
353
|
changes: [
|
|
349
354
|
{
|
|
@@ -366,18 +371,6 @@ exports.changes = {
|
|
|
366
371
|
}
|
|
367
372
|
]
|
|
368
373
|
},
|
|
369
|
-
Grid: {
|
|
370
|
-
changes: [
|
|
371
|
-
{
|
|
372
|
-
description: 'Update Grid to be a div and apply grid styles using the style macro',
|
|
373
|
-
reason: 'Updated API',
|
|
374
|
-
function: {
|
|
375
|
-
name: 'updateToNewComponent',
|
|
376
|
-
args: { newComponent: 'div' }
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
]
|
|
380
|
-
},
|
|
381
374
|
InlineAlert: {
|
|
382
375
|
changes: [
|
|
383
376
|
{
|
|
@@ -499,6 +492,14 @@ exports.changes = {
|
|
|
499
492
|
newValue: 'white'
|
|
500
493
|
}
|
|
501
494
|
}
|
|
495
|
+
},
|
|
496
|
+
{
|
|
497
|
+
description: 'Remove inner anchor element if used (legacy API)',
|
|
498
|
+
reason: 'Updated API',
|
|
499
|
+
function: {
|
|
500
|
+
name: 'updateLegacyLink',
|
|
501
|
+
args: {}
|
|
502
|
+
}
|
|
502
503
|
}
|
|
503
504
|
]
|
|
504
505
|
},
|
|
@@ -1090,17 +1091,5 @@ exports.changes = {
|
|
|
1090
1091
|
}
|
|
1091
1092
|
}
|
|
1092
1093
|
]
|
|
1093
|
-
},
|
|
1094
|
-
View: {
|
|
1095
|
-
changes: [
|
|
1096
|
-
{
|
|
1097
|
-
description: 'Update View to be a div and apply styles using the style macro',
|
|
1098
|
-
reason: 'Updated API',
|
|
1099
|
-
function: {
|
|
1100
|
-
name: 'updateToNewComponent',
|
|
1101
|
-
args: { newComponent: 'div' }
|
|
1102
|
-
}
|
|
1103
|
-
}
|
|
1104
|
-
]
|
|
1105
1094
|
}
|
|
1106
1095
|
};
|
|
@@ -41,6 +41,7 @@ let availableComponents = (0, getComponents_1.getComponents)();
|
|
|
41
41
|
availableComponents.add('View');
|
|
42
42
|
availableComponents.add('Flex');
|
|
43
43
|
availableComponents.add('Grid');
|
|
44
|
+
availableComponents.add('Well');
|
|
44
45
|
// Replaced by collection component-specific items
|
|
45
46
|
availableComponents.add('Item');
|
|
46
47
|
availableComponents.add('Section');
|
|
@@ -196,9 +197,11 @@ function transformer(file, api, options) {
|
|
|
196
197
|
if (t.isImportSpecifier(b.path.node) &&
|
|
197
198
|
t.isIdentifier(b.path.node.imported) &&
|
|
198
199
|
(b.path.node.imported.name === 'Item' || b.path.node.imported.name === 'Section')) {
|
|
199
|
-
// Keep Item and Section imports
|
|
200
|
-
|
|
201
|
-
|
|
200
|
+
// Keep Item and Section imports if they are still used
|
|
201
|
+
bindings[0]?.path.scope.crawl();
|
|
202
|
+
if (bindings[0]?.path.scope.bindings[b.path.node.local.name]?.referencePaths.length > 0) {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
202
205
|
}
|
|
203
206
|
b.path.remove();
|
|
204
207
|
// If the import statement is now empty, remove it entirely.
|
|
@@ -484,7 +484,7 @@ function handleProp(path, element, colorVersion) {
|
|
|
484
484
|
(0, utils_1.addComment)(path.node, ' TODO(S2-upgrade): check this UNSAFE_style');
|
|
485
485
|
break;
|
|
486
486
|
case 'UNSAFE_className':
|
|
487
|
-
if (element === 'Flex' || element === 'Grid' || element === 'View') {
|
|
487
|
+
if (element === 'Flex' || element === 'Grid' || element === 'View' || element === 'Well') {
|
|
488
488
|
path.get('name').replaceWith(t.jsxIdentifier('className'));
|
|
489
489
|
}
|
|
490
490
|
else {
|
|
@@ -508,13 +508,26 @@ function transformStyleProps(path, element) {
|
|
|
508
508
|
let macroValues = new Map;
|
|
509
509
|
let dynamicValues = new Map;
|
|
510
510
|
let conditions = new Map;
|
|
511
|
-
let isDOMElement = element === 'Flex' || element === 'Grid' || element === 'View';
|
|
511
|
+
let isDOMElement = element === 'Flex' || element === 'Grid' || element === 'View' || element === 'Well';
|
|
512
512
|
if (element === 'Flex') {
|
|
513
513
|
macroValues.set('display', 'flex');
|
|
514
514
|
}
|
|
515
515
|
else if (element === 'Grid') {
|
|
516
516
|
macroValues.set('display', 'grid');
|
|
517
517
|
}
|
|
518
|
+
else if (element === 'Well') {
|
|
519
|
+
macroValues.set('display', 'block');
|
|
520
|
+
macroValues.set('textAlign', 'start');
|
|
521
|
+
macroValues.set('minWidth', 160);
|
|
522
|
+
macroValues.set('padding', 16);
|
|
523
|
+
macroValues.set('marginTop', 4);
|
|
524
|
+
macroValues.set('borderWidth', 1);
|
|
525
|
+
macroValues.set('borderRadius', 'sm');
|
|
526
|
+
macroValues.set('backgroundColor', 'layer-1');
|
|
527
|
+
macroValues.set('borderStyle', 'solid');
|
|
528
|
+
macroValues.set('borderColor', 'transparent-black-75');
|
|
529
|
+
macroValues.set('font', 'body-sm');
|
|
530
|
+
}
|
|
518
531
|
let attrs = path.get('openingElement').get('attributes');
|
|
519
532
|
// Find the color version in use.
|
|
520
533
|
let colorVersion = 5;
|
|
@@ -663,6 +663,28 @@ function updateAvatarSize(path) {
|
|
|
663
663
|
}
|
|
664
664
|
}
|
|
665
665
|
}
|
|
666
|
+
/**
|
|
667
|
+
* Handles the legacy `Link` API where an `a` tag or custom router component could be used within a `Link` component.
|
|
668
|
+
* Removes the inner component and moves its attributes to the `Link` component.
|
|
669
|
+
*/
|
|
670
|
+
function updateLegacyLink(path) {
|
|
671
|
+
let missingOuterHref = t.isJSXElement(path.node) && !path.node.openingElement.attributes.some((attr) => t.isJSXAttribute(attr) && attr.name.name === 'href');
|
|
672
|
+
if (missingOuterHref) {
|
|
673
|
+
let innerLink = path.node.children.find((child) => t.isJSXElement(child) && t.isJSXIdentifier(child.openingElement.name));
|
|
674
|
+
if (innerLink && t.isJSXElement(innerLink)) {
|
|
675
|
+
let innerAttributes = innerLink.openingElement.attributes;
|
|
676
|
+
let outerAttributes = path.node.openingElement.attributes;
|
|
677
|
+
innerAttributes.forEach((attr) => {
|
|
678
|
+
outerAttributes.push(attr);
|
|
679
|
+
});
|
|
680
|
+
if (t.isJSXIdentifier(innerLink.openingElement.name) &&
|
|
681
|
+
innerLink.openingElement.name.name !== 'a') {
|
|
682
|
+
(0, utils_1.addComment)(path.node, ' TODO(S2-upgrade): You may have been using a custom link component here. You\'ll need to update this manually.');
|
|
683
|
+
}
|
|
684
|
+
path.node.children = innerLink.children;
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
}
|
|
666
688
|
exports.functionMap = {
|
|
667
689
|
updatePropNameAndValue,
|
|
668
690
|
updatePropValueAndAddNewProp,
|
|
@@ -681,5 +703,6 @@ exports.functionMap = {
|
|
|
681
703
|
convertDimensionValueToPx,
|
|
682
704
|
updatePlacementToSingleValue,
|
|
683
705
|
removeComponentIfWithinParent,
|
|
684
|
-
updateAvatarSize
|
|
706
|
+
updateAvatarSize,
|
|
707
|
+
updateLegacyLink
|
|
685
708
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-spectrum/codemods",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2-nightly.5030+32574f874",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"bin": "dist/index.js",
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"@babel/parser": "^7.24.5",
|
|
25
25
|
"@babel/traverse": "^7.24.5",
|
|
26
26
|
"@babel/types": "^7.24.5",
|
|
27
|
-
"@react-spectrum/s2": "
|
|
28
|
-
"@react-types/shared": "
|
|
27
|
+
"@react-spectrum/s2": "0.3.2-nightly.5030+32574f874",
|
|
28
|
+
"@react-types/shared": "3.0.0-nightly.3102+32574f874",
|
|
29
29
|
"@types/node": "^20",
|
|
30
30
|
"boxen": "^5.1.2",
|
|
31
31
|
"build": "^0.1.4",
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"publishConfig": {
|
|
48
48
|
"access": "public"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "32574f874fd8a8b667a409938457819ac33f8e84"
|
|
51
51
|
}
|