Skip to content

Commit d802fc2

Browse files
committed
fix(@angular-devkit/build-angular): cache stylesheet load errors with application builder
When using the `application` and/or `browser-esbuild` builders, stylesheets that generate errors will now have the errors cached between rebuilds during watch mode (include `ng serve`). This not only avoids reprocessing files that contain errors and that have not changed but also provides file watching information from the cache to ensure the error-causing files are properly invalidated.
1 parent cbe55df commit d802fc2

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

packages/angular_devkit/build_angular/src/tools/esbuild/load-result-cache.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ export function createCachedLoad(
3030
if (result === undefined) {
3131
result = await callback(args);
3232

33-
// Do not cache null or undefined or results with errors
34-
if (result && result.errors === undefined) {
33+
// Do not cache null or undefined
34+
if (result) {
3535
await cache.put(loadCacheKey, result);
3636
}
3737
}

packages/angular_devkit/build_angular/src/tools/esbuild/stylesheets/less-language.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ async function compileString(
115115
};
116116
} catch (error) {
117117
if (isLessException(error)) {
118+
const location = convertExceptionLocation(error);
119+
118120
// Retry with a warning for less files requiring the deprecated inline JavaScript option
119121
if (error.message.includes('Inline JavaScript is not enabled.')) {
120122
const withJsResult = await compileString(
@@ -127,7 +129,7 @@ async function compileString(
127129
withJsResult.warnings = [
128130
{
129131
text: 'Deprecated inline execution of JavaScript has been enabled ("javascriptEnabled")',
130-
location: convertExceptionLocation(error),
132+
location,
131133
notes: [
132134
{
133135
location: null,
@@ -148,10 +150,11 @@ async function compileString(
148150
errors: [
149151
{
150152
text: error.message,
151-
location: convertExceptionLocation(error),
153+
location,
152154
},
153155
],
154156
loader: 'css',
157+
watchFiles: location.file ? [filename, location.file] : [filename],
155158
};
156159
}
157160

packages/angular_devkit/build_angular/src/tools/esbuild/stylesheets/sass-language.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ async function compileString(
176176
};
177177
} catch (error) {
178178
if (isSassException(error)) {
179-
const file = error.span.url ? fileURLToPath(error.span.url) : undefined;
179+
const fileWithError = error.span.url ? fileURLToPath(error.span.url) : undefined;
180180

181181
return {
182182
loader: 'css',
@@ -186,7 +186,7 @@ async function compileString(
186186
},
187187
],
188188
warnings,
189-
watchFiles: file ? [file] : undefined,
189+
watchFiles: fileWithError ? [filePath, fileWithError] : [filePath],
190190
};
191191
}
192192

0 commit comments

Comments
 (0)