Skip to content

Commit fe939cd

Browse files
committed
fixup! fix(@angular/build): scope BundlerContext invalidation and cache one-shot bundle results
1 parent 548b56a commit fe939cd

2 files changed

Lines changed: 23 additions & 24 deletions

File tree

‎packages/angular/build/src/tools/esbuild/bundler-context.ts‎

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -450,11 +450,11 @@ export class BundlerContext {
450450
? entryPoints.map((entry) => (typeof entry === 'string' ? entry : entry.in))
451451
: Object.values(entryPoints);
452452
for (const entry of entries) {
453-
if (!isInternalAngularFile(entry) && !isInternalBundlerFile(entry)) {
454-
this.watchFiles.add(
455-
isAbsolute(entry) ? normalize(entry) : join(this.workspaceRoot, entry),
456-
);
453+
if (isInternalAngularFile(entry) || isInternalBundlerFile(entry)) {
454+
continue;
457455
}
456+
457+
this.watchFiles.add(isAbsolute(entry) ? normalize(entry) : join(this.workspaceRoot, entry));
458458
}
459459
}
460460

@@ -474,20 +474,22 @@ export class BundlerContext {
474474

475475
async #addLoadCacheFilesToWatch(): Promise<void> {
476476
const loadCache = this.#loadCache;
477-
if (this.incremental && loadCache && this.#loadCacheKeys) {
478-
const results = await Promise.all(
479-
Array.from(this.#loadCacheKeys, (key) => loadCache.get(key)),
480-
);
481-
for (const cachedResult of results) {
482-
if (cachedResult?.watchFiles) {
483-
for (const file of cachedResult.watchFiles) {
484-
if (!isInternalAngularFile(file)) {
485-
this.watchFiles.add(
486-
isAbsolute(file) ? normalize(file) : join(this.workspaceRoot, file),
487-
);
488-
}
489-
}
477+
if (!this.incremental || !loadCache || !this.#loadCacheKeys) {
478+
return;
479+
}
480+
481+
const results = await Promise.all(Array.from(this.#loadCacheKeys, (key) => loadCache.get(key)));
482+
for (const cachedResult of results) {
483+
if (!cachedResult?.watchFiles) {
484+
continue;
485+
}
486+
487+
for (const file of cachedResult.watchFiles) {
488+
if (isInternalAngularFile(file)) {
489+
continue;
490490
}
491+
492+
this.watchFiles.add(isAbsolute(file) ? normalize(file) : join(this.workspaceRoot, file));
491493
}
492494
}
493495
}

‎packages/angular/build/src/tools/esbuild/bundler-context_spec.ts‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,8 @@ describe('BundlerContext', () => {
159159
const resultA2 = await contextA.bundle();
160160
expect(resultB2).toBe(resultB1);
161161
expect(resultA2).not.toBe(resultA1);
162-
if (!resultA2.errors) {
163-
expect(resultA2.outputFiles[0].text).toContain('green');
164-
}
162+
assert(!resultA2.errors);
163+
expect(resultA2.outputFiles[0].text).toContain('green');
165164
});
166165

167166
it('should work when watchFiles is smaller than changed files', () => {
@@ -217,10 +216,8 @@ describe('BundlerContext', () => {
217216
expect(context.invalidate([subCssPath])).toBeTrue();
218217

219218
const recoveredResult = await context.bundle();
220-
expect(recoveredResult.errors).toBeUndefined();
221-
if (!recoveredResult.errors) {
222-
expect(recoveredResult.outputFiles[0].text).toContain('purple');
223-
}
219+
assert(!recoveredResult.errors);
220+
expect(recoveredResult.outputFiles[0].text).toContain('purple');
224221
});
225222
});
226223
});

0 commit comments

Comments
 (0)