Comparing version 4.10.0 to 4.10.1
4.10.1 / 2018-09-21 | ||
================== | ||
**fixes** | ||
* [[`33c07db`](http://github.com/eggjs/egg-core/commit/33c07db023ebc1a120d5ce1fa37da9e42b18e8f1)] - fix: ensure treat function app.js as configDidLoad (#181) (Yiyu He <<dead_horse@qq.com>>) | ||
4.10.0 / 2018-09-06 | ||
@@ -3,0 +9,0 @@ ================== |
@@ -83,2 +83,15 @@ 'use strict'; | ||
addFunctionAsBootHook(hook) { | ||
// app.js is export as a funciton | ||
// call this function in configDidLoad | ||
this[BOOT_HOOKS].push(class Hook { | ||
constructor(app) { | ||
this.app = app; | ||
} | ||
configDidLoad() { | ||
hook(this.app); | ||
} | ||
}); | ||
} | ||
/** | ||
@@ -85,0 +98,0 @@ * init boots and trigger config did config |
@@ -98,6 +98,2 @@ 'use strict'; | ||
get bootFileName() { | ||
return this.app.type === 'application' ? 'app' : 'agent'; | ||
} | ||
/** | ||
@@ -472,3 +468,2 @@ * Get {@link AppInfo#env} | ||
require('./mixin/router'), | ||
require('./mixin/boot'), | ||
]; | ||
@@ -475,0 +470,0 @@ |
'use strict'; | ||
const is = require('is-type-of'); | ||
const path = require('path'); | ||
const LOAD_BOOT_HOOK = Symbol('Loader#loadBootHook'); | ||
module.exports = { | ||
@@ -11,20 +14,26 @@ | ||
* @example | ||
* - old: | ||
* | ||
* ```js | ||
* module.exports = function(app) { | ||
* // can do everything | ||
* do(); | ||
* doSomething(); | ||
* } | ||
* ``` | ||
* | ||
* // if you will invoke asynchronous, you can use readyCallback | ||
* const done = app.readyCallback(); | ||
* doAsync(done); | ||
* - new: | ||
* | ||
* ```js | ||
* module.exports = class Boot { | ||
* constructor(app) { | ||
* this.app = app; | ||
* } | ||
* configDidLoad() { | ||
* doSomething(); | ||
* } | ||
* } | ||
* ``` | ||
* @since 1.0.0 | ||
*/ | ||
loadCustomApp() { | ||
this.timing.start('Load app.js'); | ||
this[LOAD_BOOT_HOOK]('app'); | ||
this.lifecycle.triggerConfigDidLoad(); | ||
this.getLoadUnits() | ||
.forEach(unit => this.loadFile(this.resolveModule(path.join(unit.path, 'app')))); | ||
this.timing.end('Load app.js'); | ||
}, | ||
@@ -36,8 +45,31 @@ | ||
loadCustomAgent() { | ||
this.timing.start('Load agent.js'); | ||
this[LOAD_BOOT_HOOK]('agent'); | ||
this.lifecycle.triggerConfigDidLoad(); | ||
this.getLoadUnits() | ||
.forEach(unit => this.loadFile(this.resolveModule(path.join(unit.path, 'agent')))); | ||
this.timing.end('Load agent.js'); | ||
}, | ||
// FIXME: no logger used after egg removed | ||
loadBootHook() { | ||
// do nothing | ||
}, | ||
[LOAD_BOOT_HOOK](fileName) { | ||
this.timing.start(`Load ${fileName}.js`); | ||
for (const unit of this.getLoadUnits()) { | ||
const bootFilePath = this.resolveModule(path.join(unit.path, fileName)); | ||
if (!bootFilePath) { | ||
continue; | ||
} | ||
const bootHook = this.requireFile(bootFilePath); | ||
if (is.class(bootHook)) { | ||
// if is boot class, add to lifecycle | ||
this.lifecycle.addBootHook(bootHook); | ||
} else { | ||
// if is boot function, wrap to class | ||
this.lifecycle.addFunctionAsBootHook(bootHook); | ||
} | ||
} | ||
// init boots | ||
this.lifecycle.init(); | ||
this.timing.end(`Load ${fileName}.js`); | ||
}, | ||
}; |
{ | ||
"name": "egg-core", | ||
"version": "4.10.0", | ||
"version": "4.10.1", | ||
"description": "A core Pluggable framework based on koa", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -123,7 +123,7 @@ # egg-core | ||
Load app.js | ||
Load app.js, if app.js export boot class, then trigger configDidLoad | ||
#### loadCustomAgent | ||
Load agent.js | ||
Load agent.js, if agent.js export boot class, then trigger configDidLoad | ||
@@ -130,0 +130,0 @@ #### loadService |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
110735
2702
24