fs-fixture 1.0.0 → 1.1.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.
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -32,6 +32,6 @@ declare class FsFixture {
|
|
|
32
32
|
declare type FileTree = {
|
|
33
33
|
[path: string]: string | FileTree;
|
|
34
34
|
};
|
|
35
|
-
declare function createFixture(source
|
|
35
|
+
declare function createFixture(source?: string | FileTree): Promise<FsFixture>;
|
|
36
36
|
|
|
37
37
|
export { FileTree, FsFixture, createFixture };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var i=require("fs"),l=require("path"),p=require("os");function u(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var c=u(i),a=u(l),d=u(p);class h{path;constructor(t){this.path=t}exists(t=""){return i.promises.access(a.default.join(this.path,t)).then(()=>!0,()=>!1)}rm(t=""){return i.promises.rm(a.default.join(this.path,t),{recursive:!0,force:!0})}writeFile(t,r){return i.promises.writeFile(a.default.join(this.path,t),r)}writeJson(t,r){return this.writeFile(t,JSON.stringify(r,null,2))}readFile(t,r){return i.promises.readFile(a.default.join(this.path,t),r)}}const m=a.default.join(c.default.realpathSync(d.default.tmpdir()),"test-fixtures",Date.now().toString());let o=0;function w(){return o+=1,o}const{hasOwnProperty:y}=Object.prototype,j=(e,t)=>y.call(e,t);function f(e,t){const r=[];for(const s in e){if(!j(e,s))continue;const n=e[s];typeof n=="string"?r.push({path:a.default.join(t,s),content:n}):r.push(...f(n,a.default.join(t,s)))}return r}async function v(e){const t=a.default.join(m,`fixture-${w()}`);return await i.promises.mkdir(t,{recursive:!0}),e&&(typeof e=="string"?await i.promises.cp(e,t,{recursive:!0}):typeof e=="object"&&await Promise.all(f(e,t).map(async r=>{await i.promises.mkdir(a.default.dirname(r.path),{recursive:!0}),await i.promises.writeFile(r.path,r.content)}))),new h(t)}exports.createFixture=v;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import p,{promises as n}from"fs";import i from"path";import u from"os";class h{path;constructor(t){this.path=t}exists(t=""){return n.access(i.join(this.path,t)).then(()=>!0,()=>!1)}rm(t=""){return n.rm(i.join(this.path,t),{recursive:!0,force:!0})}writeFile(t,e){return n.writeFile(i.join(this.path,t),e)}writeJson(t,e){return this.writeFile(t,JSON.stringify(e,null,2))}readFile(t,e){return n.readFile(i.join(this.path,t),e)}}const f=i.join(p.realpathSync(u.tmpdir()),"test-fixtures",Date.now().toString());let a=0;function l(){return a+=1,a}const{hasOwnProperty:m}=Object.prototype,w=(r,t)=>m.call(r,t);function c(r,t){const e=[];for(const o in r){if(!w(r,o))continue;const s=r[o];typeof s=="string"?e.push({path:i.join(t,o),content:s}):e.push(...c(s,i.join(t,o)))}return e}async function y(r){const t=i.join(f,`fixture-${l()}`);return await n.mkdir(t,{recursive:!0}),r&&(typeof r=="string"?await n.cp(r,t,{recursive:!0}):typeof r=="object"&&await Promise.all(c(r,t).map(async e=>{await n.mkdir(i.dirname(e.path),{recursive:!0}),await n.writeFile(e.path,e.content)}))),new h(t)}export{y as createFixture};
|