fs-fixture 2.7.2 → 2.8.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
@@ -170,6 +170,11 @@ class FsFixture {
170
170
  */
171
171
  cp(sourcePath: string, destinationSubpath?: string): Promise<void>
172
172
 
173
+ /**
174
+ Create a new folder in the fixture directory.
175
+ */
176
+ mkdir(folderPath: string): Promise<void>
177
+
173
178
  /**
174
179
  Create a file in the fixture directory.
175
180
  */
package/dist/index.cjs CHANGED
@@ -1 +1 @@
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;
1
+ "use strict";var d=Object.defineProperty;var n=(s,t)=>d(s,"name",{value:t,configurable:!0});var a=require("node:fs/promises"),c=require("node:path"),v=require("node:fs"),F=require("node:os");typeof Symbol.asyncDispose!="symbol"&&Object.defineProperty(Symbol,"asyncDispose",{configurable:!1,enumerable:!1,writable:!1,value:Symbol.for("asyncDispose")});class b{static{n(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,i){return r?r.endsWith(c.sep)&&(r+=c.basename(t)):r=c.basename(t),a.cp(t,this.getPath(r),i)}mkdir(t){return a.mkdir(this.getPath(t),{recursive:!0})}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=v.realpathSync(F.tmpdir()),D=`fs-fixture-${Date.now()}-${process.pid}`;let p=0;const j=n(()=>(p+=1,p),"getId");class y{static{n(this,"Path")}path;constructor(t){this.path=t}}class f extends y{static{n(this,"Directory")}}class m extends y{static{n(this,"File")}content;constructor(t,r){super(t),this.content=r}}class l{static{n(this,"Symlink")}target;type;path;constructor(t,r){this.target=t,this.type=r}}const w=n((s,t,r)=>{const i=[];for(const u in s){if(!Object.hasOwn(s,u))continue;const e=c.join(t,u);let o=s[u];if(typeof o=="function"){const g=Object.assign(Object.create(r),{filePath:e}),h=o(g);if(h instanceof l){h.path=e,i.push(h);continue}else o=h}typeof o=="string"?i.push(new m(e,o)):i.push(new f(e),...w(o,e,r))}return i},"flattenFileTree"),k=n(async(s,t)=>{const r=t?.tempDir?c.resolve(t.tempDir):P,i=c.join(r,`${D}-${j()}/`);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 u={fixturePath:i,getPath:n((...e)=>c.join(i,...e),"getPath"),symlink:n((e,o)=>new l(e,o),"symlink")};await Promise.all(w(s,i,u).map(async e=>{e instanceof f?await a.mkdir(e.path,{recursive:!0}):e instanceof l?(await a.mkdir(c.dirname(e.path),{recursive:!0}),await a.symlink(e.target,e.path,e.type)):e instanceof m&&(await a.mkdir(c.dirname(e.path),{recursive:!0}),await a.writeFile(e.path,e.content))}))}}return new b(i)},"createFixture");exports.createFixture=k;
package/dist/index.d.cts CHANGED
@@ -26,6 +26,10 @@ declare class FsFixture {
26
26
  */
27
27
  cp(sourcePath: string, destinationSubpath?: string, options?: CopyOptions): Promise<void>;
28
28
  /**
29
+ Create a new folder in the fixture directory.
30
+ */
31
+ mkdir(folderPath: string): Promise<string | undefined>;
32
+ /**
29
33
  Create a file in the fixture directory.
30
34
  */
31
35
  writeFile(filePath: string, content: string): Promise<void>;
@@ -46,7 +50,6 @@ declare class FsFixture {
46
50
  }
47
51
  type FsFixtureType = FsFixture;
48
52
 
49
- type FilterFunction = CopyOptions['filter'];
50
53
  type SymlinkType = 'file' | 'dir' | 'junction';
51
54
  declare class Symlink {
52
55
  target: string;
@@ -59,8 +62,8 @@ type ApiBase = {
59
62
  getPath(...subpaths: string[]): string;
60
63
  symlink(targetPath: string,
61
64
  /**
62
- * Symlink type for Windows. Defaults to auto-detect by Node.
63
- */
65
+ * Symlink type for Windows. Defaults to auto-detect by Node.
66
+ */
64
67
  type?: SymlinkType): Symlink;
65
68
  };
66
69
  type Api = ApiBase & {
@@ -69,6 +72,8 @@ type Api = ApiBase & {
69
72
  type FileTree = {
70
73
  [path: string]: string | FileTree | ((api: Api) => string | Symlink);
71
74
  };
75
+
76
+ type FilterFunction = CopyOptions['filter'];
72
77
  type CreateFixtureOptions = {
73
78
  /**
74
79
  * The temporary directory to create the fixtures in.
@@ -83,4 +88,4 @@ type CreateFixtureOptions = {
83
88
  };
84
89
  declare const createFixture: (source?: string | FileTree, options?: CreateFixtureOptions) => Promise<FsFixture>;
85
90
 
86
- export { type CreateFixtureOptions, type FileTree, type FsFixtureType as FsFixture, createFixture };
91
+ export { type CreateFixtureOptions, type FsFixtureType as FsFixture, createFixture };
package/dist/index.d.mts CHANGED
@@ -26,6 +26,10 @@ declare class FsFixture {
26
26
  */
27
27
  cp(sourcePath: string, destinationSubpath?: string, options?: CopyOptions): Promise<void>;
28
28
  /**
29
+ Create a new folder in the fixture directory.
30
+ */
31
+ mkdir(folderPath: string): Promise<string | undefined>;
32
+ /**
29
33
  Create a file in the fixture directory.
30
34
  */
31
35
  writeFile(filePath: string, content: string): Promise<void>;
@@ -46,7 +50,6 @@ declare class FsFixture {
46
50
  }
47
51
  type FsFixtureType = FsFixture;
48
52
 
49
- type FilterFunction = CopyOptions['filter'];
50
53
  type SymlinkType = 'file' | 'dir' | 'junction';
51
54
  declare class Symlink {
52
55
  target: string;
@@ -59,8 +62,8 @@ type ApiBase = {
59
62
  getPath(...subpaths: string[]): string;
60
63
  symlink(targetPath: string,
61
64
  /**
62
- * Symlink type for Windows. Defaults to auto-detect by Node.
63
- */
65
+ * Symlink type for Windows. Defaults to auto-detect by Node.
66
+ */
64
67
  type?: SymlinkType): Symlink;
65
68
  };
66
69
  type Api = ApiBase & {
@@ -69,6 +72,8 @@ type Api = ApiBase & {
69
72
  type FileTree = {
70
73
  [path: string]: string | FileTree | ((api: Api) => string | Symlink);
71
74
  };
75
+
76
+ type FilterFunction = CopyOptions['filter'];
72
77
  type CreateFixtureOptions = {
73
78
  /**
74
79
  * The temporary directory to create the fixtures in.
@@ -83,4 +88,4 @@ type CreateFixtureOptions = {
83
88
  };
84
89
  declare const createFixture: (source?: string | FileTree, options?: CreateFixtureOptions) => Promise<FsFixture>;
85
90
 
86
- export { type CreateFixtureOptions, type FileTree, type FsFixtureType as FsFixture, createFixture };
91
+ export { type CreateFixtureOptions, type FsFixtureType as FsFixture, createFixture };
package/dist/index.mjs CHANGED
@@ -1 +1 @@
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};
1
+ var d=Object.defineProperty;var n=(s,t)=>d(s,"name",{value:t,configurable:!0});import a from"node:fs/promises";import c from"node:path";import b from"node:fs";import F from"node:os";typeof Symbol.asyncDispose!="symbol"&&Object.defineProperty(Symbol,"asyncDispose",{configurable:!1,enumerable:!1,writable:!1,value:Symbol.for("asyncDispose")});class P{static{n(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,i){return r?r.endsWith(c.sep)&&(r+=c.basename(t)):r=c.basename(t),a.cp(t,this.getPath(r),i)}mkdir(t){return a.mkdir(this.getPath(t),{recursive:!0})}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 v=b.realpathSync(F.tmpdir()),D=`fs-fixture-${Date.now()}-${process.pid}`;let m=0;const j=n(()=>(m+=1,m),"getId");class u{static{n(this,"Path")}path;constructor(t){this.path=t}}class f extends u{static{n(this,"Directory")}}class y extends u{static{n(this,"File")}content;constructor(t,r){super(t),this.content=r}}class l{static{n(this,"Symlink")}target;type;path;constructor(t,r){this.target=t,this.type=r}}const w=n((s,t,r)=>{const i=[];for(const p in s){if(!Object.hasOwn(s,p))continue;const e=c.join(t,p);let o=s[p];if(typeof o=="function"){const g=Object.assign(Object.create(r),{filePath:e}),h=o(g);if(h instanceof l){h.path=e,i.push(h);continue}else o=h}typeof o=="string"?i.push(new y(e,o)):i.push(new f(e),...w(o,e,r))}return i},"flattenFileTree"),k=n(async(s,t)=>{const r=t?.tempDir?c.resolve(t.tempDir):v,i=c.join(r,`${D}-${j()}/`);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:n((...e)=>c.join(i,...e),"getPath"),symlink:n((e,o)=>new l(e,o),"symlink")};await Promise.all(w(s,i,p).map(async e=>{e instanceof f?await a.mkdir(e.path,{recursive:!0}):e instanceof l?(await a.mkdir(c.dirname(e.path),{recursive:!0}),await a.symlink(e.target,e.path,e.type)):e instanceof y&&(await a.mkdir(c.dirname(e.path),{recursive:!0}),await a.writeFile(e.path,e.content))}))}}return new P(i)},"createFixture");export{k as createFixture};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fs-fixture",
3
- "version": "2.7.2",
3
+ "version": "2.8.0",
4
4
  "description": "Easily create test fixtures at a temporary file-system path",
5
5
  "keywords": [
6
6
  "test",