Skip to content

Commit

Permalink
fix(core): remove workaround for broken dotnet format builtin (#443)
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder authored May 20, 2022
1 parent ef7c11d commit e0f04eb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
21 changes: 8 additions & 13 deletions packages/core/src/executors/format/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { workspaceRoot } from 'nx/src/utils/app-root';

import { existsSync } from 'fs';
import { join } from 'path';
import * as semver from 'semver';

import { DotNetClient, dotnetFactory } from '@nx-dotnet/dotnet';
import {
Expand Down Expand Up @@ -35,18 +36,20 @@ export default async function runExecutor(
dotnetClient: DotNetClient = new DotNetClient(dotnetFactory()),
) {
const sdkVersion = dotnetClient.getSdkVersion();
const majorVersion = parseInt(sdkVersion.split('.')[0]);
const isNet6OrHigher = majorVersion >= 6;
const forceToolUsage = semver.satisfies(sdkVersion, '6.0.0 - 6.0.203');
const majorVersion = semver.major(sdkVersion);

const nxProjectConfiguration = getExecutedProjectConfiguration(context);
const projectFilePath = await getProjectFileForNxProject(
nxProjectConfiguration,
);

const normalized = normalizeOptions(options, isNet6OrHigher);
const normalized = normalizeOptions(options, majorVersion >= 6);

ensureFormatToolInstalled(context, dotnetClient, majorVersion);
dotnetClient.format(projectFilePath, normalized, isNet6OrHigher);
if (forceToolUsage || majorVersion < 6) {
ensureFormatToolInstalled(context, dotnetClient, majorVersion);
}
dotnetClient.format(projectFilePath, normalized, forceToolUsage);

return {
success: true,
Expand All @@ -58,14 +61,6 @@ function ensureFormatToolInstalled(
dotnetClient: DotNetClient,
majorVersion: number,
) {
// Currently the built-in .NET Format executor is broken on .NET 6
// Fall back to installing and using the tool directly
// eslint-disable-next-line no-constant-condition
if (false && majorVersion >= 6) {
// dotnet-format is already included as part of .NET SDK 6+
return;
}

const manifestPath = join(workspaceRoot, './.config/dotnet-tools.json');
console.log(manifestPath);
const manifest = existsSync(manifestPath)
Expand Down
2 changes: 1 addition & 1 deletion packages/dotnet/src/lib/core/dotnet.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export class DotNetClient {
forceToolUsage?: boolean,
): void {
const params = forceToolUsage
? ['tool', 'run', 'dotnet-format', project]
? ['tool', 'run', 'dotnet-format', '--', project]
: [`format`, project];
if (parameters) {
parameters = swapKeysUsingMap(parameters, formatKeyMap);
Expand Down

0 comments on commit e0f04eb

Please sign in to comment.