fs-fixture 2.10.0 → 2.10.2

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.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var g=Object.defineProperty;var a=(s,e)=>g(s,"name",{value:e,configurable:!0});var n=require("node:fs/promises"),o=require("node:path"),F=require("node:url"),v=require("node:fs"),P=require("node:os");typeof Symbol.asyncDispose!="symbol"&&Object.defineProperty(Symbol,"asyncDispose",{configurable:!1,enumerable:!1,writable:!1,value:Symbol.for("asyncDispose")});class b{static{a(this,"FsFixture")}path;constructor(e){this.path=e}getPath(...e){return o.join(this.path,...e)}exists(e=""){return n.access(this.getPath(e)).then(()=>!0,()=>!1)}rm(e=""){return n.rm(this.getPath(e),{recursive:!0,force:!0})}cp(e,r,i){return r?r.endsWith(o.sep)&&(r+=o.basename(e)):r=o.basename(e),n.cp(e,this.getPath(r),i)}mkdir(e){return n.mkdir(this.getPath(e),{recursive:!0})}readFile=a(((e,r)=>n.readFile(this.getPath(e),r)),"readFile");readdir=a(((e,r)=>n.readdir(this.getPath(e||""),r)),"readdir");writeFile=a(((e,r,...i)=>n.writeFile(this.getPath(e),r,...i)),"writeFile");async readJson(e){const r=await this.readFile(e,"utf8");return JSON.parse(r)}writeJson(e,r,i=2){return this.writeFile(e,JSON.stringify(r,null,i))}async[Symbol.asyncDispose](){await this.rm()}}const D=v.realpathSync(P.tmpdir());class p{static{a(this,"PathBase")}constructor(e){this.path=e}}class y extends p{static{a(this,"Directory")}}class m extends p{static{a(this,"File")}constructor(e,r){super(e),this.content=r}}class u extends p{static{a(this,"Symlink")}constructor(e,r,i){super(i??""),this.target=e,this.type=r}}const w=a((s,e,r)=>{const i=[];for(const l in s){if(!Object.hasOwn(s,l))continue;const c=o.join(e,l);let t=s[l];if(typeof t=="function"){const h=Object.assign(Object.create(r),{filePath:c}),f=t(h);if(f instanceof u){const d=new u(f.target,f.type,c);i.push(d);continue}else t=f}if(typeof t=="string"||Buffer.isBuffer(t))i.push(new m(c,t));else if(t&&typeof t=="object"&&!Array.isArray(t))i.push(new y(c),...w(t,c,r));else throw new TypeError(`Invalid file content for path "${c}". Functions must return a string, Buffer, Symlink, or a nested FileTree object. Received: ${String(t)}`)}return i},"flattenFileTree"),j=a(async(s,e)=>{const r=e?.tempDir?o.resolve(typeof e.tempDir=="string"?e.tempDir:F.fileURLToPath(e.tempDir)):D;e?.tempDir&&await n.mkdir(r,{recursive:!0});const i=await n.mkdtemp(o.join(r,"fs-fixture-"));if(s){if(typeof s=="string")await n.cp(s,i,{recursive:!0,filter:e?.templateFilter});else if(typeof s=="object"){const c=w(s,i,{fixturePath:i,getPath:a((...t)=>o.join(i,...t),"getPath"),symlink:a((t,h)=>new u(t,h),"symlink")});await Promise.all(c.filter(t=>t instanceof y).map(t=>n.mkdir(t.path,{recursive:!0}))),await Promise.all(c.map(async t=>{t instanceof u?await n.symlink(t.target,t.path,t.type):t instanceof m&&await n.writeFile(t.path,t.content)}))}}return new b(i)},"createFixture");exports.createFixture=j;
1
+ "use strict";var g=Object.defineProperty;var n=(s,e)=>g(s,"name",{value:e,configurable:!0});var c=require("node:fs/promises"),f=require("node:path"),F=require("node:url"),v=require("node:fs"),P=require("node:os");typeof Symbol.asyncDispose!="symbol"&&Object.defineProperty(Symbol,"asyncDispose",{configurable:!1,enumerable:!1,writable:!1,value:Symbol.for("asyncDispose")});class b{static{n(this,"FsFixture")}path;constructor(e){this.path=e}getPath(...e){return f.join(this.path,...e)}exists(e=""){return c.access(this.getPath(e)).then(()=>!0,()=>!1)}rm(e=""){return c.rm(this.getPath(e),{recursive:!0,force:!0})}cp(e,t,i){return t?t.endsWith(f.sep)&&(t+=f.basename(e)):t=f.basename(e),c.cp(e,this.getPath(t),i)}mkdir(e){return c.mkdir(this.getPath(e),{recursive:!0})}readFile=n(((e,t)=>c.readFile(this.getPath(e),t)),"readFile");readdir=n(((e,t)=>c.readdir(this.getPath(e||""),t)),"readdir");writeFile=n(((e,t,...i)=>c.writeFile(this.getPath(e),t,...i)),"writeFile");async readJson(e){const t=await this.readFile(e,"utf8");return JSON.parse(t)}writeJson(e,t,i=2){return this.writeFile(e,JSON.stringify(t,null,i))}async[Symbol.asyncDispose](){await this.rm()}}const D=v.realpathSync(P.tmpdir());class p{static{n(this,"PathBase")}constructor(e){this.path=e}}class m extends p{static{n(this,"Directory")}}class y extends p{static{n(this,"File")}constructor(e,t){super(e),this.content=t}}class u extends p{static{n(this,"Symlink")}constructor(e,t,i){super(i??""),this.target=e,this.type=t}}const d=n((s,e,t)=>{const i=[];for(const h in s){if(!Object.hasOwn(s,h))continue;const o=f.join(e,h);let a=s[h];if(typeof a=="function"){const r=Object.assign(Object.create(t),{filePath:o}),l=a(r);if(l instanceof u){const w=new u(l.target,l.type,o);i.push(w);continue}else a=l}if(typeof a=="string"||Buffer.isBuffer(a))i.push(new y(o,a));else if(a&&typeof a=="object"&&!Array.isArray(a))i.push(new m(o),...d(a,o,t));else throw new TypeError(`Invalid file content for path "${o}". Functions must return a string, Buffer, Symlink, or a nested FileTree object. Received: ${String(a)}`)}return i},"flattenFileTree"),j=n(async(s,e)=>{const t=e?.tempDir?f.resolve(typeof e.tempDir=="string"?e.tempDir:F.fileURLToPath(e.tempDir)):D;e?.tempDir&&await c.mkdir(t,{recursive:!0});const i=await c.mkdtemp(f.join(t,"fs-fixture-"));if(s){if(typeof s=="string")await c.cp(s,i,{recursive:!0,filter:e?.templateFilter});else if(typeof s=="object"){const o=d(s,i,{fixturePath:i,getPath:n((...r)=>f.join(i,...r),"getPath"),symlink:n((r,l)=>new u(r,l),"symlink")}),a=new Set;for(const r of o)r instanceof m?a.add(r.path):(r instanceof y||r instanceof u)&&a.add(f.dirname(r.path));await Promise.all(Array.from(a).map(r=>c.mkdir(r,{recursive:!0}))),await Promise.all(o.map(async r=>{r instanceof u?await c.symlink(r.target,r.path,r.type):r instanceof y&&await c.writeFile(r.path,r.content)}))}}return new b(i)},"createFixture");exports.createFixture=j;
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- var d=Object.defineProperty;var a=(s,e)=>d(s,"name",{value:e,configurable:!0});import n from"node:fs/promises";import c from"node:path";import{fileURLToPath as F}from"node:url";import P from"node:fs";import b from"node:os";typeof Symbol.asyncDispose!="symbol"&&Object.defineProperty(Symbol,"asyncDispose",{configurable:!1,enumerable:!1,writable:!1,value:Symbol.for("asyncDispose")});class D{static{a(this,"FsFixture")}path;constructor(e){this.path=e}getPath(...e){return c.join(this.path,...e)}exists(e=""){return n.access(this.getPath(e)).then(()=>!0,()=>!1)}rm(e=""){return n.rm(this.getPath(e),{recursive:!0,force:!0})}cp(e,r,i){return r?r.endsWith(c.sep)&&(r+=c.basename(e)):r=c.basename(e),n.cp(e,this.getPath(r),i)}mkdir(e){return n.mkdir(this.getPath(e),{recursive:!0})}readFile=a(((e,r)=>n.readFile(this.getPath(e),r)),"readFile");readdir=a(((e,r)=>n.readdir(this.getPath(e||""),r)),"readdir");writeFile=a(((e,r,...i)=>n.writeFile(this.getPath(e),r,...i)),"writeFile");async readJson(e){const r=await this.readFile(e,"utf8");return JSON.parse(r)}writeJson(e,r,i=2){return this.writeFile(e,JSON.stringify(r,null,i))}async[Symbol.asyncDispose](){await this.rm()}}const j=P.realpathSync(b.tmpdir());class h{static{a(this,"PathBase")}constructor(e){this.path=e}}class u extends h{static{a(this,"Directory")}}class y extends h{static{a(this,"File")}constructor(e,r){super(e),this.content=r}}class p extends h{static{a(this,"Symlink")}constructor(e,r,i){super(i??""),this.target=e,this.type=r}}const w=a((s,e,r)=>{const i=[];for(const f in s){if(!Object.hasOwn(s,f))continue;const o=c.join(e,f);let t=s[f];if(typeof t=="function"){const m=Object.assign(Object.create(r),{filePath:o}),l=t(m);if(l instanceof p){const g=new p(l.target,l.type,o);i.push(g);continue}else t=l}if(typeof t=="string"||Buffer.isBuffer(t))i.push(new y(o,t));else if(t&&typeof t=="object"&&!Array.isArray(t))i.push(new u(o),...w(t,o,r));else throw new TypeError(`Invalid file content for path "${o}". Functions must return a string, Buffer, Symlink, or a nested FileTree object. Received: ${String(t)}`)}return i},"flattenFileTree"),k=a(async(s,e)=>{const r=e?.tempDir?c.resolve(typeof e.tempDir=="string"?e.tempDir:F(e.tempDir)):j;e?.tempDir&&await n.mkdir(r,{recursive:!0});const i=await n.mkdtemp(c.join(r,"fs-fixture-"));if(s){if(typeof s=="string")await n.cp(s,i,{recursive:!0,filter:e?.templateFilter});else if(typeof s=="object"){const o=w(s,i,{fixturePath:i,getPath:a((...t)=>c.join(i,...t),"getPath"),symlink:a((t,m)=>new p(t,m),"symlink")});await Promise.all(o.filter(t=>t instanceof u).map(t=>n.mkdir(t.path,{recursive:!0}))),await Promise.all(o.map(async t=>{t instanceof p?await n.symlink(t.target,t.path,t.type):t instanceof y&&await n.writeFile(t.path,t.content)}))}}return new D(i)},"createFixture");export{k as createFixture};
1
+ var g=Object.defineProperty;var n=(s,e)=>g(s,"name",{value:e,configurable:!0});import o from"node:fs/promises";import f from"node:path";import{fileURLToPath as F}from"node:url";import P from"node:fs";import b from"node:os";typeof Symbol.asyncDispose!="symbol"&&Object.defineProperty(Symbol,"asyncDispose",{configurable:!1,enumerable:!1,writable:!1,value:Symbol.for("asyncDispose")});class D{static{n(this,"FsFixture")}path;constructor(e){this.path=e}getPath(...e){return f.join(this.path,...e)}exists(e=""){return o.access(this.getPath(e)).then(()=>!0,()=>!1)}rm(e=""){return o.rm(this.getPath(e),{recursive:!0,force:!0})}cp(e,t,i){return t?t.endsWith(f.sep)&&(t+=f.basename(e)):t=f.basename(e),o.cp(e,this.getPath(t),i)}mkdir(e){return o.mkdir(this.getPath(e),{recursive:!0})}readFile=n(((e,t)=>o.readFile(this.getPath(e),t)),"readFile");readdir=n(((e,t)=>o.readdir(this.getPath(e||""),t)),"readdir");writeFile=n(((e,t,...i)=>o.writeFile(this.getPath(e),t,...i)),"writeFile");async readJson(e){const t=await this.readFile(e,"utf8");return JSON.parse(t)}writeJson(e,t,i=2){return this.writeFile(e,JSON.stringify(t,null,i))}async[Symbol.asyncDispose](){await this.rm()}}const j=P.realpathSync(b.tmpdir());class h{static{n(this,"PathBase")}constructor(e){this.path=e}}class y extends h{static{n(this,"Directory")}}class u extends h{static{n(this,"File")}constructor(e,t){super(e),this.content=t}}class m extends h{static{n(this,"Symlink")}constructor(e,t,i){super(i??""),this.target=e,this.type=t}}const d=n((s,e,t)=>{const i=[];for(const p in s){if(!Object.hasOwn(s,p))continue;const c=f.join(e,p);let a=s[p];if(typeof a=="function"){const r=Object.assign(Object.create(t),{filePath:c}),l=a(r);if(l instanceof m){const w=new m(l.target,l.type,c);i.push(w);continue}else a=l}if(typeof a=="string"||Buffer.isBuffer(a))i.push(new u(c,a));else if(a&&typeof a=="object"&&!Array.isArray(a))i.push(new y(c),...d(a,c,t));else throw new TypeError(`Invalid file content for path "${c}". Functions must return a string, Buffer, Symlink, or a nested FileTree object. Received: ${String(a)}`)}return i},"flattenFileTree"),k=n(async(s,e)=>{const t=e?.tempDir?f.resolve(typeof e.tempDir=="string"?e.tempDir:F(e.tempDir)):j;e?.tempDir&&await o.mkdir(t,{recursive:!0});const i=await o.mkdtemp(f.join(t,"fs-fixture-"));if(s){if(typeof s=="string")await o.cp(s,i,{recursive:!0,filter:e?.templateFilter});else if(typeof s=="object"){const c=d(s,i,{fixturePath:i,getPath:n((...r)=>f.join(i,...r),"getPath"),symlink:n((r,l)=>new m(r,l),"symlink")}),a=new Set;for(const r of c)r instanceof y?a.add(r.path):(r instanceof u||r instanceof m)&&a.add(f.dirname(r.path));await Promise.all(Array.from(a).map(r=>o.mkdir(r,{recursive:!0}))),await Promise.all(c.map(async r=>{r instanceof m?await o.symlink(r.target,r.path,r.type):r instanceof u&&await o.writeFile(r.path,r.content)}))}}return new D(i)},"createFixture");export{k as createFixture};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fs-fixture",
3
- "version": "2.10.0",
3
+ "version": "2.10.2",
4
4
  "description": "Easily create test fixtures at a temporary file-system path",
5
5
  "keywords": [
6
6
  "test",