snyk-nuget-plugin
Version:
Snyk CLI NuGet plugin
74 lines • 3.48 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
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 = __importStar(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