fs-fixture 2.4.0 → 2.5.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/dist/index.cjs +1 -1
- package/dist/index.d.cts +10 -2
- package/dist/index.d.mts +10 -2
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var m=Object.defineProperty;var o=(r,t)=>m(r,"name",{value:t,configurable:!0});var a=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{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})}writeFile(t,i){return a.writeFile(this.getPath(t),i)}writeJson(t,i){return this.writeFile(t,JSON.stringify(i,null,2))}readFile(t,i){return a.readFile(this.getPath(t),i)}async[Symbol.asyncDispose](){await this.rm()}}const d=w.realpathSync(g.tmpdir()),v=`fs-fixture-${Date.now()}`;let p=0;const F=o(()=>(p+=1,p),"getId");class l{static{o(this,"Symlink")}target;type;path;constructor(t,i){this.target=t,this.type=i}}const y=o((r,t,i)=>{const s=[];for(const u in r){if(!Object.hasOwn(r,u))continue;const e=c.join(t,u);let n=r[u];if(typeof n=="function"){const f=Object.assign(Object.create(i),{filePath:e}),h=n(f);if(h instanceof l){h.path=e,s.push(h);continue}else n=h}typeof n=="string"?s.push({path:e,content:n}):s.push(...y(n,e,i))}return s},"flattenFileTree"),P=o(async(r,t)=>{const i=t?.tempDir?c.resolve(t.tempDir):d,s=c.join(i,`${v}-${F()}/`);if(await a.mkdir(s,{recursive:!0}),r){if(typeof r=="string")await a.cp(r,s,{recursive:!0});else if(typeof r=="object"){const u={fixturePath:s,getPath:o((...e)=>c.join(s,...e),"getPath"),symlink:o((e,n)=>new l(e,n),"symlink")};await Promise.all(y(r,s,u).map(async e=>{await a.mkdir(c.dirname(e.path),{recursive:!0}),e instanceof l?await a.symlink(e.target,e.path,e.type):await a.writeFile(e.path,e.content)}))}}return new b(s)},"createFixture");exports.createFixture=P;
|
package/dist/index.d.cts
CHANGED
|
@@ -38,6 +38,7 @@ declare class FsFixture {
|
|
|
38
38
|
*/
|
|
39
39
|
[Symbol.asyncDispose](): Promise<void>;
|
|
40
40
|
}
|
|
41
|
+
type FsFixtureType = FsFixture;
|
|
41
42
|
|
|
42
43
|
type SymlinkType = 'file' | 'dir' | 'junction';
|
|
43
44
|
declare class Symlink {
|
|
@@ -61,6 +62,13 @@ type Api = ApiBase & {
|
|
|
61
62
|
type FileTree = {
|
|
62
63
|
[path: string]: string | FileTree | ((api: Api) => string | Symlink);
|
|
63
64
|
};
|
|
64
|
-
|
|
65
|
+
type CreateFixtureOptions = {
|
|
66
|
+
/**
|
|
67
|
+
* The temporary directory to create the fixtures in.
|
|
68
|
+
* Defaults to `os.tmpdir()`.
|
|
69
|
+
*/
|
|
70
|
+
tempDir?: string;
|
|
71
|
+
};
|
|
72
|
+
declare const createFixture: (source?: string | FileTree, options?: CreateFixtureOptions) => Promise<FsFixture>;
|
|
65
73
|
|
|
66
|
-
export { type FileTree, FsFixture, createFixture };
|
|
74
|
+
export { type CreateFixtureOptions, type FileTree, type FsFixtureType as FsFixture, createFixture };
|
package/dist/index.d.mts
CHANGED
|
@@ -38,6 +38,7 @@ declare class FsFixture {
|
|
|
38
38
|
*/
|
|
39
39
|
[Symbol.asyncDispose](): Promise<void>;
|
|
40
40
|
}
|
|
41
|
+
type FsFixtureType = FsFixture;
|
|
41
42
|
|
|
42
43
|
type SymlinkType = 'file' | 'dir' | 'junction';
|
|
43
44
|
declare class Symlink {
|
|
@@ -61,6 +62,13 @@ type Api = ApiBase & {
|
|
|
61
62
|
type FileTree = {
|
|
62
63
|
[path: string]: string | FileTree | ((api: Api) => string | Symlink);
|
|
63
64
|
};
|
|
64
|
-
|
|
65
|
+
type CreateFixtureOptions = {
|
|
66
|
+
/**
|
|
67
|
+
* The temporary directory to create the fixtures in.
|
|
68
|
+
* Defaults to `os.tmpdir()`.
|
|
69
|
+
*/
|
|
70
|
+
tempDir?: string;
|
|
71
|
+
};
|
|
72
|
+
declare const createFixture: (source?: string | FileTree, options?: CreateFixtureOptions) => Promise<FsFixture>;
|
|
65
73
|
|
|
66
|
-
export { type FileTree, FsFixture, createFixture };
|
|
74
|
+
export { type CreateFixtureOptions, type FileTree, type FsFixtureType as FsFixture, createFixture };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
var y=Object.defineProperty;var o=(r,t)=>y(r,"name",{value:t,configurable:!0});import a 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{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})}writeFile(t,i){return a.writeFile(this.getPath(t),i)}writeJson(t,i){return this.writeFile(t,JSON.stringify(i,null,2))}readFile(t,i){return a.readFile(this.getPath(t),i)}async[Symbol.asyncDispose](){await this.rm()}}const d=w.realpathSync(g.tmpdir()),P=`fs-fixture-${Date.now()}`;let u=0;const F=o(()=>(u+=1,u),"getId");class l{static{o(this,"Symlink")}target;type;path;constructor(t,i){this.target=t,this.type=i}}const f=o((r,t,i)=>{const s=[];for(const p in r){if(!Object.hasOwn(r,p))continue;const e=c.join(t,p);let n=r[p];if(typeof n=="function"){const m=Object.assign(Object.create(i),{filePath:e}),h=n(m);if(h instanceof l){h.path=e,s.push(h);continue}else n=h}typeof n=="string"?s.push({path:e,content:n}):s.push(...f(n,e,i))}return s},"flattenFileTree"),j=o(async(r,t)=>{const i=t?.tempDir?c.resolve(t.tempDir):d,s=c.join(i,`${P}-${F()}/`);if(await a.mkdir(s,{recursive:!0}),r){if(typeof r=="string")await a.cp(r,s,{recursive:!0});else if(typeof r=="object"){const p={fixturePath:s,getPath:o((...e)=>c.join(s,...e),"getPath"),symlink:o((e,n)=>new l(e,n),"symlink")};await Promise.all(f(r,s,p).map(async e=>{await a.mkdir(c.dirname(e.path),{recursive:!0}),e instanceof l?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};
|