Skip to content

Commit bc0c55c

Browse files
author
Angular Builds
committed
ca0a836 refactor(@angular-devkit/build-angular): move diagnostic logging out of build execution
1 parent 8d43857 commit bc0c55c

File tree

9 files changed

+120
-68
lines changed

9 files changed

+120
-68
lines changed

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
22
"name": "@angular-devkit/build-angular",
3-
"version": "17.1.0-rc.0+sha-ecdad2a",
3+
"version": "17.1.0-rc.0+sha-ca0a836",
44
"description": "Angular Webpack Build Facade",
55
"main": "src/index.js",
66
"typings": "src/index.d.ts",
77
"builders": "builders.json",
88
"dependencies": {
99
"@ampproject/remapping": "2.2.1",
10-
"@angular-devkit/architect": "github:angular/angular-devkit-architect-builds#ecdad2a",
11-
"@angular-devkit/build-webpack": "github:angular/angular-devkit-build-webpack-builds#ecdad2a",
12-
"@angular-devkit/core": "github:angular/angular-devkit-core-builds#ecdad2a",
10+
"@angular-devkit/architect": "github:angular/angular-devkit-architect-builds#ca0a836",
11+
"@angular-devkit/build-webpack": "github:angular/angular-devkit-build-webpack-builds#ca0a836",
12+
"@angular-devkit/core": "github:angular/angular-devkit-core-builds#ca0a836",
1313
"@babel/core": "7.23.7",
1414
"@babel/generator": "7.23.6",
1515
"@babel/helper-annotate-as-pure": "7.22.5",
@@ -20,7 +20,7 @@
2020
"@babel/preset-env": "7.23.7",
2121
"@babel/runtime": "7.23.7",
2222
"@discoveryjs/json-ext": "0.5.7",
23-
"@ngtools/webpack": "github:angular/ngtools-webpack-builds#ecdad2a",
23+
"@ngtools/webpack": "github:angular/ngtools-webpack-builds#ca0a836",
2424
"@vitejs/plugin-basic-ssl": "1.0.2",
2525
"ansi-colors": "4.1.3",
2626
"autoprefixer": "10.4.16",

src/builders/application/build-action.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ async function* runEsBuildBuildAction(action, options) {
5252
// Initial build
5353
let result;
5454
try {
55+
// Perform the build action
5556
result = await withProgress('Building...', () => action());
57+
// Log all diagnostic (error/warning) messages from the build
58+
await (0, utils_1.logMessages)(logger, result);
5659
}
5760
finally {
5861
// Ensure Sass workers are shutdown if not watching
@@ -139,6 +142,8 @@ async function* runEsBuildBuildAction(action, options) {
139142
logger.info(changes.toDebugString());
140143
}
141144
result = await withProgress('Changes detected. Rebuilding...', () => action(result.createRebuildState(changes)));
145+
// Log all diagnostic (error/warning) messages from the rebuild
146+
await (0, utils_1.logMessages)(logger, result);
142147
// Update watched locations provided by the new build result.
143148
// Keep watching all previous files if there are any errors; otherwise consider all
144149
// files stale until confirmed present in the new result's watch files.

src/builders/application/execute-build.js

Lines changed: 6 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,10 @@
99
Object.defineProperty(exports, "__esModule", { value: true });
1010
exports.executeBuild = void 0;
1111
const source_file_cache_1 = require("../../tools/esbuild/angular/source-file-cache");
12-
const application_code_bundle_1 = require("../../tools/esbuild/application-code-bundle");
1312
const budget_stats_1 = require("../../tools/esbuild/budget-stats");
1413
const bundler_context_1 = require("../../tools/esbuild/bundler-context");
1514
const bundler_execution_result_1 = require("../../tools/esbuild/bundler-execution-result");
1615
const commonjs_checker_1 = require("../../tools/esbuild/commonjs-checker");
17-
const global_scripts_1 = require("../../tools/esbuild/global-scripts");
18-
const global_styles_1 = require("../../tools/esbuild/global-styles");
1916
const license_extractor_1 = require("../../tools/esbuild/license-extractor");
2017
const utils_1 = require("../../tools/esbuild/utils");
2118
const bundle_calculator_1 = require("../../utils/bundle-calculator");
@@ -24,11 +21,11 @@ const copy_assets_1 = require("../../utils/copy-assets");
2421
const supported_browsers_1 = require("../../utils/supported-browsers");
2522
const execute_post_bundle_1 = require("./execute-post-bundle");
2623
const i18n_1 = require("./i18n");
27-
// eslint-disable-next-line max-lines-per-function
24+
const setup_bundling_1 = require("./setup-bundling");
2825
async function executeBuild(options, context, rebuildState) {
29-
const { projectRoot, workspaceRoot, i18nOptions, optimizationOptions, serverEntryPoint, assets, cacheOptions, prerenderOptions, appShellOptions, ssrOptions, } = options;
26+
const { projectRoot, workspaceRoot, i18nOptions, optimizationOptions, assets, cacheOptions, prerenderOptions, } = options;
27+
// TODO: Consider integrating into watch mode. Would require full rebuild on target changes.
3028
const browsers = (0, supported_browsers_1.getSupportedBrowsers)(projectRoot, context.logger);
31-
const target = (0, utils_1.transformSupportedBrowsersToTargets)(browsers);
3229
// Load active translations if inlining
3330
// TODO: Integrate into watch mode and only load changed translations
3431
if (i18nOptions.shouldInline) {
@@ -39,53 +36,11 @@ async function executeBuild(options, context, rebuildState) {
3936
const codeBundleCache = rebuildState?.codeBundleCache ??
4037
new source_file_cache_1.SourceFileCache(cacheOptions.enabled ? cacheOptions.path : undefined);
4138
if (bundlerContexts === undefined) {
42-
bundlerContexts = [];
43-
// Browser application code
44-
bundlerContexts.push(new bundler_context_1.BundlerContext(workspaceRoot, !!options.watch, (0, application_code_bundle_1.createBrowserCodeBundleOptions)(options, target, codeBundleCache)));
45-
// Browser polyfills code
46-
const browserPolyfillBundleOptions = (0, application_code_bundle_1.createBrowserPolyfillBundleOptions)(options, target, codeBundleCache);
47-
if (browserPolyfillBundleOptions) {
48-
bundlerContexts.push(new bundler_context_1.BundlerContext(workspaceRoot, !!options.watch, browserPolyfillBundleOptions));
49-
}
50-
// Global Stylesheets
51-
if (options.globalStyles.length > 0) {
52-
for (const initial of [true, false]) {
53-
const bundleOptions = (0, global_styles_1.createGlobalStylesBundleOptions)(options, target, initial);
54-
if (bundleOptions) {
55-
bundlerContexts.push(new bundler_context_1.BundlerContext(workspaceRoot, !!options.watch, bundleOptions, () => initial));
56-
}
57-
}
58-
}
59-
// Global Scripts
60-
if (options.globalScripts.length > 0) {
61-
for (const initial of [true, false]) {
62-
const bundleOptions = (0, global_scripts_1.createGlobalScriptsBundleOptions)(options, target, initial);
63-
if (bundleOptions) {
64-
bundlerContexts.push(new bundler_context_1.BundlerContext(workspaceRoot, !!options.watch, bundleOptions, () => initial));
65-
}
66-
}
67-
}
68-
// Skip server build when none of the features are enabled.
69-
if (serverEntryPoint && (prerenderOptions || appShellOptions || ssrOptions)) {
70-
const nodeTargets = [...target, ...(0, utils_1.getSupportedNodeTargets)()];
71-
// Server application code
72-
bundlerContexts.push(new bundler_context_1.BundlerContext(workspaceRoot, !!options.watch, (0, application_code_bundle_1.createServerCodeBundleOptions)({
73-
...options,
74-
// Disable external deps for server bundles.
75-
// This is because it breaks Vite 'optimizeDeps' for SSR.
76-
externalPackages: false,
77-
}, nodeTargets, codeBundleCache), () => false));
78-
// Server polyfills code
79-
const serverPolyfillBundleOptions = (0, application_code_bundle_1.createServerPolyfillBundleOptions)(options, nodeTargets, codeBundleCache);
80-
if (serverPolyfillBundleOptions) {
81-
bundlerContexts.push(new bundler_context_1.BundlerContext(workspaceRoot, !!options.watch, serverPolyfillBundleOptions, () => false));
82-
}
83-
}
39+
bundlerContexts = (0, setup_bundling_1.setupBundlerContexts)(options, browsers, codeBundleCache);
8440
}
8541
const bundlingResult = await bundler_context_1.BundlerContext.bundleAll(bundlerContexts, rebuildState?.fileChanges.all);
86-
// Log all warnings and errors generated during bundling
87-
await (0, utils_1.logMessages)(context, bundlingResult);
8842
const executionResult = new bundler_execution_result_1.ExecutionResult(bundlerContexts, codeBundleCache);
43+
executionResult.addWarnings(bundlingResult.warnings);
8944
// Return if the bundling has errors
9045
if (bundlingResult.errors) {
9146
executionResult.addErrors(bundlingResult.errors);
@@ -169,8 +124,7 @@ async function executeBuild(options, context, rebuildState) {
169124
}
170125
context.logger.info(color_1.colors.magenta(prerenderMsg) + '\n');
171126
}
172-
(0, utils_1.logBuildStats)(context, metafile, initialFiles, budgetFailures, changedFiles, estimatedTransferSizes);
173-
await (0, utils_1.logMessages)(context, executionResult);
127+
(0, utils_1.logBuildStats)(context.logger, metafile, initialFiles, budgetFailures, changedFiles, estimatedTransferSizes);
174128
// Write metafile if stats option is enabled
175129
if (options.stats) {
176130
executionResult.addOutputFile('stats.json', JSON.stringify(metafile, null, 2), bundler_context_1.BuildOutputFileType.Root);

src/builders/application/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ function buildApplication(options, context, pluginsOrExtensions) {
9292
codePlugins: pluginsOrExtensions,
9393
};
9494
}
95+
else {
96+
extensions = pluginsOrExtensions;
97+
}
9598
return buildApplicationInternal(options, context, undefined, extensions);
9699
}
97100
exports.buildApplication = buildApplication;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
import { SourceFileCache } from '../../tools/esbuild/angular/source-file-cache';
9+
import { BundlerContext } from '../../tools/esbuild/bundler-context';
10+
import { NormalizedApplicationBuildOptions } from './options';
11+
/**
12+
* Generates one or more BundlerContext instances based on the builder provided
13+
* configuration.
14+
* @param options The normalized application builder options to use.
15+
* @param browsers An string array of browserslist browsers to support.
16+
* @param codeBundleCache An instance of the TypeScript source file cache.
17+
* @returns An array of BundlerContext objects.
18+
*/
19+
export declare function setupBundlerContexts(options: NormalizedApplicationBuildOptions, browsers: string[], codeBundleCache: SourceFileCache): BundlerContext[];
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
"use strict";
2+
/**
3+
* @license
4+
* Copyright Google LLC All Rights Reserved.
5+
*
6+
* Use of this source code is governed by an MIT-style license that can be
7+
* found in the LICENSE file at https://angular.io/license
8+
*/
9+
Object.defineProperty(exports, "__esModule", { value: true });
10+
exports.setupBundlerContexts = void 0;
11+
const application_code_bundle_1 = require("../../tools/esbuild/application-code-bundle");
12+
const bundler_context_1 = require("../../tools/esbuild/bundler-context");
13+
const global_scripts_1 = require("../../tools/esbuild/global-scripts");
14+
const global_styles_1 = require("../../tools/esbuild/global-styles");
15+
const utils_1 = require("../../tools/esbuild/utils");
16+
/**
17+
* Generates one or more BundlerContext instances based on the builder provided
18+
* configuration.
19+
* @param options The normalized application builder options to use.
20+
* @param browsers An string array of browserslist browsers to support.
21+
* @param codeBundleCache An instance of the TypeScript source file cache.
22+
* @returns An array of BundlerContext objects.
23+
*/
24+
function setupBundlerContexts(options, browsers, codeBundleCache) {
25+
const { appShellOptions, prerenderOptions, serverEntryPoint, ssrOptions, workspaceRoot } = options;
26+
const target = (0, utils_1.transformSupportedBrowsersToTargets)(browsers);
27+
const bundlerContexts = [];
28+
// Browser application code
29+
bundlerContexts.push(new bundler_context_1.BundlerContext(workspaceRoot, !!options.watch, (0, application_code_bundle_1.createBrowserCodeBundleOptions)(options, target, codeBundleCache)));
30+
// Browser polyfills code
31+
const browserPolyfillBundleOptions = (0, application_code_bundle_1.createBrowserPolyfillBundleOptions)(options, target, codeBundleCache);
32+
if (browserPolyfillBundleOptions) {
33+
bundlerContexts.push(new bundler_context_1.BundlerContext(workspaceRoot, !!options.watch, browserPolyfillBundleOptions));
34+
}
35+
// Global Stylesheets
36+
if (options.globalStyles.length > 0) {
37+
for (const initial of [true, false]) {
38+
const bundleOptions = (0, global_styles_1.createGlobalStylesBundleOptions)(options, target, initial);
39+
if (bundleOptions) {
40+
bundlerContexts.push(new bundler_context_1.BundlerContext(workspaceRoot, !!options.watch, bundleOptions, () => initial));
41+
}
42+
}
43+
}
44+
// Global Scripts
45+
if (options.globalScripts.length > 0) {
46+
for (const initial of [true, false]) {
47+
const bundleOptions = (0, global_scripts_1.createGlobalScriptsBundleOptions)(options, target, initial);
48+
if (bundleOptions) {
49+
bundlerContexts.push(new bundler_context_1.BundlerContext(workspaceRoot, !!options.watch, bundleOptions, () => initial));
50+
}
51+
}
52+
}
53+
// Skip server build when none of the features are enabled.
54+
if (serverEntryPoint && (prerenderOptions || appShellOptions || ssrOptions)) {
55+
const nodeTargets = [...target, ...(0, utils_1.getSupportedNodeTargets)()];
56+
// Server application code
57+
bundlerContexts.push(new bundler_context_1.BundlerContext(workspaceRoot, !!options.watch, (0, application_code_bundle_1.createServerCodeBundleOptions)({
58+
...options,
59+
// Disable external deps for server bundles.
60+
// This is because it breaks Vite 'optimizeDeps' for SSR.
61+
externalPackages: false,
62+
}, nodeTargets, codeBundleCache), () => false));
63+
// Server polyfills code
64+
const serverPolyfillBundleOptions = (0, application_code_bundle_1.createServerPolyfillBundleOptions)(options, nodeTargets, codeBundleCache);
65+
if (serverPolyfillBundleOptions) {
66+
bundlerContexts.push(new bundler_context_1.BundlerContext(workspaceRoot, !!options.watch, serverPolyfillBundleOptions, () => false));
67+
}
68+
}
69+
return bundlerContexts;
70+
}
71+
exports.setupBundlerContexts = setupBundlerContexts;

src/tools/esbuild/utils.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import { BuilderContext } from '@angular-devkit/architect';
8+
import { logging } from '@angular-devkit/core';
99
import { BuildOptions, Metafile, OutputFile, PartialMessage } from 'esbuild';
1010
import { NormalizedOutputOptions } from '../../builders/application/options';
1111
import { BudgetCalculatorResult } from '../../utils/bundle-calculator';
1212
import { BuildOutputFile, BuildOutputFileType, InitialFileRecord } from './bundler-context';
1313
import { BuildOutputAsset } from './bundler-execution-result';
14-
export declare function logBuildStats(context: BuilderContext, metafile: Metafile, initial: Map<string, InitialFileRecord>, budgetFailures: BudgetCalculatorResult[] | undefined, changedFiles?: Set<string>, estimatedTransferSizes?: Map<string, number>): void;
14+
export declare function logBuildStats(logger: logging.LoggerApi, metafile: Metafile, initial: Map<string, InitialFileRecord>, budgetFailures: BudgetCalculatorResult[] | undefined, changedFiles?: Set<string>, estimatedTransferSizes?: Map<string, number>): void;
1515
export declare function calculateEstimatedTransferSizes(outputFiles: OutputFile[]): Promise<Map<string, number>>;
1616
export declare function withSpinner<T>(text: string, action: () => T | Promise<T>): Promise<T>;
1717
export declare function withNoProgress<T>(text: string, action: () => T | Promise<T>): Promise<T>;
18-
export declare function logMessages(context: BuilderContext, { errors, warnings }: {
18+
export declare function logMessages(logger: logging.LoggerApi, { errors, warnings }: {
1919
errors?: PartialMessage[];
2020
warnings?: PartialMessage[];
2121
}): Promise<void>;

src/tools/esbuild/utils.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const semver_1 = require("semver");
2121
const spinner_1 = require("../../utils/spinner");
2222
const stats_1 = require("../webpack/utils/stats");
2323
const bundler_context_1 = require("./bundler-context");
24-
function logBuildStats(context, metafile, initial, budgetFailures, changedFiles, estimatedTransferSizes) {
24+
function logBuildStats(logger, metafile, initial, budgetFailures, changedFiles, estimatedTransferSizes) {
2525
const stats = [];
2626
let unchangedCount = 0;
2727
for (const [file, output] of Object.entries(metafile.outputs)) {
@@ -53,13 +53,13 @@ function logBuildStats(context, metafile, initial, budgetFailures, changedFiles,
5353
}
5454
if (stats.length > 0) {
5555
const tableText = (0, stats_1.generateBuildStatsTable)(stats, true, unchangedCount === 0, !!estimatedTransferSizes, budgetFailures);
56-
context.logger.info('\n' + tableText + '\n');
56+
logger.info('\n' + tableText + '\n');
5757
}
5858
else if (changedFiles !== undefined) {
59-
context.logger.info('\nNo output file changes.\n');
59+
logger.info('\nNo output file changes.\n');
6060
}
6161
if (unchangedCount > 0) {
62-
context.logger.info(`Unchanged output files: ${unchangedCount}`);
62+
logger.info(`Unchanged output files: ${unchangedCount}`);
6363
}
6464
}
6565
exports.logBuildStats = logBuildStats;
@@ -117,14 +117,14 @@ async function withNoProgress(text, action) {
117117
return action();
118118
}
119119
exports.withNoProgress = withNoProgress;
120-
async function logMessages(context, { errors, warnings }) {
120+
async function logMessages(logger, { errors, warnings }) {
121121
if (warnings?.length) {
122122
const warningMessages = await (0, esbuild_1.formatMessages)(warnings, { kind: 'warning', color: true });
123-
context.logger.warn(warningMessages.join('\n'));
123+
logger.warn(warningMessages.join('\n'));
124124
}
125125
if (errors?.length) {
126126
const errorMessages = await (0, esbuild_1.formatMessages)(errors, { kind: 'error', color: true });
127-
context.logger.error(errorMessages.join('\n'));
127+
logger.error(errorMessages.join('\n'));
128128
}
129129
}
130130
exports.logMessages = logMessages;

uniqueId

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Fri Jan 05 2024 18:41:29 GMT+0000 (Coordinated Universal Time)
1+
Tue Jan 09 2024 00:38:09 GMT+0000 (Coordinated Universal Time)

0 commit comments

Comments
 (0)