Skip to content

Commit 5507046

Browse files
committed
do not change templateUrls and styleUrls, add moduleId instead
1 parent a00ac50 commit 5507046

File tree

9 files changed

+80
-102
lines changed

9 files changed

+80
-102
lines changed

atmosphere-packages/angular-compilers/plugin/register.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ if(process.env.BLAZE){
2020

2121
let aot = ((process.env.NODE_ENV == 'production') && (process.env.AOT != '0')) || process.env.AOT == '1';
2222
let rollup = (process.env.ROLLUP == '1');
23-
23+
let compiler, compilerCli;
2424
try{
2525
if(aot){
26-
require('@angular/compiler');
27-
require('@angular/compiler-cli');
26+
compiler = require('@angular/compiler');
27+
compilerCli = require('@angular/compiler-cli');
2828
}
2929
}catch(e){
3030
console.log('@angular/compiler and @angular/compiler-cli must be installed for AOT compilation!');
@@ -40,7 +40,9 @@ Plugin.registerCompiler({
4040
filenames: ['tsconfig.json']
4141
}, () => new AngularTsCompiler({
4242
aot,
43-
rollup
43+
rollup,
44+
compiler,
45+
compilerCli
4446
}));
4547
Plugin.registerCompiler({
4648
extensions: [templateExtension]

atmosphere-packages/angular-typescript-compiler/index.js

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ const ngcOptions = {
6666
};
6767

6868
export class AngularTsCompiler {
69-
constructor({aot, rollup}){
69+
constructor({aot, rollup, compiler, compilerCli}){
7070
this.isAot = aot;
7171
this.isRollup = rollup;
7272
if(this.isAot){
73-
this.compiler = require('@angular/compiler');
74-
this.compilerCli = require ('@angular/compiler-cli');
73+
this.compiler = compiler;
74+
this.compilerCli = compilerCli;
7575
}
7676

7777
}
@@ -92,7 +92,6 @@ export class AngularTsCompiler {
9292

9393
if (fakeLoaderCode){
9494
newSource = fakeLoaderCode + '\n' + newSource;
95-
console.log(newSource);
9695
}
9796

9897
return newSource;
@@ -103,15 +102,20 @@ export class AngularTsCompiler {
103102

104103
return code.replace(LOAD_CHILDREN_REGEX,
105104
(match, url) => {
106-
url = url.split('\'').join('').split('"').join('').split(',').join('');
105+
const curlyBracesAtTheEnd = url.includes('}');
106+
url = url.split('\'').join('').split('"').join('').split(',').join('').split('}').join('');
107107
const urlArr = url.split('#');
108108
let modulePath = urlArr[0].trim();
109109
let moduleName = urlArr[1].trim();
110110
if(this.isAot){
111111
modulePath += '.ngfactory';
112112
moduleName += 'NgFactory';
113113
}
114-
return `loadChildren: () => module.dynamicImport('${modulePath}').then(allModule => allModule['${moduleName}']),`;
114+
let finalReplacement = `loadChildren: () => module.dynamicImport('${modulePath}').then(allModule => allModule['${moduleName}']),`;
115+
if(curlyBracesAtTheEnd){
116+
finalReplacement += '}'
117+
}
118+
return finalReplacement;
115119
});
116120

117121
}
@@ -121,13 +125,8 @@ export class AngularTsCompiler {
121125
(match, quote, url) => `'${(firstSlash ? '/' : '~/../') + path.join(basePath, url)}'`)
122126
.replace(/\\/g, '/');
123127
}
124-
fixResourceUrls(source, basePath) {
125-
const newSource = source
126-
.replace(TEMPLATE_URL_REGEX,
127-
(match, url) => `templateUrl:${this.replaceStringsWithFullUrls(basePath, url, false)}`)
128-
.replace(STYLES_URLS_REGEX,
129-
(match, urls) => `styleUrls:${this.replaceStringsWithFullUrls(basePath, urls, false)}`);
130-
return newSource;
128+
addModuleIdForComponent(code){
129+
return code.replace('Component({', 'Component({ moduleId: module.id,');
131130
}
132131
processFilesForTarget(inputFiles) {
133132
const filesMap = new Map();
@@ -253,7 +252,7 @@ export class AngularTsCompiler {
253252
}
254253
const basePath = inputFile.getPathInPackage().replace(inputFile.getBasename(), '');
255254
if (!this.isAot) {
256-
code = this.fixResourceUrls(code, basePath)
255+
code = this.addModuleIdForComponent(code, basePath)
257256
}
258257
code = code.split('require("node_modules/').join('require("');
259258
if(this.isRollup){

examples/MeteorCLI/all-in-one/.meteor/versions

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
2-
angular-compilers@0.2.9_3
3-
angular-html-compiler@0.2.9
4-
angular-scss-compiler@0.2.9_1
5-
angular-typescript-compiler@0.2.9_6
2+
angular-compilers@0.3.1_2
3+
angular-html-compiler@0.3.1_2
4+
angular-scss-compiler@0.3.1_2
5+
angular-typescript-compiler@0.3.1_2
66
77
88
@@ -32,8 +32,6 @@ [email protected]
3232
3333
3434
35-
36-
3735
3836
3937
@@ -54,9 +52,6 @@ [email protected]
5452
5553
5654
57-
58-
59-
6055
6156
6257
Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,7 @@
1-
import { Component, OnInit, OnDestroy } from '@angular/core';
2-
import { Router, NavigationEnd, ActivatedRoute } from '@angular/router';
3-
import { Title } from '@angular/platform-browser';
4-
5-
import { Subscription } from 'rxjs/Subscription';
1+
import { Component } from '@angular/core';
62

73
@Component({
84
selector: 'app',
95
templateUrl: 'app.html'
106
})
11-
export class AppComponent implements OnInit, OnDestroy {
12-
//Dynamic title change along with router
13-
private titleChangeSubscription: Subscription;
14-
constructor(
15-
private router: Router,
16-
private activatedRoute: ActivatedRoute,
17-
private titleService: Title
18-
) { }
19-
ngOnInit() {
20-
this.titleChangeSubscription =
21-
this.router.events
22-
.filter((event) => event instanceof NavigationEnd)
23-
.map(() => this.activatedRoute)
24-
.map((route) => {
25-
while (route.firstChild) route = route.firstChild;
26-
return route;
27-
})
28-
.filter((route) => route.outlet === 'primary')
29-
.mergeMap((route) => route.data)
30-
.subscribe((event) => this.titleService.setTitle(event['title']));
31-
}
32-
ngOnDestroy() {
33-
this.titleChangeSubscription.unsubscribe();
34-
}
35-
}
7+
export class AppComponent {}

examples/MeteorCLI/all-in-one/imports/app/app.module.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,11 @@ import { PageNotFoundComponent } from './page-not-found/page-not-found.component
2020
RouterModule.forRoot([
2121
{
2222
path: 'todoList',
23-
component: TodoListComponent,
24-
data: {
25-
title: 'Todo List'
26-
}
23+
component: TodoListComponent
2724
},
2825
{
2926
path: 'todoAdd',
30-
loadChildren: './todo-add/todo-add.module#TodoAddModule',
31-
data: {
32-
title: 'Add Todo'
33-
}
27+
loadChildren: './todo-add/todo-add.module#TodoAddModule'
3428
},
3529
// Home Page
3630
{
@@ -41,10 +35,7 @@ import { PageNotFoundComponent } from './page-not-found/page-not-found.component
4135
// 404 Page
4236
{
4337
path: '**',
44-
component: PageNotFoundComponent,
45-
data: {
46-
title: '404 Page Not Found'
47-
}
38+
component: PageNotFoundComponent
4839
}
4940
])
5041
],

examples/MeteorCLI/all-in-one/imports/app/todo-list/todo-list.component.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ export class TodoListComponent implements OnInit, OnDestroy {
2020
this.todos = Todos.find();
2121
// Subscribe and connect it to Angular's change detection system
2222
// while running on client
23-
if (Meteor.isClient)
23+
if (Meteor.isClient){
2424
this.todoListSubscription = MeteorObservable.subscribe('todoList').subscribe();
25+
}
2526
}
2627
ngOnDestroy() {
27-
if (this.todoListSubscription)
28+
if (this.todoListSubscription){
2829
this.todoListSubscription.unsubscribe();
30+
}
2931
}
3032
removeTodo(_id: string) {
3133
Meteor.call('removeTodo', _id);

examples/MeteorCLI/all-in-one/package-lock.json

Lines changed: 20 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/MeteorCLI/all-in-one/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
"@angular/platform-server": "^5.2.9",
1818
"@angular/router": "^5.2.9",
1919
"@babel/runtime": "^7.0.0-beta.42",
20-
"core-js": "^2.5.3",
20+
"core-js": "^2.5.4",
2121
"meteor-node-stubs": "~0.3.3",
2222
"meteor-rxjs": "^0.4.10",
23-
"rxjs": "^5.5.7",
24-
"zone.js": "^0.8.20"
23+
"rxjs": "^5.5.8",
24+
"zone.js": "^0.8.21"
2525
},
2626
"devDependencies": {
2727
"@angular/compiler-cli": "^5.2.9",
@@ -31,7 +31,7 @@
3131
"@types/sinon": "^4.1.0",
3232
"chai": "^4.1.2",
3333
"phantomjs-prebuilt": "^2.1.16",
34-
"sinon": "^4.1.3",
35-
"typescript": "^2.7.2"
34+
"sinon": "^4.5.0",
35+
"typescript": "^2.8.1"
3636
}
3737
}

0 commit comments

Comments
 (0)