Browse Source

Remove unused Bun.peek

SukkaW 1 year ago
parent
commit
7167be852f

+ 1 - 4
Build/build-apple-cdn.ts

@@ -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[] = peeked === promise
-    ? await span.traceChildPromise('get apple cdn domains', promise)
-    : (peeked as string[]);
+  const res: string[] = await span.traceChildPromise('get apple cdn domains', promise);
 
 
   const description = [
   const description = [
     ...SHARED_DESCRIPTION,
     ...SHARED_DESCRIPTION,

+ 1 - 5
Build/build-chn-cidr.ts

@@ -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 peeked = Bun.peek(cidrPromise);
-  const filteredCidr: string[] = peeked === cidrPromise
-    ? await span.traceChildPromise('download chnroutes2', cidrPromise)
-    : (peeked as string[]);
+  const filteredCidr = await span.traceChildAsync('download chnroutes2', getChnCidrPromise);
 
 
   // Can not use SHARED_DESCRIPTION here as different license
   // Can not use SHARED_DESCRIPTION here as different license
   const description = [
   const description = [

+ 2 - 2
Build/build-speedtest-domainset.ts

@@ -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) {

+ 1 - 5
Build/build-telegram-cidr.ts

@@ -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 peeked = Bun.peek(promise);
-  const { date, results } = peeked === promise
-    ? await span.traceChildPromise('get telegram cidr', promise)
-    : (peeked as { date: Date, results: string[] });
+  const { date, results } = await span.traceChildAsync('get telegram cidr', getTelegramCIDRPromise);
 
 
   if (results.length === 0) {
   if (results.length === 0) {
     throw new Error('Failed to fetch data!');
     throw new Error('Failed to fetch data!');

+ 1 - 4
Build/download-previous-build.ts

@@ -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(
-          // @ts-expect-error -- DOM type is incompatible with Node type
-          resp.body
-        ),
+        Readable.fromWeb(resp.body),
         gunzip,
         gunzip,
         extract
         extract
       );
       );

+ 0 - 2
Build/lib/fetch-text-by-line.ts

@@ -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));

+ 1 - 1
Build/lib/trie.ts

@@ -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 - 1
tsconfig.json

@@ -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",