Skip to content

fix(cjs): keep .default and the ESM names on require() - #222

Merged
Shinrai merged 4 commits into
nextfrom
fix/cjs-shim-names
Nov 29, 2026
Merged

Shinrai merged 4 commits into
nextfrom
fix/cjs-shim-names

Conversation

@cldmv-bot

@cldmv-bot cldmv-bot Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

🚀 What's Changed

💥 Breaking Changes

No breaking changes

✨ Features

No new features

🐛 Bug Fixes

📦 Dependencies

No dependency updates

🔧 Other Changes

👥 Contributors

require() returns the fixHeaders function again with .default and .fixHeaders set on it, so require(x).default and const { fixHeaders } = require(x) work as before.
@cldmv-bot cldmv-bot Bot added ! fix → next v4 flow: fix contributor PR targeting the next integration branch area: core Touches core library / runtime source code area: tests Touches test files, fixtures, or test infrastructure labels Nov 29, 2026
The test already checks that dist/index.cjs is byte-for-byte the src/
shim and that it loads ./index.mjs, so a size cap adds nothing and only
breaks when the shim or its header grows.
Replaces the old size cap. The hash covers everything below the
fix-headers file header, so restamped dates don't change it but any edit
to the shim does. Also corrects the shim's doc comment to say require()
carries .default and .fixHeaders.
@Shinrai
Shinrai merged commit 753568f into next Nov 29, 2026
34 checks passed
@cldmv-bot
cldmv-bot Bot deleted the fix/cjs-shim-names branch November 29, 2026 04:46
cldmv-bot Bot added a commit that referenced this pull request Nov 29, 2026
# `@cldmv/fix-headers` v2.6.2 Changelog

**Release Date**: November 2026
**Release Type**: Patch
**Branch**: `next` → `master`

---

## Overview

The CommonJS entry now follows the usual CommonJS convention of an export plus `.default` and its names. For fix-headers `require("@cldmv/fix-headers")` is still the `fixHeaders` function, as before, and it now also carries `.default` and `.fixHeaders`, so `require(x).default`, `require(x).fixHeaders` and `const { fixHeaders } = require(x)` all work. The release also bumps the repository's dev tools; fix-headers' options and header output are unchanged.

---

## 🐛 Bug Fixes

### CJS shim keeps `.default` and the ESM names on `require()` ([#222](#222))

`src/index.cjs` is the generic CLDMV drop-in shim. Its earlier version returned a lone exported value bare, with no names on it, which left `require(x).default` and destructured named imports undefined. The shim now attaches `.default` and every ESM export name to that value when all the exports are one function or object, and returns the module object, as before, when the entry exports several distinct values.

fix-headers' `src/index.mjs` exports `fixHeaders` as both a named and the default export, so all its exports are one value:

- Before: `require("@cldmv/fix-headers")` was the `fixHeaders` function, with no `.default` and no `.fixHeaders`.
- Now: it is the same function, carrying `.default` and `.fixHeaders`, both pointing back at the function. Calling `require(x)(options)` works exactly as before.

The tests assert the new properties, and the integration test no longer caps `dist/index.cjs` at 2 KB. It compares a sha256 of the shim body, with the fix-headers file header stripped so restamped dates don't matter, against the reviewed version, so the build can't drift from the shared shim unnoticed.

---

## 🔧 Dependencies

Development dependencies only; the runtime dependency (`ignore`) is unchanged ([#224](#224)).

- `@cldmv/vitest-runner` 1.11.3 → 1.11.4.
- `@cldmv/eslint-plugin-jsonv` `^1.0.10` → `^2.0.0` (locked 1.1.2 → 2.0.0), `@cldmv/jsonv` and `@cldmv/prettier-plugin-jsonv` to `^1.2.4`.
- `@cldmv/configs` stays at 1.5.0.

## 📚 Documentation

- **NEW:** [docs/changelog/v2/v2.6.2.md](https://github.com/CLDMV/fix-headers/blob/v2.6.2/docs/changelog/v2/v2.6.2.md), this changelog.
- README What's New promoted to v2.6.2.

---

## Upgrade notes

- Nothing to do. `require("@cldmv/fix-headers")` still returns the `fixHeaders` function; it just has `.default` and `.fixHeaders` on it too. The behaviour matches [v2.6.1](https://github.com/CLDMV/fix-headers/blob/v2.6.2/docs/changelog/v2/v2.6.1.md).



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

- @Shinrai

</details>

---

<!-- coverage-start -->

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

| Metric | Coverage |
|--------|----------|
| Statements | 99.9% |
| Branches   | 98.8% |
| Functions  | 100.0% |
| Lines      | 99.9% |

*Avg: **99.6%** · `8a9d2fd` · 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: core Touches core library / runtime source code area: tests Touches test files, fixtures, or test infrastructure ! fix → next v4 flow: fix contributor PR targeting the next integration branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant