@atlaskit/codemod-cli 0.34.8 → 1.0.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 (233) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/cli.js +4 -3
  3. package/dist/cjs/get-transform-module.js +14 -0
  4. package/dist/cjs/get-transform-path.js +11 -0
  5. package/dist/cjs/get-transform-version.js +16 -0
  6. package/dist/cjs/{transforms.js → get-transforms.js} +19 -45
  7. package/dist/cjs/has-transform.js +10 -0
  8. package/dist/cjs/index.js +1 -14
  9. package/dist/cjs/main.js +17 -12
  10. package/dist/cjs/no-transforms-exist-error.js +23 -0
  11. package/dist/cjs/parse-transform-path.js +11 -0
  12. package/dist/cjs/presets/migrate-deprecated-icon/utils/mock-deprecated-icons.js +22 -0
  13. package/dist/cjs/presets/migrate-deprecated-icon/utils/{mock.js → mock-metadata.js} +1 -17
  14. package/dist/cjs/presets/migrate-icon-object-to-object/codemods/migrate-icon-object-to-object.js +6 -4
  15. package/dist/cjs/presets/migrate-icon-object-to-object/utils/create-default-import-declaration.js +12 -0
  16. package/dist/cjs/presets/migrate-icon-object-to-object/utils/get-new-import-info.js +28 -0
  17. package/dist/cjs/presets/migrate-icon-object-to-object/utils/kebab-to-pascal-case.js +13 -0
  18. package/dist/cjs/presets/migrate-icon-object-to-object/utils/parse-icon-object-import.js +29 -0
  19. package/dist/cjs/presets/migrate-to-link/codemods/migrate-to-link.js +4 -2
  20. package/dist/cjs/presets/migrate-to-link/utils/comments.js +2 -13
  21. package/dist/cjs/presets/migrate-to-link/utils/generic-unsupported-migration-comment.js +11 -0
  22. package/dist/cjs/presets/migrate-to-link/utils/style-prop-comment.js +12 -0
  23. package/dist/cjs/presets/migrate-to-new-buttons/codemods/next-migrate-link-button-to-link.js +2 -2
  24. package/dist/cjs/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js +18 -16
  25. package/dist/cjs/presets/migrate-to-new-buttons/utils/check-if-variant-already-imported.js +11 -0
  26. package/dist/cjs/presets/migrate-to-new-buttons/utils/{if-variant-already-imported.js → find-variant-already-imported.js} +1 -5
  27. package/dist/cjs/presets/migrate-to-new-buttons/utils/{generate-link-element.js → generate-link-component.js} +3 -12
  28. package/dist/cjs/presets/migrate-to-new-buttons/utils/generate-new-element.js +47 -0
  29. package/dist/cjs/presets/migrate-to-new-buttons/utils/get-icon-attributes.js +15 -0
  30. package/dist/cjs/presets/migrate-to-new-buttons/utils/get-icon-element.js +13 -0
  31. package/dist/cjs/presets/migrate-to-new-buttons/utils/handle-icon-attributes.js +81 -0
  32. package/dist/cjs/presets/migrate-to-new-buttons/utils/migrate-fit-container-icon-button.js +4 -3
  33. package/dist/cjs/presets/migrate-to-new-buttons/utils/modify-button-attributes.js +18 -0
  34. package/dist/cjs/presets/migrate-to-new-buttons/utils/modify-link-attributes.js +16 -0
  35. package/dist/cjs/presets/remove-token-fallbacks/after-all.js +337 -0
  36. package/dist/cjs/presets/remove-token-fallbacks/before-all.js +33 -0
  37. package/dist/cjs/presets/remove-token-fallbacks/remove-token-fallbacks.js +4 -360
  38. package/dist/cjs/presets/remove-token-fallbacks/utils/clear-folder.js +68 -0
  39. package/dist/cjs/presets/remove-token-fallbacks/utils/{color-utils.js → color-to-hex.js} +0 -37
  40. package/dist/cjs/presets/remove-token-fallbacks/utils/{reporter.js → combine-reports.js} +59 -182
  41. package/dist/cjs/presets/remove-token-fallbacks/utils/compare-hex.js +25 -0
  42. package/dist/cjs/presets/remove-token-fallbacks/utils/is-valid-color.js +41 -0
  43. package/dist/cjs/presets/remove-token-fallbacks/utils/normalize-values.js +8 -6
  44. package/dist/cjs/presets/remove-token-fallbacks/utils/write-reports.js +83 -0
  45. package/dist/cjs/sinceRef.js +2 -2
  46. package/dist/cjs/types.js +1 -31
  47. package/dist/cjs/validation-error.js +23 -0
  48. package/dist/es2019/cli.js +2 -1
  49. package/dist/es2019/get-transform-module.js +7 -0
  50. package/dist/es2019/get-transform-path.js +4 -0
  51. package/dist/es2019/get-transform-version.js +9 -0
  52. package/dist/es2019/{transforms.js → get-transforms.js} +10 -31
  53. package/dist/es2019/has-transform.js +2 -0
  54. package/dist/es2019/index.js +1 -2
  55. package/dist/es2019/main.js +7 -2
  56. package/dist/es2019/no-transforms-exist-error.js +1 -0
  57. package/dist/es2019/parse-transform-path.js +2 -0
  58. package/dist/es2019/presets/migrate-deprecated-icon/utils/mock-deprecated-icons.js +16 -0
  59. package/dist/es2019/presets/migrate-deprecated-icon/utils/{mock.js → mock-metadata.js} +0 -16
  60. package/dist/es2019/presets/migrate-icon-object-to-object/codemods/migrate-icon-object-to-object.js +3 -1
  61. package/dist/es2019/presets/migrate-icon-object-to-object/utils/create-default-import-declaration.js +6 -0
  62. package/dist/es2019/presets/migrate-icon-object-to-object/utils/get-new-import-info.js +22 -0
  63. package/dist/es2019/presets/migrate-icon-object-to-object/utils/kebab-to-pascal-case.js +5 -0
  64. package/dist/es2019/presets/migrate-icon-object-to-object/utils/parse-icon-object-import.js +19 -0
  65. package/dist/es2019/presets/migrate-to-link/codemods/migrate-to-link.js +3 -1
  66. package/dist/es2019/presets/migrate-to-link/utils/comments.js +1 -11
  67. package/dist/es2019/presets/migrate-to-link/utils/generic-unsupported-migration-comment.js +4 -0
  68. package/dist/es2019/presets/migrate-to-link/utils/style-prop-comment.js +6 -0
  69. package/dist/es2019/presets/migrate-to-new-buttons/codemods/next-migrate-link-button-to-link.js +1 -1
  70. package/dist/es2019/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js +5 -3
  71. package/dist/es2019/presets/migrate-to-new-buttons/utils/check-if-variant-already-imported.js +4 -0
  72. package/dist/es2019/presets/migrate-to-new-buttons/utils/{if-variant-already-imported.js → find-variant-already-imported.js} +0 -3
  73. package/dist/es2019/presets/migrate-to-new-buttons/utils/{generate-link-element.js → generate-link-component.js} +1 -10
  74. package/dist/es2019/presets/migrate-to-new-buttons/utils/generate-new-element.js +39 -0
  75. package/dist/es2019/presets/migrate-to-new-buttons/utils/get-icon-attributes.js +7 -0
  76. package/dist/es2019/presets/migrate-to-new-buttons/utils/get-icon-element.js +7 -0
  77. package/dist/es2019/presets/migrate-to-new-buttons/utils/handle-icon-attributes.js +68 -0
  78. package/dist/es2019/presets/migrate-to-new-buttons/utils/migrate-fit-container-icon-button.js +2 -1
  79. package/dist/es2019/presets/migrate-to-new-buttons/utils/modify-button-attributes.js +12 -0
  80. package/dist/es2019/presets/migrate-to-new-buttons/utils/modify-link-attributes.js +10 -0
  81. package/dist/es2019/presets/remove-token-fallbacks/after-all.js +139 -0
  82. package/dist/es2019/presets/remove-token-fallbacks/before-all.js +8 -0
  83. package/dist/es2019/presets/remove-token-fallbacks/remove-token-fallbacks.js +2 -150
  84. package/dist/es2019/presets/remove-token-fallbacks/utils/clear-folder.js +15 -0
  85. package/dist/es2019/presets/remove-token-fallbacks/utils/{color-utils.js → color-to-hex.js} +0 -34
  86. package/dist/es2019/presets/remove-token-fallbacks/utils/{reporter.js → combine-reports.js} +1 -50
  87. package/dist/es2019/presets/remove-token-fallbacks/utils/compare-hex.js +17 -0
  88. package/dist/es2019/presets/remove-token-fallbacks/utils/is-valid-color.js +35 -0
  89. package/dist/es2019/presets/remove-token-fallbacks/utils/normalize-values.js +3 -1
  90. package/dist/es2019/presets/remove-token-fallbacks/utils/write-reports.js +41 -0
  91. package/dist/es2019/sinceRef.js +1 -1
  92. package/dist/es2019/types.js +1 -7
  93. package/dist/es2019/validation-error.js +1 -0
  94. package/dist/esm/cli.js +2 -1
  95. package/dist/esm/get-transform-module.js +7 -0
  96. package/dist/esm/get-transform-path.js +5 -0
  97. package/dist/esm/get-transform-version.js +9 -0
  98. package/dist/esm/{transforms.js → get-transforms.js} +16 -42
  99. package/dist/esm/has-transform.js +4 -0
  100. package/dist/esm/index.js +1 -2
  101. package/dist/esm/main.js +7 -2
  102. package/dist/esm/no-transforms-exist-error.js +16 -0
  103. package/dist/esm/parse-transform-path.js +4 -0
  104. package/dist/esm/presets/migrate-deprecated-icon/utils/mock-deprecated-icons.js +16 -0
  105. package/dist/esm/presets/migrate-deprecated-icon/utils/{mock.js → mock-metadata.js} +0 -16
  106. package/dist/esm/presets/migrate-icon-object-to-object/codemods/migrate-icon-object-to-object.js +3 -1
  107. package/dist/esm/presets/migrate-icon-object-to-object/utils/create-default-import-declaration.js +6 -0
  108. package/dist/esm/presets/migrate-icon-object-to-object/utils/get-new-import-info.js +22 -0
  109. package/dist/esm/presets/migrate-icon-object-to-object/utils/kebab-to-pascal-case.js +7 -0
  110. package/dist/esm/presets/migrate-icon-object-to-object/utils/parse-icon-object-import.js +22 -0
  111. package/dist/esm/presets/migrate-to-link/codemods/migrate-to-link.js +3 -1
  112. package/dist/esm/presets/migrate-to-link/utils/comments.js +1 -12
  113. package/dist/esm/presets/migrate-to-link/utils/generic-unsupported-migration-comment.js +5 -0
  114. package/dist/esm/presets/migrate-to-link/utils/style-prop-comment.js +6 -0
  115. package/dist/esm/presets/migrate-to-new-buttons/codemods/next-migrate-link-button-to-link.js +1 -1
  116. package/dist/esm/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js +5 -3
  117. package/dist/esm/presets/migrate-to-new-buttons/utils/check-if-variant-already-imported.js +5 -0
  118. package/dist/esm/presets/migrate-to-new-buttons/utils/{if-variant-already-imported.js → find-variant-already-imported.js} +0 -4
  119. package/dist/esm/presets/migrate-to-new-buttons/utils/{generate-link-element.js → generate-link-component.js} +1 -10
  120. package/dist/esm/presets/migrate-to-new-buttons/utils/generate-new-element.js +41 -0
  121. package/dist/esm/presets/migrate-to-new-buttons/utils/get-icon-attributes.js +9 -0
  122. package/dist/esm/presets/migrate-to-new-buttons/utils/get-icon-element.js +7 -0
  123. package/dist/esm/presets/migrate-to-new-buttons/utils/handle-icon-attributes.js +75 -0
  124. package/dist/esm/presets/migrate-to-new-buttons/utils/migrate-fit-container-icon-button.js +2 -1
  125. package/dist/esm/presets/migrate-to-new-buttons/utils/modify-button-attributes.js +12 -0
  126. package/dist/esm/presets/migrate-to-new-buttons/utils/modify-link-attributes.js +10 -0
  127. package/dist/esm/presets/remove-token-fallbacks/after-all.js +331 -0
  128. package/dist/esm/presets/remove-token-fallbacks/before-all.js +27 -0
  129. package/dist/esm/presets/remove-token-fallbacks/remove-token-fallbacks.js +2 -357
  130. package/dist/esm/presets/remove-token-fallbacks/utils/clear-folder.js +62 -0
  131. package/dist/esm/presets/remove-token-fallbacks/utils/{color-utils.js → color-to-hex.js} +0 -36
  132. package/dist/esm/presets/remove-token-fallbacks/utils/{reporter.js → combine-reports.js} +57 -180
  133. package/dist/esm/presets/remove-token-fallbacks/utils/compare-hex.js +19 -0
  134. package/dist/esm/presets/remove-token-fallbacks/utils/is-valid-color.js +35 -0
  135. package/dist/esm/presets/remove-token-fallbacks/utils/normalize-values.js +3 -1
  136. package/dist/esm/presets/remove-token-fallbacks/utils/write-reports.js +75 -0
  137. package/dist/esm/sinceRef.js +1 -1
  138. package/dist/esm/types.js +1 -29
  139. package/dist/esm/validation-error.js +16 -0
  140. package/dist/types/get-transform-module.d.ts +2 -0
  141. package/dist/types/get-transform-path.d.ts +2 -0
  142. package/dist/types/get-transform-version.d.ts +2 -0
  143. package/dist/types/get-transforms.d.ts +3 -0
  144. package/dist/types/has-transform.d.ts +1 -0
  145. package/dist/types/index.d.ts +0 -1
  146. package/dist/types/main.d.ts +1 -1
  147. package/dist/types/no-transforms-exist-error.d.ts +2 -0
  148. package/dist/types/parse-transform-path.d.ts +2 -0
  149. package/dist/types/presets/migrate-deprecated-icon/utils/mock-deprecated-icons.d.ts +16 -0
  150. package/dist/types/presets/migrate-deprecated-icon/utils/{mock.d.ts → mock-metadata.d.ts} +0 -16
  151. package/dist/types/presets/migrate-icon-object-to-object/utils/create-default-import-declaration.d.ts +1 -0
  152. package/dist/types/presets/migrate-icon-object-to-object/utils/get-new-import-info.d.ts +4 -0
  153. package/dist/types/presets/migrate-icon-object-to-object/utils/kebab-to-pascal-case.d.ts +1 -0
  154. package/dist/types/presets/migrate-icon-object-to-object/utils/parse-icon-object-import.d.ts +4 -0
  155. package/dist/types/presets/migrate-to-link/utils/comments.d.ts +0 -5
  156. package/dist/types/presets/migrate-to-link/utils/generic-unsupported-migration-comment.d.ts +1 -0
  157. package/dist/types/presets/migrate-to-link/utils/style-prop-comment.d.ts +4 -0
  158. package/dist/types/presets/migrate-to-new-buttons/utils/check-if-variant-already-imported.d.ts +2 -0
  159. package/dist/types/presets/migrate-to-new-buttons/utils/{if-variant-already-imported.d.ts → find-variant-already-imported.d.ts} +0 -1
  160. package/dist/types/presets/migrate-to-new-buttons/utils/{generate-link-element.d.ts → generate-link-component.d.ts} +0 -1
  161. package/dist/types/presets/migrate-to-new-buttons/utils/generate-new-element.d.ts +3 -0
  162. package/dist/types/presets/migrate-to-new-buttons/utils/get-icon-attributes.d.ts +2 -0
  163. package/dist/types/presets/migrate-to-new-buttons/utils/get-icon-element.d.ts +2 -0
  164. package/dist/types/presets/migrate-to-new-buttons/utils/handle-icon-attributes.d.ts +2 -0
  165. package/dist/types/presets/migrate-to-new-buttons/utils/modify-button-attributes.d.ts +2 -0
  166. package/dist/types/presets/migrate-to-new-buttons/utils/modify-link-attributes.d.ts +2 -0
  167. package/dist/types/presets/remove-token-fallbacks/after-all.d.ts +2 -0
  168. package/dist/types/presets/remove-token-fallbacks/before-all.d.ts +2 -0
  169. package/dist/types/presets/remove-token-fallbacks/remove-token-fallbacks.d.ts +0 -9
  170. package/dist/types/presets/remove-token-fallbacks/utils/clear-folder.d.ts +1 -0
  171. package/dist/types/presets/remove-token-fallbacks/utils/color-to-hex.d.ts +1 -0
  172. package/dist/types/presets/remove-token-fallbacks/utils/combine-reports.d.ts +1 -0
  173. package/dist/types/presets/remove-token-fallbacks/utils/compare-hex.d.ts +1 -0
  174. package/dist/types/presets/remove-token-fallbacks/utils/is-valid-color.d.ts +1 -0
  175. package/dist/types/presets/remove-token-fallbacks/utils/{reporter.d.ts → write-reports.d.ts} +0 -2
  176. package/dist/types/sinceRef.d.ts +1 -1
  177. package/dist/types/types.d.ts +0 -4
  178. package/dist/types/validation-error.d.ts +2 -0
  179. package/dist/types-ts4.5/get-transform-module.d.ts +2 -0
  180. package/dist/types-ts4.5/get-transform-path.d.ts +2 -0
  181. package/dist/types-ts4.5/get-transform-version.d.ts +2 -0
  182. package/dist/types-ts4.5/get-transforms.d.ts +3 -0
  183. package/dist/types-ts4.5/has-transform.d.ts +1 -0
  184. package/dist/types-ts4.5/index.d.ts +0 -1
  185. package/dist/types-ts4.5/main.d.ts +1 -1
  186. package/dist/types-ts4.5/no-transforms-exist-error.d.ts +2 -0
  187. package/dist/types-ts4.5/parse-transform-path.d.ts +2 -0
  188. package/dist/types-ts4.5/presets/migrate-deprecated-icon/utils/mock-deprecated-icons.d.ts +16 -0
  189. package/dist/types-ts4.5/presets/migrate-deprecated-icon/utils/{mock.d.ts → mock-metadata.d.ts} +0 -16
  190. package/dist/types-ts4.5/presets/migrate-icon-object-to-object/utils/create-default-import-declaration.d.ts +1 -0
  191. package/dist/types-ts4.5/presets/migrate-icon-object-to-object/utils/get-new-import-info.d.ts +4 -0
  192. package/dist/types-ts4.5/presets/migrate-icon-object-to-object/utils/kebab-to-pascal-case.d.ts +1 -0
  193. package/dist/types-ts4.5/presets/migrate-icon-object-to-object/utils/parse-icon-object-import.d.ts +4 -0
  194. package/dist/types-ts4.5/presets/migrate-to-link/utils/comments.d.ts +0 -5
  195. package/dist/types-ts4.5/presets/migrate-to-link/utils/generic-unsupported-migration-comment.d.ts +1 -0
  196. package/dist/types-ts4.5/presets/migrate-to-link/utils/style-prop-comment.d.ts +4 -0
  197. package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/check-if-variant-already-imported.d.ts +2 -0
  198. package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/{if-variant-already-imported.d.ts → find-variant-already-imported.d.ts} +0 -1
  199. package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/{generate-link-element.d.ts → generate-link-component.d.ts} +0 -1
  200. package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/generate-new-element.d.ts +3 -0
  201. package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/get-icon-attributes.d.ts +2 -0
  202. package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/get-icon-element.d.ts +2 -0
  203. package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/handle-icon-attributes.d.ts +2 -0
  204. package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/modify-button-attributes.d.ts +2 -0
  205. package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/modify-link-attributes.d.ts +2 -0
  206. package/dist/types-ts4.5/presets/remove-token-fallbacks/after-all.d.ts +2 -0
  207. package/dist/types-ts4.5/presets/remove-token-fallbacks/before-all.d.ts +2 -0
  208. package/dist/types-ts4.5/presets/remove-token-fallbacks/remove-token-fallbacks.d.ts +0 -9
  209. package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/clear-folder.d.ts +1 -0
  210. package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/color-to-hex.d.ts +1 -0
  211. package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/combine-reports.d.ts +1 -0
  212. package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/compare-hex.d.ts +1 -0
  213. package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/is-valid-color.d.ts +1 -0
  214. package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/{reporter.d.ts → write-reports.d.ts} +0 -2
  215. package/dist/types-ts4.5/sinceRef.d.ts +1 -1
  216. package/dist/types-ts4.5/types.d.ts +0 -4
  217. package/dist/types-ts4.5/validation-error.d.ts +2 -0
  218. package/package.json +4 -4
  219. package/dist/cjs/presets/migrate-icon-object-to-object/utils/icon-mappings.js +0 -81
  220. package/dist/cjs/presets/migrate-to-new-buttons/utils/generate-new-button-element.js +0 -160
  221. package/dist/es2019/presets/migrate-icon-object-to-object/utils/icon-mappings.js +0 -67
  222. package/dist/es2019/presets/migrate-to-new-buttons/utils/generate-new-button-element.js +0 -143
  223. package/dist/esm/presets/migrate-icon-object-to-object/utils/icon-mappings.js +0 -72
  224. package/dist/esm/presets/migrate-to-new-buttons/utils/generate-new-button-element.js +0 -154
  225. package/dist/types/presets/migrate-icon-object-to-object/utils/icon-mappings.d.ts +0 -29
  226. package/dist/types/presets/migrate-to-new-buttons/utils/generate-new-button-element.d.ts +0 -20
  227. package/dist/types/presets/remove-token-fallbacks/utils/color-utils.d.ts +0 -3
  228. package/dist/types/transforms.d.ts +0 -11
  229. package/dist/types-ts4.5/presets/migrate-icon-object-to-object/utils/icon-mappings.d.ts +0 -29
  230. package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/generate-new-button-element.d.ts +0 -20
  231. package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/color-utils.d.ts +0 -3
  232. package/dist/types-ts4.5/transforms.d.ts +0 -11
  233. package/transforms/package.json +0 -14
@@ -0,0 +1,22 @@
1
+ /* eslint-disable @repo/internal/fs/filename-pattern-match */
2
+
3
+ import { ICON_TO_OBJECT_NAME_MAPPINGS } from './constants';
4
+ import { kebabToPascalCase } from './kebab-to-pascal-case';
5
+ export function getNewImportInfo(iconName, size) {
6
+ // Check if this icon name needs to be mapped to a different object name
7
+ var objectName = ICON_TO_OBJECT_NAME_MAPPINGS[iconName] || iconName;
8
+
9
+ // Convert the object name to PascalCase
10
+ var pascalCaseName = kebabToPascalCase(objectName);
11
+ if (size === '16') {
12
+ return {
13
+ importPath: "@atlaskit/object/".concat(objectName),
14
+ componentName: "".concat(pascalCaseName, "Object")
15
+ };
16
+ } else {
17
+ return {
18
+ importPath: "@atlaskit/object/tile/".concat(objectName),
19
+ componentName: "".concat(pascalCaseName, "ObjectTile")
20
+ };
21
+ }
22
+ }
@@ -0,0 +1,7 @@
1
+ /* eslint-disable @repo/internal/fs/filename-pattern-match */
2
+
3
+ export function kebabToPascalCase(str) {
4
+ return str.split('-').map(function (word) {
5
+ return word.charAt(0).toUpperCase() + word.slice(1);
6
+ }).join('');
7
+ }
@@ -0,0 +1,22 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ /* eslint-disable @repo/internal/fs/filename-pattern-match */
3
+
4
+ import { AVAILABLE_ICON_NAMES } from './constants';
5
+ export function parseIconObjectImport(importPath) {
6
+ var match = importPath.match(/^@atlaskit\/icon-object\/glyph\/([^/]+)\/(16|24)$/);
7
+ if (!match) {
8
+ return null;
9
+ }
10
+ var _match = _slicedToArray(match, 3),
11
+ iconName = _match[1],
12
+ size = _match[2];
13
+
14
+ // Check if this is a valid icon name we support
15
+ if (!AVAILABLE_ICON_NAMES.includes(iconName)) {
16
+ return null;
17
+ }
18
+ return {
19
+ iconName: iconName,
20
+ size: size
21
+ };
22
+ }
@@ -1,9 +1,11 @@
1
1
  /* eslint-disable @repo/internal/fs/filename-pattern-match */
2
2
  import { getImportDeclaration } from '@hypermod/utils';
3
3
  import { addCommentBefore } from '@atlaskit/codemod-utils';
4
- import { genericUnsupportedMigrationComment, spreadPropsComment, stylePropComment } from '../utils/comments';
4
+ import { spreadPropsComment } from '../utils/comments';
5
5
  import { LINK_ENTRY_POINT, LINK_EXPORT_NAME, PRINT_SETTINGS, UNSUPPORTED_STYLE_PROPS } from '../utils/constants';
6
6
  import { findJSXAttributeWithValue } from '../utils/find-attribute-with-value';
7
+ import { genericUnsupportedMigrationComment } from '../utils/generic-unsupported-migration-comment';
8
+ import { stylePropComment } from '../utils/style-prop-comment';
7
9
  export default function transformer(file, api) {
8
10
  var j = api.jscodeshift;
9
11
  var source = j(file.source);
@@ -1,12 +1 @@
1
- import { LINK_ENTRY_POINT } from './constants';
2
- export var stylePropComment = function stylePropComment(_ref) {
3
- var propName = _ref.propName,
4
- _ref$prefix = _ref.prefix,
5
- prefix = _ref$prefix === void 0 ? '' : _ref$prefix;
6
- return "".concat(prefix, "This link could not be migrated due to custom styles in `").concat(propName, "` prop.");
7
- };
8
- export var spreadPropsComment = "This link could not be migrated due to usage of spread props. The codemod cannot determine the props being spread. Please manually migrate.";
9
- export var genericUnsupportedMigrationComment = function genericUnsupportedMigrationComment() {
10
- var prefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
11
- return "".concat(prefix, "- If this is a simple text-based link, replace with `").concat(LINK_ENTRY_POINT, "`.\n").concat(prefix, "- If this is a button-like link style, replace with a link button from `@atlaskit/button`.\n").concat(prefix, "- If this needs to retain custom styles, use the `Anchor` primitive from `@atlaskit/primitives`.");
12
- };
1
+ export var spreadPropsComment = "This link could not be migrated due to usage of spread props. The codemod cannot determine the props being spread. Please manually migrate.";
@@ -0,0 +1,5 @@
1
+ import { LINK_ENTRY_POINT } from './constants';
2
+ export var genericUnsupportedMigrationComment = function genericUnsupportedMigrationComment() {
3
+ var prefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
4
+ return "".concat(prefix, "- If this is a simple text-based link, replace with `").concat(LINK_ENTRY_POINT, "`.\n").concat(prefix, "- If this is a button-like link style, replace with a link button from `@atlaskit/button`.\n").concat(prefix, "- If this needs to retain custom styles, use the `Anchor` primitive from `@atlaskit/primitives`.");
5
+ };
@@ -0,0 +1,6 @@
1
+ export var stylePropComment = function stylePropComment(_ref) {
2
+ var propName = _ref.propName,
3
+ _ref$prefix = _ref.prefix,
4
+ prefix = _ref$prefix === void 0 ? '' : _ref$prefix;
5
+ return "".concat(prefix, "This link could not be migrated due to custom styles in `").concat(propName, "` prop.");
6
+ };
@@ -3,7 +3,7 @@ import { getImportDeclaration } from '@hypermod/utils';
3
3
  import { addCommentBefore } from '@atlaskit/codemod-utils';
4
4
  import { migrateButtonToSubtleLinkButton, migrateSubtleButtonToSubtleLinkButton, NEW_BUTTON_ENTRY_POINT, NEW_BUTTON_VARIANTS, PRINT_SETTINGS } from '../utils/constants';
5
5
  import { findJSXAttributeWithValue } from '../utils/find-attribute-with-value';
6
- import { modifyLinkAttributes } from '../utils/generate-link-element';
6
+ import { modifyLinkAttributes } from '../utils/modify-link-attributes';
7
7
  import moveIconValueFromLinkButtonPropsToLinkChildren from '../utils/move-icon-value-from-link-button-to-link-children';
8
8
  function transformer(file, api) {
9
9
  var j = api.jscodeshift;
@@ -4,16 +4,18 @@ import { getDefaultImportSpecifierName } from '@hypermod/utils';
4
4
  import { addCommentBefore } from '@atlaskit/codemod-utils';
5
5
  import { addCommentForCustomThemeButtons } from '../utils/add-comment-for-custom-theme-buttons';
6
6
  import { addCommentForOverlayProp } from '../utils/add-comment-for-overlay-prop';
7
+ import { checkIfVariantAlreadyImported } from '../utils/check-if-variant-already-imported';
7
8
  import { buttonPropsNoLongerSupportedComment, entryPointsMapping, linkButtonMissingHrefComment, loadingButtonComment, migrateButtonToSubtleLinkButton, migrateSubtleButtonToSubtleLinkButton, NEW_BUTTON_ENTRY_POINT, NEW_BUTTON_VARIANTS, noSpacinglinkButtonMissingHrefComment, OLD_BUTTON_ENTRY_POINT, OLD_BUTTON_VARIANTS, PRINT_SETTINGS, unsupportedProps } from '../utils/constants';
8
9
  import { findJSXAttributeWithValue } from '../utils/find-attribute-with-value';
9
- import { generateLinkComponent } from '../utils/generate-link-element';
10
- import { generateNewElement, handleIconAttributes, modifyButtonAttributes } from '../utils/generate-new-button-element';
10
+ import { generateLinkComponent } from '../utils/generate-link-component';
11
+ import { generateNewElement } from '../utils/generate-new-element';
11
12
  import getDefaultImports from '../utils/get-default-imports';
12
13
  import getSpecifierNames from '../utils/get-specifier-names';
14
+ import { handleIconAttributes } from '../utils/handle-icon-attributes';
13
15
  import { ifHasUnsupportedProps } from '../utils/has-unsupported-props';
14
- import { checkIfVariantAlreadyImported } from '../utils/if-variant-already-imported';
15
16
  import { importTypesFromNewEntryPoint } from '../utils/import-types-from-new-entry-point';
16
17
  import { migrateFitContainerIconButton } from '../utils/migrate-fit-container-icon-button';
18
+ import { modifyButtonAttributes } from '../utils/modify-button-attributes';
17
19
  import { renameDefaultButtonToLegacyButtonImport } from '../utils/rename-default-button-to-legacy-button';
18
20
  var transformer = function transformer(file, api) {
19
21
  var j = api.jscodeshift;
@@ -0,0 +1,5 @@
1
+ import { findVariantAlreadyImported } from './find-variant-already-imported';
2
+ export var checkIfVariantAlreadyImported = function checkIfVariantAlreadyImported(variant, entryPoint, fileSource, j) {
3
+ var isDefaultSpecifier = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
4
+ return findVariantAlreadyImported(variant, entryPoint, fileSource, j, isDefaultSpecifier).length > 0;
5
+ };
@@ -9,8 +9,4 @@ export var findVariantAlreadyImported = function findVariantAlreadyImported(vari
9
9
  return imports.find(j.ImportSpecifier).filter(function (path) {
10
10
  return path.node.imported.name === variant;
11
11
  });
12
- };
13
- export var checkIfVariantAlreadyImported = function checkIfVariantAlreadyImported(variant, entryPoint, fileSource, j) {
14
- var isDefaultSpecifier = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
15
- return findVariantAlreadyImported(variant, entryPoint, fileSource, j, isDefaultSpecifier).length > 0;
16
12
  };
@@ -1,13 +1,4 @@
1
- export var modifyLinkAttributes = function modifyLinkAttributes(element, j) {
2
- j(element).find(j.JSXAttribute).filter(function (path) {
3
- var _path$node$value, _path$node$value2;
4
- return path.node.name.name === 'appearance' && ((_path$node$value = path.node.value) === null || _path$node$value === void 0 ? void 0 : _path$node$value.type) === 'StringLiteral' && path.node.value.value === 'link' || path.node.name.name === 'spacing' && ((_path$node$value2 = path.node.value) === null || _path$node$value2 === void 0 ? void 0 : _path$node$value2.type) === 'StringLiteral' && path.node.value.value === 'none';
5
- }).remove();
6
- j(element).find(j.JSXAttribute).filter(function (path) {
7
- var _path$node$value3;
8
- return path.node.name.name === 'appearance' && ((_path$node$value3 = path.node.value) === null || _path$node$value3 === void 0 ? void 0 : _path$node$value3.type) === 'StringLiteral' && path.node.value.value === 'subtle-link';
9
- }).replaceWith(j.jsxAttribute(j.jsxIdentifier('appearance'), j.stringLiteral('subtle')));
10
- };
1
+ import { modifyLinkAttributes } from './modify-link-attributes';
11
2
  export var generateLinkComponent = function generateLinkComponent(element, j) {
12
3
  var attributes = element.openingElement.attributes;
13
4
  if (!element.children) {
@@ -0,0 +1,41 @@
1
+ import { NEW_BUTTON_VARIANTS } from './constants';
2
+ import { getIconAttributes } from './get-icon-attributes';
3
+ import { handleIconAttributes } from './handle-icon-attributes';
4
+ export var generateNewElement = function generateNewElement(variant, element, j) {
5
+ var attributes = element.openingElement.attributes;
6
+ var iconAttrs = attributes && getIconAttributes(attributes);
7
+ var isIconOrLinkIcon = variant === NEW_BUTTON_VARIANTS.icon || variant === NEW_BUTTON_VARIANTS.linkIcon;
8
+ if (variant === NEW_BUTTON_VARIANTS.link) {
9
+ j(element).find(j.JSXAttribute).filter(function (path) {
10
+ var _path$node$value;
11
+ return path.node.name.name === 'appearance' && ((_path$node$value = path.node.value) === null || _path$node$value === void 0 ? void 0 : _path$node$value.type) === 'StringLiteral' && (path.node.value.value === 'subtle-link' || path.node.value.value === 'link');
12
+ }).replaceWith(j.jsxAttribute(j.jsxIdentifier('appearance'), j.stringLiteral('subtle')));
13
+ }
14
+ if (isIconOrLinkIcon && iconAttrs !== null && iconAttrs !== void 0 && iconAttrs.length) {
15
+ handleIconAttributes(element, j, true);
16
+
17
+ // rename iconBefore/iconAfter to icon
18
+ iconAttrs[0].name.name = 'icon';
19
+ var ariaLabelAttr = j(element.openingElement).find(j.JSXAttribute).filter(function (attribute) {
20
+ return attribute.node.name.name === 'aria-label';
21
+ });
22
+ if (ariaLabelAttr.length) {
23
+ var hasNoLabelProp = !(attributes !== null && attributes !== void 0 && attributes.find(function (attribute) {
24
+ return attribute.type === 'JSXAttribute' && attribute.name.name === 'label';
25
+ }));
26
+ if (hasNoLabelProp && attributes) {
27
+ attributes.unshift(j.jsxAttribute.from({
28
+ name: j.jsxIdentifier('label'),
29
+ value: j.literal(ariaLabelAttr.get().value.value.value)
30
+ }));
31
+ }
32
+ ariaLabelAttr.remove();
33
+ }
34
+ }
35
+ return j.jsxElement.from({
36
+ openingElement: j.jsxOpeningElement(j.jsxIdentifier(variant), attributes, isIconOrLinkIcon),
37
+ // self closing if it's an icon button or icon link button
38
+ closingElement: isIconOrLinkIcon ? null : j.jsxClosingElement(j.jsxIdentifier(variant)),
39
+ children: element.children
40
+ });
41
+ };
@@ -0,0 +1,9 @@
1
+ export var getIconAttributes = function getIconAttributes(attributes) {
2
+ var iconAttr = attributes === null || attributes === void 0 ? void 0 : attributes.filter(function (attribute) {
3
+ return attribute.type === 'JSXAttribute' && (attribute.name.name === 'iconBefore' || attribute.name.name === 'iconAfter');
4
+ });
5
+ if (iconAttr !== null && iconAttr !== void 0 && iconAttr.length) {
6
+ return iconAttr;
7
+ }
8
+ return null;
9
+ };
@@ -0,0 +1,7 @@
1
+ export var getIconElement = function getIconElement(iconAttr) {
2
+ var _iconAttr$value;
3
+ if (iconAttr && ((_iconAttr$value = iconAttr.value) === null || _iconAttr$value === void 0 ? void 0 : _iconAttr$value.type) === 'JSXExpressionContainer' && iconAttr.value.expression.type === 'JSXElement') {
4
+ return iconAttr.value.expression;
5
+ }
6
+ return null;
7
+ };
@@ -0,0 +1,75 @@
1
+ import { getIconAttributes } from './get-icon-attributes';
2
+ import { getIconElement } from './get-icon-element';
3
+ export var handleIconAttributes = function handleIconAttributes(element, j) {
4
+ var iconRenamed = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
5
+ var buttonAttributes = element.openingElement.attributes;
6
+ // Get iconBefore and iconAfter attributes
7
+ var buttonIconAttributes = buttonAttributes && getIconAttributes(buttonAttributes);
8
+ buttonIconAttributes === null || buttonIconAttributes === void 0 || buttonIconAttributes.forEach(function (iconAttribute) {
9
+ var iconElement = getIconElement(iconAttribute);
10
+ if (!iconElement) {
11
+ return;
12
+ }
13
+ var iconAttributes = iconElement.openingElement.attributes;
14
+ if (!Array.isArray(iconAttributes)) {
15
+ return;
16
+ }
17
+
18
+ // 1. Move label to root button element, only if label doesn't exist already. Button label
19
+ // takes precedence over icon label.
20
+
21
+ var buttonAlreadyHasLabelProp = buttonAttributes === null || buttonAttributes === void 0 ? void 0 : buttonAttributes.find(function (buttonAttribute) {
22
+ return buttonAttribute.type === 'JSXAttribute' && buttonAttribute.name.name === 'label';
23
+ });
24
+ var buttonAlreadyHasAriaLabelProp = buttonAttributes === null || buttonAttributes === void 0 ? void 0 : buttonAttributes.find(function (buttonAttribute) {
25
+ return buttonAttribute.type === 'JSXAttribute' && buttonAttribute.name.name === 'aria-label';
26
+ });
27
+ if (!buttonAlreadyHasLabelProp && !buttonAlreadyHasAriaLabelProp) {
28
+ var labelAttribute = iconAttributes.find(function (attribute) {
29
+ return attribute.type === 'JSXAttribute' && attribute.name.name === 'label';
30
+ });
31
+ if (labelAttribute && labelAttribute.type === 'JSXAttribute' && iconRenamed) {
32
+ buttonAttributes === null || buttonAttributes === void 0 || buttonAttributes.unshift(labelAttribute);
33
+ }
34
+ }
35
+
36
+ // 2. If there are any other props on icon, move to render prop
37
+ var attributesOtherThanLabelOrMediumSize = iconAttributes.filter(function (iconAttribute) {
38
+ var _iconAttribute$value, _iconAttribute$value2;
39
+ // Exclude size="medium"
40
+ if (iconAttribute.type === 'JSXAttribute' && iconAttribute.name.name === 'size' && ((_iconAttribute$value = iconAttribute.value) === null || _iconAttribute$value === void 0 ? void 0 : _iconAttribute$value.type) === 'StringLiteral' && ((_iconAttribute$value2 = iconAttribute.value) === null || _iconAttribute$value2 === void 0 ? void 0 : _iconAttribute$value2.value) === 'medium') {
41
+ return false;
42
+ }
43
+
44
+ // Exclude label
45
+ if (iconAttribute.type === 'JSXAttribute' && iconAttribute.name.name === 'label') {
46
+ return false;
47
+ }
48
+ return true;
49
+ });
50
+ if (attributesOtherThanLabelOrMediumSize.length > 0) {
51
+ // Move to render prop: `<MoreIcon primaryColor />` -> `(props) => <MoreIcon {...props} primaryColor />`
52
+
53
+ // Remove label and size="medium" attributes
54
+ j(iconElement.openingElement).find(j.JSXAttribute).filter(function (attribute) {
55
+ return attribute.value.name.name === 'label' || attribute.value.type === 'JSXAttribute' && attribute.value.name.name === 'size' && attribute.value.value && attribute.value.value.type === 'StringLiteral' && attribute.value.value.value === 'medium' || false;
56
+ }).remove();
57
+
58
+ // Add spread props
59
+ iconAttributes.unshift(j.jsxSpreadAttribute(j.identifier('iconProps')));
60
+
61
+ // Create new arrow function (renderProp)
62
+ iconAttribute.value = j.jsxExpressionContainer(j.arrowFunctionExpression.from({
63
+ params: [j.identifier('iconProps')],
64
+ body: iconElement,
65
+ expression: true
66
+ }));
67
+ } else {
68
+ var _iconAttribute$value3;
69
+ // Move to bounded API: {<MoreIcon />} => {MoreIcon}
70
+ if (iconElement.openingElement.name.type === 'JSXIdentifier' && ((_iconAttribute$value3 = iconAttribute.value) === null || _iconAttribute$value3 === void 0 ? void 0 : _iconAttribute$value3.type) === 'JSXExpressionContainer') {
71
+ iconAttribute.value.expression = j.identifier(iconElement.openingElement.name.name);
72
+ }
73
+ }
74
+ });
75
+ };
@@ -1,6 +1,7 @@
1
1
  import { addCommentBefore } from '@atlaskit/codemod-utils';
2
- import { getIconAttributes, getIconElement } from '../utils/generate-new-button-element';
3
2
  import { migrateFitContainerButtonToDefaultButtonComment, migrateFitContainerButtonToIconButtonComment, NEW_BUTTON_VARIANTS } from './constants';
3
+ import { getIconAttributes } from './get-icon-attributes';
4
+ import { getIconElement } from './get-icon-element';
4
5
  export var migrateFitContainerIconButton = function migrateFitContainerIconButton(element, j) {
5
6
  var _iconElement$openingE, _labelAttribute$value;
6
7
  var attributes = element.value.openingElement.attributes;
@@ -0,0 +1,12 @@
1
+ export var modifyButtonAttributes = function modifyButtonAttributes(element, j, hasSpacingNone) {
2
+ j(element).find(j.JSXAttribute).filter(function (path) {
3
+ var _path$node$value;
4
+ return path.node.name.name === 'appearance' && ((_path$node$value = path.node.value) === null || _path$node$value === void 0 ? void 0 : _path$node$value.type) === 'StringLiteral' && (path.node.value.value === 'link' || path.node.value.value === 'subtle-link');
5
+ }).replaceWith(j.jsxAttribute(j.jsxIdentifier('appearance'), j.stringLiteral('subtle')));
6
+ if (hasSpacingNone) {
7
+ j(element).find(j.JSXAttribute).filter(function (path) {
8
+ var _path$node$value2;
9
+ return path.node.name.name === 'spacing' && ((_path$node$value2 = path.node.value) === null || _path$node$value2 === void 0 ? void 0 : _path$node$value2.type) === 'StringLiteral' && path.node.value.value === 'none';
10
+ }).remove();
11
+ }
12
+ };
@@ -0,0 +1,10 @@
1
+ export var modifyLinkAttributes = function modifyLinkAttributes(element, j) {
2
+ j(element).find(j.JSXAttribute).filter(function (path) {
3
+ var _path$node$value, _path$node$value2;
4
+ return path.node.name.name === 'appearance' && ((_path$node$value = path.node.value) === null || _path$node$value === void 0 ? void 0 : _path$node$value.type) === 'StringLiteral' && path.node.value.value === 'link' || path.node.name.name === 'spacing' && ((_path$node$value2 = path.node.value) === null || _path$node$value2 === void 0 ? void 0 : _path$node$value2.type) === 'StringLiteral' && path.node.value.value === 'none';
5
+ }).remove();
6
+ j(element).find(j.JSXAttribute).filter(function (path) {
7
+ var _path$node$value3;
8
+ return path.node.name.name === 'appearance' && ((_path$node$value3 = path.node.value) === null || _path$node$value3 === void 0 ? void 0 : _path$node$value3.type) === 'StringLiteral' && path.node.value.value === 'subtle-link';
9
+ }).replaceWith(j.jsxAttribute(j.jsxIdentifier('appearance'), j.stringLiteral('subtle')));
10
+ };