@jestaubach/fs-helpers 0.2.27 → 0.2.29

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.
@@ -1,31 +1,34 @@
1
- var d = Object.defineProperty;
2
- var S = (t, e, r) => e in t ? d(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
3
- var n = (t, e, r) => (S(t, typeof e != "symbol" ? e + "" : e, r), r);
4
- const c = {}, { default: v } = (() => {
1
+ var S = Object.defineProperty;
2
+ var m = (t, e, r) => e in t ? S(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
3
+ var o = (t, e, r) => (m(t, typeof e != "symbol" ? e + "" : e, r), r);
4
+ const { default: b } = (() => {
5
5
  const t = require("fs-extra");
6
6
  return t && t.__esModule ? t : Object.assign(/* @__PURE__ */ Object.create(null), t, { default: t, [Symbol.toStringTag]: "Module" });
7
+ })(), { default: c } = (() => {
8
+ const t = require("node:path");
9
+ return t && t.__esModule ? t : Object.assign(/* @__PURE__ */ Object.create(null), t, { default: t, [Symbol.toStringTag]: "Module" });
7
10
  })(), i = /* @__PURE__ */ new Map();
8
- function m(t) {
11
+ function v(t) {
9
12
  const { root: e, dir: r } = c.parse(t), s = r.split(e).slice(1).join(e).split(c.sep);
10
- for (let u = 0; u < s.length; u++) {
11
- const y = [e, s.slice(0, u + 1).join(c.sep)].join("");
12
- f(y);
13
+ for (let l = 0; l < s.length; l++) {
14
+ const y = [e, s.slice(0, l + 1).join(c.sep)].join("");
15
+ d(y);
13
16
  }
14
- const o = v.readFileSync(t).toString();
15
- l(t, o);
17
+ const n = b.readFileSync(t).toString();
18
+ a(t, n);
16
19
  }
17
20
  function p(t, e) {
18
21
  const [r, s] = i.get(t) || ["", ""];
19
22
  return Buffer.from(s);
20
23
  }
21
- function l(t, e, r) {
24
+ function a(t, e, r) {
22
25
  i.set(t, ["file", e]);
23
26
  }
24
27
  function g(t) {
25
28
  return t === c.resolve(".") ? !0 : i.has(t);
26
29
  }
27
- function a(t, e) {
28
- const [r, s] = i.get(t) || ["", ""], o = {
30
+ function h(t, e) {
31
+ const [r, s] = i.get(t) || ["", ""], n = {
29
32
  isDirectory: () => t === c.resolve(".") ? !0 : r === "dir",
30
33
  isFile: () => i.has(t) && r === "file",
31
34
  isBlockDevice: () => !1,
@@ -52,57 +55,57 @@ function a(t, e) {
52
55
  ctime: /* @__PURE__ */ new Date(0),
53
56
  birthtime: /* @__PURE__ */ new Date(0)
54
57
  };
55
- return o.isBlockDevice(), o.isCharacterDevice(), o.isSymbolicLink(), o.isFIFO(), o.isSocket(), o;
58
+ return n.isBlockDevice(), n.isCharacterDevice(), n.isSymbolicLink(), n.isFIFO(), n.isSocket(), n;
56
59
  }
57
- function b(t, e) {
60
+ function F(t, e) {
58
61
  }
59
- class F extends Error {
62
+ class D extends Error {
60
63
  constructor(r) {
61
64
  super(r);
62
- n(this, "code");
65
+ o(this, "code");
63
66
  this.code = "ENOENT";
64
67
  }
65
68
  }
66
69
  function E(t, e) {
67
70
  const r = t, s = e;
68
71
  if (!i.has(r))
69
- throw new F("source path not found");
70
- h(r, s, !0);
72
+ throw new D("source path not found");
73
+ f(r, s, !0);
71
74
  }
72
- function h(t, e, r) {
75
+ function f(t, e, r) {
73
76
  const s = { source: t, target: e, deleteSource: r };
74
- for (const o of Array.from(i.keys()))
75
- D(o, s);
77
+ for (const n of Array.from(i.keys()))
78
+ k(n, s);
76
79
  }
77
- function D(t, e) {
80
+ function k(t, e) {
78
81
  if (!t.includes(e.source))
79
82
  return;
80
83
  const r = t.split(e.source).join(e.target), s = i.get(t) || /* istanbul ignore next */
81
84
  ["", ""];
82
85
  e.deleteSource && i.delete(t), i.set(r, s);
83
86
  }
84
- function k(t, e, r) {
87
+ function x(t, e, r) {
85
88
  if (i.has(e))
86
89
  throw new Error("destination directory exists");
87
- h(t, e, !1);
90
+ f(t, e, !1);
88
91
  }
89
- function x(t) {
92
+ function w(t) {
90
93
  let e;
91
94
  const r = c.resolve(".");
92
95
  for (let s = 0; s < t.length; s++) {
93
- const o = t.slice(0, s + 1).join(c.sep), u = `${r}${o}`;
94
- e = w(u, o, e);
96
+ const n = t.slice(0, s + 1).join(c.sep), l = `${r}${n}`;
97
+ e = A(l, n, e);
95
98
  }
96
99
  return e;
97
100
  }
98
- function w(t, e, r) {
101
+ function A(t, e, r) {
99
102
  return i.has(t) || e === "" ? r : (i.set(t, ["dir", ""]), r ?? t);
100
103
  }
101
- function f(t) {
102
- if (a(t).isFile())
104
+ function d(t) {
105
+ if (h(t).isFile())
103
106
  throw new Error("file exists at destination");
104
107
  const e = t.split(c.resolve(".")).join("").split(c.sep);
105
- return x(e);
108
+ return w(e);
106
109
  }
107
110
  function $(t) {
108
111
  for (const e of Array.from(i.keys()))
@@ -111,23 +114,26 @@ function $(t) {
111
114
  function P(t) {
112
115
  i.has(t) || i.set(t, ["file", ""]);
113
116
  }
114
- const A = { existsSync: g, lstatSync: a, chmodSync: b, renameSync: E, readFileSync: p, copySync: k, removeSync: $, ensureFileSync: P, mkdirpSync: f, outputFileSync: l, seedFile: m }, { default: _ } = (() => {
117
+ const _ = { existsSync: g, lstatSync: h, chmodSync: F, renameSync: E, readFileSync: p, copySync: x, removeSync: $, ensureFileSync: P, mkdirpSync: d, outputFileSync: a, seedFile: v }, { default: M } = (() => {
115
118
  const t = require("fs-extra");
116
119
  return t && t.__esModule ? t : Object.assign(/* @__PURE__ */ Object.create(null), t, { default: t, [Symbol.toStringTag]: "Module" });
120
+ })(), { default: u } = (() => {
121
+ const t = require("node:path");
122
+ return t && t.__esModule ? t : Object.assign(/* @__PURE__ */ Object.create(null), t, { default: t, [Symbol.toStringTag]: "Module" });
117
123
  })();
118
- class M {
124
+ class I {
119
125
  constructor(e, r) {
120
- n(this, "existsSync");
121
- n(this, "lstatSync");
122
- n(this, "chmodSync");
123
- n(this, "renameSync");
124
- n(this, "readFileSync");
125
- n(this, "copySync");
126
- n(this, "removeSync");
127
- n(this, "ensureFileSync");
128
- n(this, "outputFileSync");
129
- n(this, "mkdirpSync");
130
- n(this, "seedFile");
126
+ o(this, "existsSync");
127
+ o(this, "lstatSync");
128
+ o(this, "chmodSync");
129
+ o(this, "renameSync");
130
+ o(this, "readFileSync");
131
+ o(this, "copySync");
132
+ o(this, "removeSync");
133
+ o(this, "ensureFileSync");
134
+ o(this, "outputFileSync");
135
+ o(this, "mkdirpSync");
136
+ o(this, "seedFile");
131
137
  if ({
132
138
  existsSync: this.existsSync,
133
139
  lstatSync: this.lstatSync,
@@ -140,7 +146,7 @@ class M {
140
146
  outputFileSync: this.outputFileSync,
141
147
  mkdirpSync: this.mkdirpSync,
142
148
  seedFile: this.seedFile
143
- } = e, this.seedFile !== void 0 && r !== void 0)
149
+ } = e, this.readFile = this.readFile.bind(this), this.writeFile = this.writeFile.bind(this), this.checkIfFileExists = this.checkIfFileExists.bind(this), this.checkIfDirExists = this.checkIfDirExists.bind(this), this.getAbsolutePath = this.getAbsolutePath.bind(this), this.createDir = this.createDir.bind(this), this.touchFile = this.touchFile.bind(this), this.rimrafDir = this.rimrafDir.bind(this), this.rimrafDirs = this.rimrafDirs.bind(this), this.abortDirCreation = this.abortDirCreation.bind(this), this.renameDir = this.renameDir.bind(this), this.copyDirAbs = this.copyDirAbs.bind(this), this.seedFile !== void 0 && r !== void 0)
144
150
  for (const s of r)
145
151
  this.mockExistingFile(s);
146
152
  }
@@ -159,8 +165,8 @@ class M {
159
165
  return this.outputFileSync(this.getAbsolutePath(e).value, r), { success: !0, error: null };
160
166
  }
161
167
  checkIfPathExists(e, r, s) {
162
- const o = this.getAbsolutePath(e).value;
163
- return this.existsSync(o) ? s(this.lstatSync(o)) ? { success: !0, value: !0, error: null } : {
168
+ const n = this.getAbsolutePath(e).value;
169
+ return this.existsSync(n) ? s(this.lstatSync(n)) ? { success: !0, value: !0, error: null } : {
164
170
  success: !1,
165
171
  value: !1,
166
172
  error: `checkIf${r === "file" ? "File" : "Dir"}Exists: '${e}' is not a ${r}.`
@@ -178,7 +184,7 @@ class M {
178
184
  throw new Error("Dir is undefined.");
179
185
  if (e.match(/^[.a-zA-Z0-9\-_/:\\]+$/g) === null)
180
186
  throw new Error(`Dir contains unsupported characters. Received ${e}.`);
181
- return { success: !0, value: c.normalize(c.resolve(e)), error: null };
187
+ return { success: !0, value: u.normalize(u.resolve(e)), error: null };
182
188
  } catch (r) {
183
189
  return console.error(`Error resolving path: ${e}`), {
184
190
  success: !1,
@@ -192,7 +198,7 @@ class M {
192
198
  if (e === void 0)
193
199
  throw new Error(`Function "createDir" expected a path. Recieved "${e}".`);
194
200
  const r = this.getAbsolutePath(e).value, s = this.mkdirpSync(r);
195
- return { success: !0, value: c.normalize(s.replace(/^\\\\\?\\/, "")), error: null };
201
+ return { success: !0, value: u.normalize(s.replace(/^\\\\\?\\/, "")), error: null };
196
202
  } catch {
197
203
  return console.error(`Error creating dir: ${e}`), { success: !1, value: void 0, error: `Error creating dir: '${e}'` };
198
204
  }
@@ -225,10 +231,10 @@ class M {
225
231
  }
226
232
  }
227
233
  }
228
- function I(t, e) {
229
- return new M(t, e);
234
+ function j(t, e) {
235
+ return new I(t, e);
230
236
  }
231
- const O = { use: I, default: _, mock: A };
237
+ const C = { use: j, default: M, mock: _ };
232
238
  export {
233
- O as default
239
+ C as default
234
240
  };
@@ -1 +1 @@
1
- (function(n,c){typeof exports=="object"&&typeof module<"u"?module.exports=c():typeof define=="function"&&define.amd?define(c):(n=typeof globalThis<"u"?globalThis:n||self,n["fs-helpers"]=c())})(this,function(){"use strict";var M=Object.defineProperty;var j=(n,c,i)=>c in n?M(n,c,{enumerable:!0,configurable:!0,writable:!0,value:i}):n[c]=i;var u=(n,c,i)=>(j(n,typeof c!="symbol"?c+"":c,i),i);const n={},{default:c}=(()=>{const t=require("fs-extra");return t&&t.__esModule?t:Object.assign(Object.create(null),t,{default:t,[Symbol.toStringTag]:"Module"})})(),i=new Map;function y(t){const{root:e,dir:r}=n.parse(t),s=r.split(e).slice(1).join(e).split(n.sep);for(let l=0;l<s.length;l++){const _=[e,s.slice(0,l+1).join(n.sep)].join("");d(_)}const o=c.readFileSync(t).toString();a(t,o)}function S(t,e){const[r,s]=i.get(t)||["",""];return Buffer.from(s)}function a(t,e,r){i.set(t,["file",e])}function v(t){return t===n.resolve(".")?!0:i.has(t)}function h(t,e){const[r,s]=i.get(t)||["",""],o={isDirectory:()=>t===n.resolve(".")?!0:r==="dir",isFile:()=>i.has(t)&&r==="file",isBlockDevice:()=>!1,isCharacterDevice:()=>!1,isSymbolicLink:()=>!1,isFIFO:()=>!1,isSocket:()=>!1,dev:0,ino:0,mode:0,nlink:0,uid:0,gid:0,rdev:0,size:0,blksize:0,blocks:0,atimeMs:0,mtimeMs:0,ctimeMs:0,birthtimeMs:0,atime:new Date(0),mtime:new Date(0),ctime:new Date(0),birthtime:new Date(0)};return o.isBlockDevice(),o.isCharacterDevice(),o.isSymbolicLink(),o.isFIFO(),o.isSocket(),o}function m(t,e){}class p extends Error{constructor(r){super(r);u(this,"code");this.code="ENOENT"}}function g(t,e){const r=t,s=e;if(!i.has(r))throw new p("source path not found");f(r,s,!0)}function f(t,e,r){const s={source:t,target:e,deleteSource:r};for(const o of Array.from(i.keys()))b(o,s)}function b(t,e){if(!t.includes(e.source))return;const r=t.split(e.source).join(e.target),s=i.get(t)||["",""];e.deleteSource&&i.delete(t),i.set(r,s)}function F(t,e,r){if(i.has(e))throw new Error("destination directory exists");f(t,e,!1)}function E(t){let e;const r=n.resolve(".");for(let s=0;s<t.length;s++){const o=t.slice(0,s+1).join(n.sep),l=`${r}${o}`;e=D(l,o,e)}return e}function D(t,e,r){return i.has(t)||e===""?r:(i.set(t,["dir",""]),r??t)}function d(t){if(h(t).isFile())throw new Error("file exists at destination");const e=t.split(n.resolve(".")).join("").split(n.sep);return E(e)}function k(t){for(const e of Array.from(i.keys()))e.includes(t)&&i.delete(e)}function x(t){i.has(t)||i.set(t,["file",""])}const w={existsSync:v,lstatSync:h,chmodSync:m,renameSync:g,readFileSync:S,copySync:F,removeSync:k,ensureFileSync:x,mkdirpSync:d,outputFileSync:a,seedFile:y},{default:$}=(()=>{const t=require("fs-extra");return t&&t.__esModule?t:Object.assign(Object.create(null),t,{default:t,[Symbol.toStringTag]:"Module"})})();class P{constructor(e,r){u(this,"existsSync");u(this,"lstatSync");u(this,"chmodSync");u(this,"renameSync");u(this,"readFileSync");u(this,"copySync");u(this,"removeSync");u(this,"ensureFileSync");u(this,"outputFileSync");u(this,"mkdirpSync");u(this,"seedFile");if({existsSync:this.existsSync,lstatSync:this.lstatSync,chmodSync:this.chmodSync,renameSync:this.renameSync,readFileSync:this.readFileSync,copySync:this.copySync,removeSync:this.removeSync,ensureFileSync:this.ensureFileSync,outputFileSync:this.outputFileSync,mkdirpSync:this.mkdirpSync,seedFile:this.seedFile}=e,this.seedFile!==void 0&&r!==void 0)for(const s of r)this.mockExistingFile(s)}mockExistingFile(e){const r=this.getAbsolutePath(e).value;this.seedFile(r)}readFile(e,r){return{success:!0,value:this.readFileSync(this.getAbsolutePath(e).value,r),error:null}}writeFile(e,r){return this.outputFileSync(this.getAbsolutePath(e).value,r),{success:!0,error:null}}checkIfPathExists(e,r,s){const o=this.getAbsolutePath(e).value;return this.existsSync(o)?s(this.lstatSync(o))?{success:!0,value:!0,error:null}:{success:!1,value:!1,error:`checkIf${r==="file"?"File":"Dir"}Exists: '${e}' is not a ${r}.`}:{success:!0,value:!1,error:null}}checkIfFileExists(e){return this.checkIfPathExists(e,"file",r=>r.isFile())}checkIfDirExists(e){return this.checkIfPathExists(e,"directory",r=>r.isDirectory())}getAbsolutePath(e){try{if(e===void 0)throw new Error("Dir is undefined.");if(e.match(/^[.a-zA-Z0-9\-_/:\\]+$/g)===null)throw new Error(`Dir contains unsupported characters. Received ${e}.`);return{success:!0,value:n.normalize(n.resolve(e)),error:null}}catch(r){return console.error(`Error resolving path: ${e}`),{success:!1,value:void 0,error:`Error resolving path: '${e}'. Received error: '${r}'`}}}createDir(e){try{if(e===void 0)throw new Error(`Function "createDir" expected a path. Recieved "${e}".`);const r=this.getAbsolutePath(e).value,s=this.mkdirpSync(r);return{success:!0,value:n.normalize(s.replace(/^\\\\\?\\/,"")),error:null}}catch{return console.error(`Error creating dir: ${e}`),{success:!1,value:void 0,error:`Error creating dir: '${e}'`}}}touchFile(e,r){const s=this.getAbsolutePath(e).value;return this.ensureFileSync(s),r!==void 0&&this.chmodSync(s,r),{success:!0,error:null}}rimrafDir(e){return this.getAbsolutePath(e).value!==void 0&&this.checkIfDirExists(e).value?(this.removeSync(e),{success:!0,value:e,error:null}):(console.error(`Error deleting dir: ${e}`),{success:!1,value:void 0,error:`Error deleting dir: '${e}'`})}rimrafDirs(e){return e.map(r=>this.rimrafDir(this.getAbsolutePath(r).value))}abortDirCreation(e){return e!==null&&this.checkIfDirExists(e).value?(console.error(`Cleaning up due to abort, directories created starting at: ${JSON.stringify(e)}`),this.rimrafDir(e),{success:!0,error:null}):(console.error("Cleaning up due to abort, no directory to clean up."),{success:!1,error:"Cleaning up due to abort, no directory to clean up."})}renameDir(e,r){try{return this.renameSync(this.getAbsolutePath(e).value,this.getAbsolutePath(r).value),{success:!0,value:"Successfully renamed the directory.",error:null}}catch(s){return console.error(s.code),{success:!1,value:void 0,error:`renameDir from '${e}' to '${r} failed.`}}}copyDirAbs(e,r){try{return this.copySync(this.getAbsolutePath(e).value,this.getAbsolutePath(r).value,{overwrite:!1,errorOnExist:!0}),{success:!0,error:null}}catch{return{success:!1,error:`Error copying absolute from '${e}' to '${r}'`}}}}function A(t,e){return new P(t,e)}return{use:A,default:$,mock:w}});
1
+ (function(u,n){typeof exports=="object"&&typeof module<"u"?module.exports=n():typeof define=="function"&&define.amd?define(n):(u=typeof globalThis<"u"?globalThis:u||self,u["fs-helpers"]=n())})(this,function(){"use strict";var j=Object.defineProperty;var I=(u,n,i)=>n in u?j(u,n,{enumerable:!0,configurable:!0,writable:!0,value:i}):u[n]=i;var c=(u,n,i)=>(I(u,typeof n!="symbol"?n+"":n,i),i);const{default:u}=(()=>{const t=require("fs-extra");return t&&t.__esModule?t:Object.assign(Object.create(null),t,{default:t,[Symbol.toStringTag]:"Module"})})(),{default:n}=(()=>{const t=require("node:path");return t&&t.__esModule?t:Object.assign(Object.create(null),t,{default:t,[Symbol.toStringTag]:"Module"})})(),i=new Map;function m(t){const{root:e,dir:r}=n.parse(t),s=r.split(e).slice(1).join(e).split(n.sep);for(let l=0;l<s.length;l++){const M=[e,s.slice(0,l+1).join(n.sep)].join("");y(M)}const o=u.readFileSync(t).toString();h(t,o)}function S(t,e){const[r,s]=i.get(t)||["",""];return Buffer.from(s)}function h(t,e,r){i.set(t,["file",e])}function b(t){return t===n.resolve(".")?!0:i.has(t)}function f(t,e){const[r,s]=i.get(t)||["",""],o={isDirectory:()=>t===n.resolve(".")?!0:r==="dir",isFile:()=>i.has(t)&&r==="file",isBlockDevice:()=>!1,isCharacterDevice:()=>!1,isSymbolicLink:()=>!1,isFIFO:()=>!1,isSocket:()=>!1,dev:0,ino:0,mode:0,nlink:0,uid:0,gid:0,rdev:0,size:0,blksize:0,blocks:0,atimeMs:0,mtimeMs:0,ctimeMs:0,birthtimeMs:0,atime:new Date(0),mtime:new Date(0),ctime:new Date(0),birthtime:new Date(0)};return o.isBlockDevice(),o.isCharacterDevice(),o.isSymbolicLink(),o.isFIFO(),o.isSocket(),o}function p(t,e){}class v extends Error{constructor(r){super(r);c(this,"code");this.code="ENOENT"}}function g(t,e){const r=t,s=e;if(!i.has(r))throw new v("source path not found");d(r,s,!0)}function d(t,e,r){const s={source:t,target:e,deleteSource:r};for(const o of Array.from(i.keys()))F(o,s)}function F(t,e){if(!t.includes(e.source))return;const r=t.split(e.source).join(e.target),s=i.get(t)||["",""];e.deleteSource&&i.delete(t),i.set(r,s)}function D(t,e,r){if(i.has(e))throw new Error("destination directory exists");d(t,e,!1)}function E(t){let e;const r=n.resolve(".");for(let s=0;s<t.length;s++){const o=t.slice(0,s+1).join(n.sep),l=`${r}${o}`;e=k(l,o,e)}return e}function k(t,e,r){return i.has(t)||e===""?r:(i.set(t,["dir",""]),r??t)}function y(t){if(f(t).isFile())throw new Error("file exists at destination");const e=t.split(n.resolve(".")).join("").split(n.sep);return E(e)}function x(t){for(const e of Array.from(i.keys()))e.includes(t)&&i.delete(e)}function w(t){i.has(t)||i.set(t,["file",""])}const A={existsSync:b,lstatSync:f,chmodSync:p,renameSync:g,readFileSync:S,copySync:D,removeSync:x,ensureFileSync:w,mkdirpSync:y,outputFileSync:h,seedFile:m},{default:$}=(()=>{const t=require("fs-extra");return t&&t.__esModule?t:Object.assign(Object.create(null),t,{default:t,[Symbol.toStringTag]:"Module"})})(),{default:a}=(()=>{const t=require("node:path");return t&&t.__esModule?t:Object.assign(Object.create(null),t,{default:t,[Symbol.toStringTag]:"Module"})})();class P{constructor(e,r){c(this,"existsSync");c(this,"lstatSync");c(this,"chmodSync");c(this,"renameSync");c(this,"readFileSync");c(this,"copySync");c(this,"removeSync");c(this,"ensureFileSync");c(this,"outputFileSync");c(this,"mkdirpSync");c(this,"seedFile");if({existsSync:this.existsSync,lstatSync:this.lstatSync,chmodSync:this.chmodSync,renameSync:this.renameSync,readFileSync:this.readFileSync,copySync:this.copySync,removeSync:this.removeSync,ensureFileSync:this.ensureFileSync,outputFileSync:this.outputFileSync,mkdirpSync:this.mkdirpSync,seedFile:this.seedFile}=e,this.readFile=this.readFile.bind(this),this.writeFile=this.writeFile.bind(this),this.checkIfFileExists=this.checkIfFileExists.bind(this),this.checkIfDirExists=this.checkIfDirExists.bind(this),this.getAbsolutePath=this.getAbsolutePath.bind(this),this.createDir=this.createDir.bind(this),this.touchFile=this.touchFile.bind(this),this.rimrafDir=this.rimrafDir.bind(this),this.rimrafDirs=this.rimrafDirs.bind(this),this.abortDirCreation=this.abortDirCreation.bind(this),this.renameDir=this.renameDir.bind(this),this.copyDirAbs=this.copyDirAbs.bind(this),this.seedFile!==void 0&&r!==void 0)for(const s of r)this.mockExistingFile(s)}mockExistingFile(e){const r=this.getAbsolutePath(e).value;this.seedFile(r)}readFile(e,r){return{success:!0,value:this.readFileSync(this.getAbsolutePath(e).value,r),error:null}}writeFile(e,r){return this.outputFileSync(this.getAbsolutePath(e).value,r),{success:!0,error:null}}checkIfPathExists(e,r,s){const o=this.getAbsolutePath(e).value;return this.existsSync(o)?s(this.lstatSync(o))?{success:!0,value:!0,error:null}:{success:!1,value:!1,error:`checkIf${r==="file"?"File":"Dir"}Exists: '${e}' is not a ${r}.`}:{success:!0,value:!1,error:null}}checkIfFileExists(e){return this.checkIfPathExists(e,"file",r=>r.isFile())}checkIfDirExists(e){return this.checkIfPathExists(e,"directory",r=>r.isDirectory())}getAbsolutePath(e){try{if(e===void 0)throw new Error("Dir is undefined.");if(e.match(/^[.a-zA-Z0-9\-_/:\\]+$/g)===null)throw new Error(`Dir contains unsupported characters. Received ${e}.`);return{success:!0,value:a.normalize(a.resolve(e)),error:null}}catch(r){return console.error(`Error resolving path: ${e}`),{success:!1,value:void 0,error:`Error resolving path: '${e}'. Received error: '${r}'`}}}createDir(e){try{if(e===void 0)throw new Error(`Function "createDir" expected a path. Recieved "${e}".`);const r=this.getAbsolutePath(e).value,s=this.mkdirpSync(r);return{success:!0,value:a.normalize(s.replace(/^\\\\\?\\/,"")),error:null}}catch{return console.error(`Error creating dir: ${e}`),{success:!1,value:void 0,error:`Error creating dir: '${e}'`}}}touchFile(e,r){const s=this.getAbsolutePath(e).value;return this.ensureFileSync(s),r!==void 0&&this.chmodSync(s,r),{success:!0,error:null}}rimrafDir(e){return this.getAbsolutePath(e).value!==void 0&&this.checkIfDirExists(e).value?(this.removeSync(e),{success:!0,value:e,error:null}):(console.error(`Error deleting dir: ${e}`),{success:!1,value:void 0,error:`Error deleting dir: '${e}'`})}rimrafDirs(e){return e.map(r=>this.rimrafDir(this.getAbsolutePath(r).value))}abortDirCreation(e){return e!==null&&this.checkIfDirExists(e).value?(console.error(`Cleaning up due to abort, directories created starting at: ${JSON.stringify(e)}`),this.rimrafDir(e),{success:!0,error:null}):(console.error("Cleaning up due to abort, no directory to clean up."),{success:!1,error:"Cleaning up due to abort, no directory to clean up."})}renameDir(e,r){try{return this.renameSync(this.getAbsolutePath(e).value,this.getAbsolutePath(r).value),{success:!0,value:"Successfully renamed the directory.",error:null}}catch(s){return console.error(s.code),{success:!1,value:void 0,error:`renameDir from '${e}' to '${r} failed.`}}}copyDirAbs(e,r){try{return this.copySync(this.getAbsolutePath(e).value,this.getAbsolutePath(r).value,{overwrite:!1,errorOnExist:!0}),{success:!0,error:null}}catch{return{success:!1,error:`Error copying absolute from '${e}' to '${r}'`}}}}function _(t,e){return new P(t,e)}return{use:_,default:$,mock:A}});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jestaubach/fs-helpers",
3
- "version": "0.2.27",
3
+ "version": "0.2.29",
4
4
  "type": "module",
5
5
  "main": "./dist/fs-helpers.umd.cjs",
6
6
  "module": "./dist/fs-helpers.js",