mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-12 01:00:34 +08:00
Remove unused Bun.peek
This commit is contained in:
parent
6e32af4dc8
commit
7167be852f
@ -19,10 +19,7 @@ export const getAppleCdnDomainsPromise = createMemoizedPromise(() => fsFetchCach
|
|||||||
|
|
||||||
export const buildAppleCdn = task(import.meta.path, async (span) => {
|
export const buildAppleCdn = task(import.meta.path, async (span) => {
|
||||||
const promise = getAppleCdnDomainsPromise();
|
const promise = getAppleCdnDomainsPromise();
|
||||||
const peeked = Bun.peek(promise);
|
const res: string[] = await span.traceChildPromise('get apple cdn domains', promise);
|
||||||
const res: string[] = peeked === promise
|
|
||||||
? await span.traceChildPromise('get apple cdn domains', promise)
|
|
||||||
: (peeked as string[]);
|
|
||||||
|
|
||||||
const description = [
|
const description = [
|
||||||
...SHARED_DESCRIPTION,
|
...SHARED_DESCRIPTION,
|
||||||
|
|||||||
@ -14,11 +14,7 @@ export const getChnCidrPromise = createMemoizedPromise(async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
export const buildChnCidr = task(import.meta.path, async (span) => {
|
export const buildChnCidr = task(import.meta.path, async (span) => {
|
||||||
const cidrPromise = getChnCidrPromise();
|
const filteredCidr = await span.traceChildAsync('download chnroutes2', getChnCidrPromise);
|
||||||
const peeked = Bun.peek(cidrPromise);
|
|
||||||
const filteredCidr: string[] = peeked === cidrPromise
|
|
||||||
? await span.traceChildPromise('download chnroutes2', cidrPromise)
|
|
||||||
: (peeked as string[]);
|
|
||||||
|
|
||||||
// Can not use SHARED_DESCRIPTION here as different license
|
// Can not use SHARED_DESCRIPTION here as different license
|
||||||
const description = [
|
const description = [
|
||||||
|
|||||||
@ -21,7 +21,7 @@ const s = new Sema(2);
|
|||||||
const latestTopUserAgentsPromise = fsFetchCache.apply(
|
const latestTopUserAgentsPromise = fsFetchCache.apply(
|
||||||
'https://cdn.jsdelivr.net/npm/top-user-agents@latest/src/desktop.json',
|
'https://cdn.jsdelivr.net/npm/top-user-agents@latest/src/desktop.json',
|
||||||
() => fetchWithRetry('https://cdn.jsdelivr.net/npm/top-user-agents@latest/src/desktop.json')
|
() => fetchWithRetry('https://cdn.jsdelivr.net/npm/top-user-agents@latest/src/desktop.json')
|
||||||
.then(res => res.json())
|
.then(res => res.json() as any)
|
||||||
.then((userAgents: string[]) => userAgents.filter(ua => ua.startsWith('Mozilla/5.0 '))),
|
.then((userAgents: string[]) => userAgents.filter(ua => ua.startsWith('Mozilla/5.0 '))),
|
||||||
{
|
{
|
||||||
serializer: serializeArray,
|
serializer: serializeArray,
|
||||||
@ -61,7 +61,7 @@ const querySpeedtestApi = async (keyword: string): Promise<Array<string | null>>
|
|||||||
retry: {
|
retry: {
|
||||||
retries: 2
|
retries: 2
|
||||||
}
|
}
|
||||||
})).then(r => r.json()).then((data: Array<{ url: string }>) => data.reduce<string[]>(
|
})).then(r => r.json() as any).then((data: Array<{ url: string }>) => data.reduce<string[]>(
|
||||||
(prev, cur) => {
|
(prev, cur) => {
|
||||||
const hn = getHostname(cur.url, { detectIp: false });
|
const hn = getHostname(cur.url, { detectIp: false });
|
||||||
if (hn) {
|
if (hn) {
|
||||||
|
|||||||
@ -33,11 +33,7 @@ export const getTelegramCIDRPromise = createMemoizedPromise(async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
export const buildTelegramCIDR = task(import.meta.path, async (span) => {
|
export const buildTelegramCIDR = task(import.meta.path, async (span) => {
|
||||||
const promise = getTelegramCIDRPromise();
|
const { date, results } = await span.traceChildAsync('get telegram cidr', getTelegramCIDRPromise);
|
||||||
const peeked = Bun.peek(promise);
|
|
||||||
const { date, results } = peeked === promise
|
|
||||||
? await span.traceChildPromise('get telegram cidr', promise)
|
|
||||||
: (peeked as { date: Date, results: string[] });
|
|
||||||
|
|
||||||
if (results.length === 0) {
|
if (results.length === 0) {
|
||||||
throw new Error('Failed to fetch data!');
|
throw new Error('Failed to fetch data!');
|
||||||
|
|||||||
@ -65,10 +65,7 @@ export const downloadPreviousBuild = task(import.meta.path, async (span) => {
|
|||||||
const extract = tarStream.extract();
|
const extract = tarStream.extract();
|
||||||
|
|
||||||
pipeline(
|
pipeline(
|
||||||
Readable.fromWeb(
|
Readable.fromWeb(resp.body),
|
||||||
// @ts-expect-error -- DOM type is incompatible with Node type
|
|
||||||
resp.body
|
|
||||||
),
|
|
||||||
gunzip,
|
gunzip,
|
||||||
extract
|
extract
|
||||||
);
|
);
|
||||||
|
|||||||
@ -44,7 +44,6 @@ const getBunBlob = (file: string | URL | BunFile) => {
|
|||||||
return file;
|
return file;
|
||||||
};
|
};
|
||||||
|
|
||||||
// @ts-expect-error -- ReadableStream<string> should be AsyncIterable<string>
|
|
||||||
export const readFileByLine: ((file: string | URL | BunFile) => AsyncIterable<string>) = enableTextLineStream
|
export const readFileByLine: ((file: string | URL | BunFile) => AsyncIterable<string>) = enableTextLineStream
|
||||||
? (file: string | URL | BunFile) => getBunBlob(file).stream().pipeThrough(new PolyfillTextDecoderStream()).pipeThrough(new TextLineStream())
|
? (file: string | URL | BunFile) => getBunBlob(file).stream().pipeThrough(new PolyfillTextDecoderStream()).pipeThrough(new TextLineStream())
|
||||||
: (file: string | URL | BunFile) => createTextLineAsyncIterableFromStreamSource(getBunBlob(file).stream());
|
: (file: string | URL | BunFile) => createTextLineAsyncIterableFromStreamSource(getBunBlob(file).stream());
|
||||||
@ -59,7 +58,6 @@ const ensureResponseBody = (resp: Response) => {
|
|||||||
return resp.body;
|
return resp.body;
|
||||||
};
|
};
|
||||||
|
|
||||||
// @ts-expect-error -- ReadableStream<string> should be AsyncIterable<string>
|
|
||||||
export const createReadlineInterfaceFromResponse: ((resp: Response) => AsyncIterable<string>) = enableTextLineStream
|
export const createReadlineInterfaceFromResponse: ((resp: Response) => AsyncIterable<string>) = enableTextLineStream
|
||||||
? (resp) => ensureResponseBody(resp).pipeThrough(new PolyfillTextDecoderStream()).pipeThrough(new TextLineStream())
|
? (resp) => ensureResponseBody(resp).pipeThrough(new PolyfillTextDecoderStream()).pipeThrough(new TextLineStream())
|
||||||
: (resp) => createTextLineAsyncIterableFromStreamSource(ensureResponseBody(resp));
|
: (resp) => createTextLineAsyncIterableFromStreamSource(ensureResponseBody(resp));
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
const SENTINEL = Symbol('SENTINEL');
|
const SENTINEL = Symbol('SENTINEL');
|
||||||
const PARENT = Symbol('Parent Node');
|
const PARENT = Symbol('Parent Node');
|
||||||
|
|
||||||
const noop: VoidFunction = () => { /** noop */ };
|
const noop = () => { /** noop */ };
|
||||||
|
|
||||||
type TrieNode = {
|
type TrieNode = {
|
||||||
[SENTINEL]: boolean,
|
[SENTINEL]: boolean,
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "esnext",
|
"target": "esnext",
|
||||||
"lib": ["DOM", "DOM.Iterable"],
|
"lib": ["ESNext"],
|
||||||
"moduleDetection": "force",
|
"moduleDetection": "force",
|
||||||
"module": "esnext",
|
"module": "esnext",
|
||||||
"moduleResolution": "bundler",
|
"moduleResolution": "bundler",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user