@@ -21,7 +21,15 @@ const bundleTypes = {
21
21
} ;
22
22
23
23
async function run ( argv ) {
24
- const { bundle, largeFiles, outDir : outDirBase , verbose, cjsDir } = argv ;
24
+ const {
25
+ bundle,
26
+ largeFiles,
27
+ outDir : outDirBase ,
28
+ verbose,
29
+ cjsDir,
30
+ babelIgnore,
31
+ babelFlag : babelFlags ,
32
+ } = argv ;
25
33
26
34
if ( ! validBundles . includes ( bundle ) ) {
27
35
throw new TypeError (
@@ -32,11 +40,16 @@ async function run(argv) {
32
40
const packageJsonPath = path . resolve ( './package.json' ) ;
33
41
const packageJson = JSON . parse ( await fs . readFile ( packageJsonPath , { encoding : 'utf8' } ) ) ;
34
42
35
- const babelRuntimeVersion = packageJson . dependencies ?. [ '@babel/runtime' ] ;
43
+ let babelRuntimeVersion = packageJson . dependencies [ '@babel/runtime' ] ;
36
44
if ( ! babelRuntimeVersion ) {
37
45
throw new Error (
38
46
'package.json needs to have a dependency on `@babel/runtime` when building with `@babel/plugin-transform-runtime`.' ,
39
47
) ;
48
+ } else if ( babelRuntimeVersion === 'catalog:' ) {
49
+ // resolve the version from the given package
50
+ const { stdout : listedBabelRuntime } = await exec ( 'pnpm list "@babel/runtime" --json' ) ;
51
+ const jsonListedDependencies = JSON . parse ( listedBabelRuntime ) ;
52
+ babelRuntimeVersion = jsonListedDependencies [ 0 ] . dependencies [ '@babel/runtime' ] . version ;
40
53
}
41
54
42
55
const babelConfigPath = path . resolve ( getWorkspaceRoot ( ) , 'babel.config.js' ) ;
@@ -46,11 +59,13 @@ async function run(argv) {
46
59
'**/*.test.js' ,
47
60
'**/*.test.ts' ,
48
61
'**/*.test.tsx' ,
62
+ '**/*.spec.js' ,
49
63
'**/*.spec.ts' ,
50
64
'**/*.spec.tsx' ,
51
65
'**/*.d.ts' ,
52
66
'**/*.test/*.*' ,
53
67
'**/test-cases/*.*' ,
68
+ ...babelIgnore ,
54
69
] ;
55
70
56
71
const outFileExtension = '.js' ;
@@ -68,7 +83,7 @@ async function run(argv) {
68
83
MUI_BUILD_VERBOSE : verbose ,
69
84
MUI_BABEL_RUNTIME_VERSION : babelRuntimeVersion ,
70
85
MUI_OUT_FILE_EXTENSION : outFileExtension ,
71
- ...( await getVersionEnvVariables ( packageJson ) ) ,
86
+ ...getVersionEnvVariables ( packageJson ) ,
72
87
} ;
73
88
74
89
const babelArgs = [
@@ -82,6 +97,7 @@ async function run(argv) {
82
97
'--ignore' ,
83
98
// Need to put these patterns in quotes otherwise they might be evaluated by the used terminal.
84
99
`"${ ignore . join ( '","' ) } "` ,
100
+ ...babelFlags ,
85
101
] ;
86
102
87
103
if ( outFileExtension !== '.js' ) {
@@ -153,7 +169,14 @@ yargs(process.argv.slice(2))
153
169
description : 'The directory to copy the cjs files to.' ,
154
170
} )
155
171
. option ( 'out-dir' , { default : './build' , type : 'string' } )
156
- . option ( 'verbose' , { type : 'boolean' } ) ;
172
+ . option ( 'babel-ignore' , { type : 'string' , array : true , default : [ ] } )
173
+ . option ( 'verbose' , { type : 'boolean' } )
174
+ . option ( 'babel-flag' , {
175
+ type : 'string' ,
176
+ array : true ,
177
+ default : [ ] ,
178
+ description : 'Additional flags to pass to babel cli.' ,
179
+ } ) ;
157
180
} ,
158
181
handler : run ,
159
182
} )
0 commit comments