Skip to content

Commit

Permalink
fix: adjust implicitly enable logic (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
gxcsoccer committed Dec 1, 2017
1 parent 7a6e86e commit 035098c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
6 changes: 0 additions & 6 deletions lib/loader/mixin/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,6 @@ module.exports = {
continue;
}

// Can't enable the plugin implicitly when it's disabled by application
if (appPlugins[name] && !appPlugins[name].enable) {
debug('Disable %j, as disabled by app', name);
continue;
}

plugins[name] = plugin;

if (plugin.enable) {
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/plugin-dep-disable/plugins/a/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "a",
"eggPlugin": {
"name": "a",
"dep": ["b", "c"]
"dep": ["b"],
"optionalDependencies": ["c", "e"]
}
}
27 changes: 20 additions & 7 deletions test/loader/mixin/load_plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,26 @@ describe('test/load_plugin.test.js', function() {
}
});

it('should not override the plugin.js of app implicitly', () => {
assert.throws(() => {
app = utils.createApp('plugin-dep-disable');
const loader = app.loader;
loader.loadPlugin();
loader.loadConfig();
}, /sequencify plugins has problem, missing: \[b,c], recursive: \[]\n\t>> Plugin \[b] is disabled or missed, but is required by \[a,d]\n\t>> Plugin \[c] is disabled or missed, but is required by \[a]/);
it('should enable dependencies implicitly but not optionalDependencies', done => {
app = utils.createApp('plugin-dep-disable');
mm(app.console, 'info', msg => {
if (msg.startsWith('[egg:loader] eggPlugin is missing')) {
done(new Error('should no run here'));
return;
}
// Following plugins will be enabled implicitly.
// - b required by [a,d]
assert(msg === 'Following plugins will be enabled implicitly.\n - b required by [a,d]');
done();
});
const loader = app.loader;
loader.loadPlugin();
loader.loadConfig();
assert(loader.plugins.a && loader.plugins.a.enable);
assert(loader.plugins.b && loader.plugins.b.enable);
assert(loader.plugins.d && loader.plugins.d.enable);
assert(!loader.plugins.c);
assert(!loader.plugins.e);
});

it('should enable when not match env', function() {
Expand Down

0 comments on commit 035098c

Please sign in to comment.