"use strict";
/**
 * Bundled from @npmcli/package-json/lib/read-package.js
 * This is a zero-dependency bundle created by esbuild.
 */
var __defProp = Object.defineProperty;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
var __commonJS = (cb, mod) => function __require() {
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
};

// node_modules/.pnpm/json-parse-even-better-errors@4.0.0/node_modules/json-parse-even-better-errors/lib/index.js
var require_lib = __commonJS({
  "node_modules/.pnpm/json-parse-even-better-errors@4.0.0/node_modules/json-parse-even-better-errors/lib/index.js"(exports2, module2) {
    "use strict";
    var INDENT = Symbol.for("indent");
    var NEWLINE = Symbol.for("newline");
    var DEFAULT_NEWLINE = "\n";
    var DEFAULT_INDENT = "  ";
    var BOM = /^\uFEFF/;
    var FORMAT = /^\s*[{[]((?:\r?\n)+)([\s\t]*)/;
    var EMPTY = /^(?:\{\}|\[\])((?:\r?\n)+)?$/;
    var UNEXPECTED_TOKEN = /^Unexpected token '?(.)'?(,)? /i;
    var hexify = /* @__PURE__ */ __name((char) => {
      const h = char.charCodeAt(0).toString(16).toUpperCase();
      return `0x${h.length % 2 ? "0" : ""}${h}`;
    }, "hexify");
    var stripBOM = /* @__PURE__ */ __name((txt) => String(txt).replace(BOM, ""), "stripBOM");
    var makeParsedError = /* @__PURE__ */ __name((msg, parsing, position = 0) => ({
      message: `${msg} while parsing ${parsing}`,
      position
    }), "makeParsedError");
    var parseError = /* @__PURE__ */ __name((e, txt, context = 20) => {
      let msg = e.message;
      if (!txt) {
        return makeParsedError(msg, "empty string");
      }
      const badTokenMatch = msg.match(UNEXPECTED_TOKEN);
      const badIndexMatch = msg.match(/ position\s+(\d+)/i);
      if (badTokenMatch) {
        msg = msg.replace(
          UNEXPECTED_TOKEN,
          `Unexpected token ${JSON.stringify(badTokenMatch[1])} (${hexify(badTokenMatch[1])})$2 `
        );
      }
      let errIdx;
      if (badIndexMatch) {
        errIdx = +badIndexMatch[1];
      } else if (msg.match(/^Unexpected end of JSON.*/i)) {
        errIdx = txt.length - 1;
      }
      if (errIdx == null) {
        return makeParsedError(msg, `'${txt.slice(0, context * 2)}'`);
      }
      const start = errIdx <= context ? 0 : errIdx - context;
      const end = errIdx + context >= txt.length ? txt.length : errIdx + context;
      const slice = `${start ? "..." : ""}${txt.slice(start, end)}${end === txt.length ? "" : "..."}`;
      return makeParsedError(
        msg,
        `${txt === slice ? "" : "near "}${JSON.stringify(slice)}`,
        errIdx
      );
    }, "parseError");
    var JSONParseError = class extends SyntaxError {
      static {
        __name(this, "JSONParseError");
      }
      constructor(er, txt, context, caller) {
        const metadata = parseError(er, txt, context);
        super(metadata.message);
        Object.assign(this, metadata);
        this.code = "EJSONPARSE";
        this.systemError = er;
        Error.captureStackTrace(this, caller || this.constructor);
      }
      get name() {
        return this.constructor.name;
      }
      set name(n) {
      }
      get [Symbol.toStringTag]() {
        return this.constructor.name;
      }
    };
    var parseJson = /* @__PURE__ */ __name((txt, reviver) => {
      const result = JSON.parse(txt, reviver);
      if (result && typeof result === "object") {
        const match = txt.match(EMPTY) || txt.match(FORMAT) || [null, "", ""];
        result[NEWLINE] = match[1] ?? DEFAULT_NEWLINE;
        result[INDENT] = match[2] ?? DEFAULT_INDENT;
      }
      return result;
    }, "parseJson");
    var parseJsonError = /* @__PURE__ */ __name((raw, reviver, context) => {
      const txt = stripBOM(raw);
      try {
        return parseJson(txt, reviver);
      } catch (e) {
        if (typeof raw !== "string" && !Buffer.isBuffer(raw)) {
          const msg = Array.isArray(raw) && raw.length === 0 ? "an empty array" : String(raw);
          throw Object.assign(
            new TypeError(`Cannot parse ${msg}`),
            { code: "EJSONPARSE", systemError: e }
          );
        }
        throw new JSONParseError(e, txt, context, parseJsonError);
      }
    }, "parseJsonError");
    module2.exports = parseJsonError;
    parseJsonError.JSONParseError = JSONParseError;
    parseJsonError.noExceptions = (raw, reviver) => {
      try {
        return parseJson(stripBOM(raw), reviver);
      } catch {
      }
    };
  }
});

// node_modules/.pnpm/@npmcli+package-json@7.0.0/node_modules/@npmcli/package-json/lib/read-package.js
var { readFile } = require("fs/promises");
var parseJSON = require_lib();
async function read(filename) {
  try {
    const data = await readFile(filename, "utf8");
    return data;
  } catch (err) {
    err.message = `Could not read package.json: ${err}`;
    throw err;
  }
}
__name(read, "read");
function parse(data) {
  try {
    const content = parseJSON(data);
    return content;
  } catch (err) {
    err.message = `Invalid package.json: ${err}`;
    throw err;
  }
}
__name(parse, "parse");
async function readPackage(filename) {
  const data = await read(filename);
  const content = parse(data);
  return content;
}
__name(readPackage, "readPackage");
module.exports = {
  read,
  parse,
  readPackage
};
