"use strict";
/* Socket Lib - Built with rolldown */
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_constants_platform = require('../../../constants/platform.js');
const require_primordials_array = require('../../../primordials/array.js');
const require_debug_namespace = require('../../../debug/namespace.js');
const require_process_spawn_child = require('../../../process/spawn/child.js');
const require_constants_agents = require('../../../constants/agents.js');
const require_eco_npm_npm_flags = require('./flags.js');

//#region src/eco/npm/npm/exec.ts
/**
* @file Execute npm commands with optimized flags and security defaults.
*   SECURITY: Array-based arguments prevent command injection. All elements in
*   the args array are properly escaped by Node.js when passed to spawn().
*   NOTE: We don't apply hardening flags to npm because:
*
*   1. npm is a trusted system tool installed with Node.js.
*   2. npm requires full system access (filesystem, network, child processes).
*   3. Hardening flags would prevent npm from functioning even with --allow-*
*      grants.
*   4. The permission model is intended for untrusted user code, not package
*      managers.
*/
/**
* Execute npm commands with optimized flags and settings.
*
* @example
*   ;```typescript
*   await execNpm(['install', '--save', 'lodash'])
*   await execNpm(['run', 'build'], { cwd: '/tmp/project' })
*   ```
*/
function execNpm(args, options) {
	const useDebug = /* @__PURE__ */ require_debug_namespace.isDebug();
	const terminatorPos = require_primordials_array.ArrayPrototypeIndexOf(args, "--");
	const npmArgs = (terminatorPos === -1 ? args : require_primordials_array.ArrayPrototypeSlice(args, 0, terminatorPos)).filter((a) => !/* @__PURE__ */ require_eco_npm_npm_flags.isNpmAuditFlag(a) && !/* @__PURE__ */ require_eco_npm_npm_flags.isNpmFundFlag(a) && !/* @__PURE__ */ require_eco_npm_npm_flags.isNpmProgressFlag(a));
	const otherArgs = terminatorPos === -1 ? [] : require_primordials_array.ArrayPrototypeSlice(args, terminatorPos);
	return require_process_spawn_child.spawn(require_constants_agents.NPM_BIN_PATH, [
		"--no-audit",
		"--no-fund",
		"--no-progress",
		...useDebug || npmArgs.some(require_eco_npm_npm_flags.isNpmLoglevelFlag) ? [] : ["--loglevel", "warn"],
		...npmArgs,
		...otherArgs
	], {
		__proto__: null,
		shell: require_constants_platform.WIN32,
		...options
	});
}

//#endregion
exports.execNpm = execNpm;