Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dev: lint
Browse files Browse the repository at this point in the history
Torathion committed Jan 22, 2025
1 parent f8db6f7 commit e2b5b3e
Showing 2 changed files with 13 additions and 15 deletions.
19 changes: 8 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -116,12 +116,12 @@ function processPatterns(
const newPattern = normalizePattern(pattern, expandDirectories, cwd, properties, false);
matchPatterns.push(newPattern);
const split = newPattern.split('/');
let splitSize = split.length
let splitSize = split.length;
if (split[splitSize - 1] === '**') {
if (split[splitSize - 2] !== '..') {
split[splitSize - 2] = '**';
split.pop();
splitSize--
splitSize--;
}
transformed.push(splitSize ? split.join('/') : '*');
} else {
@@ -184,7 +184,7 @@ function crawl(options: GlobOptions, cwd: string, sync: boolean) {
};

const processed = processPatterns(options, cwd, properties);
const nocase = options.caseSensitiveMatch === false
const nocase = options.caseSensitiveMatch === false;

const matcher = picomatch(processed.match, {
dot: options.dot,
@@ -216,7 +216,7 @@ function crawl(options: GlobOptions, cwd: string, sync: boolean) {
const matches = matcher(path);

if (matches) {
log(`matched ${path}`)
log(`matched ${path}`);
}

return matches;
@@ -229,7 +229,7 @@ function crawl(options: GlobOptions, cwd: string, sync: boolean) {
const skipped = ignore(relativePath) || exclude(relativePath);

if (!skipped) {
log(`crawling ${p}`)
log(`crawling ${p}`);
}

return skipped;
@@ -266,18 +266,15 @@ function crawl(options: GlobOptions, cwd: string, sync: boolean) {
}

// backslashes are removed so that inferred roots like `C:/New folder \\(1\\)` work
const root = properties.root = properties.root.replace(/\\/g, '');
properties.root = properties.root.replace(/\\/g, '');
const root = properties.root;
const api = new fdir(fdirOptions).crawl(root);

if (cwd === root || options.absolute) {
return sync ? api.sync() : api.withPromise();
}

return sync
? formatPaths(api.sync(), cwd, root)
: api
.withPromise()
.then(paths => formatPaths(paths, cwd, root));
return sync ? formatPaths(api.sync(), cwd, root) : api.withPromise().then(paths => formatPaths(paths, cwd, root));
}

export function glob(patterns: string | string[], options?: Omit<GlobOptions, 'patterns'>): Promise<string[]>;
9 changes: 5 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import picomatch from 'picomatch';

const isWin = process.platform === 'win32'
const isWin = process.platform === 'win32';

// #region convertPathToPattern
const ESCAPED_WIN32_BACKSLASHES = /\\(?![()[\]{}!+@])/g;
@@ -12,8 +12,9 @@ export function convertWin32PathToPattern(path: string): string {
return escapeWin32Path(path).replace(ESCAPED_WIN32_BACKSLASHES, '/');
}

export const convertPathToPattern: (path: string) => string =
isWin ? convertWin32PathToPattern : convertPosixPathToPattern;
export const convertPathToPattern: (path: string) => string = isWin
? convertWin32PathToPattern
: convertPosixPathToPattern;
// #endregion

// #region escapePath
@@ -62,6 +63,6 @@ export function isDynamicPattern(pattern: string, options?: { caseSensitiveMatch
* @param task - the current task.
*/
export function log(task: string): void {
console.log(`[tinyglobby ${new Date().toLocaleTimeString('es')}] ${task}`)
console.log(`[tinyglobby ${new Date().toLocaleTimeString('es')}] ${task}`);
}
// #endregion

0 comments on commit e2b5b3e

Please sign in to comment.