import {
  execa,
  outputContent,
  outputDebug
} from "./chunk-IW7KNM7Q.js";
import {
  init_cjs_shims
} from "./chunk-POZ5MGPT.js";

// ../cli-kit/dist/public/node/os.js
init_cjs_shims();
import { userInfo as osUserInfo } from "os";
async function username(platform = process.platform) {
  outputDebug(outputContent`Obtaining user name...`);
  let environmentVariable = getEnvironmentVariable();
  if (environmentVariable)
    return environmentVariable;
  let userInfoUsername = getUsernameFromOsUserInfo();
  if (userInfoUsername)
    return userInfoUsername;
  try {
    if (platform === "win32") {
      let { stdout } = await execa("whoami");
      return cleanWindowsCommand(stdout);
    }
    let { stdout: userId } = await execa("id", ["-u"]);
    try {
      let { stdout } = await execa("id", ["-un", userId]);
      return stdout;
    } catch {
    }
    return makeUsernameFromId(userId);
  } catch {
    return null;
  }
}
function platformAndArch(platform = process.platform, arch = process.arch) {
  let archString;
  return arch === "x64" ? archString = "amd64" : arch === "ia32" ? archString = "386" : archString = arch, { platform: platform.match(/^win.+/) ? "windows" : platform, arch: archString };
}
function getEnvironmentVariable() {
  let { env } = process;
  return env.SUDO_USER || env.C9_USER || env.LOGNAME || env.USER || env.LNAME || env.USERNAME;
}
function getUsernameFromOsUserInfo() {
  try {
    return osUserInfo().username;
  } catch {
    return null;
  }
}
function cleanWindowsCommand(value) {
  return value.replace(/^.*\\/, "");
}
function makeUsernameFromId(userId) {
  return `no-username-${userId}`;
}

export {
  username,
  platformAndArch
};
//# sourceMappingURL=chunk-O7YFJ6MY.js.map
