@workday/canvas-kit-codemod 14.0.0-alpha.1237-next.0 → 14.0.0-alpha.1239-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.
- package/dist/es6/v14/index.d.ts.map +1 -1
- package/dist/es6/v14/index.js +11 -1
- package/dist/es6/v14/renameErrorTypeAlert.d.ts +3 -0
- package/dist/es6/v14/renameErrorTypeAlert.d.ts.map +1 -0
- package/dist/es6/v14/renameErrorTypeAlert.js +37 -0
- package/dist/es6/v14/renameErrorTypeAlertOnInputs.d.ts +3 -0
- package/dist/es6/v14/renameErrorTypeAlertOnInputs.d.ts.map +1 -0
- package/dist/es6/v14/renameErrorTypeAlertOnInputs.js +65 -0
- package/dist/es6/v14/updateFormFieldAlert.d.ts +3 -0
- package/dist/es6/v14/updateFormFieldAlert.d.ts.map +1 -0
- package/dist/es6/v14/updateFormFieldAlert.js +42 -0
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../lib/v14/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../lib/v14/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAStC,QAAA,MAAM,SAAS,EAAE,SAWhB,CAAC;AAEF,eAAe,SAAS,CAAC"}
|
package/dist/es6/v14/index.js
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
import updateStatusIndicatorPreview from './updateStatusIndicatorPreview';
|
|
2
2
|
import updatePillAvatarProp from './updatePillAvatarProp';
|
|
3
3
|
import updateExpandableAvatarProp from './updateExpandableAvatarProp';
|
|
4
|
+
import updateFormFieldAlert from './updateFormFieldAlert';
|
|
5
|
+
import renameErrorTypeAlertOnInputs from './renameErrorTypeAlertOnInputs';
|
|
6
|
+
import renameErrorTypeAlert from './renameErrorTypeAlert';
|
|
4
7
|
const transform = (file, api, options) => {
|
|
5
8
|
// These will run in order. If your transform depends on others, place yours after dependent transforms
|
|
6
|
-
const fixes = [
|
|
9
|
+
const fixes = [
|
|
10
|
+
updateStatusIndicatorPreview,
|
|
11
|
+
updatePillAvatarProp,
|
|
12
|
+
updateExpandableAvatarProp,
|
|
13
|
+
renameErrorTypeAlert,
|
|
14
|
+
updateFormFieldAlert,
|
|
15
|
+
renameErrorTypeAlertOnInputs,
|
|
16
|
+
];
|
|
7
17
|
return fixes.reduce((source, fix) => fix({ ...file, source }, api, options), file.source);
|
|
8
18
|
};
|
|
9
19
|
export default transform;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renameErrorTypeAlert.d.ts","sourceRoot":"","sources":["../../../lib/v14/renameErrorTypeAlert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAoB,OAAO,EAAC,MAAM,aAAa,CAAC;AAOrE,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UA8C7E"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { hasImportSpecifiers } from '../v6/utils';
|
|
2
|
+
import { getImportRenameMap } from './utils/getImportRenameMap';
|
|
3
|
+
const packages = ['@workday/canvas-kit-react', '@workday/canvas-kit-react/common'];
|
|
4
|
+
const packageImports = ['ErrorType'];
|
|
5
|
+
export default function transformer(file, api, options) {
|
|
6
|
+
const j = api.jscodeshift;
|
|
7
|
+
const root = j(file.source);
|
|
8
|
+
// exit if the named imports aren't found
|
|
9
|
+
if (!hasImportSpecifiers(api, root, packages, packageImports)) {
|
|
10
|
+
return file.source;
|
|
11
|
+
}
|
|
12
|
+
// getImportRenameMap utility will tell us if the file containsCanvasImports
|
|
13
|
+
// and give us an importMap to track what identifiers we need to update
|
|
14
|
+
const { importMap, styledMap } = getImportRenameMap(j, root, '@workday/canvas-kit-react');
|
|
15
|
+
// Find all member expressions that match ErrorType.Alert pattern
|
|
16
|
+
const memberExpressions = root.find(j.MemberExpression, (value) => {
|
|
17
|
+
// Check if it's a member expression with ErrorType.Alert pattern
|
|
18
|
+
return (value.object.type === 'Identifier' &&
|
|
19
|
+
value.property.type === 'Identifier' &&
|
|
20
|
+
value.object.type === 'Identifier' &&
|
|
21
|
+
(value.object.name === importMap.ErrorType || value.object.name === styledMap.ErrorType) &&
|
|
22
|
+
value.property.name === 'Alert');
|
|
23
|
+
});
|
|
24
|
+
// Replace ErrorType.Alert with ErrorType.Caution
|
|
25
|
+
memberExpressions.forEach(path => {
|
|
26
|
+
const memberExpression = path.value;
|
|
27
|
+
// Get the ErrorType identifier name (in case it was renamed during import)
|
|
28
|
+
if (memberExpression.object.type === 'Identifier') {
|
|
29
|
+
const errorTypeIdentifier = memberExpression.object.name;
|
|
30
|
+
// Create the new member expression: ErrorType.Caution
|
|
31
|
+
const newMemberExpression = j.memberExpression(j.identifier(errorTypeIdentifier), j.identifier('Caution'));
|
|
32
|
+
j(path).replaceWith(newMemberExpression);
|
|
33
|
+
}
|
|
34
|
+
// Replace the entire member expression
|
|
35
|
+
});
|
|
36
|
+
return root.toSource();
|
|
37
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renameErrorTypeAlertOnInputs.d.ts","sourceRoot":"","sources":["../../../lib/v14/renameErrorTypeAlertOnInputs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAA4B,OAAO,EAAC,MAAM,aAAa,CAAC;AAY7E,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UA8E7E"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { hasImportSpecifiers } from '../v6/utils';
|
|
2
|
+
import { getImportRenameMap } from './utils/getImportRenameMap';
|
|
3
|
+
const packages = [
|
|
4
|
+
'@workday/canvas-kit-react',
|
|
5
|
+
'@workday/canvas-kit-react/text-input',
|
|
6
|
+
'@workday/canvas-kit-react/switch',
|
|
7
|
+
'@workday/canvas-kit-react/text-area',
|
|
8
|
+
];
|
|
9
|
+
const packageImports = ['TextInput', 'Switch', 'TextArea'];
|
|
10
|
+
export default function transformer(file, api, options) {
|
|
11
|
+
const j = api.jscodeshift;
|
|
12
|
+
const root = j(file.source);
|
|
13
|
+
// exit if the named imports aren't found
|
|
14
|
+
if (!hasImportSpecifiers(api, root, packages, packageImports)) {
|
|
15
|
+
return file.source;
|
|
16
|
+
}
|
|
17
|
+
// getImportRenameMap utility will tell us if the file containsCanvasImports
|
|
18
|
+
// and give us an importMap to track what identifiers we need to update
|
|
19
|
+
const { importMap, styledMap } = getImportRenameMap(j, root, '@workday/canvas-kit-react');
|
|
20
|
+
// Find all TextInput, Switch, and TextArea components
|
|
21
|
+
const components = root.find(j.JSXElement, (value) => value.openingElement.name.type === 'JSXIdentifier' &&
|
|
22
|
+
(value.openingElement.name.name === importMap.TextInput ||
|
|
23
|
+
value.openingElement.name.name === styledMap.TextInput ||
|
|
24
|
+
value.openingElement.name.name === importMap.Switch ||
|
|
25
|
+
value.openingElement.name.name === styledMap.Switch ||
|
|
26
|
+
value.openingElement.name.name === importMap.TextArea ||
|
|
27
|
+
value.openingElement.name.name === styledMap.TextArea));
|
|
28
|
+
// Update the `error` prop from ComponentName.ErrorType.Alert to ComponentName.ErrorType.Caution
|
|
29
|
+
components.forEach(component => {
|
|
30
|
+
var _a;
|
|
31
|
+
const errorProp = (_a = component.value.openingElement.attributes) === null || _a === void 0 ? void 0 : _a.find(attr => attr.type === 'JSXAttribute' && attr.name.name === 'error');
|
|
32
|
+
if (errorProp && errorProp.value && errorProp.value.type === 'JSXExpressionContainer') {
|
|
33
|
+
const expression = errorProp.value.expression;
|
|
34
|
+
// Check if it's a member expression like TextInput.ErrorType.Alert
|
|
35
|
+
if (expression.type === 'MemberExpression') {
|
|
36
|
+
const memberExpr = expression;
|
|
37
|
+
// Check if it matches the pattern ComponentName.ErrorType.Alert
|
|
38
|
+
if (memberExpr.object.type === 'MemberExpression' &&
|
|
39
|
+
memberExpr.object.property.type === 'Identifier' &&
|
|
40
|
+
memberExpr.object.property.name === 'ErrorType' &&
|
|
41
|
+
memberExpr.property.type === 'Identifier' &&
|
|
42
|
+
memberExpr.property.name === 'Alert') {
|
|
43
|
+
// Get the component name (TextInput, Switch, or TextArea)
|
|
44
|
+
const componentIdentifier = memberExpr.object.object;
|
|
45
|
+
if (componentIdentifier.type === 'Identifier') {
|
|
46
|
+
// Verify it's one of our target components
|
|
47
|
+
const componentName = componentIdentifier.name;
|
|
48
|
+
const isTargetComponent = componentName === importMap.TextInput ||
|
|
49
|
+
componentName === styledMap.TextInput ||
|
|
50
|
+
componentName === importMap.Switch ||
|
|
51
|
+
componentName === styledMap.Switch ||
|
|
52
|
+
componentName === importMap.TextArea ||
|
|
53
|
+
componentName === styledMap.TextArea;
|
|
54
|
+
if (isTargetComponent) {
|
|
55
|
+
// Create the new member expression: ComponentName.ErrorType.Caution
|
|
56
|
+
const newMemberExpression = j.memberExpression(j.memberExpression(j.identifier(componentName), j.identifier('ErrorType')), j.identifier('Caution'));
|
|
57
|
+
errorProp.value = j.jsxExpressionContainer(newMemberExpression);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
return root.toSource();
|
|
65
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"updateFormFieldAlert.d.ts","sourceRoot":"","sources":["../../../lib/v14/updateFormFieldAlert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAA4B,OAAO,EAAC,MAAM,aAAa,CAAC;AAO7E,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UA6D7E"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { hasImportSpecifiers } from '../v6/utils';
|
|
2
|
+
import { getImportRenameMap } from './utils/getImportRenameMap';
|
|
3
|
+
const packages = ['@workday/canvas-kit-preview-react', '@workday/canvas-kit-react/form-field'];
|
|
4
|
+
const packageImports = ['FormField'];
|
|
5
|
+
export default function transformer(file, api, options) {
|
|
6
|
+
const j = api.jscodeshift;
|
|
7
|
+
const root = j(file.source);
|
|
8
|
+
// exit if the named imports aren't found
|
|
9
|
+
if (!hasImportSpecifiers(api, root, packages, packageImports)) {
|
|
10
|
+
return file.source;
|
|
11
|
+
}
|
|
12
|
+
// getImportRenameMap utility will tell us if the file containsCanvasImports
|
|
13
|
+
// and give us an importMap to track what identifiers we need to update
|
|
14
|
+
const { importMap, styledMap } = getImportRenameMap(j, root, '@workday/canvas-kit-react');
|
|
15
|
+
// Find all <FormField> components
|
|
16
|
+
const components = root.find(j.JSXElement, (value) => value.openingElement.name.type === 'JSXIdentifier' &&
|
|
17
|
+
(value.openingElement.name.name === importMap.FormField ||
|
|
18
|
+
value.openingElement.name.name === styledMap.FormField));
|
|
19
|
+
// Update the `error` prop to the new value
|
|
20
|
+
components.forEach(component => {
|
|
21
|
+
var _a;
|
|
22
|
+
const errorProp = (_a = component.value.openingElement.attributes) === null || _a === void 0 ? void 0 : _a.find(attr => attr.type === 'JSXAttribute' && attr.name.name === 'error');
|
|
23
|
+
// For string literals like `error="alert"`
|
|
24
|
+
if (errorProp && errorProp.value && errorProp.value.type === 'StringLiteral') {
|
|
25
|
+
errorProp.value = j.stringLiteral('caution');
|
|
26
|
+
}
|
|
27
|
+
if (errorProp &&
|
|
28
|
+
errorProp.value &&
|
|
29
|
+
errorProp.value.type === 'JSXExpressionContainer' &&
|
|
30
|
+
(errorProp.value.expression.type === 'Literal' ||
|
|
31
|
+
errorProp.value.expression.type === 'StringLiteral')) {
|
|
32
|
+
errorProp.value = j.stringLiteral('caution');
|
|
33
|
+
}
|
|
34
|
+
if (errorProp &&
|
|
35
|
+
errorProp.value &&
|
|
36
|
+
errorProp.value.type === 'JSXExpressionContainer' &&
|
|
37
|
+
errorProp.value.expression.type === 'ConditionalExpression') {
|
|
38
|
+
errorProp.value = j.jsxExpressionContainer(j.conditionalExpression(errorProp.value.expression.test, j.stringLiteral('error'), j.stringLiteral('caution')));
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
return root.toSource();
|
|
42
|
+
}
|
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": "14.0.0-alpha.
|
|
5
|
+
"version": "14.0.0-alpha.1239-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": "fdb8b845a09a86de1fb0a383fb3c5def6016e064"
|
|
50
50
|
}
|