@workday/canvas-kit-codemod 13.0.0-alpha.998-next.0 → 13.0.1
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/addPillLabel.d.ts +3 -0
- package/dist/es6/v13/addPillLabel.d.ts.map +1 -0
- package/dist/es6/v13/addPillLabel.js +49 -0
- 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 +16 -0
- package/dist/es6/v13/promoteExpandable.d.ts +4 -0
- package/dist/es6/v13/promoteExpandable.d.ts.map +1 -0
- package/dist/es6/v13/promoteExpandable.js +56 -0
- package/dist/es6/v13/renameDubLogosImports.d.ts +3 -0
- package/dist/es6/v13/renameDubLogosImports.d.ts.map +1 -0
- package/dist/es6/v13/renameDubLogosImports.js +43 -0
- package/dist/es6/v13/renameDubLogosReferences.d.ts +3 -0
- package/dist/es6/v13/renameDubLogosReferences.d.ts.map +1 -0
- package/dist/es6/v13/renameDubLogosReferences.js +38 -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":"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
|
+
}
|
|
@@ -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;AAMtC,QAAA,MAAM,SAAS,EAAE,SAUhB,CAAC;AAEF,eAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import addPillLabel from './addPillLabel';
|
|
2
|
+
import renameDubLogosImports from './renameDubLogosImports';
|
|
3
|
+
import renameDubLogosReferences from './renameDubLogosReferences';
|
|
4
|
+
import promoteExpandable from './promoteExpandable';
|
|
5
|
+
const transform = (file, api, options) => {
|
|
6
|
+
// These will run in order. If your transform depends on others, place yours after dependent transforms
|
|
7
|
+
const fixes = [
|
|
8
|
+
// add codemods here
|
|
9
|
+
addPillLabel,
|
|
10
|
+
promoteExpandable,
|
|
11
|
+
renameDubLogosImports,
|
|
12
|
+
renameDubLogosReferences,
|
|
13
|
+
];
|
|
14
|
+
return fixes.reduce((source, fix) => fix({ ...file, source }, api, options), file.source);
|
|
15
|
+
};
|
|
16
|
+
export default transform;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promoteExpandable.d.ts","sourceRoot":"","sources":["../../../lib/v13/promoteExpandable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAA6B,MAAM,aAAa,CAAC;AAIlE,QAAA,MAAM,SAAS,EAAE,SAyEhB,CAAC;AAEF,eAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
const transform = (file, api) => {
|
|
2
|
+
const j = api.jscodeshift;
|
|
3
|
+
const root = j(file.source);
|
|
4
|
+
const expandableSpecifiers = [];
|
|
5
|
+
const foundImport = [];
|
|
6
|
+
root
|
|
7
|
+
.find(j.ImportDeclaration, {
|
|
8
|
+
source: { value: (value) => value.includes('@workday/canvas-kit-labs-react') },
|
|
9
|
+
})
|
|
10
|
+
.forEach(nodePath => {
|
|
11
|
+
var _a;
|
|
12
|
+
nodePath.value.specifiers = (_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.filter(specifier => {
|
|
13
|
+
if (specifier.type === 'ImportSpecifier' &&
|
|
14
|
+
specifier.local &&
|
|
15
|
+
specifier.imported.name === 'Expandable') {
|
|
16
|
+
expandableSpecifiers.push({
|
|
17
|
+
importedName: specifier.imported.name,
|
|
18
|
+
name: specifier.local.name,
|
|
19
|
+
});
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
return true;
|
|
23
|
+
});
|
|
24
|
+
if (expandableSpecifiers.length) {
|
|
25
|
+
foundImport.push(nodePath);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
const existinExpandableImports = root.find(j.ImportDeclaration, {
|
|
29
|
+
source: { value: '@workday/canvas-kit-react/expandable' },
|
|
30
|
+
});
|
|
31
|
+
const mapToSpecifiers = (specifier) => {
|
|
32
|
+
return j.importSpecifier(j.identifier(specifier.importedName), specifier.name ? j.identifier(specifier.name) : undefined);
|
|
33
|
+
};
|
|
34
|
+
// add to existing import
|
|
35
|
+
if (existinExpandableImports.length) {
|
|
36
|
+
existinExpandableImports.forEach(nodePath => {
|
|
37
|
+
var _a;
|
|
38
|
+
nodePath.value.specifiers = (_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.concat(expandableSpecifiers.map(mapToSpecifiers));
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
// create new import
|
|
43
|
+
if (foundImport.length) {
|
|
44
|
+
foundImport[0].insertBefore(j.importDeclaration(expandableSpecifiers.map(mapToSpecifiers), j.stringLiteral('@workday/canvas-kit-react/expandable')));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
foundImport.forEach(importPath => {
|
|
48
|
+
var _a;
|
|
49
|
+
if (!((_a = importPath.value.specifiers) === null || _a === void 0 ? void 0 : _a.length) ||
|
|
50
|
+
importPath.value.source.value === '@workday/canvas-kit-labs-react/expandable') {
|
|
51
|
+
importPath.prune();
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
return root.toSource();
|
|
55
|
+
};
|
|
56
|
+
export default transform;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renameDubLogosImports.d.ts","sourceRoot":"","sources":["../../../lib/v13/renameDubLogosImports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAC,MAAM,aAAa,CAAC;AAOnD,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UAsC7E"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { hasImportSpecifiers } from '../v6/utils';
|
|
2
|
+
const mainPackage = '@workday/canvas-kit-react';
|
|
3
|
+
const dubLogoPackage = '@workday/canvas-kit-react/common';
|
|
4
|
+
const dubLogoImports = ['dubLogoBlue', 'dubLogoWhite', 'wdayLogoBlue', 'wdayLogoWhite'];
|
|
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, dubLogoPackage, dubLogoImports)) {
|
|
10
|
+
return file.source;
|
|
11
|
+
}
|
|
12
|
+
root
|
|
13
|
+
.find(j.ImportDeclaration, {
|
|
14
|
+
// filter on imports from "@workday/canvas-kit/react" including slash imports
|
|
15
|
+
source: { value: (value) => value.includes(mainPackage) },
|
|
16
|
+
})
|
|
17
|
+
.forEach(nodePath => {
|
|
18
|
+
var _a;
|
|
19
|
+
(_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.forEach(specifier => {
|
|
20
|
+
if (specifier.type === 'ImportSpecifier') {
|
|
21
|
+
// Transform named import
|
|
22
|
+
// e.g. `import {dubLogoBlue}` becomes `import {dubLogoPrimary}`
|
|
23
|
+
if (specifier.imported.name === 'dubLogoBlue') {
|
|
24
|
+
specifier.imported.name = 'dubLogoPrimary';
|
|
25
|
+
// e.g. `import {dubLogoWhite}` becomes `import {dubLogoReversed}`
|
|
26
|
+
}
|
|
27
|
+
else if (specifier.imported.name === 'dubLogoWhite') {
|
|
28
|
+
specifier.imported.name = 'dubLogoReversed';
|
|
29
|
+
// e.g. `import {wdayLogoBlue}` becomes `import {wdayLogoPrimary}`
|
|
30
|
+
}
|
|
31
|
+
else if (specifier.imported.name === 'wdayLogoBlue') {
|
|
32
|
+
specifier.imported.name = 'wdayLogoPrimary';
|
|
33
|
+
// e.g. `import {wdayLogoWhite}` becomes `import {wdayLogoReversed}`
|
|
34
|
+
}
|
|
35
|
+
else if (specifier.imported.name === 'wdayLogoWhite') {
|
|
36
|
+
specifier.imported.name = 'wdayLogoReversed';
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return specifier;
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
return root.toSource();
|
|
43
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renameDubLogosReferences.d.ts","sourceRoot":"","sources":["../../../lib/v13/renameDubLogosReferences.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAc,OAAO,EAAC,MAAM,aAAa,CAAC;AAQ/D,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UAyC7E"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { hasImportSpecifiers } from '../v6/utils';
|
|
2
|
+
import { getImportRenameMap } from './utils/getImportRenameMap';
|
|
3
|
+
const dubLogoPackages = ['@workday/canvas-kit-react', '@workday/canvas-kit-react/common'];
|
|
4
|
+
const packageImports = ['dubLogoPrimary', 'dubLogoReversed', 'wdayLogoPrimary', 'wdayLogoReversed'];
|
|
5
|
+
const oldpackageImports = ['dubLogoBlue', 'dubLogoWhite', 'wdayLogoBlue', 'wdayLogoWhite'];
|
|
6
|
+
export default function transformer(file, api, options) {
|
|
7
|
+
const j = api.jscodeshift;
|
|
8
|
+
const root = j(file.source);
|
|
9
|
+
// exit if the named imports aren't found
|
|
10
|
+
if (!hasImportSpecifiers(api, root, dubLogoPackages, packageImports)) {
|
|
11
|
+
return file.source;
|
|
12
|
+
}
|
|
13
|
+
// getImportRenameMap utility will tell us if the file containsCanvasImports
|
|
14
|
+
// and give us an importMap to track what identifiers we need to update
|
|
15
|
+
const { importMap } = getImportRenameMap(j, root, '@workday/canvas-kit-react');
|
|
16
|
+
const expressions = root.find(j.JSXExpressionContainer);
|
|
17
|
+
// Transform attributes
|
|
18
|
+
expressions
|
|
19
|
+
.find(j.Identifier, (value) => {
|
|
20
|
+
const isCorrectImport = Object.entries(importMap).some(([original, imported]) => imported === original && oldpackageImports.includes(value.name));
|
|
21
|
+
return isCorrectImport;
|
|
22
|
+
})
|
|
23
|
+
.forEach(nodePath => {
|
|
24
|
+
if (nodePath.node.name === 'dubLogoBlue') {
|
|
25
|
+
nodePath.node.name = 'dubLogoPrimary';
|
|
26
|
+
}
|
|
27
|
+
else if (nodePath.node.name === 'dubLogoWhite') {
|
|
28
|
+
nodePath.node.name = 'dubLogoReversed';
|
|
29
|
+
}
|
|
30
|
+
if (nodePath.node.name === 'wdayLogoBlue') {
|
|
31
|
+
nodePath.node.name = 'wdayLogoPrimary';
|
|
32
|
+
}
|
|
33
|
+
if (nodePath.node.name === 'wdayLogoWhite') {
|
|
34
|
+
nodePath.node.name = 'wdayLogoReversed';
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
return root.toSource();
|
|
38
|
+
}
|
|
@@ -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": "13.0.
|
|
5
|
+
"version": "13.0.1",
|
|
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": "bb1ae05330f359a59d9776efe8e99cdc20e99f52"
|
|
50
50
|
}
|