snyk-docker-plugin
Version:
Snyk CLI docker plugin
33 lines • 1.38 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.getRequirements = void 0;
const common_1 = require("./common");
// This looks like a crazy regex, but it's long because of the named capture groups
// which make the result easier to read. It essentially breaks each line into name,
// specifier and version, where only the name is mandatory
const VERSION_PARSE_REGEX = /^(?<name>[\w.-]+)((\[(?<extras>.*)\])?)((?<specifier><|<=|!=|==|>=|>|~=|===)(?<version>[\w.]*))?/;
function getRequirements(fileContent) {
const lines = fileContent.split("\n");
const parsedLines = lines.map(parseLine).filter((res) => res !== null);
return parsedLines;
}
exports.getRequirements = getRequirements;
function parseLine(line) {
line = line.trim();
if (line.length === 0) {
return null;
}
const parsedLine = VERSION_PARSE_REGEX.exec(line);
if (!(parsedLine === null || parsedLine === void 0 ? void 0 : parsedLine.groups)) {
return null;
}
const { name, extras, specifier, version } = parsedLine.groups;
const correctedSpecifier = (0, common_1.specifierValidRange)(specifier, version);
return {
name: name.toLowerCase(),
specifier: correctedSpecifier,
version,
extras: (0, common_1.parseExtraNames)(extras),
};
}
//# sourceMappingURL=requirements-parser.js.map
;