UNPKG

@eljs/utils

Version:
71 lines (69 loc) 2.19 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/npm/package-manager.ts var package_manager_exports = {}; __export(package_manager_exports, { getPackageManager: () => getPackageManager }); module.exports = __toCommonJS(package_manager_exports); var import_env = require("../env"); var import_path = require("../path"); var cache = /* @__PURE__ */ new Map(); async function getPackageManager(cwd = process.cwd()) { const type = await getTypeofLockFile(cwd); if (type) { return type; } const [hasPnpm, hasYarn] = await Promise.all([ (0, import_env.hasGlobalInstallation)("pnpm"), (0, import_env.hasGlobalInstallation)("yarn") ]); if (hasPnpm) { return "pnpm"; } if (hasYarn) { return "yarn"; } return "npm"; } async function getTypeofLockFile(cwd = process.cwd()) { const key = `has_lockfile_${cwd}`; if (cache.has(key)) { return Promise.resolve(cache.get(key)); } return Promise.all([ (0, import_path.getPnpmWorkspaceRoot)(cwd), (0, import_path.getYarnWorkspaceRoot)(cwd), (0, import_path.getNpmWorkspaceRoot)(cwd) ]).then(([isPnpm, isYarn, isNpm]) => { let value = null; if (isPnpm) { value = "pnpm"; } else if (isYarn) { value = "yarn"; } else if (isNpm) { value = "npm"; } cache.set(key, value); return value; }); } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { getPackageManager });