Skip to content

Commit 19a2e2c

Browse files
committed
Bring into compatibility with Angular 4.2.2
1 parent 252b77f commit 19a2e2c

File tree

6 files changed

+45
-50
lines changed

6 files changed

+45
-50
lines changed

package.json

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-ssr",
3-
"version": "0.10.11",
3+
"version": "0.10.12",
44
"description": "Angular server-side rendering implementation",
55
"main": "build/index.js",
66
"typings": "build/index.d.ts",
@@ -55,21 +55,21 @@
5555
},
5656
"peerDependencies": {
5757
"@angular/cli": ">=1.1.0",
58-
"@angular/common": ">=4.0.0 <5.0.0",
59-
"@angular/compiler": ">=4.0.0 <5.0.0",
60-
"@angular/compiler-cli": ">=4.0.0 <5.0.0",
61-
"@angular/core": ">=4.0.0 <5.0.0",
62-
"@angular/forms": ">=4.0.0 <5.0.0",
63-
"@angular/http": ">=4.0.0 <5.0.0",
64-
"@angular/platform-browser": ">=4.0.0 <5.0.0",
65-
"@angular/router": ">=4.0.0 <5.0.0",
66-
"@angular/tsc-wrapped": ">=4.0.0 <5.0.0",
58+
"@angular/common": ">=4.2.0 <5.0.0",
59+
"@angular/compiler": ">=4.2.0 <5.0.0",
60+
"@angular/compiler-cli": ">=4.2.0 <5.0.0",
61+
"@angular/core": ">=4.2.0 <5.0.0",
62+
"@angular/forms": ">=4.2.0 <5.0.0",
63+
"@angular/http": ">=4.2.0 <5.0.0",
64+
"@angular/platform-browser": ">=4.2.0 <5.0.0",
65+
"@angular/router": ">=4.2.0 <5.0.0",
66+
"@angular/tsc-wrapped": ">=4.2.0 <5.0.0",
6767
"@angular/service-worker": ">=1.0.0 || >=1.0.0-beta.8",
68-
"reflect-metadata": "^0.1.10",
69-
"rxjs": "^5.0.1",
70-
"zone.js": "^0.8",
68+
"reflect-metadata": ">=0.1.10",
69+
"rxjs": ">=5.0.1",
70+
"zone.js": ">=0.8",
7171
"typescript": ">=2.1.0",
72-
"webpack": "^2.3.3"
72+
"webpack": ">=2.3.0"
7373
},
7474
"dependencies": {
7575
"@angular/cli": ">=1.1.0",
@@ -88,7 +88,7 @@
8888
"npm-run-all": "^4.0.2",
8989
"preboot": "^4.5.2",
9090
"rimraf": "2.5.4",
91-
"rxjs": "^5.0.1",
91+
"rxjs": ">=5.0.1",
9292
"scoped-logger": "^0.0.19",
9393
"source-map-support": ">=0.1.0",
9494
"symbol-observable": "^1.0.4",
@@ -111,12 +111,12 @@
111111
"jasmine": "^2.6.0",
112112
"jasmine-core": "2.6.1",
113113
"jest": "^20.0.4",
114-
"reflect-metadata": "^0.1.10",
114+
"reflect-metadata": ">=0.1.10",
115115
"ts-jest": "^20.0.4",
116116
"tslint": "4.4.2",
117117
"typescript": ">=2.2.0",
118-
"webpack": "^2.4.1",
119-
"zone.js": "^0.8.9"
118+
"webpack": ">=2.4.1",
119+
"zone.js": ">=0.8.9"
120120
},
121121
"jest": {
122122
"automock": false,

source/application/compiler/ngc/compiler.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {Provider} from '@angular/core';
22

3-
import {AotCompiler} from '@angular/compiler';
3+
import {toTypeScript} from '@angular/compiler';
44

55
import {MetadataWriterHost} from '@angular/tsc-wrapped';
66

@@ -35,8 +35,8 @@ import {projectToOptions, loadApplicationModule} from '../options';
3535
export class NgcCompiler implements ApplicationCompiler {
3636
constructor(private project: Project) {}
3737

38-
createPlatform(providers: Array<Provider>) {
39-
return createStaticPlatform(providers) as ServerPlatform;
38+
createPlatform(providers: Array<Provider>): ServerPlatform {
39+
return createStaticPlatform(providers) as any;
4040
}
4141

4242
async compile(): Promise<ModuleLoader> {
@@ -110,18 +110,22 @@ export class NgcCompiler implements ApplicationCompiler {
110110
return build;
111111
}
112112

113-
private async generateTemplateCode(compilerHost: CompilerHost, ngCompilerHost: AngularCompilerHost, compiler: AotCompiler, program: Program, build: Build) {
113+
private async generateTemplateCode(compilerHost: CompilerHost, ngCompilerHost: AngularCompilerHost, compiler, program: Program, build: Build) {
114114
const filenames = program.getSourceFiles().map(sf => ngCompilerHost.getCanonicalFileName(sf.fileName));
115115

116-
const generatedModules = await compiler.compileAll(filenames);
116+
const analyzedModules = await compiler.analyzeModulesAsync(filenames);
117+
118+
const generatedModules = compiler.emitAllImpls(analyzedModules);
117119

118120
return generatedModules.map(
119121
generatedModule => {
120122
const sourceFile = program.getSourceFile(generatedModule.srcFileUrl);
121123

122124
const emitPath = ngCompilerHost.calculateEmitPath(generatedModule.genFileUrl);
123125

124-
compilerHost.writeFile(emitPath, generatedModule.source, false, function () {}, [sourceFile]);
126+
const source = generatedModule.source || toTypeScript(generatedModule, String());
127+
128+
compilerHost.writeFile(emitPath, source, false, function () {}, [sourceFile]);
125129

126130
build.emit(emitPath, [sourceFile]);
127131

source/application/compiler/ngc/tests/compiler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ describe('NgcCompiler', () => {
1919
const module = await loader.lazy({source: 'source/test/fixtures/application-basic-external', symbol: 'BasicExternalModule'});
2020
expect(module).not.toBeNull();
2121
expect(typeof module).toBe('object');
22-
expect(module.constructor.name).toBe('NgModuleFactory');
22+
expect(/NgModuleFactory/.test(module.constructor.name)).toBeTruthy();
2323
});
2424

2525
it('can build application with lazy routes into executable NgModuleFactory', async () => {
2626
const module = await loader.lazy({source: 'source/test/fixtures/application-routed', symbol: 'BasicRoutedModule'});
2727
expect(module).not.toBeNull();
2828
expect(typeof module).toBe('object');
29-
expect(module.constructor.name).toBe('NgModuleFactory');
29+
expect(/NgModuleFactory/.test(module.constructor.name)).toBeTruthy();
3030
});
3131

3232
afterEach(() => {

source/platform/application/bootstrap.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const bootstrapModule = <M>(zone: NgZone, moduleRef: NgModuleRef<M>): Pro
3838

3939
const applicationRef: ApplicationRef = moduleRef.injector.get(ApplicationRef);
4040

41-
const {bootstrapFactories, instance: {ngDoBootstrap}} = <any> moduleRef;
41+
const {_bootstrapComponents, instance: {ngDoBootstrap}} = <any> moduleRef;
4242

4343
const location = moduleRef.injector.get(PlatformLocation) as LocationImpl;
4444

@@ -51,8 +51,8 @@ export const bootstrapModule = <M>(zone: NgZone, moduleRef: NgModuleRef<M>): Pro
5151
}
5252

5353
applicationInit.donePromise.then(() => {
54-
if (bootstrapFactories.length > 0) {
55-
for (const component of bootstrapFactories) {
54+
if (_bootstrapComponents.length > 0) {
55+
for (const component of _bootstrapComponents) {
5656
applicationRef.bootstrap(component);
5757
}
5858
resolve();

source/platform/platform.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,17 @@ export class ServerPlatform implements PlatformRef {
3434
}
3535

3636
async bootstrapModule<M>(moduleType: Type<M>, compilerOptions: CompilerOptions | Array<CompilerOptions> = [], providers?: Array<Provider>): Promise<NgModuleRef<M>> {
37-
const moduleFactory = await this.compileModule(moduleType, compilerOptions);
37+
const module = await this.compileModule(moduleType, compilerOptions);
3838

39-
return await this.bootstrapModuleFactory(moduleFactory, providers);
39+
return await this.bootstrapModuleFactory(module, providers);
4040
}
4141

42-
async bootstrapModuleFactory<M>(moduleFactory: NgModuleFactory<M>, providers?: Array<Provider>, bootstrap?: (moduleRef: NgModuleRef<M>) => void | Promise<void>): Promise<NgModuleRef<M>> {
42+
async bootstrapModuleFactory<M>(module: NgModuleFactory<M>, providers?: Array<Provider>, bootstrap?: (moduleRef: NgModuleRef<M>) => void | Promise<void>): Promise<NgModuleRef<M>> {
4343
const zone = new NgZone({enableLongStackTrace: true});
4444

4545
const injector = createPlatformInjector(this.injector, zone, providers);
4646

47-
const moduleRef = createInjector(injector, moduleFactory);
47+
const moduleRef = module.create(injector);
4848

4949
const unmap = mapZoneToInjector(Zone.current, moduleRef.injector);
5050

@@ -54,8 +54,6 @@ export class ServerPlatform implements PlatformRef {
5454
this.references.delete(moduleRef);
5555
});
5656

57-
moduleRef.create();
58-
5957
if (typeof bootstrap === 'function') {
6058
await Promise.resolve(bootstrap(moduleRef));
6159
}
@@ -103,11 +101,3 @@ export class ServerPlatform implements PlatformRef {
103101
destroyers.forEach(handler => handler());
104102
}
105103
}
106-
107-
type InstantiableModule<M> = NgModuleRef<M> & {create: () => void};
108-
109-
// It would be great if we did not have to access this private member, but the fact is we need a reference to the
110-
// injector instance before create() is called on it, so that we can apply the zone mapping before any instantiation
111-
// of modules or components happens. Otherwise, if someone attempts to start an HTTP request from inside of a module
112-
// constructor it will fail with nasty messages about how there is no zone mapping.
113-
const createInjector = <M>(injector: Injector, moduleFactory: NgModuleFactory<M>): InstantiableModule<M> => new moduleFactory['_injectorClass'](injector);

source/snapshot/creator/preboot.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,23 @@ export const injectPreboot = <M>(moduleRef: NgModuleRef<M>, vop: RenderVariantOp
2424

2525
const autodetect = noSeparateRoots === true && noSingleRoot === true;
2626
if (autodetect) {
27-
const {bootstrapFactories} = moduleRef as {bootstrapFactories?};
27+
const {_bootstrapComponents} = moduleRef as {_bootstrapComponents?};
2828

29-
if (bootstrapFactories == null || bootstrapFactories.length === 0) {
29+
if (_bootstrapComponents == null || _bootstrapComponents.length === 0) {
3030
throw new ConfigurationException(`Cannot auto-detect preboot root because no components are defined in module 'bootstrap' properties`);
3131
}
3232

3333
const selectors = c => {
34-
if (c.factory == null ||
35-
c.factory.selector == null ||
36-
c.factory.selector.length === 0) {
34+
const component = Reflect.getOwnMetadata('annotations', c).find(c => c.toString() === '@Component');
35+
if (component == null ||
36+
component.selector == null ||
37+
component.selector.length === 0) {
3738
return null;
3839
}
39-
return c.factory.selector.split(/[\s,]/g).filter(v => v);
40+
return component.selector.split(/[\s,]/g).filter(v => v);
4041
};
4142

42-
preboot.appRoot = flatten<string>(bootstrapFactories.map(selectors)).filter(v => v);
43+
preboot.appRoot = flatten<string>(_bootstrapComponents.map(selectors)).filter(v => v);
4344
}
4445

4546
const container = moduleRef.injector.get(DocumentContainer);

0 commit comments

Comments
 (0)