@atlaskit/codemod-cli 0.24.3 → 0.25.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 +16 -0
  2. package/README.md +19 -9
  3. package/bin/codemod-cli.js +10 -10
  4. package/dist/cjs/main.js +1 -1
  5. package/dist/cjs/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js +30 -0
  6. package/dist/cjs/presets/migrate-to-new-buttons/utils/add-comment-for-custom-theme-buttons.js +3 -1
  7. package/dist/cjs/presets/migrate-to-new-buttons/utils/add-comment-for-overlay-prop.js +15 -0
  8. package/dist/cjs/presets/migrate-to-new-buttons/utils/constants.js +2 -1
  9. package/dist/es2019/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js +26 -0
  10. package/dist/es2019/presets/migrate-to-new-buttons/utils/add-comment-for-custom-theme-buttons.js +3 -1
  11. package/dist/es2019/presets/migrate-to-new-buttons/utils/add-comment-for-overlay-prop.js +7 -0
  12. package/dist/es2019/presets/migrate-to-new-buttons/utils/constants.js +1 -0
  13. package/dist/esm/main.js +1 -1
  14. package/dist/esm/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js +30 -0
  15. package/dist/esm/presets/migrate-to-new-buttons/utils/add-comment-for-custom-theme-buttons.js +3 -1
  16. package/dist/esm/presets/migrate-to-new-buttons/utils/add-comment-for-overlay-prop.js +9 -0
  17. package/dist/esm/presets/migrate-to-new-buttons/utils/constants.js +1 -0
  18. package/dist/types/presets/migrate-to-new-buttons/utils/add-comment-for-overlay-prop.d.ts +2 -0
  19. package/dist/types/presets/migrate-to-new-buttons/utils/constants.d.ts +1 -0
  20. package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/add-comment-for-overlay-prop.d.ts +2 -0
  21. package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/constants.d.ts +1 -0
  22. package/index.js +6 -6
  23. package/package.json +63 -63
  24. package/report.api.md +29 -28
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @atlaskit/codemod-cli
2
2
 
3
+ ## 0.25.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#111403](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/111403)
8
+ [`cc57d517bca2a`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/cc57d517bca2a) -
9
+ Migrate to new buttons codemod now adds comment for deprecated `overlay` props.
10
+
11
+ ## 0.24.4
12
+
13
+ ### Patch Changes
14
+
15
+ - [#108929](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/108929)
16
+ [`a25122bc3dc8f`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/a25122bc3dc8f) -
17
+ Fixed the duplicated "Button" imports after migrating loading buttons to default buttons.
18
+
3
19
  ## 0.24.3
4
20
 
5
21
  ### Patch Changes
package/README.md CHANGED
@@ -1,10 +1,13 @@
1
1
  # Codemods
2
2
 
3
- To easily download and run codemods associated with atlassian-frontend components and services, we provide a CLI tool called `@atlaskit/codemod-cli`.
3
+ To easily download and run codemods associated with atlassian-frontend components and services, we
4
+ provide a CLI tool called `@atlaskit/codemod-cli`.
4
5
 
5
- The idea is that upgrading major versions can be **assisted** by codemods, reducing upgrade-pain, improving adoption and giving component authors the flexibility to improve API and component design.
6
+ The idea is that upgrading major versions can be **assisted** by codemods, reducing upgrade-pain,
7
+ improving adoption and giving component authors the flexibility to improve API and component design.
6
8
 
7
- **Note:** Codemods will be designed to do the heavy lifting, but they'll often not be perfect so some manual work may still be required in order to successfully migrate.
9
+ **Note:** Codemods will be designed to do the heavy lifting, but they'll often not be perfect so
10
+ some manual work may still be required in order to successfully migrate.
8
11
 
9
12
  ---
10
13
 
@@ -16,7 +19,8 @@ The idea is that upgrading major versions can be **assisted** by codemods, reduc
16
19
 
17
20
  ### --preset, -n
18
21
 
19
- Select which transform to run from existing transform list by providing the preset name. This will allow you run the transfrom without any interaction.
22
+ Select which transform to run from existing transform list by providing the preset name. This will
23
+ allow you run the transfrom without any interaction.
20
24
 
21
25
  **example:**
22
26
 
@@ -33,7 +37,8 @@ The transform to run, transforms can be either a single file or directory with a
33
37
 
34
38
  ### --since-ref <git-ref>
35
39
 
36
- Determines changed packages since the specified git ref and runs all codemods for them. The automatic version of `--packages`. The ref can be any valid git ref, e.g. a commit hash, HEAD etc.
40
+ Determines changed packages since the specified git ref and runs all codemods for them. The
41
+ automatic version of `--packages`. The ref can be any valid git ref, e.g. a commit hash, HEAD etc.
37
42
 
38
43
  **example:**
39
44
 
@@ -42,7 +47,8 @@ Determines changed packages since the specified git ref and runs all codemods fo
42
47
 
43
48
  ### --packages
44
49
 
45
- Runs transforms for the specified comma separated list of packages, optionally include a version for each package to run all transforms since that version
50
+ Runs transforms for the specified comma separated list of packages, optionally include a version for
51
+ each package to run all transforms since that version
46
52
 
47
53
  **example:**
48
54
 
@@ -85,7 +91,9 @@ Ignore files that match a provided glob expression
85
91
 
86
92
  ### --no-filter-paths
87
93
 
88
- The codemod CLI filters supplied file paths by default, improving runtime by preventing codemods from running in non-dependent packages. Add this flag if there are problems with the filtering logic.
94
+ The codemod CLI filters supplied file paths by default, improving runtime by preventing codemods
95
+ from running in non-dependent packages. Add this flag if there are problems with the filtering
96
+ logic.
89
97
 
90
98
  **example:**
91
99
 
@@ -110,7 +118,8 @@ Print all help text to the command line
110
118
 
111
119
  ### Custom options
112
120
 
113
- All options are passed to the transformer, which means you can supply custom options that are not listed here.
121
+ All options are passed to the transformer, which means you can supply custom options that are not
122
+ listed here.
114
123
 
115
124
  **examples:**
116
125
 
@@ -132,4 +141,5 @@ For a list of commands run it with `-h` or refer to the documentation above.
132
141
 
133
142
  ## For internal Atlassians
134
143
 
135
- _Internal Atlassians can access [additional documentation on Confluence](https://hello.atlassian.net/wiki/spaces/AF/pages/2627171992/Codemods)._
144
+ _Internal Atlassians can access
145
+ [additional documentation on Confluence](https://hello.atlassian.net/wiki/spaces/AF/pages/2627171992/Codemods)._
@@ -8,16 +8,16 @@ const project = path.join(__dirname, '../tsconfig.json');
8
8
  const dev = fs.existsSync(project);
9
9
 
10
10
  if (dev && !require.extensions['.ts']) {
11
- // ts-node can only handle being registered once, see https://github.com/TypeStrong/ts-node/issues/409
12
- require('ts-node').register({ project });
11
+ // ts-node can only handle being registered once, see https://github.com/TypeStrong/ts-node/issues/409
12
+ require('ts-node').register({ project });
13
13
  }
14
14
 
15
15
  require(path.join('..', dev ? 'src/cli' : 'dist/cjs/cli'))
16
- .run()
17
- .catch((error) => {
18
- if (typeof error === 'number') {
19
- process.exit(error);
20
- }
21
- console.error(error);
22
- process.exit(1);
23
- });
16
+ .run()
17
+ .catch((error) => {
18
+ if (typeof error === 'number') {
19
+ process.exit(error);
20
+ }
21
+ console.error(error);
22
+ process.exit(1);
23
+ });
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.25.0", _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) {
@@ -18,6 +18,7 @@ var _renameDefaultButtonToLegacyButton = require("../utils/rename-default-button
18
18
  var _migrateFitContainerIconButton = require("../utils/migrate-fit-container-icon-button");
19
19
  var _importTypesFromNewEntryPoint = require("../utils/import-types-from-new-entry-point");
20
20
  var _addCommentForCustomThemeButtons = require("../utils/add-comment-for-custom-theme-buttons");
21
+ var _addCommentForOverlayProp = require("../utils/add-comment-for-overlay-prop");
21
22
  var transformer = function transformer(file, api) {
22
23
  var j = api.jscodeshift;
23
24
  var fileSource = j(file.source);
@@ -56,6 +57,7 @@ var transformer = function transformer(file, api) {
56
57
  var oldButtonElements = fileSource.find(j.JSXElement).filter(function (path) {
57
58
  return path.value.openingElement.name.type === 'JSXIdentifier' && ((oldDefaultImportSpecifiers === null || oldDefaultImportSpecifiers === void 0 ? void 0 : oldDefaultImportSpecifiers.includes(path.value.openingElement.name.name)) || Object.values(_constants.OLD_BUTTON_VARIANTS).includes(path.value.openingElement.name.name));
58
59
  });
60
+ (0, _addCommentForOverlayProp.addCommentForOverlayProp)(oldButtonElements, j);
59
61
  var oldButtonsWithoutUnsupportedProps = oldButtonElements.filter(function (path) {
60
62
  return !(0, _hasUnsupportedProps.ifHasUnsupportedProps)(path.value.openingElement.attributes);
61
63
  });
@@ -115,6 +117,33 @@ var transformer = function transformer(file, api) {
115
117
  hasVariant.iconButton = true;
116
118
  } else {
117
119
  hasVariant.defaultButton = true;
120
+
121
+ // rename existing Button to LegacyButton
122
+ var existingDefaultButtonSpecifier = fileSource.find(j.ImportDefaultSpecifier).filter(function (path) {
123
+ var _path$value$local;
124
+ return ((_path$value$local = path.value.local) === null || _path$value$local === void 0 ? void 0 : _path$value$local.name) === _constants.NEW_BUTTON_VARIANTS.default;
125
+ });
126
+ if (existingDefaultButtonSpecifier.length > 0) {
127
+ fileSource.find(j.JSXElement).filter(function (path) {
128
+ return path.value.openingElement.name.type === 'JSXIdentifier' && path.value.openingElement.name.name === _constants.NEW_BUTTON_VARIANTS.default;
129
+ }).forEach(function (element) {
130
+ var _element$value$childr2, _element$value$childr3;
131
+ // find all default <Button> JSX elements and replace with <LegacyButton>
132
+ 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));
133
+ });
134
+
135
+ // rename Button to LegacyButton in all call expressions i.e. render(Button), find(Button)
136
+ fileSource.find(j.CallExpression).find(j.Identifier).forEach(function (path) {
137
+ if (path.node.name === _constants.NEW_BUTTON_VARIANTS.default) {
138
+ path.node.name = 'LegacyButton';
139
+ }
140
+ });
141
+
142
+ // rename Button to LegacyButton in import declaration
143
+ existingDefaultButtonSpecifier.forEach(function (specifier) {
144
+ return j(specifier).replaceWith(j.importDefaultSpecifier(j.identifier('LegacyButton')));
145
+ });
146
+ }
118
147
  }
119
148
  j(element).replaceWith(newElement);
120
149
  if (hasHref || linkAppearanceAttribute) {
@@ -240,6 +269,7 @@ var transformer = function transformer(file, api) {
240
269
  fileSource.find(j.ImportDeclaration).filter(function (path) {
241
270
  return (path.node.source.value === '@atlaskit/button' || path.node.source.value === '@atlaskit/button/types') && !!path.node.specifiers && path.node.specifiers.length === 0;
242
271
  }).remove();
272
+ (0, _addCommentForCustomThemeButtons.addCommentForCustomThemeButtons)(fileSource, j);
243
273
  return fileSource.toSource(_constants.PRINT_SETTINGS);
244
274
  };
245
275
  var _default = exports.default = transformer;
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.addCommentForCustomThemeButtons = void 0;
7
7
  var _codemodUtils = require("@atlaskit/codemod-utils");
8
8
  var _constants = require("./constants");
9
+ var _addCommentForOverlayProp = require("./add-comment-for-overlay-prop");
9
10
  var addCommentForCustomThemeButtons = exports.addCommentForCustomThemeButtons = function addCommentForCustomThemeButtons(fileSource, j) {
10
11
  var _fileSource$find$filt;
11
12
  var customThemeButtonImportName;
@@ -29,5 +30,6 @@ var addCommentForCustomThemeButtons = exports.addCommentForCustomThemeButtons =
29
30
  if (!customThemeButtonElement.length) {
30
31
  return;
31
32
  }
32
- (0, _codemodUtils.addCommentBefore)(j, j(customThemeButtonElement.get(0).node.openingElement), _constants.customThemeButtonComment, 'line');
33
+ (0, _addCommentForOverlayProp.addCommentForOverlayProp)(customThemeButtonElement, j);
34
+ (0, _codemodUtils.addCommentBefore)(j, j(customThemeButtonElement.get(0).node.openingElement), _constants.customThemeButtonComment, 'block');
33
35
  };
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.addCommentForOverlayProp = void 0;
7
+ var _codemodUtils = require("@atlaskit/codemod-utils");
8
+ var _constants = require("./constants");
9
+ var addCommentForOverlayProp = exports.addCommentForOverlayProp = function addCommentForOverlayProp(oldButtons, j) {
10
+ oldButtons.find(j.JSXAttribute).filter(function (attribute) {
11
+ return attribute.node.name.name === 'overlay';
12
+ }).forEach(function (attribute) {
13
+ (0, _codemodUtils.addCommentBefore)(j, j(attribute), _constants.overlayPropComment, 'block');
14
+ });
15
+ };
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.unsupportedProps = exports.migrateFitContainerButtonToIconButtonComment = exports.migrateFitContainerButtonToDefaultButtonComment = exports.loadingButtonComment = exports.linkButtonMissingHrefComment = exports.entryPointsMapping = exports.customThemeButtonComment = exports.buttonPropsNoLongerSupportedComment = exports.UNSAFE_SIZE_PROPS_MAP = exports.PRINT_SETTINGS = exports.OLD_BUTTON_VARIANTS = exports.OLD_BUTTON_ENTRY_POINT = exports.NEW_BUTTON_VARIANTS = exports.NEW_BUTTON_ENTRY_POINT = exports.BUTTON_TYPES = void 0;
6
+ exports.unsupportedProps = exports.overlayPropComment = exports.migrateFitContainerButtonToIconButtonComment = exports.migrateFitContainerButtonToDefaultButtonComment = exports.loadingButtonComment = exports.linkButtonMissingHrefComment = exports.entryPointsMapping = exports.customThemeButtonComment = exports.buttonPropsNoLongerSupportedComment = exports.UNSAFE_SIZE_PROPS_MAP = exports.PRINT_SETTINGS = exports.OLD_BUTTON_VARIANTS = exports.OLD_BUTTON_ENTRY_POINT = exports.NEW_BUTTON_VARIANTS = exports.NEW_BUTTON_ENTRY_POINT = exports.BUTTON_TYPES = void 0;
7
7
  var PRINT_SETTINGS = exports.PRINT_SETTINGS = {
8
8
  quote: 'single'
9
9
  };
@@ -40,6 +40,7 @@ var buttonPropsNoLongerSupportedComment = exports.buttonPropsNoLongerSupportedCo
40
40
  var migrateFitContainerButtonToDefaultButtonComment = exports.migrateFitContainerButtonToDefaultButtonComment = "Migrated to a default button with text which is from the icon label.";
41
41
  var migrateFitContainerButtonToIconButtonComment = exports.migrateFitContainerButtonToIconButtonComment = "\"shouldFitContainer\" is not available in icon buttons, please consider using a default button with text.";
42
42
  var customThemeButtonComment = exports.customThemeButtonComment = "CustomThemeButton will be deprecated. Please consider migrating to Pressable or Anchor Primitives with custom styles.";
43
+ var overlayPropComment = exports.overlayPropComment = "The 'overlay' prop has been deprecated. This only existed in legacy buttons for supporting loading spinners, which can now be achieved in new buttons using the `isLoading` prop. Please remove the `overlay` prop and consider using the new `isLoading` prop.";
43
44
  var loadingButtonComment = exports.loadingButtonComment = function loadingButtonComment(_ref) {
44
45
  var hasLinkAppearance = _ref.hasLinkAppearance,
45
46
  hasHref = _ref.hasHref;
@@ -10,6 +10,7 @@ import { renameDefaultButtonToLegacyButtonImport } from '../utils/rename-default
10
10
  import { migrateFitContainerIconButton } from '../utils/migrate-fit-container-icon-button';
11
11
  import { importTypesFromNewEntryPoint } from '../utils/import-types-from-new-entry-point';
12
12
  import { addCommentForCustomThemeButtons } from '../utils/add-comment-for-custom-theme-buttons';
13
+ import { addCommentForOverlayProp } from '../utils/add-comment-for-overlay-prop';
13
14
  const transformer = (file, api) => {
14
15
  const j = api.jscodeshift;
15
16
  const fileSource = j(file.source);
@@ -44,6 +45,7 @@ const transformer = (file, api) => {
44
45
  const oldButtonElements = fileSource.find(j.JSXElement).filter(path => {
45
46
  return path.value.openingElement.name.type === 'JSXIdentifier' && ((oldDefaultImportSpecifiers === null || oldDefaultImportSpecifiers === void 0 ? void 0 : oldDefaultImportSpecifiers.includes(path.value.openingElement.name.name)) || Object.values(OLD_BUTTON_VARIANTS).includes(path.value.openingElement.name.name));
46
47
  });
48
+ addCommentForOverlayProp(oldButtonElements, j);
47
49
  const oldButtonsWithoutUnsupportedProps = oldButtonElements.filter(path => !ifHasUnsupportedProps(path.value.openingElement.attributes));
48
50
  oldButtonsWithoutUnsupportedProps.forEach(element => {
49
51
  var _element$value$childr;
@@ -101,6 +103,29 @@ const transformer = (file, api) => {
101
103
  hasVariant.iconButton = true;
102
104
  } else {
103
105
  hasVariant.defaultButton = true;
106
+
107
+ // rename existing Button to LegacyButton
108
+ const existingDefaultButtonSpecifier = fileSource.find(j.ImportDefaultSpecifier).filter(path => {
109
+ var _path$value$local;
110
+ return ((_path$value$local = path.value.local) === null || _path$value$local === void 0 ? void 0 : _path$value$local.name) === NEW_BUTTON_VARIANTS.default;
111
+ });
112
+ if (existingDefaultButtonSpecifier.length > 0) {
113
+ fileSource.find(j.JSXElement).filter(path => path.value.openingElement.name.type === 'JSXIdentifier' && path.value.openingElement.name.name === NEW_BUTTON_VARIANTS.default).forEach(element => {
114
+ var _element$value$childr2, _element$value$childr3;
115
+ // find all default <Button> JSX elements and replace with <LegacyButton>
116
+ 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));
117
+ });
118
+
119
+ // rename Button to LegacyButton in all call expressions i.e. render(Button), find(Button)
120
+ fileSource.find(j.CallExpression).find(j.Identifier).forEach(path => {
121
+ if (path.node.name === NEW_BUTTON_VARIANTS.default) {
122
+ path.node.name = 'LegacyButton';
123
+ }
124
+ });
125
+
126
+ // rename Button to LegacyButton in import declaration
127
+ existingDefaultButtonSpecifier.forEach(specifier => j(specifier).replaceWith(j.importDefaultSpecifier(j.identifier('LegacyButton'))));
128
+ }
104
129
  }
105
130
  j(element).replaceWith(newElement);
106
131
  if (hasHref || linkAppearanceAttribute) {
@@ -205,6 +230,7 @@ const transformer = (file, api) => {
205
230
 
206
231
  // remove empty import declarations
207
232
  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();
233
+ addCommentForCustomThemeButtons(fileSource, j);
208
234
  return fileSource.toSource(PRINT_SETTINGS);
209
235
  };
210
236
  export default transformer;
@@ -1,5 +1,6 @@
1
1
  import { addCommentBefore } from '@atlaskit/codemod-utils';
2
2
  import { entryPointsMapping, customThemeButtonComment } from './constants';
3
+ import { addCommentForOverlayProp } from './add-comment-for-overlay-prop';
3
4
  export const addCommentForCustomThemeButtons = (fileSource, j) => {
4
5
  var _fileSource$find$filt;
5
6
  let customThemeButtonImportName;
@@ -19,5 +20,6 @@ export const addCommentForCustomThemeButtons = (fileSource, j) => {
19
20
  if (!customThemeButtonElement.length) {
20
21
  return;
21
22
  }
22
- addCommentBefore(j, j(customThemeButtonElement.get(0).node.openingElement), customThemeButtonComment, 'line');
23
+ addCommentForOverlayProp(customThemeButtonElement, j);
24
+ addCommentBefore(j, j(customThemeButtonElement.get(0).node.openingElement), customThemeButtonComment, 'block');
23
25
  };
@@ -0,0 +1,7 @@
1
+ import { addCommentBefore } from '@atlaskit/codemod-utils';
2
+ import { overlayPropComment } from './constants';
3
+ export const addCommentForOverlayProp = (oldButtons, j) => {
4
+ oldButtons.find(j.JSXAttribute).filter(attribute => attribute.node.name.name === 'overlay').forEach(attribute => {
5
+ addCommentBefore(j, j(attribute), overlayPropComment, 'block');
6
+ });
7
+ };
@@ -34,6 +34,7 @@ export const buttonPropsNoLongerSupportedComment = `Buttons with "component", "c
34
34
  export const migrateFitContainerButtonToDefaultButtonComment = `Migrated to a default button with text which is from the icon label.`;
35
35
  export const migrateFitContainerButtonToIconButtonComment = `"shouldFitContainer" is not available in icon buttons, please consider using a default button with text.`;
36
36
  export const customThemeButtonComment = `CustomThemeButton will be deprecated. Please consider migrating to Pressable or Anchor Primitives with custom styles.`;
37
+ export const overlayPropComment = `The 'overlay' prop has been deprecated. This only existed in legacy buttons for supporting loading spinners, which can now be achieved in new buttons using the \`isLoading\` prop. Please remove the \`overlay\` prop and consider using the new \`isLoading\` prop.`;
37
38
  export const loadingButtonComment = ({
38
39
  hasLinkAppearance,
39
40
  hasHref
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.25.0", _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) {
@@ -11,6 +11,7 @@ import { renameDefaultButtonToLegacyButtonImport } from '../utils/rename-default
11
11
  import { migrateFitContainerIconButton } from '../utils/migrate-fit-container-icon-button';
12
12
  import { importTypesFromNewEntryPoint } from '../utils/import-types-from-new-entry-point';
13
13
  import { addCommentForCustomThemeButtons } from '../utils/add-comment-for-custom-theme-buttons';
14
+ import { addCommentForOverlayProp } from '../utils/add-comment-for-overlay-prop';
14
15
  var transformer = function transformer(file, api) {
15
16
  var j = api.jscodeshift;
16
17
  var fileSource = j(file.source);
@@ -49,6 +50,7 @@ var transformer = function transformer(file, api) {
49
50
  var oldButtonElements = fileSource.find(j.JSXElement).filter(function (path) {
50
51
  return path.value.openingElement.name.type === 'JSXIdentifier' && ((oldDefaultImportSpecifiers === null || oldDefaultImportSpecifiers === void 0 ? void 0 : oldDefaultImportSpecifiers.includes(path.value.openingElement.name.name)) || Object.values(OLD_BUTTON_VARIANTS).includes(path.value.openingElement.name.name));
51
52
  });
53
+ addCommentForOverlayProp(oldButtonElements, j);
52
54
  var oldButtonsWithoutUnsupportedProps = oldButtonElements.filter(function (path) {
53
55
  return !ifHasUnsupportedProps(path.value.openingElement.attributes);
54
56
  });
@@ -108,6 +110,33 @@ var transformer = function transformer(file, api) {
108
110
  hasVariant.iconButton = true;
109
111
  } else {
110
112
  hasVariant.defaultButton = true;
113
+
114
+ // rename existing Button to LegacyButton
115
+ var existingDefaultButtonSpecifier = fileSource.find(j.ImportDefaultSpecifier).filter(function (path) {
116
+ var _path$value$local;
117
+ return ((_path$value$local = path.value.local) === null || _path$value$local === void 0 ? void 0 : _path$value$local.name) === NEW_BUTTON_VARIANTS.default;
118
+ });
119
+ if (existingDefaultButtonSpecifier.length > 0) {
120
+ fileSource.find(j.JSXElement).filter(function (path) {
121
+ return path.value.openingElement.name.type === 'JSXIdentifier' && path.value.openingElement.name.name === NEW_BUTTON_VARIANTS.default;
122
+ }).forEach(function (element) {
123
+ var _element$value$childr2, _element$value$childr3;
124
+ // find all default <Button> JSX elements and replace with <LegacyButton>
125
+ 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));
126
+ });
127
+
128
+ // rename Button to LegacyButton in all call expressions i.e. render(Button), find(Button)
129
+ fileSource.find(j.CallExpression).find(j.Identifier).forEach(function (path) {
130
+ if (path.node.name === NEW_BUTTON_VARIANTS.default) {
131
+ path.node.name = 'LegacyButton';
132
+ }
133
+ });
134
+
135
+ // rename Button to LegacyButton in import declaration
136
+ existingDefaultButtonSpecifier.forEach(function (specifier) {
137
+ return j(specifier).replaceWith(j.importDefaultSpecifier(j.identifier('LegacyButton')));
138
+ });
139
+ }
111
140
  }
112
141
  j(element).replaceWith(newElement);
113
142
  if (hasHref || linkAppearanceAttribute) {
@@ -233,6 +262,7 @@ var transformer = function transformer(file, api) {
233
262
  fileSource.find(j.ImportDeclaration).filter(function (path) {
234
263
  return (path.node.source.value === '@atlaskit/button' || path.node.source.value === '@atlaskit/button/types') && !!path.node.specifiers && path.node.specifiers.length === 0;
235
264
  }).remove();
265
+ addCommentForCustomThemeButtons(fileSource, j);
236
266
  return fileSource.toSource(PRINT_SETTINGS);
237
267
  };
238
268
  export default transformer;
@@ -1,5 +1,6 @@
1
1
  import { addCommentBefore } from '@atlaskit/codemod-utils';
2
2
  import { entryPointsMapping, customThemeButtonComment } from './constants';
3
+ import { addCommentForOverlayProp } from './add-comment-for-overlay-prop';
3
4
  export var addCommentForCustomThemeButtons = function addCommentForCustomThemeButtons(fileSource, j) {
4
5
  var _fileSource$find$filt;
5
6
  var customThemeButtonImportName;
@@ -23,5 +24,6 @@ export var addCommentForCustomThemeButtons = function addCommentForCustomThemeBu
23
24
  if (!customThemeButtonElement.length) {
24
25
  return;
25
26
  }
26
- addCommentBefore(j, j(customThemeButtonElement.get(0).node.openingElement), customThemeButtonComment, 'line');
27
+ addCommentForOverlayProp(customThemeButtonElement, j);
28
+ addCommentBefore(j, j(customThemeButtonElement.get(0).node.openingElement), customThemeButtonComment, 'block');
27
29
  };
@@ -0,0 +1,9 @@
1
+ import { addCommentBefore } from '@atlaskit/codemod-utils';
2
+ import { overlayPropComment } from './constants';
3
+ export var addCommentForOverlayProp = function addCommentForOverlayProp(oldButtons, j) {
4
+ oldButtons.find(j.JSXAttribute).filter(function (attribute) {
5
+ return attribute.node.name.name === 'overlay';
6
+ }).forEach(function (attribute) {
7
+ addCommentBefore(j, j(attribute), overlayPropComment, 'block');
8
+ });
9
+ };
@@ -34,6 +34,7 @@ export var buttonPropsNoLongerSupportedComment = "Buttons with \"component\", \"
34
34
  export var migrateFitContainerButtonToDefaultButtonComment = "Migrated to a default button with text which is from the icon label.";
35
35
  export var migrateFitContainerButtonToIconButtonComment = "\"shouldFitContainer\" is not available in icon buttons, please consider using a default button with text.";
36
36
  export var customThemeButtonComment = "CustomThemeButton will be deprecated. Please consider migrating to Pressable or Anchor Primitives with custom styles.";
37
+ export var overlayPropComment = "The 'overlay' prop has been deprecated. This only existed in legacy buttons for supporting loading spinners, which can now be achieved in new buttons using the `isLoading` prop. Please remove the `overlay` prop and consider using the new `isLoading` prop.";
37
38
  export var loadingButtonComment = function loadingButtonComment(_ref) {
38
39
  var hasLinkAppearance = _ref.hasLinkAppearance,
39
40
  hasHref = _ref.hasHref;
@@ -0,0 +1,2 @@
1
+ import type { API, Collection, JSXElement } from 'jscodeshift';
2
+ export declare const addCommentForOverlayProp: (oldButtons: Collection<JSXElement>, j: API['jscodeshift']) => void;
@@ -22,6 +22,7 @@ export declare const buttonPropsNoLongerSupportedComment = "Buttons with \"compo
22
22
  export declare const migrateFitContainerButtonToDefaultButtonComment = "Migrated to a default button with text which is from the icon label.";
23
23
  export declare const migrateFitContainerButtonToIconButtonComment = "\"shouldFitContainer\" is not available in icon buttons, please consider using a default button with text.";
24
24
  export declare const customThemeButtonComment = "CustomThemeButton will be deprecated. Please consider migrating to Pressable or Anchor Primitives with custom styles.";
25
+ export declare const overlayPropComment = "The 'overlay' prop has been deprecated. This only existed in legacy buttons for supporting loading spinners, which can now be achieved in new buttons using the `isLoading` prop. Please remove the `overlay` prop and consider using the new `isLoading` prop.";
25
26
  export declare const loadingButtonComment: ({ hasLinkAppearance, hasHref, }: {
26
27
  hasLinkAppearance: boolean;
27
28
  hasHref: boolean;
@@ -0,0 +1,2 @@
1
+ import type { API, Collection, JSXElement } from 'jscodeshift';
2
+ export declare const addCommentForOverlayProp: (oldButtons: Collection<JSXElement>, j: API['jscodeshift']) => void;
@@ -22,6 +22,7 @@ export declare const buttonPropsNoLongerSupportedComment = "Buttons with \"compo
22
22
  export declare const migrateFitContainerButtonToDefaultButtonComment = "Migrated to a default button with text which is from the icon label.";
23
23
  export declare const migrateFitContainerButtonToIconButtonComment = "\"shouldFitContainer\" is not available in icon buttons, please consider using a default button with text.";
24
24
  export declare const customThemeButtonComment = "CustomThemeButton will be deprecated. Please consider migrating to Pressable or Anchor Primitives with custom styles.";
25
+ export declare const overlayPropComment = "The 'overlay' prop has been deprecated. This only existed in legacy buttons for supporting loading spinners, which can now be achieved in new buttons using the `isLoading` prop. Please remove the `overlay` prop and consider using the new `isLoading` prop.";
25
26
  export declare const loadingButtonComment: ({ hasLinkAppearance, hasHref, }: {
26
27
  hasLinkAppearance: boolean;
27
28
  hasHref: boolean;
package/index.js CHANGED
@@ -11,12 +11,12 @@ const dev = fs.existsSync(project);
11
11
 
12
12
  let entrypoint = path.join(__dirname, 'dist', 'cjs', 'index');
13
13
  if (dev) {
14
- if (!require.extensions['.ts']) {
15
- // ts-node can only handle being registered once, see https://github.com/TypeStrong/ts-node/issues/409
16
- // eslint-disable-next-line import/no-extraneous-dependencies
17
- require('ts-node').register({ project });
18
- }
19
- entrypoint = path.join(__dirname, 'src', 'index');
14
+ if (!require.extensions['.ts']) {
15
+ // ts-node can only handle being registered once, see https://github.com/TypeStrong/ts-node/issues/409
16
+ // eslint-disable-next-line import/no-extraneous-dependencies
17
+ require('ts-node').register({ project });
18
+ }
19
+ entrypoint = path.join(__dirname, 'src', 'index');
20
20
  }
21
21
 
22
22
  module.exports = require(entrypoint);
package/package.json CHANGED
@@ -1,64 +1,64 @@
1
1
  {
2
- "name": "@atlaskit/codemod-cli",
3
- "version": "0.24.3",
4
- "description": "A cli for distributing codemods for atlassian-frontend components and services",
5
- "publishConfig": {
6
- "registry": "https://registry.npmjs.org/"
7
- },
8
- "repository": "https://bitbucket.org/atlassian/atlassian-frontend-mirror",
9
- "author": "Atlassian Pty Ltd",
10
- "license": "Apache-2.0",
11
- "main": "index.js",
12
- "types": "dist/types/index.d.ts",
13
- "typesVersions": {
14
- ">=4.5 <4.9": {
15
- "*": [
16
- "dist/types-ts4.5/*",
17
- "dist/types-ts4.5/index.d.ts"
18
- ]
19
- }
20
- },
21
- "atlaskit:src": "src/index.ts",
22
- "af:exports": {
23
- ".": "./src/index.ts",
24
- "./cli": "./src/cli.ts",
25
- "./filepath": "./src/filepath.ts",
26
- "./main": "./src/main.ts",
27
- "./sinceRef": "./src/sinceRef.ts",
28
- "./transforms": "./src/transforms.ts",
29
- "./types": "./src/types.ts",
30
- "./utils": "./src/utils.ts"
31
- },
32
- "atlassian": {
33
- "team": "Design System Team",
34
- "releaseModel": "continuous"
35
- },
36
- "scripts": {
37
- "prestart": "cd ../../ && yarn build @atlaskit/codemod-utils tokens",
38
- "start": "./bin/codemod-cli.js"
39
- },
40
- "bin": "./bin/codemod-cli.js",
41
- "dependencies": {
42
- "@atlaskit/codemod-utils": "^4.2.0",
43
- "@atlaskit/tokens": "^1.49.0",
44
- "@babel/runtime": "^7.0.0",
45
- "@codeshift/utils": "^0.2.4",
46
- "@hypermod/utils": "^0.4.2",
47
- "@types/jscodeshift": "^0.11.0",
48
- "chalk": "^4.1.2",
49
- "enquirer": "^2.3.4",
50
- "glob": "9.0.0",
51
- "jscodeshift": "^0.13.0",
52
- "meow": "^8.1.1",
53
- "projector-spawn": "^1.0.1",
54
- "semver": "^7.5.2",
55
- "simple-git": "^3.16.0"
56
- },
57
- "devDependencies": {
58
- "@af/formatting": "*",
59
- "prettier": "^3.2.5",
60
- "ts-node": "^10.9.1",
61
- "typescript": "~5.4.2"
62
- },
63
- "homepage": "https://atlaskit.atlassian.com/packages/monorepo-tooling/codemod-cli"
64
- }
2
+ "name": "@atlaskit/codemod-cli",
3
+ "version": "0.25.0",
4
+ "description": "A cli for distributing codemods for atlassian-frontend components and services",
5
+ "publishConfig": {
6
+ "registry": "https://registry.npmjs.org/"
7
+ },
8
+ "repository": "https://bitbucket.org/atlassian/atlassian-frontend-mirror",
9
+ "author": "Atlassian Pty Ltd",
10
+ "license": "Apache-2.0",
11
+ "main": "index.js",
12
+ "types": "dist/types/index.d.ts",
13
+ "typesVersions": {
14
+ ">=4.5 <4.9": {
15
+ "*": [
16
+ "dist/types-ts4.5/*",
17
+ "dist/types-ts4.5/index.d.ts"
18
+ ]
19
+ }
20
+ },
21
+ "atlaskit:src": "src/index.ts",
22
+ "af:exports": {
23
+ ".": "./src/index.ts",
24
+ "./cli": "./src/cli.ts",
25
+ "./filepath": "./src/filepath.ts",
26
+ "./main": "./src/main.ts",
27
+ "./sinceRef": "./src/sinceRef.ts",
28
+ "./transforms": "./src/transforms.ts",
29
+ "./types": "./src/types.ts",
30
+ "./utils": "./src/utils.ts"
31
+ },
32
+ "atlassian": {
33
+ "team": "Design System Team",
34
+ "releaseModel": "continuous"
35
+ },
36
+ "scripts": {
37
+ "prestart": "cd ../../ && yarn build @atlaskit/codemod-utils tokens",
38
+ "start": "./bin/codemod-cli.js"
39
+ },
40
+ "bin": "./bin/codemod-cli.js",
41
+ "dependencies": {
42
+ "@atlaskit/codemod-utils": "^4.2.0",
43
+ "@atlaskit/tokens": "^1.51.0",
44
+ "@babel/runtime": "^7.0.0",
45
+ "@codeshift/utils": "^0.2.4",
46
+ "@hypermod/utils": "^0.4.2",
47
+ "@types/jscodeshift": "^0.11.0",
48
+ "chalk": "^4.1.2",
49
+ "enquirer": "^2.3.4",
50
+ "glob": "9.0.0",
51
+ "jscodeshift": "^0.13.0",
52
+ "meow": "^8.1.1",
53
+ "projector-spawn": "^1.0.1",
54
+ "semver": "^7.5.2",
55
+ "simple-git": "^3.16.0"
56
+ },
57
+ "devDependencies": {
58
+ "@af/formatting": "*",
59
+ "prettier": "^3.2.5",
60
+ "ts-node": "^10.9.1",
61
+ "typescript": "~5.4.2"
62
+ },
63
+ "homepage": "https://atlaskit.atlassian.com/packages/monorepo-tooling/codemod-cli"
64
+ }
package/report.api.md CHANGED
@@ -2,7 +2,8 @@
2
2
 
3
3
  ## API Report File for "@atlaskit/codemod-cli"
4
4
 
5
- > Do not edit this file. This report is auto-generated using [API Extractor](https://api-extractor.com/).
5
+ > Do not edit this file. This report is auto-generated using
6
+ > [API Extractor](https://api-extractor.com/).
6
7
  > [Learn more about API reports](https://hello.atlassian.net/wiki/spaces/UR/pages/1825484529/Package+API+Reports)
7
8
 
8
9
  ### Table of contents
@@ -17,15 +18,15 @@
17
18
  ```ts
18
19
  // @public (undocumented)
19
20
  type CliFlags = {
20
- transform?: string;
21
- preset?: string;
22
- packages?: string;
23
- parser: 'babel' | 'babylon' | 'flow' | 'ts' | 'tsx';
24
- extensions: string;
25
- ignorePattern: string;
26
- sinceRef?: string;
27
- failOnError?: boolean;
28
- filterPaths?: boolean;
21
+ transform?: string;
22
+ preset?: string;
23
+ packages?: string;
24
+ parser: 'babel' | 'babylon' | 'flow' | 'ts' | 'tsx';
25
+ extensions: string;
26
+ ignorePattern: string;
27
+ sinceRef?: string;
28
+ failOnError?: boolean;
29
+ filterPaths?: boolean;
29
30
  };
30
31
 
31
32
  // @public
@@ -33,34 +34,34 @@ type Default<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
33
34
 
34
35
  // @public (undocumented)
35
36
  const defaultFlags: {
36
- parser: 'babel';
37
- extensions: string;
38
- ignorePattern: string;
39
- logger: Console;
37
+ parser: 'babel';
38
+ extensions: string;
39
+ ignorePattern: string;
40
+ logger: Console;
40
41
  };
41
42
 
42
43
  // @public (undocumented)
43
44
  type Flags_2 = CliFlags & {
44
- logger: {
45
- log: (...args: any) => void;
46
- warn: (...args: any) => void;
47
- };
45
+ logger: {
46
+ log: (...args: any) => void;
47
+ warn: (...args: any) => void;
48
+ };
48
49
  };
49
50
  export { Flags_2 as Flags };
50
51
 
51
52
  // @public (undocumented)
52
53
  function main(
53
- input: string[],
54
- userFlags: UserFlags,
54
+ input: string[],
55
+ userFlags: UserFlags,
55
56
  ): Promise<{
56
- transforms: {
57
- module: string;
58
- root: string;
59
- dir: string;
60
- base: string;
61
- ext: string;
62
- name: string;
63
- }[];
57
+ transforms: {
58
+ module: string;
59
+ root: string;
60
+ dir: string;
61
+ base: string;
62
+ ext: string;
63
+ name: string;
64
+ }[];
64
65
  }>;
65
66
  export default main;
66
67