ee-core 1.5.2-beta.1 → 2.0.0-beta.1

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.
Files changed (72) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +2 -2
  3. package/addon/window/index.js +91 -91
  4. package/bin/tools.js +18 -18
  5. package/config/config.default.js +287 -280
  6. package/core/index.js +12 -12
  7. package/core/lib/ee.js +218 -218
  8. package/core/lib/loader/context_loader.js +106 -106
  9. package/core/lib/loader/ee_loader.js +461 -457
  10. package/core/lib/loader/file_loader.js +325 -325
  11. package/core/lib/loader/mixin/addon.js +32 -32
  12. package/core/lib/loader/mixin/config.js +135 -135
  13. package/core/lib/loader/mixin/controller.js +125 -124
  14. package/core/lib/loader/mixin/service.js +28 -28
  15. package/core/lib/utils/base_context_class.js +34 -34
  16. package/core/lib/utils/function.js +30 -0
  17. package/core/lib/utils/index.js +127 -127
  18. package/core/lib/utils/sequencify.js +59 -59
  19. package/core/lib/utils/timing.js +77 -77
  20. package/index.js +49 -49
  21. package/lib/appLoader.js +48 -53
  22. package/lib/application.js +85 -84
  23. package/lib/baseApp.js +114 -131
  24. package/lib/eeApp.js +325 -359
  25. package/{lib/constant.js → module/const/index.js} +12 -9
  26. package/{lib/httpclient.js → module/httpclient/index.js} +170 -136
  27. package/module/jobs/child/forkProcess.js +99 -0
  28. package/module/jobs/child/index.js +33 -0
  29. package/module/jobs/index.js +55 -0
  30. package/module/jobs/renderer/index.js +140 -0
  31. package/module/jobs/renderer/loadView.js +40 -0
  32. package/module/loader/index.js +78 -0
  33. package/module/log/index.js +53 -0
  34. package/module/log/logger.js +61 -0
  35. package/module/message/index.js +13 -0
  36. package/module/message/ipcMain.js +160 -0
  37. package/module/message/ipcRender.js +0 -0
  38. package/{lib → module}/socket/httpServer.js +142 -142
  39. package/{lib → module}/socket/io.js +23 -23
  40. package/{lib → module}/socket/ipcServer.js +106 -108
  41. package/{lib → module}/socket/socketClient.js +51 -50
  42. package/{lib → module}/socket/socketServer.js +77 -76
  43. package/module/socket/start.js +22 -0
  44. package/{lib → module}/storage/index.js +35 -34
  45. package/module/storage/jsondb/adapters/Base.js +14 -0
  46. package/module/storage/jsondb/adapters/FileSync.js +32 -0
  47. package/{lib/storage/lowdb → module/storage/jsondb}/main.js +42 -46
  48. package/{lib/storage/lowdbStorage.js → module/storage/jsondbStorage.js} +98 -99
  49. package/{lib → module}/storage/sqliteStorage.js +123 -127
  50. package/module/utils/copyto.js +161 -0
  51. package/module/utils/helper.js +117 -0
  52. package/module/utils/index.js +120 -0
  53. package/module/utils/json.js +72 -0
  54. package/module/utils/ps.js +175 -0
  55. package/{utils → module/utils}/wrap.js +35 -37
  56. package/package.json +44 -48
  57. package/tools/encrypt.js +274 -274
  58. package/tools/replaceDist.js +61 -61
  59. package/utils/index.js +128 -246
  60. package/lib/logger.js +0 -47
  61. package/lib/socket/start.js +0 -22
  62. package/lib/storage/lowdb/adapters/Base.js +0 -15
  63. package/lib/storage/lowdb/adapters/FileAsync.js +0 -41
  64. package/lib/storage/lowdb/adapters/FileSync.js +0 -39
  65. package/lib/storage/lowdb/adapters/LocalStorage.js +0 -20
  66. package/lib/storage/lowdb/adapters/Memory.js +0 -8
  67. package/lib/storage/lowdb/adapters/_stringify.js +0 -4
  68. package/lib/storage/lowdb/common.js +0 -33
  69. package/lib/storage/lowdb/fp.js +0 -23
  70. package/lib/storage/lowdb/is-promise.js +0 -6
  71. package/lib/storage/lowdb/nano.js +0 -5
  72. package/utils/common.js +0 -91
@@ -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;
@@ -0,0 +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,127 +1,127 @@
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('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.exports = {
18
- extensions: Module._extensions,
19
-
20
- loadFile(filepath) {
21
- try {
22
- // if not js module, just return content buffer
23
- const extname = path.extname(filepath);
24
- if (extname && !Module._extensions[extname]) {
25
- return fs.readFileSync(filepath);
26
- }
27
-
28
- // require js module
29
- const obj = require(filepath);
30
- if (!obj) return obj;
31
- // it's es module
32
- if (obj.__esModule) return 'default' in obj ? obj.default : obj;
33
- return obj;
34
- } catch (err) {
35
- err.message = `[ee-core] load file: ${filepath}, error: ${err.message}`;
36
- throw err;
37
- }
38
- },
39
-
40
- methods: [ 'head', 'options', 'get', 'put', 'patch', 'post', 'delete' ],
41
-
42
- async callFn(fn, args, ctx) {
43
- args = args || [];
44
- if (!is.function(fn)) return;
45
- if (is.generatorFunction(fn)) fn = co.wrap(fn);
46
- return ctx ? fn.call(ctx, ...args) : fn(...args);
47
- },
48
-
49
- middleware(fn) {
50
- return is.generatorFunction(fn) ? convert(fn) : fn;
51
- },
52
-
53
- getCalleeFromStack(withLine, stackIndex) {
54
- stackIndex = stackIndex === undefined ? 2 : stackIndex;
55
- const limit = Error.stackTraceLimit;
56
- const prep = Error.prepareStackTrace;
57
-
58
- Error.prepareStackTrace = prepareObjectStackTrace;
59
- Error.stackTraceLimit = 5;
60
-
61
- // capture the stack
62
- const obj = {};
63
- Error.captureStackTrace(obj);
64
- let callSite = obj.stack[stackIndex];
65
- let fileName;
66
- /* istanbul ignore else */
67
- if (callSite) {
68
- fileName = callSite.getFileName();
69
- /* istanbul ignore if */
70
- if (fileName && fileName.endsWith('egg-mock/lib/app.js')) {
71
- // TODO: add test
72
- callSite = obj.stack[stackIndex + 1];
73
- fileName = callSite.getFileName();
74
- }
75
- }
76
-
77
- Error.prepareStackTrace = prep;
78
- Error.stackTraceLimit = limit;
79
-
80
- /* istanbul ignore if */
81
- if (!callSite || !fileName) return '<anonymous>';
82
- if (!withLine) return fileName;
83
- return `${fileName}:${callSite.getLineNumber()}:${callSite.getColumnNumber()}`;
84
- },
85
-
86
- getResolvedFilename(filepath, baseDir) {
87
- const reg = /[/\\]/g;
88
- return filepath.replace(baseDir + path.sep, '').replace(reg, '/');
89
- },
90
-
91
- /**
92
- * 字节码类
93
- */
94
- isBytecodeClass (exports) {
95
- let isClass = false;
96
-
97
- // 标识
98
- if (exports.toString().indexOf('[class') != -1) {
99
- isClass = true;
100
- }
101
- // TODO 更严谨的判断,应该加上文件名和路径
102
-
103
- return isClass;
104
- },
105
-
106
- /**
107
- * 文件类型
108
- */
109
- filePatterns () {
110
- const files = (process.env.EE_TYPESCRIPT === 'true' && Module._extensions['.ts'])
111
- ? [ '**/*.(js|ts)', '!**/*.d.ts' ]
112
- : [ '**/*.js','**/*.jsc' ];
113
-
114
- return files;
115
- }
116
-
117
- };
118
-
119
-
120
- /**
121
- * Capture call site stack from v8.
122
- * https://github.com/v8/v8/wiki/Stack-Trace-API
123
- */
124
-
125
- function prepareObjectStackTrace(obj, stack) {
126
- return stack;
127
- }
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('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.exports = {
18
+ extensions: Module._extensions,
19
+
20
+ loadFile(filepath) {
21
+ try {
22
+ // if not js module, just return content buffer
23
+ const extname = path.extname(filepath);
24
+ if (extname && !Module._extensions[extname]) {
25
+ return fs.readFileSync(filepath);
26
+ }
27
+
28
+ // require js module
29
+ const obj = require(filepath);
30
+ if (!obj) return obj;
31
+ // it's es module
32
+ if (obj.__esModule) return 'default' in obj ? obj.default : obj;
33
+ return obj;
34
+ } catch (err) {
35
+ err.message = `[ee-core] load file: ${filepath}, error: ${err.message}`;
36
+ throw err;
37
+ }
38
+ },
39
+
40
+ methods: [ 'head', 'options', 'get', 'put', 'patch', 'post', 'delete' ],
41
+
42
+ async callFn(fn, args, ctx) {
43
+ args = args || [];
44
+ if (!is.function(fn)) return;
45
+ if (is.generatorFunction(fn)) fn = co.wrap(fn);
46
+ return ctx ? fn.call(ctx, ...args) : fn(...args);
47
+ },
48
+
49
+ middleware(fn) {
50
+ return is.generatorFunction(fn) ? convert(fn) : fn;
51
+ },
52
+
53
+ getCalleeFromStack(withLine, stackIndex) {
54
+ stackIndex = stackIndex === undefined ? 2 : stackIndex;
55
+ const limit = Error.stackTraceLimit;
56
+ const prep = Error.prepareStackTrace;
57
+
58
+ Error.prepareStackTrace = prepareObjectStackTrace;
59
+ Error.stackTraceLimit = 5;
60
+
61
+ // capture the stack
62
+ const obj = {};
63
+ Error.captureStackTrace(obj);
64
+ let callSite = obj.stack[stackIndex];
65
+ let fileName;
66
+ /* istanbul ignore else */
67
+ if (callSite) {
68
+ fileName = callSite.getFileName();
69
+ /* istanbul ignore if */
70
+ if (fileName && fileName.endsWith('egg-mock/lib/app.js')) {
71
+ // TODO: add test
72
+ callSite = obj.stack[stackIndex + 1];
73
+ fileName = callSite.getFileName();
74
+ }
75
+ }
76
+
77
+ Error.prepareStackTrace = prep;
78
+ Error.stackTraceLimit = limit;
79
+
80
+ /* istanbul ignore if */
81
+ if (!callSite || !fileName) return '<anonymous>';
82
+ if (!withLine) return fileName;
83
+ return `${fileName}:${callSite.getLineNumber()}:${callSite.getColumnNumber()}`;
84
+ },
85
+
86
+ getResolvedFilename(filepath, baseDir) {
87
+ const reg = /[/\\]/g;
88
+ return filepath.replace(baseDir + path.sep, '').replace(reg, '/');
89
+ },
90
+
91
+ /**
92
+ * 字节码类
93
+ */
94
+ isBytecodeClass (exports) {
95
+ let isClass = false;
96
+
97
+ // 标识
98
+ if (exports.toString().indexOf('[class') != -1) {
99
+ isClass = true;
100
+ }
101
+ // TODO 更严谨的判断,应该加上文件名和路径
102
+
103
+ return isClass;
104
+ },
105
+
106
+ /**
107
+ * 文件类型
108
+ */
109
+ filePatterns () {
110
+ const files = (process.env.EE_TYPESCRIPT === 'true' && Module._extensions['.ts'])
111
+ ? [ '**/*.(js|ts)', '!**/*.d.ts' ]
112
+ : [ '**/*.js','**/*.jsc' ];
113
+
114
+ return files;
115
+ }
116
+
117
+ };
118
+
119
+
120
+ /**
121
+ * Capture call site stack from v8.
122
+ * https://github.com/v8/v8/wiki/Stack-Trace-API
123
+ */
124
+
125
+ function prepareObjectStackTrace(obj, stack) {
126
+ return stack;
127
+ }
@@ -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
+ };
@@ -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;