From d51e2b98d18486a904193e100e22a9c9ed8cbb08 Mon Sep 17 00:00:00 2001 From: Superchupu <53496941+SuperchupuDev@users.noreply.github.com> Date: Sun, 1 Dec 2024 16:21:57 +0100 Subject: [PATCH] add `debug` option closes #74 --- src/index.ts | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/src/index.ts b/src/index.ts index 97a3b88..0eb4dc1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -15,6 +15,7 @@ export interface GlobOptions { expandDirectories?: boolean; onlyDirectories?: boolean; onlyFiles?: boolean; + debug?: boolean; } interface InternalProperties { @@ -191,13 +192,41 @@ function crawl(options: GlobOptions, cwd: string, sync: boolean) { ignore: processed.transformed }); + if (process.env.TINYGLOBBY_DEBUG) { + options.debug = true; + } + const fdirOptions: Partial = { // use relative paths in the matcher - filters: [(p, isDirectory) => matcher(processPath(p, cwd, properties.root, isDirectory, options.absolute))], - exclude: (_, p) => { - const relativePath = processPath(p, cwd, properties.root, true, true); - return ignore(relativePath) || exclude(relativePath); - }, + filters: [ + options.debug + ? (p, isDirectory) => { + const path = processPath(p, cwd, properties.root, isDirectory, options.absolute); + const matches = matcher(path); + + if (matches) { + console.log(`[tinyglobby ${new Date().toLocaleTimeString('es')}] matched ${path}`); + } + + return matches; + } + : (p, isDirectory) => matcher(processPath(p, cwd, properties.root, isDirectory, options.absolute)) + ], + exclude: options.debug + ? (_, p) => { + const relativePath = processPath(p, cwd, properties.root, true, true); + const skipped = ignore(relativePath) || exclude(relativePath); + + if (!skipped) { + console.log(`[tinyglobby ${new Date().toLocaleTimeString('es')}] crawling ${p}`); + } + + return skipped; + } + : (_, p) => { + const relativePath = processPath(p, cwd, properties.root, true, true); + return ignore(relativePath) || exclude(relativePath); + }, pathSeparator: '/', relativePaths: true, resolveSymlinks: true