@workday/canvas-kit-codemod 6.0.0-beta.0-next.16 → 6.0.3

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.
@@ -0,0 +1,3 @@
1
+ import { API, FileInfo, Options } from 'jscodeshift';
2
+ export default function transformer(file: FileInfo, api: API, options: Options): string;
3
+ //# sourceMappingURL=deprecateCookieBanner.d.ts.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,112 @@
1
+ var mainPackage = '@workday/canvas-kit-react';
2
+ var cookieBannerPackage = '@workday/canvas-kit-react/cookie-banner';
3
+ export default function transformer(file, api, options) {
4
+ var j = api.jscodeshift;
5
+ var root = j(file.source);
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
+ }
@@ -0,0 +1,3 @@
1
+ import { API, FileInfo } from 'jscodeshift';
2
+ export default function transformer(file: FileInfo, api: API): string;
3
+ //# sourceMappingURL=deprecateHeader.d.ts.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,115 @@
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'];
16
+ var headerRenameMap = {
17
+ DubLogoTitle: 'DeprecatedDubLogoTitle',
18
+ GlobalHeader: 'DeprecatedGlobalHeader',
19
+ Header: 'DeprecatedHeader',
20
+ HeaderHeight: 'DeprecatedHeaderHeight',
21
+ HeaderTheme: 'DeprecatedHeaderTheme',
22
+ HeaderVariant: 'DeprecatedHeaderVariant',
23
+ ThemeAttributes: 'DeprecatedHeaderThemeAttributes',
24
+ Themes: 'DeprecatedHeaderThemes',
25
+ WorkdayLogoTitle: 'DeprecatedWorkdayLogoTitle',
26
+ themes: 'deprecatedHeaderThemes',
27
+ };
28
+ export default function transformer(file, api) {
29
+ var j = api.jscodeshift;
30
+ var root = j(file.source);
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
+ }
@@ -0,0 +1,3 @@
1
+ import { API, FileInfo, Options } from 'jscodeshift';
2
+ export default function transformer(file: FileInfo, api: API, options: Options): string;
3
+ //# sourceMappingURL=deprecatePageHeader.d.ts.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,102 @@
1
+ var mainPackage = '@workday/canvas-kit-react';
2
+ var pageHeaderPackage = '@workday/canvas-kit-react/page-header';
3
+ export default function transformer(file, api, options) {
4
+ var j = api.jscodeshift;
5
+ var root = j(file.source);
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
+ }
@@ -1,3 +1,3 @@
1
1
  import { API, FileInfo, Options } from 'jscodeshift';
2
- export default function transformer(file: FileInfo, api: API, options: Options): void;
2
+ export default function transformer(file: FileInfo, api: API, options: Options): string;
3
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,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAC,MAAM,aAAa,CAAC;AAInD,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,QAO7E"}
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"}
@@ -1,8 +1,33 @@
1
- // Future v6 codemods go here!
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ // deprecate PageHeader
13
+ import deprecatePageHeader from './deprecatePageHeader';
14
+ // deprecate CookieBanner
15
+ import deprecateCookieBanner from './deprecateCookieBanner';
16
+ // move and rename SearchBar
17
+ import moveAndRenameSearchBar from './moveAndRenameSearchBar';
18
+ // deprecate header imports
19
+ import deprecateHeader from './deprecateHeader';
20
+ // rename CanvasDepthValue
21
+ import renameCanvasDepthValue from './renameCanvasDepthValue';
2
22
  export default function transformer(file, api, options) {
3
- // These will run in order. If your transform depends on others, place yours after dependent
4
- // transforms
5
- return;
6
- // const fixes = [];
7
- // return fixes.reduce((source, fix) => fix({...file, source}, api, options), file.source);
23
+ // These will run in order. If your transform depends on others, place yours after dependent transforms
24
+ var fixes = [
25
+ deprecatePageHeader,
26
+ deprecateCookieBanner,
27
+ moveAndRenameSearchBar,
28
+ // needs to run after `moveAndRenameSearchBar`
29
+ deprecateHeader,
30
+ renameCanvasDepthValue,
31
+ ];
32
+ return fixes.reduce(function (source, fix) { return fix(__assign(__assign({}, file), { source: source }), api, options); }, file.source);
8
33
  }
@@ -0,0 +1,3 @@
1
+ import { API, FileInfo } from 'jscodeshift';
2
+ export default function transformer(file: FileInfo, api: API): string;
3
+ //# sourceMappingURL=moveAndRenameSearchBar.d.ts.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,117 @@
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 { filterImportSpecifiers, renameImportSpecifiers, } from './utils';
9
+ var mainPackage = '@workday/canvas-kit-labs-react';
10
+ var headerPackage = '@workday/canvas-kit-labs-react/header';
11
+ var searchBarRenameImports = ['SearchBar', 'SearchBarProps', 'SearchBarState'];
12
+ var searchBarImportSpecifiers = __spreadArrays(searchBarRenameImports, [
13
+ 'SearchThemeAttributes',
14
+ 'SearchThemes',
15
+ ]);
16
+ var renameMap = {
17
+ SearchBar: 'SearchForm',
18
+ SearchBarProps: 'SearchFormProps',
19
+ SearchBarState: 'SearchFormState',
20
+ };
21
+ export default function transformer(file, api) {
22
+ var j = api.jscodeshift;
23
+ var root = j(file.source);
24
+ var hasSearchBarImports = false;
25
+ function insertImportDeclarationBefore(nodePath, specifiers, sourcePath) {
26
+ nodePath.insertBefore(j.importDeclaration(specifiers, j.stringLiteral(sourcePath)));
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
+ }
44
+ // Rename search-bar named imports from @workday/canvas-kit-labs-react
45
+ // e.g. import { SearchBar, SearchBarProps } from '@workday/canvas-kit-labs-react';
46
+ // becomes import { SearchForm, SearchFormProps } from '@workday/canvas-kit-labs-react';
47
+ root.find(j.ImportDeclaration, { source: { value: mainPackage } }).forEach(function (nodePath) {
48
+ var importSpecifiers = nodePath.value.specifiers || [];
49
+ // Filter search bar imports
50
+ var searchBarImports = filterImportSpecifiers(importSpecifiers);
51
+ // Rename search bar imports
52
+ renameImportSpecifiers(searchBarImports, renameMap);
53
+ });
54
+ // Handle imports from @workday/canvas-kit-react/header
55
+ // e.g import { Header, SearchBar, SearchBarProps } from '@workday/canvas-kit-labs-react/header';
56
+ // becomes import { Header } from '@workday/canvas-kit-labs-react/header';
57
+ // and import { SearchForm, SearchFormProps } from '@workday/canvas-kit-labs-react/search-form';
58
+ root.find(j.ImportDeclaration, { source: { value: headerPackage } }).forEach(function (nodePath) {
59
+ var importSpecifiers = nodePath.value.specifiers || [];
60
+ var headerSpecifiers = [];
61
+ var searchBarSpecifiers = [];
62
+ importSpecifiers.forEach(function (specifier) {
63
+ // If there is a SearchBar import specifier, keep it in an array.
64
+ // This will be used to build a new import declaration later.
65
+ if (specifier.type === 'ImportSpecifier' &&
66
+ searchBarImportSpecifiers.includes(specifier.imported.name)) {
67
+ searchBarSpecifiers.push(specifier);
68
+ }
69
+ else {
70
+ // If there is another header import specifier, keep it in a separate array.
71
+ // This will be used to build a new import declaration later.
72
+ headerSpecifiers.push(specifier);
73
+ }
74
+ });
75
+ // Remove the original import declaration
76
+ root.find(j.ImportDeclaration, { source: { value: headerPackage } }).remove();
77
+ // If SearchBar import specifiers were found, insert a new import declaration above the original import declaration
78
+ if (searchBarSpecifiers.length) {
79
+ var renamedSearchBarSpecifiers = renameImportSpecifiers(searchBarSpecifiers, renameMap);
80
+ insertImportDeclarationBefore(nodePath, renamedSearchBarSpecifiers, '@workday/canvas-kit-labs-react/search-form');
81
+ }
82
+ // If other header import specifiers were found, insert a new import declaration above the original import declaration
83
+ // This will replace the import declaration that was removed above
84
+ if (headerSpecifiers.length) {
85
+ insertImportDeclarationBefore(nodePath, headerSpecifiers, headerPackage);
86
+ }
87
+ });
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
+ }
@@ -0,0 +1,3 @@
1
+ import { API, FileInfo } from 'jscodeshift';
2
+ export default function transformer(file: FileInfo, api: API): string;
3
+ //# sourceMappingURL=renameCanvasDepthValue.d.ts.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,74 @@
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) {
7
+ var j = api.jscodeshift;
8
+ var root = j(file.source);
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
+ }
@@ -0,0 +1,51 @@
1
+ import { ImportSpecifier, ImportDefaultSpecifier, ImportNamespaceSpecifier } from 'jscodeshift';
2
+ export declare type ImportSpecifierArray = (ImportSpecifier | ImportNamespaceSpecifier | ImportDefaultSpecifier)[];
3
+ /**
4
+ * Returns a filtered array of ImportSpecifiers
5
+ * You can filter all ImportSpecifiers or additionally filter by providing an array of import names.
6
+ * @example
7
+ * root.find(j.ImportDeclaration, (nodePath: ImportDeclaration) => {
8
+ * const importSpecifiers = nodePath.specifiers || [];
9
+ * // specific named imports we're looking for
10
+ * const importNames = ['PageHeader', 'PageHeaderProps']
11
+ * const pageHeaderImports = filterImportSpecifiers(importSpecifiers, importNames);
12
+ * ...
13
+ * }
14
+ */
15
+ export declare function filterImportSpecifiers(importSpecifiers: ImportSpecifierArray, importNames?: string[]): ImportSpecifier[];
16
+ export declare type RenameMap = {
17
+ [key: string]: string;
18
+ };
19
+ /**
20
+ * Renames import specifiers for a given rename map
21
+ * @example
22
+ * const renameMap = {
23
+ * 'PageHeader': 'DeprecatedPageHeader',
24
+ * 'PageHeaderProps': 'DeprecatedPageHeaderProps',
25
+ * };
26
+ * const pageHeaderImports = filterImportSpecifiers(importSpecifiers, importNames);
27
+ * renameImportSpecifiers(pageHeaderSpecifiers, renameMap);
28
+ */
29
+ export declare function renameImportSpecifiers(importSpecifiers: ImportSpecifier[], renameMap: RenameMap): ImportSpecifier[];
30
+ /**
31
+ * Returns a filtered array of ImportDefaultSpecifiers
32
+ * You can filter all ImportDefaultSpecifiers or additionally filter by providing an array of import names.
33
+ * @example
34
+ * root.find(j.ImportDeclaration, (nodePath: ImportDeclaration) => {
35
+ * const importSpecifiers = nodePath.specifiers || [];
36
+ * // specific default imports we're looking for
37
+ * const importNames = ['PageHeader']
38
+ * const pageHeaderImports = filterImportDefaultSpecifiers(importSpecifiers, importNames);
39
+ * ...
40
+ * }
41
+ */
42
+ export declare function filterImportDefaultSpecifiers(importSpecifiers: ImportSpecifierArray, importNames?: string[]): ImportDefaultSpecifier[];
43
+ /**
44
+ * Renames import default specifiers for a given rename map
45
+ * @example
46
+ * const renameMap = { 'PageHeader': 'DeprecatedPageHeader' };
47
+ * const pageHeaderImports = filterImportDefaultSpecifiers(importSpecifiers, importNames);
48
+ * renameImportSpecifiers(pageHeaderSpecifiers, renameMap);
49
+ */
50
+ export declare function renameImportDefaultSpecifiers(importSpecifiers: ImportDefaultSpecifier[], renameMap: RenameMap): ImportDefaultSpecifier[];
51
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Returns a filtered array of ImportSpecifiers
3
+ * You can filter all ImportSpecifiers or additionally filter by providing an array of import names.
4
+ * @example
5
+ * root.find(j.ImportDeclaration, (nodePath: ImportDeclaration) => {
6
+ * const importSpecifiers = nodePath.specifiers || [];
7
+ * // specific named imports we're looking for
8
+ * const importNames = ['PageHeader', 'PageHeaderProps']
9
+ * const pageHeaderImports = filterImportSpecifiers(importSpecifiers, importNames);
10
+ * ...
11
+ * }
12
+ */
13
+ export function filterImportSpecifiers(importSpecifiers, importNames) {
14
+ var filteredSpecifiers = [];
15
+ importSpecifiers.forEach(function (specifier) {
16
+ if (specifier.type === 'ImportSpecifier') {
17
+ if (importNames && importNames.includes(specifier.imported.name)) {
18
+ filteredSpecifiers.push(specifier);
19
+ }
20
+ else {
21
+ filteredSpecifiers.push(specifier);
22
+ }
23
+ }
24
+ });
25
+ return filteredSpecifiers;
26
+ }
27
+ /**
28
+ * Renames import specifiers for a given rename map
29
+ * @example
30
+ * const renameMap = {
31
+ * 'PageHeader': 'DeprecatedPageHeader',
32
+ * 'PageHeaderProps': 'DeprecatedPageHeaderProps',
33
+ * };
34
+ * const pageHeaderImports = filterImportSpecifiers(importSpecifiers, importNames);
35
+ * renameImportSpecifiers(pageHeaderSpecifiers, renameMap);
36
+ */
37
+ export function renameImportSpecifiers(importSpecifiers, renameMap) {
38
+ importSpecifiers.forEach(function (specifier) {
39
+ var specifierName = specifier.imported.name;
40
+ if (specifierName in renameMap) {
41
+ specifier.imported.name = renameMap[specifierName];
42
+ }
43
+ });
44
+ return importSpecifiers;
45
+ }
46
+ /**
47
+ * Returns a filtered array of ImportDefaultSpecifiers
48
+ * You can filter all ImportDefaultSpecifiers or additionally filter by providing an array of import names.
49
+ * @example
50
+ * root.find(j.ImportDeclaration, (nodePath: ImportDeclaration) => {
51
+ * const importSpecifiers = nodePath.specifiers || [];
52
+ * // specific default imports we're looking for
53
+ * const importNames = ['PageHeader']
54
+ * const pageHeaderImports = filterImportDefaultSpecifiers(importSpecifiers, importNames);
55
+ * ...
56
+ * }
57
+ */
58
+ export function filterImportDefaultSpecifiers(importSpecifiers, importNames) {
59
+ var filteredSpecifiers = [];
60
+ importSpecifiers.forEach(function (specifier) {
61
+ var _a;
62
+ if (specifier.type === 'ImportDefaultSpecifier') {
63
+ var localName = ((_a = specifier.local) === null || _a === void 0 ? void 0 : _a.name) || '';
64
+ if (importNames && importNames.includes(localName)) {
65
+ filteredSpecifiers.push(specifier);
66
+ }
67
+ else {
68
+ filteredSpecifiers.push(specifier);
69
+ }
70
+ }
71
+ });
72
+ return filteredSpecifiers;
73
+ }
74
+ /**
75
+ * Renames import default specifiers for a given rename map
76
+ * @example
77
+ * const renameMap = { 'PageHeader': 'DeprecatedPageHeader' };
78
+ * const pageHeaderImports = filterImportDefaultSpecifiers(importSpecifiers, importNames);
79
+ * renameImportSpecifiers(pageHeaderSpecifiers, renameMap);
80
+ */
81
+ export function renameImportDefaultSpecifiers(importSpecifiers, renameMap) {
82
+ importSpecifiers.forEach(function (specifier) {
83
+ var _a;
84
+ var specifierName = (_a = specifier.local) === null || _a === void 0 ? void 0 : _a.name;
85
+ if (specifier.local && specifierName && specifierName in renameMap) {
86
+ specifier.local.name = renameMap[specifierName];
87
+ }
88
+ });
89
+ return importSpecifiers;
90
+ }
package/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict';
3
3
 
4
- const {exec} = require('child_process');
4
+ const {spawn} = require('child_process');
5
5
  require('colors');
6
6
 
7
7
  const {_: commands, path} = require('yargs')
@@ -14,6 +14,13 @@ const {_: commands, path} = require('yargs')
14
14
  describe: 'The path to execute the transform in (recursively).'.gray,
15
15
  });
16
16
  })
17
+ .command('v6 [path]', 'Canvas Kit v5 > v6 migration transform'.gray, yargs => {
18
+ yargs.positional('path', {
19
+ type: 'string',
20
+ default: '.',
21
+ describe: 'The path to execute the transform in (recursively).'.gray,
22
+ });
23
+ })
17
24
  .demandCommand(1, 'You must provide a transform to apply.'.red.bold)
18
25
  .strictCommands()
19
26
  .fail((msg, err, yargs) => {
@@ -35,18 +42,19 @@ const transform = commands[0];
35
42
  console.log(transform, path);
36
43
 
37
44
  console.log(`\nApplying ${transform} transform to '${path}'\n`.brightBlue);
45
+ const args = `-t ${__dirname}/dist/es6/${transform} ${path} --parser tsx --extensions js,jsx,ts,tsx`.split(
46
+ ' '
47
+ );
38
48
 
39
- exec(
40
- `jscodeshift -t ${__dirname}/dist/es6/${transform} ${path} --parser=tsx --extensions=js,jsx,ts,tsx --verbose=2`,
41
- (error, stdout, stderr) => {
42
- if (error) {
43
- console.error(`${error}\n`);
44
- return;
45
- }
46
- console.log(`${stdout}\n`);
49
+ const proc = spawn(`jscodeshift`, args);
47
50
 
48
- if (stderr) {
49
- console.error(`${stderr}\n`);
50
- }
51
- }
52
- );
51
+ let errCode = 0;
52
+ proc.stdout.on('data', data => console.log(data.toString()));
53
+ proc.stderr.on('data', data => {
54
+ errCode = 1;
55
+ console.error(data.toString());
56
+ });
57
+
58
+ proc.on('close', code => {
59
+ process.exit(code || errCode);
60
+ });
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.0.0-beta.0-next.16+2c70e470",
5
+ "version": "6.0.3",
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,
@@ -38,5 +38,5 @@
38
38
  "build": "tsc -p tsconfig.es6.json",
39
39
  "test": "TZ=UTC jest -c ../../jest.config.js"
40
40
  },
41
- "gitHead": "2c70e470ff0afecfdd18ea96837ab7f19f812128"
41
+ "gitHead": "735c60ddf52268f643c72ceb915e896906f74bcc"
42
42
  }