Skip to content

feat: add CJS support to published npm packages#39

Closed
Copilot wants to merge 6 commits intomainfrom
copilot/check-cjs-support
Closed

feat: add CJS support to published npm packages#39
Copilot wants to merge 6 commits intomainfrom
copilot/check-cjs-support

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 31, 2026

  • Add tsup@8.5.1 as devDependency to root package, @dupecom/botcha-verify, and @dupecom/botcha-langchain
  • Create tsup.config.ts for root package, packages/verify, and packages/langchain
  • Update package.json exports with require conditions, types first, main→CJS, module field, buildtsup
  • Update CHANGELOG.md with CJS support entry under [Unreleased]
  • Add noExternal: ['jose'] to packages/verify/tsup.config.tsjose@5.x is ESM-only and would throw ERR_REQUIRE_ESM in CJS mode without bundling it
  • Add scripts/cjs-smoke.cjs to require() all CJS entry points after build
  • Add CJS smoke test step to ci.yml (runs after bun run build)
  • Fix CI: add explicit build steps for packages/verify and packages/langchain before the CJS smoke test (root bun run build only builds the root package)
Original prompt

Look into CJS support for this project

Copilot AI and others added 2 commits March 31, 2026 12:37
Agent-Logs-Url: https://github.com/dupe-com/botcha/sessions/ddb8489d-2178-4e8a-9e59-e31bd16d5088

Co-authored-by: i8ramin <49030+i8ramin@users.noreply.github.com>
…d botcha-langchain

Agent-Logs-Url: https://github.com/dupe-com/botcha/sessions/ddb8489d-2178-4e8a-9e59-e31bd16d5088

Co-authored-by: i8ramin <49030+i8ramin@users.noreply.github.com>
Copilot AI changed the title [WIP] Investigate CJS support for the project feat: add CJS support to published npm packages Mar 31, 2026
Copilot AI requested a review from i8ramin March 31, 2026 12:47
@i8ramin i8ramin marked this pull request as ready for review March 31, 2026 12:52
@i8ramin i8ramin requested a review from Copilot March 31, 2026 12:52
@i8ramin
Copy link
Copy Markdown
Collaborator

i8ramin commented Mar 31, 2026

@copilot plz also update the CHANGELOG file (or create one if we don't have one)

Agent-Logs-Url: https://github.com/dupe-com/botcha/sessions/78d3375a-1b68-4a0d-9d99-af8455917291

Co-authored-by: i8ramin <49030+i8ramin@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 31, 2026

@copilot plz also update the CHANGELOG file (or create one if we don't have one)

Added a CJS support entry to the [Unreleased] section of CHANGELOG.md in commit d444b3e. It covers the build tooling change (tsup), the package exports updates, and includes a quick usage example.

Copilot AI requested a review from i8ramin March 31, 2026 12:57
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds dual ESM+CJS support for the published npm packages so CommonJS consumers can require() them without switching module systems.

Changes:

  • Replaces tsc builds with tsup configs that emit both esm and cjs formats (plus declarations).
  • Updates each package’s package.json (main/module + exports with require conditions pointing at .cjs).
  • Updates lockfile to include tsup and its transitive dependencies.

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tsup.config.ts Adds root tsup config to build dual ESM/CJS outputs into dist/.
package.json Switches root build to tsup and adds CJS-aware main/exports.require.
packages/verify/tsup.config.ts Adds tsup config for @dupecom/botcha-verify with multiple entrypoints.
packages/verify/package.json Adds .cjs entrypoints via main/exports.require and switches build to tsup.
packages/langchain/tsup.config.ts Adds tsup config for @dupecom/botcha-langchain dual-format builds.
packages/langchain/package.json Adds .cjs entrypoints via main/exports.require and switches build/dev to tsup.
package-lock.json Locks tsup@8.5.1 and related dependencies.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

'middleware/express': 'src/middleware/express.ts',
'middleware/hono': 'src/middleware/hono.ts',
},
format: ['esm', 'cjs'],
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new CJS build for @dupecom/botcha-verify will still execute a require('jose') at runtime (the library imports jose), but jose@5.x is ESM-only. If tsup keeps dependencies external (common default), dist/index.cjs will throw ERR_REQUIRE_ESM when used from CommonJS, defeating the goal of this PR. Consider bundling jose into the CJS output (e.g., via tsup noExternal/node_modules bundling settings) or switching to a CJS-compatible JOSE dependency/loader approach for the CJS entry.

Suggested change
format: ['esm', 'cjs'],
format: ['esm', 'cjs'],
noExternal: ['jose'],

Copilot uses AI. Check for mistakes.
Comment on lines +6 to 24
"main": "dist/index.cjs",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js",
"types": "./dist/index.d.ts"
"require": "./dist/index.cjs"
},
"./express": {
"types": "./dist/middleware/express.d.ts",
"import": "./dist/middleware/express.js",
"types": "./dist/middleware/express.d.ts"
"require": "./dist/middleware/express.cjs"
},
"./hono": {
"types": "./dist/middleware/hono.d.ts",
"import": "./dist/middleware/hono.js",
"types": "./dist/middleware/hono.d.ts"
"require": "./dist/middleware/hono.cjs"
}
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR changes the package entrypoints/exports to add CJS support, but the test suite only imports from src/ (no validation that the built dist/*.cjs entrypoints can be require()’d). Adding a small build+runtime smoke test in CI (e.g., build then run Node in CJS mode to require('@dupecom/botcha-verify'), require('@dupecom/botcha-verify/express'), and require('@dupecom/botcha-verify/hono')) would prevent publishing a broken CJS artifact.

Copilot uses AI. Check for mistakes.
Comment thread package.json
Comment on lines +8 to 27
"main": "dist/lib/index.cjs",
"module": "dist/lib/index.js",
"types": "dist/lib/index.d.ts",
"type": "module",
"exports": {
".": {
"types": "./dist/lib/index.d.ts",
"import": "./dist/lib/index.js",
"types": "./dist/lib/index.d.ts"
"require": "./dist/lib/index.cjs"
},
"./client": {
"types": "./dist/lib/client/index.d.ts",
"import": "./dist/lib/client/index.js",
"types": "./dist/lib/client/index.d.ts"
"require": "./dist/lib/client/index.cjs"
},
"./middleware": {
"types": "./dist/src/middleware/tap-enhanced-verify.d.ts",
"import": "./dist/src/middleware/tap-enhanced-verify.js",
"types": "./dist/src/middleware/tap-enhanced-verify.d.ts"
"require": "./dist/src/middleware/tap-enhanced-verify.cjs"
}
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this PR changes the published entrypoints/exports to support CommonJS (main/exports.require), it would be good to add a build-time smoke test that exercises the published surface via Node’s resolver (e.g., after tsup, run Node in CJS mode to require('@dupecom/botcha') and require('@dupecom/botcha/client'), and in ESM mode to import('@dupecom/botcha/client')). This helps catch mismatches between exports paths and whatever filenames tsup actually emits.

Copilot uses AI. Check for mistakes.
@i8ramin
Copy link
Copy Markdown
Collaborator

i8ramin commented Mar 31, 2026

@copilot look at PR comments and address as/if needed

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 31, 2026

@copilot look at PR comments and address as/if needed

Addressed both review items in commit c5229dc:

  1. jose ESM-only bug — added noExternal: ['jose'] to packages/verify/tsup.config.ts so tsup bundles jose into the CJS output rather than leaving it as an external require('jose') that would throw ERR_REQUIRE_ESM at runtime.

  2. CJS smoke tests — added scripts/cjs-smoke.cjs that require()s every .cjs entry point for all three packages (@dupecom/botcha, @dupecom/botcha-verify, @dupecom/botcha-langchain), and wired it as a CI step in ci.yml right after bun run build.

@i8ramin
Copy link
Copy Markdown
Collaborator

i8ramin commented Apr 5, 2026

@copilot CI tests are failing:

Run node scripts/cjs-smoke.cjs
  node scripts/cjs-smoke.cjs
  shell: /usr/bin/bash -e {0}
  env:
    pythonLocation: /opt/hostedtoolcache/Python/3.12.13/x64
    PKG_CONFIG_PATH: /opt/hostedtoolcache/Python/3.12.13/x64/lib/pkgconfig
    Python_ROOT_DIR: /opt/hostedtoolcache/Python/3.12.13/x64
    Python2_ROOT_DIR: /opt/hostedtoolcache/Python/3.12.13/x64
    Python3_ROOT_DIR: /opt/hostedtoolcache/Python/3.12.13/x64
    LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.12.13/x64/lib

@dupecom/botcha
  ✓ require("./dist/lib/index.cjs")
    exports: botcha, default, solve, …
  ✓ require("./dist/lib/client/index.cjs")
    exports: BotchaClient, BotchaStreamClient, default, …
  ✓ require("./dist/src/middleware/tap-enhanced-verify.cjs")
    exports: createTAPVerifyMiddleware, default, tapEnhancedVerify, …

@dupecom/botcha-verify
  ✗ require("./packages/verify/dist/index.cjs")
    Cannot find module '/home/runner/work/botcha/botcha/packages/verify/dist/index.cjs'
Require stack:
- /home/runner/work/botcha/botcha/scripts/cjs-smoke.cjs
  ✗ require("./packages/verify/dist/middleware/express.cjs")
    Cannot find module '/home/runner/work/botcha/botcha/packages/verify/dist/middleware/express.cjs'
Require stack:
- /home/runner/work/botcha/botcha/scripts/cjs-smoke.cjs
  ✗ require("./packages/verify/dist/middleware/hono.cjs")
    Cannot find module '/home/runner/work/botcha/botcha/packages/verify/dist/middleware/hono.cjs'
Require stack:
- /home/runner/work/botcha/botcha/scripts/cjs-smoke.cjs

@dupecom/botcha-langchain
  ✗ require("./packages/langchain/dist/index.cjs")
    Cannot find module '/home/runner/work/botcha/botcha/packages/langchain/dist/index.cjs'
Require stack:
- /home/runner/work/botcha/botcha/scripts/cjs-smoke.cjs

7 checks: 3 passed, 4 failed
Error: Process completed with exit code 1.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 5, 2026

@copilot CI tests are failing:

...

Fixed in commit dfc9af9. The root bun run build only builds the root package — packages/verify and packages/langchain were never built before the smoke test ran. Added explicit build steps for each subpackage in ci.yml before the CJS smoke test step.

@i8ramin i8ramin closed this Apr 14, 2026
@github-actions
Copy link
Copy Markdown

🧹 Preview worker botcha-pr-39 deleted (PR closed).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants