"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
function _export(target, all) {
    for(var name in all)Object.defineProperty(target, name, {
        enumerable: true,
        get: Object.getOwnPropertyDescriptor(all, name).get
    });
}
_export(exports, {
    get detectNodePackageManager () {
        return detectNodePackageManager;
    },
    get installNodePackage () {
        return installNodePackage;
    }
});
function _promises() {
    const data = require("node:fs/promises");
    _promises = function() {
        return data;
    };
    return data;
}
function _exec() {
    const data = require("~/base/node/exec");
    _exec = function() {
        return data;
    };
    return data;
}
const detectNodePackageManager = async (cwd)=>{
    const files = await (0, _promises().readdir)(cwd);
    if (files.includes("pnpm-lock.yaml")) {
        return "pnpm";
    }
    if (files.includes("yarn.lock")) {
        return "yarn";
    }
    if (files.includes("bun.lockb")) {
        return "bun";
    }
    if (files.includes("package-lock.json")) {
        return "npm";
    }
    return;
};
const installNodePackage = async (name, { cwd, manager = "npm", verbose = false, dev })=>{
    const _items = name;
    if (manager === "pnpm") {
        return await (0, _exec().exec)({
            command: `pnpm install ${_items} ${dev ? "--save-dev" : ""}`,
            cwd,
            verbose
        });
    }
    if (manager === "yarn") {
        return await (0, _exec().exec)({
            command: `yarn add ${_items} ${dev ? "--dev" : ""}`,
            cwd,
            verbose
        });
    }
    if (manager === "bun") {
        return await (0, _exec().exec)({
            command: `bun add ${_items} ${dev ? "--dev" : ""}`,
            cwd,
            verbose
        });
    }
    return await (0, _exec().exec)({
        command: `npm install ${_items} ${dev ? "--save-dev" : ""}`,
        cwd,
        verbose
    });
};
