@stryke/fs 0.6.0 → 0.7.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.
@@ -4,17 +4,24 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.listFiles = listFiles;
7
- var _promises = require("node:fs/promises");
8
7
  var _isFile = require("@stryke/path/utilities/is-file");
9
8
  var _joinPaths = require("@stryke/path/utilities/join-paths");
10
- async function listFiles(a) {
11
- const s = [],
12
- t = async r => {
13
- const n = await (0, _promises.readdir)(r);
14
- await Promise.all(n.map(async o => {
15
- const i = (0, _joinPaths.joinPaths)(r, o);
16
- (0, _isFile.isDirectory)(i) ? await t(i) : s.push(i);
17
- }));
9
+ var _promises = require("node:fs/promises");
10
+ var _picomatch = _interopRequireDefault(require("picomatch"));
11
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
+ async function listFiles(e, a = {}) {
13
+ const {
14
+ ignored: t = []
15
+ } = a,
16
+ r = [],
17
+ n = async s => {
18
+ if (!(0, _picomatch.default)(s, t)) {
19
+ const c = await (0, _promises.readdir)(s);
20
+ await Promise.all(c.map(async f => {
21
+ const i = (0, _joinPaths.joinPaths)(s, f);
22
+ (0, _picomatch.default)(i, t) || ((0, _isFile.isDirectory)(i) ? await n(i) : r.push(i));
23
+ }));
24
+ }
18
25
  };
19
- return await t(a), s;
26
+ return await n(e), r;
20
27
  }
@@ -1,7 +1,15 @@
1
+ export interface ListFilesOptions {
2
+ /**
3
+ * A list of directories/files to ignore
4
+ *
5
+ * @defaultValue []
6
+ */
7
+ ignored?: string[];
8
+ }
1
9
  /**
2
10
  * The file listing library used by Storm Software for building TypeScript applications.
3
11
  *
4
12
  * @param directoryPath - The directory path to list files from
5
13
  * @returns A list of file paths
6
14
  */
7
- export declare function listFiles(directoryPath: string): Promise<string[]>;
15
+ export declare function listFiles(directoryPath: string, options?: ListFilesOptions): Promise<string[]>;
@@ -1 +1 @@
1
- import{readdir as e}from"node:fs/promises";import{isDirectory as m}from"@stryke/path/utilities/is-file";import{joinPaths as c}from"@stryke/path/utilities/join-paths";export async function listFiles(a){const s=[],t=async r=>{const n=await e(r);await Promise.all(n.map(async o=>{const i=c(r,o);m(i)?await t(i):s.push(i)}))};return await t(a),s}
1
+ import{isDirectory as m}from"@stryke/path/utilities/is-file";import{joinPaths as l}from"@stryke/path/utilities/join-paths";import{readdir as p}from"node:fs/promises";import o from"picomatch";export async function listFiles(e,a={}){const{ignored:t=[]}=a,r=[],n=async s=>{if(!o(s,t)){const c=await p(s);await Promise.all(c.map(async f=>{const i=l(s,f);o(i,t)||(m(i)?await n(i):r.push(i))}))}};return await n(e),r}
@@ -25,10 +25,10 @@ const readFileSync = e => {
25
25
  throw new Error("An error occurred writing data to file");
26
26
  }
27
27
  },
28
- readFile = e => {
28
+ readFile = async e => {
29
29
  try {
30
30
  if (!e) throw new Error("No file path provided to read data");
31
- return (0, _promises.readFile)(e, {
31
+ return await (0, _promises.readFile)(e, {
32
32
  encoding: "utf8"
33
33
  });
34
34
  } catch {
@@ -78,6 +78,6 @@ async function readYamlFile(e, n) {
78
78
  function readFileIfExistingSync(e) {
79
79
  return (0, _nodeFs.existsSync)(e) ? readFileSync(e) : "";
80
80
  }
81
- function readFileIfExisting(e) {
81
+ async function readFileIfExisting(e) {
82
82
  return (0, _nodeFs.existsSync)(e) ? readFile(e) : "";
83
83
  }
@@ -68,5 +68,5 @@ export declare function readFileIfExistingSync(path: string): string;
68
68
  * @param path - The path to the file to read.
69
69
  * @returns The content of the file if it exists, otherwise an empty string.
70
70
  */
71
- export declare function readFileIfExisting(path: string): Promise<string> | "";
71
+ export declare function readFileIfExisting(path: string): Promise<string>;
72
72
  export {};
@@ -1 +1 @@
1
- import{StormJSON as o}from"@stryke/json/storm-json";import{isError as i}from"@stryke/types/type-checks/is-error";import{existsSync as s,readFileSync as a}from"node:fs";import{readFile as c}from"node:fs/promises";export const readFileSync=e=>{try{if(!e)throw new Error("No file path provided to read data");return a(e,{encoding:"utf8"})}catch{throw new Error("An error occurred writing data to file")}},readFile=e=>{try{if(!e)throw new Error("No file path provided to read data");return c(e,{encoding:"utf8"})}catch{throw new Error("An error occurred writing data to file")}};export function readJsonFileSync(e,n){const t=readFileSync(e);n&&(n.endsWithNewline=t.codePointAt(t.length-1)===10);try{return o.parseJson(t,n)}catch(r){throw i(r)?(r.message=r.message.replace("JSON",e),r):new Error(`Failed to parse JSON: ${e}`)}}export async function readJsonFile(e,n){const t=await readFile(e);n&&(n.endsWithNewline=t.codePointAt(t.length-1)===10);try{return o.parseJson(t,n)}catch(r){throw i(r)?(r.message=r.message.replace("JSON",e),r):new Error(`Failed to parse JSON: ${e}`)}}export function readYamlFileSync(e,n){const t=readFileSync(e),{load:r}=require("@zkochan/js-yaml");return r(t,{...n,filename:e})}export async function readYamlFile(e,n){const t=await readFile(e),{load:r}=require("@zkochan/js-yaml");return r(t,{...n,filename:e})}export function readFileIfExistingSync(e){return s(e)?readFileSync(e):""}export function readFileIfExisting(e){return s(e)?readFile(e):""}
1
+ import{StormJSON as o}from"@stryke/json/storm-json";import{isError as i}from"@stryke/types/type-checks/is-error";import{existsSync as s,readFileSync as a}from"node:fs";import{readFile as c}from"node:fs/promises";export const readFileSync=e=>{try{if(!e)throw new Error("No file path provided to read data");return a(e,{encoding:"utf8"})}catch{throw new Error("An error occurred writing data to file")}},readFile=async e=>{try{if(!e)throw new Error("No file path provided to read data");return await c(e,{encoding:"utf8"})}catch{throw new Error("An error occurred writing data to file")}};export function readJsonFileSync(e,n){const t=readFileSync(e);n&&(n.endsWithNewline=t.codePointAt(t.length-1)===10);try{return o.parseJson(t,n)}catch(r){throw i(r)?(r.message=r.message.replace("JSON",e),r):new Error(`Failed to parse JSON: ${e}`)}}export async function readJsonFile(e,n){const t=await readFile(e);n&&(n.endsWithNewline=t.codePointAt(t.length-1)===10);try{return o.parseJson(t,n)}catch(r){throw i(r)?(r.message=r.message.replace("JSON",e),r):new Error(`Failed to parse JSON: ${e}`)}}export function readYamlFileSync(e,n){const t=readFileSync(e),{load:r}=require("@zkochan/js-yaml");return r(t,{...n,filename:e})}export async function readYamlFile(e,n){const t=await readFile(e),{load:r}=require("@zkochan/js-yaml");return r(t,{...n,filename:e})}export function readFileIfExistingSync(e){return s(e)?readFileSync(e):""}export async function readFileIfExisting(e){return s(e)?readFile(e):""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/fs",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "type": "module",
5
5
  "description": "A package containing various file system utilities that expand the functionality of NodeJs's `fs` module.",
6
6
  "repository": {
@@ -16,13 +16,15 @@
16
16
  "@zkochan/js-yaml": "^0.0.7",
17
17
  "chalk": "^5.4.1",
18
18
  "nanotar": "^0.2.0",
19
+ "picomatch": "^4.0.2",
19
20
  "semver": "7.7.1",
20
21
  "@stryke/json": ">=0.4.2",
21
- "@stryke/path": ">=0.3.1",
22
+ "@stryke/path": ">=0.3.2",
22
23
  "@stryke/types": ">=0.5.1"
23
24
  },
24
25
  "devDependencies": {
25
26
  "@types/node": "^22.13.1",
27
+ "@types/picomatch": "^3.0.2",
26
28
  "nx": "^20.4.6",
27
29
  "tinyexec": "^0.3.2"
28
30
  },