mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-12 01:00:34 +08:00
Refactor: drop Bun.peek usage as much as possible
This commit is contained in:
parent
93fc073a22
commit
b947f9f818
@ -1,5 +1,6 @@
|
|||||||
// @ts-check
|
// @ts-check
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
import fsp from 'fs/promises';
|
||||||
import { DOMESTICS } from '../Source/non_ip/domestic';
|
import { DOMESTICS } from '../Source/non_ip/domestic';
|
||||||
import { DIRECTS, LANS } from '../Source/non_ip/direct';
|
import { DIRECTS, LANS } from '../Source/non_ip/direct';
|
||||||
import { readFileIntoProcessedArray } from './lib/fetch-text-by-line';
|
import { readFileIntoProcessedArray } from './lib/fetch-text-by-line';
|
||||||
@ -95,7 +96,7 @@ export const buildDomesticRuleset = task(import.meta.main, import.meta.path)(asy
|
|||||||
],
|
],
|
||||||
path.resolve(import.meta.dir, '../Modules/sukka_local_dns_mapping.sgmodule')
|
path.resolve(import.meta.dir, '../Modules/sukka_local_dns_mapping.sgmodule')
|
||||||
),
|
),
|
||||||
Bun.write(
|
fsp.writeFile(
|
||||||
path.resolve(import.meta.dir, '../Internal/clash_nameserver_policy.yaml'),
|
path.resolve(import.meta.dir, '../Internal/clash_nameserver_policy.yaml'),
|
||||||
yaml.stringify(
|
yaml.stringify(
|
||||||
{
|
{
|
||||||
@ -128,7 +129,8 @@ export const buildDomesticRuleset = task(import.meta.main, import.meta.path)(asy
|
|||||||
)
|
)
|
||||||
},
|
},
|
||||||
{ version: '1.1' }
|
{ version: '1.1' }
|
||||||
)
|
),
|
||||||
|
{ encoding: 'utf-8' }
|
||||||
)
|
)
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -6,11 +6,7 @@ import { getChnCidrPromise } from './build-chn-cidr';
|
|||||||
import { NON_CN_CIDR_INCLUDED_IN_CHNROUTE, RESERVED_IPV4_CIDR } from './constants/cidr';
|
import { NON_CN_CIDR_INCLUDED_IN_CHNROUTE, RESERVED_IPV4_CIDR } from './constants/cidr';
|
||||||
|
|
||||||
export const buildInternalReverseChnCIDR = task(import.meta.main, import.meta.path)(async () => {
|
export const buildInternalReverseChnCIDR = task(import.meta.main, import.meta.path)(async () => {
|
||||||
const cidrPromise = getChnCidrPromise();
|
const cidr = await getChnCidrPromise();
|
||||||
const peeked = Bun.peek(cidrPromise);
|
|
||||||
const cidr: string[] = peeked === cidrPromise
|
|
||||||
? await cidrPromise
|
|
||||||
: (peeked as string[]);
|
|
||||||
|
|
||||||
const reversedCidr = merge(
|
const reversedCidr = merge(
|
||||||
exclude(
|
exclude(
|
||||||
|
|||||||
@ -2,7 +2,6 @@
|
|||||||
import { fetchRemoteTextByLine } from './fetch-text-by-line';
|
import { fetchRemoteTextByLine } from './fetch-text-by-line';
|
||||||
import { NetworkFilter } from '@cliqz/adblocker';
|
import { NetworkFilter } from '@cliqz/adblocker';
|
||||||
import { processLine } from './process-line';
|
import { processLine } from './process-line';
|
||||||
import { getGorhillPublicSuffixPromise } from './get-gorhill-publicsuffix';
|
|
||||||
import type { PublicSuffixList } from '@gorhill/publicsuffixlist';
|
import type { PublicSuffixList } from '@gorhill/publicsuffixlist';
|
||||||
|
|
||||||
import picocolors from 'picocolors';
|
import picocolors from 'picocolors';
|
||||||
@ -11,6 +10,7 @@ import { fetchAssets } from './fetch-assets';
|
|||||||
import { deserializeArray, fsFetchCache, serializeArray } from './cache-filesystem';
|
import { deserializeArray, fsFetchCache, serializeArray } from './cache-filesystem';
|
||||||
import type { Span } from '../trace';
|
import type { Span } from '../trace';
|
||||||
import createKeywordFilter from './aho-corasick';
|
import createKeywordFilter from './aho-corasick';
|
||||||
|
import { getGorhillPublicSuffixPromise } from './get-gorhill-publicsuffix';
|
||||||
|
|
||||||
const DEBUG_DOMAIN_TO_FIND: string | null = null; // example.com | null
|
const DEBUG_DOMAIN_TO_FIND: string | null = null; // example.com | null
|
||||||
let foundDebugDomain = false;
|
let foundDebugDomain = false;
|
||||||
@ -147,11 +147,7 @@ export async function processFilterRules(
|
|||||||
|
|
||||||
const warningMessages: string[] = [];
|
const warningMessages: string[] = [];
|
||||||
|
|
||||||
const gorhillPromise = getGorhillPublicSuffixPromise();
|
const gorhill = await span.traceChild('get gorhill').tracePromise(getGorhillPublicSuffixPromise());
|
||||||
const peekedGorhill = Bun.peek(gorhillPromise);
|
|
||||||
const gorhill = peekedGorhill === gorhillPromise
|
|
||||||
? await span.traceChild('get gorhill').tracePromise(gorhillPromise)
|
|
||||||
: (peekedGorhill as PublicSuffixList);
|
|
||||||
|
|
||||||
const MUTABLE_PARSE_LINE_RESULT: [string, ParseType] = ['', 1000];
|
const MUTABLE_PARSE_LINE_RESULT: [string, ParseType] = ['', 1000];
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user