@e-mc/module 0.9.13 → 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 +26 -5
  3. package/package.json +2 -2
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.13/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.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
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
@@ -548,7 +548,7 @@ function addCacheItem(map, key, data, cache) {
548
548
  map.set(key, [Date.now(), data]);
549
549
  }
550
550
  }
551
- function listDir(src, paths, depth, include, exclude, outFiles) {
551
+ function listDir(src, paths, depth, include, exclude, excludeDir, outFiles) {
552
552
  const srcDir = path.join(src, ...paths);
553
553
  fs.readdirSync(srcDir, { withFileTypes: true }).forEach(file => {
554
554
  if (file.isFile()) {
@@ -558,7 +558,10 @@ function listDir(src, paths, depth, include, exclude, outFiles) {
558
558
  }
559
559
  }
560
560
  else if (depth > 0 && file.isDirectory()) {
561
- 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
+ }
562
565
  }
563
566
  });
564
567
  }
@@ -734,7 +737,7 @@ class Module extends EventEmitter {
734
737
  this[_f] = new AbortController();
735
738
  this[_g] = null;
736
739
  }
737
- static get VERSION() { return "0.9.13"; }
740
+ static get VERSION() { return "0.9.14"; }
738
741
  static get LOG_TYPE() { return types_1.LOG_TYPE; }
739
742
  static get STATUS_TYPE() { return types_1.STATUS_TYPE; }
740
743
  static get MAX_TIMEOUT() { return 2147483647; }
@@ -1705,7 +1708,13 @@ class Module extends EventEmitter {
1705
1708
  return Promise.reject(errorDirectory(asFile(src) || "Unknown"));
1706
1709
  }
1707
1710
  const pmOpts = { posixSlashes: true, windows: true, nocase: PLATFORM_WIN32 };
1708
- 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;
1709
1718
  if ((0, types_1.isObject)(options)) {
1710
1719
  if (options.matchBase) {
1711
1720
  pmOpts.matchBase = true;
@@ -1717,13 +1726,25 @@ class Module extends EventEmitter {
1717
1726
  pmOpts.dot = true;
1718
1727
  }
1719
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
+ }
1720
1741
  }
1721
1742
  else {
1722
1743
  recursive = options;
1723
1744
  }
1724
1745
  recursive ??= true;
1725
1746
  const result = [];
1726
- 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);
1727
1748
  return result;
1728
1749
  }
1729
1750
  static renameFile(src, dest, throws = true) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/module",
3
- "version": "0.9.13",
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",
@@ -20,7 +20,7 @@
20
20
  "license": "BSD-3-Clause",
21
21
  "homepage": "https://github.com/anpham6/e-mc#readme",
22
22
  "dependencies": {
23
- "@e-mc/types": "0.9.13",
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",