@e-mc/module 0.9.13 → 0.9.15

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 +22 -6
  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.15/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.15/lib/core.d.ts
398
+ - https://www.unpkg.com/@e-mc/types@0.9.15/lib/logger.d.ts
399
+ - https://www.unpkg.com/@e-mc/types@0.9.15/lib/module.d.ts
400
+ - https://www.unpkg.com/@e-mc/types@0.9.15/lib/node.d.ts
401
+ - https://www.unpkg.com/@e-mc/types@0.9.15/lib/settings.d.ts
402
402
 
403
403
  * https://www.npmjs.com/package/@types/node
404
404
 
package/index.js CHANGED
@@ -548,17 +548,21 @@ 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()) {
555
555
  const pathname = path.join(srcDir, file.name);
556
- if (include(pathname) && !exclude?.(pathname)) {
556
+ const pathglob = pathname.substring(src.length);
557
+ if (include(pathglob) && !exclude?.(pathglob)) {
557
558
  outFiles.push(pathname);
558
559
  }
559
560
  }
560
561
  else if (depth > 0 && file.isDirectory()) {
561
- listDir(src, paths.concat(file.name), depth - 1, include, exclude, outFiles);
562
+ const subDirs = paths.concat(file.name);
563
+ if (!excludeDir?.includes(subDirs.join('/') + '/')) {
564
+ listDir(src, subDirs, depth - 1, include, exclude, excludeDir, outFiles);
565
+ }
562
566
  }
563
567
  });
564
568
  }
@@ -734,7 +738,7 @@ class Module extends EventEmitter {
734
738
  this[_f] = new AbortController();
735
739
  this[_g] = null;
736
740
  }
737
- static get VERSION() { return "0.9.13"; }
741
+ static get VERSION() { return "0.9.15"; }
738
742
  static get LOG_TYPE() { return types_1.LOG_TYPE; }
739
743
  static get STATUS_TYPE() { return types_1.STATUS_TYPE; }
740
744
  static get MAX_TIMEOUT() { return 2147483647; }
@@ -1705,7 +1709,7 @@ class Module extends EventEmitter {
1705
1709
  return Promise.reject(errorDirectory(asFile(src) || "Unknown"));
1706
1710
  }
1707
1711
  const pmOpts = { posixSlashes: true, windows: true, nocase: PLATFORM_WIN32 };
1708
- let exclude, recursive;
1712
+ let exclude, excludeDir, recursive;
1709
1713
  if ((0, types_1.isObject)(options)) {
1710
1714
  if (options.matchBase) {
1711
1715
  pmOpts.matchBase = true;
@@ -1717,13 +1721,25 @@ class Module extends EventEmitter {
1717
1721
  pmOpts.dot = true;
1718
1722
  }
1719
1723
  ({ exclude, recursive } = options);
1724
+ if (exclude) {
1725
+ const items = Array.isArray(exclude) ? exclude : [exclude];
1726
+ exclude = [];
1727
+ for (const value of items) {
1728
+ if (/^[^\\/][^*]+[\\/]$/.test(value) && !(0, types_1.hasGlob)(value)) {
1729
+ (excludeDir ||= []).push(this.normalizePath(value, 4));
1730
+ }
1731
+ else {
1732
+ exclude.push(value);
1733
+ }
1734
+ }
1735
+ }
1720
1736
  }
1721
1737
  else {
1722
1738
  recursive = options;
1723
1739
  }
1724
1740
  recursive ??= true;
1725
1741
  const result = [];
1726
- listDir(outDir, [], !recursive ? 0 : typeof recursive === 'number' ? recursive : Infinity, pm(pattern, pmOpts), exclude ? pm(exclude, pmOpts) : undefined, result);
1742
+ listDir(ensureDir(outDir), [], !recursive ? 0 : typeof recursive === 'number' ? recursive : Infinity, pm(pattern, pmOpts), exclude?.length ? pm(exclude, pmOpts) : undefined, excludeDir, result);
1727
1743
  return result;
1728
1744
  }
1729
1745
  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.15",
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.15",
24
24
  "chalk": "4.1.2",
25
25
  "file-type": "16.5.4",
26
26
  "js-yaml": "^4.1.0",