Skip to content

Commit

Permalink
fix: clear analysis cache to detect invalid imports in watch mode
Browse files Browse the repository at this point in the history
As the analysis file cache was previously never invalidated, any newly
introduced imports would not be detected in the analysis phase. This could
result in e.g. circular imports or self imports to go unnoticed during
watch builds.
  • Loading branch information
JoostK committed Oct 10, 2020
1 parent 3162fbb commit 42365ae
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
19 changes: 14 additions & 5 deletions integration/watch/intra-dependent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,27 @@ describe('intra-dependent', () => {
harness.expectFesm2015ToMatch('intra-dependent-secondary', /count = 100/);
});

it('should throw error component inputs is changed without updating usages', (done) => {
it('should throw error component inputs is changed without updating usages', done => {
harness.copyTestCase('invalid-component-property');

harness.onFailure((error) => {
harness.onFailure(error => {
expect(error.message).to.match(/Can\'t bind to \'count\' since it isn\'t a known property/);
harness.copyTestCase('valid');
done();
});
});

it('should throw error service method is changed without updating usages', (done) => {
it('should throw error service method is changed without updating usages', done => {
harness.copyTestCase('invalid-service-method');

harness.onFailure((error) => {
harness.onFailure(error => {
expect(error.message).to.match(/Property \'initialize\' does not exist on type \'PrimaryAngularService\'/);
harness.copyTestCase('valid');
done();
});
});

it('should only build entrypoints that are dependent on the file changed.', (done) => {
it('should only build entrypoints that are dependent on the file changed.', done => {
const primaryFesmPath = harness.getFilePath('fesm2015/intra-dependent.js');
const secondaryFesmPath = harness.getFilePath('fesm2015/intra-dependent-secondary.js');
const thirdFesmPath = harness.getFilePath('fesm2015/intra-dependent-third.js');
Expand All @@ -59,4 +59,13 @@ describe('intra-dependent', () => {
done();
});
});

it('should fail when introducing a circular import.', done => {
harness.copyTestCase('circular');

harness.onFailure(error => {
expect(error.message).to.contain('Entry point intra-dependent has a circular dependency on itself.');
done();
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Injectable } from '@angular/core';
import 'intra-dependent';

@Injectable()
export class PrimaryAngularService {
initialize() {
// stub
}
}
4 changes: 4 additions & 0 deletions src/lib/ng-package/package.transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ const watchTransformFactory = (
entryPoint.state = 'dirty';
const { metadata } = entryPoint.data.destinationFiles;
sourcesFileCache.delete(metadata);

uriToClean.forEach(url => {
entryPoint.cache.analysesSourcesFileCache.delete(fileUrlPath(url));
});
}
});

Expand Down

0 comments on commit 42365ae

Please sign in to comment.