"use strict";
/* Socket Lib - Built with rolldown */
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_primordials_array = require('../../../primordials/array.js');
const require_debug_namespace = require('../../../debug/namespace.js');
const require_env_ci = require('../../../env/ci.js');
const require_bin_exec = require('../../../bin/exec.js');
const require_eco_npm_npm_flags = require('../npm/flags.js');
const require_eco_npm_pnpm_flags = require('./flags.js');

//#region src/eco/npm/pnpm/exec.ts
/**
* @file Execute pnpm 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 execBin().
*/
/**
* Execute pnpm commands with optimized flags and settings.
*
* @example
*   ;```typescript
*   await execPnpm(['install'])
*   await execPnpm(['add', 'lodash'], { allowLockfileUpdate: true })
*   ```
*/
function execPnpm(args, options) {
	const { allowLockfileUpdate, ...extBinOpts } = {
		__proto__: null,
		...options
	};
	const useDebug = /* @__PURE__ */ require_debug_namespace.isDebug();
	const terminatorPos = require_primordials_array.ArrayPrototypeIndexOf(args, "--");
	const pnpmArgs = (terminatorPos === -1 ? args : require_primordials_array.ArrayPrototypeSlice(args, 0, terminatorPos)).filter((a) => !/* @__PURE__ */ require_eco_npm_npm_flags.isNpmProgressFlag(a));
	const otherArgs = terminatorPos === -1 ? [] : require_primordials_array.ArrayPrototypeSlice(args, terminatorPos);
	const firstArg = pnpmArgs[0];
	const supportsIgnoreScripts = firstArg ? require_eco_npm_pnpm_flags.PNPM_INSTALL_LIKE_COMMANDS.has(firstArg) : false;
	const logLevelArgs = useDebug || pnpmArgs.some(require_eco_npm_pnpm_flags.isPnpmLoglevelFlag) ? [] : ["--loglevel", "warn"];
	const hasIgnoreScriptsFlag = pnpmArgs.some(require_eco_npm_pnpm_flags.isPnpmIgnoreScriptsFlag);
	const ignoreScriptsArgs = !supportsIgnoreScripts || hasIgnoreScriptsFlag ? [] : ["--ignore-scripts"];
	/* c8 ignore start */
	const frozenLockfileArgs = [];
	if (/* @__PURE__ */ require_env_ci.getCI() && allowLockfileUpdate && firstArg && /* @__PURE__ */ require_eco_npm_pnpm_flags.isPnpmInstallCommand(firstArg) && !pnpmArgs.some(require_eco_npm_pnpm_flags.isPnpmFrozenLockfileFlag)) frozenLockfileArgs.push("--no-frozen-lockfile");
	/* c8 ignore stop */
	return /* @__PURE__ */ require_bin_exec.execBin("pnpm", [
		...logLevelArgs,
		...ignoreScriptsArgs,
		...frozenLockfileArgs,
		...pnpmArgs,
		...otherArgs
	], extBinOpts);
}

//#endregion
exports.execPnpm = execPnpm;