-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
[code-infra] Prevent wrong nested imports in Base UI #44426
base: master
Are you sure you want to change the base?
Conversation
f8c378c
to
f2f1986
Compare
Netlify deploy previewhttps://deploy-preview-44426--material-ui.netlify.app/ Bundle size report |
Once mui/base-ui#821 is merged, importing private utilities won't be possible, so these rules will become obsolete. |
@michaldudak I'm not seeing this. Not being possible to import files that are not in the I guess TypeScript would statically report when imports are wrong, replacing eslint there. |
Could you explain what you mean? With the |
@michaldudak but this won't prevent us to make: import bar from '@base-ui-components/react/tree-view/bar'; a valid import. I assume that we don't want to allow anything else other than one-level deep imports. Or at least, not without the pain of disabling the rule in specific instances. There were discussions related to this at mui/mui-x#10920. Maybe we should approach this like this:
import { frFR } from '@mui/x-date-pickers/locales/frFR';
import { frFR } from '@mui/x-date-pickers/locales/frFR'; because it's likely a better DX than: import { frFR } from '@mui/x-date-pickers/locales-frFR'; |
It will. If only ./tree-view is present in package.json exports, nothing else from it will be possible to be imported. I created a project for testing the new package layout with the exports field: https://github.com/michaldudak/base-ui-bundler-tests. It uses a build from mui/base-ui#821. "exports": {
".": {
"require": {
"types": "./cjs/index.d.ts",
"default": "./cjs/index.js"
},
"import": {
"types": "./esm/index.d.ts",
"default": "./esm/index.js"
}
},
"./*": {
"require": {
"types": "./cjs/*/index.d.ts",
"default": "./cjs/*/index.js"
},
"import": {
"types": "./esm/*/index.d.ts",
"default": "./esm/*/index.js"
}
}
} Makes only top-level identifiers importable from other projects. So for example this fails: import { useMenuItem } from '@base-ui-components/react/Menu/Item/useMenuItem' |
@michaldudak Agree with this. I was probably not clear enough, I think the discussion is about the value of having fail safes, i.e. what happens if someone go to the package.json and manually add a to the exports field a deep .js module? This eslint rule can catch it. |
If someone makes the effort to include the deeply nested identifier in |
@michaldudak We have to have all exports in
I'm missing something: If an npm package exports a module, in the same repository, a docs or test should exists for it, given that we don't allow relative imports for tests and docs, the eslint rule would catch it in the same PR, so it works? |
I fail to see why we need a convention when we have a proper tool for making identifiers public.
It's not necessarily more effort, but it has to be done intentionally. |
Reflect mui/base-ui#488 and mui/base-ui#805.