This commit introduces a mechanism for incremental compilation to the ngtsc compiler. Previously, incremental information was used in the construction of the ts.Program for subsequent compilations, but was not used in ngtsc itself. This commit adds an IncrementalState class, which tracks state between ngtsc compilations. Currently, this supports skipping the TypeScript emit step when the compiler can prove the contents of emit have not changed. This is implemented for @Injectables as well as for files which don't contain any Angular decorated types. These are the only files which can be proven to be safe today. See ngtsc/incremental/README.md for more details. PR Close #29380
47 lines
1.3 KiB
TypeScript
47 lines
1.3 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
* found in the LICENSE file at https://angular.io/license
|
|
*/
|
|
|
|
import {NgtscTestEnvironment} from './env';
|
|
|
|
describe('ngtsc incremental compilation', () => {
|
|
let env !: NgtscTestEnvironment;
|
|
beforeEach(() => {
|
|
env = NgtscTestEnvironment.setup();
|
|
env.enableMultipleCompilations();
|
|
env.tsconfig();
|
|
});
|
|
|
|
it('should compile incrementally', () => {
|
|
env.write('service.ts', `
|
|
import {Injectable} from '@angular/core';
|
|
|
|
@Injectable()
|
|
export class Service {}
|
|
`);
|
|
env.write('test.ts', `
|
|
import {Component} from '@angular/core';
|
|
import {Service} from './service';
|
|
|
|
@Component({selector: 'cmp', template: 'cmp'})
|
|
export class Cmp {
|
|
constructor(service: Service) {}
|
|
}
|
|
`);
|
|
env.driveMain();
|
|
env.flushWrittenFileTracking();
|
|
|
|
// Pretend a change was made to test.ts.
|
|
env.invalidateCachedFile('test.ts');
|
|
env.driveMain();
|
|
const written = env.getFilesWrittenSinceLastFlush();
|
|
|
|
// The component should be recompiled, but not the service.
|
|
expect(written).toContain('/test.js');
|
|
expect(written).not.toContain('/service.js');
|
|
});
|
|
}); |