Skip to content

feat: add CJS (CommonJS) support via dual ESM/CJS build#40

Merged
i8ramin merged 3 commits intomainfrom
feat/cjs-support
Apr 14, 2026
Merged

feat: add CJS (CommonJS) support via dual ESM/CJS build#40
i8ramin merged 3 commits intomainfrom
feat/cjs-support

Conversation

@chocothebot
Copy link
Copy Markdown
Collaborator

Closes #37

What

Adds CommonJS support so the package works in CJS projects with require().

How

  • Dual build: bun run build now compiles both ESM (dist/lib/) and CJS (dist/cjs/) via a new tsconfig.cjs.json
  • exports map: Updated with require conditions for all 3 entry points (., ./client, ./middleware)
  • dist/cjs/package.json: Written at build time with { "type": "commonjs" } so Node.js treats .js files there correctly — no need to rename to .cjs
  • main field: Now points to CJS entry for legacy tools that ignore exports
  • scripts/verify-cjs.cjs: Standalone verification script — CI runs it after build

Usage

// CJS
const { botcha, verify, solve } = require("@dupecom/botcha");
const { BotchaStreamClient } = require("@dupecom/botcha/client");

// ESM (unchanged)
import { botcha, verify, solve } from "@dupecom/botcha";

CI

Added "Verify CJS output" step after build. Also fixes the types condition ordering in exports (must come before require/import per bundler spec).

Closes #37

## Changes

- **tsconfig.cjs.json**: New tsconfig targeting CommonJS + Node moduleResolution,
  outputting to dist/cjs/
- **package.json**:
  - Updated build script to compile both ESM and CJS, writes
    dist/cjs/package.json with { type: 'commonjs' } so Node.js
    treats the output correctly
  - Updated exports map: added 'require' condition for all three
    entry points (., ./client, ./middleware); moved 'types' first
    per bundler convention
  - Updated 'main' to point to CJS entry for legacy require() compat
  - Added 'test:cjs' script
  - Added dist/cjs to files
- **scripts/verify-cjs.cjs**: Standalone verification script that
  require()s all three package entry points and asserts exports
- **ci.yml**: Added 'Verify CJS output' step after build

## Usage

ESM (unchanged):
  import { botcha, verify, solve } from '@dupecom/botcha'

CJS (new):
  const { botcha, verify, solve } = require('@dupecom/botcha')
@github-actions
Copy link
Copy Markdown

🤖 BOTCHA Verification Required

This repository only accepts contributions from AI agents.

To prove you're an agent, solve this challenge:


Challenge ID: gh-1774960765-40

Numbers: [115354, 127600, 102585, 114574, 112174]

Task: Compute SHA256 of each number, return the first 8 hex characters.

Reply with this exact format:

BOTCHA:gh-1774960765-40:
["your_answer_1", "your_answer_2", "your_answer_3", "your_answer_4", "your_answer_5"]

Time limit: 5 minutes from this comment.

A human would need to manually run echo -n "123456" | sha256sum five times and copy-paste results. An AI agent just... computes it.

Powered by BOTCHA (https://botcha.ai) — Prove you're a bot. Humans need not apply.

@chocothebot
Copy link
Copy Markdown
Collaborator Author

BOTCHA:gh-1774960765-40:
["af57a5ae", "c4ec38f4", "37c95fd5", "494e3c55", "c828e0b1"]

@github-actions
Copy link
Copy Markdown

✅ BOTCHA Verification Passed!

🤖 @chocothebot has proven they are an AI agent.

⏱️ Solved in 32 seconds

📊 Challenge Details:

  • 🆔 Challenge ID: gh-1774960765-40
  • 🎯 All 5 SHA256 hashes computed correctly
  • ⚡ Solved in 0.53 minutes

This PR is now eligible for review and merge.


Welcome, fellow agent! 🦞

i8ramin and others added 2 commits April 14, 2026 12:24
The CJS tsconfig had declaration/declarationMap enabled, generating 32
unnecessary .d.ts/.d.ts.map files under dist/cjs/ that were never
referenced (exports map points types to the ESM declarations).
Disabling them cuts the CJS output from 368KB to 192KB.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The CJS entry point starts a setInterval for challenge cleanup, which
keeps the Node process alive after all checks complete. Add explicit
process.exit(0) so CI doesn't hang.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@i8ramin i8ramin merged commit bf17b71 into main Apr 14, 2026
2 checks passed
@github-actions
Copy link
Copy Markdown

🧹 Preview worker botcha-pr-40 deleted (PR merged).

i8ramin added a commit that referenced this pull request Apr 14, 2026
Features:
- CJS (CommonJS) support via dual ESM/CJS build (PR #40, closes #37)
- GET /v1/agents/me shorthand for authenticated agent lookup (PR #41)
- GET /v1/agents/:id/reputation alias (PR #41)
- ACTION_CATEGORY_MISMATCH error includes valid_actions array (PR #41)

Fixes:
- Agent-identity tokens accepted in app-gate and TAP routes (PR #38)
- verifyToken allowedTypes option (PR #36)
- OAuth device flow UX improvements (PR #35)
- time_remaining renamed to time_remaining_seconds (breaking, PR #41)
- ttl_seconds validated on session creation (PR #41)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for CJS?

2 participants