diff --git a/Build/build-public.ts b/Build/build-public.ts index 1739b3a7..82e7733f 100644 --- a/Build/build-public.ts +++ b/Build/build-public.ts @@ -22,7 +22,8 @@ export const buildPublic = task(import.meta.path, async (span) => { .traceChild('copy public files') .traceAsyncFn(async () => { const filesToBeCopied = (await listDir( - rootPath, { + rootPath, + { ignoreHidden: true, ignorePattern: /node_modules|Build|public/ } diff --git a/Build/index.ts b/Build/index.ts index 4fc2c06e..c3fb0e66 100644 --- a/Build/index.ts +++ b/Build/index.ts @@ -64,9 +64,7 @@ console.log('Bun version:', Bun.version, Bun.revision); const buildMicrosoftCdnPromise = downloadPreviousBuildPromise.then(() => buildMicrosoftCdn(rootSpan)); - const buildSSPanelUIMAppProfilePromise = Promise.all([ - downloadPreviousBuildPromise - ]).then(() => buildSSPanelUIMAppProfile(rootSpan)); + const buildSSPanelUIMAppProfilePromise = downloadPreviousBuildPromise.then(() => buildSSPanelUIMAppProfile(rootSpan)); const downloadMockAssetsPromise = downloadMockAssets(rootSpan); diff --git a/Build/lib/fetch-text-by-line.ts b/Build/lib/fetch-text-by-line.ts index 3c2cfd7c..aa8e080d 100644 --- a/Build/lib/fetch-text-by-line.ts +++ b/Build/lib/fetch-text-by-line.ts @@ -7,15 +7,12 @@ import { processLine } from './process-line'; const enableTextLineStream = !!process.env.ENABLE_TEXT_LINE_STREAM; -interface TextLineStreamLike { - [Symbol.asyncIterator](): AsyncIterableIterator -} - const decoder = new TextDecoder('utf-8'); -async function *createTextLineAsyncGeneratorFromStreamSource(stream: ReadableStream): AsyncGenerator { +async function *createTextLineAsyncIterableFromStreamSource(stream: ReadableStream): AsyncIterable { let buf = ''; - for await (const chunk of stream as any) { + // @ts-expect-error -- ReadableStream should be AsyncIterable + for await (const chunk of stream) { const chunkStr = decoder.decode(chunk).replaceAll('\r\n', '\n'); for (let i = 0, len = chunkStr.length; i < len; i++) { const char = chunkStr[i]; @@ -33,45 +30,34 @@ async function *createTextLineAsyncGeneratorFromStreamSource(stream: ReadableStr } } -export const readFileByLine: ((file: string | URL | BunFile) => TextLineStreamLike) = enableTextLineStream - ? (file: string | URL | BunFile) => { - if (typeof file === 'string') { - file = Bun.file(file); - } else if (!('writer' in file)) { - file = Bun.file(file); - } - - return file.stream().pipeThrough(new PolyfillTextDecoderStream()).pipeThrough(new TextLineStream()); +const getBunBlob = (file: string | URL | BunFile) => { + if (typeof file === 'string') { + return Bun.file(file); + } if (!('writer' in file)) { + return Bun.file(file); } - : (file: string | URL | BunFile) => { - if (typeof file === 'string') { - file = Bun.file(file); - } else if (!('writer' in file)) { - file = Bun.file(file); - } + return file; +}; - return createTextLineAsyncGeneratorFromStreamSource(file.stream()) as any; - }; +// @ts-expect-error -- ReadableStream should be AsyncIterable +export const readFileByLine: ((file: string | URL | BunFile) => AsyncIterable) = enableTextLineStream + ? (file: string | URL | BunFile) => getBunBlob(file).stream().pipeThrough(new PolyfillTextDecoderStream()).pipeThrough(new TextLineStream()) + : (file: string | URL | BunFile) => createTextLineAsyncIterableFromStreamSource(getBunBlob(file).stream()); -export const createReadlineInterfaceFromResponse: ((resp: Response) => TextLineStreamLike) = enableTextLineStream - ? (resp) => { - if (!resp.body) { - throw new Error('Failed to fetch remote text'); - } - if (resp.bodyUsed) { - throw new Error('Body has already been consumed.'); - } - return resp.body.pipeThrough(new PolyfillTextDecoderStream()).pipeThrough(new TextLineStream()); +const ensureResponseBody = (resp: Response) => { + if (!resp.body) { + throw new Error('Failed to fetch remote text'); } - : (resp) => { - if (!resp.body) { - throw new Error('Failed to fetch remote text'); - } - if (resp.bodyUsed) { - throw new Error('Body has already been consumed.'); - } - return createTextLineAsyncGeneratorFromStreamSource(resp.body) as any; - }; + if (resp.bodyUsed) { + throw new Error('Body has already been consumed.'); + } + return resp.body; +}; + +// @ts-expect-error -- ReadableStream should be AsyncIterable +export const createReadlineInterfaceFromResponse: ((resp: Response) => AsyncIterable) = enableTextLineStream + ? (resp) => ensureResponseBody(resp).pipeThrough(new PolyfillTextDecoderStream()).pipeThrough(new TextLineStream()) + : (resp) => createTextLineAsyncIterableFromStreamSource(ensureResponseBody(resp)); export function fetchRemoteTextByLine(url: string | URL) { return fetchWithRetry(url, defaultRequestInit).then(createReadlineInterfaceFromResponse); diff --git a/Build/lib/process-line.ts b/Build/lib/process-line.ts index 9124ca1f..ab41b08f 100644 --- a/Build/lib/process-line.ts +++ b/Build/lib/process-line.ts @@ -23,7 +23,7 @@ export const processLine = (line: string): string | null => { return trimmed; }; -export const processLineFromReadline = async (rl: AsyncGenerator | ReadableStream): Promise => { +export const processLineFromReadline = async (rl: AsyncIterable): Promise => { const res: string[] = []; for await (const line of rl) { const l: string | null = processLine(line); diff --git a/Build/lib/text-decoder-stream.ts b/Build/lib/text-decoder-stream.ts index 04502696..b99d948b 100644 --- a/Build/lib/text-decoder-stream.ts +++ b/Build/lib/text-decoder-stream.ts @@ -21,7 +21,7 @@ export class PolyfillTextDecoderStream extends TransformStream[1] = {} ) { const decoder = new TextDecoder(encoding, { fatal, ignoreBOM });