Skip to content

Commit 05b3896

Browse files
author
Brijesh Bittu
committed
Reorder babel plugin to work with packages with css imports
1 parent 903e9c2 commit 05b3896

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

scripts/buildTypes.mts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,23 @@ async function emitDeclarations(tsconfig: string, outDir: string) {
1616
await $$`tsc -p ${tsconfig} --outDir ${outDir} --declaration --emitDeclarationOnly`;
1717
}
1818

19-
async function postProcessImports(folder: string, removeCss: boolean) {
19+
async function postProcessImports(folder: string, removeCss: boolean, filter = '.d.ts') {
2020
// eslint-disable-next-line no-console
2121
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 });
2323
if (dtsFiles.length === 0) {
24-
throw new Error(`Unable to find declaration files in '${folder}'`);
24+
return;
2525
}
2626

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 }]];
3128

3229
if (removeCss) {
3330
babelPlugins.push(['babel-plugin-transform-remove-imports', { test: /\.css$/ }]);
3431
}
3532

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+
3636
await Promise.all(
3737
dtsFiles.map(async (dtsFile) => {
3838
const result = await babel.transformFileAsync(dtsFile, {
@@ -125,13 +125,13 @@ async function main(argv: HandlerArgv) {
125125

126126
await copyDeclarations(esmDir, cjsDir);
127127

128-
await postProcessImports(esmDir, argv.removeCss);
129-
await postProcessImports(cjsDir, argv.removeCss);
130-
131128
if (EXPERIMENTAL_MJS) {
132129
await renameDtsFilesToDmts(esmDir);
133130
}
134131

132+
await postProcessImports(esmDir, argv.removeCss, '.d.mts');
133+
await postProcessImports(cjsDir, argv.removeCss, '.d.ts');
134+
135135
const tsbuildinfo = await glob('**/*.tsbuildinfo', { absolute: true, cwd: buildFolder });
136136
await Promise.all(tsbuildinfo.map(async (file) => fs.rm(file)));
137137
}

0 commit comments

Comments
 (0)