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

//#region src/paths/walk.ts
/**
* @file Walk parent directories. `walkUp` is the lazy ancestor generator that
*   `fs/find-up` and package-root lookups build on: given a starting path it
*   yields that path, then each parent, up to and INCLUDING the filesystem root
*   (or a caller-supplied `stopAt` boundary). Lazy so a caller can stop early
*   without computing the whole chain.
*/
/**
* Lazily yield `from` and each of its ancestor directories, up to and including
* the filesystem root (or `stopAt`). Each yielded path is normalized to forward
* slashes.
*
* @example
*   ;```ts
*   for (const dir of walkUp('/a/b/c')) {
*     // '/a/b/c', '/a/b', '/a', '/'
*   }
*
*   // Stop at a boundary (inclusive):
*   [...walkUp('/a/b/c', { stopAt: '/a' })] // ['/a/b/c', '/a/b', '/a']
*   ```
*
* @param from - Path to start from. Relative values resolve against `cwd`.
* @param options - `cwd` and `stopAt` boundary.
*
* @returns Generator of normalized absolute directory paths.
*/
function* walkUp(from, options) {
	const { cwd = node_process.default.cwd(), stopAt } = {
		__proto__: null,
		...options
	};
	const path = /* @__PURE__ */ require_node_path.getNodePath();
	const dirname = (/* @__PURE__ */ require_smol_path.getSmolPath())?.dirname ?? path.dirname;
	let dir = path.resolve(cwd, from);
	const stopDir = stopAt ? path.resolve(cwd, stopAt) : void 0;
	let prev;
	while (dir !== prev) {
		yield /* @__PURE__ */ require_paths_normalize.normalizePath(dir);
		if (stopDir !== void 0 && dir === stopDir) return;
		prev = dir;
		dir = dirname(dir);
	}
}

//#endregion
exports.walkUp = walkUp;