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

//#region src/process/transient.ts
/**
* @file Temporary package executor detection utilities for Socket ecosystem.
*   Identifies and handles temporary execution contexts such as npx, pnpm dlx,
*   and yarn dlx.
*/
/**
* Detects if the current process is running in a temporary package execution
* context such as npm exec, npx, pnpm dlx, or yarn dlx.
*
* When package managers run commands via exec/npx/dlx, they execute in
* temporary directories that are cleaned up after execution. Creating
* persistent shadows or modifying PATH in these contexts can break subsequent
* package manager commands.
*
* @example
*   ;```typescript
*   if (isTransientProcess()) {
*     console.log('Running in a temporary executor context')
*   }
*   ```
*/
function isTransientProcess(cwd = node_process.default.cwd()) {
	const userAgent = node_process.default.env["npm_config_user_agent"];
	if (userAgent?.includes("exec") || userAgent?.includes("npx") || userAgent?.includes("dlx")) return true;
	const normalizedCwd = /* @__PURE__ */ require_paths_normalize.normalizePath(cwd);
	const npmCache = node_process.default.env["npm_config_cache"];
	if (npmCache && normalizedCwd.includes(/* @__PURE__ */ require_paths_normalize.normalizePath(npmCache))) return true;
	const tempPatterns = [
		"_npx",
		".pnpm-store",
		"dlx-",
		".yarn/$$"
	];
	/* c8 ignore start */
	if (require_constants_platform.WIN32) tempPatterns.push("AppData/Local/Temp/xfs-");
	/* c8 ignore stop */
	return tempPatterns.some((pattern) => normalizedCwd.includes(pattern));
}

//#endregion
exports.isTransientProcess = isTransientProcess;