Socket
Socket
Sign inDemoInstall

egg-core

Package Overview
Dependencies
Maintainers
4
Versions
137
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

egg-core - npm Package Compare versions

Comparing version 0.6.0 to 1.0.0

test/fixtures/egg/plugins/zzz/package.json

6

History.md
1.0.0 / 2016-11-04
==================
* feat: warn when redefine plugin (#28)
* refactor: assert eggPath should be string
0.6.0 / 2016-10-28

@@ -3,0 +9,0 @@ ==================

2

lib/loader/egg_loader.js

@@ -163,3 +163,3 @@ 'use strict';

const eggPath = proto[Symbol.for('egg#eggPath')];
// 使用 fs.realpathSync 来找到最终路径
assert(eggPath && typeof eggPath === 'string', 'Symbol.for(\'egg#eggPath\') should be string');
const realpath = fs.realpathSync(eggPath);

@@ -166,0 +166,0 @@ if (eggPaths.indexOf(realpath) === -1) {

@@ -90,5 +90,5 @@ 'use strict';

this.allPlugins = {};
extendPlugins(this.allPlugins, eggPlugins);
extendPlugins(this.allPlugins, appPlugins);
extendPlugins(this.allPlugins, customPlugins);
this._extendPlugins(this.allPlugins, eggPlugins);
this._extendPlugins(this.allPlugins, appPlugins);
this._extendPlugins(this.allPlugins, customPlugins);

@@ -171,3 +171,3 @@ const enabledPluginNames = []; // enabled plugins that configured explicitly

extendPlugins(plugins, config);
this._extendPlugins(plugins, config);
}

@@ -329,27 +329,32 @@

};
function extendPlugins(target, plugins) {
if (!plugins) {
return;
}
for (const name in plugins) {
const plugin = plugins[name];
if (!target[name]) {
target[name] = {};
_extendPlugins(target, plugins) {
if (!plugins) {
return;
}
if (plugin.path || plugin.package) {
delete target[name].path;
delete target[name].package;
}
for (const prop in plugin) {
if (plugin[prop] === undefined) {
continue;
for (const name in plugins) {
const plugin = plugins[name];
let targetPlugin = target[name];
if (!targetPlugin) {
targetPlugin = target[name] = {};
}
if (target[name][prop] && Array.isArray(plugin[prop]) && !plugin[prop].length) {
continue;
if ((targetPlugin.path || targetPlugin.package) && (plugin.path || plugin.package)) {
this.options.logger.warn('plugin %s has been defined that is %j, but you define again in %s',
name, targetPlugin, plugin.from);
}
target[name][prop] = plugin[prop];
if (plugin.path || plugin.package) {
delete targetPlugin.path;
delete targetPlugin.package;
}
for (const prop in plugin) {
if (plugin[prop] === undefined) {
continue;
}
if (targetPlugin[prop] && Array.isArray(plugin[prop]) && !plugin[prop].length) {
continue;
}
targetPlugin[prop] = plugin[prop];
}
}
}
}
},
};
{
"name": "egg-core",
"version": "0.6.0",
"version": "1.0.0",
"description": "A core Pluggable framework based on koa",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -30,2 +30,8 @@ 'use strict';

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

@@ -5,2 +5,3 @@ 'use strict';

session: false,
zzz: false,
};

@@ -66,2 +66,10 @@ 'use strict';

});
it('should assert eggPath type', () => {
(function() {
utils.createApp('eggpath', {
Application: require(utils.getFilepath('framework-wrong-eggpath')),
});
}).should.throw('Symbol.for(\'egg#eggPath\') should be string');
});
});

@@ -19,7 +19,7 @@ 'use strict';

const units = app.loader.getLoadUnits();
units.length.should.eql(10);
units[8].type.should.eql('framework');
units[8].path.should.eql(utils.getFilepath('egg'));
units[9].type.should.eql('app');
units[9].path.should.eql(utils.getFilepath('plugin'));
units.length.should.eql(11);
units[9].type.should.eql('framework');
units[9].path.should.eql(utils.getFilepath('egg'));
units[10].type.should.eql('app');
units[10].path.should.eql(utils.getFilepath('plugin'));
});

@@ -26,0 +26,0 @@

@@ -213,2 +213,3 @@ 'use strict';

'session',
'zzz',
// 'depd',

@@ -409,2 +410,22 @@ // 'onerror',

});
it('should warn when redefine plugin', () => {
app = utils.createApp('load-plugin-config-override');
mm(app.console, 'warn', function(msg, name, targetPlugin, from) {
msg.should.eql('plugin %s has been defined that is %j, but you define again in %s');
name.should.eql('zzz');
targetPlugin.should.eql({
enable: true,
path: utils.getFilepath('egg/plugins/zzz'),
name: 'zzz',
dep: [],
env: [],
from: utils.getFilepath('egg/config/plugin.js'),
});
from.should.eql(utils.getFilepath('load-plugin-config-override/config/plugin.js'));
});
const loader = app.loader;
loader.loadPlugin();
loader.allPlugins.zzz.path.should.eql(utils.getFilepath('load-plugin-config-override/plugins/zzz'));
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc