@node-kit/which-pm
Version:
A simple utility to get which package manager used in the project
57 lines (53 loc) • 1.63 kB
JavaScript
import { pmInfoSync, pmInfo } from 'pm-info';
function asyncGeneratorStep(n, t, e, r, o, a, c) {
try {
var i = n[a](c),
u = i.value;
} catch (n) {
return void e(n);
}
i.done ? t(u) : Promise.resolve(u).then(r, o);
}
function _asyncToGenerator(n) {
return function () {
var t = this,
e = arguments;
return new Promise(function (r, o) {
var a = n.apply(t, e);
function _next(n) {
asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
}
function _throw(n) {
asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
}
_next(void 0);
});
};
}
function whichPM() {
return _whichPM.apply(this, arguments);
}
function _whichPM() {
_whichPM = _asyncToGenerator(function* () {
var cwd = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : process.cwd();
var withVersion = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : true;
var info = yield pmInfo(cwd);
if (!info)
return null;
else if (!withVersion)
return info.name;
return "".concat(info.name).concat(info.version ? "@" + info.version : "");
});
return _whichPM.apply(this, arguments);
}
function whichPMSync() {
var cwd = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : process.cwd();
var withVersion = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : true;
var info = pmInfoSync(cwd);
if (!info)
return null;
else if (!withVersion)
return info.name;
return "".concat(info.name).concat(info.version ? "@" + info.version : "");
}
export { whichPM, whichPMSync };