@@ -25,7 +25,15 @@ const bundleTypes = {
2525} ;
2626
2727async function run ( argv ) {
28- const { bundle, largeFiles, outDir : outDirBase , verbose, cjsDir } = argv ;
28+ const {
29+ bundle,
30+ largeFiles,
31+ outDir : outDirBase ,
32+ verbose,
33+ cjsDir,
34+ babelIgnore,
35+ babelFlag : babelFlags ,
36+ } = argv ;
2937
3038 if ( ! validBundles . includes ( bundle ) ) {
3139 throw new TypeError (
@@ -36,11 +44,16 @@ async function run(argv) {
3644 const packageJsonPath = path . resolve ( './package.json' ) ;
3745 const packageJson = JSON . parse ( await fs . readFile ( packageJsonPath , { encoding : 'utf8' } ) ) ;
3846
39- const babelRuntimeVersion = packageJson . dependencies ?. [ '@babel/runtime' ] ;
47+ let babelRuntimeVersion = packageJson . dependencies [ '@babel/runtime' ] ;
4048 if ( ! babelRuntimeVersion ) {
4149 throw new Error (
4250 'package.json needs to have a dependency on `@babel/runtime` when building with `@babel/plugin-transform-runtime`.' ,
4351 ) ;
52+ } else if ( babelRuntimeVersion === 'catalog:' ) {
53+ // resolve the version from the given package
54+ const { stdout : listedBabelRuntime } = await exec ( 'pnpm list "@babel/runtime" --json' ) ;
55+ const jsonListedDependencies = JSON . parse ( listedBabelRuntime ) ;
56+ babelRuntimeVersion = jsonListedDependencies [ 0 ] . dependencies [ '@babel/runtime' ] . version ;
4457 }
4558
4659 const babelConfigPath = path . resolve ( getWorkspaceRoot ( ) , 'babel.config.js' ) ;
@@ -50,11 +63,13 @@ async function run(argv) {
5063 '**/*.test.js' ,
5164 '**/*.test.ts' ,
5265 '**/*.test.tsx' ,
66+ '**/*.spec.js' ,
5367 '**/*.spec.ts' ,
5468 '**/*.spec.tsx' ,
5569 '**/*.d.ts' ,
5670 '**/*.test/*.*' ,
5771 '**/test-cases/*.*' ,
72+ ...babelIgnore ,
5873 ] ;
5974
6075 let outFileExtension = '.js' ;
@@ -78,7 +93,7 @@ async function run(argv) {
7893 MUI_BUILD_VERBOSE : verbose ,
7994 MUI_BABEL_RUNTIME_VERSION : babelRuntimeVersion ,
8095 MUI_OUT_FILE_EXTENSION : outFileExtension ,
81- ...( await getVersionEnvVariables ( packageJson ) ) ,
96+ ...getVersionEnvVariables ( packageJson ) ,
8297 } ;
8398
8499 const babelArgs = [
@@ -92,6 +107,7 @@ async function run(argv) {
92107 '--ignore' ,
93108 // Need to put these patterns in quotes otherwise they might be evaluated by the used terminal.
94109 `"${ ignore . join ( '","' ) } "` ,
110+ ...babelFlags ,
95111 ] ;
96112
97113 if ( outFileExtension !== '.js' ) {
@@ -161,7 +177,14 @@ yargs(process.argv.slice(2))
161177 description : 'The directory to copy the cjs files to.' ,
162178 } )
163179 . option ( 'out-dir' , { default : './build' , type : 'string' } )
164- . option ( 'verbose' , { type : 'boolean' } ) ;
180+ . option ( 'babel-ignore' , { type : 'string' , array : true , default : [ ] } )
181+ . option ( 'verbose' , { type : 'boolean' } )
182+ . option ( 'babel-flag' , {
183+ type : 'string' ,
184+ array : true ,
185+ default : [ ] ,
186+ description : 'Additional flags to pass to babel cli.' ,
187+ } ) ;
165188 } ,
166189 handler : run ,
167190 } )
0 commit comments