@e-mc/module 0.9.12 → 0.9.14

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 +6 -6
  2. package/index.js +27 -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.12/lib/index.d.ts)
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.9.14/lib/index.d.ts)
13
13
 
14
14
  ```typescript
15
15
  import type { LogStatus } from "./squared";
@@ -394,11 +394,11 @@ type ForegroundColor = typeof IForegroundColor | `#${string}`;
394
394
 
395
395
  ## References
396
396
 
397
- - https://www.unpkg.com/@e-mc/types@0.9.12/lib/core.d.ts
398
- - https://www.unpkg.com/@e-mc/types@0.9.12/lib/logger.d.ts
399
- - https://www.unpkg.com/@e-mc/types@0.9.12/lib/module.d.ts
400
- - https://www.unpkg.com/@e-mc/types@0.9.12/lib/node.d.ts
401
- - https://www.unpkg.com/@e-mc/types@0.9.12/lib/settings.d.ts
397
+ - https://www.unpkg.com/@e-mc/types@0.9.14/lib/core.d.ts
398
+ - https://www.unpkg.com/@e-mc/types@0.9.14/lib/logger.d.ts
399
+ - https://www.unpkg.com/@e-mc/types@0.9.14/lib/module.d.ts
400
+ - https://www.unpkg.com/@e-mc/types@0.9.14/lib/node.d.ts
401
+ - https://www.unpkg.com/@e-mc/types@0.9.14/lib/settings.d.ts
402
402
 
403
403
  * https://www.npmjs.com/package/@types/node
404
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"]: '',
@@ -549,7 +548,7 @@ function addCacheItem(map, key, data, cache) {
549
548
  map.set(key, [Date.now(), data]);
550
549
  }
551
550
  }
552
- function listDir(src, paths, depth, include, exclude, outFiles) {
551
+ function listDir(src, paths, depth, include, exclude, excludeDir, outFiles) {
553
552
  const srcDir = path.join(src, ...paths);
554
553
  fs.readdirSync(srcDir, { withFileTypes: true }).forEach(file => {
555
554
  if (file.isFile()) {
@@ -559,7 +558,10 @@ function listDir(src, paths, depth, include, exclude, outFiles) {
559
558
  }
560
559
  }
561
560
  else if (depth > 0 && file.isDirectory()) {
562
- listDir(src, paths.concat(file.name), depth - 1, include, exclude, outFiles);
561
+ const subDirs = paths.concat(file.name);
562
+ if (!excludeDir?.includes(subDirs.join('/') + '/')) {
563
+ listDir(src, subDirs, depth - 1, include, exclude, excludeDir, outFiles);
564
+ }
563
565
  }
564
566
  });
565
567
  }
@@ -735,7 +737,7 @@ class Module extends EventEmitter {
735
737
  this[_f] = new AbortController();
736
738
  this[_g] = null;
737
739
  }
738
- static get VERSION() { return "0.9.12"; }
740
+ static get VERSION() { return "0.9.14"; }
739
741
  static get LOG_TYPE() { return types_1.LOG_TYPE; }
740
742
  static get STATUS_TYPE() { return types_1.STATUS_TYPE; }
741
743
  static get MAX_TIMEOUT() { return 2147483647; }
@@ -778,7 +780,6 @@ class Module extends EventEmitter {
778
780
  case "error.fatal":
779
781
  return VALUES[key];
780
782
  case "node.require.ext":
781
- case "node.settings.package_manager":
782
783
  case "process.password":
783
784
  case "process.cipher.algorithm":
784
785
  return VALUES[key] !== '';
@@ -1707,7 +1708,13 @@ class Module extends EventEmitter {
1707
1708
  return Promise.reject(errorDirectory(asFile(src) || "Unknown"));
1708
1709
  }
1709
1710
  const pmOpts = { posixSlashes: true, windows: true, nocase: PLATFORM_WIN32 };
1710
- let exclude, recursive;
1711
+ const prependSrc = (value) => {
1712
+ if (pmOpts.matchBase) {
1713
+ return value;
1714
+ }
1715
+ return (Array.isArray(value) ? value : [value]).map(item => path.join(outDir, item));
1716
+ };
1717
+ let exclude, excludeDir, recursive;
1711
1718
  if ((0, types_1.isObject)(options)) {
1712
1719
  if (options.matchBase) {
1713
1720
  pmOpts.matchBase = true;
@@ -1719,13 +1726,25 @@ class Module extends EventEmitter {
1719
1726
  pmOpts.dot = true;
1720
1727
  }
1721
1728
  ({ exclude, recursive } = options);
1729
+ if (exclude) {
1730
+ const items = Array.isArray(exclude) ? exclude : [exclude];
1731
+ exclude = [];
1732
+ for (const value of items) {
1733
+ if (/^[^\\/][^*]+[\\/]$/.test(value) && !(0, types_1.hasGlob)(value)) {
1734
+ (excludeDir ||= []).push(this.normalizePath(value, 4));
1735
+ }
1736
+ else {
1737
+ exclude.push(value);
1738
+ }
1739
+ }
1740
+ }
1722
1741
  }
1723
1742
  else {
1724
1743
  recursive = options;
1725
1744
  }
1726
1745
  recursive ??= true;
1727
1746
  const result = [];
1728
- listDir(outDir, [], !recursive ? 0 : typeof recursive === 'number' ? recursive : Infinity, pm(pattern, pmOpts), exclude ? pm(exclude, pmOpts) : undefined, result);
1747
+ listDir(outDir, [], !recursive ? 0 : typeof recursive === 'number' ? recursive : Infinity, pm(prependSrc(pattern), pmOpts), exclude?.length ? pm(prependSrc(exclude), pmOpts) : undefined, excludeDir, result);
1729
1748
  return result;
1730
1749
  }
1731
1750
  static renameFile(src, dest, throws = true) {
@@ -2320,17 +2339,6 @@ class Module extends EventEmitter {
2320
2339
  VALUES["node.require.inline"] = inline;
2321
2340
  }
2322
2341
  }
2323
- const manager = node.settings?.package_manager;
2324
- switch (manager) {
2325
- case 'npm':
2326
- case 'yarn':
2327
- case 'pnpm':
2328
- VALUES["node.settings.package_manager"] = manager;
2329
- break;
2330
- default:
2331
- VALUES["node.settings.package_manager"] = '';
2332
- break;
2333
- }
2334
2342
  }
2335
2343
  if ((0, types_1.isPlainObject)(settings.process)) {
2336
2344
  const { env, cipher, password: pwd } = settings.process;
@@ -3423,7 +3431,7 @@ class Module extends EventEmitter {
3423
3431
  if (typeof options === 'number') {
3424
3432
  options = undefined;
3425
3433
  }
3426
- 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] } });
3434
+ 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] } });
3427
3435
  return true;
3428
3436
  }
3429
3437
  if (value) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/module",
3
- "version": "0.9.12",
3
+ "version": "0.9.14",
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.12",
23
+ "@e-mc/types": "0.9.14",
24
24
  "chalk": "4.1.2",
25
25
  "file-type": "16.5.4",
26
26
  "js-yaml": "^4.1.0",