@@ -6,6 +6,7 @@ const Catbox = require('catbox');
6
6
const Hoek = require ( 'hoek' ) ;
7
7
const Items = require ( 'items' ) ;
8
8
const Podium = require ( 'podium' ) ;
9
+ const Somever = require ( 'somever' ) ;
9
10
const Connection = require ( './connection' ) ;
10
11
const Ext = require ( './ext' ) ;
11
12
const Package = require ( '../package.json' ) ;
@@ -223,6 +224,7 @@ internals.Plugin.prototype.register = function (plugins /*, [options], callback
223
224
pluginOptions : plugin . options ,
224
225
dependencies : attributes . dependencies ,
225
226
connections : attributes . connections ,
227
+ requirements : attributes . requirements ,
226
228
options : {
227
229
once : attributes . once || ( plugin . once !== undefined ? plugin . once : options . once ) ,
228
230
routes : {
@@ -252,6 +254,12 @@ internals.Plugin.prototype.register = function (plugins /*, [options], callback
252
254
attributes : item . register . attributes
253
255
} ;
254
256
257
+ // Validate requirements
258
+
259
+ const requirements = item . requirements ;
260
+ Hoek . assert ( ! requirements . node || Somever . match ( process . version , requirements . node ) , 'Plugin' , item . name , 'requires node version' , requirements . node , 'but found' , process . version ) ;
261
+ Hoek . assert ( ! requirements . hapi || Somever . match ( this . version , requirements . hapi ) , 'Plugin' , item . name , 'requires hapi version' , requirements . hapi , 'but found' , this . version ) ;
262
+
255
263
// Protect against multiple registrations
256
264
257
265
const connectionless = ( item . connections === 'conditional' ? selection . connections . length === 0 : ! item . connections ) ;
@@ -408,11 +416,24 @@ internals.Plugin.prototype.dependency = function (dependencies, after) {
408
416
Hoek . assert ( this . realm . plugin , 'Cannot call dependency() outside of a plugin' ) ;
409
417
Hoek . assert ( ! after || typeof after === 'function' , 'Invalid after method' ) ;
410
418
411
- dependencies = [ ] . concat ( dependencies ) ;
419
+ // Normalize to { plugin: version }
420
+
421
+ if ( typeof dependencies === 'string' ) {
422
+ dependencies = { [ dependencies ] : '*' } ;
423
+ }
424
+ else if ( Array . isArray ( dependencies ) ) {
425
+ const map = { } ;
426
+ for ( const dependency of dependencies ) {
427
+ map [ dependency ] = '*' ;
428
+ }
429
+
430
+ dependencies = map ;
431
+ }
432
+
412
433
this . root . _dependencies . push ( { plugin : this . realm . plugin , connections : this . connections , deps : dependencies } ) ;
413
434
414
435
if ( after ) {
415
- this . ext ( 'onPreStart' , after , { after : dependencies } ) ;
436
+ this . ext ( 'onPreStart' , after , { after : Object . keys ( dependencies ) } ) ;
416
437
}
417
438
} ;
418
439
0 commit comments