@e-mc/module 0.8.22 → 0.8.24
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/README.md +5 -5
- package/index.js +19 -33
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
## Interface
|
|
11
11
|
|
|
12
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
12
|
+
- https://www.unpkg.com/@e-mc/types@0.8.24/lib/index.d.ts
|
|
13
13
|
|
|
14
14
|
```typescript
|
|
15
15
|
import type { LogStatus } from "./squared";
|
|
@@ -231,10 +231,10 @@ interface ModuleConstructor {
|
|
|
231
231
|
|
|
232
232
|
## References
|
|
233
233
|
|
|
234
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
235
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
236
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
237
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
234
|
+
- https://www.unpkg.com/@e-mc/types@0.8.24/lib/core.d.ts
|
|
235
|
+
- https://www.unpkg.com/@e-mc/types@0.8.24/lib/logger.d.ts
|
|
236
|
+
- https://www.unpkg.com/@e-mc/types@0.8.24/lib/module.d.ts
|
|
237
|
+
- https://www.unpkg.com/@e-mc/types@0.8.24/lib/node.d.ts
|
|
238
238
|
|
|
239
239
|
## LICENSE
|
|
240
240
|
|
package/index.js
CHANGED
|
@@ -129,6 +129,8 @@ const MEMORY_CACHE_DISK = {
|
|
|
129
129
|
exclude: null
|
|
130
130
|
};
|
|
131
131
|
const REGEXP_TORRENT = /^(?:magnet:\?xt=|(?:https?|s?ftp):\/\/[^/][^\n]*?\.(?:torrent|metalink|meta4)(?:\?[^\n]*)?$)/i;
|
|
132
|
+
const REGEXP_CLIESCAPE = /[^\w+-.,/:@]/g;
|
|
133
|
+
const REGEXP_CLIOPTION = /^(-[^\s=]+|--[^-\s=][^\s=]*)(=)?\s*(.*)$/s;
|
|
132
134
|
const RESERVED_SHELL = [
|
|
133
135
|
'if',
|
|
134
136
|
'then',
|
|
@@ -679,7 +681,7 @@ function formatPercent(value, precision) {
|
|
|
679
681
|
return value.toPrecision(value < 1 ? 2 : precision) + '%';
|
|
680
682
|
}
|
|
681
683
|
const hideAbort = (err) => err.name === 'AbortError' && SETTINGS.abort === false;
|
|
682
|
-
const asFile = (value) =>
|
|
684
|
+
const asFile = (value) => typeof value === 'string' ? PLATFORM_WIN32 ? value.trim() : value : value instanceof URL && value.protocol === 'file:' ? url.fileURLToPath(value) : '';
|
|
683
685
|
const wrapQuote = (value) => '"' + value.replace(/"/g, '\\"') + '"';
|
|
684
686
|
const isFunction = (value) => typeof value === 'function';
|
|
685
687
|
const isFileURL = (value) => /^file:\/\//i.test(value);
|
|
@@ -714,7 +716,7 @@ class Module extends EventEmitter {
|
|
|
714
716
|
this[_f] = new AbortController();
|
|
715
717
|
this[_g] = null;
|
|
716
718
|
}
|
|
717
|
-
static get VERSION() { return "0.8.
|
|
719
|
+
static get VERSION() { return "0.8.24"; }
|
|
718
720
|
static get LOG_TYPE() { return types_1.LOG_TYPE; }
|
|
719
721
|
static get STATUS_TYPE() { return types_1.STATUS_TYPE; }
|
|
720
722
|
static get MAX_TIMEOUT() { return 2147483647; }
|
|
@@ -800,7 +802,7 @@ class Module extends EventEmitter {
|
|
|
800
802
|
if (error && hideAbort(message)) {
|
|
801
803
|
return;
|
|
802
804
|
}
|
|
803
|
-
if (options.type) {
|
|
805
|
+
if (typeof options.type === 'number') {
|
|
804
806
|
type |= options.type;
|
|
805
807
|
}
|
|
806
808
|
const BROADCAST_OUT = VALUES["broadcast.out"];
|
|
@@ -1305,7 +1307,7 @@ class Module extends EventEmitter {
|
|
|
1305
1307
|
filename = undefined;
|
|
1306
1308
|
}
|
|
1307
1309
|
if (typeof value === 'string') {
|
|
1308
|
-
let pathname = value.trim(), convert = true;
|
|
1310
|
+
let pathname = PLATFORM_WIN32 ? value.trim() : value, convert = true;
|
|
1309
1311
|
if (normalize) {
|
|
1310
1312
|
pathname = path.normalize(pathname);
|
|
1311
1313
|
convert = PLATFORM_WIN32;
|
|
@@ -1412,7 +1414,7 @@ class Module extends EventEmitter {
|
|
|
1412
1414
|
return false;
|
|
1413
1415
|
}
|
|
1414
1416
|
static resolveFile(value) {
|
|
1415
|
-
if (isFileURL(value = value instanceof URL ? value.toString() : value
|
|
1417
|
+
if (isFileURL(value = value instanceof URL ? value.toString() : value)) {
|
|
1416
1418
|
try {
|
|
1417
1419
|
return url.fileURLToPath(value);
|
|
1418
1420
|
}
|
|
@@ -1427,7 +1429,7 @@ class Module extends EventEmitter {
|
|
|
1427
1429
|
}
|
|
1428
1430
|
static resolvePath(value, base) {
|
|
1429
1431
|
try {
|
|
1430
|
-
if (this.isURL(value
|
|
1432
|
+
if (this.isURL(value)) {
|
|
1431
1433
|
return isFileURL(value) ? url.fileURLToPath(value) : new URL(value).href;
|
|
1432
1434
|
}
|
|
1433
1435
|
if (base instanceof URL || this.isURL(base)) {
|
|
@@ -1459,7 +1461,7 @@ class Module extends EventEmitter {
|
|
|
1459
1461
|
if (typeof flags === 'boolean') {
|
|
1460
1462
|
flags = flags ? 2 : 0;
|
|
1461
1463
|
}
|
|
1462
|
-
let result = value.trim();
|
|
1464
|
+
let result = PLATFORM_WIN32 ? value.trim() : value;
|
|
1463
1465
|
result = flags & 1 ? path.resolve(result) : path.normalize(result);
|
|
1464
1466
|
if ((flags & 3) && result.length) {
|
|
1465
1467
|
result = ensureDir(result);
|
|
@@ -2090,12 +2092,10 @@ class Module extends EventEmitter {
|
|
|
2090
2092
|
}
|
|
2091
2093
|
static sanitizeArgs(values, doubleQuote) {
|
|
2092
2094
|
const result = typeof values === 'string' ? [values] : values;
|
|
2093
|
-
const pattern = /[^\w+-.,/:@]/g;
|
|
2094
|
-
const sanitize = (value) => value.replace(pattern, capture => capture === '\n' ? "'\n'" : (capture === '$' || capture === '`' ? '\\' : '') + '\\' + capture);
|
|
2095
2095
|
for (let i = 0; i < result.length; ++i) {
|
|
2096
2096
|
let value = result[i].trim(), leading = '';
|
|
2097
2097
|
if (value !== '--') {
|
|
2098
|
-
const opt =
|
|
2098
|
+
const opt = REGEXP_CLIOPTION.exec(value);
|
|
2099
2099
|
if (opt) {
|
|
2100
2100
|
if (!opt[2] && !opt[3]) {
|
|
2101
2101
|
result[i] = opt[1];
|
|
@@ -2105,7 +2105,7 @@ class Module extends EventEmitter {
|
|
|
2105
2105
|
value = opt[3];
|
|
2106
2106
|
}
|
|
2107
2107
|
if (value) {
|
|
2108
|
-
const quoted = /^(["'])(.*)\1
|
|
2108
|
+
const quoted = /^(["'])(.*)\1$/s.exec(value);
|
|
2109
2109
|
if (PLATFORM_WIN32) {
|
|
2110
2110
|
if (quoted) {
|
|
2111
2111
|
if (quoted[1] === '"') {
|
|
@@ -2118,33 +2118,19 @@ class Module extends EventEmitter {
|
|
|
2118
2118
|
value = wrapQuote(value);
|
|
2119
2119
|
}
|
|
2120
2120
|
}
|
|
2121
|
-
else {
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
if (quoted[1] === "'") {
|
|
2125
|
-
result[i] = leading + value;
|
|
2126
|
-
continue;
|
|
2127
|
-
}
|
|
2128
|
-
value = quoted[2];
|
|
2129
|
-
type = true;
|
|
2130
|
-
}
|
|
2131
|
-
if (pattern.test(value)) {
|
|
2132
|
-
if (type) {
|
|
2133
|
-
value = '"' + sanitize(value) + '"';
|
|
2134
|
-
}
|
|
2135
|
-
else {
|
|
2136
|
-
value = "'" + value.replace(/'/g, "'\\''") + "'";
|
|
2137
|
-
}
|
|
2121
|
+
else if (!quoted) {
|
|
2122
|
+
if (REGEXP_CLIESCAPE.test(value)) {
|
|
2123
|
+
value = doubleQuote ? `"${value.replace(/(?<!\\)"/g, '\\"')}"` : `'${value.replace(/'/g, "'\\''")}'`;
|
|
2138
2124
|
}
|
|
2139
2125
|
else if (RESERVED_SHELL.includes(value)) {
|
|
2140
|
-
value =
|
|
2126
|
+
value = `'${value}'`;
|
|
2141
2127
|
}
|
|
2142
2128
|
}
|
|
2143
2129
|
}
|
|
2144
2130
|
else if (opt) {
|
|
2145
2131
|
leading = leading.trim();
|
|
2146
2132
|
if (!PLATFORM_WIN32 && leading.length > 2 && leading[1] !== '-') {
|
|
2147
|
-
leading
|
|
2133
|
+
leading.replace(REGEXP_CLIESCAPE, capture => '\\' + capture);
|
|
2148
2134
|
}
|
|
2149
2135
|
}
|
|
2150
2136
|
}
|
|
@@ -3391,12 +3377,12 @@ class Module extends EventEmitter {
|
|
|
3391
3377
|
}
|
|
3392
3378
|
}
|
|
3393
3379
|
writeLog(type, value, timeStamp, duration) {
|
|
3394
|
-
let queue;
|
|
3380
|
+
let queue = false;
|
|
3395
3381
|
if ((0, types_1.isObject)(type)) {
|
|
3396
3382
|
if (typeof value === 'boolean') {
|
|
3397
3383
|
queue = value;
|
|
3398
3384
|
}
|
|
3399
|
-
|
|
3385
|
+
value = type.value;
|
|
3400
3386
|
}
|
|
3401
3387
|
const output = Module.asString(value);
|
|
3402
3388
|
if (output) {
|
|
@@ -3424,7 +3410,7 @@ class Module extends EventEmitter {
|
|
|
3424
3410
|
from = timeStamp;
|
|
3425
3411
|
timeStamp = 0;
|
|
3426
3412
|
}
|
|
3427
|
-
else if ((0, types_1.
|
|
3413
|
+
else if ((0, types_1.isPlainObject)(timeStamp)) {
|
|
3428
3414
|
({ timeStamp, duration, from, source } = timeStamp);
|
|
3429
3415
|
}
|
|
3430
3416
|
const name = types_1.STATUS_TYPE[type] || types_1.STATUS_TYPE[type = 0];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/module",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.24",
|
|
4
4
|
"description": "Module base class for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/types": "0.8.
|
|
23
|
+
"@e-mc/types": "0.8.24",
|
|
24
24
|
"abort-controller": "^3.0.0",
|
|
25
25
|
"chalk": "4.1.2",
|
|
26
26
|
"event-target-shim": "^5.0.1",
|