fs-fixture 2.2.0 → 2.4.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 +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +10 -4
- package/dist/index.d.mts +10 -4
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -112,7 +112,7 @@ type Api = {
|
|
|
112
112
|
filePath: string
|
|
113
113
|
|
|
114
114
|
// Get path from the root of the fixture
|
|
115
|
-
getPath: (
|
|
115
|
+
getPath: (...subpaths: string[]) => string
|
|
116
116
|
|
|
117
117
|
// Create a symlink
|
|
118
118
|
symlink: (target: string) => Symlink
|
|
@@ -136,7 +136,7 @@ class FsFixture {
|
|
|
136
136
|
/**
|
|
137
137
|
Get the full path to a subpath in the fixture directory.
|
|
138
138
|
*/
|
|
139
|
-
getPath(
|
|
139
|
+
getPath(...subpaths: string[]): string
|
|
140
140
|
|
|
141
141
|
/**
|
|
142
142
|
Check if the fixture exists. Pass in a subpath to check if it exists.
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var s=require("fs/promises"),
|
|
1
|
+
"use strict";var s=require("fs/promises"),o=require("path"),f=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 o.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,r){return s.writeFile(this.getPath(t),r)}writeJson(t,r){return this.writeFile(t,JSON.stringify(r,null,2))}readFile(t,r){return s.readFile(this.getPath(t),r)}async[Symbol.asyncDispose](){await this.rm()}}const g=f.realpathSync(m.tmpdir()),b=`fs-fixture-${Date.now()}`;let l=0;const F=()=>(l+=1,l);class h{target;type;path;constructor(t,r){this.target=t,this.type=r}}const p=(i,t,r)=>{const e=[];for(const n in i){if(!Object.hasOwn(i,n))continue;const c=o.join(t,n);let a=i[n];if(typeof a=="function"){const y=Object.assign(Object.create(r),{filePath:c}),u=a(y);if(u instanceof h){u.path=c,e.push(u);continue}else a=u}typeof a=="string"?e.push({path:c,content:a}):e.push(...p(a,c,r))}return e},P=async i=>{const t=o.join(g,`${b}-${F()}/`);if(await s.mkdir(t,{recursive:!0}),i){if(typeof i=="string")await s.cp(i,t,{recursive:!0});else if(typeof i=="object"){const r={fixturePath:t,getPath:(...e)=>o.join(t,...e),symlink:(e,n)=>new h(e,n)};await Promise.all(p(i,t,r).map(async e=>{await s.mkdir(o.dirname(e.path),{recursive:!0}),e instanceof h?await s.symlink(e.target,e.path,e.type):await s.writeFile(e.path,e.content)}))}}return new w(t)};exports.createFixture=P;
|
package/dist/index.d.cts
CHANGED
|
@@ -10,7 +10,7 @@ declare class FsFixture {
|
|
|
10
10
|
/**
|
|
11
11
|
Get the full path to a subpath in the fixture directory.
|
|
12
12
|
*/
|
|
13
|
-
getPath(
|
|
13
|
+
getPath(...subpaths: string[]): string;
|
|
14
14
|
/**
|
|
15
15
|
Check if the fixture exists. Pass in a subpath to check if it exists.
|
|
16
16
|
*/
|
|
@@ -39,15 +39,21 @@ declare class FsFixture {
|
|
|
39
39
|
[Symbol.asyncDispose](): Promise<void>;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
type SymlinkType = 'file' | 'dir' | 'junction';
|
|
42
43
|
declare class Symlink {
|
|
43
44
|
target: string;
|
|
45
|
+
type?: SymlinkType;
|
|
44
46
|
path?: string;
|
|
45
|
-
constructor(target: string);
|
|
47
|
+
constructor(target: string, type?: SymlinkType);
|
|
46
48
|
}
|
|
47
49
|
type ApiBase = {
|
|
48
50
|
fixturePath: string;
|
|
49
|
-
getPath(
|
|
50
|
-
symlink(targetPath: string
|
|
51
|
+
getPath(...subpaths: string[]): string;
|
|
52
|
+
symlink(targetPath: string,
|
|
53
|
+
/**
|
|
54
|
+
* Symlink type for Windows. Defaults to auto-detect by Node.
|
|
55
|
+
*/
|
|
56
|
+
type?: SymlinkType): Symlink;
|
|
51
57
|
};
|
|
52
58
|
type Api = ApiBase & {
|
|
53
59
|
filePath: string;
|
package/dist/index.d.mts
CHANGED
|
@@ -10,7 +10,7 @@ declare class FsFixture {
|
|
|
10
10
|
/**
|
|
11
11
|
Get the full path to a subpath in the fixture directory.
|
|
12
12
|
*/
|
|
13
|
-
getPath(
|
|
13
|
+
getPath(...subpaths: string[]): string;
|
|
14
14
|
/**
|
|
15
15
|
Check if the fixture exists. Pass in a subpath to check if it exists.
|
|
16
16
|
*/
|
|
@@ -39,15 +39,21 @@ declare class FsFixture {
|
|
|
39
39
|
[Symbol.asyncDispose](): Promise<void>;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
type SymlinkType = 'file' | 'dir' | 'junction';
|
|
42
43
|
declare class Symlink {
|
|
43
44
|
target: string;
|
|
45
|
+
type?: SymlinkType;
|
|
44
46
|
path?: string;
|
|
45
|
-
constructor(target: string);
|
|
47
|
+
constructor(target: string, type?: SymlinkType);
|
|
46
48
|
}
|
|
47
49
|
type ApiBase = {
|
|
48
50
|
fixturePath: string;
|
|
49
|
-
getPath(
|
|
50
|
-
symlink(targetPath: string
|
|
51
|
+
getPath(...subpaths: string[]): string;
|
|
52
|
+
symlink(targetPath: string,
|
|
53
|
+
/**
|
|
54
|
+
* Symlink type for Windows. Defaults to auto-detect by Node.
|
|
55
|
+
*/
|
|
56
|
+
type?: SymlinkType): Symlink;
|
|
51
57
|
};
|
|
52
58
|
type Api = ApiBase & {
|
|
53
59
|
filePath: string;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import s from"fs/promises";import
|
|
1
|
+
import s from"fs/promises";import o from"path";import y from"fs";import m 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 o.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,r){return s.writeFile(this.getPath(t),r)}writeJson(t,r){return this.writeFile(t,JSON.stringify(r,null,2))}readFile(t,r){return s.readFile(this.getPath(t),r)}async[Symbol.asyncDispose](){await this.rm()}}const g=y.realpathSync(m.tmpdir()),b=`fs-fixture-${Date.now()}`;let l=0;const P=()=>(l+=1,l);class h{target;type;path;constructor(t,r){this.target=t,this.type=r}}const u=(i,t,r)=>{const e=[];for(const n in i){if(!Object.hasOwn(i,n))continue;const c=o.join(t,n);let a=i[n];if(typeof a=="function"){const f=Object.assign(Object.create(r),{filePath:c}),p=a(f);if(p instanceof h){p.path=c,e.push(p);continue}else a=p}typeof a=="string"?e.push({path:c,content:a}):e.push(...u(a,c,r))}return e},d=async i=>{const t=o.join(g,`${b}-${P()}/`);if(await s.mkdir(t,{recursive:!0}),i){if(typeof i=="string")await s.cp(i,t,{recursive:!0});else if(typeof i=="object"){const r={fixturePath:t,getPath:(...e)=>o.join(t,...e),symlink:(e,n)=>new h(e,n)};await Promise.all(u(i,t,r).map(async e=>{await s.mkdir(o.dirname(e.path),{recursive:!0}),e instanceof h?await s.symlink(e.target,e.path,e.type):await s.writeFile(e.path,e.content)}))}}return new w(t)};export{d as createFixture};
|