async execute()

in eng/tools/typespec-validation/src/rules/compile.ts [10:61]


  async execute(host: TsvHost, folder: string): Promise<RuleResult> {
    let success = true;
    let stdOutput = "";
    let errorOutput = "";

    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,
      );
      if (
        stdout.toLowerCase().includes("no emitter was configured") ||
        stdout.toLowerCase().includes("no output was generated")
      ) {
        success = false;
        errorOutput += "No emitter was configured and/or no output was generated.";
      }
      if (err) {
        success = false;
        errorOutput += err.message;
      }
      stdOutput += stdout;
      errorOutput += stderr;
    }
    if (await host.checkFileExists(path.join(folder, "client.tsp"))) {
      let [err, stdout, stderr] = await host.runCmd(
        `npm exec --no -- tsp compile client.tsp --no-emit --warn-as-error`,
        folder,
      );
      if (err) {
        success = false;
        errorOutput += err.message;
      }
      stdOutput += stdout;
      errorOutput += stderr;
    }

    if (success) {
      const gitDiffResult = await host.gitDiffTopSpecFolder(host, folder);
      stdOutput += gitDiffResult.stdOutput;
      if (!gitDiffResult.success) {
        success = false;
        errorOutput += gitDiffResult.errorOutput;
        errorOutput += `\nFiles have been changed after \`tsp compile\`. Run \`tsp compile\` and ensure all files are included in your change.`;
      }
    }
    return {
      success: success,
      stdOutput: stdOutput,
      errorOutput: errorOutput,
    };
  }