fs-fixture 2.4.1 → 2.6.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 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +17 -2
- package/dist/index.d.mts +17 -2
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -86,7 +86,7 @@ await using fixture = await createFixture({ file: 'hello' })
|
|
|
86
86
|
|
|
87
87
|
## API
|
|
88
88
|
|
|
89
|
-
### createFixture(source)
|
|
89
|
+
### createFixture(source, options)
|
|
90
90
|
|
|
91
91
|
An async function that creates a fixture from the `source` you pass in, and returns a `FsFixture` instance.
|
|
92
92
|
|
|
@@ -96,6 +96,23 @@ Type: `string | FileTree`
|
|
|
96
96
|
Path to a template fixture path, or a `FileTree` object that represents the fixture content.
|
|
97
97
|
|
|
98
98
|
|
|
99
|
+
#### options
|
|
100
|
+
|
|
101
|
+
##### tempDir
|
|
102
|
+
|
|
103
|
+
Type: `string`
|
|
104
|
+
|
|
105
|
+
Default: `os.tmpdir()`
|
|
106
|
+
|
|
107
|
+
The directory where the fixture will be created.
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
##### templateFilter
|
|
111
|
+
|
|
112
|
+
Type: `(source: string, destination: string) => boolean | Promise<boolean>`
|
|
113
|
+
|
|
114
|
+
Function to filter files to copy when using a template path. Return `true` to copy the item, `false` to ignore it.
|
|
115
|
+
|
|
99
116
|
### Types
|
|
100
117
|
#### FileTree
|
|
101
118
|
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var w=Object.defineProperty;var n=(r,t)=>w(r,"name",{value:t,configurable:!0});var c=require("node:fs/promises"),u=require("node:path"),h=require("fs/promises"),g=require("path"),b=require("fs"),v=require("os");typeof Symbol.asyncDispose!="symbol"&&Object.defineProperty(Symbol,"asyncDispose",{configurable:!1,enumerable:!1,writable:!1,value:Symbol.for("asyncDispose")});class F{static{n(this,"FsFixture")}path;constructor(t){this.path=t}getPath(...t){return g.join(this.path,...t)}exists(t=""){return h.access(this.getPath(t)).then(()=>!0,()=>!1)}rm(t=""){return h.rm(this.getPath(t),{recursive:!0,force:!0})}writeFile(t,i){return h.writeFile(this.getPath(t),i)}writeJson(t,i){return this.writeFile(t,JSON.stringify(i,null,2))}readFile(t,i){return h.readFile(this.getPath(t),i)}async[Symbol.asyncDispose](){await this.rm()}}const d=b.realpathSync(v.tmpdir()),P=`fs-fixture-${Date.now()}`;let y=0;const j=n(()=>(y+=1,y),"getId");class p{static{n(this,"Symlink")}target;type;path;constructor(t,i){this.target=t,this.type=i}}const f=n((r,t,i)=>{const s=[];for(const o in r){if(!Object.hasOwn(r,o))continue;const e=u.join(t,o);let a=r[o];if(typeof a=="function"){const m=Object.assign(Object.create(i),{filePath:e}),l=a(m);if(l instanceof p){l.path=e,s.push(l);continue}else a=l}typeof a=="string"?s.push({path:e,content:a}):s.push(...f(a,e,i))}return s},"flattenFileTree"),D=n(async(r,t)=>{const i=t?.tempDir?u.resolve(t.tempDir):d,s=u.join(i,`${P}-${j()}/`);if(await c.mkdir(s,{recursive:!0}),r){if(typeof r=="string")await c.cp(r,s,{recursive:!0,filter:t?.templateFilter});else if(typeof r=="object"){const o={fixturePath:s,getPath:n((...e)=>u.join(s,...e),"getPath"),symlink:n((e,a)=>new p(e,a),"symlink")};await Promise.all(f(r,s,o).map(async e=>{await c.mkdir(u.dirname(e.path),{recursive:!0}),e instanceof p?await c.symlink(e.target,e.path,e.type):await c.writeFile(e.path,e.content)}))}}return new F(s)},"createFixture");exports.createFixture=D;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { CopyOptions } from 'node:fs';
|
|
2
|
+
|
|
1
3
|
declare class FsFixture {
|
|
2
4
|
/**
|
|
3
5
|
Path to the fixture directory.
|
|
@@ -40,6 +42,7 @@ declare class FsFixture {
|
|
|
40
42
|
}
|
|
41
43
|
type FsFixtureType = FsFixture;
|
|
42
44
|
|
|
45
|
+
type FilterFunction = CopyOptions['filter'];
|
|
43
46
|
type SymlinkType = 'file' | 'dir' | 'junction';
|
|
44
47
|
declare class Symlink {
|
|
45
48
|
target: string;
|
|
@@ -62,6 +65,18 @@ type Api = ApiBase & {
|
|
|
62
65
|
type FileTree = {
|
|
63
66
|
[path: string]: string | FileTree | ((api: Api) => string | Symlink);
|
|
64
67
|
};
|
|
65
|
-
|
|
68
|
+
type CreateFixtureOptions = {
|
|
69
|
+
/**
|
|
70
|
+
* The temporary directory to create the fixtures in.
|
|
71
|
+
* Defaults to `os.tmpdir()`.
|
|
72
|
+
*/
|
|
73
|
+
tempDir?: string;
|
|
74
|
+
/**
|
|
75
|
+
* Function to filter files to copy when using a template path.
|
|
76
|
+
* Return `true` to copy the item, `false` to ignore it.
|
|
77
|
+
*/
|
|
78
|
+
templateFilter?: FilterFunction;
|
|
79
|
+
};
|
|
80
|
+
declare const createFixture: (source?: string | FileTree, options?: CreateFixtureOptions) => Promise<FsFixture>;
|
|
66
81
|
|
|
67
|
-
export { type FileTree, type FsFixtureType as FsFixture, createFixture };
|
|
82
|
+
export { type CreateFixtureOptions, type FileTree, type FsFixtureType as FsFixture, createFixture };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { CopyOptions } from 'node:fs';
|
|
2
|
+
|
|
1
3
|
declare class FsFixture {
|
|
2
4
|
/**
|
|
3
5
|
Path to the fixture directory.
|
|
@@ -40,6 +42,7 @@ declare class FsFixture {
|
|
|
40
42
|
}
|
|
41
43
|
type FsFixtureType = FsFixture;
|
|
42
44
|
|
|
45
|
+
type FilterFunction = CopyOptions['filter'];
|
|
43
46
|
type SymlinkType = 'file' | 'dir' | 'junction';
|
|
44
47
|
declare class Symlink {
|
|
45
48
|
target: string;
|
|
@@ -62,6 +65,18 @@ type Api = ApiBase & {
|
|
|
62
65
|
type FileTree = {
|
|
63
66
|
[path: string]: string | FileTree | ((api: Api) => string | Symlink);
|
|
64
67
|
};
|
|
65
|
-
|
|
68
|
+
type CreateFixtureOptions = {
|
|
69
|
+
/**
|
|
70
|
+
* The temporary directory to create the fixtures in.
|
|
71
|
+
* Defaults to `os.tmpdir()`.
|
|
72
|
+
*/
|
|
73
|
+
tempDir?: string;
|
|
74
|
+
/**
|
|
75
|
+
* Function to filter files to copy when using a template path.
|
|
76
|
+
* Return `true` to copy the item, `false` to ignore it.
|
|
77
|
+
*/
|
|
78
|
+
templateFilter?: FilterFunction;
|
|
79
|
+
};
|
|
80
|
+
declare const createFixture: (source?: string | FileTree, options?: CreateFixtureOptions) => Promise<FsFixture>;
|
|
66
81
|
|
|
67
|
-
export { type FileTree, type FsFixtureType as FsFixture, createFixture };
|
|
82
|
+
export { type CreateFixtureOptions, type FileTree, type FsFixtureType as FsFixture, createFixture };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var w=Object.defineProperty;var n=(r,t)=>w(r,"name",{value:t,configurable:!0});import c from"node:fs/promises";import p from"node:path";import f from"fs/promises";import g from"path";import b from"fs";import d from"os";typeof Symbol.asyncDispose!="symbol"&&Object.defineProperty(Symbol,"asyncDispose",{configurable:!1,enumerable:!1,writable:!1,value:Symbol.for("asyncDispose")});class F{static{n(this,"FsFixture")}path;constructor(t){this.path=t}getPath(...t){return g.join(this.path,...t)}exists(t=""){return f.access(this.getPath(t)).then(()=>!0,()=>!1)}rm(t=""){return f.rm(this.getPath(t),{recursive:!0,force:!0})}writeFile(t,i){return f.writeFile(this.getPath(t),i)}writeJson(t,i){return this.writeFile(t,JSON.stringify(i,null,2))}readFile(t,i){return f.readFile(this.getPath(t),i)}async[Symbol.asyncDispose](){await this.rm()}}const P=b.realpathSync(d.tmpdir()),j=`fs-fixture-${Date.now()}`;let m=0;const D=n(()=>(m+=1,m),"getId");class h{static{n(this,"Symlink")}target;type;path;constructor(t,i){this.target=t,this.type=i}}const u=n((r,t,i)=>{const s=[];for(const o in r){if(!Object.hasOwn(r,o))continue;const e=p.join(t,o);let a=r[o];if(typeof a=="function"){const y=Object.assign(Object.create(i),{filePath:e}),l=a(y);if(l instanceof h){l.path=e,s.push(l);continue}else a=l}typeof a=="string"?s.push({path:e,content:a}):s.push(...u(a,e,i))}return s},"flattenFileTree"),v=n(async(r,t)=>{const i=t?.tempDir?p.resolve(t.tempDir):P,s=p.join(i,`${j}-${D()}/`);if(await c.mkdir(s,{recursive:!0}),r){if(typeof r=="string")await c.cp(r,s,{recursive:!0,filter:t?.templateFilter});else if(typeof r=="object"){const o={fixturePath:s,getPath:n((...e)=>p.join(s,...e),"getPath"),symlink:n((e,a)=>new h(e,a),"symlink")};await Promise.all(u(r,s,o).map(async e=>{await c.mkdir(p.dirname(e.path),{recursive:!0}),e instanceof h?await c.symlink(e.target,e.path,e.type):await c.writeFile(e.path,e.content)}))}}return new F(s)},"createFixture");export{v as createFixture};
|