Skip to content

Commit 53d6b99

Browse files
committed
fixup! perf(@angular/build): avoid TS AST eviction and d.ts re-emit on external resource edits
1 parent 80670f5 commit 53d6b99

1 file changed

Lines changed: 21 additions & 58 deletions

File tree

  • packages/angular/build/src/builders/library/tests/behavior

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

Lines changed: 21 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88

99
import { rm } from 'node:fs/promises';
10-
import { ParallelCompilation } from '../../../../tools/angular/compilation/parallel-compilation';
1110
import { executeLibraryBuilder } from '../../builder';
1211
import { CompilationMode, InlineStyleLanguage } from '../../schema';
1312
import { BASE_OPTIONS, LIBRARY_BUILDER_INFO, describeLibraryBuilder } from '../setup';
@@ -849,7 +848,7 @@ describeLibraryBuilder(executeLibraryBuilder, LIBRARY_BUILDER_INFO, (harness) =>
849848
]);
850849
});
851850

852-
it('should update .mjs bundle without invalidating .ts or re-emitting .d.ts when external Sass or partial is modified', async () => {
851+
it('should rebuild when an external Sass stylesheet or imported partial is modified', async () => {
853852
await harness.writeFiles({
854853
'projects/lib/src/lib/_vars.scss': '$primary-color: rgb(10, 20, 30);',
855854
'projects/lib/src/lib/lib.component.scss':
@@ -866,9 +865,6 @@ describeLibraryBuilder(executeLibraryBuilder, LIBRARY_BUILDER_INFO, (harness) =>
866865
`,
867866
});
868867

869-
const updateSpy = spyOn(ParallelCompilation.prototype, 'update').and.callThrough();
870-
const emitSpy = spyOn(ParallelCompilation.prototype, 'emitAffectedFiles').and.callThrough();
871-
872868
harness.useTarget('build', {
873869
...BASE_OPTIONS,
874870
watch: true,
@@ -880,62 +876,48 @@ describeLibraryBuilder(executeLibraryBuilder, LIBRARY_BUILDER_INFO, (harness) =>
880876
const content = harness.readFile('dist/lib/fesm2022/lib.mjs');
881877
expect(content).toMatch(/color:\s*(?:#0a141e|rgb\(10,\s*20,\s*30\))/);
882878
expect(content).toMatch(/padding:\s*4px/);
883-
884-
updateSpy.calls.reset();
885-
emitSpy.calls.reset();
879+
expect(harness.readFile('dist/lib/types/lib.d.ts')).toContain('LibComponent');
886880

887881
// Modify the external component stylesheet directly
888882
await harness.writeFile(
889883
'projects/lib/src/lib/lib.component.scss',
890884
'@use "./vars"; :host { color: vars.$primary-color; padding: 16px; }',
891885
);
892886
},
893-
async ({ result }) => {
887+
async ({ result, logs }) => {
894888
expect(result?.success).toBeTrue();
895889
const content = harness.readFile('dist/lib/fesm2022/lib.mjs');
896890
expect(content).toMatch(/color:\s*(?:#0a141e|rgb\(10,\s*20,\s*30\))/);
897891
expect(content).toMatch(/padding:\s*16px/);
898-
899-
expect(updateSpy).toHaveBeenCalledTimes(1);
900-
const updatedFilesAfterScss = [...(updateSpy.calls.mostRecent().args[0] ?? [])];
901-
expect(updatedFilesAfterScss.some((f) => f.endsWith('.ts'))).toBeFalse();
902-
903-
expect(emitSpy).toHaveBeenCalledTimes(1);
904-
const emittedAfterScss = [...(await emitSpy.calls.mostRecent().returnValue)];
905-
expect(emittedAfterScss.some((f) => f.filename.endsWith('lib.component.js'))).toBeTrue();
906-
expect(emittedAfterScss.some((f) => f.filename.endsWith('.d.ts'))).toBeFalse();
907-
908-
updateSpy.calls.reset();
909-
emitSpy.calls.reset();
892+
expect(harness.readFile('dist/lib/types/lib.d.ts')).toContain('LibComponent');
893+
expect(logs).toContain(
894+
jasmine.objectContaining({
895+
message: jasmine.stringContaining('Compiling lib...'),
896+
}),
897+
);
910898

911899
// Modify the imported Sass partial
912900
await harness.writeFile(
913901
'projects/lib/src/lib/_vars.scss',
914902
'$primary-color: rgb(200, 100, 50);',
915903
);
916904
},
917-
async ({ result }) => {
905+
({ result, logs }) => {
918906
expect(result?.success).toBeTrue();
919907
const content = harness.readFile('dist/lib/fesm2022/lib.mjs');
920908
expect(content).toMatch(/color:\s*(?:#c86432|rgb\(200,\s*100,\s*50\))/);
921909
expect(content).toMatch(/padding:\s*16px/);
922-
923-
expect(updateSpy).toHaveBeenCalledTimes(1);
924-
const updatedFilesAfterPartial = [...(updateSpy.calls.mostRecent().args[0] ?? [])];
925-
expect(updatedFilesAfterPartial.some((f) => f.endsWith('.ts'))).toBeFalse();
926-
expect(updatedFilesAfterPartial.some((f) => f.endsWith('lib.component.scss'))).toBeTrue();
927-
928-
expect(emitSpy).toHaveBeenCalledTimes(1);
929-
const emittedAfterPartial = [...(await emitSpy.calls.mostRecent().returnValue)];
930-
expect(
931-
emittedAfterPartial.some((f) => f.filename.endsWith('lib.component.js')),
932-
).toBeTrue();
933-
expect(emittedAfterPartial.some((f) => f.filename.endsWith('.d.ts'))).toBeFalse();
910+
expect(harness.readFile('dist/lib/types/lib.d.ts')).toContain('LibComponent');
911+
expect(logs).toContain(
912+
jasmine.objectContaining({
913+
message: jasmine.stringContaining('Compiling lib...'),
914+
}),
915+
);
934916
},
935917
]);
936918
});
937919

938-
it('should update .mjs bundle and report template errors without re-emitting .d.ts when external template is modified', async () => {
920+
it('should report template errors and recover when an external template is modified', async () => {
939921
await harness.writeFiles({
940922
'projects/lib/src/lib/lib.component.html': '<h1>{{ title }}</h1>',
941923
'projects/lib/src/lib/lib.component.ts': `
@@ -951,8 +933,6 @@ describeLibraryBuilder(executeLibraryBuilder, LIBRARY_BUILDER_INFO, (harness) =>
951933
`,
952934
});
953935

954-
const emitSpy = spyOn(ParallelCompilation.prototype, 'emitAffectedFiles').and.callThrough();
955-
956936
harness.useTarget('build', {
957937
...BASE_OPTIONS,
958938
watch: true,
@@ -962,8 +942,7 @@ describeLibraryBuilder(executeLibraryBuilder, LIBRARY_BUILDER_INFO, (harness) =>
962942
async ({ result }) => {
963943
expect(result?.success).toBeTrue();
964944
expect(harness.readFile('dist/lib/fesm2022/lib.mjs')).toContain('h1');
965-
966-
emitSpy.calls.reset();
945+
expect(harness.readFile('dist/lib/types/lib.d.ts')).toContain('LibComponent');
967946

968947
// Modify external HTML template with valid markup
969948
await harness.writeFile(
@@ -974,13 +953,7 @@ describeLibraryBuilder(executeLibraryBuilder, LIBRARY_BUILDER_INFO, (harness) =>
974953
async ({ result }) => {
975954
expect(result?.success).toBeTrue();
976955
expect(harness.readFile('dist/lib/fesm2022/lib.mjs')).toContain('section');
977-
978-
expect(emitSpy).toHaveBeenCalledTimes(1);
979-
const emittedAfterHtml = [...(await emitSpy.calls.mostRecent().returnValue)];
980-
expect(emittedAfterHtml.some((f) => f.filename.endsWith('lib.component.js'))).toBeTrue();
981-
expect(emittedAfterHtml.some((f) => f.filename.endsWith('.d.ts'))).toBeFalse();
982-
983-
emitSpy.calls.reset();
956+
expect(harness.readFile('dist/lib/types/lib.d.ts')).toContain('LibComponent');
984957

985958
// Introduce a template type-checking error in the external HTML template
986959
await harness.writeFile(
@@ -996,26 +969,16 @@ describeLibraryBuilder(executeLibraryBuilder, LIBRARY_BUILDER_INFO, (harness) =>
996969
}),
997970
);
998971

999-
expect(emitSpy).toHaveBeenCalledTimes(1);
1000-
const emittedOnError = [...(await emitSpy.calls.mostRecent().returnValue)];
1001-
expect(emittedOnError.some((f) => f.filename.endsWith('.d.ts'))).toBeFalse();
1002-
1003-
emitSpy.calls.reset();
1004-
1005972
// Fix the external HTML template error
1006973
await harness.writeFile(
1007974
'projects/lib/src/lib/lib.component.html',
1008975
'<footer>{{ title }}</footer>',
1009976
);
1010977
},
1011-
async ({ result }) => {
978+
({ result }) => {
1012979
expect(result?.success).toBeTrue();
1013980
expect(harness.readFile('dist/lib/fesm2022/lib.mjs')).toContain('footer');
1014-
1015-
expect(emitSpy).toHaveBeenCalledTimes(1);
1016-
const emittedOnRecovery = [...(await emitSpy.calls.mostRecent().returnValue)];
1017-
expect(emittedOnRecovery.some((f) => f.filename.endsWith('lib.component.js'))).toBeTrue();
1018-
expect(emittedOnRecovery.some((f) => f.filename.endsWith('.d.ts'))).toBeFalse();
981+
expect(harness.readFile('dist/lib/types/lib.d.ts')).toContain('LibComponent');
1019982
},
1020983
]);
1021984
});

0 commit comments

Comments
 (0)