ee-core 2.9.2 → 2.10.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.
- 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 +86 -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 +58 -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
package/utils/get-port/index.js
CHANGED
|
@@ -1,148 +1,148 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
const net = require('net');
|
|
3
|
-
const os = require('os');
|
|
4
|
-
|
|
5
|
-
class Locked extends Error {
|
|
6
|
-
constructor(port) {
|
|
7
|
-
super(`${port} is locked`);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const lockedPorts = {
|
|
12
|
-
old: new Set(),
|
|
13
|
-
young: new Set()
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
// On this interval, the old locked ports are discarded,
|
|
17
|
-
// the young locked ports are moved to old locked ports,
|
|
18
|
-
// and a new young set for locked ports are created.
|
|
19
|
-
const releaseOldLockedPortsIntervalMs = 1000 * 15;
|
|
20
|
-
|
|
21
|
-
// Lazily create interval on first use
|
|
22
|
-
let interval;
|
|
23
|
-
|
|
24
|
-
const getLocalHosts = () => {
|
|
25
|
-
const interfaces = os.networkInterfaces();
|
|
26
|
-
|
|
27
|
-
// Add undefined value for createServer function to use default host,
|
|
28
|
-
// and default IPv4 host in case createServer defaults to IPv6.
|
|
29
|
-
const results = new Set([undefined, '0.0.0.0']);
|
|
30
|
-
|
|
31
|
-
for (const _interface of Object.values(interfaces)) {
|
|
32
|
-
for (const config of _interface) {
|
|
33
|
-
results.add(config.address);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return results;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const checkAvailablePort = options =>
|
|
41
|
-
new Promise((resolve, reject) => {
|
|
42
|
-
const server = net.createServer();
|
|
43
|
-
server.unref();
|
|
44
|
-
server.on('error', reject);
|
|
45
|
-
|
|
46
|
-
server.listen(options, () => {
|
|
47
|
-
const {port} = server.address();
|
|
48
|
-
server.close(() => {
|
|
49
|
-
resolve(port);
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
const getAvailablePort = async (options, hosts) => {
|
|
55
|
-
if (options.host || options.port === 0) {
|
|
56
|
-
return checkAvailablePort(options);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
for (const host of hosts) {
|
|
60
|
-
try {
|
|
61
|
-
await checkAvailablePort({port: options.port, host}); // eslint-disable-line no-await-in-loop
|
|
62
|
-
} catch (error) {
|
|
63
|
-
if (!['EADDRNOTAVAIL', 'EINVAL'].includes(error.code)) {
|
|
64
|
-
throw error;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return options.port;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
const portCheckSequence = function * (ports) {
|
|
73
|
-
if (ports) {
|
|
74
|
-
yield * ports;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
yield 0; // Fall back to 0 if anything else failed
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
module.exports = async options => {
|
|
81
|
-
let ports;
|
|
82
|
-
|
|
83
|
-
if (options) {
|
|
84
|
-
ports = typeof options.port === 'number' ? [options.port] : options.port;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (interval === undefined) {
|
|
88
|
-
interval = setInterval(() => {
|
|
89
|
-
lockedPorts.old = lockedPorts.young;
|
|
90
|
-
lockedPorts.young = new Set();
|
|
91
|
-
}, releaseOldLockedPortsIntervalMs);
|
|
92
|
-
|
|
93
|
-
// Does not exist in some environments (Electron, Jest jsdom env, browser, etc).
|
|
94
|
-
if (interval.unref) {
|
|
95
|
-
interval.unref();
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const hosts = getLocalHosts();
|
|
100
|
-
|
|
101
|
-
for (const port of portCheckSequence(ports)) {
|
|
102
|
-
try {
|
|
103
|
-
let availablePort = await getAvailablePort({...options, port}, hosts); // eslint-disable-line no-await-in-loop
|
|
104
|
-
while (lockedPorts.old.has(availablePort) || lockedPorts.young.has(availablePort)) {
|
|
105
|
-
if (port !== 0) {
|
|
106
|
-
throw new Locked(port);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
availablePort = await getAvailablePort({...options, port}, hosts); // eslint-disable-line no-await-in-loop
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
lockedPorts.young.add(availablePort);
|
|
113
|
-
return availablePort;
|
|
114
|
-
} catch (error) {
|
|
115
|
-
if (!['EADDRINUSE', 'EACCES'].includes(error.code) && !(error instanceof Locked)) {
|
|
116
|
-
throw error;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
throw new Error('No available ports found');
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
module.exports.makeRange = (from, to) => {
|
|
125
|
-
if (!Number.isInteger(from) || !Number.isInteger(to)) {
|
|
126
|
-
throw new TypeError('`from` and `to` must be integer numbers');
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (from < 1024 || from > 65535) {
|
|
130
|
-
throw new RangeError('`from` must be between 1024 and 65535');
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if (to < 1024 || to > 65536) {
|
|
134
|
-
throw new RangeError('`to` must be between 1024 and 65536');
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
if (to < from) {
|
|
138
|
-
throw new RangeError('`to` must be greater than or equal to `from`');
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const generator = function * (from, to) {
|
|
142
|
-
for (let port = from; port <= to; port++) {
|
|
143
|
-
yield port;
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
return generator(from, to);
|
|
148
|
-
};
|
|
1
|
+
'use strict';
|
|
2
|
+
const net = require('net');
|
|
3
|
+
const os = require('os');
|
|
4
|
+
|
|
5
|
+
class Locked extends Error {
|
|
6
|
+
constructor(port) {
|
|
7
|
+
super(`${port} is locked`);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const lockedPorts = {
|
|
12
|
+
old: new Set(),
|
|
13
|
+
young: new Set()
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// On this interval, the old locked ports are discarded,
|
|
17
|
+
// the young locked ports are moved to old locked ports,
|
|
18
|
+
// and a new young set for locked ports are created.
|
|
19
|
+
const releaseOldLockedPortsIntervalMs = 1000 * 15;
|
|
20
|
+
|
|
21
|
+
// Lazily create interval on first use
|
|
22
|
+
let interval;
|
|
23
|
+
|
|
24
|
+
const getLocalHosts = () => {
|
|
25
|
+
const interfaces = os.networkInterfaces();
|
|
26
|
+
|
|
27
|
+
// Add undefined value for createServer function to use default host,
|
|
28
|
+
// and default IPv4 host in case createServer defaults to IPv6.
|
|
29
|
+
const results = new Set([undefined, '0.0.0.0']);
|
|
30
|
+
|
|
31
|
+
for (const _interface of Object.values(interfaces)) {
|
|
32
|
+
for (const config of _interface) {
|
|
33
|
+
results.add(config.address);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return results;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const checkAvailablePort = options =>
|
|
41
|
+
new Promise((resolve, reject) => {
|
|
42
|
+
const server = net.createServer();
|
|
43
|
+
server.unref();
|
|
44
|
+
server.on('error', reject);
|
|
45
|
+
|
|
46
|
+
server.listen(options, () => {
|
|
47
|
+
const {port} = server.address();
|
|
48
|
+
server.close(() => {
|
|
49
|
+
resolve(port);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const getAvailablePort = async (options, hosts) => {
|
|
55
|
+
if (options.host || options.port === 0) {
|
|
56
|
+
return checkAvailablePort(options);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
for (const host of hosts) {
|
|
60
|
+
try {
|
|
61
|
+
await checkAvailablePort({port: options.port, host}); // eslint-disable-line no-await-in-loop
|
|
62
|
+
} catch (error) {
|
|
63
|
+
if (!['EADDRNOTAVAIL', 'EINVAL'].includes(error.code)) {
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return options.port;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const portCheckSequence = function * (ports) {
|
|
73
|
+
if (ports) {
|
|
74
|
+
yield * ports;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
yield 0; // Fall back to 0 if anything else failed
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
module.exports = async options => {
|
|
81
|
+
let ports;
|
|
82
|
+
|
|
83
|
+
if (options) {
|
|
84
|
+
ports = typeof options.port === 'number' ? [options.port] : options.port;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (interval === undefined) {
|
|
88
|
+
interval = setInterval(() => {
|
|
89
|
+
lockedPorts.old = lockedPorts.young;
|
|
90
|
+
lockedPorts.young = new Set();
|
|
91
|
+
}, releaseOldLockedPortsIntervalMs);
|
|
92
|
+
|
|
93
|
+
// Does not exist in some environments (Electron, Jest jsdom env, browser, etc).
|
|
94
|
+
if (interval.unref) {
|
|
95
|
+
interval.unref();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const hosts = getLocalHosts();
|
|
100
|
+
|
|
101
|
+
for (const port of portCheckSequence(ports)) {
|
|
102
|
+
try {
|
|
103
|
+
let availablePort = await getAvailablePort({...options, port}, hosts); // eslint-disable-line no-await-in-loop
|
|
104
|
+
while (lockedPorts.old.has(availablePort) || lockedPorts.young.has(availablePort)) {
|
|
105
|
+
if (port !== 0) {
|
|
106
|
+
throw new Locked(port);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
availablePort = await getAvailablePort({...options, port}, hosts); // eslint-disable-line no-await-in-loop
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
lockedPorts.young.add(availablePort);
|
|
113
|
+
return availablePort;
|
|
114
|
+
} catch (error) {
|
|
115
|
+
if (!['EADDRINUSE', 'EACCES'].includes(error.code) && !(error instanceof Locked)) {
|
|
116
|
+
throw error;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
throw new Error('No available ports found');
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
module.exports.makeRange = (from, to) => {
|
|
125
|
+
if (!Number.isInteger(from) || !Number.isInteger(to)) {
|
|
126
|
+
throw new TypeError('`from` and `to` must be integer numbers');
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (from < 1024 || from > 65535) {
|
|
130
|
+
throw new RangeError('`from` must be between 1024 and 65535');
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (to < 1024 || to > 65536) {
|
|
134
|
+
throw new RangeError('`to` must be between 1024 and 65536');
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (to < from) {
|
|
138
|
+
throw new RangeError('`to` must be greater than or equal to `from`');
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const generator = function * (from, to) {
|
|
142
|
+
for (let port = from; port <= to; port++) {
|
|
143
|
+
yield port;
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
return generator(from, to);
|
|
148
|
+
};
|