"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var file_exports = {};
__export(file_exports, {
  FilesystemSync: () => FilesystemSync,
  isDirectory: () => isDirectory,
  isFile: () => isFile,
  maybeReadJsonSync: () => maybeReadJsonSync,
  maybeReaddirSync: () => maybeReaddirSync,
  maybeStatSync: () => maybeStatSync
});
module.exports = __toCommonJS(file_exports);
var import_node_fs = require("node:fs");
var import_node_path = require("node:path");
var import_errors = require("./errors.js");
/**
 * @license
 * Copyright 2022-2026 Greg Lauckhart <greg@lauckhart.com>
 * SPDX-License-Identifier: Apache-2.0
 */
function isNotFoundError(e) {
  return typeof e === "object" && e !== null && "code" in e && (e.code === "ENOENT" || e.code === "ENOTDIR");
}
function maybeStatSync(path) {
  try {
    return (0, import_node_fs.statSync)(path);
  } catch (e) {
    if (isNotFoundError(e)) {
      return;
    }
    throw e;
  }
}
function maybeReadJsonSync(path) {
  try {
    return JSON.parse((0, import_node_fs.readFileSync)(path, "utf-8"));
  } catch (e) {
    if (isNotFoundError(e)) {
      return;
    }
    if (e instanceof SyntaxError) {
      e.message = `Error parsing ${path}: ${e.message}`;
      throw e;
    }
    throw e;
  }
}
function maybeReaddirSync(path) {
  try {
    return (0, import_node_fs.readdirSync)(path);
  } catch (e) {
    if (isNotFoundError(e)) {
      return;
    }
  }
}
function isDirectory(path) {
  return !!(0, import_errors.ignoreErrorSync)("ENOENT", () => (0, import_node_fs.statSync)(path).isDirectory());
}
function isFile(path) {
  return !!(0, import_errors.ignoreErrorSync)("ENOENT", () => (0, import_node_fs.statSync)(path).isFile());
}
function FilesystemSync() {
  return {
    resolve(...segments) {
      return (0, import_node_path.resolve)(...segments);
    },
    readdir(path) {
      return maybeReaddirSync(path);
    },
    stat(path) {
      const stats = maybeStatSync(path);
      if (stats) {
        return {
          get isFile() {
            return stats.isFile();
          },
          get isDirectory() {
            return stats.isDirectory();
          }
        };
      }
    }
  };
}
//# sourceMappingURL=file.js.map
