Repository navigation
fix(@angular/build): rebuild stylesheets when files are added to a PostCSS directory dependency #34451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(@angular/build): rebuild stylesheets when files are added to a PostCSS directory dependency #34451
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,7 @@ | |
| */ | ||
|
|
||
| import type { OnLoadResult, PluginBuild } from 'esbuild'; | ||
| import { normalize } from 'node:path'; | ||
| import { dirname, normalize } from 'node:path'; | ||
|
|
||
| export interface LoadResultCache { | ||
| get(path: string): OnLoadResult | Promise<OnLoadResult | undefined> | undefined; | ||
|
|
@@ -108,16 +108,27 @@ export class MemoryLoadResultCache implements LoadResultCache { | |
| } | ||
|
|
||
| invalidate(path: string): boolean { | ||
| const affectedPaths = this.#fileDependencies.get(path); | ||
| if (!affectedPaths) { | ||
| return false; | ||
| } | ||
| let invalid = false; | ||
|
|
||
| // Check parent directories to support directory dependencies (PostCSS `dir-dependency`) | ||
| let current = normalize(path); | ||
| while (true) { | ||
| const affectedPaths = this.#fileDependencies.get(current); | ||
| if (affectedPaths) { | ||
| for (const affected of affectedPaths) { | ||
| this.#loadResults.delete(affected); | ||
| } | ||
| invalid = true; | ||
| } | ||
|
|
||
| for (const affected of affectedPaths) { | ||
| this.#loadResults.delete(affected); | ||
| const parent = dirname(current); | ||
| if (parent === current) { | ||
| break; | ||
| } | ||
| current = parent; | ||
| } | ||
|
|
||
| return true; | ||
| return invalid; | ||
| } | ||
|
Comment on lines
+111
to
132
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Walking up Also, after recent changes on Lastly, |
||
|
|
||
| get watchFiles(): string[] { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -401,6 +401,8 @@ async function compileString( | |
| typeof resultMessage['glob'] === 'string' | ||
| ) { | ||
| loadResult.watchFiles ??= []; | ||
| // Watch the directory itself so files added or moved into it later also cause a rebuild | ||
| loadResult.watchFiles.push(resultMessage['dir']); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding
|
||
| const dependencies = await glob(resultMessage['glob'], { | ||
| absolute: true, | ||
| cwd: resultMessage['dir'], | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use a unique plugin filename here instead of
test-plugin.js. An earlier test in this suite also uses./test-plugin.jsin.postcssrc.json, andStylesheetPluginFactorycaches PostCSS processors by config andrequire.cache, which can cause the wrong plugin to be reused.