@workday/canvas-kit-codemod 6.8.2 → 6.8.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.
@@ -1 +1 @@
1
- {"version":3,"file":"moveAndRenameSearchBar.d.ts","sourceRoot":"","sources":["../../../lib/v6/moveAndRenameSearchBar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,SAAS,EAAqC,MAAM,aAAa,CAAC;AAyBnF,QAAA,MAAM,SAAS,EAAE,SA0EhB,CAAC;AAEF,eAAe,SAAS,CAAC"}
1
+ {"version":3,"file":"moveAndRenameSearchBar.d.ts","sourceRoot":"","sources":["../../../lib/v6/moveAndRenameSearchBar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,SAAS,EAAqC,MAAM,aAAa,CAAC;AAyBnF,QAAA,MAAM,SAAS,EAAE,SAyGhB,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -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, renameImports, hasImportSpecifiers, } from './utils';
8
+ import { filterImportSpecifiers, renameImports, hasImportSpecifiers, } 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'];
@@ -27,6 +27,7 @@ var transform = function (file, api) {
27
27
  function insertImportDeclarationBefore(nodePath, specifiers, sourcePath) {
28
28
  nodePath.insertBefore(j.importDeclaration(specifiers, j.stringLiteral(sourcePath)));
29
29
  }
30
+ var discoveredImportSpecifiers = {};
30
31
  // Rename search-bar named imports from @workday/canvas-kit-labs-react
31
32
  // e.g. import { SearchBar, SearchBarProps } from '@workday/canvas-kit-labs-react';
32
33
  // becomes import { SearchForm, SearchFormProps } from '@workday/canvas-kit-labs-react';
@@ -35,7 +36,16 @@ var transform = function (file, api) {
35
36
  // Filter search bar imports
36
37
  var searchBarImports = filterImportSpecifiers(importSpecifiers);
37
38
  // Rename search bar imports
38
- renameImportSpecifiers(searchBarImports, renameMap);
39
+ searchBarImports.forEach(function (specifier) {
40
+ var specifierName = specifier.imported.name;
41
+ if (specifierName in renameMap) {
42
+ // if it hasn't been aliased, track it for updating JSX
43
+ if (!specifier.local || specifier.local.name === specifier.imported.name) {
44
+ discoveredImportSpecifiers[specifier.imported.name] = true;
45
+ }
46
+ specifier.imported.name = renameMap[specifierName];
47
+ }
48
+ });
39
49
  });
40
50
  // Handle imports from @workday/canvas-kit-react/header
41
51
  // e.g import { Header, SearchBar, SearchBarProps } from '@workday/canvas-kit-labs-react/header';
@@ -62,8 +72,17 @@ var transform = function (file, api) {
62
72
  root.find(j.ImportDeclaration, { source: { value: headerPackage } }).remove();
63
73
  // If SearchBar import specifiers were found, insert a new import declaration above the original import declaration
64
74
  if (searchBarSpecifiers.length) {
65
- var renamedSearchBarSpecifiers = renameImportSpecifiers(searchBarSpecifiers, renameMap);
66
- insertImportDeclarationBefore(nodePath, renamedSearchBarSpecifiers, '@workday/canvas-kit-labs-react/search-form');
75
+ searchBarSpecifiers.forEach(function (specifier) {
76
+ var specifierName = specifier.imported.name;
77
+ if (specifierName in renameMap) {
78
+ // if it hasn't been aliased, track it for updating JSX
79
+ if (!specifier.local || specifier.local.name === specifier.imported.name) {
80
+ discoveredImportSpecifiers[specifier.imported.name] = true;
81
+ }
82
+ specifier.imported.name = renameMap[specifierName];
83
+ }
84
+ });
85
+ insertImportDeclarationBefore(nodePath, searchBarSpecifiers, '@workday/canvas-kit-labs-react/search-form');
67
86
  }
68
87
  // If other header import specifiers were found, insert a new import declaration above the original import declaration
69
88
  // This will replace the import declaration that was removed above
@@ -71,6 +90,6 @@ var transform = function (file, api) {
71
90
  insertImportDeclarationBefore(nodePath, headerSpecifiers, headerPackage);
72
91
  }
73
92
  });
74
- return renameImports(api, root, '@workday/canvas-kit-labs-react/header', renameMap).toSource();
93
+ return renameImports(api, root, '@workday/canvas-kit-labs-react/search-form', renameMap, discoveredImportSpecifiers).toSource();
75
94
  };
76
95
  export default transform;
@@ -16,17 +16,6 @@ export declare function filterImportSpecifiers(importSpecifiers: ImportSpecifier
16
16
  export declare type RenameMap = {
17
17
  [key: string]: string;
18
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
19
  /**
31
20
  * Returns a filtered array of ImportDefaultSpecifiers
32
21
  * You can filter all ImportDefaultSpecifiers or additionally filter by providing an array of import names.
@@ -66,5 +55,5 @@ export declare function renameImportDefaultSpecifiers(importSpecifiers: ImportDe
66
55
  * }
67
56
  */
68
57
  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>;
58
+ export declare function renameImports(api: API, root: Collection<any>, packageName: string, specifierMap: Record<string, string>, discoveredImportSpecifiers?: Record<string, boolean>): Collection<any>;
70
59
  //# 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,EACL,eAAe,EACf,sBAAsB,EACtB,wBAAwB,EACxB,UAAU,EACV,GAAG,EACJ,MAAM,aAAa,CAAC;AAErB,oBAAY,oBAAoB,GAAG,CAC/B,eAAe,GACf,wBAAwB,GACxB,sBAAsB,CACzB,EAAE,CAAC;AAEJ;;;;;;;;;;;GAWG;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AgB,EAAE,oBAAoB,EACtC,WAAW,CAAC,EAAE,MAAM,EAAE,qBAevB;AAED,oBAAY,SAAS,GAAG;IACtB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CACvB,CAAC;AAEF;;;;;;;;;;;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;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,UAAU,CAAC,GAAG,CAAC,EACrB,WAAW,EAAE,MAAM,GAAG,MAAM,EAAE,EAC9B,UAAU,EAAE,MAAM,EAAE,WAkCrB;AAED,wBAAgB,aAAa,CAC3B,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,UAAU,CAAC,GAAG,CAAC,EACrB,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACpC,0BAA0B,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GACvD,UAAU,CAAC,GAAG,CAAC,CA+GjB"}
@@ -24,25 +24,6 @@ export function filterImportSpecifiers(importSpecifiers, importNames) {
24
24
  });
25
25
  return filteredSpecifiers;
26
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
27
  /**
47
28
  * Returns a filtered array of ImportDefaultSpecifiers
48
29
  * You can filter all ImportDefaultSpecifiers or additionally filter by providing an array of import names.
@@ -134,7 +115,8 @@ export function hasImportSpecifiers(api, root, packageName, specifiers) {
134
115
  return false;
135
116
  });
136
117
  }
137
- export function renameImports(api, root, packageName, specifierMap) {
118
+ export function renameImports(api, root, packageName, specifierMap, discoveredImportSpecifiers) {
119
+ if (discoveredImportSpecifiers === void 0) { discoveredImportSpecifiers = {}; }
138
120
  var j = api.jscodeshift;
139
121
  if (!hasImportSpecifiers(api, root, packageName, Object.keys(specifierMap))) {
140
122
  return root;
@@ -146,27 +128,41 @@ export function renameImports(api, root, packageName, specifierMap) {
146
128
  // Transform import statements
147
129
  // e.g. import { CookieBanner, CookieBannerProps } from '@workday/canvas-kit-react';
148
130
  // becomes import { DeprecatedCookieBanner, DeprecatedCookieBannerProps } from '@workday/canvas-kit-react';
131
+ // Find imports from main packages
132
+ // ex. '@workday/canvas-kit-labs-react'
149
133
  root.find(j.ImportDeclaration, { source: { value: mainPackage } }).forEach(function (nodePath) {
150
134
  var _a;
151
135
  (_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.forEach(function (specifier) {
152
136
  if (specifier.type === 'ImportSpecifier') {
153
137
  if (Object.keys(specifierMap).includes(specifier.imported.name)) {
138
+ // if it hasn't been aliased, track it for updating JSX
139
+ if (!specifier.local || specifier.local.name === specifier.imported.name) {
140
+ discoveredImportSpecifiers[specifier.imported.name] = true;
141
+ }
154
142
  specifier.imported.name = specifierMap[specifier.imported.name];
155
143
  }
156
144
  }
157
145
  });
158
146
  });
159
- // Transforms default imports from package
147
+ // Find imports from component specific packages
148
+ // ex. '@workday/canvas-kit-labs-react/header'
160
149
  root.find(j.ImportDeclaration, { source: { value: packageName } }).forEach(function (nodePath) {
161
150
  var _a;
162
151
  (_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.forEach(function (specifier) {
152
+ // Transforms default imports
163
153
  if (specifier.type === 'ImportDefaultSpecifier') {
164
154
  if (specifier.local && Object.keys(specifierMap).includes(specifier.local.name)) {
155
+ discoveredImportSpecifiers[specifier.local.name] = true;
165
156
  specifier.local.name = specifierMap[specifier.local.name];
166
157
  }
167
158
  }
159
+ // Transform named exports
168
160
  if (specifier.type === 'ImportSpecifier') {
169
161
  if (Object.keys(specifierMap).includes(specifier.imported.name)) {
162
+ // if it hasn't been aliased, track it for updating JSX
163
+ if (!specifier.local || specifier.local.name === specifier.imported.name) {
164
+ discoveredImportSpecifiers[specifier.imported.name] = true;
165
+ }
170
166
  specifier.imported.name = specifierMap[specifier.imported.name];
171
167
  }
172
168
  }
@@ -195,7 +191,10 @@ export function renameImports(api, root, packageName, specifierMap) {
195
191
  // Transform JSXElements
196
192
  // e.g. `<CookieBanner>` becomes `<DeprecatedCookieBanner>`
197
193
  root.find(j.JSXIdentifier).forEach(function (nodePath) {
198
- if (Object.keys(specifierMap).includes(nodePath.value.name)) {
194
+ if (
195
+ // Check to see if it was imported from Canvas Kit
196
+ discoveredImportSpecifiers[nodePath.value.name] &&
197
+ Object.keys(specifierMap).includes(nodePath.value.name)) {
199
198
  nodePath.node.name = specifierMap[nodePath.value.name];
200
199
  }
201
200
  });
@@ -203,6 +202,8 @@ export function renameImports(api, root, packageName, specifierMap) {
203
202
  // e.g. `CookieBanner.DefaultNotice` becomes `DeprecatedCookieBanner.DefaultNotice`
204
203
  root.find(j.MemberExpression, { object: { type: 'Identifier' } }).forEach(function (nodePath) {
205
204
  if (nodePath.value.object.type === 'Identifier' &&
205
+ // Check to see if it was imported from Canvas Kit
206
+ discoveredImportSpecifiers[nodePath.value.object.name] &&
206
207
  Object.keys(specifierMap).includes(nodePath.value.object.name)) {
207
208
  nodePath.value.object.name = specifierMap[nodePath.value.object.name];
208
209
  }
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.8.2",
5
+ "version": "6.8.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,
@@ -42,5 +42,5 @@
42
42
  "test": "TZ=UTC jest -c ../../jest.config.js",
43
43
  "typecheck:src": "tsc -p . --noEmit --incremental false"
44
44
  },
45
- "gitHead": "4f98e7c4d826edea5f98caaeee2ca0b73e0c6bbd"
45
+ "gitHead": "6dce5532d5eda5fa36ce4243a98fd9f586c4ab14"
46
46
  }