ProvenPin Install

cosmiconfig load config from fixture files: working versions (tested 2026-10-15)

Use cosmiconfigSync to load JSON and JS module configs from a temporary search root without touching the real filesystem home.

passed2 passed · 0 failed2026-10-15 20:56 UTC
Status
passed
Last passed
2026-10-15 20:56 UTC
Tests
2 / 2
Language
TypeScript
Runtime
node v22.23.3
pinned versions3
cosmiconfig@10.0.1@types/node@26.6.5tsx@4.23.15
run it
npm install --no-audit --no-fund --ignore-scripts=false
npm test
test environment
node v22.23.3
linux 6.17.0-1022-azure
x64
runner: github-actions 38805962781

The code

Exactly the files that passed. Your agent can pull them with get_recipe("cosmiconfig-fixture-load") (install), or see them on GitHub.

package.json
{
  "name": "cosmiconfig-fixture-load",
  "private": true,
  "type": "module",
  "scripts": {
    "test": "node --import tsx --test test/*.test.ts"
  },
  "dependencies": {
    "cosmiconfig": "10.0.1"
  },
  "devDependencies": {
    "@types/node": "26.6.5",
    "tsx": "4.23.15"
  }
}
src/load-config.ts
import { cosmiconfigSync } from "cosmiconfig";
import { mkdirSync, writeFileSync } from "node:fs";
import { join } from "node:path";

export type AppConfig = { port: number; name: string };

export function writeFixture(root: string, filename: string, data: unknown) {
  mkdirSync(root, { recursive: true });
  writeFileSync(join(root, filename), typeof data === "string" ? data : JSON.stringify(data, null, 2));
}

export function loadAppConfig(searchFrom: string): AppConfig {
  const explorer = cosmiconfigSync("demoapp", {
    searchPlaces: [".demoapprc.json", "demoapp.config.json"],
  });
  const result = explorer.search(searchFrom);
  if (!result || result.isEmpty) throw new Error("config not found");
  return result.config as AppConfig;
}
test/load-config.test.ts
import { test } from "node:test";
import assert from "node:assert/strict";
import { mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { loadAppConfig, writeFixture } from "../src/load-config.ts";

test("loads .demoapprc.json from search root", () => {
  const root = mkdtempSync(join(tmpdir(), "cosmo-"));
  try {
    writeFixture(root, ".demoapprc.json", { port: 4090, name: "demo" });
    const cfg = loadAppConfig(root);
    assert.equal(cfg.port, 4090);
    assert.equal(cfg.name, "demo");
  } finally {
    rmSync(root, { recursive: true, force: true });
  }
});

test("throws when no config exists", () => {
  const root = mkdtempSync(join(tmpdir(), "cosmo-empty-"));
  try {
    assert.throws(() => loadAppConfig(root), /config not found/);
  } finally {
    rmSync(root, { recursive: true, force: true });
  }
});

Connect to ProvenPin

Add the free MCP server so your agent can pull this recipe and others like it. Same setup as the docs.

terminal
claude mcp add --transport http provenpin https://mcp.provenpin.com/mcp

Any other MCP client: Streamable HTTP at https://mcp.provenpin.com/mcp. No API key, no signup.