Merge pull request #12 from strongloop/feature/drop-peer-dep-on-loopback

Drop peer dep on loopback; add a runtime check
This commit is contained in:
Miroslav Bajtoš 2014-06-16 19:43:24 +02:00
commit a0d5dafd99
2 changed files with 23 additions and 6 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

@ -10,7 +10,7 @@
],
"repository": {
"type": "git",
"url": "https://github.com/loobpack/loopback-boot"
"url": "https://github.com/strongloop/loopback-boot"
},
"main": "index.js",
"browser": "browser.js",
@ -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"
}
}