Skip to content

Commit

Permalink
[TypeSpecValidation] Pass target path to "tsp compile" (Azure#31371)
Browse files Browse the repository at this point in the history
- Earlier bugs required running "tsp compile" from target dir
- Should effectively be a no-op for the tool and its users
  • Loading branch information
mikeharder authored Oct 31, 2024
1 parent 69fd707 commit b0679e9
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions eng/tools/typespec-validation/src/rules/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ export class CompileRule implements Rule {

if (await host.checkFileExists(path.join(folder, "main.tsp"))) {
let [err, stdout, stderr] = await host.runCmd(
`npm exec --no -- tsp compile . --warn-as-error`,
folder,
`npm exec --no -- tsp compile --warn-as-error ${folder}`,
);
if (
stdout.toLowerCase().includes("no emitter was configured") ||
Expand All @@ -31,10 +30,11 @@ export class CompileRule implements Rule {
stdOutput += stdout;
errorOutput += stderr;
}
if (await host.checkFileExists(path.join(folder, "client.tsp"))) {

const clientTsp = path.join(folder, "client.tsp");
if (await host.checkFileExists(clientTsp)) {
let [err, stdout, stderr] = await host.runCmd(
`npm exec --no -- tsp compile client.tsp --no-emit --warn-as-error`,
folder,
`npm exec --no -- tsp compile --no-emit --warn-as-error ${clientTsp}`,
);
if (err) {
success = false;
Expand Down
2 changes: 1 addition & 1 deletion eng/tools/typespec-validation/src/tsv-host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export interface TsvHost {
isDirectory(path: string): Promise<boolean>;
gitOperation(folder: string): IGitOperation;
readTspConfig(folder: string): Promise<string>;
runCmd(cmd: string, cwd: string): Promise<[Error | null, string, string]>;
runCmd(cmd: string, cwd?: string): Promise<[Error | null, string, string]>;
normalizePath(folder: string): string;
gitDiffTopSpecFolder(host: TsvHost, folder: string): Promise<RuleResult>;
globby(patterns: string[]): Promise<string[]>;
Expand Down
2 changes: 1 addition & 1 deletion eng/tools/typespec-validation/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { exec } from "child_process";
import defaultPath, { PlatformPath } from "path";
import { TsvHost } from "./tsv-host.js";

export async function runCmd(cmd: string, cwd: string) {
export async function runCmd(cmd: string, cwd?: string) {
console.log(`run command:${cmd}`);
const { err, stdout, stderr } = (await new Promise((res) =>
exec(
Expand Down
4 changes: 2 additions & 2 deletions eng/tools/typespec-validation/test/compile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe("compile", function () {
it("should fail if no emitter was configured", async function () {
let host = new TsvTestHost();
host.runCmd = async (cmd: string, _cwd: string): Promise<[Error | null, string, string]> => {
if (cmd.includes("tsp compile .")) {
if (cmd.includes("tsp compile")) {
return [null, "no emitter was configured", ""];
} else {
return [null, "", ""];
Expand All @@ -29,7 +29,7 @@ describe("compile", function () {
it("should fail if no output was generated", async function () {
let host = new TsvTestHost();
host.runCmd = async (cmd: string, _cwd: string): Promise<[Error | null, string, string]> => {
if (cmd.includes("tsp compile .")) {
if (cmd.includes("tsp compile")) {
return [null, "no output was generated", ""];
} else {
return [null, "", ""];
Expand Down

0 comments on commit b0679e9

Please sign in to comment.