@atlaskit/codemod-cli 0.32.1 → 0.33.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 (24) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/cjs/main.js +2 -2
  3. package/dist/cjs/presets/index.js +2 -1
  4. package/dist/cjs/presets/remove-token-fallbacks/utils/token-processor.js +1 -1
  5. package/dist/cjs/presets/tag-to-newTag-migration/codemods/tag-to-newTag-migration.js +388 -0
  6. package/dist/cjs/presets/tag-to-newTag-migration/tag-to-newTag-migration.js +44 -0
  7. package/dist/es2019/main.js +1 -1
  8. package/dist/es2019/presets/index.js +2 -1
  9. package/dist/es2019/presets/remove-token-fallbacks/utils/token-processor.js +1 -1
  10. package/dist/es2019/presets/tag-to-newTag-migration/codemods/tag-to-newTag-migration.js +373 -0
  11. package/dist/es2019/presets/tag-to-newTag-migration/tag-to-newTag-migration.js +18 -0
  12. package/dist/es2019/sinceRef.js +1 -1
  13. package/dist/esm/main.js +2 -2
  14. package/dist/esm/presets/index.js +2 -1
  15. package/dist/esm/presets/remove-token-fallbacks/utils/token-processor.js +1 -1
  16. package/dist/esm/presets/tag-to-newTag-migration/codemods/tag-to-newTag-migration.js +381 -0
  17. package/dist/esm/presets/tag-to-newTag-migration/tag-to-newTag-migration.js +37 -0
  18. package/dist/types/presets/index.d.ts +1 -0
  19. package/dist/types/presets/tag-to-newTag-migration/codemods/tag-to-newTag-migration.d.ts +20 -0
  20. package/dist/types/presets/tag-to-newTag-migration/tag-to-newTag-migration.d.ts +2 -0
  21. package/dist/types-ts4.5/presets/index.d.ts +1 -0
  22. package/dist/types-ts4.5/presets/tag-to-newTag-migration/codemods/tag-to-newTag-migration.d.ts +20 -0
  23. package/dist/types-ts4.5/presets/tag-to-newTag-migration/tag-to-newTag-migration.d.ts +2 -0
  24. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # @atlaskit/codemod-cli
2
2
 
3
+ ## 0.33.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`ddad767837bd1`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/ddad767837bd1) -
8
+ [ux] Add a new codemod `tag-to-newTag-migration` to migrate deprecated Tag to new Tag appearance
9
+ and API or PeopleTag as part of the Labelling System Phase 1 migration.
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies
14
+
15
+ ## 0.32.2
16
+
17
+ ### Patch Changes
18
+
19
+ - [`a60a82196851a`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/a60a82196851a) -
20
+ Internal refactors to remove unused variables. No functional or public changes.
21
+ - Updated dependencies
22
+
3
23
  ## 0.32.1
4
24
 
5
25
  ### Patch Changes
package/dist/cjs/main.js CHANGED
@@ -186,7 +186,7 @@ var runTransform = /*#__PURE__*/function () {
186
186
  _fs.default.writeFileSync(jscodeshift, jscodeshiftContentNew);
187
187
  try {
188
188
  transformModule = require(transformPath);
189
- } catch (error) {
189
+ } catch (_unused) {
190
190
  // eslint-disable-next-line no-console
191
191
  console.warn("Error loading transform module: ".concat(transformPath, ". Skipping lifecycle hooks."));
192
192
  }
@@ -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.0.0-development", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
365
+ _process$env$_PACKAGE = "0.33.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) {
@@ -17,12 +17,13 @@ require("./remove-token-fallbacks/remove-token-fallbacks");
17
17
  require("./lozenge-appearance-semantic-migration/lozenge-appearance-semantic-migration");
18
18
  require("./lozenge-to-tag-migration/lozenge-to-tag-migration");
19
19
  require("./badge-appearance-semantic-migration/badge-appearance-semantic-migration");
20
+ require("./tag-to-newTag-migration/tag-to-newTag-migration");
20
21
  /**
21
22
  * Manually import presets to make sure typescript includes them
22
23
  * in the final bundle.
23
24
  */
24
25
 
25
- 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-semantic-migration', 'lozenge-to-tag-migration', 'badge-appearance-semantic-migration'].map(function (preset) {
26
+ 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-semantic-migration', 'lozenge-to-tag-migration', 'badge-appearance-semantic-migration', 'tag-to-newTag-migration'].map(function (preset) {
26
27
  return _path.default.join(__dirname, preset, "".concat(preset, ".@(ts|js|tsx)"));
27
28
  });
28
29
  var _default = exports.default = presets;
@@ -601,7 +601,7 @@ var TokenProcessor = exports.TokenProcessor = /*#__PURE__*/function () {
601
601
  });
602
602
  this.logVerbose("Resolved module path: ".concat(_chalk.default.green(resolvedPath), " for ").concat(_chalk.default.cyan(moduleName)));
603
603
  return resolvedPath;
604
- } catch (error) {
604
+ } catch (_unused) {
605
605
  return null;
606
606
  }
607
607
  }
@@ -0,0 +1,388 @@
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 _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
+ var _utils = require("@hypermod/utils");
10
+ var TAG_ENTRY_POINT = '@atlaskit/tag';
11
+ var TAG_REMOVABLE_ENTRY_POINT = '@atlaskit/tag/removable-tag';
12
+ var TAG_SIMPLE_ENTRY_POINT = '@atlaskit/tag/simple-tag';
13
+ var AVATAR_ENTRY_POINT = '@atlaskit/avatar';
14
+ var PRINT_SETTINGS = {
15
+ quote: 'single'
16
+ };
17
+
18
+ // Color mapping from Light versions to non-light versions
19
+ var COLOR_MAP = {
20
+ limeLight: 'lime',
21
+ orangeLight: 'orange',
22
+ magentaLight: 'magenta',
23
+ greenLight: 'green',
24
+ blueLight: 'blue',
25
+ redLight: 'red',
26
+ purpleLight: 'purple',
27
+ greyLight: 'gray',
28
+ // Note: grey -> gray spelling change
29
+ tealLight: 'teal',
30
+ yellowLight: 'yellow',
31
+ grey: 'gray' // Also handle non-light grey -> gray
32
+ };
33
+
34
+ // Valid target color values that don't need migration
35
+ var VALID_COLORS = new Set(['lime', 'orange', 'magenta', 'green', 'blue', 'red', 'purple', 'gray', 'teal', 'yellow', 'standard']);
36
+ /**
37
+ * Check if a JSX expression is an Avatar component from '@atlaskit/avatar'
38
+ */
39
+ function isAvatarComponent(expression) {
40
+ // Handle <Avatar ... />
41
+ if (expression.type === 'JSXElement') {
42
+ var _openingElement$name;
43
+ var openingElement = expression.openingElement;
44
+ if (((_openingElement$name = openingElement.name) === null || _openingElement$name === void 0 ? void 0 : _openingElement$name.type) === 'JSXIdentifier') {
45
+ return openingElement.name.name === 'Avatar';
46
+ }
47
+ }
48
+ return false;
49
+ }
50
+
51
+ /**
52
+ * Check if elemBefore contains only an Avatar component (directly or via render props)
53
+ */
54
+ function hasOnlyAvatarInElemBefore(attr) {
55
+ var _attr$value;
56
+ if (((_attr$value = attr.value) === null || _attr$value === void 0 ? void 0 : _attr$value.type) === 'JSXExpressionContainer') {
57
+ var expression = attr.value.expression;
58
+
59
+ // Direct Avatar: elemBefore={<Avatar />}
60
+ if (isAvatarComponent(expression)) {
61
+ return {
62
+ isAvatar: true,
63
+ avatarJSX: expression
64
+ };
65
+ }
66
+
67
+ // Render props: elemBefore={(props) => <Avatar {...props} />}
68
+ if ((expression.type === 'ArrowFunctionExpression' || expression.type === 'FunctionExpression') && expression.body) {
69
+ // Check if the function body is an Avatar component
70
+ var body = expression.body;
71
+ if (isAvatarComponent(body)) {
72
+ return {
73
+ isAvatar: true,
74
+ avatarJSX: body
75
+ };
76
+ }
77
+ }
78
+ }
79
+ return {
80
+ isAvatar: false
81
+ };
82
+ }
83
+
84
+ /**
85
+ * Extract string value from a JSX attribute value
86
+ */
87
+ function extractStringValue(attrValue) {
88
+ if (!attrValue) {
89
+ return null;
90
+ }
91
+ if (attrValue.type === 'StringLiteral') {
92
+ return attrValue.value;
93
+ }
94
+ if (attrValue.type === 'JSXExpressionContainer') {
95
+ var expression = attrValue.expression;
96
+ if (expression.type === 'StringLiteral') {
97
+ return expression.value;
98
+ }
99
+ }
100
+ return null;
101
+ }
102
+
103
+ /**
104
+ * Find an attribute by name in the attributes array
105
+ */
106
+ function findAttribute(attributes, attrName) {
107
+ return attributes === null || attributes === void 0 ? void 0 : attributes.find(function (attr) {
108
+ var _attr$name;
109
+ return attr.type === 'JSXAttribute' && ((_attr$name = attr.name) === null || _attr$name === void 0 ? void 0 : _attr$name.type) === 'JSXIdentifier' && attr.name.name === attrName;
110
+ });
111
+ }
112
+
113
+ /**
114
+ * Codemod to migrate Tag components to new Tag/AvatarTag API.
115
+ *
116
+ * This codemod:
117
+ * 1. Identifies all Tag imports from various entry points
118
+ * 2. For tags with elemBefore containing only Avatar:
119
+ * - Migrates to AvatarTag from '@atlaskit/tag'
120
+ * - Renames elemBefore to avatar
121
+ * - Converts avatar to render props function
122
+ * - Removes color prop
123
+ * - Adds isRemovable={false} if original was SimpleTag
124
+ * 3. For other tags:
125
+ * - Migrates to default import from '@atlaskit/tag'
126
+ * - Removes appearance prop
127
+ * - Migrates color values using COLOR_MAP
128
+ * - Adds isRemovable={false} if original was SimpleTag
129
+ * - Adds comment for manual migration if color can't be mapped
130
+ */
131
+ function transformer(file, api) {
132
+ var j = api.jscodeshift;
133
+ var source = j(file.source);
134
+
135
+ // Track all Tag identifiers and whether they were SimpleTag
136
+ var tagIdentifiers = new Map();
137
+
138
+ // Find all Tag imports from main entry point
139
+ var mainTagImports = (0, _utils.getImportDeclaration)(j, source, TAG_ENTRY_POINT);
140
+ mainTagImports.forEach(function (importPath) {
141
+ var _importPath$value$spe;
142
+ (_importPath$value$spe = importPath.value.specifiers) === null || _importPath$value$spe === void 0 || _importPath$value$spe.forEach(function (specifier) {
143
+ var _specifier$imported;
144
+ if (specifier.type === 'ImportDefaultSpecifier') {
145
+ var _specifier$local, _specifier$local2;
146
+ // import Tag from '@atlaskit/tag' -> RemovableTag (default)
147
+ tagIdentifiers.set(((_specifier$local = specifier.local) === null || _specifier$local === void 0 ? void 0 : _specifier$local.name) || 'Tag', {
148
+ localName: ((_specifier$local2 = specifier.local) === null || _specifier$local2 === void 0 ? void 0 : _specifier$local2.name) || 'Tag',
149
+ isSimpleTag: false
150
+ });
151
+ } else if (specifier.type === 'ImportSpecifier' && ((_specifier$imported = specifier.imported) === null || _specifier$imported === void 0 ? void 0 : _specifier$imported.type) === 'Identifier') {
152
+ var _specifier$local3;
153
+ var localName = ((_specifier$local3 = specifier.local) === null || _specifier$local3 === void 0 ? void 0 : _specifier$local3.name) || specifier.imported.name;
154
+ if (specifier.imported.name === 'SimpleTag') {
155
+ // import { SimpleTag } from '@atlaskit/tag'
156
+ tagIdentifiers.set(localName, {
157
+ localName: localName,
158
+ isSimpleTag: true
159
+ });
160
+ } else if (specifier.imported.name === 'RemovableTag') {
161
+ // import { RemovableTag } from '@atlaskit/tag'
162
+ tagIdentifiers.set(localName, {
163
+ localName: localName,
164
+ isSimpleTag: false
165
+ });
166
+ }
167
+ }
168
+ });
169
+ });
170
+
171
+ // Find imports from removable-tag entry point
172
+ var removableTagImports = (0, _utils.getImportDeclaration)(j, source, TAG_REMOVABLE_ENTRY_POINT);
173
+ removableTagImports.forEach(function (importPath) {
174
+ var _importPath$value$spe2;
175
+ (_importPath$value$spe2 = importPath.value.specifiers) === null || _importPath$value$spe2 === void 0 || _importPath$value$spe2.forEach(function (specifier) {
176
+ if (specifier.type === 'ImportDefaultSpecifier') {
177
+ var _specifier$local4, _specifier$local5;
178
+ // import RemovableTag from '@atlaskit/tag/removable-tag'
179
+ tagIdentifiers.set(((_specifier$local4 = specifier.local) === null || _specifier$local4 === void 0 ? void 0 : _specifier$local4.name) || 'RemovableTag', {
180
+ localName: ((_specifier$local5 = specifier.local) === null || _specifier$local5 === void 0 ? void 0 : _specifier$local5.name) || 'RemovableTag',
181
+ isSimpleTag: false
182
+ });
183
+ }
184
+ });
185
+ });
186
+
187
+ // Find imports from simple-tag entry point
188
+ var simpleTagImports = (0, _utils.getImportDeclaration)(j, source, TAG_SIMPLE_ENTRY_POINT);
189
+ simpleTagImports.forEach(function (importPath) {
190
+ var _importPath$value$spe3;
191
+ (_importPath$value$spe3 = importPath.value.specifiers) === null || _importPath$value$spe3 === void 0 || _importPath$value$spe3.forEach(function (specifier) {
192
+ if (specifier.type === 'ImportDefaultSpecifier') {
193
+ var _specifier$local6, _specifier$local7;
194
+ // import SimpleTag from '@atlaskit/tag/simple-tag'
195
+ tagIdentifiers.set(((_specifier$local6 = specifier.local) === null || _specifier$local6 === void 0 ? void 0 : _specifier$local6.name) || 'SimpleTag', {
196
+ localName: ((_specifier$local7 = specifier.local) === null || _specifier$local7 === void 0 ? void 0 : _specifier$local7.name) || 'SimpleTag',
197
+ isSimpleTag: true
198
+ });
199
+ }
200
+ });
201
+ });
202
+
203
+ // If no Tag imports found, exit early
204
+ if (tagIdentifiers.size === 0) {
205
+ return file.source;
206
+ }
207
+
208
+ // Check if Avatar is imported
209
+ var avatarImports = (0, _utils.getImportDeclaration)(j, source, AVATAR_ENTRY_POINT);
210
+ var hasAvatarImport = avatarImports.length > 0;
211
+
212
+ // Track which tags need AvatarTag vs regular Tag
213
+ var tagsToMigrateToAvatarTag = new Set();
214
+ var tagsNeedingManualMigration = new Set();
215
+ var hasRegularTagUsage = false; // Track if any tag remains as regular Tag
216
+
217
+ // Find and process all Tag JSX elements
218
+ source.find(j.JSXElement).forEach(function (path) {
219
+ var _openingElement$name2;
220
+ var openingElement = path.value.openingElement;
221
+ if (((_openingElement$name2 = openingElement.name) === null || _openingElement$name2 === void 0 ? void 0 : _openingElement$name2.type) === 'JSXIdentifier' && tagIdentifiers.has(openingElement.name.name)) {
222
+ var componentName = openingElement.name.name;
223
+ var tagInfo = tagIdentifiers.get(componentName);
224
+ var attributes = openingElement.attributes || [];
225
+
226
+ // Check for elemBefore with Avatar
227
+ var elemBeforeAttr = findAttribute(attributes, 'elemBefore');
228
+ var colorAttr = findAttribute(attributes, 'color');
229
+ var shouldMigrateToAvatarTag = false;
230
+ if (elemBeforeAttr && hasAvatarImport) {
231
+ var _hasOnlyAvatarInElemB = hasOnlyAvatarInElemBefore(elemBeforeAttr),
232
+ isAvatar = _hasOnlyAvatarInElemB.isAvatar,
233
+ avatarJSX = _hasOnlyAvatarInElemB.avatarJSX;
234
+ if (isAvatar && avatarJSX) {
235
+ var _path$value$closingEl, _elemBeforeAttr$name, _elemBeforeAttr$value;
236
+ shouldMigrateToAvatarTag = true;
237
+ tagsToMigrateToAvatarTag.add(componentName);
238
+
239
+ // Rename component to AvatarTag
240
+ openingElement.name.name = 'AvatarTag';
241
+ if (((_path$value$closingEl = path.value.closingElement) === null || _path$value$closingEl === void 0 || (_path$value$closingEl = _path$value$closingEl.name) === null || _path$value$closingEl === void 0 ? void 0 : _path$value$closingEl.type) === 'JSXIdentifier') {
242
+ path.value.closingElement.name.name = 'AvatarTag';
243
+ }
244
+
245
+ // Rename elemBefore to avatar
246
+ if (((_elemBeforeAttr$name = elemBeforeAttr.name) === null || _elemBeforeAttr$name === void 0 ? void 0 : _elemBeforeAttr$name.type) === 'JSXIdentifier') {
247
+ elemBeforeAttr.name.name = 'avatar';
248
+ }
249
+
250
+ // Convert avatar to render props function if not already
251
+ if (((_elemBeforeAttr$value = elemBeforeAttr.value) === null || _elemBeforeAttr$value === void 0 ? void 0 : _elemBeforeAttr$value.type) === 'JSXExpressionContainer') {
252
+ var expression = elemBeforeAttr.value.expression;
253
+
254
+ // If it's a direct Avatar component, convert to render props
255
+ if (isAvatarComponent(expression)) {
256
+ // Create: (avatarProps) => <Avatar {...avatarProps} originalProps... />
257
+ var avatarElement = expression;
258
+ var avatarAttributes = avatarElement.openingElement.attributes || [];
259
+
260
+ // Build new attributes with spread first, then existing props
261
+ var newAttributes = [j.jsxSpreadAttribute(j.identifier('avatarProps'))].concat((0, _toConsumableArray2.default)(avatarAttributes));
262
+ avatarElement.openingElement.attributes = newAttributes;
263
+
264
+ // Wrap in arrow function
265
+ var renderPropsFunc = j.arrowFunctionExpression([j.identifier('avatarProps')], avatarElement);
266
+ elemBeforeAttr.value.expression = renderPropsFunc;
267
+ }
268
+ // If it's already a function, leave it as is
269
+ }
270
+
271
+ // Remove color prop
272
+ openingElement.attributes = (openingElement.attributes || []).filter(function (attr) {
273
+ var _attr$name2;
274
+ if (attr.type === 'JSXAttribute' && ((_attr$name2 = attr.name) === null || _attr$name2 === void 0 ? void 0 : _attr$name2.type) === 'JSXIdentifier') {
275
+ return attr.name.name !== 'color';
276
+ }
277
+ return true;
278
+ });
279
+ }
280
+ }
281
+ if (!shouldMigrateToAvatarTag) {
282
+ var _path$value$closingEl2;
283
+ // Keep as regular Tag, rename to "Tag" if needed
284
+ hasRegularTagUsage = true;
285
+ openingElement.name.name = 'Tag';
286
+ if (((_path$value$closingEl2 = path.value.closingElement) === null || _path$value$closingEl2 === void 0 || (_path$value$closingEl2 = _path$value$closingEl2.name) === null || _path$value$closingEl2 === void 0 ? void 0 : _path$value$closingEl2.type) === 'JSXIdentifier') {
287
+ path.value.closingElement.name.name = 'Tag';
288
+ }
289
+
290
+ // Migrate color if present
291
+ if (colorAttr) {
292
+ var colorValue = extractStringValue(colorAttr.value);
293
+ if (colorValue && COLOR_MAP[colorValue]) {
294
+ var _colorAttr$value, _colorAttr$value2;
295
+ // Update the color value
296
+ if (((_colorAttr$value = colorAttr.value) === null || _colorAttr$value === void 0 ? void 0 : _colorAttr$value.type) === 'StringLiteral') {
297
+ colorAttr.value.value = COLOR_MAP[colorValue];
298
+ } else if (((_colorAttr$value2 = colorAttr.value) === null || _colorAttr$value2 === void 0 ? void 0 : _colorAttr$value2.type) === 'JSXExpressionContainer') {
299
+ var _expression = colorAttr.value.expression;
300
+ if (_expression.type === 'StringLiteral') {
301
+ _expression.value = COLOR_MAP[colorValue];
302
+ }
303
+ }
304
+ } else if (colorValue && !COLOR_MAP[colorValue] && !VALID_COLORS.has(colorValue)) {
305
+ // Color value is unknown/custom - mark for manual migration
306
+ tagsNeedingManualMigration.add(path);
307
+ }
308
+ }
309
+ }
310
+
311
+ // Remove appearance prop (for both AvatarTag and Tag)
312
+ openingElement.attributes = (openingElement.attributes || []).filter(function (attr) {
313
+ var _attr$name3;
314
+ if (attr.type === 'JSXAttribute' && ((_attr$name3 = attr.name) === null || _attr$name3 === void 0 ? void 0 : _attr$name3.type) === 'JSXIdentifier') {
315
+ return attr.name.name !== 'appearance';
316
+ }
317
+ return true;
318
+ });
319
+
320
+ // Add isRemovable={false} if original was SimpleTag and prop doesn't exist
321
+ if (tagInfo.isSimpleTag && !findAttribute(openingElement.attributes || [], 'isRemovable')) {
322
+ openingElement.attributes = openingElement.attributes || [];
323
+ openingElement.attributes.push(j.jsxAttribute(j.jsxIdentifier('isRemovable'), j.jsxExpressionContainer(j.booleanLiteral(false))));
324
+ }
325
+ }
326
+ });
327
+
328
+ // Add comments for manual migration
329
+ tagsNeedingManualMigration.forEach(function (path) {
330
+ var comment = ' TODO: Manual migration needed - color prop value could not be automatically migrated ';
331
+ j(path).forEach(function (p) {
332
+ var node = p.value;
333
+ node.comments = node.comments || [];
334
+ node.comments.push(j.commentBlock(comment));
335
+ });
336
+ });
337
+
338
+ // Update imports
339
+ var needsAvatarTagImport = tagsToMigrateToAvatarTag.size > 0;
340
+ // We need default Tag import if there are any regular tag usages
341
+ var needsDefaultTagImport = hasRegularTagUsage;
342
+
343
+ // Create new imports
344
+ var newImports = [];
345
+ if (needsDefaultTagImport) {
346
+ newImports.push(j.importDeclaration([j.importDefaultSpecifier(j.identifier('Tag'))], j.literal(TAG_ENTRY_POINT)));
347
+ }
348
+ if (needsAvatarTagImport) {
349
+ newImports.push(j.importDeclaration([j.importSpecifier(j.identifier('AvatarTag'))], j.literal(TAG_ENTRY_POINT)));
350
+ }
351
+
352
+ // Remove old Tag imports first
353
+ mainTagImports.forEach(function (importPath) {
354
+ return j(importPath).remove();
355
+ });
356
+ removableTagImports.forEach(function (importPath) {
357
+ return j(importPath).remove();
358
+ });
359
+ simpleTagImports.forEach(function (importPath) {
360
+ return j(importPath).remove();
361
+ });
362
+
363
+ // Insert new imports after Avatar import (if exists) or at the beginning
364
+ if (newImports.length > 0) {
365
+ var program = source.find(j.Program);
366
+ if (program.length > 0) {
367
+ var body = program.at(0).get('body').value;
368
+ if (avatarImports.length > 0) {
369
+ // Find the Avatar import in the body
370
+ var avatarImportNode = avatarImports.at(0).get().value;
371
+ var avatarIndex = body.findIndex(function (node) {
372
+ return node === avatarImportNode;
373
+ });
374
+ if (avatarIndex !== -1) {
375
+ // Insert all new imports right after Avatar import
376
+ body.splice.apply(body, [avatarIndex + 1, 0].concat(newImports));
377
+ } else {
378
+ // Fallback: add at beginning
379
+ body.unshift.apply(body, (0, _toConsumableArray2.default)(newImports.reverse()));
380
+ }
381
+ } else {
382
+ // No Avatar import, add at beginning
383
+ body.unshift.apply(body, (0, _toConsumableArray2.default)(newImports.reverse()));
384
+ }
385
+ }
386
+ }
387
+ return source.toSource(PRINT_SETTINGS);
388
+ }
@@ -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 _tagToNewTagMigration = _interopRequireDefault(require("./codemods/tag-to-newTag-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 = [_tagToNewTagMigration.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
+ }
@@ -115,7 +115,7 @@ const runTransform = async (filePaths, transform, flags) => {
115
115
  let transformModule;
116
116
  try {
117
117
  transformModule = require(transformPath);
118
- } catch (error) {
118
+ } catch {
119
119
  // eslint-disable-next-line no-console
120
120
  console.warn(`Error loading transform module: ${transformPath}. Skipping lifecycle hooks.`);
121
121
  }
@@ -15,5 +15,6 @@ import './remove-token-fallbacks/remove-token-fallbacks';
15
15
  import './lozenge-appearance-semantic-migration/lozenge-appearance-semantic-migration';
16
16
  import './lozenge-to-tag-migration/lozenge-to-tag-migration';
17
17
  import './badge-appearance-semantic-migration/badge-appearance-semantic-migration';
18
- 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-semantic-migration', 'lozenge-to-tag-migration', 'badge-appearance-semantic-migration'].map(preset => path.join(__dirname, preset, `${preset}.@(ts|js|tsx)`));
18
+ import './tag-to-newTag-migration/tag-to-newTag-migration';
19
+ 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-semantic-migration', 'lozenge-to-tag-migration', 'badge-appearance-semantic-migration', 'tag-to-newTag-migration'].map(preset => path.join(__dirname, preset, `${preset}.@(ts|js|tsx)`));
19
20
  export default presets;
@@ -402,7 +402,7 @@ export class TokenProcessor {
402
402
  });
403
403
  this.logVerbose(`Resolved module path: ${chalk.green(resolvedPath)} for ${chalk.cyan(moduleName)}`);
404
404
  return resolvedPath;
405
- } catch (error) {
405
+ } catch {
406
406
  return null;
407
407
  }
408
408
  }