diff --git a/babel.config.js b/babel.config.js index 4d49a519eca6..6d812eba0163 100644 --- a/babel.config.js +++ b/babel.config.js @@ -1,6 +1,16 @@ +// @ts-check const path = require('path'); const generateReleaseInfo = require('./packages/x-license/generateReleaseInfo'); +/** + * @typedef {import('@babel/core')} babel + */ + +/** + * + * @param {string} relativeToBabelConf + * @returns {string} + */ function resolveAliasPath(relativeToBabelConf) { const resolvedPath = path.relative(process.cwd(), path.resolve(__dirname, relativeToBabelConf)); return `./${resolvedPath.replace('\\', '/')}`; @@ -33,6 +43,7 @@ const productionPlugins = [ ['babel-plugin-react-remove-properties', { properties: ['data-mui-test'] }], ]; +/** @type {babel.ConfigFunction} */ module.exports = function getBabelConfig(api) { const useESModules = api.env(['modern', 'stable', 'rollup']); @@ -56,6 +67,16 @@ module.exports = function getBabelConfig(api) { '@babel/preset-typescript', ]; + const usesAliases = + // in this config: + api.env(['coverage', 'development', 'test', 'benchmark']) || + process.env.NODE_ENV === 'test' || + // in webpack config: + api.env(['regressions']); + + const outFileExtension = '.js'; + + /** @type {babel.PluginItem[]} */ const plugins = [ 'babel-plugin-optimize-clsx', // Need the following 3 transforms for all targets in .browserslistrc. @@ -125,6 +146,17 @@ module.exports = function getBabelConfig(api) { } } + if (useESModules) { + plugins.push([ + '@mui/internal-babel-plugin-resolve-imports', + { + // Don't replace the extension when we're using aliases. + // Essentially only replace in production builds. + outExtension: usesAliases ? null : outFileExtension, + }, + ]); + } + return { assumptions: { noDocumentAll: true, diff --git a/package.json b/package.json index f96fd51d9dee..12574377b452 100644 --- a/package.json +++ b/package.json @@ -89,6 +89,7 @@ "@emotion/cache": "^11.13.1", "@emotion/react": "^11.13.3", "@emotion/styled": "^11.13.0", + "@mui/internal-babel-plugin-resolve-imports": "1.0.16-dev.20240822-123416-f4a704707a", "@mui/icons-material": "^5.16.7", "@mui/internal-markdown": "^1.0.11", "@mui/internal-test-utils": "^1.0.10", diff --git a/packages/x-charts-pro/src/themeAugmentation/index.ts b/packages/x-charts-pro/src/themeAugmentation/index.ts index 1a4a7fc3c80d..52475626c4f0 100644 --- a/packages/x-charts-pro/src/themeAugmentation/index.ts +++ b/packages/x-charts-pro/src/themeAugmentation/index.ts @@ -1,4 +1,4 @@ -export * from '@mui/x-charts/themeAugmentation'; -export * from './overrides'; -export * from './props'; -export * from './components'; +export type * from '@mui/x-charts/themeAugmentation'; +export type * from './overrides'; +export type * from './props'; +export type * from './components'; diff --git a/packages/x-charts/src/themeAugmentation/index.ts b/packages/x-charts/src/themeAugmentation/index.ts index 492f27d8f917..d387cd19110f 100644 --- a/packages/x-charts/src/themeAugmentation/index.ts +++ b/packages/x-charts/src/themeAugmentation/index.ts @@ -1,3 +1,3 @@ -export * from './overrides'; -export * from './props'; -export * from './components'; +export type * from './overrides'; +export type * from './props'; +export type * from './components'; diff --git a/packages/x-date-pickers-pro/src/themeAugmentation/index.ts b/packages/x-date-pickers-pro/src/themeAugmentation/index.ts index 7141a607d90b..5c6664875f63 100644 --- a/packages/x-date-pickers-pro/src/themeAugmentation/index.ts +++ b/packages/x-date-pickers-pro/src/themeAugmentation/index.ts @@ -1,4 +1,4 @@ export * from '@mui/x-date-pickers/themeAugmentation'; -export * from './overrides'; -export * from './props'; -export * from './components'; +export type * from './overrides'; +export type * from './props'; +export type * from './components'; diff --git a/packages/x-date-pickers/src/themeAugmentation/index.ts b/packages/x-date-pickers/src/themeAugmentation/index.ts index 492f27d8f917..d387cd19110f 100644 --- a/packages/x-date-pickers/src/themeAugmentation/index.ts +++ b/packages/x-date-pickers/src/themeAugmentation/index.ts @@ -1,3 +1,3 @@ -export * from './overrides'; -export * from './props'; -export * from './components'; +export type * from './overrides'; +export type * from './props'; +export type * from './components'; diff --git a/packages/x-tree-view-pro/src/themeAugmentation/index.ts b/packages/x-tree-view-pro/src/themeAugmentation/index.ts index 492f27d8f917..d387cd19110f 100644 --- a/packages/x-tree-view-pro/src/themeAugmentation/index.ts +++ b/packages/x-tree-view-pro/src/themeAugmentation/index.ts @@ -1,3 +1,3 @@ -export * from './overrides'; -export * from './props'; -export * from './components'; +export type * from './overrides'; +export type * from './props'; +export type * from './components'; diff --git a/packages/x-tree-view/src/themeAugmentation/index.ts b/packages/x-tree-view/src/themeAugmentation/index.ts index 492f27d8f917..d387cd19110f 100644 --- a/packages/x-tree-view/src/themeAugmentation/index.ts +++ b/packages/x-tree-view/src/themeAugmentation/index.ts @@ -1,3 +1,3 @@ -export * from './overrides'; -export * from './props'; -export * from './components'; +export type * from './overrides'; +export type * from './props'; +export type * from './components'; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a377b74e87df..28c1ed05238a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -86,6 +86,9 @@ importers: '@mui/icons-material': specifier: ^5.16.7 version: 5.16.7(@mui/material@5.16.7(@emotion/react@11.13.3(@types/react@18.3.4)(react@18.3.1))(@emotion/styled@11.13.0(@emotion/react@11.13.3(@types/react@18.3.4)(react@18.3.1))(@types/react@18.3.4)(react@18.3.1))(@types/react@18.3.4)(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(@types/react@18.3.4)(react@18.3.1) + '@mui/internal-babel-plugin-resolve-imports': + specifier: 1.0.16-dev.20240822-123416-f4a704707a + version: 1.0.16-dev.20240822-123416-f4a704707a(@babel/core@7.25.2) '@mui/internal-markdown': specifier: ^1.0.11 version: 1.0.11 @@ -3089,6 +3092,11 @@ packages: '@types/react': optional: true + '@mui/internal-babel-plugin-resolve-imports@1.0.16-dev.20240822-123416-f4a704707a': + resolution: {integrity: sha512-zfxISMMAgZucsirZgqWqJXXCosnpKS+ZflBDKXyfbkNwWk5YUVwHNBfhQJ6yBLL+ZQIpXj22nCPC+38rkG76Pg==} + peerDependencies: + '@babel/core': '7' + '@mui/internal-docs-utils@1.0.11': resolution: {integrity: sha512-vnI+2mLMZSl4V3EDbXLj/pYpEH4xDBjLxhgBnEp2R6Agf89w6l6LRshrZADqHVVy9WEJ3ywoIZ1bYQCQd1bzzw==} @@ -11865,6 +11873,11 @@ snapshots: optionalDependencies: '@types/react': 18.3.4 + '@mui/internal-babel-plugin-resolve-imports@1.0.16-dev.20240822-123416-f4a704707a(@babel/core@7.25.2)': + dependencies: + '@babel/core': 7.25.2 + resolve: 1.22.8 + '@mui/internal-docs-utils@1.0.11': dependencies: rimraf: 5.0.10