@design-edito/tools 0.0.25 → 0.0.27
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/package.json
CHANGED
@@ -14,14 +14,20 @@ export type Options = {
|
|
14
14
|
followSimlinks?: boolean;
|
15
15
|
dedupeSimlinksContents?: boolean;
|
16
16
|
maxDepth?: number;
|
17
|
-
|
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(
|
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
|
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};
|