Refactor: make Node.js run compatible

This commit is contained in:
SukkaW
2024-07-23 17:42:10 +08:00
parent 1f42c27afe
commit 553dd62eb1
32 changed files with 163 additions and 136 deletions

View File

@@ -1,10 +1,16 @@
import { toASCII } from 'punycode';
import fsp from 'fs/promises';
import { toASCII } from 'punycode/punycode';
import { createMemoizedPromise } from './memo-promise';
import { getPublicSuffixListTextPromise } from './download-publicsuffixlist';
import { fileURLToPath } from 'url';
const customFetch = typeof Bun !== 'undefined'
? (url: string | URL) => Promise.resolve(Bun.file(url))
: (url: string | URL) => fetch(url).then(resp => resp.blob() as Promise<Blob>);
: async (url: string | URL) => {
const filePath = fileURLToPath(url);
const file = await fsp.readFile(filePath);
return new Blob([file]) as any;
};
export const getGorhillPublicSuffixPromise = createMemoizedPromise(async () => {
const [publicSuffixListDat, { default: gorhill }] = await Promise.all([