@e-mc/module 0.8.17 → 0.8.19

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 CHANGED
@@ -1,7 +1,7 @@
1
- Copyright 2024 An Pham
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
-
5
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
-
1
+ Copyright 2024 An Pham
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
7
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,242 +1,241 @@
1
- # @e-mc/module
2
-
3
- * NodeJS 14
4
- * ES2019
5
-
6
- ## General Usage
7
-
8
- * [Read the Docs](https://e-mc.readthedocs.io)
9
-
10
- ## Interface
11
-
12
- - https://www.unpkg.com/@e-mc/types@0.8.17/lib/index.d.ts
13
-
14
- ```typescript
15
- import type { LogStatus } from "./squared";
16
-
17
- import type { IHost } from "./index";
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";
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
- import type { Settings } from "./node";
22
-
23
- import type { SpawnOptions } from "child_process";
24
- import type { BinaryLike } from "crypto";
25
- import type { FileTypeResult } from "file-type";
26
- import type { NoParamCallback } from "fs";
27
-
28
- import type * as EventEmitter from "events";
29
-
30
- type BufferView = Buffer | string | NodeJS.ArrayBufferView;
31
- type CpuUsage = NodeJS.CpuUsage;
32
-
33
- interface IModule extends EventEmitter, IAbortComponent {
34
- readonly status: LogStatus<StatusType>[];
35
- readonly errors: unknown[];
36
- supported(major: number, minor?: number, patch?: number, lts?: boolean): boolean;
37
- supports(name: string, value?: boolean): boolean;
38
- getTempDir(options: GetTempDirOptions): string;
39
- getTempDir(uuidDir: boolean, createDir?: boolean): string;
40
- getTempDir(pathname: string, createDir?: boolean): string;
41
- getTempDir(uuidDir: boolean, filename: string, createDir?: boolean): string;
42
- getTempDir(pathname?: string, filename?: string, createDir?: boolean): string;
43
- canRead(uri: string, options?: PermissionOptions): boolean;
44
- canWrite(uri: string, options?: PermissionOptions): boolean;
45
- readFile(src: string): Buffer | undefined;
46
- readFile(src: string, options?: ReadFileOptions): Promise<Buffer | string> | Buffer | string | undefined;
47
- readFile(src: string, promises: true): Promise<Buffer | undefined>;
48
- readFile(src: string, options: ReadFileOptions, promises: true): Promise<Buffer | string | undefined>;
49
- readFile(src: string, callback: ReadFileCallback<Buffer>): Buffer | undefined;
50
- readFile(src: string, options: ReadFileOptions, callback: ReadFileCallback<Buffer | string>): Buffer | string | undefined;
51
- writeFile(src: string, data: BufferView, options?: WriteFileOptions): boolean;
52
- writeFile(src: string, data: BufferView, promises: true): Promise<boolean>;
53
- writeFile(src: string, data: BufferView, options: WriteFileOptions, promises: true): Promise<boolean>;
54
- writeFile(src: string, data: BufferView, callback: NoParamCallback): void;
55
- writeFile(src: string, data: BufferView, options: WriteFileOptions, callback: NoParamCallback): void;
56
- deleteFile(src: string, options?: DeleteFileOptions): boolean;
57
- deleteFile(src: string, promises: true): Promise<boolean>;
58
- deleteFile(src: string, options: DeleteFileOptions, promises: true): Promise<boolean>;
59
- deleteFile(src: string, callback: NoParamCallback): void;
60
- deleteFile(src: string, options: DeleteFileOptions, callback: NoParamCallback): void;
61
- copyFile(src: string, dest: string, options?: CopyFileOptions): boolean;
62
- copyFile(src: string, dest: string, promises: true): Promise<boolean>;
63
- copyFile(src: string, dest: string, options: CopyFileOptions, promises: true): Promise<boolean>;
64
- copyFile(src: string, dest: string, callback: NoParamCallback): void;
65
- copyFile(src: string, dest: string, options: CopyFileOptions, callback: NoParamCallback): void;
66
- moveFile(src: string, dest: string, options?: MoveFileOptions): boolean;
67
- moveFile(src: string, dest: string, promises: true): Promise<boolean>;
68
- moveFile(src: string, dest: string, options: MoveFileOptions, promises: true): Promise<boolean>;
69
- moveFile(src: string, dest: string, callback: NoParamCallback): void;
70
- moveFile(src: string, dest: string, options: MoveFileOptions, callback: NoParamCallback): void;
71
- createDir(src: string, options?: CreateDirOptions): boolean;
72
- createDir(src: string, promises: true): Promise<boolean>;
73
- createDir(src: string, options: CreateDirOptions, promises: true): Promise<boolean>;
74
- createDir(src: string, callback: NoParamCallback): void;
75
- createDir(src: string, options: CreateDirOptions, callback: NoParamCallback): void;
76
- removeDir(src: string, options?: RemoveDirOptions): boolean;
77
- removeDir(src: string, promises: true): Promise<boolean>;
78
- removeDir(src: string, options: RemoveDirOptions, promises: true): Promise<boolean>;
79
- removeDir(src: string, callback: NoParamCallback): void;
80
- removeDir(src: string, options: RemoveDirOptions, callback: NoParamCallback): void;
81
- allSettled(values: readonly PromiseLike<unknown>[], rejected?: LogValue, options?: LogFailOptions | LogType): Promise<PromiseFulfilledResult<unknown>[]>;
82
- formatMessage(type: LogType, title: string, value: LogValue, message?: unknown, options?: LogMessageOptions): void;
83
- formatFail(type: LogType, title: string, value: LogValue, message?: unknown, options?: LogFailOptions): void;
84
- writeFail(value: LogValue, message?: unknown, options?: LogFailOptions | LogType): void;
85
- writeTimeProcess(title: string, value: string, startTime: LogTime, options?: LogProcessOptions): void;
86
- writeTimeElapsed(title: string, value: LogValue, startTime: LogTime, options?: LogMessageOptions): void;
87
- checkPackage(err: unknown, name: string | undefined, options?: LogFailOptions | LogType): boolean;
88
- checkPackage(err: unknown, name: string | undefined, value?: LogValue, options?: LogFailOptions | LogType): boolean;
89
- checkFail(message: unknown, options: LogFailOptions): LogArguments | false | undefined;
90
- writeLog(component: LogComponent, queue?: boolean): void;
91
- writeLog(type: StatusType, value: unknown, options?: LogOptions): void;
92
- writeLog(type: StatusType, value: unknown, timeStamp?: LogDate, duration?: number): void;
93
- addLog(component: LogComponent, queue?: boolean): void;
94
- addLog(type: StatusType, value: unknown, from: string, source?: string): void;
95
- addLog(type: StatusType, value: unknown, options?: LogOptions): void;
96
- addLog(type: StatusType, value: unknown, timeStamp?: LogDate, from?: string, source?: string): void;
97
- addLog(type: StatusType, value: unknown, timeStamp?: LogDate, duration?: number, from?: string, source?: string): void;
98
- getLog(...type: StatusType[]): LogStatus<StatusType>[];
99
- flushLog(): void;
100
- willAbort(value: unknown): boolean;
101
- hasOwnPermission(): boolean;
102
- isFatal(err?: unknown): boolean;
103
- detach(): void;
104
- reset(): void;
105
- get moduleName(): string;
106
- set host(value);
107
- get host(): IHost | null;
108
- set permission(value);
109
- get permission(): IPermission | null;
110
- get aborted(): boolean;
111
- set abortable(value);
112
- get abortable(): boolean;
113
- get threadable(): boolean;
114
- set sessionId(value);
115
- get sessionId(): string;
116
- set broadcastId(value);
117
- get broadcastId(): string | string[];
118
- get logType(): LOG_TYPE;
119
- set logLevel(value: number | string);
120
- get logLevel(): number;
121
- get statusType(): STATUS_TYPE;
122
- set tempDir(value);
123
- get tempDir(): string;
124
-
125
- /* EventEmitter */
126
- on(event: "exec", listener: (command: ExecCommand, options?: SpawnOptions) => void): this;
127
- on(event: "error", listener: (err: Error) => void): this;
128
- on(event: "file:read", listener: (src: string, data: Buffer | string, options?: ReadFileOptions) => void): this;
129
- on(event: "file:write", listener: (src: string, options?: WriteFileOptions) => void): this;
130
- on(event: "file:delete", listener: (src: string, options?: DeleteFileOptions) => void): this;
131
- on(event: "file:copy", listener: (dest: string, options?: CopyFileOptions) => void): this;
132
- on(event: "file:move", listener: (dest: string, options?: MoveFileOptions) => void): this;
133
- on(event: "dir:create", listener: (src: string, options?: CreateDirOptions) => void): this;
134
- on(event: "dir:remove", listener: (src: string, options?: RemoveDirOptions) => void): this;
135
- once(event: "exec", listener: (command: ExecCommand, options?: SpawnOptions) => void): this;
136
- once(event: "error", listener: (err: Error) => void): this;
137
- once(event: "file:read", listener: (src: string, data: Buffer | string, options?: ReadFileOptions) => void): this;
138
- once(event: "file:write", listener: (src: string, options?: WriteFileOptions) => void): this;
139
- once(event: "file:delete", listener: (src: string, options?: DeleteFileOptions) => void): this;
140
- once(event: "file:copy", listener: (dest: string, options?: CopyFileOptions) => void): this;
141
- once(event: "file:move", listener: (dest: string, options?: MoveFileOptions) => void): this;
142
- once(event: "dir:create", listener: (src: string, options?: CreateDirOptions) => void): this;
143
- once(event: "dir:remove", listener: (src: string, options?: RemoveDirOptions) => void): this;
144
- emit(event: "exec", command: ExecCommand, options?: SpawnOptions): boolean;
145
- emit(event: "error", err: Error): boolean;
146
- emit(event: "file:read", src: string, data: Buffer | string, options?: ReadFileOptions): boolean;
147
- emit(event: "file:write", src: string, options?: WriteFileOptions): boolean;
148
- emit(event: "file:delete", src: string, options?: DeleteFileOptions): boolean;
149
- emit(event: "file:copy", dest: string, options?: CopyFileOptions): boolean;
150
- emit(event: "file:move", dest: string, options?: MoveFileOptions): boolean;
151
- emit(event: "dir:create", src: string, options?: CreateDirOptions): boolean;
152
- emit(event: "dir:remove", src: string, options?: RemoveDirOptions): boolean;
153
- }
154
-
155
- interface ModuleConstructor {
156
- PROCESS_TIMEOUT: number;
157
- LOG_STYLE_FAIL: LogMessageOptions;
158
- LOG_STYLE_SUCCESS: LogMessageOptions;
159
- LOG_STYLE_INFO: LogMessageOptions;
160
- LOG_STYLE_WARN: LogMessageOptions;
161
- LOG_STYLE_NOTICE: LogMessageOptions;
162
- LOG_STYLE_REVERSE: LogMessageOptions;
163
- readonly VERSION: string;
164
- readonly LOG_TYPE: LOG_TYPE;
165
- readonly STATUS_TYPE: STATUS_TYPE;
166
- readonly MAX_TIMEOUT: number;
167
- readonly TEMP_DIR: string;
168
- supported(major: number, minor?: number, patch?: number, lts?: boolean): boolean;
169
- formatMessage(type: LogType, title: string, value: LogValue, message?: unknown, options?: LogMessageOptions): void;
170
- writeFail(value: LogValue, message?: unknown, options?: LogFailOptions | LogType): void;
171
- enabled(key: string, username?: string): boolean;
172
- parseFunction(value: unknown, options?: ParseFunctionOptions): ((...args: unknown[]) => Promise<unknown> | unknown) | null;
173
- parseFunction(value: unknown, absolute: boolean, sync?: boolean): ((...args: unknown[]) => Promise<unknown> | unknown) | null;
174
- asString(value: unknown, cacheKey?: boolean | "throws"): string;
175
- asHash(data: BinaryLike, options: AsHashOptions): string;
176
- asHash(data: BinaryLike, digest: unknown): string;
177
- asHash(data: BinaryLike, algorithm?: NumString | AsHashOptions, digest?: unknown): string;
178
- readHash(value: string | URL, options?: ReadHashOptions): Promise<string>;
179
- toPosix(value: unknown, normalize: boolean): string;
180
- toPosix(value: unknown, filename?: string, normalize?: boolean): string;
181
- hasLogType(value: LogType): boolean;
182
- isURL(value: string, ...exclude: string[]): boolean;
183
- isFile(value: string | URL, type?: ProtocolType): boolean;
184
- isDir(value: string | URL): boolean;
185
- isPath(value: string | URL, type?: "unc" | "unc-exists"): boolean;
186
- isPath(value: string | URL, isFile?: boolean): boolean;
187
- isErrorCode(err: unknown, ...code: string[]): boolean;
188
- fromLocalPath(value: string): string;
189
- resolveFile(value: string): string;
190
- resolvePath(value: string, base: string | URL): string;
191
- joinPath(...values: [...paths: unknown[], normalize: boolean][]): string;
192
- joinPath(...values: unknown[]): string;
193
- normalizePath(value: unknown, flags?: boolean | NormalizeFlags): string;
194
- createDir(value: string | URL, overwrite?: boolean): boolean;
195
- removeDir(value: string | URL, sinceCreated: number, recursive?: boolean): boolean;
196
- removeDir(value: string | URL, empty?: boolean, recursive?: boolean): boolean;
197
- copyDir(src: string | URL, dest: string | URL, options: CopyDirOptions): Promise<CopyDirResult>;
198
- copyDir(src: string | URL, dest: string | URL, move?: boolean, recursive?: boolean): Promise<CopyDirResult>;
199
- renameFile(src: string | URL, dest: string | URL, throws?: boolean): boolean;
200
- streamFile(src: string, cache: boolean): Promise<Buffer | string>;
201
- streamFile(src: string, options: ReadBufferOptions): Promise<Buffer | string>;
202
- streamFile(src: string, cache?: boolean | ReadBufferOptions, options?: ReadBufferOptions): Promise<Buffer | string>;
203
- readText(value: string | URL, cache: boolean): string;
204
- readText(value: string | URL, options: ReadTextOptions): Promise<string> | string;
205
- readText(value: string | URL, encoding?: BufferEncoding | boolean | ReadTextOptions, cache?: boolean): string;
206
- readBuffer(value: string | URL, options: ReadBufferOptions): Promise<Buffer | null> | Buffer | null;
207
- readBuffer(value: string | URL, cache?: boolean): Buffer | null;
208
- resolveMime(data: string | Buffer | Uint8Array | ArrayBuffer): Promise<FileTypeResult | undefined>;
209
- lookupMime(value: string, extension?: boolean): string;
210
- initCpuUsage(instance?: IModule): CpuUsage;
211
- getCpuUsage(start: CpuUsage, format: true): string;
212
- getCpuUsage(start: CpuUsage, format?: boolean): number;
213
- getMemUsage(format: true): string;
214
- getMemUsage(format?: boolean): number;
215
- formatCpuMem(start: CpuUsage, all?: boolean): string;
216
- getPackageVersion(name: string | [string, string], startDir: string, baseDir?: string): string;
217
- getPackageVersion(name: string | [string, string], unstable?: boolean, startDir?: string, baseDir?: string): string;
218
- checkSemVer(name: string | [string, string], options: CheckSemVerOptions): boolean;
219
- checkSemVer(name: string | [string, string], min: number | string, max: number | string, options: CheckSemVerOptions): boolean;
220
- checkSemVer(name: string | [string, string], min: number | string, max?: number | string, unstable?: boolean, startDir?: string): boolean;
221
- sanitizeCmd(value: string): string;
222
- sanitizeArgs(value: string, doubleQuote?: boolean): string;
223
- sanitizeArgs(values: string[], doubleQuote?: boolean): string[];
224
- purgeMemory(percent: number, parent: boolean | number): Promise<number>;
225
- purgeMemory(percent?: number, limit?: number, parent?: boolean | number): Promise<number>;
226
- canWrite(name: "temp" | "home"): boolean;
227
- loadSettings(settings: Settings, password?: string): boolean;
228
- readonly prototype: IModule<IHost>;
229
- new(): IModule<IHost>;
230
- }
231
- ```
232
-
233
- ## References
234
-
235
- - https://www.unpkg.com/@e-mc/types@0.8.17/lib/core.d.ts
236
- - https://www.unpkg.com/@e-mc/types@0.8.17/lib/logger.d.ts
237
- - https://www.unpkg.com/@e-mc/types@0.8.17/lib/module.d.ts
238
- - https://www.unpkg.com/@e-mc/types@0.8.17/lib/node.d.ts
239
-
240
- ## LICENSE
241
-
1
+ # @e-mc/module
2
+
3
+ * NodeJS 14
4
+ * ES2019
5
+
6
+ ## General Usage
7
+
8
+ * [Read the Docs](https://e-mc.readthedocs.io)
9
+
10
+ ## Interface
11
+
12
+ - https://www.unpkg.com/@e-mc/types@0.8.19/lib/index.d.ts
13
+
14
+ ```typescript
15
+ import type { LogStatus } from "./squared";
16
+
17
+ import type { IHost } from "./index";
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";
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
+ import type { Settings } from "./node";
22
+
23
+ import type { SpawnOptions } from "child_process";
24
+ import type { BinaryLike } from "crypto";
25
+ import type { FileTypeResult } from "file-type";
26
+ import type { NoParamCallback } from "fs";
27
+
28
+ import type * as EventEmitter from "events";
29
+
30
+ type BufferView = Buffer | string | NodeJS.ArrayBufferView;
31
+ type CpuUsage = NodeJS.CpuUsage;
32
+
33
+ interface IModule extends EventEmitter, IAbortComponent {
34
+ readonly status: LogStatus<StatusType>[];
35
+ readonly errors: unknown[];
36
+ supported(major: number, minor?: number, patch?: number, lts?: boolean): boolean;
37
+ supports(name: string, value?: boolean): boolean;
38
+ getTempDir(options: GetTempDirOptions): string;
39
+ getTempDir(uuidDir: boolean, createDir?: boolean): string;
40
+ getTempDir(pathname: string, createDir?: boolean): string;
41
+ getTempDir(uuidDir: boolean, filename: string, createDir?: boolean): string;
42
+ getTempDir(pathname?: string, filename?: string, createDir?: boolean): string;
43
+ canRead(uri: string, options?: PermissionOptions): boolean;
44
+ canWrite(uri: string, options?: PermissionOptions): boolean;
45
+ readFile(src: string): Buffer | undefined;
46
+ readFile(src: string, options?: ReadFileOptions): Promise<Buffer | string> | Buffer | string | undefined;
47
+ readFile(src: string, promises: true): Promise<Buffer | undefined>;
48
+ readFile(src: string, options: ReadFileOptions, promises: true): Promise<Buffer | string | undefined>;
49
+ readFile(src: string, callback: ReadFileCallback<Buffer>): Buffer | undefined;
50
+ readFile(src: string, options: ReadFileOptions, callback: ReadFileCallback<Buffer | string>): Buffer | string | undefined;
51
+ writeFile(src: string, data: BufferView, options?: WriteFileOptions): boolean;
52
+ writeFile(src: string, data: BufferView, promises: true): Promise<boolean>;
53
+ writeFile(src: string, data: BufferView, options: WriteFileOptions, promises: true): Promise<boolean>;
54
+ writeFile(src: string, data: BufferView, callback: NoParamCallback): void;
55
+ writeFile(src: string, data: BufferView, options: WriteFileOptions, callback: NoParamCallback): void;
56
+ deleteFile(src: string, options?: DeleteFileOptions): boolean;
57
+ deleteFile(src: string, promises: true): Promise<boolean>;
58
+ deleteFile(src: string, options: DeleteFileOptions, promises: true): Promise<boolean>;
59
+ deleteFile(src: string, callback: NoParamCallback): void;
60
+ deleteFile(src: string, options: DeleteFileOptions, callback: NoParamCallback): void;
61
+ copyFile(src: string, dest: string, options?: CopyFileOptions): boolean;
62
+ copyFile(src: string, dest: string, promises: true): Promise<boolean>;
63
+ copyFile(src: string, dest: string, options: CopyFileOptions, promises: true): Promise<boolean>;
64
+ copyFile(src: string, dest: string, callback: NoParamCallback): void;
65
+ copyFile(src: string, dest: string, options: CopyFileOptions, callback: NoParamCallback): void;
66
+ moveFile(src: string, dest: string, options?: MoveFileOptions): boolean;
67
+ moveFile(src: string, dest: string, promises: true): Promise<boolean>;
68
+ moveFile(src: string, dest: string, options: MoveFileOptions, promises: true): Promise<boolean>;
69
+ moveFile(src: string, dest: string, callback: NoParamCallback): void;
70
+ moveFile(src: string, dest: string, options: MoveFileOptions, callback: NoParamCallback): void;
71
+ createDir(src: string, options?: CreateDirOptions): boolean;
72
+ createDir(src: string, promises: true): Promise<boolean>;
73
+ createDir(src: string, options: CreateDirOptions, promises: true): Promise<boolean>;
74
+ createDir(src: string, callback: NoParamCallback): void;
75
+ createDir(src: string, options: CreateDirOptions, callback: NoParamCallback): void;
76
+ removeDir(src: string, options?: RemoveDirOptions): boolean;
77
+ removeDir(src: string, promises: true): Promise<boolean>;
78
+ removeDir(src: string, options: RemoveDirOptions, promises: true): Promise<boolean>;
79
+ removeDir(src: string, callback: NoParamCallback): void;
80
+ removeDir(src: string, options: RemoveDirOptions, callback: NoParamCallback): void;
81
+ allSettled(values: readonly PromiseLike<unknown>[], rejected?: LogValue, options?: LogFailOptions | LogType): Promise<PromiseFulfilledResult<unknown>[]>;
82
+ formatMessage(type: LogType, title: string, value: LogValue, message?: unknown, options?: LogMessageOptions): void;
83
+ formatFail(type: LogType, title: string, value: LogValue, message?: unknown, options?: LogFailOptions): void;
84
+ writeFail(value: LogValue, message?: unknown, options?: LogFailOptions | LogType): void;
85
+ writeTimeProcess(title: string, value: string, startTime: LogTime, options?: LogProcessOptions): void;
86
+ writeTimeElapsed(title: string, value: LogValue, startTime: LogTime, options?: LogMessageOptions): void;
87
+ checkPackage(err: unknown, name: string | undefined, options?: LogFailOptions | LogType): boolean;
88
+ checkPackage(err: unknown, name: string | undefined, value?: LogValue, options?: LogFailOptions | LogType): boolean;
89
+ checkFail(message: unknown, options: LogFailOptions): LogArguments | false | undefined;
90
+ writeLog(component: LogComponent, queue?: boolean): void;
91
+ writeLog(type: StatusType, value: unknown, options?: LogOptions): void;
92
+ writeLog(type: StatusType, value: unknown, timeStamp?: LogDate, duration?: number): void;
93
+ addLog(component: LogComponent, queue?: boolean): void;
94
+ addLog(type: StatusType, value: unknown, from: string, source?: string): void;
95
+ addLog(type: StatusType, value: unknown, options?: LogOptions): void;
96
+ addLog(type: StatusType, value: unknown, timeStamp?: LogDate, from?: string, source?: string): void;
97
+ addLog(type: StatusType, value: unknown, timeStamp?: LogDate, duration?: number, from?: string, source?: string): void;
98
+ getLog(...type: StatusType[]): LogStatus<StatusType>[];
99
+ flushLog(): void;
100
+ willAbort(value: unknown): boolean;
101
+ hasOwnPermission(): boolean;
102
+ isFatal(err?: unknown): boolean;
103
+ detach(): void;
104
+ reset(): void;
105
+ get moduleName(): string;
106
+ set host(value);
107
+ get host(): IHost | null;
108
+ set permission(value);
109
+ get permission(): IPermission | null;
110
+ get aborted(): boolean;
111
+ set abortable(value);
112
+ get abortable(): boolean;
113
+ get threadable(): boolean;
114
+ set sessionId(value);
115
+ get sessionId(): string;
116
+ set broadcastId(value);
117
+ get broadcastId(): string | string[];
118
+ get logType(): LOG_TYPE;
119
+ set logLevel(value: number | string);
120
+ get logLevel(): number;
121
+ get statusType(): STATUS_TYPE;
122
+ set tempDir(value);
123
+ get tempDir(): string;
124
+
125
+ /* EventEmitter */
126
+ on(event: "exec", listener: (command: ExecCommand, options?: SpawnOptions) => void): this;
127
+ on(event: "error", listener: (err: Error) => void): this;
128
+ on(event: "file:read", listener: (src: string, data: Buffer | string, options?: ReadFileOptions) => void): this;
129
+ on(event: "file:write", listener: (src: string, options?: WriteFileOptions) => void): this;
130
+ on(event: "file:delete", listener: (src: string, options?: DeleteFileOptions) => void): this;
131
+ on(event: "file:copy", listener: (dest: string, options?: CopyFileOptions) => void): this;
132
+ on(event: "file:move", listener: (dest: string, options?: MoveFileOptions) => void): this;
133
+ on(event: "dir:create", listener: (src: string, options?: CreateDirOptions) => void): this;
134
+ on(event: "dir:remove", listener: (src: string, options?: RemoveDirOptions) => void): this;
135
+ once(event: "exec", listener: (command: ExecCommand, options?: SpawnOptions) => void): this;
136
+ once(event: "error", listener: (err: Error) => void): this;
137
+ once(event: "file:read", listener: (src: string, data: Buffer | string, options?: ReadFileOptions) => void): this;
138
+ once(event: "file:write", listener: (src: string, options?: WriteFileOptions) => void): this;
139
+ once(event: "file:delete", listener: (src: string, options?: DeleteFileOptions) => void): this;
140
+ once(event: "file:copy", listener: (dest: string, options?: CopyFileOptions) => void): this;
141
+ once(event: "file:move", listener: (dest: string, options?: MoveFileOptions) => void): this;
142
+ once(event: "dir:create", listener: (src: string, options?: CreateDirOptions) => void): this;
143
+ once(event: "dir:remove", listener: (src: string, options?: RemoveDirOptions) => void): this;
144
+ emit(event: "exec", command: ExecCommand, options?: SpawnOptions): boolean;
145
+ emit(event: "error", err: Error): boolean;
146
+ emit(event: "file:read", src: string, data: Buffer | string, options?: ReadFileOptions): boolean;
147
+ emit(event: "file:write", src: string, options?: WriteFileOptions): boolean;
148
+ emit(event: "file:delete", src: string, options?: DeleteFileOptions): boolean;
149
+ emit(event: "file:copy", dest: string, options?: CopyFileOptions): boolean;
150
+ emit(event: "file:move", dest: string, options?: MoveFileOptions): boolean;
151
+ emit(event: "dir:create", src: string, options?: CreateDirOptions): boolean;
152
+ emit(event: "dir:remove", src: string, options?: RemoveDirOptions): boolean;
153
+ }
154
+
155
+ interface ModuleConstructor {
156
+ PROCESS_TIMEOUT: number;
157
+ LOG_STYLE_FAIL: LogMessageOptions;
158
+ LOG_STYLE_SUCCESS: LogMessageOptions;
159
+ LOG_STYLE_INFO: LogMessageOptions;
160
+ LOG_STYLE_WARN: LogMessageOptions;
161
+ LOG_STYLE_NOTICE: LogMessageOptions;
162
+ LOG_STYLE_REVERSE: LogMessageOptions;
163
+ readonly VERSION: string;
164
+ readonly LOG_TYPE: LOG_TYPE;
165
+ readonly STATUS_TYPE: STATUS_TYPE;
166
+ readonly MAX_TIMEOUT: number;
167
+ readonly TEMP_DIR: string;
168
+ supported(major: number, minor?: number, patch?: number, lts?: boolean): boolean;
169
+ formatMessage(type: LogType, title: string, value: LogValue, message?: unknown, options?: LogMessageOptions): void;
170
+ writeFail(value: LogValue, message?: unknown, options?: LogFailOptions | LogType): void;
171
+ enabled(key: string, username?: string): boolean;
172
+ parseFunction(value: unknown, options?: ParseFunctionOptions): ((...args: unknown[]) => Promise<unknown> | unknown) | null;
173
+ parseFunction(value: unknown, absolute: boolean, sync?: boolean): ((...args: unknown[]) => Promise<unknown> | unknown) | null;
174
+ asString(value: unknown, cacheKey?: boolean | "throws"): string;
175
+ asHash(data: BinaryLike, options: AsHashOptions): string;
176
+ asHash(data: BinaryLike, algorithm?: unknown, digest?: unknown): string;
177
+ readHash(value: string | URL, options?: ReadHashOptions): Promise<string>;
178
+ toPosix(value: unknown, normalize: boolean): string;
179
+ toPosix(value: unknown, filename?: string, normalize?: boolean): string;
180
+ hasLogType(value: LogType): boolean;
181
+ isURL(value: string, ...exclude: string[]): boolean;
182
+ isFile(value: string | URL, type?: ProtocolType): boolean;
183
+ isDir(value: string | URL): boolean;
184
+ isPath(value: string | URL, type?: "unc" | "unc-exists"): boolean;
185
+ isPath(value: string | URL, isFile?: boolean): boolean;
186
+ isErrorCode(err: unknown, ...code: string[]): boolean;
187
+ fromLocalPath(value: string): string;
188
+ resolveFile(value: string): string;
189
+ resolvePath(value: string, base: string | URL): string;
190
+ joinPath(...values: [...paths: unknown[], normalize: boolean][]): string;
191
+ joinPath(...values: unknown[]): string;
192
+ normalizePath(value: unknown, flags?: boolean | NormalizeFlags): string;
193
+ createDir(value: string | URL, overwrite?: boolean): boolean;
194
+ removeDir(value: string | URL, sinceCreated: number, recursive?: boolean): boolean;
195
+ removeDir(value: string | URL, empty?: boolean, recursive?: boolean): boolean;
196
+ copyDir(src: string | URL, dest: string | URL, options: CopyDirOptions): Promise<CopyDirResult>;
197
+ copyDir(src: string | URL, dest: string | URL, move?: boolean, recursive?: boolean): Promise<CopyDirResult>;
198
+ renameFile(src: string | URL, dest: string | URL, throws?: boolean): boolean;
199
+ streamFile(src: string, cache: boolean): Promise<Buffer | string>;
200
+ streamFile(src: string, options: ReadBufferOptions): Promise<Buffer | string>;
201
+ streamFile(src: string, cache?: boolean | ReadBufferOptions, options?: ReadBufferOptions): Promise<Buffer | string>;
202
+ readText(value: string | URL, cache: boolean): string;
203
+ readText(value: string | URL, options: ReadTextOptions): Promise<string> | string;
204
+ readText(value: string | URL, encoding?: BufferEncoding | boolean | ReadTextOptions, cache?: boolean): string;
205
+ readBuffer(value: string | URL, options: ReadBufferOptions): Promise<Buffer | null> | Buffer | null;
206
+ readBuffer(value: string | URL, cache?: boolean): Buffer | null;
207
+ resolveMime(data: string | Buffer | Uint8Array | ArrayBuffer): Promise<FileTypeResult | undefined>;
208
+ lookupMime(value: string, extension?: boolean): string;
209
+ initCpuUsage(instance?: IModule): CpuUsage;
210
+ getCpuUsage(start: CpuUsage, format: true): string;
211
+ getCpuUsage(start: CpuUsage, format?: boolean): number;
212
+ getMemUsage(format: true): string;
213
+ getMemUsage(format?: boolean): number;
214
+ formatCpuMem(start: CpuUsage, all?: boolean): string;
215
+ getPackageVersion(name: string | [string, string], startDir: string, baseDir?: string): string;
216
+ getPackageVersion(name: string | [string, string], unstable?: boolean, startDir?: string, baseDir?: string): string;
217
+ checkSemVer(name: string | [string, string], options: CheckSemVerOptions): boolean;
218
+ checkSemVer(name: string | [string, string], min: number | string, max: number | string, options: CheckSemVerOptions): boolean;
219
+ checkSemVer(name: string | [string, string], min: number | string, max?: number | string, unstable?: boolean, startDir?: string): boolean;
220
+ sanitizeCmd(value: string): string;
221
+ sanitizeArgs(value: string, doubleQuote?: boolean): string;
222
+ sanitizeArgs(values: string[], doubleQuote?: boolean): string[];
223
+ purgeMemory(percent: number, parent: boolean | number): Promise<number>;
224
+ purgeMemory(percent?: number, limit?: number, parent?: boolean | number): Promise<number>;
225
+ canWrite(name: "temp" | "home"): boolean;
226
+ loadSettings(settings: Settings, password?: string): boolean;
227
+ readonly prototype: IModule<IHost>;
228
+ new(): IModule<IHost>;
229
+ }
230
+ ```
231
+
232
+ ## References
233
+
234
+ - https://www.unpkg.com/@e-mc/types@0.8.19/lib/core.d.ts
235
+ - https://www.unpkg.com/@e-mc/types@0.8.19/lib/logger.d.ts
236
+ - https://www.unpkg.com/@e-mc/types@0.8.19/lib/module.d.ts
237
+ - https://www.unpkg.com/@e-mc/types@0.8.19/lib/node.d.ts
238
+
239
+ ## LICENSE
240
+
242
241
  MIT
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 '@e-mc/types/lib';
2
+
3
+ declare const Module: ModuleConstructor;
4
+
5
5
  export = Module;
package/index.js CHANGED
@@ -106,6 +106,7 @@ const VALUES = {
106
106
  ["node.process.cpu_usage"]: true,
107
107
  ["node.process.memory_usage"]: true,
108
108
  ["node.process.inline"]: true,
109
+ ["node.settings.package_manager"]: '',
109
110
  ["temp.dir"]: "tmp",
110
111
  ["temp.write"]: false,
111
112
  ["process.password"]: '',
@@ -176,7 +177,7 @@ function setPnpmVer() {
176
177
  value = value.substring(0, index);
177
178
  }
178
179
  index = value.lastIndexOf(value.indexOf('@', 2) !== -1 ? '@' : '/');
179
- const name = value.substring(1, index);
180
+ const name = value.substring(0, index).replace(/^\//, '');
180
181
  const version = value.substring(index + 1);
181
182
  if (!items.find(item => item[0] === name && item[1] === version)) {
182
183
  items.push([name, version]);
@@ -714,7 +715,7 @@ class Module extends EventEmitter {
714
715
  this[_f] = new AbortController();
715
716
  this[_g] = null;
716
717
  }
717
- static get VERSION() { return "0.8.17"; }
718
+ static get VERSION() { return "0.8.19"; }
718
719
  static get LOG_TYPE() { return types_1.LOG_TYPE; }
719
720
  static get STATUS_TYPE() { return types_1.STATUS_TYPE; }
720
721
  static get MAX_TIMEOUT() { return 2147483647; }
@@ -756,6 +757,7 @@ class Module extends EventEmitter {
756
757
  case "error.fatal":
757
758
  return VALUES[key];
758
759
  case "node.require.ext":
760
+ case "node.settings.package_manager":
759
761
  case "process.password":
760
762
  case "process.cipher.algorithm":
761
763
  return VALUES[key] !== '';
@@ -2090,8 +2092,8 @@ class Module extends EventEmitter {
2090
2092
  }
2091
2093
  static sanitizeArgs(values, doubleQuote) {
2092
2094
  const result = typeof values === 'string' ? [values] : values;
2093
- const pattern = /[^0-9a-z%+-./:=@_]/gi;
2094
- const sanitize = (value) => value.replace(pattern, capture => (capture === '$' || capture === '`' ? '\\' : '') + '\\' + capture);
2095
+ const pattern = /[^\w+-.,/:@]/g;
2096
+ const sanitize = (value) => value.replace(pattern, capture => capture === '\n' ? "'\n'" : (capture === '$' || capture === '`' ? '\\' : '') + '\\' + capture);
2095
2097
  for (let i = 0; i < result.length; ++i) {
2096
2098
  let value = result[i].trim(), leading = '';
2097
2099
  if (value !== '--') {
@@ -2204,8 +2206,8 @@ class Module extends EventEmitter {
2204
2206
  }
2205
2207
  }
2206
2208
  static loadSettings(settings, password) {
2207
- var _h;
2208
- var _j;
2209
+ var _h, _j;
2210
+ var _k;
2209
2211
  const current = VALUES["process.password"];
2210
2212
  if (current) {
2211
2213
  const proc = settings.process || {};
@@ -2260,6 +2262,17 @@ class Module extends EventEmitter {
2260
2262
  VALUES["node.require.inline"] = inline;
2261
2263
  }
2262
2264
  }
2265
+ const manager = (_j = node.settings) === null || _j === void 0 ? void 0 : _j.package_manager;
2266
+ switch (manager) {
2267
+ case 'npm':
2268
+ case 'yarn':
2269
+ case 'pnpm':
2270
+ VALUES["node.settings.package_manager"] = manager;
2271
+ break;
2272
+ default:
2273
+ VALUES["node.settings.package_manager"] = '';
2274
+ break;
2275
+ }
2263
2276
  }
2264
2277
  if ((0, types_1.isPlainObject)(settings.process)) {
2265
2278
  const { env, cipher, password: pwd } = settings.process;
@@ -2267,7 +2280,7 @@ class Module extends EventEmitter {
2267
2280
  VALUES["process.env.apply"] = env.apply;
2268
2281
  }
2269
2282
  if ((0, types_1.isString)(pwd)) {
2270
- VALUES[_j = "process.password"] || (VALUES[_j] = encryptMessage(pwd, cipher));
2283
+ VALUES[_k = "process.password"] || (VALUES[_k] = encryptMessage(pwd, cipher));
2271
2284
  }
2272
2285
  }
2273
2286
  if ((0, types_1.isPlainObject)(memory === null || memory === void 0 ? void 0 : memory.settings)) {
@@ -3347,7 +3360,7 @@ class Module extends EventEmitter {
3347
3360
  if (typeof options === 'number') {
3348
3361
  options = undefined;
3349
3362
  }
3350
- this.writeFail("Unknown", err, { ...options, type: types_1.LOG_TYPE.SYSTEM, code: types_1.ERR_CODE.MODULE_NOT_FOUND, exec: { command: 'npm', args: ['i', name] } });
3363
+ this.writeFail("Unknown", err, { ...options, type: types_1.LOG_TYPE.SYSTEM, code: types_1.ERR_CODE.MODULE_NOT_FOUND, exec: { command: VALUES["node.settings.package_manager"] || (setPnpmVer() ? 'pnpm' : setYarnVer() ? 'yarn' : 'npm'), args: ['install', name] } });
3351
3364
  return true;
3352
3365
  }
3353
3366
  if (value) {
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 '@e-mc/types/lib/compat-v4';
2
+
3
+ declare const LibV4: IModuleLibV4;
4
+
5
5
  export = LibV4;
package/package.json CHANGED
@@ -1,33 +1,33 @@
1
- {
2
- "name": "@e-mc/module",
3
- "version": "0.8.17",
4
- "description": "Module base class for E-mc.",
5
- "main": "index.js",
6
- "types": "index.d.ts",
7
- "publishConfig": {
8
- "access": "public"
9
- },
10
- "repository": {
11
- "type": "git",
12
- "url": "git+https://github.com/anpham6/e-mc.git",
13
- "directory": "src/module"
14
- },
15
- "keywords": [
16
- "squared",
17
- "squared-functions"
18
- ],
19
- "author": "An Pham <anpham6@gmail.com>",
20
- "license": "MIT",
21
- "homepage": "https://github.com/anpham6/e-mc#readme",
22
- "dependencies": {
23
- "@e-mc/types": "0.8.17",
24
- "abort-controller": "^3.0.0",
25
- "chalk": "4.1.2",
26
- "event-target-shim": "^5.0.1",
27
- "file-type": "16.5.4",
28
- "js-yaml": "^4.1.0",
29
- "mime-types": "^2.1.35",
30
- "picomatch": "^3.0.1",
31
- "strip-ansi": "6.0.1"
32
- }
33
- }
1
+ {
2
+ "name": "@e-mc/module",
3
+ "version": "0.8.19",
4
+ "description": "Module base class for E-mc.",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/anpham6/e-mc.git",
13
+ "directory": "src/module"
14
+ },
15
+ "keywords": [
16
+ "squared",
17
+ "squared-functions"
18
+ ],
19
+ "author": "An Pham <anpham6@gmail.com>",
20
+ "license": "MIT",
21
+ "homepage": "https://github.com/anpham6/e-mc#readme",
22
+ "dependencies": {
23
+ "@e-mc/types": "0.8.19",
24
+ "abort-controller": "^3.0.0",
25
+ "chalk": "4.1.2",
26
+ "event-target-shim": "^5.0.1",
27
+ "file-type": "16.5.4",
28
+ "js-yaml": "^4.1.0",
29
+ "mime-types": "^2.1.35",
30
+ "picomatch": "^3.0.1",
31
+ "strip-ansi": "6.0.1"
32
+ }
33
+ }