import { builtinModules } from 'node:module';

// src/features/gen-html/infrastructure/local-server/paths.ts
var LOCAL_SERVER_SASS_VERSION = "^1.86.3";
var LOCAL_SERVER_REACT_QUERY_VERSION = "^5.81.2";
var LOCAL_SERVER_TYPES_NODE_VERSION = "^25.0.10";
var LOCAL_SERVER_TYPES_REACT_VERSION = "19.1.0";
var LOCAL_SERVER_TYPES_REACT_DOM_VERSION = "19.1.1";
var LOCAL_SERVER_TYPESCRIPT_VERSION = "5.8.2";
var LOCAL_SERVER_VITE_VERSION = "^6.3.1";
var STORYBOOK_VERSION = "8.6.14";
var PACKAGE_MANIFEST_DEPENDENCY_FIELDS = ["dependencies", "devDependencies", "optionalDependencies", "peerDependencies"];
new Set(
  builtinModules.flatMap((moduleName) => [moduleName, moduleName.replace(/^node:/, ""), `node:${moduleName.replace(/^node:/, "")}`])
);
var LOCAL_SERVER_DEFAULT_PACKAGE_JSON = {
  dependencies: {
    "@types/node": LOCAL_SERVER_TYPES_NODE_VERSION,
    "@types/react": LOCAL_SERVER_TYPES_REACT_VERSION,
    "@types/react-dom": LOCAL_SERVER_TYPES_REACT_DOM_VERSION,
    "@tanstack/react-query": LOCAL_SERVER_REACT_QUERY_VERSION,
    "@storybook/addon-essentials": STORYBOOK_VERSION,
    "@storybook/react": STORYBOOK_VERSION,
    "@storybook/react-vite": STORYBOOK_VERSION,
    react: "^19.1.0",
    "react-dom": "^19.1.0",
    sass: LOCAL_SERVER_SASS_VERSION,
    storybook: STORYBOOK_VERSION,
    typescript: LOCAL_SERVER_TYPESCRIPT_VERSION,
    vite: LOCAL_SERVER_VITE_VERSION
  },
  name: "ju-hong-e-local-server",
  private: true,
  scripts: {
    dev: "storybook dev -c ./.storybook",
    start: "storybook dev -c ./.storybook"
  },
  type: "commonjs"
};
function isRecord(value) {
  return typeof value === "object" && value !== null && !Array.isArray(value);
}

// src/features/gen-html/infrastructure/local-server/dependencies/manifest.ts
function normalizeDependencies(value) {
  if (!isRecord(value)) {
    return {};
  }
  return Object.entries(value).reduce((accumulator, [key, dependencyValue]) => {
    if (typeof dependencyValue === "string" && dependencyValue.trim()) {
      accumulator[key] = dependencyValue;
    }
    return accumulator;
  }, {});
}
function extractPackageManifestDependencies(value) {
  if (!isRecord(value)) {
    return {};
  }
  return PACKAGE_MANIFEST_DEPENDENCY_FIELDS.reduce((accumulator, fieldName) => {
    Object.assign(accumulator, normalizeDependencies(value[fieldName]));
    return accumulator;
  }, {});
}
function mergeLocalServerPackageJson(value, extraDependencies = {}) {
  const current = isRecord(value) ? value : {};
  const dependencies = normalizeDependencies(current.dependencies);
  const scripts = normalizeDependencies(current.scripts);
  return {
    ...current,
    dependencies: {
      ...LOCAL_SERVER_DEFAULT_PACKAGE_JSON.dependencies,
      ...extraDependencies,
      ...dependencies
    },
    name: typeof current.name === "string" && current.name.trim() ? current.name : LOCAL_SERVER_DEFAULT_PACKAGE_JSON.name,
    private: typeof current.private === "boolean" ? current.private : LOCAL_SERVER_DEFAULT_PACKAGE_JSON.private,
    scripts: {
      ...scripts,
      ...LOCAL_SERVER_DEFAULT_PACKAGE_JSON.scripts
    },
    type: LOCAL_SERVER_DEFAULT_PACKAGE_JSON.type
  };
}
function toSortedDependencies(dependencies) {
  return Object.fromEntries(Object.entries(dependencies).sort(([left], [right]) => left.localeCompare(right)));
}

export { extractPackageManifestDependencies, mergeLocalServerPackageJson, normalizeDependencies, toSortedDependencies };
