@atlaskit/codemod-cli 0.29.1 → 0.30.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @atlaskit/codemod-cli
2
2
 
3
+ ## 0.30.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`1b338696ed4bd`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/1b338696ed4bd) -
8
+ Add a new codemod `lozenge-appearance-to-color` to migrate deprecated Lozenge appearances to
9
+ colors as part of the Labelling System Phase 1 migration.
10
+
11
+ ## 0.29.2
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated dependencies
16
+
3
17
  ## 0.29.1
4
18
 
5
19
  ### Patch Changes
@@ -371,7 +385,6 @@
371
385
  - [#40270](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/40270)
372
386
  [`27bbdfcb6ad`](https://bitbucket.org/atlassian/atlassian-frontend/commits/27bbdfcb6ad) - This
373
387
  update includes several improvements and fixes to the css-to-design-tokens preset:
374
-
375
388
  - Resolved transformation errors.
376
389
  - Added support for new color properties such as `border-color-left`.
377
390
  - Omitted unrecognized functions, including `url`, and certain Less functions to prevent compile
@@ -596,7 +609,6 @@
596
609
  - [#20310](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/20310)
597
610
  [`1977986ea86`](https://bitbucket.org/atlassian/atlassian-frontend/commits/1977986ea86) - Bumping
598
611
  dependencies via Renovate:
599
-
600
612
  - simple-git
601
613
 
602
614
  ## 0.9.2
@@ -606,7 +618,6 @@
606
618
  - [#19927](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/19927)
607
619
  [`5c45b17200d`](https://bitbucket.org/atlassian/atlassian-frontend/commits/5c45b17200d) - Bumping
608
620
  dependencies via Renovate:
609
-
610
621
  - simple-git
611
622
 
612
623
  ## 0.9.1
@@ -709,13 +720,11 @@
709
720
  [Commit Changelog](https://github.com/facebook/jscodeshift/commit/2fd5e11f469427d474983b2d1c47be9408677591).
710
721
 
711
722
  ### Added
712
-
713
723
  - Added a `--fail-on-error` flag to return a `1` error code when errors were found (#416,
714
724
  @marcodejongh)
715
725
  - Created `template.asyncExpression` (#405, @jedwards1211)
716
726
 
717
727
  ### Changed
718
-
719
728
  - Removed lodash dependency from tsx parser (#432, @JHilker and @robyoder)
720
729
 
721
730
  ## 0.6.6
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.0.0-development", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
365
+ _process$env$_PACKAGE = "0.29.2", _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,13 @@ 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");
17
18
  /**
18
19
  * Manually import presets to make sure typescript includes them
19
20
  * in the final bundle.
20
21
  */
21
22
 
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) {
23
+ 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'].map(function (preset) {
23
24
  return _path.default.join(__dirname, preset, "".concat(preset, ".@(ts|js|tsx)"));
24
25
  });
25
26
  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
+ }
@@ -12,5 +12,6 @@ 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
+ 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'].map(preset => path.join(__dirname, preset, `${preset}.@(ts|js|tsx)`));
16
17
  export default presets;
@@ -0,0 +1,137 @@
1
+ import { getImportDeclaration } from '@hypermod/utils';
2
+ import { addCommentBefore } from '@atlaskit/codemod-utils';
3
+ const LOZENGE_ENTRY_POINT = '@atlaskit/lozenge';
4
+ const PRINT_SETTINGS = {
5
+ quote: 'single'
6
+ };
7
+
8
+ // Semantic appearance values that map directly to color values
9
+ const APPEARANCE_TO_COLOR_MAP = {
10
+ default: 'neutral',
11
+ inprogress: 'information',
12
+ moved: 'warning',
13
+ new: 'discovery',
14
+ removed: 'danger',
15
+ success: 'success'
16
+ };
17
+ /**
18
+ * Codemod to migrate Lozenge component from `appearance` prop to `color` prop.
19
+ *
20
+ * This codemod:
21
+ * 1. Renames `appearance` prop to `color` for semantic values
22
+ * 2. Maps existing semantic values directly (e.g. success → success)
23
+ * 3. Adds comments for dynamic values that need manual verification
24
+ */
25
+ export default function transformer(file, api) {
26
+ const j = api.jscodeshift;
27
+ const source = j(file.source);
28
+
29
+ // Find all Lozenge imports
30
+ const lozengeImports = getImportDeclaration(j, source, LOZENGE_ENTRY_POINT);
31
+
32
+ // If no Lozenge imports, exit early
33
+ if (!lozengeImports.length) {
34
+ return file.source;
35
+ }
36
+
37
+ // Get all imported Lozenge identifiers (could be renamed)
38
+ const lozengeIdentifiers = new Set();
39
+ lozengeImports.forEach(importPath => {
40
+ var _importPath$value$spe;
41
+ (_importPath$value$spe = importPath.value.specifiers) === null || _importPath$value$spe === void 0 ? void 0 : _importPath$value$spe.forEach(specifier => {
42
+ var _specifier$imported;
43
+ if (specifier.type === 'ImportDefaultSpecifier') {
44
+ var _specifier$local;
45
+ // Handle: import Lozenge from '@atlaskit/lozenge'
46
+ lozengeIdentifiers.add(((_specifier$local = specifier.local) === null || _specifier$local === void 0 ? void 0 : _specifier$local.name) || 'Lozenge');
47
+ } else if (specifier.type === 'ImportSpecifier' && ((_specifier$imported = specifier.imported) === null || _specifier$imported === void 0 ? void 0 : _specifier$imported.type) === 'Identifier' && specifier.imported.name === 'default') {
48
+ var _specifier$local2;
49
+ // Handle: import { default as Badge } from '@atlaskit/lozenge'
50
+ lozengeIdentifiers.add(((_specifier$local2 = specifier.local) === null || _specifier$local2 === void 0 ? void 0 : _specifier$local2.name) || 'Lozenge');
51
+ }
52
+ });
53
+ });
54
+
55
+ // If no Lozenge identifiers found, exit early
56
+ if (lozengeIdentifiers.size === 0) {
57
+ return file.source;
58
+ }
59
+
60
+ // Find all Lozenge JSX elements
61
+ const lozengeElements = [];
62
+ source.find(j.JSXElement).forEach(path => {
63
+ var _openingElement$name;
64
+ const openingElement = path.value.openingElement;
65
+ if (((_openingElement$name = openingElement.name) === null || _openingElement$name === void 0 ? void 0 : _openingElement$name.type) === 'JSXIdentifier' && lozengeIdentifiers.has(openingElement.name.name)) {
66
+ var _openingElement$attri;
67
+ const element = {
68
+ path,
69
+ hasAppearanceProp: false
70
+ };
71
+
72
+ // Check for appearance prop
73
+ (_openingElement$attri = openingElement.attributes) === null || _openingElement$attri === void 0 ? void 0 : _openingElement$attri.forEach(attr => {
74
+ var _attr$name;
75
+ if (attr.type === 'JSXAttribute' && ((_attr$name = attr.name) === null || _attr$name === void 0 ? void 0 : _attr$name.type) === 'JSXIdentifier') {
76
+ if (attr.name.name === 'appearance') {
77
+ var _attr$value, _attr$value2;
78
+ element.hasAppearanceProp = true;
79
+ if (((_attr$value = attr.value) === null || _attr$value === void 0 ? void 0 : _attr$value.type) === 'StringLiteral') {
80
+ element.appearanceValue = attr.value.value;
81
+ } else if (((_attr$value2 = attr.value) === null || _attr$value2 === void 0 ? void 0 : _attr$value2.type) === 'JSXExpressionContainer') {
82
+ // Handle dynamic values
83
+ const expression = attr.value.expression;
84
+ if (expression.type === 'StringLiteral') {
85
+ element.appearanceValue = expression.value;
86
+ } else {
87
+ element.appearanceValue = 'dynamic';
88
+ }
89
+ }
90
+ }
91
+ }
92
+ });
93
+ lozengeElements.push(element);
94
+ }
95
+ });
96
+
97
+ // Process each Lozenge element
98
+ lozengeElements.forEach(element => {
99
+ const {
100
+ path,
101
+ hasAppearanceProp,
102
+ appearanceValue
103
+ } = element;
104
+ const openingElement = path.value.openingElement;
105
+
106
+ // Transform appearance prop to color prop
107
+ if (hasAppearanceProp) {
108
+ var _openingElement$attri2;
109
+ (_openingElement$attri2 = openingElement.attributes) === null || _openingElement$attri2 === void 0 ? void 0 : _openingElement$attri2.forEach(attr => {
110
+ var _attr$name2;
111
+ if (attr.type === 'JSXAttribute' && ((_attr$name2 = attr.name) === null || _attr$name2 === void 0 ? void 0 : _attr$name2.type) === 'JSXIdentifier' && attr.name.name === 'appearance') {
112
+ // Rename appearance to color
113
+ attr.name.name = 'color';
114
+
115
+ // Handle different types of appearance values
116
+ if (appearanceValue === 'dynamic') {
117
+ // For dynamic values, add a comment
118
+ addCommentBefore(j, j(path), `FIXME: This Lozenge component uses a dynamic \`appearance\` prop that has been renamed to \`color\`.
119
+ Please verify that the values being passed are valid color values (semantic: default, inprogress, moved, new, removed, success).`);
120
+ } else if (appearanceValue && !APPEARANCE_TO_COLOR_MAP[appearanceValue]) {
121
+ // For invalid string values, add a warning comment
122
+ addCommentBefore(j, j(path), `FIXME: This Lozenge component uses an invalid \`appearance\` value "${appearanceValue}" that has been renamed to \`color\`.
123
+ Valid semantic color values are: ${Object.keys(APPEARANCE_TO_COLOR_MAP).join(', ')}.
124
+ Please update this value to a valid semantic color or use a custom color value.`);
125
+ } else if (appearanceValue && APPEARANCE_TO_COLOR_MAP[appearanceValue]) {
126
+ var _attr$value3;
127
+ // For valid string values, update the value to the mapped color
128
+ if (((_attr$value3 = attr.value) === null || _attr$value3 === void 0 ? void 0 : _attr$value3.type) === 'StringLiteral') {
129
+ attr.value.value = APPEARANCE_TO_COLOR_MAP[appearanceValue];
130
+ }
131
+ }
132
+ }
133
+ });
134
+ }
135
+ });
136
+ return source.toSource(PRINT_SETTINGS);
137
+ }
@@ -0,0 +1,18 @@
1
+ import lozengeAppearanceToColorTransformer from './codemods/lozenge-appearance-to-color';
2
+ export default async function transformer(file, api) {
3
+ const transformers = [lozengeAppearanceToColorTransformer];
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
+ }
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.0.0-development", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
358
+ _process$env$_PACKAGE = "0.29.2", _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) {
@@ -12,7 +12,8 @@ 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
- 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
+ import './lozenge-appearance-to-color/lozenge-appearance-to-color';
16
+ 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'].map(function (preset) {
16
17
  return path.join(__dirname, preset, "".concat(preset, ".@(ts|js|tsx)"));
17
18
  });
18
19
  export default presets;
@@ -0,0 +1,132 @@
1
+ import { getImportDeclaration } from '@hypermod/utils';
2
+ import { addCommentBefore } from '@atlaskit/codemod-utils';
3
+ var LOZENGE_ENTRY_POINT = '@atlaskit/lozenge';
4
+ var PRINT_SETTINGS = {
5
+ quote: 'single'
6
+ };
7
+
8
+ // Semantic appearance values that map directly to color values
9
+ var APPEARANCE_TO_COLOR_MAP = {
10
+ default: 'neutral',
11
+ inprogress: 'information',
12
+ moved: 'warning',
13
+ new: 'discovery',
14
+ removed: 'danger',
15
+ success: 'success'
16
+ };
17
+ /**
18
+ * Codemod to migrate Lozenge component from `appearance` prop to `color` prop.
19
+ *
20
+ * This codemod:
21
+ * 1. Renames `appearance` prop to `color` for semantic values
22
+ * 2. Maps existing semantic values directly (e.g. success → success)
23
+ * 3. Adds comments for dynamic values that need manual verification
24
+ */
25
+ export default function transformer(file, api) {
26
+ var j = api.jscodeshift;
27
+ var source = j(file.source);
28
+
29
+ // Find all Lozenge imports
30
+ var lozengeImports = getImportDeclaration(j, source, LOZENGE_ENTRY_POINT);
31
+
32
+ // If no Lozenge imports, exit early
33
+ if (!lozengeImports.length) {
34
+ return file.source;
35
+ }
36
+
37
+ // Get all imported Lozenge identifiers (could be renamed)
38
+ var lozengeIdentifiers = new Set();
39
+ lozengeImports.forEach(function (importPath) {
40
+ var _importPath$value$spe;
41
+ (_importPath$value$spe = importPath.value.specifiers) === null || _importPath$value$spe === void 0 || _importPath$value$spe.forEach(function (specifier) {
42
+ var _specifier$imported;
43
+ if (specifier.type === 'ImportDefaultSpecifier') {
44
+ var _specifier$local;
45
+ // Handle: import Lozenge from '@atlaskit/lozenge'
46
+ lozengeIdentifiers.add(((_specifier$local = specifier.local) === null || _specifier$local === void 0 ? void 0 : _specifier$local.name) || 'Lozenge');
47
+ } else if (specifier.type === 'ImportSpecifier' && ((_specifier$imported = specifier.imported) === null || _specifier$imported === void 0 ? void 0 : _specifier$imported.type) === 'Identifier' && specifier.imported.name === 'default') {
48
+ var _specifier$local2;
49
+ // Handle: import { default as Badge } from '@atlaskit/lozenge'
50
+ lozengeIdentifiers.add(((_specifier$local2 = specifier.local) === null || _specifier$local2 === void 0 ? void 0 : _specifier$local2.name) || 'Lozenge');
51
+ }
52
+ });
53
+ });
54
+
55
+ // If no Lozenge identifiers found, exit early
56
+ if (lozengeIdentifiers.size === 0) {
57
+ return file.source;
58
+ }
59
+
60
+ // Find all Lozenge JSX elements
61
+ var lozengeElements = [];
62
+ source.find(j.JSXElement).forEach(function (path) {
63
+ var _openingElement$name;
64
+ var openingElement = path.value.openingElement;
65
+ if (((_openingElement$name = openingElement.name) === null || _openingElement$name === void 0 ? void 0 : _openingElement$name.type) === 'JSXIdentifier' && lozengeIdentifiers.has(openingElement.name.name)) {
66
+ var _openingElement$attri;
67
+ var element = {
68
+ path: path,
69
+ hasAppearanceProp: false
70
+ };
71
+
72
+ // Check for appearance prop
73
+ (_openingElement$attri = openingElement.attributes) === null || _openingElement$attri === void 0 || _openingElement$attri.forEach(function (attr) {
74
+ var _attr$name;
75
+ if (attr.type === 'JSXAttribute' && ((_attr$name = attr.name) === null || _attr$name === void 0 ? void 0 : _attr$name.type) === 'JSXIdentifier') {
76
+ if (attr.name.name === 'appearance') {
77
+ var _attr$value, _attr$value2;
78
+ element.hasAppearanceProp = true;
79
+ if (((_attr$value = attr.value) === null || _attr$value === void 0 ? void 0 : _attr$value.type) === 'StringLiteral') {
80
+ element.appearanceValue = attr.value.value;
81
+ } else if (((_attr$value2 = attr.value) === null || _attr$value2 === void 0 ? void 0 : _attr$value2.type) === 'JSXExpressionContainer') {
82
+ // Handle dynamic values
83
+ var expression = attr.value.expression;
84
+ if (expression.type === 'StringLiteral') {
85
+ element.appearanceValue = expression.value;
86
+ } else {
87
+ element.appearanceValue = 'dynamic';
88
+ }
89
+ }
90
+ }
91
+ }
92
+ });
93
+ lozengeElements.push(element);
94
+ }
95
+ });
96
+
97
+ // Process each Lozenge element
98
+ lozengeElements.forEach(function (element) {
99
+ var path = element.path,
100
+ hasAppearanceProp = element.hasAppearanceProp,
101
+ appearanceValue = element.appearanceValue;
102
+ var openingElement = path.value.openingElement;
103
+
104
+ // Transform appearance prop to color prop
105
+ if (hasAppearanceProp) {
106
+ var _openingElement$attri2;
107
+ (_openingElement$attri2 = openingElement.attributes) === null || _openingElement$attri2 === void 0 || _openingElement$attri2.forEach(function (attr) {
108
+ var _attr$name2;
109
+ if (attr.type === 'JSXAttribute' && ((_attr$name2 = attr.name) === null || _attr$name2 === void 0 ? void 0 : _attr$name2.type) === 'JSXIdentifier' && attr.name.name === 'appearance') {
110
+ // Rename appearance to color
111
+ attr.name.name = 'color';
112
+
113
+ // Handle different types of appearance values
114
+ if (appearanceValue === 'dynamic') {
115
+ // For dynamic values, add a comment
116
+ 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).");
117
+ } else if (appearanceValue && !APPEARANCE_TO_COLOR_MAP[appearanceValue]) {
118
+ // For invalid string values, add a warning comment
119
+ 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."));
120
+ } else if (appearanceValue && APPEARANCE_TO_COLOR_MAP[appearanceValue]) {
121
+ var _attr$value3;
122
+ // For valid string values, update the value to the mapped color
123
+ if (((_attr$value3 = attr.value) === null || _attr$value3 === void 0 ? void 0 : _attr$value3.type) === 'StringLiteral') {
124
+ attr.value.value = APPEARANCE_TO_COLOR_MAP[appearanceValue];
125
+ }
126
+ }
127
+ }
128
+ });
129
+ }
130
+ });
131
+ return source.toSource(PRINT_SETTINGS);
132
+ }
@@ -0,0 +1,37 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
3
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
4
+ 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; }
5
+ 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) { _defineProperty(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; }
6
+ import lozengeAppearanceToColorTransformer from './codemods/lozenge-appearance-to-color';
7
+ export default function transformer(_x, _x2) {
8
+ return _transformer.apply(this, arguments);
9
+ }
10
+ function _transformer() {
11
+ _transformer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(file, api) {
12
+ var transformers, src;
13
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
14
+ while (1) switch (_context.prev = _context.next) {
15
+ case 0:
16
+ transformers = [lozengeAppearanceToColorTransformer];
17
+ src = file.source;
18
+ transformers.forEach(function (transformer) {
19
+ if (typeof src === 'undefined') {
20
+ return;
21
+ }
22
+ var nextSrc = transformer(_objectSpread(_objectSpread({}, file), {}, {
23
+ source: src
24
+ }), api);
25
+ if (nextSrc) {
26
+ src = nextSrc;
27
+ }
28
+ });
29
+ return _context.abrupt("return", src);
30
+ case 4:
31
+ case "end":
32
+ return _context.stop();
33
+ }
34
+ }, _callee);
35
+ }));
36
+ return _transformer.apply(this, arguments);
37
+ }
@@ -10,5 +10,6 @@ import './migrate-icon-object-to-object/migrate-icon-object-to-object';
10
10
  import './upgrade-pragmatic-drag-and-drop-to-stable/upgrade-pragmatic-drag-and-drop-to-stable';
11
11
  import './remove-dark-theme-vr-options/remove-dark-theme-vr-options';
12
12
  import './remove-token-fallbacks/remove-token-fallbacks';
13
+ import './lozenge-appearance-to-color/lozenge-appearance-to-color';
13
14
  declare const presets: string[];
14
15
  export default presets;
@@ -0,0 +1,10 @@
1
+ import { type API, type FileInfo } from 'jscodeshift';
2
+ /**
3
+ * Codemod to migrate Lozenge component from `appearance` prop to `color` prop.
4
+ *
5
+ * This codemod:
6
+ * 1. Renames `appearance` prop to `color` for semantic values
7
+ * 2. Maps existing semantic values directly (e.g. success → success)
8
+ * 3. Adds comments for dynamic values that need manual verification
9
+ */
10
+ export default function transformer(file: FileInfo, api: API): string;
@@ -0,0 +1,2 @@
1
+ import type { API, FileInfo } from 'jscodeshift';
2
+ export default function transformer(file: FileInfo, api: API): Promise<string>;
@@ -10,5 +10,6 @@ import './migrate-icon-object-to-object/migrate-icon-object-to-object';
10
10
  import './upgrade-pragmatic-drag-and-drop-to-stable/upgrade-pragmatic-drag-and-drop-to-stable';
11
11
  import './remove-dark-theme-vr-options/remove-dark-theme-vr-options';
12
12
  import './remove-token-fallbacks/remove-token-fallbacks';
13
+ import './lozenge-appearance-to-color/lozenge-appearance-to-color';
13
14
  declare const presets: string[];
14
15
  export default presets;
@@ -0,0 +1,10 @@
1
+ import { type API, type FileInfo } from 'jscodeshift';
2
+ /**
3
+ * Codemod to migrate Lozenge component from `appearance` prop to `color` prop.
4
+ *
5
+ * This codemod:
6
+ * 1. Renames `appearance` prop to `color` for semantic values
7
+ * 2. Maps existing semantic values directly (e.g. success → success)
8
+ * 3. Adds comments for dynamic values that need manual verification
9
+ */
10
+ export default function transformer(file: FileInfo, api: API): string;
@@ -0,0 +1,2 @@
1
+ import type { API, FileInfo } from 'jscodeshift';
2
+ export default function transformer(file: FileInfo, api: API): Promise<string>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/codemod-cli",
3
- "version": "0.29.1",
3
+ "version": "0.30.0",
4
4
  "description": "A cli for distributing codemods for atlassian-frontend components and services",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -29,7 +29,7 @@
29
29
  "bin": "./bin/codemod-cli.js",
30
30
  "dependencies": {
31
31
  "@atlaskit/codemod-utils": "^4.2.0",
32
- "@atlaskit/tokens": "^6.5.0",
32
+ "@atlaskit/tokens": "^7.0.0",
33
33
  "@babel/runtime": "^7.0.0",
34
34
  "@codeshift/utils": "^0.2.4",
35
35
  "@hypermod/utils": "^0.4.2",