Skip to content

Commit 695a01b

Browse files
alan-agius4clydin
authored andcommitted
feat(@schematics/angular): configure new libraries to be published in Ivy partial mode
With this change we configure new libraries to be published using Ivy partial compilation instead of the deprecated View Engine rendering engine, we also remove several view engine specific `angularCompilerOptions`. New libraries can be published using this format, as they are not depend upon by View Engine libraries or application.
1 parent de63f41 commit 695a01b

File tree

9 files changed

+119
-41
lines changed

9 files changed

+119
-41
lines changed

packages/angular_devkit/build_angular/test/hello-world-lib/projects/lib/tsconfig.lib.json

-5
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@
1111
"es2018"
1212
]
1313
},
14-
"angularCompilerOptions": {
15-
"skipTemplateCodegen": true,
16-
"strictMetadataEmit": true,
17-
"enableResourceInlining": true
18-
},
1914
"exclude": [
2015
"src/test.ts",
2116
"**/*.spec.ts"

packages/angular_devkit/build_angular/test/hello-world-lib/projects/lib/tsconfig.lib.prod.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
"declarationMap": false
55
},
66
"angularCompilerOptions": {
7-
"enableIvy": false
7+
"compilationMode": "partial"
88
}
99
}

packages/schematics/angular/library/files/tsconfig.lib.json.template

-5
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@
1313
"es2018"
1414
]
1515
},
16-
"angularCompilerOptions": {
17-
"skipTemplateCodegen": true,
18-
"strictMetadataEmit": true,
19-
"enableResourceInlining": true
20-
},
2116
"exclude": [
2217
"src/test.ts",
2318
"**/*.spec.ts"

packages/schematics/angular/library/files/tsconfig.lib.prod.json.template

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
"declarationMap": false
66
},
77
"angularCompilerOptions": {
8-
"enableIvy": false
8+
"compilationMode": "partial"
99
}
1010
}

packages/schematics/angular/utility/latest-versions.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ export const latestVersions = {
2020
// should not be updated.
2121
DevkitBuildAngular: '~0.1200.0-next.9',
2222

23-
ngPackagr: '^12.0.0-next.0',
23+
ngPackagr: '^12.0.0-next.8',
2424
};

tests/legacy-cli/e2e/tests/generate/library/library-basic.ts

-11
This file was deleted.

tests/legacy-cli/e2e/tests/generate/library/library-consumption.ts renamed to tests/legacy-cli/e2e/tests/generate/library/library-consumption-ivy-full.ts

+18-11
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { writeFile } from '../../../utils/fs';
22
import { ng } from '../../../utils/process';
3+
import { updateJsonFile } from '../../../utils/project';
34

45
export default async function () {
56
await ng('generate', 'library', 'my-lib');
7+
68
await writeFile('./src/app/app.module.ts', `
79
import { BrowserModule } from '@angular/platform-browser';
810
import { NgModule } from '@angular/core';
@@ -33,7 +35,7 @@ export default async function () {
3335
template: '<lib-my-lib></lib-my-lib>'
3436
})
3537
export class AppComponent {
36-
title = 'app';
38+
title = 'test-project';
3739
3840
constructor(myLibService: MyLibService) {
3941
console.log(myLibService);
@@ -67,19 +69,24 @@ export default async function () {
6769
});
6870
`);
6971

70-
await runLibraryTests();
71-
await runLibraryTests(true);
72-
}
72+
// Build library in full mode (development)
73+
await ng('build', 'my-lib', '--configuration=development');
7374

74-
async function runLibraryTests(prodMode = false): Promise<void> {
75-
const args = ['build', 'my-lib'];
76-
if (!prodMode) {
77-
args.push('--configuration=development');
78-
}
75+
// AOT linking
76+
await runTests();
7977

80-
await ng(...args);
78+
// JIT linking
79+
await updateJsonFile('angular.json', config => {
80+
const build = config.projects['test-project'].architect.build;
81+
build.options.aot = false;
82+
build.configurations.production.buildOptimizer = false;
83+
});
84+
85+
await runTests();
86+
}
8187

82-
// Check that the tests succeeds both with named project, unnammed (should test app), and prod.
88+
async function runTests(): Promise<void> {
89+
// Check that the tests succeeds both with named project, unnamed (should test app), and prod.
8390
await ng('e2e');
8491
await ng('e2e', 'test-project', '--devServerTarget=test-project:serve:production');
8592
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import { writeFile } from '../../../utils/fs';
2+
import { ng } from '../../../utils/process';
3+
import { updateJsonFile } from '../../../utils/project';
4+
5+
export default async function () {
6+
await ng('generate', 'library', 'my-lib');
7+
8+
await writeFile('./src/app/app.module.ts', `
9+
import { BrowserModule } from '@angular/platform-browser';
10+
import { NgModule } from '@angular/core';
11+
import { MyLibModule } from 'my-lib';
12+
13+
import { AppComponent } from './app.component';
14+
15+
@NgModule({
16+
declarations: [
17+
AppComponent
18+
],
19+
imports: [
20+
BrowserModule,
21+
MyLibModule,
22+
],
23+
providers: [],
24+
bootstrap: [AppComponent]
25+
})
26+
export class AppModule { }
27+
`);
28+
29+
await writeFile('./src/app/app.component.ts', `
30+
import { Component } from '@angular/core';
31+
import { MyLibService } from 'my-lib';
32+
33+
@Component({
34+
selector: 'app-root',
35+
template: '<lib-my-lib></lib-my-lib>'
36+
})
37+
export class AppComponent {
38+
title = 'test-project';
39+
40+
constructor(myLibService: MyLibService) {
41+
console.log(myLibService);
42+
}
43+
}
44+
`);
45+
46+
await writeFile('e2e/src/app.e2e-spec.ts', `
47+
import { browser, logging, element, by } from 'protractor';
48+
import { AppPage } from './app.po';
49+
50+
describe('workspace-project App', () => {
51+
let page: AppPage;
52+
53+
beforeEach(() => {
54+
page = new AppPage();
55+
});
56+
57+
it('should display text from library component', async () => {
58+
await page.navigateTo();
59+
expect(await element(by.css('lib-my-lib p')).getText()).toEqual('my-lib works!');
60+
});
61+
62+
afterEach(async () => {
63+
// Assert that there are no errors emitted from the browser
64+
const logs = await browser.manage().logs().get(logging.Type.BROWSER);
65+
expect(logs).not.toContain(jasmine.objectContaining({
66+
level: logging.Level.SEVERE,
67+
}));
68+
});
69+
});
70+
`);
71+
72+
// Build library in partial mode (production)
73+
await ng('build', 'my-lib', '--configuration=production');
74+
75+
// AOT linking
76+
await runTests();
77+
78+
// JIT linking
79+
await updateJsonFile('angular.json', config => {
80+
const build = config.projects['test-project'].architect.build;
81+
build.options.aot = false;
82+
build.configurations.production.buildOptimizer = false;
83+
});
84+
85+
await runTests();
86+
}
87+
88+
async function runTests(): Promise<void> {
89+
// Check that the tests succeeds both with named project, unnamed (should test app), and prod.
90+
await ng('e2e');
91+
await ng('e2e', 'test-project', '--devServerTarget=test-project:serve:production');
92+
}

tests/legacy-cli/e2e/tests/generate/library/library-consumption-linker.ts renamed to tests/legacy-cli/e2e/tests/generate/library/library-consumption-ve.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import { updateJsonFile } from '../../../utils/project';
55
export default async function () {
66
await ng('generate', 'library', 'my-lib');
77

8-
// Enable partial compilation mode (linker) for the library
9-
await updateJsonFile('projects/my-lib/tsconfig.lib.json', config => {
8+
await updateJsonFile('projects/my-lib/tsconfig.lib.prod.json', config => {
109
const { angularCompilerOptions = {} } = config;
11-
angularCompilerOptions.enableIvy = true;
12-
angularCompilerOptions.compilationMode = 'partial';
10+
angularCompilerOptions.enableIvy = false;
11+
angularCompilerOptions.skipTemplateCodegen = true;
12+
angularCompilerOptions.strictMetadataEmit = true;
1313
config.angularCompilerOptions = angularCompilerOptions;
1414
});
1515

@@ -77,8 +77,8 @@ export default async function () {
7777
});
7878
`);
7979

80-
// Build library in partial mode (development)
81-
await ng('build', 'my-lib', '--configuration=development');
80+
// Build library in VE mode (production)
81+
await ng('build', 'my-lib', '--configuration=production');
8282

8383
// AOT linking
8484
await runTests();

0 commit comments

Comments
 (0)