Skip to content

Commit 4f1c19a

Browse files
authored
fix: only filter the plugin which is disabled by app (#145) (#146)
1 parent 25b728c commit 4f1c19a

9 files changed

Lines changed: 51 additions & 27 deletions

File tree

lib/loader/mixin/plugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ module.exports = {
306306

307307
// should warn when the plugin is disabled by app
308308
message = implicitEnabledPlugins
309-
.filter(name => !appPlugins[name].enable)
309+
.filter(name => appPlugins[name] && appPlugins[name].enable === false)
310310
.map(name => ` - ${name} required by [${requireMap[name]}]`)
311311
.join('\n');
312312
this.options.logger.warn(`Following plugins will be enabled implicitly that is disabled by application.\n${message}`);
Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,3 @@
1-
const path = require('path');
1+
'use strict';
22

3-
module.exports = {
4-
a: {
5-
enable: true,
6-
path: path.join(__dirname, '../plugins/a'),
7-
},
8-
9-
b: {
10-
enable: false,
11-
path: path.join(__dirname, '../plugins/b'),
12-
},
13-
14-
c: {
15-
enable: false,
16-
path: path.join(__dirname, '../plugins/c'),
17-
},
18-
19-
d: {
20-
enable: true,
21-
path: path.join(__dirname, '../plugins/d'),
22-
}
23-
};
3+
exports.e = false;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const path = require('path');
2+
3+
module.exports = {
4+
a: {
5+
enable: true,
6+
path: path.join(__dirname, '../plugins/a'),
7+
},
8+
9+
b: {
10+
enable: false,
11+
path: path.join(__dirname, '../plugins/b'),
12+
},
13+
14+
c: {
15+
enable: false,
16+
path: path.join(__dirname, '../plugins/c'),
17+
},
18+
19+
d: {
20+
enable: true,
21+
path: path.join(__dirname, '../plugins/d'),
22+
},
23+
24+
e: {
25+
enable: true,
26+
path: path.join(__dirname, '../plugins/e'),
27+
},
28+
};

test/fixtures/plugin-dep-disable/plugins/a/package.json renamed to test/fixtures/plugin-dep-disable/framework/plugins/a/package.json

File renamed without changes.

test/fixtures/plugin-dep-disable/plugins/b/package.json renamed to test/fixtures/plugin-dep-disable/framework/plugins/b/package.json

File renamed without changes.

test/fixtures/plugin-dep-disable/plugins/c/package.json renamed to test/fixtures/plugin-dep-disable/framework/plugins/c/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "c",
33
"eggPlugin": {
4-
"name": "c"
4+
"name": "c",
5+
"dep": [ "e" ]
56
}
67
}

test/fixtures/plugin-dep-disable/plugins/d/package.json renamed to test/fixtures/plugin-dep-disable/framework/plugins/d/package.json

File renamed without changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "e",
3+
"eggPlugin": {
4+
"name": "e"
5+
}
6+
}

test/loader/mixin/load_plugin.test.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const utils = require('../../utils');
1111
const EggCore = require('../../..').EggCore;
1212
const EggLoader = require('../../..').EggLoader;
1313

14+
1415
describe('test/load_plugin.test.js', function() {
1516
let app;
1617
afterEach(mm.restore);
@@ -281,18 +282,26 @@ describe('test/load_plugin.test.js', function() {
281282
});
282283

283284
it('should enable dependencies implicitly but not optionalDependencies', done => {
285+
class Application extends EggCore {
286+
get [Symbol.for('egg#eggPath')]() {
287+
return utils.getFilepath('plugin-dep-disable/framework');
288+
}
289+
}
290+
284291
done = pedding(done, 2);
285-
app = utils.createApp('plugin-dep-disable');
292+
app = utils.createApp('plugin-dep-disable', {
293+
Application,
294+
});
286295
mm(app.console, 'info', msg => {
287296
if (msg.startsWith('[egg:loader] eggPlugin is missing')) {
288297
done(new Error('should no run here'));
289298
return;
290299
}
291-
assert(msg === 'Following plugins will be enabled implicitly.\n - b required by [a,d]\n - c required by [a]');
300+
assert(msg === 'Following plugins will be enabled implicitly.\n - b required by [a,d]\n - e required by [c]\n - c required by [a]');
292301
done();
293302
});
294303
mm(app.console, 'warn', msg => {
295-
assert(msg === 'Following plugins will be enabled implicitly that is disabled by application.\n - b required by [a,d]\n - c required by [a]');
304+
assert(msg === 'Following plugins will be enabled implicitly that is disabled by application.\n - e required by [c]');
296305
done();
297306
});
298307
const loader = app.loader;

0 commit comments

Comments
 (0)