import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
import path from "node:path";
import test from "node:test";
import { fileURLToPath } from "node:url";

const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");

type PackageJson = {
  exports?: Record<string, { types?: string; "remnic-source"?: string; import?: string }>;
};

test("@remnic/core exposes the peers public subpath", async () => {
  const packageJsonRaw = await readFile(
    path.join(repoRoot, "packages", "remnic-core", "package.json"),
    "utf8",
  );
  const pkg = JSON.parse(packageJsonRaw) as PackageJson;
  const expected = {
    types: "./dist/peers/index.d.ts",
    "remnic-source": "./src/peers/index.ts",
    import: "./dist/peers/index.js",
  };

  assert.deepEqual(pkg.exports?.["./peers"], expected);
  assert.deepEqual(pkg.exports?.["./peers.js"], expected);
  assert.deepEqual(pkg.exports?.["./peers/index"], expected);
  assert.deepEqual(pkg.exports?.["./peers/index.js"], expected);
});
