mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-12 06:56:24 +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 { regexMatches } from '../../../../test/util';
|
||||||
|
import { minimatch } from '../../../util/minimatch';
|
||||||
import { defaultConfig } from './default-config';
|
import { defaultConfig } from './default-config';
|
||||||
|
|
||||||
describe('modules/manager/hermit/default-config', () => {
|
describe('modules/manager/hermit/default-config', () => {
|
||||||
describe('excludeCommitPaths', () => {
|
describe('excludeCommitPaths', () => {
|
||||||
function miniMatches(target: string, patterns: string[]): boolean {
|
function miniMatches(target: string, patterns: string[]): boolean {
|
||||||
return patterns.some((patt: string) => {
|
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 upath from 'upath';
|
||||||
import { logger } from '../../../logger';
|
import { logger } from '../../../logger';
|
||||||
import { readLocalDirectory } from '../../../util/fs';
|
import { readLocalDirectory } from '../../../util/fs';
|
||||||
|
import { minimatch } from '../../../util/minimatch';
|
||||||
import { regEx } from '../../../util/regex';
|
import { regEx } from '../../../util/regex';
|
||||||
import { HermitDatasource } from '../../datasource/hermit';
|
import { HermitDatasource } from '../../datasource/hermit';
|
||||||
import type { PackageDependency, PackageFileContent } from '../types';
|
import type { PackageDependency, PackageFileContent } from '../types';
|
||||||
|
@ -68,7 +68,7 @@ async function listHermitPackages(
|
||||||
const out = [] as HermitListItem[];
|
const out = [] as HermitListItem[];
|
||||||
|
|
||||||
for (const f of files) {
|
for (const f of files) {
|
||||||
if (!minimatch(f, '.*.pkg')) {
|
if (!minimatch('.*.pkg').match(f)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
import { minimatch } from 'minimatch';
|
|
||||||
import { logger } from '../../../../logger';
|
import { logger } from '../../../../logger';
|
||||||
|
import { minimatch } from '../../../../util/minimatch';
|
||||||
|
|
||||||
export function matchesAnyPattern(val: string, patterns: string[]): boolean {
|
export function matchesAnyPattern(val: string, patterns: string[]): boolean {
|
||||||
const res = patterns.some(
|
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`);
|
logger.trace({ val, patterns, res }, `matchesAnyPattern`);
|
||||||
return res;
|
return res;
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
// TODO: types (#7154)
|
// TODO: types (#7154)
|
||||||
import is from '@sindresorhus/is';
|
import is from '@sindresorhus/is';
|
||||||
import { minimatch } from 'minimatch';
|
|
||||||
import upath from 'upath';
|
import upath from 'upath';
|
||||||
import { GlobalConfig } from '../../../../config/global';
|
import { GlobalConfig } from '../../../../config/global';
|
||||||
import {
|
import {
|
||||||
|
@ -20,6 +19,7 @@ import {
|
||||||
readLocalFile,
|
readLocalFile,
|
||||||
renameLocalFile,
|
renameLocalFile,
|
||||||
} from '../../../../util/fs';
|
} from '../../../../util/fs';
|
||||||
|
import { minimatch } from '../../../../util/minimatch';
|
||||||
import { trimSlashes } from '../../../../util/url';
|
import { trimSlashes } from '../../../../util/url';
|
||||||
import type { PostUpdateConfig, Upgrade } from '../../types';
|
import type { PostUpdateConfig, Upgrade } from '../../types';
|
||||||
import { composeLockFile, parseLockFile } from '../utils';
|
import { composeLockFile, parseLockFile } from '../utils';
|
||||||
|
@ -246,7 +246,7 @@ export function divideWorkspaceAndRootDeps(
|
||||||
// stop when the first match is found and
|
// stop when the first match is found and
|
||||||
// add workspaceDir to workspaces set and upgrade object
|
// add workspaceDir to workspaces set and upgrade object
|
||||||
for (const workspacePattern of workspacePatterns ?? []) {
|
for (const workspacePattern of workspacePatterns ?? []) {
|
||||||
if (minimatch(workspaceDir, workspacePattern)) {
|
if (minimatch(workspacePattern).match(workspaceDir)) {
|
||||||
workspaceName = workspaceDir;
|
workspaceName = workspaceDir;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import is from '@sindresorhus/is';
|
import is from '@sindresorhus/is';
|
||||||
import { minimatch } from 'minimatch';
|
|
||||||
import type { PackageRule, PackageRuleInputConfig } from '../../config/types';
|
import type { PackageRule, PackageRuleInputConfig } from '../../config/types';
|
||||||
|
import { minimatch } from '../minimatch';
|
||||||
import { Matcher } from './base';
|
import { Matcher } from './base';
|
||||||
|
|
||||||
export class FileNamesMatcher extends Matcher {
|
export class FileNamesMatcher extends Matcher {
|
||||||
|
@ -17,10 +17,10 @@ export class FileNamesMatcher extends Matcher {
|
||||||
|
|
||||||
return matchFileNames.some(
|
return matchFileNames.some(
|
||||||
(matchFileName) =>
|
(matchFileName) =>
|
||||||
minimatch(packageFile, matchFileName, { dot: true }) ||
|
minimatch(matchFileName, { dot: true }).match(packageFile) ||
|
||||||
(is.array(lockFiles) &&
|
(is.array(lockFiles) &&
|
||||||
lockFiles.some((lockFile) =>
|
lockFiles.some((lockFile) =>
|
||||||
minimatch(lockFile, matchFileName, { dot: true })
|
minimatch(matchFileName, { dot: true }).match(lockFile)
|
||||||
))
|
))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import is from '@sindresorhus/is';
|
import is from '@sindresorhus/is';
|
||||||
import { minimatch } from 'minimatch';
|
|
||||||
import { logger } from '../../logger';
|
import { logger } from '../../logger';
|
||||||
|
import { minimatch } from '../minimatch';
|
||||||
import { regEx } from '../regex';
|
import { regEx } from '../regex';
|
||||||
|
|
||||||
export function matchRegexOrMinimatch(pattern: string, input: string): boolean {
|
export function matchRegexOrMinimatch(pattern: string, input: string): boolean {
|
||||||
|
@ -13,7 +13,8 @@ export function matchRegexOrMinimatch(pattern: string, input: string): boolean {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return minimatch(input, pattern, { dot: true });
|
|
||||||
|
return minimatch(pattern, { dot: true }).match(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function anyMatchRegexOrMinimatch(
|
export function anyMatchRegexOrMinimatch(
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { minimatch } from 'minimatch';
|
|
||||||
import type { RenovateConfig } from '../../../config/types';
|
import type { RenovateConfig } from '../../../config/types';
|
||||||
import { logger } from '../../../logger';
|
import { logger } from '../../../logger';
|
||||||
|
import { minimatch } from '../../../util/minimatch';
|
||||||
import { regEx } from '../../../util/regex';
|
import { regEx } from '../../../util/regex';
|
||||||
|
|
||||||
export function getIncludedFiles(
|
export function getIncludedFiles(
|
||||||
|
@ -13,7 +13,8 @@ export function getIncludedFiles(
|
||||||
return fileList.filter((file) =>
|
return fileList.filter((file) =>
|
||||||
includePaths.some(
|
includePaths.some(
|
||||||
(includePath) =>
|
(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(
|
!ignorePaths.some(
|
||||||
(ignorePath) =>
|
(ignorePath) =>
|
||||||
file.includes(ignorePath) ||
|
file.includes(ignorePath) ||
|
||||||
minimatch(file, ignorePath, { dot: true })
|
minimatch(ignorePath, { dot: true }).match(file)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
// TODO #7154
|
// TODO #7154
|
||||||
import is from '@sindresorhus/is';
|
import is from '@sindresorhus/is';
|
||||||
import { minimatch } from 'minimatch';
|
|
||||||
import { GlobalConfig } from '../../../../config/global';
|
import { GlobalConfig } from '../../../../config/global';
|
||||||
import { CONFIG_SECRETS_EXPOSED } from '../../../../constants/error-messages';
|
import { CONFIG_SECRETS_EXPOSED } from '../../../../constants/error-messages';
|
||||||
import { logger } from '../../../../logger';
|
import { logger } from '../../../../logger';
|
||||||
import { scm } from '../../../../modules/platform/scm';
|
import { scm } from '../../../../modules/platform/scm';
|
||||||
|
import { minimatch } from '../../../../util/minimatch';
|
||||||
import { sanitize } from '../../../../util/sanitize';
|
import { sanitize } from '../../../../util/sanitize';
|
||||||
import type { BranchConfig } from '../../../types';
|
import type { BranchConfig } from '../../../types';
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ export function commitFilesToBranch(
|
||||||
if (is.nonEmptyArray(config.excludeCommitPaths)) {
|
if (is.nonEmptyArray(config.excludeCommitPaths)) {
|
||||||
updatedFiles = updatedFiles.filter(({ path: filePath }) => {
|
updatedFiles = updatedFiles.filter(({ path: filePath }) => {
|
||||||
const matchesExcludePaths = config.excludeCommitPaths!.some(
|
const matchesExcludePaths = config.excludeCommitPaths!.some(
|
||||||
(excludedPath) => minimatch(filePath, excludedPath, { dot: true })
|
(excludedPath) => minimatch(excludedPath, { dot: true }).match(filePath)
|
||||||
);
|
);
|
||||||
if (matchesExcludePaths) {
|
if (matchesExcludePaths) {
|
||||||
logger.debug(`Excluding ${filePath} from commit`);
|
logger.debug(`Excluding ${filePath} from commit`);
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
// TODO #7154
|
// TODO #7154
|
||||||
import is from '@sindresorhus/is';
|
import is from '@sindresorhus/is';
|
||||||
import { minimatch } from 'minimatch';
|
|
||||||
import { mergeChildConfig } from '../../../../config';
|
import { mergeChildConfig } from '../../../../config';
|
||||||
import { GlobalConfig } from '../../../../config/global';
|
import { GlobalConfig } from '../../../../config/global';
|
||||||
import { addMeta, logger } from '../../../../logger';
|
import { addMeta, logger } from '../../../../logger';
|
||||||
|
@ -13,6 +12,7 @@ import {
|
||||||
} from '../../../../util/fs';
|
} from '../../../../util/fs';
|
||||||
import { getRepoStatus } from '../../../../util/git';
|
import { getRepoStatus } from '../../../../util/git';
|
||||||
import type { FileChange } from '../../../../util/git/types';
|
import type { FileChange } from '../../../../util/git/types';
|
||||||
|
import { minimatch } from '../../../../util/minimatch';
|
||||||
import { regEx } from '../../../../util/regex';
|
import { regEx } from '../../../../util/regex';
|
||||||
import { sanitize } from '../../../../util/sanitize';
|
import { sanitize } from '../../../../util/sanitize';
|
||||||
import { compile } from '../../../../util/template';
|
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 relativePath of status.modified.concat(status.not_added)) {
|
||||||
for (const pattern of fileFilters) {
|
for (const pattern of fileFilters) {
|
||||||
if (minimatch(relativePath, pattern, { dot: true })) {
|
if (minimatch(pattern, { dot: true }).match(relativePath)) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
{ file: relativePath, pattern },
|
{ file: relativePath, pattern },
|
||||||
'Post-upgrade file saved'
|
'Post-upgrade file saved'
|
||||||
|
@ -138,7 +138,7 @@ export async function postUpgradeCommandsExecutor(
|
||||||
|
|
||||||
for (const relativePath of status.deleted || []) {
|
for (const relativePath of status.deleted || []) {
|
||||||
for (const pattern of fileFilters) {
|
for (const pattern of fileFilters) {
|
||||||
if (minimatch(relativePath, pattern, { dot: true })) {
|
if (minimatch(pattern, { dot: true }).match(relativePath)) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
{ file: relativePath, pattern },
|
{ file: relativePath, pattern },
|
||||||
'Post-upgrade file removed'
|
'Post-upgrade file removed'
|
||||||
|
|
Loading…
Reference in a new issue