Socket
Socket
Sign inDemoInstall

egg-core

Package Overview
Dependencies
13
Maintainers
4
Versions
137
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.1 to 0.3.0

test/fixtures/agent/app/extend/agent.js

10

History.md
0.3.0 / 2016-10-13
==================
* fix: always get the executor's homedir (#17)
* doc: Plugable > Pluggable (#16)
* test: delete type testcase (#15)
* fix: can't get appConfig in appConfig (#14)
* feat: add plugin.from where declare the plugin (#13)
* feat: [BREAKING_CHANGE] remove compatible support loadExtend (#12)
0.2.1 / 2016-08-18

@@ -3,0 +13,0 @@ ==================

7

lib/loader/egg_loader.js

@@ -10,4 +10,3 @@ 'use strict';

const ContextLoader = require('./context_loader');
const loadFile = require('../utils').loadFile;
const getHomedir = require('../utils').getHomedir;
const utils = require('../utils');
const EggCore = require('../egg');

@@ -61,3 +60,3 @@

env: this.serverEnv,
HOME: getHomedir(),
HOME: utils.getHomedir(),
pkg: this.pkg,

@@ -195,3 +194,3 @@ };

const ret = loadFile(filepath);
const ret = utils.loadFile(filepath);
// function(arg1, args, ...) {}

@@ -198,0 +197,0 @@ let inject = Array.prototype.slice.call(arguments, 1);

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

const is = require('is-type-of');
const loadFile = require('../utils').loadFile;
const utils = require('../utils');
const FULLPATH = Symbol('EGG_LOADER_ITEM_FULLPATH');

@@ -119,3 +119,3 @@ const EXPORTS = Symbol('EGG_LOADER_ITEM_EXPORTS');

function getExports(fullpath, initializer, isCall, inject) {
let exports = loadFile(fullpath);
let exports = utils.loadFile(fullpath);

@@ -122,0 +122,0 @@ // process exports as you like

@@ -39,3 +39,4 @@ 'use strict';

for (const unit of this.getLoadUnits()) {
const config = this._loadConfig(unit.path, filename, appConfig, unit.type);
const isApp = unit.type === 'app';
const config = this._loadConfig(unit.path, filename, isApp ? undefined : appConfig, unit.type);

@@ -42,0 +43,0 @@ if (!config) {

'use strict';
const fs = require('fs');
const path = require('path');

@@ -76,10 +75,3 @@ const interopRequire = require('interop-require');

// 获取需要加载的文件
const filepaths = this.getLoadUnits()
.map(unit => {
let pluginExtendsPath = path.join(unit.path, 'app/extend');
if (!fs.existsSync(pluginExtendsPath)) {
pluginExtendsPath = path.join(unit.path, 'app');
}
return path.join(pluginExtendsPath, name);
});
const filepaths = this.getLoadUnits().map(unit => path.join(unit.path, 'app/extend', name));
const mergeRecord = new Map();

@@ -86,0 +78,0 @@ for (const filepath of filepaths) {

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

for (const name in config) {
this.normalizePluginConfig(config, name);
this.normalizePluginConfig(config, name, configPath);
}

@@ -170,3 +170,3 @@

normalizePluginConfig(plugins, name) {
normalizePluginConfig(plugins, name, configPath) {
const plugin = plugins[name];

@@ -181,2 +181,3 @@

env: [],
from: configPath,
};

@@ -192,2 +193,3 @@ return;

plugin.env = plugin.env || [];
plugin.from = configPath;
},

@@ -194,0 +196,0 @@

'use strict';
const interopRequire = require('interop-require');
const homedir = require('node-homedir');
module.exports = exports = {
module.exports = {

@@ -28,3 +29,3 @@ loadFile(filepath) {

getHomedir() {
return process.env.HOME || '/home/admin';
return homedir() || '/home/admin';
},

@@ -31,0 +32,0 @@

{
"name": "egg-core",
"version": "0.2.1",
"description": "A core Plugable framework based on koa",
"version": "0.3.0",
"description": "A core Pluggable framework based on koa",
"main": "index.js",

@@ -58,2 +58,3 @@ "scripts": {

"koa-router": "^5.4.0",
"node-homedir": "^0.0.1",
"ready-callback": "^1.0.0",

@@ -60,0 +61,0 @@ "utility": "^1.8.0"

@@ -23,3 +23,3 @@ # egg-core

A core Plugable framework based on [koa](https://github.com/koajs/koa)
A core Pluggable framework based on [koa](https://github.com/koajs/koa)

@@ -26,0 +26,0 @@ **Don't use it directly, see [egg]**

@@ -6,3 +6,2 @@ const path = require('path');

env: ['local'],
type: ['alipay'],
path: path.join(__dirname, '../../../plugins/test-me')

@@ -13,4 +12,3 @@ };

enable: true,
type: ['ali'],
path: path.join(__dirname, '../../../plugins/test-me-ali')
};
{
"name": "dont-load-plugin",
"egg": {
"type": "alipay"
}
"name": "dont-load-plugin"
}
'use strict';
module.exports = function(antx) {
module.exports = function(antx, appConfig) {
return {

@@ -10,4 +10,5 @@ app: {

val: 2,
}
},
appInApp: appConfig != null,
};
};

@@ -115,3 +115,4 @@ 'use strict';

loader.config.plugin.sub.should.not.equal(loader.config.app.sub);
loader.config.appInApp.should.false();
});
});

@@ -9,2 +9,4 @@ 'use strict';

const utils = require('../../utils');
const EggCore = require('../../..').EggCore;
const EggLoader = require('../../..').EggLoader;

@@ -29,2 +31,3 @@ describe('test/load_plugin.test.js', function() {

path: path.join(baseDir, 'node_modules/b'),
from: path.join(baseDir, 'config/plugin.js'),
});

@@ -37,2 +40,3 @@ loader.plugins.c.should.eql({

path: path.join(baseDir, 'node_modules/c'),
from: path.join(baseDir, 'config/plugin.js'),
});

@@ -45,2 +49,3 @@ loader.plugins.e.should.eql({

path: path.join(baseDir, 'plugins/e'),
from: path.join(baseDir, 'config/plugin.js'),
});

@@ -64,2 +69,3 @@ loader.orderPlugins.should.be.an.Array;

path: path.join(baseDir, 'node_modules/rds'),
from: path.join(baseDir, 'config/plugin.js'),
});

@@ -82,2 +88,3 @@ });

path: path.join(baseDir, 'node_modules/d'),
from: path.join(baseDir, 'config/plugin.js'),
});

@@ -101,2 +108,3 @@ should.not.exists(loader.plugins.d);

version: '1.0.0',
from: path.join(baseDir, 'config/plugin.js'),
});

@@ -143,2 +151,3 @@ });

path: path.join(baseDir, 'node_modules/d'),
from: path.join(baseDir, 'config/plugin.js'),
});

@@ -295,26 +304,2 @@ loader.plugins.foo.should.eql({

it('should enable that match type', function() {
// mock local
mm(process.env, 'NODE_ENV', 'development');
app = utils.createApp('dont-load-plugin');
const loader = app.loader;
loader.loadPlugin();
loader.loadConfig();
const names = loader.orderPlugins.map(function(plugin) {
return plugin.name;
});
names.should.containEql('testMe');
});
it('should enable that match one type', function() {
app = utils.createApp('ali-plugin');
const loader = app.loader;
loader.loadPlugin();
loader.loadConfig();
const names = loader.orderPlugins.map(function(plugin) {
return plugin.name;
});
names.should.containEql('foo');
});
it('should complement infomation by config/plugin.js from plugin', function() {

@@ -351,2 +336,3 @@ const baseDir = utils.getFilepath('plugin');

path: path.join(baseDir, 'node_modules/a1'),
from: path.join(baseDir, 'config/plugin.js'),
});

@@ -396,2 +382,19 @@ });

});
it('should get the defining plugin path in every plugin', () => {
app = utils.createApp('plugin-from', {
Application: class Application extends EggCore {
get [Symbol.for('egg#loader')]() {
return EggLoader;
}
get [Symbol.for('egg#eggPath')]() {
return utils.getFilepath('plugin-from/framework');
}
},
});
const loader = app.loader;
loader.loadPlugin();
loader.plugins.a.from.should.equal(utils.getFilepath('plugin-from/config/plugin.js'));
loader.plugins.b.from.should.equal(utils.getFilepath('plugin-from/framework/config/plugin.js'));
});
});
'use strict';
const mm = require('mm');
const os = require('os');
const utils = require('../../lib/utils');
const should = require('should');

@@ -12,2 +14,7 @@ describe('test/utils/index.test.js', () => {

it('should return process.env.HOME', () => {
if (os.userInfo && os.userInfo().homedir) {
const userInfo = os.userInfo();
delete userInfo.homedir;
mm(os, 'userInfo', () => userInfo);
}
utils.getHomedir().should.equal(process.env.HOME);

@@ -18,5 +25,9 @@ });

mm(process.env, 'HOME', '');
utils.getHomedir().should.equal('/home/admin');
if (os.userInfo && os.userInfo().homedir) {
should.ok(utils.getHomedir().indexOf(process.env.USER) > -1);
} else {
utils.getHomedir().should.equal('/home/admin');
}
});
});
});
SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc