@amaster.ai/cli 1.1.22 → 1.1.23
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 +128 -20
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +128 -20
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +128 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +128 -20
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -636,19 +636,82 @@ function parseTypeScriptError(line) {
|
|
|
636
636
|
message
|
|
637
637
|
};
|
|
638
638
|
}
|
|
639
|
+
function parseTypeScriptErrors(output) {
|
|
640
|
+
return output.split("\n").map((line) => line.trim()).filter(Boolean).map(parseTypeScriptError).filter((item) => item !== null);
|
|
641
|
+
}
|
|
642
|
+
function getLocalBin(cwd, command) {
|
|
643
|
+
const suffix = process.platform === "win32" ? ".cmd" : "";
|
|
644
|
+
const binPath = join(cwd, "node_modules", ".bin", `${command}${suffix}`);
|
|
645
|
+
return existsSync(binPath) ? binPath : null;
|
|
646
|
+
}
|
|
647
|
+
function getTypeCheckCommands(cwd, args) {
|
|
648
|
+
const commands = [];
|
|
649
|
+
const tsgo = getLocalBin(cwd, "tsgo");
|
|
650
|
+
if (tsgo) {
|
|
651
|
+
commands.push({
|
|
652
|
+
command: tsgo,
|
|
653
|
+
args,
|
|
654
|
+
label: "tsgo",
|
|
655
|
+
fallbackOnInfrastructureFailure: true
|
|
656
|
+
});
|
|
657
|
+
}
|
|
658
|
+
const tsc = getLocalBin(cwd, "tsc");
|
|
659
|
+
if (tsc) {
|
|
660
|
+
commands.push({
|
|
661
|
+
command: tsc,
|
|
662
|
+
args,
|
|
663
|
+
label: "tsc",
|
|
664
|
+
fallbackOnInfrastructureFailure: false
|
|
665
|
+
});
|
|
666
|
+
}
|
|
667
|
+
commands.push({
|
|
668
|
+
command: "npx",
|
|
669
|
+
args: ["--no-install", "tsc", ...args],
|
|
670
|
+
label: "npx --no-install tsc",
|
|
671
|
+
fallbackOnInfrastructureFailure: false
|
|
672
|
+
});
|
|
673
|
+
return commands;
|
|
674
|
+
}
|
|
675
|
+
function getTypeCheckFailureDetails(label, output) {
|
|
676
|
+
const details = output.trim().split("\n").slice(0, 10).join("\n");
|
|
677
|
+
return `Type check command failed before reporting TypeScript diagnostics: ${label}${details ? `
|
|
678
|
+
${details}` : ""}`;
|
|
679
|
+
}
|
|
680
|
+
function getReactViteTypeCheckCommands(cwd) {
|
|
681
|
+
return getTypeCheckCommands(cwd, ["-p", "tsconfig.app.json", "--noEmit", "--pretty", "false"]);
|
|
682
|
+
}
|
|
639
683
|
function runReactViteTypeCheck(cwd) {
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
684
|
+
let errors = [];
|
|
685
|
+
let output = "";
|
|
686
|
+
let activeLabel = "";
|
|
687
|
+
for (const typeCheck of getReactViteTypeCheckCommands(cwd)) {
|
|
688
|
+
activeLabel = typeCheck.label;
|
|
689
|
+
console.log(`\u{1F50D} Running filtered TypeScript type check with ${typeCheck.label}...
|
|
690
|
+
`);
|
|
691
|
+
const result = runCommandCapture(typeCheck.command, typeCheck.args, { cwd });
|
|
692
|
+
const spawnError = result.error instanceof Error ? `${result.error.name}: ${result.error.message}
|
|
693
|
+
` : "";
|
|
694
|
+
output = `${spawnError}${result.stdout ?? ""}${result.stderr ?? ""}`;
|
|
695
|
+
if (result.status === 0) {
|
|
696
|
+
console.log("\u2705 No type errors\n");
|
|
697
|
+
return;
|
|
698
|
+
}
|
|
699
|
+
errors = parseTypeScriptErrors(output);
|
|
700
|
+
if (errors.length > 0) {
|
|
701
|
+
break;
|
|
702
|
+
}
|
|
703
|
+
if (typeCheck.fallbackOnInfrastructureFailure) {
|
|
704
|
+
console.warn(
|
|
705
|
+
`\u26A0\uFE0F ${typeCheck.label} failed before reporting TypeScript diagnostics, falling back...
|
|
706
|
+
`
|
|
707
|
+
);
|
|
708
|
+
continue;
|
|
709
|
+
}
|
|
710
|
+
throw new Error(getTypeCheckFailureDetails(activeLabel, output));
|
|
711
|
+
}
|
|
712
|
+
if (errors.length === 0) {
|
|
713
|
+
throw new Error(getTypeCheckFailureDetails(activeLabel, output));
|
|
650
714
|
}
|
|
651
|
-
const errors = output.split("\n").map((line) => line.trim()).filter(Boolean).map(parseTypeScriptError).filter((item) => item !== null);
|
|
652
715
|
const critical = errors.filter((item) => CRITICAL_TS_ERRORS.includes(item.code));
|
|
653
716
|
const ignorable = errors.filter((item) => IGNORABLE_TS_ERRORS.includes(item.code));
|
|
654
717
|
const other = errors.filter(
|
|
@@ -685,12 +748,39 @@ function runReactViteTypeCheck(cwd) {
|
|
|
685
748
|
console.log("\u2705 No critical errors, proceeding...\n");
|
|
686
749
|
}
|
|
687
750
|
function runTaroTypeCheck(cwd) {
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
751
|
+
let output = "";
|
|
752
|
+
let activeLabel = "";
|
|
753
|
+
for (const typeCheck of getTypeCheckCommands(cwd, ["--noEmit", "--pretty", "false"])) {
|
|
754
|
+
activeLabel = typeCheck.label;
|
|
755
|
+
console.log(`\u{1F50D} Running TypeScript type check with ${typeCheck.label}...`);
|
|
756
|
+
const result = runCommandCapture(typeCheck.command, typeCheck.args, { cwd });
|
|
757
|
+
const spawnError = result.error instanceof Error ? `${result.error.name}: ${result.error.message}
|
|
758
|
+
` : "";
|
|
759
|
+
output = `${spawnError}${result.stdout ?? ""}${result.stderr ?? ""}`;
|
|
760
|
+
if (result.status === 0) {
|
|
761
|
+
console.log("\u2705 Type check passed!");
|
|
762
|
+
return;
|
|
763
|
+
}
|
|
764
|
+
const errors = parseTypeScriptErrors(output);
|
|
765
|
+
if (errors.length > 0) {
|
|
766
|
+
if (result.stdout) {
|
|
767
|
+
process.stdout.write(result.stdout);
|
|
768
|
+
}
|
|
769
|
+
if (result.stderr) {
|
|
770
|
+
process.stderr.write(result.stderr);
|
|
771
|
+
}
|
|
772
|
+
throw new Error("Type check failed. Please fix the errors.");
|
|
773
|
+
}
|
|
774
|
+
if (typeCheck.fallbackOnInfrastructureFailure) {
|
|
775
|
+
console.warn(
|
|
776
|
+
`\u26A0\uFE0F ${typeCheck.label} failed before reporting TypeScript diagnostics, falling back...
|
|
777
|
+
`
|
|
778
|
+
);
|
|
779
|
+
continue;
|
|
780
|
+
}
|
|
781
|
+
throw new Error(getTypeCheckFailureDetails(activeLabel, output));
|
|
692
782
|
}
|
|
693
|
-
|
|
783
|
+
throw new Error(getTypeCheckFailureDetails(activeLabel, output));
|
|
694
784
|
}
|
|
695
785
|
var BUILD_ERROR_PATTERNS = [
|
|
696
786
|
/\[ERROR\]/i,
|
|
@@ -1055,11 +1145,29 @@ async function runReactVitePreCommitChecks(cwd) {
|
|
|
1055
1145
|
}
|
|
1056
1146
|
async function runTaroPreCommitChecks(cwd) {
|
|
1057
1147
|
const stagedFiles = getStagedFiles(cwd, ["*.ts", "*.tsx", "*.js", "*.jsx", "*.json", "*.css", "*.md"]);
|
|
1148
|
+
const stagedCodeFiles = getStagedFiles(cwd, ["*.ts", "*.tsx", "*.js", "*.jsx"]);
|
|
1149
|
+
const stagedBuildFiles = getStagedFiles(cwd, [
|
|
1150
|
+
"*.ts",
|
|
1151
|
+
"*.tsx",
|
|
1152
|
+
"*.js",
|
|
1153
|
+
"*.jsx",
|
|
1154
|
+
"*.json",
|
|
1155
|
+
"*.css",
|
|
1156
|
+
"*.scss"
|
|
1157
|
+
]);
|
|
1058
1158
|
runCommonFormattingChecks(cwd, stagedFiles);
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1159
|
+
if (stagedCodeFiles.length === 0) {
|
|
1160
|
+
console.log("\u23ED\uFE0F No code files (.ts/.tsx/.js/.jsx) staged, skipping type-check.");
|
|
1161
|
+
} else {
|
|
1162
|
+
await runTypeCheck({ cwd, stack: "taro" });
|
|
1163
|
+
console.log("");
|
|
1164
|
+
}
|
|
1165
|
+
if (stagedBuildFiles.length === 0) {
|
|
1166
|
+
console.log("\u23ED\uFE0F No build-affecting files staged, skipping build-check.");
|
|
1167
|
+
} else {
|
|
1168
|
+
await runBuildCheck({ cwd, stack: "taro" });
|
|
1169
|
+
console.log("\u2705 Build check passed!");
|
|
1170
|
+
}
|
|
1063
1171
|
}
|
|
1064
1172
|
async function runPreCommitCheck(options) {
|
|
1065
1173
|
const cwd = options.cwd ?? process.cwd();
|