@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.
Files changed (63) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +313 -25
  3. package/bin/fix-headers.mjs +70 -0
  4. package/dist/index.cjs +28 -0
  5. package/dist/index.mjs +23 -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 +1 -23
  10. package/types/src/core/file-discovery.d.mts +17 -5
  11. package/types/src/core/fix-headers.d.mts +59 -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 +28 -7
  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/template.d.mts +4 -3
  34. package/types/src/utils/diff.d.mts +53 -0
  35. package/types/src/utils/fs.d.mts +10 -3
  36. package/types/src/utils/git.d.mts +27 -0
  37. package/types/src/utils/time.d.mts +55 -0
  38. package/index.cjs +0 -39
  39. package/index.mjs +0 -20
  40. package/src/cli.mjs +0 -323
  41. package/src/constants.mjs +0 -50
  42. package/src/core/file-discovery.mjs +0 -213
  43. package/src/core/fix-headers.mjs +0 -413
  44. package/src/detect/project.mjs +0 -190
  45. package/src/detectors/css.mjs +0 -67
  46. package/src/detectors/go.mjs +0 -65
  47. package/src/detectors/html.mjs +0 -67
  48. package/src/detectors/index.mjs +0 -187
  49. package/src/detectors/json.mjs +0 -76
  50. package/src/detectors/node.mjs +0 -90
  51. package/src/detectors/php.mjs +0 -66
  52. package/src/detectors/python.mjs +0 -75
  53. package/src/detectors/rust.mjs +0 -62
  54. package/src/detectors/shared.mjs +0 -45
  55. package/src/detectors/yaml.mjs +0 -79
  56. package/src/fix-header.mjs +0 -30
  57. package/src/header/parser.mjs +0 -145
  58. package/src/header/syntax.mjs +0 -69
  59. package/src/header/template.mjs +0 -65
  60. package/src/utils/fs.mjs +0 -138
  61. package/src/utils/git.mjs +0 -135
  62. package/src/utils/time.mjs +0 -44
  63. package/types/src/detectors/shared.d.mts +0 -14
package/src/utils/git.mjs DELETED
@@ -1,135 +0,0 @@
1
- /**
2
- * @Project: @cldmv/fix-headers
3
- * @Filename: /src/utils/git.mjs
4
- * @Date: 2026-03-01T17:59:32-08:00 (1772416772)
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-01T17:59:32-08:00 (1772416772)
10
- * -----
11
- * @Copyright: Copyright (c) 2026-2026 Catalyzed Motivation Inc. All rights reserved.
12
- */
13
-
14
- import { execFile } from "node:child_process";
15
- import { promisify } from "node:util";
16
-
17
- const execFileAsync = promisify(execFile);
18
-
19
- /**
20
- * @fileoverview Git helpers for author identity and file history metadata.
21
- * @module fix-headers/utils/git
22
- */
23
-
24
- /**
25
- * Runs a git command and returns trimmed stdout.
26
- * @param {string} cwd - Working directory.
27
- * @param {string[]} args - Git command arguments.
28
- * @returns {Promise<string | null>} Trimmed stdout or null on failure.
29
- */
30
- export async function runGit(cwd, args) {
31
- try {
32
- const { stdout } = await execFileAsync("git", args, { cwd });
33
- const value = stdout.trim();
34
- return value.length > 0 ? value : null;
35
- } catch {
36
- return null;
37
- }
38
- }
39
-
40
- /**
41
- * Parses a signer UID string into author name and optional email.
42
- * @param {string} signerUid - Raw signer UID (for example: "Name (Comment) <email@example.com>").
43
- * @returns {{authorName: string | null, authorEmail: string | null}} Parsed signer identity.
44
- */
45
- function parseSignerUid(signerUid) {
46
- const trimmed = signerUid.trim();
47
- if (trimmed.length === 0) {
48
- return { authorName: null, authorEmail: null };
49
- }
50
-
51
- const emailMatch = trimmed.match(/<([^>\n]+)>\s*$/);
52
- const authorEmail = emailMatch?.[1]?.trim() || null;
53
- const authorName = (emailMatch ? trimmed.slice(0, emailMatch.index) : trimmed).trim() || null;
54
-
55
- return { authorName, authorEmail };
56
- }
57
-
58
- /**
59
- * Detects git author name and email from config or commit history.
60
- * @param {string} cwd - Project directory.
61
- * @param {{useGpgSignerAuthor?: boolean}} [options={}] - Detection options.
62
- * @returns {Promise<{authorName: string | null, authorEmail: string | null}>} Author information.
63
- */
64
- export async function detectGitAuthor(cwd, options = {}) {
65
- let authorName = await runGit(cwd, ["config", "--get", "user.name"]);
66
- let authorEmail = await runGit(cwd, ["config", "--get", "user.email"]);
67
- if (options.useGpgSignerAuthor === true) {
68
- const signerUid = await runGit(cwd, ["log", "-1", "--format=%GS"]);
69
- const signerIdentity = parseSignerUid(signerUid || "");
70
- authorName = signerIdentity.authorName || authorName;
71
- authorEmail = authorEmail || signerIdentity.authorEmail;
72
- }
73
-
74
- if (!authorName || !authorEmail) {
75
- const fallback = await runGit(cwd, ["log", "-1", "--format=%an|%ae"]);
76
- if (fallback) {
77
- const [fallbackName, fallbackEmail] = fallback.split("|");
78
- authorName = authorName || fallbackName || null;
79
- authorEmail = authorEmail || fallbackEmail || null;
80
- }
81
- }
82
-
83
- return { authorName, authorEmail };
84
- }
85
-
86
- /**
87
- * Gets a file's first commit date from git history.
88
- * @param {string} cwd - Project directory.
89
- * @param {string} filePath - Relative file path.
90
- * @returns {Promise<{date: string, timestamp: number} | null>} Git creation date payload.
91
- */
92
- export async function getGitCreationDate(cwd, filePath) {
93
- const output = await runGit(cwd, ["log", "--follow", "--format=%aI|%at", "--reverse", "--", filePath]);
94
- if (!output) {
95
- return null;
96
- }
97
-
98
- const firstLine = output.split("\n")[0];
99
- const [date, timestampText] = firstLine.split("|");
100
- if (!date || !timestampText) {
101
- return null;
102
- }
103
-
104
- const timestamp = Number.parseInt(timestampText, 10);
105
- if (Number.isNaN(timestamp)) {
106
- return null;
107
- }
108
-
109
- return { date, timestamp };
110
- }
111
-
112
- /**
113
- * Gets a file's latest commit date from git history.
114
- * @param {string} cwd - Project directory.
115
- * @param {string} filePath - Relative file path.
116
- * @returns {Promise<{date: string, timestamp: number} | null>} Git last-modified payload.
117
- */
118
- export async function getGitLastModifiedDate(cwd, filePath) {
119
- const output = await runGit(cwd, ["log", "-1", "--format=%aI|%at", "--", filePath]);
120
- if (!output) {
121
- return null;
122
- }
123
-
124
- const [date, timestampText] = output.split("|");
125
- if (!date || !timestampText) {
126
- return null;
127
- }
128
-
129
- const timestamp = Number.parseInt(timestampText, 10);
130
- if (Number.isNaN(timestamp)) {
131
- return null;
132
- }
133
-
134
- return { date, timestamp };
135
- }
@@ -1,44 +0,0 @@
1
- /**
2
- * @Project: @cldmv/fix-headers
3
- * @Filename: /src/utils/time.mjs
4
- * @Date: 2026-03-01T17:59:32-08:00 (1772416772)
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-01T17:59:32-08:00 (1772416772)
10
- * -----
11
- * @Copyright: Copyright (c) 2026-2026 Catalyzed Motivation Inc. All rights reserved.
12
- */
13
-
14
- /**
15
- * @fileoverview Date/time helpers used for header timestamp formatting.
16
- * @module fix-headers/utils/time
17
- */
18
-
19
- /**
20
- * Formats a date as `YYYY-MM-DD HH:mm:ss ±HH:MM`.
21
- * @param {Date} date - Input date.
22
- * @returns {string} Formatted date string.
23
- */
24
- export function formatDateWithTimezone(date) {
25
- const pad = (value) => String(value).padStart(2, "0");
26
- const tzOffset = -date.getTimezoneOffset();
27
- const sign = tzOffset >= 0 ? "+" : "-";
28
- const tzHours = pad(Math.floor(Math.abs(tzOffset) / 60));
29
- const tzMinutes = pad(Math.abs(tzOffset) % 60);
30
-
31
- return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())} ${sign}${tzHours}:${tzMinutes}`;
32
- }
33
-
34
- /**
35
- * Returns a formatted date and unix timestamp.
36
- * @param {Date} [date=new Date()] - Date value to format.
37
- * @returns {{ date: string, timestamp: number }} Formatted datetime payload.
38
- */
39
- export function toDatePayload(date = new Date()) {
40
- return {
41
- date: formatDateWithTimezone(date),
42
- timestamp: Math.floor(date.getTime() / 1000)
43
- };
44
- }
@@ -1,14 +0,0 @@
1
- /**
2
- * @fileoverview Shared detector helpers for nearest marker search.
3
- * @module fix-headers/detectors/shared
4
- */
5
- /**
6
- * Finds the closest marker file by walking up parent directories.
7
- * @param {string} startPath - Starting directory or file path.
8
- * @param {string[]} markers - Marker filenames to search.
9
- * @returns {Promise<{root: string, marker: string} | null>} Closest located marker.
10
- */
11
- export function findNearestMarker(startPath: string, markers: string[]): Promise<{
12
- root: string;
13
- marker: string;
14
- } | null>;