@homedev/files 1.0.4 → 1.0.6

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.d.ts CHANGED
@@ -8,6 +8,27 @@ declare interface FilePatternOptions {
8
8
 
9
9
  export declare const globMap: <T>(pattern: string | string[], options: FilePatternOptions) => Promise<T[] | T>;
10
10
 
11
+ /**
12
+ * @public
13
+ */
14
+ export declare const importGlob: (patterns: string[], options?: ImportOptions) => Promise<any[]>;
15
+
16
+ /**
17
+ * @public
18
+ */
19
+ export declare const importList: (modules: string[], options?: ImportOptions) => Promise<any[]>;
20
+
21
+ /**
22
+ * @public
23
+ */
24
+ export declare interface ImportOptions {
25
+ cwd?: string;
26
+ resolveDefault?: boolean | 'only';
27
+ filter?: (name: string) => boolean | undefined;
28
+ fail?: (name: string, error: any) => boolean | undefined;
29
+ map?: (module: any, name: string) => any;
30
+ }
31
+
11
32
  /**
12
33
  * @public
13
34
  * @param fileName
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- var M=Object.create;var{getPrototypeOf:R,defineProperty:i,getOwnPropertyNames:j,getOwnPropertyDescriptor:_}=Object,A=Object.prototype.hasOwnProperty;var t=(r,e,c)=>{c=r!=null?M(R(r)):{};let n=e||!r||!r.__esModule?i(c,"default",{value:r,enumerable:!0}):c;for(let m of j(r))if(!A.call(n,m))i(n,m,{get:()=>r[m],enumerable:!0});return n},F=new WeakMap,$=(r)=>{var e=F.get(r),c;if(e)return e;if(e=i({},"__esModule",{value:!0}),r&&typeof r==="object"||typeof r==="function")j(r).map((n)=>!A.call(e,n)&&i(e,n,{get:()=>r[n],enumerable:!(c=_(r,n))||c.enumerable}));return F.set(r,e),e};var q=(r,e)=>{for(var c in e)i(r,c,{get:e[c],enumerable:!0,configurable:!0,set:(n)=>e[c]=()=>n})};var G={};q(G,{writeOutputs:()=>C,writeOutput:()=>E,writeFormat:()=>s,locate:()=>a,loadFormat:()=>z,globMap:()=>B,exists:()=>y});module.exports=$(G);var w=t(require("fs/promises")),y=async(r)=>{try{return await w.default.access(r,w.default.constants.R_OK),!0}catch{return!1}};var g=t(require("path"));var a=async(r,e)=>{let c=!g.default.isAbsolute(r)&&e?["",...e]:[""];for(let n of c){let m=g.default.join(n,r);if(await y(m))return g.default.resolve(m)}throw Error(`File not found: "${r}"`)};var O=t(require("fs/promises")),T=t(require("path")),l=t(require("yaml"));var z=async(r,e)=>{let c=await a(r,e?.dirs),n=await O.default.readFile(c),m=T.default.dirname(c),J={"[.](yml|yaml)$":l.default.parse,"[.]json$":JSON.parse,...e?.parsers},d=Object.entries(J).find((K)=>c.match(K[0]));if(!d)throw Error(`Unhandled file type: ${r}`);return{content:d[1](n.toString()),fullPath:c,folderPath:m}};var x=t(require("fs/promises")),S=t(require("yaml")),s=async(r,e,c="text")=>{switch(c){case"yaml":await x.default.writeFile(r,S.default.stringify(e));break;case"json":await x.default.writeFile(r,JSON.stringify(e));break;case"text":default:await x.default.writeFile(r,e.toString())}};var v=t(require("fs/promises")),B=async(r,e)=>{if(typeof r==="string"&&!r.includes("*"))return await e.map(r,0,[]);let c=await Array.fromAsync(v.default.glob(r,{cwd:e.cwd})),n=e.filter?c.filter(e.filter):c;return await Promise.all(n.map(e.map))};var b=t(require("fs/promises")),f=t(require("path"));var C=async(r,e)=>{if(e?.targetDirectory&&e?.removeFirst)try{await b.default.rm(e?.targetDirectory,{recursive:!0,force:!0})}catch(c){throw Error(`Failed to clean the output directory: ${c.message}`)}for(let c of r)await E(c,e)},E=async(r,e)=>{let c=f.default.join(e?.targetDirectory??".",r.name),n=f.default.dirname(c);if(e?.classes){if(r.class!==void 0&&!e.classes.includes(r.class))return;if(e.classRequired&&r.class===void 0)throw Error(`Output "${r.name}" is missing class field`)}if(e?.writing?.(r)===!1)return;try{await b.default.mkdir(n,{recursive:!0})}catch(m){throw Error(`Failed to create target directory "${n}" for output "${c}": ${m.message}`)}try{await s(c,r.value,r.type??"text")}catch(m){throw Error(`Failed to write output "${c}": ${m.message}`)}};
1
+ import c from"fs/promises";var l=async(r)=>{try{return await c.access(r,c.constants.R_OK),!0}catch{return!1}};import o from"path";var y=async(r,e)=>{let t=!o.isAbsolute(r)&&e?["",...e]:[""];for(let n of t){let a=o.join(n,r);if(await l(a))return o.resolve(a)}throw Error(`File not found: "${r}"`)};import A from"path";var D=async(r,e)=>{let t=await y(r,e?.dirs),n=await Bun.file(t).text(),a=A.dirname(t),s={"[.]json$":JSON.parse,"[.](yml|yaml)$":Bun.YAML.parse,"[.]toml$":Bun.TOML.parse,...e?.parsers},i=Object.entries(s).find((b)=>t.match(b[0]));if(!i)throw Error(`Unhandled file type: ${r}`);return{content:i[1](n),fullPath:t,folderPath:a}};var u=async(r,e,t="text")=>{switch(t){case"yaml":await Bun.write(r,Bun.YAML.stringify(e));break;case"json":await Bun.write(r,JSON.stringify(e));break;case"text":default:await Bun.write(r,e.toString())}};import O from"fs/promises";var C=async(r,e)=>{if(typeof r==="string"&&!r.includes("*"))return await e.map(r,0,[]);let t=await Array.fromAsync(O.glob(r,{cwd:e.cwd})),n=e.filter?t.filter(e.filter):t;return await Promise.all(n.map(e.map))};import x from"fs/promises";import g from"path";var _=async(r,e)=>{if(e?.targetDirectory&&e?.removeFirst)try{await x.rm(e?.targetDirectory,{recursive:!0,force:!0})}catch(t){throw Error(`Failed to clean the output directory: ${t.message}`)}for(let t of r)await v(t,e)},v=async(r,e)=>{let t=g.join(e?.targetDirectory??".",r.name),n=g.dirname(t);if(e?.classes){if(r.class!==void 0&&!e.classes.includes(r.class))return;if(e.classRequired&&r.class===void 0)throw Error(`Output "${r.name}" is missing class field`)}if(e?.writing?.(r)===!1)return;try{await x.mkdir(n,{recursive:!0})}catch(a){throw Error(`Failed to create target directory "${n}" for output "${t}": ${a.message}`)}try{await u(t,r.value,r.type??"text")}catch(a){throw Error(`Failed to write output "${t}": ${a.message}`)}};import w from"path";import d from"path";var f=(r)=>r?d.isAbsolute(r)?r:d.join(process.cwd(),r):process.cwd();var B=async(r,e)=>{let t=[];for(let n of r)try{let a=!w.isAbsolute(n)?w.join(f(e?.cwd),n):n;if(e?.filter?.(a)===!1)continue;let s=await import(a);if(e?.resolveDefault==="only"&&!s.default)throw Error(`Module ${n} does not have a default export`);let i=e?.resolveDefault?s.default??s:s,m=e?.map?await e.map(i,n):i;if(m!==void 0)t.push(m)}catch(a){if(e?.fail?.(n,a)===!1)continue;throw Error(`Failed to import module ${n}: ${a.message??a}`)}return t},V=async(r,e)=>{let t=[];for(let n of r){let a=await Array.fromAsync(new Bun.Glob(n).scan({cwd:f(e?.cwd),absolute:!0}));t.push(...await B(a,e))}return t};export{_ as writeOutputs,v as writeOutput,u as writeFormat,y as locate,D as loadFormat,B as importList,V as importGlob,C as globMap,l as exists};
package/package.json CHANGED
@@ -1,13 +1,10 @@
1
1
  {
2
2
  "name": "@homedev/files",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "files utilities",
5
5
  "author": "julzor",
6
6
  "license": "ISC",
7
7
  "main": "dist/index.js",
8
8
  "type": "module",
9
- "dependencies": {
10
- "yaml": "^2.8.2"
11
- },
12
9
  "typings": "dist/index.d.ts"
13
10
  }