snyk-nuget-plugin
Version:
Snyk CLI NuGet plugin
41 lines • 2.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PACKS_PATH = exports.PACKAGE_OVERRIDES_FILE = void 0;
exports.parseSdkInfoFromDotnetOutput = parseSdkInfoFromDotnetOutput;
exports.extractSdkInfo = extractSdkInfo;
exports.findLatestMatchingVersion = findLatestMatchingVersion;
const errors_1 = require("../errors");
const dotnet = require("./cli/dotnet");
exports.PACKAGE_OVERRIDES_FILE = 'data/PackageOverrides.txt';
exports.PACKS_PATH = '/packs/Microsoft.NETCore.App.Ref/';
function parseSdkInfoFromDotnetOutput(infoOutput) {
const regex = /Version:\s*(\d+)\.[\d.]+.*?\.NET SDKs installed:\s*([\s\S]*?)(?:\n\s*\1\.([\d.]+)\s+\[([^\]]*)\])/s;
const match = infoOutput.match(regex);
if (!match) {
throw new errors_1.CliCommandError(`Could not fetch details about the dotnet SDK. Cannot continue without it.
Dotnet info output: ${infoOutput}`);
}
return { sdkVersion: `${match[1]}.${match[3]}`, sdkPath: match[4] };
}
// Relying on dotnet to fetch the right version that the project will use.
// Details: https://learn.microsoft.com/en-us/dotnet/core/versions/selection#the-sdk-uses-the-latest-installed-version
// And here: https://learn.microsoft.com/en-us/dotnet/core/tools/global-json#matching-rules
async function extractSdkInfo(projectPath) {
const infoOutput = await dotnet.execute(['--info'], projectPath);
return parseSdkInfoFromDotnetOutput(infoOutput);
}
function findLatestMatchingVersion(input, sdkVersion) {
const majorSdkVersion = sdkVersion.split('.')[0];
const regex = new RegExp(`Microsoft\\.NETCore\\.App ${majorSdkVersion}\\.(\\d+\\.\\d+) \\[`, 'g');
let lastMatchVersion = null;
let match;
while ((match = regex.exec(input)) !== null) {
lastMatchVersion = `${majorSdkVersion}.${match[1]}`;
}
if (!lastMatchVersion) {
throw new errors_1.CliCommandError(`Could not fetch details about the dotnet runtime. Cannot continue without it.
Dotnet list-runtimes output: ${input}`);
}
return lastMatchVersion;
}
//# sourceMappingURL=runtime-assembly-v2.js.map