diff --git a/lib/executor.js b/lib/executor.js index 538970e..245ae7f 100644 --- a/lib/executor.js +++ b/lib/executor.js @@ -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 = diff --git a/package.json b/package.json index f0b3cf9..6d2dc18 100644 --- a/package.json +++ b/package.json @@ -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" } }