From 7f783289abdb580022e2b73247c4d43e8e553ba4 Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Sat, 14 Nov 2015 08:10:31 -0800 Subject: [PATCH] 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 #5230 --- gulpfile.js | 8 ++++-- tools/check-environment.js | 59 ++++++++++++++++++++++++++++++++------ 2 files changed, 56 insertions(+), 11 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index b745570e31..cda5ac647e 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,5 +1,11 @@ 'use strict'; +// THIS CHECK SHOULD BE THE FIRST THING IN THIS FILE +// This is to ensure that we catch env issues before we error while requiring other dependencies. +require('./tools/check-environment')( + {requiredNpmVersion: '>=2.14.7 <3.0.0', requiredNodeVersion: '>=4.2.1 <5.0.0'}); + + var del = require('del'); var gulp = require('gulp'); var gulpPlugins = require('gulp-load-plugins')(); @@ -26,8 +32,6 @@ var dartSdk = require('./tools/build/dart'); var browserProvidersConf = require('./browser-providers.conf.js'); -require('./tools/check-environment')( - {requiredNpmVersion: '>=2.14.7', requiredNodeVersion: '>=4.2.1'}); var cliArgs = minimist(process.argv.slice(2)); diff --git a/tools/check-environment.js b/tools/check-environment.js index 16c473370d..b10be47f4c 100644 --- a/tools/check-environment.js +++ b/tools/check-environment.js @@ -1,7 +1,42 @@ -var exec = require('child_process').exec; -var semver = require('semver'); +/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !!! !!! + !!! This file is special in that it must be able to execute with wrong Node version !!! + !!! or even when node_modules are missing. !!! + !!! !!! + !!! Do not depend on Node4+ features or presence of npm packages here. !!! + !!! !!! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ -var checkNodeModules = require('./npm/check-node-modules.js'); +'use strict'; + +var exec = require('child_process').exec; +var checkNodeModules; +var semver; + + +var issues = []; + +// coarse Node version check +if (process.version[1] !== '4') { + issues.push("Angular 2 build currently requires Node 4. Use nvm to update your node version."); +} + +try { + semver = require('semver'); +} catch(e) { + issues.push("Looks like you are missing some npm dependencies. Run: npm install"); +} + +// wrap in try/catch in case someone requires from within that file +try { + checkNodeModules = require('./npm/check-node-modules.js'); +} catch(e) { + issues.push("Looks like you are missing some npm dependencies. Run: npm install"); + throw e; +} finally { + // print warnings and move on, the next steps will likely fail, but hey, we warned them. + printWarning(issues); +} function checkEnvironment(reqs) { @@ -26,14 +61,20 @@ function checkEnvironment(reqs) { issues.push('Your node_modules directory is stale or out of sync with npm-shrinkwrap.json. Run: npm install'); } - if (issues.length) { - 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('!')); - } + printWarning(issues); }); } +function printWarning(issues) { + if (!issues.length) return; + + console.warn(''); + console.warn(Array(110).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(110).join('!')); + console.warn(''); +} + module.exports = checkEnvironment;