@@ -16,23 +16,23 @@ async function emitDeclarations(tsconfig: string, outDir: string) {
16
16
await $$ `tsc -p ${ tsconfig } --outDir ${ outDir } --declaration --emitDeclarationOnly` ;
17
17
}
18
18
19
- async function postProcessImports ( folder : string , removeCss : boolean ) {
19
+ async function postProcessImports ( folder : string , removeCss : boolean , filter = '.d.ts' ) {
20
20
// eslint-disable-next-line no-console
21
21
console . log ( `Adding import extensions` ) ;
22
- const dtsFiles = await glob ( ' **/*.d.ts' , { absolute : true , cwd : folder } ) ;
22
+ const dtsFiles = await glob ( ` **/*${ filter } ` , { absolute : true , cwd : folder } ) ;
23
23
if ( dtsFiles . length === 0 ) {
24
- throw new Error ( `Unable to find declaration files in ' ${ folder } '` ) ;
24
+ return ;
25
25
}
26
26
27
- const babelPlugins : babel . PluginItem [ ] = [
28
- [ '@babel/plugin-syntax-typescript' , { dts : true } ] ,
29
- [ '@mui/internal-babel-plugin-resolve-imports' ] ,
30
- ] ;
27
+ const babelPlugins : babel . PluginItem [ ] = [ [ '@babel/plugin-syntax-typescript' , { dts : true } ] ] ;
31
28
32
29
if ( removeCss ) {
33
30
babelPlugins . push ( [ 'babel-plugin-transform-remove-imports' , { test : / \. c s s $ / } ] ) ;
34
31
}
35
32
33
+ // this plugin needs to come after remove-imports so that css imports are already removed
34
+ babelPlugins . push ( [ '@mui/internal-babel-plugin-resolve-imports' ] ) ;
35
+
36
36
await Promise . all (
37
37
dtsFiles . map ( async ( dtsFile ) => {
38
38
const result = await babel . transformFileAsync ( dtsFile , {
@@ -125,13 +125,13 @@ async function main(argv: HandlerArgv) {
125
125
126
126
await copyDeclarations ( esmDir , cjsDir ) ;
127
127
128
- await postProcessImports ( esmDir , argv . removeCss ) ;
129
- await postProcessImports ( cjsDir , argv . removeCss ) ;
130
-
131
128
if ( EXPERIMENTAL_MJS ) {
132
129
await renameDtsFilesToDmts ( esmDir ) ;
133
130
}
134
131
132
+ await postProcessImports ( esmDir , argv . removeCss , '.d.mts' ) ;
133
+ await postProcessImports ( cjsDir , argv . removeCss , '.d.ts' ) ;
134
+
135
135
const tsbuildinfo = await glob ( '**/*.tsbuildinfo' , { absolute : true , cwd : buildFolder } ) ;
136
136
await Promise . all ( tsbuildinfo . map ( async ( file ) => fs . rm ( file ) ) ) ;
137
137
}
0 commit comments