@e-mc/module 0.8.7 → 0.9.0
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 +10 -10
- package/README.md +202 -24
- package/index.d.ts +4 -4
- package/index.js +145 -114
- package/lib-v4.d.ts +4 -4
- package/lib-v4.js +13 -14
- package/package.json +3 -5
package/LICENSE
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
Copyright 2024 An Pham
|
|
2
|
-
|
|
3
|
-
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
4
|
-
|
|
5
|
-
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
6
|
-
|
|
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
|
-
|
|
1
|
+
Copyright 2024 An Pham
|
|
2
|
+
|
|
3
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
4
|
+
|
|
5
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
6
|
+
|
|
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
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,6 +1,6 @@
|
|
|
1
1
|
# @e-mc/module
|
|
2
2
|
|
|
3
|
-
* NodeJS 14
|
|
3
|
+
* NodeJS 14/16
|
|
4
4
|
* ES2020
|
|
5
5
|
|
|
6
6
|
## General Usage
|
|
@@ -9,16 +9,17 @@
|
|
|
9
9
|
|
|
10
10
|
## Interface
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
* [View Source](https://www.unpkg.com/@e-mc/types@0.9.0/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,12 +237,183 @@ 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
|
+
|
|
392
|
+
## NodeJS 14 LTS
|
|
393
|
+
|
|
394
|
+
Any optional fail safe dependencies were removed as of `E-mc 0.9`. The code itself will still be *ES2020* and will continue to work equivalently when self-installing these dependencies:
|
|
395
|
+
|
|
396
|
+
### Under 15.4 + 16.0
|
|
397
|
+
|
|
398
|
+
```sh
|
|
399
|
+
npm i abort-controller event-target-shim
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
### Under 14.17 + 15.6
|
|
403
|
+
|
|
404
|
+
```sh
|
|
405
|
+
npm i uuid
|
|
406
|
+
```
|
|
407
|
+
|
|
233
408
|
## References
|
|
234
409
|
|
|
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.
|
|
410
|
+
- https://www.unpkg.com/@e-mc/types@0.9.0/lib/core.d.ts
|
|
411
|
+
- https://www.unpkg.com/@e-mc/types@0.9.0/lib/logger.d.ts
|
|
412
|
+
- https://www.unpkg.com/@e-mc/types@0.9.0/lib/module.d.ts
|
|
413
|
+
- https://www.unpkg.com/@e-mc/types@0.9.0/lib/node.d.ts
|
|
414
|
+
- https://www.unpkg.com/@e-mc/types@0.9.0/lib/settings.d.ts
|
|
415
|
+
|
|
416
|
+
* https://www.npmjs.com/package/@types/node
|
|
239
417
|
|
|
240
418
|
## LICENSE
|
|
241
419
|
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ModuleConstructor } from '../types/lib';
|
|
2
|
-
|
|
3
|
-
declare const Module: ModuleConstructor;
|
|
4
|
-
|
|
1
|
+
import type { ModuleConstructor } from '../types/lib';
|
|
2
|
+
|
|
3
|
+
declare const Module: ModuleConstructor;
|
|
4
|
+
|
|
5
5
|
export = Module;
|
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");
|
|
@@ -549,16 +548,27 @@ function encryptMessage(data, cipher, algorithm) {
|
|
|
549
548
|
}
|
|
550
549
|
return data;
|
|
551
550
|
}
|
|
552
|
-
function
|
|
553
|
-
|
|
554
|
-
|
|
551
|
+
function relayMessage(args) {
|
|
552
|
+
const host = this.host;
|
|
553
|
+
if (host?.logState === 0) {
|
|
554
|
+
host.delayMessage(args);
|
|
555
|
+
}
|
|
556
|
+
else {
|
|
557
|
+
Module.formatMessage(...args);
|
|
555
558
|
}
|
|
556
|
-
|
|
557
|
-
|
|
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
|
+
}
|
|
559
566
|
}
|
|
560
567
|
}
|
|
561
568
|
function hasFileSystem(type, value, options, ignoreExists, overwrite) {
|
|
569
|
+
if (!(value = asFile(value))) {
|
|
570
|
+
return '';
|
|
571
|
+
}
|
|
562
572
|
let result;
|
|
563
573
|
if (path.isAbsolute(value)) {
|
|
564
574
|
if (options.absolutePath === false) {
|
|
@@ -648,7 +658,7 @@ function formatPercent(value, precision = 3) {
|
|
|
648
658
|
return (value * 100).toPrecision(precision) + '%';
|
|
649
659
|
}
|
|
650
660
|
const hideAbort = (err) => err.name === 'AbortError' && SETTINGS.abort === false;
|
|
651
|
-
const asFile = (value) =>
|
|
661
|
+
const asFile = (value) => typeof value === 'string' ? value.trim() : value instanceof URL && value.protocol === 'file:' ? url.fileURLToPath(value) : '';
|
|
652
662
|
const wrapQuote = (value) => '"' + value.replace(/"/g, '\\"') + '"';
|
|
653
663
|
const isFunction = (value) => typeof value === 'function';
|
|
654
664
|
const isFileURL = (value) => /^file:\/\//i.test(value);
|
|
@@ -656,11 +666,12 @@ const sanitizePath = (value) => value ? path.resolve(value) : '';
|
|
|
656
666
|
const ensureDir = (value) => value.endsWith(path.sep) ? value : value + path.sep;
|
|
657
667
|
const trimDir = (value) => value.endsWith(path.sep) ? value.substring(0, value.length - 1) : value;
|
|
658
668
|
const getExtension = (value) => path.extname(value).toLowerCase().substring(1);
|
|
659
|
-
const hasString = (item, value) =>
|
|
669
|
+
const hasString = (item, value) => item === value || Array.isArray(item) && item.includes(value);
|
|
660
670
|
const getCpuTimes = () => os.cpus().reduce((a, b) => a + b.times.user + b.times.sys, 0) * 1000;
|
|
661
671
|
const autoMemoryCache = () => MEMORY_CACHE_DISK.enabled && MEMORY_CACHE_DISK.max_size > 0;
|
|
662
672
|
const errorDirectory = (value) => (0, types_1.errorValue)("Path is not a directory", value);
|
|
663
|
-
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);
|
|
664
675
|
class Module extends EventEmitter {
|
|
665
676
|
constructor() {
|
|
666
677
|
super(...arguments);
|
|
@@ -683,11 +694,12 @@ class Module extends EventEmitter {
|
|
|
683
694
|
this[_f] = new AbortController();
|
|
684
695
|
this[_g] = null;
|
|
685
696
|
}
|
|
686
|
-
static get VERSION() { return "0.
|
|
697
|
+
static get VERSION() { return "0.9.0"; }
|
|
687
698
|
static get LOG_TYPE() { return types_1.LOG_TYPE; }
|
|
688
699
|
static get STATUS_TYPE() { return types_1.STATUS_TYPE; }
|
|
689
700
|
static get MAX_TIMEOUT() { return 2147483647; }
|
|
690
701
|
static get TEMP_DIR() { return TEMP_DIR; }
|
|
702
|
+
static get LOG_FORMAT() { return (0, types_1.cloneObject)(SETTINGS.format, true); }
|
|
691
703
|
static supported(major, minor = 0, patch = 0, lts) {
|
|
692
704
|
if (VER_MAJOR < major) {
|
|
693
705
|
return false;
|
|
@@ -1035,8 +1047,8 @@ class Module extends EventEmitter {
|
|
|
1035
1047
|
}
|
|
1036
1048
|
}
|
|
1037
1049
|
if (!output) {
|
|
1038
|
-
const m = truncateStart(this.asString(message), options.messageWidth ?? format.message.width);
|
|
1039
|
-
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 ? '}' : ')') : '');
|
|
1040
1052
|
}
|
|
1041
1053
|
if (broadcastId) {
|
|
1042
1054
|
if (BROADCAST_OUT) {
|
|
@@ -1122,13 +1134,11 @@ class Module extends EventEmitter {
|
|
|
1122
1134
|
catch {
|
|
1123
1135
|
}
|
|
1124
1136
|
}
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
this.writeFail(["Unable to read file", value], err, 32);
|
|
1131
|
-
}
|
|
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);
|
|
1132
1142
|
}
|
|
1133
1143
|
}
|
|
1134
1144
|
if (external && !pathname && VALUES["node.require.npm"] && /^(?:@[a-z\d-*~][a-z\d-*._~]*\/|node:)?[a-z\d-~][a-z\d-._~]*(?:\/.*)?$/.test(location)) {
|
|
@@ -1457,60 +1467,62 @@ class Module extends EventEmitter {
|
|
|
1457
1467
|
}
|
|
1458
1468
|
static createDir(value, overwrite) {
|
|
1459
1469
|
const outDir = sanitizePath(value = asFile(value));
|
|
1460
|
-
if (outDir) {
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
try {
|
|
1468
|
-
fs.unlinkSync(outDir);
|
|
1469
|
-
}
|
|
1470
|
-
catch {
|
|
1471
|
-
this.formatMessage(32, 'WARN', "Unable to overwrite file", value, { ...this.LOG_STYLE_WARN });
|
|
1472
|
-
return false;
|
|
1473
|
-
}
|
|
1474
|
-
}
|
|
1475
|
-
else {
|
|
1476
|
-
return false;
|
|
1477
|
-
}
|
|
1470
|
+
if (!outDir) {
|
|
1471
|
+
return false;
|
|
1472
|
+
}
|
|
1473
|
+
try {
|
|
1474
|
+
const stat = fs.statSync(outDir);
|
|
1475
|
+
if (stat.isDirectory()) {
|
|
1476
|
+
return true;
|
|
1478
1477
|
}
|
|
1479
|
-
|
|
1480
|
-
|
|
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 });
|
|
1481
1484
|
return false;
|
|
1482
1485
|
}
|
|
1483
1486
|
}
|
|
1484
|
-
|
|
1485
|
-
return
|
|
1487
|
+
else {
|
|
1488
|
+
return false;
|
|
1486
1489
|
}
|
|
1487
|
-
|
|
1488
|
-
|
|
1490
|
+
}
|
|
1491
|
+
catch (err) {
|
|
1492
|
+
if (this.isErrorCode(err, 'EBUSY', 'EPERM')) {
|
|
1493
|
+
return false;
|
|
1489
1494
|
}
|
|
1490
1495
|
}
|
|
1496
|
+
try {
|
|
1497
|
+
return tryCreateDir(outDir);
|
|
1498
|
+
}
|
|
1499
|
+
catch (err) {
|
|
1500
|
+
this.writeFail(["Unable to create directory", value], err, 32);
|
|
1501
|
+
}
|
|
1491
1502
|
return false;
|
|
1492
1503
|
}
|
|
1493
1504
|
static removeDir(value, empty = false, recursive = true) {
|
|
1494
1505
|
const outDir = sanitizePath(value = asFile(value));
|
|
1495
|
-
if (outDir) {
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
return tryRemoveDir(outDir, empty, !!recursive).length === 0;
|
|
1502
|
-
}
|
|
1503
|
-
if (!fs.existsSync(outDir)) {
|
|
1504
|
-
if (empty && typeof empty !== 'number') {
|
|
1505
|
-
this.createDir(outDir);
|
|
1506
|
-
}
|
|
1507
|
-
return true;
|
|
1508
|
-
}
|
|
1506
|
+
if (!outDir) {
|
|
1507
|
+
return false;
|
|
1508
|
+
}
|
|
1509
|
+
try {
|
|
1510
|
+
if (typeof empty === 'number' && empty <= 0) {
|
|
1511
|
+
empty = true;
|
|
1509
1512
|
}
|
|
1510
|
-
|
|
1511
|
-
|
|
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;
|
|
1512
1521
|
}
|
|
1513
1522
|
}
|
|
1523
|
+
catch (err) {
|
|
1524
|
+
this.writeFail(["Unable to remove directory", value], err, 32);
|
|
1525
|
+
}
|
|
1514
1526
|
return false;
|
|
1515
1527
|
}
|
|
1516
1528
|
static async copyDir(src, dest, move, recursive = true) {
|
|
@@ -1588,7 +1600,7 @@ class Module extends EventEmitter {
|
|
|
1588
1600
|
.then(() => {
|
|
1589
1601
|
success.push(destPath);
|
|
1590
1602
|
})
|
|
1591
|
-
.catch(err => {
|
|
1603
|
+
.catch((err) => {
|
|
1592
1604
|
failed.push(srcPath);
|
|
1593
1605
|
if (!silent) {
|
|
1594
1606
|
this.writeFail([move ? "Unable to move file" : "Unable to copy file", path.basename(srcPath)], err, 32);
|
|
@@ -1669,7 +1681,7 @@ class Module extends EventEmitter {
|
|
|
1669
1681
|
}
|
|
1670
1682
|
return false;
|
|
1671
1683
|
}
|
|
1672
|
-
static async streamFile(
|
|
1684
|
+
static async streamFile(value, cache, options) {
|
|
1673
1685
|
if ((0, types_1.isObject)(cache)) {
|
|
1674
1686
|
options = cache;
|
|
1675
1687
|
}
|
|
@@ -1677,28 +1689,32 @@ class Module extends EventEmitter {
|
|
|
1677
1689
|
if (options) {
|
|
1678
1690
|
({ minStreamSize = 0, encoding, signal, cache } = options);
|
|
1679
1691
|
}
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
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
|
+
}
|
|
1688
1707
|
}
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
data = data.toString(encoding);
|
|
1708
|
+
else {
|
|
1709
|
+
data = fs.readFileSync(src, encoding);
|
|
1692
1710
|
}
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
resolve(data);
|
|
1701
|
-
});
|
|
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));
|
|
1702
1718
|
}
|
|
1703
1719
|
static readText(value, encoding, cache) {
|
|
1704
1720
|
let minStreamSize, options;
|
|
@@ -1721,7 +1737,7 @@ class Module extends EventEmitter {
|
|
|
1721
1737
|
return this.streamFile(src, options);
|
|
1722
1738
|
}
|
|
1723
1739
|
try {
|
|
1724
|
-
result = fs.readFileSync(
|
|
1740
|
+
result = fs.readFileSync(src, encoding);
|
|
1725
1741
|
if (result && (cache || cache !== false && autoMemoryCache())) {
|
|
1726
1742
|
addCacheItem(CACHE_READTEXT, src, result, cache);
|
|
1727
1743
|
}
|
|
@@ -1749,7 +1765,7 @@ class Module extends EventEmitter {
|
|
|
1749
1765
|
return this.streamFile(src, options);
|
|
1750
1766
|
}
|
|
1751
1767
|
try {
|
|
1752
|
-
result = fs.readFileSync(
|
|
1768
|
+
result = fs.readFileSync(src);
|
|
1753
1769
|
if (result && (cache || cache !== false && autoMemoryCache())) {
|
|
1754
1770
|
addCacheItem(CACHE_READBUFFER, src, result, cache);
|
|
1755
1771
|
}
|
|
@@ -2135,6 +2151,8 @@ class Module extends EventEmitter {
|
|
|
2135
2151
|
CACHE_CPUHOST = new WeakMap();
|
|
2136
2152
|
(0, types_1.purgeMemory)();
|
|
2137
2153
|
CACHE_TOTAL = 0;
|
|
2154
|
+
PNPM_VER = undefined;
|
|
2155
|
+
YARN_VER = undefined;
|
|
2138
2156
|
}
|
|
2139
2157
|
else if (percent > 0) {
|
|
2140
2158
|
const stored = [];
|
|
@@ -2575,6 +2593,9 @@ class Module extends EventEmitter {
|
|
|
2575
2593
|
ownPermissionOnly = true;
|
|
2576
2594
|
}
|
|
2577
2595
|
}
|
|
2596
|
+
if (!(uri = asFile(uri))) {
|
|
2597
|
+
return false;
|
|
2598
|
+
}
|
|
2578
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()))) {
|
|
2579
2600
|
return true;
|
|
2580
2601
|
}
|
|
@@ -2596,6 +2617,9 @@ class Module extends EventEmitter {
|
|
|
2596
2617
|
ownPermissionOnly = true;
|
|
2597
2618
|
}
|
|
2598
2619
|
}
|
|
2620
|
+
if (!(uri = asFile(uri))) {
|
|
2621
|
+
return false;
|
|
2622
|
+
}
|
|
2599
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()))) {
|
|
2600
2624
|
return true;
|
|
2601
2625
|
}
|
|
@@ -2616,7 +2640,7 @@ class Module extends EventEmitter {
|
|
|
2616
2640
|
}
|
|
2617
2641
|
};
|
|
2618
2642
|
let result;
|
|
2619
|
-
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))) {
|
|
2620
2644
|
if (cache) {
|
|
2621
2645
|
result = getCacheItem(CACHE_READCJS, outSrc);
|
|
2622
2646
|
}
|
|
@@ -2634,8 +2658,7 @@ class Module extends EventEmitter {
|
|
|
2634
2658
|
result || (result = (encoding ? getCacheItem(CACHE_READTEXT, outSrc) : getCacheItem(CACHE_READBUFFER, outSrc)));
|
|
2635
2659
|
}
|
|
2636
2660
|
try {
|
|
2637
|
-
minStreamSize = (0, types_1.alignSize)(minStreamSize)
|
|
2638
|
-
if (!isNaN(minStreamSize) || promises && fs.statSync(outSrc).size >= 2097152000) {
|
|
2661
|
+
if (!isNaN(minStreamSize = (0, types_1.alignSize)(minStreamSize)) || promises && fs.statSync(outSrc).size >= 2097152000) {
|
|
2639
2662
|
if (result) {
|
|
2640
2663
|
return Promise.resolve(result);
|
|
2641
2664
|
}
|
|
@@ -2674,7 +2697,7 @@ class Module extends EventEmitter {
|
|
|
2674
2697
|
if (!err) {
|
|
2675
2698
|
setCache(data);
|
|
2676
2699
|
}
|
|
2677
|
-
callback(err, data);
|
|
2700
|
+
(callback)(err, data);
|
|
2678
2701
|
});
|
|
2679
2702
|
}
|
|
2680
2703
|
return;
|
|
@@ -2686,7 +2709,7 @@ class Module extends EventEmitter {
|
|
|
2686
2709
|
return result;
|
|
2687
2710
|
}
|
|
2688
2711
|
catch (err) {
|
|
2689
|
-
this.writeFail(["Unable to read file", path.basename(src)], err, 32);
|
|
2712
|
+
this.writeFail(["Unable to read file", path.basename(asFile(src))], err, 32);
|
|
2690
2713
|
}
|
|
2691
2714
|
}
|
|
2692
2715
|
else if (promises) {
|
|
@@ -2711,7 +2734,7 @@ class Module extends EventEmitter {
|
|
|
2711
2734
|
if (!err) {
|
|
2712
2735
|
this.emit('file:write', outSrc, options);
|
|
2713
2736
|
}
|
|
2714
|
-
callback(err);
|
|
2737
|
+
(callback)(err);
|
|
2715
2738
|
});
|
|
2716
2739
|
return;
|
|
2717
2740
|
}
|
|
@@ -2721,7 +2744,7 @@ class Module extends EventEmitter {
|
|
|
2721
2744
|
return true;
|
|
2722
2745
|
}
|
|
2723
2746
|
catch (err) {
|
|
2724
|
-
this.writeFail(["Unable to write file", path.basename(
|
|
2747
|
+
this.writeFail(["Unable to write file", path.basename(outSrc)], err, 32);
|
|
2725
2748
|
}
|
|
2726
2749
|
}
|
|
2727
2750
|
else if (promises) {
|
|
@@ -2748,7 +2771,7 @@ class Module extends EventEmitter {
|
|
|
2748
2771
|
if (!err) {
|
|
2749
2772
|
this.emit('file:delete', outSrc, options);
|
|
2750
2773
|
}
|
|
2751
|
-
callback(err);
|
|
2774
|
+
(callback)(err);
|
|
2752
2775
|
});
|
|
2753
2776
|
return;
|
|
2754
2777
|
}
|
|
@@ -2757,7 +2780,7 @@ class Module extends EventEmitter {
|
|
|
2757
2780
|
}
|
|
2758
2781
|
catch (err) {
|
|
2759
2782
|
if (!Module.isErrorCode(err, 'ENOENT')) {
|
|
2760
|
-
this.writeFail(["Unable to delete file", path.basename(
|
|
2783
|
+
this.writeFail(["Unable to delete file", path.basename(outSrc)], err, 32);
|
|
2761
2784
|
return false;
|
|
2762
2785
|
}
|
|
2763
2786
|
}
|
|
@@ -2803,7 +2826,7 @@ class Module extends EventEmitter {
|
|
|
2803
2826
|
if (!err) {
|
|
2804
2827
|
this.emit('file:copy', outDest, options);
|
|
2805
2828
|
}
|
|
2806
|
-
callback(err);
|
|
2829
|
+
(callback)(err);
|
|
2807
2830
|
});
|
|
2808
2831
|
return;
|
|
2809
2832
|
}
|
|
@@ -2813,7 +2836,7 @@ class Module extends EventEmitter {
|
|
|
2813
2836
|
return true;
|
|
2814
2837
|
}
|
|
2815
2838
|
catch (err) {
|
|
2816
|
-
this.writeFail(["Unable to copy file",
|
|
2839
|
+
this.writeFail(["Unable to copy file", path.basename(outDest)], err, 32);
|
|
2817
2840
|
}
|
|
2818
2841
|
}
|
|
2819
2842
|
}
|
|
@@ -2882,7 +2905,7 @@ class Module extends EventEmitter {
|
|
|
2882
2905
|
if (!err) {
|
|
2883
2906
|
this.emit('file:move', outDest, options);
|
|
2884
2907
|
}
|
|
2885
|
-
callback(err);
|
|
2908
|
+
(callback)(err);
|
|
2886
2909
|
});
|
|
2887
2910
|
return;
|
|
2888
2911
|
}
|
|
@@ -2896,7 +2919,7 @@ class Module extends EventEmitter {
|
|
|
2896
2919
|
this.emit('file:move', outDest, options);
|
|
2897
2920
|
return true;
|
|
2898
2921
|
}
|
|
2899
|
-
this.writeFail(["Unable to move file",
|
|
2922
|
+
this.writeFail(["Unable to move file", path.basename(outDest)], err, 32);
|
|
2900
2923
|
}
|
|
2901
2924
|
}
|
|
2902
2925
|
}
|
|
@@ -2953,7 +2976,7 @@ class Module extends EventEmitter {
|
|
|
2953
2976
|
return success;
|
|
2954
2977
|
});
|
|
2955
2978
|
if (callback) {
|
|
2956
|
-
result.catch(err => callback(err));
|
|
2979
|
+
result.catch((err) => callback(errorCheck(err, outSrc)));
|
|
2957
2980
|
}
|
|
2958
2981
|
return promises ? result : undefined;
|
|
2959
2982
|
}
|
|
@@ -2964,7 +2987,7 @@ class Module extends EventEmitter {
|
|
|
2964
2987
|
}
|
|
2965
2988
|
}
|
|
2966
2989
|
catch (err) {
|
|
2967
|
-
this.writeFail(["Unable to create directory",
|
|
2990
|
+
this.writeFail(["Unable to create directory", path.basename(outSrc)], err, 32);
|
|
2968
2991
|
}
|
|
2969
2992
|
}
|
|
2970
2993
|
else if (promises) {
|
|
@@ -3002,7 +3025,7 @@ class Module extends EventEmitter {
|
|
|
3002
3025
|
return success;
|
|
3003
3026
|
});
|
|
3004
3027
|
if (callback) {
|
|
3005
|
-
result.catch(err => callback(err));
|
|
3028
|
+
result.catch((err) => callback(errorCheck(err, outSrc)));
|
|
3006
3029
|
}
|
|
3007
3030
|
return promises ? result : undefined;
|
|
3008
3031
|
}
|
|
@@ -3034,7 +3057,7 @@ class Module extends EventEmitter {
|
|
|
3034
3057
|
}
|
|
3035
3058
|
}
|
|
3036
3059
|
catch (err) {
|
|
3037
|
-
this.writeFail(["Unable to remove directory",
|
|
3060
|
+
this.writeFail(["Unable to remove directory", path.basename(outSrc)], err, 32);
|
|
3038
3061
|
}
|
|
3039
3062
|
}
|
|
3040
3063
|
else if (promises) {
|
|
@@ -3060,7 +3083,7 @@ class Module extends EventEmitter {
|
|
|
3060
3083
|
}
|
|
3061
3084
|
return items;
|
|
3062
3085
|
})
|
|
3063
|
-
.catch(err => {
|
|
3086
|
+
.catch((err) => {
|
|
3064
3087
|
this.writeFail(rejected, err, options);
|
|
3065
3088
|
return [];
|
|
3066
3089
|
});
|
|
@@ -3122,7 +3145,7 @@ class Module extends EventEmitter {
|
|
|
3122
3145
|
}
|
|
3123
3146
|
else {
|
|
3124
3147
|
setCpuAndMem.call(this, options);
|
|
3125
|
-
|
|
3148
|
+
relayMessage.call(this, args);
|
|
3126
3149
|
}
|
|
3127
3150
|
if (!options.bypassLog) {
|
|
3128
3151
|
this.addLog(types_1.STATUS_TYPE.INFO, title + ' -> ' + value, Date.now(), duration);
|
|
@@ -3159,7 +3182,7 @@ class Module extends EventEmitter {
|
|
|
3159
3182
|
this._logQueued.push(args);
|
|
3160
3183
|
}
|
|
3161
3184
|
else {
|
|
3162
|
-
|
|
3185
|
+
relayMessage.call(this, args);
|
|
3163
3186
|
}
|
|
3164
3187
|
}
|
|
3165
3188
|
formatFail(type, title, value, message, options = {}) {
|
|
@@ -3299,7 +3322,7 @@ class Module extends EventEmitter {
|
|
|
3299
3322
|
this._logQueued.push(args);
|
|
3300
3323
|
}
|
|
3301
3324
|
else {
|
|
3302
|
-
|
|
3325
|
+
relayMessage.call(this, args);
|
|
3303
3326
|
}
|
|
3304
3327
|
}
|
|
3305
3328
|
checkPackage(err, name, value, options) {
|
|
@@ -3311,7 +3334,7 @@ class Module extends EventEmitter {
|
|
|
3311
3334
|
options = value;
|
|
3312
3335
|
value = undefined;
|
|
3313
3336
|
}
|
|
3314
|
-
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) {
|
|
3315
3338
|
if (typeof options === 'number') {
|
|
3316
3339
|
options = undefined;
|
|
3317
3340
|
}
|
|
@@ -3606,16 +3629,24 @@ Module.LOG_STYLE_INFO = Object.freeze({ titleBgColor: 'bgBlue', titleColor: 'whi
|
|
|
3606
3629
|
Module.LOG_STYLE_WARN = Object.freeze({ titleBgColor: 'bgBlack', titleColor: 'yellow', titleBold: true });
|
|
3607
3630
|
Module.LOG_STYLE_NOTICE = Object.freeze({ titleBgColor: 'bgGrey', titleColor: 'white' });
|
|
3608
3631
|
Module.LOG_STYLE_REVERSE = Object.freeze({ titleBgColor: 'bgWhite', titleColor: 'black', messageBgColor: 'bgGrey' });
|
|
3609
|
-
if (!Module.supported(15, 4)
|
|
3610
|
-
(
|
|
3611
|
-
|
|
3632
|
+
if (!Module.supported(15, 4)) {
|
|
3633
|
+
if (!global.AbortController) {
|
|
3634
|
+
try {
|
|
3635
|
+
({ AbortController: global.AbortController } = require('abort-controller'));
|
|
3636
|
+
}
|
|
3637
|
+
catch {
|
|
3638
|
+
}
|
|
3639
|
+
}
|
|
3640
|
+
if (!global.EventTarget) {
|
|
3641
|
+
try {
|
|
3642
|
+
({ EventTarget: global.EventTarget } = require('event-target-shim'));
|
|
3643
|
+
}
|
|
3644
|
+
catch {
|
|
3645
|
+
}
|
|
3646
|
+
}
|
|
3612
3647
|
}
|
|
3613
3648
|
EventEmitter.defaultMaxListeners = Infinity;
|
|
3614
3649
|
Object.freeze(types_1.LOG_TYPE);
|
|
3615
3650
|
Object.freeze(types_1.STATUS_TYPE);
|
|
3616
|
-
exports.default = Module;
|
|
3617
3651
|
|
|
3618
|
-
|
|
3619
|
-
module.exports = exports.default;
|
|
3620
|
-
module.exports.default = exports.default;
|
|
3621
|
-
}
|
|
3652
|
+
module.exports = Module;
|
package/lib-v4.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { IModuleLibV4 } from '../types/lib/compat-v4';
|
|
2
|
-
|
|
3
|
-
declare const LibV4: IModuleLibV4;
|
|
4
|
-
|
|
1
|
+
import type { IModuleLibV4 } from '../types/lib/compat-v4';
|
|
2
|
+
|
|
3
|
+
declare const LibV4: IModuleLibV4;
|
|
4
|
+
|
|
5
5
|
export = LibV4;
|
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.0",
|
|
4
4
|
"description": "Module base class for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -20,14 +20,12 @@
|
|
|
20
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.0",
|
|
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
|
}
|