/
githubmirror
/
angular-cli
Обзор
Документация
Войти
/
githubmirror
/
angular-cli
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/ngtools/webpack/src/ivy/symbol.ts
58 строк
1 KB
Charles Lyding
refactor(@ngtools/webpack): add types to exported module variables
15 янв 2025, 17:06
15 янв 2025, 17:06
e5368b8
Код
Авторство
О чём код?
/** * @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 */ export const AngularPluginSymbol: unique symbol = Symbol.for('@ngtools/webpack[angular-compiler]'); export interface EmitFileResult { content?: string; map?: string; dependencies: readonly string[]; hash?: Uint8Array; } export type FileEmitter = (file: string) => Promise<EmitFileResult | undefined>; export class FileEmitterRegistration { #fileEmitter?: FileEmitter; update(emitter: FileEmitter): void { this.#fileEmitter = emitter; } emit(file: string): Promise<EmitFileResult | undefined> { if (!this.#fileEmitter) { throw new Error('Emit attempted before Angular Webpack plugin initialization.'); } return this.#fileEmitter(file); } } export class FileEmitterCollection { #registrations: FileEmitterRegistration[] = []; register(): FileEmitterRegistration { const registration = new FileEmitterRegistration(); this.#registrations.push(registration); return registration; } async emit(file: string): Promise<EmitFileResult | undefined> { if (this.#registrations.length === 1) { return this.#registrations[0].emit(file); } for (const registration of this.#registrations) { const result = await registration.emit(file); if (result) { return result; } } } }