@e-mc/module 0.8.6 → 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 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
- - https://www.unpkg.com/@e-mc/types@0.8.6/lib/index.d.ts
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?: boolean): string;
40
- getTempDir(pathname: string, createDir?: boolean): string;
41
- getTempDir(uuidDir: boolean, filename: string, createDir?: boolean): string;
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, options?: LogFailOptions | LogType): Promise<PromiseFulfilledResult<unknown>[]>;
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, options?: LogFailOptions | LogType): void;
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, options?: LogFailOptions | LogType): boolean;
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?: LogOptions): void;
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?: number | string | AsHashOptions, minLength?: number | AsHashOptions): string;
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 | boolean | ReadTextOptions, cache?: boolean): string;
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;
@@ -213,16 +219,17 @@ interface ModuleConstructor {
213
219
  getMemUsage(format: true): string;
214
220
  getMemUsage(format?: boolean): number;
215
221
  formatCpuMem(start: CpuUsage, all?: boolean): string;
216
- getPackageVersion(name: string | [string, string], startDir: string): string;
217
- getPackageVersion(name: string | [string, string], unstable?: boolean, startDir?: string): string;
222
+ getPackageVersion(name: string | [string, string], startDir: string, baseDir?: string): string;
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 | number): Promise<number>;
225
- purgeMemory(percent?: number, limit?: number, parent?: boolean | number): Promise<number>;
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.8.6/lib/core.d.ts
236
- - https://www.unpkg.com/@e-mc/types@0.8.6/lib/logger.d.ts
237
- - https://www.unpkg.com/@e-mc/types@0.8.6/lib/module.d.ts
238
- - https://www.unpkg.com/@e-mc/types@0.8.6/lib/node.d.ts
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");
@@ -132,28 +131,84 @@ const REGEXP_TORRENT = /^(?:magnet:\?xt=|(?:https?|s?ftp):\/\/[^/][^\n]*?\.(?:to
132
131
  let LOG_NEWLINE = true;
133
132
  let LOG_EMPTYLINE = false;
134
133
  let TEMP_DIR = path.join(PROCESS_CWD, "tmp");
135
- const PNPM_VER = (function () {
136
- try {
137
- const pathname = path.resolve('./node_modules/.modules.yaml');
138
- if (fs.existsSync(pathname)) {
139
- return fs.readFileSync(pathname, 'utf-8');
134
+ let PNPM_VER;
135
+ let YARN_VER;
136
+ function parseYaml(pathname) {
137
+ return require('js-yaml').load(fs.readFileSync(pathname, 'utf-8'));
138
+ }
139
+ function setPnpmVer() {
140
+ if (PNPM_VER === undefined) {
141
+ PNPM_VER = false;
142
+ const items = [];
143
+ let baseDir;
144
+ try {
145
+ let pathname = path.resolve("node_modules/.modules.yaml"), config;
146
+ if (fs.existsSync(pathname) && (0, types_1.isPlainObject)(config = parseYaml(pathname))) {
147
+ if (config.nodeLinker === 'hoisted') {
148
+ return PNPM_VER = true;
149
+ }
150
+ if (config.nodeLinker === 'pnp') {
151
+ return false;
152
+ }
153
+ const addPackage = (value) => {
154
+ let index = value.indexOf('(');
155
+ if (index !== -1) {
156
+ value = value.substring(0, index);
157
+ }
158
+ index = value.lastIndexOf(value.indexOf('@', 2) !== -1 ? '@' : '/');
159
+ const name = value.substring(1, index);
160
+ const version = value.substring(index + 1);
161
+ if (!items.find(item => item[0] === name && item[1] === version)) {
162
+ items.push([name, version]);
163
+ }
164
+ };
165
+ for (const name in config.hoistedDependencies) {
166
+ addPackage(name);
167
+ }
168
+ if (!path.isAbsolute(baseDir = config.virtualStoreDir)) {
169
+ baseDir = path.resolve('node_modules', baseDir);
170
+ }
171
+ if (!fs.existsSync(pathname = path.resolve(baseDir, "lock.yaml"))) {
172
+ baseDir = undefined;
173
+ }
174
+ else if ((0, types_1.isPlainObject)(config = parseYaml(pathname))) {
175
+ for (const name in config.packages) {
176
+ addPackage(name);
177
+ }
178
+ }
179
+ }
140
180
  }
141
- }
142
- catch {
143
- }
144
- return '';
145
- })();
146
- const YARN_VER = (function () {
147
- try {
148
- const pathname = path.resolve('./.pnp.cjs');
149
- if (fs.existsSync(pathname)) {
150
- return require(pathname);
181
+ catch {
182
+ }
183
+ if (items.length) {
184
+ PNPM_VER = { baseDir, items };
151
185
  }
152
186
  }
153
- catch {
187
+ return PNPM_VER;
188
+ }
189
+ function setYarnVer() {
190
+ if (YARN_VER === undefined) {
191
+ YARN_VER = false;
192
+ try {
193
+ const pathname = path.resolve(".yarnrc.yml");
194
+ let config;
195
+ if (fs.existsSync(pathname) && (0, types_1.isPlainObject)(config = parseYaml(pathname)) && config.nodeLinker === 'node-modules') {
196
+ return YARN_VER = true;
197
+ }
198
+ }
199
+ catch {
200
+ }
201
+ try {
202
+ const pathname = path.resolve(".pnp.cjs");
203
+ if (fs.existsSync(pathname)) {
204
+ return YARN_VER = require(pathname);
205
+ }
206
+ }
207
+ catch {
208
+ }
154
209
  }
155
- return null;
156
- })();
210
+ return YARN_VER;
211
+ }
157
212
  function applyStyle(options, style) {
158
213
  var _h;
159
214
  for (const attr in style) {
@@ -493,16 +548,27 @@ function encryptMessage(data, cipher, algorithm) {
493
548
  }
494
549
  return data;
495
550
  }
496
- function setCpuAndMem(options) {
497
- if (options.messageUnit) {
498
- return;
551
+ function relayMessage(args) {
552
+ const host = this.host;
553
+ if (host?.logState === 0) {
554
+ host.delayMessage(args);
499
555
  }
500
- const usage = ('startCPU' in this) && this.startCPU || CACHE_CPUHOST.get(this) || this.host && CACHE_CPUHOST.get(this.host);
501
- if (usage) {
502
- options.messageUnit = Module.formatCpuMem(usage);
556
+ else {
557
+ Module.formatMessage(...args);
558
+ }
559
+ }
560
+ function setCpuAndMem(options) {
561
+ if (!options.messageUnit) {
562
+ const usage = CACHE_CPUHOST.get(this) || this.host && CACHE_CPUHOST.get(this.host);
563
+ if (usage) {
564
+ options.messageUnit = Module.formatCpuMem(usage);
565
+ }
503
566
  }
504
567
  }
505
568
  function hasFileSystem(type, value, options, ignoreExists, overwrite) {
569
+ if (!(value = asFile(value))) {
570
+ return '';
571
+ }
506
572
  let result;
507
573
  if (path.isAbsolute(value)) {
508
574
  if (options.absolutePath === false) {
@@ -592,7 +658,7 @@ function formatPercent(value, precision = 3) {
592
658
  return (value * 100).toPrecision(precision) + '%';
593
659
  }
594
660
  const hideAbort = (err) => err.name === 'AbortError' && SETTINGS.abort === false;
595
- const asFile = (value) => (0, types_1.isString)(value) ? value.trim() : value instanceof URL && value.protocol === 'file:' ? url.fileURLToPath(value) : '';
661
+ const asFile = (value) => typeof value === 'string' ? value.trim() : value instanceof URL && value.protocol === 'file:' ? url.fileURLToPath(value) : '';
596
662
  const wrapQuote = (value) => '"' + value.replace(/"/g, '\\"') + '"';
597
663
  const isFunction = (value) => typeof value === 'function';
598
664
  const isFileURL = (value) => /^file:\/\//i.test(value);
@@ -600,11 +666,12 @@ const sanitizePath = (value) => value ? path.resolve(value) : '';
600
666
  const ensureDir = (value) => value.endsWith(path.sep) ? value : value + path.sep;
601
667
  const trimDir = (value) => value.endsWith(path.sep) ? value.substring(0, value.length - 1) : value;
602
668
  const getExtension = (value) => path.extname(value).toLowerCase().substring(1);
603
- const hasString = (item, value) => (0, types_1.isString)(value) && (item === value || Array.isArray(item) && item.includes(value));
669
+ const hasString = (item, value) => item === value || Array.isArray(item) && item.includes(value);
604
670
  const getCpuTimes = () => os.cpus().reduce((a, b) => a + b.times.user + b.times.sys, 0) * 1000;
605
671
  const autoMemoryCache = () => MEMORY_CACHE_DISK.enabled && MEMORY_CACHE_DISK.max_size > 0;
606
672
  const errorDirectory = (value) => (0, types_1.errorValue)("Path is not a directory", value);
607
- 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);
608
675
  class Module extends EventEmitter {
609
676
  constructor() {
610
677
  super(...arguments);
@@ -627,11 +694,12 @@ class Module extends EventEmitter {
627
694
  this[_f] = new AbortController();
628
695
  this[_g] = null;
629
696
  }
630
- static get VERSION() { return "0.8.6"; }
697
+ static get VERSION() { return "0.9.0"; }
631
698
  static get LOG_TYPE() { return types_1.LOG_TYPE; }
632
699
  static get STATUS_TYPE() { return types_1.STATUS_TYPE; }
633
700
  static get MAX_TIMEOUT() { return 2147483647; }
634
701
  static get TEMP_DIR() { return TEMP_DIR; }
702
+ static get LOG_FORMAT() { return (0, types_1.cloneObject)(SETTINGS.format, true); }
635
703
  static supported(major, minor = 0, patch = 0, lts) {
636
704
  if (VER_MAJOR < major) {
637
705
  return false;
@@ -979,8 +1047,8 @@ class Module extends EventEmitter {
979
1047
  }
980
1048
  }
981
1049
  if (!output) {
982
- const m = truncateStart(this.asString(message), options.messageWidth ?? format.message.width);
983
- 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 ? '}' : ')') : '');
984
1052
  }
985
1053
  if (broadcastId) {
986
1054
  if (BROADCAST_OUT) {
@@ -1066,13 +1134,11 @@ class Module extends EventEmitter {
1066
1134
  catch {
1067
1135
  }
1068
1136
  }
1069
- if (!result) {
1070
- try {
1071
- result = (0, types_1.asFunction)(fs.readFileSync(pathname, 'utf-8'), sync);
1072
- }
1073
- catch (err) {
1074
- this.writeFail(["Unable to read file", value], err, 32);
1075
- }
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);
1076
1142
  }
1077
1143
  }
1078
1144
  if (external && !pathname && VALUES["node.require.npm"] && /^(?:@[a-z\d-*~][a-z\d-*._~]*\/|node:)?[a-z\d-~][a-z\d-._~]*(?:\/.*)?$/.test(location)) {
@@ -1191,7 +1257,7 @@ class Module extends EventEmitter {
1191
1257
  }
1192
1258
  }
1193
1259
  catch (err) {
1194
- if (err instanceof Error && err.code === 'ENOENT') {
1260
+ if (this.isErrorCode(err, 'ENOENT')) {
1195
1261
  throw err;
1196
1262
  }
1197
1263
  }
@@ -1401,59 +1467,61 @@ class Module extends EventEmitter {
1401
1467
  }
1402
1468
  static createDir(value, overwrite) {
1403
1469
  const outDir = sanitizePath(value = asFile(value));
1404
- if (outDir) {
1405
- try {
1406
- const stat = fs.statSync(outDir);
1407
- if (stat.isDirectory()) {
1408
- return true;
1409
- }
1410
- if (overwrite && (stat.isFile() || stat.isSymbolicLink())) {
1411
- try {
1412
- fs.unlinkSync(outDir);
1413
- }
1414
- catch {
1415
- this.formatMessage(32, 'WARN', "Unable to overwrite file", value, { ...this.LOG_STYLE_WARN });
1416
- return false;
1417
- }
1418
- }
1419
- else {
1420
- return false;
1421
- }
1470
+ if (!outDir) {
1471
+ return false;
1472
+ }
1473
+ try {
1474
+ const stat = fs.statSync(outDir);
1475
+ if (stat.isDirectory()) {
1476
+ return true;
1422
1477
  }
1423
- catch (err) {
1424
- if (this.isErrorCode(err, 'EBUSY', 'EPERM')) {
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 });
1425
1484
  return false;
1426
1485
  }
1427
1486
  }
1428
- try {
1429
- return tryCreateDir(outDir);
1487
+ else {
1488
+ return false;
1430
1489
  }
1431
- catch (err) {
1432
- this.writeFail(["Unable to create directory", value], err, 32);
1490
+ }
1491
+ catch (err) {
1492
+ if (this.isErrorCode(err, 'EBUSY', 'EPERM')) {
1493
+ return false;
1433
1494
  }
1434
1495
  }
1496
+ try {
1497
+ return tryCreateDir(outDir);
1498
+ }
1499
+ catch (err) {
1500
+ this.writeFail(["Unable to create directory", value], err, 32);
1501
+ }
1435
1502
  return false;
1436
1503
  }
1437
1504
  static removeDir(value, empty = false, recursive = true) {
1438
1505
  const outDir = sanitizePath(value = asFile(value));
1439
- if (outDir) {
1440
- try {
1441
- if (typeof empty === 'number' && empty <= 0) {
1442
- empty = true;
1443
- }
1444
- if (this.isDir(outDir)) {
1445
- return tryRemoveDir(outDir, empty, !!recursive).length === 0;
1446
- }
1447
- if (!fs.existsSync(outDir)) {
1448
- if (empty && typeof empty !== 'number') {
1449
- this.createDir(outDir);
1450
- }
1451
- return true;
1452
- }
1506
+ if (!outDir) {
1507
+ return false;
1508
+ }
1509
+ try {
1510
+ if (typeof empty === 'number' && empty <= 0) {
1511
+ empty = true;
1453
1512
  }
1454
- catch (err) {
1455
- this.writeFail(["Unable to remove directory", value], err, 32);
1513
+ if (this.isDir(outDir)) {
1514
+ return tryRemoveDir(outDir, empty, !!recursive).length === 0;
1456
1515
  }
1516
+ if (!fs.existsSync(outDir)) {
1517
+ if (empty && typeof empty !== 'number') {
1518
+ this.createDir(outDir);
1519
+ }
1520
+ return true;
1521
+ }
1522
+ }
1523
+ catch (err) {
1524
+ this.writeFail(["Unable to remove directory", value], err, 32);
1457
1525
  }
1458
1526
  return false;
1459
1527
  }
@@ -1532,7 +1600,7 @@ class Module extends EventEmitter {
1532
1600
  .then(() => {
1533
1601
  success.push(destPath);
1534
1602
  })
1535
- .catch(err => {
1603
+ .catch((err) => {
1536
1604
  failed.push(srcPath);
1537
1605
  if (!silent) {
1538
1606
  this.writeFail([move ? "Unable to move file" : "Unable to copy file", path.basename(srcPath)], err, 32);
@@ -1613,7 +1681,7 @@ class Module extends EventEmitter {
1613
1681
  }
1614
1682
  return false;
1615
1683
  }
1616
- static async streamFile(src, cache, options) {
1684
+ static async streamFile(value, cache, options) {
1617
1685
  if ((0, types_1.isObject)(cache)) {
1618
1686
  options = cache;
1619
1687
  }
@@ -1621,28 +1689,32 @@ class Module extends EventEmitter {
1621
1689
  if (options) {
1622
1690
  ({ minStreamSize = 0, encoding, signal, cache } = options);
1623
1691
  }
1624
- return new Promise(async (resolve) => {
1625
- const fileSize = fs.statSync(src).size;
1626
- let data;
1627
- if (fileSize >= (0, types_1.alignSize)(minStreamSize) || fileSize >= 2097152000) {
1628
- const readable = fs.createReadStream(src, { signal });
1629
- const chunks = [];
1630
- for await (const chunk of readable) {
1631
- chunks.push(Buffer.from(chunk));
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
+ }
1707
+ }
1708
+ else {
1709
+ data = fs.readFileSync(src, encoding);
1632
1710
  }
1633
- data = Buffer.concat(chunks);
1634
- if (encoding) {
1635
- data = data.toString(encoding);
1711
+ if (cache || cache !== false && autoMemoryCache()) {
1712
+ addCacheItem(encoding ? CACHE_READTEXT : CACHE_READBUFFER, src, data, cache);
1636
1713
  }
1637
- }
1638
- else {
1639
- data = fs.readFileSync(src, encoding);
1640
- }
1641
- if (cache || cache !== false && autoMemoryCache()) {
1642
- addCacheItem(encoding ? CACHE_READTEXT : CACHE_READBUFFER, src, data, cache);
1643
- }
1644
- resolve(data);
1645
- });
1714
+ resolve(data);
1715
+ });
1716
+ }
1717
+ return Promise.resolve((encoding ? '' : null));
1646
1718
  }
1647
1719
  static readText(value, encoding, cache) {
1648
1720
  let minStreamSize, options;
@@ -1665,7 +1737,7 @@ class Module extends EventEmitter {
1665
1737
  return this.streamFile(src, options);
1666
1738
  }
1667
1739
  try {
1668
- result = fs.readFileSync(value, encoding);
1740
+ result = fs.readFileSync(src, encoding);
1669
1741
  if (result && (cache || cache !== false && autoMemoryCache())) {
1670
1742
  addCacheItem(CACHE_READTEXT, src, result, cache);
1671
1743
  }
@@ -1693,7 +1765,7 @@ class Module extends EventEmitter {
1693
1765
  return this.streamFile(src, options);
1694
1766
  }
1695
1767
  try {
1696
- result = fs.readFileSync(value);
1768
+ result = fs.readFileSync(src);
1697
1769
  if (result && (cache || cache !== false && autoMemoryCache())) {
1698
1770
  addCacheItem(CACHE_READBUFFER, src, result, cache);
1699
1771
  }
@@ -1811,8 +1883,11 @@ class Module extends EventEmitter {
1811
1883
  }
1812
1884
  return result;
1813
1885
  }
1814
- static getPackageVersion(value, unstable, startDir) {
1886
+ static getPackageVersion(value, unstable, startDir, baseDir) {
1815
1887
  if (typeof unstable === 'string') {
1888
+ if (typeof startDir === 'string') {
1889
+ baseDir = startDir;
1890
+ }
1816
1891
  startDir = unstable;
1817
1892
  unstable = false;
1818
1893
  }
@@ -1834,7 +1909,10 @@ class Module extends EventEmitter {
1834
1909
  folders.push(startDir);
1835
1910
  folders.reverse();
1836
1911
  }
1837
- for (const folder of folders) {
1912
+ for (let folder of folders) {
1913
+ if (baseDir) {
1914
+ folder = path.join(baseDir, folder.substring(PROCESS_CWD.length));
1915
+ }
1838
1916
  try {
1839
1917
  const pkg = path.join(folder, `node_modules/${value}/package.json`);
1840
1918
  if (fs.existsSync(pkg)) {
@@ -1887,18 +1965,18 @@ class Module extends EventEmitter {
1887
1965
  }
1888
1966
  return result[0];
1889
1967
  };
1890
- if (PNPM_VER) {
1891
- const result = [];
1892
- const pattern = new RegExp(`/${(0, types_1.escapePattern)(value)}/([^:]+):`, 'g');
1893
- let match;
1894
- while (match = pattern.exec(PNPM_VER)) {
1895
- result.push(match[1]);
1896
- }
1897
- if (result.length) {
1898
- return latest(result);
1968
+ if (setPnpmVer()) {
1969
+ if ((0, types_1.isObject)(PNPM_VER)) {
1970
+ if (startDir && !baseDir) {
1971
+ return this.getPackageVersion(value, unstable, startDir, PNPM_VER.baseDir || path.join(PROCESS_CWD, 'node_modules/.pnpm'));
1972
+ }
1973
+ const result = PNPM_VER.items.filter(item => item[0] === value).map(item => item[1]);
1974
+ if (result.length) {
1975
+ return latest(result);
1976
+ }
1899
1977
  }
1900
1978
  }
1901
- if (YARN_VER) {
1979
+ else if (setYarnVer() && (0, types_1.isObject)(YARN_VER)) {
1902
1980
  folders.forEach((folder, index) => {
1903
1981
  folder = ensureDir(folder).replace(path.sep + 'node_modules' + path.sep, path.sep + 'packages' + path.sep);
1904
1982
  folders[index] = PLATFORM_WIN32 ? folder.toLowerCase() : folder;
@@ -2073,6 +2151,8 @@ class Module extends EventEmitter {
2073
2151
  CACHE_CPUHOST = new WeakMap();
2074
2152
  (0, types_1.purgeMemory)();
2075
2153
  CACHE_TOTAL = 0;
2154
+ PNPM_VER = undefined;
2155
+ YARN_VER = undefined;
2076
2156
  }
2077
2157
  else if (percent > 0) {
2078
2158
  const stored = [];
@@ -2513,6 +2593,9 @@ class Module extends EventEmitter {
2513
2593
  ownPermissionOnly = true;
2514
2594
  }
2515
2595
  }
2596
+ if (!(uri = asFile(uri))) {
2597
+ return false;
2598
+ }
2516
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()))) {
2517
2600
  return true;
2518
2601
  }
@@ -2534,6 +2617,9 @@ class Module extends EventEmitter {
2534
2617
  ownPermissionOnly = true;
2535
2618
  }
2536
2619
  }
2620
+ if (!(uri = asFile(uri))) {
2621
+ return false;
2622
+ }
2537
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()))) {
2538
2624
  return true;
2539
2625
  }
@@ -2554,7 +2640,7 @@ class Module extends EventEmitter {
2554
2640
  }
2555
2641
  };
2556
2642
  let result;
2557
- if (requireExt && VALUES["node.require.ext"] && hasString(requireExt === true ? VALUES["node.require.ext"] : requireExt, getExtension(src))) {
2643
+ if (requireExt && VALUES["node.require.ext"] && hasString(requireExt === true ? VALUES["node.require.ext"] : requireExt, getExtension(outSrc))) {
2558
2644
  if (cache) {
2559
2645
  result = getCacheItem(CACHE_READCJS, outSrc);
2560
2646
  }
@@ -2572,8 +2658,7 @@ class Module extends EventEmitter {
2572
2658
  result || (result = (encoding ? getCacheItem(CACHE_READTEXT, outSrc) : getCacheItem(CACHE_READBUFFER, outSrc)));
2573
2659
  }
2574
2660
  try {
2575
- minStreamSize = (0, types_1.alignSize)(minStreamSize);
2576
- if (!isNaN(minStreamSize) || promises && fs.statSync(outSrc).size >= 2097152000) {
2661
+ if (!isNaN(minStreamSize = (0, types_1.alignSize)(minStreamSize)) || promises && fs.statSync(outSrc).size >= 2097152000) {
2577
2662
  if (result) {
2578
2663
  return Promise.resolve(result);
2579
2664
  }
@@ -2612,7 +2697,7 @@ class Module extends EventEmitter {
2612
2697
  if (!err) {
2613
2698
  setCache(data);
2614
2699
  }
2615
- callback(err, data);
2700
+ (callback)(err, data);
2616
2701
  });
2617
2702
  }
2618
2703
  return;
@@ -2624,7 +2709,7 @@ class Module extends EventEmitter {
2624
2709
  return result;
2625
2710
  }
2626
2711
  catch (err) {
2627
- this.writeFail(["Unable to read file", path.basename(src)], err, 32);
2712
+ this.writeFail(["Unable to read file", path.basename(asFile(src))], err, 32);
2628
2713
  }
2629
2714
  }
2630
2715
  else if (promises) {
@@ -2649,7 +2734,7 @@ class Module extends EventEmitter {
2649
2734
  if (!err) {
2650
2735
  this.emit('file:write', outSrc, options);
2651
2736
  }
2652
- callback(err);
2737
+ (callback)(err);
2653
2738
  });
2654
2739
  return;
2655
2740
  }
@@ -2659,7 +2744,7 @@ class Module extends EventEmitter {
2659
2744
  return true;
2660
2745
  }
2661
2746
  catch (err) {
2662
- this.writeFail(["Unable to write file", path.basename(src)], err, 32);
2747
+ this.writeFail(["Unable to write file", path.basename(outSrc)], err, 32);
2663
2748
  }
2664
2749
  }
2665
2750
  else if (promises) {
@@ -2686,7 +2771,7 @@ class Module extends EventEmitter {
2686
2771
  if (!err) {
2687
2772
  this.emit('file:delete', outSrc, options);
2688
2773
  }
2689
- callback(err);
2774
+ (callback)(err);
2690
2775
  });
2691
2776
  return;
2692
2777
  }
@@ -2695,7 +2780,7 @@ class Module extends EventEmitter {
2695
2780
  }
2696
2781
  catch (err) {
2697
2782
  if (!Module.isErrorCode(err, 'ENOENT')) {
2698
- this.writeFail(["Unable to delete file", path.basename(src)], err, 32);
2783
+ this.writeFail(["Unable to delete file", path.basename(outSrc)], err, 32);
2699
2784
  return false;
2700
2785
  }
2701
2786
  }
@@ -2741,7 +2826,7 @@ class Module extends EventEmitter {
2741
2826
  if (!err) {
2742
2827
  this.emit('file:copy', outDest, options);
2743
2828
  }
2744
- callback(err);
2829
+ (callback)(err);
2745
2830
  });
2746
2831
  return;
2747
2832
  }
@@ -2751,7 +2836,7 @@ class Module extends EventEmitter {
2751
2836
  return true;
2752
2837
  }
2753
2838
  catch (err) {
2754
- this.writeFail(["Unable to copy file", dest], err, 32);
2839
+ this.writeFail(["Unable to copy file", path.basename(outDest)], err, 32);
2755
2840
  }
2756
2841
  }
2757
2842
  }
@@ -2820,7 +2905,7 @@ class Module extends EventEmitter {
2820
2905
  if (!err) {
2821
2906
  this.emit('file:move', outDest, options);
2822
2907
  }
2823
- callback(err);
2908
+ (callback)(err);
2824
2909
  });
2825
2910
  return;
2826
2911
  }
@@ -2834,7 +2919,7 @@ class Module extends EventEmitter {
2834
2919
  this.emit('file:move', outDest, options);
2835
2920
  return true;
2836
2921
  }
2837
- this.writeFail(["Unable to move file", dest], err, 32);
2922
+ this.writeFail(["Unable to move file", path.basename(outDest)], err, 32);
2838
2923
  }
2839
2924
  }
2840
2925
  }
@@ -2891,7 +2976,7 @@ class Module extends EventEmitter {
2891
2976
  return success;
2892
2977
  });
2893
2978
  if (callback) {
2894
- result.catch(err => callback(err));
2979
+ result.catch((err) => callback(errorCheck(err, outSrc)));
2895
2980
  }
2896
2981
  return promises ? result : undefined;
2897
2982
  }
@@ -2902,7 +2987,7 @@ class Module extends EventEmitter {
2902
2987
  }
2903
2988
  }
2904
2989
  catch (err) {
2905
- this.writeFail(["Unable to create directory", src], err, 32);
2990
+ this.writeFail(["Unable to create directory", path.basename(outSrc)], err, 32);
2906
2991
  }
2907
2992
  }
2908
2993
  else if (promises) {
@@ -2940,7 +3025,7 @@ class Module extends EventEmitter {
2940
3025
  return success;
2941
3026
  });
2942
3027
  if (callback) {
2943
- result.catch(err => callback(err));
3028
+ result.catch((err) => callback(errorCheck(err, outSrc)));
2944
3029
  }
2945
3030
  return promises ? result : undefined;
2946
3031
  }
@@ -2972,7 +3057,7 @@ class Module extends EventEmitter {
2972
3057
  }
2973
3058
  }
2974
3059
  catch (err) {
2975
- this.writeFail(["Unable to remove directory", src], err, 32);
3060
+ this.writeFail(["Unable to remove directory", path.basename(outSrc)], err, 32);
2976
3061
  }
2977
3062
  }
2978
3063
  else if (promises) {
@@ -2998,7 +3083,7 @@ class Module extends EventEmitter {
2998
3083
  }
2999
3084
  return items;
3000
3085
  })
3001
- .catch(err => {
3086
+ .catch((err) => {
3002
3087
  this.writeFail(rejected, err, options);
3003
3088
  return [];
3004
3089
  });
@@ -3060,7 +3145,7 @@ class Module extends EventEmitter {
3060
3145
  }
3061
3146
  else {
3062
3147
  setCpuAndMem.call(this, options);
3063
- Module.formatMessage(...args);
3148
+ relayMessage.call(this, args);
3064
3149
  }
3065
3150
  if (!options.bypassLog) {
3066
3151
  this.addLog(types_1.STATUS_TYPE.INFO, title + ' -> ' + value, Date.now(), duration);
@@ -3097,7 +3182,7 @@ class Module extends EventEmitter {
3097
3182
  this._logQueued.push(args);
3098
3183
  }
3099
3184
  else {
3100
- Module.formatMessage(...args);
3185
+ relayMessage.call(this, args);
3101
3186
  }
3102
3187
  }
3103
3188
  formatFail(type, title, value, message, options = {}) {
@@ -3237,7 +3322,7 @@ class Module extends EventEmitter {
3237
3322
  this._logQueued.push(args);
3238
3323
  }
3239
3324
  else {
3240
- Module.formatMessage(...args);
3325
+ relayMessage.call(this, args);
3241
3326
  }
3242
3327
  }
3243
3328
  checkPackage(err, name, value, options) {
@@ -3249,7 +3334,7 @@ class Module extends EventEmitter {
3249
3334
  options = value;
3250
3335
  value = undefined;
3251
3336
  }
3252
- if (err instanceof Error && err.code === types_1.ERR_CODE.MODULE_NOT_FOUND && (0, types_1.isString)(name)) {
3337
+ if (err instanceof Error && err.code === types_1.ERR_CODE.MODULE_NOT_FOUND && name) {
3253
3338
  if (typeof options === 'number') {
3254
3339
  options = undefined;
3255
3340
  }
@@ -3544,16 +3629,24 @@ Module.LOG_STYLE_INFO = Object.freeze({ titleBgColor: 'bgBlue', titleColor: 'whi
3544
3629
  Module.LOG_STYLE_WARN = Object.freeze({ titleBgColor: 'bgBlack', titleColor: 'yellow', titleBold: true });
3545
3630
  Module.LOG_STYLE_NOTICE = Object.freeze({ titleBgColor: 'bgGrey', titleColor: 'white' });
3546
3631
  Module.LOG_STYLE_REVERSE = Object.freeze({ titleBgColor: 'bgWhite', titleColor: 'black', messageBgColor: 'bgGrey' });
3547
- if (!Module.supported(15, 4) && (!global.AbortController || !global.EventTarget)) {
3548
- ({ AbortController: global.AbortController } = require('abort-controller'));
3549
- ({ EventTarget: global.EventTarget } = require('event-target-shim'));
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
+ }
3550
3647
  }
3551
3648
  EventEmitter.defaultMaxListeners = Infinity;
3552
3649
  Object.freeze(types_1.LOG_TYPE);
3553
3650
  Object.freeze(types_1.STATUS_TYPE);
3554
- exports.default = Module;
3555
3651
 
3556
- if (exports.default) {
3557
- module.exports = exports.default;
3558
- module.exports.default = exports.default;
3559
- }
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.default.isPath(value)) ? getSize(value) : Buffer.byteLength(value, encoding && (0, types_1.getEncoding)(encoding));
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.default.isErrorCode(err, 'ENOENT')) {
75
- index_1.default.writeFail(["Unable to delete file", path.basename(uri)], err, 32);
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.default.isPath(value, isFile);
84
+ return index_1.isPath(value, isFile);
86
85
  }
87
86
  exports.existsSafe = existsSafe;
88
87
  function isFileHTTP(value) {
89
- return index_1.default.isFile(value, 'http/s');
88
+ return index_1.isFile(value, 'http/s');
90
89
  }
91
90
  exports.isFileHTTP = isFileHTTP;
92
91
  function isFileUNC(value) {
93
- return index_1.default.isFile(value, 'unc');
92
+ return index_1.isFile(value, 'unc');
94
93
  }
95
94
  exports.isFileUNC = isFileUNC;
96
95
  function isPathUNC(value) {
97
- return index_1.default.isPath(value, 'unc');
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.default.readBuffer(value, cache) : index_1.default.readText(value, encoding, cache);
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.default.parseFunction(value, options);
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.default.asString(value) || "Unknown");
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.default.writeFail(rejected, item.reason, options);
146
+ index_1.writeFail(rejected, item.reason, options);
148
147
  }
149
148
  }
150
149
  return items;
151
150
  })
152
- .catch(err => {
153
- index_1.default.writeFail(rejected, err, options);
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.8.6",
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,13 +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.8.6",
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",
26
+ "js-yaml": "^4.1.0",
28
27
  "mime-types": "^2.1.35",
29
- "picomatch": "^3.0.1",
28
+ "picomatch": "^4.0.2",
30
29
  "strip-ansi": "6.0.1"
31
30
  }
32
31
  }