@cldmv/fix-headers 1.3.12 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +313 -25
- package/bin/fix-headers.mjs +70 -0
- package/dist/index.cjs +28 -0
- package/dist/index.mjs +23 -0
- package/package.json +39 -19
- package/types/src/cli.d.mts +20 -2
- package/types/src/config/load.d.mts +36 -0
- package/types/src/constants.d.mts +1 -23
- package/types/src/core/file-discovery.d.mts +17 -5
- package/types/src/core/fix-headers.d.mts +59 -4
- package/types/src/core/ignore-rules.d.mts +38 -0
- package/types/src/detect/project.d.mts +64 -15
- package/types/src/detectors/css.d.mts +0 -8
- package/types/src/detectors/go.d.mts +0 -8
- package/types/src/detectors/html.d.mts +0 -8
- package/types/src/detectors/index.d.mts +28 -7
- package/types/src/detectors/json.d.mts +0 -8
- package/types/src/detectors/node.d.mts +0 -8
- package/types/src/detectors/php.d.mts +0 -8
- package/types/src/detectors/python.d.mts +0 -8
- package/types/src/detectors/rust.d.mts +0 -8
- package/types/src/detectors/yaml.d.mts +0 -8
- package/types/src/drivers/go.d.mts +2 -0
- package/types/src/drivers/index.d.mts +154 -0
- package/types/src/drivers/node.d.mts +2 -0
- package/types/src/drivers/php.d.mts +2 -0
- package/types/src/drivers/python.d.mts +2 -0
- package/types/src/drivers/rust.d.mts +2 -0
- package/types/src/drivers/shared.d.mts +78 -0
- package/types/src/header/dates.d.mts +108 -0
- package/types/src/header/fields.d.mts +48 -0
- package/types/src/header/template.d.mts +4 -3
- package/types/src/utils/diff.d.mts +53 -0
- package/types/src/utils/fs.d.mts +10 -3
- package/types/src/utils/git.d.mts +27 -0
- package/types/src/utils/time.d.mts +55 -0
- package/index.cjs +0 -39
- package/index.mjs +0 -20
- package/src/cli.mjs +0 -323
- package/src/constants.mjs +0 -50
- package/src/core/file-discovery.mjs +0 -213
- package/src/core/fix-headers.mjs +0 -413
- package/src/detect/project.mjs +0 -190
- package/src/detectors/css.mjs +0 -67
- package/src/detectors/go.mjs +0 -65
- package/src/detectors/html.mjs +0 -67
- package/src/detectors/index.mjs +0 -187
- package/src/detectors/json.mjs +0 -76
- package/src/detectors/node.mjs +0 -90
- package/src/detectors/php.mjs +0 -66
- package/src/detectors/python.mjs +0 -75
- package/src/detectors/rust.mjs +0 -62
- package/src/detectors/shared.mjs +0 -45
- package/src/detectors/yaml.mjs +0 -79
- package/src/fix-header.mjs +0 -30
- package/src/header/parser.mjs +0 -145
- package/src/header/syntax.mjs +0 -69
- package/src/header/template.mjs +0 -65
- package/src/utils/fs.mjs +0 -138
- package/src/utils/git.mjs +0 -135
- package/src/utils/time.mjs +0 -44
- package/types/src/detectors/shared.d.mts +0 -14
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -8,14 +8,33 @@ Multi-language source header normalizer for Node.js projects.
|
|
|
8
8
|
|
|
9
9
|
[![Contributors]][contributors_url] [![Sponsor shinrai]][sponsor_url]
|
|
10
10
|
|
|
11
|
+
## ✨ What's New
|
|
12
|
+
|
|
13
|
+
### Latest: v2.0.0 (September 2026)
|
|
14
|
+
|
|
15
|
+
- **Breaking: built package, discovery and `@Project`** — npm now ships a tsup-built `dist/` and `bin/` instead of `src/`, so deep imports into `src/` stop resolving; the package entry point and the `fix-headers` binary work as before ([#56](https://github.com/CLDMV/fix-headers/pull/56), [#65](https://github.com/CLDMV/fix-headers/pull/65), [#78](https://github.com/CLDMV/fix-headers/pull/78)). Nothing is skipped by name any more: `node_modules`, `dist`, `build`, `coverage`, `tmp`, `.next` and `.turbo` are processed unless an ignore file (everything git honours) or `excludeFolders` excludes them ([#73](https://github.com/CLDMV/fix-headers/pull/73)). `@Project` and the project root come from the project's manifest (`package.json`, `pyproject.toml`, `Cargo.toml`, …) whatever the file's type, so some CSS, HTML, YAML, JSON and Python headers are rewritten on the next run ([#72](https://github.com/CLDMV/fix-headers/pull/72), [#75](https://github.com/CLDMV/fix-headers/pull/75)). The `@Copyright` holder has no built-in default: it is the manifest's author unless `companyName` is set, and is left out when there is none; the start year is the year of each file's `@Date` ([#91](https://github.com/CLDMV/fix-headers/pull/91), [#89](https://github.com/CLDMV/fix-headers/pull/89)). Preview the first run with `--dry-run --diff --verbose`.
|
|
16
|
+
- **Date checks, time zones, header diffs and include options** — `--check` validates header dates without writing and exits `1` on drift, `@Date` follows "oldest wins" across the header, git and the filesystem, and mismatched epochs are repaired ([#67](https://github.com/CLDMV/fix-headers/pull/67)); an opt-in `--timezone` writes, and `--convert-timezone` sweeps, header dates into one IANA zone ([#81](https://github.com/CLDMV/fix-headers/pull/81)). `--diff` prints a unified header diff and `sampleOutput` lists per-field issues ([#66](https://github.com/CLDMV/fix-headers/pull/66)); `includeFolders` takes non-recursive entries and never processes a file twice ([#60](https://github.com/CLDMV/fix-headers/pull/60)); a config file can `extends` a shared config by URL, npm package or path ([#88](https://github.com/CLDMV/fix-headers/pull/88)).
|
|
17
|
+
- [View full v2.0.0 Changelog](https://github.com/CLDMV/fix-headers/blob/master/docs/changelog/v2/v2.0.0.md)
|
|
18
|
+
|
|
19
|
+
### Recent Releases
|
|
20
|
+
|
|
21
|
+
- **v1.3.12** (September 2026) — `engines.node` raised to `>=22.12.0` with the move to vitest 5; `ignore` bumped to 7.0.8 ([#38](https://github.com/CLDMV/fix-headers/pull/38), [#40](https://github.com/CLDMV/fix-headers/pull/40), [#43](https://github.com/CLDMV/fix-headers/pull/43)) ([Release](https://github.com/CLDMV/fix-headers/releases/tag/v1.3.12))
|
|
22
|
+
- **v1.3.11** (September 2026) — CI and release automation only, no runtime change: bot identity and GPG secrets passed to the v4 release and hotfix-redirect workflows ([#32](https://github.com/CLDMV/fix-headers/pull/32), [#36](https://github.com/CLDMV/fix-headers/pull/36)) ([Release](https://github.com/CLDMV/fix-headers/releases/tag/v1.3.11))
|
|
23
|
+
- **v1.3.10** (August 2026) — tests only, no runtime change: fallback-path tests run in a workspace with no project ancestry ([#28](https://github.com/CLDMV/fix-headers/pull/28)) ([Release](https://github.com/CLDMV/fix-headers/releases/tag/v1.3.10))
|
|
24
|
+
- **v1.3.9** (August 2026) — an existing header's `@Last modified by` identity is preserved unless `forceLastModifiedAuthorUpdate` / `--force-last-modified-author-update` is set, so a different local git identity no longer rewrites headers tree-wide ([#25](https://github.com/CLDMV/fix-headers/pull/25)) ([Release](https://github.com/CLDMV/fix-headers/releases/tag/v1.3.9))
|
|
25
|
+
|
|
26
|
+
📚 For complete release notes, see the [docs/changelog/](https://github.com/CLDMV/fix-headers/tree/master/docs/changelog/) folder and the [GitHub Releases](https://github.com/CLDMV/fix-headers/releases).
|
|
27
|
+
|
|
11
28
|
## Features
|
|
12
29
|
|
|
13
|
-
-
|
|
30
|
+
- Finds the project each file belongs to from its manifest (`package.json`, `pyproject.toml` / `setup.cfg` / `setup.py`, `composer.json`, `Cargo.toml`, `go.mod`), whatever the file's type
|
|
31
|
+
- `@Project` is the name from that project's manifest, so a CSS, HTML, YAML or JSON file in a Python, PHP, Rust or Go project gets that project's name too; the folder name is used only when no manifest provides one. Override it with `projectName`. See [Project name and root](#project-name-and-root)
|
|
14
32
|
- Auto-detects author and email from git config/commit history
|
|
15
33
|
- Supports per-run overrides for every detected value
|
|
16
|
-
- Supports folder inclusion and exclusion configuration
|
|
17
|
-
- Supports
|
|
34
|
+
- Supports folder inclusion and exclusion configuration; skips only what the project's ignore files (everything git honours) or your own exclusions say
|
|
35
|
+
- Supports monorepos: every file resolves its own project from the nearest manifest in its parent tree
|
|
18
36
|
- Supports per-detector syntax overrides for line and block comment tokens
|
|
37
|
+
- Config files can use `extends` to build on a shared config (an https URL, an npm package path or a file path), so one organisation-wide config serves every repository. See [Shared configs](#shared-configs)
|
|
19
38
|
- Supports both ESM and CJS consumers
|
|
20
39
|
|
|
21
40
|
## Install
|
|
@@ -51,22 +70,31 @@ npm run cli -- --dry-run --json
|
|
|
51
70
|
Common CLI options:
|
|
52
71
|
|
|
53
72
|
- `--dry-run`
|
|
73
|
+
- `--check` - validate header dates without writing; exits `1` on date drift (see [Date checks](#date-checks))
|
|
74
|
+
- `--fix-created-date`
|
|
75
|
+
- `--strict-created-date`
|
|
76
|
+
- `--normalize-date-format`
|
|
77
|
+
- `--timezone <name>` - write new header dates in an IANA time zone (see [Time zone](#time-zone))
|
|
78
|
+
- `--convert-timezone` - with `--timezone`, also rewrite existing header dates into that zone
|
|
54
79
|
- `--json`
|
|
55
|
-
- `--sample-output`
|
|
80
|
+
- `--verbose` - list updated files; together with `--sample-output` or `--diff`, also list each file's field differences (`authorName: found "X", expected "Y"`)
|
|
81
|
+
- `--sample-output` - print the previous/new header and detected values for each changed file
|
|
82
|
+
- `--diff` - print a unified diff of each changed file's header (implies sample output)
|
|
56
83
|
- `--force-author-update`
|
|
57
84
|
- `--force-last-modified-author-update`
|
|
58
|
-
- `--use-gpg-signer-author`
|
|
85
|
+
- `--use-gpg-signer-author` (the signing key's UID name, with the OpenPGP UID comment dropped)
|
|
59
86
|
- `--cwd <path>`
|
|
60
87
|
- `--input <path>`
|
|
61
88
|
- `--include-folder <path>` (repeatable)
|
|
89
|
+
- `--include-folder-non-recursive <path>` (repeatable) - include only that folder's own files, not its subfolders
|
|
62
90
|
- `--exclude-folder <path>` (repeatable)
|
|
63
91
|
- `--include-extension <ext>` (repeatable)
|
|
64
92
|
- `--enable-detector <id>` / `--disable-detector <id>` (repeatable)
|
|
65
93
|
- `--project-name <name>`
|
|
66
94
|
- `--author-name <name>` / `--author-email <email>`
|
|
67
|
-
- `--company-name <name>`
|
|
68
|
-
- `--copyright-start-year <year>`
|
|
69
|
-
- `--config <json-file>`
|
|
95
|
+
- `--company-name <name>` - the `@Copyright` holder for every file, instead of the one the manifests provide (see [Copyright holder](#copyright-holder))
|
|
96
|
+
- `--copyright-start-year <year>` - the `@Copyright` start year for every file (default: the year of each file's `@Date`)
|
|
97
|
+
- `--config <json-file>` - load options from a JSON file, which may use `extends` to build on shared configs (see [Shared configs](#shared-configs)); flags on the command line win over the file
|
|
70
98
|
|
|
71
99
|
### CommonJS
|
|
72
100
|
|
|
@@ -87,27 +115,33 @@ Important options:
|
|
|
87
115
|
- `cwd?: string` - start directory for project detection
|
|
88
116
|
- `input?: string` - explicit single file or folder path to process
|
|
89
117
|
- `dryRun?: boolean` - compute changes without writing files
|
|
90
|
-
- `
|
|
91
|
-
- `
|
|
118
|
+
- `check?: boolean` - validate each existing header's dates and write nothing (implies `dryRun`). Each result entry gets `dateIssues`, and the result gets `filesWithDateDrift` and `dateAdvisories`. See [Date checks](#date-checks)
|
|
119
|
+
- `fixCreatedDate?: boolean` - move an existing `@Date` back to the oldest of itself, the file's git first commit, and its filesystem creation time (see [Creation date](#creation-date)). It only ever moves `@Date` earlier. Off by default: an existing `@Date` is kept as written
|
|
120
|
+
- `strictCreatedDate?: boolean` - with `check`, count a `@Date` later than the file's git first commit or filesystem creation time as drift (fails the run). Off by default, where it is an advisory
|
|
121
|
+
- `normalizeDateFormat?: boolean` - write every header date in the git `%aI` form (`2026-03-01T17:59:32-08:00`), keeping each date's offset and instant. Off by default; the first run rewrites (and restamps) every managed file whose dates use the space form (`2026-03-01 17:59:32 -08:00`)
|
|
122
|
+
- `timezone?: string` - an IANA time zone name (`America/Los_Angeles`, `UTC`, `Asia/Kolkata`, ...). Every date fix-headers writes (a new header's `@Date`, and `@Last modified time`) is expressed in that zone; the instant and its epoch never change. Unset (the default): dates are written as today. An unknown zone name throws. See [Time zone](#time-zone)
|
|
123
|
+
- `convertTimezone?: boolean` - with `timezone`, also rewrite the existing `@Date` and `@Last modified time` values of every header into that zone, keeping each instant. Throws when `timezone` is not set. See [Time zone](#time-zone)
|
|
124
|
+
- `sampleOutput?: boolean` - include a `sample` for each changed file: previous/new header text, a unified `diff`, per-field `issues`, and `detectedValues` (see [Sample output](#sample-output))
|
|
125
|
+
- `configFile?: string` - load JSON options from file (resolved from `cwd`). The file may use `extends` to build on shared configs by URL, npm package path or file path (see [Shared configs](#shared-configs)); options passed in the call win over everything from files
|
|
92
126
|
- `includeExtensions?: string[]` - file extensions to process
|
|
93
127
|
- `enabledDetectors?: string[]` - detector ids to enable (defaults to all)
|
|
94
128
|
- `disabledDetectors?: string[]` - detector ids to disable
|
|
95
129
|
- `detectorSyntaxOverrides?: Record<string, { linePrefix?: string, lineSeparator?: string, blockStart?: string, blockLinePrefix?: string, blockEnd?: string }>` - override detector comment syntax tokens
|
|
96
|
-
- `includeFolders?: string
|
|
97
|
-
- `excludeFolders?: string[]` - folder names or relative paths to exclude
|
|
98
|
-
- `gitignore?: boolean | string | string[]` -
|
|
99
|
-
- `projectName?: string`
|
|
100
|
-
- `language?: string`
|
|
101
|
-
- `projectRoot?: string`
|
|
102
|
-
- `marker?: string | null`
|
|
130
|
+
- `includeFolders?: Array<string | { path: string, recursive?: boolean }>` - project-relative folders to scan. A string entry is scanned recursively; `{ path, recursive: false }` includes only that folder's own files (for example `{ path: ".", recursive: false }` for the project-root files without the whole tree). Overlapping entries are collapsed, so every file is scanned once however the folders nest or are spelled (`"."` next to `"src"`, `"src"` next to `"src/core"`, `"./src"` next to `"src/"`)
|
|
131
|
+
- `excludeFolders?: string[]` - folder names or relative paths to exclude, on top of what the ignore files exclude
|
|
132
|
+
- `gitignore?: boolean | string | string[]` - which ignore files decide what discovery skips. Omitted (or `true`): every ignore file git honours (see [Which files are processed](#which-files-are-processed)). `false`: no ignore files, every file is processed. A path or array of paths (relative to the project root): exactly those files, parsed with `.gitignore` syntax, without asking git.
|
|
133
|
+
- `projectName?: string` - the `@Project` value for every file, instead of the manifest name
|
|
134
|
+
- `language?: string` - the reported `language` for every file (does not change comment syntax or project resolution)
|
|
135
|
+
- `projectRoot?: string` - the project root for every file (the base of `@Filename` and of git history lookups) and the scan root
|
|
136
|
+
- `marker?: string | null` - the reported `marker` for every file
|
|
103
137
|
- `authorName?: string`
|
|
104
138
|
- `authorEmail?: string`
|
|
105
139
|
- `company?: string` - appends to `@Author` as `Name <Company>`
|
|
106
140
|
- `forceAuthorUpdate?: boolean` - force update `@Author`/`@Email` to detected or overridden current values
|
|
107
141
|
- `forceLastModifiedAuthorUpdate?: boolean` - force update `@Last modified by` to detected or overridden current values. Without this, an existing header's recorded `@Last modified by` identity is preserved and does not by itself trigger an update just because the running author differs (e.g. a different `git config user.name` than whoever last touched the file)
|
|
108
|
-
- `useGpgSignerAuthor?: boolean` -
|
|
109
|
-
- `companyName?: string`
|
|
110
|
-
- `copyrightStartYear?: number` (default:
|
|
142
|
+
- `useGpgSignerAuthor?: boolean` - take the detected `@Author` name from the user ID of the OpenPGP key git signs commits with (`user.signingkey`, read through `gpg.openpgp.program` / `gpg.program` / `gpg`; the first user ID that is not revoked or expired). The OpenPGP UID comment is dropped, so `Nate Corcoran (2023 PC) <nate@example.com>` becomes `Nate Corcoran` (with `company: "CLDMV"`: `Nate Corcoran <CLDMV>`). It describes whoever runs the tool, whatever the last commit is — a squash merge made by GitHub or a bot has no locally verifiable signer. With no readable OpenPGP signing key (none configured, `gpg.format` is `ssh`/`x509`, or gpg is unavailable) it falls back to the last commit's signer (`%GS`), then `git config user.name`, then the last commit's author
|
|
143
|
+
- `companyName?: string` - the `@Copyright` holder for every file, instead of the one the project's manifests provide. There is no built-in default: unset, the holder comes from the manifests, and with none it is left out of the line (see [Copyright holder](#copyright-holder))
|
|
144
|
+
- `copyrightStartYear?: number` - the `@Copyright` start year for every file. Unset (the default): each file's start year is the year of its own `@Date`, see [Copyright years](#copyright-years)
|
|
111
145
|
|
|
112
146
|
Example:
|
|
113
147
|
|
|
@@ -116,7 +150,7 @@ const result = await fixHeaders({
|
|
|
116
150
|
cwd: process.cwd(),
|
|
117
151
|
dryRun: false,
|
|
118
152
|
configFile: "fix-headers.config.json",
|
|
119
|
-
includeFolders: ["src", "scripts"],
|
|
153
|
+
includeFolders: ["src", "scripts", { path: ".", recursive: false }],
|
|
120
154
|
excludeFolders: ["src/generated", "dist"],
|
|
121
155
|
detectorSyntaxOverrides: {
|
|
122
156
|
node: {
|
|
@@ -135,13 +169,267 @@ const result = await fixHeaders({
|
|
|
135
169
|
});
|
|
136
170
|
```
|
|
137
171
|
|
|
172
|
+
## Shared configs
|
|
173
|
+
|
|
174
|
+
A config file (`--config <path>` on the CLI, `configFile` in the API) can extend other configs with `extends`, so an organisation keeps its header settings in one place instead of copying them into every repository. `extends` is a string or an array of strings, and each entry is one of:
|
|
175
|
+
|
|
176
|
+
- **An https URL**, fetched on every run. There is no local cache, so every run uses the current shared config. A failed request, a non-2xx response or a body that is not a JSON object fails the run with an error naming the URL. Plain `http://` is accepted only for the local machine (`localhost`, `127.0.0.1`, `[::1]`).
|
|
177
|
+
- **An npm package path**, such as `@cldmv/configs/fix-headers.json`, resolved from the config file's own folder the way Node resolves packages (`require.resolve`), so the package's `exports` map is honoured. Install the package as a dev dependency.
|
|
178
|
+
- **A relative or absolute file path**, resolved from the config file's folder. Relative paths start with `./` or `../`; anything else that is not a URL or an absolute path is treated as a package path.
|
|
179
|
+
|
|
180
|
+
Merge rules:
|
|
181
|
+
|
|
182
|
+
- Extended configs apply in order, then the file's own settings on top, so the repository's file overrides what it extends, and a later `extends` entry overrides an earlier one.
|
|
183
|
+
- Plain objects (such as `detectorSyntaxOverrides`) merge key by key; arrays (such as `includeFolders`) and scalars replace.
|
|
184
|
+
- Extended configs can extend others in turn. A cycle (`a` → `b` → `a`) is an error. Inside a fetched config, relative references (`./base.json`, `../base.json`, `/base.json`) resolve against that config's URL; a fetched config cannot reference an npm package.
|
|
185
|
+
- Options passed directly on the command line or in the `fixHeaders()` call win over everything from files.
|
|
186
|
+
|
|
187
|
+
The CLDMV repositories share one config published as `@cldmv/configs`. A repository's `.configs/fix-headers.json` extends it and adds its own settings:
|
|
188
|
+
|
|
189
|
+
```json
|
|
190
|
+
{
|
|
191
|
+
"extends": "@cldmv/configs/fix-headers.json",
|
|
192
|
+
"includeFolders": ["src", "tests", { "path": ".", "recursive": false }],
|
|
193
|
+
"excludeFolders": ["tests/fixtures"]
|
|
194
|
+
}
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
npm install --save-dev @cldmv/configs
|
|
199
|
+
fix-headers --config .configs/fix-headers.json
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
A shared config can also be served from a URL, and mixed with local files:
|
|
203
|
+
|
|
204
|
+
```json
|
|
205
|
+
{
|
|
206
|
+
"extends": ["https://example.com/configs/fix-headers.json", "./fix-headers.local.json"],
|
|
207
|
+
"projectName": "@scope/my-package"
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## Project name and root
|
|
212
|
+
|
|
213
|
+
Which project a file belongs to depends on the manifests around it, not on the file's type. Comment syntax is the only thing the file's type decides.
|
|
214
|
+
|
|
215
|
+
Each ecosystem has a manifest driver in `src/drivers/`:
|
|
216
|
+
|
|
217
|
+
| Driver | Claims a folder holding | Name | Copyright holder | Native files |
|
|
218
|
+
| -------- | ------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------- |
|
|
219
|
+
| `node` | `package.json` | `name` | `author.company`, else `author.name`, else the name part of a string `author` (`"Name <email> (url)"`) | `.js .mjs .cjs .ts .tsx .jsx` |
|
|
220
|
+
| `python` | `pyproject.toml`, `setup.cfg` or `setup.py` | `pyproject.toml` `[project].name`, then `[tool.poetry].name`; `setup.cfg` `[metadata] name`; `setup.py` `setup(name=...)` | `pyproject.toml` `[project].authors[0].name`, then the name part of `[tool.poetry].authors[0]`; `setup.cfg` `[metadata] author`; `setup.py` `setup(author=...)` | `.py` |
|
|
221
|
+
| `php` | `composer.json` | `name` | `authors[0].name` | `.php` |
|
|
222
|
+
| `rust` | `Cargo.toml` | `[package].name` | the name part of `[package].authors[0]` | `.rs` |
|
|
223
|
+
| `go` | `go.mod` | the `module` path | none (`go.mod` has no author) | `.go` |
|
|
224
|
+
|
|
225
|
+
A manifest claims its folder as soon as it exists and can be read, even when it is malformed or has no name. `requirements.txt` does not claim a folder: it carries no name and often sits in folders that are not projects of their own (`docs/requirements.txt`).
|
|
226
|
+
|
|
227
|
+
For each file:
|
|
228
|
+
|
|
229
|
+
1. **Project root.** Walk up from the file's folder. The nearest folder that at least one driver claims is the project root. `@Filename` is the file's path relative to it, and git history (`@Date`, `@Last modified time`) is looked up from it.
|
|
230
|
+
2. **Order.** When several drivers claim that folder, the file's native driver is read first (a `.py` file reads `python` first), then the fixed order `node`, `python`, `php`, `rust`, `go`. Language-neutral files (CSS, HTML, YAML, JSON, …) use the fixed order.
|
|
231
|
+
3. **Per-field fallback.** Each value is taken from the first driver in that order whose manifest provides it. In a folder with a nameless `package.json` and a named `pyproject.toml`, every file gets the `pyproject.toml` name.
|
|
232
|
+
4. **Climbing.** A value no driver at the project root provides is looked up the same way in each ancestor folder a driver claims, up to and including the scan root (`projectRoot`, else `cwd`), never above it. A nameless sub-package therefore takes the name of the repository around it. Only values climb: the project root, and with it `@Filename` and the git lookups, stays the nearest claimed folder.
|
|
233
|
+
5. **Folder name.** When nothing up to the scan root provides a name, `@Project` is the project root's folder name.
|
|
234
|
+
|
|
235
|
+
A folder holding `.git` is a repository boundary: neither the root search nor the climb goes past it, so a nested repository without a manifest is a project of its own. With no manifest up to the repository root, that repository root is the project root and its folder name is the name. With neither a manifest nor a repository anywhere above the file, the file's own folder is the project root: `@Project` is that folder's name and `@Filename` is `/<file name>`.
|
|
236
|
+
|
|
237
|
+
`projectName`, `projectRoot`, `language` and `marker` override the detected values for every file. The copyright holder is resolved from the same manifests by the same rules, see [Copyright holder](#copyright-holder).
|
|
238
|
+
|
|
239
|
+
For example, scanning `repo/`:
|
|
240
|
+
|
|
241
|
+
```text
|
|
242
|
+
repo/
|
|
243
|
+
├── package.json { "name": "@scope/repo" }
|
|
244
|
+
├── pyproject.toml [project] name = "repo-py"
|
|
245
|
+
├── scripts/build.py → @Project: repo-py @Filename: /scripts/build.py
|
|
246
|
+
├── site/main.css → @Project: @scope/repo @Filename: /site/main.css
|
|
247
|
+
└── packages/
|
|
248
|
+
├── a/
|
|
249
|
+
│ ├── package.json { "private": true }
|
|
250
|
+
│ └── src/x.mjs → @Project: @scope/repo @Filename: /src/x.mjs
|
|
251
|
+
└── b/
|
|
252
|
+
├── Cargo.toml [package] name = "b-crate"
|
|
253
|
+
└── src/lib.rs → @Project: b-crate @Filename: /src/lib.rs
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
To support another ecosystem, add a module to `src/drivers/` that exports a `driver` with `id`, `languages` (the file-type detector ids native to it), `manifests` (filenames that claim a folder, in reading order), `detect(dirPath)` (returns `detectManifests(dirPath, manifests)` from `src/drivers/shared.mjs`) and `read(detection)` (returns `{ name, company }`, each `undefined` when the manifest has none), then add it to `MANIFEST_DRIVERS` in `src/drivers/index.mjs` at its place in the fixed order.
|
|
257
|
+
|
|
258
|
+
## Copyright holder
|
|
259
|
+
|
|
260
|
+
The holder on the `@Copyright` line (`companyName`) comes from the manifest of the project the file belongs to, read by the same drivers and with the same rules as the project name: the nearest claimed folder, the file's native driver first, the per-field fallback, and climbing up to the scan root (never past a `.git` folder). The holder climbs on its own, so a sub-package whose `package.json` has a name but no author takes the repository's author while keeping its own `@Project`. The field each driver reads is in the table above.
|
|
261
|
+
|
|
262
|
+
- **`companyName`** (CLI `--company-name`) overrides the manifests for every file.
|
|
263
|
+
- **No holder** anywhere up to the scan root: the holder is left out of the line, which reads `Copyright (c) 2019-2026 All rights reserved.`
|
|
264
|
+
|
|
265
|
+
For example, scanning `repo/`:
|
|
266
|
+
|
|
267
|
+
```text
|
|
268
|
+
repo/
|
|
269
|
+
├── package.json { "name": "@scope/repo", "author": { "name": "Jane Doe", "company": "ACME Inc." } }
|
|
270
|
+
├── src/main.mjs → @Copyright: Copyright (c) 2026-2026 ACME Inc. All rights reserved.
|
|
271
|
+
└── packages/
|
|
272
|
+
├── a/
|
|
273
|
+
│ ├── package.json { "name": "@scope/a" }
|
|
274
|
+
│ └── src/x.mjs → @Copyright: Copyright (c) 2026-2026 ACME Inc. All rights reserved.
|
|
275
|
+
└── b/
|
|
276
|
+
├── Cargo.toml [package] authors = ["Rust Dev <dev@example.com>"]
|
|
277
|
+
└── src/lib.rs → @Copyright: Copyright (c) 2026-2026 Rust Dev All rights reserved.
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
With `companyName: "Example Co"` every file gets `Copyright (c) 2026-2026 Example Co All rights reserved.`; with no author in any manifest every file gets `Copyright (c) 2026-2026 All rights reserved.`
|
|
281
|
+
|
|
282
|
+
With `sampleOutput`, `detectedValues.companyName` is the resolved holder (`null` when there is none) and `detectedValues.companyNameSource` says where it came from: `{ from: "manifest", driver, manifest, dir }`, `{ from: "option" }` (`companyName`) or `{ from: "none" }`. `result.metadata` carries the same two values for the scan root. The `@Author` suffix set by `company` (`Name <Company>`) is a separate option and does not affect the holder.
|
|
283
|
+
|
|
284
|
+
## Creation date
|
|
285
|
+
|
|
286
|
+
`@Date` is "oldest wins": a file cannot have been created later than its first commit or than the time the filesystem first saw it, and an `@Date` older than both (a file brought in from elsewhere, or dated before it was committed) is kept.
|
|
287
|
+
|
|
288
|
+
- **New header** (no `@Date`, or one without a `(epoch)`): the older of the git first-commit date and the filesystem creation time. Git wins a tie.
|
|
289
|
+
- **Existing `@Date`**: kept exactly as written. Only its epoch is repaired when it disagrees with the datetime text.
|
|
290
|
+
- **Existing `@Date` with `fixCreatedDate`**: the oldest of the existing `@Date`, the git first commit, and the filesystem creation time. The existing value wins a tie, so the correction only ever moves `@Date` earlier. An existing value whose datetime is not recognised is replaced.
|
|
291
|
+
|
|
292
|
+
The filesystem creation time is the earlier of the file's birth time and its modification time. Content last written at the modification time existed by then, so it bounds creation even when the birth time is later (an extracted archive or a `cp -p` copy keeps the source's modification time). Where the platform reports no birth time, the modification time is used. A fresh clone or CI checkout gives every file a current filesystem time, so there the git first commit decides.
|
|
293
|
+
|
|
294
|
+
## Copyright years
|
|
295
|
+
|
|
296
|
+
`@Copyright: Copyright (c) <start>-<end> <companyName> All rights reserved.`
|
|
297
|
+
|
|
298
|
+
- **`<start>`** is `copyrightStartYear` when it is set. Otherwise it is the year of the file's `@Date` as resolved above: the existing value, the git first commit or filesystem creation time for a new header, or the earlier date `fixCreatedDate` moves it to. The year is read in the zone the date is written in: the `timezone` option when it is set, else the date's own offset. `2019-12-31T23:30:00-08:00` gives `2019`, and `2020` with `timezone: "UTC"`. An `@Date` whose datetime is not recognised gives the year of its epoch in the local time zone.
|
|
299
|
+
- **`<end>`** is the year of the run.
|
|
300
|
+
|
|
301
|
+
A file created in 2019 therefore gets `2019-2026` when fix-headers runs in 2026, not `2026-2026`.
|
|
302
|
+
|
|
303
|
+
## Date checks
|
|
304
|
+
|
|
305
|
+
`check: true` / `--check` validates the `@Date` and `@Last modified time` values of every existing header and writes nothing. It compares instants, not strings, so the same moment written with another offset or in the space/`T` form is not drift. It is independent of the rendered-header diff: an author, identity, copyright, or other content difference never fails the check. Files without a header are skipped.
|
|
306
|
+
|
|
307
|
+
| Check | Fails the run | Meaning |
|
|
308
|
+
| ------------------------------------ | --------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
309
|
+
| `created-format` / `modified-format` | yes | the value is not a `<datetime> (<epoch>)` pair with a recognised datetime (a datetime without a UTC offset is not recognised) |
|
|
310
|
+
| `created-epoch` / `modified-epoch` | yes | the parenthesised epoch is not the instant the datetime text describes |
|
|
311
|
+
| `created-newer-than-source` | with `strictCreatedDate`, else advisory | `@Date` is later than the older of the git first commit and the filesystem creation time; the message names the older source. An earlier `@Date` is fine |
|
|
312
|
+
| `modified-git` | no (advisory) | `@Last modified time` is not the file's git last-commit date |
|
|
313
|
+
|
|
314
|
+
```bash
|
|
315
|
+
$ fix-headers --check --verbose
|
|
316
|
+
fix-headers check: scanned=3, drift=1, advisories=2
|
|
317
|
+
drift: src/epoch.mjs: @Date epoch 1758382412 does not match 2026-09-20T15:33:32+00:00 (expected 1789918412)
|
|
318
|
+
advisory: src/later.mjs: @Date 2026-09-21 09:00:00 -07:00 is later than the git first commit 2026-09-20T15:33:32+00:00 (1789918412)
|
|
319
|
+
advisory: src/later.mjs: @Last modified time 2026-09-21 09:00:00 -07:00 does not match the git last commit 2026-09-20T15:33:32+00:00 (1789918412)
|
|
320
|
+
$ echo $?
|
|
321
|
+
1
|
|
322
|
+
$ fix-headers --check --strict-created-date
|
|
323
|
+
fix-headers check: scanned=3, drift=2, advisories=1
|
|
324
|
+
drift: src/epoch.mjs: @Date epoch 1758382412 does not match 2026-09-20T15:33:32+00:00 (expected 1789918412)
|
|
325
|
+
drift: src/later.mjs: @Date 2026-09-21 09:00:00 -07:00 is later than the git first commit 2026-09-20T15:33:32+00:00 (1789918412)
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
A third file, `src/early.mjs`, has `@Date: 2026-09-20 08:28:32 -07:00`: five minutes before its first commit, as stamped from the file's creation time before it was committed. That is not drift, strict or not.
|
|
329
|
+
|
|
330
|
+
To make the created-date check fail CI, set `"strictCreatedDate": true` in the config file or pass `--strict-created-date`.
|
|
331
|
+
|
|
332
|
+
Advisories are counted in the summary and listed with `--verbose`; `--json` prints the full result and uses the same exit code. `--dry-run` still always exits `0`.
|
|
333
|
+
|
|
334
|
+
In a normal (writing) run, an epoch that disagrees with its datetime text is recomputed from the text; the datetime text itself is left as written. `created-newer-than-source` is corrected only with `fixCreatedDate` / `--fix-created-date`.
|
|
335
|
+
|
|
336
|
+
## Time zone
|
|
337
|
+
|
|
338
|
+
A header date is correct in any zone: the offset is only how the instant is shown, and the epoch in parentheses is the instant. So nothing is converted by default. `timezone` / `--timezone <name>` is for projects that want every date shown in one zone:
|
|
339
|
+
|
|
340
|
+
- **Dates fix-headers writes** are expressed in the zone: a new header's `@Date` (from the git first commit or the filesystem, see [Creation date](#creation-date)), an `@Date` moved by `fixCreatedDate`, and the `@Last modified time` stamped on every changed file.
|
|
341
|
+
- **Dates already in a header** are kept as written, unless `convertTimezone` / `--convert-timezone` is also set. That sweep rewrites existing `@Date` and `@Last modified time` values into the zone. A value whose datetime is not recognised is left alone, and so is one already in the zone's offset at that instant.
|
|
342
|
+
|
|
343
|
+
Only the wall-clock time and the offset change; the instant and the epoch stay the same. The offset is the zone's offset at that instant, from the time zone data built into Node (`Intl`), so daylight saving time is applied per date: with `America/Los_Angeles`, a January date is written at `-08:00` and a July date at `-07:00`. Half-hour and other zones work the same way (`Asia/Kolkata` is `+05:30`, `Pacific/Kiritimati` is `+14:00`). The zone name is validated with `Intl`, and an unknown name fails the run.
|
|
344
|
+
|
|
345
|
+
A converted value keeps its shape: the space form (`2026-01-18 20:39:48 -08:00`) stays in the space form, and the T-form (`2026-01-18T20:39:48-08:00`, as git dates are written) stays in the T-form. With `normalizeDateFormat` every date is then written in the T-form, in the zone.
|
|
346
|
+
|
|
347
|
+
Rewriting a date is a header change like any other, so a file the sweep rewrites also gets a fresh `@Last modified time`, the same as a file whose epoch is repaired or whose dates `normalizeDateFormat` rewrites. The first `--convert-timezone` run therefore restamps every managed file with a date outside the zone. A file whose dates are all in the zone already (or unrecognised) and whose header is otherwise current is not touched.
|
|
348
|
+
|
|
349
|
+
`--check` compares instants, so a date shown in another zone than `timezone` is not drift, and the check has no time zone rule.
|
|
350
|
+
|
|
351
|
+
```bash
|
|
352
|
+
$ fix-headers --timezone America/Los_Angeles --convert-timezone
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
```diff
|
|
356
|
+
- * @Date: 2026-01-19 04:39:48 +00:00 (1768797588)
|
|
357
|
+
+ * @Date: 2026-01-18 20:39:48 -08:00 (1768797588)
|
|
358
|
+
...
|
|
359
|
+
- * @Last modified time: 2026-07-19T04:39:48+00:00 (1784435988)
|
|
360
|
+
+ * @Last modified time: 2026-09-28 10:15:02 -07:00 (1790615702)
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
The `@Date` instant is unchanged; `@Last modified time` is restamped with the time of the run, in the zone.
|
|
364
|
+
|
|
365
|
+
## Which files are processed
|
|
366
|
+
|
|
367
|
+
By default every file with a supported extension is processed. Nothing is skipped because of its name: `node_modules`, `dist`, `build`, `coverage`, `tmp` and the like are processed unless something excludes them. Files are skipped only when:
|
|
368
|
+
|
|
369
|
+
- the project's ignore files ignore them, or
|
|
370
|
+
- you exclude them with `excludeFolders` / `--exclude-folder`.
|
|
371
|
+
|
|
372
|
+
The one exception is `.git`, git's own storage, which is never walked.
|
|
373
|
+
|
|
374
|
+
"Ignore files" means everything git itself honours: the root `.gitignore`, `.gitignore` files in subfolders (each applying to its own folder), `.git/info/exclude`, and the global excludes file (`core.excludesFile`), including negation patterns.
|
|
375
|
+
|
|
376
|
+
- **Inside a git work tree**, git decides. Discovery runs `git ls-files --cached --others --exclude-standard` once per repository and processes the files it lists. Tracked files are always processed, even when an ignore pattern matches them, because git does not treat tracked files as ignored. Starting discovery in a subfolder of a repository applies that repository's rules.
|
|
377
|
+
- **Outside a git work tree** (or when git is not installed), the `.gitignore` files found under the discovery root are parsed instead, each one scoped to its own folder, with deeper files taking precedence. `.git/info/exclude` and `core.excludesFile` belong to a repository, so they do not apply here.
|
|
378
|
+
- **A folder holding several repositories** is walked as usual, and every repository found inside it (a folder containing `.git`, including submodules and nested clones) applies its own ignore rules to its own files. The rules of the folder around a nested repository still decide whether that repository is walked at all.
|
|
379
|
+
- **A discovery root that the enclosing repository ignores** (for example `--input vendor/lib` when `vendor/` is in the repository's `.gitignore`) was asked for explicitly, so it is treated as a standalone folder: its own `.gitignore` files apply, the enclosing repository's do not.
|
|
380
|
+
|
|
381
|
+
`gitignore: false` turns all of this off, and `gitignore: "<file>"` / `["<file>", ...]` replaces it with exactly the listed files.
|
|
382
|
+
|
|
138
383
|
## Notes
|
|
139
384
|
|
|
140
385
|
- `excludeFolders` supports both folder-name and nested path matching.
|
|
141
|
-
-
|
|
142
|
-
-
|
|
143
|
-
- For monorepos, each file resolves
|
|
144
|
-
- With `sampleOutput` enabled, each changed file includes `previousValue`, `newValue`, and `detectedValues` in results.
|
|
386
|
+
- `includeFolders` entries never double-count a file. A folder that lies inside another recursive include is not walked a second time; the exception is a folder the outer walk never enters because `excludeFolders` excludes it (for example `node_modules/pkg` listed explicitly while `node_modules` is excluded), which keeps being walked on its own because it was named explicitly. An `includeFolders` entry does not override the ignore files: a folder they ignore contributes no files.
|
|
387
|
+
- File discovery is described in [Which files are processed](#which-files-are-processed).
|
|
388
|
+
- For monorepos, each file resolves its project from the nearest manifest in its parent tree (see [Project name and root](#project-name-and-root)).
|
|
389
|
+
- With `sampleOutput` enabled, each changed file includes `previousValue`, `newValue`, `diff`, `issues`, and `detectedValues` in results.
|
|
390
|
+
|
|
391
|
+
## Sample output
|
|
392
|
+
|
|
393
|
+
With `sampleOutput: true` (CLI: `--sample-output` or `--diff`), every changed entry in `result.changes` carries a `sample` object. It costs nothing when the option is off.
|
|
394
|
+
|
|
395
|
+
- `previousValue` - the existing header block, or `null` when the file had none.
|
|
396
|
+
- `newValue` - the header block this run writes.
|
|
397
|
+
- `diff` - a ready-to-print unified diff of the header block. The `---`/`+++` lines name the file (`a/<file>` / `b/<file>`, or `/dev/null` when there was no previous header, in which case the whole new header shows as added), and hunk line numbers are file line numbers.
|
|
398
|
+
- `issues` - one `{ field, previous, detected }` entry per header field whose written value differs from the existing header, in header order. Fields: `projectName`, `filename`, `createdAt`, `authorName`, `authorEmail`, `lastModifiedByName`, `lastModifiedByEmail`, `lastModifiedAt`, `copyrightStartYear`, `copyrightEndYear`, `companyName`. Values are the field text as written in the header (dates keep their `date (timestamp)` form); `previous` is `null` when the field was missing.
|
|
399
|
+
- `detectedValues` - the metadata resolved for the file. `projectNameSource` says where `projectName` came from: `{ from: "manifest", driver, manifest, dir }` (the driver, its manifest and the folder it sits in), `{ from: "folder", dir }` (the project root's folder name) or `{ from: "option" }` (`projectName`). `copyrightStartYear` is the start year written for the file, and `copyrightStartYearSource` says where it came from: `"option"` (`copyrightStartYear`) or `"created-date"` (the year of the file's `@Date`, see [Copyright years](#copyright-years)). The run-level `result.metadata.copyrightStartYear` is the `copyrightStartYear` option, or `null` when it is not set.
|
|
400
|
+
|
|
401
|
+
`issues` compares the existing header against what is actually written, not against the raw detected metadata. fix-headers preserves an existing `@Author`/`@Email` and `@Last modified by` identity unless `forceAuthorUpdate` / `forceLastModifiedAuthorUpdate` is set, so those fields only appear when they really change. An updated file always gets a fresh `@Last modified time`, so `lastModifiedAt` is listed for every changed file that already had a header.
|
|
402
|
+
|
|
403
|
+
```js
|
|
404
|
+
const { changes } = await fixHeaders({ dryRun: true, sampleOutput: true });
|
|
405
|
+
for (const { file, sample } of changes.filter((change) => change.sample)) {
|
|
406
|
+
for (const issue of sample.issues) {
|
|
407
|
+
console.log(`${file}: ${issue.field}: found ${issue.previous}, expected ${issue.detected}`);
|
|
408
|
+
}
|
|
409
|
+
console.log(sample.diff);
|
|
410
|
+
}
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
```text
|
|
414
|
+
$ fix-headers --dry-run --diff --verbose --input src/cli.mjs --company-name "CLDMV Inc."
|
|
415
|
+
fix-headers complete: scanned=1, updated=1, dryRun=true
|
|
416
|
+
updated: src/cli.mjs
|
|
417
|
+
issues: src/cli.mjs
|
|
418
|
+
lastModifiedAt: found "2026-03-01T17:59:32-08:00 (1772416772)", expected "2026-09-28 09:20:28 -07:00 (1790612428)"
|
|
419
|
+
companyName: found "Catalyzed Motivation Inc.", expected "CLDMV Inc."
|
|
420
|
+
--- a/src/cli.mjs
|
|
421
|
+
+++ b/src/cli.mjs
|
|
422
|
+
@@ -7,7 +7,7 @@
|
|
423
|
+
* @Email: <Shinrai@users.noreply.github.com>
|
|
424
|
+
* -----
|
|
425
|
+
* @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
|
|
426
|
+
- * @Last modified time: 2026-03-01T17:59:32-08:00 (1772416772)
|
|
427
|
+
+ * @Last modified time: 2026-09-28 09:20:28 -07:00 (1790612428)
|
|
428
|
+
* -----
|
|
429
|
+
- * @Copyright: Copyright (c) 2026-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
430
|
+
+ * @Copyright: Copyright (c) 2026-2026 CLDMV Inc. All rights reserved.
|
|
431
|
+
*/
|
|
432
|
+
```
|
|
145
433
|
|
|
146
434
|
## License
|
|
147
435
|
|