Skip to content

Commit 31cbec0

Browse files
IgorMinarmhevery
authored andcommitted
build(gulp): check node and npm version and log a warning if incompatible
Closes angular#1758
1 parent d717529 commit 31cbec0

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

gulpfile.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
var autoprefixer = require('gulp-autoprefixer');
44
var del = require('del');
55
var format = require('gulp-clang-format');
6+
var exec = require('child_process').exec;
67
var fork = require('child_process').fork;
78
var gulp = require('gulp');
89
var gulpPlugins = require('gulp-load-plugins')();
@@ -13,6 +14,7 @@ var madge = require('madge');
1314
var merge = require('merge');
1415
var merge2 = require('merge2');
1516
var path = require('path');
17+
var semver = require('semver');
1618
var watch = require('gulp-watch');
1719

1820
var clean = require('./tools/build/clean');
@@ -49,8 +51,37 @@ var angularBuilder = {
4951
cleanup: function() {}
5052
};
5153

52-
// Note: when DART_SDK is not found, all gulp tasks ending with `.dart` will be skipped.
54+
(function checkNodeAndNpmVersions() {
55+
var requiredNpmVersion = '>=2.9.0';
56+
var requiredNodeVersion = '>=0.10.x'; // TODO: bump this to 0.12 once travis runs on 0.12
57+
58+
exec('npm --version', function(e, stdout) {
59+
var foundNpmVersion = semver.clean(stdout);
60+
var foundNodeVersion = process.version;
61+
var issues = [];
62+
5363

64+
if (!semver.satisfies(foundNodeVersion, requiredNodeVersion)) {
65+
issues.push('You are running unsupported node version. Found: ' + foundNodeVersion +
66+
' Expected: ' + requiredNodeVersion);
67+
}
68+
69+
if (!semver.satisfies(foundNpmVersion, requiredNpmVersion)) {
70+
issues.push('You are running unsuported npm version. Found: ' + foundNpmVersion +
71+
' Expected: ' + requiredNpmVersion);
72+
}
73+
74+
if (issues.length) {
75+
// TODO: in the future we should error, but let's just display the warning for a few days first
76+
console.warn(Array(80).join('!'));
77+
console.warn('Your environment is not in a good shape. Following issues were found:');
78+
issues.forEach(function(issue) {console.warn(' - ' + issue)});
79+
console.warn(Array(80).join('!'));
80+
}
81+
});
82+
}())
83+
84+
// Note: when DART_SDK is not found, all gulp tasks ending with `.dart` will be skipped.
5485
var DART_SDK = require('./tools/build/dartdetect')(gulp);
5586

5687
// -----------------------

npm-shrinkwrap.clean.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8382,6 +8382,9 @@
83828382
}
83838383
}
83848384
},
8385+
"semver": {
8386+
"version": "4.3.4"
8387+
},
83858388
"sorted-object": {
83868389
"version": "1.0.0"
83878390
},

npm-shrinkwrap.json

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

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
"q": "^1.0.1",
101101
"react": "^0.13.2",
102102
"run-sequence": "^0.3.6",
103+
"semver": "^4.3.4",
103104
"sorted-object": "^1.0.0",
104105
"source-map": "^0.3.0",
105106
"sprintf-js": "1.0.*",

0 commit comments

Comments
 (0)