Skip to content

Commit aab4248

Browse files
committed
refactor(@angular/build): support multiple results per application build action
The `application` builder may now return more than one build result per rebuild action. This will typically occur when using the development server with HMR enabled. In this scenario, component template update results may be sent to the development server in addition to incremental updates for global styles. TailwindCSS, for instance, may update the global stylesheet for an application based on the usage of styles within a given template.
1 parent 04b8184 commit aab4248

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

packages/angular/build/src/builders/application/build-action.ts

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export async function* runEsBuildBuildAction(
144144
// Output the first build results after setting up the watcher to ensure that any code executed
145145
// higher in the iterator call stack will trigger the watcher. This is particularly relevant for
146146
// unit tests which execute the builder and modify the file system programmatically.
147-
yield emitOutputResult(result, outputOptions);
147+
yield* emitOutputResults(result, outputOptions);
148148

149149
// Finish if watch mode is not enabled
150150
if (!watcher) {
@@ -196,11 +196,13 @@ export async function* runEsBuildBuildAction(
196196
watcher.remove([...staleWatchFiles]);
197197
}
198198

199-
yield emitOutputResult(
199+
for (const outputResult of emitOutputResults(
200200
result,
201201
outputOptions,
202202
incrementalResults ? rebuildState.previousOutputInfo : undefined,
203-
);
203+
)) {
204+
yield outputResult;
205+
}
204206
}
205207
} finally {
206208
// Stop the watcher and cleanup incremental rebuild state
@@ -210,7 +212,7 @@ export async function* runEsBuildBuildAction(
210212
}
211213
}
212214

213-
function emitOutputResult(
215+
function* emitOutputResults(
214216
{
215217
outputFiles,
216218
assetFiles,
@@ -223,16 +225,18 @@ function emitOutputResult(
223225
}: ExecutionResult,
224226
outputOptions: NormalizedApplicationBuildOptions['outputOptions'],
225227
previousOutputInfo?: ReadonlyMap<string, { hash: string; type: BuildOutputFileType }>,
226-
): Result {
228+
): Iterable<Result> {
227229
if (errors.length > 0) {
228-
return {
230+
yield {
229231
kind: ResultKind.Failure,
230232
errors: errors as ResultMessage[],
231233
warnings: warnings as ResultMessage[],
232234
detail: {
233235
outputOptions,
234236
},
235237
};
238+
239+
return;
236240
}
237241

238242
// Template updates only exist if no other JS changes have occurred
@@ -247,7 +251,7 @@ function emitOutputResult(
247251
})),
248252
};
249253

250-
return updateResult;
254+
yield updateResult;
251255
}
252256

253257
// Use an incremental result if previous output information is available
@@ -273,6 +277,13 @@ function emitOutputResult(
273277
for (const file of outputFiles) {
274278
removedOutputFiles.delete(file.path);
275279

280+
// Temporarily ignore JS files until Angular compiler plugin refactor to allow
281+
// bypassing application code bundling for template affecting only changes.
282+
// TODO: Remove once refactor is complete.
283+
if (hasTemplateUpdates && /\.js(?:\.map)?$/.test(file.path)) {
284+
continue;
285+
}
286+
276287
const previousHash = previousOutputInfo.get(file.path)?.hash;
277288
let needFile = false;
278289
if (previousHash === undefined) {
@@ -312,7 +323,9 @@ function emitOutputResult(
312323
};
313324
}
314325

315-
return incrementalResult;
326+
yield incrementalResult;
327+
328+
return;
316329
}
317330

318331
// Otherwise, use a full result
@@ -343,5 +356,5 @@ function emitOutputResult(
343356
};
344357
}
345358

346-
return result;
359+
yield result;
347360
}

0 commit comments

Comments
 (0)