@stryke/fs 0.11.3 → 0.12.1

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,26 +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(s, a) {
13
- const o = [],
14
- n = (0, _picomatch.default)(s, {
15
- dot: !0,
16
- ...a
17
- }),
18
- r = async t => {
19
- if (!n(t)) {
20
- const e = await (0, _promises.readdir)(t);
21
- await Promise.all(e.map(async c => {
22
- const i = (0, _joinPaths.joinPaths)(t, c);
23
- n(i) || ((0, _isFile.isDirectory)(i) ? await r(i) : o.push(i));
24
- }));
25
- }
26
- };
27
- return await r(s), 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());
28
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 m}from"@stryke/path/is-file";import{joinPaths as p}from"@stryke/path/join-paths";import{readdir as f}from"node:fs/promises";import l from"picomatch";export async function listFiles(s,a){const o=[],n=l(s,{dot:!0,...a}),r=async t=>{if(!n(t)){const e=await f(t);await Promise.all(e.map(async c=>{const i=p(t,c);n(i)||(m(i)?await r(i):o.push(i))}))}};return await r(s),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())}
@@ -38,8 +38,7 @@ export declare function getPackageInfoSync(name: string, options?: PackageResolv
38
38
  /**
39
39
  * Get the package info from the package.json file
40
40
  *
41
- * @param name - The name of the package
42
- * @param options - The options to use when resolving the package
41
+ * @param cwd - The current working directory
43
42
  * @returns The package info
44
43
  */
45
44
  export declare function loadPackageJSON(cwd?: any): Promise<PackageJson | null>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/fs",
3
- "version": "0.11.3",
3
+ "version": "0.12.1",
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,17 +15,17 @@
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
- "@stryke/path": "^0.4.8",
23
+ "@stryke/path": "^0.4.9",
23
24
  "@stryke/type-checks": "^0.3.1",
24
25
  "@stryke/types": "^0.8.1"
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"