@stryke/fs 0.11.2 → 0.12.0

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.
@@ -3,22 +3,27 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.list = list;
7
+ exports.listDirectories = listDirectories;
6
8
  exports.listFiles = listFiles;
7
- var _isFile = require("@stryke/path/is-file");
8
- var _joinPaths = require("@stryke/path/join-paths");
9
- var _promises = require("node:fs/promises");
10
- var _picomatch = _interopRequireDefault(require("picomatch"));
9
+ var _defu = _interopRequireDefault(require("defu"));
10
+ var _glob = require("glob");
11
11
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
- async function listFiles(e, s = {}) {
13
- const o = [],
14
- r = async t => {
15
- if (!(0, _picomatch.default)(t, s)) {
16
- const n = await (0, _promises.readdir)(t);
17
- await Promise.all(n.map(async m => {
18
- const i = (0, _joinPaths.joinPaths)(t, m);
19
- (0, _picomatch.default)(i, s) || ((0, _isFile.isDirectory)(i) ? await r(i) : o.push(i));
20
- }));
21
- }
22
- };
23
- return await r(e), o;
12
+ const p = {
13
+ dot: !0
14
+ };
15
+ async function list(i, t) {
16
+ return (0, _glob.glob)(i, (0, _defu.default)(t ?? {}, p));
17
+ }
18
+ async function listFiles(i, t) {
19
+ const s = (await list(i, (0, _defu.default)({
20
+ withFileTypes: !0
21
+ }, t ?? {}))).filter(e => e.isFile());
22
+ return t?.withFileTypes ? s : s.map(e => e.fullpath());
23
+ }
24
+ async function listDirectories(i, t) {
25
+ const s = (await list(i, (0, _defu.default)({
26
+ withFileTypes: !0
27
+ }, t ?? {}))).filter(e => e.isDirectory());
28
+ return t?.withFileTypes ? s : s.map(e => e.fullpath());
24
29
  }
@@ -1,9 +1,24 @@
1
- import type { PicomatchOptions } from "picomatch";
2
- export type ListFilesOptions = PicomatchOptions;
1
+ import type { GlobOptions, Path } from "glob";
2
+ export type ListOptions = GlobOptions;
3
+ export type InferListReturnType<TOptions extends GlobOptions> = TOptions["withFileTypes"] extends true ? Path[] : string[];
3
4
  /**
4
- * The file listing library used by Storm Software for building TypeScript applications.
5
+ * A files and directories listing helper function
5
6
  *
6
- * @param directoryPath - The directory path to list files from
7
+ * @param filesGlob - A glob pattern to match files
7
8
  * @returns A list of file paths
8
9
  */
9
- export declare function listFiles(directoryPath: string, options?: ListFilesOptions): Promise<string[]>;
10
+ export declare function list<TOptions extends ListOptions>(filesGlob: string, options?: TOptions): Promise<InferListReturnType<TOptions>>;
11
+ /**
12
+ * A file listing helper function
13
+ *
14
+ * @param filesGlob - A glob pattern to match files
15
+ * @returns A list of file paths
16
+ */
17
+ export declare function listFiles<TOptions extends ListOptions>(filesGlob: string, options?: TOptions): Promise<InferListReturnType<TOptions>>;
18
+ /**
19
+ * A directories listing helper function
20
+ *
21
+ * @param filesGlob - A glob pattern to match files
22
+ * @returns A list of file paths
23
+ */
24
+ export declare function listDirectories<TOptions extends ListOptions>(filesGlob: string, options?: TOptions): Promise<InferListReturnType<TOptions>>;
@@ -1 +1 @@
1
- import{isDirectory as c}from"@stryke/path/is-file";import{joinPaths as p}from"@stryke/path/join-paths";import{readdir as f}from"node:fs/promises";import a from"picomatch";export async function listFiles(e,s={}){const o=[],r=async t=>{if(!a(t,s)){const n=await f(t);await Promise.all(n.map(async m=>{const i=p(t,m);a(i,s)||(c(i)?await r(i):o.push(i))}))}};return await r(e),o}
1
+ import n from"defu";import{glob as r}from"glob";const p={dot:!0};export async function list(i,t){return r(i,n(t??{},p))}export async function listFiles(i,t){const s=(await list(i,n({withFileTypes:!0},t??{}))).filter(e=>e.isFile());return t?.withFileTypes?s:s.map(e=>e.fullpath())}export async function listDirectories(i,t){const s=(await list(i,n({withFileTypes:!0},t??{}))).filter(e=>e.isDirectory());return t?.withFileTypes?s:s.map(e=>e.fullpath())}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/fs",
3
- "version": "0.11.2",
3
+ "version": "0.12.0",
4
4
  "type": "module",
5
5
  "description": "A package containing various file system utilities that expand the functionality of NodeJs's built-in `fs` module.",
6
6
  "repository": {
@@ -15,8 +15,9 @@
15
15
  "@antfu/install-pkg": "^1.0.0",
16
16
  "@zkochan/js-yaml": "^0.0.7",
17
17
  "chalk": "^5.4.1",
18
+ "defu": "^6.1.4",
19
+ "glob": "^11.0.1",
18
20
  "nanotar": "^0.2.0",
19
- "picomatch": "^4.0.2",
20
21
  "semver": "7.7.1",
21
22
  "@stryke/json": "^0.7.1",
22
23
  "@stryke/path": "^0.4.8",
@@ -25,7 +26,6 @@
25
26
  },
26
27
  "devDependencies": {
27
28
  "@types/node": "^22.13.1",
28
- "@types/picomatch": "^3.0.2",
29
29
  "@types/semver": "^7.5.8",
30
30
  "nx": "^20.5.0",
31
31
  "tinyexec": "^0.3.2"