Skip to content

Commit c4c79ed

Browse files
mikeharderpjpatel12
authored andcommitted
[TypeSpecValidation] Pass target path to "tsp compile" (Azure#31371)
- Earlier bugs required running "tsp compile" from target dir - Should effectively be a no-op for the tool and its users
1 parent 672540a commit c4c79ed

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

eng/tools/typespec-validation/src/rules/compile.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ export class CompileRule implements Rule {
1414

1515
if (await host.checkFileExists(path.join(folder, "main.tsp"))) {
1616
let [err, stdout, stderr] = await host.runCmd(
17-
`npm exec --no -- tsp compile . --warn-as-error`,
18-
folder,
17+
`npm exec --no -- tsp compile --warn-as-error ${folder}`,
1918
);
2019
if (
2120
stdout.toLowerCase().includes("no emitter was configured") ||
@@ -31,10 +30,11 @@ export class CompileRule implements Rule {
3130
stdOutput += stdout;
3231
errorOutput += stderr;
3332
}
34-
if (await host.checkFileExists(path.join(folder, "client.tsp"))) {
33+
34+
const clientTsp = path.join(folder, "client.tsp");
35+
if (await host.checkFileExists(clientTsp)) {
3536
let [err, stdout, stderr] = await host.runCmd(
36-
`npm exec --no -- tsp compile client.tsp --no-emit --warn-as-error`,
37-
folder,
37+
`npm exec --no -- tsp compile --no-emit --warn-as-error ${clientTsp}`,
3838
);
3939
if (err) {
4040
success = false;

eng/tools/typespec-validation/src/tsv-host.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export interface TsvHost {
55
isDirectory(path: string): Promise<boolean>;
66
gitOperation(folder: string): IGitOperation;
77
readTspConfig(folder: string): Promise<string>;
8-
runCmd(cmd: string, cwd: string): Promise<[Error | null, string, string]>;
8+
runCmd(cmd: string, cwd?: string): Promise<[Error | null, string, string]>;
99
normalizePath(folder: string): string;
1010
gitDiffTopSpecFolder(host: TsvHost, folder: string): Promise<RuleResult>;
1111
globby(patterns: string[]): Promise<string[]>;

eng/tools/typespec-validation/src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { exec } from "child_process";
33
import defaultPath, { PlatformPath } from "path";
44
import { TsvHost } from "./tsv-host.js";
55

6-
export async function runCmd(cmd: string, cwd: string) {
6+
export async function runCmd(cmd: string, cwd?: string) {
77
console.log(`run command:${cmd}`);
88
const { err, stdout, stderr } = (await new Promise((res) =>
99
exec(

eng/tools/typespec-validation/test/compile.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe("compile", function () {
1414
it("should fail if no emitter was configured", async function () {
1515
let host = new TsvTestHost();
1616
host.runCmd = async (cmd: string, _cwd: string): Promise<[Error | null, string, string]> => {
17-
if (cmd.includes("tsp compile .")) {
17+
if (cmd.includes("tsp compile")) {
1818
return [null, "no emitter was configured", ""];
1919
} else {
2020
return [null, "", ""];
@@ -29,7 +29,7 @@ describe("compile", function () {
2929
it("should fail if no output was generated", async function () {
3030
let host = new TsvTestHost();
3131
host.runCmd = async (cmd: string, _cwd: string): Promise<[Error | null, string, string]> => {
32-
if (cmd.includes("tsp compile .")) {
32+
if (cmd.includes("tsp compile")) {
3333
return [null, "no output was generated", ""];
3434
} else {
3535
return [null, "", ""];

0 commit comments

Comments
 (0)