-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathbundle-dts.ts
More file actions
34 lines (28 loc) · 884 Bytes
/
bundle-dts.ts
File metadata and controls
34 lines (28 loc) · 884 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { readFileSync, writeFileSync } from "node:fs";
function readDtsFile(reference: string) {
return readFileSync(
`../../vendor/vscode/extensions/node_modules/typescript/lib/lib.${reference}.d.ts`,
"utf8"
);
}
function writeDtsFile(reference: string, content: string) {
return writeFileSync(
`../../vendor/vscode/extensions/node_modules/typescript/lib/lib.${reference}.d.ts`,
content
);
}
const importRegex = /\/\/\/ <reference lib="(.+?)" \/>/g;
function replaceReferences(dts: string) {
return dts.replaceAll(importRegex, (_, ref) => {
const innerDts = readDtsFile(ref);
console.log("Including", ref, `(${innerDts.split("\n").length} lines)`);
return innerDts;
});
}
function inlineDts(dts: string) {
if (!importRegex.test(dts)) {
return dts;
}
return inlineDts(replaceReferences(dts));
}
writeDtsFile("es2022", inlineDts(readDtsFile("es2022")));