@design-edito/tools 0.0.25 → 0.0.27

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@design-edito/tools",
3
- "version": "0.0.25",
3
+ "version": "0.0.27",
4
4
  "description": "",
5
5
  "author": "Maxime Fabas",
6
6
  "license": "ISC",
@@ -14,14 +14,20 @@ export type Options = {
14
14
  followSimlinks?: boolean;
15
15
  dedupeSimlinksContents?: boolean;
16
16
  maxDepth?: number;
17
- filter?: (path: string, details: ChildDetails) => boolean | Promise<boolean>;
17
+ returnRelative?: boolean;
18
+ exclude?: RegExp | null;
19
+ include?: RegExp | null;
20
+ filter?: ((path: string, details: ChildDetails) => boolean | Promise<boolean>);
18
21
  };
19
22
  export declare const defaultOptions: Required<Options>;
20
23
  export declare const fillOptions: (input: Options) => Required<Options>;
21
24
  export type Context = {
22
25
  depth?: number;
23
26
  lstats?: Stats | null;
27
+ rootPath?: string | null;
24
28
  };
25
29
  export declare const defaultContext: Required<Context>;
26
30
  export declare const fillContext: (input: Context) => Required<Context>;
27
- export default function listSubpaths(inputPath: string, _options?: Options, _context?: Context): Promise<string[]>;
31
+ export default function listSubpaths(...args: Parameters<typeof listAbsoluteSubpaths>): Promise<string[]>;
32
+ declare function listAbsoluteSubpaths(inputPath: string, _options?: Options, __private_context?: Context): Promise<string[]>;
33
+ export {};
@@ -1 +1 @@
1
- import{promises as a}from"node:fs";import m from"node:path";var S={directories:!0,files:!0,symlinks:!0,hidden:!0,followSimlinks:!1,dedupeSimlinksContents:!1,maxDepth:1/0,filter:()=>!0},k=i=>({...S,...i}),C={depth:0,lstats:null},D=i=>({...C,...i});async function p(i,y={},b={}){let t=k(y),r=D(b),e=[];if(r.depth>t.maxDepth)return e;try{if(!(r.lstats??await a.lstat(i)).isDirectory())return e}catch{return e}let w=await a.readdir(i);return await Promise.all(w.map(async h=>{let s=m.join(i,h),l=await a.lstat(s);try{let o=l.isDirectory(),n=l.isSymbolicLink(),d=!o&&!n,u=m.basename(s).startsWith("."),x=o?"directory":n?"symlink":"file";if(o&&t.directories===!1)throw!0;if(n&&t.symlinks===!1||d&&t.files===!1||u&&t.hidden===!1)throw!1;let c=n?await a.realpath(s):s;if(!await t.filter(s,{type:x,hidden:u,realPath:c}))throw!0;if(n)if(t.followSimlinks===!1)e.push(s);else{let f=await p(c,t,{depth:r.depth+1});e.push(c,...f)}else if(o){let f=await p(s,t,{depth:r.depth+1,lstats:l});e.push(s,...f)}else e.push(s)}catch(o){if(typeof o!="boolean")throw new Error("This try/catch block should only throw booleans");if(!o)return[];let d=await p(s,t,{depth:r.depth+1,lstats:l});e.push(...d)}})),t.dedupeSimlinksContents?Array.from(new Set(e)):e}export{p as default,C as defaultContext,S as defaultOptions,D as fillContext,k as fillOptions};
1
+ import{promises as a}from"node:fs";import h from"node:path";var P={directories:!0,files:!0,symlinks:!0,hidden:!0,followSimlinks:!1,dedupeSimlinksContents:!1,maxDepth:1/0,returnRelative:!1,exclude:null,include:null,filter:()=>!0},w=s=>({...P,...s}),v={depth:0,lstats:null,rootPath:null},g=s=>({...v,...s});async function O(...s){let[u,c]=s,t=w(c??{}),e=await p(...s);return t.returnRelative?e.map(i=>h.relative(u,i)):e}async function p(s,u={},c={}){let t=w(u),e=g(c);e.rootPath===null&&(e.rootPath=s);let i=[];if(e.depth>t.maxDepth)return i;try{if(!(e.lstats??await a.lstat(s)).isDirectory())return i}catch{return i}let S=await a.readdir(s);return await Promise.all(S.map(async d=>{let o=h.join(s,d),k=h.relative(e.rootPath??s,o),r=await a.lstat(o);try{let l=r.isDirectory(),n=r.isSymbolicLink(),f=!l&&!n,x=h.basename(o).startsWith("."),C=l?"directory":n?"symlink":"file";if(l&&t.directories===!1)throw!0;if(n&&t.symlinks===!1||f&&t.files===!1||x&&t.hidden===!1)throw!1;let m=n?await a.realpath(o):o,y=t.returnRelative?k:o,R=t.exclude?.test(y)===!0,D=t.include?.test(y)===!0;if(R&&!D)throw!1;if(!await t.filter(y,{type:C,hidden:x,realPath:m}))throw!0;if(n)if(t.followSimlinks===!1)i.push(o);else{let b=await p(m,t,{...e,depth:e.depth+1});i.push(m,...b)}else if(l){let b=await p(o,t,{...e,depth:e.depth+1,lstats:r});i.push(o,...b)}else i.push(o)}catch(l){if(typeof l!="boolean")throw new Error("This try/catch block should only throw booleans");if(!l)return[];let f=await p(o,t,{...e,depth:e.depth+1,lstats:r});i.push(...f)}})),t.dedupeSimlinksContents?Array.from(new Set(i)):i}export{O as default,v as defaultContext,P as defaultOptions,g as fillContext,w as fillOptions};