Skip to content

fix(cjs): require the ESM entry directly and fail clearly on Node without require(esm) - #48

Merged
Shinrai merged 1 commit into
nextfrom
fix/cjs-require-esm-check
Oct 3, 2026
Merged

Shinrai merged 1 commit into
nextfrom
fix/cjs-require-esm-check

Conversation

@cldmv-bot

@cldmv-bot cldmv-bot Bot commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

🚀 What's Changed

💥 Breaking Changes

No breaking changes

✨ Features

No new features

🐛 Bug Fixes

  • fix(cjs): require the ESM entry directly and fail clearly on Node without require(esm) (50023db)

📦 Dependencies

No dependency updates

🔧 Other Changes

No other changes

👥 Contributors

…hout require(esm)

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 (the devcheck import already ran
  inside a fire-and-forget async IIFE), so no change was needed there.
- tests/cjs: node:test checks run by `npm test` and `npm run coverage` after
  Vitest: require() returns the same objects as import, and the version
  check fires when require(esm) is off.
@cldmv-bot cldmv-bot Bot added ! fix → next v4 flow: fix contributor PR targeting the next integration branch area: tests Touches test files, fixtures, or test infrastructure type: dependencies Relates to dependency updates, version bumps, or package management labels Oct 3, 2026
@Shinrai
Shinrai merged commit a488f20 into next Oct 3, 2026
31 checks passed
@cldmv-bot
cldmv-bot Bot deleted the fix/cjs-require-esm-check branch October 3, 2026 17:54
cldmv-bot Bot added a commit that referenced this pull request Oct 3, 2026
# HoldMyTask v2.0.4 Changelog

**Release Date**: October 2026
**Release Type**: Patch

---

## Overview

v2.0.4 makes the CommonJS entry fail clearly on Node.js versions that cannot `require()` an ES module, picks up a fix for a medium-severity denial-of-service advisory in `brace-expansion` (a development-time dependency), and moves two development tools forward. Behavior on supported Node.js versions is unchanged.

---

## 🐛 Bug Fixes

### CommonJS entry requires the ESM entry directly and fails clearly on older Node.js ([#48](#48))

`index.cjs` is a thin wrapper that loads `index.mjs` through Node's synchronous `require(esm)`. It now calls `require("./index.mjs")` directly instead of going through `createRequire`, and checks `process.features.require_module` first. On a Node.js version without `require(esm)` (before 20.19 and 22.12), `require("@cldmv/holdmytask")` used to die with a bare `ERR_REQUIRE_ESM`; it now throws an error with the same code and a message that names the supported versions (`^20.19.0` or `>=22.12.0`) and suggests loading the package with `import()` instead. On Node.js versions that support `require(esm)` the module resolves exactly as before. The new `tests/cjs/entry.test.cjs` runs under `node --test` (through the new `test:cjs` script, also part of `npm test` and `npm run coverage`) and checks that `require()` and `import` return the same object and that the error appears when `require(esm)` is disabled.

---

## 🔒 Security & supply chain

### brace-expansion 5.0.9 → 5.0.12 ([#44](#44))

Fixes [GHSA-q2hr-2g5m-vwhr](GHSA-q2hr-2g5m-vwhr) (CVE-2026-102277, medium, CVSS 5.3): expanding `{a},b}`-shaped input took quadratic time in the number of literal `}` characters, so an untrusted pattern could block the event loop. `brace-expansion` is a development-only dependency, pulled in solely by `minimatch` in the lint and test toolchain, and the package has no runtime dependencies, so the shipped code never loaded it. The update clears the open Dependabot alert on the lockfile.

## 🔧 Dependencies

- `@eslint/css` 1.4.0 → 2.0.0 (development; [#43](#43)). The major release adds `meta.languages` to the CSS rules. `npm run lint` passes unchanged with the repo's `css/recommended` configuration.
- `prettier` 3.9.6 → 3.9.9 (development; [#41](#41)). Lockfile-only: the `^3.0.0` range in `package.json` already allowed it.

## 🔧 CI & tooling

- The header comments in the generated `types/*.d.mts` files and their source maps were refreshed to the shared file-header format. Only comments changed; no type declarations differ from v2.0.3.

---

## Upgrade notes

No breaking changes — drop-in for [v2.0.3](./v2.0.3.md). The only runtime-visible difference is the clearer error for `require()` on Node.js versions that already could not load the package.



<details>
<summary>👥 Contributors</summary>

- @Shinrai

</details>

---

<!-- coverage-start -->

![coverage](https://img.shields.io/badge/coverage-76.2%25-green?style=for-the-badge&logo=vitest&logoColor=white)

| Metric | Coverage |
|--------|----------|
| Statements | 79.7% |
| Branches   | 73.6% |
| Functions  | 71.1% |
| Lines      | 80.7% |

*Avg: **76.2%** · `dc7821b` · Node lts/**

<!-- coverage-end -->

<!-- co-authors -->

Co-authored-by: Shinrai <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: tests Touches test files, fixtures, or test infrastructure ! fix → next v4 flow: fix contributor PR targeting the next integration branch type: dependencies Relates to dependency updates, version bumps, or package management

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant