@workday/canvas-kit-codemod 7.0.0-alpha.96-next.22 → 7.0.0-alpha.97-next.23
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../lib/v7/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../lib/v7/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AActC,QAAA,MAAM,SAAS,EAAE,SAiBhB,CAAC;AACF,eAAe,SAAS,CAAC"}
|
package/dist/es6/v7/index.js
CHANGED
|
@@ -19,6 +19,7 @@ import renameIconPosition from './renameIconPosition';
|
|
|
19
19
|
import recategorizeIconButtons from './recategorizeIconButtons';
|
|
20
20
|
import updateModelSignatures from './updateModelSignatures';
|
|
21
21
|
import updateTabs from './updateTabs';
|
|
22
|
+
import updateDisclosureShowHide from './updateDisclosureShowHide';
|
|
22
23
|
var transform = function (file, api, options) {
|
|
23
24
|
// These will run in order. If your transform depends on others, place yours after dependent transforms
|
|
24
25
|
var fixes = [
|
|
@@ -32,6 +33,7 @@ var transform = function (file, api, options) {
|
|
|
32
33
|
updateSegmentedControl,
|
|
33
34
|
updateModelSignatures,
|
|
34
35
|
updateTabs,
|
|
36
|
+
updateDisclosureShowHide,
|
|
35
37
|
];
|
|
36
38
|
return fixes.reduce(function (source, fix) { return fix(__assign(__assign({}, file), { source: source }), api, options); }, file.source);
|
|
37
39
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"updateDisclosureShowHide.d.ts","sourceRoot":"","sources":["../../../lib/v7/updateDisclosureShowHide.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAA6B,OAAO,EAAC,MAAM,aAAa,CAAC;AAK9E,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UAiH7E"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { getImportRenameMap } from './utils/getImportRenameMap';
|
|
2
|
+
var keys = function (input) { return Object.keys(input); };
|
|
3
|
+
export default function transformer(file, api, options) {
|
|
4
|
+
var j = api.jscodeshift;
|
|
5
|
+
var root = j(file.source);
|
|
6
|
+
var _a = getImportRenameMap(j, root), containsCanvasImports = _a.containsCanvasImports, importMap = _a.importMap;
|
|
7
|
+
if (!containsCanvasImports) {
|
|
8
|
+
return file.source;
|
|
9
|
+
}
|
|
10
|
+
var disclosureModels = [
|
|
11
|
+
'useDisclosureModel',
|
|
12
|
+
'usePopupModel',
|
|
13
|
+
'useModalModel',
|
|
14
|
+
'useDialogModel',
|
|
15
|
+
];
|
|
16
|
+
// inverse the import map. It is more useful this way for this function
|
|
17
|
+
var imports = Object.keys(importMap).reduce(function (result, key) {
|
|
18
|
+
result[importMap[key]] = key;
|
|
19
|
+
return result;
|
|
20
|
+
}, {});
|
|
21
|
+
root.find(j.CallExpression).forEach(function (nodePath) {
|
|
22
|
+
var value = nodePath.value;
|
|
23
|
+
// check if the identifier was imported from CK AND follows the `use{*}Model` naming convention
|
|
24
|
+
if (value.callee.type === 'Identifier' &&
|
|
25
|
+
disclosureModels.includes(imports[value.callee.name])) {
|
|
26
|
+
// loop over all the arguments of the `use{*}Model` hook
|
|
27
|
+
value.arguments.forEach(function (argument) {
|
|
28
|
+
// look for object expressions: `use{*}Model({ /* here */ })`
|
|
29
|
+
if (argument.type === 'ObjectExpression') {
|
|
30
|
+
// loop over all the properties looking for `ObjectMethod` and `ObjectProperties` where
|
|
31
|
+
// the value is a function matching `on{*}` or `should{*}` naming convention
|
|
32
|
+
argument.properties.forEach(function (property) {
|
|
33
|
+
// If it is an `ObjectMethod` or an `ObjectProperty` with an arrow function expression:
|
|
34
|
+
// {
|
|
35
|
+
// onShow() {}, // ObjectMethod
|
|
36
|
+
// onHide: () => {}, ObjectProperty with arrow function expression
|
|
37
|
+
// }
|
|
38
|
+
if ((property.type === 'ObjectMethod' ||
|
|
39
|
+
(property.type === 'ObjectProperty' &&
|
|
40
|
+
property.value.type === 'ArrowFunctionExpression')) &&
|
|
41
|
+
property.key.type === 'Identifier') {
|
|
42
|
+
var propertyName_1 = property.key.name;
|
|
43
|
+
// Both types have a `params`, but are at different places in the AST
|
|
44
|
+
var params_1 = property.type === 'ObjectMethod'
|
|
45
|
+
? property.params
|
|
46
|
+
: property.value.type === 'ArrowFunctionExpression'
|
|
47
|
+
? property.value.params
|
|
48
|
+
: [];
|
|
49
|
+
// create a mapping for param names of callbacks and guards. This makes the logic more
|
|
50
|
+
// difficult to follow, but decreases duplication
|
|
51
|
+
var paramMapping_1 = {
|
|
52
|
+
on: ['event'],
|
|
53
|
+
should: ['event'],
|
|
54
|
+
};
|
|
55
|
+
// We will be overriding the params with this variable later
|
|
56
|
+
var finalParams_1 = [];
|
|
57
|
+
// loop over each `paramMapping` type. `on*` and `should*` functions have different signatures
|
|
58
|
+
keys(paramMapping_1).forEach(function (key) {
|
|
59
|
+
// matches `onShow` and `shouldShow`
|
|
60
|
+
if (new RegExp(key + "[A-Za-z]+").test(propertyName_1)) {
|
|
61
|
+
params_1.forEach(function (param) {
|
|
62
|
+
if (param.type === 'ObjectPattern') {
|
|
63
|
+
param.properties.forEach(function (property) {
|
|
64
|
+
if (property.type === 'ObjectProperty' &&
|
|
65
|
+
property.key.type === 'Identifier') {
|
|
66
|
+
if (property.value.type === 'Identifier' ||
|
|
67
|
+
property.value.type === 'ObjectPattern') {
|
|
68
|
+
var index = paramMapping_1[key].indexOf(property.key.name);
|
|
69
|
+
// use `property.value` instead of `property.key.name` in case they
|
|
70
|
+
// renamed it example `shouldShow({ data: myData })`. The key name is
|
|
71
|
+
// `data` while the value is `myData`
|
|
72
|
+
finalParams_1[index] = property.value;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
// `ObjectMethod` and `ObjectProperty` have params in a different place in the
|
|
79
|
+
// AST, so apply `finalParams` where appropriate
|
|
80
|
+
if (property.type === 'ObjectMethod') {
|
|
81
|
+
property.params = finalParams_1;
|
|
82
|
+
}
|
|
83
|
+
else if (property.type === 'ObjectProperty' &&
|
|
84
|
+
property.value.type === 'ArrowFunctionExpression') {
|
|
85
|
+
property.value.params = finalParams_1;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
return root.toSource();
|
|
96
|
+
}
|
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": "7.0.0-alpha.
|
|
5
|
+
"version": "7.0.0-alpha.97-next.23+36224fdd",
|
|
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,
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"test": "TZ=UTC jest -c ../../jest.config.js",
|
|
43
43
|
"typecheck:src": "tsc -p . --noEmit --incremental false"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "36224fddf0e1c2382b1cbbeb1a2a2d356bfd22a3"
|
|
46
46
|
}
|