fs-fixture 2.1.0 → 2.2.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 +18 -3
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +12 -2
- package/dist/index.d.mts +12 -2
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -42,9 +42,10 @@ import { createFixture } from 'fs-fixture'
|
|
|
42
42
|
const fixture = await createFixture({
|
|
43
43
|
// Nested directory syntax
|
|
44
44
|
'dir-a': {
|
|
45
|
+
'file-a.txt': 'hello world',
|
|
45
46
|
'dir-b': {
|
|
46
|
-
'file-
|
|
47
|
-
'
|
|
47
|
+
'file-b.txt': ({ fixturePath }) => `Fixture path: ${fixturePath}`,
|
|
48
|
+
'symlink-c': ({ symlink }) => symlink('../file-a.txt')
|
|
48
49
|
}
|
|
49
50
|
},
|
|
50
51
|
|
|
@@ -100,7 +101,21 @@ Path to a template fixture path, or a `FileTree` object that represents the fixt
|
|
|
100
101
|
|
|
101
102
|
```ts
|
|
102
103
|
type FileTree = {
|
|
103
|
-
[path: string]: string | FileTree
|
|
104
|
+
[path: string]: string | FileTree | ((api: Api) => string)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
type Api = {
|
|
108
|
+
// Fixture root path
|
|
109
|
+
fixturePath: string
|
|
110
|
+
|
|
111
|
+
// Current file path
|
|
112
|
+
filePath: string
|
|
113
|
+
|
|
114
|
+
// Get path from the root of the fixture
|
|
115
|
+
getPath: (subpath: string) => string
|
|
116
|
+
|
|
117
|
+
// Create a symlink
|
|
118
|
+
symlink: (target: string) => Symlink
|
|
104
119
|
}
|
|
105
120
|
```
|
|
106
121
|
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var s=require("fs/promises"),n=require("path"),y=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 n.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,i){return s.writeFile(this.getPath(t),i)}writeJson(t,i){return this.writeFile(t,JSON.stringify(i,null,2))}readFile(t,i){return s.readFile(this.getPath(t),i)}async[Symbol.asyncDispose](){await this.rm()}}const g=y.realpathSync(m.tmpdir()),b=`fs-fixture-${Date.now()}`;let l=0;const F=()=>(l+=1,l);class h{target;path;constructor(t){this.target=t}}const p=(r,t,i)=>{const e=[];for(const u in r){if(!Object.hasOwn(r,u))continue;const o=n.join(t,u);let a=r[u];if(typeof a=="function"){const f=Object.assign(Object.create(i),{filePath:o}),c=a(f);if(c instanceof h){c.path=o,e.push(c);continue}else a=c}typeof a=="string"?e.push({path:o,content:a}):e.push(...p(a,o,i))}return e},P=async r=>{const t=n.join(g,`${b}-${F()}/`);if(await s.mkdir(t,{recursive:!0}),r){if(typeof r=="string")await s.cp(r,t,{recursive:!0});else if(typeof r=="object"){const i={fixturePath:t,getPath:e=>n.join(t,e),symlink:e=>new h(e)};await Promise.all(p(r,t,i).map(async e=>{await s.mkdir(n.dirname(e.path),{recursive:!0}),e instanceof h?await s.symlink(e.target,e.path):await s.writeFile(e.path,e.content)}))}}return new w(t)};exports.createFixture=P;
|
package/dist/index.d.cts
CHANGED
|
@@ -39,11 +39,21 @@ declare class FsFixture {
|
|
|
39
39
|
[Symbol.asyncDispose](): Promise<void>;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
declare class Symlink {
|
|
43
|
+
target: string;
|
|
44
|
+
path?: string;
|
|
45
|
+
constructor(target: string);
|
|
46
|
+
}
|
|
47
|
+
type ApiBase = {
|
|
43
48
|
fixturePath: string;
|
|
49
|
+
getPath(subpath: string): string;
|
|
50
|
+
symlink(targetPath: string): Symlink;
|
|
51
|
+
};
|
|
52
|
+
type Api = ApiBase & {
|
|
53
|
+
filePath: string;
|
|
44
54
|
};
|
|
45
55
|
type FileTree = {
|
|
46
|
-
[path: string]: string | FileTree | ((api: Api) => string);
|
|
56
|
+
[path: string]: string | FileTree | ((api: Api) => string | Symlink);
|
|
47
57
|
};
|
|
48
58
|
declare const createFixture: (source?: string | FileTree) => Promise<FsFixture>;
|
|
49
59
|
|
package/dist/index.d.mts
CHANGED
|
@@ -39,11 +39,21 @@ declare class FsFixture {
|
|
|
39
39
|
[Symbol.asyncDispose](): Promise<void>;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
declare class Symlink {
|
|
43
|
+
target: string;
|
|
44
|
+
path?: string;
|
|
45
|
+
constructor(target: string);
|
|
46
|
+
}
|
|
47
|
+
type ApiBase = {
|
|
43
48
|
fixturePath: string;
|
|
49
|
+
getPath(subpath: string): string;
|
|
50
|
+
symlink(targetPath: string): Symlink;
|
|
51
|
+
};
|
|
52
|
+
type Api = ApiBase & {
|
|
53
|
+
filePath: string;
|
|
44
54
|
};
|
|
45
55
|
type FileTree = {
|
|
46
|
-
[path: string]: string | FileTree | ((api: Api) => string);
|
|
56
|
+
[path: string]: string | FileTree | ((api: Api) => string | Symlink);
|
|
47
57
|
};
|
|
48
58
|
declare const createFixture: (source?: string | FileTree) => Promise<FsFixture>;
|
|
49
59
|
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import s from"fs/promises";import n from"path";import m from"fs";import y 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 n.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,i){return s.writeFile(this.getPath(t),i)}writeJson(t,i){return this.writeFile(t,JSON.stringify(i,null,2))}readFile(t,i){return s.readFile(this.getPath(t),i)}async[Symbol.asyncDispose](){await this.rm()}}const g=m.realpathSync(y.tmpdir()),b=`fs-fixture-${Date.now()}`;let l=0;const P=()=>(l+=1,l);class h{target;path;constructor(t){this.target=t}}const f=(r,t,i)=>{const e=[];for(const p in r){if(!Object.hasOwn(r,p))continue;const o=n.join(t,p);let a=r[p];if(typeof a=="function"){const u=Object.assign(Object.create(i),{filePath:o}),c=a(u);if(c instanceof h){c.path=o,e.push(c);continue}else a=c}typeof a=="string"?e.push({path:o,content:a}):e.push(...f(a,o,i))}return e},d=async r=>{const t=n.join(g,`${b}-${P()}/`);if(await s.mkdir(t,{recursive:!0}),r){if(typeof r=="string")await s.cp(r,t,{recursive:!0});else if(typeof r=="object"){const i={fixturePath:t,getPath:e=>n.join(t,e),symlink:e=>new h(e)};await Promise.all(f(r,t,i).map(async e=>{await s.mkdir(n.dirname(e.path),{recursive:!0}),e instanceof h?await s.symlink(e.target,e.path):await s.writeFile(e.path,e.content)}))}}return new w(t)};export{d as createFixture};
|