fs-fixture 2.6.0 → 2.7.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/README.md CHANGED
@@ -13,7 +13,7 @@ Tiny (`560 B` gzipped) and no dependencies!
13
13
 
14
14
  ### Example
15
15
  ```ts
16
- import fs from 'fs/promises'
16
+ import fs from 'node:fs/promises'
17
17
  import { createFixture } from 'fs-fixture'
18
18
 
19
19
  const fixture = await createFixture({
@@ -165,6 +165,11 @@ class FsFixture {
165
165
  */
166
166
  rm(subpath?: string): Promise<void>
167
167
 
168
+ /**
169
+ Copy a path into the fixture directory.
170
+ */
171
+ cp(sourcePath: string, destinationSubpath?: string): Promise<void>
172
+
168
173
  /**
169
174
  Create a file in the fixture directory.
170
175
  */
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var w=Object.defineProperty;var n=(r,t)=>w(r,"name",{value:t,configurable:!0});var c=require("node:fs/promises"),u=require("node:path"),h=require("fs/promises"),g=require("path"),b=require("fs"),v=require("os");typeof Symbol.asyncDispose!="symbol"&&Object.defineProperty(Symbol,"asyncDispose",{configurable:!1,enumerable:!1,writable:!1,value:Symbol.for("asyncDispose")});class F{static{n(this,"FsFixture")}path;constructor(t){this.path=t}getPath(...t){return g.join(this.path,...t)}exists(t=""){return h.access(this.getPath(t)).then(()=>!0,()=>!1)}rm(t=""){return h.rm(this.getPath(t),{recursive:!0,force:!0})}writeFile(t,i){return h.writeFile(this.getPath(t),i)}writeJson(t,i){return this.writeFile(t,JSON.stringify(i,null,2))}readFile(t,i){return h.readFile(this.getPath(t),i)}async[Symbol.asyncDispose](){await this.rm()}}const d=b.realpathSync(v.tmpdir()),P=`fs-fixture-${Date.now()}`;let y=0;const j=n(()=>(y+=1,y),"getId");class p{static{n(this,"Symlink")}target;type;path;constructor(t,i){this.target=t,this.type=i}}const f=n((r,t,i)=>{const s=[];for(const o in r){if(!Object.hasOwn(r,o))continue;const e=u.join(t,o);let a=r[o];if(typeof a=="function"){const m=Object.assign(Object.create(i),{filePath:e}),l=a(m);if(l instanceof p){l.path=e,s.push(l);continue}else a=l}typeof a=="string"?s.push({path:e,content:a}):s.push(...f(a,e,i))}return s},"flattenFileTree"),D=n(async(r,t)=>{const i=t?.tempDir?u.resolve(t.tempDir):d,s=u.join(i,`${P}-${j()}/`);if(await c.mkdir(s,{recursive:!0}),r){if(typeof r=="string")await c.cp(r,s,{recursive:!0,filter:t?.templateFilter});else if(typeof r=="object"){const o={fixturePath:s,getPath:n((...e)=>u.join(s,...e),"getPath"),symlink:n((e,a)=>new p(e,a),"symlink")};await Promise.all(f(r,s,o).map(async e=>{await c.mkdir(u.dirname(e.path),{recursive:!0}),e instanceof p?await c.symlink(e.target,e.path,e.type):await c.writeFile(e.path,e.content)}))}}return new F(s)},"createFixture");exports.createFixture=D;
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 F=w.realpathSync(g.tmpdir()),P=`fs-fixture-${Date.now()}`;let p=0;const d=c(()=>(p+=1,p),"getId");class h{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}),l=n(f);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(...y(n,e,r))}return s},"flattenFileTree"),v=c(async(i,t)=>{const r=t?.tempDir?o.resolve(t.tempDir):F,s=o.join(r,`${P}-${d()}/`);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 h(e,n),"symlink")};await Promise.all(y(i,s,u).map(async e=>{await a.mkdir(o.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");exports.createFixture=v;
package/dist/index.d.cts CHANGED
@@ -22,6 +22,10 @@ declare class FsFixture {
22
22
  */
23
23
  rm(subpath?: string): Promise<void>;
24
24
  /**
25
+ Copy a path into the fixture directory.
26
+ */
27
+ cp(sourcePath: string, destinationSubpath: string, options?: CopyOptions): Promise<void>;
28
+ /**
25
29
  Create a file in the fixture directory.
26
30
  */
27
31
  writeFile(filePath: string, content: string): Promise<void>;
package/dist/index.d.mts CHANGED
@@ -22,6 +22,10 @@ declare class FsFixture {
22
22
  */
23
23
  rm(subpath?: string): Promise<void>;
24
24
  /**
25
+ Copy a path into the fixture directory.
26
+ */
27
+ cp(sourcePath: string, destinationSubpath: string, options?: CopyOptions): Promise<void>;
28
+ /**
25
29
  Create a file in the fixture directory.
26
30
  */
27
31
  writeFile(filePath: string, content: string): Promise<void>;
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- var w=Object.defineProperty;var n=(r,t)=>w(r,"name",{value:t,configurable:!0});import c from"node:fs/promises";import p from"node:path";import f from"fs/promises";import g from"path";import b from"fs";import d from"os";typeof Symbol.asyncDispose!="symbol"&&Object.defineProperty(Symbol,"asyncDispose",{configurable:!1,enumerable:!1,writable:!1,value:Symbol.for("asyncDispose")});class F{static{n(this,"FsFixture")}path;constructor(t){this.path=t}getPath(...t){return g.join(this.path,...t)}exists(t=""){return f.access(this.getPath(t)).then(()=>!0,()=>!1)}rm(t=""){return f.rm(this.getPath(t),{recursive:!0,force:!0})}writeFile(t,i){return f.writeFile(this.getPath(t),i)}writeJson(t,i){return this.writeFile(t,JSON.stringify(i,null,2))}readFile(t,i){return f.readFile(this.getPath(t),i)}async[Symbol.asyncDispose](){await this.rm()}}const P=b.realpathSync(d.tmpdir()),j=`fs-fixture-${Date.now()}`;let m=0;const D=n(()=>(m+=1,m),"getId");class h{static{n(this,"Symlink")}target;type;path;constructor(t,i){this.target=t,this.type=i}}const u=n((r,t,i)=>{const s=[];for(const o in r){if(!Object.hasOwn(r,o))continue;const e=p.join(t,o);let a=r[o];if(typeof a=="function"){const y=Object.assign(Object.create(i),{filePath:e}),l=a(y);if(l instanceof h){l.path=e,s.push(l);continue}else a=l}typeof a=="string"?s.push({path:e,content:a}):s.push(...u(a,e,i))}return s},"flattenFileTree"),v=n(async(r,t)=>{const i=t?.tempDir?p.resolve(t.tempDir):P,s=p.join(i,`${j}-${D()}/`);if(await c.mkdir(s,{recursive:!0}),r){if(typeof r=="string")await c.cp(r,s,{recursive:!0,filter:t?.templateFilter});else if(typeof r=="object"){const o={fixturePath:s,getPath:n((...e)=>p.join(s,...e),"getPath"),symlink:n((e,a)=>new h(e,a),"symlink")};await Promise.all(u(r,s,o).map(async e=>{await c.mkdir(p.dirname(e.path),{recursive:!0}),e instanceof h?await c.symlink(e.target,e.path,e.type):await c.writeFile(e.path,e.content)}))}}return new F(s)},"createFixture");export{v as createFixture};
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 P=w.realpathSync(g.tmpdir()),d=`fs-fixture-${Date.now()}`;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):P,s=c.join(r,`${d}-${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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fs-fixture",
3
- "version": "2.6.0",
3
+ "version": "2.7.0",
4
4
  "description": "Easily create test fixtures at a temporary file-system path",
5
5
  "keywords": [
6
6
  "test",