fix(cjs): require the ESM entry directly, fail clearly on Node without require(esm), and stop publishing devcheck - #58
Merged
Conversation
…t require(esm), and stop publishing devcheck
index.cjs used createRequire(__filename) to synchronously load index.mjs. That
idiom predates Node's native require(esm) and breaks bundlers (esbuild,
webpack) that don't follow a createRequire-constructed require the way they
follow a literal require() call.
- index.cjs: a plain require("./index.mjs") instead of createRequire. Where
Node.js has no require(esm) (before 20.19 / 22.12) it now throws
ERR_REQUIRE_ESM with a message pointing to import() instead of a bare
loader error.
- index.mjs already avoided top-level await, so no change was needed there.
- devcheck.mjs is a source-checkout-only dev warning and was never meant to
ship: dropped "./devcheck" from exports and devcheck.mjs/types/devcheck.d.mts
from files, and trimmed the now-stale devcheck globs out of bundle-size.yml's
dist_paths. devcheck.mjs itself stays in the repo (index.mjs's fire-and-forget
import of it already tolerates a missing file in the published package).
- tests/cjs: node:test checks run by `npm test` and `npm run coverage` after
Vitest: require() returns the same objects as import (type/identity only -
droidsock() opens a real ADB connection, so no call is made), and the version
check fires when require(esm) is off. test:cjs runs with CI=1 so devcheck's
own NODE_OPTIONS guard (unrelated to this fix, source-checkout only) doesn't
process.exit() the test runner.
Shinrai
approved these changes
Oct 3, 2026
cldmv-bot Bot
added a commit
that referenced
this pull request
Oct 5, 2026
# DroidSock v2.0.3 Changelog **Release Date**: October 2026 **Release Type**: Patch **Branch**: `release/2.0.3` --- ## Overview v2.0.3 cleans up the CommonJS entry and the published file list. `index.cjs` now loads the ESM entry with a plain `require()`, which bundlers can follow, and fails with a clear message on Node.js versions that can't `require()` ES modules. The ESM entry and the API itself are unchanged. The release also stops publishing `devcheck.mjs`, a source-checkout-only development check, and removes its `./devcheck` subpath export. Removing an export is technically a breaking change despite this being a patch release, so it's listed under Breaking Changes below. In practice the module did nothing in an installed copy of the package. --- ## 💥 Breaking Changes ### `@cldmv/droidsock/devcheck` is no longer exported or published ([#58](#58)) `package.json` no longer lists a `./devcheck` export, and `devcheck.mjs` and `types/devcheck.d.mts` are no longer in the published files. Importing `@cldmv/droidsock/devcheck` now fails with `ERR_PACKAGE_PATH_NOT_EXPORTED`. The module was never part of the documented API. It has no exports; its only job is to warn a developer working in a source checkout who forgot to set `NODE_OPTIONS=--conditions=droidsock-dev`. It only acts when a `src/` folder sits next to it, and the published package has no `src/`, so importing it from an installed copy did nothing. `index.mjs` still loads it fire-and-forget and already tolerates it being missing, so the main entry is unaffected. **Upgrade step:** if anything imports `@cldmv/droidsock/devcheck`, delete that import. Nothing replaces it, because it never did anything outside this repository. ## 🐛 Bug Fixes ### Require the ESM entry directly, and fail clearly without `require(esm)` ([#58](#58)) `index.cjs` used `createRequire(__filename)` to load `index.mjs`. That idiom predates Node's native `require(esm)`, and bundlers such as esbuild and webpack don't follow a `createRequire`-constructed `require` the way they follow a literal `require()` call, so a CommonJS build that bundled droidsock could miss the ESM entry. - `index.cjs` now calls `require("./index.mjs")` directly and exports the same functions as before (`module.exports` is the `droidsock` quick path, with `createDroidSock`, `DroidSock`, `ADB` and `AndroidDebugBridge` as properties). - On a Node.js version without `require(esm)` (before 20.19.0, or 22.0.0 to 22.11.x), `index.cjs` throws an `ERR_REQUIRE_ESM` error whose message names the supported versions and points to `import()`, instead of a bare loader error. The package's `engines.node` is already `>=22.12.0`, so this only matters for installs that ignore `engines`. - `index.mjs` already avoided top-level `await`, so it needed no change. - New `tests/cjs/entry.test.cjs` checks run under Node's own test runner after Vitest, from both `npm test` and `npm run coverage` (through the new `test:cjs` script). They check that `require()` returns the same functions as `import`, and that the version check fires when `require(esm)` is turned off. They don't call `droidsock()`, since that opens a real ADB connection. ## 🔧 CI & tooling - `bundle-size.yml` no longer lists the `devcheck` files in `dist_paths`, matching the new published file list ([#58](#58)). ## 📚 Documentation - **NEW:** [docs/changelog/v2/v2.0.3.md](./v2.0.3.md): this changelog. - **NEW:** backfilled [v1.1.1](../v1/v1.1.1.md), [v2.0.1](./v2.0.1.md) and [v2.0.2](./v2.0.2.md). - README restructured to the standard CLDMV layout, with a new Requirements section that states the Node.js floor for `import` and `require()`. ## 🔧 Dependencies Both changes are to development dependencies; the package has no runtime dependency changes and the published package is unaffected. Only `package.json` and the lockfile changed in these bumps, and no file headers were restamped. - `@cldmv/fix-headers` `^2.1.2` → `^2.2.0` ([#61](#61) took it to `^2.1.4`, [#63](#63) to `^2.2.0`). Version 2.1.4 no longer writes a JavaScript comment into JSON or Markdown files, processes every repeated `--input`, and never walks dependency folders such as `node_modules`. Version 2.2.0 makes the `@Last modified by` header tag follow content edits only, so a header-only rewrite keeps the recorded editor instead of replacing it. It requires Node.js `>=22.12.0`, which matches the package's `engines.node`. - `@cldmv/configs` `^1.2.1` → `^1.2.4` ([#63](#63)). It provides the shared `fix-headers` configuration that `.configs/fix-headers.json` extends. Version 1.2.4 turns off `forceAuthorUpdate` and `forceLastModifiedAuthorUpdate` (both were on in 1.2.1), so the shared configuration no longer overwrites the recorded author or last editor. --- ## Upgrade notes - If anything imports `@cldmv/droidsock/devcheck`, remove that import. Nothing else needs to change. - `import droidsock from "@cldmv/droidsock"` and `require("@cldmv/droidsock")` both work as before on Node.js 22.12.0 or later. <details> <summary>👥 Contributors</summary> - @Shinrai </details> --- <!-- coverage-start -->  | Metric | Coverage | |--------|----------| | Statements | 93.0% | | Branches | 85.3% | | Functions | 94.4% | | Lines | 94.5% | *Avg: **91.8%** · `d7d1cb5` · Node lts/** <!-- coverage-end --> <!-- co-authors --> Co-authored-by: Shinrai <Shinrai@users.noreply.github.com>
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.
🚀 What's Changed
💥 Breaking Changes
No breaking changes
✨ Features
No new features
🐛 Bug Fixes
📦 Dependencies
No dependency updates
🔧 Other Changes
No other changes
👥 Contributors