Skip to content
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

[core] Allow deeper import of @mui/utils #38806

Merged
merged 7 commits into from
Sep 16, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,6 @@ module.exports = {
{
patterns: [
'@mui/*/*/*',
// Begin block: Packages with files instead of packages in the top level
// Importing from the top level pulls in CommonJS instead of ES modules
// Allowing /icons as to reduce cold-start of dev builds significantly.
// There's nothing to tree-shake when importing from /icons this way:
// '@mui/icons-material/*/',
'@mui/utils/*',
// End block
Comment on lines -70 to -76
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the pattern we want to allow, removing.

// Macros are fine since their import path is transpiled away
'!@mui/utils/macros',
'@mui/utils/macros/*',
Expand Down Expand Up @@ -333,7 +326,7 @@ module.exports = {
'error',
{
patterns: [
// Allow deeper imports for TypeScript types. TODO?
// Allow deeper imports for TypeScript types. TODO remove
'@mui/*/*/*/*',
Comment on lines -336 to 330
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Types should be exposed at the same level as the other modules.

// Macros are fine since they're transpiled into something else
'!@mui/utils/macros/*.macro',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import { useAutocomplete } from '@mui/base/useAutocomplete';
import { Popper } from '@mui/base/Popper';
import { styled } from '@mui/system';
import { unstable_useForkRef as useForkRef } from '@mui/utils';
import useForkRef from '@mui/utils/useForkRef';

const Autocomplete = React.forwardRef(function Autocomplete(props, ref) {
const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import { useAutocomplete, UseAutocompleteProps } from '@mui/base/useAutocomplete';
import { Popper } from '@mui/base/Popper';
import { styled } from '@mui/system';
import { unstable_useForkRef as useForkRef } from '@mui/utils';
import useForkRef from '@mui/utils/useForkRef';

const Autocomplete = React.forwardRef(function Autocomplete(
props: UseAutocompleteProps<(typeof top100Films)[number], false, false, false>,
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-base/src/FormControl/FormControl.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client';
import * as React from 'react';
import PropTypes from 'prop-types';
import { unstable_useControlled as useControlled } from '@mui/utils';
import useControlled from '@mui/utils/useControlled';
import { PolymorphicComponent } from '../utils/PolymorphicComponent';
import { FormControlContext } from './FormControlContext';
import { getFormControlUtilityClass } from './formControlClasses';
Expand Down
3 changes: 2 additions & 1 deletion packages/mui-base/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
"rootDir": "./src"
},
"include": ["src/**/*.ts*"],
"exclude": ["src/**/*.spec.ts*", "src/**/*.test.ts*"]
"exclude": ["src/**/*.spec.ts*", "src/**/*.test.ts*"],
"references": [{ "path": "../mui-utils/tsconfig.build.json" }]
}
4 changes: 4 additions & 0 deletions packages/mui-material/scripts/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ const nestedFolder = {
return resolveNestedImport('mui-base', importee);
}

if (importee.indexOf('@mui/utils/') === 0) {
return resolveNestedImport('mui-utils', importee);
}

if (importee.indexOf('@mui/private-theming/') === 0) {
return resolveNestedImport('mui-private-theming', importee);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { unstable_generateUtilityClasses as generateUtilityClasses } from '@mui/utils';
import generateUtilityClasses from '@mui/utils/generateUtilityClasses';
import generateUtilityClass from '../generateUtilityClass';

export interface ListSubheaderClasses {
Expand Down
3 changes: 2 additions & 1 deletion packages/mui-system/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
"rootDir": "./src"
},
"include": ["src/**/*.ts*"],
"exclude": ["src/**/*.spec.ts*", "src/**/*.test.ts*"]
"exclude": ["src/**/*.spec.ts*", "src/**/*.test.ts*"],
"references": [{ "path": "../mui-utils/tsconfig.build.json" }]
}
5 changes: 5 additions & 0 deletions packages/mui-utils/src/integerPropType.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import PropTypes from 'prop-types';

declare const integerPropType: PropTypes.Requireable<number>;

export default integerPropType;
1 change: 1 addition & 0 deletions packages/mui-utils/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Actual .ts source files are transpiled via babel
"extends": "./tsconfig.json",
"compilerOptions": {
"composite": true,
Copy link
Member Author

@oliviertassinari oliviertassinari Sep 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should aim to introduce this flag on all our projects (after we deal with circular references) to speed up the build times.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, I wrote a typo: with without.

"declaration": true,
"noEmit": false,
"emitDeclarationOnly": true,
Expand Down
2 changes: 2 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
"@mui/types": ["./packages/mui-types"],
"@mui/base": ["./packages/mui-base/src"],
"@mui/base/*": ["./packages/mui-base/src/*"],
"@mui/utils": ["./packages/mui-utils/src"],
"@mui/utils/*": ["./packages/mui-utils/src/*"],
"@mui/docs": ["./packages/mui-docs/src"],
"@mui/docs/*": ["./packages/mui-docs/src/*"],
"@mui/material-next": ["./packages/mui-material-next/src"],
Expand Down