"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var utils_exports = {};
__export(utils_exports, {
  addTrailingSlash: () => addTrailingSlash,
  awaitableGetter: () => awaitableGetter,
  camelCase: () => camelCase,
  castArray: () => castArray,
  cloneDeep: () => cloneDeep,
  createVirtualModule: () => createVirtualModule,
  deepmerge: () => import_deepmerge.default,
  ensureAbsolutePath: () => ensureAbsolutePath,
  getCoreJsVersion: () => getCoreJsVersion,
  getSharedPkgCompiledPath: () => getSharedPkgCompiledPath,
  isBeyondReact17: () => isBeyondReact17,
  isDev: () => isDev,
  isFunction: () => isFunction,
  isObject: () => isObject,
  isPackageInstalled: () => isPackageInstalled,
  isPlainObject: () => isPlainObject,
  isProd: () => isProd,
  isRegExp: () => isRegExp,
  isServerTarget: () => isServerTarget,
  isString: () => isString,
  isTest: () => isTest,
  isURL: () => isURL,
  isUndefined: () => isUndefined,
  isUseCssSourceMap: () => isUseCssSourceMap,
  isUseJsSourceMap: () => isUseJsSourceMap,
  isWebTarget: () => isWebTarget,
  removeLeadingSlash: () => removeLeadingSlash,
  removeTailSlash: () => removeTailSlash,
  resolvePackage: () => resolvePackage
});
module.exports = __toCommonJS(utils_exports);
var import_path = __toESM(require("path"));
var import_fs_extra = __toESM(require("../compiled/fs-extra"));
var import_semver = __toESM(require("semver"));
var import_fs = require("./fs");
var import_deepmerge = __toESM(require("../compiled/deepmerge"));
const isDev = () => process.env.NODE_ENV === "development";
const isProd = () => process.env.NODE_ENV === "production";
const isTest = () => process.env.NODE_ENV === "test";
const isString = (str) => typeof str === "string";
const isUndefined = (obj) => typeof obj === "undefined";
const isFunction = (func) => typeof func === "function";
const isObject = (obj) => obj !== null && typeof obj === "object";
const isPlainObject = (obj) => isObject(obj) && Object.prototype.toString.call(obj) === "[object Object]";
const isRegExp = (obj) => Object.prototype.toString.call(obj) === "[object RegExp]";
const createVirtualModule = (content) => `data:text/javascript,${content}`;
const removeLeadingSlash = (s) => s.replace(/^\/+/, "");
const removeTailSlash = (s) => s.replace(/\/+$/, "");
const addTrailingSlash = (s) => s.endsWith("/") ? s : `${s}/`;
const awaitableGetter = (promises) => {
  const then = (...args) => Promise.all(promises).then(...args);
  return { then, promises };
};
const isUseJsSourceMap = (config) => {
  const { disableSourceMap } = config.output || {};
  if (typeof disableSourceMap === "boolean") {
    return !disableSourceMap;
  }
  return !disableSourceMap.js;
};
const isUseCssSourceMap = (config) => {
  const { disableSourceMap } = config.output || {};
  if (typeof disableSourceMap === "boolean") {
    return !disableSourceMap;
  }
  if (disableSourceMap.css === void 0) {
    return process.env.NODE_ENV !== "production";
  }
  return !disableSourceMap.css;
};
const getSharedPkgCompiledPath = (packageName) => import_path.default.join(__dirname, "../compiled", packageName);
const isURL = (str) => str.startsWith("http") || str.startsWith("//:");
function isWebTarget(target) {
  return ["web", "web-worker"].some(
    (t) => (Array.isArray(target) ? target : [target]).includes(t)
  );
}
function isServerTarget(target) {
  return (Array.isArray(target) ? target : [target]).some(
    (item) => ["node", "service-worker"].includes(item)
  );
}
function resolvePackage(loader, dirname) {
  return process.env.VITEST ? loader : require.resolve(loader, { paths: [dirname] });
}
const getCoreJsVersion = (corejsPkgPath) => {
  try {
    const { version } = import_fs_extra.default.readJSONSync(corejsPkgPath);
    const [major, minor] = version.split(".");
    return `${major}.${minor}`;
  } catch (err) {
    return "3";
  }
};
const ensureAbsolutePath = (base, filePath) => import_path.default.isAbsolute(filePath) ? filePath : import_path.default.resolve(base, filePath);
const castArray = (arr) => {
  if (arr === void 0) {
    return [];
  }
  return Array.isArray(arr) ? arr : [arr];
};
const isPackageInstalled = (name, resolvePaths) => {
  try {
    require.resolve(name, { paths: castArray(resolvePaths) });
    return true;
  } catch (err) {
    return false;
  }
};
const isBeyondReact17 = async (cwd) => {
  const pkgPath = await (0, import_fs.findUp)({ cwd, filename: "package.json" });
  if (!pkgPath) {
    return false;
  }
  const pkgInfo = JSON.parse(import_fs_extra.default.readFileSync(pkgPath, "utf8"));
  const deps = {
    ...pkgInfo.devDependencies,
    ...pkgInfo.dependencies
  };
  if (typeof deps.react !== "string") {
    return false;
  }
  return import_semver.default.satisfies(import_semver.default.minVersion(deps.react), ">=17.0.0");
};
const camelCase = (input) => input.replace(/[-_](\w)/g, (_, c) => c.toUpperCase());
const cloneDeep = (value) => (0, import_deepmerge.default)({}, value);
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  addTrailingSlash,
  awaitableGetter,
  camelCase,
  castArray,
  cloneDeep,
  createVirtualModule,
  deepmerge,
  ensureAbsolutePath,
  getCoreJsVersion,
  getSharedPkgCompiledPath,
  isBeyondReact17,
  isDev,
  isFunction,
  isObject,
  isPackageInstalled,
  isPlainObject,
  isProd,
  isRegExp,
  isServerTarget,
  isString,
  isTest,
  isURL,
  isUndefined,
  isUseCssSourceMap,
  isUseJsSourceMap,
  isWebTarget,
  removeLeadingSlash,
  removeTailSlash,
  resolvePackage
});
