Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5e0656fe2c | ||
|
|
12e442f823 | ||
|
|
f03d245ef1 |
@@ -1,3 +1,4 @@
|
|||||||
node_modules
|
node_modules
|
||||||
index.d.ts
|
index.d.ts
|
||||||
*.tgz
|
*.tgz
|
||||||
|
*lock*
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
import * as fs from "node:fs";
|
||||||
|
const symbolRegex = /(?:var|function) (\w+)/g;
|
||||||
|
const globalSymbols = [];
|
||||||
|
let buffer = '';
|
||||||
|
|
||||||
|
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 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;
|
||||||
|
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");
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
import * as fs from "node:fs"
|
|
||||||
|
|
||||||
const globalRegex = / (?:var|function) (\w+)/g
|
|
||||||
const globalSymbols: string[] = []
|
|
||||||
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<string>()
|
|
||||||
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")
|
|
||||||
Generated
+19
-10
@@ -7,10 +7,13 @@
|
|||||||
"": {
|
"": {
|
||||||
"name": "@sugoidogo/node-web-globals",
|
"name": "@sugoidogo/node-web-globals",
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"license": "MIT",
|
"license": "Apache-2.0",
|
||||||
|
"dependencies": {
|
||||||
|
"undici-types": "^7.21.0"
|
||||||
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@sugoidogo/importable-types-web": "^1.0.0",
|
"@sugoidogo/importable-types-web": "^1.0.0",
|
||||||
"@types/node": "^25.2.2",
|
"@types/node": "^22.19.17",
|
||||||
"@types/web": "^0.0.329"
|
"@types/web": "^0.0.329"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -25,15 +28,22 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@types/node": {
|
"node_modules/@types/node": {
|
||||||
"version": "25.2.2",
|
"version": "22.19.17",
|
||||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-25.2.2.tgz",
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.19.17.tgz",
|
||||||
"integrity": "sha512-BkmoP5/FhRYek5izySdkOneRyXYN35I860MFAGupTdebyE66uZaR+bXLHq8k4DirE5DwQi3NuhvRU1jqTVwUrQ==",
|
"integrity": "sha512-wGdMcf+vPYM6jikpS/qhg6WiqSV/OhG+jeeHT/KlVqxYfD40iYJf9/AE1uQxVWFvU7MipKRkRv8NSHiCGgPr8Q==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"undici-types": "~7.16.0"
|
"undici-types": "~6.21.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@types/node/node_modules/undici-types": {
|
||||||
|
"version": "6.21.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz",
|
||||||
|
"integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
"node_modules/@types/web": {
|
"node_modules/@types/web": {
|
||||||
"version": "0.0.329",
|
"version": "0.0.329",
|
||||||
"resolved": "https://registry.npmjs.org/@types/web/-/web-0.0.329.tgz",
|
"resolved": "https://registry.npmjs.org/@types/web/-/web-0.0.329.tgz",
|
||||||
@@ -42,10 +52,9 @@
|
|||||||
"license": "Apache-2.0"
|
"license": "Apache-2.0"
|
||||||
},
|
},
|
||||||
"node_modules/undici-types": {
|
"node_modules/undici-types": {
|
||||||
"version": "7.16.0",
|
"version": "7.24.7",
|
||||||
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.16.0.tgz",
|
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.24.7.tgz",
|
||||||
"integrity": "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw==",
|
"integrity": "sha512-XA+gOBkzYD3C74sZowtCLTpgtaCdqZhqCvR6y9LXvrKTt/IVU6bz49T4D+BPi475scshCCkb0IklJRw6T1ZlgQ==",
|
||||||
"dev": true,
|
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -14,14 +14,14 @@
|
|||||||
"index.d.ts"
|
"index.d.ts"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"prepack": "node main.ts"
|
"prepack": "node main.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"undici-types": "^7.21.0"
|
"undici-types": "^7.21.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@sugoidogo/importable-types-web": "^1.0.0",
|
"@sugoidogo/importable-types-web": "^1.0.0",
|
||||||
"@types/node": "^25.2.2",
|
"@types/node": "^22.19.17",
|
||||||
"@types/web": "^0.0.329"
|
"@types/web": "^0.0.329"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-42
@@ -1,42 +0,0 @@
|
|||||||
import * as fs from 'node:fs'
|
|
||||||
import * as path from 'node:path'
|
|
||||||
|
|
||||||
const sourceDir = 'node_modules/@types/node/'
|
|
||||||
const importRegex = /import .+? from "(?:node\:)?(.+?)"/g
|
|
||||||
|
|
||||||
if (fs.existsSync('dist')) fs.rmSync('dist', { 'recursive': true })
|
|
||||||
|
|
||||||
let imports=new Set<string>()
|
|
||||||
for (const basename of fs.readdirSync(sourceDir + 'web-globals/')) {
|
|
||||||
imports.add('web-globals/'+basename.split('.')[0])
|
|
||||||
}
|
|
||||||
|
|
||||||
let startSize=0
|
|
||||||
do {
|
|
||||||
startSize = imports.size
|
|
||||||
let buffer = ''
|
|
||||||
for (const importName of imports) {
|
|
||||||
if (!fs.existsSync(sourceDir + importName + '.d.ts')) {
|
|
||||||
console.warn(importName + ' is not in sources, ignoring')
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
buffer+=fs.readFileSync(sourceDir+importName+'.d.ts')
|
|
||||||
}
|
|
||||||
for (const match of buffer.matchAll(importRegex)) {
|
|
||||||
imports.add(match[1])
|
|
||||||
}
|
|
||||||
} while (startSize != imports.size)
|
|
||||||
|
|
||||||
let index = ''
|
|
||||||
for (const importName of imports) {
|
|
||||||
if (!fs.existsSync(sourceDir + importName + '.d.ts')) {
|
|
||||||
console.warn(importName + ' is not in sources, ignoring')
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
fs.mkdirSync(path.dirname('dist/'+importName+'.d.ts'),{'recursive':true})
|
|
||||||
fs.copyFileSync(sourceDir + importName + '.d.ts', 'dist/' + importName + '.d.ts')
|
|
||||||
index += `/// <reference path="${importName}.d.ts" />\n`
|
|
||||||
}
|
|
||||||
|
|
||||||
fs.writeFileSync('dist/index.d.ts',index)
|
|
||||||
fs.cpSync('node_modules/@types/node/LICENSE', 'LICENSE')
|
|
||||||
+4
-3
@@ -1,9 +1,10 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "es2022",
|
"allowJs": true,
|
||||||
"module": "es2022",
|
"noEmit": true,
|
||||||
"moduleResolution": "node",
|
"moduleResolution": "node",
|
||||||
"lib": ["ES2022"],
|
"target": "es2022",
|
||||||
|
"lib": ["ESNext"],
|
||||||
"types": ["node"]
|
"types": ["node"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user