@workday/canvas-kit-codemod 5.3.0-next.10 → 5.3.0-next.24

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":"index.d.ts","sourceRoot":"","sources":["../../../lib/v6/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAC,MAAM,aAAa,CAAC;AAUnD,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UAW7E"}
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"}
@@ -17,6 +17,8 @@ import deprecateCookieBanner from './deprecateCookieBanner';
17
17
  import moveAndRenameSearchBar from './moveAndRenameSearchBar';
18
18
  // deprecate header imports
19
19
  import deprecateHeader from './deprecateHeader';
20
+ // rename CanvasDepthValue
21
+ import renameCanvasDepthValue from './renameCanvasDepthValue';
20
22
  export default function transformer(file, api, options) {
21
23
  // These will run in order. If your transform depends on others, place yours after dependent transforms
22
24
  var fixes = [
@@ -25,6 +27,7 @@ export default function transformer(file, api, options) {
25
27
  moveAndRenameSearchBar,
26
28
  // needs to run after `moveAndRenameSearchBar`
27
29
  deprecateHeader,
30
+ renameCanvasDepthValue,
28
31
  ];
29
32
  return fixes.reduce(function (source, fix) { return fix(__assign(__assign({}, file), { source: source }), api, options); }, file.source);
30
33
  }
@@ -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
+ }
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')
@@ -42,18 +42,19 @@ const transform = commands[0];
42
42
  console.log(transform, path);
43
43
 
44
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
+ );
45
48
 
46
- exec(
47
- `jscodeshift -t ${__dirname}/dist/es6/${transform} ${path} --parser=tsx --extensions=js,jsx,ts,tsx`,
48
- (error, stdout, stderr) => {
49
- if (error) {
50
- console.error(`${error}\n`);
51
- return;
52
- }
53
- console.log(`${stdout}\n`);
49
+ const proc = spawn(`jscodeshift`, args);
54
50
 
55
- if (stderr) {
56
- console.error(`${stderr}\n`);
57
- }
58
- }
59
- );
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": "5.3.0-next.10+b216c2fc",
5
+ "version": "5.3.0-next.24+98e275f5",
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,
@@ -36,7 +36,8 @@
36
36
  "scripts": {
37
37
  "clean": "rimraf dist && rimraf .build-info && mkdirp dist",
38
38
  "build": "tsc -p tsconfig.es6.json",
39
- "test": "TZ=UTC jest -c ../../jest.config.js"
39
+ "test": "TZ=UTC jest -c ../../jest.config.js",
40
+ "typecheck:src": "tsc -p . --noEmit --incremental false"
40
41
  },
41
- "gitHead": "b216c2fce58ac89402ca5b152640ddabdca25596"
42
+ "gitHead": "98e275f55f5fb0abecdc77f1cea1189eb5d6b791"
42
43
  }