@jestaubach/fs-helpers 0.2.28 → 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.
- package/dist/fs-helpers.js +44 -44
- package/dist/fs-helpers.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/fs-helpers.js
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
var S = Object.defineProperty;
|
|
2
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
|
|
4
|
-
const { default:
|
|
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
7
|
})(), { default: c } = (() => {
|
|
8
8
|
const t = require("node:path");
|
|
9
9
|
return t && t.__esModule ? t : Object.assign(/* @__PURE__ */ Object.create(null), t, { default: t, [Symbol.toStringTag]: "Module" });
|
|
10
10
|
})(), i = /* @__PURE__ */ new Map();
|
|
11
|
-
function
|
|
11
|
+
function v(t) {
|
|
12
12
|
const { root: e, dir: r } = c.parse(t), s = r.split(e).slice(1).join(e).split(c.sep);
|
|
13
|
-
for (let
|
|
14
|
-
const y = [e, s.slice(0,
|
|
13
|
+
for (let l = 0; l < s.length; l++) {
|
|
14
|
+
const y = [e, s.slice(0, l + 1).join(c.sep)].join("");
|
|
15
15
|
d(y);
|
|
16
16
|
}
|
|
17
|
-
const
|
|
18
|
-
a(t,
|
|
17
|
+
const n = b.readFileSync(t).toString();
|
|
18
|
+
a(t, n);
|
|
19
19
|
}
|
|
20
|
-
function
|
|
20
|
+
function p(t, e) {
|
|
21
21
|
const [r, s] = i.get(t) || ["", ""];
|
|
22
22
|
return Buffer.from(s);
|
|
23
23
|
}
|
|
24
24
|
function a(t, e, r) {
|
|
25
25
|
i.set(t, ["file", e]);
|
|
26
26
|
}
|
|
27
|
-
function
|
|
27
|
+
function g(t) {
|
|
28
28
|
return t === c.resolve(".") ? !0 : i.has(t);
|
|
29
29
|
}
|
|
30
30
|
function h(t, e) {
|
|
31
|
-
const [r, s] = i.get(t) || ["", ""],
|
|
31
|
+
const [r, s] = i.get(t) || ["", ""], n = {
|
|
32
32
|
isDirectory: () => t === c.resolve(".") ? !0 : r === "dir",
|
|
33
33
|
isFile: () => i.has(t) && r === "file",
|
|
34
34
|
isBlockDevice: () => !1,
|
|
@@ -55,27 +55,27 @@ function h(t, e) {
|
|
|
55
55
|
ctime: /* @__PURE__ */ new Date(0),
|
|
56
56
|
birthtime: /* @__PURE__ */ new Date(0)
|
|
57
57
|
};
|
|
58
|
-
return
|
|
58
|
+
return n.isBlockDevice(), n.isCharacterDevice(), n.isSymbolicLink(), n.isFIFO(), n.isSocket(), n;
|
|
59
59
|
}
|
|
60
60
|
function F(t, e) {
|
|
61
61
|
}
|
|
62
|
-
class
|
|
62
|
+
class D extends Error {
|
|
63
63
|
constructor(r) {
|
|
64
64
|
super(r);
|
|
65
|
-
|
|
65
|
+
o(this, "code");
|
|
66
66
|
this.code = "ENOENT";
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
-
function
|
|
69
|
+
function E(t, e) {
|
|
70
70
|
const r = t, s = e;
|
|
71
71
|
if (!i.has(r))
|
|
72
|
-
throw new
|
|
72
|
+
throw new D("source path not found");
|
|
73
73
|
f(r, s, !0);
|
|
74
74
|
}
|
|
75
75
|
function f(t, e, r) {
|
|
76
76
|
const s = { source: t, target: e, deleteSource: r };
|
|
77
|
-
for (const
|
|
78
|
-
k(
|
|
77
|
+
for (const n of Array.from(i.keys()))
|
|
78
|
+
k(n, s);
|
|
79
79
|
}
|
|
80
80
|
function k(t, e) {
|
|
81
81
|
if (!t.includes(e.source))
|
|
@@ -93,12 +93,12 @@ function w(t) {
|
|
|
93
93
|
let e;
|
|
94
94
|
const r = c.resolve(".");
|
|
95
95
|
for (let s = 0; s < t.length; s++) {
|
|
96
|
-
const
|
|
97
|
-
e =
|
|
96
|
+
const n = t.slice(0, s + 1).join(c.sep), l = `${r}${n}`;
|
|
97
|
+
e = A(l, n, e);
|
|
98
98
|
}
|
|
99
99
|
return e;
|
|
100
100
|
}
|
|
101
|
-
function
|
|
101
|
+
function A(t, e, r) {
|
|
102
102
|
return i.has(t) || e === "" ? r : (i.set(t, ["dir", ""]), r ?? t);
|
|
103
103
|
}
|
|
104
104
|
function d(t) {
|
|
@@ -107,33 +107,33 @@ function d(t) {
|
|
|
107
107
|
const e = t.split(c.resolve(".")).join("").split(c.sep);
|
|
108
108
|
return w(e);
|
|
109
109
|
}
|
|
110
|
-
function
|
|
110
|
+
function $(t) {
|
|
111
111
|
for (const e of Array.from(i.keys()))
|
|
112
112
|
e.includes(t) && i.delete(e);
|
|
113
113
|
}
|
|
114
|
-
function
|
|
114
|
+
function P(t) {
|
|
115
115
|
i.has(t) || i.set(t, ["file", ""]);
|
|
116
116
|
}
|
|
117
|
-
const _ = { existsSync:
|
|
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 } = (() => {
|
|
118
118
|
const t = require("fs-extra");
|
|
119
119
|
return t && t.__esModule ? t : Object.assign(/* @__PURE__ */ Object.create(null), t, { default: t, [Symbol.toStringTag]: "Module" });
|
|
120
|
-
})(), { default:
|
|
120
|
+
})(), { default: u } = (() => {
|
|
121
121
|
const t = require("node:path");
|
|
122
122
|
return t && t.__esModule ? t : Object.assign(/* @__PURE__ */ Object.create(null), t, { default: t, [Symbol.toStringTag]: "Module" });
|
|
123
123
|
})();
|
|
124
|
-
class
|
|
124
|
+
class I {
|
|
125
125
|
constructor(e, r) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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");
|
|
137
137
|
if ({
|
|
138
138
|
existsSync: this.existsSync,
|
|
139
139
|
lstatSync: this.lstatSync,
|
|
@@ -146,7 +146,7 @@ class j {
|
|
|
146
146
|
outputFileSync: this.outputFileSync,
|
|
147
147
|
mkdirpSync: this.mkdirpSync,
|
|
148
148
|
seedFile: this.seedFile
|
|
149
|
-
} = 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)
|
|
150
150
|
for (const s of r)
|
|
151
151
|
this.mockExistingFile(s);
|
|
152
152
|
}
|
|
@@ -165,8 +165,8 @@ class j {
|
|
|
165
165
|
return this.outputFileSync(this.getAbsolutePath(e).value, r), { success: !0, error: null };
|
|
166
166
|
}
|
|
167
167
|
checkIfPathExists(e, r, s) {
|
|
168
|
-
const
|
|
169
|
-
return this.existsSync(
|
|
168
|
+
const n = this.getAbsolutePath(e).value;
|
|
169
|
+
return this.existsSync(n) ? s(this.lstatSync(n)) ? { success: !0, value: !0, error: null } : {
|
|
170
170
|
success: !1,
|
|
171
171
|
value: !1,
|
|
172
172
|
error: `checkIf${r === "file" ? "File" : "Dir"}Exists: '${e}' is not a ${r}.`
|
|
@@ -184,7 +184,7 @@ class j {
|
|
|
184
184
|
throw new Error("Dir is undefined.");
|
|
185
185
|
if (e.match(/^[.a-zA-Z0-9\-_/:\\]+$/g) === null)
|
|
186
186
|
throw new Error(`Dir contains unsupported characters. Received ${e}.`);
|
|
187
|
-
return { success: !0, value:
|
|
187
|
+
return { success: !0, value: u.normalize(u.resolve(e)), error: null };
|
|
188
188
|
} catch (r) {
|
|
189
189
|
return console.error(`Error resolving path: ${e}`), {
|
|
190
190
|
success: !1,
|
|
@@ -198,7 +198,7 @@ class j {
|
|
|
198
198
|
if (e === void 0)
|
|
199
199
|
throw new Error(`Function "createDir" expected a path. Recieved "${e}".`);
|
|
200
200
|
const r = this.getAbsolutePath(e).value, s = this.mkdirpSync(r);
|
|
201
|
-
return { success: !0, value:
|
|
201
|
+
return { success: !0, value: u.normalize(s.replace(/^\\\\\?\\/, "")), error: null };
|
|
202
202
|
} catch {
|
|
203
203
|
return console.error(`Error creating dir: ${e}`), { success: !1, value: void 0, error: `Error creating dir: '${e}'` };
|
|
204
204
|
}
|
|
@@ -231,10 +231,10 @@ class j {
|
|
|
231
231
|
}
|
|
232
232
|
}
|
|
233
233
|
}
|
|
234
|
-
function
|
|
235
|
-
return new
|
|
234
|
+
function j(t, e) {
|
|
235
|
+
return new I(t, e);
|
|
236
236
|
}
|
|
237
|
-
const C = { use:
|
|
237
|
+
const C = { use: j, default: M, mock: _ };
|
|
238
238
|
export {
|
|
239
239
|
C as default
|
|
240
240
|
};
|
package/dist/fs-helpers.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
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
|
|
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}});
|