Socket
Socket
Sign inDemoInstall

egg-core

Package Overview
Dependencies
Maintainers
5
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 3.20.3 to 3.21.0

lib/utils/timing.js

6

History.md
3.21.0 / 2018-05-07
==================
**features**
* [[`5609d12`](http://github.com/eggjs/egg-core/commit/5609d123edd4bb7b51fc3f2de3a4af775d93398b)] - feat: add timing data for loader (#160) (Haoliang Gao <<sakura9515@gmail.com>>)
3.20.3 / 2018-03-09

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

37

lib/egg.js

@@ -13,4 +13,4 @@ 'use strict';

const Router = require('./utils/router');
const Timing = require('./utils/timing');
const DEPRECATE = Symbol('EggCore#deprecate');

@@ -23,4 +23,4 @@ const CLOSESET = Symbol('EggCore#closeSet');

const INIT_READY = Symbol('EggCore#initReady');
const EGG_READY_TIMEOUT_ENV = Symbol('EggCore#eggReadyTimeoutEnv');
class EggCore extends KoaApplication {

@@ -47,2 +47,4 @@

this.timing = new Timing();
// register a close set

@@ -53,7 +55,6 @@ this[CLOSESET] = new Set();

// get app timeout from env or use default timeout 10 second
const eggReadyTimeoutEnv = process.env.EGG_READY_TIMEOUT_ENV;
this[EGG_READY_TIMEOUT_ENV] = Number.parseInt(eggReadyTimeoutEnv || 10000);
this[INIT_READY]();
assert(Number.isInteger(this[EGG_READY_TIMEOUT_ENV]), `process.env.EGG_READY_TIMEOUT_ENV ${eggReadyTimeoutEnv} should be able to parseInt.`);
this.timing.start('Application Start');
this.ready(() => this.timing.end('Application Start'));

@@ -129,4 +130,2 @@ /**

});
this[INIT_READY]();
}

@@ -222,2 +221,6 @@

const name = utils.getCalleeFromStack(true);
const timingkey = 'Before Start in ' + utils.getResolvedFilename(name, this.options.baseDir);
this.timing.start(timingkey);
const done = this.readyCallback(name);

@@ -229,3 +232,9 @@

yield utils.callFn(scope);
}).then(() => done(), done);
}).then(() => {
done();
this.timing.end(timingkey);
}, err => {
done(err);
this.timing.end(timingkey);
});
});

@@ -291,2 +300,6 @@ }

// get app timeout from env or use default timeout 10 second
const eggReadyTimeoutEnv = Number.parseInt(process.env.EGG_READY_TIMEOUT_ENV || 10000);
assert(Number.isInteger(eggReadyTimeoutEnv), `process.env.EGG_READY_TIMEOUT_ENV ${process.env.EGG_READY_TIMEOUT_ENV} should be able to parseInt.`);
/**

@@ -305,3 +318,3 @@ * If a client starts asynchronously, you can register `readyCallback`,

*/
require('ready-callback')({ timeout: this[EGG_READY_TIMEOUT_ENV] }).mixin(this);
require('ready-callback')({ timeout: eggReadyTimeoutEnv }).mixin(this);

@@ -311,6 +324,4 @@ this.on('ready_stat', data => {

}).on('ready_timeout', id => {
this.console.warn('[egg:core:ready_timeout] %s seconds later %s was still unable to finish.', this[EGG_READY_TIMEOUT_ENV] / 1000, id);
this.console.warn('[egg:core:ready_timeout] %s seconds later %s was still unable to finish.', eggReadyTimeoutEnv / 1000, id);
});
this.ready(() => debug('egg emit ready, application started'));
}

@@ -317,0 +328,0 @@

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

const REQUIRE_COUNT = Symbol('EggLoader#requireCount');
class EggLoader {

@@ -34,2 +36,4 @@

this.app = this.options.app;
this.timing = this.app.timing;
this[REQUIRE_COUNT] = 0;

@@ -291,6 +295,10 @@ /**

const ret = utils.loadFile(filepath);
const timingKey = `Require(${this[REQUIRE_COUNT]++}) ${utils.getResolvedFilename(filepath, this.options.baseDir)}`;
this.timing.start(timingKey);
let ret = utils.loadFile(filepath);
// function(arg1, args, ...) {}
if (inject.length === 0) inject = [ this.app ];
return isFunction(ret) ? ret(...inject) : ret;
ret = isFunction(ret) ? ret(...inject) : ret;
this.timing.end(timingKey);
return ret;
}

@@ -361,3 +369,7 @@

}, opt);
const timingKey = `Load "${property}" to Application`;
this.timing.start(timingKey);
new FileLoader(opt).load();
this.timing.end(timingKey);
}

@@ -378,3 +390,7 @@

}, opt);
const timingKey = `Load "${property}" to Context`;
this.timing.start(timingKey);
new ContextLoader(opt).load();
this.timing.end(timingKey);
}

@@ -381,0 +397,0 @@

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

const SET_CONFIG_META = Symbol('Loader#setConfigMeta');

@@ -23,2 +24,3 @@

loadConfig() {
this.timing.start('Load Config');
this.configMeta = {};

@@ -56,2 +58,3 @@

this.config = target;
this.timing.end('Load Config');
},

@@ -58,0 +61,0 @@

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

module.exports = {

@@ -17,2 +18,3 @@

loadController(opt) {
this.timing.start('Load Controller');
opt = Object.assign({

@@ -54,2 +56,3 @@ caseStyle: 'lower',

this.options.logger.info('[egg:loader] Controller loaded: %s', controllerBase);
this.timing.end('Load Controller');
},

@@ -56,0 +59,0 @@

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

module.exports = {

@@ -25,4 +26,6 @@

loadCustomApp() {
this.timing.start('Load app.js');
this.getLoadUnits()
.forEach(unit => this.loadFile(path.join(unit.path, 'app.js')));
this.timing.end('Load app.js');
},

@@ -34,6 +37,8 @@

loadCustomAgent() {
this.timing.start('Load agent.js');
this.getLoadUnits()
.forEach(unit => this.loadFile(path.join(unit.path, 'agent.js')));
this.timing.end('Load agent.js');
},
};

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

loadExtend(name, proto) {
this.timing.start(`Load extend/${name}.js`);
// All extend files

@@ -150,3 +151,4 @@ const filepaths = this.getExtendFilePaths(name);

}
this.timing.end(`Load extend/${name}.js`);
},
};

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

module.exports = {

@@ -34,2 +35,3 @@

loadMiddleware(opt) {
this.timing.start('Load Middleware');
const app = this.app;

@@ -90,2 +92,3 @@

this.options.logger.info('[egg:loader] Loaded middleware from %j', middlewarePaths);
this.timing.end('Load Middleware');
},

@@ -92,0 +95,0 @@

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

module.exports = {

@@ -59,2 +60,4 @@

loadPlugin() {
this.timing.start('Load Plugin');
// loader plugins from application

@@ -140,2 +143,4 @@ const appPlugins = this.readPluginConfigs(path.join(this.options.baseDir, 'config/plugin.default.js'));

this.plugins = enablePlugins;
this.timing.end('Load Plugin');
},

@@ -142,0 +147,0 @@

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

module.exports = {

@@ -15,5 +16,7 @@

loadRouter() {
this.timing.start('Load Router');
// 加载 router.js
this.loadFile(path.join(this.options.baseDir, 'app/router.js'));
this.timing.end('Load Router');
},
};

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

module.exports = {

@@ -15,2 +16,3 @@

loadService(opt) {
this.timing.start('Load Service');
// 载入到 app.serviceClasses

@@ -25,4 +27,5 @@ opt = Object.assign({

this.loadToContext(servicePaths, 'service', opt);
this.timing.end('Load Service');
},
};

@@ -95,2 +95,7 @@ 'use strict';

},
getResolvedFilename(filepath, baseDir) {
const reg = /\\|\//g;
return filepath.replace(baseDir + path.sep, '').replace(reg, '/');
},
};

@@ -97,0 +102,0 @@

{
"name": "egg-core",
"version": "3.20.3",
"version": "3.21.0",
"description": "A core Pluggable framework based on koa",

@@ -33,3 +33,3 @@ "main": "index.js",

"ci": {
"version": "6, 8"
"version": "6, 8, 10"
},

@@ -39,9 +39,9 @@ "devDependencies": {

"coffee": "^4.1.0",
"egg-bin": "^4.3.7",
"egg-bin": "^4.7.0",
"egg-ci": "^1.8.0",
"eslint": "^4.13.1",
"eslint-config-egg": "^5.1.1",
"js-yaml": "^3.10.0",
"eslint": "^4.19.1",
"eslint-config-egg": "^7.0.0",
"js-yaml": "^3.11.0",
"mm": "^2.2.0",
"mz-modules": "^2.0.0",
"mz-modules": "^2.1.0",
"pedding": "^1.1.0",

@@ -55,4 +55,4 @@ "rimraf": "^2.6.2",

"debug": "^3.1.0",
"depd": "^1.1.1",
"egg-logger": "^1.6.0",
"depd": "^1.1.2",
"egg-logger": "^1.6.2",
"egg-path-matching": "^1.0.1",

@@ -63,3 +63,3 @@ "extend2": "^1.0.0",

"is-type-of": "^1.2.0",
"koa": "^1.4.1",
"koa": "^1.6.0",
"koa-router": "^5.4.2",

@@ -66,0 +66,0 @@ "node-homedir": "^1.1.0",

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