fs-fixture 2.7.1 → 2.7.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 m=Object.defineProperty;var c=(i,t)=>m(i,"name",{value:t,configurable:!0});var a=require("node:fs/promises"),o=require("node:path"),w=require("node:fs"),g=require("node:os");typeof Symbol.asyncDispose!="symbol"&&Object.defineProperty(Symbol,"asyncDispose",{configurable:!1,enumerable:!1,writable:!1,value:Symbol.for("asyncDispose")});class b{static{c(this,"FsFixture")}path;constructor(t){this.path=t}getPath(...t){return o.join(this.path,...t)}exists(t=""){return a.access(this.getPath(t)).then(()=>!0,()=>!1)}rm(t=""){return a.rm(this.getPath(t),{recursive:!0,force:!0})}cp(t,r,s){return a.cp(t,this.getPath(r),s)}writeFile(t,r){return a.writeFile(this.getPath(t),r)}writeJson(t,r){return this.writeFile(t,JSON.stringify(r,null,2))}readFile(t,r){return a.readFile(this.getPath(t),r)}async[Symbol.asyncDispose](){await this.rm()}}const d=w.realpathSync(g.tmpdir()),F=`fs-fixture-${Date.now()}-${process.pid}`;let h=0;const P=c(()=>(h+=1,h),"getId");class l{static{c(this,"Symlink")}target;type;path;constructor(t,r){this.target=t,this.type=r}}const y=c((i,t,r)=>{const s=[];for(const u in i){if(!Object.hasOwn(i,u))continue;const e=o.join(t,u);let n=i[u];if(typeof n=="function"){const f=Object.assign(Object.create(r),{filePath:e}),p=n(f);if(p instanceof l){p.path=e,s.push(p);continue}else n=p}typeof n=="string"?s.push({path:e,content:n}):s.push(...y(n,e,r))}return s},"flattenFileTree"),v=c(async(i,t)=>{const r=t?.tempDir?o.resolve(t.tempDir):d,s=o.join(r,`${F}-${P()}/`);if(await a.mkdir(s,{recursive:!0}),i){if(typeof i=="string")await a.cp(i,s,{recursive:!0,filter:t?.templateFilter});else if(typeof i=="object"){const u={fixturePath:s,getPath:c((...e)=>o.join(s,...e),"getPath"),symlink:c((e,n)=>new l(e,n),"symlink")};await Promise.all(y(i,s,u).map(async e=>{await a.mkdir(o.dirname(e.path),{recursive:!0}),e instanceof l?await a.symlink(e.target,e.path,e.type):await a.writeFile(e.path,e.content)}))}}return new b(s)},"createFixture");exports.createFixture=v;
1
+ "use strict";var m=Object.defineProperty;var o=(s,e)=>m(s,"name",{value:e,configurable:!0});var a=require("node:fs/promises"),n=require("node:path"),w=require("node:fs"),g=require("node:os");typeof Symbol.asyncDispose!="symbol"&&Object.defineProperty(Symbol,"asyncDispose",{configurable:!1,enumerable:!1,writable:!1,value:Symbol.for("asyncDispose")});class b{static{o(this,"FsFixture")}path;constructor(e){this.path=e}getPath(...e){return n.join(this.path,...e)}exists(e=""){return a.access(this.getPath(e)).then(()=>!0,()=>!1)}rm(e=""){return a.rm(this.getPath(e),{recursive:!0,force:!0})}cp(e,t,i){return t?t.endsWith(n.sep)&&(t+=n.basename(e)):t=n.basename(e),a.cp(e,this.getPath(t),i)}writeFile(e,t){return a.writeFile(this.getPath(e),t)}writeJson(e,t){return this.writeFile(e,JSON.stringify(t,null,2))}readFile(e,t){return a.readFile(this.getPath(e),t)}async[Symbol.asyncDispose](){await this.rm()}}const F=w.realpathSync(g.tmpdir()),v=`fs-fixture-${Date.now()}-${process.pid}`;let h=0;const P=o(()=>(h+=1,h),"getId");class u{static{o(this,"Symlink")}target;type;path;constructor(e,t){this.target=e,this.type=t}}const f=o((s,e,t)=>{const i=[];for(const l in s){if(!Object.hasOwn(s,l))continue;const r=n.join(e,l);let c=s[l];if(typeof c=="function"){const y=Object.assign(Object.create(t),{filePath:r}),p=c(y);if(p instanceof u){p.path=r,i.push(p);continue}else c=p}typeof c=="string"?i.push({path:r,content:c}):i.push(...f(c,r,t))}return i},"flattenFileTree"),d=o(async(s,e)=>{const t=e?.tempDir?n.resolve(e.tempDir):F,i=n.join(t,`${v}-${P()}/`);if(await a.mkdir(i,{recursive:!0}),s){if(typeof s=="string")await a.cp(s,i,{recursive:!0,filter:e?.templateFilter});else if(typeof s=="object"){const l={fixturePath:i,getPath:o((...r)=>n.join(i,...r),"getPath"),symlink:o((r,c)=>new u(r,c),"symlink")};await Promise.all(f(s,i,l).map(async r=>{await a.mkdir(n.dirname(r.path),{recursive:!0}),r instanceof u?await a.symlink(r.target,r.path,r.type):await a.writeFile(r.path,r.content)}))}}return new b(i)},"createFixture");exports.createFixture=d;
package/dist/index.d.cts CHANGED
@@ -24,7 +24,7 @@ declare class FsFixture {
24
24
  /**
25
25
  Copy a path into the fixture directory.
26
26
  */
27
- cp(sourcePath: string, destinationSubpath: string, options?: CopyOptions): Promise<void>;
27
+ cp(sourcePath: string, destinationSubpath?: string, options?: CopyOptions): Promise<void>;
28
28
  /**
29
29
  Create a file in the fixture directory.
30
30
  */
package/dist/index.d.mts CHANGED
@@ -24,7 +24,7 @@ declare class FsFixture {
24
24
  /**
25
25
  Copy a path into the fixture directory.
26
26
  */
27
- cp(sourcePath: string, destinationSubpath: string, options?: CopyOptions): Promise<void>;
27
+ cp(sourcePath: string, destinationSubpath?: string, options?: CopyOptions): Promise<void>;
28
28
  /**
29
29
  Create a file in the fixture directory.
30
30
  */
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- var y=Object.defineProperty;var o=(i,t)=>y(i,"name",{value:t,configurable:!0});import a from"node:fs/promises";import c from"node:path";import w from"node:fs";import g from"node:os";typeof Symbol.asyncDispose!="symbol"&&Object.defineProperty(Symbol,"asyncDispose",{configurable:!1,enumerable:!1,writable:!1,value:Symbol.for("asyncDispose")});class b{static{o(this,"FsFixture")}path;constructor(t){this.path=t}getPath(...t){return c.join(this.path,...t)}exists(t=""){return a.access(this.getPath(t)).then(()=>!0,()=>!1)}rm(t=""){return a.rm(this.getPath(t),{recursive:!0,force:!0})}cp(t,r,s){return a.cp(t,this.getPath(r),s)}writeFile(t,r){return a.writeFile(this.getPath(t),r)}writeJson(t,r){return this.writeFile(t,JSON.stringify(r,null,2))}readFile(t,r){return a.readFile(this.getPath(t),r)}async[Symbol.asyncDispose](){await this.rm()}}const d=w.realpathSync(g.tmpdir()),P=`fs-fixture-${Date.now()}-${process.pid}`;let u=0;const F=o(()=>(u+=1,u),"getId");class h{static{o(this,"Symlink")}target;type;path;constructor(t,r){this.target=t,this.type=r}}const f=o((i,t,r)=>{const s=[];for(const p in i){if(!Object.hasOwn(i,p))continue;const e=c.join(t,p);let n=i[p];if(typeof n=="function"){const m=Object.assign(Object.create(r),{filePath:e}),l=n(m);if(l instanceof h){l.path=e,s.push(l);continue}else n=l}typeof n=="string"?s.push({path:e,content:n}):s.push(...f(n,e,r))}return s},"flattenFileTree"),j=o(async(i,t)=>{const r=t?.tempDir?c.resolve(t.tempDir):d,s=c.join(r,`${P}-${F()}/`);if(await a.mkdir(s,{recursive:!0}),i){if(typeof i=="string")await a.cp(i,s,{recursive:!0,filter:t?.templateFilter});else if(typeof i=="object"){const p={fixturePath:s,getPath:o((...e)=>c.join(s,...e),"getPath"),symlink:o((e,n)=>new h(e,n),"symlink")};await Promise.all(f(i,s,p).map(async e=>{await a.mkdir(c.dirname(e.path),{recursive:!0}),e instanceof h?await a.symlink(e.target,e.path,e.type):await a.writeFile(e.path,e.content)}))}}return new b(s)},"createFixture");export{j as createFixture};
1
+ var u=Object.defineProperty;var c=(s,t)=>u(s,"name",{value:t,configurable:!0});import a from"node:fs/promises";import n from"node:path";import w from"node:fs";import g from"node:os";typeof Symbol.asyncDispose!="symbol"&&Object.defineProperty(Symbol,"asyncDispose",{configurable:!1,enumerable:!1,writable:!1,value:Symbol.for("asyncDispose")});class b{static{c(this,"FsFixture")}path;constructor(t){this.path=t}getPath(...t){return n.join(this.path,...t)}exists(t=""){return a.access(this.getPath(t)).then(()=>!0,()=>!1)}rm(t=""){return a.rm(this.getPath(t),{recursive:!0,force:!0})}cp(t,e,i){return e?e.endsWith(n.sep)&&(e+=n.basename(t)):e=n.basename(t),a.cp(t,this.getPath(e),i)}writeFile(t,e){return a.writeFile(this.getPath(t),e)}writeJson(t,e){return this.writeFile(t,JSON.stringify(e,null,2))}readFile(t,e){return a.readFile(this.getPath(t),e)}async[Symbol.asyncDispose](){await this.rm()}}const F=w.realpathSync(g.tmpdir()),P=`fs-fixture-${Date.now()}-${process.pid}`;let m=0;const d=c(()=>(m+=1,m),"getId");class f{static{c(this,"Symlink")}target;type;path;constructor(t,e){this.target=t,this.type=e}}const h=c((s,t,e)=>{const i=[];for(const p in s){if(!Object.hasOwn(s,p))continue;const r=n.join(t,p);let o=s[p];if(typeof o=="function"){const y=Object.assign(Object.create(e),{filePath:r}),l=o(y);if(l instanceof f){l.path=r,i.push(l);continue}else o=l}typeof o=="string"?i.push({path:r,content:o}):i.push(...h(o,r,e))}return i},"flattenFileTree"),j=c(async(s,t)=>{const e=t?.tempDir?n.resolve(t.tempDir):F,i=n.join(e,`${P}-${d()}/`);if(await a.mkdir(i,{recursive:!0}),s){if(typeof s=="string")await a.cp(s,i,{recursive:!0,filter:t?.templateFilter});else if(typeof s=="object"){const p={fixturePath:i,getPath:c((...r)=>n.join(i,...r),"getPath"),symlink:c((r,o)=>new f(r,o),"symlink")};await Promise.all(h(s,i,p).map(async r=>{await a.mkdir(n.dirname(r.path),{recursive:!0}),r instanceof f?await a.symlink(r.target,r.path,r.type):await a.writeFile(r.path,r.content)}))}}return new b(i)},"createFixture");export{j as createFixture};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fs-fixture",
3
- "version": "2.7.1",
3
+ "version": "2.7.2",
4
4
  "description": "Easily create test fixtures at a temporary file-system path",
5
5
  "keywords": [
6
6
  "test",