@workday/canvas-kit-codemod 6.3.0-next.1 → 6.3.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/v5/getImportRenameMap.d.ts.map +1 -1
- package/dist/es6/v5/getImportRenameMap.js +0 -1
- package/dist/es6/v5/removeButtonEnums.d.ts.map +1 -1
- package/dist/es6/v5/removeButtonEnums.js +1 -3
- package/dist/es6/v5/renamePreviewTokenImports.js +1 -1
- package/dist/es6/v6/deprecateCookieBanner.d.ts +2 -3
- package/dist/es6/v6/deprecateCookieBanner.d.ts.map +1 -1
- package/dist/es6/v6/deprecateCookieBanner.js +110 -8
- package/dist/es6/v6/deprecateHeader.d.ts +2 -3
- package/dist/es6/v6/deprecateHeader.d.ts.map +1 -1
- package/dist/es6/v6/deprecateHeader.js +101 -5
- package/dist/es6/v6/deprecatePageHeader.d.ts +2 -3
- package/dist/es6/v6/deprecatePageHeader.d.ts.map +1 -1
- package/dist/es6/v6/deprecatePageHeader.js +100 -8
- package/dist/es6/v6/index.d.ts +2 -3
- package/dist/es6/v6/index.d.ts.map +1 -1
- package/dist/es6/v6/index.js +2 -3
- package/dist/es6/v6/moveAndRenameSearchBar.d.ts +2 -3
- package/dist/es6/v6/moveAndRenameSearchBar.d.ts.map +1 -1
- package/dist/es6/v6/moveAndRenameSearchBar.js +49 -8
- package/dist/es6/v6/renameCanvasDepthValue.d.ts +2 -3
- package/dist/es6/v6/renameCanvasDepthValue.d.ts.map +1 -1
- package/dist/es6/v6/renameCanvasDepthValue.js +72 -7
- package/dist/es6/v6/utils/index.d.ts +1 -20
- package/dist/es6/v6/utils/index.d.ts.map +1 -1
- package/dist/es6/v6/utils/index.js +0 -121
- package/index.js +9 -9
- package/package.json +4 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getImportRenameMap.d.ts","sourceRoot":"","sources":["../../../lib/v5/getImportRenameMap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,
|
|
1
|
+
{"version":3,"file":"getImportRenameMap.d.ts","sourceRoot":"","sources":["../../../lib/v5/getImportRenameMap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAqB,WAAW,EAAiB,MAAM,aAAa,CAAC;AAEvF,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,CAAC,GAAG,CAAC,EAAE,WAAW,SAAK;;;;EAwDzF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"removeButtonEnums.d.ts","sourceRoot":"","sources":["../../../lib/v5/removeButtonEnums.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,EACH,QAAQ,EACR,OAAO,EAKR,MAAM,aAAa,CAAC;AAkHrB,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"removeButtonEnums.d.ts","sourceRoot":"","sources":["../../../lib/v5/removeButtonEnums.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,EACH,QAAQ,EACR,OAAO,EAKR,MAAM,aAAa,CAAC;AAkHrB,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UAmI7E"}
|
|
@@ -199,9 +199,7 @@ export default function transformer(file, api, options) {
|
|
|
199
199
|
}
|
|
200
200
|
return null;
|
|
201
201
|
}
|
|
202
|
-
root
|
|
203
|
-
.find(j.TSTypeReference, function (node) { return !!findTypeRename(node); })
|
|
204
|
-
.replaceWith(function (nodePath) {
|
|
202
|
+
root.find(j.TSTypeReference, findTypeRename).replaceWith(function (nodePath) {
|
|
205
203
|
var node = nodePath.value;
|
|
206
204
|
var matches = findTypeRename(node);
|
|
207
205
|
if (matches) {
|
|
@@ -24,7 +24,7 @@ export default function transformer(file, api) {
|
|
|
24
24
|
else {
|
|
25
25
|
// `insertBefore` ensures the import order multiple specifiers from labs-react/tokens
|
|
26
26
|
// are split into new imports. `insertAfter` would reverse the order, which isn't incorrect,
|
|
27
|
-
// but probably not what you'd intuitively expect.
|
|
27
|
+
// but probably not what you'd intuitively expect.
|
|
28
28
|
nodePath.insertBefore(j.importDeclaration([specifier], j.stringLiteral('@workday/canvas-kit-react/tokens')));
|
|
29
29
|
}
|
|
30
30
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export default transform;
|
|
1
|
+
import { API, FileInfo, Options } from 'jscodeshift';
|
|
2
|
+
export default function transformer(file: FileInfo, api: API, options: Options): string;
|
|
4
3
|
//# sourceMappingURL=deprecateCookieBanner.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deprecateCookieBanner.d.ts","sourceRoot":"","sources":["../../../lib/v6/deprecateCookieBanner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"deprecateCookieBanner.d.ts","sourceRoot":"","sources":["../../../lib/v6/deprecateCookieBanner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAiC,OAAO,EAAC,MAAM,aAAa,CAAC;AAKlF,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UAsH7E"}
|
|
@@ -1,10 +1,112 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
1
|
+
var mainPackage = '@workday/canvas-kit-react';
|
|
2
|
+
var cookieBannerPackage = '@workday/canvas-kit-react/cookie-banner';
|
|
3
|
+
export default function transformer(file, api, options) {
|
|
3
4
|
var j = api.jscodeshift;
|
|
4
5
|
var root = j(file.source);
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
var hasCookieBannerImports = false;
|
|
7
|
+
// This toggles the failsafe that prevents us from accidentally transforming something unintentionally.
|
|
8
|
+
root.find(j.ImportDeclaration, function (nodePath) {
|
|
9
|
+
var value = nodePath.source.value;
|
|
10
|
+
// If there's an import from the cookie-banner package, set the import boolean check to true
|
|
11
|
+
if (value === cookieBannerPackage) {
|
|
12
|
+
hasCookieBannerImports = true;
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
// If there's an import from the main package, check to see if CookieBanner or CookieBannerProps are among the named imports
|
|
16
|
+
// e.g. import {CookieBanner} from '@workday/canvas-kit-react';
|
|
17
|
+
if (value === mainPackage) {
|
|
18
|
+
(nodePath.specifiers || []).forEach(function (specifier) {
|
|
19
|
+
if (specifier.type === 'ImportSpecifier') {
|
|
20
|
+
var specifierName = specifier.imported.name;
|
|
21
|
+
if (specifierName === 'CookieBanner' || specifierName === 'CookieBannerProps') {
|
|
22
|
+
hasCookieBannerImports = true;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
// Failsafe to skip transforms unless a CookieBanner import is detected
|
|
29
|
+
if (!hasCookieBannerImports) {
|
|
30
|
+
return root.toSource();
|
|
31
|
+
}
|
|
32
|
+
// Transform CookieBanner named import statements from the main package
|
|
33
|
+
// e.g. import { CookieBanner, CookieBannerProps } from '@workday/canvas-kit-react';
|
|
34
|
+
// becomes import { DeprecatedCookieBanner, DeprecatedCookieBannerProps } from '@workday/canvas-kit-react';
|
|
35
|
+
root
|
|
36
|
+
.find(j.ImportDeclaration, { source: { value: '@workday/canvas-kit-react' } })
|
|
37
|
+
.forEach(function (nodePath) {
|
|
38
|
+
var _a;
|
|
39
|
+
(_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.forEach(function (specifier) {
|
|
40
|
+
if (specifier.type === 'ImportSpecifier') {
|
|
41
|
+
// `import {CookieBanner}` becomes `import {DeprecatedCookieBanner}`
|
|
42
|
+
if (specifier.imported.name === 'CookieBanner') {
|
|
43
|
+
specifier.imported.name = 'DeprecatedCookieBanner';
|
|
44
|
+
}
|
|
45
|
+
if (specifier.imported.name === 'CookieBannerProps') {
|
|
46
|
+
specifier.imported.name = 'DeprecatedCookieBannerProps';
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return specifier;
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
// Transform CookieBanner default and named import statements from the cookie-banner package
|
|
53
|
+
root
|
|
54
|
+
.find(j.ImportDeclaration, { source: { value: '@workday/canvas-kit-react/cookie-banner' } })
|
|
55
|
+
.forEach(function (nodePath) {
|
|
56
|
+
var _a;
|
|
57
|
+
(_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.forEach(function (specifier) {
|
|
58
|
+
var _a;
|
|
59
|
+
if (specifier.type === 'ImportDefaultSpecifier') {
|
|
60
|
+
// `import CookieBanner` becomes `import DeprecatedCookieBanner`
|
|
61
|
+
if (((_a = specifier.local) === null || _a === void 0 ? void 0 : _a.name) === 'CookieBanner') {
|
|
62
|
+
specifier.local.name = 'DeprecatedCookieBanner';
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (specifier.type === 'ImportSpecifier') {
|
|
66
|
+
// `import {CookieBanner}` becomes `import {DeprecatedCookieBanner}`
|
|
67
|
+
if (specifier.imported.name === 'CookieBanner') {
|
|
68
|
+
specifier.imported.name = 'DeprecatedCookieBanner';
|
|
69
|
+
}
|
|
70
|
+
// `import {CookieBannerProps}` becomes `import {DeprecatedCookieBannerProps}`
|
|
71
|
+
if (specifier.imported.name === 'CookieBannerProps') {
|
|
72
|
+
specifier.imported.name = 'DeprecatedCookieBannerProps';
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return specifier;
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
// Transform CookieBannerProps type references
|
|
79
|
+
// e.g. `type CustomProps = CookieBannerProps;` becomes `type CustomProps = DeprecatedCookieBannerProps;`
|
|
80
|
+
root
|
|
81
|
+
.find(j.TSTypeReference, { typeName: { type: 'Identifier', name: 'CookieBannerProps' } })
|
|
82
|
+
.forEach(function (nodePath) {
|
|
83
|
+
var identifier = nodePath.value.typeName;
|
|
84
|
+
identifier.name = 'DeprecatedCookieBannerProps';
|
|
85
|
+
});
|
|
86
|
+
// Transform CookieBannerProps type interface declaration references
|
|
87
|
+
// e.g. `interface CustomProps extends CookieBannerProps` becomes `interface CustomProps extends DeprecatedCookieBannerProps`
|
|
88
|
+
root.find(j.TSInterfaceDeclaration).forEach(function (nodePath) {
|
|
89
|
+
var _a;
|
|
90
|
+
// If the interface is extending CookieBannerProps, transform the extension name to DeprecatedCookieBannerProps
|
|
91
|
+
(_a = nodePath.node.extends) === null || _a === void 0 ? void 0 : _a.forEach(function (typeExtension) {
|
|
92
|
+
if (typeExtension.expression.type === 'Identifier' &&
|
|
93
|
+
typeExtension.expression.name === 'CookieBannerProps') {
|
|
94
|
+
typeExtension.expression.name = 'DeprecatedCookieBannerProps';
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
// Transform CookieBanner JSXElements
|
|
99
|
+
// e.g. `<CookieBanner>` becomes `<DeprecatedCookieBanner>`
|
|
100
|
+
root.find(j.JSXIdentifier, { name: 'CookieBanner' }).forEach(function (nodePath) {
|
|
101
|
+
nodePath.node.name = 'DeprecatedCookieBanner';
|
|
102
|
+
});
|
|
103
|
+
// Transform CookieBanner MemberExpressions
|
|
104
|
+
// e.g. `CookieBanner.DefaultNotice` becomes `DeprecatedCookieBanner.DefaultNotice`
|
|
105
|
+
root
|
|
106
|
+
.find(j.MemberExpression, { object: { type: 'Identifier', name: 'CookieBanner' } })
|
|
107
|
+
.forEach(function (nodePath) {
|
|
108
|
+
var identifier = nodePath.value.object;
|
|
109
|
+
identifier.name = 'DeprecatedCookieBanner';
|
|
110
|
+
});
|
|
111
|
+
return root.toSource();
|
|
112
|
+
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export default transform;
|
|
1
|
+
import { API, FileInfo } from 'jscodeshift';
|
|
2
|
+
export default function transformer(file: FileInfo, api: API): string;
|
|
4
3
|
//# sourceMappingURL=deprecateHeader.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deprecateHeader.d.ts","sourceRoot":"","sources":["../../../lib/v6/deprecateHeader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"deprecateHeader.d.ts","sourceRoot":"","sources":["../../../lib/v6/deprecateHeader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAgC,MAAM,aAAa,CAAC;AAiCzE,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,UAqG3D"}
|
|
@@ -1,4 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
var __spreadArrays = (this && this.__spreadArrays) || function () {
|
|
2
|
+
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
|
3
|
+
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
4
|
+
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
5
|
+
r[k] = a[j];
|
|
6
|
+
return r;
|
|
7
|
+
};
|
|
8
|
+
import { filterImportDefaultSpecifiers, filterImportSpecifiers, renameImportDefaultSpecifiers, renameImportSpecifiers, } from './utils';
|
|
9
|
+
var mainPackage = '@workday/canvas-kit-labs-react';
|
|
10
|
+
var headerPackage = '@workday/canvas-kit-labs-react/header';
|
|
11
|
+
var headerComponents = ['DubLogoTitle', 'Header', 'GlobalHeader', 'WorkdayLogoTitle'];
|
|
12
|
+
var headerUtils = ['themes'];
|
|
13
|
+
var headerTypes = ['Themes', 'ThemeAttributes', 'HeaderTheme', 'HeaderVariant', 'HeaderHeight'];
|
|
14
|
+
var headerImportSpecifiers = __spreadArrays(headerComponents, headerUtils, headerTypes);
|
|
15
|
+
var headerDefaultImportSpecifiers = ['Header'];
|
|
2
16
|
var headerRenameMap = {
|
|
3
17
|
DubLogoTitle: 'DeprecatedDubLogoTitle',
|
|
4
18
|
GlobalHeader: 'DeprecatedGlobalHeader',
|
|
@@ -11,9 +25,91 @@ var headerRenameMap = {
|
|
|
11
25
|
WorkdayLogoTitle: 'DeprecatedWorkdayLogoTitle',
|
|
12
26
|
themes: 'deprecatedHeaderThemes',
|
|
13
27
|
};
|
|
14
|
-
|
|
28
|
+
export default function transformer(file, api) {
|
|
15
29
|
var j = api.jscodeshift;
|
|
16
30
|
var root = j(file.source);
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
31
|
+
var hasHeaderImports = false;
|
|
32
|
+
root.find(j.ImportDeclaration, function (nodePath) {
|
|
33
|
+
var value = nodePath.source.value;
|
|
34
|
+
// if importing from the header package, set the failsafe to true
|
|
35
|
+
if (value === headerPackage) {
|
|
36
|
+
hasHeaderImports = true;
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
// if importing from the main package, check for header imports and toggle the failsafe if any are found
|
|
40
|
+
if (value === mainPackage) {
|
|
41
|
+
var importSpecifiers = nodePath.specifiers || [];
|
|
42
|
+
var headerSpecifiers = filterImportSpecifiers(importSpecifiers, headerImportSpecifiers);
|
|
43
|
+
if (headerSpecifiers.length) {
|
|
44
|
+
hasHeaderImports = true;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
// Failsafe to skip transforms unless a header import is detected
|
|
49
|
+
if (!hasHeaderImports) {
|
|
50
|
+
return root.toSource();
|
|
51
|
+
}
|
|
52
|
+
// Rename header named imports from @workday/canvas-kit-labs-react
|
|
53
|
+
// e.g. `import { Header } from '@workday/canvas-kit-labs-react';`
|
|
54
|
+
// becomes `import { DeprecatedHeader } from '@workday/canvas-kit-labs-react';`
|
|
55
|
+
root.find(j.ImportDeclaration, { source: { value: mainPackage } }).forEach(function (nodePath) {
|
|
56
|
+
var importSpecifiers = nodePath.value.specifiers || [];
|
|
57
|
+
// filter header imports
|
|
58
|
+
var headerImports = filterImportSpecifiers(importSpecifiers, headerImportSpecifiers);
|
|
59
|
+
renameImportSpecifiers(headerImports, headerRenameMap);
|
|
60
|
+
});
|
|
61
|
+
// Rename default and named header imports from @workday/canvas-kit-labs-react/header
|
|
62
|
+
// e.g. `import Header, { GlobalHeader } from '@workday/canvas-kit-labs-react/header';`
|
|
63
|
+
// becomes `import DeprecatedHeader, { DeprecatedGlobalHeader } from '@workday/canvas-kit-labs-react/header';`
|
|
64
|
+
root.find(j.ImportDeclaration, { source: { value: headerPackage } }).forEach(function (nodePath) {
|
|
65
|
+
var importSpecifiers = nodePath.value.specifiers || [];
|
|
66
|
+
// filter header named imports
|
|
67
|
+
var headerImports = filterImportSpecifiers(importSpecifiers, headerImportSpecifiers);
|
|
68
|
+
// rename header import specifiers
|
|
69
|
+
// e.g import { Header } becomes import { DeprecatedHeader }
|
|
70
|
+
renameImportSpecifiers(headerImports, headerRenameMap);
|
|
71
|
+
// filter header default imports
|
|
72
|
+
var headerDefaultImports = filterImportDefaultSpecifiers(importSpecifiers, headerDefaultImportSpecifiers);
|
|
73
|
+
// rename header import default specifiers
|
|
74
|
+
// e.g import Header becomes import DeprecatedHeader
|
|
75
|
+
renameImportDefaultSpecifiers(headerDefaultImports, headerRenameMap);
|
|
76
|
+
});
|
|
77
|
+
// Transform header type references
|
|
78
|
+
// e.g. `type CustomThemeAttributes = ThemeAttributes;` becomes `type CustomThemeAttributes = DeprecatedCThemeAttributes;`
|
|
79
|
+
root.find(j.TSTypeReference, { typeName: { type: 'Identifier' } }).forEach(function (nodePath) {
|
|
80
|
+
var identifier = nodePath.value.typeName;
|
|
81
|
+
if (headerTypes.includes(identifier.name)) {
|
|
82
|
+
identifier.name = headerRenameMap[identifier.name];
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
// Transform header type interface declaration references
|
|
86
|
+
// e.g. `interface CustomThemeAttributes extends ThemeAttributes {}`
|
|
87
|
+
// becomes `interface CustomThemeAttributes extends DeprecatedHeaderThemeAttributes {}`
|
|
88
|
+
root.find(j.TSInterfaceDeclaration).forEach(function (nodePath) {
|
|
89
|
+
var _a;
|
|
90
|
+
// If the interface is extending header type, transform the extension name,
|
|
91
|
+
(_a = nodePath.node.extends) === null || _a === void 0 ? void 0 : _a.forEach(function (typeExtension) {
|
|
92
|
+
if (typeExtension.expression.type === 'Identifier' &&
|
|
93
|
+
headerTypes.includes(typeExtension.expression.name)) {
|
|
94
|
+
typeExtension.expression.name = headerRenameMap[typeExtension.expression.name];
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
// Transform header JSXElements
|
|
99
|
+
// e.g. `<Header>` becomes `<DeprecatedHeader>`
|
|
100
|
+
root.find(j.JSXIdentifier).forEach(function (nodePath) {
|
|
101
|
+
var identifierName = nodePath.node.name;
|
|
102
|
+
if (headerComponents.includes(identifierName)) {
|
|
103
|
+
nodePath.node.name = headerRenameMap[identifierName];
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
// Transform header MemberExpressions
|
|
107
|
+
// e.g. `HeaderHeight.Small` becomes `DeprecatedHeaderHeight.Small`
|
|
108
|
+
root.find(j.MemberExpression, { object: { type: 'Identifier' } }).forEach(function (nodePath) {
|
|
109
|
+
var identifier = nodePath.value.object;
|
|
110
|
+
if (identifier.name in headerRenameMap) {
|
|
111
|
+
identifier.name = headerRenameMap[identifier.name];
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
return root.toSource();
|
|
115
|
+
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export default transform;
|
|
1
|
+
import { API, FileInfo, Options } from 'jscodeshift';
|
|
2
|
+
export default function transformer(file: FileInfo, api: API, options: Options): string;
|
|
4
3
|
//# sourceMappingURL=deprecatePageHeader.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deprecatePageHeader.d.ts","sourceRoot":"","sources":["../../../lib/v6/deprecatePageHeader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"deprecatePageHeader.d.ts","sourceRoot":"","sources":["../../../lib/v6/deprecatePageHeader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAiC,OAAO,EAAC,MAAM,aAAa,CAAC;AAKlF,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UA0G7E"}
|
|
@@ -1,10 +1,102 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
1
|
+
var mainPackage = '@workday/canvas-kit-react';
|
|
2
|
+
var pageHeaderPackage = '@workday/canvas-kit-react/page-header';
|
|
3
|
+
export default function transformer(file, api, options) {
|
|
3
4
|
var j = api.jscodeshift;
|
|
4
5
|
var root = j(file.source);
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
var hasPageHeaderImports = false;
|
|
7
|
+
// This toggles the failsafe that prevents us from accidentally transforming something unintentionally.
|
|
8
|
+
root.find(j.ImportDeclaration, function (nodePath) {
|
|
9
|
+
var value = nodePath.source.value;
|
|
10
|
+
// If there's an import from the page-header package, set the import boolean check to true
|
|
11
|
+
if (value === pageHeaderPackage) {
|
|
12
|
+
hasPageHeaderImports = true;
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
// If there's an import from the main package, check to see if PageHeader or PageHeaderProps are among the named imports
|
|
16
|
+
// e.g. import {PageHeader} from '@workday/canvas-kit-react';
|
|
17
|
+
if (value === mainPackage) {
|
|
18
|
+
(nodePath.specifiers || []).forEach(function (specifier) {
|
|
19
|
+
if (specifier.type === 'ImportSpecifier') {
|
|
20
|
+
var specifierName = specifier.imported.name;
|
|
21
|
+
if (specifierName === 'PageHeader' || specifierName === 'PageHeaderProps') {
|
|
22
|
+
hasPageHeaderImports = true;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
// Failsafe to skip transforms unless a PageHeader import is detected
|
|
29
|
+
if (!hasPageHeaderImports) {
|
|
30
|
+
return root.toSource();
|
|
31
|
+
}
|
|
32
|
+
root
|
|
33
|
+
.find(j.ImportDeclaration, { source: { value: '@workday/canvas-kit-react' } })
|
|
34
|
+
.forEach(function (nodePath) {
|
|
35
|
+
var _a;
|
|
36
|
+
(_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.forEach(function (specifier) {
|
|
37
|
+
if (specifier.type === 'ImportSpecifier') {
|
|
38
|
+
// `import {PageHeader}` becomes `import {DeprecatedPageHeader}`
|
|
39
|
+
if (specifier.imported.name === 'PageHeader') {
|
|
40
|
+
specifier.imported.name = 'DeprecatedPageHeader';
|
|
41
|
+
}
|
|
42
|
+
// `import {PageHeaderProps}` becomes `import {DeprecatedPageHeaderProps}`
|
|
43
|
+
if (specifier.imported.name === 'PageHeaderProps') {
|
|
44
|
+
specifier.imported.name = 'DeprecatedPageHeaderProps';
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return specifier;
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
// Transform PageHeader default and named import statements from the page-header package
|
|
51
|
+
root
|
|
52
|
+
.find(j.ImportDeclaration, { source: { value: '@workday/canvas-kit-react/page-header' } })
|
|
53
|
+
.forEach(function (nodePath) {
|
|
54
|
+
var _a;
|
|
55
|
+
(_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.forEach(function (specifier) {
|
|
56
|
+
var _a;
|
|
57
|
+
if (specifier.type === 'ImportDefaultSpecifier') {
|
|
58
|
+
// `import PageHeader` becomes `import DeprecatedPageHeader`
|
|
59
|
+
if (((_a = specifier.local) === null || _a === void 0 ? void 0 : _a.name) === 'PageHeader') {
|
|
60
|
+
specifier.local.name = 'DeprecatedPageHeader';
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (specifier.type === 'ImportSpecifier') {
|
|
64
|
+
// `import {PageHeader}` becomes `import {DeprecatedPageHeader}`
|
|
65
|
+
if (specifier.imported.name === 'PageHeader') {
|
|
66
|
+
specifier.imported.name = 'DeprecatedPageHeader';
|
|
67
|
+
}
|
|
68
|
+
// `import {PageHeaderProps}` becomes `import {DeprecatedPageHeaderProps}`
|
|
69
|
+
if (specifier.imported.name === 'PageHeaderProps') {
|
|
70
|
+
specifier.imported.name = 'DeprecatedPageHeaderProps';
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return specifier;
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
// Transform PageHeaderProps type references
|
|
77
|
+
// e.g. `type CustomProps = PageHeaderProps;` becomes `type CustomProps = DeprecatedPageHeaderProps;`
|
|
78
|
+
root
|
|
79
|
+
.find(j.TSTypeReference, { typeName: { type: 'Identifier', name: 'PageHeaderProps' } })
|
|
80
|
+
.forEach(function (nodePath) {
|
|
81
|
+
var identifier = nodePath.value.typeName;
|
|
82
|
+
identifier.name = 'DeprecatedPageHeaderProps';
|
|
83
|
+
});
|
|
84
|
+
// Transform PageHeaderProps type interface declaration references
|
|
85
|
+
// e.g. `interface CustomProps extends PageHeaderProps` becomes `interface CustomProps extends DeprecatedPageHeaderProps`
|
|
86
|
+
root.find(j.TSInterfaceDeclaration).forEach(function (nodePath) {
|
|
87
|
+
var _a;
|
|
88
|
+
// If the interface is extending PageHeaderProps, transform the extension name to DeprecatedPageHeaderProps
|
|
89
|
+
(_a = nodePath.node.extends) === null || _a === void 0 ? void 0 : _a.forEach(function (typeExtension) {
|
|
90
|
+
if (typeExtension.expression.type === 'Identifier' &&
|
|
91
|
+
typeExtension.expression.name === 'PageHeaderProps') {
|
|
92
|
+
typeExtension.expression.name = 'DeprecatedPageHeaderProps';
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
// Transform PageHeader JSXElements
|
|
97
|
+
// e.g. `<PageHeader>` becomes `<DeprecatedPageHeader>`
|
|
98
|
+
root.find(j.JSXIdentifier, { name: 'PageHeader' }).forEach(function (nodePath) {
|
|
99
|
+
nodePath.node.name = 'DeprecatedPageHeader';
|
|
100
|
+
});
|
|
101
|
+
return root.toSource();
|
|
102
|
+
}
|
package/dist/es6/v6/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export default transform;
|
|
1
|
+
import { API, FileInfo, Options } from 'jscodeshift';
|
|
2
|
+
export default function transformer(file: FileInfo, api: API, options: Options): string;
|
|
4
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../lib/v6/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../lib/v6/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAC,MAAM,aAAa,CAAC;AAYnD,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UAY7E"}
|
package/dist/es6/v6/index.js
CHANGED
|
@@ -19,7 +19,7 @@ import moveAndRenameSearchBar from './moveAndRenameSearchBar';
|
|
|
19
19
|
import deprecateHeader from './deprecateHeader';
|
|
20
20
|
// rename CanvasDepthValue
|
|
21
21
|
import renameCanvasDepthValue from './renameCanvasDepthValue';
|
|
22
|
-
|
|
22
|
+
export default function transformer(file, api, options) {
|
|
23
23
|
// These will run in order. If your transform depends on others, place yours after dependent transforms
|
|
24
24
|
var fixes = [
|
|
25
25
|
deprecatePageHeader,
|
|
@@ -30,5 +30,4 @@ var transform = function (file, api, options) {
|
|
|
30
30
|
renameCanvasDepthValue,
|
|
31
31
|
];
|
|
32
32
|
return fixes.reduce(function (source, fix) { return fix(__assign(__assign({}, file), { source: source }), api, options); }, file.source);
|
|
33
|
-
}
|
|
34
|
-
export default transform;
|
|
33
|
+
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export default transform;
|
|
1
|
+
import { API, FileInfo } from 'jscodeshift';
|
|
2
|
+
export default function transformer(file: FileInfo, api: API): string;
|
|
4
3
|
//# sourceMappingURL=moveAndRenameSearchBar.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"moveAndRenameSearchBar.d.ts","sourceRoot":"","sources":["../../../lib/v6/moveAndRenameSearchBar.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"moveAndRenameSearchBar.d.ts","sourceRoot":"","sources":["../../../lib/v6/moveAndRenameSearchBar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAW,QAAQ,EAAiD,MAAM,aAAa,CAAC;AAwBnG,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,UAsH3D"}
|
|
@@ -5,7 +5,7 @@ var __spreadArrays = (this && this.__spreadArrays) || function () {
|
|
|
5
5
|
r[k] = a[j];
|
|
6
6
|
return r;
|
|
7
7
|
};
|
|
8
|
-
import { filterImportSpecifiers, renameImportSpecifiers,
|
|
8
|
+
import { filterImportSpecifiers, renameImportSpecifiers, } from './utils';
|
|
9
9
|
var mainPackage = '@workday/canvas-kit-labs-react';
|
|
10
10
|
var headerPackage = '@workday/canvas-kit-labs-react/header';
|
|
11
11
|
var searchBarRenameImports = ['SearchBar', 'SearchBarProps', 'SearchBarState'];
|
|
@@ -18,15 +18,29 @@ var renameMap = {
|
|
|
18
18
|
SearchBarProps: 'SearchFormProps',
|
|
19
19
|
SearchBarState: 'SearchFormState',
|
|
20
20
|
};
|
|
21
|
-
|
|
21
|
+
export default function transformer(file, api) {
|
|
22
22
|
var j = api.jscodeshift;
|
|
23
23
|
var root = j(file.source);
|
|
24
|
-
|
|
25
|
-
return file.source;
|
|
26
|
-
}
|
|
24
|
+
var hasSearchBarImports = false;
|
|
27
25
|
function insertImportDeclarationBefore(nodePath, specifiers, sourcePath) {
|
|
28
26
|
nodePath.insertBefore(j.importDeclaration(specifiers, j.stringLiteral(sourcePath)));
|
|
29
27
|
}
|
|
28
|
+
// This toggles the failsafe that prevents us from accidentally transforming something unintentionally.
|
|
29
|
+
root.find(j.ImportDeclaration, function (nodePath) {
|
|
30
|
+
var value = nodePath.source.value;
|
|
31
|
+
// if there's any SearchBar imports from either the main package or the header package, toggle the failsafe
|
|
32
|
+
if (value === mainPackage || value === headerPackage) {
|
|
33
|
+
var importSpecifiers = nodePath.specifiers || [];
|
|
34
|
+
var searchBarImports = filterImportSpecifiers(importSpecifiers, searchBarImportSpecifiers);
|
|
35
|
+
if (searchBarImports.length) {
|
|
36
|
+
hasSearchBarImports = true;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
// Failsafe to skip transforms unless a SearchBar import is detected
|
|
41
|
+
if (!hasSearchBarImports) {
|
|
42
|
+
return root.toSource();
|
|
43
|
+
}
|
|
30
44
|
// Rename search-bar named imports from @workday/canvas-kit-labs-react
|
|
31
45
|
// e.g. import { SearchBar, SearchBarProps } from '@workday/canvas-kit-labs-react';
|
|
32
46
|
// becomes import { SearchForm, SearchFormProps } from '@workday/canvas-kit-labs-react';
|
|
@@ -71,6 +85,33 @@ var transform = function (file, api) {
|
|
|
71
85
|
insertImportDeclarationBefore(nodePath, headerSpecifiers, headerPackage);
|
|
72
86
|
}
|
|
73
87
|
});
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
88
|
+
// Transform SearchBar JSXElements
|
|
89
|
+
// e.g. `<SearchBar>` becomes `<SearchForm>`
|
|
90
|
+
root.find(j.JSXIdentifier, { name: 'SearchBar' }).forEach(function (nodePath) {
|
|
91
|
+
nodePath.node.name = 'SearchForm';
|
|
92
|
+
});
|
|
93
|
+
// Transform SearchBarProps and SearchBarState type references
|
|
94
|
+
// e.g. type CustomSearchType = SearchBarProps & SearchBarState;
|
|
95
|
+
// becomes type CustomSearchType = SearchFormProps & SearchFormState;
|
|
96
|
+
root.find(j.TSTypeReference, { typeName: { type: 'Identifier' } }).forEach(function (nodePath) {
|
|
97
|
+
var identifier = nodePath.value.typeName;
|
|
98
|
+
if (identifier.name in renameMap) {
|
|
99
|
+
identifier.name = renameMap[identifier.name];
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
// Transform SearchBarProps type interface declaration references
|
|
103
|
+
// e.g. `interface CustomProps extends SearchBarProps` becomes `interface CustomProps extends SearchFormProps`
|
|
104
|
+
root.find(j.TSInterfaceDeclaration).forEach(function (nodePath) {
|
|
105
|
+
var _a;
|
|
106
|
+
// If the interface is extending SearchBarProps, transform the extension name to SearchFormProps
|
|
107
|
+
(_a = nodePath.node.extends) === null || _a === void 0 ? void 0 : _a.forEach(function (typeExtension) {
|
|
108
|
+
if (typeExtension.expression.type === 'Identifier') {
|
|
109
|
+
var typeName = typeExtension.expression.name;
|
|
110
|
+
if (typeName in renameMap) {
|
|
111
|
+
typeExtension.expression.name = renameMap[typeName];
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
return root.toSource();
|
|
117
|
+
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export default transform;
|
|
1
|
+
import { API, FileInfo } from 'jscodeshift';
|
|
2
|
+
export default function transformer(file: FileInfo, api: API): string;
|
|
4
3
|
//# sourceMappingURL=renameCanvasDepthValue.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renameCanvasDepthValue.d.ts","sourceRoot":"","sources":["../../../lib/v6/renameCanvasDepthValue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"renameCanvasDepthValue.d.ts","sourceRoot":"","sources":["../../../lib/v6/renameCanvasDepthValue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAgC,MAAM,aAAa,CAAC;AAUzE,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,UA0E3D"}
|
|
@@ -1,9 +1,74 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
1
|
+
var mainPackage = '@workday/canvas-kit-react';
|
|
2
|
+
var tokensPackage = '@workday/canvas-kit-react/tokens';
|
|
3
|
+
var renameMap = {
|
|
4
|
+
CanvasDepthValue: 'CanvasDepthValues',
|
|
5
|
+
};
|
|
6
|
+
export default function transformer(file, api) {
|
|
3
7
|
var j = api.jscodeshift;
|
|
4
8
|
var root = j(file.source);
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
var hasCanvasDepthValueImports = false;
|
|
10
|
+
// Toggles the failsafe that prevents us from accidentally transforming something unintentionally.
|
|
11
|
+
root.find(j.ImportDeclaration, function (nodePath) {
|
|
12
|
+
var value = nodePath.source.value;
|
|
13
|
+
// if there is a CanvasDepthValue import from either the main package or the tokens package, toggle the failsafe
|
|
14
|
+
if (value === mainPackage || value === tokensPackage) {
|
|
15
|
+
var importSpecifiers = nodePath.specifiers || [];
|
|
16
|
+
importSpecifiers.forEach(function (specifier) {
|
|
17
|
+
if (specifier.type === 'ImportSpecifier' && specifier.imported.name in renameMap) {
|
|
18
|
+
hasCanvasDepthValueImports = true;
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
// Failsafe to skip transforms unless a CanvasDepthValue import is detected
|
|
24
|
+
if (!hasCanvasDepthValueImports) {
|
|
25
|
+
return root.toSource();
|
|
26
|
+
}
|
|
27
|
+
// Rename CanvasDepthValue import from @workday/canvas-kit-react
|
|
28
|
+
// e.g. import { CanvasDepthValue } from '@workday/canvas-kit-react';
|
|
29
|
+
// becomes import { CanvasDepthValues } from '@workday/canvas-kit-react';
|
|
30
|
+
root.find(j.ImportDeclaration, { source: { value: mainPackage } }).forEach(function (nodePath) {
|
|
31
|
+
var importSpecifiers = nodePath.value.specifiers || [];
|
|
32
|
+
importSpecifiers.forEach(function (specifier) {
|
|
33
|
+
if (specifier.type === 'ImportSpecifier' && specifier.imported.name in renameMap) {
|
|
34
|
+
specifier.imported.name = renameMap[specifier.imported.name];
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
// Rename CanvasDepthValue import from @workday/canvas-kit-react/tokens
|
|
39
|
+
// e.g. import { CanvasDepthValue } from '@workday/canvas-kit-react/tokens';
|
|
40
|
+
// becomes import { CanvasDepthValues } from '@workday/canvas-kit-react/tokens';
|
|
41
|
+
root.find(j.ImportDeclaration, { source: { value: tokensPackage } }).forEach(function (nodePath) {
|
|
42
|
+
var importSpecifiers = nodePath.value.specifiers || [];
|
|
43
|
+
importSpecifiers.forEach(function (specifier) {
|
|
44
|
+
if (specifier.type === 'ImportSpecifier' && specifier.imported.name in renameMap) {
|
|
45
|
+
specifier.imported.name = renameMap[specifier.imported.name];
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
// Transform CanvasDepthValue type references
|
|
50
|
+
// e.g. type CustomDepthValues = CanvasDepthValue;
|
|
51
|
+
// becomes type CustomDepthValues = CanvasDepthValues;
|
|
52
|
+
root.find(j.TSTypeReference, { typeName: { type: 'Identifier' } }).forEach(function (nodePath) {
|
|
53
|
+
var identifier = nodePath.value.typeName;
|
|
54
|
+
if (identifier.name in renameMap) {
|
|
55
|
+
identifier.name = renameMap[identifier.name];
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
// Transform CanvasDepthValue type interface declaration references
|
|
59
|
+
// e.g. interface OtherCustomDepthValues extends CanvasDepthValue {};
|
|
60
|
+
// becomes interface OtherCustomDepthValues extends CanvasDepthValues {};
|
|
61
|
+
root.find(j.TSInterfaceDeclaration).forEach(function (nodePath) {
|
|
62
|
+
var _a;
|
|
63
|
+
// If the interface is extending SearchBarProps, transform the extension name to SearchFormProps
|
|
64
|
+
(_a = nodePath.node.extends) === null || _a === void 0 ? void 0 : _a.forEach(function (typeExtension) {
|
|
65
|
+
if (typeExtension.expression.type === 'Identifier') {
|
|
66
|
+
var typeName = typeExtension.expression.name;
|
|
67
|
+
if (typeExtension.expression.name in renameMap) {
|
|
68
|
+
typeExtension.expression.name = renameMap[typeName];
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
return root.toSource();
|
|
74
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ImportSpecifier, ImportDefaultSpecifier, ImportNamespaceSpecifier
|
|
1
|
+
import { ImportSpecifier, ImportDefaultSpecifier, ImportNamespaceSpecifier } from 'jscodeshift';
|
|
2
2
|
export declare type ImportSpecifierArray = (ImportSpecifier | ImportNamespaceSpecifier | ImportDefaultSpecifier)[];
|
|
3
3
|
/**
|
|
4
4
|
* Returns a filtered array of ImportSpecifiers
|
|
@@ -48,23 +48,4 @@ export declare function filterImportDefaultSpecifiers(importSpecifiers: ImportSp
|
|
|
48
48
|
* renameImportSpecifiers(pageHeaderSpecifiers, renameMap);
|
|
49
49
|
*/
|
|
50
50
|
export declare function renameImportDefaultSpecifiers(importSpecifiers: ImportDefaultSpecifier[], renameMap: RenameMap): ImportDefaultSpecifier[];
|
|
51
|
-
/**
|
|
52
|
-
* Search for import statements for a package and specific import specifiers. This
|
|
53
|
-
* is useful for codemods to skip files that don't contain import specifiers that
|
|
54
|
-
* require codemoding.
|
|
55
|
-
*
|
|
56
|
-
* @example
|
|
57
|
-
* const hasImports = hasImportSpecifiers(
|
|
58
|
-
* api,
|
|
59
|
-
* root,
|
|
60
|
-
* '@workday/canvas-kit-react/cookie-banner',
|
|
61
|
-
* ['CookieBanner', 'CookieBannerProps']
|
|
62
|
-
* )
|
|
63
|
-
*
|
|
64
|
-
* if (!hasImports) {
|
|
65
|
-
* return file.source
|
|
66
|
-
* }
|
|
67
|
-
*/
|
|
68
|
-
export declare function hasImportSpecifiers(api: API, root: Collection<any>, packageName: string | string[], specifiers: string[]): boolean;
|
|
69
|
-
export declare function renameImports(api: API, root: Collection<any>, packageName: string, specifierMap: Record<string, string>): Collection<any>;
|
|
70
51
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../lib/v6/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../lib/v6/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAE,sBAAsB,EAAE,wBAAwB,EAAC,MAAM,aAAa,CAAC;AAE9F,oBAAY,oBAAoB,GAAG,CAC/B,eAAe,GACf,wBAAwB,GACxB,sBAAsB,CACzB,EAAE,CAAC;AAEJ;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CACpC,gBAAgB,EAAE,oBAAoB,EACtC,WAAW,CAAC,EAAE,MAAM,EAAE,qBAevB;AAED,oBAAY,SAAS,GAAG;IACtB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CACvB,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CAAC,gBAAgB,EAAE,eAAe,EAAE,EAAE,SAAS,EAAE,SAAS,qBAQ/F;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,6BAA6B,CAC3C,gBAAgB,EAAE,oBAAoB,EACtC,WAAW,CAAC,EAAE,MAAM,EAAE,4BAevB;AAED;;;;;;GAMG;AACH,wBAAgB,6BAA6B,CAC3C,gBAAgB,EAAE,sBAAsB,EAAE,EAC1C,SAAS,EAAE,SAAS,4BASrB"}
|
|
@@ -88,124 +88,3 @@ export function renameImportDefaultSpecifiers(importSpecifiers, renameMap) {
|
|
|
88
88
|
});
|
|
89
89
|
return importSpecifiers;
|
|
90
90
|
}
|
|
91
|
-
/**
|
|
92
|
-
* Search for import statements for a package and specific import specifiers. This
|
|
93
|
-
* is useful for codemods to skip files that don't contain import specifiers that
|
|
94
|
-
* require codemoding.
|
|
95
|
-
*
|
|
96
|
-
* @example
|
|
97
|
-
* const hasImports = hasImportSpecifiers(
|
|
98
|
-
* api,
|
|
99
|
-
* root,
|
|
100
|
-
* '@workday/canvas-kit-react/cookie-banner',
|
|
101
|
-
* ['CookieBanner', 'CookieBannerProps']
|
|
102
|
-
* )
|
|
103
|
-
*
|
|
104
|
-
* if (!hasImports) {
|
|
105
|
-
* return file.source
|
|
106
|
-
* }
|
|
107
|
-
*/
|
|
108
|
-
export function hasImportSpecifiers(api, root, packageName, specifiers) {
|
|
109
|
-
var j = api.jscodeshift;
|
|
110
|
-
return !!root.find(j.ImportDeclaration, function (nodePath) {
|
|
111
|
-
var value = nodePath.source.value;
|
|
112
|
-
// package name was found
|
|
113
|
-
if (typeof packageName === 'string'
|
|
114
|
-
? value === packageName
|
|
115
|
-
: packageName.includes(value)) {
|
|
116
|
-
return true;
|
|
117
|
-
}
|
|
118
|
-
// Extract the main package(s) from the import, and test specifiers against that package
|
|
119
|
-
var mainPackage = (typeof packageName === 'string' ? [packageName] : packageName).map(function (s) {
|
|
120
|
-
return s
|
|
121
|
-
.split('/')
|
|
122
|
-
.slice(0, -1)
|
|
123
|
-
.join('/');
|
|
124
|
-
});
|
|
125
|
-
if (mainPackage.includes(value)) {
|
|
126
|
-
return !!(nodePath.specifiers || []).find(function (specifier) {
|
|
127
|
-
if (specifier.type === 'ImportSpecifier') {
|
|
128
|
-
var specifierName = specifier.imported.name;
|
|
129
|
-
return specifiers.includes(specifierName);
|
|
130
|
-
}
|
|
131
|
-
return false;
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
return false;
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
export function renameImports(api, root, packageName, specifierMap) {
|
|
138
|
-
var j = api.jscodeshift;
|
|
139
|
-
if (!hasImportSpecifiers(api, root, packageName, Object.keys(specifierMap))) {
|
|
140
|
-
return root;
|
|
141
|
-
}
|
|
142
|
-
var mainPackage = packageName
|
|
143
|
-
.split('/')
|
|
144
|
-
.slice(0, -1)
|
|
145
|
-
.join('/');
|
|
146
|
-
// Transform import statements
|
|
147
|
-
// e.g. import { CookieBanner, CookieBannerProps } from '@workday/canvas-kit-react';
|
|
148
|
-
// becomes import { DeprecatedCookieBanner, DeprecatedCookieBannerProps } from '@workday/canvas-kit-react';
|
|
149
|
-
root.find(j.ImportDeclaration, { source: { value: mainPackage } }).forEach(function (nodePath) {
|
|
150
|
-
var _a;
|
|
151
|
-
(_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.forEach(function (specifier) {
|
|
152
|
-
if (specifier.type === 'ImportSpecifier') {
|
|
153
|
-
if (Object.keys(specifierMap).includes(specifier.imported.name)) {
|
|
154
|
-
specifier.imported.name = specifierMap[specifier.imported.name];
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
});
|
|
159
|
-
// Transforms default imports from package
|
|
160
|
-
root.find(j.ImportDeclaration, { source: { value: packageName } }).forEach(function (nodePath) {
|
|
161
|
-
var _a;
|
|
162
|
-
(_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.forEach(function (specifier) {
|
|
163
|
-
if (specifier.type === 'ImportDefaultSpecifier') {
|
|
164
|
-
if (specifier.local && Object.keys(specifierMap).includes(specifier.local.name)) {
|
|
165
|
-
specifier.local.name = specifierMap[specifier.local.name];
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
if (specifier.type === 'ImportSpecifier') {
|
|
169
|
-
if (Object.keys(specifierMap).includes(specifier.imported.name)) {
|
|
170
|
-
specifier.imported.name = specifierMap[specifier.imported.name];
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
});
|
|
175
|
-
// Transform type references
|
|
176
|
-
// e.g. `type CustomProps = CookieBannerProps;` becomes `type CustomProps = DeprecatedCookieBannerProps;`
|
|
177
|
-
root.find(j.TSTypeReference, { typeName: { type: 'Identifier' } }).forEach(function (nodePath) {
|
|
178
|
-
if (nodePath.value.typeName.type === 'Identifier' &&
|
|
179
|
-
Object.keys(specifierMap).includes(nodePath.value.typeName.name)) {
|
|
180
|
-
nodePath.value.typeName.name = specifierMap[nodePath.value.typeName.name];
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
// Transform type interface declaration references
|
|
184
|
-
// e.g. `interface CustomProps extends CookieBannerProps` becomes `interface CustomProps extends DeprecatedCookieBannerProps`
|
|
185
|
-
root.find(j.TSInterfaceDeclaration).forEach(function (nodePath) {
|
|
186
|
-
var _a;
|
|
187
|
-
// If the interface is extending CookieBannerProps, transform the extension name to DeprecatedCookieBannerProps
|
|
188
|
-
(_a = nodePath.node.extends) === null || _a === void 0 ? void 0 : _a.forEach(function (typeExtension) {
|
|
189
|
-
if (typeExtension.expression.type === 'Identifier' &&
|
|
190
|
-
Object.keys(specifierMap).includes(typeExtension.expression.name)) {
|
|
191
|
-
typeExtension.expression.name = specifierMap[typeExtension.expression.name];
|
|
192
|
-
}
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
// Transform JSXElements
|
|
196
|
-
// e.g. `<CookieBanner>` becomes `<DeprecatedCookieBanner>`
|
|
197
|
-
root.find(j.JSXIdentifier).forEach(function (nodePath) {
|
|
198
|
-
if (Object.keys(specifierMap).includes(nodePath.value.name)) {
|
|
199
|
-
nodePath.node.name = specifierMap[nodePath.value.name];
|
|
200
|
-
}
|
|
201
|
-
});
|
|
202
|
-
// Transform MemberExpressions
|
|
203
|
-
// e.g. `CookieBanner.DefaultNotice` becomes `DeprecatedCookieBanner.DefaultNotice`
|
|
204
|
-
root.find(j.MemberExpression, { object: { type: 'Identifier' } }).forEach(function (nodePath) {
|
|
205
|
-
if (nodePath.value.object.type === 'Identifier' &&
|
|
206
|
-
Object.keys(specifierMap).includes(nodePath.value.object.name)) {
|
|
207
|
-
nodePath.value.object.name = specifierMap[nodePath.value.object.name];
|
|
208
|
-
}
|
|
209
|
-
});
|
|
210
|
-
return root;
|
|
211
|
-
}
|
package/index.js
CHANGED
|
@@ -2,32 +2,32 @@
|
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
const {spawn} = require('child_process');
|
|
5
|
-
|
|
5
|
+
require('colors');
|
|
6
6
|
|
|
7
7
|
const {_: commands, path} = require('yargs')
|
|
8
8
|
.scriptName('canvas-kit-codemod')
|
|
9
|
-
.usage(
|
|
10
|
-
.command('v5 [path]',
|
|
9
|
+
.usage('$0 <transform> [path]'.brightBlue.bold)
|
|
10
|
+
.command('v5 [path]', 'Canvas Kit v4 > v5 migration transform'.gray, yargs => {
|
|
11
11
|
yargs.positional('path', {
|
|
12
12
|
type: 'string',
|
|
13
13
|
default: '.',
|
|
14
|
-
describe:
|
|
14
|
+
describe: 'The path to execute the transform in (recursively).'.gray,
|
|
15
15
|
});
|
|
16
16
|
})
|
|
17
|
-
.command('v6 [path]',
|
|
17
|
+
.command('v6 [path]', 'Canvas Kit v5 > v6 migration transform'.gray, yargs => {
|
|
18
18
|
yargs.positional('path', {
|
|
19
19
|
type: 'string',
|
|
20
20
|
default: '.',
|
|
21
|
-
describe:
|
|
21
|
+
describe: 'The path to execute the transform in (recursively).'.gray,
|
|
22
22
|
});
|
|
23
23
|
})
|
|
24
|
-
.demandCommand(1,
|
|
24
|
+
.demandCommand(1, 'You must provide a transform to apply.'.red.bold)
|
|
25
25
|
.strictCommands()
|
|
26
26
|
.fail((msg, err, yargs) => {
|
|
27
27
|
if (err) {
|
|
28
28
|
throw err;
|
|
29
29
|
}
|
|
30
|
-
console.error(`\n${
|
|
30
|
+
console.error(`\n${msg.red.bold}\n`);
|
|
31
31
|
console.error(yargs.help());
|
|
32
32
|
process.exit(1);
|
|
33
33
|
})
|
|
@@ -41,7 +41,7 @@ const {_: commands, path} = require('yargs')
|
|
|
41
41
|
const transform = commands[0];
|
|
42
42
|
console.log(transform, path);
|
|
43
43
|
|
|
44
|
-
console.log(
|
|
44
|
+
console.log(`\nApplying ${transform} transform to '${path}'\n`.brightBlue);
|
|
45
45
|
const args = `-t ${__dirname}/dist/es6/${transform} ${path} --parser tsx --extensions js,jsx,ts,tsx`.split(
|
|
46
46
|
' '
|
|
47
47
|
);
|
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": "6.3.0
|
|
5
|
+
"version": "6.3.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,
|
|
@@ -29,18 +29,15 @@
|
|
|
29
29
|
},
|
|
30
30
|
"homepage": "https://github.com/Workday/canvas-kit#readme",
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"
|
|
33
|
-
"jscodeshift": "^0.
|
|
32
|
+
"colors": "1.4.0",
|
|
33
|
+
"jscodeshift": "^0.11.0",
|
|
34
34
|
"yargs": "^16.2.0"
|
|
35
35
|
},
|
|
36
|
-
"devDependencies": {
|
|
37
|
-
"@types/jscodeshift": "^0.11.3"
|
|
38
|
-
},
|
|
39
36
|
"scripts": {
|
|
40
37
|
"clean": "rimraf dist && rimraf .build-info && mkdirp dist",
|
|
41
38
|
"build": "tsc -p tsconfig.es6.json",
|
|
42
39
|
"test": "TZ=UTC jest -c ../../jest.config.js",
|
|
43
40
|
"typecheck:src": "tsc -p . --noEmit --incremental false"
|
|
44
41
|
},
|
|
45
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "94d5ae2d79daa43b9c2ef5f8eef572fc89694d5e"
|
|
46
43
|
}
|