Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TypeSpecValidation] Pass target path to "tsp compile" #31371

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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