-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(manager/custom): reorganize and update utility functions (#3…
- Loading branch information
1 parent
f78d778
commit d094afe
Showing
8 changed files
with
73 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import is from '@sindresorhus/is'; | ||
import { logger } from '../../../logger'; | ||
import type { PackageDependency } from '../types'; | ||
|
||
export const validMatchFields = [ | ||
'depName', | ||
'packageName', | ||
'currentValue', | ||
'currentDigest', | ||
'datasource', | ||
'versioning', | ||
'extractVersion', | ||
'registryUrl', | ||
'depType', | ||
'indentation', | ||
] as const; | ||
|
||
export type ValidMatchFields = (typeof validMatchFields)[number]; | ||
|
||
export function isValidDependency({ | ||
depName, | ||
currentValue, | ||
currentDigest, | ||
packageName, | ||
datasource, | ||
}: PackageDependency): boolean { | ||
// check if all the fields are set | ||
return ( | ||
(is.nonEmptyStringAndNotWhitespace(depName) || | ||
is.nonEmptyStringAndNotWhitespace(packageName)) && | ||
(is.nonEmptyStringAndNotWhitespace(currentDigest) || | ||
is.nonEmptyStringAndNotWhitespace(currentValue)) && | ||
is.nonEmptyStringAndNotWhitespace(datasource) | ||
); | ||
} | ||
|
||
export function checkIsValidDependency( | ||
dep: PackageDependency, | ||
packageFile: string, | ||
manager: string, | ||
): boolean { | ||
const isValid = isValidDependency(dep); | ||
if (!isValid) { | ||
const meta = { | ||
packageDependency: dep, | ||
packageFile, | ||
manager, | ||
}; | ||
logger.trace( | ||
meta, | ||
'Discovered a package dependency, but it did not pass validation. Discarding', | ||
); | ||
return isValid; | ||
} | ||
|
||
return isValid; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters