diff --git a/e2e/core-e2e/tests/nx-dotnet.spec.ts b/e2e/core-e2e/tests/nx-dotnet.spec.ts index 8dc80df9..d0d2a098 100644 --- a/e2e/core-e2e/tests/nx-dotnet.spec.ts +++ b/e2e/core-e2e/tests/nx-dotnet.spec.ts @@ -124,6 +124,17 @@ describe('nx-dotnet e2e', () => { ?.childNamed('OutputPath')?.val as string; expect(outputPath).toBeTruthy(); }); + + it('should lint', async () => { + const app = uniq('app'); + await runNxCommandAsync( + `generate @nx-dotnet/core:app ${app} --language="C#" --template="webapi"`, + ); + const promise = runNxCommandAsync(`lint ${app}`, { + silenceError: true, + }).then((x) => x.stderr); + await expect(promise).resolves.toContain('WHITESPACE'); + }); }); describe('nx g test', () => { diff --git a/packages/core/src/executors/format/executor.spec.ts b/packages/core/src/executors/format/executor.spec.ts index 0b93dc9d..3b356fed 100644 --- a/packages/core/src/executors/format/executor.spec.ts +++ b/packages/core/src/executors/format/executor.spec.ts @@ -15,6 +15,9 @@ const options: FormatExecutorSchema = { }; const root = process.cwd() + '/tmp'; +jest.mock('@nrwl/tao/src/utils/app-root', () => ({ + appRootPath: process.cwd() + '/tmp', +})); jest.mock('../../../../dotnet/src/lib/core/dotnet.client'); @@ -46,7 +49,7 @@ describe('Format Executor', () => { isVerbose: false, }; dotnetClient = new DotNetClient(mockDotnetFactory()); - (dotnetClient as jest.Mocked).printSdkVersion.mockReturnValue( + (dotnetClient as jest.Mocked).getSdkVersion.mockReturnValue( Buffer.from('5.0.402'), ); }); @@ -140,7 +143,7 @@ describe('Format Executor', () => { }); it('does not install dotnet-format if SDK is 6+', async () => { - (dotnetClient as jest.Mocked).printSdkVersion.mockReturnValue( + (dotnetClient as jest.Mocked).getSdkVersion.mockReturnValue( Buffer.from('6.0.101'), ); @@ -182,7 +185,7 @@ describe('Format Executor', () => { }); it('passes the --verify-no-changes option on .NET 6 and later', async () => { - (dotnetClient as jest.Mocked).printSdkVersion.mockReturnValue( + (dotnetClient as jest.Mocked).getSdkVersion.mockReturnValue( Buffer.from('6.0.101'), ); diff --git a/packages/core/src/executors/format/executor.ts b/packages/core/src/executors/format/executor.ts index 2f1fbbb6..95a2662b 100644 --- a/packages/core/src/executors/format/executor.ts +++ b/packages/core/src/executors/format/executor.ts @@ -1,5 +1,8 @@ import { ExecutorContext, readJsonFile } from '@nrwl/devkit'; +import { appRootPath } from '@nrwl/tao/src/utils/app-root'; + import { existsSync } from 'fs'; +import { join } from 'path'; import { DotNetClient, @@ -35,7 +38,7 @@ export default async function runExecutor( context: ExecutorContext, dotnetClient: DotNetClient = new DotNetClient(dotnetFactory()), ) { - const sdkVersion = dotnetClient.printSdkVersion().toString(); + const sdkVersion = dotnetClient.getSdkVersion().toString(); const majorVersion = parseInt(sdkVersion.split('.')[0]); const isNet6OrHigher = majorVersion >= 6; @@ -70,7 +73,8 @@ function ensureFormatToolInstalled( return; } - const manifestPath = `${context.cwd}/.config/dotnet-tools.json`; + const manifestPath = join(appRootPath, './.config/dotnet-tools.json'); + console.log(manifestPath); const manifest = existsSync(manifestPath) ? readJsonFile(manifestPath) : undefined; diff --git a/packages/dotnet/src/lib/core/dotnet.client.ts b/packages/dotnet/src/lib/core/dotnet.client.ts index b7eb96fe..196eca0f 100644 --- a/packages/dotnet/src/lib/core/dotnet.client.ts +++ b/packages/dotnet/src/lib/core/dotnet.client.ts @@ -27,7 +27,7 @@ import { LoadedCLI } from './dotnet.factory'; export class DotNetClient { constructor(private cliCommand: LoadedCLI, public cwd?: string) {} - new(template: dotnetTemplate, parameters?: dotnetNewOptions): Buffer { + new(template: dotnetTemplate, parameters?: dotnetNewOptions): void { let cmd = `${this.cliCommand.command} new ${template}`; if (parameters) { parameters = swapArrayFieldValueUsingMap(parameters, 'flag', newKeyMap); @@ -37,7 +37,7 @@ export class DotNetClient { return this.logAndExecute(cmd); } - build(project: string, parameters?: dotnetBuildOptions): Buffer { + build(project: string, parameters?: dotnetBuildOptions): void { let cmd = `${this.cliCommand.command} build ${project}`; if (parameters) { parameters = swapArrayFieldValueUsingMap(parameters, 'flag', buildKeyMap); @@ -71,7 +71,7 @@ export class DotNetClient { project: string, watch?: boolean, parameters?: dotnetTestOptions, - ): Buffer | ChildProcess { + ): void | ChildProcess { let cmd = watch ? ` watch --project ${project} test` : `test ${project}`; cmd = `${this.cliCommand.command} ${cmd}`; @@ -103,7 +103,7 @@ export class DotNetClient { project: string, pkg: string, parameters?: dotnetAddPackageOptions, - ): Buffer { + ): void { let cmd = `${this.cliCommand.command} add ${project} package ${pkg}`; if (parameters) { parameters = swapArrayFieldValueUsingMap( @@ -117,7 +117,7 @@ export class DotNetClient { return this.logAndExecute(cmd); } - addProjectReference(hostCsProj: string, targetCsProj: string): Buffer { + addProjectReference(hostCsProj: string, targetCsProj: string): void { return this.logAndExecute( `${this.cliCommand.command} add ${hostCsProj} reference ${targetCsProj}`, ); @@ -128,7 +128,7 @@ export class DotNetClient { parameters?: dotnetPublishOptions, publishProfile?: string, extraParameters?: string, - ): Buffer { + ): void { let cmd = `${this.cliCommand.command} publish ${project}`; if (parameters) { parameters = swapArrayFieldValueUsingMap( @@ -148,22 +148,22 @@ export class DotNetClient { return this.logAndExecute(cmd); } - installTool(tool: string): Buffer { + installTool(tool: string): void { const cmd = `${this.cliCommand.command} tool install ${tool}`; return this.logAndExecute(cmd); } - restorePackages(project: string): Buffer { + restorePackages(project: string): void { const cmd = `${this.cliCommand.command} restore ${project}`; return this.logAndExecute(cmd); } - restoreTools(): Buffer { + restoreTools(): void { const cmd = `${this.cliCommand.command} tool restore`; return this.logAndExecute(cmd); } - format(project: string, parameters?: dotnetFormatOptions): Buffer { + format(project: string, parameters?: dotnetFormatOptions): void { let cmd = `${this.cliCommand.command} format ${project}`; if (parameters) { parameters = swapArrayFieldValueUsingMap( @@ -177,12 +177,21 @@ export class DotNetClient { return this.logAndExecute(cmd); } - printSdkVersion(): Buffer { - return this.logAndExecute('dotnet --version'); + getSdkVersion(): Buffer { + const cmd = 'dotnet --version'; + return this.execute(cmd); } - private logAndExecute(cmd: string): Buffer { + printSdkVersion(): void { + this.logAndExecute('dotnet --version'); + } + + private logAndExecute(cmd: string): void { console.log(`Executing Command: ${cmd}`); - return execSync(cmd, { stdio: 'inherit', cwd: this.cwd || process.cwd() }); + execSync(cmd, { stdio: 'inherit', cwd: this.cwd || process.cwd() }); + } + + private execute(cmd: string): Buffer { + return execSync(cmd, { cwd: this.cwd || process.cwd() }); } } diff --git a/packages/utils/src/lib/utility-functions/childprocess.ts b/packages/utils/src/lib/utility-functions/childprocess.ts index 5a3d763e..d5dace44 100644 --- a/packages/utils/src/lib/utility-functions/childprocess.ts +++ b/packages/utils/src/lib/utility-functions/childprocess.ts @@ -6,8 +6,6 @@ import { ChildProcess } from 'child_process'; * TypeScript typings think ChildProcess is an interface, its a class. */ export function isChildProcess(obj: any): obj is cp.ChildProcess { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore return obj instanceof cp.ChildProcess; }