Merge pull request #89 from strongloop/fix/version-error-message

Fix "incompatible loopback version" check & msg
This commit is contained in:
Miroslav Bajtoš 2015-01-12 17:55:11 +01:00
commit 146a3183eb
1 changed files with 11 additions and 5 deletions

View File

@ -4,6 +4,7 @@ var semver = require('semver');
var debug = require('debug')('loopback:boot:executor');
var async = require('async');
var path = require('path');
var format = require('util').format;
/**
* Execute bootstrap instructions gathered by `boot.compile`.
@ -73,12 +74,17 @@ function assertLoopBackVersion(app) {
var RANGE = '1.x || 2.x';
var loopback = app.loopback;
if (!semver.satisfies(loopback.version || '1.0.0', RANGE)) {
throw new Error(
'The `app` is powered by an incompatible loopback version %s. ' +
'Supported versions: %s',
loopback.version || '(unknown)',
// remove any pre-release tag from the version string,
// because semver has special treatment of pre-release versions,
// while loopback-boot treats pre-releases the same way as regular versions
var version = (loopback.version || '1.0.0').replace(/-.*$/, '');
if (!semver.satisfies(version, RANGE)) {
var msg = format(
'The `app` is powered by an incompatible loopback version %s. ' +
'Supported versions: %s',
loopback.version || '(unknown)',
RANGE);
throw new Error(msg);
}
}