UNPKG

snyk-go-plugin

Version:
47 lines 1.82 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseConfig = void 0; const fs = require("fs"); const path = require("path"); const snyk_go_parser_1 = require("snyk-go-parser"); const pkg_manager_1 = require("./pkg-manager"); const debug_1 = require("./debug"); async function parseConfig(root, targetFile) { const pkgManager = (0, pkg_manager_1.pkgManagerByTarget)(targetFile); (0, debug_1.debug)('detected package-manager:', pkgManager); switch (pkgManager) { case 'golangdep': { try { return await (0, snyk_go_parser_1.parseGoPkgConfig)(getDepManifest(root, targetFile), getDepLock(root, targetFile)); } catch (e) { throw new Error('failed parsing manifest/lock files for Go dep: ' + e.message); } } case 'govendor': { try { return await (0, snyk_go_parser_1.parseGoVendorConfig)(getGovendorJson(root, targetFile)); } catch (e) { throw new Error('failed parsing config file for Go Vendor Tool: ' + e.message); } } default: { throw new Error('Unsupported file: ' + targetFile); } } } exports.parseConfig = parseConfig; function getDepLock(root, targetFile) { return fs.readFileSync(path.join(root, targetFile), 'utf8'); } function getDepManifest(root, targetFile) { const manifestDir = path.dirname(path.join(root, targetFile)); const manifestPath = path.join(manifestDir, 'Gopkg.toml'); return fs.readFileSync(manifestPath, 'utf8'); } // TODO: branch, old Version can be a tag too? function getGovendorJson(root, targetFile) { return fs.readFileSync(path.join(root, targetFile), 'utf8'); } //# sourceMappingURL=config.js.map