import { __esmMin } from "../../_virtual/_rolldown/runtime.js";
import { parse, resolve } from "node:path";
import { homedir } from "node:os";
//#region src/config/workspace-path.ts
/** Expand leading `~` to the user home directory. */
function expandWorkspacePathString(raw) {
	const s = raw.trim();
	if (s.startsWith("~")) return s.replace(/^~(?=$|[/\\])/, homedir());
	return s;
}
/**
* Normalize and validate a workspace directory path.
* Returns `null` when the input is empty or resolves to a filesystem root
* (e.g. `/` or `C:\`) — both are almost certainly misconfiguration.
*/
function normalizeWorkspaceDir(workspaceDir) {
	const trimmed = workspaceDir?.trim();
	if (!trimmed) return null;
	const resolved = resolve(trimmed.startsWith("~") ? expandWorkspacePathString(trimmed) : trimmed);
	if (resolved === parse(resolved).root) return null;
	return resolved;
}
/**
* Resolve a workspace root, falling back to `process.cwd()` when the
* provided path is empty or invalid.
*/
function resolveWorkspaceRoot(workspaceDir) {
	return normalizeWorkspaceDir(workspaceDir) ?? process.cwd();
}
var init_workspace_path = __esmMin((() => {}));
//#endregion
init_workspace_path();
export { expandWorkspacePathString, init_workspace_path, normalizeWorkspaceDir, resolveWorkspaceRoot };

//# sourceMappingURL=workspace-path.js.map