UNPKG

snyk-go-parser

Version:

Generate a dep tree given a collection of manifests

19 lines 952 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseGoModRelativeManifestReplaces = parseGoModRelativeManifestReplaces; const GO_MOD_DELIMITER = ' => '; const replaceSectionRegex = /replace\W?\(?(.*)\)?/s; // s as regex flag means . will match newlines too const relativePathRegex = /^\.\.?\//; function parseGoModRelativeManifestReplaces(goModFileContent) { const [, replaceSection] = replaceSectionRegex.exec(goModFileContent) || []; if (!replaceSection) { return []; } return replaceSection .replace(/\/\/.*/g, '') // remove all comments .split('\n') // now we got lines of "ModulePath" => "ModulePath" | "FilePath" .map((line) => line.trim().split(GO_MOD_DELIMITER)) // split lines by ' => ' .filter(([, filePath]) => relativePathRegex.test(filePath)) .map(([, filePath]) => filePath); } //# sourceMappingURL=gomod-relative-manifest-parser.js.map