X Tutup
Skip to content

Commit 7f78328

Browse files
IgorMinarjelbourn
authored andcommitted
build: improve the environmental check and warnings
- we now correctly print errors even on old Node versions - we print error messages even when node_modules are missing or messed up - error messages looks better Closes angular#5230
1 parent 1417e12 commit 7f78328

File tree

2 files changed

+55
-10
lines changed

2 files changed

+55
-10
lines changed

gulpfile.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
'use strict';
22

3+
// THIS CHECK SHOULD BE THE FIRST THING IN THIS FILE
4+
// This is to ensure that we catch env issues before we error while requiring other dependencies.
5+
require('./tools/check-environment')(
6+
{requiredNpmVersion: '>=2.14.7 <3.0.0', requiredNodeVersion: '>=4.2.1 <5.0.0'});
7+
8+
39
var del = require('del');
410
var gulp = require('gulp');
511
var gulpPlugins = require('gulp-load-plugins')();
@@ -26,8 +32,6 @@ var dartSdk = require('./tools/build/dart');
2632
var browserProvidersConf = require('./browser-providers.conf.js');
2733

2834

29-
require('./tools/check-environment')(
30-
{requiredNpmVersion: '>=2.14.7', requiredNodeVersion: '>=4.2.1'});
3135

3236
var cliArgs = minimist(process.argv.slice(2));
3337

tools/check-environment.js

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,42 @@
1+
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2+
!!! !!!
3+
!!! This file is special in that it must be able to execute with wrong Node version !!!
4+
!!! or even when node_modules are missing. !!!
5+
!!! !!!
6+
!!! Do not depend on Node4+ features or presence of npm packages here. !!!
7+
!!! !!!
8+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
9+
10+
'use strict';
11+
112
var exec = require('child_process').exec;
2-
var semver = require('semver');
13+
var checkNodeModules;
14+
var semver;
315

4-
var checkNodeModules = require('./npm/check-node-modules.js');
16+
17+
var issues = [];
18+
19+
// coarse Node version check
20+
if (process.version[1] !== '4') {
21+
issues.push("Angular 2 build currently requires Node 4. Use nvm to update your node version.");
22+
}
23+
24+
try {
25+
semver = require('semver');
26+
} catch(e) {
27+
issues.push("Looks like you are missing some npm dependencies. Run: npm install");
28+
}
29+
30+
// wrap in try/catch in case someone requires from within that file
31+
try {
32+
checkNodeModules = require('./npm/check-node-modules.js');
33+
} catch(e) {
34+
issues.push("Looks like you are missing some npm dependencies. Run: npm install");
35+
throw e;
36+
} finally {
37+
// print warnings and move on, the next steps will likely fail, but hey, we warned them.
38+
printWarning(issues);
39+
}
540

641

742
function checkEnvironment(reqs) {
@@ -26,14 +61,20 @@ function checkEnvironment(reqs) {
2661
issues.push('Your node_modules directory is stale or out of sync with npm-shrinkwrap.json. Run: npm install');
2762
}
2863

29-
if (issues.length) {
30-
console.warn(Array(80).join('!'));
31-
console.warn('Your environment is not in a good shape. Following issues were found:');
32-
issues.forEach(function(issue) {console.warn(' - ' + issue)});
33-
console.warn(Array(80).join('!'));
34-
}
64+
printWarning(issues);
3565
});
3666
}
3767

68+
function printWarning(issues) {
69+
if (!issues.length) return;
70+
71+
console.warn('');
72+
console.warn(Array(110).join('!'));
73+
console.warn('!!! Your environment is not in a good shape. Following issues were found:');
74+
issues.forEach(function(issue) {console.warn('!!! - ' + issue)});
75+
console.warn(Array(110).join('!'));
76+
console.warn('');
77+
}
78+
3879

3980
module.exports = checkEnvironment;

0 commit comments

Comments
 (0)
X Tutup