@cldmv/fix-headers 1.2.0 → 1.2.3
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
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
# fix-headers
|
|
1
|
+
# @cldmv/fix-headers
|
|
2
2
|
|
|
3
3
|
Multi-language source header normalizer for Node.js projects.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
`@cldmv/fix-headers` scans project files, auto-detects project metadata (language, root, project name, git author/email), and inserts or updates standard file headers.
|
|
6
6
|
|
|
7
7
|
[![npm version]][npm_version_url] [![npm downloads]][npm_downloads_url] <!-- [![GitHub release]][github_release_url] -->[![GitHub downloads]][github_downloads_url] [![Last commit]][last_commit_url] <!-- [![Release date]][release_date_url] -->[![npm last update]][npm_last_update_url] [![Coverage]][coverage_url]
|
|
8
8
|
|
|
@@ -21,7 +21,7 @@ Multi-language source header normalizer for Node.js projects.
|
|
|
21
21
|
## Install
|
|
22
22
|
|
|
23
23
|
```bash
|
|
24
|
-
npm i fix-headers
|
|
24
|
+
npm i @cldmv/fix-headers
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
## Usage
|
|
@@ -29,7 +29,7 @@ npm i fix-headers
|
|
|
29
29
|
### ESM
|
|
30
30
|
|
|
31
31
|
```js
|
|
32
|
-
import fixHeaders from "fix-headers";
|
|
32
|
+
import fixHeaders from "@cldmv/fix-headers";
|
|
33
33
|
|
|
34
34
|
const result = await fixHeaders({ dryRun: true });
|
|
35
35
|
```
|
|
@@ -70,7 +70,7 @@ Common CLI options:
|
|
|
70
70
|
### CommonJS
|
|
71
71
|
|
|
72
72
|
```js
|
|
73
|
-
const fixHeaders = require("fix-headers");
|
|
73
|
+
const fixHeaders = require("@cldmv/fix-headers");
|
|
74
74
|
|
|
75
75
|
const result = await fixHeaders({ dryRun: true });
|
|
76
76
|
```
|
package/package.json
CHANGED
|
@@ -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-
|
|
9
|
+
* @Last modified time: 2026-03-04 20:59:30 -08:00 (1772686770)
|
|
10
10
|
* -----
|
|
11
|
-
* @Copyright: Copyright (c)
|
|
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
|
|
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
|
|
137
|
-
const
|
|
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
|
package/src/header/parser.mjs
CHANGED
|
@@ -66,9 +66,19 @@ function matchHeaderSegment(content, syntax) {
|
|
|
66
66
|
return content.match(new RegExp(`^(?:${linePrefix}.*\\n)+\\n*`));
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
69
|
+
// Block comments (/* … */ family). A block comment opens with `/*` and is
|
|
70
|
+
// terminated by the FIRST `*/` after the opener (block comments do not nest in
|
|
71
|
+
// JS/JSONC/CSS/PHP). Match that real grammar rather than the detector's *styled*
|
|
72
|
+
// tokens: `blockStart` may be `/*` or `/**` (so anchor on `/*`, which prefixes
|
|
73
|
+
// both), and `blockEnd` carries a leading space (" */") that exists for GENERATION
|
|
74
|
+
// only. Using the styled " */" to bound an EXISTING header is the data-loss bug —
|
|
75
|
+
// any real closer that isn't byte-for-byte " */" (e.g. `**/`, a tab-indented `*/`,
|
|
76
|
+
// or `*/` at column 0) is skipped, so the lazy match runs on to the next `*/`
|
|
77
|
+
// downstream (inside a `//` line comment, a string literal, or another block) and
|
|
78
|
+
// everything in between is deleted on replace. Trim the styled space off so we stop
|
|
79
|
+
// at the header's own terminator.
|
|
80
|
+
const blockEnd = escapeRegex((syntax.blockEnd || " */").trim());
|
|
81
|
+
return content.match(new RegExp(`^/\\*[\\s\\S]*?${blockEnd}\\n*`));
|
|
72
82
|
}
|
|
73
83
|
|
|
74
84
|
/**
|
|
@@ -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 {};
|