Skip to content

Commit 9fac321

Browse files
authored
fix(core): nx lint {project} should work when cwd !== appRootPath (#216)
Closes #215
1 parent ceae237 commit 9fac321

File tree

5 files changed

+46
-21
lines changed

5 files changed

+46
-21
lines changed

e2e/core-e2e/tests/nx-dotnet.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,17 @@ describe('nx-dotnet e2e', () => {
124124
?.childNamed('OutputPath')?.val as string;
125125
expect(outputPath).toBeTruthy();
126126
});
127+
128+
it('should lint', async () => {
129+
const app = uniq('app');
130+
await runNxCommandAsync(
131+
`generate @nx-dotnet/core:app ${app} --language="C#" --template="webapi"`,
132+
);
133+
const promise = runNxCommandAsync(`lint ${app}`, {
134+
silenceError: true,
135+
}).then((x) => x.stderr);
136+
await expect(promise).resolves.toContain('WHITESPACE');
137+
});
127138
});
128139

129140
describe('nx g test', () => {

packages/core/src/executors/format/executor.spec.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ const options: FormatExecutorSchema = {
1515
};
1616

1717
const root = process.cwd() + '/tmp';
18+
jest.mock('@nrwl/tao/src/utils/app-root', () => ({
19+
appRootPath: process.cwd() + '/tmp',
20+
}));
1821

1922
jest.mock('../../../../dotnet/src/lib/core/dotnet.client');
2023

@@ -46,7 +49,7 @@ describe('Format Executor', () => {
4649
isVerbose: false,
4750
};
4851
dotnetClient = new DotNetClient(mockDotnetFactory());
49-
(dotnetClient as jest.Mocked<DotNetClient>).printSdkVersion.mockReturnValue(
52+
(dotnetClient as jest.Mocked<DotNetClient>).getSdkVersion.mockReturnValue(
5053
Buffer.from('5.0.402'),
5154
);
5255
});
@@ -140,7 +143,7 @@ describe('Format Executor', () => {
140143
});
141144

142145
it('does not install dotnet-format if SDK is 6+', async () => {
143-
(dotnetClient as jest.Mocked<DotNetClient>).printSdkVersion.mockReturnValue(
146+
(dotnetClient as jest.Mocked<DotNetClient>).getSdkVersion.mockReturnValue(
144147
Buffer.from('6.0.101'),
145148
);
146149

@@ -182,7 +185,7 @@ describe('Format Executor', () => {
182185
});
183186

184187
it('passes the --verify-no-changes option on .NET 6 and later', async () => {
185-
(dotnetClient as jest.Mocked<DotNetClient>).printSdkVersion.mockReturnValue(
188+
(dotnetClient as jest.Mocked<DotNetClient>).getSdkVersion.mockReturnValue(
186189
Buffer.from('6.0.101'),
187190
);
188191

packages/core/src/executors/format/executor.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { ExecutorContext, readJsonFile } from '@nrwl/devkit';
2+
import { appRootPath } from '@nrwl/tao/src/utils/app-root';
3+
24
import { existsSync } from 'fs';
5+
import { join } from 'path';
36

47
import {
58
DotNetClient,
@@ -35,7 +38,7 @@ export default async function runExecutor(
3538
context: ExecutorContext,
3639
dotnetClient: DotNetClient = new DotNetClient(dotnetFactory()),
3740
) {
38-
const sdkVersion = dotnetClient.printSdkVersion().toString();
41+
const sdkVersion = dotnetClient.getSdkVersion().toString();
3942
const majorVersion = parseInt(sdkVersion.split('.')[0]);
4043
const isNet6OrHigher = majorVersion >= 6;
4144

@@ -70,7 +73,8 @@ function ensureFormatToolInstalled(
7073
return;
7174
}
7275

73-
const manifestPath = `${context.cwd}/.config/dotnet-tools.json`;
76+
const manifestPath = join(appRootPath, './.config/dotnet-tools.json');
77+
console.log(manifestPath);
7478
const manifest = existsSync(manifestPath)
7579
? readJsonFile(manifestPath)
7680
: undefined;

packages/dotnet/src/lib/core/dotnet.client.ts

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { LoadedCLI } from './dotnet.factory';
2727
export class DotNetClient {
2828
constructor(private cliCommand: LoadedCLI, public cwd?: string) {}
2929

30-
new(template: dotnetTemplate, parameters?: dotnetNewOptions): Buffer {
30+
new(template: dotnetTemplate, parameters?: dotnetNewOptions): void {
3131
let cmd = `${this.cliCommand.command} new ${template}`;
3232
if (parameters) {
3333
parameters = swapArrayFieldValueUsingMap(parameters, 'flag', newKeyMap);
@@ -37,7 +37,7 @@ export class DotNetClient {
3737
return this.logAndExecute(cmd);
3838
}
3939

40-
build(project: string, parameters?: dotnetBuildOptions): Buffer {
40+
build(project: string, parameters?: dotnetBuildOptions): void {
4141
let cmd = `${this.cliCommand.command} build ${project}`;
4242
if (parameters) {
4343
parameters = swapArrayFieldValueUsingMap(parameters, 'flag', buildKeyMap);
@@ -71,7 +71,7 @@ export class DotNetClient {
7171
project: string,
7272
watch?: boolean,
7373
parameters?: dotnetTestOptions,
74-
): Buffer | ChildProcess {
74+
): void | ChildProcess {
7575
let cmd = watch ? ` watch --project ${project} test` : `test ${project}`;
7676
cmd = `${this.cliCommand.command} ${cmd}`;
7777

@@ -103,7 +103,7 @@ export class DotNetClient {
103103
project: string,
104104
pkg: string,
105105
parameters?: dotnetAddPackageOptions,
106-
): Buffer {
106+
): void {
107107
let cmd = `${this.cliCommand.command} add ${project} package ${pkg}`;
108108
if (parameters) {
109109
parameters = swapArrayFieldValueUsingMap(
@@ -117,7 +117,7 @@ export class DotNetClient {
117117
return this.logAndExecute(cmd);
118118
}
119119

120-
addProjectReference(hostCsProj: string, targetCsProj: string): Buffer {
120+
addProjectReference(hostCsProj: string, targetCsProj: string): void {
121121
return this.logAndExecute(
122122
`${this.cliCommand.command} add ${hostCsProj} reference ${targetCsProj}`,
123123
);
@@ -128,7 +128,7 @@ export class DotNetClient {
128128
parameters?: dotnetPublishOptions,
129129
publishProfile?: string,
130130
extraParameters?: string,
131-
): Buffer {
131+
): void {
132132
let cmd = `${this.cliCommand.command} publish ${project}`;
133133
if (parameters) {
134134
parameters = swapArrayFieldValueUsingMap(
@@ -148,22 +148,22 @@ export class DotNetClient {
148148
return this.logAndExecute(cmd);
149149
}
150150

151-
installTool(tool: string): Buffer {
151+
installTool(tool: string): void {
152152
const cmd = `${this.cliCommand.command} tool install ${tool}`;
153153
return this.logAndExecute(cmd);
154154
}
155155

156-
restorePackages(project: string): Buffer {
156+
restorePackages(project: string): void {
157157
const cmd = `${this.cliCommand.command} restore ${project}`;
158158
return this.logAndExecute(cmd);
159159
}
160160

161-
restoreTools(): Buffer {
161+
restoreTools(): void {
162162
const cmd = `${this.cliCommand.command} tool restore`;
163163
return this.logAndExecute(cmd);
164164
}
165165

166-
format(project: string, parameters?: dotnetFormatOptions): Buffer {
166+
format(project: string, parameters?: dotnetFormatOptions): void {
167167
let cmd = `${this.cliCommand.command} format ${project}`;
168168
if (parameters) {
169169
parameters = swapArrayFieldValueUsingMap(
@@ -177,12 +177,21 @@ export class DotNetClient {
177177
return this.logAndExecute(cmd);
178178
}
179179

180-
printSdkVersion(): Buffer {
181-
return this.logAndExecute('dotnet --version');
180+
getSdkVersion(): Buffer {
181+
const cmd = 'dotnet --version';
182+
return this.execute(cmd);
182183
}
183184

184-
private logAndExecute(cmd: string): Buffer {
185+
printSdkVersion(): void {
186+
this.logAndExecute('dotnet --version');
187+
}
188+
189+
private logAndExecute(cmd: string): void {
185190
console.log(`Executing Command: ${cmd}`);
186-
return execSync(cmd, { stdio: 'inherit', cwd: this.cwd || process.cwd() });
191+
execSync(cmd, { stdio: 'inherit', cwd: this.cwd || process.cwd() });
192+
}
193+
194+
private execute(cmd: string): Buffer {
195+
return execSync(cmd, { cwd: this.cwd || process.cwd() });
187196
}
188197
}

packages/utils/src/lib/utility-functions/childprocess.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import { ChildProcess } from 'child_process';
66
* TypeScript typings think ChildProcess is an interface, its a class.
77
*/
88
export function isChildProcess(obj: any): obj is cp.ChildProcess {
9-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
10-
// @ts-ignore
119
return obj instanceof cp.ChildProcess;
1210
}
1311

0 commit comments

Comments
 (0)