Skip to content

Commit b4bfb44

Browse files
committed
perf(@angular/cli): fix unnecessary esbuild rebuilds
When using esbuild, Angular sets up a custom file watcher using esbuilds metafile inputs. Esbuild will generate <define:KEY> entries see https://esbuild.github.io/try/#YgAwLjI1LjMALS1kZWZpbmU6Rk9PPSd7fScgLS1tZXRhZmlsZSAtLWJ1bmRsZQBlAGVudHJ5LmpzAGNvbnNvbGUubG9nKEZPTyk. After the build is finished, the file watcher will notice that the <define:KEY> entries no longer exist on the file system and trigger a rebuild even though no files have changed. This change, fixes the above issue by filtering files starting with `<define:`.
1 parent 6e9a054 commit b4bfb44

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ export class BundlerContext {
245245
// When incremental always add any files from the load result cache
246246
if (this.#loadCache) {
247247
for (const file of this.#loadCache.watchFiles) {
248-
if (!isInternalAngularFile(file)) {
248+
if (!isInternalAngularFileOrEsBuildDefine(file)) {
249249
// watch files are fully resolved paths
250250
this.watchFiles.add(file);
251251
}
@@ -260,7 +260,7 @@ export class BundlerContext {
260260
if (this.incremental) {
261261
// Add input files except virtual angular files which do not exist on disk
262262
for (const input of Object.keys(result.metafile.inputs)) {
263-
if (!isInternalAngularFile(input)) {
263+
if (!isInternalAngularFileOrEsBuildDefine(input)) {
264264
// input file paths are always relative to the workspace root
265265
this.watchFiles.add(join(this.workspaceRoot, input));
266266
}
@@ -417,12 +417,12 @@ export class BundlerContext {
417417
#addErrorsToWatch(result: BuildFailure | BuildResult): void {
418418
for (const error of result.errors) {
419419
let file = error.location?.file;
420-
if (file && !isInternalAngularFile(file)) {
420+
if (file && !isInternalAngularFileOrEsBuildDefine(file)) {
421421
this.watchFiles.add(join(this.workspaceRoot, file));
422422
}
423423
for (const note of error.notes) {
424424
file = note.location?.file;
425-
if (file && !isInternalAngularFile(file)) {
425+
if (file && !isInternalAngularFileOrEsBuildDefine(file)) {
426426
this.watchFiles.add(join(this.workspaceRoot, file));
427427
}
428428
}
@@ -475,6 +475,6 @@ export class BundlerContext {
475475
}
476476
}
477477

478-
function isInternalAngularFile(file: string) {
479-
return file.startsWith('angular:');
478+
function isInternalAngularFileOrEsBuildDefine(file: string) {
479+
return file.startsWith('angular:') || file.startsWith('<define:');
480480
}

0 commit comments

Comments
 (0)