fs-fixture 1.0.0 → 1.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 +6 -0
- package/dist/index.cjs +1 -0
- package/dist/{index.d.ts → index.d.cts} +2 -2
- package/dist/index.d.mts +37 -0
- package/dist/index.mjs +1 -1
- package/package.json +14 -6
- package/dist/index.js +0 -1
package/README.md
CHANGED
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var i=require("fs"),c=require("path"),l=require("os");function o(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var p=o(i),a=o(c),d=o(l);class h{path;constructor(t){this.path=t}exists(t=""){return i.promises.access(a.default.join(this.path,t)).then(()=>!0,()=>!1)}rm(t=""){return i.promises.rm(a.default.join(this.path,t),{recursive:!0,force:!0})}writeFile(t,r){return i.promises.writeFile(a.default.join(this.path,t),r)}writeJson(t,r){return this.writeFile(t,JSON.stringify(r,null,2))}readFile(t,r){return i.promises.readFile(a.default.join(this.path,t),r)}}const m=p.default.realpathSync(d.default.tmpdir()),y=`fs-fixture-${Date.now()}`;let u=0;function w(){return u+=1,u}const{hasOwnProperty:j}=Object.prototype,v=(e,t)=>j.call(e,t);function f(e,t){const r=[];for(const s in e){if(!v(e,s))continue;const n=e[s];typeof n=="string"?r.push({path:a.default.join(t,s),content:n}):r.push(...f(n,a.default.join(t,s)))}return r}async function F(e){const t=a.default.join(m,`${y}-${w()}`);return await i.promises.mkdir(t,{recursive:!0}),e&&(typeof e=="string"?await i.promises.cp(e,t,{recursive:!0}):typeof e=="object"&&await Promise.all(f(e,t).map(async r=>{await i.promises.mkdir(a.default.dirname(r.path),{recursive:!0}),await i.promises.writeFile(r.path,r.content)}))),new h(t)}exports.createFixture=F;
|
|
@@ -29,9 +29,9 @@ declare class FsFixture {
|
|
|
29
29
|
readFile(filePath: string, encoding?: BufferEncoding): Promise<string | Buffer>;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
type FileTree = {
|
|
33
33
|
[path: string]: string | FileTree;
|
|
34
34
|
};
|
|
35
|
-
declare function createFixture(source
|
|
35
|
+
declare function createFixture(source?: string | FileTree): Promise<FsFixture>;
|
|
36
36
|
|
|
37
37
|
export { FileTree, FsFixture, createFixture };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
declare class FsFixture {
|
|
2
|
+
/**
|
|
3
|
+
Path to the fixture directory.
|
|
4
|
+
*/
|
|
5
|
+
path: string;
|
|
6
|
+
/**
|
|
7
|
+
Create a Fixture instance from a path. Does not create the fixture directory.
|
|
8
|
+
*/
|
|
9
|
+
constructor(fixturePath: string);
|
|
10
|
+
/**
|
|
11
|
+
Check if the fixture exists. Pass in a subpath to check if it exists.
|
|
12
|
+
*/
|
|
13
|
+
exists(subpath?: string): Promise<boolean>;
|
|
14
|
+
/**
|
|
15
|
+
Delete the fixture directory. Pass in a subpath to delete it.
|
|
16
|
+
*/
|
|
17
|
+
rm(subpath?: string): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
Create a file in the fixture directory.
|
|
20
|
+
*/
|
|
21
|
+
writeFile(filePath: string, content: string): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
Create a JSON file in the fixture directory.
|
|
24
|
+
*/
|
|
25
|
+
writeJson(filePath: string, json: any): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
Read a file from the fixture directory.
|
|
28
|
+
*/
|
|
29
|
+
readFile(filePath: string, encoding?: BufferEncoding): Promise<string | Buffer>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
type FileTree = {
|
|
33
|
+
[path: string]: string | FileTree;
|
|
34
|
+
};
|
|
35
|
+
declare function createFixture(source?: string | FileTree): Promise<FsFixture>;
|
|
36
|
+
|
|
37
|
+
export { FileTree, FsFixture, createFixture };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import p,{promises as i}from"fs";import n from"path";import u from"os";class h{path;constructor(t){this.path=t}exists(t=""){return i.access(n.join(this.path,t)).then(()=>!0,()=>!1)}rm(t=""){return i.rm(n.join(this.path,t),{recursive:!0,force:!0})}writeFile(t,e){return i.writeFile(n.join(this.path,t),e)}writeJson(t,e){return this.writeFile(t,JSON.stringify(e,null,2))}readFile(t,e){return i.readFile(n.join(this.path,t),e)}}const f=p.realpathSync(u.tmpdir()),l=`fs-fixture-${Date.now()}`;let a=0;function m(){return a+=1,a}const{hasOwnProperty:w}=Object.prototype,y=(r,t)=>w.call(r,t);function c(r,t){const e=[];for(const o in r){if(!y(r,o))continue;const s=r[o];typeof s=="string"?e.push({path:n.join(t,o),content:s}):e.push(...c(s,n.join(t,o)))}return e}async function F(r){const t=n.join(f,`${l}-${m()}`);return await i.mkdir(t,{recursive:!0}),r&&(typeof r=="string"?await i.cp(r,t,{recursive:!0}):typeof r=="object"&&await Promise.all(c(r,t).map(async e=>{await i.mkdir(n.dirname(e.path),{recursive:!0}),await i.writeFile(e.path,e.content)}))),new h(t)}export{F as createFixture};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fs-fixture",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Easily create test fixtures at a temporary file-system path",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"test",
|
|
@@ -22,13 +22,18 @@
|
|
|
22
22
|
"files": [
|
|
23
23
|
"dist"
|
|
24
24
|
],
|
|
25
|
-
"main": "./dist/index.
|
|
25
|
+
"main": "./dist/index.cjs",
|
|
26
26
|
"module": "./dist/index.mjs",
|
|
27
|
-
"types": "./dist/index.d.
|
|
27
|
+
"types": "./dist/index.d.cts",
|
|
28
28
|
"exports": {
|
|
29
|
-
"require":
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
"require": {
|
|
30
|
+
"types": "./dist/index.d.cts",
|
|
31
|
+
"default": "./dist/index.cjs"
|
|
32
|
+
},
|
|
33
|
+
"import": {
|
|
34
|
+
"types": "./dist/index.d.mts",
|
|
35
|
+
"default": "./dist/index.mjs"
|
|
36
|
+
}
|
|
32
37
|
},
|
|
33
38
|
"imports": {
|
|
34
39
|
"#fs-fixture": {
|
|
@@ -36,5 +41,8 @@
|
|
|
36
41
|
"development": "./src/index.ts",
|
|
37
42
|
"default": "./dist/index.mjs"
|
|
38
43
|
}
|
|
44
|
+
},
|
|
45
|
+
"engines": {
|
|
46
|
+
"node": ">=16.7.0"
|
|
39
47
|
}
|
|
40
48
|
}
|
package/dist/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var a=require("fs"),c=require("path"),d=require("os");function u(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var h=u(a),i=u(c),m=u(d);class w{path;constructor(t){this.path=t}exists(t=""){return a.promises.access(i.default.join(this.path,t)).then(()=>!0,()=>!1)}rm(t=""){return a.promises.rm(i.default.join(this.path,t),{recursive:!0,force:!0})}writeFile(t,r){return a.promises.writeFile(i.default.join(this.path,t),r)}writeJson(t,r){return this.writeFile(t,JSON.stringify(r,null,2))}readFile(t,r){return a.promises.readFile(i.default.join(this.path,t),r)}}const o=i.default.join(h.default.realpathSync(m.default.tmpdir()),"test-fixtures",Date.now().toString());let l=0;function f(){return l+=1,l}const{hasOwnProperty:y}=Object.prototype,j=(e,t)=>y.call(e,t);function p(e,t){const r=[];for(const s in e){if(!j(e,s))continue;const n=e[s];typeof n=="string"?r.push({path:i.default.join(t,s),content:n}):r.push(...p(n,i.default.join(t,s)))}return r}async function v(e){let t;return typeof e=="string"?(t=i.default.join(o,`${i.default.basename(e)}-${f()}`),await a.promises.mkdir(t,{recursive:!0}),await a.promises.cp(e,t,{recursive:!0})):(t=i.default.join(o,`fixture-${f()}`),await Promise.all(p(e,t).map(async r=>{await a.promises.mkdir(i.default.dirname(r.path),{recursive:!0}),await a.promises.writeFile(r.path,r.content)}))),new w(t)}exports.createFixture=v;
|