Skip to content

Commit d9bf2db

Browse files
alan-agius4vikerman
authored andcommitted
fix(@angular-devkit/build-angular): avoid attempting to copy directories
Avoid copying directly directories, also which this change we cache `fs.existsSync` to optimize copying when a lot of file are being copied to the same destination. Closes: #15816
1 parent 5b8b628 commit d9bf2db

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

packages/angular_devkit/build_angular/src/utils/copy-assets.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@ export async function copyAssets(
2929
const files = await globAsync(entry.glob, {
3030
cwd,
3131
dot: true,
32+
nodir: true,
3233
ignore: entry.ignore ? defaultIgnore.concat(entry.ignore) : defaultIgnore,
3334
});
3435

36+
const directoryExists = new Set<string>();
37+
3538
for (const file of files) {
3639
const src = path.join(cwd, file);
3740
if (changed && !changed.has(src)) {
@@ -42,9 +45,11 @@ export async function copyAssets(
4245
for (const base of basePaths) {
4346
const dest = path.join(base, entry.output, filePath);
4447
const dir = path.dirname(dest);
45-
if (!fs.existsSync(dir)) {
46-
// tslint:disable-next-line: no-any
47-
fs.mkdirSync(dir, { recursive: true } as any);
48+
if (!directoryExists.has(dir)) {
49+
if (!fs.existsSync(dir)) {
50+
fs.mkdirSync(dir, { recursive: true });
51+
}
52+
directoryExists.add(dir);
4853
}
4954
copyFile(src, dest);
5055
}

packages/angular_devkit/build_angular/test/browser/assets_spec_large.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@ describe('Browser Builder assets', () => {
2828
'./src/folder/.gitkeep': '',
2929
'./src/string-file-asset.txt': 'string-file-asset.txt',
3030
'./src/string-folder-asset/file.txt': 'string-folder-asset.txt',
31+
'./src/nested/nested/file.txt': 'nested-file.txt',
3132
'./src/glob-asset.txt': 'glob-asset.txt',
3233
'./src/folder/folder-asset.txt': 'folder-asset.txt',
3334
'./src/output-asset.txt': 'output-asset.txt',
3435
};
3536
const matches: { [path: string]: string } = {
3637
'./dist/string-file-asset.txt': 'string-file-asset.txt',
3738
'./dist/string-folder-asset/file.txt': 'string-folder-asset.txt',
39+
'./dist/nested/nested/file.txt': 'nested-file.txt',
3840
'./dist/glob-asset.txt': 'glob-asset.txt',
3941
'./dist/folder/folder-asset.txt': 'folder-asset.txt',
4042
'./dist/output-folder/output-asset.txt': 'output-asset.txt',
@@ -43,6 +45,7 @@ describe('Browser Builder assets', () => {
4345

4446
const overrides = {
4547
assets: [
48+
'src/nested',
4649
'src/string-file-asset.txt',
4750
'src/string-folder-asset',
4851
{ glob: 'glob-asset.txt', input: 'src/', output: '/' },

0 commit comments

Comments
 (0)