mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-11 22:46:27 +00:00
refactor: use minimatch util (#23549)
This commit is contained in:
parent
ce1be2c5a1
commit
2159444ee1
9 changed files with 24 additions and 21 deletions
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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';
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 {
|
||||
|
@ -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';
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
@ -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)
|
||||
))
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
@ -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(
|
||||
|
|
|
@ -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(
|
||||
|
@ -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)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -30,7 +31,7 @@ export function filterIgnoredFiles(
|
|||
!ignorePaths.some(
|
||||
(ignorePath) =>
|
||||
file.includes(ignorePath) ||
|
||||
minimatch(file, ignorePath, { dot: true })
|
||||
minimatch(ignorePath, { dot: true }).match(file)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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';
|
||||
|
||||
|
@ -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`);
|
||||
|
|
|
@ -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';
|
||||
|
@ -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';
|
||||
|
@ -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'
|
||||
|
@ -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'
|
||||
|
|
Loading…
Reference in a new issue