Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): avoid attempting to copy directories
Browse files Browse the repository at this point in the history
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
  • Loading branch information
alan-agius4 authored and vikerman committed Oct 11, 2019
1 parent 5b8b628 commit d9bf2db
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/angular_devkit/build_angular/src/utils/copy-assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ export async function copyAssets(
const files = await globAsync(entry.glob, {
cwd,
dot: true,
nodir: true,
ignore: entry.ignore ? defaultIgnore.concat(entry.ignore) : defaultIgnore,
});

const directoryExists = new Set<string>();

for (const file of files) {
const src = path.join(cwd, file);
if (changed && !changed.has(src)) {
Expand All @@ -42,9 +45,11 @@ export async function copyAssets(
for (const base of basePaths) {
const dest = path.join(base, entry.output, filePath);
const dir = path.dirname(dest);
if (!fs.existsSync(dir)) {
// tslint:disable-next-line: no-any
fs.mkdirSync(dir, { recursive: true } as any);
if (!directoryExists.has(dir)) {
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
}
directoryExists.add(dir);
}
copyFile(src, dest);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ describe('Browser Builder assets', () => {
'./src/folder/.gitkeep': '',
'./src/string-file-asset.txt': 'string-file-asset.txt',
'./src/string-folder-asset/file.txt': 'string-folder-asset.txt',
'./src/nested/nested/file.txt': 'nested-file.txt',
'./src/glob-asset.txt': 'glob-asset.txt',
'./src/folder/folder-asset.txt': 'folder-asset.txt',
'./src/output-asset.txt': 'output-asset.txt',
};
const matches: { [path: string]: string } = {
'./dist/string-file-asset.txt': 'string-file-asset.txt',
'./dist/string-folder-asset/file.txt': 'string-folder-asset.txt',
'./dist/nested/nested/file.txt': 'nested-file.txt',
'./dist/glob-asset.txt': 'glob-asset.txt',
'./dist/folder/folder-asset.txt': 'folder-asset.txt',
'./dist/output-folder/output-asset.txt': 'output-asset.txt',
Expand All @@ -43,6 +45,7 @@ describe('Browser Builder assets', () => {

const overrides = {
assets: [
'src/nested',
'src/string-file-asset.txt',
'src/string-folder-asset',
{ glob: 'glob-asset.txt', input: 'src/', output: '/' },
Expand Down

0 comments on commit d9bf2db

Please sign in to comment.