/
githubmirror
/
angular-cli
Обзор
Документация
Войти
/
githubmirror
/
angular-cli
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/angular/build/src/utils/index-file/html-rewriting-stream.ts
37 строк
1 KB
Alan Agius
refactor: replace `loadEsmModule` with dynamic `import()`
21 окт 2025, 16:05
21 окт 2025, 16:05
b356bb1
Код
Авторство
О чём код?
/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.dev/license */ import { Readable } from 'node:stream'; import { pipeline } from 'node:stream/promises'; import type { RewritingStream } from 'parse5-html-rewriting-stream'; // Export helper types for the rewriter export type StartTag = Parameters<RewritingStream['emitStartTag']>[0]; export type EndTag = Parameters<RewritingStream['emitEndTag']>[0]; export type { RewritingStream }; export async function htmlRewritingStream(content: string): Promise<{ rewriter: RewritingStream; transformedContent: () => Promise<string>; }> { const { RewritingStream } = await import('parse5-html-rewriting-stream'); const rewriter = new RewritingStream(); return { rewriter, transformedContent: () => pipeline(Readable.from(content), rewriter, async function (source) { const chunks = []; for await (const chunk of source) { chunks.push(Buffer.from(chunk)); } return Buffer.concat(chunks).toString('utf-8'); }), }; }