Skip to content

Commit d027d4c

Browse files
authored
feat(codemods): add named-exports codemod to convert default imports to named imports (#3162)
* chore: add named exports to mostly all packages * feat(codemods): add import-related utils * feat(codemods): add named-exports codemod * docs(codemods): named-exports * chore: changesets * test(codemods): fix output test and rm redundant test
1 parent 519ee28 commit d027d4c

File tree

42 files changed

+610
-19
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+610
-19
lines changed

.changeset/moody-sites-relate.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@lg-tools/codemods': minor
3+
---
4+
5+
Add `named-exports` codemod for migrating LG package default exports to named exports. [codemods README](https://github.com/mongodb/leafygreen-ui/tree/main/tools/codemods#named-exports)

.changeset/yummy-glasses-switch.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
'@leafygreen-ui/confirmation-modal': minor
3+
'@leafygreen-ui/inline-definition': minor
4+
'@leafygreen-ui/expandable-card': minor
5+
'@leafygreen-ui/marketing-modal': minor
6+
'@leafygreen-ui/form-footer': minor
7+
'@leafygreen-ui/icon-button': minor
8+
'@leafygreen-ui/pagination': minor
9+
'@leafygreen-ui/text-input': minor
10+
'@leafygreen-ui/text-area': minor
11+
'@leafygreen-ui/checkbox': minor
12+
'@leafygreen-ui/copyable': minor
13+
'@leafygreen-ui/callout': minor
14+
'@leafygreen-ui/popover': minor
15+
'@leafygreen-ui/stepper': minor
16+
'@leafygreen-ui/tooltip': minor
17+
'@leafygreen-ui/button': minor
18+
'@leafygreen-ui/portal': minor
19+
'@leafygreen-ui/toggle': minor
20+
'@leafygreen-ui/badge': minor
21+
'@leafygreen-ui/modal': minor
22+
'@leafygreen-ui/card': minor
23+
'@leafygreen-ui/code': minor
24+
'@leafygreen-ui/icon': minor
25+
'@leafygreen-ui/logo': minor
26+
---
27+
28+
Mark default export as deprecated and add named export if missing. See [named-exports codemod documentation](https://github.com/mongodb/leafygreen-ui/tree/main/tools/codemods#named-exports) for migration assistance.

packages/badge/src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
import Badge from './Badge/Badge';
22
export { type BadgeProps, Variant } from './Badge/Badge.types';
3+
4+
/**
5+
* @deprecated Use named export `{ Badge }` instead. See [named-exports codemod documentation](https://github.com/mongodb/leafygreen-ui/tree/main/tools/codemods#named-exports) for migration assistance.
6+
*/
37
export default Badge;
8+
9+
export { Badge };

packages/button/src/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1-
export { Button as default } from './Button';
1+
export {
2+
Button,
3+
/**
4+
* @deprecated Use named export `{ Button }` instead. See [named-exports codemod documentation](https://github.com/mongodb/leafygreen-ui/tree/main/tools/codemods#named-exports) for migration assistance.
5+
*/
6+
Button as default,
7+
} from './Button';
28
export type { BaseButtonProps, ButtonProps } from './types';
39
export { FontSize, Size, Variant } from './types';

packages/callout/src/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
1-
export { default } from './Callout/Callout';
1+
export {
2+
default as Callout,
3+
/**
4+
* @deprecated Use named export `{ Callout }` instead. See [named-exports codemod documentation](https://github.com/mongodb/leafygreen-ui/tree/main/tools/codemods#named-exports) for migration assistance.
5+
*/
6+
default,
7+
} from './Callout/Callout';
28
export { type CalloutProps, Variant } from './Callout/Callout.types';

packages/card/src/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
export { type CardProps, ContentStyle } from './Card';
2-
export { Card as default } from './Card';
2+
export {
3+
Card,
4+
/**
5+
* @deprecated Use named export `{ Card }` instead. See [named-exports codemod documentation](https://github.com/mongodb/leafygreen-ui/tree/main/tools/codemods#named-exports) for migration assistance.
6+
*/
7+
Card as default,
8+
} from './Card';

packages/checkbox/src/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
export { type CheckboxProps, checkWrapperClassName, default } from './Checkbox';
1+
export {
2+
default as Checkbox,
3+
type CheckboxProps,
4+
checkWrapperClassName,
5+
/**
6+
* @deprecated Use named export `{ Checkbox }` instead. See [named-exports codemod documentation](https://github.com/mongodb/leafygreen-ui/tree/main/tools/codemods#named-exports) for migration assistance.
7+
*/
8+
default,
9+
} from './Checkbox';
210
export {
311
DEFAULT_LGID_ROOT,
412
getLgIds,

packages/code/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@ export type { SyntaxProps } from './Syntax/Syntax.types';
99
export type { LineHighlightingDefinition } from './types';
1010
export { Language } from './types';
1111
export { getLgIds, type GetLgIdsReturnType } from './utils';
12+
/**
13+
* @deprecated Use named export `{ Code }` instead. See [named-exports codemod documentation](https://github.com/mongodb/leafygreen-ui/tree/main/tools/codemods#named-exports) for migration assistance.
14+
*/
1215
export default Code;

packages/confirmation-modal/src/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
export { ConfirmationModal as default } from './ConfirmationModal/ConfirmationModal';
1+
export {
2+
ConfirmationModal,
3+
/**
4+
* @deprecated Use named export `{ ConfirmationModal }` instead. See [named-exports codemod documentation](https://github.com/mongodb/leafygreen-ui/tree/main/tools/codemods#named-exports) for migration assistance.
5+
*/
6+
ConfirmationModal as default,
7+
} from './ConfirmationModal/ConfirmationModal';
28
export {
39
type ConfirmationModalProps,
410
Variant,

packages/copyable/src/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
1-
export { default } from './Copyable';
1+
export {
2+
default as Copyable,
3+
/**
4+
* @deprecated Use named export `{ Copyable }` instead. See [named-exports codemod documentation](https://github.com/mongodb/leafygreen-ui/tree/main/tools/codemods#named-exports) for migration assistance.
5+
*/
6+
default,
7+
} from './Copyable';
28
export { type CopyableProps, Size } from './Copyable';

0 commit comments

Comments
 (0)