"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.npmClients = exports.installWithNpmClient = exports.getNpmClient = exports.NpmClientEnum = void 0;
var _fs = require("fs");
var _path = require("path");
const npmClients = ['pnpm', 'tnpm', 'cnpm', 'yarn', 'npm'];
exports.npmClients = npmClients;
let NpmClientEnum = /*#__PURE__*/function (NpmClientEnum) {
  NpmClientEnum["pnpm"] = "pnpm";
  NpmClientEnum["tnpm"] = "tnpm";
  NpmClientEnum["cnpm"] = "cnpm";
  NpmClientEnum["yarn"] = "yarn";
  NpmClientEnum["npm"] = "npm";
  return NpmClientEnum;
}({});
exports.NpmClientEnum = NpmClientEnum;
const getNpmClient = opts => {
  const chokidarPkg = require('chokidar/package.json');
  if (chokidarPkg.__npminstall_done) {
    return chokidarPkg._resolved.includes('registry.npm.alibaba-inc.com') ? 'tnpm' : 'cnpm';
  }
  const chokidarPath = require.resolve('chokidar');
  if (chokidarPath.includes('.pnpm') || (0, _fs.existsSync)((0, _path.join)(opts.cwd, 'node_modules', '.pnpm'))) {
    return 'pnpm';
  }
  if ((0, _fs.existsSync)((0, _path.join)(opts.cwd, 'yarn.lock')) || (0, _fs.existsSync)((0, _path.join)(opts.cwd, 'node_modules', '.yarn-integrity'))) {
    return 'yarn';
  }
  return 'npm';
};
exports.getNpmClient = getNpmClient;
const installWithNpmClient = ({
  npmClient,
  cwd
}) => {
  const {
    sync
  } = require('../compiled/cross-spawn');
  const npm = sync(npmClient, [npmClient === 'yarn' ? '' : 'install'], {
    stdio: 'inherit',
    cwd
  });
  if (npm.error) {
    throw npm.error;
  }
};
exports.installWithNpmClient = installWithNpmClient;