feat: add CJS support to published npm packages#39
Conversation
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 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>
There was a problem hiding this comment.
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
tscbuilds withtsupconfigs that emit bothesmandcjsformats (plus declarations). - Updates each package’s
package.json(main/module+exportswithrequireconditions pointing at.cjs). - Updates lockfile to include
tsupand 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'], |
There was a problem hiding this comment.
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.
| format: ['esm', 'cjs'], | |
| format: ['esm', 'cjs'], | |
| noExternal: ['jose'], |
| "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" | ||
| } |
There was a problem hiding this comment.
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.
| "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" | ||
| } |
There was a problem hiding this comment.
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 look at PR comments and address as/if needed |
Agent-Logs-Url: https://github.com/dupe-com/botcha/sessions/ceeaed17-72a6-4dda-87ec-61b4a9bd652e Co-authored-by: i8ramin <49030+i8ramin@users.noreply.github.com>
Addressed both review items in commit c5229dc:
|
|
@copilot CI tests are failing: |
Agent-Logs-Url: https://github.com/dupe-com/botcha/sessions/81bf6d4e-ac81-4b08-a699-e7d953c42bee Co-authored-by: i8ramin <49030+i8ramin@users.noreply.github.com>
|
🧹 Preview worker |
tsup@8.5.1as devDependency to root package,@dupecom/botcha-verify, and@dupecom/botcha-langchaintsup.config.tsfor root package,packages/verify, andpackages/langchainpackage.jsonexports withrequireconditions,typesfirst,main→CJS,modulefield,build→tsupnoExternal: ['jose']topackages/verify/tsup.config.ts—jose@5.xis ESM-only and would throwERR_REQUIRE_ESMin CJS mode without bundling itscripts/cjs-smoke.cjstorequire()all CJS entry points after buildci.yml(runs afterbun run build)packages/verifyandpackages/langchainbefore the CJS smoke test (rootbun run buildonly builds the root package)Original prompt