Skip to content

Commit d97104c

Browse files
authored
chore(build): remove 'module.exports' export from dts for backward compatibility of TS < 5.6.2 (#12948)
* chore: remove 'module.exports' export from dts to support old TS * chore: update
1 parent 12609ab commit d97104c

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

packages/rspack/etc/core.api.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6819,7 +6819,6 @@ type Rspack = typeof rspack_2 & typeof rspackExports & {
68196819
// @public (undocumented)
68206820
const rspack: Rspack;
68216821
export default rspack;
6822-
export { rspack as module.exports }
68236822
export { rspack }
68246823

68256824
// @public (undocumented)

packages/rspack/rslib.config.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,26 @@ const codmodPlugin: RsbuildPlugin = {
167167
},
168168
};
169169

170+
// Remove `export { rspack as 'module.exports' };` to avoid parsing errors with TypeScript < 5.6.2
171+
const removeDtsExportPlugin: RsbuildPlugin = {
172+
name: 'remove-dts-export',
173+
setup(api) {
174+
api.onAfterBuild(async () => {
175+
const dtsPath = path.resolve(import.meta.dirname, 'dist/index.d.ts');
176+
if (fs.existsSync(dtsPath)) {
177+
const content = await fs.promises.readFile(dtsPath, 'utf-8');
178+
const newContent = content.replace(
179+
"export { rspack as 'module.exports' };",
180+
'',
181+
);
182+
await fs.promises.writeFile(dtsPath, newContent);
183+
}
184+
});
185+
},
186+
};
187+
170188
export default defineConfig({
171-
plugins: [mfRuntimePlugin, codmodPlugin],
189+
plugins: [mfRuntimePlugin, codmodPlugin, removeDtsExportPlugin],
172190
lib: [
173191
merge(commonLibConfig, {
174192
dts: {

0 commit comments

Comments
 (0)