@cldmv/fix-headers 1.3.7 → 1.3.10

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/README.md CHANGED
@@ -54,6 +54,7 @@ Common CLI options:
54
54
  - `--json`
55
55
  - `--sample-output`
56
56
  - `--force-author-update`
57
+ - `--force-last-modified-author-update`
57
58
  - `--use-gpg-signer-author`
58
59
  - `--cwd <path>`
59
60
  - `--input <path>`
@@ -103,6 +104,7 @@ Important options:
103
104
  - `authorEmail?: string`
104
105
  - `company?: string` - appends to `@Author` as `Name <Company>`
105
106
  - `forceAuthorUpdate?: boolean` - force update `@Author`/`@Email` to detected or overridden current values
107
+ - `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)
106
108
  - `useGpgSignerAuthor?: boolean` - use signed-commit UID (`%GS`) for detected `@Author` (includes signer comment when present)
107
109
  - `companyName?: string` (default: `Catalyzed Motivation Inc.`)
108
110
  - `copyrightStartYear?: number` (default: current year)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cldmv/fix-headers",
3
- "version": "1.3.7",
3
+ "version": "1.3.10",
4
4
  "description": "Multi-language project header normalizer with auto-detection and override support.",
5
5
  "type": "module",
6
6
  "main": "./index.cjs",
package/src/cli.mjs CHANGED
@@ -23,7 +23,7 @@ import fixHeaders from "./fix-header.mjs";
23
23
  * @module fix-headers/cli
24
24
  */
25
25
 
26
- const HELP_TEXT = `fix-headers CLI\n\nUsage:\n fix-headers [options]\n\nOptions:\n -h, --help Show help\n --dry-run Compute changes without writing files\n --json Print JSON output\n --verbose Print updated file paths in summary mode\n --sample-output Show previous/new header sample for changed files\n --force-author-update Always update @Author/@Email to detected/current values\n --use-gpg-signer-author Use signed-commit UID (%GS) for detected @Author\n --cwd <path> Working directory for project detection\n --input <path> Single file or folder input\n --include-folder <path> Include folder (repeatable)\n --exclude-folder <path> Exclude folder name/path (repeatable)\n --include-extension <ext> Include extension (repeatable)\n --enable-detector <id> Enable only specific detector (repeatable)\n --disable-detector <id> Disable detector by id (repeatable)\n --project-name <name> Override project name\n --language <id> Override language id\n --project-root <path> Override project root\n --marker <name|null> Override marker filename\n --author-name <name> Override author name\n --author-email <email> Override author email\n --company <name> Append company suffix to @Author (Name <Company>)\n --company-name <name> Override company name\n --copyright-start-year <year> Override copyright start year\n --config <path> Load JSON options file\n\nExamples:\n fix-headers --dry-run --include-folder src\n fix-headers --project-name @scope/pkg --company-name "Catalyzed Motivation Inc."\n`;
26
+ const HELP_TEXT = `fix-headers CLI\n\nUsage:\n fix-headers [options]\n\nOptions:\n -h, --help Show help\n --dry-run Compute changes without writing files\n --json Print JSON output\n --verbose Print updated file paths in summary mode\n --sample-output Show previous/new header sample for changed files\n --force-author-update Always update @Author/@Email to detected/current values\n --force-last-modified-author-update Always update @Last modified by to detected/current values\n --use-gpg-signer-author Use signed-commit UID (%GS) for detected @Author\n --cwd <path> Working directory for project detection\n --input <path> Single file or folder input\n --include-folder <path> Include folder (repeatable)\n --exclude-folder <path> Exclude folder name/path (repeatable)\n --include-extension <ext> Include extension (repeatable)\n --enable-detector <id> Enable only specific detector (repeatable)\n --disable-detector <id> Disable detector by id (repeatable)\n --project-name <name> Override project name\n --language <id> Override language id\n --project-root <path> Override project root\n --marker <name|null> Override marker filename\n --author-name <name> Override author name\n --author-email <email> Override author email\n --company <name> Append company suffix to @Author (Name <Company>)\n --company-name <name> Override company name\n --copyright-start-year <year> Override copyright start year\n --config <path> Load JSON options file\n\nExamples:\n fix-headers --dry-run --include-folder src\n fix-headers --project-name @scope/pkg --company-name "Catalyzed Motivation Inc."\n`;
27
27
 
28
28
  /**
29
29
  * Converts CLI flag token to camelCase key.
@@ -95,6 +95,10 @@ export function parseCliArgs(argv) {
95
95
  options.forceAuthorUpdate = true;
96
96
  continue;
97
97
  }
98
+ if (arg === "--force-last-modified-author-update") {
99
+ options.forceLastModifiedAuthorUpdate = true;
100
+ continue;
101
+ }
98
102
  if (arg === "--use-gpg-signer-author") {
99
103
  options.useGpgSignerAuthor = true;
100
104
  continue;
@@ -29,6 +29,7 @@ import { toDatePayload } from "../utils/time.mjs";
29
29
  * configFile?: string,
30
30
  * sampleOutput?: boolean,
31
31
  * forceAuthorUpdate?: boolean,
32
+ * forceLastModifiedAuthorUpdate?: boolean,
32
33
  * useGpgSignerAuthor?: boolean,
33
34
  * enabledDetectors?: string[],
34
35
  * disabledDetectors?: string[],
@@ -129,6 +130,20 @@ function extractHeaderAuthorIdentity(headerText) {
129
130
  };
130
131
  }
131
132
 
133
+ /**
134
+ * Extracts original last-modified-by identity from an existing header block.
135
+ * @param {string} headerText - Existing header content.
136
+ * @returns {{ authorName?: string, authorEmail?: string }} Parsed identity values.
137
+ */
138
+ function extractHeaderLastModifiedIdentity(headerText) {
139
+ const match = headerText.match(/@Last modified by:\s*(.+?)\s*\(([^)\n]+)\)\s*$/m);
140
+
141
+ return {
142
+ authorName: match?.[1]?.trim(),
143
+ authorEmail: match?.[2]?.trim()
144
+ };
145
+ }
146
+
132
147
  /**
133
148
  * Extracts original created-at payload from an existing header block.
134
149
  * @param {string} headerText - Existing header content.
@@ -253,6 +268,7 @@ export async function fixHeaders(options = {}) {
253
268
  });
254
269
  const existingHeaderText = existingHeader ? original.slice(existingHeader.start, existingHeader.end) : "";
255
270
  const existingIdentity = existingHeaderText.length > 0 ? extractHeaderAuthorIdentity(existingHeaderText) : {};
271
+ const existingLastModifiedIdentity = existingHeaderText.length > 0 ? extractHeaderLastModifiedIdentity(existingHeaderText) : {};
256
272
  const existingCreatedAt = existingHeaderText.length > 0 ? extractHeaderCreatedAt(existingHeaderText) : null;
257
273
  const existingLastModifiedAt = existingHeaderText.length > 0 ? extractHeaderLastModifiedAt(existingHeaderText) : null;
258
274
  const filesystemDates = await readFileDates(filePath);
@@ -270,6 +286,7 @@ export async function fixHeaders(options = {}) {
270
286
  const createdAt = existingCreatedAt || gitCreated || toDatePayload(filesystemDates.createdAt);
271
287
  const comparisonLastModifiedAt = existingLastModifiedAt || gitLastUpdated || toDatePayload(filesystemDates.updatedAt);
272
288
  const shouldForceAuthorUpdate = effectiveOptions.forceAuthorUpdate === true;
289
+ const shouldForceLastModifiedAuthorUpdate = effectiveOptions.forceLastModifiedAuthorUpdate === true;
273
290
 
274
291
  const comparisonHeader = buildHeader({
275
292
  absoluteFilePath: filePath,
@@ -284,8 +301,12 @@ export async function fixHeaders(options = {}) {
284
301
  projectName: fileMetadata.projectName,
285
302
  createdByName: shouldForceAuthorUpdate ? fileMetadata.authorName : existingIdentity.authorName || fileMetadata.authorName,
286
303
  createdByEmail: shouldForceAuthorUpdate ? fileMetadata.authorEmail : existingIdentity.authorEmail || fileMetadata.authorEmail,
287
- lastModifiedByName: fileMetadata.authorName,
288
- lastModifiedByEmail: fileMetadata.authorEmail,
304
+ lastModifiedByName: shouldForceLastModifiedAuthorUpdate
305
+ ? fileMetadata.authorName
306
+ : existingLastModifiedIdentity.authorName || fileMetadata.authorName,
307
+ lastModifiedByEmail: shouldForceLastModifiedAuthorUpdate
308
+ ? fileMetadata.authorEmail
309
+ : existingLastModifiedIdentity.authorEmail || fileMetadata.authorEmail,
289
310
  authorName: fileMetadata.authorName,
290
311
  authorEmail: fileMetadata.authorEmail,
291
312
  createdAt,
@@ -319,8 +340,12 @@ export async function fixHeaders(options = {}) {
319
340
  projectName: fileMetadata.projectName,
320
341
  createdByName: shouldForceAuthorUpdate ? fileMetadata.authorName : existingIdentity.authorName || fileMetadata.authorName,
321
342
  createdByEmail: shouldForceAuthorUpdate ? fileMetadata.authorEmail : existingIdentity.authorEmail || fileMetadata.authorEmail,
322
- lastModifiedByName: fileMetadata.authorName,
323
- lastModifiedByEmail: fileMetadata.authorEmail,
343
+ lastModifiedByName: shouldForceLastModifiedAuthorUpdate
344
+ ? fileMetadata.authorName
345
+ : existingLastModifiedIdentity.authorName || fileMetadata.authorName,
346
+ lastModifiedByEmail: shouldForceLastModifiedAuthorUpdate
347
+ ? fileMetadata.authorEmail
348
+ : existingLastModifiedIdentity.authorEmail || fileMetadata.authorEmail,
324
349
  authorName: fileMetadata.authorName,
325
350
  authorEmail: fileMetadata.authorEmail,
326
351
  createdAt,
@@ -1,7 +1,27 @@
1
1
  /** @type {string} */
2
2
  export const DEFAULT_COMPANY_NAME: string;
3
- /** @type {number} */
3
+ /** Header must sit near the top of the file, but a metadata block can legitimately
4
+ * run long; cap the scan generously so a long block's closing `*​/` is still seen.
5
+ * @type {number} */
4
6
  export const DEFAULT_MAX_HEADER_SCAN_LINES: number;
5
- /** @type {Set<string>} */
7
+ /**
8
+ * Folders skipped at ANY depth — vendored / VCS directories that are never source and can
9
+ * legitimately nest (hoisted `node_modules`, submodule `.git`).
10
+ * @type {Set<string>}
11
+ */
12
+ export const ALWAYS_IGNORE_FOLDERS: Set<string>;
13
+ /**
14
+ * Folders skipped ONLY at the project root — build / cache output directories. Anchored to
15
+ * the root so a nested SOURCE directory that happens to share the name (e.g. `tools/build`,
16
+ * `packages/x/dist`-style source) is still processed; only the top-level `/build`, `/dist`,
17
+ * `/coverage`, … are ignored.
18
+ * @type {Set<string>}
19
+ */
20
+ export const ROOT_IGNORE_FOLDERS: Set<string>;
21
+ /**
22
+ * Backward-compatible union of {@link ALWAYS_IGNORE_FOLDERS} and {@link ROOT_IGNORE_FOLDERS}.
23
+ * Discovery applies the two sets with different scoping; prefer the specific sets.
24
+ * @type {Set<string>}
25
+ */
6
26
  export const DEFAULT_IGNORE_FOLDERS: Set<string>;
7
27
  export { DETECTOR_PROFILES, getAllowedExtensions, getEnabledDetectors } from "./detectors/index.mjs";
@@ -7,8 +7,10 @@
7
7
  * enabledDetectors?: string[],
8
8
  * disabledDetectors?: string[],
9
9
  * includeFolders?: string[],
10
- * excludeFolders?: string[]
11
- * }} options - File discovery options.
10
+ * excludeFolders?: string[],
11
+ * gitignore?: boolean | string | string[]
12
+ * }} options - File discovery options. `gitignore`: `false` disables; a path or array of
13
+ * paths loads those ignore files; anything else / omitted auto-detects `<projectRoot>/.gitignore`.
12
14
  * @returns {Promise<string[]>} Absolute file paths.
13
15
  */
14
16
  export function discoverFiles(options: {
@@ -19,4 +21,5 @@ export function discoverFiles(options: {
19
21
  disabledDetectors?: string[];
20
22
  includeFolders?: string[];
21
23
  excludeFolders?: string[];
24
+ gitignore?: boolean | string | string[];
22
25
  }): Promise<string[]>;
@@ -15,6 +15,7 @@ export type FixHeadersOptions = {
15
15
  configFile?: string;
16
16
  sampleOutput?: boolean;
17
17
  forceAuthorUpdate?: boolean;
18
+ forceLastModifiedAuthorUpdate?: boolean;
18
19
  useGpgSignerAuthor?: boolean;
19
20
  enabledDetectors?: string[];
20
21
  disabledDetectors?: string[];
@@ -28,6 +29,7 @@ export type FixHeadersOptions = {
28
29
  includeFolders?: string[];
29
30
  excludeFolders?: string[];
30
31
  includeExtensions?: string[];
32
+ gitignore?: boolean | string | string[];
31
33
  projectName?: string;
32
34
  language?: string;
33
35
  projectRoot?: string;
@@ -26,13 +26,14 @@ export function getDetectorById(id: string): (typeof DETECTOR_PROFILES)[number]
26
26
  /**
27
27
  * Resolves comment syntax for a file path using detector-specific templates.
28
28
  * @param {string} filePath - File path.
29
- * @param {{ language?: string, enabledDetectors?: string[], disabledDetectors?: string[], detectorSyntaxOverrides?: Record<string, { linePrefix?: string, lineSeparator?: string, blockStart?: string, blockLinePrefix?: string, blockEnd?: string }> }} [options={}] - Runtime options.
29
+ * @param {{ language?: string, enabledDetectors?: string[], disabledDetectors?: string[], detectors?: DetectorProfile[], detectorSyntaxOverrides?: Record<string, { linePrefix?: string, lineSeparator?: string, blockStart?: string, blockLinePrefix?: string, blockEnd?: string }> }} [options={}] - Runtime options. `detectors` overrides the enabled-detector set (matching {@link detectProjectFromMarkers}).
30
30
  * @returns {{kind: "block" | "line" | "html", linePrefix?: string, lineSeparator?: string, blockStart?: string, blockLinePrefix?: string, blockEnd?: string}} Syntax descriptor.
31
31
  */
32
32
  export function getCommentSyntaxForFile(filePath: string, options?: {
33
33
  language?: string;
34
34
  enabledDetectors?: string[];
35
35
  disabledDetectors?: string[];
36
+ detectors?: DetectorProfile[];
36
37
  detectorSyntaxOverrides?: Record<string, {
37
38
  linePrefix?: string;
38
39
  lineSeparator?: string;