@e-mc/module 0.10.2 → 0.10.4

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.4/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.4/lib/core.d.ts
411
+ - https://www.unpkg.com/@e-mc/types@0.10.4/lib/logger.d.ts
412
+ - https://www.unpkg.com/@e-mc/types@0.10.4/lib/module.d.ts
413
+ - https://www.unpkg.com/@e-mc/types@0.10.4/lib/node.d.ts
414
+ - https://www.unpkg.com/@e-mc/types@0.10.4/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,23 @@ 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, excludeDir, 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
+ const subDirs = paths.concat(file.name);
643
+ if (!excludeDir?.includes(subDirs.join('/') + '/')) {
644
+ listDir(src, subDirs, depth - 1, include, exclude, excludeDir, outFiles);
645
+ }
646
+ }
647
+ });
648
+ }
632
649
  function checkFunction(value) {
633
650
  if (typeof value === 'function') {
634
651
  Object.defineProperty(value, "__cjs__", { value: true, writable: false, enumerable: false });
@@ -899,7 +916,7 @@ function truncateStart(value, length = LOG_MIN_WIDTH, style = false) {
899
916
  function truncateEnd(value, length) {
900
917
  return (REGEXP_ANSIESCAPE.test(value) ? stripansi(value) : value).length > length ? '...' + value.substring(value.length - length + 3) : value;
901
918
  }
902
- const escapeArg = (value) => value.replace(REGEXP_CLIESCAPE, capture => (capture === '$' || capture === '`' ? '\\' : '') + '\\' + capture);
919
+ const escapeArg = (value) => value.replace(REGEXP_CLIESCAPE, capture => capture === '\n' ? "'\n'" : (capture === '$' || capture === '`' ? '\\' : '') + '\\' + capture);
903
920
  const isMeterUnit = (type, ident) => (type & 256) === 256 && !ident;
904
921
  const formatLogMessage = (type, message, unit, ident) => isMeterUnit(type, ident) ? (unit + LOG_DIVIDER + message).trimEnd() : unit ? (message + (ident ? '' : ' ') + unit).trimStart() : message;
905
922
  const hideAbort = (err) => err.name === 'AbortError' && SETTINGS.abort === false;
@@ -943,7 +960,7 @@ class Module extends EventEmitter {
943
960
  this[_g] = null;
944
961
  }
945
962
  static get VERSION() {
946
- return "0.10.2";
963
+ return "0.10.4";
947
964
  }
948
965
  static get LOG_TYPE() {
949
966
  return types_1.LOG_TYPE;
@@ -1904,6 +1921,51 @@ class Module extends EventEmitter {
1904
1921
  });
1905
1922
  });
1906
1923
  }
1924
+ static async globDir(src, pattern, options) {
1925
+ const outDir = sanitizePath(asFile(src));
1926
+ if (!(outDir && this.isDir(outDir))) {
1927
+ return Promise.reject(errorDirectory(asFile(src) || "Unknown"));
1928
+ }
1929
+ const pmOpts = { posixSlashes: true, windows: true, nocase: PLATFORM_WIN32 };
1930
+ const prependSrc = (value) => {
1931
+ if (pmOpts.matchBase) {
1932
+ return value;
1933
+ }
1934
+ return (Array.isArray(value) ? value : [value]).map(item => path.join(outDir, item));
1935
+ };
1936
+ let exclude, excludeDir, recursive;
1937
+ if ((0, types_1.isObject)(options)) {
1938
+ if (options.matchBase) {
1939
+ pmOpts.matchBase = true;
1940
+ }
1941
+ if (options.contains) {
1942
+ pmOpts.contains = true;
1943
+ }
1944
+ if (options.dot) {
1945
+ pmOpts.dot = true;
1946
+ }
1947
+ ({ exclude, recursive } = options);
1948
+ if (exclude) {
1949
+ const items = Array.isArray(exclude) ? exclude : [exclude];
1950
+ exclude = [];
1951
+ for (const value of items) {
1952
+ if (/^[^\\/][^*]+[\\/]$/.test(value) && !(0, types_1.hasGlob)(value)) {
1953
+ (excludeDir ||= []).push(this.normalizePath(value, 4));
1954
+ }
1955
+ else {
1956
+ exclude.push(value);
1957
+ }
1958
+ }
1959
+ }
1960
+ }
1961
+ else {
1962
+ recursive = options;
1963
+ }
1964
+ recursive ??= true;
1965
+ const result = [];
1966
+ listDir(outDir, [], !recursive ? 0 : typeof recursive === 'number' ? recursive : Infinity, pm(prependSrc(pattern), pmOpts), exclude?.length ? pm(prependSrc(exclude), pmOpts) : undefined, excludeDir, result);
1967
+ return result;
1968
+ }
1907
1969
  static renameFile(src, dest, throws = true) {
1908
1970
  try {
1909
1971
  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.4",
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.4",
24
24
  "chalk": "4.1.2",
25
25
  "file-type": "^18.7.0",
26
26
  "js-yaml": "^4.1.0",