@atlaskit/codemod-cli 0.28.2 → 0.29.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 (56) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/cli/package.json +1 -1
  3. package/dist/cjs/main.js +1 -1
  4. package/dist/cjs/presets/index.js +2 -1
  5. package/dist/cjs/presets/migrate-icon-object-to-object/codemods/migrate-icon-object-to-object.js +138 -0
  6. package/dist/cjs/presets/migrate-icon-object-to-object/migrate-icon-object-to-object.js +44 -0
  7. package/dist/cjs/presets/migrate-icon-object-to-object/utils/constants.js +44 -0
  8. package/dist/cjs/presets/migrate-icon-object-to-object/utils/icon-mappings.js +65 -0
  9. package/dist/es2019/presets/index.js +2 -1
  10. package/dist/es2019/presets/migrate-icon-object-to-object/codemods/migrate-icon-object-to-object.js +130 -0
  11. package/dist/es2019/presets/migrate-icon-object-to-object/migrate-icon-object-to-object.js +18 -0
  12. package/dist/es2019/presets/migrate-icon-object-to-object/utils/constants.js +38 -0
  13. package/dist/es2019/presets/migrate-icon-object-to-object/utils/icon-mappings.js +54 -0
  14. package/dist/esm/main.js +1 -1
  15. package/dist/esm/presets/index.js +2 -1
  16. package/dist/esm/presets/migrate-icon-object-to-object/codemods/migrate-icon-object-to-object.js +132 -0
  17. package/dist/esm/presets/migrate-icon-object-to-object/migrate-icon-object-to-object.js +37 -0
  18. package/dist/esm/presets/migrate-icon-object-to-object/utils/constants.js +38 -0
  19. package/dist/esm/presets/migrate-icon-object-to-object/utils/icon-mappings.js +57 -0
  20. package/dist/types/presets/index.d.ts +1 -0
  21. package/dist/types/presets/migrate-icon-object-to-object/codemods/migrate-icon-object-to-object.d.ts +3 -0
  22. package/dist/types/presets/migrate-icon-object-to-object/migrate-icon-object-to-object.d.ts +2 -0
  23. package/dist/types/presets/migrate-icon-object-to-object/utils/constants.d.ts +9 -0
  24. package/dist/types/presets/migrate-icon-object-to-object/utils/icon-mappings.d.ts +23 -0
  25. package/dist/types/presets/migrate-to-link/utils/comments.d.ts +1 -1
  26. package/dist/types/presets/migrate-to-new-buttons/utils/add-comment-for-custom-theme-buttons.d.ts +1 -1
  27. package/dist/types/presets/migrate-to-new-buttons/utils/add-comment-for-overlay-prop.d.ts +1 -1
  28. package/dist/types/presets/migrate-to-new-buttons/utils/generate-link-element.d.ts +2 -2
  29. package/dist/types/presets/migrate-to-new-buttons/utils/generate-new-button-element.d.ts +3 -3
  30. package/dist/types/presets/migrate-to-new-buttons/utils/if-variant-already-imported.d.ts +2 -2
  31. package/dist/types/presets/migrate-to-new-buttons/utils/migrate-fit-container-icon-button.d.ts +1 -1
  32. package/dist/types/presets/migrate-to-new-buttons/utils/move-icon-value-from-link-button-to-link-children.d.ts +1 -1
  33. package/dist/types/presets/migrate-to-new-buttons/utils/rename-default-button-to-legacy-button.d.ts +1 -1
  34. package/dist/types/transforms.d.ts +0 -1
  35. package/dist/types-ts4.5/presets/index.d.ts +1 -0
  36. package/dist/types-ts4.5/presets/migrate-icon-object-to-object/codemods/migrate-icon-object-to-object.d.ts +3 -0
  37. package/dist/types-ts4.5/presets/migrate-icon-object-to-object/migrate-icon-object-to-object.d.ts +2 -0
  38. package/dist/types-ts4.5/presets/migrate-icon-object-to-object/utils/constants.d.ts +9 -0
  39. package/dist/types-ts4.5/presets/migrate-icon-object-to-object/utils/icon-mappings.d.ts +23 -0
  40. package/dist/types-ts4.5/presets/migrate-to-link/utils/comments.d.ts +1 -1
  41. package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/add-comment-for-custom-theme-buttons.d.ts +1 -1
  42. package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/add-comment-for-overlay-prop.d.ts +1 -1
  43. package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/generate-link-element.d.ts +2 -2
  44. package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/generate-new-button-element.d.ts +3 -3
  45. package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/if-variant-already-imported.d.ts +2 -2
  46. package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/migrate-fit-container-icon-button.d.ts +1 -1
  47. package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/move-icon-value-from-link-button-to-link-children.d.ts +1 -1
  48. package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/rename-default-button-to-legacy-button.d.ts +1 -1
  49. package/dist/types-ts4.5/transforms.d.ts +0 -1
  50. package/filepath/package.json +1 -1
  51. package/main/package.json +1 -1
  52. package/package.json +3 -4
  53. package/sinceRef/package.json +1 -1
  54. package/transforms/package.json +1 -1
  55. package/types/package.json +1 -1
  56. package/utils/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @atlaskit/codemod-cli
2
2
 
3
+ ## 0.29.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`e1d1e430b2dbb`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/e1d1e430b2dbb) -
8
+ Created a new codemod called "migrate-icon-object-to-object" to migrate the
9
+ `@atlaskit/icon-object` package to `@atlaskit/object`.
10
+
11
+ ## 0.28.3
12
+
13
+ ### Patch Changes
14
+
15
+ - [`098cfbb01dc36`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/098cfbb01dc36) -
16
+ Add missing npmignore files to remove unnecessary files from published package
17
+
3
18
  ## 0.28.2
4
19
 
5
20
  ### Patch Changes
package/cli/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "module:es2019": "../dist/es2019/cli.js",
6
6
  "types": "../dist/types/cli.d.ts",
7
7
  "typesVersions": {
8
- ">=4.5 <5.4": {
8
+ ">=4.5 <5.9": {
9
9
  "*": [
10
10
  "../dist/types-ts4.5/cli.d.ts"
11
11
  ]
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.28.1", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
365
+ _process$env$_PACKAGE = "0.0.0-development", _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) {
@@ -10,6 +10,7 @@ require("./styled-to-emotion/styled-to-emotion");
10
10
  require("./theme-remove-deprecated-mixins/theme-remove-deprecated-mixins");
11
11
  require("./migrate-to-link/migrate-to-link");
12
12
  require("./migrate-to-new-buttons/migrate-to-new-buttons");
13
+ require("./migrate-icon-object-to-object/migrate-icon-object-to-object");
13
14
  require("./upgrade-pragmatic-drag-and-drop-to-stable/upgrade-pragmatic-drag-and-drop-to-stable");
14
15
  require("./remove-dark-theme-vr-options/remove-dark-theme-vr-options");
15
16
  require("./remove-token-fallbacks/remove-token-fallbacks");
@@ -18,7 +19,7 @@ require("./remove-token-fallbacks/remove-token-fallbacks");
18
19
  * in the final bundle.
19
20
  */
20
21
 
21
- var presets = ['styled-to-emotion', 'theme-remove-deprecated-mixins', 'migrate-to-link', 'migrate-to-new-buttons', 'upgrade-pragmatic-drag-and-drop-to-stable', 'remove-dark-theme-vr-options', 'remove-token-fallbacks'].map(function (preset) {
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) {
22
23
  return _path.default.join(__dirname, preset, "".concat(preset, ".@(ts|js|tsx)"));
23
24
  });
24
25
  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 = void 0;
7
+ var _constants = require("../utils/constants");
8
+ var _iconMappings = require("../utils/icon-mappings");
9
+ /* eslint-disable @repo/internal/fs/filename-pattern-match */
10
+
11
+ var transformer = function transformer(file, api) {
12
+ var j = api.jscodeshift;
13
+ var fileSource = j(file.source);
14
+
15
+ // Find all icon-object imports
16
+ var iconObjectImports = fileSource.find(j.ImportDeclaration).filter(function (path) {
17
+ var source = path.node.source.value;
18
+ return typeof source === 'string' && source.startsWith(_constants.OLD_ICON_OBJECT_ENTRY_POINT);
19
+ });
20
+ if (!iconObjectImports.length) {
21
+ return fileSource.toSource();
22
+ }
23
+
24
+ // Track import name mappings (old name -> new name) and new imports to create
25
+ var importNameMappings = new Map();
26
+ var newImportsToCreate = [];
27
+
28
+ // Process each icon-object import
29
+ iconObjectImports.forEach(function (importPath) {
30
+ var _importDeclaration$sp;
31
+ var importDeclaration = importPath.node;
32
+ var source = importDeclaration.source.value;
33
+ var parsedImport = (0, _iconMappings.parseIconObjectImport)(source);
34
+ if (!parsedImport) {
35
+ return; // Skip invalid imports
36
+ }
37
+ var iconName = parsedImport.iconName,
38
+ size = parsedImport.size;
39
+ var _getNewImportInfo = (0, _iconMappings.getNewImportInfo)(iconName, size),
40
+ newImportPath = _getNewImportInfo.importPath,
41
+ componentName = _getNewImportInfo.componentName;
42
+
43
+ // Get the current import name (could be default import or renamed)
44
+ var defaultSpecifier = (_importDeclaration$sp = importDeclaration.specifiers) === null || _importDeclaration$sp === void 0 ? void 0 : _importDeclaration$sp.find(function (spec) {
45
+ return spec.type === 'ImportDefaultSpecifier';
46
+ });
47
+ if (defaultSpecifier) {
48
+ var _defaultSpecifier$loc;
49
+ var currentImportName = (_defaultSpecifier$loc = defaultSpecifier.local) === null || _defaultSpecifier$loc === void 0 ? void 0 : _defaultSpecifier$loc.name;
50
+ if (currentImportName) {
51
+ // Map the old import name to the new component name
52
+ importNameMappings.set(currentImportName, componentName);
53
+
54
+ // Track the new import to create
55
+ newImportsToCreate.push({
56
+ componentName: componentName,
57
+ importPath: newImportPath
58
+ });
59
+ }
60
+ }
61
+ });
62
+
63
+ // Update JSX elements to use new component names
64
+ importNameMappings.forEach(function (newName, oldName) {
65
+ fileSource.find(j.JSXElement).filter(function (path) {
66
+ var openingElement = path.value.openingElement;
67
+ return openingElement.name.type === 'JSXIdentifier' && openingElement.name.name === oldName;
68
+ }).forEach(function (elementPath) {
69
+ var _element$closingEleme;
70
+ var element = elementPath.value;
71
+
72
+ // Update opening tag
73
+ if (element.openingElement.name.type === 'JSXIdentifier') {
74
+ element.openingElement.name.name = newName;
75
+ }
76
+
77
+ // Update closing tag if it exists
78
+ if (((_element$closingEleme = element.closingElement) === null || _element$closingEleme === void 0 ? void 0 : _element$closingEleme.name.type) === 'JSXIdentifier') {
79
+ element.closingElement.name.name = newName;
80
+ }
81
+
82
+ // For 24px icons (now object tiles), add size="small" prop
83
+ if (newName.endsWith('ObjectTile')) {
84
+ var attributes = element.openingElement.attributes;
85
+ if (attributes) {
86
+ // Add size="small" (24px icons should be small tiles)
87
+ attributes.push(j.jsxAttribute(j.jsxIdentifier('size'), j.stringLiteral('small')));
88
+ }
89
+ }
90
+ });
91
+ });
92
+
93
+ // Update other references (like in render calls, etc.)
94
+ importNameMappings.forEach(function (newName, oldName) {
95
+ fileSource.find(j.Identifier).filter(function (path) {
96
+ return path.node.name === oldName;
97
+ }).forEach(function (path) {
98
+ var _parent$value, _parent$value2;
99
+ // Only update if it's not part of an import declaration or JSX element
100
+ // (those are handled separately)
101
+ var parent = path.parent;
102
+ if ((parent === null || parent === void 0 || (_parent$value = parent.value) === null || _parent$value === void 0 ? void 0 : _parent$value.type) !== 'ImportDefaultSpecifier' && (parent === null || parent === void 0 || (_parent$value2 = parent.value) === null || _parent$value2 === void 0 ? void 0 : _parent$value2.type) !== 'JSXIdentifier') {
103
+ path.node.name = newName;
104
+ }
105
+ });
106
+ });
107
+
108
+ // Remove old icon-object imports
109
+ iconObjectImports.remove();
110
+
111
+ // Create new individual default imports
112
+ var newImports = newImportsToCreate.map(function (_ref) {
113
+ var componentName = _ref.componentName,
114
+ importPath = _ref.importPath;
115
+ return (0, _iconMappings.createDefaultImportDeclaration)(j, componentName, importPath);
116
+ });
117
+
118
+ // Insert new imports at the top of the file
119
+ if (newImports.length > 0) {
120
+ var firstImport = fileSource.find(j.ImportDeclaration).at(0);
121
+ if (firstImport.length > 0) {
122
+ // Insert before the first existing import
123
+ // insertBefore adds in reverse order, so we need to reverse the array
124
+ newImports.reverse().forEach(function (importDecl) {
125
+ firstImport.insertBefore(importDecl);
126
+ });
127
+ } else {
128
+ // No existing imports, add at the top of the file
129
+ var body = fileSource.find(j.Program).get('body');
130
+ // For unshift, we also need to reverse to maintain correct order
131
+ newImports.reverse().forEach(function (importDecl) {
132
+ body.unshift(importDecl);
133
+ });
134
+ }
135
+ }
136
+ return fileSource.toSource(_constants.PRINT_SETTINGS);
137
+ };
138
+ 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 _migrateIconObjectToObject = _interopRequireDefault(require("./codemods/migrate-icon-object-to-object"));
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 = [_migrateIconObjectToObject.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,44 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.PRINT_SETTINGS = exports.OLD_ICON_OBJECT_ENTRY_POINT = exports.NEW_OBJECT_TILE_ENTRY_POINT = exports.NEW_OBJECT_ENTRY_POINT = exports.ICON_NAME_MAPPINGS = exports.AVAILABLE_ICON_NAMES = void 0;
7
+ /* eslint-disable @repo/internal/fs/filename-pattern-match */
8
+
9
+ // Entry points
10
+ var OLD_ICON_OBJECT_ENTRY_POINT = exports.OLD_ICON_OBJECT_ENTRY_POINT = '@atlaskit/icon-object';
11
+ var NEW_OBJECT_ENTRY_POINT = exports.NEW_OBJECT_ENTRY_POINT = '@atlaskit/object';
12
+ var NEW_OBJECT_TILE_ENTRY_POINT = exports.NEW_OBJECT_TILE_ENTRY_POINT = '@atlaskit/object/tile';
13
+
14
+ // Icon name mappings from kebab-case to PascalCase
15
+ var ICON_NAME_MAPPINGS = exports.ICON_NAME_MAPPINGS = {
16
+ blog: 'Blog',
17
+ branch: 'Branch',
18
+ bug: 'Bug',
19
+ calendar: 'Calendar',
20
+ changes: 'Changes',
21
+ code: 'Code',
22
+ commit: 'Commit',
23
+ epic: 'Epic',
24
+ improvement: 'Improvement',
25
+ incident: 'Incident',
26
+ issue: 'Issue',
27
+ 'new-feature': 'NewFeature',
28
+ page: 'Page',
29
+ 'page-live-doc': 'PageLiveDoc',
30
+ problem: 'Problem',
31
+ 'pull-request': 'PullRequest',
32
+ question: 'Question',
33
+ story: 'Story',
34
+ subtask: 'Subtask',
35
+ task: 'Task',
36
+ whiteboard: 'Whiteboard'
37
+ };
38
+
39
+ // Available icon names (kebab-case)
40
+ var AVAILABLE_ICON_NAMES = exports.AVAILABLE_ICON_NAMES = Object.keys(ICON_NAME_MAPPINGS);
41
+ var PRINT_SETTINGS = exports.PRINT_SETTINGS = {
42
+ quote: 'single',
43
+ trailingComma: true
44
+ };
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.createDefaultImportDeclaration = createDefaultImportDeclaration;
8
+ exports.getNewImportInfo = getNewImportInfo;
9
+ exports.parseIconObjectImport = parseIconObjectImport;
10
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
11
+ var _constants = require("./constants");
12
+ /* eslint-disable @repo/internal/fs/filename-pattern-match */
13
+
14
+ /**
15
+ * Extracts icon name and size from an icon-object import path
16
+ * @param importPath - The import path like '@atlaskit/icon-object/glyph/new-feature/16'
17
+ * @returns Object with iconName and size, or null if not a valid icon-object import
18
+ */
19
+ function parseIconObjectImport(importPath) {
20
+ var match = importPath.match(/^@atlaskit\/icon-object\/glyph\/([^/]+)\/(16|24)$/);
21
+ if (!match) {
22
+ return null;
23
+ }
24
+ var _match = (0, _slicedToArray2.default)(match, 3),
25
+ iconName = _match[1],
26
+ size = _match[2];
27
+
28
+ // Check if this is a valid icon name we support
29
+ if (!_constants.ICON_NAME_MAPPINGS[iconName]) {
30
+ return null;
31
+ }
32
+ return {
33
+ iconName: iconName,
34
+ size: size
35
+ };
36
+ }
37
+
38
+ /**
39
+ * Gets the new import specifier for an icon based on its name and size
40
+ * @param iconName - The kebab-case icon name (e.g., 'new-feature')
41
+ * @param size - The size ('16' or '24')
42
+ * @returns Object with the new import path and component name
43
+ */
44
+ function getNewImportInfo(iconName, size) {
45
+ var pascalCaseName = _constants.ICON_NAME_MAPPINGS[iconName];
46
+ if (size === '16') {
47
+ return {
48
+ importPath: "@atlaskit/object/".concat(iconName),
49
+ componentName: "".concat(pascalCaseName, "Object")
50
+ };
51
+ } else {
52
+ return {
53
+ importPath: "@atlaskit/object/tile/".concat(iconName),
54
+ componentName: "".concat(pascalCaseName, "ObjectTile")
55
+ };
56
+ }
57
+ }
58
+
59
+ /**
60
+ * Creates a new default import declaration for the transformed component
61
+ */
62
+ function createDefaultImportDeclaration(j, componentName, importPath) {
63
+ var defaultSpecifier = j.importDefaultSpecifier(j.identifier(componentName));
64
+ return j.importDeclaration([defaultSpecifier], j.stringLiteral(importPath));
65
+ }
@@ -8,8 +8,9 @@ import './styled-to-emotion/styled-to-emotion';
8
8
  import './theme-remove-deprecated-mixins/theme-remove-deprecated-mixins';
9
9
  import './migrate-to-link/migrate-to-link';
10
10
  import './migrate-to-new-buttons/migrate-to-new-buttons';
11
+ import './migrate-icon-object-to-object/migrate-icon-object-to-object';
11
12
  import './upgrade-pragmatic-drag-and-drop-to-stable/upgrade-pragmatic-drag-and-drop-to-stable';
12
13
  import './remove-dark-theme-vr-options/remove-dark-theme-vr-options';
13
14
  import './remove-token-fallbacks/remove-token-fallbacks';
14
- const presets = ['styled-to-emotion', 'theme-remove-deprecated-mixins', 'migrate-to-link', 'migrate-to-new-buttons', '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
+ 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
16
  export default presets;
@@ -0,0 +1,130 @@
1
+ /* eslint-disable @repo/internal/fs/filename-pattern-match */
2
+
3
+ import { OLD_ICON_OBJECT_ENTRY_POINT, PRINT_SETTINGS } from '../utils/constants';
4
+ import { createDefaultImportDeclaration, getNewImportInfo, parseIconObjectImport } from '../utils/icon-mappings';
5
+ const transformer = (file, api) => {
6
+ const j = api.jscodeshift;
7
+ const fileSource = j(file.source);
8
+
9
+ // Find all icon-object imports
10
+ const iconObjectImports = fileSource.find(j.ImportDeclaration).filter(path => {
11
+ const source = path.node.source.value;
12
+ return typeof source === 'string' && source.startsWith(OLD_ICON_OBJECT_ENTRY_POINT);
13
+ });
14
+ if (!iconObjectImports.length) {
15
+ return fileSource.toSource();
16
+ }
17
+
18
+ // Track import name mappings (old name -> new name) and new imports to create
19
+ const importNameMappings = new Map();
20
+ const newImportsToCreate = [];
21
+
22
+ // Process each icon-object import
23
+ iconObjectImports.forEach(importPath => {
24
+ var _importDeclaration$sp;
25
+ const importDeclaration = importPath.node;
26
+ const source = importDeclaration.source.value;
27
+ const parsedImport = parseIconObjectImport(source);
28
+ if (!parsedImport) {
29
+ return; // Skip invalid imports
30
+ }
31
+ const {
32
+ iconName,
33
+ size
34
+ } = parsedImport;
35
+ const {
36
+ importPath: newImportPath,
37
+ componentName
38
+ } = getNewImportInfo(iconName, size);
39
+
40
+ // Get the current import name (could be default import or renamed)
41
+ const defaultSpecifier = (_importDeclaration$sp = importDeclaration.specifiers) === null || _importDeclaration$sp === void 0 ? void 0 : _importDeclaration$sp.find(spec => spec.type === 'ImportDefaultSpecifier');
42
+ if (defaultSpecifier) {
43
+ var _defaultSpecifier$loc;
44
+ const currentImportName = (_defaultSpecifier$loc = defaultSpecifier.local) === null || _defaultSpecifier$loc === void 0 ? void 0 : _defaultSpecifier$loc.name;
45
+ if (currentImportName) {
46
+ // Map the old import name to the new component name
47
+ importNameMappings.set(currentImportName, componentName);
48
+
49
+ // Track the new import to create
50
+ newImportsToCreate.push({
51
+ componentName,
52
+ importPath: newImportPath
53
+ });
54
+ }
55
+ }
56
+ });
57
+
58
+ // Update JSX elements to use new component names
59
+ importNameMappings.forEach((newName, oldName) => {
60
+ fileSource.find(j.JSXElement).filter(path => {
61
+ const openingElement = path.value.openingElement;
62
+ return openingElement.name.type === 'JSXIdentifier' && openingElement.name.name === oldName;
63
+ }).forEach(elementPath => {
64
+ var _element$closingEleme;
65
+ const element = elementPath.value;
66
+
67
+ // Update opening tag
68
+ if (element.openingElement.name.type === 'JSXIdentifier') {
69
+ element.openingElement.name.name = newName;
70
+ }
71
+
72
+ // Update closing tag if it exists
73
+ if (((_element$closingEleme = element.closingElement) === null || _element$closingEleme === void 0 ? void 0 : _element$closingEleme.name.type) === 'JSXIdentifier') {
74
+ element.closingElement.name.name = newName;
75
+ }
76
+
77
+ // For 24px icons (now object tiles), add size="small" prop
78
+ if (newName.endsWith('ObjectTile')) {
79
+ const attributes = element.openingElement.attributes;
80
+ if (attributes) {
81
+ // Add size="small" (24px icons should be small tiles)
82
+ attributes.push(j.jsxAttribute(j.jsxIdentifier('size'), j.stringLiteral('small')));
83
+ }
84
+ }
85
+ });
86
+ });
87
+
88
+ // Update other references (like in render calls, etc.)
89
+ importNameMappings.forEach((newName, oldName) => {
90
+ fileSource.find(j.Identifier).filter(path => path.node.name === oldName).forEach(path => {
91
+ var _parent$value, _parent$value2;
92
+ // Only update if it's not part of an import declaration or JSX element
93
+ // (those are handled separately)
94
+ const parent = path.parent;
95
+ if ((parent === null || parent === void 0 ? void 0 : (_parent$value = parent.value) === null || _parent$value === void 0 ? void 0 : _parent$value.type) !== 'ImportDefaultSpecifier' && (parent === null || parent === void 0 ? void 0 : (_parent$value2 = parent.value) === null || _parent$value2 === void 0 ? void 0 : _parent$value2.type) !== 'JSXIdentifier') {
96
+ path.node.name = newName;
97
+ }
98
+ });
99
+ });
100
+
101
+ // Remove old icon-object imports
102
+ iconObjectImports.remove();
103
+
104
+ // Create new individual default imports
105
+ const newImports = newImportsToCreate.map(({
106
+ componentName,
107
+ importPath
108
+ }) => createDefaultImportDeclaration(j, componentName, importPath));
109
+
110
+ // Insert new imports at the top of the file
111
+ if (newImports.length > 0) {
112
+ const firstImport = fileSource.find(j.ImportDeclaration).at(0);
113
+ if (firstImport.length > 0) {
114
+ // Insert before the first existing import
115
+ // insertBefore adds in reverse order, so we need to reverse the array
116
+ newImports.reverse().forEach(importDecl => {
117
+ firstImport.insertBefore(importDecl);
118
+ });
119
+ } else {
120
+ // No existing imports, add at the top of the file
121
+ const body = fileSource.find(j.Program).get('body');
122
+ // For unshift, we also need to reverse to maintain correct order
123
+ newImports.reverse().forEach(importDecl => {
124
+ body.unshift(importDecl);
125
+ });
126
+ }
127
+ }
128
+ return fileSource.toSource(PRINT_SETTINGS);
129
+ };
130
+ export default transformer;
@@ -0,0 +1,18 @@
1
+ import migrateIconObjectToObjectTransformer from './codemods/migrate-icon-object-to-object';
2
+ export default async function transformer(file, api) {
3
+ const transformers = [migrateIconObjectToObjectTransformer];
4
+ let src = file.source;
5
+ transformers.forEach(transformer => {
6
+ if (typeof src === 'undefined') {
7
+ return;
8
+ }
9
+ const nextSrc = transformer({
10
+ ...file,
11
+ source: src
12
+ }, api);
13
+ if (nextSrc) {
14
+ src = nextSrc;
15
+ }
16
+ });
17
+ return src;
18
+ }
@@ -0,0 +1,38 @@
1
+ /* eslint-disable @repo/internal/fs/filename-pattern-match */
2
+
3
+ // Entry points
4
+ export const OLD_ICON_OBJECT_ENTRY_POINT = '@atlaskit/icon-object';
5
+ export const NEW_OBJECT_ENTRY_POINT = '@atlaskit/object';
6
+ export const NEW_OBJECT_TILE_ENTRY_POINT = '@atlaskit/object/tile';
7
+
8
+ // Icon name mappings from kebab-case to PascalCase
9
+ export const ICON_NAME_MAPPINGS = {
10
+ blog: 'Blog',
11
+ branch: 'Branch',
12
+ bug: 'Bug',
13
+ calendar: 'Calendar',
14
+ changes: 'Changes',
15
+ code: 'Code',
16
+ commit: 'Commit',
17
+ epic: 'Epic',
18
+ improvement: 'Improvement',
19
+ incident: 'Incident',
20
+ issue: 'Issue',
21
+ 'new-feature': 'NewFeature',
22
+ page: 'Page',
23
+ 'page-live-doc': 'PageLiveDoc',
24
+ problem: 'Problem',
25
+ 'pull-request': 'PullRequest',
26
+ question: 'Question',
27
+ story: 'Story',
28
+ subtask: 'Subtask',
29
+ task: 'Task',
30
+ whiteboard: 'Whiteboard'
31
+ };
32
+
33
+ // Available icon names (kebab-case)
34
+ export const AVAILABLE_ICON_NAMES = Object.keys(ICON_NAME_MAPPINGS);
35
+ export const PRINT_SETTINGS = {
36
+ quote: 'single',
37
+ trailingComma: true
38
+ };
@@ -0,0 +1,54 @@
1
+ /* eslint-disable @repo/internal/fs/filename-pattern-match */
2
+
3
+ import { ICON_NAME_MAPPINGS } from './constants';
4
+
5
+ /**
6
+ * Extracts icon name and size from an icon-object import path
7
+ * @param importPath - The import path like '@atlaskit/icon-object/glyph/new-feature/16'
8
+ * @returns Object with iconName and size, or null if not a valid icon-object import
9
+ */
10
+ export function parseIconObjectImport(importPath) {
11
+ const match = importPath.match(/^@atlaskit\/icon-object\/glyph\/([^/]+)\/(16|24)$/);
12
+ if (!match) {
13
+ return null;
14
+ }
15
+ const [, iconName, size] = match;
16
+
17
+ // Check if this is a valid icon name we support
18
+ if (!ICON_NAME_MAPPINGS[iconName]) {
19
+ return null;
20
+ }
21
+ return {
22
+ iconName,
23
+ size: size
24
+ };
25
+ }
26
+
27
+ /**
28
+ * Gets the new import specifier for an icon based on its name and size
29
+ * @param iconName - The kebab-case icon name (e.g., 'new-feature')
30
+ * @param size - The size ('16' or '24')
31
+ * @returns Object with the new import path and component name
32
+ */
33
+ export function getNewImportInfo(iconName, size) {
34
+ const pascalCaseName = ICON_NAME_MAPPINGS[iconName];
35
+ if (size === '16') {
36
+ return {
37
+ importPath: `@atlaskit/object/${iconName}`,
38
+ componentName: `${pascalCaseName}Object`
39
+ };
40
+ } else {
41
+ return {
42
+ importPath: `@atlaskit/object/tile/${iconName}`,
43
+ componentName: `${pascalCaseName}ObjectTile`
44
+ };
45
+ }
46
+ }
47
+
48
+ /**
49
+ * Creates a new default import declaration for the transformed component
50
+ */
51
+ export function createDefaultImportDeclaration(j, componentName, importPath) {
52
+ const defaultSpecifier = j.importDefaultSpecifier(j.identifier(componentName));
53
+ return j.importDeclaration([defaultSpecifier], j.stringLiteral(importPath));
54
+ }
package/dist/esm/main.js CHANGED
@@ -355,7 +355,7 @@ function _main() {
355
355
  case 4:
356
356
  _yield$parseArgs = _context6.sent;
357
357
  packages = _yield$parseArgs.packages;
358
- _process$env$_PACKAGE = "0.28.1", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
358
+ _process$env$_PACKAGE = "0.0.0-development", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
359
359
  logger.log(chalk.bgBlue(chalk.black("\uD83D\uDCDA Atlassian-Frontend codemod library @ ".concat(_PACKAGE_VERSION_, " \uD83D\uDCDA"))));
360
360
  if (packages && packages.length > 0) {
361
361
  logger.log(chalk.gray("Searching for codemods for newer versions of the following packages: ".concat(packages.map(function (pkg) {
@@ -8,10 +8,11 @@ import './styled-to-emotion/styled-to-emotion';
8
8
  import './theme-remove-deprecated-mixins/theme-remove-deprecated-mixins';
9
9
  import './migrate-to-link/migrate-to-link';
10
10
  import './migrate-to-new-buttons/migrate-to-new-buttons';
11
+ import './migrate-icon-object-to-object/migrate-icon-object-to-object';
11
12
  import './upgrade-pragmatic-drag-and-drop-to-stable/upgrade-pragmatic-drag-and-drop-to-stable';
12
13
  import './remove-dark-theme-vr-options/remove-dark-theme-vr-options';
13
14
  import './remove-token-fallbacks/remove-token-fallbacks';
14
- var presets = ['styled-to-emotion', 'theme-remove-deprecated-mixins', 'migrate-to-link', 'migrate-to-new-buttons', 'upgrade-pragmatic-drag-and-drop-to-stable', 'remove-dark-theme-vr-options', 'remove-token-fallbacks'].map(function (preset) {
15
+ 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) {
15
16
  return path.join(__dirname, preset, "".concat(preset, ".@(ts|js|tsx)"));
16
17
  });
17
18
  export default presets;