Files
desa-darmasaba/xcoba2.ts
nico 171d7f7947 fix(biome-lint): resolve critical and medium priority lint issues
CRITICAL FIXES:
- Fix noAsyncPromiseExecutor in xcoba.ts and xcoba2.ts
  * Removed async promise executor pattern
  * Refactored to proper promise chain with .then()/.catch()
  * Added proper error handling for unhandled rejections

- Fix useIterableCallbackReturn in seed_berita.ts
  * Replaced forEach with for...of loop to avoid returning values in callbacks

MEDIUM FIXES:
- Fix useNodejsImportProtocol (728 files auto-fixed)
  * Updated Node.js builtin imports to use node: protocol
  * Files: eslint.config.mjs, vitest.config.ts, zgen/image.ts, and 725+ more

- Fix useOptionalChain in xcoba.ts (auto-fixed)
  * Changed 'resOut && resOut.body' to 'resOut?.body'

- Fix noImportantStyles in dark-mode-table.css
  * Added biome-ignore suppression comments with justification
  * Required to override Mantine UI library styles

- Fix noUselessContinue in find-port.ts (auto-fixed)
  * Removed unnecessary continue statement

- Fix useLiteralKeys (700+ files auto-fixed)
  * Simplified computed expressions to use literal keys
  * Example: obj['create'] -> obj.create

RESULTS:
- Errors reduced: 4,516 → 3,521 (-22%)
- Warnings reduced: 3,861 → 2,083 (-46%)
- Total issues reduced: 8,991 → 6,115 (-32%)
- 735 files auto-fixed by biome lint --fix

Remaining issues (~6,115):
- Mostly noExplicitAny warnings requiring manual refactoring
- Will be addressed in gradual code quality improvements

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-04-09 17:27:17 +08:00

109 lines
3.2 KiB
TypeScript

import { spawn } from 'bun';
async function proc(params?: {
env?: Record<string, string | undefined>;
cmd?: string;
cwd?: string;
timeout?: number;
exitCode?: number;
onStdOut?: (chunk: string) => void;
onStdErr?: (chunk: string) => void;
onStdio?: (chunk: string) => void;
}) {
const { env = {}, cmd, cwd = "./", timeout = 600000 } = params || {};
return new Promise((resolve, reject) => {
if (!cmd || typeof cmd !== "string") {
return reject(new Error("Invalid or missing command"));
}
const std = {
stdout: "",
stderr: "",
stdio: "",
};
try {
// Spawn the child process
const child = spawn(cmd.split(" "), {
cwd,
env: {
PATH: process.env.PATH,
...env,
},
});
// Set a timeout to kill the process if it takes too long
const timeOut = setTimeout(() => {
try {
child.kill();
} catch (err) {
console.warn("Failed to kill child process:", err);
}
reject(new Error("Process timed out"));
}, timeout);
// Read stdout and stderr as text
Promise.all([
readStream(child.stdout),
child.stderr ? readStream(child.stderr) : Promise.resolve(""),
])
.then(([stdout, stderr]) => {
// Handle stdout
std.stdout = stdout;
std.stdio += stdout;
if (params?.onStdOut) {
params.onStdOut(stdout.trim());
}
if (params?.onStdio) {
params.onStdio(stdout.trim());
}
// Handle stderr
std.stderr = stderr ?? "";
std.stdio += stderr;
if (params?.onStdErr) {
params.onStdErr((stderr ?? "").trim());
}
if (params?.onStdio) {
params.onStdio((stderr ?? "").trim());
}
clearTimeout(timeOut);
resolve(std);
})
.catch((err) => {
clearTimeout(timeOut);
reject(err);
});
} catch (err) {
reject(err);
}
});
}
async function readStream(stream: ReadableStream<Uint8Array>): Promise<string> {
const reader = stream.getReader();
const decoder = new TextDecoder();
let result = '';
let done = false;
while (!done) {
const { value, done: streamDone } = await reader.read();
done = streamDone;
if (value) {
result += decoder.decode(value, { stream: true });
}
}
result += decoder.decode(); // flush any remaining data
return result.trim();
}
export default proc;
proc({
cmd: "bun run build",
cwd: "./",
onStdio: (text) => {
console.log(text.trim());
}
})