fs-fixture 2.2.0 → 2.3.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
@@ -112,7 +112,7 @@ type Api = {
112
112
  filePath: string
113
113
 
114
114
  // Get path from the root of the fixture
115
- getPath: (subpath: string) => string
115
+ getPath: (...subpaths: string[]) => string
116
116
 
117
117
  // Create a symlink
118
118
  symlink: (target: string) => Symlink
@@ -136,7 +136,7 @@ class FsFixture {
136
136
  /**
137
137
  Get the full path to a subpath in the fixture directory.
138
138
  */
139
- getPath(subpath: string): string
139
+ getPath(...subpaths: string[]): string
140
140
 
141
141
  /**
142
142
  Check if the fixture exists. Pass in a subpath to check if it exists.
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var s=require("fs/promises"),n=require("path"),y=require("fs"),m=require("os");typeof Symbol.asyncDispose!="symbol"&&Object.defineProperty(Symbol,"asyncDispose",{configurable:!1,enumerable:!1,writable:!1,value:Symbol.for("asyncDispose")});class w{path;constructor(t){this.path=t}getPath(t){return n.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 g=y.realpathSync(m.tmpdir()),b=`fs-fixture-${Date.now()}`;let l=0;const F=()=>(l+=1,l);class h{target;path;constructor(t){this.target=t}}const p=(r,t,i)=>{const e=[];for(const u in r){if(!Object.hasOwn(r,u))continue;const o=n.join(t,u);let a=r[u];if(typeof a=="function"){const f=Object.assign(Object.create(i),{filePath:o}),c=a(f);if(c instanceof h){c.path=o,e.push(c);continue}else a=c}typeof a=="string"?e.push({path:o,content:a}):e.push(...p(a,o,i))}return e},P=async r=>{const t=n.join(g,`${b}-${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:e=>n.join(t,e),symlink:e=>new h(e)};await Promise.all(p(r,t,i).map(async e=>{await s.mkdir(n.dirname(e.path),{recursive:!0}),e instanceof h?await s.symlink(e.target,e.path):await s.writeFile(e.path,e.content)}))}}return new w(t)};exports.createFixture=P;
1
+ "use strict";var s=require("fs/promises"),n=require("path"),y=require("fs"),m=require("os");typeof Symbol.asyncDispose!="symbol"&&Object.defineProperty(Symbol,"asyncDispose",{configurable:!1,enumerable:!1,writable:!1,value:Symbol.for("asyncDispose")});class w{path;constructor(t){this.path=t}getPath(...t){return n.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 g=y.realpathSync(m.tmpdir()),b=`fs-fixture-${Date.now()}`;let l=0;const F=()=>(l+=1,l);class h{target;path;constructor(t){this.target=t}}const p=(r,t,i)=>{const e=[];for(const u in r){if(!Object.hasOwn(r,u))continue;const o=n.join(t,u);let a=r[u];if(typeof a=="function"){const f=Object.assign(Object.create(i),{filePath:o}),c=a(f);if(c instanceof h){c.path=o,e.push(c);continue}else a=c}typeof a=="string"?e.push({path:o,content:a}):e.push(...p(a,o,i))}return e},P=async r=>{const t=n.join(g,`${b}-${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:(...e)=>n.join(t,...e),symlink:e=>new h(e)};await Promise.all(p(r,t,i).map(async e=>{await s.mkdir(n.dirname(e.path),{recursive:!0}),e instanceof h?await s.symlink(e.target,e.path):await s.writeFile(e.path,e.content)}))}}return new w(t)};exports.createFixture=P;
package/dist/index.d.cts CHANGED
@@ -10,7 +10,7 @@ declare class FsFixture {
10
10
  /**
11
11
  Get the full path to a subpath in the fixture directory.
12
12
  */
13
- getPath(subpath: string): string;
13
+ getPath(...subpaths: string[]): string;
14
14
  /**
15
15
  Check if the fixture exists. Pass in a subpath to check if it exists.
16
16
  */
@@ -46,7 +46,7 @@ declare class Symlink {
46
46
  }
47
47
  type ApiBase = {
48
48
  fixturePath: string;
49
- getPath(subpath: string): string;
49
+ getPath(...subpaths: string[]): string;
50
50
  symlink(targetPath: string): Symlink;
51
51
  };
52
52
  type Api = ApiBase & {
package/dist/index.d.mts CHANGED
@@ -10,7 +10,7 @@ declare class FsFixture {
10
10
  /**
11
11
  Get the full path to a subpath in the fixture directory.
12
12
  */
13
- getPath(subpath: string): string;
13
+ getPath(...subpaths: string[]): string;
14
14
  /**
15
15
  Check if the fixture exists. Pass in a subpath to check if it exists.
16
16
  */
@@ -46,7 +46,7 @@ declare class Symlink {
46
46
  }
47
47
  type ApiBase = {
48
48
  fixturePath: string;
49
- getPath(subpath: string): string;
49
+ getPath(...subpaths: string[]): string;
50
50
  symlink(targetPath: string): Symlink;
51
51
  };
52
52
  type Api = ApiBase & {
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import s from"fs/promises";import n from"path";import m from"fs";import y from"os";typeof Symbol.asyncDispose!="symbol"&&Object.defineProperty(Symbol,"asyncDispose",{configurable:!1,enumerable:!1,writable:!1,value:Symbol.for("asyncDispose")});class w{path;constructor(t){this.path=t}getPath(t){return n.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 g=m.realpathSync(y.tmpdir()),b=`fs-fixture-${Date.now()}`;let l=0;const P=()=>(l+=1,l);class h{target;path;constructor(t){this.target=t}}const f=(r,t,i)=>{const e=[];for(const p in r){if(!Object.hasOwn(r,p))continue;const o=n.join(t,p);let a=r[p];if(typeof a=="function"){const u=Object.assign(Object.create(i),{filePath:o}),c=a(u);if(c instanceof h){c.path=o,e.push(c);continue}else a=c}typeof a=="string"?e.push({path:o,content:a}):e.push(...f(a,o,i))}return e},d=async r=>{const t=n.join(g,`${b}-${P()}/`);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:e=>n.join(t,e),symlink:e=>new h(e)};await Promise.all(f(r,t,i).map(async e=>{await s.mkdir(n.dirname(e.path),{recursive:!0}),e instanceof h?await s.symlink(e.target,e.path):await s.writeFile(e.path,e.content)}))}}return new w(t)};export{d as createFixture};
1
+ import s from"fs/promises";import n from"path";import m from"fs";import y from"os";typeof Symbol.asyncDispose!="symbol"&&Object.defineProperty(Symbol,"asyncDispose",{configurable:!1,enumerable:!1,writable:!1,value:Symbol.for("asyncDispose")});class w{path;constructor(t){this.path=t}getPath(...t){return n.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 g=m.realpathSync(y.tmpdir()),b=`fs-fixture-${Date.now()}`;let l=0;const P=()=>(l+=1,l);class h{target;path;constructor(t){this.target=t}}const f=(r,t,i)=>{const e=[];for(const p in r){if(!Object.hasOwn(r,p))continue;const o=n.join(t,p);let a=r[p];if(typeof a=="function"){const u=Object.assign(Object.create(i),{filePath:o}),c=a(u);if(c instanceof h){c.path=o,e.push(c);continue}else a=c}typeof a=="string"?e.push({path:o,content:a}):e.push(...f(a,o,i))}return e},d=async r=>{const t=n.join(g,`${b}-${P()}/`);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:(...e)=>n.join(t,...e),symlink:e=>new h(e)};await Promise.all(f(r,t,i).map(async e=>{await s.mkdir(n.dirname(e.path),{recursive:!0}),e instanceof h?await s.symlink(e.target,e.path):await s.writeFile(e.path,e.content)}))}}return new w(t)};export{d as createFixture};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fs-fixture",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "Easily create test fixtures at a temporary file-system path",
5
5
  "keywords": [
6
6
  "test",