Browse Source

Minor changes to previous build downloading

SukkaW 2 years ago
parent
commit
59b2608ef2

+ 1 - 1
Build/build-cdn-download-conf.ts

@@ -4,7 +4,7 @@ import { readFileIntoProcessedArray } from './lib/fetch-text-by-line';
 import { createTrie } from './lib/trie';
 import { task } from './trace';
 import { SHARED_DESCRIPTION } from './lib/constants';
-import { getPublicSuffixListTextPromise } from './download-publicsuffixlist';
+import { getPublicSuffixListTextPromise } from './lib/download-publicsuffixlist';
 
 const getS3OSSDomainsPromise = (async (): Promise<Set<string>> => {
   const trie = createTrie((await getPublicSuffixListTextPromise()).split('\n'));

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

@@ -22,8 +22,8 @@ const s = new Sema(2);
 const latestTopUserAgentsPromise = fsFetchCache.apply(
   'https://unpkg.com/top-user-agents@latest/src/desktop.json',
   () => fetchWithRetry('https://unpkg.com/top-user-agents@latest/src/desktop.json')
-    .then(res => res.json<string[]>())
-    .then(userAgents => userAgents.filter(ua => ua.startsWith('Mozilla/5.0 '))),
+    .then(res => res.json())
+    .then((userAgents: string[]) => userAgents.filter(ua => ua.startsWith('Mozilla/5.0 '))),
   {
     serializer: serializeArray,
     deserializer: deserializeArray,
@@ -62,7 +62,7 @@ const querySpeedtestApi = async (keyword: string): Promise<Array<string | null>>
         retry: {
           retries: 2
         }
-      })).then(r => r.json<Array<{ url: string }>>()).then(data => data.reduce<string[]>(
+      })).then(r => r.json()).then((data: Array<{ url: string }>) => data.reduce<string[]>(
         (prev, cur) => {
           const hn = tldts.getHostname(cur.url, { detectIp: false });
           if (hn) {

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

@@ -61,10 +61,11 @@ export const downloadPreviousBuild = task(import.meta.path, async (span) => {
         throw new Error('Download previous build failed! No body found');
       }
 
-      const extract = tarStream.extract();
       const gunzip = zlib.createGunzip();
+      const extract = tarStream.extract();
+
       pipeline(
-        Readable.fromWeb(resp.body) as any,
+        Readable.fromWeb(resp.body as unknown as import('stream/web').ReadableStream<any>),
         gunzip,
         extract
       );
@@ -86,10 +87,7 @@ export const downloadPreviousBuild = task(import.meta.path, async (span) => {
         const targetPath = path.join(import.meta.dir, '..', relativeEntryPath);
 
         await mkdir(path.dirname(targetPath), { recursive: true });
-        await pipeline(
-          entry as any,
-          createWriteStream(targetPath)
-        );
+        await pipeline(entry, createWriteStream(targetPath));
       }
     });
 });

+ 3 - 3
Build/download-publicsuffixlist.ts → Build/lib/download-publicsuffixlist.ts

@@ -1,6 +1,6 @@
-import { TTL, fsFetchCache } from './lib/cache-filesystem';
-import { defaultRequestInit, fetchWithRetry } from './lib/fetch-retry';
-import { createMemoizedPromise } from './lib/memo-promise';
+import { TTL, fsFetchCache } from './cache-filesystem';
+import { defaultRequestInit, fetchWithRetry } from './fetch-retry';
+import { createMemoizedPromise } from './memo-promise';
 
 export const getPublicSuffixListTextPromise = createMemoizedPromise(() => fsFetchCache.apply(
   'https://publicsuffix.org/list/public_suffix_list.dat',

+ 1 - 1
Build/lib/get-gorhill-publicsuffix.ts

@@ -1,6 +1,6 @@
 import { toASCII } from 'punycode';
 import { createMemoizedPromise } from './memo-promise';
-import { getPublicSuffixListTextPromise } from '../download-publicsuffixlist';
+import { getPublicSuffixListTextPromise } from './download-publicsuffixlist';
 
 const customFetch = (url: string | URL): Promise<Blob> => Promise.resolve(Bun.file(url));