Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/loader/mixin/extend.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ module.exports = {
loadExtend(name, proto) {
// 获取需要加载的文件
const filepaths = this.getLoadUnits().map(unit => path.join(unit.path, 'app/extend', name));
for (let i = 0, l = filepaths.length; i < l; i++) {
const filepath = filepaths[i];
filepaths.push(filepath + `.${this.serverEnv}`);
}


const mergeRecord = new Map();
for (const filepath of filepaths) {
if (!utils.existsModule(filepath)) {
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/extend-env/app/extend/application.custom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

exports.a = 'a1';

exports.custom = true;
4 changes: 4 additions & 0 deletions test/fixtures/extend-env/app/extend/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
'use strict';

exports.a = 'a';
exports.b = 'b';
8 changes: 8 additions & 0 deletions test/fixtures/extend-env/config/plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

const path = require('path');

exports.a = {
enable: true,
path: path.join(__dirname, '../plugins/a'),
};
3 changes: 3 additions & 0 deletions test/fixtures/extend-env/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "extend-env"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

exports.b = 'b1';
5 changes: 5 additions & 0 deletions test/fixtures/extend-env/plugins/a/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"eggPlugin": {
"name": "a"
}
}
14 changes: 14 additions & 0 deletions test/loader/mixin/load_extend.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require('should');
const request = require('supertest');
const mm = require('mm');
const utils = require('../../utils');

describe('test/loader/mixin/load_extend.test.js', function() {
Expand Down Expand Up @@ -95,4 +96,17 @@ describe('test/loader/mixin/load_extend.test.js', function() {
app.loader.loadApplicationExtend();
app[utils.symbol.view].should.equal('view');
});

it('should load application by custom env', function() {
mm(process.env, 'EGG_SERVER_ENV', 'custom');
const app = utils.createApp('extend-env');
app.loader.loadPlugin();
app.loader.loadApplicationExtend();
app.custom.should.be.true();
// application.custom.js override application.js
app.a.should.eql('a1');
// application.custom.js in plugin also can override application.js in app
app.b.should.eql('b1');
});

});