"use strict";
/* Socket Lib - Built with esbuild */
"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 find_packages_exports = {};
__export(find_packages_exports, {
  FIND_PACKAGES_PATTERN_MAX_LEN: () => FIND_PACKAGES_PATTERN_MAX_LEN,
  findPackages: () => findPackages,
  jsFindPackages: () => jsFindPackages
});
module.exports = __toCommonJS(find_packages_exports);
var import_error = require("../../primordials/error");
var import_regexp = require("../../primordials/regexp");
var import_manifest = require("../../smol/manifest");
const FIND_PACKAGES_PATTERN_MAX_LEN = 256;
function jsFindPackages(lockfile, pattern) {
  let regex;
  if (pattern instanceof import_regexp.RegExpCtor) {
    if (pattern.source.length > FIND_PACKAGES_PATTERN_MAX_LEN) {
      throw new import_error.RangeErrorCtor(
        `pattern exceeds maximum length (${FIND_PACKAGES_PATTERN_MAX_LEN})`
      );
    }
    regex = pattern;
  } else {
    if (typeof pattern !== "string") {
      throw new import_error.TypeErrorCtor("pattern must be a string or RegExp");
    }
    if (pattern.length > FIND_PACKAGES_PATTERN_MAX_LEN) {
      throw new import_error.RangeErrorCtor(
        `pattern exceeds maximum length (${FIND_PACKAGES_PATTERN_MAX_LEN})`
      );
    }
    regex = new import_regexp.RegExpCtor(pattern);
  }
  const result = [];
  const pkgs = lockfile.packages;
  for (let i = 0, { length } = pkgs; i < length; i++) {
    const pkg = pkgs[i];
    if ((0, import_regexp.RegExpPrototypeTest)(regex, pkg.name)) {
      result[result.length] = pkg;
    }
  }
  return result;
}
const _smol = (0, import_manifest.getSmolManifest)();
const findPackages = _smol ? _smol.findPackages : jsFindPackages;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  FIND_PACKAGES_PATTERN_MAX_LEN,
  findPackages,
  jsFindPackages
});
