2022-08-29 19:40:03 +00:00
|
|
|
import is from '@sindresorhus/is';
|
|
|
|
import type { PackageRule, PackageRuleInputConfig } from '../../config/types';
|
2023-07-26 07:51:10 +00:00
|
|
|
import { minimatch } from '../minimatch';
|
2022-08-29 19:40:03 +00:00
|
|
|
import { Matcher } from './base';
|
|
|
|
|
2023-05-25 15:46:28 +00:00
|
|
|
export class FileNamesMatcher extends Matcher {
|
2022-08-29 19:40:03 +00:00
|
|
|
override matches(
|
|
|
|
{ packageFile, lockFiles }: PackageRuleInputConfig,
|
2023-05-25 15:46:28 +00:00
|
|
|
{ matchFileNames }: PackageRule
|
2022-08-29 19:40:03 +00:00
|
|
|
): boolean | null {
|
2023-05-25 15:46:28 +00:00
|
|
|
if (is.undefined(matchFileNames)) {
|
2022-08-29 19:40:03 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
if (is.undefined(packageFile)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-05-25 15:46:28 +00:00
|
|
|
return matchFileNames.some(
|
|
|
|
(matchFileName) =>
|
2023-07-26 07:51:10 +00:00
|
|
|
minimatch(matchFileName, { dot: true }).match(packageFile) ||
|
2023-05-25 15:46:28 +00:00
|
|
|
(is.array(lockFiles) &&
|
|
|
|
lockFiles.some((lockFile) =>
|
2023-07-26 07:51:10 +00:00
|
|
|
minimatch(matchFileName, { dot: true }).match(lockFile)
|
2023-05-25 15:46:28 +00:00
|
|
|
))
|
2022-08-29 19:40:03 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|