Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): use all style language watch file…
Browse files Browse the repository at this point in the history
…s in esbuild builder

A recent change to better support Tailwind CSS in watch mode unintentionally caused part
of the watch files list for stylesheets to be ignored when Tailwind and/or autoprefixer
were required to be executed. This resulted in rebuilds occurring but all stylesheet changes
were not fully propagated to the development server. This has now been corrected.

(cherry picked from commit 4cf83eb)
  • Loading branch information
clydin authored and alan-agius4 committed Jun 26, 2023
1 parent 3475e02 commit 5023650
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ async function compileString(
options: StylesheetPluginOptions,
): Promise<OnLoadResult> {
try {
const result = await postcssProcessor.process(data, {
const postcssResult = await postcssProcessor.process(data, {
from: filename,
to: filename,
map: options.sourcemap && {
Expand All @@ -241,11 +241,15 @@ async function compileString(
},
});

const rawWarnings = result.warnings();
let warnings;
const loadResult: OnLoadResult = {
contents: postcssResult.css,
loader: 'css',
};

const rawWarnings = postcssResult.warnings();
if (rawWarnings.length > 0) {
const lineMappings = new Map<string, string[] | null>();
warnings = rawWarnings.map((warning) => {
loadResult.warnings = rawWarnings.map((warning) => {
const file = warning.node.source?.input.file;
if (file === undefined) {
return { text: warning.text };
Expand All @@ -269,28 +273,22 @@ async function compileString(
});
}

let watchFiles;
for (const resultMessage of result.messages) {
for (const resultMessage of postcssResult.messages) {
if (resultMessage.type === 'dependency' && typeof resultMessage['file'] === 'string') {
watchFiles ??= [];
watchFiles.push(resultMessage['file']);
loadResult.watchFiles ??= [];
loadResult.watchFiles.push(resultMessage['file']);
} else if (
resultMessage.type === 'dir-dependency' &&
typeof resultMessage['dir'] === 'string' &&
typeof resultMessage['glob'] === 'string'
) {
watchFiles ??= [];
loadResult.watchFiles ??= [];
const dependencies = await glob(resultMessage['glob'], { cwd: resultMessage['dir'] });
watchFiles.push(...dependencies);
loadResult.watchFiles.push(...dependencies);
}
}

return {
contents: result.css,
loader: 'css',
warnings,
watchFiles,
};
return loadResult;
} catch (error) {
postcss ??= (await import('postcss')).default;
if (error instanceof postcss.CssSyntaxError) {
Expand Down
15 changes: 15 additions & 0 deletions tests/legacy-cli/e2e/tests/basic/rebuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,19 @@ export default async function () {
throw new Error('Expected component CSS to update.');
}
}

await Promise.all([
waitForAnyProcessOutputToMatch(validBundleRegEx),
writeMultipleFiles({
'src/styles.css': 'div { color: green; }',
}),
]);

{
const response = await fetch(`http://localhost:${port}/styles.css`);
const body = await response.text();
if (!body.match(/color:\s?green/)) {
throw new Error('Expected component CSS to update.');
}
}
}

0 comments on commit 5023650

Please sign in to comment.