First commit.

Signed-off-by: Chen Xiao <abigwc@gmail.com>
This commit is contained in:
Chen Xiao
2026-05-08 14:43:16 +08:00
commit 0b64e2de94
10989 changed files with 2253791 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
import { warnOnce } from "./warn.js";
import { installPackage } from "@antfu/install-pkg";
import { styleText } from "node:util";
let pending;
const tasks = {};
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
async function tryInstallPkg(name, autoInstall) {
if (pending) await pending;
if (!tasks[name]) {
console.log(styleText("cyan", `Installing ${name}...`));
if (typeof autoInstall === "function") tasks[name] = pending = autoInstall(name).then(() => sleep(300)).finally(() => {
pending = void 0;
});
else tasks[name] = pending = installPackage(name, {
dev: true,
preferOffline: true
}).then(() => sleep(300)).catch((e) => {
warnOnce(`Failed to install ${name}`);
console.error(e);
}).finally(() => {
pending = void 0;
});
}
return tasks[name];
}
export { tryInstallPkg };