@workday/canvas-kit-codemod 12.3.3 → 13.0.0-alpha.1007-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/v13/index.d.ts +4 -0
- package/dist/es6/v13/index.d.ts.map +1 -0
- package/dist/es6/v13/index.js +8 -0
- package/dist/es6/v13/utils/getImportRenameMap.d.ts +7 -0
- package/dist/es6/v13/utils/getImportRenameMap.d.ts.map +1 -0
- package/dist/es6/v13/utils/getImportRenameMap.js +47 -0
- package/index.js +7 -0
- package/package.json +2 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../lib/v13/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAEtC,QAAA,MAAM,SAAS,EAAE,SAMhB,CAAC;AAEF,eAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const transform = (file, api, options) => {
|
|
2
|
+
// These will run in order. If your transform depends on others, place yours after dependent transforms
|
|
3
|
+
// const fixes = [
|
|
4
|
+
// // add codemods here
|
|
5
|
+
// ];
|
|
6
|
+
// return fixes.reduce((source, fix) => fix({...file, source}, api, options) as string, file.source);
|
|
7
|
+
};
|
|
8
|
+
export default transform;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Collection, JSCodeshift } from 'jscodeshift';
|
|
2
|
+
export declare function getImportRenameMap(j: JSCodeshift, root: Collection<any>, mainPackage?: string, packageName?: string): {
|
|
3
|
+
containsCanvasImports: boolean;
|
|
4
|
+
importMap: Record<string, string>;
|
|
5
|
+
styledMap: Record<string, string>;
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=getImportRenameMap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getImportRenameMap.d.ts","sourceRoot":"","sources":["../../../../lib/v13/utils/getImportRenameMap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,WAAW,EAAiB,MAAM,aAAa,CAAC;AAEpE,wBAAgB,kBAAkB,CAChC,CAAC,EAAE,WAAW,EACd,IAAI,EAAE,UAAU,CAAC,GAAG,CAAC,EACrB,WAAW,SAA8B,EACzC,WAAW,SAAK;;;;EAwDjB"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export function getImportRenameMap(j, root, mainPackage = '@workday/canvas-kit-react', packageName = '') {
|
|
2
|
+
let containsCanvasImports = false;
|
|
3
|
+
// build import name remapping - in case someone renamed imports...
|
|
4
|
+
// i.e. `import { IconButton as StyledIconButton } ...`
|
|
5
|
+
const importMap = {};
|
|
6
|
+
const styledMap = {};
|
|
7
|
+
root.find(j.ImportDeclaration, node => {
|
|
8
|
+
// imports our module
|
|
9
|
+
const value = node.source.value;
|
|
10
|
+
if (typeof value === 'string' &&
|
|
11
|
+
(value === mainPackage || value.startsWith(mainPackage) || value === packageName)) {
|
|
12
|
+
containsCanvasImports = true;
|
|
13
|
+
(node.specifiers || []).forEach(specifier => {
|
|
14
|
+
if (specifier.type === 'ImportSpecifier') {
|
|
15
|
+
if (!specifier.local || specifier.local.name === specifier.imported.name) {
|
|
16
|
+
importMap[specifier.imported.name] = specifier.imported.name;
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
importMap[specifier.imported.name] = specifier.local.name;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return false;
|
|
25
|
+
});
|
|
26
|
+
root
|
|
27
|
+
.find(j.CallExpression, (node) => {
|
|
28
|
+
if (node.callee.type === 'Identifier' &&
|
|
29
|
+
node.callee.name === 'styled' &&
|
|
30
|
+
node.arguments[0].type === 'Identifier') {
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
34
|
+
})
|
|
35
|
+
.forEach(nodePath => {
|
|
36
|
+
if ((nodePath.parent.value.type === 'CallExpression' ||
|
|
37
|
+
nodePath.parent.value.type === 'TaggedTemplateExpression') &&
|
|
38
|
+
nodePath.parent.parent.value.type === 'VariableDeclarator' &&
|
|
39
|
+
nodePath.parent.parent.value.id.type === 'Identifier') {
|
|
40
|
+
const styledName = nodePath.parent.parent.value.id.name;
|
|
41
|
+
if (nodePath.value.arguments[0].type === 'Identifier') {
|
|
42
|
+
styledMap[nodePath.value.arguments[0].name] = styledName;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
return { containsCanvasImports, importMap, styledMap };
|
|
47
|
+
}
|
package/index.js
CHANGED
|
@@ -81,6 +81,13 @@ const {
|
|
|
81
81
|
describe: chalk.gray('The path to execute the transform in (recursively).'),
|
|
82
82
|
});
|
|
83
83
|
})
|
|
84
|
+
.command('v13 [path]', chalk.gray('Canvas Kit v12 > v13 upgrade transform'), yargs => {
|
|
85
|
+
yargs.positional('path', {
|
|
86
|
+
type: 'string',
|
|
87
|
+
default: '.',
|
|
88
|
+
describe: chalk.gray('The path to execute the transform in (recursively).'),
|
|
89
|
+
});
|
|
90
|
+
})
|
|
84
91
|
.demandCommand(1, chalk.red.bold('You must provide a transform to apply.'))
|
|
85
92
|
.strictCommands()
|
|
86
93
|
.fail((msg, err, yargs) => {
|
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": "
|
|
5
|
+
"version": "13.0.0-alpha.1007-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": "b069877352a0d8b64fe2e045a208b5833d713ce9"
|
|
50
50
|
}
|