Drop peer dep on loopback; add a runtime check

Replace peerDependency with a run-time check based on
`app.loopback.version`.
This commit is contained in:
Miroslav Bajtoš 2014-06-16 15:23:32 +02:00
parent e5e8f29d30
commit c3a9a09941
2 changed files with 22 additions and 5 deletions

View File

@ -1,6 +1,7 @@
var assert = require('assert');
var _ = require('underscore');
var loopback = require('loopback');
var semver = require('semver');
var debug = require('debug')('loopback:boot:executor');
/**
@ -13,6 +14,8 @@ var debug = require('debug')('loopback:boot:executor');
*/
module.exports = function execute(app, instructions) {
assertLoopBackVersion(app);
setHost(app, instructions);
setPort(app, instructions);
setApiRoot(app, instructions);
@ -27,6 +30,22 @@ module.exports = function execute(app, instructions) {
enableAnonymousSwagger(app, instructions);
};
function assertLoopBackVersion(app) {
var RANGE = '1.x || 2.x';
// app.loopback was introduced in 1.9.0
var loopback = app.loopback || {};
var version = loopback.version || '1.0.0';
if (!semver.satisfies(version, RANGE)) {
throw new Error(
'The `app` is powered by an incompatible loopback version %s. ' +
'Supported versions: %s',
loopback.version || '<1.9',
RANGE);
}
}
function setHost(app, instructions) {
//jshint camelcase:false
var host =

View File

@ -23,9 +23,10 @@
"url": "https://github.com/strongloop/loopback-boot/blob/master/LICENSE"
},
"dependencies": {
"underscore": "^1.6.0",
"commondir": "0.0.1",
"debug": "^0.8.1",
"commondir": "0.0.1"
"semver": "^2.3.0",
"underscore": "^1.6.0"
},
"devDependencies": {
"loopback": "^1.5.0",
@ -34,8 +35,5 @@
"supertest": "^0.13.0",
"fs-extra": "^0.9.1",
"browserify": "^4.1.8"
},
"peerDependencies": {
"loopback": "1.x || 2.x"
}
}