mirror of
https://github.com/SukkaW/Surge.git
synced 2026-02-03 20:41:52 +08:00
Refactor: make Node.js run compatible
This commit is contained in:
@@ -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([
|
||||
|
||||
Reference in New Issue
Block a user