fix parsing to grab globals from all definitions
/ publish (push) Successful in 21s

This commit is contained in:
2026-04-04 15:06:38 -07:00
parent 12e442f823
commit 5e0656fe2c
3 changed files with 58 additions and 15 deletions
+29 -5
View File
@@ -1,12 +1,36 @@
// @ts-check
import * as fs from "node:fs";
const globalRegex = / (?:var|function) (\w+)/g;
const symbolRegex = /(?: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");
const fileQueue = []
const dirQueue = ["node_modules/@types/node"]
while (dirQueue.length !== 0) {
const dirname = dirQueue.pop()
for (const basename of fs.readdirSync(dirname)) {
const path = dirname + "/" + basename
if (fs.statSync(path).isDirectory()) {
dirQueue.push(path)
} else {
fileQueue.push(path)
}
}
}
for (const match of buffer.matchAll(globalRegex)) {
for (const path of fileQueue) {
const filebuffer = fs.readFileSync(path, "utf8");
const lines = filebuffer.split('\n')
let startLine=0
for (const line of lines) {
if (line.trim().endsWith("global {")) {
break
}
startLine++
}
buffer+=lines.slice(startLine).join('\n')
}
for (const match of buffer.matchAll(symbolRegex)) {
globalSymbols.push(match[0].trim());
}
const declarationRegex = /(?:^\/\*\*[\s\S]+?\*\/\n)?^(interface|type|declare \w+) (\w+).+\n(?:(?: .+\n)*};?\n)?/gm;