@bgicli/bgicli 2.2.3 → 2.2.4
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/bgi.js +19 -6
- package/package.json +1 -1
package/dist/bgi.js
CHANGED
|
@@ -13762,20 +13762,33 @@ function executeTool(name, args) {
|
|
|
13762
13762
|
return { output: "", error: String(err) };
|
|
13763
13763
|
}
|
|
13764
13764
|
}
|
|
13765
|
+
function decodeBuffer(buf) {
|
|
13766
|
+
if (!buf) return "";
|
|
13767
|
+
if (typeof buf === "string") return buf;
|
|
13768
|
+
try {
|
|
13769
|
+
return new TextDecoder("utf-8", { fatal: true }).decode(buf);
|
|
13770
|
+
} catch {
|
|
13771
|
+
try {
|
|
13772
|
+
return new TextDecoder("gbk").decode(buf);
|
|
13773
|
+
} catch {
|
|
13774
|
+
return buf.toString("latin1");
|
|
13775
|
+
}
|
|
13776
|
+
}
|
|
13777
|
+
}
|
|
13765
13778
|
function toolBash(command, workdir, timeoutMs = 3e4) {
|
|
13766
13779
|
try {
|
|
13767
|
-
const
|
|
13780
|
+
const buf = (0, import_child_process.execSync)(command, {
|
|
13768
13781
|
cwd: workdir ?? process.cwd(),
|
|
13769
13782
|
timeout: timeoutMs,
|
|
13770
|
-
encoding: "
|
|
13783
|
+
encoding: "buffer",
|
|
13771
13784
|
stdio: ["pipe", "pipe", "pipe"],
|
|
13772
|
-
maxBuffer: 10 * 1024 * 1024
|
|
13773
|
-
|
|
13785
|
+
maxBuffer: 10 * 1024 * 1024,
|
|
13786
|
+
env: { ...process.env, PYTHONIOENCODING: "utf-8" }
|
|
13774
13787
|
});
|
|
13775
|
-
return { output:
|
|
13788
|
+
return { output: decodeBuffer(buf).trim() };
|
|
13776
13789
|
} catch (err) {
|
|
13777
13790
|
const e2 = err;
|
|
13778
|
-
const out = ((e2.stdout
|
|
13791
|
+
const out = (decodeBuffer(e2.stdout) + "\n" + decodeBuffer(e2.stderr)).trim();
|
|
13779
13792
|
return { output: out, error: e2.message ?? String(err) };
|
|
13780
13793
|
}
|
|
13781
13794
|
}
|