From 2d0965744b1abd574a511168a5b0ae92a7eeed21 Mon Sep 17 00:00:00 2001 From: Craigory Coppola Date: Thu, 10 Mar 2022 12:14:08 -0500 Subject: [PATCH 1/2] fix(core): add workaround for broken .NET format command in v6+ (#397) --- .eslintrc.json | 4 ++- .husky/pre-push | 0 .../src/executors/format/executor.spec.ts | 8 ++--- .../core/src/executors/format/executor.ts | 29 +++++++++++++++---- packages/dotnet/src/lib/core/dotnet.client.ts | 22 ++++++++++---- tools/scripts/e2e.ts | 2 +- 6 files changed, 48 insertions(+), 17 deletions(-) mode change 100644 => 100755 .husky/pre-push diff --git a/.eslintrc.json b/.eslintrc.json index 06cc47d9..382a8325 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -24,7 +24,9 @@ { "files": ["*.ts", "*.tsx"], "extends": ["plugin:@nrwl/nx/typescript"], - "rules": {} + "rules": { + "eqeqeq": ["error", "smart"] + } }, { "files": ["*.js", "*.jsx"], diff --git a/.husky/pre-push b/.husky/pre-push old mode 100644 new mode 100755 diff --git a/packages/core/src/executors/format/executor.spec.ts b/packages/core/src/executors/format/executor.spec.ts index 84fa3d71..285d6e9d 100644 --- a/packages/core/src/executors/format/executor.spec.ts +++ b/packages/core/src/executors/format/executor.spec.ts @@ -55,7 +55,7 @@ describe('Format Executor', () => { }; dotnetClient = new DotNetClient(mockDotnetFactory()); (dotnetClient as jest.Mocked).getSdkVersion.mockReturnValue( - Buffer.from('5.0.402'), + '5.0.402', ); }); @@ -91,7 +91,7 @@ describe('Format Executor', () => { it('does not install dotnet-format if SDK is 6+', async () => { (dotnetClient as jest.Mocked).getSdkVersion.mockReturnValue( - Buffer.from('6.0.101'), + '6.0.101', ); jest.spyOn(fs, 'existsSync').mockReturnValue(true); @@ -108,7 +108,7 @@ describe('Format Executor', () => { it('passes the --check option on .NET 5 and earlier', async () => { (dotnetClient as jest.Mocked).getSdkVersion.mockReturnValue( - Buffer.from('5.0.101'), + '5.0.101', ); jest.spyOn(fs, 'existsSync').mockReturnValue(true); jest @@ -126,7 +126,7 @@ describe('Format Executor', () => { it('passes the --verify-no-changes option on .NET 6 and later', async () => { (dotnetClient as jest.Mocked).getSdkVersion.mockReturnValue( - Buffer.from('6.0.101'), + '6.0.101', ); const res = await executor(options, context, dotnetClient); diff --git a/packages/core/src/executors/format/executor.ts b/packages/core/src/executors/format/executor.ts index c42f26ae..9b5076fa 100644 --- a/packages/core/src/executors/format/executor.ts +++ b/packages/core/src/executors/format/executor.ts @@ -34,7 +34,7 @@ export default async function runExecutor( context: ExecutorContext, dotnetClient: DotNetClient = new DotNetClient(dotnetFactory()), ) { - const sdkVersion = dotnetClient.getSdkVersion().toString(); + const sdkVersion = dotnetClient.getSdkVersion(); const majorVersion = parseInt(sdkVersion.split('.')[0]); const isNet6OrHigher = majorVersion >= 6; @@ -45,8 +45,8 @@ export default async function runExecutor( const normalized = normalizeOptions(options, isNet6OrHigher); - ensureFormatToolInstalled(context, dotnetClient, isNet6OrHigher); - dotnetClient.format(projectFilePath, normalized); + ensureFormatToolInstalled(context, dotnetClient, majorVersion); + dotnetClient.format(projectFilePath, normalized, isNet6OrHigher); return { success: true, @@ -56,9 +56,12 @@ export default async function runExecutor( function ensureFormatToolInstalled( context: ExecutorContext, dotnetClient: DotNetClient, - isNet6OrHigher: boolean, + majorVersion: number, ) { - if (isNet6OrHigher) { + // 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; } @@ -73,5 +76,19 @@ function ensureFormatToolInstalled( return; } - dotnetClient.installTool('dotnet-format'); + 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'); + } } diff --git a/packages/dotnet/src/lib/core/dotnet.client.ts b/packages/dotnet/src/lib/core/dotnet.client.ts index c3d7124d..90fed7c1 100644 --- a/packages/dotnet/src/lib/core/dotnet.client.ts +++ b/packages/dotnet/src/lib/core/dotnet.client.ts @@ -115,8 +115,14 @@ export class DotNetClient { return this.logAndExecute(params); } - installTool(tool: string): void { + installTool(tool: string, version?: string, source?: string): void { const cmd = [`tool`, `install`, tool]; + if (version) { + cmd.push('--version', version); + } + if (source) { + cmd.push('--add-source', source); + } return this.logAndExecute(cmd); } @@ -130,8 +136,14 @@ export class DotNetClient { return this.logAndExecute(cmd); } - format(project: string, parameters?: dotnetFormatOptions): void { - const params = [`format`, project]; + format( + project: string, + parameters?: dotnetFormatOptions, + forceToolUsage?: boolean, + ): void { + const params = forceToolUsage + ? ['tool', 'run', 'dotnet-format', project] + : [`format`, project]; if (parameters) { parameters = swapKeysUsingMap(parameters, formatKeyMap); params.push(...getSpawnParameterArray(parameters)); @@ -144,8 +156,8 @@ export class DotNetClient { this.logAndExecute(params); } - getSdkVersion(): Buffer { - return this.execute(['--version']); + getSdkVersion(): string { + return this.cliCommand.info.version.toString(); } printSdkVersion(): void { diff --git a/tools/scripts/e2e.ts b/tools/scripts/e2e.ts index c95eddbc..c6b5ca5e 100644 --- a/tools/scripts/e2e.ts +++ b/tools/scripts/e2e.ts @@ -17,7 +17,7 @@ async function runTest() { let selectedProjects = process.argv[2]; let testNamePattern = ''; - if (process.argv[3] === '-t' || process.argv[3] == '--testNamePattern') { + if (process.argv[3] === '-t' || process.argv[3] === '--testNamePattern') { testNamePattern = `--testNamePattern "${process.argv[4]}"`; } From f86eb62f83295e5652a6614de7bc1e8c200c061c Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Thu, 10 Mar 2022 17:18:33 +0000 Subject: [PATCH 2/2] release: 1.9.6 [skip ci] ## [1.9.6](https://github.com/nx-dotnet/nx-dotnet/compare/v1.9.5...v1.9.6) (2022-03-10) ### Bug Fixes * **core:** add workaround for broken .NET format command in v6+ ([#397](https://github.com/nx-dotnet/nx-dotnet/issues/397)) ([2d09657](https://github.com/nx-dotnet/nx-dotnet/commit/2d0965744b1abd574a511168a5b0ae92a7eeed21)) Mar 10, 2022, 5:18 PM --- CHANGELOG.md | 6 ++++++ package.json | 2 +- packages/core/package.json | 2 +- packages/dotnet/package.json | 2 +- packages/nx-ghpages/package.json | 2 +- packages/nxdoc/package.json | 2 +- packages/typescript/package.json | 2 +- packages/utils/package.json | 2 +- 8 files changed, 13 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 12b3b9d0..bfb4483d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## [1.9.6](https://github.com/nx-dotnet/nx-dotnet/compare/v1.9.5...v1.9.6) (2022-03-10) + +### Bug Fixes + +- **core:** add workaround for broken .NET format command in v6+ ([#397](https://github.com/nx-dotnet/nx-dotnet/issues/397)) ([2d09657](https://github.com/nx-dotnet/nx-dotnet/commit/2d0965744b1abd574a511168a5b0ae92a7eeed21)) + ## [1.9.5](https://github.com/nx-dotnet/nx-dotnet/compare/v1.9.4...v1.9.5) (2022-03-03) ### Bug Fixes diff --git a/package.json b/package.json index 8ecfd650..a85bfd26 100644 --- a/package.json +++ b/package.json @@ -92,5 +92,5 @@ "type": "git", "url": "https://github.com/nx-dotnet/nx-dotnet.git" }, - "version": "1.9.5" + "version": "1.9.6" } diff --git a/packages/core/package.json b/packages/core/package.json index 5ebec98f..db3a3bfd 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -37,5 +37,5 @@ "nx-migrations": { "migrations": "./migrations.json" }, - "version": "1.9.5" + "version": "1.9.6" } diff --git a/packages/dotnet/package.json b/packages/dotnet/package.json index 6b7846d5..f0c51847 100644 --- a/packages/dotnet/package.json +++ b/packages/dotnet/package.json @@ -20,5 +20,5 @@ "url": "https://github.com/nx-dotnet/nx-dotnet" }, "homepage": "https://nx-dotnet.com/", - "version": "1.9.5" + "version": "1.9.6" } diff --git a/packages/nx-ghpages/package.json b/packages/nx-ghpages/package.json index 98f0ff1b..491000ef 100644 --- a/packages/nx-ghpages/package.json +++ b/packages/nx-ghpages/package.json @@ -24,5 +24,5 @@ "url": "https://github.com/nx-dotnet/nx-dotnet" }, "homepage": "https://nx-dotnet.com/", - "version": "1.9.5" + "version": "1.9.6" } diff --git a/packages/nxdoc/package.json b/packages/nxdoc/package.json index cc492e61..fb5dcaca 100644 --- a/packages/nxdoc/package.json +++ b/packages/nxdoc/package.json @@ -24,5 +24,5 @@ "type": "git", "url": "https://github.com/nx-dotnet/nx-dotnet" }, - "version": "1.9.5" + "version": "1.9.6" } diff --git a/packages/typescript/package.json b/packages/typescript/package.json index a418a585..fce3bc26 100644 --- a/packages/typescript/package.json +++ b/packages/typescript/package.json @@ -25,5 +25,5 @@ "type": "git", "url": "https://github.com/nx-dotnet/nx-dotnet" }, - "version": "1.9.5" + "version": "1.9.6" } diff --git a/packages/utils/package.json b/packages/utils/package.json index 5a24c1fd..abb20b7f 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -24,5 +24,5 @@ "url": "https://github.com/nx-dotnet/nx-dotnet" }, "homepage": "https://nx-dotnet.com/", - "version": "1.9.5" + "version": "1.9.6" }