From c3a9a09941a0158356ef52f1bd3899382776b75b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Mon, 16 Jun 2014 15:23:32 +0200 Subject: [PATCH 1/2] Drop peer dep on loopback; add a runtime check Replace peerDependency with a run-time check based on `app.loopback.version`. --- lib/executor.js | 19 +++++++++++++++++++ package.json | 8 +++----- 2 files changed, 22 insertions(+), 5 deletions(-) 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..2de86be 100644 --- a/package.json +++ b/package.json @@ -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" } } From bad5b60623f32a89edebe80907d072317e045137 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Mon, 16 Jun 2014 15:27:23 +0200 Subject: [PATCH 2/2] package: Fix repository url --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2de86be..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",