Repository navigation
fix(@angular/build): align library watch asset matching with initial build and deduplicate outputs #34432
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
Merged
alan-agius4
merged 4 commits into
angular:main
from
alan-agius4:fix/library-assets-watch-and-dedup
Oct 21, 2026
Merged
fix(@angular/build): align library watch asset matching with initial build and deduplicate outputs #34432
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
18d6d74
fix(@angular/build): align library watch asset matching with initial …
alan-agius4 9103274
fixup! fix(@angular/build): align library watch asset matching with i…
alan-agius4 f016e0a
fixup! fix(@angular/build): align library watch asset matching with i…
alan-agius4 b166b6a
fixup! fix(@angular/build): align library watch asset matching with i…
alan-agius4 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
179 changes: 179 additions & 0 deletions
179
packages/angular/build/src/builders/library/pipeline/assets_spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,179 @@ | ||
| /** | ||
| * @license | ||
| * Copyright Google LLC All Rights Reserved. | ||
| * | ||
| * Use of this source code is governed by an MIT-style license that can be | ||
| * found in the LICENSE file at https://angular.dev/license | ||
| */ | ||
|
|
||
| import assert from 'node:assert'; | ||
| import { mkdir, mkdtemp, rm, symlink, writeFile } from 'node:fs/promises'; | ||
| import path from 'node:path'; | ||
| import { toPosixPath } from '../../../utils/path'; | ||
| import { collectAssetsToEmit, createAssetMatchers } from './assets'; | ||
|
|
||
| describe('library pipeline assets', () => { | ||
| let tempRoot: string; | ||
|
|
||
| beforeEach(async () => { | ||
| const baseTmpDir = process.env['TEST_TMPDIR']; | ||
| assert(baseTmpDir, 'TEST_TMPDIR is not set'); | ||
| tempRoot = toPosixPath(await mkdtemp(path.join(baseTmpDir, 'angular-cli-assets-spec-'))); | ||
| }); | ||
|
|
||
| afterEach(async () => { | ||
| await rm(tempRoot, { recursive: true, force: true }); | ||
| }); | ||
|
|
||
| describe('createAssetMatchers', () => { | ||
| it('should normalize patterns, expand directories in ignore, and skip empty strings', () => { | ||
| const matchers = createAssetMatchers([ | ||
| { | ||
| glob: './**/*.txt', | ||
| input: `${tempRoot}/assets`, | ||
| output: 'assets', | ||
| ignore: ['', 'ignored-dir', './ignored-dir-2/', 'specific.txt'], | ||
| }, | ||
| ]); | ||
|
|
||
| expect(matchers).toHaveSize(1); | ||
| const [matcher] = matchers; | ||
|
|
||
| expect(matcher.isMatch('keep.txt')).toBeTrue(); | ||
| expect(matcher.isMatch('nested/keep.txt')).toBeTrue(); | ||
| expect(matcher.isMatch('.hidden.txt')).toBeTrue(); | ||
| expect(matcher.isMatch('specific.txt')).toBeFalse(); | ||
| expect(matcher.isMatch('ignored-dir/file.txt')).toBeFalse(); | ||
| expect(matcher.isMatch('ignored-dir/sub/file.txt')).toBeFalse(); | ||
| expect(matcher.isMatch('ignored-dir-2/file.txt')).toBeFalse(); | ||
| expect(matcher.isMatch('.gitkeep')).toBeFalse(); | ||
| expect(matcher.isMatch('nested/.DS_Store')).toBeFalse(); | ||
| }); | ||
|
|
||
| it('should not throw when glob is an empty string', () => { | ||
| const matchers = createAssetMatchers([ | ||
| { | ||
| glob: '', | ||
| input: `${tempRoot}/assets`, | ||
| output: 'assets', | ||
| }, | ||
| ]); | ||
|
|
||
| expect(matchers).toHaveSize(1); | ||
| expect(matchers[0].isMatch('any.txt')).toBeFalse(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('collectAssetsToEmit', () => { | ||
| it('should deduplicate resolved assets by destination path with later patterns overriding earlier ones', async () => { | ||
| const defaultDir = `${tempRoot}/lib`; | ||
| const customDir = `${tempRoot}/docs`; | ||
| await mkdir(defaultDir, { recursive: true }); | ||
| await mkdir(customDir, { recursive: true }); | ||
|
|
||
| const defaultReadme = `${defaultDir}/README.md`; | ||
| const customReadme = `${customDir}/README.md`; | ||
| await writeFile(defaultReadme, '# Default'); | ||
| await writeFile(customReadme, '# Custom'); | ||
|
|
||
| const assets = [ | ||
| { glob: 'README.md', input: defaultDir, output: '.' }, | ||
| { glob: 'README.md', input: customDir, output: '.' }, | ||
| ]; | ||
|
|
||
| const initialResult = await collectAssetsToEmit(assets, tempRoot, new Map()); | ||
| expect(initialResult.filesToEmit).toEqual([ | ||
| { | ||
| origin: 'disk', | ||
| source: customReadme, | ||
| path: 'README.md', | ||
| }, | ||
| ]); | ||
|
|
||
| // Watch mode: even if customReadme appears before defaultReadme in modifiedFiles, | ||
| // the later asset pattern (customReadme) should still take precedence. | ||
| const watchResult = await collectAssetsToEmit( | ||
| assets, | ||
| tempRoot, | ||
| new Map(), | ||
| new Set([customReadme, defaultReadme]), | ||
| ); | ||
| expect(watchResult.filesToEmit).toEqual([ | ||
| { | ||
| origin: 'disk', | ||
| source: customReadme, | ||
| path: 'README.md', | ||
| }, | ||
| ]); | ||
| }); | ||
|
|
||
| it('should respect followSymlinks in watch mode', async () => { | ||
| const assetsDir = `${tempRoot}/assets`; | ||
| await mkdir(assetsDir, { recursive: true }); | ||
|
|
||
| const targetFile = `${tempRoot}/external.txt`; | ||
| const symlinkFile = `${assetsDir}/linked.txt`; | ||
| await writeFile(targetFile, 'external'); | ||
| await symlink(targetFile, symlinkFile); | ||
|
|
||
| const assetsNoFollow = [ | ||
| { glob: '**/*.txt', input: assetsDir, output: 'out', followSymlinks: false }, | ||
| ]; | ||
| const noFollowResult = await collectAssetsToEmit( | ||
| assetsNoFollow, | ||
| tempRoot, | ||
| new Map(), | ||
| new Set([symlinkFile]), | ||
| ); | ||
| expect(noFollowResult.filesToEmit).toEqual([]); | ||
|
|
||
| const assetsFollow = [ | ||
| { glob: '**/*.txt', input: assetsDir, output: 'out', followSymlinks: true }, | ||
| ]; | ||
| const followResult = await collectAssetsToEmit( | ||
| assetsFollow, | ||
| tempRoot, | ||
| new Map(), | ||
| new Set([symlinkFile]), | ||
| ); | ||
| expect(followResult.filesToEmit).toEqual([ | ||
| { | ||
| origin: 'disk', | ||
| source: symlinkFile, | ||
| path: 'out/linked.txt', | ||
| }, | ||
| ]); | ||
| }); | ||
|
|
||
| it('should queue nested emitted assets for deletion when a deleted directory is reported in watch mode', async () => { | ||
| const assetsDir = `${tempRoot}/assets`; | ||
| const subDir = `${assetsDir}/sub`; | ||
| const keepDir = `${assetsDir}/keep-dir`; | ||
| await mkdir(keepDir, { recursive: true }); | ||
|
|
||
| const nestedFileA = `${subDir}/a.txt`; | ||
| const nestedFileB = `${subDir}/deep/b.txt`; | ||
| const keepFile = `${keepDir}/keep.txt`; | ||
| await writeFile(keepFile, 'keep'); | ||
|
|
||
| const emittedAssets = new Map<string, Set<string>>([ | ||
| [nestedFileA, new Set(['out/sub/a.txt'])], | ||
| [nestedFileB, new Set(['out/sub/deep/b.txt'])], | ||
| [keepFile, new Set(['out/keep-dir/keep.txt'])], | ||
| ]); | ||
|
|
||
| const assets = [{ glob: '**/*.txt', input: assetsDir, output: 'out' }]; | ||
|
|
||
| // subDir does not exist on disk; keepDir still exists on disk | ||
| const result = await collectAssetsToEmit( | ||
| assets, | ||
| tempRoot, | ||
| emittedAssets, | ||
| new Set([subDir, keepDir]), | ||
| ); | ||
|
|
||
| expect(result.filesToEmit).toEqual([]); | ||
| expect(result.filesToDelete).toEqual([nestedFileA, nestedFileB]); | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.