snyk-go-parser
Advanced tools
Comparing version 1.3.3 to 1.4.0
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var InvalidUserInputError = /** @class */ (function (_super) { | ||
tslib_1.__extends(InvalidUserInputError, _super); | ||
function InvalidUserInputError() { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
var _this = _super.apply(this, tslib_1.__spread(args)) || this; | ||
_this.code = 422; | ||
_this.name = 'InvalidUserInputError'; | ||
Error.captureStackTrace(_this, InvalidUserInputError); | ||
return _this; | ||
class InvalidUserInputError extends Error { | ||
constructor(...args) { | ||
super(...args); | ||
this.code = 422; | ||
this.name = 'InvalidUserInputError'; | ||
Error.captureStackTrace(this, InvalidUserInputError); | ||
} | ||
return InvalidUserInputError; | ||
}(Error)); | ||
} | ||
exports.InvalidUserInputError = InvalidUserInputError; | ||
//# sourceMappingURL=invalid-user-input-error.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var errors_1 = require("./errors"); | ||
const errors_1 = require("./errors"); | ||
// go.mod file format: | ||
@@ -9,31 +8,31 @@ // https://tip.golang.org/cmd/go/#hdr-The_go_mod_file | ||
// Subgroups: baseVersion, suffix, timestamp, hash | ||
var rePseudoVersion = /(v\d+\.\d+\.\d+)-(.*?)(\d{14})-([0-9a-f]{12})/; | ||
var reIndirect = /\/\/ indirect/; | ||
var reExactVersion = /^(.*?)(\+incompatible)?$/; | ||
var reStatementWord = /^(module|go|require|replace|exclude) (\(?)/; | ||
var reLineWithComments = /^(.*?)(\/\/.*)?$/; | ||
const rePseudoVersion = /(v\d+\.\d+\.\d+)-(.*?)(\d{14})-([0-9a-f]{12})/; | ||
const reIndirect = /\/\/ indirect/; | ||
const reExactVersion = /^(.*?)(\+incompatible)?$/; | ||
const reStatementWord = /^(module|go|require|replace|exclude) (\(?)/; | ||
const reLineWithComments = /^(.*?)(\/\/.*)?$/; | ||
function parseModuleAndMaybeVersion(lineRemainder) { | ||
var _a = tslib_1.__read(lineRemainder.trim().split(' '), 2), moduleName = _a[0], versionString = _a[1]; | ||
const [moduleName, versionString] = lineRemainder.trim().split(' '); | ||
if (!versionString) { | ||
return { moduleName: moduleName }; | ||
return { moduleName }; | ||
} | ||
return { moduleName: moduleName, version: parseVersion(versionString) }; | ||
return { moduleName, version: parseVersion(versionString) }; | ||
} | ||
function parseModuleAndVersion(lineRemainder) { | ||
var _a = tslib_1.__read(lineRemainder.trim().split(' '), 2), moduleName = _a[0], versionString = _a[1]; | ||
const [moduleName, versionString] = lineRemainder.trim().split(' '); | ||
if (!moduleName || !versionString) { | ||
throw new Error("could not split \"" + lineRemainder + "\" into moduleName and version"); | ||
throw new Error(`could not split "${lineRemainder}" into moduleName and version`); | ||
} | ||
return { moduleName: moduleName, version: parseVersion(versionString) }; | ||
return { moduleName, version: parseVersion(versionString) }; | ||
} | ||
function parseVersion(versionString) { | ||
var maybeRegexMatch = rePseudoVersion.exec(versionString); | ||
const maybeRegexMatch = rePseudoVersion.exec(versionString); | ||
if (maybeRegexMatch) { | ||
var _a = tslib_1.__read(maybeRegexMatch.slice(1), 4), baseVersion = _a[0], suffix = _a[1], timestamp = _a[2], hash = _a[3]; | ||
return { baseVersion: baseVersion, suffix: suffix, timestamp: timestamp, hash: hash }; | ||
const [baseVersion, suffix, timestamp, hash] = maybeRegexMatch.slice(1); | ||
return { baseVersion, suffix, timestamp, hash }; | ||
} | ||
else { | ||
// No pseudo version recognized, assuming the provided version string is exact | ||
var _b = tslib_1.__read(reExactVersion.exec(versionString).slice(1), 2), exactVersion = _b[0], incompatibleStr = _b[1]; | ||
return { exactVersion: exactVersion, incompatible: !!incompatibleStr }; | ||
const [exactVersion, incompatibleStr] = reExactVersion.exec(versionString).slice(1); | ||
return { exactVersion, incompatible: !!incompatibleStr }; | ||
} | ||
@@ -47,11 +46,11 @@ } | ||
if (!state.inMultilineDirective) { | ||
var maybeStatement = reStatementWord.exec(line); | ||
const maybeStatement = reStatementWord.exec(line); | ||
if (maybeStatement) { | ||
var currentVerb = maybeStatement[1]; | ||
var inMultilineDirective = !!maybeStatement[2]; // whether we found "(" | ||
const currentVerb = maybeStatement[1]; | ||
const inMultilineDirective = !!maybeStatement[2]; // whether we found "(" | ||
if (inMultilineDirective) { | ||
return { inMultilineDirective: inMultilineDirective, currentVerb: currentVerb, lineRemainder: null }; | ||
return { inMultilineDirective, currentVerb, lineRemainder: null }; | ||
} | ||
else { | ||
return { inMultilineDirective: inMultilineDirective, currentVerb: currentVerb, | ||
return { inMultilineDirective, currentVerb, | ||
lineRemainder: line.substr(currentVerb.length + 1).trim() }; | ||
@@ -61,3 +60,3 @@ } | ||
else { | ||
var lineNoComment = reLineWithComments.exec(line)[1].trim(); | ||
const lineNoComment = reLineWithComments.exec(line)[1].trim(); | ||
if (lineNoComment) { | ||
@@ -86,3 +85,3 @@ throw new Error('Unrecognized statement: ' + line); | ||
case 'require': | ||
var req = parseModuleAndVersion(lineRemainder); | ||
const req = parseModuleAndVersion(lineRemainder); | ||
req.indirect = reIndirect.test(lineRemainder); | ||
@@ -95,3 +94,3 @@ res.requires.push(req); | ||
case 'replace': | ||
var _a = tslib_1.__read(lineRemainder.split('=>'), 2), oldMod = _a[0], newMod = _a[1]; | ||
const [oldMod, newMod] = lineRemainder.split('=>'); | ||
if (!oldMod || !newMod) { | ||
@@ -106,14 +105,15 @@ throw new Error('could not split the line in two on "=>"'); | ||
default: | ||
throw new Error("Attempting to process unknown verb: " + verb + ", line remainder: " + lineRemainder); | ||
throw new Error(`Attempting to process unknown verb: ${verb}, line remainder: ${lineRemainder}`); | ||
} | ||
} | ||
catch (e) { | ||
throw new errors_1.InvalidUserInputError("Could not parse line " + lineNumber + " as " + verb + " directive:\n" + lineRemainder + "\nbecause of error: " + e); | ||
throw new errors_1.InvalidUserInputError(`Could not parse line ${lineNumber} as ${verb} directive: | ||
${lineRemainder} | ||
because of error: ${e}`); | ||
} | ||
} | ||
function parseGoMod(goModStr) { | ||
var e_1, _a; | ||
try { | ||
var lines = goModStr.split('\n'); | ||
var res = { | ||
const lines = goModStr.split('\n'); | ||
const res = { | ||
moduleName: '', | ||
@@ -124,23 +124,13 @@ requires: [], | ||
}; | ||
var state = { inMultilineDirective: false, currentVerb: null }; | ||
var i = 0; | ||
try { | ||
for (var lines_1 = tslib_1.__values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) { | ||
var line = lines_1_1.value; | ||
i++; | ||
line = line.trim(); | ||
var stateAndRemainder = updateParserState(line, state); | ||
state = stateAndRemainder; | ||
if (stateAndRemainder.lineRemainder) { | ||
processLineForDirective(state.currentVerb, stateAndRemainder.lineRemainder, res, i); | ||
} | ||
let state = { inMultilineDirective: false, currentVerb: null }; | ||
let i = 0; | ||
for (let line of lines) { | ||
i++; | ||
line = line.trim(); | ||
const stateAndRemainder = updateParserState(line, state); | ||
state = stateAndRemainder; | ||
if (stateAndRemainder.lineRemainder) { | ||
processLineForDirective(state.currentVerb, stateAndRemainder.lineRemainder, res, i); | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
if (!res.moduleName) { | ||
@@ -162,3 +152,3 @@ throw new errors_1.InvalidUserInputError('No module name specified in go.mod file'); | ||
function toSnykVersion(v) { | ||
var hash = v.hash; | ||
const hash = v.hash; | ||
if (hash) { | ||
@@ -165,0 +155,0 @@ return '#' + hash; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var parser_1 = require("./parser"); | ||
const tslib_1 = require("tslib"); | ||
const parser_1 = require("./parser"); | ||
exports.parseGoPkgConfig = parser_1.parseGoPkgConfig; | ||
exports.parseGoVendorConfig = parser_1.parseGoVendorConfig; | ||
var gomod_parser_1 = require("./gomod-parser"); | ||
const gomod_parser_1 = require("./gomod-parser"); | ||
exports.parseGoMod = gomod_parser_1.parseGoMod; | ||
@@ -17,6 +17,4 @@ exports.toSnykVersion = gomod_parser_1.toSnykVersion; | ||
function buildGoPkgDepTree(manifestFileContents, lockFileContents, options) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
return tslib_1.__generator(this, function (_a) { | ||
return [2 /*return*/, buildGoDepTree(parser_1.parseGoPkgConfig(manifestFileContents, lockFileContents))]; | ||
}); | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
return buildGoDepTree(parser_1.parseGoPkgConfig(manifestFileContents, lockFileContents)); | ||
}); | ||
@@ -29,6 +27,4 @@ } | ||
function buildGoVendorDepTree(manifestFileContents, options) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
return tslib_1.__generator(this, function (_a) { | ||
return [2 /*return*/, buildGoDepTree(parser_1.parseGoVendorConfig(manifestFileContents))]; | ||
}); | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
return buildGoDepTree(parser_1.parseGoVendorConfig(manifestFileContents)); | ||
}); | ||
@@ -38,4 +34,3 @@ } | ||
function buildGoDepTree(goProjectConfig) { | ||
var e_1, _a; | ||
var depTree = { | ||
const depTree = { | ||
name: goProjectConfig.packageName || 'root', | ||
@@ -45,21 +40,11 @@ version: '0.0.0', | ||
}; | ||
var dependencies = depTree.dependencies; | ||
try { | ||
for (var _b = tslib_1.__values(Object.keys(goProjectConfig.lockedVersions)), _c = _b.next(); !_c.done; _c = _b.next()) { | ||
var dep = _c.value; | ||
dependencies[dep] = { | ||
name: dep, | ||
version: goProjectConfig.lockedVersions[dep].version, | ||
}; | ||
} | ||
const dependencies = depTree.dependencies; | ||
for (const dep of Object.keys(goProjectConfig.lockedVersions)) { | ||
dependencies[dep] = { | ||
name: dep, | ||
version: goProjectConfig.lockedVersions[dep].version, | ||
}; | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
return depTree; | ||
} | ||
//# sourceMappingURL=index.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var toml = require("toml"); | ||
var errors_1 = require("./errors/"); | ||
const toml = require("toml"); | ||
const errors_1 = require("./errors/"); | ||
// TODO(kyegupov): split into go-dep-parser and go-vendor-parser files | ||
@@ -13,9 +13,9 @@ function parseGoPkgConfig(manifestFileContents, lockFileContents) { | ||
} | ||
var lockedVersions = parseDepLockContents(lockFileContents); | ||
var ignoredPkgs = []; | ||
const lockedVersions = parseDepLockContents(lockFileContents); | ||
let ignoredPkgs = []; | ||
if (manifestFileContents) { | ||
var manifest = parseDepManifestContents(manifestFileContents); | ||
const manifest = parseDepManifestContents(manifestFileContents); | ||
ignoredPkgs = manifest.ignored; | ||
} | ||
return { lockedVersions: lockedVersions, ignoredPkgs: ignoredPkgs }; | ||
return { lockedVersions, ignoredPkgs }; | ||
} | ||
@@ -32,20 +32,20 @@ exports.parseGoPkgConfig = parseGoPkgConfig; | ||
try { | ||
var lockJson = toml.parse(lockFileString); | ||
var deps_1 = {}; | ||
const lockJson = toml.parse(lockFileString); | ||
const deps = {}; | ||
if (lockJson.projects) { | ||
lockJson.projects.forEach(function (proj) { | ||
var version = proj.version || ('#' + proj.revision); | ||
proj.packages.forEach(function (subpackageName) { | ||
var name = (subpackageName === '.' ? | ||
lockJson.projects.forEach((proj) => { | ||
const version = proj.version || ('#' + proj.revision); | ||
proj.packages.forEach((subpackageName) => { | ||
const name = (subpackageName === '.' ? | ||
proj.name : | ||
proj.name + '/' + subpackageName); | ||
var dep = { | ||
name: name, | ||
version: version, | ||
const dep = { | ||
name, | ||
version, | ||
}; | ||
deps_1[dep.name] = dep; | ||
deps[dep.name] = dep; | ||
}); | ||
}); | ||
} | ||
return deps_1; | ||
return deps; | ||
} | ||
@@ -58,3 +58,3 @@ catch (e) { | ||
try { | ||
var manifestJson = toml.parse(manifestToml) || {}; | ||
const manifestJson = toml.parse(manifestToml) || {}; | ||
manifestJson.ignored = manifestJson.ignored || []; | ||
@@ -70,4 +70,4 @@ return manifestJson; | ||
try { | ||
var gvJson = JSON.parse(jsonStr); | ||
var goProjectConfig_1 = { | ||
const gvJson = JSON.parse(jsonStr); | ||
const goProjectConfig = { | ||
ignoredPkgs: [], | ||
@@ -77,24 +77,24 @@ lockedVersions: {}, | ||
}; | ||
var packages = (gvJson.package || gvJson.Package); | ||
const packages = (gvJson.package || gvJson.Package); | ||
if (packages) { | ||
packages.forEach(function (pkg) { | ||
var revision = pkg.revision || pkg.Revision || pkg.version || pkg.Version; | ||
var version = pkg.versionExact || ('#' + revision); | ||
var dep = { | ||
packages.forEach((pkg) => { | ||
const revision = pkg.revision || pkg.Revision || pkg.version || pkg.Version; | ||
const version = pkg.versionExact || ('#' + revision); | ||
const dep = { | ||
name: pkg.path, | ||
version: version, | ||
version, | ||
}; | ||
goProjectConfig_1.lockedVersions[dep.name] = dep; | ||
goProjectConfig.lockedVersions[dep.name] = dep; | ||
}); | ||
} | ||
var ignores = gvJson.ignore || ''; | ||
ignores.split(/\s/).filter(function (s) { | ||
const ignores = gvJson.ignore || ''; | ||
ignores.split(/\s/).filter((s) => { | ||
// otherwise it's a build-tag rather than a pacakge | ||
return s.indexOf('/') !== -1; | ||
}).forEach(function (pkgName) { | ||
}).forEach((pkgName) => { | ||
pkgName = pkgName.replace(/\/+$/, ''); // remove trailing / | ||
goProjectConfig_1.ignoredPkgs.push(pkgName); | ||
goProjectConfig_1.ignoredPkgs.push(pkgName + '/*'); | ||
goProjectConfig.ignoredPkgs.push(pkgName); | ||
goProjectConfig.ignoredPkgs.push(pkgName + '/*'); | ||
}); | ||
return goProjectConfig_1; | ||
return goProjectConfig; | ||
} | ||
@@ -101,0 +101,0 @@ catch (e) { |
@@ -29,3 +29,3 @@ { | ||
"toml": "^3.0.0", | ||
"tslib": "^1.9.3" | ||
"tslib": "^1.10.0" | ||
}, | ||
@@ -39,5 +39,5 @@ "devDependencies": { | ||
"tslint": "5.11.0", | ||
"typescript": "^3.7.2" | ||
"typescript": "^3.7.3" | ||
}, | ||
"version": "1.3.3" | ||
"version": "1.4.0" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27007
395
Updatedtslib@^1.10.0