1- import events from "events" ;
1+ // import events from "events";
2+ const events = require ( "events" ) ;
23const EventEmitter = events . EventEmitter ;
34
45function objHas ( obj , name ) { return Object . prototype . hasOwnProperty . call ( obj , name ) ; }
@@ -119,6 +120,10 @@ class Rectify extends EventEmitter {
119120 var services = app . services = {
120121 app : {
121122 EventEmitter : EventEmitter ,
123+ isNode : ( typeof process != "undefined" && ! process . __nwjs ? 1 : 0 ) ,
124+ isFork : ( typeof process != "undefined" && process . send ? 1 : 0 ) ,
125+ isNWJS : ( typeof process != "undefined" && process . __nwjs ? 1 : 0 ) ,
126+ isWorker : ( typeof WorkerGlobalScope != "undefined" && globalThis instanceof WorkerGlobalScope ) ? 1 : 0 ,
122127 window : typeof window == "undefined" ? global : window ,
123128 on : function ( name , callback ) {
124129 if ( typeof ( callback ) == "function" ) callback = callback . bind ( app ) ;
@@ -135,7 +140,7 @@ class Rectify extends EventEmitter {
135140
136141 var destructors = [ ] ;
137142
138- app . start = function ( callback ) {
143+ app . start = async function ( callback ) {
139144 if ( callback ) app . on ( "ready" , callback ) ;
140145 var plugin = sortedPlugins . shift ( ) ;
141146 if ( ! plugin )
@@ -148,13 +153,25 @@ class Rectify extends EventEmitter {
148153 } ) ;
149154 }
150155
156+ var $config = { } ;
157+ plugin . provides . forEach ( function ( name ) {
158+ if ( plugin . config && plugin . config [ name ] ) {
159+ $config [ name ] = plugin . config [ name ] ;
160+ } else $config [ name ] = { } ;
161+ var $c = config . config && config . config [ name ] ? config . config [ name ] : { } ;
162+ for ( var i in $c ) {
163+ $config [ name ] [ i ] = $c [ i ] ;
164+ }
165+ } ) ;
166+
151167 try {
152- plugin . setup ( imports , register ) ;
168+ await plugin . setup ( imports , register , $config ) ;
169+ return app ;
153170 } catch ( e ) {
154171 return app . emit ( "error" , e ) ;
155172 }
156173
157- function register ( err , provided ) {
174+ async function register ( err , provided ) {
158175 if ( err ) { return app . emit ( "error" , err ) ; }
159176 plugin . provides . forEach ( function ( name ) {
160177 if ( ! objHas ( provided , name ) ) {
@@ -172,7 +189,7 @@ class Rectify extends EventEmitter {
172189 destructors . push ( provided . onDestroy ) ;
173190
174191 app . emit ( "plugin" , plugin ) ;
175- app . start ( ) ;
192+ await app . start ( ) ;
176193 }
177194 } ;
178195
@@ -209,4 +226,4 @@ Rectify.build = function (config, callback) {
209226 }
210227} ;
211228
212- export default Rectify ;
229+ module . exports = Rectify ;
0 commit comments