@e-mc/module 0.8.10 → 0.9.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 +7 -3
- package/README.md +188 -26
- package/index.js +157 -149
- package/lib-v4.js +13 -14
- package/package.json +4 -6
package/LICENSE
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
Copyright 2024 An Pham
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
8
|
+
|
|
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
|
+
|
|
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
|
|
4
|
-
*
|
|
3
|
+
* NodeJS 16
|
|
4
|
+
* ES2020
|
|
5
5
|
|
|
6
6
|
## General Usage
|
|
7
7
|
|
|
@@ -9,16 +9,17 @@
|
|
|
9
9
|
|
|
10
10
|
## Interface
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
* [View Source](https://www.unpkg.com/@e-mc/types@0.9.1/lib/index.d.ts)
|
|
13
13
|
|
|
14
14
|
```typescript
|
|
15
15
|
import type { LogStatus } from "./squared";
|
|
16
16
|
|
|
17
17
|
import type { IHost } from "./index";
|
|
18
18
|
import type { IAbortComponent, IPermission } from "./core";
|
|
19
|
-
import type { LOG_TYPE, STATUS_TYPE, ExecCommand, LogArguments, LogComponent, LogDate, LogFailOptions, LogMessageOptions, LogOptions, LogProcessOptions, LogTime, LogType, LogValue, StatusType } from "./logger";
|
|
19
|
+
import type { LOG_TYPE, STATUS_TYPE, ExecCommand, LogArguments, LogComponent, LogDate, LogFailOptions, LogMessageOptions, LogOptions, LogProcessOptions, LogTime, LogType, LogValue, LoggerFormat, StatusType } from "./logger";
|
|
20
20
|
import type { AsHashOptions, CheckSemVerOptions, CopyDirOptions, CopyDirResult, CopyFileOptions, CreateDirOptions, DeleteFileOptions, GetTempDirOptions, MoveFileOptions, NormalizeFlags, ParseFunctionOptions, PermissionOptions, ProtocolType, ReadBufferOptions, ReadFileCallback, ReadFileOptions, ReadHashOptions, ReadTextOptions, RemoveDirOptions, WriteFileOptions } from "./module";
|
|
21
21
|
import type { Settings } from "./node";
|
|
22
|
+
import type { LoggerFormatSettings } from "/settings";
|
|
22
23
|
|
|
23
24
|
import type { SpawnOptions } from "child_process";
|
|
24
25
|
import type { BinaryLike } from "crypto";
|
|
@@ -36,9 +37,9 @@ interface IModule extends EventEmitter, IAbortComponent {
|
|
|
36
37
|
supported(major: number, minor?: number, patch?: number, lts?: boolean): boolean;
|
|
37
38
|
supports(name: string, value?: boolean): boolean;
|
|
38
39
|
getTempDir(options: GetTempDirOptions): string;
|
|
39
|
-
getTempDir(uuidDir: boolean, createDir
|
|
40
|
-
getTempDir(pathname: string, createDir
|
|
41
|
-
getTempDir(uuidDir: boolean, filename
|
|
40
|
+
getTempDir(uuidDir: boolean, createDir: boolean): string;
|
|
41
|
+
getTempDir(pathname: string, createDir: boolean): string;
|
|
42
|
+
getTempDir(uuidDir: boolean, filename?: string, createDir?: boolean): string;
|
|
42
43
|
getTempDir(pathname?: string, filename?: string, createDir?: boolean): string;
|
|
43
44
|
canRead(uri: string, options?: PermissionOptions): boolean;
|
|
44
45
|
canWrite(uri: string, options?: PermissionOptions): boolean;
|
|
@@ -46,7 +47,7 @@ interface IModule extends EventEmitter, IAbortComponent {
|
|
|
46
47
|
readFile(src: string, options?: ReadFileOptions): Promise<Buffer | string> | Buffer | string | undefined;
|
|
47
48
|
readFile(src: string, promises: true): Promise<Buffer | undefined>;
|
|
48
49
|
readFile(src: string, options: ReadFileOptions, promises: true): Promise<Buffer | string | undefined>;
|
|
49
|
-
readFile(src: string, callback: ReadFileCallback<Buffer>): Buffer | undefined;
|
|
50
|
+
readFile(src: string, callback: ReadFileCallback<Buffer | string>): Buffer | string | undefined;
|
|
50
51
|
readFile(src: string, options: ReadFileOptions, callback: ReadFileCallback<Buffer | string>): Buffer | string | undefined;
|
|
51
52
|
writeFile(src: string, data: BufferView, options?: WriteFileOptions): boolean;
|
|
52
53
|
writeFile(src: string, data: BufferView, promises: true): Promise<boolean>;
|
|
@@ -78,21 +79,24 @@ interface IModule extends EventEmitter, IAbortComponent {
|
|
|
78
79
|
removeDir(src: string, options: RemoveDirOptions, promises: true): Promise<boolean>;
|
|
79
80
|
removeDir(src: string, callback: NoParamCallback): void;
|
|
80
81
|
removeDir(src: string, options: RemoveDirOptions, callback: NoParamCallback): void;
|
|
81
|
-
allSettled(values: readonly PromiseLike<unknown>[], rejected?: LogValue,
|
|
82
|
+
allSettled(values: readonly PromiseLike<unknown>[], rejected?: LogValue, type?: LogType): Promise<PromiseFulfilledResult<unknown>[]>;
|
|
83
|
+
allSettled(values: readonly PromiseLike<unknown>[], rejected?: LogValue, options?: LogFailOptions): Promise<PromiseFulfilledResult<unknown>[]>;
|
|
82
84
|
formatMessage(type: LogType, title: string, value: LogValue, message?: unknown, options?: LogMessageOptions): void;
|
|
83
85
|
formatFail(type: LogType, title: string, value: LogValue, message?: unknown, options?: LogFailOptions): void;
|
|
84
|
-
writeFail(value: LogValue, message?: unknown,
|
|
86
|
+
writeFail(value: LogValue, message?: unknown, type?: LogType): void;
|
|
87
|
+
writeFail(value: LogValue, message?: unknown, options?: LogFailOptions): void;
|
|
85
88
|
writeTimeProcess(title: string, value: string, startTime: LogTime, options?: LogProcessOptions): void;
|
|
86
89
|
writeTimeElapsed(title: string, value: LogValue, startTime: LogTime, options?: LogMessageOptions): void;
|
|
87
|
-
checkPackage(err: unknown, name: string | undefined,
|
|
90
|
+
checkPackage(err: unknown, name: string | undefined, type: LogType): boolean;
|
|
91
|
+
checkPackage(err: unknown, name: string | undefined, options: LogFailOptions): boolean;
|
|
88
92
|
checkPackage(err: unknown, name: string | undefined, value?: LogValue, options?: LogFailOptions | LogType): boolean;
|
|
89
93
|
checkFail(message: unknown, options: LogFailOptions): LogArguments | false | undefined;
|
|
90
94
|
writeLog(component: LogComponent, queue?: boolean): void;
|
|
91
|
-
writeLog(type: StatusType, value: unknown, options
|
|
95
|
+
writeLog(type: StatusType, value: unknown, options: LogOptions): void;
|
|
92
96
|
writeLog(type: StatusType, value: unknown, timeStamp?: LogDate, duration?: number): void;
|
|
93
97
|
addLog(component: LogComponent, queue?: boolean): void;
|
|
98
|
+
addLog(type: StatusType, value: unknown, options: LogOptions): void;
|
|
94
99
|
addLog(type: StatusType, value: unknown, from: string, source?: string): void;
|
|
95
|
-
addLog(type: StatusType, value: unknown, options?: LogOptions): void;
|
|
96
100
|
addLog(type: StatusType, value: unknown, timeStamp?: LogDate, from?: string, source?: string): void;
|
|
97
101
|
addLog(type: StatusType, value: unknown, timeStamp?: LogDate, duration?: number, from?: string, source?: string): void;
|
|
98
102
|
getLog(...type: StatusType[]): LogStatus<StatusType>[];
|
|
@@ -162,6 +166,7 @@ interface ModuleConstructor {
|
|
|
162
166
|
LOG_STYLE_REVERSE: LogMessageOptions;
|
|
163
167
|
readonly VERSION: string;
|
|
164
168
|
readonly LOG_TYPE: LOG_TYPE;
|
|
169
|
+
readonly LOG_FORMAT: LoggerFormatSettings<LoggerFormat<number>>;
|
|
165
170
|
readonly STATUS_TYPE: STATUS_TYPE;
|
|
166
171
|
readonly MAX_TIMEOUT: number;
|
|
167
172
|
readonly TEMP_DIR: string;
|
|
@@ -172,9 +177,10 @@ interface ModuleConstructor {
|
|
|
172
177
|
parseFunction(value: unknown, options?: ParseFunctionOptions): ((...args: unknown[]) => Promise<unknown> | unknown) | null;
|
|
173
178
|
parseFunction(value: unknown, absolute: boolean, sync?: boolean): ((...args: unknown[]) => Promise<unknown> | unknown) | null;
|
|
174
179
|
asString(value: unknown, cacheKey?: boolean | "throws"): string;
|
|
175
|
-
asHash(data: BinaryLike, options: AsHashOptions): string;
|
|
176
180
|
asHash(data: BinaryLike, minLength: number): string;
|
|
177
|
-
asHash(data: BinaryLike, algorithm
|
|
181
|
+
asHash(data: BinaryLike, algorithm: string, minLength?: number): string;
|
|
182
|
+
asHash(data: BinaryLike, algorithm?: string, options?: AsHashOptions): string;
|
|
183
|
+
asHash(data: BinaryLike, options?: AsHashOptions): string;
|
|
178
184
|
readHash(value: string | URL, options?: ReadHashOptions): Promise<string>;
|
|
179
185
|
toPosix(value: unknown, normalize: boolean): string;
|
|
180
186
|
toPosix(value: unknown, filename?: string, normalize?: boolean): string;
|
|
@@ -194,17 +200,17 @@ interface ModuleConstructor {
|
|
|
194
200
|
createDir(value: string | URL, overwrite?: boolean): boolean;
|
|
195
201
|
removeDir(value: string | URL, sinceCreated: number, recursive?: boolean): boolean;
|
|
196
202
|
removeDir(value: string | URL, empty?: boolean, recursive?: boolean): boolean;
|
|
197
|
-
copyDir(src: string | URL, dest: string | URL, options: CopyDirOptions): Promise<CopyDirResult>;
|
|
198
203
|
copyDir(src: string | URL, dest: string | URL, move?: boolean, recursive?: boolean): Promise<CopyDirResult>;
|
|
204
|
+
copyDir(src: string | URL, dest: string | URL, options?: CopyDirOptions): Promise<CopyDirResult>;
|
|
199
205
|
renameFile(src: string | URL, dest: string | URL, throws?: boolean): boolean;
|
|
200
206
|
streamFile(src: string, cache: boolean): Promise<Buffer | string>;
|
|
201
207
|
streamFile(src: string, options: ReadBufferOptions): Promise<Buffer | string>;
|
|
202
208
|
streamFile(src: string, cache?: boolean | ReadBufferOptions, options?: ReadBufferOptions): Promise<Buffer | string>;
|
|
203
209
|
readText(value: string | URL, cache: boolean): string;
|
|
204
210
|
readText(value: string | URL, options: ReadTextOptions): Promise<string> | string;
|
|
205
|
-
readText(value: string | URL, encoding?: BufferEncoding |
|
|
211
|
+
readText(value: string | URL, encoding?: BufferEncoding | ReadTextOptions, cache?: boolean): string;
|
|
206
212
|
readBuffer(value: string | URL, options: ReadBufferOptions): Promise<Buffer | null> | Buffer | null;
|
|
207
|
-
readBuffer(value: string | URL, cache?: boolean): Buffer | null;
|
|
213
|
+
readBuffer(value: string | URL, cache?: boolean | ReadBufferOptions): Buffer | null;
|
|
208
214
|
resolveMime(data: string | Buffer | Uint8Array | ArrayBuffer): Promise<FileTypeResult | undefined>;
|
|
209
215
|
lookupMime(value: string, extension?: boolean): string;
|
|
210
216
|
initCpuUsage(instance?: IModule): CpuUsage;
|
|
@@ -216,13 +222,14 @@ interface ModuleConstructor {
|
|
|
216
222
|
getPackageVersion(name: string | [string, string], startDir: string, baseDir?: string): string;
|
|
217
223
|
getPackageVersion(name: string | [string, string], unstable?: boolean, startDir?: string, baseDir?: string): string;
|
|
218
224
|
checkSemVer(name: string | [string, string], options: CheckSemVerOptions): boolean;
|
|
219
|
-
checkSemVer(name: string | [string, string], min: number | string, max: number | string, options: CheckSemVerOptions): boolean;
|
|
220
225
|
checkSemVer(name: string | [string, string], min: number | string, max?: number | string, unstable?: boolean, startDir?: string): boolean;
|
|
226
|
+
checkSemVer(name: string | [string, string], min: number | string, max: number | string, options?: CheckSemVerOptions): boolean;
|
|
221
227
|
sanitizeCmd(value: string): string;
|
|
222
228
|
sanitizeArgs(value: string, doubleQuote?: boolean): string;
|
|
223
229
|
sanitizeArgs(values: string[], doubleQuote?: boolean): string[];
|
|
224
|
-
purgeMemory(percent: number, parent: boolean
|
|
225
|
-
purgeMemory(percent
|
|
230
|
+
purgeMemory(percent: number, parent: boolean): Promise<number>;
|
|
231
|
+
purgeMemory(percent: number, limit: number, parent?: boolean): Promise<number>;
|
|
232
|
+
purgeMemory(percent?: number, limit?: number | boolean, parent?: unknown): Promise<number>;
|
|
226
233
|
canWrite(name: "temp" | "home"): boolean;
|
|
227
234
|
loadSettings(settings: Settings, password?: string): boolean;
|
|
228
235
|
readonly prototype: IModule<IHost>;
|
|
@@ -230,13 +237,168 @@ interface ModuleConstructor {
|
|
|
230
237
|
}
|
|
231
238
|
```
|
|
232
239
|
|
|
240
|
+
## Settings
|
|
241
|
+
|
|
242
|
+
```typescript
|
|
243
|
+
import type { LogMessageOptions, LogTypeValue, LoggerStatus } from "./logger";
|
|
244
|
+
import type { LoggerProcessSettings } from "./settings";
|
|
245
|
+
|
|
246
|
+
import type { BackgroundColor as IBackgroundColor, ForegroundColor as IForegroundColor } from "chalk";
|
|
247
|
+
import type { BinaryLike, CipherGCMTypes } from "crypto";
|
|
248
|
+
import type { SecureVersion } from "tls";
|
|
249
|
+
|
|
250
|
+
interface NodeModule {
|
|
251
|
+
process?: {
|
|
252
|
+
cpu_usage?: boolean;
|
|
253
|
+
memory_usage?: boolean;
|
|
254
|
+
inline?: boolean;
|
|
255
|
+
};
|
|
256
|
+
require?: {
|
|
257
|
+
ext?: string | string[] | boolean;
|
|
258
|
+
npm?: boolean;
|
|
259
|
+
inline?: boolean;
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
interface ProcessModule {
|
|
264
|
+
env?: {
|
|
265
|
+
apply?: boolean;
|
|
266
|
+
};
|
|
267
|
+
cipher?: {
|
|
268
|
+
algorithm?: CipherGCMTypes;
|
|
269
|
+
key?: BinaryLike;
|
|
270
|
+
iv?: BinaryLike;
|
|
271
|
+
};
|
|
272
|
+
password?: string;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
interface MemoryModule {
|
|
276
|
+
settings?: {
|
|
277
|
+
users?: boolean | string[];
|
|
278
|
+
cache_disk?: {
|
|
279
|
+
enabled?: boolean;
|
|
280
|
+
min_size?: number | string;
|
|
281
|
+
max_size?: number | string;
|
|
282
|
+
include?: string[];
|
|
283
|
+
exclude?: string[];
|
|
284
|
+
expires?: number | string;
|
|
285
|
+
};
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
interface PermissionModule {
|
|
290
|
+
home_read?: boolean;
|
|
291
|
+
home_write?: boolean;
|
|
292
|
+
process_exec?: (string | ExecOptions)[];
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
interface ErrorModule {
|
|
296
|
+
out?: string | (err: Error, data: LogTypeValue, require?: NodeRequire) => void;
|
|
297
|
+
fatal?: boolean;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
interface TempModule {
|
|
301
|
+
dir?: string;
|
|
302
|
+
write?: boolean;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
interface LoggerModule {
|
|
306
|
+
enabled?: boolean;
|
|
307
|
+
level?: number,
|
|
308
|
+
production?: string[];
|
|
309
|
+
format?: {
|
|
310
|
+
title?: {
|
|
311
|
+
width?: number;
|
|
312
|
+
color?: ForegroundColor;
|
|
313
|
+
bg_color?: BackgroundColor;
|
|
314
|
+
bold?: boolean;
|
|
315
|
+
justify?: "left" | "center" | "right";
|
|
316
|
+
as?: StringMap;
|
|
317
|
+
};
|
|
318
|
+
value?: {
|
|
319
|
+
width?: number;
|
|
320
|
+
color?: ForegroundColor;
|
|
321
|
+
bg_color?: BackgroundColor;
|
|
322
|
+
bold?: boolean;
|
|
323
|
+
justify?: "left" | "center" | "right";
|
|
324
|
+
},
|
|
325
|
+
hint?: {
|
|
326
|
+
width?: number;
|
|
327
|
+
color?: ForegroundColor;
|
|
328
|
+
bg_color?: BackgroundColor;
|
|
329
|
+
bold?: boolean;
|
|
330
|
+
as?: StringMap;
|
|
331
|
+
unit?: "auto" | "s" | "ms";
|
|
332
|
+
};
|
|
333
|
+
message?: {
|
|
334
|
+
width?: number;
|
|
335
|
+
color?: ForegroundColor;
|
|
336
|
+
bg_color?: BackgroundColor;
|
|
337
|
+
bold?: boolean;
|
|
338
|
+
};
|
|
339
|
+
meter?: {
|
|
340
|
+
color?: ForegroundColor;
|
|
341
|
+
bg_color?: BackgroundColor;
|
|
342
|
+
bg_alt_color?: BackgroundColor;
|
|
343
|
+
bold?: boolean;
|
|
344
|
+
};
|
|
345
|
+
};
|
|
346
|
+
meter?: {
|
|
347
|
+
http?: number;
|
|
348
|
+
image?: number;
|
|
349
|
+
compress?: number;
|
|
350
|
+
process?: number;
|
|
351
|
+
};
|
|
352
|
+
broadcast?: {
|
|
353
|
+
enabled?: boolean;
|
|
354
|
+
out?: string | (value: string, options: LogMessageOptions, require?: NodeRequire) => void;
|
|
355
|
+
color?: boolean;
|
|
356
|
+
port?: number | number[];
|
|
357
|
+
secure?: {
|
|
358
|
+
port?: number | number[];
|
|
359
|
+
ca?: string;
|
|
360
|
+
key?: string;
|
|
361
|
+
cert?: string;
|
|
362
|
+
version?: SecureVersion
|
|
363
|
+
};
|
|
364
|
+
};
|
|
365
|
+
color?: boolean;
|
|
366
|
+
message?: boolean;
|
|
367
|
+
stdout?: boolean;
|
|
368
|
+
abort?: boolean;
|
|
369
|
+
status?: boolean | LoggerStatus;
|
|
370
|
+
unknown?: boolean | LoggerColor;
|
|
371
|
+
system?: boolean | LoggerColor;
|
|
372
|
+
process?: boolean | LoggerProcessSettings;
|
|
373
|
+
image?: boolean | LoggerColor;
|
|
374
|
+
compress?: boolean | LoggerColor;
|
|
375
|
+
watch?: boolean | LoggerColor;
|
|
376
|
+
file?: boolean | LoggerColor;
|
|
377
|
+
cloud?: boolean | LoggerColor;
|
|
378
|
+
db?: boolean | LoggerColor;
|
|
379
|
+
time_elapsed?: boolean | LoggerColor;
|
|
380
|
+
time_process?: boolean | LoggerColor;
|
|
381
|
+
exec?: boolean | LoggerColor;
|
|
382
|
+
http?: boolean | LoggerColor;
|
|
383
|
+
node?: boolean | LoggerColor;
|
|
384
|
+
session_id?: boolean | number;
|
|
385
|
+
stack_trace?: boolean | number;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
type BackgroundColor = typeof IBackgroundColor | `#${string}`;
|
|
389
|
+
type ForegroundColor = typeof IForegroundColor | `#${string}`;
|
|
390
|
+
```
|
|
391
|
+
|
|
233
392
|
## References
|
|
234
393
|
|
|
235
|
-
- https://www.unpkg.com/@e-mc/types@0.
|
|
236
|
-
- https://www.unpkg.com/@e-mc/types@0.
|
|
237
|
-
- https://www.unpkg.com/@e-mc/types@0.
|
|
238
|
-
- https://www.unpkg.com/@e-mc/types@0.
|
|
394
|
+
- https://www.unpkg.com/@e-mc/types@0.9.1/lib/core.d.ts
|
|
395
|
+
- https://www.unpkg.com/@e-mc/types@0.9.1/lib/logger.d.ts
|
|
396
|
+
- https://www.unpkg.com/@e-mc/types@0.9.1/lib/module.d.ts
|
|
397
|
+
- https://www.unpkg.com/@e-mc/types@0.9.1/lib/node.d.ts
|
|
398
|
+
- https://www.unpkg.com/@e-mc/types@0.9.1/lib/settings.d.ts
|
|
399
|
+
|
|
400
|
+
* https://www.npmjs.com/package/@types/node
|
|
239
401
|
|
|
240
402
|
## LICENSE
|
|
241
403
|
|
|
242
|
-
|
|
404
|
+
BSD 3-Clause
|
package/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
3
|
const path = require("path");
|
|
5
4
|
const fs = require("fs");
|
|
6
5
|
const os = require("os");
|
|
@@ -212,14 +211,12 @@ function setYarnVer() {
|
|
|
212
211
|
}
|
|
213
212
|
function applyStyle(options, style) {
|
|
214
213
|
var _h;
|
|
215
|
-
var _j;
|
|
216
214
|
for (const attr in style) {
|
|
217
|
-
(_h =
|
|
215
|
+
(_h = options)[attr] ?? (_h[attr] = style[attr]);
|
|
218
216
|
}
|
|
219
217
|
return options;
|
|
220
218
|
}
|
|
221
219
|
function checkColorOptions(type, settings, options) {
|
|
222
|
-
var _h, _j, _k, _l;
|
|
223
220
|
if (typeof settings !== 'object') {
|
|
224
221
|
return false;
|
|
225
222
|
}
|
|
@@ -233,7 +230,7 @@ function checkColorOptions(type, settings, options) {
|
|
|
233
230
|
result = true;
|
|
234
231
|
}
|
|
235
232
|
if (typeof settings.valueBold === 'boolean') {
|
|
236
|
-
|
|
233
|
+
options.valueBold ?? (options.valueBold = settings.valueBold);
|
|
237
234
|
}
|
|
238
235
|
if (settings.hintColor) {
|
|
239
236
|
options.hintColor || (options.hintColor = settings.hintColor);
|
|
@@ -244,7 +241,7 @@ function checkColorOptions(type, settings, options) {
|
|
|
244
241
|
result = true;
|
|
245
242
|
}
|
|
246
243
|
if (typeof settings.hintBold === 'boolean') {
|
|
247
|
-
|
|
244
|
+
options.hintBold ?? (options.hintBold = settings.hintBold);
|
|
248
245
|
}
|
|
249
246
|
if (type & types_1.LOG_TYPE.FAIL) {
|
|
250
247
|
return result;
|
|
@@ -258,7 +255,7 @@ function checkColorOptions(type, settings, options) {
|
|
|
258
255
|
result = true;
|
|
259
256
|
}
|
|
260
257
|
if (typeof settings.titleBold === 'boolean') {
|
|
261
|
-
|
|
258
|
+
options.titleBold ?? (options.titleBold = settings.titleBold);
|
|
262
259
|
}
|
|
263
260
|
if (settings.messageColor) {
|
|
264
261
|
options.messageColor || (options.messageColor = settings.messageColor);
|
|
@@ -269,7 +266,7 @@ function checkColorOptions(type, settings, options) {
|
|
|
269
266
|
result = true;
|
|
270
267
|
}
|
|
271
268
|
if (typeof settings.messageBold === 'boolean') {
|
|
272
|
-
|
|
269
|
+
options.messageBold ?? (options.messageBold = settings.messageBold);
|
|
273
270
|
}
|
|
274
271
|
return result;
|
|
275
272
|
}
|
|
@@ -510,7 +507,6 @@ function getCacheItem(map, key) {
|
|
|
510
507
|
return item[1];
|
|
511
508
|
}
|
|
512
509
|
function addCacheItem(map, key, data, cache) {
|
|
513
|
-
var _h;
|
|
514
510
|
const length = Buffer.byteLength(data);
|
|
515
511
|
if (length < MEMORY_CACHE_DISK.min_size || length > MEMORY_CACHE_DISK.max_size) {
|
|
516
512
|
return;
|
|
@@ -526,7 +522,7 @@ function addCacheItem(map, key, data, cache) {
|
|
|
526
522
|
cache = true;
|
|
527
523
|
}
|
|
528
524
|
}
|
|
529
|
-
if (!(cache &&
|
|
525
|
+
if (!(cache && MEMORY_CACHE_DISK.exclude?.some(value => pm.isMatch(key, value, { nocase: PLATFORM_WIN32, matchBase: value.startsWith('*') })))) {
|
|
530
526
|
if (!map.has(key)) {
|
|
531
527
|
++CACHE_TOTAL;
|
|
532
528
|
}
|
|
@@ -542,7 +538,7 @@ function checkFunction(value) {
|
|
|
542
538
|
}
|
|
543
539
|
function encryptMessage(data, cipher, algorithm) {
|
|
544
540
|
var _h;
|
|
545
|
-
if (
|
|
541
|
+
if (cipher?.key && cipher.iv) {
|
|
546
542
|
algorithm || (algorithm = cipher.algorithm || 'aes-256-gcm');
|
|
547
543
|
const result = (0, types_1.encryptUTF8)(algorithm, cipher.key, cipher.iv, data);
|
|
548
544
|
if (result) {
|
|
@@ -552,16 +548,27 @@ function encryptMessage(data, cipher, algorithm) {
|
|
|
552
548
|
}
|
|
553
549
|
return data;
|
|
554
550
|
}
|
|
555
|
-
function
|
|
556
|
-
|
|
557
|
-
|
|
551
|
+
function relayMessage(args) {
|
|
552
|
+
const host = this.host;
|
|
553
|
+
if (host?.logState === 0) {
|
|
554
|
+
host.delayMessage(args);
|
|
558
555
|
}
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
556
|
+
else {
|
|
557
|
+
Module.formatMessage(...args);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
function setCpuAndMem(options) {
|
|
561
|
+
if (!options.messageUnit) {
|
|
562
|
+
const usage = CACHE_CPUHOST.get(this) || this.host && CACHE_CPUHOST.get(this.host);
|
|
563
|
+
if (usage) {
|
|
564
|
+
options.messageUnit = Module.formatCpuMem(usage);
|
|
565
|
+
}
|
|
562
566
|
}
|
|
563
567
|
}
|
|
564
568
|
function hasFileSystem(type, value, options, ignoreExists, overwrite) {
|
|
569
|
+
if (!(value = asFile(value))) {
|
|
570
|
+
return '';
|
|
571
|
+
}
|
|
565
572
|
let result;
|
|
566
573
|
if (path.isAbsolute(value)) {
|
|
567
574
|
if (options.absolutePath === false) {
|
|
@@ -604,7 +611,7 @@ function hasFileSystem(type, value, options, ignoreExists, overwrite) {
|
|
|
604
611
|
}
|
|
605
612
|
else if (options.hostPermissionOnly) {
|
|
606
613
|
const host = this.host;
|
|
607
|
-
if (
|
|
614
|
+
if (host?.permission && !host[method](result)) {
|
|
608
615
|
if (options.throwsPermission) {
|
|
609
616
|
throw errorPermission(result);
|
|
610
617
|
}
|
|
@@ -620,8 +627,7 @@ function hasFileSystem(type, value, options, ignoreExists, overwrite) {
|
|
|
620
627
|
return result;
|
|
621
628
|
}
|
|
622
629
|
function applyLogId(options) {
|
|
623
|
-
|
|
624
|
-
(_h = options.sessionId) !== null && _h !== void 0 ? _h : (options.sessionId = this.sessionId);
|
|
630
|
+
options.sessionId ?? (options.sessionId = this.sessionId);
|
|
625
631
|
let value = options.broadcastId;
|
|
626
632
|
if (value === undefined) {
|
|
627
633
|
if (value = this.broadcastId) {
|
|
@@ -652,7 +658,7 @@ function formatPercent(value, precision = 3) {
|
|
|
652
658
|
return (value * 100).toPrecision(precision) + '%';
|
|
653
659
|
}
|
|
654
660
|
const hideAbort = (err) => err.name === 'AbortError' && SETTINGS.abort === false;
|
|
655
|
-
const asFile = (value) =>
|
|
661
|
+
const asFile = (value) => typeof value === 'string' ? value.trim() : value instanceof URL && value.protocol === 'file:' ? url.fileURLToPath(value) : '';
|
|
656
662
|
const wrapQuote = (value) => '"' + value.replace(/"/g, '\\"') + '"';
|
|
657
663
|
const isFunction = (value) => typeof value === 'function';
|
|
658
664
|
const isFileURL = (value) => /^file:\/\//i.test(value);
|
|
@@ -660,11 +666,12 @@ const sanitizePath = (value) => value ? path.resolve(value) : '';
|
|
|
660
666
|
const ensureDir = (value) => value.endsWith(path.sep) ? value : value + path.sep;
|
|
661
667
|
const trimDir = (value) => value.endsWith(path.sep) ? value.substring(0, value.length - 1) : value;
|
|
662
668
|
const getExtension = (value) => path.extname(value).toLowerCase().substring(1);
|
|
663
|
-
const hasString = (item, value) =>
|
|
669
|
+
const hasString = (item, value) => item === value || Array.isArray(item) && item.includes(value);
|
|
664
670
|
const getCpuTimes = () => os.cpus().reduce((a, b) => a + b.times.user + b.times.sys, 0) * 1000;
|
|
665
671
|
const autoMemoryCache = () => MEMORY_CACHE_DISK.enabled && MEMORY_CACHE_DISK.max_size > 0;
|
|
666
672
|
const errorDirectory = (value) => (0, types_1.errorValue)("Path is not a directory", value);
|
|
667
|
-
const errorPermission = (value) => (0, types_1.errorValue)("Unsupported access", value);
|
|
673
|
+
const errorPermission = (value) => (0, types_1.errorValue)("Unsupported access", asFile(value));
|
|
674
|
+
const errorCheck = (err, hint) => err instanceof Error ? 'code' in err || 'errno' in err ? err : (0, types_1.errorMessage)("Unknown", err.message, hint) : (0, types_1.errorValue)("Unknown", hint);
|
|
668
675
|
class Module extends EventEmitter {
|
|
669
676
|
constructor() {
|
|
670
677
|
super(...arguments);
|
|
@@ -687,11 +694,12 @@ class Module extends EventEmitter {
|
|
|
687
694
|
this[_f] = new AbortController();
|
|
688
695
|
this[_g] = null;
|
|
689
696
|
}
|
|
690
|
-
static get VERSION() { return "0.
|
|
697
|
+
static get VERSION() { return "0.9.1"; }
|
|
691
698
|
static get LOG_TYPE() { return types_1.LOG_TYPE; }
|
|
692
699
|
static get STATUS_TYPE() { return types_1.STATUS_TYPE; }
|
|
693
700
|
static get MAX_TIMEOUT() { return 2147483647; }
|
|
694
701
|
static get TEMP_DIR() { return TEMP_DIR; }
|
|
702
|
+
static get LOG_FORMAT() { return (0, types_1.cloneObject)(SETTINGS.format, true); }
|
|
695
703
|
static supported(major, minor = 0, patch = 0, lts) {
|
|
696
704
|
if (VER_MAJOR < major) {
|
|
697
705
|
return false;
|
|
@@ -768,7 +776,6 @@ class Module extends EventEmitter {
|
|
|
768
776
|
return true;
|
|
769
777
|
}
|
|
770
778
|
static formatMessage(type, title, value, message, options = {}) {
|
|
771
|
-
var _h, _j, _k, _l;
|
|
772
779
|
const error = !!message && message instanceof Error;
|
|
773
780
|
if (error && hideAbort(message)) {
|
|
774
781
|
return;
|
|
@@ -812,7 +819,7 @@ class Module extends EventEmitter {
|
|
|
812
819
|
const titleIndent = options.titleIndent ? typeof options.titleIndent === 'number' ? Math.max(options.titleIndent, 0) : 0 : -1;
|
|
813
820
|
let output, hint, valueWidth = Math.max(formatValue.width - (id ? SETTINGS.session_id + 1 : 0), 1), titleJustify = options.titleJustify || ((type & 512) || options.failed ? 'center' : formatTitle.justify);
|
|
814
821
|
if (Array.isArray(value)) {
|
|
815
|
-
hint =
|
|
822
|
+
hint = value[1] ?? '';
|
|
816
823
|
value = value[0];
|
|
817
824
|
}
|
|
818
825
|
if (error) {
|
|
@@ -961,7 +968,7 @@ class Module extends EventEmitter {
|
|
|
961
968
|
}
|
|
962
969
|
}
|
|
963
970
|
if (bold) {
|
|
964
|
-
|
|
971
|
+
options.messageBold ?? (options.messageBold = true);
|
|
965
972
|
}
|
|
966
973
|
}
|
|
967
974
|
}
|
|
@@ -979,7 +986,7 @@ class Module extends EventEmitter {
|
|
|
979
986
|
}
|
|
980
987
|
if (!hintColor && !hintBgColor) {
|
|
981
988
|
({ color: hintColor, bgColor: hintBgColor } = formatHint);
|
|
982
|
-
hintBold
|
|
989
|
+
hintBold ?? (hintBold = formatHint.bold);
|
|
983
990
|
}
|
|
984
991
|
value = getValue() + (coloring ? chalk.blackBright('[') + formatColumn(truncateEnd(hint, hintWidth), hintColor, hintBgColor, hintBold) + chalk.blackBright(']') : `[${truncateEnd(hint, hintWidth)}]`);
|
|
985
992
|
}
|
|
@@ -995,7 +1002,7 @@ class Module extends EventEmitter {
|
|
|
995
1002
|
}
|
|
996
1003
|
if (!valueColor && !valueBgColor) {
|
|
997
1004
|
({ color: valueColor, bgColor: valueBgColor } = formatValue);
|
|
998
|
-
valueBold
|
|
1005
|
+
valueBold ?? (valueBold = formatValue.bold);
|
|
999
1006
|
}
|
|
1000
1007
|
try {
|
|
1001
1008
|
let v = value, i = id, m = message;
|
|
@@ -1011,9 +1018,9 @@ class Module extends EventEmitter {
|
|
|
1011
1018
|
const formatMessage = format.message;
|
|
1012
1019
|
if (!messageColor && !messageBgColor) {
|
|
1013
1020
|
({ color: messageColor, bgColor: messageBgColor, bold: messageBold } = formatMessage);
|
|
1014
|
-
messageBold
|
|
1021
|
+
messageBold ?? (messageBold = formatMessage.bold);
|
|
1015
1022
|
}
|
|
1016
|
-
messageWidth
|
|
1023
|
+
messageWidth ?? (messageWidth = formatMessage.width);
|
|
1017
1024
|
let u = unit;
|
|
1018
1025
|
if (u) {
|
|
1019
1026
|
if ((0, types_1.isObject)(SETTINGS.time_process)) {
|
|
@@ -1034,14 +1041,14 @@ class Module extends EventEmitter {
|
|
|
1034
1041
|
}
|
|
1035
1042
|
m = '';
|
|
1036
1043
|
}
|
|
1037
|
-
output = (titleIndent !== -1 ? title : title ? formatColumn(title, titleColor || 'green', titleBgColor, (
|
|
1044
|
+
output = (titleIndent !== -1 ? title : title ? formatColumn(title, titleColor || 'green', titleBgColor, (options.titleBold || formatTitle.bold) ?? false) + chalk.blackBright(':') + ' ' : '') + formatColumn(v, valueColor, valueBgColor, valueBold) + (i ? i : ' ') + m;
|
|
1038
1045
|
}
|
|
1039
1046
|
catch {
|
|
1040
1047
|
}
|
|
1041
1048
|
}
|
|
1042
1049
|
if (!output) {
|
|
1043
|
-
const m = truncateStart(this.asString(message),
|
|
1044
|
-
output = (titleIndent !== -1 ? title : title ? title + ': ' : '') + value + (id ? id : ' ') + (m && SETTINGS.message !== false ? (error ? '{' : '(') + getMessage(m, unit) + (error ? '}' : ')') : '');
|
|
1050
|
+
const m = truncateStart(stripansi(this.asString(message)), options.messageWidth ?? format.message.width);
|
|
1051
|
+
output = (titleIndent !== -1 ? title : title ? title + ': ' : '') + stripansi(value) + (id ? id : ' ') + (m && SETTINGS.message !== false ? (error ? '{' : '(') + getMessage(m, unit) + (error ? '}' : ')') : '');
|
|
1045
1052
|
}
|
|
1046
1053
|
if (broadcastId) {
|
|
1047
1054
|
if (BROADCAST_OUT) {
|
|
@@ -1127,13 +1134,11 @@ class Module extends EventEmitter {
|
|
|
1127
1134
|
catch {
|
|
1128
1135
|
}
|
|
1129
1136
|
}
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
this.writeFail(["Unable to read file", value], err, 32);
|
|
1136
|
-
}
|
|
1137
|
+
try {
|
|
1138
|
+
result || (result = (0, types_1.asFunction)(fs.readFileSync(pathname, 'utf-8'), sync));
|
|
1139
|
+
}
|
|
1140
|
+
catch (err) {
|
|
1141
|
+
this.writeFail(["Unable to read file", value], err, 32);
|
|
1137
1142
|
}
|
|
1138
1143
|
}
|
|
1139
1144
|
if (external && !pathname && VALUES["node.require.npm"] && /^(?:@[a-z\d-*~][a-z\d-*._~]*\/|node:)?[a-z\d-~][a-z\d-._~]*(?:\/.*)?$/.test(location)) {
|
|
@@ -1462,60 +1467,62 @@ class Module extends EventEmitter {
|
|
|
1462
1467
|
}
|
|
1463
1468
|
static createDir(value, overwrite) {
|
|
1464
1469
|
const outDir = sanitizePath(value = asFile(value));
|
|
1465
|
-
if (outDir) {
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
try {
|
|
1473
|
-
fs.unlinkSync(outDir);
|
|
1474
|
-
}
|
|
1475
|
-
catch {
|
|
1476
|
-
this.formatMessage(32, 'WARN', "Unable to overwrite file", value, { ...this.LOG_STYLE_WARN });
|
|
1477
|
-
return false;
|
|
1478
|
-
}
|
|
1479
|
-
}
|
|
1480
|
-
else {
|
|
1481
|
-
return false;
|
|
1482
|
-
}
|
|
1470
|
+
if (!outDir) {
|
|
1471
|
+
return false;
|
|
1472
|
+
}
|
|
1473
|
+
try {
|
|
1474
|
+
const stat = fs.statSync(outDir);
|
|
1475
|
+
if (stat.isDirectory()) {
|
|
1476
|
+
return true;
|
|
1483
1477
|
}
|
|
1484
|
-
|
|
1485
|
-
|
|
1478
|
+
if (overwrite && (stat.isFile() || stat.isSymbolicLink())) {
|
|
1479
|
+
try {
|
|
1480
|
+
fs.unlinkSync(outDir);
|
|
1481
|
+
}
|
|
1482
|
+
catch {
|
|
1483
|
+
this.formatMessage(32, 'WARN', "Unable to overwrite file", value, { ...this.LOG_STYLE_WARN });
|
|
1486
1484
|
return false;
|
|
1487
1485
|
}
|
|
1488
1486
|
}
|
|
1489
|
-
|
|
1490
|
-
return
|
|
1487
|
+
else {
|
|
1488
|
+
return false;
|
|
1491
1489
|
}
|
|
1492
|
-
|
|
1493
|
-
|
|
1490
|
+
}
|
|
1491
|
+
catch (err) {
|
|
1492
|
+
if (this.isErrorCode(err, 'EBUSY', 'EPERM')) {
|
|
1493
|
+
return false;
|
|
1494
1494
|
}
|
|
1495
1495
|
}
|
|
1496
|
+
try {
|
|
1497
|
+
return tryCreateDir(outDir);
|
|
1498
|
+
}
|
|
1499
|
+
catch (err) {
|
|
1500
|
+
this.writeFail(["Unable to create directory", value], err, 32);
|
|
1501
|
+
}
|
|
1496
1502
|
return false;
|
|
1497
1503
|
}
|
|
1498
1504
|
static removeDir(value, empty = false, recursive = true) {
|
|
1499
1505
|
const outDir = sanitizePath(value = asFile(value));
|
|
1500
|
-
if (outDir) {
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
return tryRemoveDir(outDir, empty, !!recursive).length === 0;
|
|
1507
|
-
}
|
|
1508
|
-
if (!fs.existsSync(outDir)) {
|
|
1509
|
-
if (empty && typeof empty !== 'number') {
|
|
1510
|
-
this.createDir(outDir);
|
|
1511
|
-
}
|
|
1512
|
-
return true;
|
|
1513
|
-
}
|
|
1506
|
+
if (!outDir) {
|
|
1507
|
+
return false;
|
|
1508
|
+
}
|
|
1509
|
+
try {
|
|
1510
|
+
if (typeof empty === 'number' && empty <= 0) {
|
|
1511
|
+
empty = true;
|
|
1514
1512
|
}
|
|
1515
|
-
|
|
1516
|
-
|
|
1513
|
+
if (this.isDir(outDir)) {
|
|
1514
|
+
return tryRemoveDir(outDir, empty, !!recursive).length === 0;
|
|
1515
|
+
}
|
|
1516
|
+
if (!fs.existsSync(outDir)) {
|
|
1517
|
+
if (empty && typeof empty !== 'number') {
|
|
1518
|
+
this.createDir(outDir);
|
|
1519
|
+
}
|
|
1520
|
+
return true;
|
|
1517
1521
|
}
|
|
1518
1522
|
}
|
|
1523
|
+
catch (err) {
|
|
1524
|
+
this.writeFail(["Unable to remove directory", value], err, 32);
|
|
1525
|
+
}
|
|
1519
1526
|
return false;
|
|
1520
1527
|
}
|
|
1521
1528
|
static async copyDir(src, dest, move, recursive = true) {
|
|
@@ -1576,7 +1583,7 @@ class Module extends EventEmitter {
|
|
|
1576
1583
|
}
|
|
1577
1584
|
}
|
|
1578
1585
|
if (isFile) {
|
|
1579
|
-
if (ignoreFile
|
|
1586
|
+
if (ignoreFile?.test(name)) {
|
|
1580
1587
|
return ignore();
|
|
1581
1588
|
}
|
|
1582
1589
|
if (overwrite === false) {
|
|
@@ -1593,7 +1600,7 @@ class Module extends EventEmitter {
|
|
|
1593
1600
|
.then(() => {
|
|
1594
1601
|
success.push(destPath);
|
|
1595
1602
|
})
|
|
1596
|
-
.catch(err => {
|
|
1603
|
+
.catch((err) => {
|
|
1597
1604
|
failed.push(srcPath);
|
|
1598
1605
|
if (!silent) {
|
|
1599
1606
|
this.writeFail([move ? "Unable to move file" : "Unable to copy file", path.basename(srcPath)], err, 32);
|
|
@@ -1601,7 +1608,7 @@ class Module extends EventEmitter {
|
|
|
1601
1608
|
}));
|
|
1602
1609
|
}
|
|
1603
1610
|
else if (depth > 0 && (isDir || file.isDirectory())) {
|
|
1604
|
-
if (ignoreDir
|
|
1611
|
+
if (ignoreDir?.test(name)) {
|
|
1605
1612
|
return ignore();
|
|
1606
1613
|
}
|
|
1607
1614
|
recurse.call(this, paths.concat(name), depth - 1);
|
|
@@ -1674,7 +1681,7 @@ class Module extends EventEmitter {
|
|
|
1674
1681
|
}
|
|
1675
1682
|
return false;
|
|
1676
1683
|
}
|
|
1677
|
-
static async streamFile(
|
|
1684
|
+
static async streamFile(value, cache, options) {
|
|
1678
1685
|
if ((0, types_1.isObject)(cache)) {
|
|
1679
1686
|
options = cache;
|
|
1680
1687
|
}
|
|
@@ -1682,28 +1689,32 @@ class Module extends EventEmitter {
|
|
|
1682
1689
|
if (options) {
|
|
1683
1690
|
({ minStreamSize = 0, encoding, signal, cache } = options);
|
|
1684
1691
|
}
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
chunks
|
|
1692
|
+
const src = sanitizePath(asFile(value));
|
|
1693
|
+
if (src && this.isPath(src, true)) {
|
|
1694
|
+
return new Promise(async (resolve) => {
|
|
1695
|
+
const fileSize = fs.statSync(src).size;
|
|
1696
|
+
let data;
|
|
1697
|
+
if (fileSize >= (0, types_1.alignSize)(minStreamSize) || fileSize >= 2097152000) {
|
|
1698
|
+
const readable = fs.createReadStream(src, { signal });
|
|
1699
|
+
const chunks = [];
|
|
1700
|
+
for await (const chunk of readable) {
|
|
1701
|
+
chunks.push(Buffer.from(chunk));
|
|
1702
|
+
}
|
|
1703
|
+
data = Buffer.concat(chunks);
|
|
1704
|
+
if (encoding) {
|
|
1705
|
+
data = data.toString(encoding);
|
|
1706
|
+
}
|
|
1693
1707
|
}
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
data = data.toString(encoding);
|
|
1708
|
+
else {
|
|
1709
|
+
data = fs.readFileSync(src, encoding);
|
|
1697
1710
|
}
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
resolve(data);
|
|
1706
|
-
});
|
|
1711
|
+
if (cache || cache !== false && autoMemoryCache()) {
|
|
1712
|
+
addCacheItem(encoding ? CACHE_READTEXT : CACHE_READBUFFER, src, data, cache);
|
|
1713
|
+
}
|
|
1714
|
+
resolve(data);
|
|
1715
|
+
});
|
|
1716
|
+
}
|
|
1717
|
+
return Promise.resolve((encoding ? '' : null));
|
|
1707
1718
|
}
|
|
1708
1719
|
static readText(value, encoding, cache) {
|
|
1709
1720
|
let minStreamSize, options;
|
|
@@ -1726,7 +1737,7 @@ class Module extends EventEmitter {
|
|
|
1726
1737
|
return this.streamFile(src, options);
|
|
1727
1738
|
}
|
|
1728
1739
|
try {
|
|
1729
|
-
result = fs.readFileSync(
|
|
1740
|
+
result = fs.readFileSync(src, encoding);
|
|
1730
1741
|
if (result && (cache || cache !== false && autoMemoryCache())) {
|
|
1731
1742
|
addCacheItem(CACHE_READTEXT, src, result, cache);
|
|
1732
1743
|
}
|
|
@@ -1754,7 +1765,7 @@ class Module extends EventEmitter {
|
|
|
1754
1765
|
return this.streamFile(src, options);
|
|
1755
1766
|
}
|
|
1756
1767
|
try {
|
|
1757
|
-
result = fs.readFileSync(
|
|
1768
|
+
result = fs.readFileSync(src);
|
|
1758
1769
|
if (result && (cache || cache !== false && autoMemoryCache())) {
|
|
1759
1770
|
addCacheItem(CACHE_READBUFFER, src, result, cache);
|
|
1760
1771
|
}
|
|
@@ -2140,6 +2151,8 @@ class Module extends EventEmitter {
|
|
|
2140
2151
|
CACHE_CPUHOST = new WeakMap();
|
|
2141
2152
|
(0, types_1.purgeMemory)();
|
|
2142
2153
|
CACHE_TOTAL = 0;
|
|
2154
|
+
PNPM_VER = undefined;
|
|
2155
|
+
YARN_VER = undefined;
|
|
2143
2156
|
}
|
|
2144
2157
|
else if (percent > 0) {
|
|
2145
2158
|
const stored = [];
|
|
@@ -2177,7 +2190,6 @@ class Module extends EventEmitter {
|
|
|
2177
2190
|
}
|
|
2178
2191
|
static loadSettings(settings, password) {
|
|
2179
2192
|
var _h;
|
|
2180
|
-
var _j;
|
|
2181
2193
|
const current = VALUES["process.password"];
|
|
2182
2194
|
if (current) {
|
|
2183
2195
|
const proc = settings.process || {};
|
|
@@ -2193,7 +2205,7 @@ class Module extends EventEmitter {
|
|
|
2193
2205
|
}
|
|
2194
2206
|
}
|
|
2195
2207
|
else if ((0, types_1.isString)(password)) {
|
|
2196
|
-
VALUES["process.password"] = encryptMessage(password,
|
|
2208
|
+
VALUES["process.password"] = encryptMessage(password, settings.process?.cipher);
|
|
2197
2209
|
}
|
|
2198
2210
|
const { temp, node, permission, memory, error, logger } = settings;
|
|
2199
2211
|
if ((0, types_1.isPlainObject)(node)) {
|
|
@@ -2239,10 +2251,10 @@ class Module extends EventEmitter {
|
|
|
2239
2251
|
VALUES["process.env.apply"] = env.apply;
|
|
2240
2252
|
}
|
|
2241
2253
|
if ((0, types_1.isString)(pwd)) {
|
|
2242
|
-
VALUES[
|
|
2254
|
+
VALUES[_h = "process.password"] || (VALUES[_h] = encryptMessage(pwd, cipher));
|
|
2243
2255
|
}
|
|
2244
2256
|
}
|
|
2245
|
-
if ((0, types_1.isPlainObject)(memory
|
|
2257
|
+
if ((0, types_1.isPlainObject)(memory?.settings)) {
|
|
2246
2258
|
const { users, cache_disk } = memory.settings;
|
|
2247
2259
|
if (typeof users === 'boolean' || Array.isArray(users)) {
|
|
2248
2260
|
VALUES["memory.settings.users"] = users;
|
|
@@ -2421,7 +2433,7 @@ class Module extends EventEmitter {
|
|
|
2421
2433
|
}
|
|
2422
2434
|
}
|
|
2423
2435
|
}
|
|
2424
|
-
if (broadcast
|
|
2436
|
+
if (broadcast?.out) {
|
|
2425
2437
|
VALUES["broadcast.out"] = this.parseFunction(broadcast.out, { external: true, absolute: true });
|
|
2426
2438
|
}
|
|
2427
2439
|
if (stack_trace && stack_trace !== true && +stack_trace > 0) {
|
|
@@ -2516,7 +2528,7 @@ class Module extends EventEmitter {
|
|
|
2516
2528
|
}
|
|
2517
2529
|
const host = this.host;
|
|
2518
2530
|
const item = this[kSupports][name];
|
|
2519
|
-
return host && !
|
|
2531
|
+
return host && !item?.modified ? host.supports(name) : item?.value === true;
|
|
2520
2532
|
}
|
|
2521
2533
|
getTempDir(pathname, filename, createDir) {
|
|
2522
2534
|
let increment = 0, moduleDir, uuidDir;
|
|
@@ -2540,11 +2552,11 @@ class Module extends EventEmitter {
|
|
|
2540
2552
|
let result;
|
|
2541
2553
|
if ((0, types_1.isString)(pathname)) {
|
|
2542
2554
|
leading.push(pathname);
|
|
2543
|
-
createDir
|
|
2555
|
+
createDir ?? (createDir = true);
|
|
2544
2556
|
}
|
|
2545
2557
|
if (uuidDir) {
|
|
2546
2558
|
leading.push((0, types_1.generateUUID)());
|
|
2547
|
-
createDir
|
|
2559
|
+
createDir ?? (createDir = true);
|
|
2548
2560
|
}
|
|
2549
2561
|
if ((createDir || increment > 0) && !Module.isDir(result = path.join(...leading))) {
|
|
2550
2562
|
const [output] = tryIncrementDir(result, increment);
|
|
@@ -2581,6 +2593,9 @@ class Module extends EventEmitter {
|
|
|
2581
2593
|
ownPermissionOnly = true;
|
|
2582
2594
|
}
|
|
2583
2595
|
}
|
|
2596
|
+
if (!(uri = asFile(uri))) {
|
|
2597
|
+
return false;
|
|
2598
|
+
}
|
|
2584
2599
|
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()))) {
|
|
2585
2600
|
return true;
|
|
2586
2601
|
}
|
|
@@ -2602,6 +2617,9 @@ class Module extends EventEmitter {
|
|
|
2602
2617
|
ownPermissionOnly = true;
|
|
2603
2618
|
}
|
|
2604
2619
|
}
|
|
2620
|
+
if (!(uri = asFile(uri))) {
|
|
2621
|
+
return false;
|
|
2622
|
+
}
|
|
2605
2623
|
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()))) {
|
|
2606
2624
|
return true;
|
|
2607
2625
|
}
|
|
@@ -2622,7 +2640,7 @@ class Module extends EventEmitter {
|
|
|
2622
2640
|
}
|
|
2623
2641
|
};
|
|
2624
2642
|
let result;
|
|
2625
|
-
if (requireExt && VALUES["node.require.ext"] && hasString(requireExt === true ? VALUES["node.require.ext"] : requireExt, getExtension(
|
|
2643
|
+
if (requireExt && VALUES["node.require.ext"] && hasString(requireExt === true ? VALUES["node.require.ext"] : requireExt, getExtension(outSrc))) {
|
|
2626
2644
|
if (cache) {
|
|
2627
2645
|
result = getCacheItem(CACHE_READCJS, outSrc);
|
|
2628
2646
|
}
|
|
@@ -2640,8 +2658,7 @@ class Module extends EventEmitter {
|
|
|
2640
2658
|
result || (result = (encoding ? getCacheItem(CACHE_READTEXT, outSrc) : getCacheItem(CACHE_READBUFFER, outSrc)));
|
|
2641
2659
|
}
|
|
2642
2660
|
try {
|
|
2643
|
-
minStreamSize = (0, types_1.alignSize)(minStreamSize)
|
|
2644
|
-
if (!isNaN(minStreamSize) || promises && fs.statSync(outSrc).size >= 2097152000) {
|
|
2661
|
+
if (!isNaN(minStreamSize = (0, types_1.alignSize)(minStreamSize)) || promises && fs.statSync(outSrc).size >= 2097152000) {
|
|
2645
2662
|
if (result) {
|
|
2646
2663
|
return Promise.resolve(result);
|
|
2647
2664
|
}
|
|
@@ -2680,7 +2697,7 @@ class Module extends EventEmitter {
|
|
|
2680
2697
|
if (!err) {
|
|
2681
2698
|
setCache(data);
|
|
2682
2699
|
}
|
|
2683
|
-
callback(err, data);
|
|
2700
|
+
(callback)(err, data);
|
|
2684
2701
|
});
|
|
2685
2702
|
}
|
|
2686
2703
|
return;
|
|
@@ -2692,7 +2709,7 @@ class Module extends EventEmitter {
|
|
|
2692
2709
|
return result;
|
|
2693
2710
|
}
|
|
2694
2711
|
catch (err) {
|
|
2695
|
-
this.writeFail(["Unable to read file", path.basename(src)], err, 32);
|
|
2712
|
+
this.writeFail(["Unable to read file", path.basename(asFile(src))], err, 32);
|
|
2696
2713
|
}
|
|
2697
2714
|
}
|
|
2698
2715
|
else if (promises) {
|
|
@@ -2717,7 +2734,7 @@ class Module extends EventEmitter {
|
|
|
2717
2734
|
if (!err) {
|
|
2718
2735
|
this.emit('file:write', outSrc, options);
|
|
2719
2736
|
}
|
|
2720
|
-
callback(err);
|
|
2737
|
+
(callback)(err);
|
|
2721
2738
|
});
|
|
2722
2739
|
return;
|
|
2723
2740
|
}
|
|
@@ -2727,7 +2744,7 @@ class Module extends EventEmitter {
|
|
|
2727
2744
|
return true;
|
|
2728
2745
|
}
|
|
2729
2746
|
catch (err) {
|
|
2730
|
-
this.writeFail(["Unable to write file", path.basename(
|
|
2747
|
+
this.writeFail(["Unable to write file", path.basename(outSrc)], err, 32);
|
|
2731
2748
|
}
|
|
2732
2749
|
}
|
|
2733
2750
|
else if (promises) {
|
|
@@ -2754,7 +2771,7 @@ class Module extends EventEmitter {
|
|
|
2754
2771
|
if (!err) {
|
|
2755
2772
|
this.emit('file:delete', outSrc, options);
|
|
2756
2773
|
}
|
|
2757
|
-
callback(err);
|
|
2774
|
+
(callback)(err);
|
|
2758
2775
|
});
|
|
2759
2776
|
return;
|
|
2760
2777
|
}
|
|
@@ -2763,7 +2780,7 @@ class Module extends EventEmitter {
|
|
|
2763
2780
|
}
|
|
2764
2781
|
catch (err) {
|
|
2765
2782
|
if (!Module.isErrorCode(err, 'ENOENT')) {
|
|
2766
|
-
this.writeFail(["Unable to delete file", path.basename(
|
|
2783
|
+
this.writeFail(["Unable to delete file", path.basename(outSrc)], err, 32);
|
|
2767
2784
|
return false;
|
|
2768
2785
|
}
|
|
2769
2786
|
}
|
|
@@ -2809,7 +2826,7 @@ class Module extends EventEmitter {
|
|
|
2809
2826
|
if (!err) {
|
|
2810
2827
|
this.emit('file:copy', outDest, options);
|
|
2811
2828
|
}
|
|
2812
|
-
callback(err);
|
|
2829
|
+
(callback)(err);
|
|
2813
2830
|
});
|
|
2814
2831
|
return;
|
|
2815
2832
|
}
|
|
@@ -2819,7 +2836,7 @@ class Module extends EventEmitter {
|
|
|
2819
2836
|
return true;
|
|
2820
2837
|
}
|
|
2821
2838
|
catch (err) {
|
|
2822
|
-
this.writeFail(["Unable to copy file",
|
|
2839
|
+
this.writeFail(["Unable to copy file", path.basename(outDest)], err, 32);
|
|
2823
2840
|
}
|
|
2824
2841
|
}
|
|
2825
2842
|
}
|
|
@@ -2888,7 +2905,7 @@ class Module extends EventEmitter {
|
|
|
2888
2905
|
if (!err) {
|
|
2889
2906
|
this.emit('file:move', outDest, options);
|
|
2890
2907
|
}
|
|
2891
|
-
callback(err);
|
|
2908
|
+
(callback)(err);
|
|
2892
2909
|
});
|
|
2893
2910
|
return;
|
|
2894
2911
|
}
|
|
@@ -2902,7 +2919,7 @@ class Module extends EventEmitter {
|
|
|
2902
2919
|
this.emit('file:move', outDest, options);
|
|
2903
2920
|
return true;
|
|
2904
2921
|
}
|
|
2905
|
-
this.writeFail(["Unable to move file",
|
|
2922
|
+
this.writeFail(["Unable to move file", path.basename(outDest)], err, 32);
|
|
2906
2923
|
}
|
|
2907
2924
|
}
|
|
2908
2925
|
}
|
|
@@ -2959,7 +2976,7 @@ class Module extends EventEmitter {
|
|
|
2959
2976
|
return success;
|
|
2960
2977
|
});
|
|
2961
2978
|
if (callback) {
|
|
2962
|
-
result.catch(err => callback(err));
|
|
2979
|
+
result.catch((err) => callback(errorCheck(err, outSrc)));
|
|
2963
2980
|
}
|
|
2964
2981
|
return promises ? result : undefined;
|
|
2965
2982
|
}
|
|
@@ -2970,7 +2987,7 @@ class Module extends EventEmitter {
|
|
|
2970
2987
|
}
|
|
2971
2988
|
}
|
|
2972
2989
|
catch (err) {
|
|
2973
|
-
this.writeFail(["Unable to create directory",
|
|
2990
|
+
this.writeFail(["Unable to create directory", path.basename(outSrc)], err, 32);
|
|
2974
2991
|
}
|
|
2975
2992
|
}
|
|
2976
2993
|
else if (promises) {
|
|
@@ -3008,7 +3025,7 @@ class Module extends EventEmitter {
|
|
|
3008
3025
|
return success;
|
|
3009
3026
|
});
|
|
3010
3027
|
if (callback) {
|
|
3011
|
-
result.catch(err => callback(err));
|
|
3028
|
+
result.catch((err) => callback(errorCheck(err, outSrc)));
|
|
3012
3029
|
}
|
|
3013
3030
|
return promises ? result : undefined;
|
|
3014
3031
|
}
|
|
@@ -3040,7 +3057,7 @@ class Module extends EventEmitter {
|
|
|
3040
3057
|
}
|
|
3041
3058
|
}
|
|
3042
3059
|
catch (err) {
|
|
3043
|
-
this.writeFail(["Unable to remove directory",
|
|
3060
|
+
this.writeFail(["Unable to remove directory", path.basename(outSrc)], err, 32);
|
|
3044
3061
|
}
|
|
3045
3062
|
}
|
|
3046
3063
|
else if (promises) {
|
|
@@ -3066,7 +3083,7 @@ class Module extends EventEmitter {
|
|
|
3066
3083
|
}
|
|
3067
3084
|
return items;
|
|
3068
3085
|
})
|
|
3069
|
-
.catch(err => {
|
|
3086
|
+
.catch((err) => {
|
|
3070
3087
|
this.writeFail(rejected, err, options);
|
|
3071
3088
|
return [];
|
|
3072
3089
|
});
|
|
@@ -3128,7 +3145,7 @@ class Module extends EventEmitter {
|
|
|
3128
3145
|
}
|
|
3129
3146
|
else {
|
|
3130
3147
|
setCpuAndMem.call(this, options);
|
|
3131
|
-
|
|
3148
|
+
relayMessage.call(this, args);
|
|
3132
3149
|
}
|
|
3133
3150
|
if (!options.bypassLog) {
|
|
3134
3151
|
this.addLog(types_1.STATUS_TYPE.INFO, title + ' -> ' + value, Date.now(), duration);
|
|
@@ -3165,7 +3182,7 @@ class Module extends EventEmitter {
|
|
|
3165
3182
|
this._logQueued.push(args);
|
|
3166
3183
|
}
|
|
3167
3184
|
else {
|
|
3168
|
-
|
|
3185
|
+
relayMessage.call(this, args);
|
|
3169
3186
|
}
|
|
3170
3187
|
}
|
|
3171
3188
|
formatFail(type, title, value, message, options = {}) {
|
|
@@ -3305,7 +3322,7 @@ class Module extends EventEmitter {
|
|
|
3305
3322
|
this._logQueued.push(args);
|
|
3306
3323
|
}
|
|
3307
3324
|
else {
|
|
3308
|
-
|
|
3325
|
+
relayMessage.call(this, args);
|
|
3309
3326
|
}
|
|
3310
3327
|
}
|
|
3311
3328
|
checkPackage(err, name, value, options) {
|
|
@@ -3317,7 +3334,7 @@ class Module extends EventEmitter {
|
|
|
3317
3334
|
options = value;
|
|
3318
3335
|
value = undefined;
|
|
3319
3336
|
}
|
|
3320
|
-
if (err instanceof Error && err.code === types_1.ERR_CODE.MODULE_NOT_FOUND &&
|
|
3337
|
+
if (err instanceof Error && err.code === types_1.ERR_CODE.MODULE_NOT_FOUND && name) {
|
|
3321
3338
|
if (typeof options === 'number') {
|
|
3322
3339
|
options = undefined;
|
|
3323
3340
|
}
|
|
@@ -3502,9 +3519,8 @@ class Module extends EventEmitter {
|
|
|
3502
3519
|
return !!this[kPermission];
|
|
3503
3520
|
}
|
|
3504
3521
|
isFatal(err) {
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
return fatal !== null && fatal !== void 0 ? fatal : VALUES["error.fatal"];
|
|
3522
|
+
const fatal = this.host?.config.error?.fatal;
|
|
3523
|
+
return fatal ?? VALUES["error.fatal"];
|
|
3508
3524
|
}
|
|
3509
3525
|
get moduleName() {
|
|
3510
3526
|
return this._moduleName;
|
|
@@ -3613,16 +3629,8 @@ Module.LOG_STYLE_INFO = Object.freeze({ titleBgColor: 'bgBlue', titleColor: 'whi
|
|
|
3613
3629
|
Module.LOG_STYLE_WARN = Object.freeze({ titleBgColor: 'bgBlack', titleColor: 'yellow', titleBold: true });
|
|
3614
3630
|
Module.LOG_STYLE_NOTICE = Object.freeze({ titleBgColor: 'bgGrey', titleColor: 'white' });
|
|
3615
3631
|
Module.LOG_STYLE_REVERSE = Object.freeze({ titleBgColor: 'bgWhite', titleColor: 'black', messageBgColor: 'bgGrey' });
|
|
3616
|
-
if (!Module.supported(15, 4) && (!global.AbortController || !global.EventTarget)) {
|
|
3617
|
-
({ AbortController: global.AbortController } = require('abort-controller'));
|
|
3618
|
-
({ EventTarget: global.EventTarget } = require('event-target-shim'));
|
|
3619
|
-
}
|
|
3620
3632
|
EventEmitter.defaultMaxListeners = Infinity;
|
|
3621
3633
|
Object.freeze(types_1.LOG_TYPE);
|
|
3622
3634
|
Object.freeze(types_1.STATUS_TYPE);
|
|
3623
|
-
exports.default = Module;
|
|
3624
3635
|
|
|
3625
|
-
|
|
3626
|
-
module.exports = exports.default;
|
|
3627
|
-
module.exports.default = exports.default;
|
|
3628
|
-
}
|
|
3636
|
+
module.exports = Module;
|
package/lib-v4.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
2
|
exports.validateUUID = exports.renameExt = exports.isString = exports.isPlainObject = exports.isObject = exports.formatSize = exports.escapePattern = exports.toTimeMs = exports.coerceObject = exports.cloneObject = exports.asFunction = exports.allSettled = exports.getFunctions = exports.readFileSafe = exports.isPathUNC = exports.isFileUNC = exports.isFileHTTP = exports.existsSafe = exports.generateUUID = exports.cleanupStream = exports.byteLength = exports.hasSameStat = exports.getSize = exports.hasSize = void 0;
|
|
4
3
|
const path = require("path");
|
|
5
4
|
const fs = require("fs");
|
|
@@ -59,7 +58,7 @@ function hasSameStat(src, dest, keepEmpty) {
|
|
|
59
58
|
}
|
|
60
59
|
exports.hasSameStat = hasSameStat;
|
|
61
60
|
function byteLength(value, encoding) {
|
|
62
|
-
return typeof value === 'string' && (path.isAbsolute(value) || index_1.
|
|
61
|
+
return typeof value === 'string' && (path.isAbsolute(value) || index_1.isPath(value)) ? getSize(value) : Buffer.byteLength(value, encoding && (0, types_1.getEncoding)(encoding));
|
|
63
62
|
}
|
|
64
63
|
exports.byteLength = byteLength;
|
|
65
64
|
function cleanupStream(stream, uri) {
|
|
@@ -71,8 +70,8 @@ function cleanupStream(stream, uri) {
|
|
|
71
70
|
}
|
|
72
71
|
}
|
|
73
72
|
catch (err) {
|
|
74
|
-
if (!index_1.
|
|
75
|
-
index_1.
|
|
73
|
+
if (!index_1.isErrorCode(err, 'ENOENT')) {
|
|
74
|
+
index_1.writeFail(["Unable to delete file", path.basename(uri)], err, 32);
|
|
76
75
|
}
|
|
77
76
|
}
|
|
78
77
|
}
|
|
@@ -82,23 +81,23 @@ function generateUUID(format, dictionary) {
|
|
|
82
81
|
}
|
|
83
82
|
exports.generateUUID = generateUUID;
|
|
84
83
|
function existsSafe(value, isFile) {
|
|
85
|
-
return index_1.
|
|
84
|
+
return index_1.isPath(value, isFile);
|
|
86
85
|
}
|
|
87
86
|
exports.existsSafe = existsSafe;
|
|
88
87
|
function isFileHTTP(value) {
|
|
89
|
-
return index_1.
|
|
88
|
+
return index_1.isFile(value, 'http/s');
|
|
90
89
|
}
|
|
91
90
|
exports.isFileHTTP = isFileHTTP;
|
|
92
91
|
function isFileUNC(value) {
|
|
93
|
-
return index_1.
|
|
92
|
+
return index_1.isFile(value, 'unc');
|
|
94
93
|
}
|
|
95
94
|
exports.isFileUNC = isFileUNC;
|
|
96
95
|
function isPathUNC(value) {
|
|
97
|
-
return index_1.
|
|
96
|
+
return index_1.isPath(value, 'unc');
|
|
98
97
|
}
|
|
99
98
|
exports.isPathUNC = isPathUNC;
|
|
100
99
|
async function readFileSafe(value, encoding, cache) {
|
|
101
|
-
return encoding === 'buffer' ? index_1.
|
|
100
|
+
return encoding === 'buffer' ? index_1.readBuffer(value, cache) : index_1.readText(value, encoding, cache);
|
|
102
101
|
}
|
|
103
102
|
exports.readFileSafe = readFileSafe;
|
|
104
103
|
function getFunctions(values, absolute, sync = true, outFailed) {
|
|
@@ -117,7 +116,7 @@ function getFunctions(values, absolute, sync = true, outFailed) {
|
|
|
117
116
|
for (const value of values) {
|
|
118
117
|
let method = null;
|
|
119
118
|
if (typeof value === 'string') {
|
|
120
|
-
method = index_1.
|
|
119
|
+
method = index_1.parseFunction(value, options);
|
|
121
120
|
}
|
|
122
121
|
else if (typeof value === 'function') {
|
|
123
122
|
method = value;
|
|
@@ -129,7 +128,7 @@ function getFunctions(values, absolute, sync = true, outFailed) {
|
|
|
129
128
|
result.push(method);
|
|
130
129
|
}
|
|
131
130
|
else if (outFailed) {
|
|
132
|
-
outFailed.push(index_1.
|
|
131
|
+
outFailed.push(index_1.asString(value) || "Unknown");
|
|
133
132
|
}
|
|
134
133
|
}
|
|
135
134
|
return result;
|
|
@@ -144,13 +143,13 @@ async function allSettled(tasks, rejected, options) {
|
|
|
144
143
|
items.push(item);
|
|
145
144
|
}
|
|
146
145
|
else if (item.reason) {
|
|
147
|
-
index_1.
|
|
146
|
+
index_1.writeFail(rejected, item.reason, options);
|
|
148
147
|
}
|
|
149
148
|
}
|
|
150
149
|
return items;
|
|
151
150
|
})
|
|
152
|
-
.catch(err => {
|
|
153
|
-
index_1.
|
|
151
|
+
.catch((err) => {
|
|
152
|
+
index_1.writeFail(rejected, err, options);
|
|
154
153
|
return [];
|
|
155
154
|
});
|
|
156
155
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/module",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"description": "Module base class for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -17,17 +17,15 @@
|
|
|
17
17
|
"squared-functions"
|
|
18
18
|
],
|
|
19
19
|
"author": "An Pham <anpham6@gmail.com>",
|
|
20
|
-
"license": "
|
|
20
|
+
"license": "BSD 3-Clause",
|
|
21
21
|
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/types": "0.
|
|
24
|
-
"abort-controller": "^3.0.0",
|
|
23
|
+
"@e-mc/types": "0.9.1",
|
|
25
24
|
"chalk": "4.1.2",
|
|
26
|
-
"event-target-shim": "^5.0.1",
|
|
27
25
|
"file-type": "16.5.4",
|
|
28
26
|
"js-yaml": "^4.1.0",
|
|
29
27
|
"mime-types": "^2.1.35",
|
|
30
|
-
"picomatch": "^
|
|
28
|
+
"picomatch": "^4.0.2",
|
|
31
29
|
"strip-ansi": "6.0.1"
|
|
32
30
|
}
|
|
33
31
|
}
|