-
-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathfixDts.ts
More file actions
23 lines (21 loc) · 752 Bytes
/
Copy pathfixDts.ts
File metadata and controls
23 lines (21 loc) · 752 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import type { Plugin } from "rolldown";
import { format, type Options } from "prettier";
const prettyOptions: Options = {
parser: "typescript",
printWidth: 120,
};
/** @desc Fixes weird formatting in the .d.ts files generated by rolldown-plugin-dts v0.21 */
export const fixDtsPlugin = (): Plugin => ({
name: "fix-dts-rolldown-plugin",
generateBundle: async (_opt, bundle) => {
for (const [name, file] of Object.entries(bundle)) {
if (!(name.endsWith(".d.ts") && "code" in file)) continue;
file.code = await format(
file.code
.replaceAll(/^\/\/#(end)?region[^\r\n]*/gm, "") // rm rolldown comments
.replaceAll(/\n\s*\n/g, "\n"), // rm double newlines
prettyOptions,
);
}
},
});