@workday/canvas-kit-codemod 13.0.0-alpha.1051-next.0 → 13.0.0-alpha.1061-next.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.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addPillLabel.d.ts","sourceRoot":"","sources":["../../../lib/v13/addPillLabel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAA6B,OAAO,EAAC,MAAM,aAAa,CAAC;AAM9E,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UA4E7E"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { getImportRenameMap } from './utils/getImportRenameMap';
|
|
2
|
+
import { hasImportSpecifiers } from '../v6/utils';
|
|
3
|
+
const pillPackage = '@workday/canvas-kit-preview-react/pill';
|
|
4
|
+
export default function transformer(file, api, options) {
|
|
5
|
+
const j = api.jscodeshift;
|
|
6
|
+
const root = j(file.source);
|
|
7
|
+
// Skip transformation if Pill is not imported from the target package
|
|
8
|
+
if (!hasImportSpecifiers(api, root, pillPackage, ['Pill'])) {
|
|
9
|
+
return file.source;
|
|
10
|
+
}
|
|
11
|
+
const { importMap, styledMap } = getImportRenameMap(j, root, '@workday/canvas-kit-preview-react');
|
|
12
|
+
root
|
|
13
|
+
.find(j.JSXElement, (value) => value.openingElement.name.type === 'JSXIdentifier' &&
|
|
14
|
+
(value.openingElement.name.name === importMap.Pill ||
|
|
15
|
+
value.openingElement.name.name === styledMap.Pill))
|
|
16
|
+
.forEach(nodePath => {
|
|
17
|
+
var _a;
|
|
18
|
+
// Get the local name of the Pill component (e.g., Pill, MyPill, StyledPill)
|
|
19
|
+
const pillName = nodePath.node.openingElement.name.name;
|
|
20
|
+
// Check for subcomponents using the local Pill name
|
|
21
|
+
const hasPillSubcomponents = nodePath.node.children &&
|
|
22
|
+
nodePath.node.children.some(child => {
|
|
23
|
+
if (child.type === 'JSXElement' &&
|
|
24
|
+
child.openingElement.type === 'JSXOpeningElement' &&
|
|
25
|
+
child.openingElement.name.type === 'JSXMemberExpression' &&
|
|
26
|
+
child.openingElement.name.object.type === 'JSXIdentifier' &&
|
|
27
|
+
child.openingElement.name.object.name === pillName) {
|
|
28
|
+
return (child.openingElement.name.property.name === 'Icon' ||
|
|
29
|
+
child.openingElement.name.property.name === 'Avatar' ||
|
|
30
|
+
child.openingElement.name.property.name === 'IconButton' ||
|
|
31
|
+
child.openingElement.name.property.name === 'Count');
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
34
|
+
});
|
|
35
|
+
// If subcomponents are present, wrap text and expressions in Pill.Label
|
|
36
|
+
if (hasPillSubcomponents) {
|
|
37
|
+
nodePath.node.children = (_a = nodePath.node.children) === null || _a === void 0 ? void 0 : _a.map(child => {
|
|
38
|
+
if (child.type === 'JSXText' && child.value.trim() !== '') {
|
|
39
|
+
return j.jsxElement(j.jsxOpeningElement(j.jsxMemberExpression(j.jsxIdentifier(pillName), j.jsxIdentifier('Label')), []), j.jsxClosingElement(j.jsxMemberExpression(j.jsxIdentifier(pillName), j.jsxIdentifier('Label'))), [child]);
|
|
40
|
+
}
|
|
41
|
+
else if (child.type === 'JSXExpressionContainer') {
|
|
42
|
+
return j.jsxElement(j.jsxOpeningElement(j.jsxMemberExpression(j.jsxIdentifier(pillName), j.jsxIdentifier('Label')), []), j.jsxClosingElement(j.jsxMemberExpression(j.jsxIdentifier(pillName), j.jsxIdentifier('Label'))), [child]);
|
|
43
|
+
}
|
|
44
|
+
return child;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
return root.toSource();
|
|
49
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../lib/v13/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../lib/v13/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAGtC,QAAA,MAAM,SAAS,EAAE,SAOhB,CAAC;AAEF,eAAe,SAAS,CAAC"}
|
package/dist/es6/v13/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import addPillLabel from './addPillLabel';
|
|
1
2
|
const transform = (file, api, options) => {
|
|
2
3
|
// These will run in order. If your transform depends on others, place yours after dependent transforms
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const fixes = [
|
|
5
|
+
// add codemods here
|
|
6
|
+
addPillLabel,
|
|
7
|
+
];
|
|
8
|
+
return fixes.reduce((source, fix) => fix({ ...file, source }, api, options), file.source);
|
|
7
9
|
};
|
|
8
10
|
export default transform;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@workday/canvas-kit-codemod",
|
|
3
3
|
"author": "Workday, Inc. (https://www.workday.com)",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
|
-
"version": "13.0.0-alpha.
|
|
5
|
+
"version": "13.0.0-alpha.1061-next.0",
|
|
6
6
|
"description": "A collection of codemods for use on Workday Canvas Kit packages.",
|
|
7
7
|
"main": "dist/es6/index.js",
|
|
8
8
|
"sideEffects": false,
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"resolutions": {
|
|
47
47
|
"recast": "0.20.4"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "dcac6a3ea9994aac312ac7e7b6a616899f250d36"
|
|
50
50
|
}
|