Skip to content
This repository was archived by the owner on Oct 12, 2021. It is now read-only.

Commit f008181

Browse files
mgechevalxhub
authored andcommitted
chore(AppShell): migrate to rc6 and use ngc (#99)
1. Use ngc: - Generate metadata files. - Emit ESM modules in order in order to align with the core and provide easier tree-shaking. 2. Migrate to RC.6: - Migrate from deprecated APIs. - Update SystemJS config to use the Angular ES5 bundles. Since the current build emits ESM there's a problem with the App Shell Runtime Parser which uses CommonJS internally in order to monkey-patch APIs of parse5 (which uses CommonJS as well). As cleanest solution I'd suggest to move the Runtime Parse to a separate module once the SW plugin architecture is completed.
1 parent 1507011 commit f008181

14 files changed

+134
-162
lines changed

app-shell/angular-cli-build.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@ module.exports = function(defaults) {
1010
'zone.js/dist/*.js',
1111
'es6-shim/es6-shim.js',
1212
'reflect-metadata/*.js',
13+
'reflect-metadata/*.map',
1314
'rxjs/**/*.js',
15+
'rxjs/**/*.map',
1416
'@angular/**/*.js',
15-
'parse5/**/*.js'
17+
'@angular/**/*.map',
18+
'parse5/**/*.js',
19+
'traceur/**/*.js'
1620
]
1721
});
1822
};

app-shell/config/karma-test-shim.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@ System.import('system-config.js').then(function() {
3535
System.import('@angular/core/testing'),
3636
System.import('@angular/platform-browser-dynamic/testing')
3737
]).then(function (providers) {
38-
var testing = providers[0];
38+
var TestBed = providers[0].TestBed;
3939
var testingBrowser = providers[1];
40-
41-
testing.setBaseTestProviders(testingBrowser.TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
42-
testingBrowser.TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);
40+
TestBed.initTestEnvironment(
41+
testingBrowser.BrowserDynamicTestingModule,
42+
testingBrowser.platformBrowserDynamicTesting()
43+
);
4344
});
4445
}).then(function() {
4546
// Finally, load all spec files.

app-shell/config/karma.conf.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,17 @@ module.exports = function (config) {
1515
},
1616
files: [
1717
{ pattern: 'dist/vendor/es6-shim/es6-shim.js', included: true, watched: false },
18+
1819
{ pattern: 'dist/vendor/zone.js/dist/zone.js', included: true, watched: false },
20+
{ pattern: 'dist/vendor/zone.js/dist/proxy.js', included: true, watched: false },
21+
{ pattern: 'dist/vendor/zone.js/dist/sync-test.js', included: true, watched: false },
22+
{ pattern: 'dist/vendor/zone.js/dist/jasmine-patch.js', included: true, watched: false },
23+
{ pattern: 'dist/vendor/zone.js/dist/async-test.js', included: true, watched: false },
24+
{ pattern: 'dist/vendor/zone.js/dist/fake-async-test.js', included: true, watched: false },
25+
1926
{ pattern: 'dist/vendor/reflect-metadata/Reflect.js', included: true, watched: false },
2027
{ pattern: 'dist/vendor/systemjs/dist/system-polyfills.js', included: true, watched: false },
2128
{ pattern: 'dist/vendor/systemjs/dist/system.src.js', included: true, watched: false },
22-
{ pattern: 'dist/vendor/zone.js/dist/async-test.js', included: true, watched: false },
2329

2430
{ pattern: 'config/karma-test-shim.js', included: true, watched: true },
2531

app-shell/package.json

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,26 @@
1111
"pree2e": "webdriver-manager update",
1212
"e2e": "protractor",
1313
"clean": "rm -rf dist",
14-
"build": "ng build && tsc -p src/tsconfig.publish.es5.json && tsc -p src/tsconfig.publish.es6.json && cp src/package.json dist/app/package.json && echo '' > dist/vendor/parse5/lib/tokenizer/named_entity_trie.js && browserify dist/app/shell-parser/index.js -s shellParserFactory > dist/app/shell-parser.js && rm -rf dist/app/shell-parser && rm -rf dist/app/vendor",
14+
"build": "mkdir -p dist/app && ngc -p src/tsconfig.publish.json && cp src/package.json dist/app/package.json",
15+
"build_parser": "echo '' > dist/vendor/parse5/lib/tokenizer/named_entity_trie.js && browserify dist/app/shell-parser/index.js -s shellParserFactory > dist/app/shell-parser.js && rm -rf dist/app/shell-parser && rm -rf dist/app/vendor",
1516
"build_publish": "npm run clean && npm run build"
1617
},
1718
"private": true,
1819
"dependencies": {
19-
"@angular/common": "~2.0.0-rc.5",
20-
"@angular/compiler": "~2.0.0-rc.5",
21-
"@angular/core": "~2.0.0-rc.5",
22-
"@angular/platform-browser": "~2.0.0-rc.5",
23-
"@angular/platform-browser-dynamic": "~2.0.0-rc.5",
20+
"@angular/common": "^2.0.0-rc.6",
21+
"@angular/compiler": "^2.0.0-rc.6",
22+
"@angular/core": "^2.0.0-rc.6",
23+
"@angular/platform-browser": "^2.0.0-rc.6",
24+
"@angular/platform-browser-dynamic": "^2.0.0-rc.6",
2425
"es6-shim": "^0.35.0",
2526
"reflect-metadata": "0.1.3",
26-
"rxjs": "5.0.0-beta.6",
27+
"rxjs": "5.0.0-beta.11",
2728
"systemjs": "0.19.26",
28-
"zone.js": "^0.6.12"
29+
"zone.js": "^0.6.17"
2930
},
3031
"devDependencies": {
32+
"@angular/compiler-cli": "^0.6.0",
33+
"@angular/platform-server": "^2.0.0-rc.6",
3134
"angular-cli": "0.0.*",
3235
"browserify": "^13.0.1",
3336
"clang-format": "^1.0.35",
@@ -42,7 +45,7 @@
4245
"protractor": "^3.3.0",
4346
"ts-node": "^0.5.5",
4447
"tslint": "^3.6.0",
45-
"typescript": "^1.8.10",
48+
"typescript": "^2.0.2",
4649
"typings": "^1.0.4"
4750
}
4851
}

app-shell/src/app/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { Type, NgModule, ModuleWithProviders } from '@angular/core';
22
import { ShellRender } from './shell-render.directive';
33
import { ShellNoRender } from './shell-no-render.directive';
4+
import { IS_PRERENDER } from './is-prerender.service';
45
import { APP_SHELL_RUNTIME_PROVIDERS, APP_SHELL_BUILD_PROVIDERS } from './is-prerender.service';
56

67
export * from './is-prerender.service';
7-
export * from './shell-parser';
8+
export * from './shell-no-render.directive';
9+
export * from './shell-render.directive';
810

9-
export const APP_SHELL_DIRECTIVES: Type[] = [
11+
const APP_SHELL_DIRECTIVES: Type<any>[] = [
1012
ShellRender,
1113
ShellNoRender
1214
];

app-shell/src/app/is-prerender.service.spec.ts

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
import { OpaqueToken, provide, Provider } from '@angular/core';
1+
import { OpaqueToken, Provider } from '@angular/core';
22

33
export const IS_PRERENDER = new OpaqueToken('IsPrerender');
44

55
export const APP_SHELL_RUNTIME_PROVIDERS: Provider[] = [
6-
provide(IS_PRERENDER, {
6+
{
7+
provide: IS_PRERENDER,
78
useValue: false
8-
})
9+
}
910
];
1011

1112
export const APP_SHELL_BUILD_PROVIDERS: Provider[] = [
12-
provide(IS_PRERENDER, {
13+
{
14+
provide: IS_PRERENDER,
1315
useValue: true
14-
})
15-
];
16+
}
17+
];
Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,62 @@
11
import {
22
ComponentFixture,
3-
TestComponentBuilder
4-
} from '@angular/core/testing';
5-
6-
import {
73
async,
84
inject,
9-
addProviders
5+
TestBed
106
} from '@angular/core/testing';
11-
import { provide, Component } from '@angular/core';
7+
import { Component } from '@angular/core';
8+
129
import { ShellNoRender } from './shell-no-render.directive';
10+
import { APP_SHELL_RUNTIME_PROVIDERS, APP_SHELL_BUILD_PROVIDERS } from './is-prerender.service';
1311
import {
14-
APP_SHELL_BUILD_PROVIDERS,
15-
APP_SHELL_RUNTIME_PROVIDERS
16-
} from './is-prerender.service';
12+
AppShellModule
13+
} from './index';
1714

1815
@Component({
1916
selector: 'test-component',
20-
template: `<div *shellNoRender>Rendered</div>`,
21-
directives: [ShellNoRender]
17+
template: `<div *shellNoRender>Rendered</div>`
2218
})
2319
class TestComponent {}
2420

2521
describe('ShellNoRender Directive', () => {
22+
2623
describe('prerender', () => {
24+
2725
beforeEach(() => {
28-
addProviders([APP_SHELL_BUILD_PROVIDERS]);
26+
TestBed.configureTestingModule({
27+
imports: [AppShellModule],
28+
providers: [APP_SHELL_BUILD_PROVIDERS],
29+
declarations: [TestComponent]
30+
});
31+
TestBed.compileComponents();
2932
});
3033

31-
it('should NOT render the element', async(inject([TestComponentBuilder], (tcb:TestComponentBuilder) => {
32-
return tcb.createAsync(TestComponent).then((fixture: ComponentFixture<TestComponent>) => {
33-
fixture.detectChanges();
34-
expect(fixture.debugElement.childNodes.length).toBe(1);
35-
expect(fixture.debugElement.childNodes[0].nativeNode.textContent).toBe('template bindings={}');
36-
});
37-
})));
34+
it('should NOT render the element', () => {
35+
const fixture = TestBed.createComponent(TestComponent);
36+
fixture.detectChanges();
37+
expect(fixture.debugElement.childNodes.length).toBe(1);
38+
expect(fixture.debugElement.childNodes[0].nativeNode.textContent).toBe('template bindings={}');
39+
});
3840
});
3941

4042

4143
describe('runtime', () => {
44+
4245
beforeEach(() => {
43-
addProviders([APP_SHELL_RUNTIME_PROVIDERS]);
46+
TestBed.configureTestingModule({
47+
imports: [AppShellModule],
48+
providers: [APP_SHELL_RUNTIME_PROVIDERS],
49+
declarations: [TestComponent]
50+
});
51+
TestBed.compileComponents();
4452
});
4553

46-
it('should render the element', async(inject([TestComponentBuilder], (tcb:TestComponentBuilder) => {
47-
return tcb.createAsync(TestComponent).then((fixture: ComponentFixture<TestComponent>) => {
48-
fixture.detectChanges();
49-
expect(fixture.debugElement.childNodes.length).toBe(2);
50-
expect(fixture.debugElement.childNodes[0].nativeNode.textContent).toBe('template bindings={}');
51-
expect(fixture.debugElement.childNodes[1].nativeNode.textContent).toBe('Rendered');
52-
});
53-
})));
54+
it('should render the element', () => {
55+
const fixture = TestBed.createComponent(TestComponent);
56+
fixture.detectChanges();
57+
expect(fixture.debugElement.childNodes.length).toBe(2);
58+
expect(fixture.debugElement.childNodes[0].nativeNode.textContent).toBe('template bindings={}');
59+
expect(fixture.debugElement.childNodes[1].nativeNode.textContent).toBe('Rendered');
60+
});
5461
});
5562
});

app-shell/src/app/shell-render.directive.spec.ts

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,63 @@
11
import {
22
async,
3-
addProviders,
43
inject,
54
ComponentFixture,
6-
TestComponentBuilder
5+
TestBed
76
} from '@angular/core/testing';
8-
import { provide, Component } from '@angular/core';
7+
import { Component } from '@angular/core';
98

109
import { ShellRender } from './shell-render.directive';
10+
import { APP_SHELL_RUNTIME_PROVIDERS, APP_SHELL_BUILD_PROVIDERS } from './is-prerender.service';
1111
import {
12-
APP_SHELL_BUILD_PROVIDERS,
13-
APP_SHELL_RUNTIME_PROVIDERS
14-
} from './is-prerender.service';
12+
AppShellModule
13+
} from './index';
1514

1615
@Component({
1716
selector: 'test-component',
18-
template: `<div *shellRender>Rendered</div>`,
19-
directives: [ShellRender]
17+
template: `<div *shellRender>Rendered</div>`
2018
})
2119
class TestComponent {}
2220

2321
describe('ShellRender Directive', () => {
22+
2423
describe('prerender', () => {
24+
2525
beforeEach(() => {
26-
addProviders([APP_SHELL_BUILD_PROVIDERS]);
26+
TestBed.configureTestingModule({
27+
imports: [AppShellModule],
28+
providers: [APP_SHELL_BUILD_PROVIDERS],
29+
declarations: [TestComponent]
30+
});
31+
TestBed.compileComponents();
2732
});
2833

29-
it('should render the element', async(inject([TestComponentBuilder], (tcb:TestComponentBuilder) => {
30-
return tcb.createAsync(TestComponent).then((fixture: ComponentFixture<TestComponent>) => {
31-
fixture.detectChanges();
32-
expect(fixture.debugElement.childNodes.length).toBe(2);
33-
expect(fixture.debugElement.childNodes[0].nativeNode.textContent).toBe('template bindings={}');
34-
expect(fixture.debugElement.childNodes[1].nativeNode.textContent).toBe('Rendered');
35-
});
36-
})));
34+
it('should render the element', () => {
35+
const fixture = TestBed.createComponent(TestComponent);
36+
fixture.detectChanges();
37+
expect(fixture.debugElement.childNodes.length).toBe(2);
38+
expect(fixture.debugElement.childNodes[0].nativeNode.textContent).toBe('template bindings={}');
39+
expect(fixture.debugElement.childNodes[1].nativeNode.textContent).toBe('Rendered');
40+
});
3741
});
3842

3943

4044
describe('runtime', () => {
45+
4146
beforeEach(() => {
42-
addProviders([APP_SHELL_RUNTIME_PROVIDERS]);
47+
TestBed.configureTestingModule({
48+
imports: [AppShellModule],
49+
providers: [APP_SHELL_RUNTIME_PROVIDERS],
50+
declarations: [TestComponent]
51+
});
52+
TestBed.compileComponents();
4353
});
4454

45-
it('should NOT render the element', async(inject([TestComponentBuilder], (tcb:TestComponentBuilder) => {
46-
return tcb.createAsync(TestComponent).then((fixture: ComponentFixture<TestComponent>) => {
47-
fixture.detectChanges();
48-
expect(fixture.debugElement.childNodes.length).toBe(1);
49-
expect(fixture.debugElement.childNodes[0].nativeNode.textContent).toBe('template bindings={}');
50-
});
51-
})));
55+
it('should NOT render the element', () => {
56+
const fixture = TestBed.createComponent(TestComponent);
57+
fixture.detectChanges();
58+
expect(fixture.debugElement.childNodes.length).toBe(1);
59+
expect(fixture.debugElement.childNodes[0].nativeNode.textContent).toBe('template bindings={}');
60+
});
5261
});
5362
});
5463

app-shell/src/system-config.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,6 @@
22
declare var System: any;
33

44
const barrels: string[] = [
5-
// Angular specific barrels.
6-
'@angular/core',
7-
'@angular/common',
8-
'@angular/compiler',
9-
'@angular/http',
10-
'@angular/router',
11-
'@angular/platform-browser',
12-
'@angular/platform-browser-dynamic',
13-
145
// Parse5 barrels
156
'parse5',
167
'parse5/parser',
@@ -39,11 +30,25 @@ const barrels: string[] = [
3930
// Angular CLI SystemJS configuration.
4031
System.config({
4132
map: {
42-
'@angular': 'vendor/@angular',
4333
'parse5': 'vendor/parse5/lib',
4434
'rxjs': 'vendor/rxjs',
35+
'traceur': 'vendor/traceur/bin/traceur.js',
4536
'main': 'main.js'
4637
},
38+
paths: {
39+
'@angular/common': 'vendor/@angular/common/bundles/common.umd.js',
40+
'@angular/compiler': 'vendor/@angular/compiler/bundles/compiler.umd.js',
41+
'@angular/core': 'vendor/@angular/core/bundles/core.umd.js',
42+
'@angular/platform-browser': 'vendor/@angular/platform-browser/bundles/platform-browser.umd.js',
43+
'@angular/platform-browser-dynamic': 'vendor/@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
44+
45+
'@angular/common/testing': 'vendor/@angular/common/bundles/common-testing.umd.js',
46+
'@angular/compiler/testing': 'vendor/@angular/compiler/bundles/compiler-testing.umd.js',
47+
'@angular/core/testing': 'vendor/@angular/core/bundles/core-testing.umd.js',
48+
'@angular/platform-browser/testing': 'vendor/@angular/platform-browser/bundles/platform-browser-testing.umd.js',
49+
'@angular/platform-browser-dynamic/testing': 'vendor/@angular/platform-browser-dynamic/bundles/platform-browser-dynamic-testing.umd.js',
50+
51+
},
4752
packages: barrels.reduce((barrelConfig: any, barrelName: string) => {
4853
barrelConfig[barrelName] = {
4954
main: 'index'

0 commit comments

Comments
 (0)