Repository navigation
refactor(@angular/build): unify and deduplicate emitFilesToDisk across builders #34326
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 3 commits into
angular:main
from
alan-agius4:refactor/deduplicate-emit-files-to-disk
Oct 13, 2026
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
496c818
refactor(@angular/build): unify and deduplicate emitFilesToDisk acros…
alan-agius4 2a73fc9
fixup! refactor(@angular/build): unify and deduplicate emitFilesToDis…
alan-agius4 cfb186b
fixup! refactor(@angular/build): unify and deduplicate emitFilesToDis…
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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,67 @@ | ||
| /** | ||
| * @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 { constants, cp, mkdir, writeFile } from 'node:fs/promises'; | ||
| import { dirname } from 'node:path'; | ||
| import { runConcurrent } from './concurrency'; | ||
|
|
||
| /** | ||
| * Maximum number of concurrent file system write/copy operations to avoid open file descriptor exhaustion. | ||
| */ | ||
| const MAX_CONCURRENT_WRITES = 64; | ||
|
|
||
| /** | ||
| * Represents a file that can be emitted to disk from memory or copied from an existing path on disk. | ||
| */ | ||
| export type EmittableFile = | ||
| { origin: 'memory'; contents: string | Uint8Array } | { origin: 'disk'; source: string }; | ||
|
|
||
| /** | ||
| * Writes or copies a collection of files to disk with bounded concurrency, | ||
| * ensuring parent directories are created once per invocation. | ||
| * | ||
| * @param files The collection of files to emit. | ||
| * @param resolveDestinationPath Callback returning the absolute destination path for a file, or `undefined` to skip it. | ||
| */ | ||
| export async function emitFilesToDisk<T extends EmittableFile = EmittableFile>( | ||
| files: readonly T[], | ||
| resolveDestinationPath: (file: T) => string | undefined, | ||
| ): Promise<void> { | ||
| if (files.length === 0) { | ||
| return; | ||
| } | ||
|
|
||
| const directoryExists = new Set<string>(); | ||
|
alan-agius4 marked this conversation as resolved.
Resolved
|
||
|
|
||
| await runConcurrent(files, MAX_CONCURRENT_WRITES, async (file) => { | ||
| const fullFilePath = resolveDestinationPath(file); | ||
| if (!fullFilePath) { | ||
| return; | ||
| } | ||
|
|
||
| // Ensure output subdirectories exist | ||
| const fileBasePath = dirname(fullFilePath); | ||
| if (fileBasePath && !directoryExists.has(fileBasePath)) { | ||
| await mkdir(fileBasePath, { recursive: true }); | ||
| directoryExists.add(fileBasePath); | ||
| } | ||
|
alan-agius4 marked this conversation as resolved.
Resolved
|
||
|
|
||
| if (file.origin === 'memory') { | ||
| // Write file contents | ||
| await writeFile(fullFilePath, file.contents); | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| // Copy file contents | ||
| await cp(file.source, fullFilePath, { | ||
| mode: constants.COPYFILE_FICLONE, | ||
| preserveTimestamps: true, | ||
| }); | ||
|
alan-agius4 marked this conversation as resolved.
Resolved
|
||
| }); | ||
| } | ||
Oops, something went wrong.
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.