diff --git a/lib/analyzer/image-inspector.ts b/lib/analyzer/image-inspector.ts index ce11c78a..b5091e2e 100644 --- a/lib/analyzer/image-inspector.ts +++ b/lib/analyzer/image-inspector.ts @@ -48,7 +48,6 @@ async function pullWithDockerBinary( password: string | undefined, platform: string | undefined, ): Promise { - let pullAndSaveSuccessful = false; try { if (username || password) { debug( @@ -57,13 +56,12 @@ async function pullWithDockerBinary( } await docker.pullCli(targetImage, { platform }); await docker.save(targetImage, saveLocation); - return (pullAndSaveSuccessful = true); + return true; } catch (err) { debug(`couldn't pull ${targetImage} using docker binary: ${err.message}`); - handleDockerPullError(err.stderr, platform); - return pullAndSaveSuccessful; + return false; } } @@ -81,10 +79,9 @@ function handleDockerPullError(err: string, platform?: string) { "manifest unknown", ]; if (unknownManifestConditions.some((value) => err.includes(value))) { - if (platform) { - throw new Error(`The image does not exist for ${platform}`); - } - throw new Error(`The image does not exist for the current platform`); + throw new Error( + `The image does not exist for ${platform ?? "the current platform"}`, + ); } if (err.includes("invalid reference format")) { diff --git a/lib/inputs/file-pattern/static.ts b/lib/inputs/file-pattern/static.ts index 3f307fb8..11f0a15d 100644 --- a/lib/inputs/file-pattern/static.ts +++ b/lib/inputs/file-pattern/static.ts @@ -5,25 +5,20 @@ import { ExtractAction, ExtractedLayers } from "../../extractor/types"; import { streamToString } from "../../stream-utils"; import { ManifestFile } from "../../types"; +/** + * Return false if any exclusion pattern matches, + * return true if any inclusion pattern matches + */ function generatePathMatcher( globsInclude: string[], globsExclude: string[], ): (filePath: string) => boolean { return (filePath: string): boolean => { - let exclude = false; - for (const g of globsExclude) { - if (!exclude && minimatch(filePath, g)) { - exclude = true; - } - } - if (!exclude) { - for (const g of globsInclude) { - if (minimatch(filePath, g)) { - return true; - } - } + if (globsExclude.some((glob) => minimatch(filePath, glob))) { + return false; } - return false; + + return globsInclude.some((glob) => minimatch(filePath, glob)); }; } diff --git a/lib/python-parser/requirements-parser.ts b/lib/python-parser/requirements-parser.ts index 8fc4d136..a9b7350c 100644 --- a/lib/python-parser/requirements-parser.ts +++ b/lib/python-parser/requirements-parser.ts @@ -15,7 +15,8 @@ export function getRequirements(fileContent: string): PythonRequirement[] { function parseLine(line: string): PythonRequirement | null { line = line.trim(); - if (line.length === 0) { + // there's no point in calling the regex if the line is a comment + if (line.length === 0 || line.startsWith("#")) { return null; } const parsedLine = VERSION_PARSE_REGEX.exec(line); @@ -23,10 +24,9 @@ function parseLine(line: string): PythonRequirement | null { return null; } const { name, extras, specifier, version } = parsedLine.groups; - const correctedSpecifier = specifierValidRange(specifier, version); return { name: name.toLowerCase(), - specifier: correctedSpecifier, + specifier: specifierValidRange(specifier, version), version, extras: parseExtraNames(extras), } as PythonRequirement;