Skip to content

feat: Publish dual CJS and ESM builds - #490

Merged
mykola-mokhnach merged 3 commits into
appium:mainfrom
mykola-mokhnach:dual
Jul 26, 2026
Merged

feat: Publish dual CJS and ESM builds#490
mykola-mokhnach merged 3 commits into
appium:mainfrom
mykola-mokhnach:dual

Conversation

@mykola-mokhnach

Copy link
Copy Markdown
Contributor

Similar to appium/asyncbox#85

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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/esm and build/cjs) and generate per-build package.json files to set type.
  • Switch package metadata to conditional exports for import vs require, 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 thread package.json
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"
},

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this is ok

Comment thread test/cjs-interop.spec.cjs Outdated
@@ -0,0 +1,10 @@
const assert = require('node:assert/strict');
const {test} = require('node:test');
const teenProcess = require('../build/cjs/lib/index.js');

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

- 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>
Comment thread package.json Outdated
"clean": "npm run build -- --clean",
"build": "tsc -b tsconfig.esm.json tsconfig.cjs.json",
"postbuild": "node scripts/postbuild.mjs",
"clean": "rm -rf build",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

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>
@mykola-mokhnach
mykola-mokhnach merged commit c385840 into appium:main Jul 26, 2026
5 checks passed
@mykola-mokhnach
mykola-mokhnach deleted the dual branch July 26, 2026 21:08
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))
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 4.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants