diff --git a/.changeset/moody-zebras-change.md b/.changeset/moody-zebras-change.md new file mode 100644 index 0000000..02446ba --- /dev/null +++ b/.changeset/moody-zebras-change.md @@ -0,0 +1,5 @@ +--- +"@viem/anvil": patch +--- + +Fixed import from `http-proxy` package in cjs environments. diff --git a/examples/example-node/index.ts b/examples/example-node/index.ts index ed47c0b..b1cca03 100644 --- a/examples/example-node/index.ts +++ b/examples/example-node/index.ts @@ -1,6 +1,6 @@ import assert from "node:assert"; import { test } from "node:test"; -import { createAnvil, getVersion } from "@viem/anvil"; +import { createAnvil, createPool, getVersion, startProxy } from "@viem/anvil"; test("can fetch the anvil version", async () => { const version = await getVersion(); @@ -21,3 +21,26 @@ test("can start and stop anvil instances", async () => { await anvil.stop(); assert((anvil.status as string) === "idle"); }); + +test("can start and stop pool instances", async () => { + const pool = createPool(); + + const a = await pool.start(1); + assert(a !== undefined); + assert(a.status === "listening"); + + const b = await pool.start(123); + assert(b !== undefined); + assert(b.status === "listening"); + + await a.stop(); + assert((a.status as string) === "idle"); + + await b.stop(); + assert((b.status as string) === "idle"); +}); + +test("can start and stop an anvil proxy", async () => { + const stop = await startProxy(); + await stop(); +}); diff --git a/packages/anvil.js/src/proxy/createProxy.ts b/packages/anvil.js/src/proxy/createProxy.ts index c12c196..d5ebb41 100644 --- a/packages/anvil.js/src/proxy/createProxy.ts +++ b/packages/anvil.js/src/proxy/createProxy.ts @@ -1,4 +1,4 @@ -import httpProxy from "http-proxy"; +import { createProxyServer } from "http-proxy"; import { IncomingMessage, ServerResponse, createServer } from "node:http"; import { parseRequest, type InstanceRequestContext } from "./parseRequest.js"; import { type Pool } from "../pool/createPool.js"; @@ -77,7 +77,7 @@ export type CreateProxyOptions = { * ``` */ export function createProxy({ pool, options, fallback }: CreateProxyOptions) { - const proxy = httpProxy.createProxyServer({ + const proxy = createProxyServer({ ignorePath: true, ws: true, });