diff --git a/lib/loader/mixin/plugin.js b/lib/loader/mixin/plugin.js index de531701..8ec5d6f0 100644 --- a/lib/loader/mixin/plugin.js +++ b/lib/loader/mixin/plugin.js @@ -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) { diff --git a/test/fixtures/plugin-dep-disable/plugins/a/package.json b/test/fixtures/plugin-dep-disable/plugins/a/package.json index e42a7d6b..ce567d96 100644 --- a/test/fixtures/plugin-dep-disable/plugins/a/package.json +++ b/test/fixtures/plugin-dep-disable/plugins/a/package.json @@ -2,6 +2,7 @@ "name": "a", "eggPlugin": { "name": "a", - "dep": ["b", "c"] + "dep": ["b"], + "optionalDependencies": ["c", "e"] } } diff --git a/test/loader/mixin/load_plugin.test.js b/test/loader/mixin/load_plugin.test.js index 7a05849b..b46a878d 100644 --- a/test/loader/mixin/load_plugin.test.js +++ b/test/loader/mixin/load_plugin.test.js @@ -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() {