"use strict";
/* Socket Lib - Built with rolldown */
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_primordials_array = require('../../../../primordials/array.js');
const require_primordials_map_set = require('../../../../primordials/map-set.js');
const require_debug_namespace = require('../../../../debug/namespace.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('../../pnpm/flags.js');

//#region src/eco/npm/yarnpkg/yarn/exec.ts
/**
* @file Execute Yarn Classic (v1.x) commands with optimized flags and security
*   defaults. SECURITY: Array-based arguments prevent command injection. NOTE:
*   This is the canonical home of the cross-yarn execYarn. Yarn Berry (v2-v4)
*   and ZPM (v6+) currently delegate to this implementation — that's
*   load-bearing in the dir layout: when version-specific behavior diverges
*   (e.g. Berry's `--immutable` replacing Classic's `--frozen-lockfile`), the
*   override lands in the version's own eco/npm/yarn-{berry,zpm}/exec.ts file,
*   and yarn-classic stays here.
*/
const yarnInstallLikeCommands = new require_primordials_map_set.SetCtor([
	"add",
	"import",
	"install",
	"link",
	"remove",
	"unlink",
	"upgrade"
]);
/**
* Execute yarn commands with optimized flags and settings.
*
* @example
*   ;```typescript
*   await execYarn(['install'])
*   await execYarn(['add', 'lodash'], { cwd: '/tmp/project' })
*   ```
*/
function execYarn(args, options) {
	const useDebug = /* @__PURE__ */ require_debug_namespace.isDebug();
	const terminatorPos = require_primordials_array.ArrayPrototypeIndexOf(args, "--");
	const yarnArgs = (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 = yarnArgs[0];
	/* c8 ignore start */
	const supportsIgnoreScripts = firstArg ? yarnInstallLikeCommands.has(firstArg) : false;
	const logLevelArgs = useDebug || yarnArgs.some(require_eco_npm_npm_flags.isNpmLoglevelFlag) ? [] : ["--silent"];
	const hasIgnoreScriptsFlag = yarnArgs.some(require_eco_npm_pnpm_flags.isPnpmIgnoreScriptsFlag);
	const ignoreScriptsArgs = !supportsIgnoreScripts || hasIgnoreScriptsFlag ? [] : ["--ignore-scripts"];
	/* c8 ignore stop */
	return /* @__PURE__ */ require_bin_exec.execBin("yarn", [
		...logLevelArgs,
		...ignoreScriptsArgs,
		...yarnArgs,
		...otherArgs
	], {
		__proto__: null,
		...options
	});
}

//#endregion
exports.execYarn = execYarn;