Skip to content

Commit 727a6da

Browse files
committed
Compatibility with Angular 5.0.0, RxJS 5.5.2 and update to Closure Compiler fork
1 parent 953c3f0 commit 727a6da

10 files changed

+129
-71
lines changed

Diff for: build.prod.js

+38-9
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ let canServe = false;
3535
let allowPostCSS = true;
3636
let isRemote = false;
3737
let startElectron = false;
38+
let useExterns = true;
3839

3940
/* Test for arguments the ngr cli spits out */
4041

@@ -63,6 +64,9 @@ process.argv.forEach((arg) => {
6364
if (arg.includes('remote')) {
6465
isRemote = arg.split('=')[1].trim() === 'true' ? true : false;
6566
}
67+
if (arg.includes('externs')) {
68+
useExterns = arg.split('=')[1].trim() === 'true' ? true : false;
69+
}
6670
});
6771

6872

@@ -215,14 +219,23 @@ const compile = {
215219
let out = '';
216220
let finalExec = '';
217221
let hasError = false;
222+
let externalVendorFileCount = 0;
218223

219224
if (isVerbose) log('processing ' + externs.length + ' externs');
220225
if (isVerbose) log('processing ' + vendorFiles.length + ' vendor files');
221226
if (isVerbose) log('processing ' + main.length + ' app files');
222227

228+
// add files to count from closure.lazy.conf, primarily the package.json files from @angular packages
229+
230+
conf.split('\n').forEach(function (item) {
231+
if (item.includes('--js')) {
232+
externalVendorFileCount++;
233+
}
234+
});
235+
223236
out += vendorFiles.join('\n');
224237
out += '\n';
225-
out += '--module=vendor:' + (vendorFiles.length + externs.length) + '\n\n'; //add the number of externs
238+
out += '--module=vendor:' + (vendorFiles.length + externs.length + externalVendorFileCount) + '\n\n'; //add the number of externs
226239

227240
out += main.join('\n');
228241
out += '\n';
@@ -235,6 +248,13 @@ const compile = {
235248

236249
conf = conf.replace('#LIST_OF_FILES#', out);
237250

251+
if (conf.includes('package.json') && parseInt(utils.angularVersion.split('.')[0]) >= 5) {
252+
conf += '--package_json_entry_names es2015' + '\n';
253+
}
254+
if (!conf.includes('--process_common_js_modules')) {
255+
conf += '--process_common_js_modules' + '\n';
256+
}
257+
238258
alert('compiled manifest');
239259
if (isVerbose) log('\n' + conf);
240260

@@ -413,6 +433,8 @@ const compile = {
413433
if (!fileName.includes('node_modules')) {
414434
return fileName;
415435
}
436+
}).map((fileName) => {
437+
return '--js ' + fileName;
416438
});
417439

418440
// loop through bundles and search for vendor files
@@ -449,6 +471,8 @@ const compile = {
449471
return fileName;
450472
}
451473

474+
}).map((fileName) => {
475+
return '--js ' + fileName;
452476
});
453477
// log('BUNDLE', bundle.fileName, bundle.fileContent.length);
454478
// log(bundle.fileContent.join('\n'));
@@ -457,21 +481,26 @@ const compile = {
457481
// remove duplicates that were included from lazyloaded bundles
458482
vendorFiles = vendorFiles.filter(function (item, pos, self) {
459483
return self.indexOf(item) == pos;
484+
}).map((fileName) => {
485+
return '--js ' + fileName;
460486
});
461487

462488
// log('MAIN');
463489
// log(main.join('\n'));
464490
// log('VENDOR');
465491
// log(vendorFiles.join('\n'));
492+
let externs = [];
466493

467-
let externs = fs.readFileSync(path.normalize(config.projectRoot + '/closure.externs.js'), 'utf-8');
468-
let externsLength = 0;
494+
if (useExterns) {
495+
let externs = fs.readFileSync(path.normalize(config.projectRoot + '/closure.externs.js'), 'utf-8');
496+
let externsLength = 0;
469497

470-
externs = externs.split('\n').filter((line) => {
471-
if (line.match(externsRegex)) {
472-
return line;
473-
}
474-
});
498+
externs = externs.split('\n').filter((line) => {
499+
if (line.match(externsRegex)) {
500+
return line;
501+
}
502+
});
503+
}
475504

476505
compile.formatManifest(conf, main, bundles, vendorFiles, externs);
477506

@@ -612,7 +641,7 @@ const compile = {
612641
} else if (startElectron === true) {
613642
alert(colors.green('Ready to serve'));
614643
utils.electron(canWatch);
615-
} else {
644+
} else {
616645
alert(colors.green('Build is ready'));
617646
}
618647
//compile.clean();

Diff for: build.scaffold.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const alert = logger.alert;
1212
const colors = logger.colors;
1313

1414
let lib = false;
15-
let useVersion = '4.4.6';
15+
let useVersion = '5.0.0';
1616
let hasWarning = false;
1717
let dynamicRoutes = false;
1818
let isLazy = false;

Diff for: build.utils.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737

3838

3939
require('shelljs/global');
40-
// LiveReload and Watcher for dev.
4140
const clim = require('clim');
4241
const cons = clim();
4342
const fs = require('fs');
@@ -62,6 +61,7 @@ if(!cliConfigPath) {
6261
}
6362

6463
const scripts = require(projectRoot+'/package.json').scripts;
64+
const angularVersion = require(projectRoot + '/package.json').dependencies['@angular/core'];
6565
let config = require(projectRoot+'/build.config.js');
6666

6767
const moduleIdRegex = /moduleId\s*:(.*)/g;
@@ -138,6 +138,7 @@ const utils = {
138138
stringRegex: stringRegex,
139139
multilineComment: multilineComment,
140140
singleLineComment: singleLineComment,
141+
angularVersion: angularVersion,
141142
serve: (watch) => {
142143

143144
let serverCommand = 'npm run serve';

Diff for: cli.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const prompt = require('prompt');
1111

1212

1313
let cliCommand = '';
14-
let useVersion = '4.4.6';
14+
let useVersion = '5.0.0';
1515

1616
function cmpVersions(a, b) {
1717
var i, diff;
@@ -44,6 +44,7 @@ program
4444
.option('--rollup [bool]', 'Bundle with Rollup prior to optimizing with ClosureCompiler in SIMPLE_OPTIMIZATIONS mode')
4545
.option('--verbose [bool]', 'Log additional messages in build')
4646
.option('--deploy [bool]', 'Option to deploy build available in buildHooks.env.post arguments' )
47+
.option('--externs [bool]', 'Option to use or ignore closure.externs.js when counting vendor files during prod build, default is true')
4748
.option('g, generate [type]', 'Generates new code from templates')
4849
.option('-n, --name [string]', 'The name of the new code to be generated (kebab-case)')
4950
.option('-f, --force [bool]', 'Force overwrite during code generate')
@@ -224,6 +225,12 @@ if (program.build) {
224225
cliCommand += ' remote=false';
225226
}
226227

228+
if (program.externs === false) {
229+
cliCommand += ' externs=false';
230+
}
231+
else {
232+
cliCommand += ' externs=true';
233+
}
227234

228235
spawn(cliCommand, { shell: true, stdio: 'inherit' });
229236

Diff for: closure.conf

+27-22
Original file line numberDiff line numberDiff line change
@@ -9,41 +9,46 @@
99
--rewrite_polyfills=false
1010
--module_resolution=NODE
1111

12-
closure.externs.js
13-
node_modules/zone.js/dist/zone_externs.js
12+
--externs closure.externs.js
13+
--externs node_modules/zone.js/dist/zone_externs.js
14+
--externs node_modules/@angular/core/src/testability/testability.externs.js
1415

1516
--js node_modules/rxjs/**.js
16-
--process_common_js_modules
1717

18-
node_modules/@angular/core/@angular/core.js
19-
--js_module_root=node_modules/@angular/core
20-
node_modules/@angular/core/src/testability/testability.externs.js
18+
--js node_modules/@angular/core/package.json
19+
--js node_modules/@angular/core/esm2015/core.js
2120

22-
node_modules/@angular/common/@angular/common.js
23-
--js_module_root=node_modules/@angular/common
21+
--js node_modules/@angular/common/package.json
22+
--js node_modules/@angular/common/esm2015/common.js
2423

25-
node_modules/@angular/platform-browser/@angular/platform-browser.js
26-
--js_module_root=node_modules/@angular/platform-browser
24+
--js node_modules/@angular/platform-browser/package.json
25+
--js node_modules/@angular/platform-browser/esm2015/platform-browser.js
2726

28-
node_modules/@angular/forms/@angular/forms.js
29-
--js_module_root=node_modules/@angular/forms
27+
--js node_modules/@angular/forms/package.json
28+
--js node_modules/@angular/forms/esm2015/forms.js
3029

31-
node_modules/@angular/http/@angular/http.js
32-
--js_module_root=node_modules/@angular/http
30+
--js node_modules/@angular/http/package.json
31+
--js node_modules/@angular/http/esm2015/http.js
3332

34-
node_modules/@angular/router/@angular/router.js
35-
--js_module_root=node_modules/@angular/router
33+
--js node_modules/@angular/common/http/package.json
34+
--js node_modules/@angular/common/esm2015/http.js
3635

37-
node_modules/@angular/animations/@angular/animations.js
38-
--js_module_root=node_modules/@angular/animations
36+
--js node_modules/@angular/router/package.json
37+
--js node_modules/@angular/router/esm2015/router.js
3938

40-
node_modules/@angular/animations/@angular/animations/browser.js
41-
--js_module_root=node_modules/@angular/animations/browser
39+
--js node_modules/@angular/animations/package.json
40+
--js node_modules/@angular/animations/esm2015/animations.js
4241

43-
node_modules/@angular/platform-browser/@angular/platform-browser/animations.js
44-
--js_module_root=node_modules/@angular/platform-browser/animations
42+
--js node_modules/@angular/animations/browser/package.json
43+
--js node_modules/@angular/animations/esm2015/browser.js
4544

45+
--js node_modules/@angular/platform-browser/animations/package.json
46+
--js node_modules/@angular/platform-browser/esm2015/animations.js
4647

4748
--js ngfactory/**.js
4849
--js main.prod.js
50+
51+
--package_json_entry_names es2015
52+
--process_common_js_modules
53+
4954
--entry_point=./main.prod

Diff for: closure.externs.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

33
var System = function(){};
44
var Hammer = function(){};
5-
var global = function(){};
5+
var global = function(){};
6+
var COMPILED = function(){};

Diff for: closure.lazy.conf

+10-15
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,15 @@
99
--rewrite_polyfills=false
1010
--module_resolution=node
1111

12-
closure.externs.js
13-
node_modules/zone.js/dist/zone_externs.js
14-
node_modules/@angular/core/src/testability/testability.externs.js
15-
16-
--process_common_js_modules
17-
18-
--js_module_root=node_modules/@angular/core
19-
--js_module_root=node_modules/@angular/common
20-
--js_module_root=node_modules/@angular/platform-browser
21-
--js_module_root=node_modules/@angular/forms
22-
--js_module_root=node_modules/@angular/http
23-
--js_module_root=node_modules/@angular/router
24-
--js_module_root=node_modules/@angular/animations
25-
--js_module_root=node_modules/@angular/animations/browser
26-
--js_module_root=node_modules/@angular/platform-browser/animations
12+
--externs closure.externs.js
13+
--externs node_modules/zone.js/dist/zone_externs.js
14+
--externs node_modules/@angular/core/src/testability/testability.externs.js
2715

16+
--js node_modules/@angular/core/package.json
17+
--js node_modules/@angular/common/package.json
18+
--js node_modules/@angular/platform-browser/package.json
19+
--js node_modules/@angular/router/package.json
20+
--js node_modules/@angular/animations/package.json
21+
--js node_modules/@angular/animations/browser/package.json
22+
--js node_modules/@angular/platform-browser/animations/package.json
2823
#LIST_OF_FILES#

Diff for: package.scaffold.json

+15-16
Original file line numberDiff line numberDiff line change
@@ -31,30 +31,29 @@
3131
"postinstall": "npm run webdriver:update"
3232
},
3333
"dependencies": {
34-
"@angular/animations": "4.4.2",
35-
"@angular/common": "4.4.2",
36-
"@angular/core": "4.4.2",
37-
"@angular/forms": "4.4.2",
38-
"@angular/http": "4.4.2",
39-
"@angular/platform-browser": "4.4.2",
40-
"@angular/platform-browser-dynamic": "4.4.2",
41-
"@angular/platform-server": "4.4.2",
42-
"@angular/router": "4.4.2",
43-
"angular-in-memory-web-api": "~0.3.2",
34+
"@angular/animations": "5.0.0",
35+
"@angular/common": "5.0.0",
36+
"@angular/core": "5.0.0",
37+
"@angular/forms": "5.0.0",
38+
"@angular/http": "5.0.0",
39+
"@angular/platform-browser": "5.0.0",
40+
"@angular/platform-browser-dynamic": "5.0.0",
41+
"@angular/platform-server": "5.0.0",
42+
"@angular/router": "5.0.0",
4443
"compression": "^1.7.0",
4544
"core-js": "^2.4.1",
4645
"express": "^4.15.0",
4746
"http": "^0.0.0",
4847
"https": "^1.0.0",
4948
"reflect-metadata": "~0.1.10",
50-
"rxjs": "~5.4.2",
49+
"rxjs": "^5.5.2",
5150
"systemjs": "0.20.14",
5251
"zone.js": "^0.8.12"
5352
},
5453
"devDependencies": {
55-
"@angular/compiler": "4.4.2",
56-
"@angular/compiler-cli": "4.4.2",
57-
"@angular/language-service": "4.4.2",
54+
"@angular/compiler": "5.0.0",
55+
"@angular/compiler-cli": "5.0.0",
56+
"@angular/language-service": "5.0.0",
5857
"@types/jasmine": "2.5.53",
5958
"@types/karma": "1.7.1",
6059
"@types/node": "8.0.2",
@@ -66,7 +65,7 @@
6665
"codelyzer": "^3.1.1",
6766
"css-mqpacker": "^6.0.1",
6867
"cssnano": "^3.10.0",
69-
"google-closure-compiler": "^20170409.0.0",
68+
"google-closure-compiler": "git+https://github.com/gregmagolan/closure-compiler.git#20170919.angular.dist",
7069
"jasmine-core": "^2.6.4",
7170
"jasmine-spec-reporter": "^4.1.1",
7271
"karma": "^1.7.0",
@@ -95,6 +94,6 @@
9594
"rollup-plugin-replace": "^1.1.1",
9695
"ts-helpers": "^1.1.2",
9796
"tslint": "^5.4.3",
98-
"typescript": "^2.4.0"
97+
"typescript": "2.4.2"
9998
}
10099
}

Diff for: src-dynamic-route/app/app.config.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ import { Inject, Injectable, Injector } from '@angular/core';
22
import { Router, Routes, Route } from '@angular/router';
33
import { Http, Response, Headers, RequestOptions } from '@angular/http';
44

5-
import { Observable } from 'rxjs/Rx';
6-
import 'rxjs/add/operator/map';
7-
import 'rxjs/add/operator/catch';
8-
import 'rxjs/add/operator/toPromise';
5+
import { Observable } from 'rxjs/Observable';
6+
import { toPromise } from 'rxjs/operator/toPromise';
97

108
import { HomeComponent } from './shared/components/home/home.component';
119

Diff for: src/public/system.config.js

+24-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,30 @@
2323
'@angular/router': 'lib:@angular/router/bundles/router.umd.js',
2424
'@angular/forms': 'lib:@angular/forms/bundles/forms.umd.js',
2525
// other libraries
26-
'rxjs': 'lib:rxjs'
26+
'rxjs/Observable': 'lib:rxjs/observable',
27+
'rxjs/observable/merge': 'lib:rxjs/observable/merge',
28+
'rxjs/observable/forkJoin': 'lib:rxjs/observable/forkJoin',
29+
'rxjs/observable/fromPromise': 'lib:rxjs/observable/fromPromise',
30+
'rxjs/observable/from': 'lib:rxjs/observable/from',
31+
'rxjs/observable/of': 'lib:rxjs/observable/of',
32+
'rxjs/observable/interval': 'lib:rxjs/observable/interval',
33+
'rxjs/Subject': 'lib:rxjs/Subject',
34+
'rxjs/BehaviorSubject': 'lib:rxjs/BehaviorSubject',
35+
'rxjs/Subscription': 'lib:rxjs/subsription',
36+
'rxjs/operators': 'lib:rxjs/operators/index',
37+
'rxjs/operator/share': 'lib:rxjs/operator/share',
38+
'rxjs/operator/map': 'lib:rxjs/operator/map',
39+
'rxjs/operator/every': 'lib:rxjs/operator/every',
40+
'rxjs/operator/first': 'lib:rxjs/operator/first',
41+
'rxjs/operator/last': 'lib:rxjs/operator/last',
42+
'rxjs/operator/reduce': 'lib:rxjs/operator/reduce',
43+
'rxjs/operator/catch': 'lib:rxjs/operator/catch',
44+
'rxjs/operator/filter': 'lib:rxjs/operator/filter',
45+
'rxjs/operator/mergeMap': 'lib:rxjs/operator/mergeMap',
46+
'rxjs/operator/mergeAll': 'lib:rxjs/operator/mergeAll',
47+
'rxjs/operator/concatMap': 'lib:rxjs/operator/concatMap',
48+
'rxjs/operator/concatAll': 'lib:rxjs/operator/concatAll',
49+
'rxjs/util/EmptyError': 'lib:rxjs/util/EmptyError'
2750
},
2851
// packages tells the System loader how to load when no filename and/or no extension
2952
packages: {

0 commit comments

Comments
 (0)