@e-mc/module 0.9.11 → 0.9.13

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.
Files changed (3) hide show
  1. package/README.md +9 -7
  2. package/index.js +47 -19
  3. package/package.json +3 -3
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.9.11/lib/index.d.ts)
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.9.13/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, GetTempDirOptions, MoveFileOptions, NormalizeFlags, ParseFunctionOptions, PermissionOptions, ProtocolType, ReadBufferOptions, ReadFileCallback, ReadFileOptions, ReadHashOptions, ReadTextOptions, RemoveDirOptions, WriteFileOptions } from "./module";
20
+ import type { AsHashOptions, CheckSemVerOptions, CopyDirOptions, CopyDirResult, CopyFileOptions, CreateDirOptions, DeleteFileOptions, GetTempDirOptions, GlobDirOptions, MoveFileOptions, NormalizeFlags, ParseFunctionOptions, PermissionOptions, ProtocolType, ReadBufferOptions, ReadFileCallback, ReadFileOptions, ReadHashOptions, ReadTextOptions, RemoveDirOptions, WriteFileOptions } from "./module";
21
21
  import type { Settings } from "./node";
22
22
  import type { LoggerFormatSettings } from "/settings";
23
23
 
@@ -200,6 +200,8 @@ interface ModuleConstructor {
200
200
  removeDir(value: string | URL, empty?: boolean, recursive?: boolean): boolean;
201
201
  copyDir(src: string | URL, dest: string | URL, move?: boolean, recursive?: boolean): Promise<CopyDirResult>;
202
202
  copyDir(src: string | URL, dest: string | URL, options?: CopyDirOptions): Promise<CopyDirResult>;
203
+ globDir(src: string | URL, pattern: string | string[], recursive: boolean | number): Promise<string[]>;
204
+ globDir(src: string | URL, pattern: string | string[], options?: GlobDirOptions): Promise<string[]>;
203
205
  renameFile(src: string | URL, dest: string | URL, throws?: boolean): boolean;
204
206
  streamFile(src: string, cache: boolean): Promise<Buffer | string>;
205
207
  streamFile(src: string, options: ReadBufferOptions): Promise<Buffer | string>;
@@ -392,11 +394,11 @@ type ForegroundColor = typeof IForegroundColor | `#${string}`;
392
394
 
393
395
  ## References
394
396
 
395
- - https://www.unpkg.com/@e-mc/types@0.9.11/lib/core.d.ts
396
- - https://www.unpkg.com/@e-mc/types@0.9.11/lib/logger.d.ts
397
- - https://www.unpkg.com/@e-mc/types@0.9.11/lib/module.d.ts
398
- - https://www.unpkg.com/@e-mc/types@0.9.11/lib/node.d.ts
399
- - https://www.unpkg.com/@e-mc/types@0.9.11/lib/settings.d.ts
397
+ - https://www.unpkg.com/@e-mc/types@0.9.13/lib/core.d.ts
398
+ - https://www.unpkg.com/@e-mc/types@0.9.13/lib/logger.d.ts
399
+ - https://www.unpkg.com/@e-mc/types@0.9.13/lib/module.d.ts
400
+ - https://www.unpkg.com/@e-mc/types@0.9.13/lib/node.d.ts
401
+ - https://www.unpkg.com/@e-mc/types@0.9.13/lib/settings.d.ts
400
402
 
401
403
  * https://www.npmjs.com/package/@types/node
402
404
 
package/index.js CHANGED
@@ -106,7 +106,6 @@ const VALUES = {
106
106
  ["node.process.cpu_usage"]: true,
107
107
  ["node.process.memory_usage"]: true,
108
108
  ["node.process.inline"]: true,
109
- ["node.settings.package_manager"]: '',
110
109
  ["temp.dir"]: "tmp",
111
110
  ["temp.write"]: false,
112
111
  ["process.password"]: '',
@@ -172,12 +171,12 @@ function setPnpmVer() {
172
171
  return false;
173
172
  }
174
173
  const addPackage = (value) => {
175
- let index = value.indexOf('(');
174
+ let index = (value = value.replace(/^\//, '')).indexOf('(');
176
175
  if (index !== -1) {
177
176
  value = value.substring(0, index);
178
177
  }
179
- index = value.lastIndexOf(value.indexOf('@', 2) !== -1 ? '@' : '/');
180
- const name = value.substring(0, index).replace(/^\//, '');
178
+ index = value.lastIndexOf(value.indexOf('@', 1) !== -1 ? '@' : '/');
179
+ const name = value.substring(0, index);
181
180
  const version = value.substring(index + 1);
182
181
  if (!items.find(item => item[0] === name && item[1] === version)) {
183
182
  items.push([name, version]);
@@ -549,6 +548,20 @@ function addCacheItem(map, key, data, cache) {
549
548
  map.set(key, [Date.now(), data]);
550
549
  }
551
550
  }
551
+ function listDir(src, paths, depth, include, exclude, outFiles) {
552
+ const srcDir = path.join(src, ...paths);
553
+ fs.readdirSync(srcDir, { withFileTypes: true }).forEach(file => {
554
+ if (file.isFile()) {
555
+ const pathname = path.join(srcDir, file.name);
556
+ if (include(pathname) && !exclude?.(pathname)) {
557
+ outFiles.push(pathname);
558
+ }
559
+ }
560
+ else if (depth > 0 && file.isDirectory()) {
561
+ listDir(src, paths.concat(file.name), depth - 1, include, exclude, outFiles);
562
+ }
563
+ });
564
+ }
552
565
  function checkFunction(value) {
553
566
  if (typeof value === 'function') {
554
567
  Object.defineProperty(value, "__cjs__", { value: true, writable: false, enumerable: false });
@@ -721,7 +734,7 @@ class Module extends EventEmitter {
721
734
  this[_f] = new AbortController();
722
735
  this[_g] = null;
723
736
  }
724
- static get VERSION() { return "0.9.11"; }
737
+ static get VERSION() { return "0.9.13"; }
725
738
  static get LOG_TYPE() { return types_1.LOG_TYPE; }
726
739
  static get STATUS_TYPE() { return types_1.STATUS_TYPE; }
727
740
  static get MAX_TIMEOUT() { return 2147483647; }
@@ -764,7 +777,6 @@ class Module extends EventEmitter {
764
777
  case "error.fatal":
765
778
  return VALUES[key];
766
779
  case "node.require.ext":
767
- case "node.settings.package_manager":
768
780
  case "process.password":
769
781
  case "process.cipher.algorithm":
770
782
  return VALUES[key] !== '';
@@ -1687,6 +1699,33 @@ class Module extends EventEmitter {
1687
1699
  });
1688
1700
  });
1689
1701
  }
1702
+ static async globDir(src, pattern, options) {
1703
+ const outDir = sanitizePath(asFile(src));
1704
+ if (!(outDir && this.isDir(outDir))) {
1705
+ return Promise.reject(errorDirectory(asFile(src) || "Unknown"));
1706
+ }
1707
+ const pmOpts = { posixSlashes: true, windows: true, nocase: PLATFORM_WIN32 };
1708
+ let exclude, recursive;
1709
+ if ((0, types_1.isObject)(options)) {
1710
+ if (options.matchBase) {
1711
+ pmOpts.matchBase = true;
1712
+ }
1713
+ if (options.contains) {
1714
+ pmOpts.contains = true;
1715
+ }
1716
+ if (options.dot) {
1717
+ pmOpts.dot = true;
1718
+ }
1719
+ ({ exclude, recursive } = options);
1720
+ }
1721
+ else {
1722
+ recursive = options;
1723
+ }
1724
+ recursive ??= true;
1725
+ const result = [];
1726
+ listDir(outDir, [], !recursive ? 0 : typeof recursive === 'number' ? recursive : Infinity, pm(pattern, pmOpts), exclude ? pm(exclude, pmOpts) : undefined, result);
1727
+ return result;
1728
+ }
1690
1729
  static renameFile(src, dest, throws = true) {
1691
1730
  try {
1692
1731
  fs.renameSync(src, dest);
@@ -2074,7 +2113,7 @@ class Module extends EventEmitter {
2074
2113
  maxVersion = [Infinity];
2075
2114
  }
2076
2115
  else {
2077
- maxVersion = [max - 1];
2116
+ maxVersion = [(max | 0) - 1];
2078
2117
  maxRange = true;
2079
2118
  }
2080
2119
  let version = this.getPackageVersion(name, unstable, startDir);
@@ -2279,17 +2318,6 @@ class Module extends EventEmitter {
2279
2318
  VALUES["node.require.inline"] = inline;
2280
2319
  }
2281
2320
  }
2282
- const manager = node.settings?.package_manager;
2283
- switch (manager) {
2284
- case 'npm':
2285
- case 'yarn':
2286
- case 'pnpm':
2287
- VALUES["node.settings.package_manager"] = manager;
2288
- break;
2289
- default:
2290
- VALUES["node.settings.package_manager"] = '';
2291
- break;
2292
- }
2293
2321
  }
2294
2322
  if ((0, types_1.isPlainObject)(settings.process)) {
2295
2323
  const { env, cipher, password: pwd } = settings.process;
@@ -3382,7 +3410,7 @@ class Module extends EventEmitter {
3382
3410
  if (typeof options === 'number') {
3383
3411
  options = undefined;
3384
3412
  }
3385
- this.writeFail("Unknown", err, { ...options, type: types_1.LOG_TYPE.SYSTEM, code: types_1.ERR_CODE.MODULE_NOT_FOUND, exec: { command: VALUES["node.settings.package_manager"] || (setPnpmVer() ? 'pnpm' : setYarnVer() ? 'yarn' : 'npm'), args: ['install', name] } });
3413
+ this.writeFail("Unknown", err, { ...options, type: types_1.LOG_TYPE.SYSTEM, code: types_1.ERR_CODE.MODULE_NOT_FOUND, exec: { command: 'npm', args: ['i', name] } });
3386
3414
  return true;
3387
3415
  }
3388
3416
  if (value) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/module",
3
- "version": "0.9.11",
3
+ "version": "0.9.13",
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.9.11",
23
+ "@e-mc/types": "0.9.13",
24
24
  "chalk": "4.1.2",
25
25
  "file-type": "16.5.4",
26
26
  "js-yaml": "^4.1.0",