Skip to content

Commit 2119fd6

Browse files
committed
fixup! perf(@angular/build): share sass directory and resolution caches across stylesheets
1 parent 9335f54 commit 2119fd6

3 files changed

Lines changed: 20 additions & 3 deletions

File tree

packages/angular/build/src/builders/application/build-action.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ import {
1515
RebuildState,
1616
} from '../../tools/esbuild/bundler-execution-result';
1717
import { BuildOutputFile, BuildOutputFileType } from '../../tools/esbuild/bundler-files';
18-
import { shutdownSassWorkerPool } from '../../tools/esbuild/stylesheets/sass-language';
18+
import {
19+
resetSassWorkerPoolCaches,
20+
shutdownSassWorkerPool,
21+
} from '../../tools/esbuild/stylesheets/sass-language';
1922
import { logMessages, withNoProgress, withSpinner } from '../../tools/esbuild/utils';
2023
import { ChangedFiles } from '../../tools/esbuild/watcher';
2124
import { shouldWatchRoot } from '../../utils/environment-options';
@@ -210,6 +213,8 @@ export async function* runEsBuildBuildAction(
210213
// Clear removed files from current watch files
211214
changes.removed.forEach((removedPath) => currentWatchFiles.delete(removedPath));
212215

216+
resetSassWorkerPoolCaches();
217+
213218
const rebuildState = result.createRebuildState(changes);
214219
result = await withProgress('Changes detected. Rebuilding...', () => action(rebuildState));
215220

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,18 @@ function isSassException(error: unknown): error is Exception {
2323
return !!error && typeof error === 'object' && 'sassMessage' in error;
2424
}
2525

26+
export function resetSassWorkerPoolCaches(): void {
27+
resolutionCache?.clear();
28+
packageRootCache?.clear();
29+
if (sassService) {
30+
sassService.clearCache();
31+
} else if (sassServicePromise) {
32+
void sassServicePromise.then((service) => service.clearCache());
33+
}
34+
}
35+
2636
export function shutdownSassWorkerPool(): void {
27-
resolutionCache = undefined;
28-
packageRootCache = undefined;
37+
resetSassWorkerPoolCaches();
2938
if (sassService) {
3039
void sassService.close();
3140
sassService = undefined;

packages/angular_devkit/build_angular/src/tools/webpack/configs/styles.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ export async function getStylesConfig(wco: WebpackConfigOptions): Promise<Config
7070

7171
extraPlugins.push({
7272
apply(compiler) {
73+
compiler.hooks.thisCompilation.tap('sass-service', () => {
74+
sassImplementation.clearCache();
75+
});
7376
compiler.hooks.shutdown.tap('sass-service', () => {
7477
void sassImplementation.close();
7578
});

0 commit comments

Comments
 (0)