fs-fixture 2.3.0 → 2.4.1

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 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 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;
package/dist/index.d.cts CHANGED
@@ -38,16 +38,23 @@ declare class FsFixture {
38
38
  */
39
39
  [Symbol.asyncDispose](): Promise<void>;
40
40
  }
41
+ type FsFixtureType = FsFixture;
41
42
 
43
+ type SymlinkType = 'file' | 'dir' | 'junction';
42
44
  declare class Symlink {
43
45
  target: string;
46
+ type?: SymlinkType;
44
47
  path?: string;
45
- constructor(target: string);
48
+ constructor(target: string, type?: SymlinkType);
46
49
  }
47
50
  type ApiBase = {
48
51
  fixturePath: string;
49
52
  getPath(...subpaths: string[]): string;
50
- symlink(targetPath: string): Symlink;
53
+ symlink(targetPath: string,
54
+ /**
55
+ * Symlink type for Windows. Defaults to auto-detect by Node.
56
+ */
57
+ type?: SymlinkType): Symlink;
51
58
  };
52
59
  type Api = ApiBase & {
53
60
  filePath: string;
@@ -57,4 +64,4 @@ type FileTree = {
57
64
  };
58
65
  declare const createFixture: (source?: string | FileTree) => Promise<FsFixture>;
59
66
 
60
- export { type FileTree, FsFixture, createFixture };
67
+ export { type FileTree, type FsFixtureType as FsFixture, createFixture };
package/dist/index.d.mts CHANGED
@@ -38,16 +38,23 @@ declare class FsFixture {
38
38
  */
39
39
  [Symbol.asyncDispose](): Promise<void>;
40
40
  }
41
+ type FsFixtureType = FsFixture;
41
42
 
43
+ type SymlinkType = 'file' | 'dir' | 'junction';
42
44
  declare class Symlink {
43
45
  target: string;
46
+ type?: SymlinkType;
44
47
  path?: string;
45
- constructor(target: string);
48
+ constructor(target: string, type?: SymlinkType);
46
49
  }
47
50
  type ApiBase = {
48
51
  fixturePath: string;
49
52
  getPath(...subpaths: string[]): string;
50
- symlink(targetPath: string): Symlink;
53
+ symlink(targetPath: string,
54
+ /**
55
+ * Symlink type for Windows. Defaults to auto-detect by Node.
56
+ */
57
+ type?: SymlinkType): Symlink;
51
58
  };
52
59
  type Api = ApiBase & {
53
60
  filePath: string;
@@ -57,4 +64,4 @@ type FileTree = {
57
64
  };
58
65
  declare const createFixture: (source?: string | FileTree) => Promise<FsFixture>;
59
66
 
60
- export { type FileTree, FsFixture, createFixture };
67
+ export { type FileTree, type FsFixtureType as FsFixture, createFixture };
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
+ 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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fs-fixture",
3
- "version": "2.3.0",
3
+ "version": "2.4.1",
4
4
  "description": "Easily create test fixtures at a temporary file-system path",
5
5
  "keywords": [
6
6
  "test",