Skip to content

feat: restamp tsc-copied declaration headers by default - #202

Merged
Shinrai merged 3 commits into
nextfrom
feat/generated-declarations
Nov 25, 2026
Merged

Shinrai merged 3 commits into
nextfrom
feat/generated-declarations

Conversation

@cldmv-bot

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

Copy link
Copy Markdown
Contributor

Generated declarations are what an IDE shows, so a .d.ts/.d.mts/.d.cts carrying tsc's copy of its source's header now gets a header for where it ships: @Filename: types/src/x.d.mts and that package's @Project. A staged package folder with its own package.json is its own root, so dist-packages/x-types/lib/x.d.mts gets @Filename: lib/x.d.mts. @Date, @Author, @Last modified by and @Last modified time are kept from the source's header, and a later run leaves a restamped declaration that git doesn't track as it is, since the generated file has no git history.

rewriteDeclarationCopies: false (--no-rewrite-declaration-copies) keeps the 2.4.0 skip for repos that still commit types/. This repo sets it until its own types/ moves out of git.

Resolves #201

@cldmv-bot cldmv-bot Bot added ! feature → next v4 flow: contributor PR targeting the next integration branch type: feature Implements new functionality — a PR or issue that adds a feature area: core Touches core library / runtime source code area: tests Touches test files, fixtures, or test infrastructure type: ci Changes to CI workflows, actions, or build pipelines type: config Changes to repository or project configuration files type: dependencies Relates to dependency updates, version bumps, or package management type: documentation Relates to docs, README updates, guides, or inline code comments labels Nov 25, 2026
For packages that build types/ in CI or prepack instead of committing it.
With rewriteDeclarationCopies (--rewrite-declaration-copies), a .d.ts /
.d.mts / .d.cts carrying tsc's copy of its own source's header is
restamped instead of skipped: @filename and @project follow the path and
package it ships in (a staged package folder with its own package.json is
its own project root), and @Date, @author, @last modified by and
@last modified time stay as the source's header has them. Skipping stays
the default.

Resolves #201
Generated declarations are what an IDE shows, so they get a header for the
path and package they ship in by default. rewriteDeclarationCopies: false
(--no-rewrite-declaration-copies) skips them, for repos that still commit
types/; this repo sets it until its types/ moves out of git.

Resolves #201
@Shinrai
Shinrai force-pushed the feat/generated-declarations branch from e2b686d to 4e3edd7 Compare November 25, 2026 21:54
@Shinrai Shinrai changed the title feat: rewriteDeclarationCopies restamps tsc-copied declaration headers feat: restamp tsc-copied declaration headers by default Nov 25, 2026
A gitignored declaration counted as edited on every run, so a second run
restamped it with the runner and the current time. A declaration git does
not track that already has a header is now treated as generated and keeps
the editor and dates it carries.
@Shinrai
Shinrai merged commit 1c73081 into next Nov 25, 2026
33 checks passed
@cldmv-bot
cldmv-bot Bot deleted the feat/generated-declarations branch November 25, 2026 22:06
Shinrai added a commit that referenced this pull request Nov 25, 2026
Release notes for v2.5.0: `docs/changelog/v2/v2.5.0.md` covering #202,
and README What's New promoted to v2.5.0 (v2.4.0 moves into Recent
Releases, v2.2.5 drops off).
cldmv-bot Bot added a commit that referenced this pull request Nov 25, 2026
# `@cldmv/fix-headers` v2.5.0 Changelog

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

---

## Overview

Generated TypeScript declarations get a header of their own. `tsc` copies a source file's header into the `.d.ts` / `.d.mts` / `.d.cts` it emits, so the declaration an IDE shows named the source file. fix-headers now restamps such a declaration for the path and package it ships in, keeping the source's dates and author. This is the setup for packages that build `types/` in CI or `prepack` instead of committing it.

---

## ✨ Features

### Generated declarations are restamped for where they ship ([#202](#202))

A declaration whose header names its own source (`types/src/x.d.mts` with `@Filename: src/x.mts`) gets `@Filename: types/src/x.d.mts` and its package's `@Project`. `@Date`, `@Author`, `@Last modified by` and `@Last modified time` stay as the source's header has them, since a generated file has no git history of its own. A staged package folder with its own `package.json` is its own project root, so `dist-packages/x-types/lib/x.d.mts` gets `@Filename: lib/x.d.mts` and that package's name. Run fix-headers after `tsc`, for example `fix-headers --input types` in `prepack` or CI.

A later run leaves a restamped declaration as it is when git doesn't track it: a declaration with a header that git doesn't track is treated as generated, so it keeps the editor and dates it carries instead of taking the runner and the current time.

`rewriteDeclarationCopies: false` (CLI `--no-rewrite-declaration-copies`) keeps the 2.4.0 behaviour of skipping these declarations, for repos that still commit `types/`.

Fixes [#201](#201).

## 📚 Documentation

- **NEW:** [docs/changelog/v2/v2.5.0.md](https://github.com/CLDMV/fix-headers/blob/v2.5.0/docs/changelog/v2/v2.5.0.md): this changelog.
- README: the `rewriteDeclarationCopies` option and `--rewrite-declaration-copies` / `--no-rewrite-declaration-copies` flags, and the generated-declaration rule ([#202](#202)).
- README What's New promoted to v2.5.0.

## 🔧 Dependencies

_No dependency updates._

---

## Upgrade notes

- **Repos that commit generated `types/`:** set `"rewriteDeclarationCopies": false` in the fix-headers config. Otherwise fix-headers and `tsc` rewrite each other's `@Filename` on every build, as before 2.4.0. The better fix is to gitignore `types/` and build it in CI and `prepack`.
- Repos that don't run fix-headers on declaration files see no change.



<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.9% |
| Functions  | 100.0% |
| Lines      | 99.9% |

*Avg: **99.6%** · `9f69cbb` · 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 ! feature → next v4 flow: contributor PR targeting the next integration branch type: ci Changes to CI workflows, actions, or build pipelines type: config Changes to repository or project configuration files type: dependencies Relates to dependency updates, version bumps, or package management type: documentation Relates to docs, README updates, guides, or inline code comments type: feature Implements new functionality — a PR or issue that adds a feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant