ee-core 2.9.2 → 2.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +65 -65
- package/addon/index.js +34 -34
- package/addon/window/index.js +98 -98
- package/bin/tools.js +8 -8
- package/config/cache.js +41 -38
- package/config/config.default.js +331 -330
- package/config/index.js +75 -73
- package/const/channel.js +17 -17
- package/const/index.js +8 -8
- package/controller/baseContextClass.js +34 -34
- package/controller/index.js +34 -34
- package/core/index.js +10 -10
- package/core/lib/ee.js +216 -216
- package/core/lib/loader/context_loader.js +106 -106
- package/core/lib/loader/ee_loader.js +435 -435
- package/core/lib/loader/file_loader.js +326 -326
- package/core/lib/loader/mixin/addon.js +32 -32
- package/core/lib/loader/mixin/config.js +130 -130
- package/core/lib/loader/mixin/controller.js +125 -125
- package/core/lib/loader/mixin/service.js +28 -28
- package/core/lib/utils/base_context_class.js +34 -34
- package/core/lib/utils/function.js +30 -30
- package/core/lib/utils/index.js +133 -133
- package/core/lib/utils/sequencify.js +59 -59
- package/core/lib/utils/timing.js +77 -77
- package/cross/index.js +183 -183
- package/cross/spawnProcess.js +183 -183
- package/ee/appLoader.js +48 -48
- package/ee/application.js +99 -99
- package/ee/baseApp.js +103 -102
- package/ee/eeApp.js +408 -408
- package/ee/index.js +57 -57
- package/electron/app/index.js +64 -58
- package/electron/index.js +19 -19
- package/electron/window/index.js +73 -73
- package/electron/window/winState.js +186 -186
- package/exception/index.js +112 -112
- package/html/boot.html +98 -98
- package/html/cross-failure.html +28 -28
- package/html/failure.html +28 -28
- package/html/index.js +13 -13
- package/httpclient/index.js +161 -161
- package/index.js +54 -54
- package/jobs/baseJobClass.js +16 -16
- package/jobs/child/app.js +65 -65
- package/jobs/child/forkProcess.js +145 -145
- package/jobs/child/index.js +82 -82
- package/jobs/child-pool/index.js +213 -213
- package/jobs/index.js +8 -8
- package/jobs/load-balancer/algorithm/index.js +11 -11
- package/jobs/load-balancer/algorithm/minimumConnection.js +18 -18
- package/jobs/load-balancer/algorithm/polling.js +11 -11
- package/jobs/load-balancer/algorithm/random.js +9 -9
- package/jobs/load-balancer/algorithm/specify.js +14 -14
- package/jobs/load-balancer/algorithm/weights.js +21 -21
- package/jobs/load-balancer/algorithm/weightsMinimumConnection.js +29 -29
- package/jobs/load-balancer/algorithm/weightsPolling.js +22 -22
- package/jobs/load-balancer/algorithm/weightsRandom.js +16 -16
- package/jobs/load-balancer/consts.js +9 -9
- package/jobs/load-balancer/index.js +201 -201
- package/jobs/load-balancer/scheduler.js +31 -31
- package/jobs/renderer/index.js +141 -141
- package/jobs/renderer/loadView.js +40 -40
- package/jobs/unification.js +63 -63
- package/loader/index.js +172 -172
- package/log/index.js +68 -68
- package/log/logger.js +86 -80
- package/main/index.js +56 -56
- package/message/childMessage.js +54 -54
- package/message/index.js +18 -18
- package/old-utils/index.js +91 -91
- package/package.json +38 -38
- package/ps/index.js +371 -371
- package/services/baseContextClass.js +34 -34
- package/services/index.js +40 -40
- package/socket/httpServer.js +147 -147
- package/socket/index.js +81 -81
- package/socket/io.js +27 -27
- package/socket/ipcServer.js +112 -112
- package/socket/socketServer.js +69 -67
- package/storage/index.js +38 -38
- package/storage/jsondb/adapters/Base.js +23 -23
- package/storage/jsondb/adapters/FileSync.js +64 -52
- package/storage/jsondb/main.js +55 -42
- package/storage/jsondbStorage.js +195 -195
- package/storage/sqliteStorage.js +123 -123
- package/utils/co.js +237 -237
- package/utils/copyto.js +160 -160
- package/utils/depd/index.js +538 -538
- package/utils/depd/lib/browser/index.js +77 -77
- package/utils/extend.js +73 -73
- package/utils/get-port/index.d.ts +64 -64
- package/utils/get-port/index.js +148 -148
- package/utils/helper.js +220 -220
- package/utils/index.js +160 -160
- package/utils/ip.js +261 -261
- package/utils/is.js +145 -145
- package/utils/json.js +72 -72
- package/utils/pargv.js +263 -263
- package/utils/time/index.js +19 -19
- package/utils/time/ms.js +162 -162
- package/utils/wrap.js +35 -35
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* BaseContextClass is a base class that can be extended,
|
|
5
|
-
* it's instantiated in context level,
|
|
6
|
-
* {@link Helper}, {@link Service} is extending it.
|
|
7
|
-
*/
|
|
8
|
-
class BaseContextClass {
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @class
|
|
12
|
-
* @param {Context} ctx - context instance
|
|
13
|
-
* @since 1.0.0
|
|
14
|
-
*/
|
|
15
|
-
constructor(ctx) {
|
|
16
|
-
/**
|
|
17
|
-
* @member {Application} BaseContextClass#app
|
|
18
|
-
* @since 1.0.0
|
|
19
|
-
*/
|
|
20
|
-
this.app = ctx;
|
|
21
|
-
/**
|
|
22
|
-
* @member {Config} BaseContextClass#config
|
|
23
|
-
* @since 1.0.0
|
|
24
|
-
*/
|
|
25
|
-
this.config = ctx.config;
|
|
26
|
-
/**
|
|
27
|
-
* @member {Service} BaseContextClass#service
|
|
28
|
-
* @since 1.0.0
|
|
29
|
-
*/
|
|
30
|
-
this.service = ctx.service;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
module.exports = BaseContextClass;
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* BaseContextClass is a base class that can be extended,
|
|
5
|
+
* it's instantiated in context level,
|
|
6
|
+
* {@link Helper}, {@link Service} is extending it.
|
|
7
|
+
*/
|
|
8
|
+
class BaseContextClass {
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @class
|
|
12
|
+
* @param {Context} ctx - context instance
|
|
13
|
+
* @since 1.0.0
|
|
14
|
+
*/
|
|
15
|
+
constructor(ctx) {
|
|
16
|
+
/**
|
|
17
|
+
* @member {Application} BaseContextClass#app
|
|
18
|
+
* @since 1.0.0
|
|
19
|
+
*/
|
|
20
|
+
this.app = ctx;
|
|
21
|
+
/**
|
|
22
|
+
* @member {Config} BaseContextClass#config
|
|
23
|
+
* @since 1.0.0
|
|
24
|
+
*/
|
|
25
|
+
this.config = ctx.config;
|
|
26
|
+
/**
|
|
27
|
+
* @member {Service} BaseContextClass#service
|
|
28
|
+
* @since 1.0.0
|
|
29
|
+
*/
|
|
30
|
+
this.service = ctx.service;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
module.exports = BaseContextClass;
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
const assert = require('assert');
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* A empty function.
|
|
5
|
-
*
|
|
6
|
-
* @return {Function}
|
|
7
|
-
* @public
|
|
8
|
-
*/
|
|
9
|
-
exports.noop = function noop() {};
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Get a function parameter's names.
|
|
13
|
-
*
|
|
14
|
-
* @param {Function} func
|
|
15
|
-
* @param {Boolean} [useCache], default is true
|
|
16
|
-
* @return {Array} names
|
|
17
|
-
*/
|
|
18
|
-
exports.getParamNames = function getParamNames(func, cache) {
|
|
19
|
-
var type = typeof func;
|
|
20
|
-
assert(type === 'function', 'The "func" must be a function. Received type "' + type + '"');
|
|
21
|
-
|
|
22
|
-
cache = cache !== false;
|
|
23
|
-
if (cache && func.__cache_names) {
|
|
24
|
-
return func.__cache_names;
|
|
25
|
-
}
|
|
26
|
-
var str = func.toString();
|
|
27
|
-
var names = str.slice(str.indexOf('(') + 1, str.indexOf(')')).match(/([^\s,]+)/g) || [];
|
|
28
|
-
func.__cache_names = names;
|
|
29
|
-
return names;
|
|
30
|
-
};
|
|
1
|
+
const assert = require('assert');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A empty function.
|
|
5
|
+
*
|
|
6
|
+
* @return {Function}
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
exports.noop = function noop() {};
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Get a function parameter's names.
|
|
13
|
+
*
|
|
14
|
+
* @param {Function} func
|
|
15
|
+
* @param {Boolean} [useCache], default is true
|
|
16
|
+
* @return {Array} names
|
|
17
|
+
*/
|
|
18
|
+
exports.getParamNames = function getParamNames(func, cache) {
|
|
19
|
+
var type = typeof func;
|
|
20
|
+
assert(type === 'function', 'The "func" must be a function. Received type "' + type + '"');
|
|
21
|
+
|
|
22
|
+
cache = cache !== false;
|
|
23
|
+
if (cache && func.__cache_names) {
|
|
24
|
+
return func.__cache_names;
|
|
25
|
+
}
|
|
26
|
+
var str = func.toString();
|
|
27
|
+
var names = str.slice(str.indexOf('(') + 1, str.indexOf(')')).match(/([^\s,]+)/g) || [];
|
|
28
|
+
func.__cache_names = names;
|
|
29
|
+
return names;
|
|
30
|
+
};
|
package/core/lib/utils/index.js
CHANGED
|
@@ -1,133 +1,133 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
require('bytenode');
|
|
4
|
-
const convert = require('koa-convert');
|
|
5
|
-
const is = require('is-type-of');
|
|
6
|
-
const path = require('path');
|
|
7
|
-
const fs = require('fs');
|
|
8
|
-
const co = require('../../../utils/co');
|
|
9
|
-
const BuiltinModule = require('module');
|
|
10
|
-
|
|
11
|
-
// Guard against poorly mocked module constructors.
|
|
12
|
-
const Module = module.constructor.length > 1
|
|
13
|
-
? module.constructor
|
|
14
|
-
/* istanbul ignore next */
|
|
15
|
-
: BuiltinModule;
|
|
16
|
-
|
|
17
|
-
// Module._extensions:
|
|
18
|
-
// '.js': [Function (anonymous)],
|
|
19
|
-
// '.json': [Function (anonymous)],
|
|
20
|
-
// '.node': [Function: func],
|
|
21
|
-
// '.jsc': [Function (anonymous)]
|
|
22
|
-
|
|
23
|
-
module.exports = {
|
|
24
|
-
extensions: Module._extensions,
|
|
25
|
-
|
|
26
|
-
loadFile(filepath) {
|
|
27
|
-
try {
|
|
28
|
-
// if not js module, just return content buffer
|
|
29
|
-
const extname = path.extname(filepath);
|
|
30
|
-
if (extname && !Module._extensions[extname]) {
|
|
31
|
-
return fs.readFileSync(filepath);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// require js module
|
|
35
|
-
const obj = require(filepath);
|
|
36
|
-
if (!obj) return obj;
|
|
37
|
-
// it's es module
|
|
38
|
-
if (obj.__esModule) return 'default' in obj ? obj.default : obj;
|
|
39
|
-
return obj;
|
|
40
|
-
} catch (err) {
|
|
41
|
-
err.message = `[ee-core] load file: ${filepath}, error: ${err.message}`;
|
|
42
|
-
throw err;
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
|
|
46
|
-
methods: [ 'head', 'options', 'get', 'put', 'patch', 'post', 'delete' ],
|
|
47
|
-
|
|
48
|
-
async callFn(fn, args, ctx) {
|
|
49
|
-
args = args || [];
|
|
50
|
-
if (!is.function(fn)) return;
|
|
51
|
-
if (is.generatorFunction(fn)) fn = co.wrap(fn);
|
|
52
|
-
return ctx ? fn.call(ctx, ...args) : fn(...args);
|
|
53
|
-
},
|
|
54
|
-
|
|
55
|
-
middleware(fn) {
|
|
56
|
-
return is.generatorFunction(fn) ? convert(fn) : fn;
|
|
57
|
-
},
|
|
58
|
-
|
|
59
|
-
getCalleeFromStack(withLine, stackIndex) {
|
|
60
|
-
stackIndex = stackIndex === undefined ? 2 : stackIndex;
|
|
61
|
-
const limit = Error.stackTraceLimit;
|
|
62
|
-
const prep = Error.prepareStackTrace;
|
|
63
|
-
|
|
64
|
-
Error.prepareStackTrace = prepareObjectStackTrace;
|
|
65
|
-
Error.stackTraceLimit = 5;
|
|
66
|
-
|
|
67
|
-
// capture the stack
|
|
68
|
-
const obj = {};
|
|
69
|
-
Error.captureStackTrace(obj);
|
|
70
|
-
let callSite = obj.stack[stackIndex];
|
|
71
|
-
let fileName;
|
|
72
|
-
/* istanbul ignore else */
|
|
73
|
-
if (callSite) {
|
|
74
|
-
fileName = callSite.getFileName();
|
|
75
|
-
/* istanbul ignore if */
|
|
76
|
-
if (fileName && fileName.endsWith('egg-mock/lib/app.js')) {
|
|
77
|
-
// TODO: add test
|
|
78
|
-
callSite = obj.stack[stackIndex + 1];
|
|
79
|
-
fileName = callSite.getFileName();
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
Error.prepareStackTrace = prep;
|
|
84
|
-
Error.stackTraceLimit = limit;
|
|
85
|
-
|
|
86
|
-
/* istanbul ignore if */
|
|
87
|
-
if (!callSite || !fileName) return '<anonymous>';
|
|
88
|
-
if (!withLine) return fileName;
|
|
89
|
-
return `${fileName}:${callSite.getLineNumber()}:${callSite.getColumnNumber()}`;
|
|
90
|
-
},
|
|
91
|
-
|
|
92
|
-
getResolvedFilename(filepath, baseDir) {
|
|
93
|
-
const reg = /[/\\]/g;
|
|
94
|
-
return filepath.replace(baseDir + path.sep, '').replace(reg, '/');
|
|
95
|
-
},
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* 字节码类
|
|
99
|
-
*/
|
|
100
|
-
isBytecodeClass (exports) {
|
|
101
|
-
let isClass = false;
|
|
102
|
-
|
|
103
|
-
// 标识
|
|
104
|
-
if (exports.toString().indexOf('[class') != -1) {
|
|
105
|
-
isClass = true;
|
|
106
|
-
}
|
|
107
|
-
// TODO 更严谨的判断,应该加上文件名和路径
|
|
108
|
-
|
|
109
|
-
return isClass;
|
|
110
|
-
},
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* 文件类型
|
|
114
|
-
*/
|
|
115
|
-
filePatterns () {
|
|
116
|
-
const files = (process.env.EE_TYPESCRIPT === 'true' && Module._extensions['.ts'])
|
|
117
|
-
? [ '**/*.(js|ts)', '!**/*.d.ts' ]
|
|
118
|
-
: [ '**/*.js','**/*.jsc' ];
|
|
119
|
-
|
|
120
|
-
return files;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Capture call site stack from v8.
|
|
128
|
-
* https://github.com/v8/v8/wiki/Stack-Trace-API
|
|
129
|
-
*/
|
|
130
|
-
|
|
131
|
-
function prepareObjectStackTrace(obj, stack) {
|
|
132
|
-
return stack;
|
|
133
|
-
}
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
require('bytenode');
|
|
4
|
+
const convert = require('koa-convert');
|
|
5
|
+
const is = require('is-type-of');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
const fs = require('fs');
|
|
8
|
+
const co = require('../../../utils/co');
|
|
9
|
+
const BuiltinModule = require('module');
|
|
10
|
+
|
|
11
|
+
// Guard against poorly mocked module constructors.
|
|
12
|
+
const Module = module.constructor.length > 1
|
|
13
|
+
? module.constructor
|
|
14
|
+
/* istanbul ignore next */
|
|
15
|
+
: BuiltinModule;
|
|
16
|
+
|
|
17
|
+
// Module._extensions:
|
|
18
|
+
// '.js': [Function (anonymous)],
|
|
19
|
+
// '.json': [Function (anonymous)],
|
|
20
|
+
// '.node': [Function: func],
|
|
21
|
+
// '.jsc': [Function (anonymous)]
|
|
22
|
+
|
|
23
|
+
module.exports = {
|
|
24
|
+
extensions: Module._extensions,
|
|
25
|
+
|
|
26
|
+
loadFile(filepath) {
|
|
27
|
+
try {
|
|
28
|
+
// if not js module, just return content buffer
|
|
29
|
+
const extname = path.extname(filepath);
|
|
30
|
+
if (extname && !Module._extensions[extname]) {
|
|
31
|
+
return fs.readFileSync(filepath);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// require js module
|
|
35
|
+
const obj = require(filepath);
|
|
36
|
+
if (!obj) return obj;
|
|
37
|
+
// it's es module
|
|
38
|
+
if (obj.__esModule) return 'default' in obj ? obj.default : obj;
|
|
39
|
+
return obj;
|
|
40
|
+
} catch (err) {
|
|
41
|
+
err.message = `[ee-core] load file: ${filepath}, error: ${err.message}`;
|
|
42
|
+
throw err;
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
methods: [ 'head', 'options', 'get', 'put', 'patch', 'post', 'delete' ],
|
|
47
|
+
|
|
48
|
+
async callFn(fn, args, ctx) {
|
|
49
|
+
args = args || [];
|
|
50
|
+
if (!is.function(fn)) return;
|
|
51
|
+
if (is.generatorFunction(fn)) fn = co.wrap(fn);
|
|
52
|
+
return ctx ? fn.call(ctx, ...args) : fn(...args);
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
middleware(fn) {
|
|
56
|
+
return is.generatorFunction(fn) ? convert(fn) : fn;
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
getCalleeFromStack(withLine, stackIndex) {
|
|
60
|
+
stackIndex = stackIndex === undefined ? 2 : stackIndex;
|
|
61
|
+
const limit = Error.stackTraceLimit;
|
|
62
|
+
const prep = Error.prepareStackTrace;
|
|
63
|
+
|
|
64
|
+
Error.prepareStackTrace = prepareObjectStackTrace;
|
|
65
|
+
Error.stackTraceLimit = 5;
|
|
66
|
+
|
|
67
|
+
// capture the stack
|
|
68
|
+
const obj = {};
|
|
69
|
+
Error.captureStackTrace(obj);
|
|
70
|
+
let callSite = obj.stack[stackIndex];
|
|
71
|
+
let fileName;
|
|
72
|
+
/* istanbul ignore else */
|
|
73
|
+
if (callSite) {
|
|
74
|
+
fileName = callSite.getFileName();
|
|
75
|
+
/* istanbul ignore if */
|
|
76
|
+
if (fileName && fileName.endsWith('egg-mock/lib/app.js')) {
|
|
77
|
+
// TODO: add test
|
|
78
|
+
callSite = obj.stack[stackIndex + 1];
|
|
79
|
+
fileName = callSite.getFileName();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
Error.prepareStackTrace = prep;
|
|
84
|
+
Error.stackTraceLimit = limit;
|
|
85
|
+
|
|
86
|
+
/* istanbul ignore if */
|
|
87
|
+
if (!callSite || !fileName) return '<anonymous>';
|
|
88
|
+
if (!withLine) return fileName;
|
|
89
|
+
return `${fileName}:${callSite.getLineNumber()}:${callSite.getColumnNumber()}`;
|
|
90
|
+
},
|
|
91
|
+
|
|
92
|
+
getResolvedFilename(filepath, baseDir) {
|
|
93
|
+
const reg = /[/\\]/g;
|
|
94
|
+
return filepath.replace(baseDir + path.sep, '').replace(reg, '/');
|
|
95
|
+
},
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* 字节码类
|
|
99
|
+
*/
|
|
100
|
+
isBytecodeClass (exports) {
|
|
101
|
+
let isClass = false;
|
|
102
|
+
|
|
103
|
+
// 标识
|
|
104
|
+
if (exports.toString().indexOf('[class') != -1) {
|
|
105
|
+
isClass = true;
|
|
106
|
+
}
|
|
107
|
+
// TODO 更严谨的判断,应该加上文件名和路径
|
|
108
|
+
|
|
109
|
+
return isClass;
|
|
110
|
+
},
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* 文件类型
|
|
114
|
+
*/
|
|
115
|
+
filePatterns () {
|
|
116
|
+
const files = (process.env.EE_TYPESCRIPT === 'true' && Module._extensions['.ts'])
|
|
117
|
+
? [ '**/*.(js|ts)', '!**/*.d.ts' ]
|
|
118
|
+
: [ '**/*.js','**/*.jsc' ];
|
|
119
|
+
|
|
120
|
+
return files;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Capture call site stack from v8.
|
|
128
|
+
* https://github.com/v8/v8/wiki/Stack-Trace-API
|
|
129
|
+
*/
|
|
130
|
+
|
|
131
|
+
function prepareObjectStackTrace(obj, stack) {
|
|
132
|
+
return stack;
|
|
133
|
+
}
|
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const debug = require('debug')('ee-core#sequencify');
|
|
4
|
-
|
|
5
|
-
function sequence(tasks, names, results, missing, recursive, nest, optional, parent) {
|
|
6
|
-
names.forEach(function(name) {
|
|
7
|
-
if (results.requires[name]) return;
|
|
8
|
-
|
|
9
|
-
const node = tasks[name];
|
|
10
|
-
|
|
11
|
-
if (!node) {
|
|
12
|
-
if (optional === true) return;
|
|
13
|
-
missing.push(name);
|
|
14
|
-
} else if (nest.includes(name)) {
|
|
15
|
-
nest.push(name);
|
|
16
|
-
recursive.push(nest.slice(0));
|
|
17
|
-
nest.pop(name);
|
|
18
|
-
} else if (node.dependencies.length || node.optionalDependencies.length) {
|
|
19
|
-
nest.push(name);
|
|
20
|
-
if (node.dependencies.length) {
|
|
21
|
-
sequence(tasks, node.dependencies, results, missing, recursive, nest, optional, name);
|
|
22
|
-
}
|
|
23
|
-
if (node.optionalDependencies.length) {
|
|
24
|
-
sequence(tasks, node.optionalDependencies, results, missing, recursive, nest, true, name);
|
|
25
|
-
}
|
|
26
|
-
nest.pop(name);
|
|
27
|
-
}
|
|
28
|
-
if (!optional) {
|
|
29
|
-
results.requires[name] = true;
|
|
30
|
-
debug('task: %s is enabled by %s', name, parent);
|
|
31
|
-
}
|
|
32
|
-
if (!results.sequence.includes(name)) {
|
|
33
|
-
results.sequence.push(name);
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// tasks: object with keys as task names
|
|
39
|
-
// names: array of task names
|
|
40
|
-
module.exports = function(tasks, names) {
|
|
41
|
-
const results = {
|
|
42
|
-
sequence: [],
|
|
43
|
-
requires: {},
|
|
44
|
-
}; // the final sequence
|
|
45
|
-
const missing = []; // missing tasks
|
|
46
|
-
const recursive = []; // recursive task dependencies
|
|
47
|
-
|
|
48
|
-
sequence(tasks, names, results, missing, recursive, [], false, 'app');
|
|
49
|
-
|
|
50
|
-
if (missing.length || recursive.length) {
|
|
51
|
-
results.sequence = []; // results are incomplete at best, completely wrong at worst, remove them to avoid confusion
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return {
|
|
55
|
-
sequence: results.sequence.filter(item => results.requires[item]),
|
|
56
|
-
missingTasks: missing,
|
|
57
|
-
recursiveDependencies: recursive,
|
|
58
|
-
};
|
|
59
|
-
};
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const debug = require('debug')('ee-core#sequencify');
|
|
4
|
+
|
|
5
|
+
function sequence(tasks, names, results, missing, recursive, nest, optional, parent) {
|
|
6
|
+
names.forEach(function(name) {
|
|
7
|
+
if (results.requires[name]) return;
|
|
8
|
+
|
|
9
|
+
const node = tasks[name];
|
|
10
|
+
|
|
11
|
+
if (!node) {
|
|
12
|
+
if (optional === true) return;
|
|
13
|
+
missing.push(name);
|
|
14
|
+
} else if (nest.includes(name)) {
|
|
15
|
+
nest.push(name);
|
|
16
|
+
recursive.push(nest.slice(0));
|
|
17
|
+
nest.pop(name);
|
|
18
|
+
} else if (node.dependencies.length || node.optionalDependencies.length) {
|
|
19
|
+
nest.push(name);
|
|
20
|
+
if (node.dependencies.length) {
|
|
21
|
+
sequence(tasks, node.dependencies, results, missing, recursive, nest, optional, name);
|
|
22
|
+
}
|
|
23
|
+
if (node.optionalDependencies.length) {
|
|
24
|
+
sequence(tasks, node.optionalDependencies, results, missing, recursive, nest, true, name);
|
|
25
|
+
}
|
|
26
|
+
nest.pop(name);
|
|
27
|
+
}
|
|
28
|
+
if (!optional) {
|
|
29
|
+
results.requires[name] = true;
|
|
30
|
+
debug('task: %s is enabled by %s', name, parent);
|
|
31
|
+
}
|
|
32
|
+
if (!results.sequence.includes(name)) {
|
|
33
|
+
results.sequence.push(name);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// tasks: object with keys as task names
|
|
39
|
+
// names: array of task names
|
|
40
|
+
module.exports = function(tasks, names) {
|
|
41
|
+
const results = {
|
|
42
|
+
sequence: [],
|
|
43
|
+
requires: {},
|
|
44
|
+
}; // the final sequence
|
|
45
|
+
const missing = []; // missing tasks
|
|
46
|
+
const recursive = []; // recursive task dependencies
|
|
47
|
+
|
|
48
|
+
sequence(tasks, names, results, missing, recursive, [], false, 'app');
|
|
49
|
+
|
|
50
|
+
if (missing.length || recursive.length) {
|
|
51
|
+
results.sequence = []; // results are incomplete at best, completely wrong at worst, remove them to avoid confusion
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
sequence: results.sequence.filter(item => results.requires[item]),
|
|
56
|
+
missingTasks: missing,
|
|
57
|
+
recursiveDependencies: recursive,
|
|
58
|
+
};
|
|
59
|
+
};
|
package/core/lib/utils/timing.js
CHANGED
|
@@ -1,77 +1,77 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const assert = require('assert');
|
|
4
|
-
const MAP = Symbol('Timing#map');
|
|
5
|
-
const LIST = Symbol('Timing#list');
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class Timing {
|
|
9
|
-
|
|
10
|
-
constructor() {
|
|
11
|
-
this._enable = true;
|
|
12
|
-
this[MAP] = new Map();
|
|
13
|
-
this[LIST] = [];
|
|
14
|
-
|
|
15
|
-
this.init();
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
init() {
|
|
19
|
-
// process start time
|
|
20
|
-
this.start('Process Start', Date.now() - Math.floor((process.uptime() * 1000)));
|
|
21
|
-
this.end('Process Start');
|
|
22
|
-
|
|
23
|
-
if (typeof process.scriptStartTime === 'number') {
|
|
24
|
-
// js script start execute time
|
|
25
|
-
this.start('Script Start', process.scriptStartTime);
|
|
26
|
-
this.end('Script Start');
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
start(name, start) {
|
|
31
|
-
if (!name || !this._enable) return;
|
|
32
|
-
|
|
33
|
-
if (this[MAP].has(name)) this.end(name);
|
|
34
|
-
|
|
35
|
-
start = start || Date.now();
|
|
36
|
-
const item = {
|
|
37
|
-
name,
|
|
38
|
-
start,
|
|
39
|
-
end: undefined,
|
|
40
|
-
duration: undefined,
|
|
41
|
-
pid: process.pid,
|
|
42
|
-
index: this[LIST].length,
|
|
43
|
-
};
|
|
44
|
-
this[MAP].set(name, item);
|
|
45
|
-
this[LIST].push(item);
|
|
46
|
-
return item;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
end(name) {
|
|
50
|
-
if (!name || !this._enable) return;
|
|
51
|
-
assert(this[MAP].has(name), `should run timing.start('${name}') first`);
|
|
52
|
-
|
|
53
|
-
const item = this[MAP].get(name);
|
|
54
|
-
item.end = Date.now();
|
|
55
|
-
item.duration = item.end - item.start;
|
|
56
|
-
return item;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
enable() {
|
|
60
|
-
this._enable = true;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
disable() {
|
|
64
|
-
this._enable = false;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
clear() {
|
|
68
|
-
this[MAP].clear();
|
|
69
|
-
this[LIST] = [];
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
toJSON() {
|
|
73
|
-
return this[LIST];
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
module.exports = Timing;
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const assert = require('assert');
|
|
4
|
+
const MAP = Symbol('Timing#map');
|
|
5
|
+
const LIST = Symbol('Timing#list');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Timing {
|
|
9
|
+
|
|
10
|
+
constructor() {
|
|
11
|
+
this._enable = true;
|
|
12
|
+
this[MAP] = new Map();
|
|
13
|
+
this[LIST] = [];
|
|
14
|
+
|
|
15
|
+
this.init();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
init() {
|
|
19
|
+
// process start time
|
|
20
|
+
this.start('Process Start', Date.now() - Math.floor((process.uptime() * 1000)));
|
|
21
|
+
this.end('Process Start');
|
|
22
|
+
|
|
23
|
+
if (typeof process.scriptStartTime === 'number') {
|
|
24
|
+
// js script start execute time
|
|
25
|
+
this.start('Script Start', process.scriptStartTime);
|
|
26
|
+
this.end('Script Start');
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
start(name, start) {
|
|
31
|
+
if (!name || !this._enable) return;
|
|
32
|
+
|
|
33
|
+
if (this[MAP].has(name)) this.end(name);
|
|
34
|
+
|
|
35
|
+
start = start || Date.now();
|
|
36
|
+
const item = {
|
|
37
|
+
name,
|
|
38
|
+
start,
|
|
39
|
+
end: undefined,
|
|
40
|
+
duration: undefined,
|
|
41
|
+
pid: process.pid,
|
|
42
|
+
index: this[LIST].length,
|
|
43
|
+
};
|
|
44
|
+
this[MAP].set(name, item);
|
|
45
|
+
this[LIST].push(item);
|
|
46
|
+
return item;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
end(name) {
|
|
50
|
+
if (!name || !this._enable) return;
|
|
51
|
+
assert(this[MAP].has(name), `should run timing.start('${name}') first`);
|
|
52
|
+
|
|
53
|
+
const item = this[MAP].get(name);
|
|
54
|
+
item.end = Date.now();
|
|
55
|
+
item.duration = item.end - item.start;
|
|
56
|
+
return item;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
enable() {
|
|
60
|
+
this._enable = true;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
disable() {
|
|
64
|
+
this._enable = false;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
clear() {
|
|
68
|
+
this[MAP].clear();
|
|
69
|
+
this[LIST] = [];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
toJSON() {
|
|
73
|
+
return this[LIST];
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
module.exports = Timing;
|