@nx-dotnet/core
Version:
- Have an existing nx workspace. For creating this, see [nrwl's documentation](https://nx.dev/latest/angular/getting-started/nx-setup). - .NET SDK is installed, and `dotnet` is available on the path. For help on this, see [Microsoft's documentation](https
56 lines • 2.5 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = runExecutor;
const semver = require("semver");
const dotnet_1 = require("@nx-dotnet/dotnet");
const utils_1 = require("@nx-dotnet/utils");
function normalizeOptions(options, isNet6OrHigher) {
const { diagnostics, include, exclude, check, fix, ...flags } = options;
const result = {
...flags,
diagnostics: Array.isArray(diagnostics)
? diagnostics.join(' ')
: diagnostics,
include: Array.isArray(include) ? include.join(' ') : include,
exclude: Array.isArray(exclude) ? exclude.join(' ') : exclude,
};
// Specifying --verify-no-changes false does not work, so we only add the switch when we want to run the check only
if (!fix && check) {
if (isNet6OrHigher) {
return { ...result, verifyNoChanges: true };
}
return { ...result, check: true }; // The --check flag is for .NET 5 and older
}
return result;
}
async function runExecutor(options, context, dotnetClient = new dotnet_1.DotNetClient((0, dotnet_1.dotnetFactory)())) {
const sdkVersion = dotnetClient.getSdkVersion();
const forceToolUsage = semver.satisfies(sdkVersion, '6.0.0 - 6.0.203');
const majorVersion = semver.major(sdkVersion);
const nxProjectConfiguration = (0, utils_1.getExecutedProjectConfiguration)(context);
const projectFilePath = await (0, utils_1.getProjectFileForNxProject)(nxProjectConfiguration);
const normalized = normalizeOptions(options, majorVersion >= 6);
if (forceToolUsage || majorVersion < 6) {
ensureFormatToolInstalled(context, dotnetClient, majorVersion);
}
dotnetClient.format(projectFilePath, normalized, forceToolUsage);
return {
success: true,
};
}
function ensureFormatToolInstalled(context, dotnetClient, majorVersion) {
if ((0, utils_1.readInstalledDotnetToolVersion)('dotnet-format')) {
// dotnet-format is already installed.
return;
}
if (majorVersion === 6) {
dotnetClient.installTool('dotnet-format', '6.*', 'https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet6/nuget/v3/index.json');
}
else if (majorVersion === 7) {
dotnetClient.installTool('dotnet-format', '7.*', 'https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json');
}
else {
dotnetClient.installTool('dotnet-format');
}
}
//# sourceMappingURL=executor.js.map