From 31cbec08571f277e78127b65749ae2b4909b7e73 Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Thu, 7 May 2015 22:37:35 -0700 Subject: [PATCH] build(gulp): check node and npm version and log a warning if incompatible Closes #1758 --- gulpfile.js | 33 ++++++++++++++++++++++++++++++++- npm-shrinkwrap.clean.json | 3 +++ npm-shrinkwrap.json | 5 +++++ package.json | 1 + 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/gulpfile.js b/gulpfile.js index 992ca4dede..e197a3a52e 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -3,6 +3,7 @@ var autoprefixer = require('gulp-autoprefixer'); var del = require('del'); var format = require('gulp-clang-format'); +var exec = require('child_process').exec; var fork = require('child_process').fork; var gulp = require('gulp'); var gulpPlugins = require('gulp-load-plugins')(); @@ -13,6 +14,7 @@ var madge = require('madge'); var merge = require('merge'); var merge2 = require('merge2'); var path = require('path'); +var semver = require('semver'); var watch = require('gulp-watch'); var clean = require('./tools/build/clean'); @@ -49,8 +51,37 @@ var angularBuilder = { cleanup: function() {} }; -// Note: when DART_SDK is not found, all gulp tasks ending with `.dart` will be skipped. +(function checkNodeAndNpmVersions() { + var requiredNpmVersion = '>=2.9.0'; + var requiredNodeVersion = '>=0.10.x'; // TODO: bump this to 0.12 once travis runs on 0.12 + exec('npm --version', function(e, stdout) { + var foundNpmVersion = semver.clean(stdout); + var foundNodeVersion = process.version; + var issues = []; + + + if (!semver.satisfies(foundNodeVersion, requiredNodeVersion)) { + issues.push('You are running unsupported node version. Found: ' + foundNodeVersion + + ' Expected: ' + requiredNodeVersion); + } + + if (!semver.satisfies(foundNpmVersion, requiredNpmVersion)) { + issues.push('You are running unsuported npm version. Found: ' + foundNpmVersion + + ' Expected: ' + requiredNpmVersion); + } + + if (issues.length) { + // TODO: in the future we should error, but let's just display the warning for a few days first + console.warn(Array(80).join('!')); + console.warn('Your environment is not in a good shape. Following issues were found:'); + issues.forEach(function(issue) {console.warn(' - ' + issue)}); + console.warn(Array(80).join('!')); + } + }); +}()) + +// Note: when DART_SDK is not found, all gulp tasks ending with `.dart` will be skipped. var DART_SDK = require('./tools/build/dartdetect')(gulp); // ----------------------- diff --git a/npm-shrinkwrap.clean.json b/npm-shrinkwrap.clean.json index 6d8eee3732..9c8249f903 100644 --- a/npm-shrinkwrap.clean.json +++ b/npm-shrinkwrap.clean.json @@ -8382,6 +8382,9 @@ } } }, + "semver": { + "version": "4.3.4" + }, "sorted-object": { "version": "1.0.0" }, diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index c4bbfe7a8a..0a220c20cd 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -12951,6 +12951,11 @@ } } }, + "semver": { + "version": "4.3.4", + "from": "semver@*", + "resolved": "https://registry.npmjs.org/semver/-/semver-4.3.4.tgz" + }, "sorted-object": { "version": "1.0.0", "from": "https://registry.npmjs.org/sorted-object/-/sorted-object-1.0.0.tgz", diff --git a/package.json b/package.json index 46fb56eceb..c9ee614b03 100644 --- a/package.json +++ b/package.json @@ -100,6 +100,7 @@ "q": "^1.0.1", "react": "^0.13.2", "run-sequence": "^0.3.6", + "semver": "^4.3.4", "sorted-object": "^1.0.0", "source-map": "^0.3.0", "sprintf-js": "1.0.*",