Skip to content

Commit

Permalink
use minimatchFilter instead of minimatch.filter
Browse files Browse the repository at this point in the history
  • Loading branch information
RahulGautamSingh committed Nov 17, 2023
1 parent a8dac53 commit 0722118
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
4 changes: 2 additions & 2 deletions lib/modules/manager/nuget/package-tree.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import is from '@sindresorhus/is';
import { Graph } from 'graph-data-structure';
import { minimatch } from 'minimatch';
import upath from 'upath';
import { logger } from '../../../logger';
import { minimatchFilter } from '../../../util/minimatch';
import { scm } from '../../platform/scm';
import type { ProjectFile } from './types';
import { readFileAsXmlDocument } from './util';
Expand Down Expand Up @@ -131,7 +131,7 @@ function reframeRelativePathToRootOfRepo(
async function getAllPackageFiles(): Promise<string[]> {
const allFiles = await scm.getFileList();
const filteredPackageFiles = allFiles.filter(
minimatch.filter('*.{cs,vb,fs}proj', { matchBase: true, nocase: true }),
minimatchFilter('*.{cs,vb,fs}proj', { matchBase: true, nocase: true }),
);

logger.trace({ filteredPackageFiles }, 'Found package files');
Expand Down
39 changes: 27 additions & 12 deletions lib/util/minimatch.spec.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
import { minimatch } from './minimatch';
import { minimatch, minimatchFilter } from './minimatch';

describe('util/minimatch', () => {
it('caches minimatch', () => {
expect(minimatch('foo')).toBe(minimatch('foo'));
expect(minimatch('foo', { dot: true })).toBe(
minimatch('foo', { dot: true }),
);
describe('minimatch', () => {
it('caches minimatch', () => {
expect(minimatch('foo')).toBe(minimatch('foo'));
expect(minimatch('foo', { dot: true })).toBe(
minimatch('foo', { dot: true }),
);
});

it('does not cache minimatch', () => {
expect(minimatch('foo', undefined, false)).not.toBe(
minimatch('foo', undefined, false),
);
expect(minimatch('foo')).not.toBe(minimatch('foo', undefined, false));
expect(minimatch('foo', { dot: true })).not.toBe(minimatch('foo'));
});
});

it('does not cache minimatch', () => {
expect(minimatch('foo', undefined, false)).not.toBe(
minimatch('foo', undefined, false),
);
expect(minimatch('foo')).not.toBe(minimatch('foo', undefined, false));
expect(minimatch('foo', { dot: true })).not.toBe(minimatch('foo'));
describe('minimatchFilter', () => {
it('should return a function', () => {
expect(minimatchFilter('*.js')).toBeFunction();
expect(minimatchFilter('*.js', undefined, false)).toBeFunction();
});

it('should correctly match filenames', () => {
const filterFunc = minimatchFilter('*.js');
expect(filterFunc('test.js')).toBe(true);
expect(filterFunc('test.txt')).toBe(false);
});
});
});
4 changes: 2 additions & 2 deletions lib/workers/global/autodiscover.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import is from '@sindresorhus/is';
import { minimatch } from 'minimatch';
import type { AllConfig } from '../../config/types';
import { logger } from '../../logger';
import { platform } from '../../modules/platform';
import { minimatchFilter } from '../../util/minimatch';
import { configRegexPredicate, isConfigRegex } from '../../util/regex';

// istanbul ignore next
Expand Down Expand Up @@ -107,7 +107,7 @@ export function applyFilters(repos: string[], filters: string[]): string[] {
}
res = repos.filter(autodiscoveryPred);
} else {
res = repos.filter(minimatch.filter(filter, { dot: true, nocase: true }));
res = repos.filter(minimatchFilter(filter, { dot: true, nocase: true }));
}
for (const repository of res) {
matched.add(repository);
Expand Down

0 comments on commit 0722118

Please sign in to comment.