@e-mc/module 0.9.5 → 0.9.7
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 +8 -10
- package/index.js +57 -31
- 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.7/lib/index.d.ts)
|
|
13
13
|
|
|
14
14
|
```typescript
|
|
15
15
|
import type { LogStatus } from "./squared";
|
|
@@ -177,10 +177,8 @@ interface ModuleConstructor {
|
|
|
177
177
|
parseFunction(value: unknown, options?: ParseFunctionOptions): ((...args: unknown[]) => Promise<unknown> | unknown) | null;
|
|
178
178
|
parseFunction(value: unknown, absolute: boolean, sync?: boolean): ((...args: unknown[]) => Promise<unknown> | unknown) | null;
|
|
179
179
|
asString(value: unknown, cacheKey?: boolean | "throws"): string;
|
|
180
|
-
asHash(data: BinaryLike,
|
|
181
|
-
asHash(data: BinaryLike, algorithm
|
|
182
|
-
asHash(data: BinaryLike, algorithm?: string, options?: AsHashOptions): string;
|
|
183
|
-
asHash(data: BinaryLike, options?: AsHashOptions): string;
|
|
180
|
+
asHash(data: BinaryLike, options: AsHashOptions): string;
|
|
181
|
+
asHash(data: BinaryLike, algorithm?: unknown, digest?: unknown): string;
|
|
184
182
|
readHash(value: string | URL, options?: ReadHashOptions): Promise<string>;
|
|
185
183
|
toPosix(value: unknown, normalize: boolean): string;
|
|
186
184
|
toPosix(value: unknown, filename?: string, normalize?: boolean): string;
|
|
@@ -391,11 +389,11 @@ type ForegroundColor = typeof IForegroundColor | `#${string}`;
|
|
|
391
389
|
|
|
392
390
|
## References
|
|
393
391
|
|
|
394
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
395
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
396
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
397
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
398
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
392
|
+
- https://www.unpkg.com/@e-mc/types@0.9.7/lib/core.d.ts
|
|
393
|
+
- https://www.unpkg.com/@e-mc/types@0.9.7/lib/logger.d.ts
|
|
394
|
+
- https://www.unpkg.com/@e-mc/types@0.9.7/lib/module.d.ts
|
|
395
|
+
- https://www.unpkg.com/@e-mc/types@0.9.7/lib/node.d.ts
|
|
396
|
+
- https://www.unpkg.com/@e-mc/types@0.9.7/lib/settings.d.ts
|
|
399
397
|
|
|
400
398
|
* https://www.npmjs.com/package/@types/node
|
|
401
399
|
|
package/index.js
CHANGED
|
@@ -129,6 +129,25 @@ 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 RESERVED_SHELL = [
|
|
133
|
+
'if',
|
|
134
|
+
'then',
|
|
135
|
+
'elif',
|
|
136
|
+
'else',
|
|
137
|
+
'fi',
|
|
138
|
+
'time',
|
|
139
|
+
'for',
|
|
140
|
+
'in',
|
|
141
|
+
'until',
|
|
142
|
+
'while',
|
|
143
|
+
'do',
|
|
144
|
+
'done',
|
|
145
|
+
'case',
|
|
146
|
+
'esac',
|
|
147
|
+
'coproc',
|
|
148
|
+
'select',
|
|
149
|
+
'function'
|
|
150
|
+
];
|
|
132
151
|
let LOG_NEWLINE = true;
|
|
133
152
|
let LOG_EMPTYLINE = false;
|
|
134
153
|
let TEMP_DIR = path.join(PROCESS_CWD, "tmp");
|
|
@@ -532,7 +551,7 @@ function addCacheItem(map, key, data, cache) {
|
|
|
532
551
|
}
|
|
533
552
|
function checkFunction(value) {
|
|
534
553
|
if (typeof value === 'function') {
|
|
535
|
-
Object.defineProperty(value, "__cjs__", { value: true });
|
|
554
|
+
Object.defineProperty(value, "__cjs__", { value: true, writable: false, enumerable: false });
|
|
536
555
|
return value;
|
|
537
556
|
}
|
|
538
557
|
return null;
|
|
@@ -645,9 +664,16 @@ function applyLogId(options) {
|
|
|
645
664
|
}
|
|
646
665
|
return options;
|
|
647
666
|
}
|
|
648
|
-
function withinDir(value, base) {
|
|
667
|
+
function withinDir(value, base, override = false) {
|
|
649
668
|
value = path.normalize(value);
|
|
650
|
-
|
|
669
|
+
if (PLATFORM_WIN32) {
|
|
670
|
+
value = value.toLowerCase();
|
|
671
|
+
base = ensureDir(base.toLowerCase());
|
|
672
|
+
}
|
|
673
|
+
else {
|
|
674
|
+
base = ensureDir(base);
|
|
675
|
+
}
|
|
676
|
+
return value.startsWith(base) && (value !== base || override);
|
|
651
677
|
}
|
|
652
678
|
function formatPercent(value, precision) {
|
|
653
679
|
if (value <= 0) {
|
|
@@ -696,7 +722,7 @@ class Module extends EventEmitter {
|
|
|
696
722
|
this[_f] = new AbortController();
|
|
697
723
|
this[_g] = null;
|
|
698
724
|
}
|
|
699
|
-
static get VERSION() { return "0.9.
|
|
725
|
+
static get VERSION() { return "0.9.7"; }
|
|
700
726
|
static get LOG_TYPE() { return types_1.LOG_TYPE; }
|
|
701
727
|
static get STATUS_TYPE() { return types_1.STATUS_TYPE; }
|
|
702
728
|
static get MAX_TIMEOUT() { return 2147483647; }
|
|
@@ -1164,13 +1190,16 @@ class Module extends EventEmitter {
|
|
|
1164
1190
|
return null;
|
|
1165
1191
|
}
|
|
1166
1192
|
static asString(value, cacheKey) {
|
|
1167
|
-
if (
|
|
1193
|
+
if (value === undefined) {
|
|
1168
1194
|
return '';
|
|
1169
1195
|
}
|
|
1170
1196
|
switch (typeof value) {
|
|
1171
1197
|
case 'string':
|
|
1172
1198
|
return value;
|
|
1173
1199
|
case 'object':
|
|
1200
|
+
if (value === null) {
|
|
1201
|
+
return '';
|
|
1202
|
+
}
|
|
1174
1203
|
if (value.constructor === Object || Object.getPrototypeOf(value) === null) {
|
|
1175
1204
|
if (Object.keys(value).length === 0) {
|
|
1176
1205
|
return '';
|
|
@@ -1211,40 +1240,34 @@ class Module extends EventEmitter {
|
|
|
1211
1240
|
}
|
|
1212
1241
|
return cacheKey ? (0, types_1.generateUUID)() : '';
|
|
1213
1242
|
}
|
|
1214
|
-
static asHash(data, algorithm,
|
|
1215
|
-
if (!algorithm && !
|
|
1243
|
+
static asHash(data, algorithm, digest) {
|
|
1244
|
+
if (!algorithm && !digest) {
|
|
1216
1245
|
return crypto.createHash("sha256").update(data).digest("hex");
|
|
1217
1246
|
}
|
|
1218
|
-
let options
|
|
1219
|
-
if (
|
|
1220
|
-
options =
|
|
1221
|
-
minLength = 0;
|
|
1222
|
-
}
|
|
1223
|
-
if (typeof algorithm === 'number') {
|
|
1224
|
-
minLength = algorithm;
|
|
1225
|
-
algorithm = undefined;
|
|
1226
|
-
}
|
|
1227
|
-
else if ((0, types_1.isObject)(algorithm)) {
|
|
1228
|
-
options = algorithm;
|
|
1229
|
-
algorithm = undefined;
|
|
1230
|
-
}
|
|
1231
|
-
if (options) {
|
|
1232
|
-
options = { ...options };
|
|
1233
|
-
if ('minLength' in options) {
|
|
1234
|
-
minLength = options.minLength;
|
|
1235
|
-
delete options.minLength;
|
|
1236
|
-
}
|
|
1247
|
+
let options;
|
|
1248
|
+
if ((0, types_1.isObject)(algorithm)) {
|
|
1249
|
+
options = { ...algorithm };
|
|
1237
1250
|
if ('algorithm' in options) {
|
|
1238
1251
|
algorithm = options.algorithm;
|
|
1239
1252
|
delete options.algorithm;
|
|
1240
1253
|
}
|
|
1254
|
+
else {
|
|
1255
|
+
algorithm = undefined;
|
|
1256
|
+
}
|
|
1241
1257
|
if ('digest' in options) {
|
|
1242
1258
|
digest = options.digest;
|
|
1243
1259
|
delete options.digest;
|
|
1244
1260
|
}
|
|
1261
|
+
else {
|
|
1262
|
+
digest = undefined;
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
else if ((0, types_1.isObject)(digest)) {
|
|
1266
|
+
options = digest;
|
|
1267
|
+
digest = undefined;
|
|
1245
1268
|
}
|
|
1246
|
-
if (
|
|
1247
|
-
|
|
1269
|
+
else if (typeof digest !== 'string') {
|
|
1270
|
+
digest = undefined;
|
|
1248
1271
|
}
|
|
1249
1272
|
try {
|
|
1250
1273
|
return crypto.createHash(algorithm || "sha256", options).update(data).digest(digest || "hex");
|
|
@@ -2132,6 +2155,9 @@ class Module extends EventEmitter {
|
|
|
2132
2155
|
value = "'" + value.replace(/'/g, "'\\''") + "'";
|
|
2133
2156
|
}
|
|
2134
2157
|
}
|
|
2158
|
+
else if (RESERVED_SHELL.includes(value)) {
|
|
2159
|
+
value = "'" + value + "'";
|
|
2160
|
+
}
|
|
2135
2161
|
}
|
|
2136
2162
|
}
|
|
2137
2163
|
else if (opt) {
|
|
@@ -2518,7 +2544,7 @@ class Module extends EventEmitter {
|
|
|
2518
2544
|
}
|
|
2519
2545
|
} while ((dir !== "tmp") && (dir = "tmp"));
|
|
2520
2546
|
if (modified) {
|
|
2521
|
-
this.formatMessage(1, 'TEMP', ["Directory was modified", dir], TEMP_DIR + (VALUES["temp.write"] ? ' -
|
|
2547
|
+
this.formatMessage(1, 'TEMP', ["Directory was modified", dir], TEMP_DIR + (VALUES["temp.write"] ? ' - writable' : ''), { ...this.LOG_STYLE_NOTICE, newline: true });
|
|
2522
2548
|
}
|
|
2523
2549
|
settings.temp_dir = dir;
|
|
2524
2550
|
if ((0, types_1.isPlainObject)(temp)) {
|
|
@@ -2607,7 +2633,7 @@ class Module extends EventEmitter {
|
|
|
2607
2633
|
if (permission && (Module.isFile(uri, 'unc') ? permission.hasUNCRead(path.normalize(uri)) || ownPermissionOnly && !permission.getUNCRead() : path.isAbsolute(uri = path.resolve(uri)) && (permission.hasDiskRead(uri) || ownPermissionOnly && !permission.getDiskRead()))) {
|
|
2608
2634
|
return true;
|
|
2609
2635
|
}
|
|
2610
|
-
return VALUES["permission.home_read"] && withinDir(uri, OS_HOMEDIR);
|
|
2636
|
+
return VALUES["permission.home_read"] && withinDir(uri, OS_HOMEDIR, true);
|
|
2611
2637
|
}
|
|
2612
2638
|
canWrite(uri, options) {
|
|
2613
2639
|
let permission = this.permission, ownPermissionOnly = false;
|
|
@@ -2631,7 +2657,7 @@ class Module extends EventEmitter {
|
|
|
2631
2657
|
if (permission && (Module.isFile(uri, 'unc') ? permission.hasUNCWrite(path.normalize(uri)) || ownPermissionOnly && !permission.getUNCWrite() : path.isAbsolute(uri = path.resolve(uri)) && (permission.hasDiskWrite(uri) || ownPermissionOnly && !permission.getDiskWrite()))) {
|
|
2632
2658
|
return true;
|
|
2633
2659
|
}
|
|
2634
|
-
return VALUES["temp.write"] && withinDir(uri, TEMP_DIR) || VALUES["permission.home_write"] && withinDir(uri, OS_HOMEDIR);
|
|
2660
|
+
return VALUES["temp.write"] && withinDir(uri, TEMP_DIR, true) || VALUES["permission.home_write"] && withinDir(uri, OS_HOMEDIR, true);
|
|
2635
2661
|
}
|
|
2636
2662
|
readFile(src, options = {}, callback) {
|
|
2637
2663
|
let promises, outSrc;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/module",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.7",
|
|
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.7",
|
|
24
24
|
"chalk": "4.1.2",
|
|
25
25
|
"file-type": "16.5.4",
|
|
26
26
|
"js-yaml": "^4.1.0",
|