target node 20 (oldest supported release)
/ publish (push) Successful in 33s

This commit is contained in:
2026-04-03 23:24:39 -07:00
parent be971e6d18
commit f03d245ef1
6 changed files with 30 additions and 86 deletions
+26
View File
@@ -0,0 +1,26 @@
// @ts-check
import * as fs from "node:fs";
const globalRegex = / (?:var|function) (\w+)/g;
const globalSymbols = [];
let buffer = '';
for (const basename of fs.readdirSync("node_modules/@types/node/web-globals")) {
buffer += fs.readFileSync("node_modules/@types/node/web-globals/" + basename, "utf8");
}
for (const match of buffer.matchAll(globalRegex)) {
globalSymbols.push(match[0].trim());
}
const declarationRegex = /(?:^\/\*\*[\s\S]+?\*\/\n)?^(interface|type|declare \w+) (\w+).+\n(?:(?: .+\n)*};?\n)?/gm;
const importableTypes = new Set();
buffer = '';
for (const match of fs.readFileSync("node_modules/@types/web/index.d.ts", "utf8").matchAll(declarationRegex)) {
if (!match[1].startsWith("declare")) {
importableTypes.add(match[2]);
continue;
}
if (globalSymbols.includes(match[1].replace("declare ", "") + " " + match[2])) {
buffer += match[0].replace(/^declare /gm, "").replaceAll("\n", "\n\t");
}
}
buffer = `import type { \n\t${Array.from(importableTypes).join(",\n\t")}\n} from "@sugoidogo/importable-types-web"\ndeclare global {\n\t${buffer.trimEnd()}\n}`;
fs.writeFileSync("index.d.ts", buffer, "utf8");
fs.copyFileSync("node_modules/@types/web/LICENSE.txt", "LICENSE.txt");