Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use minimatch util #23549

Merged
merged 4 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/modules/manager/hermit/default-config.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { minimatch } from 'minimatch';
import { regexMatches } from '../../../../test/util';
import { minimatch } from '../../../util/minimatch';
import { defaultConfig } from './default-config';

describe('modules/manager/hermit/default-config', () => {
describe('excludeCommitPaths', () => {
function miniMatches(target: string, patterns: string[]): boolean {
return patterns.some((patt: string) => {
return minimatch(target, patt, { dot: true });
return minimatch(patt, { dot: true }).match(target);
});
}

Expand Down
4 changes: 2 additions & 2 deletions lib/modules/manager/hermit/extract.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { minimatch } from 'minimatch';
import upath from 'upath';
import { logger } from '../../../logger';
import { readLocalDirectory } from '../../../util/fs';
import { minimatch } from '../../../util/minimatch';
import { regEx } from '../../../util/regex';
import { HermitDatasource } from '../../datasource/hermit';
import type { PackageDependency, PackageFileContent } from '../types';
Expand Down Expand Up @@ -68,7 +68,7 @@ async function listHermitPackages(
const out = [] as HermitListItem[];

for (const f of files) {
if (!minimatch(f, '.*.pkg')) {
if (!minimatch('.*.pkg').match(f)) {
continue;
}

Expand Down
5 changes: 3 additions & 2 deletions lib/modules/manager/npm/extract/utils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { minimatch } from 'minimatch';
import { logger } from '../../../../logger';
import { minimatch } from '../../../../util/minimatch';

export function matchesAnyPattern(val: string, patterns: string[]): boolean {
const res = patterns.some(
(pattern) => pattern === val + '/' || minimatch(val, pattern, { dot: true })
(pattern) =>
pattern === `${val}/` || minimatch(pattern, { dot: true }).match(val)
);
logger.trace({ val, patterns, res }, `matchesAnyPattern`);
return res;
Expand Down
4 changes: 2 additions & 2 deletions lib/modules/manager/npm/post-update/npm.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// TODO: types (#7154)
import is from '@sindresorhus/is';
import { minimatch } from 'minimatch';
import upath from 'upath';
import { GlobalConfig } from '../../../../config/global';
import {
Expand All @@ -20,6 +19,7 @@ import {
readLocalFile,
renameLocalFile,
} from '../../../../util/fs';
import { minimatch } from '../../../../util/minimatch';
import { trimSlashes } from '../../../../util/url';
import type { PostUpdateConfig, Upgrade } from '../../types';
import { composeLockFile, parseLockFile } from '../utils';
Expand Down Expand Up @@ -246,7 +246,7 @@ export function divideWorkspaceAndRootDeps(
// stop when the first match is found and
// add workspaceDir to workspaces set and upgrade object
for (const workspacePattern of workspacePatterns ?? []) {
if (minimatch(workspaceDir, workspacePattern)) {
if (minimatch(workspacePattern).match(workspaceDir)) {
workspaceName = workspaceDir;
break;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/util/package-rules/files.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import is from '@sindresorhus/is';
import { minimatch } from 'minimatch';
import type { PackageRule, PackageRuleInputConfig } from '../../config/types';
import { minimatch } from '../minimatch';
import { Matcher } from './base';

export class FileNamesMatcher extends Matcher {
Expand All @@ -17,10 +17,10 @@ export class FileNamesMatcher extends Matcher {

return matchFileNames.some(
(matchFileName) =>
minimatch(packageFile, matchFileName, { dot: true }) ||
minimatch(matchFileName, { dot: true }).match(packageFile) ||
(is.array(lockFiles) &&
lockFiles.some((lockFile) =>
minimatch(lockFile, matchFileName, { dot: true })
minimatch(matchFileName, { dot: true }).match(lockFile)
))
);
}
Expand Down
5 changes: 3 additions & 2 deletions lib/util/package-rules/match.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import is from '@sindresorhus/is';
import { minimatch } from 'minimatch';
import { logger } from '../../logger';
import { minimatch } from '../minimatch';
import { regEx } from '../regex';

export function matchRegexOrMinimatch(pattern: string, input: string): boolean {
Expand All @@ -13,7 +13,8 @@ export function matchRegexOrMinimatch(pattern: string, input: string): boolean {
return false;
}
}
return minimatch(input, pattern, { dot: true });

return minimatch(pattern, { dot: true }).match(input);
}

export function anyMatchRegexOrMinimatch(
Expand Down
7 changes: 4 additions & 3 deletions lib/workers/repository/extract/file-match.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { minimatch } from 'minimatch';
import type { RenovateConfig } from '../../../config/types';
import { logger } from '../../../logger';
import { minimatch } from '../../../util/minimatch';
import { regEx } from '../../../util/regex';

export function getIncludedFiles(
Expand All @@ -13,7 +13,8 @@ export function getIncludedFiles(
return fileList.filter((file) =>
includePaths.some(
(includePath) =>
file === includePath || minimatch(file, includePath, { dot: true })
file === includePath ||
minimatch(includePath, { dot: true }).match(file)
)
);
}
Expand All @@ -30,7 +31,7 @@ export function filterIgnoredFiles(
!ignorePaths.some(
(ignorePath) =>
file.includes(ignorePath) ||
minimatch(file, ignorePath, { dot: true })
minimatch(ignorePath, { dot: true }).match(file)
)
);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/workers/repository/update/branch/commit.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// TODO #7154
import is from '@sindresorhus/is';
import { minimatch } from 'minimatch';
import { GlobalConfig } from '../../../../config/global';
import { CONFIG_SECRETS_EXPOSED } from '../../../../constants/error-messages';
import { logger } from '../../../../logger';
import { scm } from '../../../../modules/platform/scm';
import { minimatch } from '../../../../util/minimatch';
import { sanitize } from '../../../../util/sanitize';
import type { BranchConfig } from '../../../types';

Expand All @@ -18,7 +18,7 @@ export function commitFilesToBranch(
if (is.nonEmptyArray(config.excludeCommitPaths)) {
updatedFiles = updatedFiles.filter(({ path: filePath }) => {
const matchesExcludePaths = config.excludeCommitPaths!.some(
(excludedPath) => minimatch(filePath, excludedPath, { dot: true })
(excludedPath) => minimatch(excludedPath, { dot: true }).match(filePath)
);
if (matchesExcludePaths) {
logger.debug(`Excluding ${filePath} from commit`);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// TODO #7154
import is from '@sindresorhus/is';
import { minimatch } from 'minimatch';
import { mergeChildConfig } from '../../../../config';
import { GlobalConfig } from '../../../../config/global';
import { addMeta, logger } from '../../../../logger';
Expand All @@ -13,6 +12,7 @@ import {
} from '../../../../util/fs';
import { getRepoStatus } from '../../../../util/git';
import type { FileChange } from '../../../../util/git/types';
import { minimatch } from '../../../../util/minimatch';
import { regEx } from '../../../../util/regex';
import { sanitize } from '../../../../util/sanitize';
import { compile } from '../../../../util/template';
Expand Down Expand Up @@ -110,7 +110,7 @@ export async function postUpgradeCommandsExecutor(

for (const relativePath of status.modified.concat(status.not_added)) {
for (const pattern of fileFilters) {
if (minimatch(relativePath, pattern, { dot: true })) {
if (minimatch(pattern, { dot: true }).match(relativePath)) {
logger.debug(
{ file: relativePath, pattern },
'Post-upgrade file saved'
Expand Down Expand Up @@ -138,7 +138,7 @@ export async function postUpgradeCommandsExecutor(

for (const relativePath of status.deleted || []) {
for (const pattern of fileFilters) {
if (minimatch(relativePath, pattern, { dot: true })) {
if (minimatch(pattern, { dot: true }).match(relativePath)) {
logger.debug(
{ file: relativePath, pattern },
'Post-upgrade file removed'
Expand Down