Repository navigation
Bundle for edge runtimes; per-domain library entries - #6
Merged
Merged
Conversation
Collaborator
|
LGTM |
fibanachos
approved these changes
Oct 1, 2026
fibanachos
enabled auto-merge (squash)
October 1, 2026 10:05
…wsers `import anchorPkg from "@coral-xyz/anchor"` only works where Anchor resolves to its CommonJS build. Under the `workerd` / `worker` / `browser` conditions (Cloudflare Workers, Vercel Edge, any browser bundler) it resolves to `dist/browser`, which has no default export, so esbuild refuses the whole barrel. Named imports resolve under both. `cpAmm` also used Anchor's `Wallet` (NodeWallet), which the browser build does not ship; the throwaway provider wallet is now a plain object that never signs.
The barrel pulls in every venue SDK, so an app that only needs one flow bundles ~450 KB gzipped; `cookie-mcp/trade` alone is ~100 KB. Each domain gets its own entry in `exports` and tsup, built with the same `splitting`, so the subpaths share module state (request context, wallet cache) with the barrel and the server factory. The barrel and `./server` are unchanged. `subpaths.test.ts` bundles the barrel and every entry under the `workerd` / `worker` / `browser` conditions, the way an edge consumer would, and checks `exports` against the tsup entries. esbuild becomes an explicit dev dependency at the version the lockfile already resolves.
auto-merge was automatically disabled
October 1, 2026 13:31
Head branch was pushed to by a user without write access
Vicape7
force-pushed
the
feat/subpath-exports
branch
from
October 1, 2026 13:31
75b8efb to
73a94eb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Makes the library usable from edge runtimes (Cloudflare Workers, Vercel Edge) and lets an app import one flow without bundling every venue SDK. Two commits, so the second can be dropped on its own.
1.
fix:import Anchor by nameimport anchorPkg from "@coral-xyz/anchor"only works where Anchor resolves to its CommonJS build. Under theworkerd/worker/browserconditions it resolves todist/browser, which has no default export, so esbuild refuses the whole barrel:Now named imports in
limitOrders,dca,curveOrders,clmmandcpAmm(+ the four tests that copied the pattern).cpAmmalso used Anchor'sWallet(NodeWallet), which the browser build does not ship; the throwaway provider wallet is now a plain object that never signs (the cp-amm SDK never signs through it). This commit alone makesimport { trade } from "cookie-mcp"bundle for Workers.2.
feat:per-domain library entriescookie-mcp/trade,/transfer,/stake,/bridge,/bridge-routes,/nft,/domains,/launchpad,/limit-orders,/dca,/liquidity,/quote,/balances,/signer,/context,/submit,/errors. Built from the same tsup config withsplitting, so they share module state with the barrel and./server. The barrel and./serverare unchanged.Consumer bundle, minified + gzipped,
workerdconditions:{ trade } from "cookie-mcp"{ trade } from "cookie-mcp/trade"{ stake } from "cookie-mcp/stake"{ bridge } from "cookie-mcp/bridge"{ makeOffer } from "cookie-mcp/nft"{ deployToken } from "cookie-mcp/launchpad"{ submitSignedTransaction } from "cookie-mcp/submit"The honest cost: each subpath becomes public API you would be committing to. If you would rather expose fewer (or none), the first commit stands on its own.
src/subpaths.test.tsbundles the barrel and every entry under theworkerdconditions and checksexportsagainst the tsup entries, so a future default import (or a subpath added to one side only) fails CI. Reverting commit 1 makes it fail on.and./dca.esbuildbecomes an explicit dev dependency at the version the lockfile already resolves (yarn.lockunchanged).README ("As a library") documents the subpaths and what Workers need:
nodejs_compat, andprocess.envpopulated (default from compatibility date2025-04-01), since config is read at import time.node:net/node:dnsused by the launchpad image fetch are available undernodejs_compat.Checked
yarn lint,format:check,typecheck,smoke(57 tools),buildpass;test:unit671 pass. The two failures inimageFile.test.tsare onmaintoo and Windows-only (path separators).trade/SignatureRequired, and a context set viacookie-mcp/contextis read throughcookie-mcp.buildCpAmmDeps/buildClmmClientstill construct under Node with the Cookie program ids.nodejs_compat, compatibility date 2024-12-30):node:net,node:dns/promises,node:async_hooksandnode:pathload and work.