@atlaskit/codemod-cli 0.24.3 → 0.24.4

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,13 @@
1
1
  # @atlaskit/codemod-cli
2
2
 
3
+ ## 0.24.4
4
+
5
+ ### Patch Changes
6
+
7
+ - [#108929](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/108929)
8
+ [`a25122bc3dc8f`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/a25122bc3dc8f) -
9
+ Fixed the duplicated "Button" imports after migrating loading buttons to default buttons.
10
+
3
11
  ## 0.24.3
4
12
 
5
13
  ### Patch Changes
package/dist/cjs/main.js CHANGED
@@ -305,7 +305,7 @@ function _main() {
305
305
  case 4:
306
306
  _yield$parseArgs = _context5.sent;
307
307
  packages = _yield$parseArgs.packages;
308
- _process$env$_PACKAGE = "0.24.3", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
308
+ _process$env$_PACKAGE = "0.24.4", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
309
309
  logger.log(_chalk.default.bgBlue(_chalk.default.black("\uD83D\uDCDA Atlassian-Frontend codemod library @ ".concat(_PACKAGE_VERSION_, " \uD83D\uDCDA"))));
310
310
  if (packages && packages.length > 0) {
311
311
  logger.log(_chalk.default.gray("Searching for codemods for newer versions of the following packages: ".concat(packages.map(function (pkg) {
@@ -115,6 +115,33 @@ var transformer = function transformer(file, api) {
115
115
  hasVariant.iconButton = true;
116
116
  } else {
117
117
  hasVariant.defaultButton = true;
118
+
119
+ // rename existing Button to LegacyButton
120
+ var existingDefaultButtonSpecifier = fileSource.find(j.ImportDefaultSpecifier).filter(function (path) {
121
+ var _path$value$local;
122
+ return ((_path$value$local = path.value.local) === null || _path$value$local === void 0 ? void 0 : _path$value$local.name) === _constants.NEW_BUTTON_VARIANTS.default;
123
+ });
124
+ if (existingDefaultButtonSpecifier.length > 0) {
125
+ fileSource.find(j.JSXElement).filter(function (path) {
126
+ return path.value.openingElement.name.type === 'JSXIdentifier' && path.value.openingElement.name.name === _constants.NEW_BUTTON_VARIANTS.default;
127
+ }).forEach(function (element) {
128
+ var _element$value$childr2, _element$value$childr3;
129
+ // find all default <Button> JSX elements and replace with <LegacyButton>
130
+ j(element).replaceWith(j.jsxElement(j.jsxOpeningElement(j.jsxIdentifier('LegacyButton'), element.value.openingElement.attributes, ((_element$value$childr2 = element.value.children) === null || _element$value$childr2 === void 0 ? void 0 : _element$value$childr2.length) === 0), ((_element$value$childr3 = element.value.children) === null || _element$value$childr3 === void 0 ? void 0 : _element$value$childr3.length) === 0 ? null : j.jsxClosingElement(j.jsxIdentifier('LegacyButton')), element.value.children));
131
+ });
132
+
133
+ // rename Button to LegacyButton in all call expressions i.e. render(Button), find(Button)
134
+ fileSource.find(j.CallExpression).find(j.Identifier).forEach(function (path) {
135
+ if (path.node.name === _constants.NEW_BUTTON_VARIANTS.default) {
136
+ path.node.name = 'LegacyButton';
137
+ }
138
+ });
139
+
140
+ // rename Button to LegacyButton in import declaration
141
+ existingDefaultButtonSpecifier.forEach(function (specifier) {
142
+ return j(specifier).replaceWith(j.importDefaultSpecifier(j.identifier('LegacyButton')));
143
+ });
144
+ }
118
145
  }
119
146
  j(element).replaceWith(newElement);
120
147
  if (hasHref || linkAppearanceAttribute) {
@@ -240,6 +267,7 @@ var transformer = function transformer(file, api) {
240
267
  fileSource.find(j.ImportDeclaration).filter(function (path) {
241
268
  return (path.node.source.value === '@atlaskit/button' || path.node.source.value === '@atlaskit/button/types') && !!path.node.specifiers && path.node.specifiers.length === 0;
242
269
  }).remove();
270
+ (0, _addCommentForCustomThemeButtons.addCommentForCustomThemeButtons)(fileSource, j);
243
271
  return fileSource.toSource(_constants.PRINT_SETTINGS);
244
272
  };
245
273
  var _default = exports.default = transformer;
@@ -29,5 +29,5 @@ var addCommentForCustomThemeButtons = exports.addCommentForCustomThemeButtons =
29
29
  if (!customThemeButtonElement.length) {
30
30
  return;
31
31
  }
32
- (0, _codemodUtils.addCommentBefore)(j, j(customThemeButtonElement.get(0).node.openingElement), _constants.customThemeButtonComment, 'line');
32
+ (0, _codemodUtils.addCommentBefore)(j, j(customThemeButtonElement.get(0).node.openingElement), _constants.customThemeButtonComment, 'block');
33
33
  };
@@ -101,6 +101,29 @@ const transformer = (file, api) => {
101
101
  hasVariant.iconButton = true;
102
102
  } else {
103
103
  hasVariant.defaultButton = true;
104
+
105
+ // rename existing Button to LegacyButton
106
+ const existingDefaultButtonSpecifier = fileSource.find(j.ImportDefaultSpecifier).filter(path => {
107
+ var _path$value$local;
108
+ return ((_path$value$local = path.value.local) === null || _path$value$local === void 0 ? void 0 : _path$value$local.name) === NEW_BUTTON_VARIANTS.default;
109
+ });
110
+ if (existingDefaultButtonSpecifier.length > 0) {
111
+ fileSource.find(j.JSXElement).filter(path => path.value.openingElement.name.type === 'JSXIdentifier' && path.value.openingElement.name.name === NEW_BUTTON_VARIANTS.default).forEach(element => {
112
+ var _element$value$childr2, _element$value$childr3;
113
+ // find all default <Button> JSX elements and replace with <LegacyButton>
114
+ j(element).replaceWith(j.jsxElement(j.jsxOpeningElement(j.jsxIdentifier('LegacyButton'), element.value.openingElement.attributes, ((_element$value$childr2 = element.value.children) === null || _element$value$childr2 === void 0 ? void 0 : _element$value$childr2.length) === 0), ((_element$value$childr3 = element.value.children) === null || _element$value$childr3 === void 0 ? void 0 : _element$value$childr3.length) === 0 ? null : j.jsxClosingElement(j.jsxIdentifier('LegacyButton')), element.value.children));
115
+ });
116
+
117
+ // rename Button to LegacyButton in all call expressions i.e. render(Button), find(Button)
118
+ fileSource.find(j.CallExpression).find(j.Identifier).forEach(path => {
119
+ if (path.node.name === NEW_BUTTON_VARIANTS.default) {
120
+ path.node.name = 'LegacyButton';
121
+ }
122
+ });
123
+
124
+ // rename Button to LegacyButton in import declaration
125
+ existingDefaultButtonSpecifier.forEach(specifier => j(specifier).replaceWith(j.importDefaultSpecifier(j.identifier('LegacyButton'))));
126
+ }
104
127
  }
105
128
  j(element).replaceWith(newElement);
106
129
  if (hasHref || linkAppearanceAttribute) {
@@ -205,6 +228,7 @@ const transformer = (file, api) => {
205
228
 
206
229
  // remove empty import declarations
207
230
  fileSource.find(j.ImportDeclaration).filter(path => (path.node.source.value === '@atlaskit/button' || path.node.source.value === '@atlaskit/button/types') && !!path.node.specifiers && path.node.specifiers.length === 0).remove();
231
+ addCommentForCustomThemeButtons(fileSource, j);
208
232
  return fileSource.toSource(PRINT_SETTINGS);
209
233
  };
210
234
  export default transformer;
@@ -19,5 +19,5 @@ export const addCommentForCustomThemeButtons = (fileSource, j) => {
19
19
  if (!customThemeButtonElement.length) {
20
20
  return;
21
21
  }
22
- addCommentBefore(j, j(customThemeButtonElement.get(0).node.openingElement), customThemeButtonComment, 'line');
22
+ addCommentBefore(j, j(customThemeButtonElement.get(0).node.openingElement), customThemeButtonComment, 'block');
23
23
  };
package/dist/esm/main.js CHANGED
@@ -298,7 +298,7 @@ function _main() {
298
298
  case 4:
299
299
  _yield$parseArgs = _context5.sent;
300
300
  packages = _yield$parseArgs.packages;
301
- _process$env$_PACKAGE = "0.24.3", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
301
+ _process$env$_PACKAGE = "0.24.4", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
302
302
  logger.log(chalk.bgBlue(chalk.black("\uD83D\uDCDA Atlassian-Frontend codemod library @ ".concat(_PACKAGE_VERSION_, " \uD83D\uDCDA"))));
303
303
  if (packages && packages.length > 0) {
304
304
  logger.log(chalk.gray("Searching for codemods for newer versions of the following packages: ".concat(packages.map(function (pkg) {
@@ -108,6 +108,33 @@ var transformer = function transformer(file, api) {
108
108
  hasVariant.iconButton = true;
109
109
  } else {
110
110
  hasVariant.defaultButton = true;
111
+
112
+ // rename existing Button to LegacyButton
113
+ var existingDefaultButtonSpecifier = fileSource.find(j.ImportDefaultSpecifier).filter(function (path) {
114
+ var _path$value$local;
115
+ return ((_path$value$local = path.value.local) === null || _path$value$local === void 0 ? void 0 : _path$value$local.name) === NEW_BUTTON_VARIANTS.default;
116
+ });
117
+ if (existingDefaultButtonSpecifier.length > 0) {
118
+ fileSource.find(j.JSXElement).filter(function (path) {
119
+ return path.value.openingElement.name.type === 'JSXIdentifier' && path.value.openingElement.name.name === NEW_BUTTON_VARIANTS.default;
120
+ }).forEach(function (element) {
121
+ var _element$value$childr2, _element$value$childr3;
122
+ // find all default <Button> JSX elements and replace with <LegacyButton>
123
+ j(element).replaceWith(j.jsxElement(j.jsxOpeningElement(j.jsxIdentifier('LegacyButton'), element.value.openingElement.attributes, ((_element$value$childr2 = element.value.children) === null || _element$value$childr2 === void 0 ? void 0 : _element$value$childr2.length) === 0), ((_element$value$childr3 = element.value.children) === null || _element$value$childr3 === void 0 ? void 0 : _element$value$childr3.length) === 0 ? null : j.jsxClosingElement(j.jsxIdentifier('LegacyButton')), element.value.children));
124
+ });
125
+
126
+ // rename Button to LegacyButton in all call expressions i.e. render(Button), find(Button)
127
+ fileSource.find(j.CallExpression).find(j.Identifier).forEach(function (path) {
128
+ if (path.node.name === NEW_BUTTON_VARIANTS.default) {
129
+ path.node.name = 'LegacyButton';
130
+ }
131
+ });
132
+
133
+ // rename Button to LegacyButton in import declaration
134
+ existingDefaultButtonSpecifier.forEach(function (specifier) {
135
+ return j(specifier).replaceWith(j.importDefaultSpecifier(j.identifier('LegacyButton')));
136
+ });
137
+ }
111
138
  }
112
139
  j(element).replaceWith(newElement);
113
140
  if (hasHref || linkAppearanceAttribute) {
@@ -233,6 +260,7 @@ var transformer = function transformer(file, api) {
233
260
  fileSource.find(j.ImportDeclaration).filter(function (path) {
234
261
  return (path.node.source.value === '@atlaskit/button' || path.node.source.value === '@atlaskit/button/types') && !!path.node.specifiers && path.node.specifiers.length === 0;
235
262
  }).remove();
263
+ addCommentForCustomThemeButtons(fileSource, j);
236
264
  return fileSource.toSource(PRINT_SETTINGS);
237
265
  };
238
266
  export default transformer;
@@ -23,5 +23,5 @@ export var addCommentForCustomThemeButtons = function addCommentForCustomThemeBu
23
23
  if (!customThemeButtonElement.length) {
24
24
  return;
25
25
  }
26
- addCommentBefore(j, j(customThemeButtonElement.get(0).node.openingElement), customThemeButtonComment, 'line');
26
+ addCommentBefore(j, j(customThemeButtonElement.get(0).node.openingElement), customThemeButtonComment, 'block');
27
27
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/codemod-cli",
3
- "version": "0.24.3",
3
+ "version": "0.24.4",
4
4
  "description": "A cli for distributing codemods for atlassian-frontend components and services",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"