diff --git a/Build/build-speedtest-domainset.ts b/Build/build-speedtest-domainset.ts index 0faed415..5079f8f1 100644 --- a/Build/build-speedtest-domainset.ts +++ b/Build/build-speedtest-domainset.ts @@ -13,6 +13,7 @@ import { readFileIntoProcessedArray } from './lib/fetch-text-by-line'; import { TTL, deserializeArray, fsFetchCache, serializeArray } from './lib/cache-filesystem'; import { createTrie } from './lib/trie'; +import { peek } from './lib/bun'; const s = new Sema(2); @@ -239,7 +240,7 @@ export const buildSpeedtestDomainSet = task(import.meta.main, import.meta.path)( const timer = setTimeout(() => { console.error(picocolors.red('Task timeout!')); Object.entries(pMap).forEach(([name, p]) => { - console.log(`[${name}]`, Bun.peek.status(p)); + console.log(`[${name}]`, peek.status(p)); }); resolve(); diff --git a/Build/download-previous-build.ts b/Build/download-previous-build.ts index 4c878690..dd946fb7 100644 --- a/Build/download-previous-build.ts +++ b/Build/download-previous-build.ts @@ -33,7 +33,6 @@ export const downloadPreviousBuild = task(import.meta.main, import.meta.path)(as buildOutputList.push(line); if (!isCI) { - // Bun.file().exists() doesn't check directory if (!existsSync(path.join(import.meta.dir, '..', line))) { flag = flag & ~ALL_FILES_EXISTS; } diff --git a/Build/lib/bun.ts b/Build/lib/bun.ts new file mode 100644 index 00000000..13f43b62 --- /dev/null +++ b/Build/lib/bun.ts @@ -0,0 +1,13 @@ +interface Peek { + (promise: T | Promise): Promise | T, + status( + promise: T | Promise, + ): 'pending' | 'fulfilled' | 'rejected' | 'unknown' +} + +const noopPeek = (_: Promise) => _; +noopPeek.status = () => 'unknown'; + +export const peek: Peek = typeof Bun !== 'undefined' + ? Bun.peek + : noopPeek as Peek; diff --git a/Build/lib/cache-filesystem.ts b/Build/lib/cache-filesystem.ts index 2cb0c599..bfdb1e2e 100644 --- a/Build/lib/cache-filesystem.ts +++ b/Build/lib/cache-filesystem.ts @@ -5,6 +5,7 @@ import path from 'path'; import { mkdirSync } from 'fs'; import picocolors from 'picocolors'; import { fastStringArrayJoin } from './misc'; +import { peek } from 'bun'; const identity = (x: any) => x; @@ -178,7 +179,7 @@ export class Cache { const serializer = 'serializer' in opt ? opt.serializer : identity; const promise = fn(); - const peeked = Bun.peek(promise); + const peeked = peek(promise); if (peeked === promise) { return promise.then((value) => { diff --git a/bun.lockb b/bun.lockb index b8a26819..627c72d2 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index cd09c36e..45ab37dc 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "csv-parse": "^5.5.6", "fast-cidr-tools": "^0.2.5", "fdir": "^6.1.1", + "foxact": "^0.2.36", "mnemonist": "^0.39.8", "path-scurry": "^1.11.1", "picocolors": "^1.0.1", @@ -47,5 +48,6 @@ }, "resolutions": { "has": "npm:@nolyfill/has@latest" - } + }, + "packageManager": "pnpm@9.5.0+sha512.140036830124618d624a2187b50d04289d5a087f326c9edfc0ccd733d76c4f52c3a313d4fc148794a2a9d81553016004e6742e8cf850670268a7387fc220c903" }