@e-mc/module 0.8.4 → 0.8.5
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 +4 -8
- package/README.md +2 -238
- package/index.js +9 -8
- package/package.json +3 -3
package/LICENSE
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
Copyright
|
|
1
|
+
Copyright 2024 Mile Square Park
|
|
2
2
|
|
|
3
|
-
|
|
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
4
|
|
|
5
|
-
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
6
|
|
|
7
|
-
|
|
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.
|
|
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,243 +1,7 @@
|
|
|
1
1
|
# @e-mc/module
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
* ES2020
|
|
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.4/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 { ExecCommand, LOG_TYPE, LogArguments, LogComponent, LogDate, LogFailOptions, LogMessageOptions, LogOptions, LogProcessOptions, LogTime, LogType, LogValue, STATUS_TYPE, 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 { NoParamCallback } from "fs";
|
|
24
|
-
import type { SpawnOptions } from "child_process";
|
|
25
|
-
import type { BinaryLike } from "crypto";
|
|
26
|
-
|
|
27
|
-
import type * as EventEmitter from "events";
|
|
28
|
-
|
|
29
|
-
import type { FileTypeResult } from "file-type";
|
|
30
|
-
|
|
31
|
-
type BufferView = Buffer | string | NodeJS.ArrayBufferView;
|
|
32
|
-
type CpuUsage = NodeJS.CpuUsage;
|
|
33
|
-
|
|
34
|
-
interface IModule extends EventEmitter, IAbortComponent {
|
|
35
|
-
readonly status: LogStatus<StatusType>[];
|
|
36
|
-
readonly errors: unknown[];
|
|
37
|
-
supported(major: number, minor?: number, patch?: number, lts?: boolean): boolean;
|
|
38
|
-
supports(name: string, value?: boolean): boolean;
|
|
39
|
-
getTempDir(options: GetTempDirOptions): string;
|
|
40
|
-
getTempDir(uuidDir: boolean, createDir?: boolean): string;
|
|
41
|
-
getTempDir(pathname: string, createDir?: boolean): string;
|
|
42
|
-
getTempDir(uuidDir: boolean, filename: string, createDir?: boolean): string;
|
|
43
|
-
getTempDir(pathname?: string, filename?: string, createDir?: boolean): string;
|
|
44
|
-
canRead(uri: string, options?: PermissionOptions): boolean;
|
|
45
|
-
canWrite(uri: string, options?: PermissionOptions): boolean;
|
|
46
|
-
readFile(src: string): Buffer | undefined;
|
|
47
|
-
readFile(src: string, options?: ReadFileOptions): Promise<Buffer | string> | Buffer | string | undefined;
|
|
48
|
-
readFile(src: string, promises: true): Promise<Buffer | undefined>;
|
|
49
|
-
readFile(src: string, options: ReadFileOptions, promises: true): Promise<Buffer | string | undefined>;
|
|
50
|
-
readFile(src: string, callback: ReadFileCallback<Buffer>): Buffer | undefined;
|
|
51
|
-
readFile(src: string, options: ReadFileOptions, callback: ReadFileCallback<Buffer | string>): Buffer | string | undefined;
|
|
52
|
-
writeFile(src: string, data: BufferView, options?: WriteFileOptions): boolean;
|
|
53
|
-
writeFile(src: string, data: BufferView, promises: true): Promise<boolean>;
|
|
54
|
-
writeFile(src: string, data: BufferView, options: WriteFileOptions, promises: true): Promise<boolean>;
|
|
55
|
-
writeFile(src: string, data: BufferView, callback: NoParamCallback): void;
|
|
56
|
-
writeFile(src: string, data: BufferView, options: WriteFileOptions, callback: NoParamCallback): void;
|
|
57
|
-
deleteFile(src: string, options?: DeleteFileOptions): boolean;
|
|
58
|
-
deleteFile(src: string, promises: true): Promise<boolean>;
|
|
59
|
-
deleteFile(src: string, options: DeleteFileOptions, promises: true): Promise<boolean>;
|
|
60
|
-
deleteFile(src: string, callback: NoParamCallback): void;
|
|
61
|
-
deleteFile(src: string, options: DeleteFileOptions, callback: NoParamCallback): void;
|
|
62
|
-
copyFile(src: string, dest: string, options?: CopyFileOptions): boolean;
|
|
63
|
-
copyFile(src: string, dest: string, promises: true): Promise<boolean>;
|
|
64
|
-
copyFile(src: string, dest: string, options: CopyFileOptions, promises: true): Promise<boolean>;
|
|
65
|
-
copyFile(src: string, dest: string, callback: NoParamCallback): void;
|
|
66
|
-
copyFile(src: string, dest: string, options: CopyFileOptions, callback: NoParamCallback): void;
|
|
67
|
-
moveFile(src: string, dest: string, options?: MoveFileOptions): boolean;
|
|
68
|
-
moveFile(src: string, dest: string, promises: true): Promise<boolean>;
|
|
69
|
-
moveFile(src: string, dest: string, options: MoveFileOptions, promises: true): Promise<boolean>;
|
|
70
|
-
moveFile(src: string, dest: string, callback: NoParamCallback): void;
|
|
71
|
-
moveFile(src: string, dest: string, options: MoveFileOptions, callback: NoParamCallback): void;
|
|
72
|
-
createDir(src: string, options?: CreateDirOptions): boolean;
|
|
73
|
-
createDir(src: string, promises: true): Promise<boolean>;
|
|
74
|
-
createDir(src: string, options: CreateDirOptions, promises: true): Promise<boolean>;
|
|
75
|
-
createDir(src: string, callback: NoParamCallback): void;
|
|
76
|
-
createDir(src: string, options: CreateDirOptions, callback: NoParamCallback): void;
|
|
77
|
-
removeDir(src: string, options?: RemoveDirOptions): boolean;
|
|
78
|
-
removeDir(src: string, promises: true): Promise<boolean>;
|
|
79
|
-
removeDir(src: string, options: RemoveDirOptions, promises: true): Promise<boolean>;
|
|
80
|
-
removeDir(src: string, callback: NoParamCallback): void;
|
|
81
|
-
removeDir(src: string, options: RemoveDirOptions, callback: NoParamCallback): void;
|
|
82
|
-
allSettled(values: readonly PromiseLike<unknown>[], rejected?: LogValue, options?: LogFailOptions | LogType): Promise<PromiseFulfilledResult<unknown>[]>;
|
|
83
|
-
formatMessage(type: LogType, title: string, value: LogValue, message?: unknown, options?: LogMessageOptions): void;
|
|
84
|
-
formatFail(type: LogType, title: string, value: LogValue, message?: unknown, options?: LogFailOptions): void;
|
|
85
|
-
writeFail(value: LogValue, message?: unknown, options?: LogFailOptions | LogType): void;
|
|
86
|
-
writeTimeProcess(title: string, value: string, startTime: LogTime, options?: LogProcessOptions): void;
|
|
87
|
-
writeTimeElapsed(title: string, value: LogValue, startTime: LogTime, options?: LogMessageOptions): void;
|
|
88
|
-
checkPackage(err: unknown, name: string | undefined, options?: LogFailOptions | LogType): boolean;
|
|
89
|
-
checkPackage(err: unknown, name: string | undefined, value?: LogValue, options?: LogFailOptions | LogType): boolean;
|
|
90
|
-
checkFail(message: unknown, options: LogFailOptions): LogArguments | false | undefined;
|
|
91
|
-
writeLog(component: LogComponent, queue?: boolean): void;
|
|
92
|
-
writeLog(type: StatusType, value: unknown, options?: LogOptions): void;
|
|
93
|
-
writeLog(type: StatusType, value: unknown, timeStamp?: LogDate, duration?: number): void;
|
|
94
|
-
addLog(component: LogComponent, queue?: boolean): void;
|
|
95
|
-
addLog(type: StatusType, value: unknown, from: string, source?: string): void;
|
|
96
|
-
addLog(type: StatusType, value: unknown, options?: LogOptions): void;
|
|
97
|
-
addLog(type: StatusType, value: unknown, timeStamp?: LogDate, from?: string, source?: string): void;
|
|
98
|
-
addLog(type: StatusType, value: unknown, timeStamp?: LogDate, duration?: number, from?: string, source?: string): void;
|
|
99
|
-
getLog(...type: StatusType[]): LogStatus<StatusType>[];
|
|
100
|
-
flushLog(): void;
|
|
101
|
-
willAbort(value: unknown): boolean;
|
|
102
|
-
hasOwnPermission(): boolean;
|
|
103
|
-
isFatal(err?: unknown): boolean;
|
|
104
|
-
detach(): void;
|
|
105
|
-
reset(): void;
|
|
106
|
-
get moduleName(): string;
|
|
107
|
-
set host(value);
|
|
108
|
-
get host(): IHost | null;
|
|
109
|
-
set permission(value);
|
|
110
|
-
get permission(): IPermission | null;
|
|
111
|
-
get aborted(): boolean;
|
|
112
|
-
set abortable(value);
|
|
113
|
-
get abortable(): boolean;
|
|
114
|
-
get threadable(): boolean;
|
|
115
|
-
set sessionId(value);
|
|
116
|
-
get sessionId(): string;
|
|
117
|
-
set broadcastId(value);
|
|
118
|
-
get broadcastId(): string | string[];
|
|
119
|
-
get logType(): LOG_TYPE;
|
|
120
|
-
set logLevel(value: number | string);
|
|
121
|
-
get logLevel(): number;
|
|
122
|
-
get statusType(): STATUS_TYPE;
|
|
123
|
-
set tempDir(value);
|
|
124
|
-
get tempDir(): string;
|
|
125
|
-
|
|
126
|
-
/* EventEmitter */
|
|
127
|
-
on(event: "exec", listener: (command: ExecCommand, options?: SpawnOptions) => void): this;
|
|
128
|
-
on(event: "error", listener: (err: Error) => void): this;
|
|
129
|
-
on(event: "file:read", listener: (src: string, data: Buffer | string, options?: ReadFileOptions) => void): this;
|
|
130
|
-
on(event: "file:write", listener: (src: string, options?: WriteFileOptions) => void): this;
|
|
131
|
-
on(event: "file:delete", listener: (src: string, options?: DeleteFileOptions) => void): this;
|
|
132
|
-
on(event: "file:copy", listener: (dest: string, options?: CopyFileOptions) => void): this;
|
|
133
|
-
on(event: "file:move", listener: (dest: string, options?: MoveFileOptions) => void): this;
|
|
134
|
-
on(event: "dir:create", listener: (src: string, options?: CreateDirOptions) => void): this;
|
|
135
|
-
on(event: "dir:remove", listener: (src: string, options?: RemoveDirOptions) => void): this;
|
|
136
|
-
once(event: "exec", listener: (command: ExecCommand, options?: SpawnOptions) => void): this;
|
|
137
|
-
once(event: "error", listener: (err: Error) => void): this;
|
|
138
|
-
once(event: "file:read", listener: (src: string, data: Buffer | string, options?: ReadFileOptions) => void): this;
|
|
139
|
-
once(event: "file:write", listener: (src: string, options?: WriteFileOptions) => void): this;
|
|
140
|
-
once(event: "file:delete", listener: (src: string, options?: DeleteFileOptions) => void): this;
|
|
141
|
-
once(event: "file:copy", listener: (dest: string, options?: CopyFileOptions) => void): this;
|
|
142
|
-
once(event: "file:move", listener: (dest: string, options?: MoveFileOptions) => void): this;
|
|
143
|
-
once(event: "dir:create", listener: (src: string, options?: CreateDirOptions) => void): this;
|
|
144
|
-
once(event: "dir:remove", listener: (src: string, options?: RemoveDirOptions) => void): this;
|
|
145
|
-
emit(event: "exec", command: ExecCommand, options?: SpawnOptions): boolean;
|
|
146
|
-
emit(event: "error", err: Error): boolean;
|
|
147
|
-
emit(event: "file:read", src: string, data: Buffer | string, options?: ReadFileOptions): boolean;
|
|
148
|
-
emit(event: "file:write", src: string, options?: WriteFileOptions): boolean;
|
|
149
|
-
emit(event: "file:delete", src: string, options?: DeleteFileOptions): boolean;
|
|
150
|
-
emit(event: "file:copy", dest: string, options?: CopyFileOptions): boolean;
|
|
151
|
-
emit(event: "file:move", dest: string, options?: MoveFileOptions): boolean;
|
|
152
|
-
emit(event: "dir:create", src: string, options?: CreateDirOptions): boolean;
|
|
153
|
-
emit(event: "dir:remove", src: string, options?: RemoveDirOptions): boolean;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
interface ModuleConstructor {
|
|
157
|
-
PROCESS_TIMEOUT: number;
|
|
158
|
-
LOG_STYLE_FAIL: LogMessageOptions;
|
|
159
|
-
LOG_STYLE_SUCCESS: LogMessageOptions;
|
|
160
|
-
LOG_STYLE_INFO: LogMessageOptions;
|
|
161
|
-
LOG_STYLE_WARN: LogMessageOptions;
|
|
162
|
-
LOG_STYLE_NOTICE: LogMessageOptions;
|
|
163
|
-
LOG_STYLE_REVERSE: LogMessageOptions;
|
|
164
|
-
readonly VERSION: string;
|
|
165
|
-
readonly LOG_TYPE: LOG_TYPE;
|
|
166
|
-
readonly STATUS_TYPE: STATUS_TYPE;
|
|
167
|
-
readonly MAX_TIMEOUT: number;
|
|
168
|
-
readonly TEMP_DIR: string;
|
|
169
|
-
supported(major: number, minor?: number, patch?: number, lts?: boolean): boolean;
|
|
170
|
-
formatMessage(type: LogType, title: string, value: LogValue, message?: unknown, options?: LogMessageOptions): void;
|
|
171
|
-
writeFail(value: LogValue, message?: unknown, options?: LogFailOptions | LogType): void;
|
|
172
|
-
enabled(key: string, username?: string): boolean;
|
|
173
|
-
parseFunction(value: unknown, options?: ParseFunctionOptions): ((...args: unknown[]) => Promise<unknown> | unknown) | null;
|
|
174
|
-
parseFunction(value: unknown, absolute: boolean, sync?: boolean): ((...args: unknown[]) => Promise<unknown> | unknown) | null;
|
|
175
|
-
asString(value: unknown, cacheKey?: boolean | "throws"): string;
|
|
176
|
-
asHash(data: BinaryLike, options: AsHashOptions): string;
|
|
177
|
-
asHash(data: BinaryLike, minLength: number): string;
|
|
178
|
-
asHash(data: BinaryLike, algorithm?: number | string | AsHashOptions, minLength?: number | AsHashOptions): string;
|
|
179
|
-
readHash(value: string | URL, options?: ReadHashOptions): Promise<string>;
|
|
180
|
-
toPosix(value: unknown, normalize: boolean): string;
|
|
181
|
-
toPosix(value: unknown, filename?: string, normalize?: boolean): string;
|
|
182
|
-
hasLogType(value: LogType): boolean;
|
|
183
|
-
isURL(value: string, ...exclude: string[]): boolean;
|
|
184
|
-
isFile(value: string | URL, type?: ProtocolType): boolean;
|
|
185
|
-
isDir(value: string | URL): boolean;
|
|
186
|
-
isPath(value: string | URL, type?: "unc" | "unc-exists"): boolean;
|
|
187
|
-
isPath(value: string | URL, isFile?: boolean): boolean;
|
|
188
|
-
isErrorCode(err: unknown, ...code: string[]): boolean;
|
|
189
|
-
fromLocalPath(value: string): string;
|
|
190
|
-
resolveFile(value: string): string;
|
|
191
|
-
resolvePath(value: string, base: string | URL): string;
|
|
192
|
-
joinPath(...values: [...paths: unknown[], normalize: boolean][]): string;
|
|
193
|
-
joinPath(...values: unknown[]): string;
|
|
194
|
-
normalizePath(value: unknown, flags?: boolean | NormalizeFlags): string;
|
|
195
|
-
createDir(value: string | URL, overwrite?: boolean): boolean;
|
|
196
|
-
removeDir(value: string | URL, sinceCreated: number, recursive?: boolean): boolean;
|
|
197
|
-
removeDir(value: string | URL, empty?: boolean, recursive?: boolean): boolean;
|
|
198
|
-
copyDir(src: string | URL, dest: string | URL, options: CopyDirOptions): Promise<CopyDirResult>;
|
|
199
|
-
copyDir(src: string | URL, dest: string | URL, move?: boolean, recursive?: boolean): Promise<CopyDirResult>;
|
|
200
|
-
renameFile(src: string | URL, dest: string | URL, throws?: boolean): boolean;
|
|
201
|
-
streamFile(src: string, cache: boolean): Promise<Buffer | string>;
|
|
202
|
-
streamFile(src: string, options: ReadBufferOptions): Promise<Buffer | string>;
|
|
203
|
-
streamFile(src: string, cache?: boolean | ReadBufferOptions, options?: ReadBufferOptions): Promise<Buffer | string>;
|
|
204
|
-
readText(value: string | URL, cache: boolean): string;
|
|
205
|
-
readText(value: string | URL, options: ReadTextOptions): Promise<string> | string;
|
|
206
|
-
readText(value: string | URL, encoding?: BufferEncoding | boolean | ReadTextOptions, cache?: boolean): string;
|
|
207
|
-
readBuffer(value: string | URL, options: ReadBufferOptions): Promise<Buffer | null> | Buffer | null;
|
|
208
|
-
readBuffer(value: string | URL, cache?: boolean): Buffer | null;
|
|
209
|
-
resolveMime(data: string | Buffer | Uint8Array | ArrayBuffer): Promise<FileTypeResult | undefined>;
|
|
210
|
-
lookupMime(value: string, extension?: boolean): string;
|
|
211
|
-
initCpuUsage(instance?: IModule): CpuUsage;
|
|
212
|
-
getCpuUsage(start: CpuUsage, format: true): string;
|
|
213
|
-
getCpuUsage(start: CpuUsage, format?: boolean): number;
|
|
214
|
-
getMemUsage(format: true): string;
|
|
215
|
-
getMemUsage(format?: boolean): number;
|
|
216
|
-
formatCpuMem(start: CpuUsage, all?: boolean): string;
|
|
217
|
-
getPackageVersion(name: string | [string, string], startDir: string): string;
|
|
218
|
-
getPackageVersion(name: string | [string, string], unstable?: boolean, startDir?: string): string;
|
|
219
|
-
checkSemVer(name: string | [string, string], options: CheckSemVerOptions): boolean;
|
|
220
|
-
checkSemVer(name: string | [string, string], min: number | string, max: number | string, options: CheckSemVerOptions): boolean;
|
|
221
|
-
checkSemVer(name: string | [string, string], min: number | string, max?: number | string, unstable?: boolean, startDir?: string): boolean;
|
|
222
|
-
sanitizeCmd(value: string): string;
|
|
223
|
-
sanitizeArgs(value: string, doubleQuote?: boolean): string;
|
|
224
|
-
sanitizeArgs(values: string[], doubleQuote?: boolean): string[];
|
|
225
|
-
purgeMemory(percent: number, parent: boolean | number): Promise<number>;
|
|
226
|
-
purgeMemory(percent?: number, limit?: number, parent?: boolean | number): Promise<number>;
|
|
227
|
-
canWrite(name: "temp" | "home"): boolean;
|
|
228
|
-
loadSettings(settings: Settings, password?: string): boolean;
|
|
229
|
-
readonly prototype: IModule<IHost>;
|
|
230
|
-
new(): IModule<IHost>;
|
|
231
|
-
}
|
|
232
|
-
```
|
|
233
|
-
|
|
234
|
-
## References
|
|
235
|
-
|
|
236
|
-
- https://www.unpkg.com/@e-mc/types@0.8.4/lib/core.d.ts
|
|
237
|
-
- https://www.unpkg.com/@e-mc/types@0.8.4/lib/logger.d.ts
|
|
238
|
-
- https://www.unpkg.com/@e-mc/types@0.8.4/lib/module.d.ts
|
|
239
|
-
- https://www.unpkg.com/@e-mc/types@0.8.4/lib/node.d.ts
|
|
3
|
+
PEP 402
|
|
240
4
|
|
|
241
5
|
## LICENSE
|
|
242
6
|
|
|
243
|
-
|
|
7
|
+
MIT
|
package/index.js
CHANGED
|
@@ -588,11 +588,11 @@ function formatPercent(value, precision = 3) {
|
|
|
588
588
|
return (value * 100).toPrecision(precision) + '%';
|
|
589
589
|
}
|
|
590
590
|
const hideAbort = (err) => err.name === 'AbortError' && SETTINGS.abort === false;
|
|
591
|
-
const asFile = (value) => value instanceof URL
|
|
591
|
+
const asFile = (value) => (0, types_1.isString)(value) ? value.trim() : value instanceof URL && value.protocol === 'file:' ? url.fileURLToPath(value) : '';
|
|
592
592
|
const wrapQuote = (value) => '"' + value.replace(/"/g, '\\"') + '"';
|
|
593
593
|
const isFunction = (value) => typeof value === 'function';
|
|
594
594
|
const isFileURL = (value) => /^file:\/\//i.test(value);
|
|
595
|
-
const sanitizePath = (value) =>
|
|
595
|
+
const sanitizePath = (value) => value ? path.resolve(value) : '';
|
|
596
596
|
const ensureDir = (value) => value.endsWith(path.sep) ? value : value + path.sep;
|
|
597
597
|
const trimDir = (value) => value.endsWith(path.sep) ? value.substring(0, value.length - 1) : value;
|
|
598
598
|
const getExtension = (value) => path.extname(value).toLowerCase().substring(1);
|
|
@@ -623,7 +623,7 @@ class Module extends EventEmitter {
|
|
|
623
623
|
this[_f] = new AbortController();
|
|
624
624
|
this[_g] = null;
|
|
625
625
|
}
|
|
626
|
-
static get VERSION() { return "0.8.
|
|
626
|
+
static get VERSION() { return "0.8.5" /* INTERNAL.VERSION */; }
|
|
627
627
|
static get LOG_TYPE() { return types_1.LOG_TYPE; }
|
|
628
628
|
static get STATUS_TYPE() { return types_1.STATUS_TYPE; }
|
|
629
629
|
static get MAX_TIMEOUT() { return 2147483647; }
|
|
@@ -1434,17 +1434,18 @@ class Module extends EventEmitter {
|
|
|
1434
1434
|
return false;
|
|
1435
1435
|
}
|
|
1436
1436
|
static removeDir(value, empty = false, recursive = true) {
|
|
1437
|
-
|
|
1437
|
+
const outDir = sanitizePath(value = asFile(value));
|
|
1438
|
+
if (outDir) {
|
|
1438
1439
|
try {
|
|
1439
1440
|
if (typeof empty === 'number' && empty <= 0) {
|
|
1440
1441
|
empty = true;
|
|
1441
1442
|
}
|
|
1442
|
-
if (this.isDir(
|
|
1443
|
-
return tryRemoveDir(
|
|
1443
|
+
if (this.isDir(outDir)) {
|
|
1444
|
+
return tryRemoveDir(outDir, empty, !!recursive).length === 0;
|
|
1444
1445
|
}
|
|
1445
|
-
if (!fs.existsSync(
|
|
1446
|
+
if (!fs.existsSync(outDir)) {
|
|
1446
1447
|
if (empty && typeof empty !== 'number') {
|
|
1447
|
-
this.createDir(
|
|
1448
|
+
this.createDir(outDir);
|
|
1448
1449
|
}
|
|
1449
1450
|
return true;
|
|
1450
1451
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/module",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.5",
|
|
4
4
|
"description": "Module base class for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -17,10 +17,10 @@
|
|
|
17
17
|
"squared-functions"
|
|
18
18
|
],
|
|
19
19
|
"author": "An Pham <anpham6@gmail.com>",
|
|
20
|
-
"license": "
|
|
20
|
+
"license": "MIT",
|
|
21
21
|
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/types": "0.8.
|
|
23
|
+
"@e-mc/types": "0.8.5",
|
|
24
24
|
"abort-controller": "^3.0.0",
|
|
25
25
|
"chalk": "4.1.2",
|
|
26
26
|
"event-target-shim": "^5.0.1",
|