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 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: string | FileTree): Promise<FsFixture>;
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 a=require("fs"),c=require("path"),d=require("os");function u(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var h=u(a),i=u(c),m=u(d);class w{path;constructor(t){this.path=t}exists(t=""){return a.promises.access(i.default.join(this.path,t)).then(()=>!0,()=>!1)}rm(t=""){return a.promises.rm(i.default.join(this.path,t),{recursive:!0,force:!0})}writeFile(t,r){return a.promises.writeFile(i.default.join(this.path,t),r)}writeJson(t,r){return this.writeFile(t,JSON.stringify(r,null,2))}readFile(t,r){return a.promises.readFile(i.default.join(this.path,t),r)}}const o=i.default.join(h.default.realpathSync(m.default.tmpdir()),"test-fixtures",Date.now().toString());let l=0;function f(){return l+=1,l}const{hasOwnProperty:y}=Object.prototype,j=(e,t)=>y.call(e,t);function p(e,t){const r=[];for(const s in e){if(!j(e,s))continue;const n=e[s];typeof n=="string"?r.push({path:i.default.join(t,s),content:n}):r.push(...p(n,i.default.join(t,s)))}return r}async function v(e){let t;return typeof e=="string"?(t=i.default.join(o,`${i.default.basename(e)}-${f()}`),await a.promises.mkdir(t,{recursive:!0}),await a.promises.cp(e,t,{recursive:!0})):(t=i.default.join(o,`fixture-${f()}`),await Promise.all(p(e,t).map(async r=>{await a.promises.mkdir(i.default.dirname(r.path),{recursive:!0}),await a.promises.writeFile(r.path,r.content)}))),new w(t)}exports.createFixture=v;
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 h,{promises as n}from"fs";import i from"path";import l from"os";class f{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 a=i.join(h.realpathSync(l.tmpdir()),"test-fixtures",Date.now().toString());let u=0;function c(){return u+=1,u}const{hasOwnProperty:m}=Object.prototype,w=(r,t)=>m.call(r,t);function p(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(...p(s,i.join(t,o)))}return e}async function j(r){let t;return typeof r=="string"?(t=i.join(a,`${i.basename(r)}-${c()}`),await n.mkdir(t,{recursive:!0}),await n.cp(r,t,{recursive:!0})):(t=i.join(a,`fixture-${c()}`),await Promise.all(p(r,t).map(async e=>{await n.mkdir(i.dirname(e.path),{recursive:!0}),await n.writeFile(e.path,e.content)}))),new f(t)}export{j as createFixture};
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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fs-fixture",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Easily create test fixtures at a temporary file-system path",
5
5
  "keywords": [
6
6
  "test",