Skip to content

Commit 956ccc0

Browse files
committed
fix(@angular/build): address review feedback in sass directory and resolution caching
Qualify all imports with containing URL unless they start with 'pkg:' to prevent global collision of non-dot relative imports across different component directories. Add a public clearCache() method to SassCompiler to clear the directory cache, and invoke it inside close().
1 parent f616d89 commit 956ccc0

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

packages/angular/build/src/tools/esbuild/stylesheets/sass-language.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ async function compileString(
122122
importers: [
123123
{
124124
findFileUrl: (url, options) => {
125-
const cacheKey = url.startsWith('.')
126-
? `${options.containingUrl?.href ?? ''}:${url}`
127-
: url;
125+
const cacheKey = url.startsWith('pkg:')
126+
? url
127+
: `${options.containingUrl?.href ?? ''}:${url}`;
128128

129129
return currentResolutionCache.getOrCreate(cacheKey, async () => {
130130
const result = await resolveUrl(url, options);

packages/angular/build/src/tools/sass/sass-service.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,19 @@ export class SassCompiler {
188188
return result;
189189
}
190190

191+
/**
192+
* Clear the directory cache.
193+
*/
194+
clearCache(): void {
195+
this.#directoryCache.clear();
196+
}
197+
191198
/**
192199
* Shutdown the Sass compiler.
193200
* @returns A void promise that resolves when closing is complete.
194201
*/
195202
async close(): Promise<void> {
196-
this.#directoryCache.clear();
203+
this.clearCache();
197204

198205
if (this.#asyncCompilerPromise) {
199206
try {

0 commit comments

Comments
 (0)