@e-mc/module 0.9.16 → 0.9.18
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 +6 -6
- 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
|
-
* [View Source](https://www.unpkg.com/@e-mc/types@0.9.
|
|
12
|
+
* [View Source](https://www.unpkg.com/@e-mc/types@0.9.18/lib/index.d.ts)
|
|
13
13
|
|
|
14
14
|
```typescript
|
|
15
15
|
import type { LogStatus } from "./squared";
|
|
@@ -394,11 +394,11 @@ type ForegroundColor = typeof IForegroundColor | `#${string}`;
|
|
|
394
394
|
|
|
395
395
|
## References
|
|
396
396
|
|
|
397
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
398
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
399
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
400
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
401
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
397
|
+
- https://www.unpkg.com/@e-mc/types@0.9.18/lib/core.d.ts
|
|
398
|
+
- https://www.unpkg.com/@e-mc/types@0.9.18/lib/logger.d.ts
|
|
399
|
+
- https://www.unpkg.com/@e-mc/types@0.9.18/lib/module.d.ts
|
|
400
|
+
- https://www.unpkg.com/@e-mc/types@0.9.18/lib/node.d.ts
|
|
401
|
+
- https://www.unpkg.com/@e-mc/types@0.9.18/lib/settings.d.ts
|
|
402
402
|
|
|
403
403
|
* https://www.npmjs.com/package/@types/node
|
|
404
404
|
|
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',
|
|
@@ -702,7 +704,7 @@ function formatPercent(value, precision) {
|
|
|
702
704
|
return value.toPrecision(value < 1 ? 2 : precision) + '%';
|
|
703
705
|
}
|
|
704
706
|
const hideAbort = (err) => err.name === 'AbortError' && SETTINGS.abort === false;
|
|
705
|
-
const asFile = (value) => typeof value === 'string' ? value.trim() : value instanceof URL && value.protocol === 'file:' ? url.fileURLToPath(value) : '';
|
|
707
|
+
const asFile = (value) => typeof value === 'string' ? PLATFORM_WIN32 ? value.trim() : value : value instanceof URL && value.protocol === 'file:' ? url.fileURLToPath(value) : '';
|
|
706
708
|
const wrapQuote = (value) => '"' + value.replace(/"/g, '\\"') + '"';
|
|
707
709
|
const isFunction = (value) => typeof value === 'function';
|
|
708
710
|
const isFileURL = (value) => /^file:\/\//i.test(value);
|
|
@@ -738,7 +740,7 @@ class Module extends EventEmitter {
|
|
|
738
740
|
this[_f] = new AbortController();
|
|
739
741
|
this[_g] = null;
|
|
740
742
|
}
|
|
741
|
-
static get VERSION() { return "0.9.
|
|
743
|
+
static get VERSION() { return "0.9.18"; }
|
|
742
744
|
static get LOG_TYPE() { return types_1.LOG_TYPE; }
|
|
743
745
|
static get STATUS_TYPE() { return types_1.STATUS_TYPE; }
|
|
744
746
|
static get MAX_TIMEOUT() { return 2147483647; }
|
|
@@ -824,7 +826,7 @@ class Module extends EventEmitter {
|
|
|
824
826
|
if (error && hideAbort(message)) {
|
|
825
827
|
return;
|
|
826
828
|
}
|
|
827
|
-
if (options.type) {
|
|
829
|
+
if (typeof options.type === 'number') {
|
|
828
830
|
type |= options.type;
|
|
829
831
|
}
|
|
830
832
|
const BROADCAST_OUT = VALUES["broadcast.out"];
|
|
@@ -1330,7 +1332,7 @@ class Module extends EventEmitter {
|
|
|
1330
1332
|
filename = undefined;
|
|
1331
1333
|
}
|
|
1332
1334
|
if (typeof value === 'string') {
|
|
1333
|
-
let pathname = value.trim(), convert = true;
|
|
1335
|
+
let pathname = PLATFORM_WIN32 ? value.trim() : value, convert = true;
|
|
1334
1336
|
if (normalize) {
|
|
1335
1337
|
pathname = path.normalize(pathname);
|
|
1336
1338
|
convert = PLATFORM_WIN32;
|
|
@@ -1441,7 +1443,7 @@ class Module extends EventEmitter {
|
|
|
1441
1443
|
return false;
|
|
1442
1444
|
}
|
|
1443
1445
|
static resolveFile(value) {
|
|
1444
|
-
if (isFileURL(value = value instanceof URL ? value.toString() : value
|
|
1446
|
+
if (isFileURL(value = value instanceof URL ? value.toString() : value)) {
|
|
1445
1447
|
try {
|
|
1446
1448
|
return url.fileURLToPath(value);
|
|
1447
1449
|
}
|
|
@@ -1456,7 +1458,7 @@ class Module extends EventEmitter {
|
|
|
1456
1458
|
}
|
|
1457
1459
|
static resolvePath(value, base) {
|
|
1458
1460
|
try {
|
|
1459
|
-
if (this.isURL(value
|
|
1461
|
+
if (this.isURL(value)) {
|
|
1460
1462
|
return isFileURL(value) ? url.fileURLToPath(value) : new URL(value).href;
|
|
1461
1463
|
}
|
|
1462
1464
|
if (base instanceof URL || this.isURL(base)) {
|
|
@@ -1488,7 +1490,7 @@ class Module extends EventEmitter {
|
|
|
1488
1490
|
if (typeof flags === 'boolean') {
|
|
1489
1491
|
flags = flags ? 2 : 0;
|
|
1490
1492
|
}
|
|
1491
|
-
let result = value.trim();
|
|
1493
|
+
let result = PLATFORM_WIN32 ? value.trim() : value;
|
|
1492
1494
|
result = flags & 1 ? path.resolve(result) : path.normalize(result);
|
|
1493
1495
|
if ((flags & 3) && result.length) {
|
|
1494
1496
|
result = ensureDir(result);
|
|
@@ -2164,12 +2166,10 @@ class Module extends EventEmitter {
|
|
|
2164
2166
|
}
|
|
2165
2167
|
static sanitizeArgs(values, doubleQuote) {
|
|
2166
2168
|
const result = typeof values === 'string' ? [values] : values;
|
|
2167
|
-
const pattern = /[^\w+-.,/:@]/g;
|
|
2168
|
-
const sanitize = (value) => value.replace(pattern, capture => capture === '\n' ? "'\n'" : (capture === '$' || capture === '`' ? '\\' : '') + '\\' + capture);
|
|
2169
2169
|
for (let i = 0; i < result.length; ++i) {
|
|
2170
2170
|
let value = result[i].trim(), leading = '';
|
|
2171
2171
|
if (value !== '--') {
|
|
2172
|
-
const opt =
|
|
2172
|
+
const opt = REGEXP_CLIOPTION.exec(value);
|
|
2173
2173
|
if (opt) {
|
|
2174
2174
|
if (!opt[2] && !opt[3]) {
|
|
2175
2175
|
result[i] = opt[1];
|
|
@@ -2179,7 +2179,7 @@ class Module extends EventEmitter {
|
|
|
2179
2179
|
value = opt[3];
|
|
2180
2180
|
}
|
|
2181
2181
|
if (value) {
|
|
2182
|
-
const quoted = /^(["'])(.*)\1
|
|
2182
|
+
const quoted = /^(["'])(.*)\1$/s.exec(value);
|
|
2183
2183
|
if (PLATFORM_WIN32) {
|
|
2184
2184
|
if (quoted) {
|
|
2185
2185
|
if (quoted[1] === '"') {
|
|
@@ -2192,33 +2192,19 @@ class Module extends EventEmitter {
|
|
|
2192
2192
|
value = wrapQuote(value);
|
|
2193
2193
|
}
|
|
2194
2194
|
}
|
|
2195
|
-
else {
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
if (quoted[1] === "'") {
|
|
2199
|
-
result[i] = leading + value;
|
|
2200
|
-
continue;
|
|
2201
|
-
}
|
|
2202
|
-
value = quoted[2];
|
|
2203
|
-
type = true;
|
|
2204
|
-
}
|
|
2205
|
-
if (pattern.test(value)) {
|
|
2206
|
-
if (type) {
|
|
2207
|
-
value = '"' + sanitize(value) + '"';
|
|
2208
|
-
}
|
|
2209
|
-
else {
|
|
2210
|
-
value = "'" + value.replace(/'/g, "'\\''") + "'";
|
|
2211
|
-
}
|
|
2195
|
+
else if (!quoted) {
|
|
2196
|
+
if (REGEXP_CLIESCAPE.test(value)) {
|
|
2197
|
+
value = doubleQuote ? `"${value.replace(/(?<!\\)"/g, '\\"')}"` : `'${value.replaceAll("'", "'\\''")}'`;
|
|
2212
2198
|
}
|
|
2213
2199
|
else if (RESERVED_SHELL.includes(value)) {
|
|
2214
|
-
value =
|
|
2200
|
+
value = `'${value}'`;
|
|
2215
2201
|
}
|
|
2216
2202
|
}
|
|
2217
2203
|
}
|
|
2218
2204
|
else if (opt) {
|
|
2219
2205
|
leading = leading.trim();
|
|
2220
2206
|
if (!PLATFORM_WIN32 && leading.length > 2 && leading[1] !== '-') {
|
|
2221
|
-
leading
|
|
2207
|
+
leading.replace(REGEXP_CLIESCAPE, capture => '\\' + capture);
|
|
2222
2208
|
}
|
|
2223
2209
|
}
|
|
2224
2210
|
}
|
|
@@ -3470,12 +3456,12 @@ class Module extends EventEmitter {
|
|
|
3470
3456
|
}
|
|
3471
3457
|
}
|
|
3472
3458
|
writeLog(type, value, timeStamp, duration) {
|
|
3473
|
-
let queue;
|
|
3459
|
+
let queue = false;
|
|
3474
3460
|
if ((0, types_1.isObject)(type)) {
|
|
3475
3461
|
if (typeof value === 'boolean') {
|
|
3476
3462
|
queue = value;
|
|
3477
3463
|
}
|
|
3478
|
-
|
|
3464
|
+
value = type.value;
|
|
3479
3465
|
}
|
|
3480
3466
|
const output = Module.asString(value);
|
|
3481
3467
|
if (output) {
|
|
@@ -3503,7 +3489,7 @@ class Module extends EventEmitter {
|
|
|
3503
3489
|
from = timeStamp;
|
|
3504
3490
|
timeStamp = 0;
|
|
3505
3491
|
}
|
|
3506
|
-
else if ((0, types_1.
|
|
3492
|
+
else if ((0, types_1.isPlainObject)(timeStamp)) {
|
|
3507
3493
|
({ timeStamp, duration, from, source } = timeStamp);
|
|
3508
3494
|
}
|
|
3509
3495
|
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.9.
|
|
3
|
+
"version": "0.9.18",
|
|
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": "BSD-3-Clause",
|
|
21
21
|
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/types": "0.9.
|
|
23
|
+
"@e-mc/types": "0.9.18",
|
|
24
24
|
"chalk": "4.1.2",
|
|
25
25
|
"file-type": "16.5.4",
|
|
26
26
|
"js-yaml": "^4.1.0",
|