fs-fixture 2.4.1 → 2.5.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.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var m=Object.defineProperty;var a=(r,t)=>m(r,"name",{value:t,configurable:!0});var s=require("fs/promises"),c=require("path"),w=require("fs"),g=require("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(t){this.path=t}getPath(...t){return c.join(this.path,...t)}exists(t=""){return s.access(this.getPath(t)).then(()=>!0,()=>!1)}rm(t=""){return s.rm(this.getPath(t),{recursive:!0,force:!0})}writeFile(t,i){return s.writeFile(this.getPath(t),i)}writeJson(t,i){return this.writeFile(t,JSON.stringify(i,null,2))}readFile(t,i){return s.readFile(this.getPath(t),i)}async[Symbol.asyncDispose](){await this.rm()}}const F=w.realpathSync(g.tmpdir()),P=`fs-fixture-${Date.now()}`;let p=0;const d=a(()=>(p+=1,p),"getId");class l{static{a(this,"Symlink")}target;type;path;constructor(t,i){this.target=t,this.type=i}}const y=a((r,t,i)=>{const e=[];for(const o in r){if(!Object.hasOwn(r,o))continue;const u=c.join(t,o);let n=r[o];if(typeof n=="function"){const f=Object.assign(Object.create(i),{filePath:u}),h=n(f);if(h instanceof l){h.path=u,e.push(h);continue}else n=h}typeof n=="string"?e.push({path:u,content:n}):e.push(...y(n,u,i))}return e},"flattenFileTree"),j=a(async r=>{const t=c.join(F,`${P}-${d()}/`);if(await s.mkdir(t,{recursive:!0}),r){if(typeof r=="string")await s.cp(r,t,{recursive:!0});else if(typeof r=="object"){const i={fixturePath:t,getPath:a((...e)=>c.join(t,...e),"getPath"),symlink:a((e,o)=>new l(e,o),"symlink")};await Promise.all(y(r,t,i).map(async e=>{await s.mkdir(c.dirname(e.path),{recursive:!0}),e instanceof l?await s.symlink(e.target,e.path,e.type):await s.writeFile(e.path,e.content)}))}}return new b(t)},"createFixture");exports.createFixture=j;
1
+ "use strict";var m=Object.defineProperty;var o=(r,t)=>m(r,"name",{value:t,configurable:!0});var a=require("fs/promises"),c=require("path"),w=require("fs"),g=require("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})}writeFile(t,i){return a.writeFile(this.getPath(t),i)}writeJson(t,i){return this.writeFile(t,JSON.stringify(i,null,2))}readFile(t,i){return a.readFile(this.getPath(t),i)}async[Symbol.asyncDispose](){await this.rm()}}const d=w.realpathSync(g.tmpdir()),v=`fs-fixture-${Date.now()}`;let p=0;const F=o(()=>(p+=1,p),"getId");class l{static{o(this,"Symlink")}target;type;path;constructor(t,i){this.target=t,this.type=i}}const y=o((r,t,i)=>{const s=[];for(const u in r){if(!Object.hasOwn(r,u))continue;const e=c.join(t,u);let n=r[u];if(typeof n=="function"){const f=Object.assign(Object.create(i),{filePath:e}),h=n(f);if(h instanceof l){h.path=e,s.push(h);continue}else n=h}typeof n=="string"?s.push({path:e,content:n}):s.push(...y(n,e,i))}return s},"flattenFileTree"),P=o(async(r,t)=>{const i=t?.tempDir?c.resolve(t.tempDir):d,s=c.join(i,`${v}-${F()}/`);if(await a.mkdir(s,{recursive:!0}),r){if(typeof r=="string")await a.cp(r,s,{recursive:!0});else if(typeof r=="object"){const u={fixturePath:s,getPath:o((...e)=>c.join(s,...e),"getPath"),symlink:o((e,n)=>new l(e,n),"symlink")};await Promise.all(y(r,s,u).map(async e=>{await a.mkdir(c.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=P;
package/dist/index.d.cts CHANGED
@@ -62,6 +62,13 @@ type Api = ApiBase & {
62
62
  type FileTree = {
63
63
  [path: string]: string | FileTree | ((api: Api) => string | Symlink);
64
64
  };
65
- declare const createFixture: (source?: string | FileTree) => Promise<FsFixture>;
65
+ type CreateFixtureOptions = {
66
+ /**
67
+ * The temporary directory to create the fixtures in.
68
+ * Defaults to `os.tmpdir()`.
69
+ */
70
+ tempDir?: string;
71
+ };
72
+ declare const createFixture: (source?: string | FileTree, options?: CreateFixtureOptions) => Promise<FsFixture>;
66
73
 
67
- export { type FileTree, type FsFixtureType as FsFixture, createFixture };
74
+ export { type CreateFixtureOptions, type FileTree, type FsFixtureType as FsFixture, createFixture };
package/dist/index.d.mts CHANGED
@@ -62,6 +62,13 @@ type Api = ApiBase & {
62
62
  type FileTree = {
63
63
  [path: string]: string | FileTree | ((api: Api) => string | Symlink);
64
64
  };
65
- declare const createFixture: (source?: string | FileTree) => Promise<FsFixture>;
65
+ type CreateFixtureOptions = {
66
+ /**
67
+ * The temporary directory to create the fixtures in.
68
+ * Defaults to `os.tmpdir()`.
69
+ */
70
+ tempDir?: string;
71
+ };
72
+ declare const createFixture: (source?: string | FileTree, options?: CreateFixtureOptions) => Promise<FsFixture>;
66
73
 
67
- export { type FileTree, type FsFixtureType as FsFixture, createFixture };
74
+ export { type CreateFixtureOptions, type FileTree, type FsFixtureType as FsFixture, createFixture };
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- var m=Object.defineProperty;var a=(r,t)=>m(r,"name",{value:t,configurable:!0});import s from"fs/promises";import c from"path";import w from"fs";import g from"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(t){this.path=t}getPath(...t){return c.join(this.path,...t)}exists(t=""){return s.access(this.getPath(t)).then(()=>!0,()=>!1)}rm(t=""){return s.rm(this.getPath(t),{recursive:!0,force:!0})}writeFile(t,i){return s.writeFile(this.getPath(t),i)}writeJson(t,i){return this.writeFile(t,JSON.stringify(i,null,2))}readFile(t,i){return s.readFile(this.getPath(t),i)}async[Symbol.asyncDispose](){await this.rm()}}const P=w.realpathSync(g.tmpdir()),d=`fs-fixture-${Date.now()}`;let u=0;const F=a(()=>(u+=1,u),"getId");class l{static{a(this,"Symlink")}target;type;path;constructor(t,i){this.target=t,this.type=i}}const f=a((r,t,i)=>{const e=[];for(const o in r){if(!Object.hasOwn(r,o))continue;const p=c.join(t,o);let n=r[o];if(typeof n=="function"){const y=Object.assign(Object.create(i),{filePath:p}),h=n(y);if(h instanceof l){h.path=p,e.push(h);continue}else n=h}typeof n=="string"?e.push({path:p,content:n}):e.push(...f(n,p,i))}return e},"flattenFileTree"),j=a(async r=>{const t=c.join(P,`${d}-${F()}/`);if(await s.mkdir(t,{recursive:!0}),r){if(typeof r=="string")await s.cp(r,t,{recursive:!0});else if(typeof r=="object"){const i={fixturePath:t,getPath:a((...e)=>c.join(t,...e),"getPath"),symlink:a((e,o)=>new l(e,o),"symlink")};await Promise.all(f(r,t,i).map(async e=>{await s.mkdir(c.dirname(e.path),{recursive:!0}),e instanceof l?await s.symlink(e.target,e.path,e.type):await s.writeFile(e.path,e.content)}))}}return new b(t)},"createFixture");export{j as createFixture};
1
+ var y=Object.defineProperty;var o=(r,t)=>y(r,"name",{value:t,configurable:!0});import a from"fs/promises";import c from"path";import w from"fs";import g from"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})}writeFile(t,i){return a.writeFile(this.getPath(t),i)}writeJson(t,i){return this.writeFile(t,JSON.stringify(i,null,2))}readFile(t,i){return a.readFile(this.getPath(t),i)}async[Symbol.asyncDispose](){await this.rm()}}const d=w.realpathSync(g.tmpdir()),P=`fs-fixture-${Date.now()}`;let u=0;const F=o(()=>(u+=1,u),"getId");class l{static{o(this,"Symlink")}target;type;path;constructor(t,i){this.target=t,this.type=i}}const f=o((r,t,i)=>{const s=[];for(const p in r){if(!Object.hasOwn(r,p))continue;const e=c.join(t,p);let n=r[p];if(typeof n=="function"){const m=Object.assign(Object.create(i),{filePath:e}),h=n(m);if(h instanceof l){h.path=e,s.push(h);continue}else n=h}typeof n=="string"?s.push({path:e,content:n}):s.push(...f(n,e,i))}return s},"flattenFileTree"),j=o(async(r,t)=>{const i=t?.tempDir?c.resolve(t.tempDir):d,s=c.join(i,`${P}-${F()}/`);if(await a.mkdir(s,{recursive:!0}),r){if(typeof r=="string")await a.cp(r,s,{recursive:!0});else if(typeof r=="object"){const p={fixturePath:s,getPath:o((...e)=>c.join(s,...e),"getPath"),symlink:o((e,n)=>new l(e,n),"symlink")};await Promise.all(f(r,s,p).map(async e=>{await a.mkdir(c.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");export{j as createFixture};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fs-fixture",
3
- "version": "2.4.1",
3
+ "version": "2.5.0",
4
4
  "description": "Easily create test fixtures at a temporary file-system path",
5
5
  "keywords": [
6
6
  "test",