@e-mc/module 0.10.2 → 0.10.3

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/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  ## Interface
11
11
 
12
- * [View Source](https://www.unpkg.com/@e-mc/types@0.10.2/lib/index.d.ts)
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.10.3/lib/index.d.ts)
13
13
 
14
14
  ```typescript
15
15
  import type { LogStatus } from "./squared";
@@ -17,7 +17,7 @@ import type { LogStatus } from "./squared";
17
17
  import type { IHost } from "./index";
18
18
  import type { IAbortComponent, IPermission } from "./core";
19
19
  import type { LOG_TYPE, STATUS_TYPE, ExecCommand, LogArguments, LogComponent, LogDate, LogFailOptions, LogMessageOptions, LogOptions, LogProcessOptions, LogTime, LogType, LogValue, LoggerFormat, StatusType } from "./logger";
20
- import type { AsHashOptions, CheckSemVerOptions, CopyDirOptions, CopyDirResult, CopyFileOptions, CreateDirOptions, DeleteFileOptions, MoveFileOptions, ParseFunctionOptions, PermissionOptions, ProtocolType, ReadBufferOptions, ReadFileCallback, ReadFileOptions, ReadHashOptions, ReadTextOptions, RemoveDirOptions, TempDirOptions, WriteFileOptions } from "./module";
20
+ import type { AsHashOptions, CheckSemVerOptions, CopyDirOptions, CopyDirResult, CopyFileOptions, CreateDirOptions, DeleteFileOptions, GlobDirOptions, MoveFileOptions, ParseFunctionOptions, PermissionOptions, ProtocolType, ReadBufferOptions, ReadFileCallback, ReadFileOptions, ReadHashOptions, ReadTextOptions, RemoveDirOptions, TempDirOptions, WriteFileOptions } from "./module";
21
21
  import type { Settings } from "./node";
22
22
  import type { LoggerFormatSettings } from "/settings";
23
23
 
@@ -205,6 +205,8 @@ interface ModuleConstructor {
205
205
  removeDir(value: string | URL, empty?: boolean, recursive?: boolean): boolean;
206
206
  copyDir(src: string | URL, dest: string | URL, move?: boolean, recursive?: boolean): Promise<CopyDirResult>;
207
207
  copyDir(src: string | URL, dest: string | URL, options?: CopyDirOptions): Promise<CopyDirResult>;
208
+ globDir(src: string | URL, pattern: string | string[], recursive: boolean | number): Promise<string[]>;
209
+ globDir(src: string | URL, pattern: string | string[], options?: GlobDirOptions): Promise<string[]>;
208
210
  renameFile(src: string | URL, dest: string | URL, throws?: boolean): boolean;
209
211
  streamFile(src: string, cache: boolean): Promise<Buffer | string>;
210
212
  streamFile(src: string, options: ReadBufferOptions): Promise<Buffer | string>;
@@ -261,6 +263,9 @@ interface NodeModule {
261
263
  npm?: boolean;
262
264
  inline?: boolean;
263
265
  };
266
+ settings?: {
267
+ package_manager?: "npm" | "yarn" | "pnpm";
268
+ };
264
269
  }
265
270
 
266
271
  interface ProcessModule {
@@ -402,11 +407,11 @@ interface LoggerModule {
402
407
 
403
408
  ## References
404
409
 
405
- - https://www.unpkg.com/@e-mc/types@0.10.2/lib/core.d.ts
406
- - https://www.unpkg.com/@e-mc/types@0.10.2/lib/logger.d.ts
407
- - https://www.unpkg.com/@e-mc/types@0.10.2/lib/module.d.ts
408
- - https://www.unpkg.com/@e-mc/types@0.10.2/lib/node.d.ts
409
- - https://www.unpkg.com/@e-mc/types@0.10.2/lib/settings.d.ts
410
+ - https://www.unpkg.com/@e-mc/types@0.10.3/lib/core.d.ts
411
+ - https://www.unpkg.com/@e-mc/types@0.10.3/lib/logger.d.ts
412
+ - https://www.unpkg.com/@e-mc/types@0.10.3/lib/module.d.ts
413
+ - https://www.unpkg.com/@e-mc/types@0.10.3/lib/node.d.ts
414
+ - https://www.unpkg.com/@e-mc/types@0.10.3/lib/settings.d.ts
410
415
 
411
416
  * https://www.npmjs.com/package/@types/node
412
417
 
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
@@ -141,7 +141,7 @@ const MEMORY_CACHE_DISK = {
141
141
  const SUPPORTED_CANPARSE = (0, types_1.supported)(19, 9) || (0, types_1.supported)(18, 17, 0, true);
142
142
  const REGEXP_TORRENT = /^(?:magnet:\?xt=|(?:https?|s?ftp):\/\/[^/][^\n]*?\.(?:torrent|metalink|meta4)(?:\?[^\n]*)?$)/i;
143
143
  const REGEXP_PROTOCOL = /^([a-z][a-z\d+-.]*):\/\/[^@:[\]\\^<>|\s]/i;
144
- const REGEXP_CLIESCAPE = /[^\w%+-./:=@]/g;
144
+ const REGEXP_CLIESCAPE = /[^\w+-.,/:@]/g;
145
145
  const REGEXP_CLIOPTION = /^(-[^\s=]+|--[^-\s=][^\s=]*)(=)?\s*(.*)$/;
146
146
  const REGEXP_ANSIESCAPE = /[\u001B\u009B]/;
147
147
  const LOG_CPUBARCOLOR = SETTINGS.process.cpu_bar_color;
@@ -214,12 +214,12 @@ function setPnpmVer() {
214
214
  return PNPM_VER;
215
215
  }
216
216
  function addPnpmPackage(items, value) {
217
- let index = value.indexOf('(');
217
+ let index = (value = value.replace(/^\//, '')).indexOf('(');
218
218
  if (index !== -1) {
219
219
  value = value.substring(0, index);
220
220
  }
221
- index = value.lastIndexOf(value.indexOf('@', 2) !== -1 ? '@' : '/');
222
- const name = value.substring(1, index);
221
+ index = value.lastIndexOf(value.indexOf('@', 1) !== -1 ? '@' : '/');
222
+ const name = value.substring(0, index);
223
223
  const version = value.substring(index + 1);
224
224
  if (!items.find(item => item[0] === name && item[1] === version)) {
225
225
  items.push([name, version]);
@@ -629,6 +629,20 @@ function getCacheTotal() {
629
629
  function isMatch(key, value) {
630
630
  return pm.isMatch(key, value, { nocase: PLATFORM_WIN32, matchBase: value.startsWith('*') });
631
631
  }
632
+ function listDir(src, paths, depth, include, exclude, outFiles) {
633
+ const srcDir = path.join(src, ...paths);
634
+ fs.readdirSync(srcDir, { withFileTypes: true }).forEach(file => {
635
+ if (file.isFile()) {
636
+ const pathname = path.join(srcDir, file.name);
637
+ if (include(pathname) && !exclude?.(pathname)) {
638
+ outFiles.push(pathname);
639
+ }
640
+ }
641
+ else if (depth > 0 && file.isDirectory()) {
642
+ listDir(src, paths.concat(file.name), depth - 1, include, exclude, outFiles);
643
+ }
644
+ });
645
+ }
632
646
  function checkFunction(value) {
633
647
  if (typeof value === 'function') {
634
648
  Object.defineProperty(value, "__cjs__", { value: true, writable: false, enumerable: false });
@@ -899,7 +913,7 @@ function truncateStart(value, length = LOG_MIN_WIDTH, style = false) {
899
913
  function truncateEnd(value, length) {
900
914
  return (REGEXP_ANSIESCAPE.test(value) ? stripansi(value) : value).length > length ? '...' + value.substring(value.length - length + 3) : value;
901
915
  }
902
- const escapeArg = (value) => value.replace(REGEXP_CLIESCAPE, capture => (capture === '$' || capture === '`' ? '\\' : '') + '\\' + capture);
916
+ const escapeArg = (value) => value.replace(REGEXP_CLIESCAPE, capture => capture === '\n' ? "'\n'" : (capture === '$' || capture === '`' ? '\\' : '') + '\\' + capture);
903
917
  const isMeterUnit = (type, ident) => (type & 256) === 256 && !ident;
904
918
  const formatLogMessage = (type, message, unit, ident) => isMeterUnit(type, ident) ? (unit + LOG_DIVIDER + message).trimEnd() : unit ? (message + (ident ? '' : ' ') + unit).trimStart() : message;
905
919
  const hideAbort = (err) => err.name === 'AbortError' && SETTINGS.abort === false;
@@ -943,7 +957,7 @@ class Module extends EventEmitter {
943
957
  this[_g] = null;
944
958
  }
945
959
  static get VERSION() {
946
- return "0.10.2";
960
+ return "0.10.3";
947
961
  }
948
962
  static get LOG_TYPE() {
949
963
  return types_1.LOG_TYPE;
@@ -1904,6 +1918,33 @@ class Module extends EventEmitter {
1904
1918
  });
1905
1919
  });
1906
1920
  }
1921
+ static async globDir(src, pattern, options) {
1922
+ const outDir = sanitizePath(asFile(src));
1923
+ if (!(outDir && this.isDir(outDir))) {
1924
+ return Promise.reject(errorDirectory(asFile(src) || "Unknown"));
1925
+ }
1926
+ const pmOpts = { posixSlashes: true, windows: true, nocase: PLATFORM_WIN32 };
1927
+ let exclude, recursive;
1928
+ if ((0, types_1.isObject)(options)) {
1929
+ if (options.matchBase) {
1930
+ pmOpts.matchBase = true;
1931
+ }
1932
+ if (options.contains) {
1933
+ pmOpts.contains = true;
1934
+ }
1935
+ if (options.dot) {
1936
+ pmOpts.dot = true;
1937
+ }
1938
+ ({ exclude, recursive } = options);
1939
+ }
1940
+ else {
1941
+ recursive = options;
1942
+ }
1943
+ recursive ??= true;
1944
+ const result = [];
1945
+ listDir(outDir, [], !recursive ? 0 : typeof recursive === 'number' ? recursive : Infinity, pm(pattern, pmOpts), exclude ? pm(exclude, pmOpts) : undefined, result);
1946
+ return result;
1947
+ }
1907
1948
  static renameFile(src, dest, throws = true) {
1908
1949
  try {
1909
1950
  fs.renameSync(src, dest);
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/module",
3
- "version": "0.10.2",
3
+ "version": "0.10.3",
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": "BSD 3-Clause",
20
+ "license": "BSD-3-Clause",
21
21
  "homepage": "https://github.com/anpham6/e-mc#readme",
22
22
  "dependencies": {
23
- "@e-mc/types": "0.10.2",
23
+ "@e-mc/types": "0.10.3",
24
24
  "chalk": "4.1.2",
25
25
  "file-type": "^18.7.0",
26
26
  "js-yaml": "^4.1.0",