From 1f42c27afe978cdee832206047bf27a29f76876b Mon Sep 17 00:00:00 2001 From: SukkaW Date: Tue, 23 Jul 2024 16:33:58 +0800 Subject: [PATCH] Refactor: drop `Bun.inspect` and `Bun.version` --- .swcrc | 10 ++++++++++ Build/index.ts | 2 +- Build/lib/fetch-text-by-line.ts | 15 +++++++-------- Build/lib/text-decoder-stream.ts | 2 +- Build/lib/trie.ts | 3 ++- 5 files changed, 21 insertions(+), 11 deletions(-) create mode 100644 .swcrc diff --git a/.swcrc b/.swcrc new file mode 100644 index 00000000..97a75ad4 --- /dev/null +++ b/.swcrc @@ -0,0 +1,10 @@ +{ + "$schema": "https://swc.rs/schema.json", + "jsc": { + "target": "esnext", + "parser": { + "syntax": "typescript", + "dynamicImport": true + } + } +} diff --git a/Build/index.ts b/Build/index.ts index 9abb4c1c..f5789f73 100644 --- a/Build/index.ts +++ b/Build/index.ts @@ -1,4 +1,4 @@ -console.log('Bun version:', Bun.version, Bun.revision); +console.log('Version:', process.version, typeof Bun !== 'undefined' ? Bun.revision : ''); import { downloadPreviousBuild } from './download-previous-build'; import { buildCommon } from './build-common'; diff --git a/Build/lib/fetch-text-by-line.ts b/Build/lib/fetch-text-by-line.ts index 1ed8cf82..3e89f448 100644 --- a/Build/lib/fetch-text-by-line.ts +++ b/Build/lib/fetch-text-by-line.ts @@ -69,13 +69,12 @@ export function fetchRemoteTextByLine(url: string | URL) { return fetchWithRetry(url, defaultRequestInit).then(createReadlineInterfaceFromResponse); } -export async function readFileIntoProcessedArray(file: string | URL | BunFile) { - if (typeof file === 'string') { - file = Bun.file(file); - } else if (!('writer' in file)) { - file = Bun.file(file); +export async function readFileIntoProcessedArray(file: string | BunFile | FileHandle) { + const results = []; + for await (const line of readFileByLine(file)) { + if (processLine(line)) { + results.push(line); + } } - - const content = await file.text(); - return content.split('\n').filter(processLine); + return results; } diff --git a/Build/lib/text-decoder-stream.ts b/Build/lib/text-decoder-stream.ts index bc0e8257..c06f589c 100644 --- a/Build/lib/text-decoder-stream.ts +++ b/Build/lib/text-decoder-stream.ts @@ -20,7 +20,7 @@ export class PolyfillTextDecoderStream extends TransformStream | null, hostnameMode = }, whitelist, - [Bun.inspect.custom]: (depth: number) => JSON.stringify(deepTrieNodeToJSON(root), null, 2).split('\n').map((line) => ' '.repeat(depth) + line).join('\n'), + [inspect.custom]: (depth: number) => JSON.stringify(deepTrieNodeToJSON(root), null, 2).split('\n').map((line) => ' '.repeat(depth) + line).join('\n'), hostnameMode, smolTree