From 906cec9db68f4b325b2f17620749397df47eb850 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Tue, 10 Sep 2024 16:34:56 +0000 Subject: [PATCH] refactor(@angular/build): add explicit type annotations to avoid inferred types This refactor resolves an issue where the inferred type of `renderSassStylesheet` required an external reference, which could affect portability. Fixes the following error: ``` packages/angular/build/src/tools/sass/worker.ts:59:31 - error TS2742: The inferred type of 'renderSassStylesheet' cannot be named without a reference to '../../../../../../external/npm/node_modules/source-map-js/source-map'. This is likely not portable. A type annotation is necessary. ``` Explicit type annotation added to `renderSassStylesheet` function to prevent reliance on inferred types. **Note:** Ensure compatibility with Windows Bazel builds. --- .../angular/build/src/tools/sass/worker.ts | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/packages/angular/build/src/tools/sass/worker.ts b/packages/angular/build/src/tools/sass/worker.ts index f0d7d5cd8b06..88a2d2ecfad9 100644 --- a/packages/angular/build/src/tools/sass/worker.ts +++ b/packages/angular/build/src/tools/sass/worker.ts @@ -56,7 +56,29 @@ interface RenderRequestMessage { rebase: boolean; } -export default async function renderSassStylesheet(request: RenderRequestMessage) { +interface RenderResult { + warnings: SerializableWarningMessage[] | undefined; + result: { + css: string; + loadedUrls: string[]; + sourceMap?: RawSourceMap; + }; +} + +interface RenderError { + warnings: SerializableWarningMessage[] | undefined; + error: { + message: string; + stack?: string; + span?: Omit & { url?: string }; + sassMessage?: string; + sassStack?: string; + }; +} + +export default async function renderSassStylesheet( + request: RenderRequestMessage, +): Promise { const { importerChannel, hasLogger, source, options, rebase } = request; const entryDirectory = dirname(options.url); @@ -164,6 +186,7 @@ export default async function renderSassStylesheet(request: RenderRequestMessage warnings, result: { ...result, + sourceMap: result.sourceMap as unknown as RawSourceMap | undefined, // URL is not serializable so to convert to string here and back to URL in the parent. loadedUrls: result.loadedUrls.map((p) => fileURLToPath(p)), },