@workday/canvas-kit-codemod 8.4.0-296-next.0 → 8.4.0-303-next.2

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,4 @@
1
+ import { Transform } from 'jscodeshift';
2
+ declare const transform: Transform;
3
+ export default transform;
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../lib/softDeprecate/Stack/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAItC,QAAA,MAAM,SAAS,EAAE,SAIhB,CAAC;AACF,eAAe,SAAS,CAAC"}
@@ -0,0 +1,17 @@
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
+ import softDeprecateStack from './softDeprecateStack';
13
+ var transform = function (file, api, options) {
14
+ var fixes = [softDeprecateStack];
15
+ return fixes.reduce(function (source, fix) { return fix(__assign(__assign({}, file), { source: source }), api, options); }, file.source);
16
+ };
17
+ export default transform;
@@ -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=softDeprecateStack.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"softDeprecateStack.d.ts","sourceRoot":"","sources":["../../../../lib/softDeprecate/Stack/softDeprecateStack.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAA+C,OAAO,EAAC,MAAM,aAAa,CAAC;AAOhG,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UAyM7E"}
@@ -0,0 +1,174 @@
1
+ var mainPackage = '@workday/canvas-kit-react';
2
+ var stackPackage = '@workday/canvas-kit-react/layout';
3
+ var stackImportNames = ['Stack', 'HStack', 'VStack'];
4
+ var stackImportProps = ['StackProps', 'HStackProps', 'VStackProps', 'StackStyleProps'];
5
+ export default function transformer(file, api, options) {
6
+ var j = api.jscodeshift;
7
+ var root = j(file.source);
8
+ var hasStackImports = false;
9
+ // This toggles the failsafe that prevents us from accidentally transforming something unintentionally.
10
+ root.find(j.ImportDeclaration, function (nodePath) {
11
+ var value = nodePath.source.value;
12
+ // If there's an import from the stack package, set the import boolean check to true
13
+ if (value === stackPackage) {
14
+ hasStackImports = true;
15
+ return false;
16
+ }
17
+ // If there's an import from the main package, check to see if Stack or Stackprops are among the named imports
18
+ // e.g. import {Stack} from '@workday/canvas-kit-react/layout';
19
+ if (value === mainPackage) {
20
+ (nodePath.specifiers || []).forEach(function (specifier) {
21
+ if ((specifier.type === 'ImportSpecifier' &&
22
+ stackImportNames.includes(specifier.imported.name)) ||
23
+ (specifier.type === 'ImportSpecifier' &&
24
+ stackImportProps.includes(specifier.imported.name))) {
25
+ hasStackImports = true;
26
+ }
27
+ });
28
+ }
29
+ return false;
30
+ });
31
+ // Failsafe to skip transforms unless a Stack import is detected
32
+ if (!hasStackImports) {
33
+ return root.toSource();
34
+ }
35
+ root
36
+ .find(j.ImportDeclaration, {
37
+ source: { value: function (value) { return value.includes(mainPackage); } },
38
+ })
39
+ .forEach(function (nodePath) {
40
+ var _a, _b;
41
+ (_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.forEach(function (specifier) {
42
+ if (specifier.type === 'ImportSpecifier') {
43
+ // `import {Stack}` becomes `import {Flex}`
44
+ // `import {HStack}` becomes `import {Flex}`
45
+ // `import {VStack}` becomes `import {Flex}`
46
+ if (stackImportNames.includes(specifier.imported.name)) {
47
+ specifier.imported.name = 'Flex';
48
+ }
49
+ }
50
+ return specifier;
51
+ });
52
+ nodePath.value.specifiers = (_b = nodePath.value.specifiers) === null || _b === void 0 ? void 0 : _b.filter(function (specifier, index, specifiers) {
53
+ if (specifier.type === 'ImportSpecifier' &&
54
+ specifier.imported &&
55
+ specifier.imported.type === 'Identifier') {
56
+ return (specifiers.findIndex(function (s) {
57
+ return (s.type === 'ImportSpecifier' &&
58
+ s.imported.type === 'Identifier' &&
59
+ s.imported.name === specifier.imported.name);
60
+ }) === index);
61
+ }
62
+ return true;
63
+ });
64
+ });
65
+ root
66
+ .find(j.ImportDeclaration, {
67
+ source: { value: function (value) { return value.includes(mainPackage); } },
68
+ })
69
+ .forEach(function (nodePath) {
70
+ var _a, _b;
71
+ (_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.forEach(function (specifier) {
72
+ if (specifier.type === 'ImportSpecifier') {
73
+ // `import {StackProps}` becomes `import {FlexProps}`
74
+ // `import {HStackProps}` becomes `import {FlexProps}`
75
+ // `import {VStackProps}` becomes `import {FlexProps}`
76
+ // `import {StackStyleProps}` becomes `import {FlexProps}`
77
+ if (stackImportProps.includes(specifier.imported.name)) {
78
+ specifier.imported.name = "FlexProps";
79
+ }
80
+ }
81
+ return specifier;
82
+ });
83
+ nodePath.value.specifiers = (_b = nodePath.value.specifiers) === null || _b === void 0 ? void 0 : _b.filter(function (specifier, index, specifiers) {
84
+ if (specifier.type === 'ImportSpecifier' &&
85
+ specifier.imported &&
86
+ specifier.imported.type === 'Identifier') {
87
+ return (specifiers.findIndex(function (s) {
88
+ return (s.type === 'ImportSpecifier' &&
89
+ s.imported.type === 'Identifier' &&
90
+ s.imported.name === specifier.imported.name);
91
+ }) === index);
92
+ }
93
+ return true;
94
+ });
95
+ });
96
+ // Transform StackProps type references
97
+ // e.g. `type CustomProps = StackProps;` becomes `type CustomProps = FlexProps;`
98
+ // Transform HStackProps type references
99
+ // e.g. `type CustomProps = HStackProps;` becomes `type CustomProps = FlexProps;`
100
+ // Transform VStackProps type references
101
+ // e.g. `type CustomProps = VStackProps;` becomes `type CustomProps = FlexProps;`
102
+ var typeNames = ['StackProps', 'HStackProps', 'VStackProps', 'StackStyleProps'];
103
+ root
104
+ .find(j.TSTypeReference, {
105
+ typeName: {
106
+ type: 'Identifier',
107
+ name: function (value) { return typeNames.includes(value); },
108
+ },
109
+ })
110
+ .forEach(function (nodePath) {
111
+ var identifier = nodePath.value.typeName;
112
+ identifier.name = "FlexProps";
113
+ });
114
+ // Transform StackProps type interface declaration references
115
+ // e.g. `interface CustomProps extends StackProps` becomes `interface CustomProps extends FlexProps`
116
+ root.find(j.TSInterfaceDeclaration).forEach(function (nodePath) {
117
+ var _a;
118
+ // If the interface is extending StackProps, transform the extension name to FlexProps
119
+ (_a = nodePath.node.extends) === null || _a === void 0 ? void 0 : _a.forEach(function (typeExtension) {
120
+ if (typeExtension.expression.type === 'Identifier') {
121
+ var typeExtensionName = typeExtension.expression.name;
122
+ if (typeExtension.expression.type === 'Identifier' &&
123
+ typeNames.includes(typeExtensionName)) {
124
+ typeExtension.expression.name = "FlexProps";
125
+ }
126
+ }
127
+ });
128
+ });
129
+ // Transform Stack JSXElements
130
+ // Transform `<Stack spacing="l">` to `<Flex gap="l">`
131
+ root
132
+ .findJSXElements('Stack')
133
+ .find(j.JSXIdentifier, { name: 'spacing' })
134
+ .forEach(function (nodePath) {
135
+ nodePath.node.name = 'gap';
136
+ });
137
+ // Transform Stack JSXElements
138
+ // Transform `<Stack shouldWrapChildren>` to `<Flex >`
139
+ root
140
+ .findJSXElements('Stack')
141
+ .find(j.JSXIdentifier)
142
+ .filter(function (path) { return path.node.name === 'shouldWrapChildren'; })
143
+ .remove();
144
+ // Transform Stack JSXElements
145
+ // Transform `<Stack>` to `<Flex>`
146
+ root.find(j.JSXIdentifier, { name: 'Stack' }).forEach(function (nodePath) {
147
+ nodePath.node.name = 'Flex';
148
+ });
149
+ // Transform Stack JSXElements
150
+ // e.g. `<HStack>` becomes `<Flex>`
151
+ root.find(j.JSXIdentifier, { name: 'HStack' }).forEach(function (nodePath) {
152
+ nodePath.node.name = 'Flex';
153
+ });
154
+ // Creating new JSXAttribute to push in attribute array for VStack
155
+ // Since we're replacing VStack with Flex, it will need a
156
+ // flexDirection="column" added
157
+ var newVStackProp = {
158
+ type: 'JSXAttribute',
159
+ name: { type: 'JSXIdentifier', name: 'flexDirection' },
160
+ value: { type: 'Literal', value: 'column' },
161
+ };
162
+ root
163
+ .find(j.JSXOpeningElement, { name: { type: 'JSXIdentifier', name: 'VStack' } })
164
+ .forEach(function (nodePath) {
165
+ var _a;
166
+ (_a = nodePath.node.attributes) === null || _a === void 0 ? void 0 : _a.push(newVStackProp);
167
+ });
168
+ // Transform VStack JSXElements
169
+ // e.g. `<VStack>` becomes `<Flex>`
170
+ root.find(j.JSXIdentifier, { name: 'VStack' }).forEach(function (nodePath) {
171
+ nodePath.node.name = 'Flex';
172
+ });
173
+ return root.toSource();
174
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"softDeprecateLayout.d.ts","sourceRoot":"","sources":["../../../lib/v8/softDeprecateLayout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAiC,OAAO,EAAC,MAAM,aAAa,CAAC;AAMlF,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UAwF7E"}
1
+ {"version":3,"file":"softDeprecateLayout.d.ts","sourceRoot":"","sources":["../../../lib/v8/softDeprecateLayout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAiC,OAAO,EAAC,MAAM,aAAa,CAAC;AAMlF,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UAkF7E"}
@@ -1,27 +1,20 @@
1
1
  var mainPackage = '@workday/canvas-kit-react';
2
- var layoutPackage = '@workday/canvas-kit-react/layout';
3
2
  var allImportNames = ['Layout', 'LayoutProps', 'Column', 'ColumnProps'];
3
+ var importPackages = [mainPackage, mainPackage + "/layout"];
4
4
  export default function transformer(file, api, options) {
5
5
  var j = api.jscodeshift;
6
6
  var root = j(file.source);
7
7
  var hasLayoutImports = false;
8
8
  // This toggles the failsafe that prevents us from accidentally transforming something unintentionally.
9
9
  root.find(j.ImportDeclaration, function (nodePath) {
10
- var value = nodePath.source.value;
11
- // If there's an import from the layout package, set the import boolean check to true
12
- if (value === layoutPackage) {
13
- hasLayoutImports = true;
14
- return false;
15
- }
16
- // If there's an import from the main package, check to see if Layout or LayoutProps are among the named imports
10
+ var _a;
11
+ // If there's an import from the layout package or an import from the main package,
12
+ // check to see if Layout or LayoutProps are among the named imports
17
13
  // e.g. import {Layout} from '@workday/canvas-kit-react';
18
- if (value === mainPackage) {
19
- (nodePath.specifiers || []).forEach(function (specifier) {
20
- if (specifier.type === 'ImportSpecifier') {
21
- if (allImportNames.includes(specifier.imported.name)) {
22
- hasLayoutImports = true;
23
- }
24
- }
14
+ if (importPackages.includes(nodePath.source.value)) {
15
+ (_a = nodePath.specifiers) === null || _a === void 0 ? void 0 : _a.forEach(function (specifier) {
16
+ hasLayoutImports =
17
+ specifier.type === 'ImportSpecifier' && allImportNames.includes(specifier.imported.name);
25
18
  });
26
19
  }
27
20
  return false;
@@ -37,11 +30,10 @@ export default function transformer(file, api, options) {
37
30
  .forEach(function (nodePath) {
38
31
  var _a;
39
32
  (_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.forEach(function (specifier) {
40
- if (specifier.type === 'ImportSpecifier') {
41
- // Adds Deprecated part to a import name for Layout, LayoutProps, Column, ColumnProps
42
- if (allImportNames.includes(specifier.imported.name)) {
43
- specifier.imported.name = "Deprecated" + specifier.imported.name;
44
- }
33
+ // Adds Deprecated part to a import name for Layout, LayoutProps, Column, ColumnProps
34
+ if (specifier.type === 'ImportSpecifier' &&
35
+ allImportNames.includes(specifier.imported.name)) {
36
+ specifier.imported.name = "Deprecated" + specifier.imported.name;
45
37
  }
46
38
  return specifier;
47
39
  });
package/index.js CHANGED
@@ -35,6 +35,13 @@ const {_: commands, path} = require('yargs')
35
35
  describe: chalk.gray('The path to execute the transform in (recursively).'),
36
36
  });
37
37
  })
38
+ .command('softDeprecate/Stack [path]', chalk.gray('Soft Deprecation of Stack transform'), yargs => {
39
+ yargs.positional('path', {
40
+ type: 'string',
41
+ default: '.',
42
+ describe: chalk.gray('The path to execute the transform in (recursively).'),
43
+ });
44
+ })
38
45
  .demandCommand(1, chalk.red.bold('You must provide a transform to apply.'))
39
46
  .strictCommands()
40
47
  .fail((msg, err, yargs) => {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@workday/canvas-kit-codemod",
3
3
  "author": "Workday, Inc. (https://www.workday.com)",
4
4
  "license": "Apache-2.0",
5
- "version": "8.4.0-296-next.0+d80ffb10",
5
+ "version": "8.4.0-303-next.2+ef9246fe",
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,
@@ -43,5 +43,5 @@
43
43
  "test": "TZ=UTC jest -c ../../jest.config.js",
44
44
  "typecheck:src": "tsc -p . --noEmit --incremental false"
45
45
  },
46
- "gitHead": "d80ffb10fc6fe6b613f1612865a0753dd886bf8b"
46
+ "gitHead": "ef9246fe888c63f6f2603ff35df3b6822d05baa1"
47
47
  }