Urara-Blog/node_modules/.pnpm-store/v3/files/ad/5745d3ee86bf116f9df4df763da797e27712922f8e049dd04dff99e82bbd014f1910230028f1bc49a12b5cd74dfb37a0990146e0ec6b7666ee302e21f6ada6
2022-08-14 01:14:53 +08:00

27 lines
660 B
Text

import { installPackage } from '@antfu/install-pkg';
import { sleep } from '@antfu/utils';
import { cyan } from 'kolorist';
import { warnOnce } from './warn.mjs';
let pending;
const tasks = {};
async function tryInstallPkg(name) {
if (pending) {
await pending;
}
if (!tasks[name]) {
console.log(cyan(`Installing ${name}...`));
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 };