Skip to content

Commit

Permalink
add debug option
Browse files Browse the repository at this point in the history
closes #74
  • Loading branch information
SuperchupuDev committed Dec 1, 2024
1 parent ee6e02b commit d51e2b9
Showing 1 changed file with 34 additions and 5 deletions.
39 changes: 34 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface GlobOptions {
expandDirectories?: boolean;
onlyDirectories?: boolean;
onlyFiles?: boolean;
debug?: boolean;
}

interface InternalProperties {
Expand Down Expand Up @@ -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<FdirOptions> = {
// 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
Expand Down

0 comments on commit d51e2b9

Please sign in to comment.