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 +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var g=Object.defineProperty;var
|
|
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
|
|
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};
|