"use strict";
/* Socket Lib - Built with rolldown */
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_runtime = require('../_virtual/_rolldown/runtime.js');
const require_env_rewire = require('./rewire.js');
let node_process = require("node:process");
node_process = require_runtime.__toESM(node_process);

//#region src/env/package-manager.ts
/**
* @file Package manager environment detection. Provides utilities to detect
*   which package manager (npm/pnpm/yarn/bun) is running.
*/
/**
* Detect which package manager is currently running based on environment
* variables. Checks npm_config_user_agent which all package managers set.
*
* Detection priority:
*
* 1. Npm_config_user_agent (most reliable, set by all package managers)
* 2. Binary path analysis (fallback for non-standard environments)
*
* @example
*   ;```typescript
*   // During: npm install
*   detectPackageManager() // 'npm'
*
*   // During: pnpm install
*   detectPackageManager() // 'pnpm'
*
*   // During: yarn install
*   detectPackageManager() // 'yarn'
*
*   // Outside package manager context
*   detectPackageManager() // undefined
*   ```
*
* @returns The detected package manager or null if unable to determine
*/
/*@__NO_SIDE_EFFECTS__*/
function detectPackageManager() {
	const userAgent = /* @__PURE__ */ getPackageManagerUserAgent();
	if (userAgent) {
		const match = userAgent.match(/^(npm|pnpm|yarn|bun)\//);
		if (match) return match[1];
	}
	/* c8 ignore start - argv0-based PM fallback only fires when
	npm_config_user_agent / lifecycle env detection both miss.
	In test runs argv0 is always the test runner's node binary,
	not a PM shim. */
	const argv0 = node_process.default.argv[0];
	if (argv0) {
		if (argv0.includes("/pnpm/") || argv0.includes("\\pnpm\\")) return "pnpm";
		if (argv0.includes("/yarn/") || argv0.includes("\\yarn\\") || argv0.includes("/.yarn/") || argv0.includes("\\.yarn\\")) return "yarn";
		if (argv0.includes("/bun/") || argv0.includes("\\bun\\")) return "bun";
		if (argv0.includes("/node_modules/") || argv0.includes("\\node_modules\\")) return "npm";
	}
}
/**
* Get the package manager name and version from user agent.
*
* @example
*   ;```typescript
*   getPackageManagerInfo()
*   // { name: 'pnpm', version: '8.15.1' }
*   ```
*
* @returns Object with name and version, or null if not available
*/
/*@__NO_SIDE_EFFECTS__*/
function getPackageManagerInfo() {
	const userAgent = /* @__PURE__ */ getPackageManagerUserAgent();
	if (!userAgent) return;
	const match = userAgent.match(/^([^/]+)\/([^\s]+)/);
	if (match?.[1] && match[2]) return {
		name: match[1],
		version: match[2]
	};
}
/**
* Get the package manager user agent from environment. Package managers set
* npm_config_user_agent with format: "npm/8.19.2 node/v18.12.0 darwin arm64"
*
* @example
*   ;```typescript
*   getPackageManagerUserAgent()
*   // npm: "npm/10.2.4 node/v20.11.0 darwin arm64 workspaces/false"
*   // pnpm: "pnpm/8.15.1 npm/? node/v20.11.0 darwin arm64"
*   // yarn: "yarn/1.22.19 npm/? node/v20.11.0 darwin arm64"
*   ```
*
* @returns The user agent string or undefined
*/
/*@__NO_SIDE_EFFECTS__*/
function getPackageManagerUserAgent() {
	return require_env_rewire.getEnvValue("npm_config_user_agent");
}

//#endregion
exports.detectPackageManager = detectPackageManager;
exports.getPackageManagerInfo = getPackageManagerInfo;
exports.getPackageManagerUserAgent = getPackageManagerUserAgent;