feat: Publish dual CJS and ESM builds - #490
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the build and packaging setup to publish dual ESM + CommonJS outputs, and adjusts internal/test imports to be ESM-compatible (explicit .js specifiers), similar in spirit to appium/asyncbox#85.
Changes:
- Add separate TypeScript build configs for ESM and CJS outputs (
build/esmandbuild/cjs) and generate per-buildpackage.jsonfiles to settype. - Switch package metadata to conditional exports for
importvsrequire, and update test/runtime imports accordingly. - Add a CJS interop test intended to validate
require()behavior against the CJS build.
Reviewed changes
Copilot reviewed 13 out of 14 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tsconfig.json | Excludes the new .cjs test file from TS compilation. |
| tsconfig.esm.json | New build config targeting build/esm. |
| tsconfig.cjs.json | New build config targeting build/cjs with module: CommonJS. |
| package.json | Declares type: module, adds conditional exports, and updates build/test scripts and published files. |
| scripts/postbuild.mjs | Writes build/esm/package.json and build/cjs/package.json to set module type per output. |
| lib/index.ts | Updates internal export specifiers to explicit .js for ESM compatibility. |
| lib/exec.ts | Updates internal import specifiers to explicit .js. |
| lib/subprocess.ts | Updates internal import/type-import specifiers to explicit .js. |
| test/exec.spec.ts | Updates imports to explicit .js and replaces __dirname usage for ESM. |
| test/subproc.spec.ts | Updates imports to explicit .js and replaces __dirname/__filename usage for ESM. |
| test/helpers.ts | Switches module root discovery to use import.meta.url for ESM. |
| test/circular-buffer.spec.ts | Updates import to explicit .js. |
| test/cjs-interop.spec.cjs | Adds a CJS test to validate interop with the CJS build. |
| README.md | Documents that both import and require usage are supported. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+27
to
+39
| "exports": { | ||
| ".": { | ||
| "import": { | ||
| "types": "./build/esm/lib/index.d.ts", | ||
| "default": "./build/esm/lib/index.js" | ||
| }, | ||
| "require": { | ||
| "types": "./build/cjs/lib/index.d.ts", | ||
| "default": "./build/cjs/lib/index.js" | ||
| } | ||
| }, | ||
| "./package.json": "./package.json" | ||
| }, |
| @@ -0,0 +1,10 @@ | |||
| const assert = require('node:assert/strict'); | |||
| const {test} = require('node:test'); | |||
| const teenProcess = require('../build/cjs/lib/index.js'); | |||
- clean now does rm -rf build instead of routing through the build script, so it no longer triggers postbuild and leaves stamped build/*/package.json markers behind. - cjs-interop test now require()s the package by name instead of a build path, exercising the real exports/main resolution. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
eglitise
reviewed
Jul 26, 2026
| "clean": "npm run build -- --clean", | ||
| "build": "tsc -b tsconfig.esm.json tsconfig.cjs.json", | ||
| "postbuild": "node scripts/postbuild.mjs", | ||
| "clean": "rm -rf build", |
rm -rf doesn't work in default Windows shells; use node -e with fs.rmSync instead so npm run clean/rebuild works everywhere. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
eglitise
approved these changes
Jul 26, 2026
github-actions Bot
pushed a commit
that referenced
this pull request
Jul 26, 2026
## [4.2.0](v4.1.10...v4.2.0) (2026-07-26) ### Features * Publish dual CJS and ESM builds ([#490](#490)) ([c385840](c385840))
|
🎉 This PR is included in version 4.2.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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.
Similar to appium/asyncbox#85