Comparing version 0.4.0 to 0.5.0
0.5.0 / 2016-10-24 | ||
================== | ||
* feat: app.js/agent.js support async function (#18) | ||
* feat: add EGG_HOME to getHomedir for test (#25) | ||
0.4.0 / 2016-10-24 | ||
@@ -3,0 +9,0 @@ ================== |
@@ -7,2 +7,3 @@ 'use strict'; | ||
const EggConsoleLogger = require('egg-logger').EggConsoleLogger; | ||
const debug = require('debug')('egg-core'); | ||
@@ -169,2 +170,4 @@ const DEPRECATE = Symbol('EggCore#deprecate'); | ||
}); | ||
this.ready(() => debug('egg emit ready, application started')); | ||
} | ||
@@ -171,0 +174,0 @@ |
@@ -5,2 +5,4 @@ 'use strict'; | ||
const LOAD_CUSTOM_FILE = Symbol('EggCore#loadCustomFile'); | ||
module.exports = { | ||
@@ -22,7 +24,23 @@ | ||
* ``` | ||
* | ||
* it's better to use async function | ||
* | ||
* ```js | ||
* module.exports = async function(app) { | ||
* await doAsync(); | ||
* } | ||
* ``` | ||
* | ||
* Or use generator wrapped by co.wrap | ||
* | ||
* ```js | ||
* const co = require('co'); | ||
* module.exports = co.wrap(function*(app) { | ||
* yield doAsync(); | ||
* }); | ||
* ``` | ||
* @since 1.0.0 | ||
*/ | ||
loadCustomApp() { | ||
this.getLoadUnits() | ||
.forEach(unit => this.loadFile(path.join(unit.path, 'app.js'))); | ||
this[LOAD_CUSTOM_FILE]('app.js'); | ||
}, | ||
@@ -34,6 +52,21 @@ | ||
loadCustomAgent() { | ||
this[LOAD_CUSTOM_FILE]('agent.js'); | ||
}, | ||
[LOAD_CUSTOM_FILE](filename) { | ||
this.getLoadUnits() | ||
.forEach(unit => this.loadFile(path.join(unit.path, 'agent.js'))); | ||
.forEach(unit => { | ||
const filepath = path.join(unit.path, filename); | ||
const ret = this.loadFile(filepath); | ||
registerCallback(ret, this.app, filepath); | ||
}); | ||
}, | ||
}; | ||
}; | ||
function registerCallback(ret, app, filepath) { | ||
// register readyCallback if custom file export async function | ||
if (ret instanceof Promise) { | ||
const done = app.readyCallback(filepath); | ||
ret.then(() => done()).catch(done); | ||
} | ||
} |
@@ -29,3 +29,4 @@ 'use strict'; | ||
getHomedir() { | ||
return homedir() || '/home/admin'; | ||
// EGG_HOME for test | ||
return process.env.EGG_HOME || homedir() || '/home/admin'; | ||
}, | ||
@@ -32,0 +33,0 @@ |
{ | ||
"name": "egg-core", | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"description": "A core Pluggable framework based on koa", | ||
@@ -35,2 +35,3 @@ "main": "index.js", | ||
"autod": "^2.7.0", | ||
"co": "^4.6.0", | ||
"egg-bin": "1", | ||
@@ -37,0 +38,0 @@ "egg-ci": "1", |
@@ -6,27 +6,81 @@ 'use strict'; | ||
describe('test/loader/mixin/load_custom_app.test.js', function() { | ||
describe('test/loader/mixin/load_custom_app.test.js', () => { | ||
let app; | ||
before(function() { | ||
app = utils.createApp('plugin'); | ||
app.loader.loadPlugin(); | ||
app.loader.loadConfig(); | ||
app.loader.loadCustomApp(); | ||
describe('app.js as function', () => { | ||
let app; | ||
before(() => { | ||
app = utils.createApp('plugin'); | ||
app.loader.loadPlugin(); | ||
app.loader.loadConfig(); | ||
app.loader.loadCustomApp(); | ||
}); | ||
after(() => app.close()); | ||
it('should load app.js', () => { | ||
app.b.should.equal('plugin b'); | ||
app.c.should.equal('plugin c'); | ||
app.app.should.equal('app'); | ||
}); | ||
it('should app.js of plugin before application\'s', () => { | ||
(app.dateB <= app.date).should.equal(true); | ||
(app.dateC <= app.date).should.equal(true); | ||
}); | ||
it('should not load plugin that is disabled', () => { | ||
should.not.exists(app.a); | ||
}); | ||
}); | ||
after(() => app.close()); | ||
it('should load app.js', function() { | ||
app.b.should.equal('plugin b'); | ||
app.c.should.equal('plugin c'); | ||
app.app.should.equal('app'); | ||
describe('app.js as function return promise', () => { | ||
let app; | ||
before(done => { | ||
app = utils.createApp('custom-app-promise'); | ||
app.loader.loadPlugin(); | ||
app.loader.loadConfig(); | ||
app.loader.loadCustomApp(); | ||
app.ready(done); | ||
}); | ||
after(() => app.close()); | ||
it('should load app.js success', () => { | ||
app.app.should.be.true(); | ||
}); | ||
}); | ||
it('should app.js of plugin before application\'s', function() { | ||
(app.dateB <= app.date).should.equal(true); | ||
(app.dateC <= app.date).should.equal(true); | ||
describe('app.js as async function', () => { | ||
let app; | ||
before(done => { | ||
app = utils.createApp('custom-app-async-function'); | ||
app.loader.loadPlugin(); | ||
app.loader.loadConfig(); | ||
app.loader.loadCustomApp(); | ||
app.ready(done); | ||
}); | ||
after(() => app.close()); | ||
it('should load app.js success', () => { | ||
app.app.should.be.true(); | ||
}); | ||
}); | ||
it('should not load plugin that is disabled', function() { | ||
should.not.exists(app.a); | ||
describe('app.js load async error', () => { | ||
let app; | ||
after(() => app.close()); | ||
it('should load app.js success', done => { | ||
app = utils.createApp('custom-app-error'); | ||
app.on('error', err => { | ||
err.message.should.eql('load async error'); | ||
done(); | ||
}); | ||
app.loader.loadPlugin(); | ||
app.loader.loadConfig(); | ||
app.loader.loadCustomApp(); | ||
app.ready(() => { | ||
throw new Error('should not call'); | ||
}); | ||
}); | ||
}); | ||
}); |
@@ -27,3 +27,8 @@ 'use strict'; | ||
}); | ||
it('should return when EGG_HOME exists', () => { | ||
mm(process.env, 'EGG_HOME', '/path/to/home'); | ||
utils.getHomedir().should.equal('/path/to/home'); | ||
}); | ||
}); | ||
}); |
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
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
150911
321
4726
13
38