Ensure installed correct version of modules on startup, bump dependencies (#6207)

* Ensure installed correct version of modules

* Bump dependencies

* Bump promise-polyfill

* Fix emailer test

* Fix auto-install regression

introduced in 9b5e0f9e95
This commit is contained in:
Peter Jaszkowiak
2018-01-06 12:06:42 -07:00
committed by Julian Lam
parent 9922720dd3
commit 4387d5d466
6 changed files with 42 additions and 29 deletions

View File

@@ -6,9 +6,11 @@ var path = require('path');
var packageInstall = require('./package-install');
var dirname = require('./paths').baseDir;
var defaultPackage;
// check to make sure dependencies are installed
try {
fs.readFileSync(path.join(dirname, 'package.json'));
defaultPackage = JSON.parse(fs.readFileSync(path.join(dirname, 'install/package.json'), 'utf8'));
} catch (e) {
if (e.code === 'ENOENT') {
console.warn('package.json not found.');
@@ -29,13 +31,24 @@ try {
}
try {
fs.readFileSync(path.join(dirname, 'node_modules/async/package.json'), 'utf8');
fs.readFileSync(path.join(dirname, 'node_modules/commander/package.json'), 'utf8');
fs.readFileSync(path.join(dirname, 'node_modules/colors/package.json'), 'utf8');
fs.readFileSync(path.join(dirname, 'node_modules/nconf/package.json'), 'utf8');
var semver = require('semver');
var checkVersion = function (packageName) {
var version = JSON.parse(fs.readFileSync(path.join(dirname, 'node_modules', packageName, 'package.json'), 'utf8')).version;
if (!semver.satisfies(version, defaultPackage.dependencies[packageName])) {
var e = new TypeError('Incorrect dependency version: ' + packageName);
e.code = 'DEP_WRONG_VERSION';
throw e;
}
};
checkVersion('nconf');
checkVersion('async');
checkVersion('commander');
checkVersion('colors');
} catch (e) {
if (e.code === 'ENOENT') {
console.warn('Dependencies not yet installed.');
if (['ENOENT', 'DEP_WRONG_VERSION', 'MODULE_NOT_FOUND'].indexOf(e.code) !== -1) {
console.warn('Dependencies outdated or not yet installed.');
console.log('Installing them now...\n');
packageInstall.installAll();