@cldmv/fix-headers 1.1.1 → 1.2.2

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
@@ -100,6 +100,7 @@ Important options:
100
100
  - `marker?: string | null`
101
101
  - `authorName?: string`
102
102
  - `authorEmail?: string`
103
+ - `company?: string` - appends to `@Author` as `Name <Company>`
103
104
  - `forceAuthorUpdate?: boolean` - force update `@Author`/`@Email` to detected or overridden current values
104
105
  - `useGpgSignerAuthor?: boolean` - use signed-commit UID (`%GS`) for detected `@Author` (includes signer comment when present)
105
106
  - `companyName?: string` (default: `Catalyzed Motivation Inc.`)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cldmv/fix-headers",
3
- "version": "1.1.1",
3
+ "version": "1.2.2",
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 <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 --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.
@@ -63,6 +63,7 @@ export function parseCliArgs(argv) {
63
63
  marker: "marker",
64
64
  "author-name": "authorName",
65
65
  "author-email": "authorEmail",
66
+ company: "company",
66
67
  "company-name": "companyName",
67
68
  "copyright-start-year": "copyrightStartYear",
68
69
  config: "config"
@@ -6,12 +6,13 @@
6
6
  * @Email: <Shinrai@users.noreply.github.com>
7
7
  * -----
8
8
  * @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
9
- * @Last modified time: 2026-03-01T17:59:32-08:00 (1772416772)
9
+ * @Last modified time: 2026-03-04 20:59:30 -08:00 (1772686770)
10
10
  * -----
11
- * @Copyright: Copyright (c) 2026-2026 Catalyzed Motivation Inc. All rights reserved.
11
+ * @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
12
12
  */
13
13
 
14
14
  import { join, relative, resolve } from "node:path";
15
+ import { stat } from "node:fs/promises";
15
16
  import { DEFAULT_IGNORE_FOLDERS } from "../constants.mjs";
16
17
  import { getAllowedExtensions } from "../detectors/index.mjs";
17
18
  import { walkFiles } from "../utils/fs.mjs";
@@ -58,6 +59,17 @@ function resolveIncludeFolders(includeFolders) {
58
59
  return [];
59
60
  }
60
61
 
62
+ /**
63
+ * Warns when an include folder cannot be scanned and is skipped.
64
+ * @param {string} includeFolder - Project-relative include folder.
65
+ * @param {unknown} error - Original filesystem error.
66
+ * @returns {void}
67
+ */
68
+ function reportSkippedIncludeFolder(includeFolder, error) {
69
+ const message = error instanceof Error ? error.message : String(error);
70
+ console.warn(`fix-headers: skipped include folder \"${includeFolder}\" (${message})`);
71
+ }
72
+
61
73
  /**
62
74
  * Builds a directory exclusion matcher from path and folder-name lists.
63
75
  * @param {string} projectRoot - Project root path.
@@ -128,13 +140,29 @@ export async function discoverFiles(options) {
128
140
  const includeFolders = resolveIncludeFolders(options.includeFolders);
129
141
  const excludeFolders = Array.isArray(options.excludeFolders) ? options.excludeFolders : [];
130
142
  const exclusionMatcher = buildExclusionMatcher(options.projectRoot, excludeFolders);
131
-
132
143
  const roots =
133
- includeFolders.length > 0 ? includeFolders.map((relativePath) => join(options.projectRoot, relativePath)) : [options.projectRoot];
144
+ includeFolders.length > 0
145
+ ? includeFolders.map((includeFolder) => ({ includeFolder, rootPath: join(options.projectRoot, includeFolder) }))
146
+ : [{ includeFolder: ".", rootPath: options.projectRoot }];
134
147
 
135
148
  const files = [];
136
- for (const rootPath of roots) {
137
- const discovered = await walkFiles(rootPath, {
149
+ for (const root of roots) {
150
+ const rootStats = await stat(root.rootPath).catch((error) => error);
151
+ if (rootStats instanceof Error) {
152
+ if (/** @type {{ code?: string }} */ (rootStats).code === "ENOENT") {
153
+ reportSkippedIncludeFolder(root.includeFolder, rootStats);
154
+ continue;
155
+ }
156
+
157
+ throw rootStats;
158
+ }
159
+
160
+ if (!rootStats.isDirectory()) {
161
+ reportSkippedIncludeFolder(root.includeFolder, `path is not a directory: ${root.rootPath}`);
162
+ continue;
163
+ }
164
+
165
+ const discovered = await walkFiles(root.rootPath, {
138
166
  allowedExtensions,
139
167
  ignoreFolders: DEFAULT_IGNORED_FOLDERS,
140
168
  shouldSkipDirectory: exclusionMatcher
@@ -42,6 +42,7 @@ import { toDatePayload } from "../utils/time.mjs";
42
42
  * marker?: string | null,
43
43
  * authorName?: string,
44
44
  * authorEmail?: string,
45
+ * company?: string,
45
46
  * companyName?: string,
46
47
  * copyrightStartYear?: number
47
48
  * }} FixHeadersOptions
@@ -73,6 +73,29 @@ async function findClosestDetectorMatch(startPath, detectors, preferredExtension
73
73
  return closest;
74
74
  }
75
75
 
76
+ /**
77
+ * Appends company suffix to author display name when requested.
78
+ * @param {string} authorName - Base author name.
79
+ * @param {string | undefined} company - Optional company suffix value.
80
+ * @returns {string} Formatted author name.
81
+ */
82
+ function formatAuthorNameWithCompany(authorName, company) {
83
+ if (typeof company !== "string") {
84
+ return authorName;
85
+ }
86
+
87
+ const trimmedCompany = company.trim();
88
+ if (trimmedCompany.length === 0) {
89
+ return authorName;
90
+ }
91
+
92
+ if (/<[^>]+>/.test(authorName)) {
93
+ return authorName;
94
+ }
95
+
96
+ return `${authorName} <${trimmedCompany}>`;
97
+ }
98
+
76
99
  /**
77
100
  * Detects project root and language by scanning known marker files.
78
101
  * @param {string} cwd - Starting working directory.
@@ -126,6 +149,7 @@ export async function detectProjectFromMarkers(cwd, options = {}) {
126
149
  * useGpgSignerAuthor?: boolean,
127
150
  * authorName?: string,
128
151
  * authorEmail?: string,
152
+ * company?: string,
129
153
  * companyName?: string,
130
154
  * copyrightStartYear?: number
131
155
  * }} [options={}] - Detection options and overrides.
@@ -151,13 +175,14 @@ export async function resolveProjectMetadata(options = {}) {
151
175
  useGpgSignerAuthor: options.useGpgSignerAuthor === true
152
176
  });
153
177
  const currentYear = new Date().getFullYear();
178
+ const baseAuthorName = options.authorName || gitAuthor.authorName || "Unknown Author";
154
179
 
155
180
  return {
156
181
  projectName: options.projectName || detected.projectName,
157
182
  language: options.language || detected.language,
158
183
  projectRoot: options.projectRoot || detected.rootDir,
159
184
  marker: options.marker === undefined ? detected.marker : options.marker,
160
- authorName: options.authorName || gitAuthor.authorName || "Unknown Author",
185
+ authorName: formatAuthorNameWithCompany(baseAuthorName, options.company),
161
186
  authorEmail: options.authorEmail || gitAuthor.authorEmail || "unknown@example.com",
162
187
  companyName: options.companyName || DEFAULT_COMPANY_NAME,
163
188
  copyrightStartYear: Number.isInteger(options.copyrightStartYear) ? Number(options.copyrightStartYear) : currentYear
@@ -0,0 +1,76 @@
1
+ /**
2
+ * @Project: @cldmv/fix-headers
3
+ * @Filename: /src/detectors/json.mjs
4
+ * @Date: 2026-03-01 20:00:00 -08:00 (1772433600)
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-03-01 20:00:00 -08:00 (1772433600)
10
+ * -----
11
+ * @Copyright: Copyright (c) 2026-2026 Catalyzed Motivation Inc. All rights reserved.
12
+ */
13
+
14
+ import { extname } from "node:path";
15
+ import { findNearestMarker } from "./shared.mjs";
16
+
17
+ /**
18
+ * @fileoverview JSON-family detector implementation.
19
+ * @module fix-headers/detectors/json
20
+ */
21
+
22
+ const markers = ["package.json"];
23
+ const extensions = [".jsonv", ".jsonc", ".json5"];
24
+
25
+ /**
26
+ * Parses project name from package marker content.
27
+ * @param {string} markerContent - Marker file content.
28
+ * @param {string} rootDirName - Fallback root directory name.
29
+ * @returns {string} Project name.
30
+ */
31
+ function parseJsonProjectName(markerContent, rootDirName) {
32
+ try {
33
+ const parsed = JSON.parse(markerContent);
34
+ if (typeof parsed.name === "string" && parsed.name.trim().length > 0) {
35
+ return parsed.name.trim();
36
+ }
37
+ return rootDirName;
38
+ } catch {
39
+ return rootDirName;
40
+ }
41
+ }
42
+
43
+ /**
44
+ * Resolves comment syntax for JSON-family file extensions.
45
+ * @param {string} filePath - File path.
46
+ * @returns {{kind: "block", blockStart: string, blockLinePrefix: string, blockEnd: string} | null} Syntax descriptor.
47
+ */
48
+ function resolveJsonCommentSyntax(filePath) {
49
+ const extension = extname(filePath).toLowerCase();
50
+ if (extensions.includes(extension)) {
51
+ return {
52
+ kind: "block",
53
+ blockStart: "/**",
54
+ blockLinePrefix: " *\t",
55
+ blockEnd: " */"
56
+ };
57
+ }
58
+ return null;
59
+ }
60
+
61
+ export const detector = {
62
+ id: "json",
63
+ priority: 95,
64
+ markers,
65
+ extensions,
66
+ enabledByDefault: true,
67
+ findNearestConfig(startPath) {
68
+ return findNearestMarker(startPath, markers);
69
+ },
70
+ parseProjectName(_marker, markerContent, rootDirName) {
71
+ return parseJsonProjectName(markerContent, rootDirName);
72
+ },
73
+ resolveCommentSyntax(filePath) {
74
+ return resolveJsonCommentSyntax(filePath);
75
+ }
76
+ };
@@ -20,7 +20,7 @@ import { findNearestMarker } from "./shared.mjs";
20
20
  */
21
21
 
22
22
  const markers = ["package.json"];
23
- const extensions = [".js", ".mjs", ".cjs", ".ts", ".tsx", ".jsx", ".jsonv", ".jsonc", ".json5"];
23
+ const extensions = [".js", ".mjs", ".cjs", ".ts", ".tsx", ".jsx"];
24
24
 
25
25
  /**
26
26
  * Parses Node project name from package marker content.
@@ -34,6 +34,7 @@ export type FixHeadersOptions = {
34
34
  marker?: string | null;
35
35
  authorName?: string;
36
36
  authorEmail?: string;
37
+ company?: string;
37
38
  companyName?: string;
38
39
  copyrightStartYear?: number;
39
40
  };
@@ -43,6 +43,7 @@ export function detectProjectFromMarkers(cwd: string, options?: {
43
43
  * useGpgSignerAuthor?: boolean,
44
44
  * authorName?: string,
45
45
  * authorEmail?: string,
46
+ * company?: string,
46
47
  * companyName?: string,
47
48
  * copyrightStartYear?: number
48
49
  * }} [options={}] - Detection options and overrides.
@@ -69,6 +70,7 @@ export function resolveProjectMetadata(options?: {
69
70
  useGpgSignerAuthor?: boolean;
70
71
  authorName?: string;
71
72
  authorEmail?: string;
73
+ company?: string;
72
74
  companyName?: string;
73
75
  copyrightStartYear?: number;
74
76
  }): Promise<{
@@ -0,0 +1,25 @@
1
+ export namespace detector {
2
+ export let id: string;
3
+ export let priority: number;
4
+ export { markers };
5
+ export { extensions };
6
+ export let enabledByDefault: boolean;
7
+ export function findNearestConfig(startPath: any): Promise<{
8
+ root: string;
9
+ marker: string;
10
+ }>;
11
+ export function parseProjectName(_marker: any, markerContent: any, rootDirName: any): string;
12
+ export function resolveCommentSyntax(filePath: any): {
13
+ kind: "block";
14
+ blockStart: string;
15
+ blockLinePrefix: string;
16
+ blockEnd: string;
17
+ };
18
+ }
19
+ /**
20
+ * @fileoverview JSON-family detector implementation.
21
+ * @module fix-headers/detectors/json
22
+ */
23
+ declare const markers: string[];
24
+ declare const extensions: string[];
25
+ export {};