-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[base] Ban default exports #38200
[base] Ban default exports #38200
Conversation
319e1f7
to
10a9302
Compare
dfc6853
to
ef4da86
Compare
cfce889
to
3b6e9b2
Compare
packages/mui-codemod/README.md
Outdated
@@ -62,6 +62,22 @@ npx @mui/codemod <transform> <path> --jscodeshift="--printOptions='{\"quote\":\" | |||
|
|||
### v5.0.0 | |||
|
|||
### `base-use-named-imports` | |||
|
|||
Base UI default exports were changed to named ones. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be great to add a bit of explanation of why it was done.
return null; | ||
} | ||
|
||
const baseImportPathMatch = source.match(/@mui\/base\/(?:(?:.*)\/)*([^/]+)/); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we simplify the regexp? We don't nest imports more than three times. Or is there other use-case we are trying to capture with it?
import BaseSwitch from '@mui/base/Switch'; | ||
import BaseSelect, { selectClasses } from '@mui/base/Select'; | ||
import { Menu, MenuItem } from '@mui/base'; | ||
import ClassNameConfigurator from '@mui/base/utils/ClassNameConfigurator'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say this is not a valid import. We are leaking internal API. By convention we don't allow these imports and consider them private API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Excluding this will simplify the codemod code.
|
||
export { default as ClickAwayListener } from './ClickAwayListener'; | ||
|
||
export { default as unstable_composeClasses } from './composeClasses'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This export is missing as far as I can see. We should check the unstable_
exports with the codemod. They are unstable_
but people may use them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The codemod isn't responsible for this part, it only covers exports from @mui/base
, not local.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, but we should add back the export, right?
We should check all frozen sandboxes we have in case they have default Base UI imports. cc @samuelsycamore |
packages/mui-base/src/index.d.ts
Outdated
@@ -2,7 +2,7 @@ export * from './utils'; | |||
export * from './Badge'; | |||
export * from './Button'; | |||
export * from './ClickAwayListener'; | |||
export * from './composeClasses'; | |||
export { composeClasses as unstable_composeClasses } from './composeClasses'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We likely need a map for the unstable_
utils.
@@ -8,12 +8,13 @@ import { | |||
unstable_useForkRef as useForkRef, | |||
unstable_capitalize as capitalize, | |||
} from '@mui/utils'; | |||
import composeClasses from '@mui/base/composeClasses'; | |||
import useAutocomplete, { | |||
import { composeClasses } from '@mui/base/composeClasses'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be unstable_composeClasses as composeClasses
?
|
||
let node: babel.Node = babelPath.node; | ||
|
||
if (node.declaration == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this going to work with the Unstable_NumberInput
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It shouldn't matter as the component is exported as NumberInput
from its source file. The "unstable_" prefix is added in its index.ts, which this script doesn't care about.
There is an issue with the API imports generation, for non default imports: Looks like there was a different issue even before, for e.g. https://mui.com/base-ui/react-form-control/hooks-api/#use-form-control-context |
3b6e9b2
to
7422f23
Compare
4c4672f
to
1c7e673
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good 👍
@@ -15,4 +15,4 @@ export { default as useControlled } from './useControlled'; | |||
export { default as useEventCallback } from './useEventCallback'; | |||
export { default as useForkRef } from './useForkRef'; | |||
export { default as useIsFocusVisible } from './useIsFocusVisible'; | |||
export { unstable_ClassNameGenerator } from '@mui/base/className'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should list this in the Breaking changes section.
This PR changes the default exports in Base UI to named ones. The name of the previously default export matches the file name.
Along with the changes in code, I created additional logic in API docs builders and a codemod.
Breaking change
All exports from Base UI are named:
Additionally, the
ClassNameGenerator
has been moved to the directory matching its name:A codemod is provided to help with the migration:
To reviewers: please review by commit. The codemod was tested by running it on our codebase, but I'd also appreciate it if you could think of any other cases that could be verified in its tests.
Part of #21862 (comment)