@atlaskit/codemod-cli 0.29.2 → 0.31.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.
Files changed (29) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/cjs/main.js +1 -1
  3. package/dist/cjs/presets/index.js +3 -1
  4. package/dist/cjs/presets/lozenge-appearance-to-color/codemods/lozenge-appearance-to-color.js +138 -0
  5. package/dist/cjs/presets/lozenge-appearance-to-color/lozenge-appearance-to-color.js +44 -0
  6. package/dist/cjs/presets/lozenge-to-tag-migration/codemods/lozenge-to-tag-migration.js +253 -0
  7. package/dist/cjs/presets/lozenge-to-tag-migration/lozenge-to-tag-migration.js +44 -0
  8. package/dist/es2019/presets/index.js +3 -1
  9. package/dist/es2019/presets/lozenge-appearance-to-color/codemods/lozenge-appearance-to-color.js +137 -0
  10. package/dist/es2019/presets/lozenge-appearance-to-color/lozenge-appearance-to-color.js +18 -0
  11. package/dist/es2019/presets/lozenge-to-tag-migration/codemods/lozenge-to-tag-migration.js +242 -0
  12. package/dist/es2019/presets/lozenge-to-tag-migration/lozenge-to-tag-migration.js +18 -0
  13. package/dist/esm/main.js +1 -1
  14. package/dist/esm/presets/index.js +3 -1
  15. package/dist/esm/presets/lozenge-appearance-to-color/codemods/lozenge-appearance-to-color.js +132 -0
  16. package/dist/esm/presets/lozenge-appearance-to-color/lozenge-appearance-to-color.js +37 -0
  17. package/dist/esm/presets/lozenge-to-tag-migration/codemods/lozenge-to-tag-migration.js +247 -0
  18. package/dist/esm/presets/lozenge-to-tag-migration/lozenge-to-tag-migration.js +37 -0
  19. package/dist/types/presets/index.d.ts +2 -0
  20. package/dist/types/presets/lozenge-appearance-to-color/codemods/lozenge-appearance-to-color.d.ts +10 -0
  21. package/dist/types/presets/lozenge-appearance-to-color/lozenge-appearance-to-color.d.ts +2 -0
  22. package/dist/types/presets/lozenge-to-tag-migration/codemods/lozenge-to-tag-migration.d.ts +3 -0
  23. package/dist/types/presets/lozenge-to-tag-migration/lozenge-to-tag-migration.d.ts +2 -0
  24. package/dist/types-ts4.5/presets/index.d.ts +2 -0
  25. package/dist/types-ts4.5/presets/lozenge-appearance-to-color/codemods/lozenge-appearance-to-color.d.ts +10 -0
  26. package/dist/types-ts4.5/presets/lozenge-appearance-to-color/lozenge-appearance-to-color.d.ts +2 -0
  27. package/dist/types-ts4.5/presets/lozenge-to-tag-migration/codemods/lozenge-to-tag-migration.d.ts +3 -0
  28. package/dist/types-ts4.5/presets/lozenge-to-tag-migration/lozenge-to-tag-migration.d.ts +2 -0
  29. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @atlaskit/codemod-cli
2
2
 
3
+ ## 0.31.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`2b2b250287a95`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/2b2b250287a95) -
8
+ Add a new codemod `lozenge-to-tag-migration` to automatically migrate `isBold={false}` Lozenge
9
+ usages to Tag component as part of the Labelling System Phase 1 migration.
10
+
11
+ ## 0.30.0
12
+
13
+ ### Minor Changes
14
+
15
+ - [`1b338696ed4bd`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/1b338696ed4bd) -
16
+ Add a new codemod `lozenge-appearance-to-color` to migrate deprecated Lozenge appearances to
17
+ colors as part of the Labelling System Phase 1 migration.
18
+
3
19
  ## 0.29.2
4
20
 
5
21
  ### Patch Changes
package/dist/cjs/main.js CHANGED
@@ -362,7 +362,7 @@ function _main() {
362
362
  case 4:
363
363
  _yield$parseArgs = _context6.sent;
364
364
  packages = _yield$parseArgs.packages;
365
- _process$env$_PACKAGE = "0.29.1", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
365
+ _process$env$_PACKAGE = "0.30.0", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
366
366
  logger.log(_chalk.default.bgBlue(_chalk.default.black("\uD83D\uDCDA Atlassian-Frontend codemod library @ ".concat(_PACKAGE_VERSION_, " \uD83D\uDCDA"))));
367
367
  if (packages && packages.length > 0) {
368
368
  logger.log(_chalk.default.gray("Searching for codemods for newer versions of the following packages: ".concat(packages.map(function (pkg) {
@@ -14,12 +14,14 @@ require("./migrate-icon-object-to-object/migrate-icon-object-to-object");
14
14
  require("./upgrade-pragmatic-drag-and-drop-to-stable/upgrade-pragmatic-drag-and-drop-to-stable");
15
15
  require("./remove-dark-theme-vr-options/remove-dark-theme-vr-options");
16
16
  require("./remove-token-fallbacks/remove-token-fallbacks");
17
+ require("./lozenge-appearance-to-color/lozenge-appearance-to-color");
18
+ require("./lozenge-to-tag-migration/lozenge-to-tag-migration");
17
19
  /**
18
20
  * Manually import presets to make sure typescript includes them
19
21
  * in the final bundle.
20
22
  */
21
23
 
22
- var presets = ['styled-to-emotion', 'theme-remove-deprecated-mixins', 'migrate-to-link', 'migrate-to-new-buttons', 'migrate-icon-object-to-object', 'upgrade-pragmatic-drag-and-drop-to-stable', 'remove-dark-theme-vr-options', 'remove-token-fallbacks'].map(function (preset) {
24
+ var presets = ['styled-to-emotion', 'theme-remove-deprecated-mixins', 'migrate-to-link', 'migrate-to-new-buttons', 'migrate-icon-object-to-object', 'upgrade-pragmatic-drag-and-drop-to-stable', 'remove-dark-theme-vr-options', 'remove-token-fallbacks', 'lozenge-appearance-to-color', 'lozenge-to-tag-migration'].map(function (preset) {
23
25
  return _path.default.join(__dirname, preset, "".concat(preset, ".@(ts|js|tsx)"));
24
26
  });
25
27
  var _default = exports.default = presets;
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = transformer;
7
+ var _utils = require("@hypermod/utils");
8
+ var _codemodUtils = require("@atlaskit/codemod-utils");
9
+ var LOZENGE_ENTRY_POINT = '@atlaskit/lozenge';
10
+ var PRINT_SETTINGS = {
11
+ quote: 'single'
12
+ };
13
+
14
+ // Semantic appearance values that map directly to color values
15
+ var APPEARANCE_TO_COLOR_MAP = {
16
+ default: 'neutral',
17
+ inprogress: 'information',
18
+ moved: 'warning',
19
+ new: 'discovery',
20
+ removed: 'danger',
21
+ success: 'success'
22
+ };
23
+ /**
24
+ * Codemod to migrate Lozenge component from `appearance` prop to `color` prop.
25
+ *
26
+ * This codemod:
27
+ * 1. Renames `appearance` prop to `color` for semantic values
28
+ * 2. Maps existing semantic values directly (e.g. success → success)
29
+ * 3. Adds comments for dynamic values that need manual verification
30
+ */
31
+ function transformer(file, api) {
32
+ var j = api.jscodeshift;
33
+ var source = j(file.source);
34
+
35
+ // Find all Lozenge imports
36
+ var lozengeImports = (0, _utils.getImportDeclaration)(j, source, LOZENGE_ENTRY_POINT);
37
+
38
+ // If no Lozenge imports, exit early
39
+ if (!lozengeImports.length) {
40
+ return file.source;
41
+ }
42
+
43
+ // Get all imported Lozenge identifiers (could be renamed)
44
+ var lozengeIdentifiers = new Set();
45
+ lozengeImports.forEach(function (importPath) {
46
+ var _importPath$value$spe;
47
+ (_importPath$value$spe = importPath.value.specifiers) === null || _importPath$value$spe === void 0 || _importPath$value$spe.forEach(function (specifier) {
48
+ var _specifier$imported;
49
+ if (specifier.type === 'ImportDefaultSpecifier') {
50
+ var _specifier$local;
51
+ // Handle: import Lozenge from '@atlaskit/lozenge'
52
+ lozengeIdentifiers.add(((_specifier$local = specifier.local) === null || _specifier$local === void 0 ? void 0 : _specifier$local.name) || 'Lozenge');
53
+ } else if (specifier.type === 'ImportSpecifier' && ((_specifier$imported = specifier.imported) === null || _specifier$imported === void 0 ? void 0 : _specifier$imported.type) === 'Identifier' && specifier.imported.name === 'default') {
54
+ var _specifier$local2;
55
+ // Handle: import { default as Badge } from '@atlaskit/lozenge'
56
+ lozengeIdentifiers.add(((_specifier$local2 = specifier.local) === null || _specifier$local2 === void 0 ? void 0 : _specifier$local2.name) || 'Lozenge');
57
+ }
58
+ });
59
+ });
60
+
61
+ // If no Lozenge identifiers found, exit early
62
+ if (lozengeIdentifiers.size === 0) {
63
+ return file.source;
64
+ }
65
+
66
+ // Find all Lozenge JSX elements
67
+ var lozengeElements = [];
68
+ source.find(j.JSXElement).forEach(function (path) {
69
+ var _openingElement$name;
70
+ var openingElement = path.value.openingElement;
71
+ if (((_openingElement$name = openingElement.name) === null || _openingElement$name === void 0 ? void 0 : _openingElement$name.type) === 'JSXIdentifier' && lozengeIdentifiers.has(openingElement.name.name)) {
72
+ var _openingElement$attri;
73
+ var element = {
74
+ path: path,
75
+ hasAppearanceProp: false
76
+ };
77
+
78
+ // Check for appearance prop
79
+ (_openingElement$attri = openingElement.attributes) === null || _openingElement$attri === void 0 || _openingElement$attri.forEach(function (attr) {
80
+ var _attr$name;
81
+ if (attr.type === 'JSXAttribute' && ((_attr$name = attr.name) === null || _attr$name === void 0 ? void 0 : _attr$name.type) === 'JSXIdentifier') {
82
+ if (attr.name.name === 'appearance') {
83
+ var _attr$value, _attr$value2;
84
+ element.hasAppearanceProp = true;
85
+ if (((_attr$value = attr.value) === null || _attr$value === void 0 ? void 0 : _attr$value.type) === 'StringLiteral') {
86
+ element.appearanceValue = attr.value.value;
87
+ } else if (((_attr$value2 = attr.value) === null || _attr$value2 === void 0 ? void 0 : _attr$value2.type) === 'JSXExpressionContainer') {
88
+ // Handle dynamic values
89
+ var expression = attr.value.expression;
90
+ if (expression.type === 'StringLiteral') {
91
+ element.appearanceValue = expression.value;
92
+ } else {
93
+ element.appearanceValue = 'dynamic';
94
+ }
95
+ }
96
+ }
97
+ }
98
+ });
99
+ lozengeElements.push(element);
100
+ }
101
+ });
102
+
103
+ // Process each Lozenge element
104
+ lozengeElements.forEach(function (element) {
105
+ var path = element.path,
106
+ hasAppearanceProp = element.hasAppearanceProp,
107
+ appearanceValue = element.appearanceValue;
108
+ var openingElement = path.value.openingElement;
109
+
110
+ // Transform appearance prop to color prop
111
+ if (hasAppearanceProp) {
112
+ var _openingElement$attri2;
113
+ (_openingElement$attri2 = openingElement.attributes) === null || _openingElement$attri2 === void 0 || _openingElement$attri2.forEach(function (attr) {
114
+ var _attr$name2;
115
+ if (attr.type === 'JSXAttribute' && ((_attr$name2 = attr.name) === null || _attr$name2 === void 0 ? void 0 : _attr$name2.type) === 'JSXIdentifier' && attr.name.name === 'appearance') {
116
+ // Rename appearance to color
117
+ attr.name.name = 'color';
118
+
119
+ // Handle different types of appearance values
120
+ if (appearanceValue === 'dynamic') {
121
+ // For dynamic values, add a comment
122
+ (0, _codemodUtils.addCommentBefore)(j, j(path), "FIXME: This Lozenge component uses a dynamic `appearance` prop that has been renamed to `color`.\nPlease verify that the values being passed are valid color values (semantic: default, inprogress, moved, new, removed, success).");
123
+ } else if (appearanceValue && !APPEARANCE_TO_COLOR_MAP[appearanceValue]) {
124
+ // For invalid string values, add a warning comment
125
+ (0, _codemodUtils.addCommentBefore)(j, j(path), "FIXME: This Lozenge component uses an invalid `appearance` value \"".concat(appearanceValue, "\" that has been renamed to `color`.\nValid semantic color values are: ").concat(Object.keys(APPEARANCE_TO_COLOR_MAP).join(', '), ".\nPlease update this value to a valid semantic color or use a custom color value."));
126
+ } else if (appearanceValue && APPEARANCE_TO_COLOR_MAP[appearanceValue]) {
127
+ var _attr$value3;
128
+ // For valid string values, update the value to the mapped color
129
+ if (((_attr$value3 = attr.value) === null || _attr$value3 === void 0 ? void 0 : _attr$value3.type) === 'StringLiteral') {
130
+ attr.value.value = APPEARANCE_TO_COLOR_MAP[appearanceValue];
131
+ }
132
+ }
133
+ }
134
+ });
135
+ }
136
+ });
137
+ return source.toSource(PRINT_SETTINGS);
138
+ }
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = transformer;
8
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
11
+ var _lozengeAppearanceToColor = _interopRequireDefault(require("./codemods/lozenge-appearance-to-color"));
12
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
13
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
14
+ function transformer(_x, _x2) {
15
+ return _transformer.apply(this, arguments);
16
+ }
17
+ function _transformer() {
18
+ _transformer = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(file, api) {
19
+ var transformers, src;
20
+ return _regenerator.default.wrap(function _callee$(_context) {
21
+ while (1) switch (_context.prev = _context.next) {
22
+ case 0:
23
+ transformers = [_lozengeAppearanceToColor.default];
24
+ src = file.source;
25
+ transformers.forEach(function (transformer) {
26
+ if (typeof src === 'undefined') {
27
+ return;
28
+ }
29
+ var nextSrc = transformer(_objectSpread(_objectSpread({}, file), {}, {
30
+ source: src
31
+ }), api);
32
+ if (nextSrc) {
33
+ src = nextSrc;
34
+ }
35
+ });
36
+ return _context.abrupt("return", src);
37
+ case 4:
38
+ case "end":
39
+ return _context.stop();
40
+ }
41
+ }, _callee);
42
+ }));
43
+ return _transformer.apply(this, arguments);
44
+ }
@@ -0,0 +1,253 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _codemodUtils = require("@atlaskit/codemod-utils");
8
+ var transformer = function transformer(file, api) {
9
+ var j = api.jscodeshift;
10
+ var source = j(file.source);
11
+
12
+ // Check if file has Lozenge imports
13
+ var lozengeImports = source.find(j.ImportDeclaration).filter(function (path) {
14
+ return path.node.source.value === '@atlaskit/lozenge';
15
+ });
16
+ if (lozengeImports.length === 0) {
17
+ return file.source;
18
+ }
19
+
20
+ // Get the import name for Lozenge (could be renamed)
21
+ var lozengeImportName = 'Lozenge';
22
+ lozengeImports.forEach(function (importPath) {
23
+ var _importPath$node$spec;
24
+ (_importPath$node$spec = importPath.node.specifiers) === null || _importPath$node$spec === void 0 || _importPath$node$spec.forEach(function (specifier) {
25
+ if (j.ImportDefaultSpecifier.check(specifier)) {
26
+ var _specifier$local;
27
+ lozengeImportName = ((_specifier$local = specifier.local) === null || _specifier$local === void 0 ? void 0 : _specifier$local.name) || 'Lozenge';
28
+ } else if (j.ImportSpecifier.check(specifier)) {
29
+ // Handle { default as Badge } syntax
30
+ if (j.Identifier.check(specifier.imported) && specifier.imported.name === 'default') {
31
+ var _specifier$local2;
32
+ lozengeImportName = ((_specifier$local2 = specifier.local) === null || _specifier$local2 === void 0 ? void 0 : _specifier$local2.name) || 'Lozenge';
33
+ }
34
+ }
35
+ });
36
+ });
37
+
38
+ // Appearance to color mapping
39
+ var appearanceToColorMap = {
40
+ success: 'lime',
41
+ default: 'standard',
42
+ removed: 'red',
43
+ inprogress: 'blue',
44
+ new: 'purple',
45
+ moved: 'orange'
46
+ };
47
+ var hasTransformed = false;
48
+
49
+ // Find and transform Lozenge elements
50
+ source.find(j.JSXElement).forEach(function (elementPath) {
51
+ var _element$openingEleme, _element$openingEleme2;
52
+ var element = elementPath.node;
53
+ if (!j.JSXIdentifier.check(element.openingElement.name)) {
54
+ return;
55
+ }
56
+ if (element.openingElement.name.name !== lozengeImportName) {
57
+ return;
58
+ }
59
+
60
+ // Check isBold attribute
61
+ var isBoldAttr = (_element$openingEleme = element.openingElement.attributes) === null || _element$openingEleme === void 0 ? void 0 : _element$openingEleme.find(function (attr) {
62
+ return j.JSXAttribute.check(attr) && j.JSXIdentifier.check(attr.name) && attr.name.name === 'isBold';
63
+ });
64
+
65
+ // Don't transform if isBold is true or boolean prop without value
66
+ if (isBoldAttr) {
67
+ if (j.JSXExpressionContainer.check(isBoldAttr.value)) {
68
+ var expression = isBoldAttr.value.expression;
69
+
70
+ // If it's a boolean literal true, don't transform
71
+ if (j.BooleanLiteral.check(expression) && expression.value === true) {
72
+ return;
73
+ }
74
+
75
+ // If it's a boolean literal false, we can transform
76
+ if (j.BooleanLiteral.check(expression) && expression.value === false) {
77
+ // Continue with transformation
78
+ } else {
79
+ // If it's not a boolean literal (dynamic value), add warning and don't transform
80
+ (0, _codemodUtils.addCommentBefore)(j, j(elementPath), "FIXME: This Lozenge component uses a dynamic `isBold` prop. Please manually review if this should be migrated to Tag component.\nIf isBold is typically false, consider migrating to <Tag /> from '@atlaskit/tag'.");
81
+ return;
82
+ }
83
+ } else if (!isBoldAttr.value) {
84
+ // isBold prop without value (boolean shorthand) means true, don't transform
85
+ return;
86
+ }
87
+ }
88
+
89
+ // Create new Tag element
90
+ var newAttributes = [];
91
+ var otherAttributes = [];
92
+ var colorAttribute = null;
93
+ var textContent = '';
94
+ var hasComplexChildren = false;
95
+ var hasStyleProp = false;
96
+ var hasMaxWidthProp = false;
97
+ var hasUnknownAppearance = false;
98
+ var dynamicAppearance = false;
99
+ var unknownAppearanceValue = '';
100
+
101
+ // Process children to extract text
102
+ if (element.children && element.children.length > 0) {
103
+ if (element.children.length === 1) {
104
+ var child = element.children[0];
105
+ if (j.JSXText.check(child)) {
106
+ var text = child.value.trim();
107
+ if (text) {
108
+ textContent = text;
109
+ }
110
+ } else if (j.JSXExpressionContainer.check(child) && j.StringLiteral.check(child.expression)) {
111
+ textContent = child.expression.value;
112
+ } else {
113
+ hasComplexChildren = true;
114
+ }
115
+ } else {
116
+ // Multiple children or complex structure
117
+ hasComplexChildren = true;
118
+ }
119
+ }
120
+
121
+ // Process attributes
122
+ (_element$openingEleme2 = element.openingElement.attributes) === null || _element$openingEleme2 === void 0 || _element$openingEleme2.forEach(function (attr) {
123
+ if (!j.JSXAttribute.check(attr) || !j.JSXIdentifier.check(attr.name)) {
124
+ return;
125
+ }
126
+ var attrName = attr.name.name;
127
+ switch (attrName) {
128
+ case 'appearance':
129
+ var colorValue = 'standard';
130
+ if (j.StringLiteral.check(attr.value)) {
131
+ var appearanceValue = attr.value.value;
132
+ colorValue = appearanceToColorMap[appearanceValue] || appearanceValue;
133
+ if (!appearanceToColorMap[appearanceValue]) {
134
+ hasUnknownAppearance = true;
135
+ unknownAppearanceValue = appearanceValue;
136
+ }
137
+ } else if (j.JSXExpressionContainer.check(attr.value)) {
138
+ // Dynamic appearance
139
+ dynamicAppearance = true;
140
+ colorValue = attr.value;
141
+ }
142
+ colorAttribute = j.jsxAttribute(j.jsxIdentifier('color'), typeof colorValue === 'string' ? j.stringLiteral(colorValue) : colorValue);
143
+ break;
144
+ case 'isBold':
145
+ // Skip isBold, already handled above
146
+ break;
147
+ case 'maxWidth':
148
+ hasMaxWidthProp = true;
149
+ break;
150
+ case 'style':
151
+ hasStyleProp = true;
152
+ otherAttributes.push(attr);
153
+ break;
154
+ default:
155
+ // Keep other attributes (testId, etc.)
156
+ otherAttributes.push(attr);
157
+ break;
158
+ }
159
+ });
160
+
161
+ // Assemble attributes in correct order: text, other props, color
162
+ if (textContent && !hasComplexChildren) {
163
+ newAttributes.push(j.jsxAttribute(j.jsxIdentifier('text'), j.stringLiteral(textContent)));
164
+ }
165
+
166
+ // Add other attributes
167
+ newAttributes.push.apply(newAttributes, otherAttributes);
168
+
169
+ // Add color attribute last (default to 'standard' if no appearance was found)
170
+ if (colorAttribute) {
171
+ newAttributes.push(colorAttribute);
172
+ } else {
173
+ // Default color when no appearance is specified
174
+ newAttributes.push(j.jsxAttribute(j.jsxIdentifier('color'), j.stringLiteral('standard')));
175
+ }
176
+
177
+ // Create new Tag element
178
+ var newElement = j.jsxElement(j.jsxOpeningElement(j.jsxIdentifier('Tag'), newAttributes, true), null, []);
179
+
180
+ // Add warning comments as needed
181
+ var warnings = [];
182
+ if (hasComplexChildren) {
183
+ warnings.push("FIXME: This Tag component has complex children that couldn't be automatically migrated to the text prop.\nTag component only supports simple text via the text prop. Please manually convert the children content.");
184
+ }
185
+ if (hasMaxWidthProp) {
186
+ warnings.push('FIXME: maxWidth prop was removed during migration from Lozenge to Tag.\nTag component does not support maxWidth. Please review if width constraints are needed.');
187
+ }
188
+ if (hasStyleProp) {
189
+ warnings.push('FIXME: This Tag component has a style prop that was kept during migration.\nTag component has limited style support. Please review if custom styles are compatible.');
190
+ }
191
+ if (hasUnknownAppearance) {
192
+ warnings.push("FIXME: This Tag component uses an unknown appearance value \"".concat(unknownAppearanceValue, "\".\nPlease update to a valid Tag color: standard, green, lime, blue, red, purple, magenta, grey, teal, orange, yellow."));
193
+ }
194
+ if (dynamicAppearance) {
195
+ warnings.push('FIXME: This Tag component uses a dynamic `appearance` prop that has been renamed to `color`.\nPlease verify that the values being passed are valid color values (semantic: default, inprogress, moved, new, removed, success).');
196
+ }
197
+
198
+ // Replace the element first
199
+ elementPath.replace(newElement);
200
+
201
+ // Add warning comments using addCommentBefore if needed
202
+ if (warnings.length > 0) {
203
+ var commentText = warnings.join('\n');
204
+ (0, _codemodUtils.addCommentBefore)(j, j(elementPath), commentText);
205
+ }
206
+ hasTransformed = true;
207
+ });
208
+
209
+ // Add Tag import if we transformed any elements
210
+ if (hasTransformed) {
211
+ // Check if Tag import already exists
212
+ var tagImports = source.find(j.ImportDeclaration).filter(function (path) {
213
+ return path.node.source.value === '@atlaskit/tag';
214
+ });
215
+ if (tagImports.length === 0) {
216
+ // Add Tag import after Lozenge import
217
+ var lozengeImportPath = lozengeImports.at(0);
218
+ var tagImport = j.importDeclaration([j.importDefaultSpecifier(j.identifier('Tag'))], j.stringLiteral('@atlaskit/tag'));
219
+ lozengeImportPath.insertAfter(tagImport);
220
+ }
221
+
222
+ // Check if there are any remaining Lozenge usages
223
+ var remainingLozengeUsages = source.find(j.JSXElement).filter(function (elementPath) {
224
+ var element = elementPath.node;
225
+ if (!j.JSXIdentifier.check(element.openingElement.name)) {
226
+ return false;
227
+ }
228
+ return element.openingElement.name.name === lozengeImportName;
229
+ });
230
+
231
+ // Also check for other usages like function calls, type references, etc.
232
+ var remainingLozengeReferences = source.find(j.Identifier).filter(function (identifierPath) {
233
+ // Skip JSX element names as they're already checked above
234
+ if (j.JSXElement.check(identifierPath.parent.node) || j.JSXOpeningElement.check(identifierPath.parent.node) || j.JSXClosingElement.check(identifierPath.parent.node)) {
235
+ return false;
236
+ }
237
+
238
+ // Skip import declaration identifiers
239
+ if (j.ImportDeclaration.check(identifierPath.parent.node) || j.ImportDefaultSpecifier.check(identifierPath.parent.node) || j.ImportSpecifier.check(identifierPath.parent.node)) {
240
+ return false;
241
+ }
242
+ return identifierPath.node.name === lozengeImportName;
243
+ });
244
+
245
+ // If no remaining usages, remove the Lozenge import
246
+ if (remainingLozengeUsages.length === 0 && remainingLozengeReferences.length === 0) {
247
+ lozengeImports.remove();
248
+ }
249
+ return source.toSource();
250
+ }
251
+ return source.toSource();
252
+ };
253
+ var _default = exports.default = transformer;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = transformer;
8
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
11
+ var _lozengeToTagMigration = _interopRequireDefault(require("./codemods/lozenge-to-tag-migration"));
12
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
13
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
14
+ function transformer(_x, _x2) {
15
+ return _transformer.apply(this, arguments);
16
+ }
17
+ function _transformer() {
18
+ _transformer = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(file, api) {
19
+ var transformers, src;
20
+ return _regenerator.default.wrap(function _callee$(_context) {
21
+ while (1) switch (_context.prev = _context.next) {
22
+ case 0:
23
+ transformers = [_lozengeToTagMigration.default];
24
+ src = file.source;
25
+ transformers.forEach(function (transformer) {
26
+ if (typeof src === 'undefined') {
27
+ return;
28
+ }
29
+ var nextSrc = transformer(_objectSpread(_objectSpread({}, file), {}, {
30
+ source: src
31
+ }), api);
32
+ if (nextSrc) {
33
+ src = nextSrc;
34
+ }
35
+ });
36
+ return _context.abrupt("return", src);
37
+ case 4:
38
+ case "end":
39
+ return _context.stop();
40
+ }
41
+ }, _callee);
42
+ }));
43
+ return _transformer.apply(this, arguments);
44
+ }
@@ -12,5 +12,7 @@ import './migrate-icon-object-to-object/migrate-icon-object-to-object';
12
12
  import './upgrade-pragmatic-drag-and-drop-to-stable/upgrade-pragmatic-drag-and-drop-to-stable';
13
13
  import './remove-dark-theme-vr-options/remove-dark-theme-vr-options';
14
14
  import './remove-token-fallbacks/remove-token-fallbacks';
15
- const presets = ['styled-to-emotion', 'theme-remove-deprecated-mixins', 'migrate-to-link', 'migrate-to-new-buttons', 'migrate-icon-object-to-object', 'upgrade-pragmatic-drag-and-drop-to-stable', 'remove-dark-theme-vr-options', 'remove-token-fallbacks'].map(preset => path.join(__dirname, preset, `${preset}.@(ts|js|tsx)`));
15
+ import './lozenge-appearance-to-color/lozenge-appearance-to-color';
16
+ import './lozenge-to-tag-migration/lozenge-to-tag-migration';
17
+ const presets = ['styled-to-emotion', 'theme-remove-deprecated-mixins', 'migrate-to-link', 'migrate-to-new-buttons', 'migrate-icon-object-to-object', 'upgrade-pragmatic-drag-and-drop-to-stable', 'remove-dark-theme-vr-options', 'remove-token-fallbacks', 'lozenge-appearance-to-color', 'lozenge-to-tag-migration'].map(preset => path.join(__dirname, preset, `${preset}.@(ts|js|tsx)`));
16
18
  export default presets;