fs-fixture 2.9.0 → 2.10.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/dist/index.cjs +1 -1
- package/dist/index.d.cts +5 -1
- package/dist/index.d.mts +5 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var g=Object.defineProperty;var a=(s,e)=>g(s,"name",{value:e,configurable:!0});var n=require("node:fs/promises"),o=require("node:path"),F=require("node:url"),v=require("node:fs"),P=require("node:os");typeof Symbol.asyncDispose!="symbol"&&Object.defineProperty(Symbol,"asyncDispose",{configurable:!1,enumerable:!1,writable:!1,value:Symbol.for("asyncDispose")});class b{static{a(this,"FsFixture")}path;constructor(e){this.path=e}getPath(...e){return o.join(this.path,...e)}exists(e=""){return n.access(this.getPath(e)).then(()=>!0,()=>!1)}rm(e=""){return n.rm(this.getPath(e),{recursive:!0,force:!0})}cp(e,r,i){return r?r.endsWith(o.sep)&&(r+=o.basename(e)):r=o.basename(e),n.cp(e,this.getPath(r),i)}mkdir(e){return n.mkdir(this.getPath(e),{recursive:!0})}readFile=a(((e,r)=>n.readFile(this.getPath(e),r)),"readFile");readdir=a(((e,r)=>n.readdir(this.getPath(e||""),r)),"readdir");writeFile=a(((e,r,...i)=>n.writeFile(this.getPath(e),r,...i)),"writeFile");async readJson(e){const r=await this.readFile(e,"utf8");return JSON.parse(r)}writeJson(e,r,i=2){return this.writeFile(e,JSON.stringify(r,null,i))}async[Symbol.asyncDispose](){await this.rm()}}const D=v.realpathSync(P.tmpdir());class p{static{a(this,"PathBase")}constructor(e){this.path=e}}class y extends p{static{a(this,"Directory")}}class m extends p{static{a(this,"File")}constructor(e,r){super(e),this.content=r}}class u extends p{static{a(this,"Symlink")}constructor(e,r,i){super(i??""),this.target=e,this.type=r}}const w=a((s,e,r)=>{const i=[];for(const l in s){if(!Object.hasOwn(s,l))continue;const c=o.join(e,l);let t=s[l];if(typeof t=="function"){const h=Object.assign(Object.create(r),{filePath:c}),f=t(h);if(f instanceof u){const d=new u(f.target,f.type,c);i.push(d);continue}else t=f}if(typeof t=="string"||Buffer.isBuffer(t))i.push(new m(c,t));else if(t&&typeof t=="object"&&!Array.isArray(t))i.push(new y(c),...w(t,c,r));else throw new TypeError(`Invalid file content for path "${c}". Functions must return a string, Buffer, Symlink, or a nested FileTree object. Received: ${String(t)}`)}return i},"flattenFileTree"),j=a(async(s,e)=>{const r=e?.tempDir?o.resolve(typeof e.tempDir=="string"?e.tempDir:F.fileURLToPath(e.tempDir)):D;e?.tempDir&&await n.mkdir(r,{recursive:!0});const i=await n.mkdtemp(o.join(r,"fs-fixture-"));if(s){if(typeof s=="string")await n.cp(s,i,{recursive:!0,filter:e?.templateFilter});else if(typeof s=="object"){const c=w(s,i,{fixturePath:i,getPath:a((...t)=>o.join(i,...t),"getPath"),symlink:a((t,h)=>new u(t,h),"symlink")});await Promise.all(c.filter(t=>t instanceof y).map(t=>n.mkdir(t.path,{recursive:!0}))),await Promise.all(c.map(async t=>{t instanceof u?await n.symlink(t.target,t.path,t.type):t instanceof m&&await n.writeFile(t.path,t.content)}))}}return new b(i)},"createFixture");exports.createFixture=j;
|
package/dist/index.d.cts
CHANGED
|
@@ -164,8 +164,12 @@ type CreateFixtureOptions = {
|
|
|
164
164
|
/**
|
|
165
165
|
* The temporary directory to create the fixtures in.
|
|
166
166
|
* Defaults to `os.tmpdir()`.
|
|
167
|
+
*
|
|
168
|
+
* Accepts either a string path or a URL object.
|
|
169
|
+
*
|
|
170
|
+
* Tip: use `new URL('.', import.meta.url)` to the get the file's directory (not the file).
|
|
167
171
|
*/
|
|
168
|
-
tempDir?: string;
|
|
172
|
+
tempDir?: string | URL;
|
|
169
173
|
/**
|
|
170
174
|
* Function to filter files to copy when using a template path.
|
|
171
175
|
* Return `true` to copy the item, `false` to ignore it.
|
package/dist/index.d.mts
CHANGED
|
@@ -164,8 +164,12 @@ type CreateFixtureOptions = {
|
|
|
164
164
|
/**
|
|
165
165
|
* The temporary directory to create the fixtures in.
|
|
166
166
|
* Defaults to `os.tmpdir()`.
|
|
167
|
+
*
|
|
168
|
+
* Accepts either a string path or a URL object.
|
|
169
|
+
*
|
|
170
|
+
* Tip: use `new URL('.', import.meta.url)` to the get the file's directory (not the file).
|
|
167
171
|
*/
|
|
168
|
-
tempDir?: string;
|
|
172
|
+
tempDir?: string | URL;
|
|
169
173
|
/**
|
|
170
174
|
* Function to filter files to copy when using a template path.
|
|
171
175
|
* Return `true` to copy the item, `false` to ignore it.
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var d=Object.defineProperty;var a=(s,e)=>d(s,"name",{value:e,configurable:!0});import n from"node:fs/promises";import c from"node:path";import{fileURLToPath as F}from"node:url";import P from"node:fs";import b from"node:os";typeof Symbol.asyncDispose!="symbol"&&Object.defineProperty(Symbol,"asyncDispose",{configurable:!1,enumerable:!1,writable:!1,value:Symbol.for("asyncDispose")});class D{static{a(this,"FsFixture")}path;constructor(e){this.path=e}getPath(...e){return c.join(this.path,...e)}exists(e=""){return n.access(this.getPath(e)).then(()=>!0,()=>!1)}rm(e=""){return n.rm(this.getPath(e),{recursive:!0,force:!0})}cp(e,r,i){return r?r.endsWith(c.sep)&&(r+=c.basename(e)):r=c.basename(e),n.cp(e,this.getPath(r),i)}mkdir(e){return n.mkdir(this.getPath(e),{recursive:!0})}readFile=a(((e,r)=>n.readFile(this.getPath(e),r)),"readFile");readdir=a(((e,r)=>n.readdir(this.getPath(e||""),r)),"readdir");writeFile=a(((e,r,...i)=>n.writeFile(this.getPath(e),r,...i)),"writeFile");async readJson(e){const r=await this.readFile(e,"utf8");return JSON.parse(r)}writeJson(e,r,i=2){return this.writeFile(e,JSON.stringify(r,null,i))}async[Symbol.asyncDispose](){await this.rm()}}const j=P.realpathSync(b.tmpdir());class h{static{a(this,"PathBase")}constructor(e){this.path=e}}class u extends h{static{a(this,"Directory")}}class y extends h{static{a(this,"File")}constructor(e,r){super(e),this.content=r}}class p extends h{static{a(this,"Symlink")}constructor(e,r,i){super(i??""),this.target=e,this.type=r}}const w=a((s,e,r)=>{const i=[];for(const f in s){if(!Object.hasOwn(s,f))continue;const o=c.join(e,f);let t=s[f];if(typeof t=="function"){const m=Object.assign(Object.create(r),{filePath:o}),l=t(m);if(l instanceof p){const g=new p(l.target,l.type,o);i.push(g);continue}else t=l}if(typeof t=="string"||Buffer.isBuffer(t))i.push(new y(o,t));else if(t&&typeof t=="object"&&!Array.isArray(t))i.push(new u(o),...w(t,o,r));else throw new TypeError(`Invalid file content for path "${o}". Functions must return a string, Buffer, Symlink, or a nested FileTree object. Received: ${String(t)}`)}return i},"flattenFileTree"),k=a(async(s,e)=>{const r=e?.tempDir?c.resolve(typeof e.tempDir=="string"?e.tempDir:F(e.tempDir)):j;e?.tempDir&&await n.mkdir(r,{recursive:!0});const i=await n.mkdtemp(c.join(r,"fs-fixture-"));if(s){if(typeof s=="string")await n.cp(s,i,{recursive:!0,filter:e?.templateFilter});else if(typeof s=="object"){const o=w(s,i,{fixturePath:i,getPath:a((...t)=>c.join(i,...t),"getPath"),symlink:a((t,m)=>new p(t,m),"symlink")});await Promise.all(o.filter(t=>t instanceof u).map(t=>n.mkdir(t.path,{recursive:!0}))),await Promise.all(o.map(async t=>{t instanceof p?await n.symlink(t.target,t.path,t.type):t instanceof y&&await n.writeFile(t.path,t.content)}))}}return new D(i)},"createFixture");export{k as createFixture};
|