Skip to content

Commit

Permalink
fix: only filter the plugin which is disabled by app (#145) (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
popomore committed Dec 19, 2017
1 parent 25b728c commit 4f1c19a
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 27 deletions.
2 changes: 1 addition & 1 deletion lib/loader/mixin/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ module.exports = {

// should warn when the plugin is disabled by app
message = implicitEnabledPlugins
.filter(name => !appPlugins[name].enable)
.filter(name => appPlugins[name] && appPlugins[name].enable === false)
.map(name => ` - ${name} required by [${requireMap[name]}]`)
.join('\n');
this.options.logger.warn(`Following plugins will be enabled implicitly that is disabled by application.\n${message}`);
Expand Down
24 changes: 2 additions & 22 deletions test/fixtures/plugin-dep-disable/config/plugin.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,3 @@
const path = require('path');
'use strict';

module.exports = {
a: {
enable: true,
path: path.join(__dirname, '../plugins/a'),
},

b: {
enable: false,
path: path.join(__dirname, '../plugins/b'),
},

c: {
enable: false,
path: path.join(__dirname, '../plugins/c'),
},

d: {
enable: true,
path: path.join(__dirname, '../plugins/d'),
}
};
exports.e = false;
28 changes: 28 additions & 0 deletions test/fixtures/plugin-dep-disable/framework/config/plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const path = require('path');

module.exports = {
a: {
enable: true,
path: path.join(__dirname, '../plugins/a'),
},

b: {
enable: false,
path: path.join(__dirname, '../plugins/b'),
},

c: {
enable: false,
path: path.join(__dirname, '../plugins/c'),
},

d: {
enable: true,
path: path.join(__dirname, '../plugins/d'),
},

e: {
enable: true,
path: path.join(__dirname, '../plugins/e'),
},
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "c",
"eggPlugin": {
"name": "c"
"name": "c",
"dep": [ "e" ]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "e",
"eggPlugin": {
"name": "e"
}
}
15 changes: 12 additions & 3 deletions test/loader/mixin/load_plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const utils = require('../../utils');
const EggCore = require('../../..').EggCore;
const EggLoader = require('../../..').EggLoader;


describe('test/load_plugin.test.js', function() {
let app;
afterEach(mm.restore);
Expand Down Expand Up @@ -281,18 +282,26 @@ describe('test/load_plugin.test.js', function() {
});

it('should enable dependencies implicitly but not optionalDependencies', done => {
class Application extends EggCore {
get [Symbol.for('egg#eggPath')]() {
return utils.getFilepath('plugin-dep-disable/framework');
}
}

done = pedding(done, 2);
app = utils.createApp('plugin-dep-disable');
app = utils.createApp('plugin-dep-disable', {
Application,
});
mm(app.console, 'info', msg => {
if (msg.startsWith('[egg:loader] eggPlugin is missing')) {
done(new Error('should no run here'));
return;
}
assert(msg === 'Following plugins will be enabled implicitly.\n - b required by [a,d]\n - c required by [a]');
assert(msg === 'Following plugins will be enabled implicitly.\n - b required by [a,d]\n - e required by [c]\n - c required by [a]');
done();
});
mm(app.console, 'warn', msg => {
assert(msg === 'Following plugins will be enabled implicitly that is disabled by application.\n - b required by [a,d]\n - c required by [a]');
assert(msg === 'Following plugins will be enabled implicitly that is disabled by application.\n - e required by [c]');
done();
});
const loader = app.loader;
Expand Down

0 comments on commit 4f1c19a

Please sign in to comment.