@e-mc/module 0.10.6 → 0.11.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 +1 -1
- package/README.md +15 -15
- package/index.js +99 -69
- package/package.json +3 -4
- package/lib-v4.d.ts +0 -5
- package/lib-v4.js +0 -158
package/LICENSE
CHANGED
|
@@ -8,4 +8,4 @@ Redistribution and use in source and binary forms, with or without modification,
|
|
|
8
8
|
|
|
9
9
|
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
10
10
|
|
|
11
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
11
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# @e-mc/module
|
|
2
2
|
|
|
3
|
-
* NodeJS 16
|
|
4
|
-
*
|
|
3
|
+
* NodeJS 16 LTS
|
|
4
|
+
* ES2021
|
|
5
5
|
|
|
6
6
|
## General Usage
|
|
7
7
|
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
## Interface
|
|
11
11
|
|
|
12
|
-
* [View Source](https://www.unpkg.com/@e-mc/types@0.
|
|
12
|
+
* [View Source](https://www.unpkg.com/@e-mc/types@0.11.1/lib/index.d.ts)
|
|
13
13
|
|
|
14
14
|
```typescript
|
|
15
15
|
import type { LogStatus } from "./squared";
|
|
@@ -21,11 +21,12 @@ import type { AsHashOptions, CheckSemVerOptions, CopyDirOptions, CopyDirResult,
|
|
|
21
21
|
import type { Settings } from "./node";
|
|
22
22
|
import type { LoggerFormatSettings } from "/settings";
|
|
23
23
|
|
|
24
|
-
import type { SpawnOptions } from "child_process";
|
|
25
|
-
import type { BinaryLike, HashOptions } from "crypto";
|
|
24
|
+
import type { SpawnOptions } from "node:child_process";
|
|
25
|
+
import type { BinaryLike, HashOptions } from "node:crypto";
|
|
26
|
+
import type { NoParamCallback } from "node:fs";
|
|
26
27
|
import type { FileTypeResult } from "file-type";
|
|
27
|
-
|
|
28
|
-
import type * as EventEmitter from "events";
|
|
28
|
+
|
|
29
|
+
import type * as EventEmitter from "node:events";
|
|
29
30
|
|
|
30
31
|
type BufferView = Buffer | string | NodeJS.ArrayBufferView;
|
|
31
32
|
type CpuUsage = NodeJS.CpuUsage;
|
|
@@ -182,7 +183,7 @@ interface ModuleConstructor {
|
|
|
182
183
|
parseFunction(value: unknown, absolute: boolean, sync?: boolean): ((...args: unknown[]) => Promise<unknown> | unknown) | null;
|
|
183
184
|
asString(value: unknown, cacheKey?: boolean | "throws"): string;
|
|
184
185
|
asHash(data: BinaryLike, options?: AsHashOptions): string;
|
|
185
|
-
asHash(data: BinaryLike, algorithm?: string, options?:
|
|
186
|
+
asHash(data: BinaryLike, algorithm?: string, options?: AsHashOptions): string;
|
|
186
187
|
asHash(data: BinaryLike, algorithm?: string, digest?: BinaryToTextEncoding): string;
|
|
187
188
|
readHash(value: string | URL, options?: ReadHashOptions): Promise<string>;
|
|
188
189
|
toPosix(value: unknown, normalize: boolean): string;
|
|
@@ -227,7 +228,6 @@ interface ModuleConstructor {
|
|
|
227
228
|
getPackageVersion(name: string | [string, string], startDir: string, baseDir?: string): string;
|
|
228
229
|
getPackageVersion(name: string | [string, string], unstable?: boolean, startDir?: string, baseDir?: string): string;
|
|
229
230
|
checkSemVer(name: string | [string, string], options: CheckSemVerOptions): boolean;
|
|
230
|
-
/** @deprecated options */
|
|
231
231
|
checkSemVer(name: string | [string, string], min: number | string, max?: number | string, unstable?: boolean, startDir?: string): boolean;
|
|
232
232
|
checkSemVer(name: string | [string, string], min: number | string, max: number | string, options?: Omit<CheckSemVerOptions, "min" | "max" | "equals">): boolean;
|
|
233
233
|
sanitizeCmd(value: string): string;
|
|
@@ -407,14 +407,14 @@ interface LoggerModule {
|
|
|
407
407
|
|
|
408
408
|
## References
|
|
409
409
|
|
|
410
|
-
- https://www.unpkg.com/@e-mc/types@0.
|
|
411
|
-
- https://www.unpkg.com/@e-mc/types@0.
|
|
412
|
-
- https://www.unpkg.com/@e-mc/types@0.
|
|
413
|
-
- https://www.unpkg.com/@e-mc/types@0.
|
|
414
|
-
- https://www.unpkg.com/@e-mc/types@0.
|
|
410
|
+
- https://www.unpkg.com/@e-mc/types@0.11.1/lib/core.d.ts
|
|
411
|
+
- https://www.unpkg.com/@e-mc/types@0.11.1/lib/logger.d.ts
|
|
412
|
+
- https://www.unpkg.com/@e-mc/types@0.11.1/lib/module.d.ts
|
|
413
|
+
- https://www.unpkg.com/@e-mc/types@0.11.1/lib/node.d.ts
|
|
414
|
+
- https://www.unpkg.com/@e-mc/types@0.11.1/lib/settings.d.ts
|
|
415
415
|
|
|
416
416
|
* https://www.npmjs.com/package/@types/node
|
|
417
417
|
|
|
418
418
|
## LICENSE
|
|
419
419
|
|
|
420
|
-
BSD 3-Clause
|
|
420
|
+
BSD 3-Clause
|
package/index.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
3
|
-
const path = require("path");
|
|
4
|
-
const fs = require("fs");
|
|
5
|
-
const stream = require("stream");
|
|
6
|
-
const os = require("os");
|
|
7
|
-
const crypto = require("crypto");
|
|
3
|
+
const path = require("node:path");
|
|
4
|
+
const fs = require("node:fs");
|
|
5
|
+
const stream = require("node:stream");
|
|
6
|
+
const os = require("node:os");
|
|
7
|
+
const crypto = require("node:crypto");
|
|
8
8
|
const mime = require("mime-types");
|
|
9
9
|
const pm = require("picomatch");
|
|
10
10
|
const chalk = require("chalk");
|
|
11
11
|
const yaml = require("js-yaml");
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
12
|
+
const EventEmitter = require("node:events");
|
|
13
|
+
const node_url_1 = require("node:url");
|
|
14
|
+
const node_util_1 = require("node:util");
|
|
15
15
|
const types_1 = require("@e-mc/types");
|
|
16
16
|
const kSessionId = Symbol('sessionId');
|
|
17
17
|
const kBroadcastId = Symbol('broadcastId');
|
|
@@ -116,6 +116,7 @@ const VALUES = {
|
|
|
116
116
|
["node.process.cpu_usage"]: true,
|
|
117
117
|
["node.process.memory_usage"]: true,
|
|
118
118
|
["node.process.inline"]: true,
|
|
119
|
+
["node.settings.package_manager"]: '',
|
|
119
120
|
["temp.dir"]: "tmp",
|
|
120
121
|
["temp.write"]: false,
|
|
121
122
|
["process.password"]: '',
|
|
@@ -138,7 +139,7 @@ const MEMORY_CACHE_DISK = {
|
|
|
138
139
|
include: null,
|
|
139
140
|
exclude: null
|
|
140
141
|
};
|
|
141
|
-
const SUPPORTED_CANPARSE = (0, types_1.supported)(19, 9) || (0, types_1.supported)(18, 17,
|
|
142
|
+
const SUPPORTED_CANPARSE = (0, types_1.supported)(19, 9) || (0, types_1.supported)(18, 17, true);
|
|
142
143
|
const REGEXP_TORRENT = /^(?:magnet:\?xt=|(?:https?|s?ftp):\/\/[^/][^\n]*?\.(?:torrent|metalink|meta4)(?:\?[^\n]*)?$)/i;
|
|
143
144
|
const REGEXP_PROTOCOL = /^([a-z][a-z\d+-.]*):\/\/[^@:[\]\\^<>|\s]/i;
|
|
144
145
|
const REGEXP_CLIESCAPE = /[^\w+-.,/:@]/g;
|
|
@@ -168,7 +169,7 @@ const RESERVED_SHELL = [
|
|
|
168
169
|
let LOG_NEWLINE = true;
|
|
169
170
|
let LOG_EMPTYLINE = false;
|
|
170
171
|
let LOG_MIN_WIDTH = 0;
|
|
171
|
-
let TEMP_DIR =
|
|
172
|
+
let TEMP_DIR = (0, types_1.getTempDir)();
|
|
172
173
|
let PNPM_VER;
|
|
173
174
|
let YARN_VER;
|
|
174
175
|
let FILETYPE_ESM = null;
|
|
@@ -528,7 +529,7 @@ function recurseCause(err, out, visited) {
|
|
|
528
529
|
visited = new WeakSet();
|
|
529
530
|
}
|
|
530
531
|
visited.add(err);
|
|
531
|
-
if (Object.
|
|
532
|
+
if (Object.hasOwn(err, 'cause')) {
|
|
532
533
|
const cause = err.cause;
|
|
533
534
|
if (cause instanceof Error) {
|
|
534
535
|
if (message) {
|
|
@@ -558,7 +559,7 @@ function writeLine(value) {
|
|
|
558
559
|
LOG_EMPTYLINE = false;
|
|
559
560
|
}
|
|
560
561
|
function parseFileArgs(options = {}, callback) {
|
|
561
|
-
let promises;
|
|
562
|
+
let promises = false;
|
|
562
563
|
if (typeof options === 'boolean') {
|
|
563
564
|
promises = options;
|
|
564
565
|
options = {};
|
|
@@ -583,14 +584,17 @@ function formatTimeHint(value) {
|
|
|
583
584
|
return (0, types_1.formatTime)(value);
|
|
584
585
|
}
|
|
585
586
|
}
|
|
586
|
-
function getTimeOffset(
|
|
587
|
-
if (!
|
|
587
|
+
function getTimeOffset(value, current) {
|
|
588
|
+
if (!value) {
|
|
588
589
|
return 0;
|
|
589
590
|
}
|
|
590
|
-
if (
|
|
591
|
-
return (0, types_1.convertTime)(process.hrtime(
|
|
591
|
+
if (typeof value === 'bigint') {
|
|
592
|
+
return (0, types_1.convertTime)(process.hrtime.bigint() - value);
|
|
593
|
+
}
|
|
594
|
+
if (Array.isArray(value)) {
|
|
595
|
+
return (0, types_1.convertTime)(process.hrtime(value));
|
|
592
596
|
}
|
|
593
|
-
return (current || Date.now()) - (
|
|
597
|
+
return (current || Date.now()) - (value instanceof Date ? value.getTime() : value);
|
|
594
598
|
}
|
|
595
599
|
function getTimeStamp(options, include) {
|
|
596
600
|
const timeStamp = options.timeStamp;
|
|
@@ -618,7 +622,21 @@ function addCacheItem(map, key, data, cache = false) {
|
|
|
618
622
|
const length = Buffer.byteLength(data);
|
|
619
623
|
if (length >= MEMORY_CACHE_DISK.min_size && length <= MEMORY_CACHE_DISK.max_size) {
|
|
620
624
|
key = Module.toPosix(key, true);
|
|
621
|
-
|
|
625
|
+
let valid = true;
|
|
626
|
+
if (MEMORY_CACHE_DISK.exclude) {
|
|
627
|
+
for (const value of MEMORY_CACHE_DISK.exclude) {
|
|
628
|
+
if (value.startsWith('!')) {
|
|
629
|
+
if (isMatch(key, value.substring(1))) {
|
|
630
|
+
valid = true;
|
|
631
|
+
break;
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
else if (valid && isMatch(key, value)) {
|
|
635
|
+
valid = false;
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
if (valid && (cache || !MEMORY_CACHE_DISK.include || MEMORY_CACHE_DISK.include.some(value => isMatch(key, value)))) {
|
|
622
640
|
map.set(key, [Date.now(), data]);
|
|
623
641
|
}
|
|
624
642
|
}
|
|
@@ -627,7 +645,7 @@ function getCacheTotal() {
|
|
|
627
645
|
return CACHE_READTEXT.size + CACHE_READBUFFER.size + CACHE_READCJS.size;
|
|
628
646
|
}
|
|
629
647
|
function isMatch(key, value) {
|
|
630
|
-
return pm.isMatch(key, value, { nocase: PLATFORM_WIN32, matchBase: value.startsWith('*') });
|
|
648
|
+
return pm.isMatch(key, value, { posixSlashes: true, windows: true, nocase: PLATFORM_WIN32, matchBase: value.startsWith('*') });
|
|
631
649
|
}
|
|
632
650
|
function listDir(src, paths, depth, include, exclude, excludeDir, outFiles) {
|
|
633
651
|
const srcDir = path.join(src, ...paths);
|
|
@@ -810,7 +828,7 @@ function getSessionId(value, width) {
|
|
|
810
828
|
return ['', width - 1];
|
|
811
829
|
}
|
|
812
830
|
function alignLogColumn(value, width, justify, padding) {
|
|
813
|
-
const length = (padding === 0 && REGEXP_ANSIESCAPE.test(value) ?
|
|
831
|
+
const length = (padding === 0 && REGEXP_ANSIESCAPE.test(value) ? (0, node_util_1.stripVTControlCharacters)(value) : value).length;
|
|
814
832
|
const offset = width - length;
|
|
815
833
|
const spacing = padding === 1 ? ' ' : '';
|
|
816
834
|
if (offset <= 0) {
|
|
@@ -832,7 +850,7 @@ function formatLogColumn(value, color, bgColor, bold, bgAltColor = '', options)
|
|
|
832
850
|
let indent = '', length = 0, output;
|
|
833
851
|
if (typeof value === 'string') {
|
|
834
852
|
output = value;
|
|
835
|
-
let modified;
|
|
853
|
+
let modified = false;
|
|
836
854
|
if (bgAltColor) {
|
|
837
855
|
const match = /^([ -]+)(.*)$/s.exec(output);
|
|
838
856
|
if (match) {
|
|
@@ -898,7 +916,7 @@ function truncateStart(value, length = LOG_MIN_WIDTH, style = false) {
|
|
|
898
916
|
if (!style || style === 'none') {
|
|
899
917
|
return value;
|
|
900
918
|
}
|
|
901
|
-
const width = (REGEXP_ANSIESCAPE.test(value) ?
|
|
919
|
+
const width = (REGEXP_ANSIESCAPE.test(value) ? (0, node_util_1.stripVTControlCharacters)(value) : value).length;
|
|
902
920
|
if (width > length) {
|
|
903
921
|
switch (style) {
|
|
904
922
|
case 'nowrap':
|
|
@@ -915,13 +933,13 @@ function truncateStart(value, length = LOG_MIN_WIDTH, style = false) {
|
|
|
915
933
|
return length > 0 && width <= length ? value : '';
|
|
916
934
|
}
|
|
917
935
|
function truncateEnd(value, length) {
|
|
918
|
-
return (REGEXP_ANSIESCAPE.test(value) ?
|
|
936
|
+
return (REGEXP_ANSIESCAPE.test(value) ? (0, node_util_1.stripVTControlCharacters)(value) : value).length > length ? '...' + value.substring(value.length - length + 3) : value;
|
|
919
937
|
}
|
|
920
938
|
const escapeArg = (value) => value.replace(REGEXP_CLIESCAPE, capture => capture === '\n' ? "'\n'" : (capture === '$' || capture === '`' ? '\\' : '') + '\\' + capture);
|
|
921
939
|
const isMeterUnit = (type, ident) => (type & 256) === 256 && !ident;
|
|
922
940
|
const formatLogMessage = (type, message, unit, ident) => isMeterUnit(type, ident) ? (unit + LOG_DIVIDER + message).trimEnd() : unit ? (message + (ident ? '' : ' ') + unit).trimStart() : message;
|
|
923
941
|
const hideAbort = (err) => err.name === 'AbortError' && SETTINGS.abort === false;
|
|
924
|
-
const asFile = (value) => typeof value === 'string' ? value.trim() : value instanceof URL && value.protocol === 'file:' ? (0,
|
|
942
|
+
const asFile = (value) => typeof value === 'string' ? value.trim() : value instanceof URL && value.protocol === 'file:' ? (0, node_url_1.fileURLToPath)(value) : '';
|
|
925
943
|
const wrapQuote = (value) => '"' + value.replaceAll('"', '\\"') + '"';
|
|
926
944
|
const isFunction = (value) => typeof value === 'function';
|
|
927
945
|
const isFileURL = (value) => /^file:\/\//i.test(value);
|
|
@@ -961,7 +979,7 @@ class Module extends EventEmitter {
|
|
|
961
979
|
this[_g] = null;
|
|
962
980
|
}
|
|
963
981
|
static get VERSION() {
|
|
964
|
-
return "0.
|
|
982
|
+
return "0.11.1";
|
|
965
983
|
}
|
|
966
984
|
static get LOG_TYPE() {
|
|
967
985
|
return types_1.LOG_TYPE;
|
|
@@ -1006,6 +1024,7 @@ class Module extends EventEmitter {
|
|
|
1006
1024
|
case "error.fatal":
|
|
1007
1025
|
return VALUES[key];
|
|
1008
1026
|
case "node.require.ext":
|
|
1027
|
+
case "node.settings.package_manager":
|
|
1009
1028
|
case "process.password":
|
|
1010
1029
|
case "process.cipher.algorithm":
|
|
1011
1030
|
return VALUES[key] !== '';
|
|
@@ -1073,7 +1092,7 @@ class Module extends EventEmitter {
|
|
|
1073
1092
|
return;
|
|
1074
1093
|
}
|
|
1075
1094
|
if (!options.rawOutput) {
|
|
1076
|
-
let messageUnitIndent = options.messageUnitIndent, coloring;
|
|
1095
|
+
let messageUnitIndent = options.messageUnitIndent, coloring = false;
|
|
1077
1096
|
if (!broadcastId) {
|
|
1078
1097
|
(0, types_1.setLogCurrent)({ type, title, value, message, sessionId });
|
|
1079
1098
|
coloring = !(options.useColor === false || SETTINGS.color === false);
|
|
@@ -1249,10 +1268,10 @@ class Module extends EventEmitter {
|
|
|
1249
1268
|
const messageTextWrap = options.messageTextWrap;
|
|
1250
1269
|
const logOptions = { maxLength: messageWidth ?? formatMessage.width, outLength: 0, messageTextWrap };
|
|
1251
1270
|
m = formatLogColumn(m, messageColor, messageBgColor, messageBold, messageUnitIndent ? format.meter.bgAltColor : undefined, logOptions);
|
|
1252
|
-
if (u && messageTextWrap && messageTextWrap !== 'none' && LOG_MIN_WIDTH + logOptions.outLength +
|
|
1271
|
+
if (u && messageTextWrap && messageTextWrap !== 'none' && LOG_MIN_WIDTH + logOptions.outLength + (0, node_util_1.stripVTControlCharacters)(unit).length + (messageUnitIndent ? 0 : 1) > PROCESS_STDOUT.columns) {
|
|
1253
1272
|
if (isMeterUnit(type, messageUnitIndent)) {
|
|
1254
1273
|
m = '';
|
|
1255
|
-
if (LOG_MIN_WIDTH +
|
|
1274
|
+
if (LOG_MIN_WIDTH + (0, node_util_1.stripVTControlCharacters)(u).length > PROCESS_STDOUT.columns) {
|
|
1256
1275
|
u = '';
|
|
1257
1276
|
}
|
|
1258
1277
|
}
|
|
@@ -1296,7 +1315,7 @@ class Module extends EventEmitter {
|
|
|
1296
1315
|
}
|
|
1297
1316
|
if (!output) {
|
|
1298
1317
|
const formatMessage = format.message;
|
|
1299
|
-
output = (titleIndent !== -1 ? title : title ? title + formatTitle.braces + ' ' : '') +
|
|
1318
|
+
output = (titleIndent !== -1 ? title : title ? title + formatTitle.braces + ' ' : '') + (0, node_util_1.stripVTControlCharacters)(value) + (0, node_util_1.stripVTControlCharacters)(hint) + (id || ' ') + (message && SETTINGS.message !== false ? (error ? '{' : formatMessage.braces[0]) + truncateStart(formatLogMessage(type, (0, node_util_1.stripVTControlCharacters)(this.asString(message)), (0, node_util_1.stripVTControlCharacters)(unit), messageUnitIndent), options.messageWidth ?? formatMessage.width, options.messageTextWrap) + (error ? '}' : formatMessage.braces[1]) : !formatMessage.braces[1] ? formatMessage.braces[0] : '');
|
|
1300
1319
|
}
|
|
1301
1320
|
}
|
|
1302
1321
|
else {
|
|
@@ -1506,7 +1525,7 @@ class Module extends EventEmitter {
|
|
|
1506
1525
|
}
|
|
1507
1526
|
}
|
|
1508
1527
|
catch (err) {
|
|
1509
|
-
if (this.isErrorCode(err, 'ENOENT')) {
|
|
1528
|
+
if (this.isErrorCode(err, 'ENOENT', 'EACCES', 'ELOOP', 'ENAMETOOLONG', 'EINVAL')) {
|
|
1510
1529
|
throw err;
|
|
1511
1530
|
}
|
|
1512
1531
|
}
|
|
@@ -1651,7 +1670,7 @@ class Module extends EventEmitter {
|
|
|
1651
1670
|
static resolveFile(value) {
|
|
1652
1671
|
if (isFileURL(value = value instanceof URL ? value.toString() : value.trim())) {
|
|
1653
1672
|
try {
|
|
1654
|
-
return (0,
|
|
1673
|
+
return (0, node_url_1.fileURLToPath)(value);
|
|
1655
1674
|
}
|
|
1656
1675
|
catch {
|
|
1657
1676
|
}
|
|
@@ -1665,7 +1684,7 @@ class Module extends EventEmitter {
|
|
|
1665
1684
|
static resolvePath(value, base) {
|
|
1666
1685
|
try {
|
|
1667
1686
|
if (this.isURL(value = value.trim())) {
|
|
1668
|
-
return isFileURL(value) ? (0,
|
|
1687
|
+
return isFileURL(value) ? (0, node_url_1.fileURLToPath)(value) : new URL(value).href;
|
|
1669
1688
|
}
|
|
1670
1689
|
if (base instanceof URL || this.isURL(base)) {
|
|
1671
1690
|
return new URL(value, base).href;
|
|
@@ -1679,7 +1698,7 @@ class Module extends EventEmitter {
|
|
|
1679
1698
|
return '';
|
|
1680
1699
|
}
|
|
1681
1700
|
static joinPath(...values) {
|
|
1682
|
-
let normalize;
|
|
1701
|
+
let normalize = false;
|
|
1683
1702
|
if (typeof values[values.length - 1] === 'boolean') {
|
|
1684
1703
|
normalize = values.pop();
|
|
1685
1704
|
}
|
|
@@ -1782,7 +1801,7 @@ class Module extends EventEmitter {
|
|
|
1782
1801
|
}
|
|
1783
1802
|
return false;
|
|
1784
1803
|
}
|
|
1785
|
-
static async copyDir(src, dest, move, recursive
|
|
1804
|
+
static async copyDir(src, dest, move, recursive) {
|
|
1786
1805
|
const srcOut = sanitizePath(asFile(src));
|
|
1787
1806
|
if (!(srcOut && this.isDir(srcOut))) {
|
|
1788
1807
|
return Promise.reject(errorDirectory(asFile(src) || "Unknown"));
|
|
@@ -1793,8 +1812,9 @@ class Module extends EventEmitter {
|
|
|
1793
1812
|
}
|
|
1794
1813
|
let symFile, symDir, ignoreFile, ignoreDir, silent, overwrite;
|
|
1795
1814
|
if ((0, types_1.isObject)(move)) {
|
|
1796
|
-
({ move, recursive
|
|
1815
|
+
({ move, recursive, symFile, symDir, ignoreFile, ignoreDir, silent, overwrite } = move);
|
|
1797
1816
|
}
|
|
1817
|
+
recursive ??= true;
|
|
1798
1818
|
return new Promise(resolve => {
|
|
1799
1819
|
const tasks = [];
|
|
1800
1820
|
const success = [];
|
|
@@ -1927,7 +1947,7 @@ class Module extends EventEmitter {
|
|
|
1927
1947
|
if (!(outDir && this.isDir(outDir))) {
|
|
1928
1948
|
return Promise.reject(errorDirectory(asFile(src) || "Unknown"));
|
|
1929
1949
|
}
|
|
1930
|
-
const pmOpts = { posixSlashes: true, windows: true, nocase: PLATFORM_WIN32 };
|
|
1950
|
+
const pmOpts = { posixSlashes: true, windows: true, nocase: Module.PLATFORM_WIN32 };
|
|
1931
1951
|
let exclude, excludeDir, recursive;
|
|
1932
1952
|
if ((0, types_1.isObject)(options)) {
|
|
1933
1953
|
if (options.matchBase) {
|
|
@@ -1977,7 +1997,7 @@ class Module extends EventEmitter {
|
|
|
1977
1997
|
}
|
|
1978
1998
|
catch (error) {
|
|
1979
1999
|
if (copied) {
|
|
1980
|
-
this.formatMessage(32, "WARN!", ["Unable to delete file", path.basename(src instanceof URL ? (0,
|
|
2000
|
+
this.formatMessage(32, "WARN!", ["Unable to delete file", path.basename(src instanceof URL ? (0, node_url_1.fileURLToPath)(src) : src)], error, { ...this.LOG_STYLE_WARN });
|
|
1981
2001
|
throws = false;
|
|
1982
2002
|
}
|
|
1983
2003
|
}
|
|
@@ -2279,13 +2299,13 @@ class Module extends EventEmitter {
|
|
|
2279
2299
|
}
|
|
2280
2300
|
return '0.0.0';
|
|
2281
2301
|
}
|
|
2282
|
-
static checkSemVer(name, min = 0, max = Infinity,
|
|
2283
|
-
let equals, includes;
|
|
2302
|
+
static checkSemVer(name, min = 0, max = Infinity, options) {
|
|
2303
|
+
let unstable, startDir, equals, includes;
|
|
2284
2304
|
if ((0, types_1.isObject)(min)) {
|
|
2285
2305
|
({ min = 0, max = Infinity, unstable, startDir, equals, includes } = min);
|
|
2286
2306
|
}
|
|
2287
|
-
else if (
|
|
2288
|
-
({ unstable, startDir, includes } =
|
|
2307
|
+
else if (options) {
|
|
2308
|
+
({ unstable, startDir, includes } = options);
|
|
2289
2309
|
}
|
|
2290
2310
|
let version = this.getPackageVersion(name, unstable, startDir);
|
|
2291
2311
|
if (version === '0.0.0') {
|
|
@@ -2309,7 +2329,7 @@ class Module extends EventEmitter {
|
|
|
2309
2329
|
maxVersion = [Infinity];
|
|
2310
2330
|
}
|
|
2311
2331
|
else {
|
|
2312
|
-
maxVersion = [max - (includes ? 0 : 1)];
|
|
2332
|
+
maxVersion = [(max | 0) - (includes ? 0 : 1)];
|
|
2313
2333
|
maxRange = true;
|
|
2314
2334
|
}
|
|
2315
2335
|
version = version.split('.').map(ver => parseInt(ver));
|
|
@@ -2506,6 +2526,17 @@ class Module extends EventEmitter {
|
|
|
2506
2526
|
VALUES["node.require.inline"] = inline;
|
|
2507
2527
|
}
|
|
2508
2528
|
}
|
|
2529
|
+
const manager = node.settings?.package_manager;
|
|
2530
|
+
switch (manager) {
|
|
2531
|
+
case 'npm':
|
|
2532
|
+
case 'yarn':
|
|
2533
|
+
case 'pnpm':
|
|
2534
|
+
VALUES["node.settings.package_manager"] = manager;
|
|
2535
|
+
break;
|
|
2536
|
+
default:
|
|
2537
|
+
VALUES["node.settings.package_manager"] = '';
|
|
2538
|
+
break;
|
|
2539
|
+
}
|
|
2509
2540
|
}
|
|
2510
2541
|
if (settings.process) {
|
|
2511
2542
|
const { env, cipher, password: pwd } = settings.process;
|
|
@@ -2762,11 +2793,11 @@ class Module extends EventEmitter {
|
|
|
2762
2793
|
});
|
|
2763
2794
|
}
|
|
2764
2795
|
}
|
|
2765
|
-
let dir = settings.temp_dir, env, write, modified;
|
|
2796
|
+
let dir = settings.temp_dir, env, write, modified = false;
|
|
2766
2797
|
if ((0, types_1.isPlainObject)(temp)) {
|
|
2767
2798
|
dir ||= temp.dir;
|
|
2768
|
-
if (temp.env) {
|
|
2769
|
-
env =
|
|
2799
|
+
if (!(temp.env && (env = process.env[temp.env])) && temp.os && !dir) {
|
|
2800
|
+
env = os.tmpdir();
|
|
2770
2801
|
}
|
|
2771
2802
|
write = temp.write;
|
|
2772
2803
|
}
|
|
@@ -2925,7 +2956,7 @@ class Module extends EventEmitter {
|
|
|
2925
2956
|
return VALUES["temp.write"] && withinDir(uri, TEMP_DIR, true) || VALUES["permission.home_write"] && withinDir(uri, OS_HOMEDIR, true);
|
|
2926
2957
|
}
|
|
2927
2958
|
readFile(src, options = {}, callback) {
|
|
2928
|
-
let promises, outSrc;
|
|
2959
|
+
let promises = false, outSrc;
|
|
2929
2960
|
[options, promises, callback] = parseFileArgs(options, callback);
|
|
2930
2961
|
if (outSrc = hasFileSystem(this, 0, src, options)) {
|
|
2931
2962
|
let { encoding, requireExt, minStreamSize, cache } = options;
|
|
@@ -3019,7 +3050,7 @@ class Module extends EventEmitter {
|
|
|
3019
3050
|
}
|
|
3020
3051
|
}
|
|
3021
3052
|
writeFile(src, data, options = {}, callback) {
|
|
3022
|
-
let promises, outSrc;
|
|
3053
|
+
let promises = false, outSrc;
|
|
3023
3054
|
[options, promises, callback] = parseFileArgs(options, callback);
|
|
3024
3055
|
if (outSrc = hasFileSystem(this, 1, src, options, true, options.overwrite)) {
|
|
3025
3056
|
if (promises) {
|
|
@@ -3056,7 +3087,7 @@ class Module extends EventEmitter {
|
|
|
3056
3087
|
return false;
|
|
3057
3088
|
}
|
|
3058
3089
|
deleteFile(src, options = {}, callback) {
|
|
3059
|
-
let promises, outSrc;
|
|
3090
|
+
let promises = false, outSrc;
|
|
3060
3091
|
[options, promises, callback] = parseFileArgs(options, callback);
|
|
3061
3092
|
if (outSrc = hasFileSystem(this, 1, src, options)) {
|
|
3062
3093
|
if (promises) {
|
|
@@ -3096,7 +3127,7 @@ class Module extends EventEmitter {
|
|
|
3096
3127
|
return false;
|
|
3097
3128
|
}
|
|
3098
3129
|
copyFile(src, dest, options = {}, callback) {
|
|
3099
|
-
let promises, outSrc, outDest;
|
|
3130
|
+
let promises = false, outSrc, outDest;
|
|
3100
3131
|
[options, promises, callback] = parseFileArgs(options, callback);
|
|
3101
3132
|
if ((outSrc = hasFileSystem(this, 0, src, options)) && (outDest = hasFileSystem(this, 1, dest, options, true, options.overwrite))) {
|
|
3102
3133
|
const destDir = path.dirname(outDest);
|
|
@@ -3149,7 +3180,7 @@ class Module extends EventEmitter {
|
|
|
3149
3180
|
return false;
|
|
3150
3181
|
}
|
|
3151
3182
|
moveFile(src, dest, options = {}, callback) {
|
|
3152
|
-
let promises, outSrc, outDest;
|
|
3183
|
+
let promises = false, outSrc, outDest;
|
|
3153
3184
|
[options, promises, callback] = parseFileArgs(options, callback);
|
|
3154
3185
|
if ((outSrc = hasFileSystem(this, 1, src, options)) && (outDest = hasFileSystem(this, 1, dest, options, true, options.overwrite))) {
|
|
3155
3186
|
const destDir = path.dirname(outDest);
|
|
@@ -3224,7 +3255,7 @@ class Module extends EventEmitter {
|
|
|
3224
3255
|
return false;
|
|
3225
3256
|
}
|
|
3226
3257
|
createDir(src, options = {}, callback) {
|
|
3227
|
-
let promises, outSrc;
|
|
3258
|
+
let promises = false, outSrc;
|
|
3228
3259
|
[options, promises, callback] = parseFileArgs(options, callback);
|
|
3229
3260
|
if (outSrc = hasFileSystem(this, 1, src, options, true)) {
|
|
3230
3261
|
if (Module.isDir(outSrc)) {
|
|
@@ -3288,7 +3319,7 @@ class Module extends EventEmitter {
|
|
|
3288
3319
|
return false;
|
|
3289
3320
|
}
|
|
3290
3321
|
removeDir(src, options = {}, callback) {
|
|
3291
|
-
let promises, outSrc;
|
|
3322
|
+
let promises = false, outSrc;
|
|
3292
3323
|
[options, promises, callback] = parseFileArgs(options, callback);
|
|
3293
3324
|
if (outSrc = hasFileSystem(this, 1, src, options, true)) {
|
|
3294
3325
|
try {
|
|
@@ -3401,20 +3432,18 @@ class Module extends EventEmitter {
|
|
|
3401
3432
|
: meter.process) || 250;
|
|
3402
3433
|
const duration = getTimeOffset(startTime, 0);
|
|
3403
3434
|
let meterTime = duration, delayTime = options.delayTime;
|
|
3404
|
-
if (delayTime
|
|
3405
|
-
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
meterTime -= delayTime;
|
|
3409
|
-
}
|
|
3410
|
-
else {
|
|
3411
|
-
delayTime = 0;
|
|
3412
|
-
}
|
|
3435
|
+
if (typeof delayTime === 'bigint' || Array.isArray(delayTime)) {
|
|
3436
|
+
delayTime = Math.max((0, types_1.convertTime)(delayTime), 0);
|
|
3437
|
+
if (delayTime < meterTime) {
|
|
3438
|
+
meterTime -= delayTime;
|
|
3413
3439
|
}
|
|
3414
|
-
|
|
3415
|
-
|
|
3440
|
+
else {
|
|
3441
|
+
delayTime = 0;
|
|
3416
3442
|
}
|
|
3417
3443
|
}
|
|
3444
|
+
if (typeof delayTime === 'number' && delayTime >= 0) {
|
|
3445
|
+
options.messageUnitIndent = [Math.round(delayTime / increment), '-'];
|
|
3446
|
+
}
|
|
3418
3447
|
if (failed && !http) {
|
|
3419
3448
|
value = "Failed" + ' -> ' + value;
|
|
3420
3449
|
}
|
|
@@ -3507,7 +3536,7 @@ class Module extends EventEmitter {
|
|
|
3507
3536
|
}
|
|
3508
3537
|
const host = this.host;
|
|
3509
3538
|
const target = host || this;
|
|
3510
|
-
let fatal;
|
|
3539
|
+
let fatal = false;
|
|
3511
3540
|
if (options.exec && (type & 4096) && target.willAbort("(exec)")) {
|
|
3512
3541
|
const exec = { ...options.exec };
|
|
3513
3542
|
let output = VALUES["permission.process_exec"].find(item => exec.command === ((0, types_1.isObject)(item) ? item.command : item));
|
|
@@ -3582,7 +3611,7 @@ class Module extends EventEmitter {
|
|
|
3582
3611
|
if (this._logEnabled && !(message instanceof Error && hideAbort(message))) {
|
|
3583
3612
|
if (fatal) {
|
|
3584
3613
|
const timeStamp = Date.now();
|
|
3585
|
-
this.addLog(types_1.STATUS_TYPE.FATAL, message, timeStamp, options.startTime
|
|
3614
|
+
this.addLog(types_1.STATUS_TYPE.FATAL, message, timeStamp, options.startTime ? getTimeOffset(options.startTime, timeStamp) : undefined);
|
|
3586
3615
|
}
|
|
3587
3616
|
else {
|
|
3588
3617
|
this.addLog(options.statusType || types_1.STATUS_TYPE.ERROR, message);
|
|
@@ -3627,7 +3656,8 @@ class Module extends EventEmitter {
|
|
|
3627
3656
|
if (typeof options === 'number') {
|
|
3628
3657
|
options = undefined;
|
|
3629
3658
|
}
|
|
3630
|
-
|
|
3659
|
+
const command = VALUES["node.settings.package_manager"] || (setPnpmVer() ? 'pnpm' : setYarnVer() ? 'yarn' : 'npm');
|
|
3660
|
+
this.writeFail("Unknown", err, { ...options, type: types_1.LOG_TYPE.SYSTEM, code: types_1.ERR_CODE.MODULE_NOT_FOUND, exec: { command, args: [command === 'npm' ? 'i' : 'add', name] } });
|
|
3631
3661
|
return true;
|
|
3632
3662
|
}
|
|
3633
3663
|
if (value) {
|
|
@@ -3671,7 +3701,7 @@ class Module extends EventEmitter {
|
|
|
3671
3701
|
}
|
|
3672
3702
|
}
|
|
3673
3703
|
writeLog(type, value, timeStamp, duration) {
|
|
3674
|
-
let queue;
|
|
3704
|
+
let queue = false;
|
|
3675
3705
|
if ((0, types_1.isObject)(type)) {
|
|
3676
3706
|
if (typeof value === 'boolean') {
|
|
3677
3707
|
queue = value;
|
|
@@ -3727,7 +3757,7 @@ class Module extends EventEmitter {
|
|
|
3727
3757
|
duration = undefined;
|
|
3728
3758
|
}
|
|
3729
3759
|
if (typeof value === 'string') {
|
|
3730
|
-
message = this.supports('stripAnsi') ?
|
|
3760
|
+
message = this.supports('stripAnsi') ? (0, node_util_1.stripVTControlCharacters)(value) : value;
|
|
3731
3761
|
}
|
|
3732
3762
|
else if (value instanceof Error) {
|
|
3733
3763
|
if (value.name === 'AbortError') {
|
|
@@ -3762,7 +3792,7 @@ class Module extends EventEmitter {
|
|
|
3762
3792
|
if (args.length === 2) {
|
|
3763
3793
|
const [type, value] = args;
|
|
3764
3794
|
if (this.broadcastId) {
|
|
3765
|
-
Module.formatMessage(type, '', this.supports('stripAnsi') ?
|
|
3795
|
+
Module.formatMessage(type, '', this.supports('stripAnsi') ? (0, node_util_1.stripVTControlCharacters)(value) : value, null, applySessionId(this, { sessionId: '' }));
|
|
3766
3796
|
}
|
|
3767
3797
|
else {
|
|
3768
3798
|
writeLine(args[1]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/module",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.1",
|
|
4
4
|
"description": "Module base class for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -20,12 +20,11 @@
|
|
|
20
20
|
"license": "BSD-3-Clause",
|
|
21
21
|
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/types": "0.
|
|
23
|
+
"@e-mc/types": "0.11.1",
|
|
24
24
|
"chalk": "4.1.2",
|
|
25
25
|
"file-type": "^18.7.0",
|
|
26
26
|
"js-yaml": "^4.1.0",
|
|
27
27
|
"mime-types": "^2.1.35",
|
|
28
|
-
"picomatch": "^4.0.2"
|
|
29
|
-
"strip-ansi": "6.0.1"
|
|
28
|
+
"picomatch": "^4.0.2"
|
|
30
29
|
}
|
|
31
30
|
}
|
package/lib-v4.d.ts
DELETED
package/lib-v4.js
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
exports.validateUUID = exports.renameExt = exports.isString = exports.isPlainObject = exports.isObject = exports.formatSize = exports.escapePattern = exports.toTimeMs = exports.coerceObject = exports.cloneObject = exports.asFunction = void 0;
|
|
3
|
-
exports.hasSize = hasSize;
|
|
4
|
-
exports.getSize = getSize;
|
|
5
|
-
exports.hasSameStat = hasSameStat;
|
|
6
|
-
exports.byteLength = byteLength;
|
|
7
|
-
exports.cleanupStream = cleanupStream;
|
|
8
|
-
exports.generateUUID = generateUUID;
|
|
9
|
-
exports.existsSafe = existsSafe;
|
|
10
|
-
exports.isFileHTTP = isFileHTTP;
|
|
11
|
-
exports.isFileUNC = isFileUNC;
|
|
12
|
-
exports.isPathUNC = isPathUNC;
|
|
13
|
-
exports.readFileSafe = readFileSafe;
|
|
14
|
-
exports.getFunctions = getFunctions;
|
|
15
|
-
exports.allSettled = allSettled;
|
|
16
|
-
const path = require("path");
|
|
17
|
-
const fs = require("fs");
|
|
18
|
-
const types_1 = require("@e-mc/types");
|
|
19
|
-
Object.defineProperty(exports, "asFunction", { enumerable: true, get: function () { return types_1.asFunction; } });
|
|
20
|
-
Object.defineProperty(exports, "cloneObject", { enumerable: true, get: function () { return types_1.cloneObject; } });
|
|
21
|
-
Object.defineProperty(exports, "coerceObject", { enumerable: true, get: function () { return types_1.coerceObject; } });
|
|
22
|
-
Object.defineProperty(exports, "toTimeMs", { enumerable: true, get: function () { return types_1.convertTime; } });
|
|
23
|
-
Object.defineProperty(exports, "escapePattern", { enumerable: true, get: function () { return types_1.escapePattern; } });
|
|
24
|
-
Object.defineProperty(exports, "formatSize", { enumerable: true, get: function () { return types_1.formatSize; } });
|
|
25
|
-
Object.defineProperty(exports, "isObject", { enumerable: true, get: function () { return types_1.isObject; } });
|
|
26
|
-
Object.defineProperty(exports, "isPlainObject", { enumerable: true, get: function () { return types_1.isPlainObject; } });
|
|
27
|
-
Object.defineProperty(exports, "isString", { enumerable: true, get: function () { return types_1.isString; } });
|
|
28
|
-
Object.defineProperty(exports, "renameExt", { enumerable: true, get: function () { return types_1.renameExt; } });
|
|
29
|
-
Object.defineProperty(exports, "validateUUID", { enumerable: true, get: function () { return types_1.validateUUID; } });
|
|
30
|
-
const index_1 = require("@e-mc/module");
|
|
31
|
-
function hasSize(value, keepEmpty) {
|
|
32
|
-
try {
|
|
33
|
-
const statSrc = fs.statSync(value);
|
|
34
|
-
if (statSrc.size > 0) {
|
|
35
|
-
return true;
|
|
36
|
-
}
|
|
37
|
-
if (!keepEmpty) {
|
|
38
|
-
fs.unlinkSync(value);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
catch {
|
|
42
|
-
}
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
function getSize(value, diskUsed) {
|
|
46
|
-
try {
|
|
47
|
-
return fs[diskUsed ? 'lstatSync' : 'statSync'](value).size;
|
|
48
|
-
}
|
|
49
|
-
catch {
|
|
50
|
-
return 0;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
function hasSameStat(src, dest, keepEmpty) {
|
|
54
|
-
try {
|
|
55
|
-
if (fs.existsSync(dest)) {
|
|
56
|
-
const { size, mtimeMs } = fs.statSync(src);
|
|
57
|
-
if (size > 0) {
|
|
58
|
-
const statDest = fs.statSync(dest);
|
|
59
|
-
return size === statDest.size && mtimeMs === statDest.mtimeMs;
|
|
60
|
-
}
|
|
61
|
-
if (!keepEmpty) {
|
|
62
|
-
fs.unlinkSync(src);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
catch {
|
|
67
|
-
}
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
|
-
function byteLength(value, encoding) {
|
|
71
|
-
return typeof value === 'string' && (path.isAbsolute(value) || index_1.isPath(value)) ? getSize(value) : Buffer.byteLength(value, encoding && (0, types_1.getEncoding)(encoding));
|
|
72
|
-
}
|
|
73
|
-
function cleanupStream(stream, uri) {
|
|
74
|
-
stream.removeAllListeners();
|
|
75
|
-
stream.destroy();
|
|
76
|
-
try {
|
|
77
|
-
if (uri && fs.existsSync(uri)) {
|
|
78
|
-
fs.unlinkSync(uri);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
catch (err) {
|
|
82
|
-
if (!index_1.isErrorCode(err, 'ENOENT')) {
|
|
83
|
-
index_1.writeFail(["Unable to delete file", path.basename(uri)], err, 32);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
function generateUUID(format, dictionary) {
|
|
88
|
-
return format ? (0, types_1.randomString)(format, dictionary) : (0, types_1.generateUUID)();
|
|
89
|
-
}
|
|
90
|
-
function existsSafe(value, isFile) {
|
|
91
|
-
return index_1.isPath(value, isFile);
|
|
92
|
-
}
|
|
93
|
-
function isFileHTTP(value) {
|
|
94
|
-
return index_1.isFile(value, 'http/s');
|
|
95
|
-
}
|
|
96
|
-
function isFileUNC(value) {
|
|
97
|
-
return index_1.isFile(value, 'unc');
|
|
98
|
-
}
|
|
99
|
-
function isPathUNC(value) {
|
|
100
|
-
return index_1.isPath(value, 'unc');
|
|
101
|
-
}
|
|
102
|
-
async function readFileSafe(value, encoding, cache) {
|
|
103
|
-
return encoding === 'buffer' ? index_1.readBuffer(value, cache) : index_1.readText(value, encoding, cache);
|
|
104
|
-
}
|
|
105
|
-
function getFunctions(values, absolute, sync = true, outFailed) {
|
|
106
|
-
let options, context;
|
|
107
|
-
if ((0, types_1.isObject)(absolute)) {
|
|
108
|
-
options = absolute;
|
|
109
|
-
({ context, outFailed } = absolute);
|
|
110
|
-
if (options.external === undefined) {
|
|
111
|
-
options.external = true;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
options = { external: true, absolute, sync };
|
|
116
|
-
}
|
|
117
|
-
const result = [];
|
|
118
|
-
for (const value of values) {
|
|
119
|
-
let method = null;
|
|
120
|
-
if (typeof value === 'string') {
|
|
121
|
-
method = index_1.parseFunction(value, options);
|
|
122
|
-
}
|
|
123
|
-
else if (typeof value === 'function') {
|
|
124
|
-
method = value;
|
|
125
|
-
if (context !== undefined) {
|
|
126
|
-
method.bind(context);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
if (method) {
|
|
130
|
-
result.push(method);
|
|
131
|
-
}
|
|
132
|
-
else if (outFailed) {
|
|
133
|
-
outFailed.push(index_1.asString(value) || "Unknown");
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
return result;
|
|
137
|
-
}
|
|
138
|
-
async function allSettled(tasks, rejected, options) {
|
|
139
|
-
if (rejected) {
|
|
140
|
-
return Promise.allSettled(tasks).then(result => {
|
|
141
|
-
const items = [];
|
|
142
|
-
for (const item of result) {
|
|
143
|
-
if (item.status === 'fulfilled') {
|
|
144
|
-
items.push(item);
|
|
145
|
-
}
|
|
146
|
-
else if (item.reason) {
|
|
147
|
-
index_1.writeFail(rejected, item.reason, options);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
return items;
|
|
151
|
-
})
|
|
152
|
-
.catch((err) => {
|
|
153
|
-
index_1.writeFail(rejected, err, options);
|
|
154
|
-
return [];
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
return Promise.allSettled(tasks);
|
|
158
|
-
}
|