@workday/canvas-kit-codemod 7.0.0-alpha.0-next.6 → 7.0.0-alpha.0-next.7
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":"compoundActionBar.d.ts","sourceRoot":"","sources":["../../../lib/v7/compoundActionBar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAyC,MAAM,aAAa,CAAC;AAM3F,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"compoundActionBar.d.ts","sourceRoot":"","sources":["../../../lib/v7/compoundActionBar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAyC,MAAM,aAAa,CAAC;AAM3F,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UAmD7E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renameLayoutImports.d.ts","sourceRoot":"","sources":["../../../lib/v7/renameLayoutImports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAA6B,MAAM,aAAa,CAAC;AAelE,QAAA,MAAM,SAAS,EAAE,SAqFhB,CAAC;AAEF,eAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// used to filter our imports we want to keep in @workday/canvas-kit-labs-react/common
|
|
2
|
+
var commonSpecifiers = [
|
|
3
|
+
'useTheme',
|
|
4
|
+
'ComponentStatesTable',
|
|
5
|
+
'permutateProps',
|
|
6
|
+
'useThemeRTL',
|
|
7
|
+
'useThemedRing',
|
|
8
|
+
];
|
|
9
|
+
// 1. Gather all import specifiers from @workday/canvas-kit-labs-react/layout
|
|
10
|
+
// 2. Filter through all imports from @workday/canvas-kit-labs-react/common and gather specifiers we care about
|
|
11
|
+
// 3. If there's an existing @workday/canvas-kit-react/layout add gathered specifiers to that import
|
|
12
|
+
// 4. If no existing import, create new import with specifiers and insert before closest canvas kit import
|
|
13
|
+
var transform = function (file, api) {
|
|
14
|
+
var j = api.jscodeshift;
|
|
15
|
+
var root = j(file.source);
|
|
16
|
+
var reactLayoutSpecifiers = [];
|
|
17
|
+
var foundImport = [];
|
|
18
|
+
// for each specifier in @workday/canvas-kit-labs-react/layout it pushes
|
|
19
|
+
// the specifier to reactLayoutSpecifiers
|
|
20
|
+
// We also push the found import to foundImport
|
|
21
|
+
root
|
|
22
|
+
.find(j.ImportDeclaration, { source: { value: '@workday/canvas-kit-labs-react/layout' } })
|
|
23
|
+
.forEach(function (nodePath) {
|
|
24
|
+
var _a;
|
|
25
|
+
(_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.forEach(function (specifier) {
|
|
26
|
+
var _a, _b;
|
|
27
|
+
if (specifier.type === 'ImportSpecifier') {
|
|
28
|
+
reactLayoutSpecifiers.push({
|
|
29
|
+
importedName: (_a = specifier === null || specifier === void 0 ? void 0 : specifier.local) === null || _a === void 0 ? void 0 : _a.name,
|
|
30
|
+
name: (_b = specifier === null || specifier === void 0 ? void 0 : specifier.imported) === null || _b === void 0 ? void 0 : _b.name,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
foundImport.push(nodePath);
|
|
35
|
+
});
|
|
36
|
+
// We filter through @workday/canvas-kit-labs-react/common specifiers and
|
|
37
|
+
// if it includes specifiers that we want, we push those to reactLayoutSpecifiers
|
|
38
|
+
root
|
|
39
|
+
.find(j.ImportDeclaration, { source: { value: '@workday/canvas-kit-labs-react/common' } })
|
|
40
|
+
.forEach(function (nodePath) {
|
|
41
|
+
var _a;
|
|
42
|
+
nodePath.value.specifiers = (_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.filter(function (specifier) {
|
|
43
|
+
var _a, _b;
|
|
44
|
+
if (specifier.type === 'ImportSpecifier' &&
|
|
45
|
+
!commonSpecifiers.includes(specifier.imported.name)) {
|
|
46
|
+
reactLayoutSpecifiers.push({
|
|
47
|
+
importedName: (_a = specifier === null || specifier === void 0 ? void 0 : specifier.local) === null || _a === void 0 ? void 0 : _a.name,
|
|
48
|
+
name: (_b = specifier === null || specifier === void 0 ? void 0 : specifier.imported) === null || _b === void 0 ? void 0 : _b.name,
|
|
49
|
+
});
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
return true;
|
|
53
|
+
});
|
|
54
|
+
foundImport.push(nodePath);
|
|
55
|
+
});
|
|
56
|
+
var existingLayoutImports = root.find(j.ImportDeclaration, {
|
|
57
|
+
source: { value: '@workday/canvas-kit-react/layout' },
|
|
58
|
+
});
|
|
59
|
+
var mapToSpecifiers = function (specifier) {
|
|
60
|
+
return j.importSpecifier(j.identifier(specifier.name), specifier.importedName ? j.identifier(specifier.importedName) : undefined);
|
|
61
|
+
};
|
|
62
|
+
// add to existing import
|
|
63
|
+
if (existingLayoutImports.length) {
|
|
64
|
+
existingLayoutImports.forEach(function (nodePath) {
|
|
65
|
+
var _a;
|
|
66
|
+
nodePath.value.specifiers = (_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.concat(reactLayoutSpecifiers.map(mapToSpecifiers));
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
// create new import
|
|
71
|
+
foundImport[0].insertBefore(j.importDeclaration(reactLayoutSpecifiers.map(mapToSpecifiers), j.stringLiteral('@workday/canvas-kit-react/layout')));
|
|
72
|
+
}
|
|
73
|
+
foundImport.forEach(function (importPath) {
|
|
74
|
+
var _a;
|
|
75
|
+
// remove imports we no longer need
|
|
76
|
+
if (((_a = importPath.value.specifiers) === null || _a === void 0 ? void 0 : _a.length) === 0 ||
|
|
77
|
+
importPath.value.source.value === '@workday/canvas-kit-labs-react/layout') {
|
|
78
|
+
importPath.prune();
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
return root.toSource();
|
|
82
|
+
};
|
|
83
|
+
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": "7.0.0-alpha.0-next.
|
|
5
|
+
"version": "7.0.0-alpha.0-next.7+23568685",
|
|
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": "23568685fec785046d37cb320289d8ab9e74e283"
|
|
46
46
|
}
|