fs-fixture 2.7.1 → 2.7.2
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 +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var m=Object.defineProperty;var
|
|
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;
|
package/dist/index.d.cts
CHANGED
|
@@ -24,7 +24,7 @@ declare class FsFixture {
|
|
|
24
24
|
/**
|
|
25
25
|
Copy a path into the fixture directory.
|
|
26
26
|
*/
|
|
27
|
-
cp(sourcePath: string, destinationSubpath
|
|
27
|
+
cp(sourcePath: string, destinationSubpath?: string, options?: CopyOptions): Promise<void>;
|
|
28
28
|
/**
|
|
29
29
|
Create a file in the fixture directory.
|
|
30
30
|
*/
|
package/dist/index.d.mts
CHANGED
|
@@ -24,7 +24,7 @@ declare class FsFixture {
|
|
|
24
24
|
/**
|
|
25
25
|
Copy a path into the fixture directory.
|
|
26
26
|
*/
|
|
27
|
-
cp(sourcePath: string, destinationSubpath
|
|
27
|
+
cp(sourcePath: string, destinationSubpath?: string, options?: CopyOptions): Promise<void>;
|
|
28
28
|
/**
|
|
29
29
|
Create a file in the fixture directory.
|
|
30
30
|
*/
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
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};
|