Skip to content

Commit 5c6e3ec

Browse files
committed
fix(@angular-devkit/build-angular): track postcss provided file dependencies in esbuild builder
Postcss plugins may provide result messages that contain stylesheet dependencies that should be watched and should trigger a rebuild of the stylesheet being processed. These files will now be linked to the stylesheet and will allow the provided file dependencies to be watched and in-memory caches to be invalidated. Both the `dependency` and `dir-dependency` postcss messages are supported.
1 parent 518149d commit 5c6e3ec

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

packages/angular_devkit/build_angular/src/tools/esbuild/stylesheets/stylesheet-plugin-factory.ts

+18
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import createAutoPrefixerPlugin from 'autoprefixer';
1010
import type { OnLoadResult, Plugin, PluginBuild } from 'esbuild';
11+
import glob from 'fast-glob';
1112
import assert from 'node:assert';
1213
import { readFile } from 'node:fs/promises';
1314
import { extname } from 'node:path';
@@ -268,10 +269,27 @@ async function compileString(
268269
});
269270
}
270271

272+
let watchFiles;
273+
for (const resultMessage of result.messages) {
274+
if (resultMessage.type === 'dependency' && typeof resultMessage['file'] === 'string') {
275+
watchFiles ??= [];
276+
watchFiles.push(resultMessage['file']);
277+
} else if (
278+
resultMessage.type === 'dir-dependency' &&
279+
typeof resultMessage['dir'] === 'string' &&
280+
typeof resultMessage['glob'] === 'string'
281+
) {
282+
watchFiles ??= [];
283+
const dependencies = await glob(resultMessage['glob'], { cwd: resultMessage['dir'] });
284+
watchFiles.push(...dependencies);
285+
}
286+
}
287+
271288
return {
272289
contents: result.css,
273290
loader: 'css',
274291
warnings,
292+
watchFiles,
275293
};
276294
} catch (error) {
277295
postcss ??= (await import('postcss')).default;

0 commit comments

Comments
 (0)