Skip to content

Commit 6936e55

Browse files
committed
feat(@angular/build): enhance build logs and output location for library builder
Align library builder logs with the application builder format by logging: - `Library bundle generation complete. [X seconds] - <timestamp>` on build completion - `Output location: <outputPath>` for successful builds - `Watch mode enabled. Watching for file changes...` after initial build when watch mode is active
1 parent 643947e commit 6936e55

2 files changed

Lines changed: 43 additions & 15 deletions

File tree

‎packages/angular/build/src/builders/library/builder.ts‎

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,6 @@ export async function* executeLibraryBuilder(
118118
}
119119

120120
if (isWatchMode) {
121-
if (progress) {
122-
logger.info('Watch mode enabled. Watching for file changes...');
123-
}
124-
125121
const { setupWatcher } = await import('../../utils/watcher');
126122
watcher = await setupWatcher({
127123
workspaceRoot,
@@ -158,6 +154,10 @@ export async function* executeLibraryBuilder(
158154
return;
159155
}
160156

157+
if (progress) {
158+
logger.info('Watch mode enabled. Watching for file changes...');
159+
}
160+
161161
yield* runWatchLoop(
162162
watcher,
163163
normalizedOptions,
@@ -190,11 +190,11 @@ async function executeBuild(
190190
buildAction: typeof import('./pipeline/build-action').buildAction,
191191
): Promise<BuilderOutput> {
192192
const startTime = process.hrtime.bigint();
193-
const { context, watchedCompilationFiles, isWatchMode } = actionContext;
193+
const { context, watchedCompilationFiles, isWatchMode, options } = actionContext;
194194

195195
try {
196196
await withProgress(message, () => buildAction(actionContext));
197-
logBuildResult(context.logger, startTime, true);
197+
logBuildResult(context.logger, startTime, true, options.outputPath);
198198
if (isWatchMode) {
199199
logCumulativeDurations();
200200
}
@@ -343,14 +343,19 @@ async function* runWatchLoop(
343343
/**
344344
* Logs the build completion time and status.
345345
*/
346-
function logBuildResult(logger: logging.LoggerApi, startTime: bigint, success: boolean): void {
347-
const durationMs = Number(process.hrtime.bigint() - startTime) / 1_000_000;
348-
const durationSec = (durationMs / 1000).toFixed(2);
349-
350-
if (success) {
351-
logger.info(`Build at: ${new Date().toISOString()} - Time: ${durationMs.toFixed(0)}ms`);
352-
logger.info(`Built Angular library in ${durationSec}s.`);
353-
} else {
354-
logger.error(`Build failed after ${durationSec}s.`);
346+
function logBuildResult(
347+
logger: logging.LoggerApi,
348+
startTime: bigint,
349+
success: boolean,
350+
outputPath?: string,
351+
): void {
352+
const buildTime = Number(process.hrtime.bigint() - startTime) / 10 ** 9;
353+
354+
logger.info(
355+
`Library bundle generation ${success ? 'complete' : 'failed'}. [${buildTime.toFixed(3)} seconds] - ${new Date().toISOString()}`,
356+
);
357+
358+
if (success && outputPath) {
359+
logger.info(`Output location: ${outputPath}\n`);
355360
}
356361
}

‎packages/angular/build/src/builders/library/tests/behavior/build_spec.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,5 +139,28 @@ describeLibraryBuilder(executeLibraryBuilder, LIBRARY_BUILDER_INFO, (harness) =>
139139
tslib: '^2.0.0',
140140
});
141141
});
142+
143+
it('should log completion and output location', async () => {
144+
harness.useTarget('build', {
145+
...BASE_OPTIONS,
146+
});
147+
148+
const { result, logs } = await harness.executeOnce();
149+
expect(result?.success).toBeTrue();
150+
expect(logs).toContain(
151+
jasmine.objectContaining({
152+
level: 'info',
153+
message: jasmine.stringMatching(
154+
/Library bundle generation complete\. \[\d+\.\d{3} seconds\] - \d{4}-\d{2}-\d{2}T/,
155+
),
156+
}),
157+
);
158+
expect(logs).toContain(
159+
jasmine.objectContaining({
160+
level: 'info',
161+
message: jasmine.stringMatching(/Output location: .*dist[/\\]lib/),
162+
}),
163+
);
164+
});
142165
});
143166
});

0 commit comments

Comments
 (0)