"use strict";
/* Socket Lib - Built with esbuild */
"use strict";
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);
var exec_exports = {};
__export(exec_exports, {
  execNpm: () => execNpm
});
module.exports = __toCommonJS(exec_exports);
var import_agents = require("../../../constants/agents");
var import_platform = require("../../../constants/platform");
var import_namespace = require("../../../debug/namespace");
var import_array = require("../../../primordials/array");
var import_spawn = require("../../../spawn/spawn");
var import_flags = require("./flags");
function execNpm(args, options) {
  const useDebug = (0, import_namespace.isDebug)();
  const terminatorPos = (0, import_array.ArrayPrototypeIndexOf)(args, "--");
  const npmArgs = (terminatorPos === -1 ? args : (0, import_array.ArrayPrototypeSlice)(args, 0, terminatorPos)).filter(
    (a) => !(0, import_flags.isNpmAuditFlag)(a) && !(0, import_flags.isNpmFundFlag)(a) && !(0, import_flags.isNpmProgressFlag)(a)
  );
  const otherArgs = terminatorPos === -1 ? [] : (0, import_array.ArrayPrototypeSlice)(args, terminatorPos);
  const logLevelArgs = useDebug || npmArgs.some(import_flags.isNpmLoglevelFlag) ? [] : ["--loglevel", "warn"];
  return (0, import_spawn.spawn)(
    import_agents.NPM_BIN_PATH,
    [
      // Even with `--loglevel=error`, npm still runs through 'audit'/'fund'
      // codepaths unless --no-audit / --no-fund are passed explicitly.
      "--no-audit",
      "--no-fund",
      // Avoid input being swallowed by the spinner in recent npm versions.
      "--no-progress",
      ...logLevelArgs,
      ...npmArgs,
      ...otherArgs
    ],
    {
      __proto__: null,
      // npm on Windows is a .cmd file that requires a shell.
      shell: import_platform.WIN32,
      ...options
    }
  );
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  execNpm
});
