Skip to content

fix: leave declaration files that carry tsc's copy of the source header alone - #196

Merged
Shinrai merged 1 commit into
nextfrom
fix/declaration-header-copies
Nov 25, 2026
Merged

Shinrai merged 1 commit into
nextfrom
fix/declaration-header-copies

Conversation

@cldmv-bot

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

Copy link
Copy Markdown
Contributor

tsc copies a source file's header into the declaration it emits, so fix-headers and tsc kept flipping @Filename in committed types/. The node detector now skips a .d.ts/.d.mts/.d.cts whose header names its own source (x.d.mts ← x.mts/x.mjs, x.d.ts ← x.ts/x.tsx/x.js/x.jsx, x.d.cts ← x.cts/x.cjs). Declarations with no header, or one naming any other file, are fixed as before.

Resolves #195

…er alone

tsc copies a source file's header into the .d.ts/.d.mts/.d.cts it emits,
@filename included, so fix-headers and tsc kept rewriting each other's
@filename on every run. The node detector now skips a declaration file
whose header names its own source (x.d.mts from x.mts/x.mjs, x.d.ts from
x.ts/x.tsx/x.js/x.jsx, x.d.cts from x.cts/x.cjs). Declarations with no
header, or a header naming any other file, are fixed as before.

Detectors' resolveContentSkipReason now also receives the file path.

Resolves #195
@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 type: documentation Relates to docs, README updates, guides, or inline code comments labels Nov 25, 2026
@Shinrai
Shinrai merged commit 19edcaf into next Nov 25, 2026
36 checks passed
@cldmv-bot
cldmv-bot Bot deleted the fix/declaration-header-copies branch November 25, 2026 20:58
Shinrai added a commit that referenced this pull request Nov 25, 2026
`@Filename` is the path relative to the project root, so it's now
written as `src/index.mjs` instead of `/src/index.mjs`. A header with
the old leading slash is rewritten on the next run and keeps its `@Last
modified by`, so picking this up in a repo is a header-only change.
README examples are updated to match. The declaration-copy check from
#196 compares only the file name, so it works with both forms.

The second commit restamps this repo's own headers with the new form.

Resolves #198
Shinrai added a commit that referenced this pull request Nov 25, 2026
Release notes for v2.4.0: `docs/changelog/v2/v2.4.0.md` covering #196
and #199, and README What's New promoted to v2.4.0 (v2.3.0 moves into
Recent Releases, v2.2.4 drops off).
cldmv-bot Bot added a commit that referenced this pull request Nov 25, 2026
# `@cldmv/fix-headers` v2.4.0 Changelog

**Release Date**: November 2026
**Release Type**: Minor
**Branch**: `release/2.4.0`

---

## Overview

`@Filename` is now written without a leading slash. It is the file's path relative to the project root, and `/src/index.mjs` read as an absolute path, so it is written as `src/index.mjs`. Headers written by earlier versions are rewritten on the next run.

Declaration files that `tsc` emits with a copy of their source's header are now left alone, so `tsc` and fix-headers stop rewriting each other's `@Filename` in committed `types/` folders.

---

## ✨ Features

### `@Filename` without a leading slash ([#199](#199))

`src/index.mjs` → `@Filename: src/index.mjs` (was `/src/index.mjs`). A file with no project root above it gets just its file name. An existing header with the leading slash is rewritten on the next run like any other stale field: only the `@Filename` line and `@Last modified time` change, and the recorded `@Last modified by` is kept because the file's content was not edited.

Fixes [#198](#198).

## 🐛 Bug Fixes

### Declarations carrying `tsc`'s copy of the source header are skipped ([#196](#196))

`tsc` copies a source file's leading comment into the `.d.ts` / `.d.mts` / `.d.cts` it emits, so a generated `types/src/x.d.mts` carried `@Filename` naming `src/x.mts`. fix-headers rewrote it to the declaration's own path, and the next `tsc` build wrote it back, so every build and every fix-headers run changed the committed declarations. A declaration whose header names its own source is now reported in `skipped` and left as `tsc` wrote it. The pairs are `x.d.mts` from `x.mts` / `x.mjs`, `x.d.ts` from `x.ts` / `x.tsx` / `x.js` / `x.jsx`, and `x.d.cts` from `x.cts` / `x.cjs`; the check compares file names only, so both the old slashed and the new `@Filename` form match. A declaration with no header, or one naming any other file (a hand-written declaration that was moved or renamed), is fixed as before.

Fixes [#195](#195).

## 📚 Documentation

- **NEW:** [docs/changelog/v2/v2.4.0.md](https://github.com/CLDMV/fix-headers/blob/v2.4.0/docs/changelog/v2/v2.4.0.md): this changelog.
- README: every `@Filename` example uses the slashless form, the project-root rules say so, and the skip rules describe generated declaration files ([#196](#196), [#199](#199)).
- README What's New promoted to v2.4.0.

## 🔧 Dependencies

_No dependency updates._

---

## Upgrade notes

- The first run after upgrading rewrites the `@Filename` line (and `@Last modified time`) in every file that has a header. Land it on its own, as a header-only commit, when no open PRs touch the same files.
- `@Last modified by` and `@Author` are kept on that run.
- Generated declarations whose header names their own source now show up in `skipped`; nothing else about how declarations are handled changes.



<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%** · `a32ffe5` · 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 type: documentation Relates to docs, README updates, guides, or inline code comments

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant