Skip to content

Commit

Permalink
change: extend defaultOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Torathion committed Feb 19, 2025
1 parent 7d112ed commit 4bb3b66
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
12 changes: 5 additions & 7 deletions src/fdir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ export function formatPaths(paths: string[], cwd: string, root: string): string[

// #region buildFdir
export function buildFdir(options: GlobOptions, props: InternalProps, processed: ProcessedPatterns, cwd: string, root: string): APIBuilder<PathsOutput> {
const nocase = options.caseSensitiveMatch === false;
const { absolute, debug, followSymbolicLinks, onlyDirectories } = options
const nocase = !options.caseSensitiveMatch;

const matcher = picomatch(processed.match, {
dot: options.dot,
Expand All @@ -48,9 +49,6 @@ export function buildFdir(options: GlobOptions, props: InternalProps, processed:
const ignore = picomatch(processed.ignore, partialMatcherOptions);
const partialMatcher = getPartialMatcher(processed.match, partialMatcherOptions);

const { absolute, onlyDirectories, debug } = options
const followSymlinks = options.followSymbolicLinks === false;

return new fdir({
filters: [(p, isDirectory) => {
const path = processPath(p, cwd, root, isDirectory, absolute);
Expand All @@ -72,10 +70,10 @@ export function buildFdir(options: GlobOptions, props: InternalProps, processed:
relativePaths: !absolute,
resolvePaths: absolute,
includeBasePath: absolute,
resolveSymlinks: !followSymlinks,
excludeSymlinks: followSymlinks,
resolveSymlinks: followSymbolicLinks,
excludeSymlinks: !followSymbolicLinks,
excludeFiles: onlyDirectories,
includeDirs: onlyDirectories || options.onlyFiles === false,
includeDirs: onlyDirectories || !options.onlyFiles,
maxDepth: options.deep && Math.round(options.deep - props.depthOffset)
}).crawl(root);
}
Expand Down
15 changes: 13 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,21 @@ function processPatterns(opts: GlobOptions, props: InternalProps): ProcessedPatt
return { match: matchPatterns, ignore: ignorePatterns };
}

// Only the literal type doesn't emit any typescript errors
const defaultOptions = {
expandDirectories: true,
debug: !!process.env.TINYGLOBBY_DEBUG,
ignore: [],
// tinyglobby exclusive behavior, should be considered deprecated
patterns: ['**/*'],
caseSensitiveMatch: true,
followSymbolicLinks: true,
onlyFiles: true
}

function getOptions(input: Input, options?: Partial<GlobOptions>): GlobOptions {
const opts = {
// patterns: ['**/*'] is tinyglobby exclusive behavior, should be considered deprecated
...{ expandDirectories: true, debug: !!process.env.TINYGLOBBY_DEBUG, ignore: [], patterns: ['**/*'] },
...defaultOptions,
...(Array.isArray(input) || typeof input === 'string' ? { ...options, patterns: input } : input)
};
opts.cwd = (opts.cwd ? path.resolve(opts.cwd) : process.cwd()).replace(BACKSLASHES, '/');
Expand Down

0 comments on commit 4bb3b66

Please sign in to comment.