From 8168e3bd41cc45c92349bc522321bc62a5ef4a8f Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Wed, 9 Oct 2024 14:48:08 +0200 Subject: [PATCH] build: account for absolute paths in token extraction (#29848) Fixes an error that is currently breaking the patch branch, because we didn't have a resolver for imports like `@use '@angular/cdk';`. --- tools/extract-tokens/extract-tokens.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tools/extract-tokens/extract-tokens.ts b/tools/extract-tokens/extract-tokens.ts index 62b94e9595d7..4c7813e47138 100644 --- a/tools/extract-tokens/extract-tokens.ts +++ b/tools/extract-tokens/extract-tokens.ts @@ -74,8 +74,9 @@ function extractTokens(themePath: string): Token[] { const startMarker = '/*! extract tokens start */'; const endMarker = '/*! extract tokens end */'; - const absoluteThemePath = join(process.cwd(), themePath); - const srcPath = join(process.cwd(), 'src'); + const root = process.cwd(); + const absoluteThemePath = join(root, themePath); + const srcPath = join(root, 'src'); const {prepend, append} = getTokenExtractionCode( srcPath, themePath, @@ -93,6 +94,16 @@ function extractTokens(themePath: string): Token[] { compileString(toCompile, { loadPaths: [srcPath], url: pathToFileURL(absoluteThemePath), + importers: [ + { + findFileUrl: (url: string) => { + const angularPrefix = '@angular/'; + return url.startsWith(angularPrefix) + ? pathToFileURL(join(srcPath, url.substring(angularPrefix.length))) + : null; + }, + }, + ], sourceMap: false, logger: { debug: message => {