@cldmv/fix-headers 1.3.12 → 2.1.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.
Files changed (65) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +354 -25
  3. package/bin/fix-headers.mjs +64 -0
  4. package/dist/index.cjs +28 -0
  5. package/dist/index.mjs +15 -0
  6. package/package.json +39 -19
  7. package/types/src/cli.d.mts +20 -2
  8. package/types/src/config/load.d.mts +36 -0
  9. package/types/src/constants.d.mts +15 -23
  10. package/types/src/core/file-discovery.d.mts +17 -5
  11. package/types/src/core/fix-headers.d.mts +61 -4
  12. package/types/src/core/ignore-rules.d.mts +38 -0
  13. package/types/src/detect/project.d.mts +64 -15
  14. package/types/src/detectors/css.d.mts +0 -8
  15. package/types/src/detectors/go.d.mts +0 -8
  16. package/types/src/detectors/html.d.mts +0 -8
  17. package/types/src/detectors/index.d.mts +31 -8
  18. package/types/src/detectors/json.d.mts +0 -8
  19. package/types/src/detectors/node.d.mts +0 -8
  20. package/types/src/detectors/php.d.mts +0 -8
  21. package/types/src/detectors/python.d.mts +0 -8
  22. package/types/src/detectors/rust.d.mts +0 -8
  23. package/types/src/detectors/yaml.d.mts +0 -8
  24. package/types/src/drivers/go.d.mts +2 -0
  25. package/types/src/drivers/index.d.mts +154 -0
  26. package/types/src/drivers/node.d.mts +2 -0
  27. package/types/src/drivers/php.d.mts +2 -0
  28. package/types/src/drivers/python.d.mts +2 -0
  29. package/types/src/drivers/rust.d.mts +2 -0
  30. package/types/src/drivers/shared.d.mts +78 -0
  31. package/types/src/header/dates.d.mts +108 -0
  32. package/types/src/header/fields.d.mts +48 -0
  33. package/types/src/header/parser.d.mts +6 -2
  34. package/types/src/header/syntax.d.mts +8 -3
  35. package/types/src/header/template.d.mts +7 -4
  36. package/types/src/utils/diff.d.mts +53 -0
  37. package/types/src/utils/fs.d.mts +10 -3
  38. package/types/src/utils/git.d.mts +27 -0
  39. package/types/src/utils/time.d.mts +55 -0
  40. package/index.cjs +0 -39
  41. package/index.mjs +0 -20
  42. package/src/cli.mjs +0 -323
  43. package/src/constants.mjs +0 -50
  44. package/src/core/file-discovery.mjs +0 -213
  45. package/src/core/fix-headers.mjs +0 -413
  46. package/src/detect/project.mjs +0 -190
  47. package/src/detectors/css.mjs +0 -67
  48. package/src/detectors/go.mjs +0 -65
  49. package/src/detectors/html.mjs +0 -67
  50. package/src/detectors/index.mjs +0 -187
  51. package/src/detectors/json.mjs +0 -76
  52. package/src/detectors/node.mjs +0 -90
  53. package/src/detectors/php.mjs +0 -66
  54. package/src/detectors/python.mjs +0 -75
  55. package/src/detectors/rust.mjs +0 -62
  56. package/src/detectors/shared.mjs +0 -45
  57. package/src/detectors/yaml.mjs +0 -79
  58. package/src/fix-header.mjs +0 -30
  59. package/src/header/parser.mjs +0 -145
  60. package/src/header/syntax.mjs +0 -69
  61. package/src/header/template.mjs +0 -65
  62. package/src/utils/fs.mjs +0 -138
  63. package/src/utils/git.mjs +0 -135
  64. package/src/utils/time.mjs +0 -44
  65. package/types/src/detectors/shared.d.mts +0 -14
@@ -0,0 +1,154 @@
1
+ /**
2
+ * Gets a driver by id.
3
+ * @param {string} id - Driver id.
4
+ * @returns {ManifestDriver | undefined} Driver.
5
+ */
6
+ export function getDriverById(id: string): ManifestDriver | undefined;
7
+ /**
8
+ * Runs every driver's `detect` on one folder and orders the drivers that claim it: the
9
+ * file's native driver first, then the registry order.
10
+ * @param {string} dirPath - Folder.
11
+ * @param {ManifestDriver[]} drivers - Drivers, in registry order.
12
+ * @param {string | undefined} language - The file's detector id (undefined for no file).
13
+ * @returns {Promise<Array<{ driver: ManifestDriver, detection: DriverDetection }>>} Ordered claims.
14
+ */
15
+ export function claimFolder(dirPath: string, drivers: ManifestDriver[], language: string | undefined): Promise<Array<{
16
+ driver: ManifestDriver;
17
+ detection: DriverDetection;
18
+ }>>;
19
+ /**
20
+ * Resolves the project a path belongs to from the manifest drivers.
21
+ *
22
+ * 1. Walk up from `startPath`. The nearest folder that at least one driver claims is the
23
+ * project root. A folder holding `.git` ends the walk: with no claimed folder up to and
24
+ * including it, that repository root is the project root and no driver provides values.
25
+ * 2. Each field comes from the first driver in the root's claim order (native driver first,
26
+ * then node, python, php, rust, go) whose manifest provides it.
27
+ * 3. A field no driver at the root provides is looked up the same way in each ancestor folder
28
+ * a driver claims, climbing no higher than `scanRoot` and stopping at a folder that holds
29
+ * `.git`. Without a `scanRoot`, or when the root is not inside it, nothing climbs.
30
+ *
31
+ * Only values climb; the project root stays the nearest claimed folder.
32
+ * @param {string} startPath - Folder to start from (a file's folder, or the scan root).
33
+ * @param {{ drivers?: ManifestDriver[], language?: string, scanRoot?: string }} [options={}] - Resolution options.
34
+ * @returns {Promise<ManifestProject | null>} Resolved project, or null when neither a manifest nor a `.git` exists up to the filesystem root.
35
+ */
36
+ export function resolveManifestProject(startPath: string, options?: {
37
+ drivers?: ManifestDriver[];
38
+ language?: string;
39
+ scanRoot?: string;
40
+ }): Promise<ManifestProject | null>;
41
+ /**
42
+ * @fileoverview Manifest driver registry and project resolution.
43
+ *
44
+ * A manifest driver knows one ecosystem's manifest files: whether a folder is a project of
45
+ * its kind (`detect`) and what that project's manifest says (`read`). Which project a file
46
+ * belongs to, and the values its header takes from that project, are resolved here from the
47
+ * drivers alone, whatever the file's type; comment syntax stays with the file-type detectors
48
+ * in `src/detectors/`.
49
+ * @module fix-headers/drivers
50
+ */
51
+ /**
52
+ * @typedef {import("./shared.mjs").DriverDetection} DriverDetection
53
+ */
54
+ /**
55
+ * @typedef {{ name?: string, company?: string }} ManifestData
56
+ * Values a manifest provides. A field is left undefined when the manifest doesn't carry it.
57
+ * - `name` - the project name (`@Project`).
58
+ * - `company` - the copyright holder (`@Copyright`), taken from the manifest's author.
59
+ */
60
+ /**
61
+ * @typedef {{
62
+ * id: string,
63
+ * languages: string[],
64
+ * manifests: string[],
65
+ * detect: (dirPath: string) => Promise<DriverDetection | null>,
66
+ * read: (detection: DriverDetection) => ManifestData
67
+ * }} ManifestDriver
68
+ * - `id` - driver id, reported as the source of a value.
69
+ * - `languages` - file-type detector ids whose files are native to this driver (`node` for
70
+ * `.js`/`.mjs`/`.ts`…); in a folder claimed by several drivers, a file's native driver is
71
+ * read first.
72
+ * - `manifests` - manifest filenames that claim a folder, in the order they are read.
73
+ * - `detect` - the manifests present and readable in a folder, or null when there are none.
74
+ * - `read` - the values those manifests provide.
75
+ */
76
+ /**
77
+ * @typedef {{ driver: string, manifest: string, dir: string }} FieldSource
78
+ * Where a value came from: the driver, its manifest (the first one found in the folder) and
79
+ * the folder.
80
+ */
81
+ /**
82
+ * @typedef {{
83
+ * root: string,
84
+ * marker: string,
85
+ * drivers: string[],
86
+ * fields: ManifestData,
87
+ * sources: Partial<Record<keyof ManifestData, FieldSource>>
88
+ * }} ManifestProject
89
+ * - `root` - the project root: the nearest folder a driver claims, or the repository root
90
+ * (`marker: ".git"`, no drivers) when no manifest exists below it.
91
+ * - `marker` - the first manifest of the first driver claiming the root, or `.git`.
92
+ * - `drivers` - the drivers claiming the root, in the order they are read.
93
+ * - `fields` / `sources` - the resolved values and where each came from.
94
+ */
95
+ /**
96
+ * Registered drivers, in the fixed order used when a folder is claimed by several drivers
97
+ * and none of them is native to the file. Add a new driver module here.
98
+ * @type {ManifestDriver[]}
99
+ */
100
+ export const MANIFEST_DRIVERS: ManifestDriver[];
101
+ /**
102
+ * Fields resolved from manifests. Resolution climbs until each of them is found.
103
+ * @type {Array<keyof ManifestData>}
104
+ */
105
+ export const MANIFEST_FIELDS: Array<keyof ManifestData>;
106
+ export type DriverDetection = import("./shared.mjs").DriverDetection;
107
+ /**
108
+ * Values a manifest provides. A field is left undefined when the manifest doesn't carry it.
109
+ * - `name` - the project name (`@Project`).
110
+ * - `company` - the copyright holder (`@Copyright`), taken from the manifest's author.
111
+ */
112
+ export type ManifestData = {
113
+ name?: string;
114
+ company?: string;
115
+ };
116
+ /**
117
+ * - `id` - driver id, reported as the source of a value.
118
+ * - `languages` - file-type detector ids whose files are native to this driver (`node` for
119
+ * `.js`/`.mjs`/`.ts`…); in a folder claimed by several drivers, a file's native driver is
120
+ * read first.
121
+ * - `manifests` - manifest filenames that claim a folder, in the order they are read.
122
+ * - `detect` - the manifests present and readable in a folder, or null when there are none.
123
+ * - `read` - the values those manifests provide.
124
+ */
125
+ export type ManifestDriver = {
126
+ id: string;
127
+ languages: string[];
128
+ manifests: string[];
129
+ detect: (dirPath: string) => Promise<DriverDetection | null>;
130
+ read: (detection: DriverDetection) => ManifestData;
131
+ };
132
+ /**
133
+ * Where a value came from: the driver, its manifest (the first one found in the folder) and
134
+ * the folder.
135
+ */
136
+ export type FieldSource = {
137
+ driver: string;
138
+ manifest: string;
139
+ dir: string;
140
+ };
141
+ /**
142
+ * - `root` - the project root: the nearest folder a driver claims, or the repository root
143
+ * (`marker: ".git"`, no drivers) when no manifest exists below it.
144
+ * - `marker` - the first manifest of the first driver claiming the root, or `.git`.
145
+ * - `drivers` - the drivers claiming the root, in the order they are read.
146
+ * - `fields` / `sources` - the resolved values and where each came from.
147
+ */
148
+ export type ManifestProject = {
149
+ root: string;
150
+ marker: string;
151
+ drivers: string[];
152
+ fields: ManifestData;
153
+ sources: Partial<Record<keyof ManifestData, FieldSource>>;
154
+ };
@@ -0,0 +1,2 @@
1
+ /** @type {import("./index.mjs").ManifestDriver} */
2
+ export const driver: import("./index.mjs").ManifestDriver;
@@ -0,0 +1,2 @@
1
+ /** @type {import("./index.mjs").ManifestDriver} */
2
+ export const driver: import("./index.mjs").ManifestDriver;
@@ -0,0 +1,2 @@
1
+ /** @type {import("./index.mjs").ManifestDriver} */
2
+ export const driver: import("./index.mjs").ManifestDriver;
@@ -0,0 +1,2 @@
1
+ /** @type {import("./index.mjs").ManifestDriver} */
2
+ export const driver: import("./index.mjs").ManifestDriver;
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Detects a driver's manifests in one folder. The folder counts as a project of the driver's
3
+ * kind when at least one of the manifests is present and readable; its content is not
4
+ * validated here, so a malformed manifest still marks the project root.
5
+ * @param {string} dirPath - Folder to check.
6
+ * @param {string[]} manifests - Manifest filenames, in the order the driver reads them.
7
+ * @returns {Promise<DriverDetection | null>} Detection, or null when the folder holds none of them.
8
+ */
9
+ export function detectManifests(dirPath: string, manifests: string[]): Promise<DriverDetection | null>;
10
+ /**
11
+ * Gets the content of one manifest from a detection.
12
+ * @param {DriverDetection} detection - Driver detection.
13
+ * @param {string} file - Manifest filename.
14
+ * @returns {string | null} Content, or null when that manifest isn't present.
15
+ */
16
+ export function manifestContent(detection: DriverDetection, file: string): string | null;
17
+ /**
18
+ * Normalizes a candidate name: a trimmed non-empty string, else undefined.
19
+ * @param {unknown} value - Candidate value.
20
+ * @returns {string | undefined} Name.
21
+ */
22
+ export function cleanName(value: unknown): string | undefined;
23
+ /**
24
+ * Reads the name part of a person string in the `Name <email> (url)` form used by
25
+ * `package.json` string authors, Poetry and Cargo authors: the text before the first `<` or `(`.
26
+ * @param {unknown} value - Candidate value.
27
+ * @returns {string | undefined} Name, or undefined when the value isn't a string or has no name
28
+ * before its email or url.
29
+ */
30
+ export function personName(value: unknown): string | undefined;
31
+ /**
32
+ * Parses a JSON manifest (`package.json`, `composer.json`).
33
+ * @param {string} content - Manifest content.
34
+ * @returns {any} Parsed value, or undefined when the content isn't valid JSON.
35
+ */
36
+ export function parseJsonManifest(content: string): any;
37
+ /**
38
+ * Reads a string value from a TOML table: `key = "value"` or `key = 'value'` on its own line.
39
+ * @param {string} content - TOML content.
40
+ * @param {string} table - Table name, dotted for nested tables (`tool.poetry`).
41
+ * @param {string} key - Bare key.
42
+ * @returns {string | undefined} Value, or undefined when the table or key is missing.
43
+ */
44
+ export function readTomlString(content: string, table: string, key: string): string | undefined;
45
+ /**
46
+ * Reads a value from an INI section (`key = value` or `key: value`), as in `setup.cfg`.
47
+ * @param {string} content - INI content.
48
+ * @param {string} section - Section name.
49
+ * @param {string} key - Key.
50
+ * @returns {string | undefined} Value, or undefined when the section or key is missing.
51
+ */
52
+ export function readIniValue(content: string, section: string, key: string): string | undefined;
53
+ /**
54
+ * Reads the name of the first author in a TOML `authors` array: the name part of a string
55
+ * entry (`authors = ["Name <email>"]`, as in Poetry and Cargo) or the `name` of an inline-table
56
+ * entry (`authors = [{ name = "Name", email = "..." }]`, as in PEP 621).
57
+ * @param {string} content - TOML content.
58
+ * @param {string} table - Table name, dotted for nested tables (`tool.poetry`).
59
+ * @returns {string | undefined} Name, or undefined when the table has no `authors` array or its
60
+ * first entry carries no name.
61
+ */
62
+ export function readTomlAuthor(content: string, table: string): string | undefined;
63
+ /**
64
+ * A manifest file found in a folder, with its content.
65
+ */
66
+ export type ManifestFile = {
67
+ file: string;
68
+ content: string;
69
+ };
70
+ /**
71
+ * What a driver's `detect` found in a folder: the folder, the first manifest found (in the
72
+ * driver's `manifests` order) and every manifest of the driver that is present and readable.
73
+ */
74
+ export type DriverDetection = {
75
+ dir: string;
76
+ manifest: string;
77
+ files: ManifestFile[];
78
+ };
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Picks the earliest of several labelled date payloads. Missing payloads are skipped and the
3
+ * earlier entry wins a tie, so callers list their preferred source first.
4
+ * @template {string} S
5
+ * @param {Array<{source: S, payload: DatePayload | null | undefined}>} candidates - Labelled payloads.
6
+ * @returns {{source: S, payload: DatePayload} | null} Earliest candidate, or null when none has a payload.
7
+ */
8
+ export function pickOldestDate<S extends string>(candidates: Array<{
9
+ source: S;
10
+ payload: DatePayload | null | undefined;
11
+ }>): {
12
+ source: S;
13
+ payload: DatePayload;
14
+ } | null;
15
+ /**
16
+ * Resolves the `@Date` to write ("oldest wins").
17
+ * - No usable existing `@Date` (no header, or no `(epoch)`): the older of the git first-commit
18
+ * date and the filesystem creation time (git on a tie).
19
+ * - Existing `@Date`, default: kept as written (epoch repaired separately by {@link repairDateEpoch}).
20
+ * - Existing `@Date` with `fixCreatedDate`: the oldest of the existing date (when its datetime is
21
+ * recognised), the git first commit, and the filesystem creation time. The existing date wins a
22
+ * tie, so a correction only ever moves `@Date` earlier.
23
+ * @param {{ existing: DatePayload | null, gitCreated: DatePayload | null, filesystemCreated: DatePayload, fixCreatedDate?: boolean }} input - Candidate dates.
24
+ * @returns {{source: CreatedDateSource, payload: DatePayload}} Chosen date and where it came from.
25
+ */
26
+ export function resolveCreatedDate({ existing, gitCreated, filesystemCreated, fixCreatedDate }: {
27
+ existing: DatePayload | null;
28
+ gitCreated: DatePayload | null;
29
+ filesystemCreated: DatePayload;
30
+ fixCreatedDate?: boolean;
31
+ }): {
32
+ source: CreatedDateSource;
33
+ payload: DatePayload;
34
+ };
35
+ /**
36
+ * Reads the calendar year of a header date, for the `@Copyright` start year. With a time zone the
37
+ * year is the zone's at the date's instant; without one it is the year the datetime text is
38
+ * written in, in its own offset. Text that is not a recognised datetime falls back to the year of
39
+ * its epoch in the local time zone, the zone fix-headers writes dates in by default.
40
+ * @param {DatePayload} payload - Date payload, with an epoch consistent with its text.
41
+ * @param {string | null} [timeZone=null] - IANA zone name, already validated.
42
+ * @returns {number} Calendar year.
43
+ */
44
+ export function dateYear(payload: DatePayload, timeZone?: string | null): number;
45
+ /**
46
+ * Validates the `@Date` and `@Last modified time` values of an existing header.
47
+ *
48
+ * Every comparison is between instants, so the same moment written with another offset or in
49
+ * the space/`T` form is not drift. The checks are independent of the rendered-header diff, so
50
+ * an author, identity, or other content difference never produces an issue here.
51
+ * - `*-format`: the value is not a recognised `<datetime> (<epoch>)` pair.
52
+ * - `*-epoch`: the parenthesised epoch is not the instant the datetime text describes.
53
+ * - `created-newer-than-source`: `@Date` is later than the older of the git first commit and the
54
+ * filesystem creation time. An earlier `@Date` is fine. Advisory unless `strictCreatedDate`.
55
+ * - `modified-git`: `@Last modified time` is not the file's last-commit date. Always advisory.
56
+ * @param {string} headerText - Existing header content.
57
+ * @param {{ gitCreated?: DatePayload | null, gitLastModified?: DatePayload | null, filesystemCreated?: DatePayload | null }} [sources={}] - Dates the header is compared against.
58
+ * @param {{ strictCreatedDate?: boolean }} [options={}] - Check options.
59
+ * @returns {DateCheckIssue[]} Issues found, `@Date` first.
60
+ */
61
+ export function checkHeaderDates(headerText: string, sources?: {
62
+ gitCreated?: DatePayload | null;
63
+ gitLastModified?: DatePayload | null;
64
+ filesystemCreated?: DatePayload | null;
65
+ }, options?: {
66
+ strictCreatedDate?: boolean;
67
+ }): DateCheckIssue[];
68
+ /**
69
+ * Repairs a header date payload whose epoch disagrees with its datetime text. The text is kept
70
+ * as written and the epoch is recomputed from it. Unrecognised text is returned unchanged,
71
+ * since there is no instant to recompute from.
72
+ * @param {DatePayload | null} payload - Date payload read from a header.
73
+ * @returns {DatePayload | null} Consistent payload, or null when none was given.
74
+ */
75
+ export function repairDateEpoch(payload: DatePayload | null): DatePayload | null;
76
+ /**
77
+ * Rewrites a date payload's text in the git `%aI` form (`YYYY-MM-DDTHH:mm:ss±HH:MM`), keeping
78
+ * its offset and instant. Unrecognised text is returned unchanged.
79
+ * @param {DatePayload} payload - Date payload.
80
+ * @returns {DatePayload} Payload with ISO 8601 text.
81
+ */
82
+ export function normalizeDatePayload(payload: DatePayload): DatePayload;
83
+ /**
84
+ * Rewrites a date payload's text in a time zone, keeping its instant: the wall-clock time and
85
+ * offset become the zone's at that instant (DST included). The text keeps its shape: the T-form
86
+ * stays in the T-form and anything else is written in the space form. The payload is returned
87
+ * unchanged when its text is unrecognised (there is no instant to convert), when it is already
88
+ * in the zone's offset at that instant, or when the zone's offset then is not a whole number of
89
+ * minutes (historical local mean time), which a `±HH:MM` offset cannot express.
90
+ * @param {DatePayload} payload - Date payload.
91
+ * @param {string} timeZone - IANA zone name, already validated.
92
+ * @returns {DatePayload} Payload expressed in the zone.
93
+ */
94
+ export function convertDatePayload(payload: DatePayload, timeZone: string): DatePayload;
95
+ export type DatePayload = {
96
+ date: string;
97
+ timestamp: number;
98
+ };
99
+ export type CreatedDateSource = "existing-header" | "git-created" | "filesystem-created";
100
+ export type DateCheckIssue = {
101
+ check: "created-format" | "created-epoch" | "created-newer-than-source" | "modified-format" | "modified-epoch" | "modified-git";
102
+ field: "@Date" | "@Last modified time";
103
+ advisory: boolean;
104
+ value: string;
105
+ expected?: string;
106
+ source?: "git-created" | "filesystem-created";
107
+ message: string;
108
+ };
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Parses every known field out of a header block. Values are the text as written in
3
+ * the header (dates keep their `date (timestamp)` form); a field that is missing or
4
+ * cannot be parsed is `null`.
5
+ * @param {string} headerText - Header block text.
6
+ * @returns {HeaderFields} Parsed field values.
7
+ */
8
+ export function parseHeaderFields(headerText: string): HeaderFields;
9
+ /**
10
+ * Compares an existing header with the header written by this run, field by field.
11
+ * Both sides are parsed with {@link parseHeaderFields}, so a field only appears when
12
+ * the written value really differs from what the file had. Values fix-headers
13
+ * preserves (the original author and last-modified identity, unless forced) therefore
14
+ * show up only when they actually change.
15
+ * @param {string | null} previousHeader - Existing header text, or null when the file had none.
16
+ * @param {string} nextHeader - Header text written by this run.
17
+ * @returns {HeaderFieldIssue[]} One entry per differing field, in header order.
18
+ */
19
+ export function compareHeaderFields(previousHeader: string | null, nextHeader: string): HeaderFieldIssue[];
20
+ /**
21
+ * @Project: @cldmv/fix-headers
22
+ * @Filename: /src/header/fields.mjs
23
+ * @Date: 2026-09-28T09:14:18-07:00 (1790612058)
24
+ * @Author: Nate Corcoran <CLDMV>
25
+ * @Email: <Shinrai@users.noreply.github.com>
26
+ * -----
27
+ * @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
28
+ * @Last modified time: 2026-09-28T09:14:18-07:00 (1790612058)
29
+ * -----
30
+ * @Copyright: Copyright (c) 2026-2026 Catalyzed Motivation Inc. All rights reserved.
31
+ */
32
+ /**
33
+ * @fileoverview Parses the individual fields back out of a rendered header block and
34
+ * compares two header blocks field by field.
35
+ * @module fix-headers/header/fields
36
+ */
37
+ /**
38
+ * Header field identifiers, in the order they appear in a rendered header.
39
+ * @type {ReadonlyArray<HeaderFieldName>}
40
+ */
41
+ export const HEADER_FIELDS: ReadonlyArray<HeaderFieldName>;
42
+ export type HeaderFieldName = "projectName" | "filename" | "createdAt" | "authorName" | "authorEmail" | "lastModifiedByName" | "lastModifiedByEmail" | "lastModifiedAt" | "copyrightStartYear" | "copyrightEndYear" | "companyName";
43
+ export type HeaderFields = Record<HeaderFieldName, string | null>;
44
+ export type HeaderFieldIssue = {
45
+ field: HeaderFieldName;
46
+ previous: string | null;
47
+ detected: string | null;
48
+ };
@@ -2,7 +2,7 @@
2
2
  * Finds the first top-level project header block in a file.
3
3
  * @param {string} content - File content.
4
4
  * @param {string} [filePath=""] - File path used for syntax selection.
5
- * @param {{ language?: string, enabledDetectors?: string[], disabledDetectors?: string[], detectorSyntaxOverrides?: Record<string, { linePrefix?: string, lineSeparator?: string, blockStart?: string, blockLinePrefix?: string, blockEnd?: string }> }} [syntaxOptions={}] - Syntax resolution options.
5
+ * @param {{ language?: string, enabledDetectors?: string[], disabledDetectors?: string[], detectorSyntaxOverrides?: Record<string, { linePrefix?: string, lineSeparator?: string, blockStart?: string, blockLinePrefix?: string, blockEnd?: string }>, spacing?: number, margin?: number }} [syntaxOptions={}] - Syntax resolution options.
6
6
  * @returns {{start: number, end: number} | null} Header location.
7
7
  */
8
8
  export function findProjectHeader(content: string, filePath?: string, syntaxOptions?: {
@@ -16,6 +16,8 @@ export function findProjectHeader(content: string, filePath?: string, syntaxOpti
16
16
  blockLinePrefix?: string;
17
17
  blockEnd?: string;
18
18
  }>;
19
+ spacing?: number;
20
+ margin?: number;
19
21
  }): {
20
22
  start: number;
21
23
  end: number;
@@ -25,7 +27,7 @@ export function findProjectHeader(content: string, filePath?: string, syntaxOpti
25
27
  * @param {string} content - Original file content.
26
28
  * @param {string} newHeader - Generated header text.
27
29
  * @param {string} [filePath=""] - File path used for syntax selection.
28
- * @param {{ language?: string, enabledDetectors?: string[], disabledDetectors?: string[], detectorSyntaxOverrides?: Record<string, { linePrefix?: string, lineSeparator?: string, blockStart?: string, blockLinePrefix?: string, blockEnd?: string }> }} [syntaxOptions={}] - Syntax resolution options.
30
+ * @param {{ language?: string, enabledDetectors?: string[], disabledDetectors?: string[], detectorSyntaxOverrides?: Record<string, { linePrefix?: string, lineSeparator?: string, blockStart?: string, blockLinePrefix?: string, blockEnd?: string }>, spacing?: number, margin?: number }} [syntaxOptions={}] - Syntax resolution options.
29
31
  * @returns {{nextContent: string, changed: boolean}} Updated content result.
30
32
  */
31
33
  export function replaceOrInsertHeader(content: string, newHeader: string, filePath?: string, syntaxOptions?: {
@@ -39,6 +41,8 @@ export function replaceOrInsertHeader(content: string, newHeader: string, filePa
39
41
  blockLinePrefix?: string;
40
42
  blockEnd?: string;
41
43
  }>;
44
+ spacing?: number;
45
+ margin?: number;
42
46
  }): {
43
47
  nextContent: string;
44
48
  changed: boolean;
@@ -9,13 +9,14 @@
9
9
  * lineSeparator?: string,
10
10
  * blockStart?: string,
11
11
  * blockLinePrefix?: string,
12
- * blockEnd?: string
12
+ * blockEnd?: string,
13
+ * spacing?: number
13
14
  * }} HeaderSyntax
14
15
  */
15
16
  /**
16
17
  * Resolves comment syntax for a file path based on extension.
17
18
  * @param {string} filePath - Absolute or relative file path.
18
- * @param {{ language?: string, enabledDetectors?: string[], disabledDetectors?: string[], detectorSyntaxOverrides?: Record<string, { linePrefix?: string, lineSeparator?: string, blockStart?: string, blockLinePrefix?: string, blockEnd?: string }> }} [options={}] - Syntax resolution options.
19
+ * @param {{ language?: string, enabledDetectors?: string[], disabledDetectors?: string[], detectorSyntaxOverrides?: Record<string, { linePrefix?: string, lineSeparator?: string, blockStart?: string, blockLinePrefix?: string, blockEnd?: string }>, spacing?: number }} [options={}] - Syntax resolution options. `spacing` is the number of empty comment lines just inside the header's opening and closing (default 1).
19
20
  * @returns {HeaderSyntax} Header syntax descriptor.
20
21
  */
21
22
  export function getHeaderSyntaxForFile(filePath: string, options?: {
@@ -29,9 +30,12 @@ export function getHeaderSyntaxForFile(filePath: string, options?: {
29
30
  blockLinePrefix?: string;
30
31
  blockEnd?: string;
31
32
  }>;
33
+ spacing?: number;
32
34
  }): HeaderSyntax;
33
35
  /**
34
- * Renders header body lines using a chosen syntax.
36
+ * Renders header body lines using a chosen syntax. `syntax.spacing` empty comment lines (default 1) sit
37
+ * just inside the opening and just before the closing delimiter, or a bare comment-prefix line above
38
+ * and below a line-comment header.
35
39
  * @param {HeaderSyntax} syntax - Header syntax descriptor.
36
40
  * @param {string[]} lines - Header lines without comment wrappers.
37
41
  * @returns {string} Formatted header block.
@@ -44,4 +48,5 @@ export type HeaderSyntax = {
44
48
  blockStart?: string;
45
49
  blockLinePrefix?: string;
46
50
  blockEnd?: string;
51
+ spacing?: number;
47
52
  };
@@ -7,7 +7,7 @@
7
7
  * @param {{
8
8
  * absoluteFilePath: string,
9
9
  * language?: string,
10
- * syntaxOptions?: { language?: string, enabledDetectors?: string[], disabledDetectors?: string[], detectorSyntaxOverrides?: Record<string, { linePrefix?: string, lineSeparator?: string, blockStart?: string, blockLinePrefix?: string, blockEnd?: string }> },
10
+ * syntaxOptions?: { language?: string, enabledDetectors?: string[], disabledDetectors?: string[], detectorSyntaxOverrides?: Record<string, { linePrefix?: string, lineSeparator?: string, blockStart?: string, blockLinePrefix?: string, blockEnd?: string }>, spacing?: number, margin?: number },
11
11
  * projectRoot: string,
12
12
  * createdByName?: string,
13
13
  * createdByEmail?: string,
@@ -19,9 +19,10 @@
19
19
  * createdAt: {date: string, timestamp: number},
20
20
  * lastModifiedAt: {date: string, timestamp: number},
21
21
  * copyrightStartYear: number,
22
- * companyName: string,
22
+ * companyName?: string | null,
23
23
  * currentYear: number
24
- * }} data - Header data.
24
+ * }} data - Header data. Without a `companyName` (null, undefined or blank), the `@Copyright`
25
+ * line carries no holder: `Copyright (c) 2019-2026 All rights reserved.`
25
26
  * @returns {string} Header block text.
26
27
  */
27
28
  export function buildHeader(data: {
@@ -38,6 +39,8 @@ export function buildHeader(data: {
38
39
  blockLinePrefix?: string;
39
40
  blockEnd?: string;
40
41
  }>;
42
+ spacing?: number;
43
+ margin?: number;
41
44
  };
42
45
  projectRoot: string;
43
46
  createdByName?: string;
@@ -56,6 +59,6 @@ export function buildHeader(data: {
56
59
  timestamp: number;
57
60
  };
58
61
  copyrightStartYear: number;
59
- companyName: string;
62
+ companyName?: string | null;
60
63
  currentYear: number;
61
64
  }): string;
@@ -0,0 +1,53 @@
1
+ /**
2
+ * @Project: @cldmv/fix-headers
3
+ * @Filename: /src/utils/diff.mjs
4
+ * @Date: 2026-09-28T09:14:18-07:00 (1790612058)
5
+ * @Author: Nate Corcoran <CLDMV>
6
+ * @Email: <Shinrai@users.noreply.github.com>
7
+ * -----
8
+ * @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
9
+ * @Last modified time: 2026-09-28T09:14:18-07:00 (1790612058)
10
+ * -----
11
+ * @Copyright: Copyright (c) 2026-2026 Catalyzed Motivation Inc. All rights reserved.
12
+ */
13
+ /**
14
+ * @fileoverview Minimal line-level unified diff for header blocks. Header blocks are a
15
+ * handful of lines, so a plain longest-common-subsequence table is fast enough and keeps
16
+ * the package free of a runtime diff dependency.
17
+ * @module fix-headers/utils/diff
18
+ */
19
+ /**
20
+ * @typedef {{ type: " " | "-" | "+", line: string }} DiffOperation
21
+ */
22
+ /**
23
+ * Computes the line operations that turn `previous` into `next`.
24
+ * @param {string[]} previous - Old lines.
25
+ * @param {string[]} next - New lines.
26
+ * @returns {DiffOperation[]} Ordered keep/remove/add operations.
27
+ */
28
+ export function diffLines(previous: string[], next: string[]): DiffOperation[];
29
+ /**
30
+ * Builds a unified diff between two texts.
31
+ * @param {string | null} previous - Old text, or null when there was none.
32
+ * @param {string} next - New text.
33
+ * @param {{
34
+ * fromFile?: string,
35
+ * toFile?: string,
36
+ * context?: number,
37
+ * lineOffset?: number
38
+ * }} [options={}] - `fromFile`/`toFile` label the `---`/`+++` lines (a null `previous`
39
+ * labels the old side `/dev/null`); `context` is the number of unchanged lines kept
40
+ * around each change (default 3); `lineOffset` is the number of file lines that precede
41
+ * both texts, so hunk line numbers match the file.
42
+ * @returns {string} Unified diff text, or an empty string when the texts are identical.
43
+ */
44
+ export function createUnifiedDiff(previous: string | null, next: string, options?: {
45
+ fromFile?: string;
46
+ toFile?: string;
47
+ context?: number;
48
+ lineOffset?: number;
49
+ }): string;
50
+ export type DiffOperation = {
51
+ type: " " | "-" | "+";
52
+ line: string;
53
+ };
@@ -30,17 +30,24 @@ export function readTextIfExists(filePath: string): Promise<string | null>;
30
30
  * @param {{
31
31
  * allowedExtensions: Set<string>,
32
32
  * ignoreFolders: Set<string>,
33
- * shouldSkipDirectory?: (directoryPath: string, directoryName: string) => boolean
34
- * }} options - Scan options.
33
+ * shouldSkipDirectory?: (directoryPath: string, directoryName: string) => boolean | Promise<boolean>,
34
+ * recursive?: boolean
35
+ * }} options - Scan options. `recursive: false` lists only the directory's own files.
36
+ * `shouldSkipDirectory` may be async. Symlinked directories are never followed.
35
37
  * @returns {Promise<string[]>} Matching file paths.
36
38
  */
37
39
  export function walkFiles(dirPath: string, options: {
38
40
  allowedExtensions: Set<string>;
39
41
  ignoreFolders: Set<string>;
40
- shouldSkipDirectory?: (directoryPath: string, directoryName: string) => boolean;
42
+ shouldSkipDirectory?: (directoryPath: string, directoryName: string) => boolean | Promise<boolean>;
43
+ recursive?: boolean;
41
44
  }): Promise<string[]>;
42
45
  /**
43
46
  * Gets creation-like and modified timestamps from filesystem stats.
47
+ * The creation time is the earlier of the birth time and the modification time: content last
48
+ * written at `mtime` existed by then, so `mtime` bounds creation even when the birth time is
49
+ * later (an archive extraction or `cp -p` keeps the source's `mtime` but gets a new birth time).
50
+ * Where the platform reports no birth time (`birthtimeMs` 0), `mtime` is used.
44
51
  * @param {string} filePath - Absolute file path.
45
52
  * @returns {Promise<{createdAt: Date, updatedAt: Date}>} Date pair.
46
53
  */
@@ -9,8 +9,35 @@
9
9
  * @returns {Promise<string | null>} Trimmed stdout or null on failure.
10
10
  */
11
11
  export function runGit(cwd: string, args: string[]): Promise<string | null>;
12
+ /**
13
+ * Parses a signer UID string into author name and optional email.
14
+ * The OpenPGP UID comment (`Name (Comment) <email>`) is dropped from the name;
15
+ * when the UID is only a comment, the raw name is kept.
16
+ * @param {string} signerUid - Raw signer UID (for example: "Name (Comment) <email@example.com>").
17
+ * @returns {{authorName: string | null, authorEmail: string | null}} Parsed signer identity.
18
+ */
19
+ export function parseSignerUid(signerUid: string): {
20
+ authorName: string | null;
21
+ authorEmail: string | null;
22
+ };
23
+ /**
24
+ * Reads the user ID of the OpenPGP key git signs commits with (`user.signingkey`).
25
+ * Returns the first user ID that is not revoked or expired (GnuPG lists the primary
26
+ * one first), or null when git signs with SSH/X.509, no signing key is configured,
27
+ * or GnuPG is unavailable or doesn't know the key.
28
+ * @param {string} cwd - Project directory (git config is read as git sees it there).
29
+ * @returns {Promise<string | null>} The signing key's user ID.
30
+ */
31
+ export function readSigningKeyUid(cwd: string): Promise<string | null>;
12
32
  /**
13
33
  * Detects git author name and email from config or commit history.
34
+ *
35
+ * With `useGpgSignerAuthor`, the name comes from the user ID of the OpenPGP key git is
36
+ * configured to sign with (`user.signingkey`), so it describes whoever is running the
37
+ * tool. When no such key can be read, it falls back to the signer of the last commit
38
+ * (`%GS`), and then to `user.name`. The last commit alone is unreliable: on a branch
39
+ * whose tip is a squash merge made by GitHub or a bot, it has no locally verifiable
40
+ * signer.
14
41
  * @param {string} cwd - Project directory.
15
42
  * @param {{useGpgSignerAuthor?: boolean}} [options={}] - Detection options.
16
43
  * @returns {Promise<{authorName: string | null, authorEmail: string | null}>} Author information.