@stryke/fs 0.5.1 → 0.6.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.
@@ -9,10 +9,10 @@ exports.extractFileFromTar = extractFileFromTar;
9
9
  exports.extractFileFromTarGzip = extractFileFromTarGzip;
10
10
  exports.removeDirectory = removeDirectory;
11
11
  exports.removeDirectorySync = removeDirectorySync;
12
- var _nodeFs = require("node:fs");
13
- var _promises = require("node:fs/promises");
14
12
  var _exists = require("@stryke/path/utilities/exists");
15
13
  var _nanotar = require("nanotar");
14
+ var _nodeFs = require("node:fs");
15
+ var _promises = require("node:fs/promises");
16
16
  function createDirectorySync(r) {
17
17
  if (!(0, _exists.existsSync)(r)) return (0, _nodeFs.mkdirSync)(r, {
18
18
  recursive: !0
@@ -24,12 +24,12 @@ async function createDirectory(r) {
24
24
  });
25
25
  }
26
26
  function removeDirectorySync(r) {
27
- if ((0, _exists.existsSync)(r)) return (0, _nodeFs.rmdirSync)(r, {
27
+ if ((0, _exists.existsSync)(r)) return (0, _nodeFs.rmSync)(r, {
28
28
  recursive: !0
29
29
  });
30
30
  }
31
31
  async function removeDirectory(r) {
32
- if ((0, _exists.existsSync)(r)) return (0, _promises.rmdir)(r, {
32
+ if ((0, _exists.existsSync)(r)) return (0, _promises.rm)(r, {
33
33
  recursive: !0
34
34
  });
35
35
  }
@@ -1 +1 @@
1
- import{createWriteStream as u,mkdirSync as y,rmdirSync as g}from"node:fs";import{mkdir as c,readFile as o,rmdir as p}from"node:fs/promises";import{exists as s,existsSync as a}from"@stryke/path/utilities/exists";import{parseTar as w,parseTarGzip as x}from"nanotar";export function createDirectorySync(r){if(!a(r))return y(r,{recursive:!0})}export async function createDirectory(r){if(!await s(r))return c(r,{recursive:!0})}export function removeDirectorySync(r){if(a(r))return g(r,{recursive:!0})}export async function removeDirectory(r){if(a(r))return p(r,{recursive:!0})}export async function extractFileFromTar(r,i,t){const e=w(await o(r)).find(n=>n.name===i);if(!e?.data)return;await s(t)||await c(t,{recursive:!0}),u(t).write(e.data)}export async function extractFileFromTarGzip(r,i,t){const e=(await x(await o(r))).find(n=>n.name===i);if(!e?.data)return;await s(t)||await c(t,{recursive:!0}),u(t).write(e.data)}
1
+ import{exists as c,existsSync as s}from"@stryke/path/utilities/exists";import{parseTar as y,parseTarGzip as g}from"nanotar";import{createWriteStream as u,mkdirSync as p,rmSync as w}from"node:fs";import{mkdir as a,readFile as o,rm as x}from"node:fs/promises";export function createDirectorySync(r){if(!s(r))return p(r,{recursive:!0})}export async function createDirectory(r){if(!await c(r))return a(r,{recursive:!0})}export function removeDirectorySync(r){if(s(r))return w(r,{recursive:!0})}export async function removeDirectory(r){if(s(r))return x(r,{recursive:!0})}export async function extractFileFromTar(r,i,t){const e=y(await o(r)).find(n=>n.name===i);if(!e?.data)return;await c(t)||await a(t,{recursive:!0}),u(t).write(e.data)}export async function extractFileFromTarGzip(r,i,t){const e=(await g(await o(r))).find(n=>n.name===i);if(!e?.data)return;await c(t)||await a(t,{recursive:!0}),u(t).write(e.data)}
@@ -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}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/fs",
3
- "version": "0.5.1",
3
+ "version": "0.6.1",
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
  },