Skip to content

Commit 0e312f8

Browse files
committed
See #1118
fix: removed another superfluous unrelated linebreak fix: attempted to split dist files into EMS and CJS
1 parent c19aa70 commit 0e312f8

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

rollup.config.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@ const commonOutputConfig = {
2121
exports: 'default',
2222
};
2323

24+
// 🔧 Plugin to strip named type exports from .d.ts for CommonJS
25+
const stripNamedTypeExports = () => ({
26+
name: 'strip-named-type-exports',
27+
transform(code, id) {
28+
if (id.endsWith('.d.ts')) {
29+
return {
30+
code: code.replace(/^export\s+\{\s*type[\s\S]+?^\};\s*$/gm, ''),
31+
map: null,
32+
};
33+
}
34+
},
35+
});
36+
2437
const config = [
2538
{
2639
input: 'src/purify.ts',
@@ -53,8 +66,6 @@ const config = [
5366
clean: true,
5467
}),
5568
babel({
56-
// It is recommended to configure this option explicitly (even if with its default value) so an informed decision is taken on how those babel helpers are inserted into the code.
57-
// Ref: https://github.com/rollup/plugins/tree/master/packages/babel#babelhelpers
5869
babelHelpers: 'bundled',
5970
exclude: ['**/node_modules/**'],
6071
extensions: [...DEFAULT_EXTENSIONS, '.ts'],
@@ -69,6 +80,8 @@ const config = [
6980
}),
7081
],
7182
},
83+
84+
// ESM type declarations
7285
{
7386
input: './dist/types/purify.d.ts',
7487
output: [
@@ -80,6 +93,8 @@ const config = [
8093
],
8194
plugins: [dts()],
8295
},
96+
97+
// CJS type declarations with named export stripping
8398
{
8499
input: './dist/types/purify.d.ts',
85100
output: [
@@ -89,8 +104,11 @@ const config = [
89104
banner: commonOutputConfig.banner,
90105
},
91106
],
92-
plugins: [dts()],
107+
plugins: [
108+
stripNamedTypeExports(),
109+
dts(),
110+
],
93111
},
94112
];
95113

96-
module.exports = config;
114+
module.exports = config;

test/fixtures/expect.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -919,4 +919,4 @@ export default [
919919
"payload": "<header><h1>Movie website</h1><search><form action=\"./search/\"><label for=\"movie\">Find a Movie</label><input type=\"search\" id=\"movie\" name=\"q\" /><button type=\"submit\">Search</button></form></search></header>",
920920
"expected": "<header><h1>Movie website</h1><search><form action=\"./search/\"><label for=\"movie\">Find a Movie</label><input type=\"search\" id=\"movie\" name=\"q\"><button type=\"submit\">Search</button></form></search></header>"
921921
}
922-
];
922+
];

0 commit comments

Comments
 (0)