import { createRequire as _createRequire } from 'node:module';
const require = _createRequire(import.meta.url);
import {
  init_esm_shims
} from "./chunk-4EFJZ3GQ.js";

// ../../node_modules/tsconfck/src/index.js
init_esm_shims();

// ../../node_modules/tsconfck/src/find.js
init_esm_shims();
import path2 from "node:path";
import fs2 from "node:fs";

// ../../node_modules/tsconfck/src/util.js
init_esm_shims();
import path from "node:path";
import { promises as fs } from "node:fs";
var POSIX_SEP_RE = new RegExp("\\" + path.posix.sep, "g");
var NATIVE_SEP_RE = new RegExp("\\" + path.sep, "g");
var PATTERN_REGEX_CACHE = /* @__PURE__ */ new Map();
var GLOB_ALL_PATTERN = `**/*`;
var TS_EXTENSIONS = [".ts", ".tsx", ".mts", ".cts"];
var JS_EXTENSIONS = [".js", ".jsx", ".mjs", ".cjs"];
var TSJS_EXTENSIONS = TS_EXTENSIONS.concat(JS_EXTENSIONS);
var TS_EXTENSIONS_RE_GROUP = `\\.(?:${TS_EXTENSIONS.map((ext) => ext.substring(1)).join("|")})`;
var TSJS_EXTENSIONS_RE_GROUP = `\\.(?:${TSJS_EXTENSIONS.map((ext) => ext.substring(1)).join(
  "|"
)})`;
var IS_POSIX = path.posix.sep === path.sep;
function makePromise() {
  let resolve, reject;
  const promise = new Promise((res, rej) => {
    resolve = res;
    reject = rej;
  });
  return { promise, resolve, reject };
}
async function loadTS() {
  try {
    return import("typescript").then((m) => m.default);
  } catch (e) {
    console.error('typescript must be installed to use "native" functions');
    throw e;
  }
}
async function resolveTSConfigJson(filename, cache) {
  if (path.extname(filename) !== ".json") {
    return;
  }
  const tsconfig = path.resolve(filename);
  if (cache && (cache.hasParseResult(tsconfig) || cache.hasParseResult(filename))) {
    return tsconfig;
  }
  return fs.stat(tsconfig).then((stat) => {
    if (stat.isFile() || stat.isFIFO()) {
      return tsconfig;
    } else {
      throw new Error(`${filename} exists but is not a regular file.`);
    }
  });
}
var isInNodeModules = IS_POSIX ? (dir) => dir.includes("/node_modules/") : (dir) => dir.match(/[/\\]node_modules[/\\]/);
var posix2native = IS_POSIX ? (filename) => filename : (filename) => filename.replace(POSIX_SEP_RE, path.sep);
var native2posix = IS_POSIX ? (filename) => filename : (filename) => filename.replace(NATIVE_SEP_RE, path.posix.sep);
var resolve2posix = IS_POSIX ? (dir, filename) => dir ? path.resolve(dir, filename) : path.resolve(filename) : (dir, filename) => native2posix(
  dir ? path.resolve(posix2native(dir), posix2native(filename)) : path.resolve(posix2native(filename))
);
function resolveReferencedTSConfigFiles(result, options) {
  const dir = path.dirname(result.tsconfigFile);
  return result.tsconfig.references.map((ref) => {
    const refPath = ref.path.endsWith(".json") ? ref.path : path.join(ref.path, options?.configName ?? "tsconfig.json");
    return resolve2posix(dir, refPath);
  });
}
function resolveSolutionTSConfig(filename, result) {
  const allowJs = result.tsconfig.compilerOptions?.allowJs;
  const extensions = allowJs ? TSJS_EXTENSIONS : TS_EXTENSIONS;
  if (result.referenced && extensions.some((ext) => filename.endsWith(ext)) && !isIncluded(filename, result)) {
    const solutionTSConfig = result.referenced.find(
      (referenced) => isIncluded(filename, referenced)
    );
    if (solutionTSConfig) {
      return solutionTSConfig;
    }
  }
  return result;
}
function isIncluded(filename, result) {
  const dir = native2posix(path.dirname(result.tsconfigFile));
  const files = (result.tsconfig.files || []).map((file) => resolve2posix(dir, file));
  const absoluteFilename = resolve2posix(null, filename);
  if (files.includes(filename)) {
    return true;
  }
  const allowJs = result.tsconfig.compilerOptions?.allowJs;
  const isIncluded2 = isGlobMatch(
    absoluteFilename,
    dir,
    result.tsconfig.include || (result.tsconfig.files ? [] : [GLOB_ALL_PATTERN]),
    allowJs
  );
  if (isIncluded2) {
    const isExcluded = isGlobMatch(absoluteFilename, dir, result.tsconfig.exclude || [], allowJs);
    return !isExcluded;
  }
  return false;
}
function isGlobMatch(filename, dir, patterns, allowJs) {
  const extensions = allowJs ? TSJS_EXTENSIONS : TS_EXTENSIONS;
  return patterns.some((pattern) => {
    let lastWildcardIndex = pattern.length;
    let hasWildcard = false;
    let hasExtension = false;
    let hasSlash = false;
    let lastSlashIndex = -1;
    for (let i = pattern.length - 1; i > -1; i--) {
      const c = pattern[i];
      if (!hasWildcard) {
        if (c === "*" || c === "?") {
          lastWildcardIndex = i;
          hasWildcard = true;
        }
      }
      if (!hasSlash) {
        if (c === ".") {
          hasExtension = true;
        } else if (c === "/") {
          lastSlashIndex = i;
          hasSlash = true;
        }
      }
      if (hasWildcard && hasSlash) {
        break;
      }
    }
    if (!hasExtension && (!hasWildcard || lastWildcardIndex < lastSlashIndex)) {
      pattern += `${pattern.endsWith("/") ? "" : "/"}${GLOB_ALL_PATTERN}`;
      lastWildcardIndex = pattern.length - 1;
      hasWildcard = true;
    }
    if (lastWildcardIndex < pattern.length - 1 && !filename.endsWith(pattern.slice(lastWildcardIndex + 1))) {
      return false;
    }
    if (pattern.endsWith("*") && !extensions.some((ext) => filename.endsWith(ext))) {
      return false;
    }
    if (pattern === GLOB_ALL_PATTERN) {
      return filename.startsWith(`${dir}/`);
    }
    const resolvedPattern = resolve2posix(dir, pattern);
    let firstWildcardIndex = -1;
    for (let i = 0; i < resolvedPattern.length; i++) {
      if (resolvedPattern[i] === "*" || resolvedPattern[i] === "?") {
        firstWildcardIndex = i;
        hasWildcard = true;
        break;
      }
    }
    if (firstWildcardIndex > 1 && !filename.startsWith(resolvedPattern.slice(0, firstWildcardIndex - 1))) {
      return false;
    }
    if (!hasWildcard) {
      return filename === resolvedPattern;
    } else if (firstWildcardIndex + GLOB_ALL_PATTERN.length === resolvedPattern.length - (pattern.length - 1 - lastWildcardIndex) && resolvedPattern.slice(firstWildcardIndex, firstWildcardIndex + GLOB_ALL_PATTERN.length) === GLOB_ALL_PATTERN) {
      return true;
    }
    if (PATTERN_REGEX_CACHE.has(resolvedPattern)) {
      return PATTERN_REGEX_CACHE.get(resolvedPattern).test(filename);
    }
    const regex = pattern2regex(resolvedPattern, allowJs);
    PATTERN_REGEX_CACHE.set(resolvedPattern, regex);
    return regex.test(filename);
  });
}
function pattern2regex(resolvedPattern, allowJs) {
  let regexStr = "^";
  for (let i = 0; i < resolvedPattern.length; i++) {
    const char = resolvedPattern[i];
    if (char === "?") {
      regexStr += "[^\\/]";
      continue;
    }
    if (char === "*") {
      if (resolvedPattern[i + 1] === "*" && resolvedPattern[i + 2] === "/") {
        i += 2;
        regexStr += "(?:[^\\/]*\\/)*";
        continue;
      }
      regexStr += "[^\\/]*";
      continue;
    }
    if ("/.+^${}()|[]\\".includes(char)) {
      regexStr += `\\`;
    }
    regexStr += char;
  }
  if (resolvedPattern.endsWith("*")) {
    regexStr += allowJs ? TSJS_EXTENSIONS_RE_GROUP : TS_EXTENSIONS_RE_GROUP;
  }
  regexStr += "$";
  return new RegExp(regexStr);
}
function replaceTokens(result) {
  if (result.tsconfig) {
    result.tsconfig = JSON.parse(
      JSON.stringify(result.tsconfig).replaceAll(/"\${configDir}/g, `"${native2posix(path.dirname(result.tsconfigFile))}`)
    );
  }
}

// ../../node_modules/tsconfck/src/find.js
async function find(filename, options) {
  let dir = path2.dirname(path2.resolve(filename));
  if (options?.ignoreNodeModules && isInNodeModules(dir)) {
    return null;
  }
  const cache = options?.cache;
  const configName = options?.configName ?? "tsconfig.json";
  if (cache?.hasConfigPath(dir, configName)) {
    return cache.getConfigPath(dir, configName);
  }
  const {
    /** @type {Promise<string|null>} */
    promise,
    resolve,
    reject
  } = makePromise();
  if (options?.root && !path2.isAbsolute(options.root)) {
    options.root = path2.resolve(options.root);
  }
  findUp(dir, { promise, resolve, reject }, options);
  return promise;
}
function findUp(dir, { resolve, reject, promise }, options) {
  const { cache, root, configName } = options ?? {};
  if (cache) {
    if (cache.hasConfigPath(dir, configName)) {
      let cached;
      try {
        cached = cache.getConfigPath(dir, configName);
      } catch (e) {
        reject(e);
        return;
      }
      if (cached?.then) {
        cached.then(resolve).catch(reject);
      } else {
        resolve(cached);
      }
    } else {
      cache.setConfigPath(dir, promise, configName);
    }
  }
  const tsconfig = path2.join(dir, options?.configName ?? "tsconfig.json");
  fs2.stat(tsconfig, (err, stats) => {
    if (stats && (stats.isFile() || stats.isFIFO())) {
      resolve(tsconfig);
    } else if (err?.code !== "ENOENT") {
      reject(err);
    } else {
      let parent;
      if (root === dir || (parent = path2.dirname(dir)) === dir) {
        resolve(null);
      } else {
        findUp(parent, { promise, resolve, reject }, options);
      }
    }
  });
}

// ../../node_modules/tsconfck/src/find-all.js
init_esm_shims();
import path3 from "node:path";
import { readdir } from "node:fs";
var sep = path3.sep;
async function findAll(dir, options) {
  const state = {
    files: [],
    calls: 0,
    skip: options?.skip,
    err: false,
    configNames: options?.configNames ?? ["tsconfig.json"]
  };
  return new Promise((resolve, reject) => {
    walk(path3.resolve(dir), state, (err, files) => err ? reject(err) : resolve(files));
  });
}
function walk(dir, state, done) {
  if (state.err) {
    return;
  }
  state.calls++;
  readdir(dir, { withFileTypes: true }, (err, entries = []) => {
    if (state.err) {
      return;
    }
    if (err && !(err.code === "ENOENT" || err.code === "EACCES" || err.code === "EPERM")) {
      state.err = true;
      done(err);
    } else {
      for (const ent of entries) {
        if (ent.isDirectory() && !state.skip?.(ent.name)) {
          walk(`${dir}${sep}${ent.name}`, state, done);
        } else if (ent.isFile() && state.configNames.includes(ent.name)) {
          state.files.push(`${dir}${sep}${ent.name}`);
        }
      }
      if (--state.calls === 0) {
        if (!state.err) {
          done(null, state.files);
        }
      }
    }
  });
}

// ../../node_modules/tsconfck/src/to-json.js
init_esm_shims();
function toJson(tsconfigJson) {
  const stripped = stripDanglingComma(stripJsonComments(stripBom(tsconfigJson)));
  if (stripped.trim() === "") {
    return "{}";
  } else {
    return stripped;
  }
}
function stripDanglingComma(pseudoJson) {
  let insideString = false;
  let offset = 0;
  let result = "";
  let danglingCommaPos = null;
  for (let i = 0; i < pseudoJson.length; i++) {
    const currentCharacter = pseudoJson[i];
    if (currentCharacter === '"') {
      const escaped = isEscaped(pseudoJson, i);
      if (!escaped) {
        insideString = !insideString;
      }
    }
    if (insideString) {
      danglingCommaPos = null;
      continue;
    }
    if (currentCharacter === ",") {
      danglingCommaPos = i;
      continue;
    }
    if (danglingCommaPos) {
      if (currentCharacter === "}" || currentCharacter === "]") {
        result += pseudoJson.slice(offset, danglingCommaPos) + " ";
        offset = danglingCommaPos + 1;
        danglingCommaPos = null;
      } else if (!currentCharacter.match(/\s/)) {
        danglingCommaPos = null;
      }
    }
  }
  return result + pseudoJson.substring(offset);
}
function isEscaped(jsonString, quotePosition) {
  let index = quotePosition - 1;
  let backslashCount = 0;
  while (jsonString[index] === "\\") {
    index -= 1;
    backslashCount += 1;
  }
  return Boolean(backslashCount % 2);
}
function strip(string, start, end) {
  return string.slice(start, end).replace(/\S/g, " ");
}
var singleComment = Symbol("singleComment");
var multiComment = Symbol("multiComment");
function stripJsonComments(jsonString) {
  let isInsideString = false;
  let isInsideComment = false;
  let offset = 0;
  let result = "";
  for (let index = 0; index < jsonString.length; index++) {
    const currentCharacter = jsonString[index];
    const nextCharacter = jsonString[index + 1];
    if (!isInsideComment && currentCharacter === '"') {
      const escaped = isEscaped(jsonString, index);
      if (!escaped) {
        isInsideString = !isInsideString;
      }
    }
    if (isInsideString) {
      continue;
    }
    if (!isInsideComment && currentCharacter + nextCharacter === "//") {
      result += jsonString.slice(offset, index);
      offset = index;
      isInsideComment = singleComment;
      index++;
    } else if (isInsideComment === singleComment && currentCharacter + nextCharacter === "\r\n") {
      index++;
      isInsideComment = false;
      result += strip(jsonString, offset, index);
      offset = index;
    } else if (isInsideComment === singleComment && currentCharacter === "\n") {
      isInsideComment = false;
      result += strip(jsonString, offset, index);
      offset = index;
    } else if (!isInsideComment && currentCharacter + nextCharacter === "/*") {
      result += jsonString.slice(offset, index);
      offset = index;
      isInsideComment = multiComment;
      index++;
    } else if (isInsideComment === multiComment && currentCharacter + nextCharacter === "*/") {
      index++;
      isInsideComment = false;
      result += strip(jsonString, offset, index + 1);
      offset = index + 1;
    }
  }
  return result + (isInsideComment ? strip(jsonString.slice(offset)) : jsonString.slice(offset));
}
function stripBom(string) {
  if (string.charCodeAt(0) === 65279) {
    return string.slice(1);
  }
  return string;
}

// ../../node_modules/tsconfck/src/parse.js
init_esm_shims();
import path4 from "node:path";
import { promises as fs3 } from "node:fs";
import { createRequire } from "module";
var not_found_result = {
  tsconfigFile: null,
  tsconfig: {}
};
async function parse(filename, options) {
  const cache = options?.cache;
  if (cache?.hasParseResult(filename)) {
    return getParsedDeep(filename, cache, options);
  }
  const {
    resolve,
    reject,
    /** @type {Promise<import('./public.d.ts').TSConfckParseResult>}*/
    promise
  } = makePromise();
  cache?.setParseResult(filename, promise, true);
  try {
    let tsconfigFile = await resolveTSConfigJson(filename, cache) || await find(filename, options);
    if (!tsconfigFile) {
      resolve(not_found_result);
      return promise;
    }
    let result;
    if (filename !== tsconfigFile && cache?.hasParseResult(tsconfigFile)) {
      result = await getParsedDeep(tsconfigFile, cache, options);
    } else {
      result = await parseFile(tsconfigFile, cache, filename === tsconfigFile);
      await Promise.all([parseExtends(result, cache), parseReferences(result, options)]);
    }
    replaceTokens(result);
    resolve(resolveSolutionTSConfig(filename, result));
  } catch (e) {
    reject(e);
  }
  return promise;
}
async function getParsedDeep(filename, cache, options) {
  const result = await cache.getParseResult(filename);
  if (result.tsconfig.extends && !result.extended || result.tsconfig.references && !result.referenced) {
    const promise = Promise.all([
      parseExtends(result, cache),
      parseReferences(result, options)
    ]).then(() => result);
    cache.setParseResult(filename, promise, true);
    return promise;
  }
  return result;
}
async function parseFile(tsconfigFile, cache, skipCache) {
  if (!skipCache && cache?.hasParseResult(tsconfigFile) && !cache.getParseResult(tsconfigFile)._isRootFile_) {
    return cache.getParseResult(tsconfigFile);
  }
  const promise = fs3.readFile(tsconfigFile, "utf-8").then(toJson).then((json) => {
    const parsed = JSON.parse(json);
    applyDefaults(parsed, tsconfigFile);
    return {
      tsconfigFile,
      tsconfig: normalizeTSConfig(parsed, path4.dirname(tsconfigFile))
    };
  }).catch((e) => {
    throw new TSConfckParseError(
      `parsing ${tsconfigFile} failed: ${e}`,
      "PARSE_FILE",
      tsconfigFile,
      e
    );
  });
  if (!skipCache && (!cache?.hasParseResult(tsconfigFile) || !cache.getParseResult(tsconfigFile)._isRootFile_)) {
    cache?.setParseResult(tsconfigFile, promise);
  }
  return promise;
}
function normalizeTSConfig(tsconfig, dir) {
  const baseUrl = tsconfig.compilerOptions?.baseUrl;
  if (baseUrl && !baseUrl.startsWith("${") && !path4.isAbsolute(baseUrl)) {
    tsconfig.compilerOptions.baseUrl = resolve2posix(dir, baseUrl);
  }
  return tsconfig;
}
async function parseReferences(result, options) {
  if (!result.tsconfig.references) {
    return;
  }
  const referencedFiles = resolveReferencedTSConfigFiles(result, options);
  const referenced = await Promise.all(
    referencedFiles.map((file) => parseFile(file, options?.cache))
  );
  await Promise.all(referenced.map((ref) => parseExtends(ref, options?.cache)));
  referenced.forEach((ref) => {
    ref.solution = result;
    replaceTokens(ref);
  });
  result.referenced = referenced;
}
async function parseExtends(result, cache) {
  if (!result.tsconfig.extends) {
    return;
  }
  const extended = [
    { tsconfigFile: result.tsconfigFile, tsconfig: JSON.parse(JSON.stringify(result.tsconfig)) }
  ];
  let pos = 0;
  const extendsPath = [];
  let currentBranchDepth = 0;
  while (pos < extended.length) {
    const extending = extended[pos];
    extendsPath.push(extending.tsconfigFile);
    if (extending.tsconfig.extends) {
      currentBranchDepth += 1;
      let resolvedExtends;
      if (!Array.isArray(extending.tsconfig.extends)) {
        resolvedExtends = [resolveExtends(extending.tsconfig.extends, extending.tsconfigFile)];
      } else {
        resolvedExtends = extending.tsconfig.extends.reverse().map((ex) => resolveExtends(ex, extending.tsconfigFile));
      }
      const circularExtends = resolvedExtends.find(
        (tsconfigFile) => extendsPath.includes(tsconfigFile)
      );
      if (circularExtends) {
        const circle = extendsPath.concat([circularExtends]).join(" -> ");
        throw new TSConfckParseError(
          `Circular dependency in "extends": ${circle}`,
          "EXTENDS_CIRCULAR",
          result.tsconfigFile
        );
      }
      extended.splice(
        pos + 1,
        0,
        ...await Promise.all(resolvedExtends.map((file) => parseFile(file, cache)))
      );
    } else {
      extendsPath.splice(-currentBranchDepth);
      currentBranchDepth = 0;
    }
    pos = pos + 1;
  }
  result.extended = extended;
  for (const ext of result.extended.slice(1)) {
    extendTSConfig(result, ext);
  }
}
function resolveExtends(extended, from) {
  if (extended === "..") {
    extended = "../tsconfig.json";
  }
  const req = createRequire(from);
  let error;
  try {
    return req.resolve(extended);
  } catch (e) {
    error = e;
  }
  if (extended[0] !== "." && !path4.isAbsolute(extended)) {
    try {
      return req.resolve(`${extended}/tsconfig.json`);
    } catch (e) {
      error = e;
    }
  }
  throw new TSConfckParseError(
    `failed to resolve "extends":"${extended}" in ${from}`,
    "EXTENDS_RESOLVE",
    from,
    error
  );
}
var EXTENDABLE_KEYS = [
  "compilerOptions",
  "files",
  "include",
  "exclude",
  "watchOptions",
  "compileOnSave",
  "typeAcquisition",
  "buildOptions"
];
function extendTSConfig(extending, extended) {
  const extendingConfig = extending.tsconfig;
  const extendedConfig = extended.tsconfig;
  const relativePath = native2posix(
    path4.relative(path4.dirname(extending.tsconfigFile), path4.dirname(extended.tsconfigFile))
  );
  for (const key of Object.keys(extendedConfig).filter((key2) => EXTENDABLE_KEYS.includes(key2))) {
    if (key === "compilerOptions") {
      if (!extendingConfig.compilerOptions) {
        extendingConfig.compilerOptions = {};
      }
      for (const option of Object.keys(extendedConfig.compilerOptions)) {
        if (Object.prototype.hasOwnProperty.call(extendingConfig.compilerOptions, option)) {
          continue;
        }
        extendingConfig.compilerOptions[option] = rebaseRelative(
          option,
          extendedConfig.compilerOptions[option],
          relativePath
        );
      }
    } else if (extendingConfig[key] === void 0) {
      if (key === "watchOptions") {
        extendingConfig.watchOptions = {};
        for (const option of Object.keys(extendedConfig.watchOptions)) {
          extendingConfig.watchOptions[option] = rebaseRelative(
            option,
            extendedConfig.watchOptions[option],
            relativePath
          );
        }
      } else {
        extendingConfig[key] = rebaseRelative(key, extendedConfig[key], relativePath);
      }
    }
  }
}
var REBASE_KEYS = [
  // root
  "files",
  "include",
  "exclude",
  // compilerOptions
  "baseUrl",
  "rootDir",
  "rootDirs",
  "typeRoots",
  "outDir",
  "outFile",
  "declarationDir",
  // watchOptions
  "excludeDirectories",
  "excludeFiles"
];
function rebaseRelative(key, value, prependPath) {
  if (!REBASE_KEYS.includes(key)) {
    return value;
  }
  if (Array.isArray(value)) {
    return value.map((x) => rebasePath(x, prependPath));
  } else {
    return rebasePath(value, prependPath);
  }
}
function rebasePath(value, prependPath) {
  if (path4.isAbsolute(value) || value.startsWith("${configDir}")) {
    return value;
  } else {
    return path4.posix.normalize(path4.posix.join(prependPath, value));
  }
}
var TSConfckParseError = class _TSConfckParseError extends Error {
  /**
   * error code
   * @type {string}
   */
  code;
  /**
   * error cause
   * @type { Error | undefined}
   */
  cause;
  /**
   * absolute path of tsconfig file where the error happened
   * @type {string}
   */
  tsconfigFile;
  /**
   *
   * @param {string} message - error message
   * @param {string} code - error code
   * @param {string} tsconfigFile - path to tsconfig file
   * @param {Error?} cause - cause of this error
   */
  constructor(message, code, tsconfigFile, cause) {
    super(message);
    Object.setPrototypeOf(this, _TSConfckParseError.prototype);
    this.name = _TSConfckParseError.name;
    this.code = code;
    this.cause = cause;
    this.tsconfigFile = tsconfigFile;
  }
};
function applyDefaults(tsconfig, tsconfigFile) {
  if (isJSConfig(tsconfigFile)) {
    tsconfig.compilerOptions = {
      ...DEFAULT_JSCONFIG_COMPILER_OPTIONS,
      ...tsconfig.compilerOptions
    };
  }
}
var DEFAULT_JSCONFIG_COMPILER_OPTIONS = {
  allowJs: true,
  maxNodeModuleJsDepth: 2,
  allowSyntheticDefaultImports: true,
  skipLibCheck: true,
  noEmit: true
};
function isJSConfig(configFileName) {
  return path4.basename(configFileName) === "jsconfig.json";
}

// ../../node_modules/tsconfck/src/find-native.js
init_esm_shims();
import path5 from "node:path";
async function findNative(filename, options) {
  let dir = native2posix(path5.dirname(path5.resolve(filename)));
  if (options?.ignoreNodeModules && isInNodeModules(dir)) {
    return null;
  }
  const cache = options?.cache;
  const root = options?.root ? native2posix(path5.resolve(options.root)) : void 0;
  const configName = options?.configName ?? "tsconfig.json";
  if (cache?.hasConfigPath(dir, configName)) {
    return cache.getConfigPath(dir, configName);
  }
  const ts = await loadTS();
  const { findConfigFile, sys } = ts;
  let tsconfigFile = findConfigFile(dir, sys.fileExists, configName);
  if (!tsconfigFile || is_out_of_root(tsconfigFile, root)) {
    tsconfigFile = null;
  }
  if (cache) {
    cache_result(tsconfigFile, dir, cache, root, configName);
  }
  return tsconfigFile;
}
function is_out_of_root(tsconfigFile, root) {
  return root && !tsconfigFile.startsWith(root);
}
function cache_result(tsconfigFile, fileDir, cache, root, configName) {
  const tsconfigDir = tsconfigFile ? path5.dirname(tsconfigFile) : root;
  const directories = [];
  let dir = fileDir;
  while (dir) {
    directories.push(dir);
    const parent = path5.dirname(dir);
    if (tsconfigDir === dir || parent === dir) {
      break;
    } else {
      dir = parent;
    }
  }
  directories.forEach((d) => {
    cache.setConfigPath(d, Promise.resolve(tsconfigFile), configName);
  });
}

// ../../node_modules/tsconfck/src/parse-native.js
init_esm_shims();
import path6 from "node:path";
var notFoundResult = {
  tsconfigFile: null,
  tsconfig: {},
  result: null
};
async function parseNative(filename, options) {
  const cache = options?.cache;
  if (cache?.hasParseResult(filename)) {
    return cache.getParseResult(filename);
  }
  const {
    resolve,
    reject,
    /** @type {Promise<import('./public.d.ts').TSConfckParseNativeResult>}*/
    promise
  } = makePromise();
  cache?.setParseResult(filename, promise);
  try {
    const tsconfigFile = await resolveTSConfigJson(filename, cache) || await findNative(filename, options);
    if (!tsconfigFile) {
      resolve(notFoundResult);
      return promise;
    }
    let result;
    if (filename !== tsconfigFile && cache?.hasParseResult(tsconfigFile)) {
      result = await cache.getParseResult(tsconfigFile);
    } else {
      const ts = await loadTS();
      result = await parseFile2(tsconfigFile, ts, options, filename === tsconfigFile);
      await parseReferences2(result, ts, options);
      cache?.setParseResult(tsconfigFile, Promise.resolve(result));
    }
    resolve(resolveSolutionTSConfig(filename, result));
    return promise;
  } catch (e) {
    reject(e);
    return promise;
  }
}
function parseFile2(tsconfigFile, ts, options, skipCache) {
  const cache = options?.cache;
  if (!skipCache && cache?.hasParseResult(tsconfigFile)) {
    return cache.getParseResult(tsconfigFile);
  }
  const posixTSConfigFile = native2posix(tsconfigFile);
  const { parseJsonConfigFileContent, readConfigFile, sys } = ts;
  const { config, error } = readConfigFile(posixTSConfigFile, sys.readFile);
  if (error) {
    throw new TSConfckParseNativeError(error, tsconfigFile, null);
  }
  const host = {
    useCaseSensitiveFileNames: false,
    readDirectory: sys.readDirectory,
    fileExists: sys.fileExists,
    readFile: sys.readFile
  };
  if (options?.ignoreSourceFiles) {
    config.files = [];
    config.include = [];
  }
  const nativeResult = parseJsonConfigFileContent(
    config,
    host,
    path6.dirname(posixTSConfigFile),
    void 0,
    posixTSConfigFile
  );
  checkErrors(nativeResult, tsconfigFile);
  const result = {
    tsconfigFile,
    tsconfig: result2tsconfig(nativeResult, ts, tsconfigFile),
    result: nativeResult
  };
  if (!skipCache) {
    cache?.setParseResult(tsconfigFile, Promise.resolve(result));
  }
  return result;
}
async function parseReferences2(result, ts, options) {
  if (!result.tsconfig.references) {
    return;
  }
  const referencedFiles = resolveReferencedTSConfigFiles(result, options);
  result.referenced = await Promise.all(
    referencedFiles.map((file) => parseFile2(file, ts, options))
  );
  result.referenced.forEach((ref) => ref.solution = result);
}
function checkErrors(nativeResult, tsconfigFile) {
  const ignoredErrorCodes = [
    // see https://github.com/microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json
    18002,
    // empty files list
    18003
    // no inputs
  ];
  const criticalError = nativeResult.errors?.find(
    (error) => error.category === 1 && !ignoredErrorCodes.includes(error.code)
  );
  if (criticalError) {
    throw new TSConfckParseNativeError(criticalError, tsconfigFile, nativeResult);
  }
}
function result2tsconfig(result, ts, tsconfigFile) {
  const tsconfig = JSON.parse(JSON.stringify(result.raw));
  const ignoredOptions = ["configFilePath", "pathsBasePath"];
  if (result.options && Object.keys(result.options).some((o) => !ignoredOptions.includes(o))) {
    tsconfig.compilerOptions = {
      ...result.options
    };
    for (const ignored of ignoredOptions) {
      delete tsconfig.compilerOptions[ignored];
    }
  }
  const compilerOptions = tsconfig.compilerOptions;
  if (compilerOptions) {
    if (compilerOptions.lib != null) {
      compilerOptions.lib = compilerOptions.lib.map(
        (x) => x.replace(/^lib\./, "").replace(/\.d\.ts$/, "")
      );
    }
    const enumProperties = [
      { name: "importsNotUsedAsValues", enumeration: ts.ImportsNotUsedAsValues },
      { name: "module", enumeration: ts.ModuleKind },
      {
        name: "moduleResolution",
        enumeration: {
          ...ts.ModuleResolutionKind,
          2: "node"
          /*ts.ModuleResolutionKind uses "Node10" but in tsconfig it is just node"*/
        }
      },
      {
        name: "newLine",
        enumeration: { 0: "crlf", 1: "lf" }
        /*ts.NewLineKind uses different names*/
      },
      { name: "target", enumeration: ts.ScriptTarget }
    ];
    for (const prop of enumProperties) {
      if (compilerOptions[prop.name] != null && typeof compilerOptions[prop.name] === "number") {
        compilerOptions[prop.name] = prop.enumeration[compilerOptions[prop.name]].toLowerCase();
      }
    }
    if (compilerOptions.target === "latest") {
      compilerOptions.target = "esnext";
    }
  }
  if (result.watchOptions) {
    tsconfig.watchOptions = {
      ...result.watchOptions
    };
  }
  const watchOptions = tsconfig.watchOptions;
  if (watchOptions) {
    const enumProperties = [
      { name: "watchFile", enumeration: ts.WatchFileKind },
      { name: "watchDirectory", enumeration: ts.WatchDirectoryKind },
      { name: "fallbackPolling", enumeration: ts.PollingWatchKind }
    ];
    for (const prop of enumProperties) {
      if (watchOptions[prop.name] != null && typeof watchOptions[prop.name] === "number") {
        const enumVal = prop.enumeration[watchOptions[prop.name]];
        watchOptions[prop.name] = enumVal.charAt(0).toLowerCase() + enumVal.slice(1);
      }
    }
  }
  if (tsconfig.compileOnSave === false) {
    delete tsconfig.compileOnSave;
  }
  const parseResult = { tsconfig, tsconfigFile };
  replaceTokens(parseResult);
  return parseResult.tsconfig;
}
var TSConfckParseNativeError = class _TSConfckParseNativeError extends Error {
  /**
   *
   * @param {TSDiagnosticError} diagnostic - diagnostics of ts
   * @param {string} tsconfigFile - file that errored
   * @param {any?} result  - parsed result, if any
   */
  constructor(diagnostic, tsconfigFile, result) {
    super(diagnostic.messageText);
    Object.setPrototypeOf(this, _TSConfckParseNativeError.prototype);
    this.name = _TSConfckParseNativeError.name;
    this.code = `TS ${diagnostic.code}`;
    this.diagnostic = diagnostic;
    this.result = result;
    this.tsconfigFile = tsconfigFile;
  }
  /**
   * code of typescript diagnostic, prefixed with "TS "
   * @type {string}
   */
  code;
  /**
   * full ts diagnostic that caused this error
   * @type {TSDiagnosticError}
   */
  diagnostic;
  /**
   * absolute path of tsconfig file where the error happened
   * @type {string}
   */
  tsconfigFile;
  /**
   * native result if present, contains all errors in result.errors
   * @type {any|undefined}
   */
  result;
};

// ../../node_modules/tsconfck/src/cache.js
init_esm_shims();
var TSConfckCache = class {
  /**
   * clear cache, use this if you have a long running process and tsconfig files have been added,changed or deleted
   */
  clear() {
    this.#configPaths.clear();
    this.#parsed.clear();
  }
  /**
   * has cached closest config for files in dir
   * @param {string} dir
   * @param {string} [configName=tsconfig.json]
   * @returns {boolean}
   */
  hasConfigPath(dir, configName = "tsconfig.json") {
    return this.#configPaths.has(`${dir}/${configName}`);
  }
  /**
   * get cached closest tsconfig for files in dir
   * @param {string} dir
   * @param {string} [configName=tsconfig.json]
   * @returns {Promise<string|null>|string|null}
   * @throws {unknown} if cached value is an error
   */
  getConfigPath(dir, configName = "tsconfig.json") {
    const key = `${dir}/${configName}`;
    const value = this.#configPaths.get(key);
    if (value == null || value.length || value.then) {
      return value;
    } else {
      throw value;
    }
  }
  /**
   * has parsed tsconfig for file
   * @param {string} file
   * @returns {boolean}
   */
  hasParseResult(file) {
    return this.#parsed.has(file);
  }
  /**
   * get parsed tsconfig for file
   * @param {string} file
   * @returns {Promise<T>|T}
   * @throws {unknown} if cached value is an error
   */
  getParseResult(file) {
    const value = this.#parsed.get(file);
    if (value.then || value.tsconfig) {
      return value;
    } else {
      throw value;
    }
  }
  /**
   * @internal
   * @private
   * @param file
   * @param {boolean} isRootFile a flag to check if current file which involking the parse() api, used to distinguish the normal cache which only parsed by parseFile()
   * @param {Promise<T>} result
   */
  setParseResult(file, result, isRootFile = false) {
    Object.defineProperty(result, "_isRootFile_", {
      value: isRootFile,
      writable: false,
      enumerable: false,
      configurable: false
    });
    this.#parsed.set(file, result);
    result.then((parsed) => {
      if (this.#parsed.get(file) === result) {
        this.#parsed.set(file, parsed);
      }
    }).catch((e) => {
      if (this.#parsed.get(file) === result) {
        this.#parsed.set(file, e);
      }
    });
  }
  /**
   * @internal
   * @private
   * @param {string} dir
   * @param {Promise<string|null>} configPath
   * @param {string} [configName=tsconfig.json]
   */
  setConfigPath(dir, configPath, configName = "tsconfig.json") {
    const key = `${dir}/${configName}`;
    this.#configPaths.set(key, configPath);
    configPath.then((path7) => {
      if (this.#configPaths.get(key) === configPath) {
        this.#configPaths.set(key, path7);
      }
    }).catch((e) => {
      if (this.#configPaths.get(key) === configPath) {
        this.#configPaths.set(key, e);
      }
    });
  }
  /**
   * map directories to their closest tsconfig.json
   * @internal
   * @private
   * @type{Map<string,(Promise<string|null>|string|null)>}
   */
  #configPaths = /* @__PURE__ */ new Map();
  /**
   * map files to their parsed tsconfig result
   * @internal
   * @private
   * @type {Map<string,(Promise<T>|T)> }
   */
  #parsed = /* @__PURE__ */ new Map();
};
export {
  TSConfckCache,
  TSConfckParseError,
  TSConfckParseNativeError,
  find,
  findAll,
  findNative,
  parse,
  parseNative,
  toJson
};
//# sourceMappingURL=src-PABXIGQH.js.map