数通智联化工云平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
957 B

2 years ago
'use strict';
const installPkg = require('@antfu/install-pkg');
const utils = require('@antfu/utils');
const kolorist = require('kolorist');
const loader_warn = require('./warn.cjs');
let pending;
const tasks = {};
async function tryInstallPkg(name, autoInstall) {
if (pending) {
await pending;
}
if (!tasks[name]) {
console.log(kolorist.cyan(`Installing ${name}...`));
if (typeof autoInstall === "function") {
tasks[name] = pending = autoInstall(name).then(() => utils.sleep(300)).finally(() => {
pending = void 0;
});
} else {
tasks[name] = pending = installPkg.installPackage(name, {
dev: true,
preferOffline: true
}).then(() => utils.sleep(300)).catch((e) => {
loader_warn.warnOnce(`Failed to install ${name}`);
console.error(e);
}).finally(() => {
pending = void 0;
});
}
}
return tasks[name];
}
exports.tryInstallPkg = tryInstallPkg;