Skip to content

Commit 75a01d6

Browse files
committedApr 11, 2024
refactor(@angular-devkit/build-angular): directly resolve asset files in application builder
Instead of previously attempting to reuse the Webpack-based copy assets helper function, the application builder will now only resolve all potential configured assets. This avoids depending on non-obvious parameter behavior to prevent the actual copying of the asset files.
1 parent 2acf95a commit 75a01d6

File tree

2 files changed

+47
-4
lines changed

2 files changed

+47
-4
lines changed
 

‎packages/angular_devkit/build_angular/src/builders/application/execute-build.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { checkCommonJSModules } from '../../tools/esbuild/commonjs-checker';
1515
import { extractLicenses } from '../../tools/esbuild/license-extractor';
1616
import { calculateEstimatedTransferSizes, logBuildStats } from '../../tools/esbuild/utils';
1717
import { BudgetCalculatorResult, checkBudgets } from '../../utils/bundle-calculator';
18-
import { copyAssets } from '../../utils/copy-assets';
18+
import { resolveAssets } from '../../utils/resolve-assets';
1919
import { getSupportedBrowsers } from '../../utils/supported-browsers';
2020
import { executePostBundleSteps } from './execute-post-bundle';
2121
import { inlineI18n, loadActiveTranslations } from './i18n';
@@ -129,9 +129,7 @@ export async function executeBuild(
129129

130130
// Copy assets
131131
if (assets) {
132-
// The webpack copy assets helper is used with no base paths defined. This prevents the helper
133-
// from directly writing to disk. This should eventually be replaced with a more optimized helper.
134-
executionResult.addAssets(await copyAssets(assets, [], workspaceRoot));
132+
executionResult.addAssets(await resolveAssets(assets, workspaceRoot));
135133
}
136134

137135
// Extract and write licenses for used packages
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import glob from 'fast-glob';
10+
import path from 'node:path';
11+
12+
export async function resolveAssets(
13+
entries: {
14+
glob: string;
15+
ignore?: string[];
16+
input: string;
17+
output: string;
18+
flatten?: boolean;
19+
followSymlinks?: boolean;
20+
}[],
21+
root: string,
22+
): Promise<{ source: string; destination: string }[]> {
23+
const defaultIgnore = ['.gitkeep', '**/.DS_Store', '**/Thumbs.db'];
24+
25+
const outputFiles: { source: string; destination: string }[] = [];
26+
27+
for (const entry of entries) {
28+
const cwd = path.resolve(root, entry.input);
29+
const files = await glob(entry.glob, {
30+
cwd,
31+
dot: true,
32+
ignore: entry.ignore ? defaultIgnore.concat(entry.ignore) : defaultIgnore,
33+
followSymbolicLinks: entry.followSymlinks,
34+
});
35+
36+
for (const file of files) {
37+
const src = path.join(cwd, file);
38+
const filePath = entry.flatten ? path.basename(file) : file;
39+
40+
outputFiles.push({ source: src, destination: path.join(entry.output, filePath) });
41+
}
42+
}
43+
44+
return outputFiles;
45+
}

0 commit comments

Comments
 (0)