Skip to content

Commit

Permalink
feat: update Ivy compilation pipeline to use faster NGTSC program
Browse files Browse the repository at this point in the history
  • Loading branch information
alan-agius4 committed Jun 22, 2021
1 parent ecedfb6 commit 9f17304
Show file tree
Hide file tree
Showing 28 changed files with 713 additions and 69 deletions.
1 change: 1 addition & 0 deletions integration/samples/apf/public_api.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { PrimaryAngularModule } from './src/primary.module';
export { PrimaryAngularComponent } from './src/primary.component';
export const title = 'hello world';
1 change: 1 addition & 0 deletions integration/samples/apf/secondary/public_api.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { SecondaryAngularModule } from './src/secondary.module';
export { SecondaryAngularComponent } from './src/secondary.component';
1 change: 1 addition & 0 deletions integration/samples/apf/secondary/testing/public_api.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { SecondaryAngularModule } from './src/secondary.module';
export { SecondaryAngularComponent } from './src/secondary.component';
1 change: 1 addition & 0 deletions integration/samples/apf/testing/public_api.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { SecondaryAngularModule } from './src/secondary.module';
export { SecondaryAngularComponent } from './src/secondary.component';
1 change: 1 addition & 0 deletions integration/samples/api/secondary/public_api.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { SecondaryAngularModule } from './src/secondary.module';
export { SecondaryAngularComponent } from './src/secondary.component';
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import { Component } from '@angular/core';

@Component({
selector: 'ng-component-secondary',
template: '<h1>Angular!</h1><ng-component [title]="2"></ng-component>',
template: '<h1>Angular!</h1><ng-component title="foo"></ng-component>',
})
export class SecondaryAngularComponent {}
2 changes: 1 addition & 1 deletion integration/samples/api/src/angular.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, Input } from '@angular/core';
import jsonData from './angular.component.json';
import jsonData from './angular.component2.json';

@Component({
selector: 'ng-component',
Expand Down
6 changes: 1 addition & 5 deletions integration/samples/api/tsconfig.ngc.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
{
"angularCompilerOptions": {
"enableIvy": false,
"annotateForClosureCompiler": false,
"skipTemplateCodegen": true,
"strictMetadataEmit": true,
"fullTemplateTypeCheck": true,
"enableResourceInlining": true
"strictTemplates": true,
},
"buildOnSave": false,
"compileOnSave": false,
Expand Down
8 changes: 0 additions & 8 deletions integration/watch/basic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ describe('basic', () => {
it("should perform initial compilation when 'watch' is started", () => {
harness.expectDtsToMatch('public_api', /title = "hello world"/);
harness.expectFesm2015ToMatch('basic', /hello world/);
harness.expectMetadataToContain('basic', 'metadata.title', 'hello world');
});

describe('when file changes', () => {
Expand All @@ -34,7 +33,6 @@ describe('basic', () => {
harness.onComplete(() => {
harness.expectDtsToMatch('public_api', /title = "foo bar"/);
harness.expectFesm2015ToMatch('basic', /foo bar/);
harness.expectMetadataToContain('basic', 'metadata.title', 'foo bar');
done();
});
});
Expand All @@ -45,7 +43,6 @@ describe('basic', () => {
harness.onComplete(() => {
harness.expectDtsToMatch('public_api', /title = "foo bar"/);
harness.expectFesm2015ToMatch('basic', /foo bar/);
harness.expectMetadataToContain('basic', 'metadata.title', 'foo bar');
done();
});

Expand All @@ -72,11 +69,6 @@ describe('basic', () => {

harness.onComplete(() => {
harness.expectFesm2015ToMatch('basic-secondary', /Hello Angular/);
harness.expectMetadataToContain(
'secondary/basic-secondary',
'metadata.ɵa.decorators[0].arguments[0].template',
'Hello Angular',
);
done();
});
});
Expand Down
1 change: 1 addition & 0 deletions integration/watch/basic/public_api.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { PrimaryAngularComponent } from './src/primary.component';
export { PrimaryAngularModule } from './src/primary.module';
export const title = 'hello world';
1 change: 1 addition & 0 deletions integration/watch/basic/secondary/public_api.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { SecondaryAngularModule } from './src/secondary.module';
export { SecondaryAngularComponent } from './src/secondary.component';
25 changes: 25 additions & 0 deletions integration/watch/basic/tsconfig.ngc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"angularCompilerOptions": {
},
"buildOnSave": false,
"compileOnSave": false,
"compilerOptions": {
"baseUrl": ".",
"target": "es2015",
"module": "es2015",
"moduleResolution": "node",
"outDir": "",
"resolveJsonModule": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"declaration": true,
"inlineSourceMap": true,
"inlineSources": true,
"skipLibCheck": true,
"declarationMap": true,
"emitDecoratorMetadata": false,
"experimentalDecorators": true,
"importHelpers": true,
"lib": ["dom", "es2015"]
},
}
1 change: 0 additions & 1 deletion integration/watch/intra-dependent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ describe('intra-dependent', () => {

it("should perform initial compilation when 'watch' is started", () => {
harness.expectDtsToMatch('src/primary.component', /count: number/);
harness.expectFesm2015ToMatch('intra-dependent-secondary', /count = 100/);
});

it('should throw error component inputs is changed without updating usages', done => {
Expand Down
25 changes: 25 additions & 0 deletions integration/watch/intra-dependent/tsconfig.ngc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"angularCompilerOptions": {
},
"buildOnSave": false,
"compileOnSave": false,
"compilerOptions": {
"baseUrl": ".",
"target": "es2015",
"module": "es2015",
"moduleResolution": "node",
"outDir": "",
"resolveJsonModule": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"declaration": true,
"inlineSourceMap": true,
"inlineSources": true,
"skipLibCheck": true,
"declarationMap": true,
"emitDecoratorMetadata": false,
"experimentalDecorators": true,
"importHelpers": true,
"lib": ["dom", "es2015"]
},
}
4 changes: 2 additions & 2 deletions integration/watch/resources.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('resources', () => {
describe('primary entrypoint', () => {
it("should perform initial compilation when 'watch' is started", () => {
harness.expectFesm2015ToMatch('resources', /Angular!/);
harness.expectFesm2015ToMatch('resources', /a{color:#000}/);
harness.expectFesm2015ToMatch('resources', /a\[_ngcontent-%COMP%\]{color:#000}"/);
});

describe('when file changes', () => {
Expand All @@ -35,7 +35,7 @@ describe('resources', () => {
harness.copyTestCase('scss-file');

harness.onComplete(() => {
harness.expectFesm2015ToMatch('resources', /a{color:#fff}/);
harness.expectFesm2015ToMatch('resources', /a\[_ngcontent-%COMP%\]{color:#fff}"/);
done();
});
});
Expand Down
3 changes: 2 additions & 1 deletion integration/watch/resources/public_api.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { PrimaryAngularComponent } from './src/primary.component';
export { PrimaryAngularModule } from './src/primary.module';
export const title = 'hello world';
export const title = 'hello world';
25 changes: 25 additions & 0 deletions integration/watch/resources/tsconfig.ngc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"angularCompilerOptions": {
},
"buildOnSave": false,
"compileOnSave": false,
"compilerOptions": {
"baseUrl": ".",
"target": "es2015",
"module": "es2015",
"moduleResolution": "node",
"outDir": "",
"resolveJsonModule": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"declaration": true,
"inlineSourceMap": true,
"inlineSources": true,
"skipLibCheck": true,
"declarationMap": true,
"emitDecoratorMetadata": false,
"experimentalDecorators": true,
"importHelpers": true,
"lib": ["dom", "es2015"]
},
}
6 changes: 1 addition & 5 deletions integration/watch/test-harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@ export class TestHarness {
return expect(this.readFileSync('package.json')).to.match(regexp);
}

expectMetadataToContain(fileName: string, path: string, value: any): Chai.Assertion {
const data = this.readFileSync(`${fileName}.metadata.json`, true);
return expect(data).to.have.nested.property(path, value);
}

/**
* Gets invoked when a compilation completes succesfully.
*/
Expand Down Expand Up @@ -113,6 +108,7 @@ export class TestHarness {
return new Promise(resolve => {
this.ngPackagr$$ = ngPackagr()
.forProject(path.join(this.testTempPath, 'package.json'))
.withTsConfig(path.join(this.testTempPath, 'tsconfig.ngc.json'))
.watch()
.pipe(
tap(() => resolve()), // we are only interested when in the first builds, that's why we are resolving it
Expand Down
17 changes: 13 additions & 4 deletions src/lib/file-system/file-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ export interface CacheEntry {
sourceFile?: ts.SourceFile;
content?: string;
declarationFileName?: string;
angularDiagnostics?: ts.Diagnostic[];
}

export class FileCache {
private cache: Map<string, CacheEntry> = new Map();

forEach: (
callbackfn: (value: CacheEntry, key: string, map: Map<string, CacheEntry>) => void,
thisArg?: any,
) => void = this.cache.forEach.bind(this.cache);
forEach: (callbackfn: (value: CacheEntry, key: string, map: Map<string, CacheEntry>) => void, thisArg?: any) => void =
this.cache.forEach.bind(this.cache);
clear: () => void = this.cache.clear.bind(this.cache);

size(): number {
Expand Down Expand Up @@ -48,4 +47,14 @@ export class FileCache {

return entry;
}

updateAngularDiagnostics(sourceFile: ts.SourceFile, diagnostics: ts.Diagnostic[]): void {
if (this.has(sourceFile.fileName)) {
this.get(sourceFile.fileName).angularDiagnostics = diagnostics;
}
}

getAngularDiagnostics(sourceFile: ts.SourceFile): ts.Diagnostic[] | undefined {
return this.get(sourceFile.fileName)?.angularDiagnostics;
}
}

0 comments on commit 9f17304

Please sign in to comment.