11// @ts -check
2- const path = require ( 'path' ) ;
2+ import { fileURLToPath } from 'node:url' ;
3+ import * as path from 'node:path' ;
4+ // @ts -ignore
5+ import getBaseConfig from '@mui/internal-code-infra/babel-config' ;
36
47/**
58 * @typedef {import('@babel/core') } babel
69 */
710
8- const errorCodesPath = path . resolve ( __dirname , './docs/public/static/error-codes.json' ) ;
11+ const filename = fileURLToPath ( import . meta. url ) ;
12+ const dirname = path . dirname ( filename ) ;
13+
14+ const errorCodesPath = path . resolve ( dirname , './docs/public/static/error-codes.json' ) ;
915const missingError = process . env . MUI_EXTRACT_ERROR_CODES === 'true' ? 'write' : 'annotate' ;
1016
1117/**
1218 * @param {string } relativeToBabelConf
1319 * @returns {string }
1420 */
1521function resolveAliasPath ( relativeToBabelConf ) {
16- const resolvedPath = path . relative ( process . cwd ( ) , path . resolve ( __dirname , relativeToBabelConf ) ) ;
22+ const resolvedPath = path . relative ( process . cwd ( ) , path . resolve ( dirname , relativeToBabelConf ) ) ;
1723 return `./${ resolvedPath . replace ( '\\' , '/' ) } ` ;
1824}
1925
2026/** @type {babel.ConfigFunction } */
21- module . exports = function getBabelConfig ( api ) {
27+ export default function getBabelConfig ( api ) {
28+ const baseConfig = getBaseConfig ( api ) ;
2229 const useESModules = api . env ( [ 'regressions' , 'stable' ] ) ;
2330
2431 const defaultAlias = {
@@ -41,58 +48,8 @@ module.exports = function getBabelConfig(api) {
4148 test : resolveAliasPath ( './test' ) ,
4249 } ;
4350
44- const presets = [
45- [
46- '@babel/preset-env' ,
47- {
48- bugfixes : true ,
49- browserslistEnv : api . env ( ) || process . env . NODE_ENV ,
50- debug : process . env . MUI_BUILD_VERBOSE === 'true' ,
51- modules : useESModules ? false : 'commonjs' ,
52- } ,
53- ] ,
54- [
55- '@babel/preset-react' ,
56- {
57- runtime : 'automatic' ,
58- } ,
59- ] ,
60- '@babel/preset-typescript' ,
61- ] ;
62-
63- // Essentially only replace in production builds.
64- // When aliasing we want to keep the original extension
65- const outFileExtension = process . env . MUI_OUT_FILE_EXTENSION || null ;
66-
6751 /** @type {babel.PluginItem[] } */
6852 const plugins = [
69- 'babel-plugin-optimize-clsx' ,
70- [
71- '@babel/plugin-transform-runtime' ,
72- {
73- useESModules,
74- // any package needs to declare 7.25.0 as a runtime dependency. default is ^7.0.0
75- version : process . env . MUI_BABEL_RUNTIME_VERSION || '^7.25.0' ,
76- } ,
77- ] ,
78- [
79- 'babel-plugin-transform-react-remove-prop-types' ,
80- {
81- mode : 'unsafe-wrap' ,
82- } ,
83- ] ,
84- [
85- 'transform-inline-environment-variables' ,
86- {
87- include : [
88- 'MUI_VERSION' ,
89- 'MUI_MAJOR_VERSION' ,
90- 'MUI_MINOR_VERSION' ,
91- 'MUI_PATCH_VERSION' ,
92- 'MUI_PRERELEASE' ,
93- ] ,
94- } ,
95- ] ,
9653 [
9754 '@mui/internal-babel-plugin-minify-errors' ,
9855 {
@@ -101,16 +58,6 @@ module.exports = function getBabelConfig(api) {
10158 runtimeModule : '@mui/utils/formatMuiErrorMessage' ,
10259 } ,
10360 ] ,
104- ...( useESModules
105- ? [
106- [
107- '@mui/internal-babel-plugin-resolve-imports' ,
108- {
109- outExtension : outFileExtension ,
110- } ,
111- ] ,
112- ]
113- : [ ] ) ,
11461 ] ;
11562
11663 if ( process . env . NODE_ENV === 'test' ) {
@@ -122,14 +69,15 @@ module.exports = function getBabelConfig(api) {
12269 } ,
12370 ] ) ;
12471 }
72+ const basePlugins = ( baseConfig . plugins || [ ] ) . filter (
73+ ( /** @type {[unknown, unknown, string] } */ [ , , pluginName ] ) =>
74+ pluginName !== '@mui/internal-babel-plugin-display-name' ,
75+ ) ;
76+ basePlugins . push ( ...plugins ) ;
12577
12678 return {
127- assumptions : {
128- noDocumentAll : true ,
129- } ,
130- presets,
131- plugins,
132- ignore : [ / @ b a b e l [ \\ | / ] r u n t i m e / ] , // Fix a Windows issue.
79+ ...baseConfig ,
80+ plugins : basePlugins ,
13381 overrides : [
13482 {
13583 exclude : / \. t e s t \. ( m ? j s | t s | t s x ) $ / ,
@@ -181,4 +129,4 @@ module.exports = function getBabelConfig(api) {
181129 } ,
182130 } ,
183131 } ;
184- } ;
132+ }
0 commit comments