fs-fixture 2.7.1 → 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 +5 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +10 -5
- package/dist/index.d.mts +10 -5
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
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
|
|
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
|
@@ -24,7 +24,11 @@ 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
|
+
/**
|
|
29
|
+
Create a new folder in the fixture directory.
|
|
30
|
+
*/
|
|
31
|
+
mkdir(folderPath: string): Promise<string | undefined>;
|
|
28
32
|
/**
|
|
29
33
|
Create a file in the fixture directory.
|
|
30
34
|
*/
|
|
@@ -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
|
-
|
|
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
|
|
91
|
+
export { type CreateFixtureOptions, type FsFixtureType as FsFixture, createFixture };
|
package/dist/index.d.mts
CHANGED
|
@@ -24,7 +24,11 @@ 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
|
+
/**
|
|
29
|
+
Create a new folder in the fixture directory.
|
|
30
|
+
*/
|
|
31
|
+
mkdir(folderPath: string): Promise<string | undefined>;
|
|
28
32
|
/**
|
|
29
33
|
Create a file in the fixture directory.
|
|
30
34
|
*/
|
|
@@ -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
|
-
|
|
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
|
|
91
|
+
export { type CreateFixtureOptions, type FsFixtureType as FsFixture, createFixture };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
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};
|