snyk-nuget-plugin
Advanced tools
Comparing version 2.7.13 to 2.7.14
@@ -24,2 +24,14 @@ "use strict"; | ||
} | ||
function readEncodedFile(path) { | ||
const buffer = fs.readFileSync(path); | ||
const firstChar = buffer.readUInt16LE(0); | ||
let contents; | ||
if (firstChar === 0xfeff) { | ||
contents = buffer.toString('utf16le'); | ||
} | ||
else { | ||
contents = buffer.toString('utf8'); | ||
} | ||
return contents; | ||
} | ||
function getTargetFrameworksFromProjFile(rootDir) { | ||
@@ -33,36 +45,41 @@ debug('Looking for your .csproj file in ' + rootDir); | ||
debug(`Checking .NET framework version in .csproj file ${csprojPath}`); | ||
const csprojContents = fs.readFileSync(csprojPath, 'utf-8'); | ||
const csprojContents = readEncodedFile(csprojPath); | ||
let result = []; | ||
parseXML.parseString(csprojContents, (err, parsedCsprojContents) => { | ||
if (err) { | ||
throw new errors_1.FileNotProcessableError(err); | ||
} | ||
const parsedTargetFrameworks = parsedCsprojContents?.Project?.PropertyGroup?.reduce((targetFrameworks, propertyGroup) => { | ||
const targetFrameworkSource = propertyGroup?.TargetFrameworkVersion?.[0] || | ||
propertyGroup?.TargetFramework?.[0] || | ||
propertyGroup?.TargetFrameworks?.[0] || | ||
''; | ||
return targetFrameworks | ||
.concat(targetFrameworkSource.split(';')) | ||
try { | ||
parseXML.parseString(csprojContents, (err, parsedCsprojContents) => { | ||
if (err) { | ||
throw new errors_1.FileNotProcessableError(err); | ||
} | ||
const parsedTargetFrameworks = parsedCsprojContents?.Project?.PropertyGroup?.reduce((targetFrameworks, propertyGroup) => { | ||
const targetFrameworkSource = propertyGroup?.TargetFrameworkVersion?.[0] || | ||
propertyGroup?.TargetFramework?.[0] || | ||
propertyGroup?.TargetFrameworks?.[0] || | ||
''; | ||
return targetFrameworks | ||
.concat(targetFrameworkSource.split(';')) | ||
.filter(Boolean); | ||
}, []) || []; | ||
if (parsedTargetFrameworks.length < 1) { | ||
debug('Could not find TargetFrameworkVersion/TargetFramework' + | ||
'/TargetFrameworks defined in the Project.PropertyGroup field of ' + | ||
'your .csproj file'); | ||
result = []; | ||
return; | ||
} | ||
const targetFrameworks = parsedTargetFrameworks | ||
.map(framework_1.toReadableFramework) | ||
.filter(Boolean); | ||
}, []) || []; | ||
if (parsedTargetFrameworks.length < 1) { | ||
debug('Could not find TargetFrameworkVersion/TargetFramework' + | ||
'/TargetFrameworks defined in the Project.PropertyGroup field of ' + | ||
'your .csproj file'); | ||
result = []; | ||
if (parsedTargetFrameworks.length > 1 && targetFrameworks.length < 1) { | ||
debug('Could not find valid/supported .NET version in csproj file located at' + | ||
csprojPath); | ||
} | ||
result = targetFrameworks; | ||
return; | ||
} | ||
const targetFrameworks = parsedTargetFrameworks | ||
.map(framework_1.toReadableFramework) | ||
.filter(Boolean); | ||
if (parsedTargetFrameworks.length > 1 && targetFrameworks.length < 1) { | ||
debug('Could not find valid/supported .NET version in csproj file located at' + | ||
csprojPath); | ||
} | ||
result = targetFrameworks; | ||
return; | ||
}); | ||
}); | ||
} | ||
catch (err) { | ||
throw new errors_1.FileNotProcessableError(`Could not parse ${csprojPath}`); | ||
} | ||
return result; | ||
} | ||
//# sourceMappingURL=csproj-parser.js.map |
@@ -62,3 +62,3 @@ { | ||
}, | ||
"version": "2.7.13" | ||
"version": "2.7.14" | ||
} |
Sorry, the diff of this file is not supported yet
141321
1928