@amaster.ai/cli 1.1.22 → 1.1.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.cjs CHANGED
@@ -642,19 +642,82 @@ function parseTypeScriptError(line) {
642
642
  message
643
643
  };
644
644
  }
645
+ function parseTypeScriptErrors(output) {
646
+ return output.split("\n").map((line) => line.trim()).filter(Boolean).map(parseTypeScriptError).filter((item) => item !== null);
647
+ }
648
+ function getLocalBin(cwd, command) {
649
+ const suffix = process.platform === "win32" ? ".cmd" : "";
650
+ const binPath = path.join(cwd, "node_modules", ".bin", `${command}${suffix}`);
651
+ return fs.existsSync(binPath) ? binPath : null;
652
+ }
653
+ function getTypeCheckCommands(cwd, args) {
654
+ const commands = [];
655
+ const tsgo = getLocalBin(cwd, "tsgo");
656
+ if (tsgo) {
657
+ commands.push({
658
+ command: tsgo,
659
+ args,
660
+ label: "tsgo",
661
+ fallbackOnInfrastructureFailure: true
662
+ });
663
+ }
664
+ const tsc = getLocalBin(cwd, "tsc");
665
+ if (tsc) {
666
+ commands.push({
667
+ command: tsc,
668
+ args,
669
+ label: "tsc",
670
+ fallbackOnInfrastructureFailure: false
671
+ });
672
+ }
673
+ commands.push({
674
+ command: "npx",
675
+ args: ["--no-install", "tsc", ...args],
676
+ label: "npx --no-install tsc",
677
+ fallbackOnInfrastructureFailure: false
678
+ });
679
+ return commands;
680
+ }
681
+ function getTypeCheckFailureDetails(label, output) {
682
+ const details = output.trim().split("\n").slice(0, 10).join("\n");
683
+ return `Type check command failed before reporting TypeScript diagnostics: ${label}${details ? `
684
+ ${details}` : ""}`;
685
+ }
686
+ function getReactViteTypeCheckCommands(cwd) {
687
+ return getTypeCheckCommands(cwd, ["-p", "tsconfig.app.json", "--noEmit", "--pretty", "false"]);
688
+ }
645
689
  function runReactViteTypeCheck(cwd) {
646
- console.log("\u{1F50D} Running filtered TypeScript type check...\n");
647
- const result = runCommandCapture(
648
- "npx",
649
- ["tsc", "-p", "tsconfig.app.json", "--noEmit", "--pretty", "false"],
650
- { cwd }
651
- );
652
- const output = `${result.stdout ?? ""}${result.stderr ?? ""}`;
653
- if (result.status === 0) {
654
- console.log("\u2705 No type errors\n");
655
- return;
690
+ let errors = [];
691
+ let output = "";
692
+ let activeLabel = "";
693
+ for (const typeCheck of getReactViteTypeCheckCommands(cwd)) {
694
+ activeLabel = typeCheck.label;
695
+ console.log(`\u{1F50D} Running filtered TypeScript type check with ${typeCheck.label}...
696
+ `);
697
+ const result = runCommandCapture(typeCheck.command, typeCheck.args, { cwd });
698
+ const spawnError = result.error instanceof Error ? `${result.error.name}: ${result.error.message}
699
+ ` : "";
700
+ output = `${spawnError}${result.stdout ?? ""}${result.stderr ?? ""}`;
701
+ if (result.status === 0) {
702
+ console.log("\u2705 No type errors\n");
703
+ return;
704
+ }
705
+ errors = parseTypeScriptErrors(output);
706
+ if (errors.length > 0) {
707
+ break;
708
+ }
709
+ if (typeCheck.fallbackOnInfrastructureFailure) {
710
+ console.warn(
711
+ `\u26A0\uFE0F ${typeCheck.label} failed before reporting TypeScript diagnostics, falling back...
712
+ `
713
+ );
714
+ continue;
715
+ }
716
+ throw new Error(getTypeCheckFailureDetails(activeLabel, output));
717
+ }
718
+ if (errors.length === 0) {
719
+ throw new Error(getTypeCheckFailureDetails(activeLabel, output));
656
720
  }
657
- const errors = output.split("\n").map((line) => line.trim()).filter(Boolean).map(parseTypeScriptError).filter((item) => item !== null);
658
721
  const critical = errors.filter((item) => CRITICAL_TS_ERRORS.includes(item.code));
659
722
  const ignorable = errors.filter((item) => IGNORABLE_TS_ERRORS.includes(item.code));
660
723
  const other = errors.filter(
@@ -691,12 +754,39 @@ function runReactViteTypeCheck(cwd) {
691
754
  console.log("\u2705 No critical errors, proceeding...\n");
692
755
  }
693
756
  function runTaroTypeCheck(cwd) {
694
- console.log("\u{1F50D} Running TypeScript type check...");
695
- const result = runCommand("npx", ["tsc", "--noEmit"], { cwd });
696
- if (result.status !== 0) {
697
- throw new Error("Type check failed. Please fix the errors.");
757
+ let output = "";
758
+ let activeLabel = "";
759
+ for (const typeCheck of getTypeCheckCommands(cwd, ["--noEmit", "--pretty", "false"])) {
760
+ activeLabel = typeCheck.label;
761
+ console.log(`\u{1F50D} Running TypeScript type check with ${typeCheck.label}...`);
762
+ const result = runCommandCapture(typeCheck.command, typeCheck.args, { cwd });
763
+ const spawnError = result.error instanceof Error ? `${result.error.name}: ${result.error.message}
764
+ ` : "";
765
+ output = `${spawnError}${result.stdout ?? ""}${result.stderr ?? ""}`;
766
+ if (result.status === 0) {
767
+ console.log("\u2705 Type check passed!");
768
+ return;
769
+ }
770
+ const errors = parseTypeScriptErrors(output);
771
+ if (errors.length > 0) {
772
+ if (result.stdout) {
773
+ process.stdout.write(result.stdout);
774
+ }
775
+ if (result.stderr) {
776
+ process.stderr.write(result.stderr);
777
+ }
778
+ throw new Error("Type check failed. Please fix the errors.");
779
+ }
780
+ if (typeCheck.fallbackOnInfrastructureFailure) {
781
+ console.warn(
782
+ `\u26A0\uFE0F ${typeCheck.label} failed before reporting TypeScript diagnostics, falling back...
783
+ `
784
+ );
785
+ continue;
786
+ }
787
+ throw new Error(getTypeCheckFailureDetails(activeLabel, output));
698
788
  }
699
- console.log("\u2705 Type check passed!");
789
+ throw new Error(getTypeCheckFailureDetails(activeLabel, output));
700
790
  }
701
791
  var BUILD_ERROR_PATTERNS = [
702
792
  /\[ERROR\]/i,
@@ -1061,11 +1151,29 @@ async function runReactVitePreCommitChecks(cwd) {
1061
1151
  }
1062
1152
  async function runTaroPreCommitChecks(cwd) {
1063
1153
  const stagedFiles = getStagedFiles(cwd, ["*.ts", "*.tsx", "*.js", "*.jsx", "*.json", "*.css", "*.md"]);
1154
+ const stagedCodeFiles = getStagedFiles(cwd, ["*.ts", "*.tsx", "*.js", "*.jsx"]);
1155
+ const stagedBuildFiles = getStagedFiles(cwd, [
1156
+ "*.ts",
1157
+ "*.tsx",
1158
+ "*.js",
1159
+ "*.jsx",
1160
+ "*.json",
1161
+ "*.css",
1162
+ "*.scss"
1163
+ ]);
1064
1164
  runCommonFormattingChecks(cwd, stagedFiles);
1065
- await runTypeCheck({ cwd, stack: "taro" });
1066
- console.log("");
1067
- await runBuildCheck({ cwd, stack: "taro" });
1068
- console.log("\u2705 Build check passed!");
1165
+ if (stagedCodeFiles.length === 0) {
1166
+ console.log("\u23ED\uFE0F No code files (.ts/.tsx/.js/.jsx) staged, skipping type-check.");
1167
+ } else {
1168
+ await runTypeCheck({ cwd, stack: "taro" });
1169
+ console.log("");
1170
+ }
1171
+ if (stagedBuildFiles.length === 0) {
1172
+ console.log("\u23ED\uFE0F No build-affecting files staged, skipping build-check.");
1173
+ } else {
1174
+ await runBuildCheck({ cwd, stack: "taro" });
1175
+ console.log("\u2705 Build check passed!");
1176
+ }
1069
1177
  }
1070
1178
  async function runPreCommitCheck(options) {
1071
1179
  const cwd = options.cwd ?? process.cwd();