@cldmv/fix-headers 2.2.4 → 2.2.6
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 +8 -8
- package/bin/fix-headers.mjs +25 -25
- package/dist/index.cjs +5 -5
- package/dist/index.mjs +18 -18
- package/package.json +12 -6
- package/types/devcheck.d.mts +1 -0
package/README.md
CHANGED
|
@@ -14,18 +14,17 @@ Headers stay correct without hand-editing: `@Date` follows the file's real creat
|
|
|
14
14
|
|
|
15
15
|
## ✨ What's New
|
|
16
16
|
|
|
17
|
-
### Latest: v2.2.
|
|
17
|
+
### Latest: v2.2.6 (November 2026)
|
|
18
18
|
|
|
19
|
-
-
|
|
20
|
-
-
|
|
21
|
-
- [View full v2.2.4 Changelog](https://github.com/CLDMV/fix-headers/blob/master/docs/changelog/v2/v2.2.4.md)
|
|
19
|
+
- **`engines.node` is the runtime floor again** — `engines.node` is back to `>=18.0.0`, the version the package actually needs, instead of v2.2.5's `>=22.22.0`, so installs on Node.js 18 through 22.21 no longer get an engine warning. The 22.22.0 development toolchain floor moves to `devEngines`, which only applies to work on this repository. `require()` still needs Node.js ^20.19.0 or >=22.13.0, and its error message now says so ([#176](https://github.com/CLDMV/fix-headers/pull/176)).
|
|
20
|
+
- [View full v2.2.6 Changelog](https://github.com/CLDMV/fix-headers/blob/master/docs/changelog/v2/v2.2.6.md)
|
|
22
21
|
|
|
23
22
|
### Recent Releases
|
|
24
23
|
|
|
24
|
+
- **v2.2.5** (November 2026) — the source-checkout development check is removed (the `fix-headers-dev` condition already picks `src/` or `dist/`), and `engines.node` went to `>=22.22.0` ([Changelog](https://github.com/CLDMV/fix-headers/blob/master/docs/changelog/v2/v2.2.5.md))
|
|
25
|
+
- **v2.2.4** (October 2026) — one header per file: stacked headers merge, repeated fields and stale `@Copyright` lines are dropped, only position-critical lines stay above the header, `#` headers are found in CRLF and byte-order-mark files ([Changelog](https://github.com/CLDMV/fix-headers/blob/master/docs/changelog/v2/v2.2.4.md))
|
|
25
26
|
- **v2.2.3** (October 2026) — text inside an existing header that is not a header field is kept instead of deleted, moved to its own block below the header by default (`strictHeaderBlock`), plus a dependency refresh ([Changelog](https://github.com/CLDMV/fix-headers/blob/master/docs/changelog/v2/v2.2.3.md))
|
|
26
27
|
- **v2.2.2** (October 2026) — dependency refresh with nothing the package ships changed: `ignore` 7.0.12 within its range, plus `@cldmv/vitest-runner` 1.5.3, `vitest` 5.0.3, `eslint` 10.12.0 and `globals` 17.13.0 ([Changelog](https://github.com/CLDMV/fix-headers/blob/master/docs/changelog/v2/v2.2.2.md))
|
|
27
|
-
- **v2.2.1** (October 2026) — development-setup patch: the repository's own `fix:headers` run moves to `@cldmv/configs` 1.2.4, whose shared config no longer forces author updates; nothing the package ships changed ([Changelog](https://github.com/CLDMV/fix-headers/blob/master/docs/changelog/v2/v2.2.1.md))
|
|
28
|
-
- **v2.2.0** (October 2026) — `@Last modified by` names whoever last edited the file's content: a run that only rewrites a header keeps the recorded editor instead of writing the run's identity ([Changelog](https://github.com/CLDMV/fix-headers/blob/master/docs/changelog/v2/v2.2.0.md))
|
|
29
28
|
|
|
30
29
|
📚 For complete release notes, see the [docs/changelog/](https://github.com/CLDMV/fix-headers/tree/master/docs/changelog/) folder.
|
|
31
30
|
|
|
@@ -51,8 +50,9 @@ Headers stay correct without hand-editing: `@Date` follows the file's real creat
|
|
|
51
50
|
|
|
52
51
|
### Requirements
|
|
53
52
|
|
|
54
|
-
- **Node.js
|
|
55
|
-
-
|
|
53
|
+
- **Node.js 18.0.0 or later** (`engines.node` is `>=18.0.0`). The package is an ES module and loads with `import` on every supported version. Remote (`https://`) config `extends` uses the global `fetch`, which Node.js 18 has.
|
|
54
|
+
- `require("@cldmv/fix-headers")` loads the ES module build synchronously, which needs Node.js ^20.19.0 or >=22.13.0; on older Node.js, use `import()` instead.
|
|
55
|
+
- Developing this package needs Node.js 22.22.0 or later (`devEngines`).
|
|
56
56
|
|
|
57
57
|
### Install
|
|
58
58
|
|
package/bin/fix-headers.mjs
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var
|
|
3
|
-
`,r),a=i===-1?e.length:i+1;if(!t(e.slice(r,a).replace(/\r?\n$/,""),o))break;r=a,o+=1}return e.slice(0,r)}s(se,"takeTopLines");var xt=[".go"];function
|
|
4
|
-
`).length-1);return`${o}${a}`}s(ce,"getPreservedPrefixForFile");function Bt(e,t,n={}){let r=Ut(e,n);return r&&typeof r.resolveContentSkipReason=="function"?r.resolveContentSkipReason(t):null}s(Bt,"getContentSkipReason");var zt=200,Z=1,le=2;function T(e,t,n){if(e==null)return n;if(typeof e!="number"||!Number.isInteger(e)||e<0)throw new Error(`${t} must be a whole number of 0 or more, got ${JSON.stringify(e)}`);return e}s(T,"resolveLayoutCount");import{existsSync as
|
|
5
|
-
`)}s(
|
|
6
|
-
`,n);n=r===-1?e.length:r+1}else if(/\s/.test(e[n]))n+=1;else break;return n}s(
|
|
7
|
-
`)){let a=i.split(":");if(a[0]==="uid"&&a[1]!=="r"&&a[1]!=="e"&&a[9])return
|
|
8
|
-
`)[0],[o,i]=r.split("|");if(!o||!i)return null;let a=Number.parseInt(i,10);return Number.isNaN(a)?null:{date:An(o),timestamp:a}}s(Dn,"getGitCreationDate");async function Cn(e,t){let n=await F(e,["log","-1","--format=%aI|%at","--",t]);if(!n)return null;let[r,o]=n.split("|");if(!r||!o)return null;let i=Number.parseInt(o,10);return Number.isNaN(i)?null:{date:An(r),timestamp:i}}s(Cn,"getGitLastModifiedDate");var
|
|
2
|
+
var mr=Object.defineProperty;var s=(e,t)=>mr(e,"name",{value:t,configurable:!0});import{realpathSync as er}from"node:fs";import{fileURLToPath as ki,pathToFileURL as Ei}from"node:url";import{readFile as pr}from"node:fs/promises";import{createRequire as hr}from"node:module";import{dirname as gr,isAbsolute as yr,resolve as dt}from"node:path";var xr=3e4,wr=new Set(["localhost","127.0.0.1","[::1]"]);function we(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}s(we,"isPlainObject");function be(e,t){let n={...e};for(let[r,o]of Object.entries(t))r!=="__proto__"&&(n[r]=we(n[r])&&we(o)?be(n[r],o):o);return n}s(be,"mergeConfig");function mt(e){return e.kind==="file"?e.path:e.href}s(mt,"describeSource");async function br(e){if(e.kind==="file")return{text:await pr(e.path,"utf8"),source:e};let t;try{t=await fetch(e.href,{cache:"no-store",redirect:"follow",signal:AbortSignal.timeout(xr)})}catch(n){let r=n.cause instanceof Error?n.cause.message:n.message;throw new Error(`Failed to fetch config ${e.href}: ${r}`,{cause:n})}if(!t.ok)throw new Error(`Failed to fetch config ${e.href}: HTTP ${t.status} ${t.statusText}`);return{text:await t.text(),source:{kind:"url",href:t.url}}}s(br,"readSource");function ft(e){if(e.protocol==="http:"&&!wr.has(e.hostname))throw new Error(`Refusing to fetch config over plain http: ${e.href} (use https)`);return{kind:"url",href:e.href}}s(ft,"toUrlSource");function kr(e,t){if(/^https?:\/\//i.test(e))return ft(new URL(e));if(/^[a-z][a-z\d+.-]+:\/\//i.test(e))throw new Error(`Unsupported extends URL "${e}" in ${mt(t)}; use https, a file path or a package path`);let n=/^\.{1,2}[\\/]/.test(e);if(t.kind==="url"){if(n||e.startsWith("/"))return ft(new URL(e,t.href));throw new Error(`Cannot extend package "${e}" from the remote config ${t.href}; use a URL or a relative path`)}if(n||yr(e))return{kind:"file",path:dt(gr(t.path),e)};try{return{kind:"file",path:hr(t.path).resolve(e)}}catch(r){throw new Error(`Cannot resolve extends "${e}" from ${t.path}: ${r.message}`,{cause:r})}}s(kr,"resolveReference");function Er(e,t){if(e===void 0)return[];let n=Array.isArray(e)?e:[e];if(!n.every(r=>typeof r=="string"&&r.trim().length>0))throw new Error(`Config "extends" must be a string or an array of strings: ${t}`);return n.map(r=>r.trim())}s(Er,"readExtends");async function pt(e,t){let n=mt(e);if(t.includes(n))throw new Error(`Config extends cycle: ${[...t,n].join(" -> ")}`);let{text:r,source:o}=await br(e),i;try{i=JSON.parse(r)}catch(f){throw new Error(`Config ${n} is not valid JSON: ${f.message}`,{cause:f})}if(!we(i))throw new Error(`Config file must contain a JSON object: ${n}`);let{extends:a,...c}=i,l={};for(let f of Er(a,n))l=be(l,await pt(kr(f,o),[...t,n]));return be(l,c)}s(pt,"loadSource");function $r(e,t=process.cwd()){return pt({kind:"file",path:dt(t,e)},[])}s($r,"loadConfigFile");async function re(e,t){let n=typeof e[t]=="string"?e[t].trim():"";if(n.length===0)return e;let r=typeof e.cwd=="string"&&e.cwd.length>0?e.cwd:process.cwd(),o={...await $r(n,r),...e};return delete o[t],o}s(re,"applyConfigOption");import{readFile as ui,stat as fi,writeFile as di}from"node:fs/promises";import{relative as Ve,resolve as Zn}from"node:path";import{extname as ke}from"node:path";import{extname as Sr}from"node:path";var ht=[".css"];function Ar(e){let t=Sr(e).toLowerCase();return ht.includes(t)?{kind:"block",blockStart:"/*",blockLinePrefix:" * ",blockEnd:" */"}:null}s(Ar,"resolveCssCommentSyntax");var gt={id:"css",extensions:ht,enabledByDefault:!0,keepsAboveHeader:s((e,t)=>t===0&&/^@charset "[^"]*";/.test(e),"keepsAboveHeader"),resolveCommentSyntax(e){return Ar(e)}};import{extname as Nr}from"node:path";var Dr=/^(?:#|\/\/|\/\*+|<!--)[ \t]+(vi|vim(?:[<=>]?\d+)?|Vim|ex):(.*)$/,Cr=/^[a-z]+(?:[!&]|[+^-]?=(?:\\.|[^\s:\\])*)?$/,vr=new Set(["et","expandtab","ai","autoindent","si","smartindent","ro","readonly","bin","binary","noet","noexpandtab","noai","noautoindent","nosi","nosmartindent","noro","noreadonly","nobin","nobinary","nowrap","nolist","nospell","nofen","nofoldenable","noeol","nofixeol","nofixendofline"]);function oe(e){let t=e.match(Dr);if(!t)return!1;let n=t[2].trim();if(n.endsWith("-->"))n=n.slice(0,-3).trimEnd();else if(n.endsWith("*/")){let i=n.length-2;for(;i>0&&n[i-1]==="*";)i-=1;n=n.slice(0,i).trimEnd()}let r=n.match(/^se(?:t)?[ \t]((?:\\.|[^:\\])*):/);if(!r&&t[1]==="Vim")return!1;let o=r?r[1].match(/(?:\\.|[^\s\\])+/g):n.match(/(?:\\.|[^\s:\\])+/g);return o!==null&&o.every(i=>Cr.test(i))&&o.some(i=>i.includes("=")||vr.has(i))}s(oe,"isModeline");function ie(e,t){return t===0&&e.startsWith("#!")}s(ie,"isShebang");function se(e,t,n=0){let r=0,o=n;for(;r<e.length;){let i=e.indexOf(`
|
|
3
|
+
`,r),a=i===-1?e.length:i+1;if(!t(e.slice(r,a).replace(/\r?\n$/,""),o))break;r=a,o+=1}return e.slice(0,r)}s(se,"takeTopLines");var xt=[".go"];function Fr(e){let t=Nr(e).toLowerCase();return xt.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}s(Fr,"resolveGoCommentSyntax");var yt=/^\/\/(?:go:build|\s*\+build)\s/;function Lr(e,t){let n=se(t,o=>yt.test(o)||oe(o));if(!n.split(/\r?\n/).some(o=>yt.test(o)))return"";let r=t.slice(n.length);return`${n}${r.slice(0,r.length-r.replace(/^(?:[ \t]*\r?\n)*/,"").length)}`}s(Lr,"resolveGoPreservedPrefix");var wt={id:"go",extensions:xt,enabledByDefault:!0,resolvePreservedPrefix(e,t){return Lr(e,t)},resolveCommentSyntax(e){return Fr(e)}};import{extname as jr}from"node:path";var bt=[".html",".htm"];function Mr(e){let t=jr(e).toLowerCase();return bt.includes(t)?{kind:"html",blockStart:"<!--",blockLinePrefix:" ",blockEnd:"-->"}:null}s(Mr,"resolveHtmlCommentSyntax");var kt={id:"html",extensions:bt,enabledByDefault:!0,resolveCommentSyntax(e){return Mr(e)}};import{extname as Rr}from"node:path";var Et=[".jsonv",".jsonc",".json5"];function Pr(e){let t=Rr(e).toLowerCase();return Et.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}s(Pr,"resolveJsonCommentSyntax");var $t={id:"json",extensions:Et,enabledByDefault:!0,resolveCommentSyntax(e){return Pr(e)}};import{extname as Ir}from"node:path";var St=[".md",".markdown"];function Or(e){let t=Ir(e).toLowerCase();return St.includes(t)?{kind:"html",blockStart:"<!--",blockLinePrefix:" ",blockEnd:"-->"}:null}s(Or,"resolveMarkdownCommentSyntax");function Tr(e,t){let n=t.match(/^---\r?\n[\s\S]*?\r?\n---[ \t]*(?:\r?\n|$)/);return n?n[0]:""}s(Tr,"resolveMarkdownPreservedPrefix");var At={id:"markdown",extensions:St,enabledByDefault:!1,requiresForce:!0,resolvePreservedPrefix(e,t){return Tr(e,t)},resolveCommentSyntax(e){return Or(e)}};import{extname as Hr}from"node:path";var Dt=[".js",".mjs",".cjs",".ts",".tsx",".jsx"];function _r(e){let t=Hr(e).toLowerCase();return Dt.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}s(_r,"resolveNodeCommentSyntax");var Ct={id:"node",extensions:Dt,enabledByDefault:!0,keepsAboveHeader:ie,resolveCommentSyntax(e){return _r(e)}};import{extname as Ur}from"node:path";var Nt=[".php"];function Br(e){let t=Ur(e).toLowerCase();return Nt.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}s(Br,"resolvePhpCommentSyntax");var vt=/^<\?php(?:\s|$)/i,Ft={id:"php",extensions:Nt,enabledByDefault:!0,keepsAboveHeader:s((e,t)=>t===0&&vt.test(e),"keepsAboveHeader"),resolveContentSkipReason(e){return vt.test(e.replace(/^\uFEFF/,""))?null:"the file does not start with <?php, so a comment at the top would be output as text"},resolveCommentSyntax(e){return Br(e)}};import{extname as zr}from"node:path";var Lt=[".py"],Wr=/^#.*?(?<![A-Za-z])coding[:=]\s*[-\w.]+/;function Gr(e,t){return ie(e,t)||t<=1&&Wr.test(e)}s(Gr,"keepsAboveHeader");var jt={id:"python",extensions:Lt,enabledByDefault:!0,keepsAboveHeader:Gr,resolveCommentSyntax(e){let t=zr(e).toLowerCase();return Lt.includes(t)?{kind:"line",linePrefix:"#"}:null}};import{extname as Yr}from"node:path";var Mt=[".rs"];function Vr(e){let t=Yr(e).toLowerCase();return Mt.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}s(Vr,"resolveRustCommentSyntax");var Rt={id:"rust",extensions:Mt,enabledByDefault:!0,keepsAboveHeader:s((e,t)=>t===0&&e.startsWith("#!")&&!/^#!\s*\[/.test(e),"keepsAboveHeader"),resolveCommentSyntax(e){return Vr(e)}};import{extname as Jr}from"node:path";var Pt=[".yaml",".yml"];function Kr(e){let t=Jr(e).toLowerCase();return Pt.includes(t)?{kind:"line",linePrefix:"#"}:null}s(Kr,"resolveYamlCommentSyntax");var It={id:"yaml",extensions:Pt,enabledByDefault:!0,keepsAboveHeader:s((e,t)=>t===0&&/^#cloud-config\s*$/.test(e),"keepsAboveHeader"),resolveCommentSyntax(e){return Kr(e)}};var ae=[gt,wt,kt,$t,At,Ct,Ft,jt,Rt,It],qr=new Map(ae.map(e=>[e.id,e]));function Zr(e,t){return!t||typeof t!="object"?e:e.kind==="line"?{...e,linePrefix:typeof t.linePrefix=="string"&&t.linePrefix.length>0?t.linePrefix:e.linePrefix,lineSeparator:typeof t.lineSeparator=="string"?t.lineSeparator:e.lineSeparator}:{...e,blockStart:typeof t.blockStart=="string"&&t.blockStart.length>0?t.blockStart:e.blockStart,blockLinePrefix:typeof t.blockLinePrefix=="string"&&t.blockLinePrefix.length>0?t.blockLinePrefix:e.blockLinePrefix,blockEnd:typeof t.blockEnd=="string"&&t.blockEnd.length>0?t.blockEnd:e.blockEnd}}s(Zr,"applySyntaxOverride");function Ot(e){if(e==null)return[];if(!Array.isArray(e)||e.some(n=>typeof n!="string"))throw new Error(`forcedDetectors must be an array of detector ids, got ${JSON.stringify(e)}`);let t=ae.filter(n=>n.requiresForce===!0).map(n=>n.id);for(let n of e){if(!qr.has(n))throw new Error(`forcedDetectors: unknown detector "${n}" (force-only detectors: ${t.join(", ")})`);if(!t.includes(n))throw new Error(`forcedDetectors: "${n}" does not need forcing (force-only detectors: ${t.join(", ")})`)}return Array.from(new Set(e))}s(Ot,"resolveForcedDetectors");function O(e={}){let t=new Set(Array.isArray(e.enabledDetectors)?e.enabledDetectors:[]),n=new Set(Array.isArray(e.disabledDetectors)?e.disabledDetectors:[]),r=new Set(Array.isArray(e.forcedDetectors)?e.forcedDetectors:[]);return ae.filter(o=>o.requiresForce===!0?r.has(o.id)&&!n.has(o.id):t.size>0?t.has(o.id):n.has(o.id)?!1:o.enabledByDefault)}s(O,"getEnabledDetectors");function Tt(e={}){if(Array.isArray(e.includeExtensions)&&e.includeExtensions.length>0)return new Set(e.includeExtensions.map(n=>n.toLowerCase()));let t=O(e);return new Set(t.flatMap(n=>n.extensions))}s(Tt,"getAllowedExtensions");function Ht(e,t={}){let n=ke(e).toLowerCase();if(O(t).some(a=>a.extensions.includes(n)&&a.resolveCommentSyntax(e)!==null))return null;if(n.length===0)return"the file has no extension, so its comment syntax is unknown";let o=new Set(Array.isArray(t.forcedDetectors)?t.forcedDetectors:[]),i=ae.find(a=>a.requiresForce===!0&&a.extensions.includes(n)&&!o.has(a.id));return i?`${n} files get a header only when forced (--force-detector ${i.id} / forcedDetectors: ["${i.id}"])`:`no enabled detector handles ${n} files`}s(Ht,"getHeaderSkipReason");function _t(e,t={}){let n=ke(e).toLowerCase(),r=Array.isArray(t.detectors)?t.detectors:O(t);for(let o of r){if(!o.extensions.includes(n))continue;let i=o.resolveCommentSyntax(e);if(i){let a=t.detectorSyntaxOverrides&&typeof t.detectorSyntaxOverrides=="object"?t.detectorSyntaxOverrides:{};return Zr(i,a[o.id])}}return{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}}s(_t,"getCommentSyntaxForFile");function Ut(e,t){let n=ke(e).toLowerCase();return O(t).find(r=>r.extensions.includes(n))}s(Ut,"detectorForFile");function ce(e,t,n={}){let r=Ut(e,n);if(!r)return"";let o=typeof r.resolvePreservedPrefix=="function"?r.resolvePreservedPrefix(e,t):"",i=r.keepsAboveHeader,a=se(t.slice(o.length),(c,l)=>oe(c)||typeof i=="function"&&i(c,l),o.split(`
|
|
4
|
+
`).length-1);return`${o}${a}`}s(ce,"getPreservedPrefixForFile");function Bt(e,t,n={}){let r=Ut(e,n);return r&&typeof r.resolveContentSkipReason=="function"?r.resolveContentSkipReason(t):null}s(Bt,"getContentSkipReason");var zt=200,Z=1,le=2;function T(e,t,n){if(e==null)return n;if(typeof e!="number"||!Number.isInteger(e)||e<0)throw new Error(`${t} must be a whole number of 0 or more, got ${JSON.stringify(e)}`);return e}s(T,"resolveLayoutCount");import{existsSync as lo}from"node:fs";import{join as Ne,relative as nn,resolve as Fe,sep as Ce}from"node:path";import{realpath as uo,stat as fo}from"node:fs/promises";import{access as Xr,readdir as Qr,readFile as Hs,stat as eo}from"node:fs/promises";import{constants as to}from"node:fs";import{dirname as Bs,join as no,resolve as zs}from"node:path";async function Ee(e){try{return await Xr(e,to.F_OK),!0}catch{return!1}}s(Ee,"pathExists");async function $e(e,t){let n=[],r=await Qr(e,{withFileTypes:!0});for(let o of r){let i=no(e,o.name);if(o.isDirectory()&&t.recursive===!1||o.isDirectory()&&t.ignoreFolders.has(o.name)||o.isDirectory()&&await t.shouldSkipDirectory?.(i,o.name)===!0)continue;if(o.isDirectory()){let l=await $e(i,t);n.push(...l);continue}if(!o.isFile())continue;let a=o.name.lastIndexOf(".");if(a===-1)continue;let c=o.name.slice(a).toLowerCase();t.allowedExtensions.has(c)&&n.push(i)}return n}s($e,"walkFiles");async function Wt(e){let t=await eo(e);return{createdAt:t.birthtimeMs>0&&t.birthtime<t.mtime?t.birthtime:t.mtime,updatedAt:t.mtime}}s(Wt,"readFileDates");function Gt(e){let t=e.indexOf("<");for(;t!==-1;){let n=e.indexOf(">",t+1);if(n===-1)return!1;if(n>t+1)return!0;t=e.indexOf("<",n+1)}return!1}s(Gt,"hasAngleTag");function Yt(e){let t=e.length;for(;t>0&&e[t-1]==="/";)t-=1;return e.slice(0,t)}s(Yt,"trimTrailingSlashes");import{execFile as ro}from"node:child_process";import{lstat as oo,readFile as io}from"node:fs/promises";import{dirname as Vt,isAbsolute as so,join as qt,relative as Zt,resolve as Se,sep as Xt}from"node:path";import ao from"ignore";function Jt(e,t){return new Promise(n=>{ro("git",t,{cwd:e,encoding:"utf8",maxBuffer:Number.POSITIVE_INFINITY},(r,o)=>{if(!r){n({code:0,stdout:o});return}n({code:typeof r.code=="number"?r.code:-1,stdout:""})})})}s(Jt,"runGitCommand");function De(e,t){return Zt(e,t).split(Xt).join("/")}s(De,"toPosixRelative");async function Qt(e){try{return ao().add(await io(e,"utf8"))}catch{return null}}s(Qt,"readIgnoreFile");async function co(e){return oo(qt(e,".git")).then(()=>!0,()=>!1)}s(co,"hasGitEntry");function Kt(e,t,n){for(let r=e.length-1;r>=0;r--){let{base:o,rules:i}=e[r],a=i.test(`${De(o,t)}${n?"/":""}`);if(a.ignored||a.unignored)return a.ignored}return!1}s(Kt,"matchesRules");async function en(e,t){let n=await Qt(qt(e,".gitignore"));return{kind:"rules",nested:!0,excluded:!1,matchers:n?[...t,{base:e,rules:n}]:t}}s(en,"buildRulesContext");async function Ae(e){let[t,n]=await Promise.all([Jt(e,["check-ignore","-q","."]),Jt(e,["ls-files","--cached","--others","--exclude-standard","-z"])]);if(t.code!==1||n.code!==0)return en(e,[]);let r=new Set,o=new Set;for(let i of n.stdout.split("\0")){let a=i.endsWith("/")?i.slice(0,-1):i;if(a.length!==0){r.add(a);for(let c=a.indexOf("/");c!==-1;c=a.indexOf("/",c+1))o.add(a.slice(0,c))}}return{kind:"git",root:e,entries:r,dirs:o}}s(Ae,"resolveScopeContext");function tn(e){let t=Se(e.root),n=e.gitignore;if(n===!1)return{isIgnored:s(async()=>!1,"isIgnored")};let r=new Map,o=s(async()=>{if(typeof n!="string"&&!Array.isArray(n))return Ae(t);let c=typeof n=="string"?[n]:n.filter(f=>typeof f=="string"),l=[];for(let f of c){let u=await Qt(Se(t,f));u&&l.push({base:t,rules:u})}return{kind:"rules",nested:!1,excluded:!1,matchers:l}},"buildRootContext"),i=s(c=>{let l=r.get(c);return l||(l=c===t?o():a(c),r.set(c,l)),l},"contextFor"),a=s(async c=>{let l=await i(Vt(c));return l.kind==="git"?l.entries.has(De(l.root,c))?Ae(c):l:!l.nested||l.excluded?l:Kt(l.matchers,c,!0)?{...l,excluded:!0}:await co(c)?Ae(c):en(c,l.matchers)},"deriveContext");return{async isIgnored(c,l){let f=Se(c),u=Zt(t,f);if(u.length===0||u===".."||u.startsWith(`..${Xt}`)||so(u))return!1;let m=await i(Vt(f));if(m.kind==="git"){let h=De(m.root,f);return!(m.entries.has(h)||l&&m.dirs.has(h))}return m.excluded||Kt(m.matchers,f,l)}}}s(tn,"createIgnoreFilter");function mo(e){return Tt(e)}s(mo,"resolveExtensions");var po=Object.freeze(["node_modules","bower_components","jspm_packages",".pnpm-store",".yarn"]),sn=new Set([".git",...po]),ho=Object.freeze(["autoload.php","modules.txt"]);function rn(e,t){return sn.has(t)?!0:t==="vendor"&&ho.some(n=>lo(Ne(e,n)))}s(rn,"isNeverWalked");function ve(e){return Yt(e.replace(/\\/g,"/").replace(/^\.\//,"").replace(/^\/+/,""))}s(ve,"normalizeFolderPath");function go(e){return Array.isArray(e)?e.map(t=>{if(typeof t=="string")return{path:t,recursive:!0};if(t&&typeof t=="object"&&typeof t.path=="string")return{path:t.path,recursive:t.recursive!==!1};throw new TypeError(`Invalid includeFolders entry: ${JSON.stringify(t)} (expected a path string or { path, recursive? })`)}):[]}s(go,"resolveIncludeFolders");function on(e,t){let n=t instanceof Error?t.message:String(t);console.warn(`fix-headers: skipped include folder "${e}" (${n})`)}s(on,"reportSkippedIncludeFolder");function yo(e,t){if(!Array.isArray(t)||t.length===0)return()=>!1;let n=Fe(e),r=[],o=new Set;for(let i of t){if(typeof i!="string")continue;let a=ve(i);if(a.length!==0){if(a.includes("/")){r.push(Fe(n,a));continue}o.add(a)}}return(i,a)=>{if(o.has(a))return!0;for(let l of r)if(i===l||i.startsWith(`${l}/`))return!0;let c=ve(nn(n,i));return r.some(l=>{let f=ve(nn(n,l));return c===f||c.startsWith(`${f}/`)})}}s(yo,"buildExclusionMatcher");async function Le(e){let t=mo(e),n=go(e.includeFolders),r=Array.isArray(e.excludeFolders)?e.excludeFolders:[],o=yo(e.projectRoot,r),i=tn({root:e.projectRoot,gitignore:e.gitignore}),a=s(async(d,p)=>rn(d,p)||o(d,p)||await i.isIgnored(d,!0),"shouldSkipDirectory"),c=n.length>0?n.map(d=>({includeFolder:d.path,rootPath:Ne(e.projectRoot,d.path),recursive:d.recursive})):[{includeFolder:".",rootPath:e.projectRoot,recursive:!0}],l=[];for(let d of c){let p=await fo(d.rootPath).catch(b=>b);if(p instanceof Error){if(p.code==="ENOENT"){on(d.includeFolder,p);continue}throw p}if(!p.isDirectory()){on(d.includeFolder,`path is not a directory: ${d.rootPath}`);continue}let w=await uo(d.rootPath).catch(()=>Fe(d.rootPath));l.push({...d,realRoot:w})}let f=s((d,p)=>{if(d.realRoot===p.realRoot)return d.recursive||!p.recursive;let w=d.realRoot.endsWith(Ce)?d.realRoot:`${d.realRoot}${Ce}`;if(!d.recursive||!p.realRoot.startsWith(w))return!1;let b=d.rootPath;for(let $ of p.realRoot.slice(w.length).split(Ce))if(b=Ne(b,$),rn(b,$)||o(b,$))return!1;return!0},"covers"),u=[...l].sort((d,p)=>d.realRoot.length-p.realRoot.length||Number(p.recursive)-Number(d.recursive)),m=[];for(let d of u)m.some(p=>f(p,d))||m.push(d);let h=[];for(let d of l){if(!m.includes(d))continue;let p=await $e(d.rootPath,{allowedExtensions:t,ignoreFolders:sn,shouldSkipDirectory:a,recursive:d.recursive});h.push(...p)}let y=[];for(let d of new Set(h))!o(d,d.split("/").at(-1)||"")&&!await i.isIgnored(d,!1)&&y.push(d);return y}s(Le,"discoverFiles");import{basename as zo,dirname as Wo,extname as Go,resolve as Oe}from"node:path";import{dirname as xn,isAbsolute as vo,join as wn,relative as No,resolve as bn,sep as Fo}from"node:path";import{readFile as xo}from"node:fs/promises";import{join as wo}from"node:path";async function bo(e){try{return await xo(e,"utf8")}catch{return null}}s(bo,"readManifest");async function j(e,t){let n=[];for(let r of t){let o=await bo(wo(e,r));o!==null&&n.push({file:r,content:o})}return n.length>0?{dir:e,manifest:n[0].file,files:n}:null}s(j,"detectManifests");function H(e,t){return e.files.find(n=>n.file===t)?.content??null}s(H,"manifestContent");function D(e){return typeof e=="string"&&e.trim().length>0?e.trim():void 0}s(D,"cleanName");function je(e){if(typeof e!="string")return;let t=e.search(/[<(]/);return D(t===-1?e:e.slice(0,t))}s(je,"personName");function ue(e){try{return JSON.parse(e)}catch{return}}s(ue,"parseJsonManifest");function*Me(e,t){let n="";for(let r of e.split(/\r?\n/)){let o=r.trim();if(o.startsWith("[")){let i=o.match(/^\[([^[\]]+)\]/);n=i?i[1].split(".").map(a=>a.trim()).join("."):"";continue}n===t&&(yield o)}}s(Me,"sectionLines");function X(e,t,n){let r=new RegExp(`^${n}\\s*=\\s*(?:"([^"\\\\]*)"|'([^']*)')`);for(let o of Me(e,t)){let i=o.match(r);if(i)return D(i[1]??i[2])}}s(X,"readTomlString");function Re(e,t,n){let r=new RegExp(`^${n}\\s*[=:](.*)$`);for(let o of Me(e,t)){let i=o.match(r);if(i)return D(i[1])}}s(Re,"readIniValue");function ko(e,t,n){let r=new RegExp(`^${n}\\s*=\\s*\\[`),o=null;for(let i of Me(e,t)){if(o!==null){o.push(i);continue}let a=i.match(r);a&&(o=[i.slice(a[0].length)])}return o===null?null:o.join(`
|
|
5
|
+
`)}s(ko,"tomlArrayText");function Eo(e,t){let n=t;for(;n<e.length;)if(e[n]==="#"){let r=e.indexOf(`
|
|
6
|
+
`,n);n=r===-1?e.length:r+1}else if(/\s/.test(e[n]))n+=1;else break;return n}s(Eo,"skipTomlSpace");function Q(e,t){let n=ko(e,t,"authors");if(n===null)return;let r=n.slice(Eo(n,0)),o=r.match(/^(?:"([^"\\\n]*)"|'([^'\n]*)')/);if(o)return je(o[1]??o[2]);let a=r.match(/^\{([^}\n]*)\}/)?.[1].match(/(?:^|,)\s*name\s*=\s*(?:"([^"\\\n]*)"|'([^'\n]*)')/);return a?D(a[1]??a[2]):void 0}s(Q,"readTomlAuthor");var an=["go.mod"];function $o(e){let t=e.match(/^\s*module\s+(.+)$/m);if(t)return D(t[1].replace(/\/\/.*$/,"").trim().replace(/^["`](.*)["`]$/,"$1"))}s($o,"readModulePath");var cn={id:"go",languages:["go"],manifests:an,detect(e){return j(e,an)},read(e){return{name:$o(e.files[0].content)}}};var ln=["package.json"];function So(e){let t=D(e?.name),n=D(e?.publisher),r=typeof e?.engines?.vscode=="string";return t&&n&&r?`${n}.${t}`:t}s(So,"readPublishedName");function Ao(e){if(e!==null&&typeof e=="object"){let t=e;return D(t.company)??D(t.name)}return je(e)}s(Ao,"readAuthorCompany");var un={id:"node",languages:["node"],manifests:ln,detect(e){return j(e,ln)},read(e){let t=ue(e.files[0].content);return{name:So(t),company:Ao(t?.author)}}};var fn=["composer.json"],dn={id:"php",languages:["php"],manifests:fn,detect(e){return j(e,fn)},read(e){let t=ue(e.files[0].content),n=t?.authors;return{name:D(t?.name),company:Array.isArray(n)?D(n[0]?.name):void 0}}};var mn=["pyproject.toml","setup.cfg","setup.py"];function pn(e,t){let n=e.indexOf("setup(");if(n===-1)return;let r=e.slice(n).match(new RegExp(`\\b${t}\\s*=\\s*(["'])([^"'\\n]+)\\1`));return r&&r[2].trim()||void 0}s(pn,"readSetupPyArgument");function Do(e){let t=H(e,"pyproject.toml"),n=H(e,"setup.cfg"),r=H(e,"setup.py");return(t===null?void 0:X(t,"project","name")??X(t,"tool.poetry","name"))??(n===null?void 0:Re(n,"metadata","name"))??(r===null?void 0:pn(r,"name"))}s(Do,"readPythonName");function Co(e){let t=H(e,"pyproject.toml"),n=H(e,"setup.cfg"),r=H(e,"setup.py");return(t===null?void 0:Q(t,"project")??Q(t,"tool.poetry"))??(n===null?void 0:Re(n,"metadata","author"))??(r===null?void 0:pn(r,"author"))}s(Co,"readPythonCompany");var hn={id:"python",languages:["python"],manifests:mn,detect(e){return j(e,mn)},read(e){return{name:Do(e),company:Co(e)}}};var gn=["Cargo.toml"],yn={id:"rust",languages:["rust"],manifests:gn,detect(e){return j(e,gn)},read(e){let t=e.files[0].content;return{name:X(t,"package","name"),company:Q(t,"package")}}};var Lo=[un,hn,dn,yn,cn],kn=["name","company"];async function Pe(e,t,n){let o=(await Promise.all(t.map(async a=>({driver:a,detection:await a.detect(e)})))).filter(a=>a.detection!==null),i=o.filter(a=>typeof n=="string"&&a.driver.languages.includes(n));return[...i,...o.filter(a=>!i.includes(a))]}s(Pe,"claimFolder");function jo(e,t){let n=No(t,e);return n!==""&&n!==".."&&!n.startsWith(`..${Fo}`)&&!vo(n)}s(jo,"isStrictlyInside");async function En(e,t={}){let n=Array.isArray(t.drivers)?t.drivers:Lo,r=typeof t.scanRoot=="string"?bn(t.scanRoot):null,o=bn(e),i=await Pe(o,n,t.language);for(;i.length===0;){if(await Ee(wn(o,".git")))return{root:o,marker:".git",drivers:[],fields:{},sources:{}};let u=xn(o);if(u===o)return null;o=u,i=await Pe(o,n,t.language)}let a={},c={},l=o,f=i;for(;;){for(let{driver:m,detection:h}of f){let y=m.read(h);for(let d of kn)a[d]===void 0&&y[d]!==void 0&&(a[d]=y[d],c[d]={driver:m.id,manifest:h.manifest,dir:l})}if(kn.every(m=>a[m]!==void 0)||r===null||!jo(l,r)||await Ee(wn(l,".git")))break;l=xn(l),f=await Pe(l,n,t.language)}return{root:o,marker:i[0].detection.manifest,drivers:i.map(u=>u.driver.id),fields:a,sources:c}}s(En,"resolveManifestProject");import{execFile as Mo}from"node:child_process";import{basename as Ro,dirname as Po}from"node:path";import{promisify as Io}from"node:util";var Ie=Io(Mo);async function F(e,t){try{let{stdout:n}=await Ie("git",t,{cwd:e}),r=n.trim();return r.length>0?r:null}catch{return null}}s(F,"runGit");function $n(e,t){let n=0;for(let r=t-1;r>=0&&e[r]==="\\";r--)n++;return n%2===1}s($n,"isEscaped");function Oo(e){let t=e.trim();if(!t.endsWith(")")||$n(t,t.length-1))return t;let n=0;for(let r=t.length-1;r>=0;r--){let o=t[r];if(!(o!=="("&&o!==")"||$n(t,r))&&(n+=o===")"?1:-1,n===0))return t.slice(0,r).trim()}return t}s(Oo,"stripUidComment");function To(e){let t=e.trim();if(t.length===0)return{authorName:null,authorEmail:null};let n=t.match(/<([^>\n]+)>\s*$/),r=n?.[1]?.trim()||null,o=(n?t.slice(0,n.index):t).trim();return{authorName:Oo(o)||o||null,authorEmail:r}}s(To,"parseSignerUid");async function Ho(e,t){try{let{stdout:n}=await Ie(e,t),r=n.trim();return r.length>0?r:null}catch{return null}}s(Ho,"runProgram");function _o(e){return e.replace(/\\x([0-9a-fA-F]{2})/g,(t,n)=>String.fromCharCode(Number.parseInt(n,16)))}s(_o,"decodeColonField");async function Uo(e){let t=await F(e,["config","--get","gpg.format"]);if(t!==null&&t!=="openpgp")return null;let n=await F(e,["config","--get","user.signingkey"]);if(!n)return null;let r=await F(e,["config","--get","gpg.openpgp.program"])||await F(e,["config","--get","gpg.program"])||"gpg",o=await Ho(r,["--batch","--with-colons","--list-keys",n]);if(!o)return null;for(let i of o.split(`
|
|
7
|
+
`)){let a=i.split(":");if(a[0]==="uid"&&a[1]!=="r"&&a[1]!=="e"&&a[9])return _o(a[9])}return null}s(Uo,"readSigningKeyUid");async function Sn(e,t={}){let n=await F(e,["config","--get","user.name"]),r=await F(e,["config","--get","user.email"]);if(t.useGpgSignerAuthor===!0){let o=await Uo(e)||await F(e,["log","-1","--format=%GS"]),i=To(o||"");n=i.authorName||n,r=r||i.authorEmail}if(!n||!r){let o=await F(e,["log","-1","--format=%an|%ae"]);if(o){let[i,a]=o.split("|");n=n||i||null,r=r||a||null}}return{authorName:n,authorEmail:r}}s(Sn,"detectGitAuthor");function An(e){return e.replace(/z$/i,"+00:00")}s(An,"canonicalGitDate");async function Dn(e,t){let n=await F(e,["log","--follow","--format=%aI|%at","--reverse","--",t]);if(!n)return null;let r=n.split(`
|
|
8
|
+
`)[0],[o,i]=r.split("|");if(!o||!i)return null;let a=Number.parseInt(i,10);return Number.isNaN(a)?null:{date:An(o),timestamp:a}}s(Dn,"getGitCreationDate");async function Cn(e,t){let n=await F(e,["log","-1","--format=%aI|%at","--",t]);if(!n)return null;let[r,o]=n.split("|");if(!r||!o)return null;let i=Number.parseInt(o,10);return Number.isNaN(i)?null:{date:An(r),timestamp:i}}s(Cn,"getGitLastModifiedDate");var Bo=256*1024*1024;async function vn(e){let t=Po(e);if(await F(t,["rev-parse","--is-inside-work-tree"])!=="true")return{state:"no-git",content:null};try{let{stdout:n}=await Ie("git",["show",`HEAD:./${Ro(e)}`],{cwd:t,encoding:"utf8",maxBuffer:Bo});return{state:"tracked",content:n}}catch{return{state:"untracked",content:null}}}s(vn,"readGitHeadFile");function Yo(e){return zo(e)||"project"}s(Yo,"folderName");function Vo(e,t){if(typeof t!="string")return e;let n=t.trim();return n.length===0||Gt(e)?e:`${e} <${n}>`}s(Vo,"formatAuthorNameWithCompany");async function Jo(e,t={}){let n=Array.isArray(t.detectors)?t.detectors:O(t),r=typeof t.preferredExtension=="string"?t.preferredExtension.trim().toLowerCase():"",o=r.length>0?n.find(f=>f.extensions.includes(r)):void 0,i=await En(e,{drivers:t.drivers,language:o?.id,scanRoot:t.scanRoot}),a=i?i.root:Oe(e),c=i?.sources.name,l=i?.sources.company;return{language:o?.id??i?.drivers[0]??"unknown",rootDir:a,marker:i?i.marker:null,projectName:i?.fields.name??Yo(a),projectNameSource:c?{from:"manifest",...c}:{from:"folder",dir:a},companyName:i?.fields.company??null,companyNameSource:l?{from:"manifest",...l}:{from:"none"},drivers:i?i.drivers:[]}}s(Jo,"detectProjectFromMarkers");async function Te(e={}){let t=e.targetFilePath||e.cwd||process.cwd(),n=Oe(t),r=O(e),o=e.targetFilePath?Wo(n):n,i=e.targetFilePath?Go(n).toLowerCase():"",a=Oe(e.projectRoot||e.cwd||process.cwd()),c=await Jo(o,{detectors:r,preferredExtension:i,scanRoot:a}),l=await Sn(c.rootDir,{useGpgSignerAuthor:e.useGpgSignerAuthor===!0}),f=e.authorName||l.authorName||"Unknown Author",u=typeof e.companyName=="string"?e.companyName.trim():"";return{projectName:e.projectName||c.projectName,projectNameSource:e.projectName?{from:"option"}:c.projectNameSource,language:e.language||c.language,projectRoot:e.projectRoot||c.rootDir,marker:e.marker===void 0?c.marker:e.marker,authorName:Vo(f,e.company),authorEmail:e.authorEmail||l.authorEmail||"unknown@example.com",companyName:u||c.companyName,companyNameSource:u?{from:"option"}:c.companyNameSource,copyrightStartYear:Number.isInteger(e.copyrightStartYear)?Number(e.copyrightStartYear):null}}s(Te,"resolveProjectMetadata");function Ko(e){return He({year:e.getFullYear(),month:e.getMonth()+1,day:e.getDate(),hour:e.getHours(),minute:e.getMinutes(),second:e.getSeconds(),offsetMinutes:-e.getTimezoneOffset()})}s(Ko,"formatDateWithTimezone");function He(e){return`${jn(e," ")} ${Mn(e.offsetMinutes)}`}s(He,"formatSpaceDate");function Fn(e){if(typeof e!="string")throw new Error(`timezone must be an IANA time zone name string, such as "America/Los_Angeles" or "UTC" (got ${typeof e})`);try{Ln(e)}catch(t){throw new Error(`Unknown time zone "${e}": expected an IANA time zone name, such as "America/Los_Angeles" or "UTC"`,{cause:t})}return e}s(Fn,"assertTimeZone");var Nn=new Map;function Ln(e){let t=Nn.get(e);return t||(t=new Intl.DateTimeFormat("en-US",{timeZone:e,hourCycle:"h23",year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"}),Nn.set(e,t)),t}s(Ln,"getZoneFormatter");function _e(e,t){let n={};for(let o of Ln(t).formatToParts(new Date(e*1e3)))n[o.type]=Number(o.value);let r=Date.UTC(n.year,n.month-1,n.day,n.hour,n.minute,n.second)/1e3;return{year:n.year,month:n.month,day:n.day,hour:n.hour,minute:n.minute,second:n.second,offsetMinutes:(r-e)/60}}s(_e,"toZonedDateParts");function jn(e,t){let n=s(r=>String(r).padStart(2,"0"),"pad");return`${String(e.year).padStart(4,"0")}-${n(e.month)}-${n(e.day)}${t}${n(e.hour)}:${n(e.minute)}:${n(e.second)}`}s(jn,"formatWallClock");function Mn(e){let t=s(r=>String(r).padStart(2,"0"),"pad"),n=Math.abs(e);return`${e>=0?"+":"-"}${t(Math.floor(n/60))}:${t(n%60)}`}s(Mn,"formatOffset");function fe(e=new Date){return{date:Ko(e),timestamp:Math.floor(e.getTime()/1e3)}}s(fe,"toDatePayload");var qo=/^(\d{4})-(\d{2})-(\d{2})(?:T|\s+)(\d{2}):(\d{2}):(\d{2})(?:\.\d+)?\s*(?:(Z)|([+-])(\d{2}):?(\d{2}))$/i;function _(e){let t=qo.exec(e.trim());if(!t)return null;let[n,r,o,i,a,c]=t.slice(1,7).map(Number),l=t[7]?0:Number(t[9])*60+Number(t[10]),f=t[8]==="-"?-l:l,u=new Date(Date.UTC(n,r-1,o,i,a,c));return!(u.getUTCFullYear()===n&&u.getUTCMonth()===r-1&&u.getUTCDate()===o&&u.getUTCHours()===i&&u.getUTCMinutes()===a&&u.getUTCSeconds()===c)||Number(t[10]??0)>59?null:{year:n,month:r,day:o,hour:i,minute:a,second:c,offsetMinutes:f,timestamp:Math.floor(u.getTime()/1e3)-f*60}}s(_,"parseHeaderDate");function Ue(e){return`${jn(e,"T")}${Mn(e.offsetMinutes)}`}s(Ue,"formatIsoDate");var Zo={"git-created":"git first commit","filesystem-created":"filesystem creation time"};function Rn(e,t){let n=e.match(new RegExp(`${t}:[^\\S\\n]*(.*)$`,"m"));return n?n[1].trim():null}s(Rn,"readHeaderField");function Be(e){let t=null;for(let{source:n,payload:r}of e)r&&(!t||r.timestamp<t.payload.timestamp)&&(t={source:n,payload:r});return t}s(Be,"pickOldestDate");function In({existing:e,gitCreated:t,filesystemCreated:n,fixCreatedDate:r=!1}){let o=[{source:"git-created",payload:t},{source:"filesystem-created",payload:n}];if(!e)return Be(o);if(!r)return{source:"existing-header",payload:e};let i=_(e.date)?e:null;return Be([{source:"existing-header",payload:i},...o])}s(In,"resolveCreatedDate");function On(e,t=null){if(t)return _e(e.timestamp,t).year;let n=_(e.date);return n?n.year:new Date(e.timestamp*1e3).getFullYear()}s(On,"dateYear");function Pn(e,t,n,r){let o=e.match(/^(.+?)\s*\((\d+)\)$/),i=o?_(o[1]):null;if(!o||!i)return r.push({check:`${n}-format`,field:t,advisory:!1,value:e,message:`${t} value "${e}" is not a "<datetime> (<epoch>)" pair with a recognised datetime`}),null;let a=Number.parseInt(o[2],10);return a!==i.timestamp&&r.push({check:`${n}-epoch`,field:t,advisory:!1,value:e,expected:`${o[1]} (${i.timestamp})`,message:`${t} epoch ${a} does not match ${o[1]} (expected ${i.timestamp})`}),{text:o[1],timestamp:i.timestamp}}s(Pn,"checkDateValue");function Tn(e,t={},n={}){let r=[],o=Rn(e,"@Date"),i=o===null?null:Pn(o,"@Date","created",r),a=Be([{source:"git-created",payload:t.gitCreated},{source:"filesystem-created",payload:t.filesystemCreated}]);if(i&&a&&i.timestamp>a.payload.timestamp){let u=Zo[a.source];r.push({check:"created-newer-than-source",field:"@Date",advisory:n.strictCreatedDate!==!0,value:o,expected:`${a.payload.date} (${a.payload.timestamp})`,source:a.source,message:`@Date ${i.text} is later than the ${u} ${a.payload.date} (${a.payload.timestamp})`})}let c=Rn(e,"@Last modified time"),l=c===null?null:Pn(c,"@Last modified time","modified",r),f=t.gitLastModified;return l&&f&&l.timestamp!==f.timestamp&&r.push({check:"modified-git",field:"@Last modified time",advisory:!0,value:c,expected:`${f.date} (${f.timestamp})`,message:`@Last modified time ${l.text} does not match the git last commit ${f.date} (${f.timestamp})`}),r}s(Tn,"checkHeaderDates");function ze(e){if(!e)return null;let t=_(e.date);return t&&t.timestamp!==e.timestamp?{date:e.date,timestamp:t.timestamp}:e}s(ze,"repairDateEpoch");function Hn(e){let t=_(e.date);return t?{date:Ue(t),timestamp:t.timestamp}:e}s(Hn,"normalizeDatePayload");function _n(e,t){let n=_(e.date);if(!n)return e;let r=_e(n.timestamp,t);return r.offsetMinutes===n.offsetMinutes||!Number.isInteger(r.offsetMinutes)?e:{date:/^\d{4}-\d{2}-\d{2}T/i.test(e.date.trim())?Ue(r):He(r),timestamp:n.timestamp}}s(_n,"convertDatePayload");import{relative as Qo}from"node:path";import{extname as Xo}from"node:path";function U(e,t={}){let n=Xo(e).toLowerCase(),r=T(t.spacing,"spacing",Z);return n.length===0?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */",spacing:r}:{..._t(e,t),spacing:r}}s(U,"getHeaderSyntaxForFile");function Un(e,t){let n=e.spacing??Z;if(e.kind==="line"){let c=e.linePrefix||"#",l=typeof e.lineSeparator=="string"?e.lineSeparator:" ",f=Array.from({length:n},()=>c);return[...f,...t.map(u=>`${c}${l}${u}`),...f].join(`
|
|
9
9
|
`)}let r=e.blockStart||(e.kind==="html"?"<!--":"/**"),o=e.blockLinePrefix||(e.kind==="html"?" ":" * "),i=e.blockEnd||(e.kind==="html"?"-->":" */"),a=Array.from({length:n},()=>o.trimEnd());return[r,...a,...t.map(c=>`${o}${c}`),...a,i].join(`
|
|
10
|
-
`)}s(Un,"renderHeaderLines");function Bn(e){let t=`/${
|
|
10
|
+
`)}s(Un,"renderHeaderLines");function Bn(e){let t=`/${Qo(e.projectRoot,e.absoluteFilePath).replace(/\\/g,"/")}`,n=U(e.absoluteFilePath,e.syntaxOptions||{language:e.language}),r=e.createdByName||e.authorName,o=e.createdByEmail||e.authorEmail,i=e.lastModifiedByName||e.authorName,a=e.lastModifiedByEmail||e.authorEmail,c=typeof e.companyName=="string"?e.companyName.trim():"",l=c.length>0?`${c} `:"",f=[`@Project: ${e.projectName}`,`@Filename: ${t}`,`@Date: ${e.createdAt.date} (${e.createdAt.timestamp})`,`@Author: ${r}`,`@Email: <${o}>`,"-----",`@Last modified by: ${i} (${a})`,`@Last modified time: ${e.lastModifiedAt.date} (${e.lastModifiedAt.timestamp})`,"-----",`@Copyright: Copyright (c) ${e.copyrightStartYear}-${e.currentYear} ${l}All rights reserved.`];return Un(n,f)}s(Bn,"buildHeader");var ei=Object.freeze(["projectName","filename","createdAt","authorName","authorEmail","lastModifiedByName","lastModifiedByEmail","lastModifiedAt","copyrightStartYear","copyrightEndYear","companyName"]);function I(e,t){let n=e.match(new RegExp(`@${t}:[ \\t]*(.*)$`,"m")),r=n?n[1].trim():"";return r.length>0?r:null}s(I,"readTag");function ti(e){if(e===null)return{name:null,email:null};if(!e.endsWith(")"))return{name:e,email:null};let t=e.slice(0,-1),n=t.indexOf("(",t.lastIndexOf(")")+1);return n===-1?{name:e,email:null}:{name:t.slice(0,n).trimEnd()||null,email:t.slice(n+1)||null}}s(ti,"splitLastModifiedBy");function ni(e){let t={startYear:null,endYear:null,companyName:null},n=e?.match(/^Copyright\s+\(c\)\s+(\d{4})/i);if(!n)return t;let r=e.slice(n[0].length),o=r.match(/^\s*-\s*(\d{4})/);o&&(r=r.slice(o[0].length));let i=r.toLowerCase(),a=i.endsWith("all rights reserved.")?20:i.endsWith("all rights reserved")?19:0;return a===0||!/^\s/.test(r)?t:{startYear:n[1],endYear:o?o[1]:null,companyName:r.slice(0,-a).trim()||null}}s(ni,"splitCopyright");function zn(e){let t=ti(I(e,"Last modified by")),n=ni(I(e,"Copyright")),r=I(e,"Email");return{projectName:I(e,"Project"),filename:I(e,"Filename"),createdAt:I(e,"Date"),authorName:I(e,"Author"),authorEmail:r===null?null:r.replace(/^<(.*)>$/,"$1"),lastModifiedByName:t.name,lastModifiedByEmail:t.email,lastModifiedAt:I(e,"Last modified time"),copyrightStartYear:n.startYear,copyrightEndYear:n.endYear,companyName:n.companyName}}s(zn,"parseHeaderFields");function Wn(e,t){let n=zn(e??""),r=zn(t);return ei.filter(o=>n[o]!==r[o]).map(o=>({field:o,previous:n[o],detected:r[o]}))}s(Wn,"compareHeaderFields");function ee(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}s(ee,"escapeRegex");function We(e,t,n={}){let r=t.startsWith("\uFEFF")?"\uFEFF":"",o=t.slice(r.length),i=`${r}${ce(e,o,n)}`;return{prefix:i,body:t.slice(i.length)}}s(We,"splitPreservedPrefix");function de(e){let t=e.indexOf(`
|
|
11
11
|
`);return t===-1?null:t>0&&e[t-1]==="\r"?`\r
|
|
12
12
|
`:`
|
|
13
|
-
`}s(
|
|
13
|
+
`}s(de,"lineEnding");function W(e,t){if(t.kind==="html"){let r=ee(t.blockStart||"<!--"),o=ee(t.blockEnd||"-->");return e.match(new RegExp(`^${r}[\\s\\S]*?${o}(?:\\r?\\n)*`))}if(t.kind==="line"){let r=ee(t.linePrefix||"#");return e.match(new RegExp(`^(?:${r}[^\\n]*\\n)+(?:\\r?\\n)*`))}let n=ee((t.blockEnd||" */").trim());return e.match(new RegExp(`^/\\*[\\s\\S]*?${n}(?:\\r?\\n)*`))}s(W,"matchHeaderSegment");var Vn=/^@(Project|Filename|Date|Author|Email|Last modified by|Last modified time|Copyright):/,ri="Moved out of the file header by fix-headers:";function Jn(e){return e.some(t=>/^@(?:Project|Filename):/.test(t.text))}s(Jn,"isFileHeader");function Ge(e,t){let n=e.replace(/(?:\r?\n)+$/,"");if(t.kind==="line"){let u=new RegExp(`^${ee(t.linePrefix||"#")}[ \\t]*`);return n.split(`
|
|
14
14
|
`).map(m=>{let h=m.replace(/\r$/,"");return{raw:h,text:h.replace(u,"").trim()}})}let r=t.kind==="html",o=r?n.replace(/^<!--/,"").replace(/--!?>\s*$/,""):n.replace(/^\/\*+/,"").replace(/\*+\/\s*$/,""),i=t.blockLinePrefix||(r?" ":" * "),a=r?/^\s*/:/^\s*\*?[ \t]*/,c=o.split(`
|
|
15
|
-
`).map((u,m)=>({raw:m===0&&u.trim()!==""?`${i}${u.trim()}`:u.trimEnd(),text:(m===0?u:u.replace(a,"")).trim()})),l=c[0].raw===""?1:0,
|
|
15
|
+
`).map((u,m)=>({raw:m===0&&u.trim()!==""?`${i}${u.trim()}`:u.trimEnd(),text:(m===0?u:u.replace(a,"")).trim()})),l=c[0].raw===""?1:0,f=c.length>l&&c[c.length-1].raw.trim()===""?c.length-1:c.length;return c.slice(l,f)}s(Ge,"segmentLines");function oi(e,t){let n=e.map(o=>{let i=o.text.match(Vn);return o.text===""?"blank":i&&i[1]==="Copyright"?t.copyright?"copyright":(t.copyright=!0,"field"):i?"field":/^-{3,}$/.test(o.text)?"dash":"text"}),r=s((o,i)=>{for(let a=o+i;a>=0&&a<n.length;a+=i)if(n[a]!=="blank"&&n[a]!=="dash")return n[a]==="copyright"?"field":n[a]},"neighbour");return n.map((o,i)=>o==="dash"?r(i,-1)==="field"||r(i,1)==="field"?"separator":"text":o)}s(oi,"classifyLines");function ii(e,t="",n={}){let r=U(t,n),o=[],i=[],a={copyright:!1},c=e,l=W(c,r),f=!0;for(;l&&l[0].length>0;){let p=Ge(l[0],r),w=oi(p,a),b=p.findIndex($=>$.text!=="");!f&&b!==-1&&p[b].text===ri&&(w[b]="separator"),p.forEach(($,C)=>{w[C]==="copyright"&&i.push($.text.replace(Vn,"").trim()),o.push({raw:$.raw,kind:w[C]})}),c=c.slice(l[0].length),l=W(c,r),f=!1}let u=o.findIndex(p=>p.kind==="text");if(u===-1)return{foreign:[],copyrights:i};let m=o.map(p=>p.kind).lastIndexOf("text"),h=[],y=[],d=!1;for(let p of o.slice(u,m+1))p.kind==="text"?(h.push(...d?[]:y,p.raw),y=[],d=!1):p.kind==="blank"?y.push(p.raw):d=!0;return{foreign:h,copyrights:i}}s(ii,"splitHeaderText");function si(e,t,n){let r=t.kind==="html";return t.kind==="line"?e.join(n):[t.blockStart||(r?"<!--":"/**"),...e,t.blockEnd||(r?"-->":" */")].join(n)}s(si,"renderForeignBlock");function ai(e,t,n){let r=e.split(`
|
|
16
16
|
`),o=n.kind==="html",i=n.kind==="line"?n.linePrefix||"#":(n.blockLinePrefix||(o?" ":" * ")).trimEnd(),a=Math.min(r.length-1,(n.spacing??1)+(n.kind==="line"?0:1)),c=r.length-a;return[...r.slice(0,c),i,...t,...r.slice(c)].join(`
|
|
17
|
-
`)}s(
|
|
18
|
-
`.includes(t[a-1]);)a-=1;return t.slice(0,a).split(/\s+/).filter(Boolean).join(" ").toLowerCase()}s(Gn,"copyrightHolder");function
|
|
17
|
+
`)}s(ai,"appendToHeader");function Gn(e){let t=e.trim(),n=t.match(/^copyright\b/i);t=n?t.slice(n[0].length).trimStart():t;for(let c=t.match(/^(?:\(c\)|©)/i);c;c=t.match(/^(?:\(c\)|©)/i))t=t.slice(c[0].length).trimStart();let r=t.match(/^\d{4}(?:\s*[-–,]\s*\d{4})*/);t=r?t.slice(r[0].length):t,t=t.trimEnd();let o=t.toLowerCase(),i=o.endsWith("all rights reserved.")?20:o.endsWith("all rights reserved")?19:0;t=t.slice(0,t.length-i);let a=t.length;for(;a>0&&`.,; \r
|
|
18
|
+
`.includes(t[a-1]);)a-=1;return t.slice(0,a).split(/\s+/).filter(Boolean).join(" ").toLowerCase()}s(Gn,"copyrightHolder");function ci(e,t){let n=e.split(`
|
|
19
19
|
`),r=n.findIndex(c=>c.includes("@Copyright:")),o=n.map(c=>/@[A-Za-z][A-Za-z ]*:/.test(c)).lastIndexOf(!0),i=r!==-1?r:o;if(t.length===0||i===-1)return e;let a=n[i].slice(0,n[i].indexOf("@"));return[...n.slice(0,i+1),...t.map(c=>`${a}@Copyright: ${c}`),...n.slice(i+1)].join(`
|
|
20
|
-
`)}s(
|
|
21
|
-
`)?y:`${y}${
|
|
22
|
-
`}`;return`${r}${i}${
|
|
20
|
+
`)}s(ci,"insertCopyrights");function Yn(e,t){let n=0,r=W(e,t);for(;r&&r[0].length>0&&Jn(Ge(r[0],t));)n+=r[0].length,r=W(e.slice(n),t);return n}s(Yn,"leadingHeadersLength");function me(e,t="",n={}){let r=e.startsWith("\uFEFF")?"\uFEFF":"",o=e.slice(r.length),i=ce(t,o,n),a=U(t,n),c=i.length,l=Yn(o.slice(c),a);if(l===0)return e;let f=r===""&&c===0&&o.startsWith("\uFEFF",l);f&&(r="\uFEFF",o=`${o.slice(0,l)}${o.slice(l+1)}`,l+=Yn(o.slice(l),a));let u=o.slice(c,c+l),m=o.slice(c+l),h=ce(t,`${i}${m}`,n),y=h.length>i.length?h.slice(i.length):"";if(y===""&&!f)return e;let d=y===""||y.endsWith(`
|
|
21
|
+
`)?y:`${y}${de(e)??`
|
|
22
|
+
`}`;return`${r}${i}${d}${u}${m.slice(y.length)}`}s(me,"restoreTopLines");function pe(e,t="",n={}){let{prefix:r,body:o}=We(t,e,n),i=o.split(`
|
|
23
23
|
`).slice(0,zt).join(`
|
|
24
|
-
`),a=U(t,n);if(!W(i,a))return null;let l=0,
|
|
25
|
-
`?E:E.replace(/\r?\n/g,S),"withEol");if(!i){let{prefix:E,body:S}=We(n,o,r),A=
|
|
26
|
-
`,R=
|
|
27
|
-
`)?A:"",P=`${E}${g}${V.trim()===""?`${R}${A}`:`${R}${A.repeat(l+1)}${V}`}`;return{nextContent:P,changed:P!==e,header:R,written:R,extraCopyrights:[]}}let u=o.slice(i.start,i.end),{foreign:m,copyrights:h}=
|
|
28
|
-
`).find(E=>E.includes("@Copyright:")),
|
|
29
|
-
`,b=w.repeat(l+1),$=r.strictHeaderBlock!==!1,C=
|
|
24
|
+
`),a=U(t,n);if(!W(i,a))return null;let l=0,f=0;for(;;){let u=i.slice(l),m=W(u,a);if(!m||!Jn(Ge(m[0],a)))break;l+=m[0].length,f=l}return f===0?null:{start:r.length,end:r.length+f}}s(pe,"findProjectHeader");function he(e,t,n="",r={}){let o=me(e,n,r),i=pe(o,n,r),a=U(n,r),c=T(r.margin,"margin",le),l=a.kind==="line"?Math.max(1,c):c,f=s((E,S)=>S===`
|
|
25
|
+
`?E:E.replace(/\r?\n/g,S),"withEol");if(!i){let{prefix:E,body:S}=We(n,o,r),A=de(o)??`
|
|
26
|
+
`,R=f(t,A),V=S.replace(/^(?:\r?\n)+/,""),g=E.replace(/^\uFEFF/,"")!==""&&!E.endsWith(`
|
|
27
|
+
`)?A:"",P=`${E}${g}${V.trim()===""?`${R}${A}`:`${R}${A.repeat(l+1)}${V}`}`;return{nextContent:P,changed:P!==e,header:R,written:R,extraCopyrights:[]}}let u=o.slice(i.start,i.end),{foreign:m,copyrights:h}=ii(u,n,r),y=t.split(`
|
|
28
|
+
`).find(E=>E.includes("@Copyright:")),d=new Set(y===void 0?[]:[Gn(y.slice(y.indexOf("@Copyright:")+11))]),p=[];for(let E of h){let S=Gn(E);d.has(S)||(d.add(S),p.push(E))}let w=de(o.slice(i.end))??de(u)??`
|
|
29
|
+
`,b=w.repeat(l+1),$=r.strictHeaderBlock!==!1,C=ci(t,p),M=f(m.length>0&&!$?ai(C,m,a):C,w),k=m.length>0&&$?si(m,a,w):"",B=o.slice(i.end).replace(/^(?:\r?\n)+/,""),G=k===""?B:`${k}${B.trim()===""?w:`${b}${B}`}`,Y=`${o.slice(0,i.start)}${G.trim()===""?`${M}${w}`:`${M}${b}${G}`}`,x=`${M}${k===""?"":`${b}${k}`}`;return{nextContent:Y,changed:Y!==e,header:M,written:x,extraCopyrights:p}}s(he,"replaceOrInsertHeader");function Ye(e,t="",n={}){let r=me(e,t,n),o=pe(r,t,n);if(o){let l=r.slice(0,o.start),u=he(r,"",t,{...n,strictHeaderBlock:!0}).nextContent.slice(l.length).replace(/^(?:\r?\n)+/,"");return`${l}${u.trim()===""?"":u}`}let{prefix:i,body:a}=We(t,r,n),c=a.replace(/^(?:\r?\n)+/,"");return`${i}${c.trim()===""?"":c}`}s(Ye,"extractHeaderlessBody");function li(e,t){let n=e.length,r=t.length,o=Array.from({length:n+1},()=>new Array(r+1).fill(0));for(let l=n-1;l>=0;l-=1)for(let f=r-1;f>=0;f-=1)o[l][f]=e[l]===t[f]?o[l+1][f+1]+1:Math.max(o[l+1][f],o[l][f+1]);let i=[],a=0,c=0;for(;a<n&&c<r;)e[a]===t[c]?(i.push({type:" ",line:e[a]}),a+=1,c+=1):o[a+1][c]>=o[a][c+1]?(i.push({type:"-",line:e[a]}),a+=1):(i.push({type:"+",line:t[c]}),c+=1);for(;a<n;a+=1)i.push({type:"-",line:e[a]});for(;c<r;c+=1)i.push({type:"+",line:t[c]});return i}s(li,"diffLines");function Kn(e,t){return`${t===0?e:e+1},${t}`}s(Kn,"formatRange");function qn(e,t,n={}){let r=e===null?[]:e.split(`
|
|
30
30
|
`),o=t.split(`
|
|
31
|
-
`),i=
|
|
32
|
-
`)}s(
|
|
33
|
-
`).length-1;ne.sample={previousValue:N,newValue:z,diff:
|
|
31
|
+
`),i=li(r,o),a=Math.max(0,n.context??3),c=n.lineOffset??0,l=[];if(i.forEach((h,y)=>{if(h.type===" ")return;let d=l[l.length-1];d&&y-d.last<=a*2+1?d.last=y:l.push({first:y,last:y})}),l.length===0)return"";let f=n.fromFile??"a",u=n.toFile??"b",m=[`--- ${e===null?"/dev/null":f}`,`+++ ${u}`];for(let h of l){let y=Math.max(0,h.first-a),d=Math.min(i.length,h.last+a+1),p=i.slice(0,y),w=i.slice(y,d),b=p.filter(k=>k.type!=="+").length+c,$=p.filter(k=>k.type!=="-").length+c,C=w.filter(k=>k.type!=="+").length,M=w.filter(k=>k.type!=="-").length;m.push(`@@ -${Kn(b,C)} +${Kn($,M)} @@`);for(let k of w)m.push(`${k.type}${k.line}`)}return m.join(`
|
|
32
|
+
`)}s(qn,"createUnifiedDiff");function mi(e){return re(e,"configFile")}s(mi,"resolveRuntimeOptions");function pi(e){if(e==null)return[];let t=Array.isArray(e)?e:[e];if(t.some(n=>typeof n!="string"))throw new Error(`input must be a path or an array of paths, got ${JSON.stringify(e)}`);return t.filter(n=>n.trim().length>0)}s(pi,"resolveInputs");function hi(e){let t=e.match(/@Author:\s*(.+)$/m),n=e.match(/@Email:\s*<([^>\n]+)>/m);return{authorName:t?.[1]?.trim(),authorEmail:n?.[1]?.trim()}}s(hi,"extractHeaderAuthorIdentity");function gi(e){let t=e.match(/@Last modified by:\s*(.+?)\s*\(([^)\n]+)\)\s*$/m);return{authorName:t?.[1]?.trim(),authorEmail:t?.[2]?.trim()}}s(gi,"extractHeaderLastModifiedIdentity");function yi(e){let t=e.match(/@Date:\s*(.+?)\s*\((\d+)\)$/m);if(!t||!t[1]||!t[2])return null;let n=Number.parseInt(t[2],10);return Number.isNaN(n)?null:{date:t[1].trim(),timestamp:n}}s(yi,"extractHeaderCreatedAt");function xi(e){let t=e.match(/@Last modified time:\s*(.+?)\s*\((\d+)\)$/m);if(!t||!t[1]||!t[2])return null;let n=Number.parseInt(t[2],10);return Number.isNaN(n)?null:{date:t[1].trim(),timestamp:n}}s(xi,"extractHeaderLastModifiedAt");async function wi(e,t,n){let r=await vn(t);return r.state!=="tracked"?{edited:r.state==="untracked",state:r.state}:{edited:Ye(r.content,t,n)!==Ye(e,t,n),state:"tracked"}}s(wi,"detectContentEdit");async function Xn(e={}){let t=await mi(e),n=t.timezone===void 0||t.timezone===null?null:Fn(t.timezone),r=t.convertTimezone===!0;if(r&&!n)throw new Error("convertTimezone requires timezone: set timezone (CLI --timezone <name>) to the IANA zone to convert header dates into");let o=Ot(t.forcedDetectors),i=Zn(t.projectRoot||t.cwd||process.cwd()),a=await Te({...t,cwd:i});T(t.spacing,"spacing",Z),T(t.margin,"margin",le);let c=t.check===!0,l=c||t.dryRun===!0,f=t.fixCreatedDate===!0,u=s(x=>x,"keepDate"),m=t.normalizeDateFormat===!0?Hn:u,h=n?x=>_n(x,n):u,y=r?h:u,d={language:a.language,enabledDetectors:t.enabledDetectors,disabledDetectors:t.disabledDetectors,forcedDetectors:o,includeFolders:t.includeFolders,excludeFolders:t.excludeFolders,includeExtensions:t.includeExtensions,gitignore:t.gitignore},p=pi(t.input),w;if(p.length>0){let x=new Set;for(let E of p){let S=Zn(i,E),A=await fi(S).catch(()=>null);if(!A)throw new Error(`Input path does not exist: ${E}`);if(A.isFile())x.add(S);else if(A.isDirectory())for(let R of await Le({...d,projectRoot:S}))x.add(R);else throw new Error(`Input path must be a file or directory: ${E}`)}w=Array.from(x)}else w=await Le({...d,projectRoot:i});let b=new Date().getFullYear(),$=[],C=[],M=new Set,k=0,B=0,G=0,Y=[];for(let x of w){let E=Ht(x,{enabledDetectors:t.enabledDetectors,disabledDetectors:t.disabledDetectors,forcedDetectors:o});if(E!==null){C.push({file:Ve(i,x),reason:E});continue}let S=Ve(i,x),A=await ui(x,"utf8"),R={enabledDetectors:t.enabledDetectors,disabledDetectors:t.disabledDetectors,forcedDetectors:o,detectorSyntaxOverrides:t.detectorSyntaxOverrides},V=Bt(x,me(A,x,R),R);if(V!==null){C.push({file:S,reason:V});continue}let g=await Te({...t,cwd:i,targetFilePath:x});M.add(`${g.language}:${g.projectRoot}`);let P={language:g.language,enabledDetectors:t.enabledDetectors,disabledDetectors:t.disabledDetectors,forcedDetectors:o,detectorSyntaxOverrides:t.detectorSyntaxOverrides,spacing:t.spacing,margin:t.margin,strictHeaderBlock:t.strictHeaderBlock!==!1},ge=pe(A,x,P),v=ge?A.slice(ge.start,ge.end):"",Ke=v.length>0?hi(v):{},qe=v.length>0?gi(v):{},or=v.length>0?yi(v):null,ir=v.length>0?xi(v):null,Ze=await Wt(x),Xe=Ve(g.projectRoot,x),Qe=await Dn(g.projectRoot,Xe),J=await Cn(g.projectRoot,Xe),et=fe(Ze.createdAt),ye=In({existing:ze(or),gitCreated:Qe,filesystemCreated:et,fixCreatedDate:f}),K=ze(ir),tt=ye.source,sr=K?"existing-header":J?"git-last-modified":"filesystem-updated",xe=m(tt==="existing-header"?y(ye.payload):h(ye.payload)),ar=g.copyrightStartYear===null?"created-date":"option",nt=g.copyrightStartYear??On(xe,n),rt=m(K?y(K):h(J||fe(Ze.updatedAt))),ot=t.forceAuthorUpdate===!0,cr=t.forceLastModifiedAuthorUpdate===!0,it=await wi(A,x,P),st=cr||it.edited,at=s(N=>Bn({absoluteFilePath:x,language:g.language,syntaxOptions:P,projectRoot:g.projectRoot,projectName:g.projectName,createdByName:ot?g.authorName:Ke.authorName||g.authorName,createdByEmail:ot?g.authorEmail:Ke.authorEmail||g.authorEmail,lastModifiedByName:st?g.authorName:qe.authorName||g.authorName,lastModifiedByEmail:st?g.authorEmail:qe.authorEmail||g.authorEmail,authorName:g.authorName,authorEmail:g.authorEmail,createdAt:xe,lastModifiedAt:N,copyrightStartYear:nt,companyName:g.companyName,currentYear:b}),"renderHeader"),ct=at(rt),lt=he(A,ct,x,P),lr=it.edited&&K!==null&&J!==null&&K.timestamp<J.timestamp,te=lt.changed||lr,ut=te?m(h(fe(new Date))):rt,ur=te?"current-time-on-change":sr,fr=te?at(ut):ct,L=te?he(A,fr,x,P):lt,ne={file:S,changed:L.changed};if(c){let N=Tn(v,{gitCreated:Qe,gitLastModified:J,filesystemCreated:et},{strictCreatedDate:t.strictCreatedDate===!0}),q=N.filter(z=>z.advisory).length;ne.dateIssues=N,G+=q,B+=N.length>q?1:0}if(t.sampleOutput===!0&&L.changed){let N=v.length>0?v.trimEnd():null,q=S.replace(/\\/g,"/"),z=L.written,dr=L.nextContent.slice(0,L.nextContent.indexOf(z)).split(`
|
|
33
|
+
`).length-1;ne.sample={previousValue:N,newValue:z,diff:qn(N,z,{fromFile:`a/${q}`,toFile:`b/${q}`,lineOffset:dr}),issues:Wn(N,z),detectedValues:{projectName:g.projectName,projectNameSource:g.projectNameSource,language:g.language,projectRoot:g.projectRoot,marker:g.marker,authorName:g.authorName,authorEmail:g.authorEmail,companyName:g.companyName,companyNameSource:g.companyNameSource,copyrightStartYear:nt,copyrightStartYearSource:ar,createdAtSource:tt,lastModifiedAtSource:ur,createdAt:xe,lastModifiedAt:ut}}}if(L.extraCopyrights.length>0){ne.extraCopyrights=L.extraCopyrights;for(let N of L.extraCopyrights)Y.push({file:S,copyright:N})}$.push(ne),L.changed&&(k+=1,l||await di(x,L.nextContent,"utf8"))}return{metadata:a,detectedProjects:Array.from(M),filesScanned:w.length-C.length,filesUpdated:k,filesSkipped:C.length,dryRun:l,check:c,...c?{filesWithDateDrift:B,dateAdvisories:G}:{},copyrightWarnings:Y,changes:$,skipped:C}}s(Xn,"fixHeaders");function bi(e){return Xn(e)}s(bi,"fixHeaders");var Qn=bi;var $i=`fix-headers CLI
|
|
34
34
|
|
|
35
35
|
Usage:
|
|
36
36
|
fix-headers [options]
|
|
@@ -81,5 +81,5 @@ Examples:
|
|
|
81
81
|
fix-headers --check --verbose
|
|
82
82
|
fix-headers --timezone America/Los_Angeles --convert-timezone
|
|
83
83
|
fix-headers --project-name @scope/pkg --company-name "Catalyzed Motivation Inc."
|
|
84
|
-
`;function
|
|
84
|
+
`;function Si(e){return e.replace(/-([a-z])/g,(t,n)=>n.toUpperCase())}s(Si,"toCamelCase");function Ai(e){let t={},n={help:!1,json:!1,diff:!1},r={"include-folder":"includeFolders","exclude-folder":"excludeFolders","include-extension":"includeExtensions","enable-detector":"enabledDetectors","disable-detector":"disabledDetectors","force-detector":"forcedDetectors",input:"input"},o={cwd:"cwd","project-name":"projectName",language:"language","project-root":"projectRoot",marker:"marker","author-name":"authorName","author-email":"authorEmail",company:"company","company-name":"companyName","copyright-start-year":"copyrightStartYear",spacing:"spacing",margin:"margin",timezone:"timezone",config:"config"};for(let i=0;i<e.length;i+=1){let a=e[i];if(a==="-h"||a==="--help"){n.help=!0;continue}if(a==="--json"){n.json=!0;continue}if(a==="--diff"){n.diff=!0;continue}if(a==="--verbose"){t.verbose=!0;continue}if(a==="--dry-run"){t.dryRun=!0;continue}if(a==="--check"){t.check=!0;continue}if(a==="--fix-created-date"){t.fixCreatedDate=!0;continue}if(a==="--strict-created-date"){t.strictCreatedDate=!0;continue}if(a==="--strict-header-block"){let u=e[i+1];(u==="true"||u==="false")&&(i+=1),t.strictHeaderBlock=u!=="false";continue}if(a==="--no-strict-header-block"){t.strictHeaderBlock=!1;continue}if(a==="--normalize-date-format"){t.normalizeDateFormat=!0;continue}if(a==="--convert-timezone"){t.convertTimezone=!0;continue}if(a==="--sample-output"){t.sampleOutput=!0;continue}if(a==="--force-author-update"){t.forceAuthorUpdate=!0;continue}if(a==="--force-last-modified-author-update"){t.forceLastModifiedAuthorUpdate=!0;continue}if(a==="--use-gpg-signer-author"){t.useGpgSignerAuthor=!0;continue}if(!a.startsWith("--"))throw new Error(`Unexpected argument: ${a}`);let c=a.slice(2);if(c==="include-folder-non-recursive"){let u=e[i+1];if(!u||u.startsWith("--"))throw new Error(`Missing value for --${c}`);i+=1;let m=Array.isArray(t.includeFolders)?t.includeFolders:[];t.includeFolders=[...m,{path:u,recursive:!1}];continue}if(r[c]){let u=e[i+1];if(!u||u.startsWith("--"))throw new Error(`Missing value for --${c}`);i+=1;let m=r[c],h=Array.isArray(t[m])?t[m]:[];t[m]=Array.from(new Set([...h,u]));continue}if(o[c]){let u=e[i+1];if(!u||u.startsWith("--"))throw new Error(`Missing value for --${c}`);i+=1;let m=o[c];if(m==="copyrightStartYear"||m==="spacing"||m==="margin"){if(t[m]=Number.parseInt(u,10),Number.isNaN(t[m]))throw new Error(`Invalid number for --${c}: ${u}`)}else m==="marker"&&u==="null"?t[m]=null:t[m]=u;continue}let l=Si(c),f=e[i+1];if(!f||f.startsWith("--"))throw new Error(`Unknown or malformed flag: --${c}`);i+=1,t[l]=f}return{options:t,help:n.help,json:n.json,diff:n.diff}}s(Ai,"parseCliArgs");function Di(e){return re(e,"config")}s(Di,"applyConfigFile");function Je(e){if(!e||typeof e!="object")return[];let t=e;return(Array.isArray(t.changes)?t.changes:[]).filter(r=>r&&r.changed===!0&&r.sample&&typeof r.sample.newValue=="string")}s(Je,"getSampledChanges");function tr(e){return typeof e=="string"?`"${e}"`:"(missing)"}s(tr,"formatIssueValue");function Ci(e,t){for(let n of Je(t)){let r=Array.isArray(n.sample.issues)?n.sample.issues:[];if(e(`issues: ${n.file||"<unknown-file>"}`),r.length===0){e(" (no field differences; header formatting only)");continue}for(let o of r)e(` ${o?.field||"<unknown-field>"}: found ${tr(o?.previous)}, expected ${tr(o?.detected)}`)}}s(Ci,"printIssues");function vi(e,t){for(let n of Je(t))typeof n.sample.diff=="string"&&n.sample.diff.length>0&&e(n.sample.diff)}s(vi,"printDiffs");function Ni(e,t){for(let n of Je(t))e(`sample: ${n.file||"<unknown-file>"}`),e("previous:"),e(n.sample.previousValue===null?"(none)":String(n.sample.previousValue)),e("new:"),e(n.sample.newValue),n.sample.detectedValues&&typeof n.sample.detectedValues=="object"&&(e("detected-values:"),e(JSON.stringify(n.sample.detectedValues,null,2)))}s(Ni,"printSampleOutput");function Fi(e,t){if(!t||typeof t!="object")return;let n=t,o=(Array.isArray(n.changes)?n.changes:[]).filter(i=>i&&i.changed===!0).map(i=>i.file||"<unknown-file>");for(let i of o)e(`updated: ${i}`)}s(Fi,"printChangedFiles");function nr(e,t){let n=Array.isArray(t.copyrightWarnings)?t.copyrightWarnings:[];for(let r of n)e(`warning: ${r?.file||"<unknown-file>"} keeps an additional @Copyright: ${r?.copyright??""}`)}s(nr,"printCopyrightWarnings");function Li(e,t){let n=Array.isArray(t.skipped)?t.skipped:[];for(let r of n)e(`skipped: ${r?.file||"<unknown-file>"} (${r?.reason||"no reason given"})`)}s(Li,"printSkipped");function rr(e,t,n,r){let o=n.sampleOutput===!0||r;n.verbose===!0&&(Fi(e,t),o&&Ci(e,t)),n.sampleOutput===!0&&Ni(e,t),r&&vi(e,t)}s(rr,"printDetails");function ji(e,t,n){let r=Array.isArray(t.changes)?t.changes:[];for(let o of r){let i=Array.isArray(o?.dateIssues)?o.dateIssues:[];for(let a of i)a.advisory===!0&&!n||e(`${a.advisory===!0?"advisory":"drift"}: ${o.file||"<unknown-file>"}: ${a.message}`)}}s(ji,"printDateIssues");async function Mi(e,t={}){let n=t.runner||Qn,r=t.stdout||console.log,o=t.stderr||console.error;try{let i=Ai(e);if(i.help)return r($i),0;let a=await Di(i.options),c=await n(i.diff?{...a,sampleOutput:!0}:a),l=c&&typeof c=="object"&&c.check===!0?c:null,f=l&&Number(l.filesWithDateDrift)>0?1:0;if(i.json)return r(JSON.stringify(c,null,2)),f;if(l)return r(`fix-headers check: scanned=${l.filesScanned??0}, drift=${l.filesWithDateDrift??0}, advisories=${l.dateAdvisories??0}`),ji(r,l,a.verbose===!0),nr(r,c),f;if(c&&typeof c=="object"){let u=c,m=Number(u.filesSkipped)>0?`, skipped=${u.filesSkipped}`:"",h=Array.isArray(u.copyrightWarnings)&&u.copyrightWarnings.length>0?`, warnings=${u.copyrightWarnings.length}`:"";r(`fix-headers complete: scanned=${u.filesScanned??0}, updated=${u.filesUpdated??0}${m}${h}, dryRun=${u.dryRun===!0}`),Li(r,u),nr(r,u),rr(r,c,a,i.diff)}else rr(r,c,a,i.diff),r("fix-headers complete");return 0}catch(i){let a=i instanceof Error?i.message:String(i);return o(`fix-headers failed: ${a}`),1}}s(Mi,"runCli");function Ri(e=process.argv,t=import.meta.url,n=Mi){let r=!1;if(e[1])try{let o=er(e[1]),i=er(ki(t));r=o===i}catch{r=t===Ei(e[1]).href}return r?(n(e.slice(2)).then(o=>{process.exitCode=o}),!0):!1}s(Ri,"runCliAsMain");Ri();export{Di as applyConfigFile,Ai as parseCliArgs,Mi as runCli,Ri as runCliAsMain};
|
|
85
85
|
//# sourceMappingURL=fix-headers.mjs.map
|
package/dist/index.cjs
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* @Email: <Shinrai@users.noreply.github.com>
|
|
8
8
|
* -----
|
|
9
9
|
* @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
|
|
10
|
-
* @Last modified time: 2026-
|
|
10
|
+
* @Last modified time: 2026-11-01T16:29:20-08:00 (1793579360)
|
|
11
11
|
* -----
|
|
12
12
|
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
13
|
*
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
* returns the default export, keeping the historical `module.exports = fixHeaders`
|
|
22
22
|
* shape, instead of tsup bundling a second full copy of the library for CJS.
|
|
23
23
|
*
|
|
24
|
-
* Node.js versions without require(esm) (before 20.19
|
|
25
|
-
*
|
|
26
|
-
* instead.
|
|
24
|
+
* Node.js versions without require(esm) (20.x before 20.19, 22.x before 22.12, and
|
|
25
|
+
* anything older) would fail with a bare ERR_REQUIRE_ESM, so the check below fails
|
|
26
|
+
* early with a message that says what to do instead.
|
|
27
27
|
*
|
|
28
28
|
* It sits next to the ESM entry under the same name, so `require("./index.mjs")` resolves
|
|
29
29
|
* to src/index.mjs from source and to dist/index.mjs once built. tsup's `onSuccess` copies
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
|
|
36
36
|
if (!process.features?.require_module) {
|
|
37
37
|
const error = new Error(
|
|
38
|
-
`@cldmv/fix-headers: require() needs Node.js ^20.19.0 or >=22.
|
|
38
|
+
`@cldmv/fix-headers: require() needs Node.js ^20.19.0 or >=22.13.0 (this is ${process.version}). On older Node.js, load the package with import() instead.`
|
|
39
39
|
);
|
|
40
40
|
error.code = "ERR_REQUIRE_ESM";
|
|
41
41
|
throw error;
|
package/dist/index.mjs
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
var
|
|
2
|
-
`,n),a=s===-1?e.length:s+1;if(!t(e.slice(n,a).replace(/\r?\n$/,""),o))break;n=a,o+=1}return e.slice(0,n)}i(ie,"takeTopLines");var yt=[".go"];function
|
|
3
|
-
`).length-1);return`${o}${a}`}i(ae,"getPreservedPrefixForFile");function Bt(e,t,r={}){let n=_t(e,r);return n&&typeof n.resolveContentSkipReason=="function"?n.resolveContentSkipReason(t):null}i(Bt,"getContentSkipReason");var Ut=200,Z=1,ce=2;function O(e,t,r){if(e==null)return r;if(typeof e!="number"||!Number.isInteger(e)||e<0)throw new Error(`${t} must be a whole number of 0 or more, got ${JSON.stringify(e)}`);return e}i(O,"resolveLayoutCount");import{existsSync as
|
|
4
|
-
`)}i(
|
|
5
|
-
`,r);r=n===-1?e.length:n+1}else if(/\s/.test(e[r]))r+=1;else break;return r}i(
|
|
6
|
-
`)){let a=s.split(":");if(a[0]==="uid"&&a[1]!=="r"&&a[1]!=="e"&&a[9])return
|
|
7
|
-
`)[0],[o,s]=n.split("|");if(!o||!s)return null;let a=Number.parseInt(s,10);return Number.isNaN(a)?null:{date:$r(o),timestamp:a}}i(Sr,"getGitCreationDate");async function Dr(e,t){let r=await v(e,["log","-1","--format=%aI|%at","--",t]);if(!r)return null;let[n,o]=r.split("|");if(!n||!o)return null;let s=Number.parseInt(o,10);return Number.isNaN(s)?null:{date:$r(n),timestamp:s}}i(Dr,"getGitLastModifiedDate");var
|
|
1
|
+
var an=Object.defineProperty;var i=(e,t)=>an(e,"name",{value:t,configurable:!0});import{readFile as oi,stat as ii,writeFile as si}from"node:fs/promises";import{relative as Ye,resolve as qr}from"node:path";import{readFile as cn}from"node:fs/promises";import{createRequire as ln}from"node:module";import{dirname as un,isAbsolute as dn,resolve as ut}from"node:path";var fn=3e4,mn=new Set(["localhost","127.0.0.1","[::1]"]);function xe(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}i(xe,"isPlainObject");function we(e,t){let r={...e};for(let[n,o]of Object.entries(t))n!=="__proto__"&&(r[n]=xe(r[n])&&xe(o)?we(r[n],o):o);return r}i(we,"mergeConfig");function dt(e){return e.kind==="file"?e.path:e.href}i(dt,"describeSource");async function pn(e){if(e.kind==="file")return{text:await cn(e.path,"utf8"),source:e};let t;try{t=await fetch(e.href,{cache:"no-store",redirect:"follow",signal:AbortSignal.timeout(fn)})}catch(r){let n=r.cause instanceof Error?r.cause.message:r.message;throw new Error(`Failed to fetch config ${e.href}: ${n}`,{cause:r})}if(!t.ok)throw new Error(`Failed to fetch config ${e.href}: HTTP ${t.status} ${t.statusText}`);return{text:await t.text(),source:{kind:"url",href:t.url}}}i(pn,"readSource");function lt(e){if(e.protocol==="http:"&&!mn.has(e.hostname))throw new Error(`Refusing to fetch config over plain http: ${e.href} (use https)`);return{kind:"url",href:e.href}}i(lt,"toUrlSource");function hn(e,t){if(/^https?:\/\//i.test(e))return lt(new URL(e));if(/^[a-z][a-z\d+.-]+:\/\//i.test(e))throw new Error(`Unsupported extends URL "${e}" in ${dt(t)}; use https, a file path or a package path`);let r=/^\.{1,2}[\\/]/.test(e);if(t.kind==="url"){if(r||e.startsWith("/"))return lt(new URL(e,t.href));throw new Error(`Cannot extend package "${e}" from the remote config ${t.href}; use a URL or a relative path`)}if(r||dn(e))return{kind:"file",path:ut(un(t.path),e)};try{return{kind:"file",path:ln(t.path).resolve(e)}}catch(n){throw new Error(`Cannot resolve extends "${e}" from ${t.path}: ${n.message}`,{cause:n})}}i(hn,"resolveReference");function gn(e,t){if(e===void 0)return[];let r=Array.isArray(e)?e:[e];if(!r.every(n=>typeof n=="string"&&n.trim().length>0))throw new Error(`Config "extends" must be a string or an array of strings: ${t}`);return r.map(n=>n.trim())}i(gn,"readExtends");async function ft(e,t){let r=dt(e);if(t.includes(r))throw new Error(`Config extends cycle: ${[...t,r].join(" -> ")}`);let{text:n,source:o}=await pn(e),s;try{s=JSON.parse(n)}catch(u){throw new Error(`Config ${r} is not valid JSON: ${u.message}`,{cause:u})}if(!xe(s))throw new Error(`Config file must contain a JSON object: ${r}`);let{extends:a,...c}=s,l={};for(let u of gn(a,r))l=we(l,await ft(hn(u,o),[...t,r]));return we(l,c)}i(ft,"loadSource");function yn(e,t=process.cwd()){return ft({kind:"file",path:ut(t,e)},[])}i(yn,"loadConfigFile");async function mt(e,t){let r=typeof e[t]=="string"?e[t].trim():"";if(r.length===0)return e;let n=typeof e.cwd=="string"&&e.cwd.length>0?e.cwd:process.cwd(),o={...await yn(r,n),...e};return delete o[t],o}i(mt,"applyConfigOption");import{extname as be}from"node:path";import{extname as xn}from"node:path";var pt=[".css"];function wn(e){let t=xn(e).toLowerCase();return pt.includes(t)?{kind:"block",blockStart:"/*",blockLinePrefix:" * ",blockEnd:" */"}:null}i(wn,"resolveCssCommentSyntax");var ht={id:"css",extensions:pt,enabledByDefault:!0,keepsAboveHeader:i((e,t)=>t===0&&/^@charset "[^"]*";/.test(e),"keepsAboveHeader"),resolveCommentSyntax(e){return wn(e)}};import{extname as $n}from"node:path";var bn=/^(?:#|\/\/|\/\*+|<!--)[ \t]+(vi|vim(?:[<=>]?\d+)?|Vim|ex):(.*)$/,En=/^[a-z]+(?:[!&]|[+^-]?=(?:\\.|[^\s:\\])*)?$/,kn=new Set(["et","expandtab","ai","autoindent","si","smartindent","ro","readonly","bin","binary","noet","noexpandtab","noai","noautoindent","nosi","nosmartindent","noro","noreadonly","nobin","nobinary","nowrap","nolist","nospell","nofen","nofoldenable","noeol","nofixeol","nofixendofline"]);function ne(e){let t=e.match(bn);if(!t)return!1;let r=t[2].trim();if(r.endsWith("-->"))r=r.slice(0,-3).trimEnd();else if(r.endsWith("*/")){let s=r.length-2;for(;s>0&&r[s-1]==="*";)s-=1;r=r.slice(0,s).trimEnd()}let n=r.match(/^se(?:t)?[ \t]((?:\\.|[^:\\])*):/);if(!n&&t[1]==="Vim")return!1;let o=n?n[1].match(/(?:\\.|[^\s\\])+/g):r.match(/(?:\\.|[^\s:\\])+/g);return o!==null&&o.every(s=>En.test(s))&&o.some(s=>s.includes("=")||kn.has(s))}i(ne,"isModeline");function oe(e,t){return t===0&&e.startsWith("#!")}i(oe,"isShebang");function ie(e,t,r=0){let n=0,o=r;for(;n<e.length;){let s=e.indexOf(`
|
|
2
|
+
`,n),a=s===-1?e.length:s+1;if(!t(e.slice(n,a).replace(/\r?\n$/,""),o))break;n=a,o+=1}return e.slice(0,n)}i(ie,"takeTopLines");var yt=[".go"];function Sn(e){let t=$n(e).toLowerCase();return yt.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}i(Sn,"resolveGoCommentSyntax");var gt=/^\/\/(?:go:build|\s*\+build)\s/;function Dn(e,t){let r=ie(t,o=>gt.test(o)||ne(o));if(!r.split(/\r?\n/).some(o=>gt.test(o)))return"";let n=t.slice(r.length);return`${r}${n.slice(0,n.length-n.replace(/^(?:[ \t]*\r?\n)*/,"").length)}`}i(Dn,"resolveGoPreservedPrefix");var xt={id:"go",extensions:yt,enabledByDefault:!0,resolvePreservedPrefix(e,t){return Dn(e,t)},resolveCommentSyntax(e){return Sn(e)}};import{extname as An}from"node:path";var wt=[".html",".htm"];function Cn(e){let t=An(e).toLowerCase();return wt.includes(t)?{kind:"html",blockStart:"<!--",blockLinePrefix:" ",blockEnd:"-->"}:null}i(Cn,"resolveHtmlCommentSyntax");var bt={id:"html",extensions:wt,enabledByDefault:!0,resolveCommentSyntax(e){return Cn(e)}};import{extname as Fn}from"node:path";var Et=[".jsonv",".jsonc",".json5"];function Nn(e){let t=Fn(e).toLowerCase();return Et.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}i(Nn,"resolveJsonCommentSyntax");var kt={id:"json",extensions:Et,enabledByDefault:!0,resolveCommentSyntax(e){return Nn(e)}};import{extname as vn}from"node:path";var $t=[".md",".markdown"];function Ln(e){let t=vn(e).toLowerCase();return $t.includes(t)?{kind:"html",blockStart:"<!--",blockLinePrefix:" ",blockEnd:"-->"}:null}i(Ln,"resolveMarkdownCommentSyntax");function Mn(e,t){let r=t.match(/^---\r?\n[\s\S]*?\r?\n---[ \t]*(?:\r?\n|$)/);return r?r[0]:""}i(Mn,"resolveMarkdownPreservedPrefix");var St={id:"markdown",extensions:$t,enabledByDefault:!1,requiresForce:!0,resolvePreservedPrefix(e,t){return Mn(e,t)},resolveCommentSyntax(e){return Ln(e)}};import{extname as Rn}from"node:path";var Dt=[".js",".mjs",".cjs",".ts",".tsx",".jsx"];function jn(e){let t=Rn(e).toLowerCase();return Dt.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}i(jn,"resolveNodeCommentSyntax");var At={id:"node",extensions:Dt,enabledByDefault:!0,keepsAboveHeader:oe,resolveCommentSyntax(e){return jn(e)}};import{extname as Pn}from"node:path";var Ft=[".php"];function In(e){let t=Pn(e).toLowerCase();return Ft.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}i(In,"resolvePhpCommentSyntax");var Ct=/^<\?php(?:\s|$)/i,Nt={id:"php",extensions:Ft,enabledByDefault:!0,keepsAboveHeader:i((e,t)=>t===0&&Ct.test(e),"keepsAboveHeader"),resolveContentSkipReason(e){return Ct.test(e.replace(/^\uFEFF/,""))?null:"the file does not start with <?php, so a comment at the top would be output as text"},resolveCommentSyntax(e){return In(e)}};import{extname as Tn}from"node:path";var vt=[".py"],On=/^#.*?(?<![A-Za-z])coding[:=]\s*[-\w.]+/;function Hn(e,t){return oe(e,t)||t<=1&&On.test(e)}i(Hn,"keepsAboveHeader");var Lt={id:"python",extensions:vt,enabledByDefault:!0,keepsAboveHeader:Hn,resolveCommentSyntax(e){let t=Tn(e).toLowerCase();return vt.includes(t)?{kind:"line",linePrefix:"#"}:null}};import{extname as _n}from"node:path";var Mt=[".rs"];function Bn(e){let t=_n(e).toLowerCase();return Mt.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}i(Bn,"resolveRustCommentSyntax");var Rt={id:"rust",extensions:Mt,enabledByDefault:!0,keepsAboveHeader:i((e,t)=>t===0&&e.startsWith("#!")&&!/^#!\s*\[/.test(e),"keepsAboveHeader"),resolveCommentSyntax(e){return Bn(e)}};import{extname as Un}from"node:path";var jt=[".yaml",".yml"];function zn(e){let t=Un(e).toLowerCase();return jt.includes(t)?{kind:"line",linePrefix:"#"}:null}i(zn,"resolveYamlCommentSyntax");var Pt={id:"yaml",extensions:jt,enabledByDefault:!0,keepsAboveHeader:i((e,t)=>t===0&&/^#cloud-config\s*$/.test(e),"keepsAboveHeader"),resolveCommentSyntax(e){return zn(e)}};var se=[ht,xt,bt,kt,St,At,Nt,Lt,Rt,Pt],Wn=new Map(se.map(e=>[e.id,e]));function Gn(e,t){return!t||typeof t!="object"?e:e.kind==="line"?{...e,linePrefix:typeof t.linePrefix=="string"&&t.linePrefix.length>0?t.linePrefix:e.linePrefix,lineSeparator:typeof t.lineSeparator=="string"?t.lineSeparator:e.lineSeparator}:{...e,blockStart:typeof t.blockStart=="string"&&t.blockStart.length>0?t.blockStart:e.blockStart,blockLinePrefix:typeof t.blockLinePrefix=="string"&&t.blockLinePrefix.length>0?t.blockLinePrefix:e.blockLinePrefix,blockEnd:typeof t.blockEnd=="string"&&t.blockEnd.length>0?t.blockEnd:e.blockEnd}}i(Gn,"applySyntaxOverride");function It(e){if(e==null)return[];if(!Array.isArray(e)||e.some(r=>typeof r!="string"))throw new Error(`forcedDetectors must be an array of detector ids, got ${JSON.stringify(e)}`);let t=se.filter(r=>r.requiresForce===!0).map(r=>r.id);for(let r of e){if(!Wn.has(r))throw new Error(`forcedDetectors: unknown detector "${r}" (force-only detectors: ${t.join(", ")})`);if(!t.includes(r))throw new Error(`forcedDetectors: "${r}" does not need forcing (force-only detectors: ${t.join(", ")})`)}return Array.from(new Set(e))}i(It,"resolveForcedDetectors");function T(e={}){let t=new Set(Array.isArray(e.enabledDetectors)?e.enabledDetectors:[]),r=new Set(Array.isArray(e.disabledDetectors)?e.disabledDetectors:[]),n=new Set(Array.isArray(e.forcedDetectors)?e.forcedDetectors:[]);return se.filter(o=>o.requiresForce===!0?n.has(o.id)&&!r.has(o.id):t.size>0?t.has(o.id):r.has(o.id)?!1:o.enabledByDefault)}i(T,"getEnabledDetectors");function Tt(e={}){if(Array.isArray(e.includeExtensions)&&e.includeExtensions.length>0)return new Set(e.includeExtensions.map(r=>r.toLowerCase()));let t=T(e);return new Set(t.flatMap(r=>r.extensions))}i(Tt,"getAllowedExtensions");function Ot(e,t={}){let r=be(e).toLowerCase();if(T(t).some(a=>a.extensions.includes(r)&&a.resolveCommentSyntax(e)!==null))return null;if(r.length===0)return"the file has no extension, so its comment syntax is unknown";let o=new Set(Array.isArray(t.forcedDetectors)?t.forcedDetectors:[]),s=se.find(a=>a.requiresForce===!0&&a.extensions.includes(r)&&!o.has(a.id));return s?`${r} files get a header only when forced (--force-detector ${s.id} / forcedDetectors: ["${s.id}"])`:`no enabled detector handles ${r} files`}i(Ot,"getHeaderSkipReason");function Ht(e,t={}){let r=be(e).toLowerCase(),n=Array.isArray(t.detectors)?t.detectors:T(t);for(let o of n){if(!o.extensions.includes(r))continue;let s=o.resolveCommentSyntax(e);if(s){let a=t.detectorSyntaxOverrides&&typeof t.detectorSyntaxOverrides=="object"?t.detectorSyntaxOverrides:{};return Gn(s,a[o.id])}}return{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}}i(Ht,"getCommentSyntaxForFile");function _t(e,t){let r=be(e).toLowerCase();return T(t).find(n=>n.extensions.includes(r))}i(_t,"detectorForFile");function ae(e,t,r={}){let n=_t(e,r);if(!n)return"";let o=typeof n.resolvePreservedPrefix=="function"?n.resolvePreservedPrefix(e,t):"",s=n.keepsAboveHeader,a=ie(t.slice(o.length),(c,l)=>ne(c)||typeof s=="function"&&s(c,l),o.split(`
|
|
3
|
+
`).length-1);return`${o}${a}`}i(ae,"getPreservedPrefixForFile");function Bt(e,t,r={}){let n=_t(e,r);return n&&typeof n.resolveContentSkipReason=="function"?n.resolveContentSkipReason(t):null}i(Bt,"getContentSkipReason");var Ut=200,Z=1,ce=2;function O(e,t,r){if(e==null)return r;if(typeof e!="number"||!Number.isInteger(e)||e<0)throw new Error(`${t} must be a whole number of 0 or more, got ${JSON.stringify(e)}`);return e}i(O,"resolveLayoutCount");import{existsSync as no}from"node:fs";import{join as Fe,relative as tr,resolve as Ne,sep as Ae}from"node:path";import{realpath as oo,stat as io}from"node:fs/promises";import{access as Yn,readdir as Vn,readFile as ws,stat as Jn}from"node:fs/promises";import{constants as qn}from"node:fs";import{dirname as ks,join as Kn,resolve as $s}from"node:path";async function Ee(e){try{return await Yn(e,qn.F_OK),!0}catch{return!1}}i(Ee,"pathExists");async function ke(e,t){let r=[],n=await Vn(e,{withFileTypes:!0});for(let o of n){let s=Kn(e,o.name);if(o.isDirectory()&&t.recursive===!1||o.isDirectory()&&t.ignoreFolders.has(o.name)||o.isDirectory()&&await t.shouldSkipDirectory?.(s,o.name)===!0)continue;if(o.isDirectory()){let l=await ke(s,t);r.push(...l);continue}if(!o.isFile())continue;let a=o.name.lastIndexOf(".");if(a===-1)continue;let c=o.name.slice(a).toLowerCase();t.allowedExtensions.has(c)&&r.push(s)}return r}i(ke,"walkFiles");async function zt(e){let t=await Jn(e);return{createdAt:t.birthtimeMs>0&&t.birthtime<t.mtime?t.birthtime:t.mtime,updatedAt:t.mtime}}i(zt,"readFileDates");function Wt(e){let t=e.indexOf("<");for(;t!==-1;){let r=e.indexOf(">",t+1);if(r===-1)return!1;if(r>t+1)return!0;t=e.indexOf("<",r+1)}return!1}i(Wt,"hasAngleTag");function Gt(e){let t=e.length;for(;t>0&&e[t-1]==="/";)t-=1;return e.slice(0,t)}i(Gt,"trimTrailingSlashes");import{execFile as Zn}from"node:child_process";import{lstat as Xn,readFile as Qn}from"node:fs/promises";import{dirname as Yt,isAbsolute as eo,join as qt,relative as Kt,resolve as $e,sep as Zt}from"node:path";import to from"ignore";function Vt(e,t){return new Promise(r=>{Zn("git",t,{cwd:e,encoding:"utf8",maxBuffer:Number.POSITIVE_INFINITY},(n,o)=>{if(!n){r({code:0,stdout:o});return}r({code:typeof n.code=="number"?n.code:-1,stdout:""})})})}i(Vt,"runGitCommand");function De(e,t){return Kt(e,t).split(Zt).join("/")}i(De,"toPosixRelative");async function Xt(e){try{return to().add(await Qn(e,"utf8"))}catch{return null}}i(Xt,"readIgnoreFile");async function ro(e){return Xn(qt(e,".git")).then(()=>!0,()=>!1)}i(ro,"hasGitEntry");function Jt(e,t,r){for(let n=e.length-1;n>=0;n--){let{base:o,rules:s}=e[n],a=s.test(`${De(o,t)}${r?"/":""}`);if(a.ignored||a.unignored)return a.ignored}return!1}i(Jt,"matchesRules");async function Qt(e,t){let r=await Xt(qt(e,".gitignore"));return{kind:"rules",nested:!0,excluded:!1,matchers:r?[...t,{base:e,rules:r}]:t}}i(Qt,"buildRulesContext");async function Se(e){let[t,r]=await Promise.all([Vt(e,["check-ignore","-q","."]),Vt(e,["ls-files","--cached","--others","--exclude-standard","-z"])]);if(t.code!==1||r.code!==0)return Qt(e,[]);let n=new Set,o=new Set;for(let s of r.stdout.split("\0")){let a=s.endsWith("/")?s.slice(0,-1):s;if(a.length!==0){n.add(a);for(let c=a.indexOf("/");c!==-1;c=a.indexOf("/",c+1))o.add(a.slice(0,c))}}return{kind:"git",root:e,entries:n,dirs:o}}i(Se,"resolveScopeContext");function er(e){let t=$e(e.root),r=e.gitignore;if(r===!1)return{isIgnored:i(async()=>!1,"isIgnored")};let n=new Map,o=i(async()=>{if(typeof r!="string"&&!Array.isArray(r))return Se(t);let c=typeof r=="string"?[r]:r.filter(u=>typeof u=="string"),l=[];for(let u of c){let f=await Xt($e(t,u));f&&l.push({base:t,rules:f})}return{kind:"rules",nested:!1,excluded:!1,matchers:l}},"buildRootContext"),s=i(c=>{let l=n.get(c);return l||(l=c===t?o():a(c),n.set(c,l)),l},"contextFor"),a=i(async c=>{let l=await s(Yt(c));return l.kind==="git"?l.entries.has(De(l.root,c))?Se(c):l:!l.nested||l.excluded?l:Jt(l.matchers,c,!0)?{...l,excluded:!0}:await ro(c)?Se(c):Qt(c,l.matchers)},"deriveContext");return{async isIgnored(c,l){let u=$e(c),f=Kt(t,u);if(f.length===0||f===".."||f.startsWith(`..${Zt}`)||eo(f))return!1;let p=await s(Yt(u));if(p.kind==="git"){let y=De(p.root,u);return!(p.entries.has(y)||l&&p.dirs.has(y))}return p.excluded||Jt(p.matchers,u,l)}}}i(er,"createIgnoreFilter");function so(e){return Tt(e)}i(so,"resolveExtensions");var ao=Object.freeze(["node_modules","bower_components","jspm_packages",".pnpm-store",".yarn"]),or=new Set([".git",...ao]),co=Object.freeze(["autoload.php","modules.txt"]);function rr(e,t){return or.has(t)?!0:t==="vendor"&&co.some(r=>no(Fe(e,r)))}i(rr,"isNeverWalked");function Ce(e){return Gt(e.replace(/\\/g,"/").replace(/^\.\//,"").replace(/^\/+/,""))}i(Ce,"normalizeFolderPath");function lo(e){return Array.isArray(e)?e.map(t=>{if(typeof t=="string")return{path:t,recursive:!0};if(t&&typeof t=="object"&&typeof t.path=="string")return{path:t.path,recursive:t.recursive!==!1};throw new TypeError(`Invalid includeFolders entry: ${JSON.stringify(t)} (expected a path string or { path, recursive? })`)}):[]}i(lo,"resolveIncludeFolders");function nr(e,t){let r=t instanceof Error?t.message:String(t);console.warn(`fix-headers: skipped include folder "${e}" (${r})`)}i(nr,"reportSkippedIncludeFolder");function uo(e,t){if(!Array.isArray(t)||t.length===0)return()=>!1;let r=Ne(e),n=[],o=new Set;for(let s of t){if(typeof s!="string")continue;let a=Ce(s);if(a.length!==0){if(a.includes("/")){n.push(Ne(r,a));continue}o.add(a)}}return(s,a)=>{if(o.has(a))return!0;for(let l of n)if(s===l||s.startsWith(`${l}/`))return!0;let c=Ce(tr(r,s));return n.some(l=>{let u=Ce(tr(r,l));return c===u||c.startsWith(`${u}/`)})}}i(uo,"buildExclusionMatcher");async function ve(e){let t=so(e),r=lo(e.includeFolders),n=Array.isArray(e.excludeFolders)?e.excludeFolders:[],o=uo(e.projectRoot,n),s=er({root:e.projectRoot,gitignore:e.gitignore}),a=i(async(d,m)=>rr(d,m)||o(d,m)||await s.isIgnored(d,!0),"shouldSkipDirectory"),c=r.length>0?r.map(d=>({includeFolder:d.path,rootPath:Fe(e.projectRoot,d.path),recursive:d.recursive})):[{includeFolder:".",rootPath:e.projectRoot,recursive:!0}],l=[];for(let d of c){let m=await io(d.rootPath).catch(b=>b);if(m instanceof Error){if(m.code==="ENOENT"){nr(d.includeFolder,m);continue}throw m}if(!m.isDirectory()){nr(d.includeFolder,`path is not a directory: ${d.rootPath}`);continue}let w=await oo(d.rootPath).catch(()=>Ne(d.rootPath));l.push({...d,realRoot:w})}let u=i((d,m)=>{if(d.realRoot===m.realRoot)return d.recursive||!m.recursive;let w=d.realRoot.endsWith(Ae)?d.realRoot:`${d.realRoot}${Ae}`;if(!d.recursive||!m.realRoot.startsWith(w))return!1;let b=d.rootPath;for(let $ of m.realRoot.slice(w.length).split(Ae))if(b=Fe(b,$),rr(b,$)||o(b,$))return!1;return!0},"covers"),f=[...l].sort((d,m)=>d.realRoot.length-m.realRoot.length||Number(m.recursive)-Number(d.recursive)),p=[];for(let d of f)p.some(m=>u(m,d))||p.push(d);let y=[];for(let d of l){if(!p.includes(d))continue;let m=await ke(d.rootPath,{allowedExtensions:t,ignoreFolders:or,shouldSkipDirectory:a,recursive:d.recursive});y.push(...m)}let g=[];for(let d of new Set(y))!o(d,d.split("/").at(-1)||"")&&!await s.isIgnored(d,!1)&&g.push(d);return g}i(ve,"discoverFiles");import{basename as To,dirname as Oo,extname as Ho,resolve as Ie}from"node:path";import{dirname as gr,isAbsolute as ko,join as yr,relative as $o,resolve as xr,sep as So}from"node:path";import{readFile as fo}from"node:fs/promises";import{join as mo}from"node:path";async function po(e){try{return await fo(e,"utf8")}catch{return null}}i(po,"readManifest");async function M(e,t){let r=[];for(let n of t){let o=await po(mo(e,n));o!==null&&r.push({file:n,content:o})}return r.length>0?{dir:e,manifest:r[0].file,files:r}:null}i(M,"detectManifests");function H(e,t){return e.files.find(r=>r.file===t)?.content??null}i(H,"manifestContent");function A(e){return typeof e=="string"&&e.trim().length>0?e.trim():void 0}i(A,"cleanName");function Le(e){if(typeof e!="string")return;let t=e.search(/[<(]/);return A(t===-1?e:e.slice(0,t))}i(Le,"personName");function le(e){try{return JSON.parse(e)}catch{return}}i(le,"parseJsonManifest");function*Me(e,t){let r="";for(let n of e.split(/\r?\n/)){let o=n.trim();if(o.startsWith("[")){let s=o.match(/^\[([^[\]]+)\]/);r=s?s[1].split(".").map(a=>a.trim()).join("."):"";continue}r===t&&(yield o)}}i(Me,"sectionLines");function X(e,t,r){let n=new RegExp(`^${r}\\s*=\\s*(?:"([^"\\\\]*)"|'([^']*)')`);for(let o of Me(e,t)){let s=o.match(n);if(s)return A(s[1]??s[2])}}i(X,"readTomlString");function Re(e,t,r){let n=new RegExp(`^${r}\\s*[=:](.*)$`);for(let o of Me(e,t)){let s=o.match(n);if(s)return A(s[1])}}i(Re,"readIniValue");function ho(e,t,r){let n=new RegExp(`^${r}\\s*=\\s*\\[`),o=null;for(let s of Me(e,t)){if(o!==null){o.push(s);continue}let a=s.match(n);a&&(o=[s.slice(a[0].length)])}return o===null?null:o.join(`
|
|
4
|
+
`)}i(ho,"tomlArrayText");function go(e,t){let r=t;for(;r<e.length;)if(e[r]==="#"){let n=e.indexOf(`
|
|
5
|
+
`,r);r=n===-1?e.length:n+1}else if(/\s/.test(e[r]))r+=1;else break;return r}i(go,"skipTomlSpace");function Q(e,t){let r=ho(e,t,"authors");if(r===null)return;let n=r.slice(go(r,0)),o=n.match(/^(?:"([^"\\\n]*)"|'([^'\n]*)')/);if(o)return Le(o[1]??o[2]);let a=n.match(/^\{([^}\n]*)\}/)?.[1].match(/(?:^|,)\s*name\s*=\s*(?:"([^"\\\n]*)"|'([^'\n]*)')/);return a?A(a[1]??a[2]):void 0}i(Q,"readTomlAuthor");var ir=["go.mod"];function yo(e){let t=e.match(/^\s*module\s+(.+)$/m);if(t)return A(t[1].replace(/\/\/.*$/,"").trim().replace(/^["`](.*)["`]$/,"$1"))}i(yo,"readModulePath");var sr={id:"go",languages:["go"],manifests:ir,detect(e){return M(e,ir)},read(e){return{name:yo(e.files[0].content)}}};var ar=["package.json"];function xo(e){let t=A(e?.name),r=A(e?.publisher),n=typeof e?.engines?.vscode=="string";return t&&r&&n?`${r}.${t}`:t}i(xo,"readPublishedName");function wo(e){if(e!==null&&typeof e=="object"){let t=e;return A(t.company)??A(t.name)}return Le(e)}i(wo,"readAuthorCompany");var cr={id:"node",languages:["node"],manifests:ar,detect(e){return M(e,ar)},read(e){let t=le(e.files[0].content);return{name:xo(t),company:wo(t?.author)}}};var lr=["composer.json"],ur={id:"php",languages:["php"],manifests:lr,detect(e){return M(e,lr)},read(e){let t=le(e.files[0].content),r=t?.authors;return{name:A(t?.name),company:Array.isArray(r)?A(r[0]?.name):void 0}}};var dr=["pyproject.toml","setup.cfg","setup.py"];function fr(e,t){let r=e.indexOf("setup(");if(r===-1)return;let n=e.slice(r).match(new RegExp(`\\b${t}\\s*=\\s*(["'])([^"'\\n]+)\\1`));return n&&n[2].trim()||void 0}i(fr,"readSetupPyArgument");function bo(e){let t=H(e,"pyproject.toml"),r=H(e,"setup.cfg"),n=H(e,"setup.py");return(t===null?void 0:X(t,"project","name")??X(t,"tool.poetry","name"))??(r===null?void 0:Re(r,"metadata","name"))??(n===null?void 0:fr(n,"name"))}i(bo,"readPythonName");function Eo(e){let t=H(e,"pyproject.toml"),r=H(e,"setup.cfg"),n=H(e,"setup.py");return(t===null?void 0:Q(t,"project")??Q(t,"tool.poetry"))??(r===null?void 0:Re(r,"metadata","author"))??(n===null?void 0:fr(n,"author"))}i(Eo,"readPythonCompany");var mr={id:"python",languages:["python"],manifests:dr,detect(e){return M(e,dr)},read(e){return{name:bo(e),company:Eo(e)}}};var pr=["Cargo.toml"],hr={id:"rust",languages:["rust"],manifests:pr,detect(e){return M(e,pr)},read(e){let t=e.files[0].content;return{name:X(t,"package","name"),company:Q(t,"package")}}};var Do=[cr,mr,ur,hr,sr],wr=["name","company"];async function je(e,t,r){let o=(await Promise.all(t.map(async a=>({driver:a,detection:await a.detect(e)})))).filter(a=>a.detection!==null),s=o.filter(a=>typeof r=="string"&&a.driver.languages.includes(r));return[...s,...o.filter(a=>!s.includes(a))]}i(je,"claimFolder");function Ao(e,t){let r=$o(t,e);return r!==""&&r!==".."&&!r.startsWith(`..${So}`)&&!ko(r)}i(Ao,"isStrictlyInside");async function br(e,t={}){let r=Array.isArray(t.drivers)?t.drivers:Do,n=typeof t.scanRoot=="string"?xr(t.scanRoot):null,o=xr(e),s=await je(o,r,t.language);for(;s.length===0;){if(await Ee(yr(o,".git")))return{root:o,marker:".git",drivers:[],fields:{},sources:{}};let f=gr(o);if(f===o)return null;o=f,s=await je(o,r,t.language)}let a={},c={},l=o,u=s;for(;;){for(let{driver:p,detection:y}of u){let g=p.read(y);for(let d of wr)a[d]===void 0&&g[d]!==void 0&&(a[d]=g[d],c[d]={driver:p.id,manifest:y.manifest,dir:l})}if(wr.every(p=>a[p]!==void 0)||n===null||!Ao(l,n)||await Ee(yr(l,".git")))break;l=gr(l),u=await je(l,r,t.language)}return{root:o,marker:s[0].detection.manifest,drivers:s.map(f=>f.driver.id),fields:a,sources:c}}i(br,"resolveManifestProject");import{execFile as Co}from"node:child_process";import{basename as Fo,dirname as No}from"node:path";import{promisify as vo}from"node:util";var Pe=vo(Co);async function v(e,t){try{let{stdout:r}=await Pe("git",t,{cwd:e}),n=r.trim();return n.length>0?n:null}catch{return null}}i(v,"runGit");function Er(e,t){let r=0;for(let n=t-1;n>=0&&e[n]==="\\";n--)r++;return r%2===1}i(Er,"isEscaped");function Lo(e){let t=e.trim();if(!t.endsWith(")")||Er(t,t.length-1))return t;let r=0;for(let n=t.length-1;n>=0;n--){let o=t[n];if(!(o!=="("&&o!==")"||Er(t,n))&&(r+=o===")"?1:-1,r===0))return t.slice(0,n).trim()}return t}i(Lo,"stripUidComment");function Mo(e){let t=e.trim();if(t.length===0)return{authorName:null,authorEmail:null};let r=t.match(/<([^>\n]+)>\s*$/),n=r?.[1]?.trim()||null,o=(r?t.slice(0,r.index):t).trim();return{authorName:Lo(o)||o||null,authorEmail:n}}i(Mo,"parseSignerUid");async function Ro(e,t){try{let{stdout:r}=await Pe(e,t),n=r.trim();return n.length>0?n:null}catch{return null}}i(Ro,"runProgram");function jo(e){return e.replace(/\\x([0-9a-fA-F]{2})/g,(t,r)=>String.fromCharCode(Number.parseInt(r,16)))}i(jo,"decodeColonField");async function Po(e){let t=await v(e,["config","--get","gpg.format"]);if(t!==null&&t!=="openpgp")return null;let r=await v(e,["config","--get","user.signingkey"]);if(!r)return null;let n=await v(e,["config","--get","gpg.openpgp.program"])||await v(e,["config","--get","gpg.program"])||"gpg",o=await Ro(n,["--batch","--with-colons","--list-keys",r]);if(!o)return null;for(let s of o.split(`
|
|
6
|
+
`)){let a=s.split(":");if(a[0]==="uid"&&a[1]!=="r"&&a[1]!=="e"&&a[9])return jo(a[9])}return null}i(Po,"readSigningKeyUid");async function kr(e,t={}){let r=await v(e,["config","--get","user.name"]),n=await v(e,["config","--get","user.email"]);if(t.useGpgSignerAuthor===!0){let o=await Po(e)||await v(e,["log","-1","--format=%GS"]),s=Mo(o||"");r=s.authorName||r,n=n||s.authorEmail}if(!r||!n){let o=await v(e,["log","-1","--format=%an|%ae"]);if(o){let[s,a]=o.split("|");r=r||s||null,n=n||a||null}}return{authorName:r,authorEmail:n}}i(kr,"detectGitAuthor");function $r(e){return e.replace(/z$/i,"+00:00")}i($r,"canonicalGitDate");async function Sr(e,t){let r=await v(e,["log","--follow","--format=%aI|%at","--reverse","--",t]);if(!r)return null;let n=r.split(`
|
|
7
|
+
`)[0],[o,s]=n.split("|");if(!o||!s)return null;let a=Number.parseInt(s,10);return Number.isNaN(a)?null:{date:$r(o),timestamp:a}}i(Sr,"getGitCreationDate");async function Dr(e,t){let r=await v(e,["log","-1","--format=%aI|%at","--",t]);if(!r)return null;let[n,o]=r.split("|");if(!n||!o)return null;let s=Number.parseInt(o,10);return Number.isNaN(s)?null:{date:$r(n),timestamp:s}}i(Dr,"getGitLastModifiedDate");var Io=256*1024*1024;async function Ar(e){let t=No(e);if(await v(t,["rev-parse","--is-inside-work-tree"])!=="true")return{state:"no-git",content:null};try{let{stdout:r}=await Pe("git",["show",`HEAD:./${Fo(e)}`],{cwd:t,encoding:"utf8",maxBuffer:Io});return{state:"tracked",content:r}}catch{return{state:"untracked",content:null}}}i(Ar,"readGitHeadFile");function _o(e){return To(e)||"project"}i(_o,"folderName");function Bo(e,t){if(typeof t!="string")return e;let r=t.trim();return r.length===0||Wt(e)?e:`${e} <${r}>`}i(Bo,"formatAuthorNameWithCompany");async function Uo(e,t={}){let r=Array.isArray(t.detectors)?t.detectors:T(t),n=typeof t.preferredExtension=="string"?t.preferredExtension.trim().toLowerCase():"",o=n.length>0?r.find(u=>u.extensions.includes(n)):void 0,s=await br(e,{drivers:t.drivers,language:o?.id,scanRoot:t.scanRoot}),a=s?s.root:Ie(e),c=s?.sources.name,l=s?.sources.company;return{language:o?.id??s?.drivers[0]??"unknown",rootDir:a,marker:s?s.marker:null,projectName:s?.fields.name??_o(a),projectNameSource:c?{from:"manifest",...c}:{from:"folder",dir:a},companyName:s?.fields.company??null,companyNameSource:l?{from:"manifest",...l}:{from:"none"},drivers:s?s.drivers:[]}}i(Uo,"detectProjectFromMarkers");async function Te(e={}){let t=e.targetFilePath||e.cwd||process.cwd(),r=Ie(t),n=T(e),o=e.targetFilePath?Oo(r):r,s=e.targetFilePath?Ho(r).toLowerCase():"",a=Ie(e.projectRoot||e.cwd||process.cwd()),c=await Uo(o,{detectors:n,preferredExtension:s,scanRoot:a}),l=await kr(c.rootDir,{useGpgSignerAuthor:e.useGpgSignerAuthor===!0}),u=e.authorName||l.authorName||"Unknown Author",f=typeof e.companyName=="string"?e.companyName.trim():"";return{projectName:e.projectName||c.projectName,projectNameSource:e.projectName?{from:"option"}:c.projectNameSource,language:e.language||c.language,projectRoot:e.projectRoot||c.rootDir,marker:e.marker===void 0?c.marker:e.marker,authorName:Bo(u,e.company),authorEmail:e.authorEmail||l.authorEmail||"unknown@example.com",companyName:f||c.companyName,companyNameSource:f?{from:"option"}:c.companyNameSource,copyrightStartYear:Number.isInteger(e.copyrightStartYear)?Number(e.copyrightStartYear):null}}i(Te,"resolveProjectMetadata");function zo(e){return Oe({year:e.getFullYear(),month:e.getMonth()+1,day:e.getDate(),hour:e.getHours(),minute:e.getMinutes(),second:e.getSeconds(),offsetMinutes:-e.getTimezoneOffset()})}i(zo,"formatDateWithTimezone");function Oe(e){return`${vr(e," ")} ${Lr(e.offsetMinutes)}`}i(Oe,"formatSpaceDate");function Fr(e){if(typeof e!="string")throw new Error(`timezone must be an IANA time zone name string, such as "America/Los_Angeles" or "UTC" (got ${typeof e})`);try{Nr(e)}catch(t){throw new Error(`Unknown time zone "${e}": expected an IANA time zone name, such as "America/Los_Angeles" or "UTC"`,{cause:t})}return e}i(Fr,"assertTimeZone");var Cr=new Map;function Nr(e){let t=Cr.get(e);return t||(t=new Intl.DateTimeFormat("en-US",{timeZone:e,hourCycle:"h23",year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"}),Cr.set(e,t)),t}i(Nr,"getZoneFormatter");function He(e,t){let r={};for(let o of Nr(t).formatToParts(new Date(e*1e3)))r[o.type]=Number(o.value);let n=Date.UTC(r.year,r.month-1,r.day,r.hour,r.minute,r.second)/1e3;return{year:r.year,month:r.month,day:r.day,hour:r.hour,minute:r.minute,second:r.second,offsetMinutes:(n-e)/60}}i(He,"toZonedDateParts");function vr(e,t){let r=i(n=>String(n).padStart(2,"0"),"pad");return`${String(e.year).padStart(4,"0")}-${r(e.month)}-${r(e.day)}${t}${r(e.hour)}:${r(e.minute)}:${r(e.second)}`}i(vr,"formatWallClock");function Lr(e){let t=i(n=>String(n).padStart(2,"0"),"pad"),r=Math.abs(e);return`${e>=0?"+":"-"}${t(Math.floor(r/60))}:${t(r%60)}`}i(Lr,"formatOffset");function ue(e=new Date){return{date:zo(e),timestamp:Math.floor(e.getTime()/1e3)}}i(ue,"toDatePayload");var Wo=/^(\d{4})-(\d{2})-(\d{2})(?:T|\s+)(\d{2}):(\d{2}):(\d{2})(?:\.\d+)?\s*(?:(Z)|([+-])(\d{2}):?(\d{2}))$/i;function _(e){let t=Wo.exec(e.trim());if(!t)return null;let[r,n,o,s,a,c]=t.slice(1,7).map(Number),l=t[7]?0:Number(t[9])*60+Number(t[10]),u=t[8]==="-"?-l:l,f=new Date(Date.UTC(r,n-1,o,s,a,c));return!(f.getUTCFullYear()===r&&f.getUTCMonth()===n-1&&f.getUTCDate()===o&&f.getUTCHours()===s&&f.getUTCMinutes()===a&&f.getUTCSeconds()===c)||Number(t[10]??0)>59?null:{year:r,month:n,day:o,hour:s,minute:a,second:c,offsetMinutes:u,timestamp:Math.floor(f.getTime()/1e3)-u*60}}i(_,"parseHeaderDate");function _e(e){return`${vr(e,"T")}${Lr(e.offsetMinutes)}`}i(_e,"formatIsoDate");var Go={"git-created":"git first commit","filesystem-created":"filesystem creation time"};function Mr(e,t){let r=e.match(new RegExp(`${t}:[^\\S\\n]*(.*)$`,"m"));return r?r[1].trim():null}i(Mr,"readHeaderField");function Be(e){let t=null;for(let{source:r,payload:n}of e)n&&(!t||n.timestamp<t.payload.timestamp)&&(t={source:r,payload:n});return t}i(Be,"pickOldestDate");function jr({existing:e,gitCreated:t,filesystemCreated:r,fixCreatedDate:n=!1}){let o=[{source:"git-created",payload:t},{source:"filesystem-created",payload:r}];if(!e)return Be(o);if(!n)return{source:"existing-header",payload:e};let s=_(e.date)?e:null;return Be([{source:"existing-header",payload:s},...o])}i(jr,"resolveCreatedDate");function Pr(e,t=null){if(t)return He(e.timestamp,t).year;let r=_(e.date);return r?r.year:new Date(e.timestamp*1e3).getFullYear()}i(Pr,"dateYear");function Rr(e,t,r,n){let o=e.match(/^(.+?)\s*\((\d+)\)$/),s=o?_(o[1]):null;if(!o||!s)return n.push({check:`${r}-format`,field:t,advisory:!1,value:e,message:`${t} value "${e}" is not a "<datetime> (<epoch>)" pair with a recognised datetime`}),null;let a=Number.parseInt(o[2],10);return a!==s.timestamp&&n.push({check:`${r}-epoch`,field:t,advisory:!1,value:e,expected:`${o[1]} (${s.timestamp})`,message:`${t} epoch ${a} does not match ${o[1]} (expected ${s.timestamp})`}),{text:o[1],timestamp:s.timestamp}}i(Rr,"checkDateValue");function Ir(e,t={},r={}){let n=[],o=Mr(e,"@Date"),s=o===null?null:Rr(o,"@Date","created",n),a=Be([{source:"git-created",payload:t.gitCreated},{source:"filesystem-created",payload:t.filesystemCreated}]);if(s&&a&&s.timestamp>a.payload.timestamp){let f=Go[a.source];n.push({check:"created-newer-than-source",field:"@Date",advisory:r.strictCreatedDate!==!0,value:o,expected:`${a.payload.date} (${a.payload.timestamp})`,source:a.source,message:`@Date ${s.text} is later than the ${f} ${a.payload.date} (${a.payload.timestamp})`})}let c=Mr(e,"@Last modified time"),l=c===null?null:Rr(c,"@Last modified time","modified",n),u=t.gitLastModified;return l&&u&&l.timestamp!==u.timestamp&&n.push({check:"modified-git",field:"@Last modified time",advisory:!0,value:c,expected:`${u.date} (${u.timestamp})`,message:`@Last modified time ${l.text} does not match the git last commit ${u.date} (${u.timestamp})`}),n}i(Ir,"checkHeaderDates");function Ue(e){if(!e)return null;let t=_(e.date);return t&&t.timestamp!==e.timestamp?{date:e.date,timestamp:t.timestamp}:e}i(Ue,"repairDateEpoch");function Tr(e){let t=_(e.date);return t?{date:_e(t),timestamp:t.timestamp}:e}i(Tr,"normalizeDatePayload");function Or(e,t){let r=_(e.date);if(!r)return e;let n=He(r.timestamp,t);return n.offsetMinutes===r.offsetMinutes||!Number.isInteger(n.offsetMinutes)?e:{date:/^\d{4}-\d{2}-\d{2}T/i.test(e.date.trim())?_e(n):Oe(n),timestamp:r.timestamp}}i(Or,"convertDatePayload");import{relative as Vo}from"node:path";import{extname as Yo}from"node:path";function B(e,t={}){let r=Yo(e).toLowerCase(),n=O(t.spacing,"spacing",Z);return r.length===0?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */",spacing:n}:{...Ht(e,t),spacing:n}}i(B,"getHeaderSyntaxForFile");function Hr(e,t){let r=e.spacing??Z;if(e.kind==="line"){let c=e.linePrefix||"#",l=typeof e.lineSeparator=="string"?e.lineSeparator:" ",u=Array.from({length:r},()=>c);return[...u,...t.map(f=>`${c}${l}${f}`),...u].join(`
|
|
8
8
|
`)}let n=e.blockStart||(e.kind==="html"?"<!--":"/**"),o=e.blockLinePrefix||(e.kind==="html"?" ":" * "),s=e.blockEnd||(e.kind==="html"?"-->":" */"),a=Array.from({length:r},()=>o.trimEnd());return[n,...a,...t.map(c=>`${o}${c}`),...a,s].join(`
|
|
9
|
-
`)}i(Hr,"renderHeaderLines");function _r(e){let t=`/${
|
|
9
|
+
`)}i(Hr,"renderHeaderLines");function _r(e){let t=`/${Vo(e.projectRoot,e.absoluteFilePath).replace(/\\/g,"/")}`,r=B(e.absoluteFilePath,e.syntaxOptions||{language:e.language}),n=e.createdByName||e.authorName,o=e.createdByEmail||e.authorEmail,s=e.lastModifiedByName||e.authorName,a=e.lastModifiedByEmail||e.authorEmail,c=typeof e.companyName=="string"?e.companyName.trim():"",l=c.length>0?`${c} `:"",u=[`@Project: ${e.projectName}`,`@Filename: ${t}`,`@Date: ${e.createdAt.date} (${e.createdAt.timestamp})`,`@Author: ${n}`,`@Email: <${o}>`,"-----",`@Last modified by: ${s} (${a})`,`@Last modified time: ${e.lastModifiedAt.date} (${e.lastModifiedAt.timestamp})`,"-----",`@Copyright: Copyright (c) ${e.copyrightStartYear}-${e.currentYear} ${l}All rights reserved.`];return Hr(r,u)}i(_r,"buildHeader");var Jo=Object.freeze(["projectName","filename","createdAt","authorName","authorEmail","lastModifiedByName","lastModifiedByEmail","lastModifiedAt","copyrightStartYear","copyrightEndYear","companyName"]);function I(e,t){let r=e.match(new RegExp(`@${t}:[ \\t]*(.*)$`,"m")),n=r?r[1].trim():"";return n.length>0?n:null}i(I,"readTag");function qo(e){if(e===null)return{name:null,email:null};if(!e.endsWith(")"))return{name:e,email:null};let t=e.slice(0,-1),r=t.indexOf("(",t.lastIndexOf(")")+1);return r===-1?{name:e,email:null}:{name:t.slice(0,r).trimEnd()||null,email:t.slice(r+1)||null}}i(qo,"splitLastModifiedBy");function Ko(e){let t={startYear:null,endYear:null,companyName:null},r=e?.match(/^Copyright\s+\(c\)\s+(\d{4})/i);if(!r)return t;let n=e.slice(r[0].length),o=n.match(/^\s*-\s*(\d{4})/);o&&(n=n.slice(o[0].length));let s=n.toLowerCase(),a=s.endsWith("all rights reserved.")?20:s.endsWith("all rights reserved")?19:0;return a===0||!/^\s/.test(n)?t:{startYear:r[1],endYear:o?o[1]:null,companyName:n.slice(0,-a).trim()||null}}i(Ko,"splitCopyright");function Br(e){let t=qo(I(e,"Last modified by")),r=Ko(I(e,"Copyright")),n=I(e,"Email");return{projectName:I(e,"Project"),filename:I(e,"Filename"),createdAt:I(e,"Date"),authorName:I(e,"Author"),authorEmail:n===null?null:n.replace(/^<(.*)>$/,"$1"),lastModifiedByName:t.name,lastModifiedByEmail:t.email,lastModifiedAt:I(e,"Last modified time"),copyrightStartYear:r.startYear,copyrightEndYear:r.endYear,companyName:r.companyName}}i(Br,"parseHeaderFields");function Ur(e,t){let r=Br(e??""),n=Br(t);return Jo.filter(o=>r[o]!==n[o]).map(o=>({field:o,previous:r[o],detected:n[o]}))}i(Ur,"compareHeaderFields");function ee(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}i(ee,"escapeRegex");function ze(e,t,r={}){let n=t.startsWith("\uFEFF")?"\uFEFF":"",o=t.slice(n.length),s=`${n}${ae(e,o,r)}`;return{prefix:s,body:t.slice(s.length)}}i(ze,"splitPreservedPrefix");function de(e){let t=e.indexOf(`
|
|
10
10
|
`);return t===-1?null:t>0&&e[t-1]==="\r"?`\r
|
|
11
11
|
`:`
|
|
12
|
-
`}i(de,"lineEnding");function W(e,t){if(t.kind==="html"){let n=ee(t.blockStart||"<!--"),o=ee(t.blockEnd||"-->");return e.match(new RegExp(`^${n}[\\s\\S]*?${o}(?:\\r?\\n)*`))}if(t.kind==="line"){let n=ee(t.linePrefix||"#");return e.match(new RegExp(`^(?:${n}[^\\n]*\\n)+(?:\\r?\\n)*`))}let r=ee((t.blockEnd||" */").trim());return e.match(new RegExp(`^/\\*[\\s\\S]*?${r}(?:\\r?\\n)*`))}i(W,"matchHeaderSegment");var Gr=/^@(Project|Filename|Date|Author|Email|Last modified by|Last modified time|Copyright):/,
|
|
12
|
+
`}i(de,"lineEnding");function W(e,t){if(t.kind==="html"){let n=ee(t.blockStart||"<!--"),o=ee(t.blockEnd||"-->");return e.match(new RegExp(`^${n}[\\s\\S]*?${o}(?:\\r?\\n)*`))}if(t.kind==="line"){let n=ee(t.linePrefix||"#");return e.match(new RegExp(`^(?:${n}[^\\n]*\\n)+(?:\\r?\\n)*`))}let r=ee((t.blockEnd||" */").trim());return e.match(new RegExp(`^/\\*[\\s\\S]*?${r}(?:\\r?\\n)*`))}i(W,"matchHeaderSegment");var Gr=/^@(Project|Filename|Date|Author|Email|Last modified by|Last modified time|Copyright):/,Zo="Moved out of the file header by fix-headers:";function Yr(e){return e.some(t=>/^@(?:Project|Filename):/.test(t.text))}i(Yr,"isFileHeader");function We(e,t){let r=e.replace(/(?:\r?\n)+$/,"");if(t.kind==="line"){let f=new RegExp(`^${ee(t.linePrefix||"#")}[ \\t]*`);return r.split(`
|
|
13
13
|
`).map(p=>{let y=p.replace(/\r$/,"");return{raw:y,text:y.replace(f,"").trim()}})}let n=t.kind==="html",o=n?r.replace(/^<!--/,"").replace(/--!?>\s*$/,""):r.replace(/^\/\*+/,"").replace(/\*+\/\s*$/,""),s=t.blockLinePrefix||(n?" ":" * "),a=n?/^\s*/:/^\s*\*?[ \t]*/,c=o.split(`
|
|
14
|
-
`).map((f,p)=>({raw:p===0&&f.trim()!==""?`${s}${f.trim()}`:f.trimEnd(),text:(p===0?f:f.replace(a,"")).trim()})),l=c[0].raw===""?1:0,u=c.length>l&&c[c.length-1].raw.trim()===""?c.length-1:c.length;return c.slice(l,u)}i(We,"segmentLines");function
|
|
14
|
+
`).map((f,p)=>({raw:p===0&&f.trim()!==""?`${s}${f.trim()}`:f.trimEnd(),text:(p===0?f:f.replace(a,"")).trim()})),l=c[0].raw===""?1:0,u=c.length>l&&c[c.length-1].raw.trim()===""?c.length-1:c.length;return c.slice(l,u)}i(We,"segmentLines");function Xo(e,t){let r=e.map(o=>{let s=o.text.match(Gr);return o.text===""?"blank":s&&s[1]==="Copyright"?t.copyright?"copyright":(t.copyright=!0,"field"):s?"field":/^-{3,}$/.test(o.text)?"dash":"text"}),n=i((o,s)=>{for(let a=o+s;a>=0&&a<r.length;a+=s)if(r[a]!=="blank"&&r[a]!=="dash")return r[a]==="copyright"?"field":r[a]},"neighbour");return r.map((o,s)=>o==="dash"?n(s,-1)==="field"||n(s,1)==="field"?"separator":"text":o)}i(Xo,"classifyLines");function Qo(e,t="",r={}){let n=B(t,r),o=[],s=[],a={copyright:!1},c=e,l=W(c,n),u=!0;for(;l&&l[0].length>0;){let m=We(l[0],n),w=Xo(m,a),b=m.findIndex($=>$.text!=="");!u&&b!==-1&&m[b].text===Zo&&(w[b]="separator"),m.forEach(($,C)=>{w[C]==="copyright"&&s.push($.text.replace(Gr,"").trim()),o.push({raw:$.raw,kind:w[C]})}),c=c.slice(l[0].length),l=W(c,n),u=!1}let f=o.findIndex(m=>m.kind==="text");if(f===-1)return{foreign:[],copyrights:s};let p=o.map(m=>m.kind).lastIndexOf("text"),y=[],g=[],d=!1;for(let m of o.slice(f,p+1))m.kind==="text"?(y.push(...d?[]:g,m.raw),g=[],d=!1):m.kind==="blank"?g.push(m.raw):d=!0;return{foreign:y,copyrights:s}}i(Qo,"splitHeaderText");function ei(e,t,r){let n=t.kind==="html";return t.kind==="line"?e.join(r):[t.blockStart||(n?"<!--":"/**"),...e,t.blockEnd||(n?"-->":" */")].join(r)}i(ei,"renderForeignBlock");function ti(e,t,r){let n=e.split(`
|
|
15
15
|
`),o=r.kind==="html",s=r.kind==="line"?r.linePrefix||"#":(r.blockLinePrefix||(o?" ":" * ")).trimEnd(),a=Math.min(n.length-1,(r.spacing??1)+(r.kind==="line"?0:1)),c=n.length-a;return[...n.slice(0,c),s,...t,...n.slice(c)].join(`
|
|
16
|
-
`)}i(
|
|
17
|
-
`.includes(t[a-1]);)a-=1;return t.slice(0,a).split(/\s+/).filter(Boolean).join(" ").toLowerCase()}i(zr,"copyrightHolder");function
|
|
16
|
+
`)}i(ti,"appendToHeader");function zr(e){let t=e.trim(),r=t.match(/^copyright\b/i);t=r?t.slice(r[0].length).trimStart():t;for(let c=t.match(/^(?:\(c\)|©)/i);c;c=t.match(/^(?:\(c\)|©)/i))t=t.slice(c[0].length).trimStart();let n=t.match(/^\d{4}(?:\s*[-–,]\s*\d{4})*/);t=n?t.slice(n[0].length):t,t=t.trimEnd();let o=t.toLowerCase(),s=o.endsWith("all rights reserved.")?20:o.endsWith("all rights reserved")?19:0;t=t.slice(0,t.length-s);let a=t.length;for(;a>0&&`.,; \r
|
|
17
|
+
`.includes(t[a-1]);)a-=1;return t.slice(0,a).split(/\s+/).filter(Boolean).join(" ").toLowerCase()}i(zr,"copyrightHolder");function ri(e,t){let r=e.split(`
|
|
18
18
|
`),n=r.findIndex(c=>c.includes("@Copyright:")),o=r.map(c=>/@[A-Za-z][A-Za-z ]*:/.test(c)).lastIndexOf(!0),s=n!==-1?n:o;if(t.length===0||s===-1)return e;let a=r[s].slice(0,r[s].indexOf("@"));return[...r.slice(0,s+1),...t.map(c=>`${a}@Copyright: ${c}`),...r.slice(s+1)].join(`
|
|
19
|
-
`)}i(
|
|
19
|
+
`)}i(ri,"insertCopyrights");function Wr(e,t){let r=0,n=W(e,t);for(;n&&n[0].length>0&&Yr(We(n[0],t));)r+=n[0].length,n=W(e.slice(r),t);return r}i(Wr,"leadingHeadersLength");function fe(e,t="",r={}){let n=e.startsWith("\uFEFF")?"\uFEFF":"",o=e.slice(n.length),s=ae(t,o,r),a=B(t,r),c=s.length,l=Wr(o.slice(c),a);if(l===0)return e;let u=n===""&&c===0&&o.startsWith("\uFEFF",l);u&&(n="\uFEFF",o=`${o.slice(0,l)}${o.slice(l+1)}`,l+=Wr(o.slice(l),a));let f=o.slice(c,c+l),p=o.slice(c+l),y=ae(t,`${s}${p}`,r),g=y.length>s.length?y.slice(s.length):"";if(g===""&&!u)return e;let d=g===""||g.endsWith(`
|
|
20
20
|
`)?g:`${g}${de(e)??`
|
|
21
21
|
`}`;return`${n}${s}${d}${f}${p.slice(g.length)}`}i(fe,"restoreTopLines");function me(e,t="",r={}){let{prefix:n,body:o}=ze(t,e,r),s=o.split(`
|
|
22
22
|
`).slice(0,Ut).join(`
|
|
23
23
|
`),a=B(t,r);if(!W(s,a))return null;let l=0,u=0;for(;;){let f=s.slice(l),p=W(f,a);if(!p||!Yr(We(p[0],a)))break;l+=p[0].length,u=l}return u===0?null:{start:n.length,end:n.length+u}}i(me,"findProjectHeader");function pe(e,t,r="",n={}){let o=fe(e,r,n),s=me(o,r,n),a=B(r,n),c=O(n.margin,"margin",ce),l=a.kind==="line"?Math.max(1,c):c,u=i((k,S)=>S===`
|
|
24
24
|
`?k:k.replace(/\r?\n/g,S),"withEol");if(!s){let{prefix:k,body:S}=ze(r,o,n),D=de(o)??`
|
|
25
25
|
`,j=u(t,D),V=S.replace(/^(?:\r?\n)+/,""),h=k.replace(/^\uFEFF/,"")!==""&&!k.endsWith(`
|
|
26
|
-
`)?D:"",P=`${k}${h}${V.trim()===""?`${j}${D}`:`${j}${D.repeat(l+1)}${V}`}`;return{nextContent:P,changed:P!==e,header:j,written:j,extraCopyrights:[]}}let f=o.slice(s.start,s.end),{foreign:p,copyrights:y}=
|
|
26
|
+
`)?D:"",P=`${k}${h}${V.trim()===""?`${j}${D}`:`${j}${D.repeat(l+1)}${V}`}`;return{nextContent:P,changed:P!==e,header:j,written:j,extraCopyrights:[]}}let f=o.slice(s.start,s.end),{foreign:p,copyrights:y}=Qo(f,r,n),g=t.split(`
|
|
27
27
|
`).find(k=>k.includes("@Copyright:")),d=new Set(g===void 0?[]:[zr(g.slice(g.indexOf("@Copyright:")+11))]),m=[];for(let k of y){let S=zr(k);d.has(S)||(d.add(S),m.push(k))}let w=de(o.slice(s.end))??de(f)??`
|
|
28
|
-
`,b=w.repeat(l+1),$=n.strictHeaderBlock!==!1,C=
|
|
28
|
+
`,b=w.repeat(l+1),$=n.strictHeaderBlock!==!1,C=ri(t,m),R=u(p.length>0&&!$?ti(C,p,a):C,w),E=p.length>0&&$?ei(p,a,w):"",U=o.slice(s.end).replace(/^(?:\r?\n)+/,""),G=E===""?U:`${E}${U.trim()===""?w:`${b}${U}`}`,Y=`${o.slice(0,s.start)}${G.trim()===""?`${R}${w}`:`${R}${b}${G}`}`,x=`${R}${E===""?"":`${b}${E}`}`;return{nextContent:Y,changed:Y!==e,header:R,written:x,extraCopyrights:m}}i(pe,"replaceOrInsertHeader");function Ge(e,t="",r={}){let n=fe(e,t,r),o=me(n,t,r);if(o){let l=n.slice(0,o.start),f=pe(n,"",t,{...r,strictHeaderBlock:!0}).nextContent.slice(l.length).replace(/^(?:\r?\n)+/,"");return`${l}${f.trim()===""?"":f}`}let{prefix:s,body:a}=ze(t,n,r),c=a.replace(/^(?:\r?\n)+/,"");return`${s}${c.trim()===""?"":c}`}i(Ge,"extractHeaderlessBody");function ni(e,t){let r=e.length,n=t.length,o=Array.from({length:r+1},()=>new Array(n+1).fill(0));for(let l=r-1;l>=0;l-=1)for(let u=n-1;u>=0;u-=1)o[l][u]=e[l]===t[u]?o[l+1][u+1]+1:Math.max(o[l+1][u],o[l][u+1]);let s=[],a=0,c=0;for(;a<r&&c<n;)e[a]===t[c]?(s.push({type:" ",line:e[a]}),a+=1,c+=1):o[a+1][c]>=o[a][c+1]?(s.push({type:"-",line:e[a]}),a+=1):(s.push({type:"+",line:t[c]}),c+=1);for(;a<r;a+=1)s.push({type:"-",line:e[a]});for(;c<n;c+=1)s.push({type:"+",line:t[c]});return s}i(ni,"diffLines");function Vr(e,t){return`${t===0?e:e+1},${t}`}i(Vr,"formatRange");function Jr(e,t,r={}){let n=e===null?[]:e.split(`
|
|
29
29
|
`),o=t.split(`
|
|
30
|
-
`),s=
|
|
31
|
-
`)}i(Jr,"createUnifiedDiff");function
|
|
32
|
-
`).length-1;re.sample={previousValue:N,newValue:z,diff:Jr(N,z,{fromFile:`a/${K}`,toFile:`b/${K}`,lineOffset:
|
|
30
|
+
`),s=ni(n,o),a=Math.max(0,r.context??3),c=r.lineOffset??0,l=[];if(s.forEach((y,g)=>{if(y.type===" ")return;let d=l[l.length-1];d&&g-d.last<=a*2+1?d.last=g:l.push({first:g,last:g})}),l.length===0)return"";let u=r.fromFile??"a",f=r.toFile??"b",p=[`--- ${e===null?"/dev/null":u}`,`+++ ${f}`];for(let y of l){let g=Math.max(0,y.first-a),d=Math.min(s.length,y.last+a+1),m=s.slice(0,g),w=s.slice(g,d),b=m.filter(E=>E.type!=="+").length+c,$=m.filter(E=>E.type!=="-").length+c,C=w.filter(E=>E.type!=="+").length,R=w.filter(E=>E.type!=="-").length;p.push(`@@ -${Vr(b,C)} +${Vr($,R)} @@`);for(let E of w)p.push(`${E.type}${E.line}`)}return p.join(`
|
|
31
|
+
`)}i(Jr,"createUnifiedDiff");function ai(e){return mt(e,"configFile")}i(ai,"resolveRuntimeOptions");function ci(e){if(e==null)return[];let t=Array.isArray(e)?e:[e];if(t.some(r=>typeof r!="string"))throw new Error(`input must be a path or an array of paths, got ${JSON.stringify(e)}`);return t.filter(r=>r.trim().length>0)}i(ci,"resolveInputs");function li(e){let t=e.match(/@Author:\s*(.+)$/m),r=e.match(/@Email:\s*<([^>\n]+)>/m);return{authorName:t?.[1]?.trim(),authorEmail:r?.[1]?.trim()}}i(li,"extractHeaderAuthorIdentity");function ui(e){let t=e.match(/@Last modified by:\s*(.+?)\s*\(([^)\n]+)\)\s*$/m);return{authorName:t?.[1]?.trim(),authorEmail:t?.[2]?.trim()}}i(ui,"extractHeaderLastModifiedIdentity");function di(e){let t=e.match(/@Date:\s*(.+?)\s*\((\d+)\)$/m);if(!t||!t[1]||!t[2])return null;let r=Number.parseInt(t[2],10);return Number.isNaN(r)?null:{date:t[1].trim(),timestamp:r}}i(di,"extractHeaderCreatedAt");function fi(e){let t=e.match(/@Last modified time:\s*(.+?)\s*\((\d+)\)$/m);if(!t||!t[1]||!t[2])return null;let r=Number.parseInt(t[2],10);return Number.isNaN(r)?null:{date:t[1].trim(),timestamp:r}}i(fi,"extractHeaderLastModifiedAt");async function mi(e,t,r){let n=await Ar(t);return n.state!=="tracked"?{edited:n.state==="untracked",state:n.state}:{edited:Ge(n.content,t,r)!==Ge(e,t,r),state:"tracked"}}i(mi,"detectContentEdit");async function Kr(e={}){let t=await ai(e),r=t.timezone===void 0||t.timezone===null?null:Fr(t.timezone),n=t.convertTimezone===!0;if(n&&!r)throw new Error("convertTimezone requires timezone: set timezone (CLI --timezone <name>) to the IANA zone to convert header dates into");let o=It(t.forcedDetectors),s=qr(t.projectRoot||t.cwd||process.cwd()),a=await Te({...t,cwd:s});O(t.spacing,"spacing",Z),O(t.margin,"margin",ce);let c=t.check===!0,l=c||t.dryRun===!0,u=t.fixCreatedDate===!0,f=i(x=>x,"keepDate"),p=t.normalizeDateFormat===!0?Tr:f,y=r?x=>Or(x,r):f,g=n?y:f,d={language:a.language,enabledDetectors:t.enabledDetectors,disabledDetectors:t.disabledDetectors,forcedDetectors:o,includeFolders:t.includeFolders,excludeFolders:t.excludeFolders,includeExtensions:t.includeExtensions,gitignore:t.gitignore},m=ci(t.input),w;if(m.length>0){let x=new Set;for(let k of m){let S=qr(s,k),D=await ii(S).catch(()=>null);if(!D)throw new Error(`Input path does not exist: ${k}`);if(D.isFile())x.add(S);else if(D.isDirectory())for(let j of await ve({...d,projectRoot:S}))x.add(j);else throw new Error(`Input path must be a file or directory: ${k}`)}w=Array.from(x)}else w=await ve({...d,projectRoot:s});let b=new Date().getFullYear(),$=[],C=[],R=new Set,E=0,U=0,G=0,Y=[];for(let x of w){let k=Ot(x,{enabledDetectors:t.enabledDetectors,disabledDetectors:t.disabledDetectors,forcedDetectors:o});if(k!==null){C.push({file:Ye(s,x),reason:k});continue}let S=Ye(s,x),D=await oi(x,"utf8"),j={enabledDetectors:t.enabledDetectors,disabledDetectors:t.disabledDetectors,forcedDetectors:o,detectorSyntaxOverrides:t.detectorSyntaxOverrides},V=Bt(x,fe(D,x,j),j);if(V!==null){C.push({file:S,reason:V});continue}let h=await Te({...t,cwd:s,targetFilePath:x});R.add(`${h.language}:${h.projectRoot}`);let P={language:h.language,enabledDetectors:t.enabledDetectors,disabledDetectors:t.disabledDetectors,forcedDetectors:o,detectorSyntaxOverrides:t.detectorSyntaxOverrides,spacing:t.spacing,margin:t.margin,strictHeaderBlock:t.strictHeaderBlock!==!1},he=me(D,x,P),F=he?D.slice(he.start,he.end):"",Ve=F.length>0?li(F):{},Je=F.length>0?ui(F):{},Zr=F.length>0?di(F):null,Xr=F.length>0?fi(F):null,qe=await zt(x),Ke=Ye(h.projectRoot,x),Ze=await Sr(h.projectRoot,Ke),J=await Dr(h.projectRoot,Ke),Xe=ue(qe.createdAt),ge=jr({existing:Ue(Zr),gitCreated:Ze,filesystemCreated:Xe,fixCreatedDate:u}),q=Ue(Xr),Qe=ge.source,Qr=q?"existing-header":J?"git-last-modified":"filesystem-updated",ye=p(Qe==="existing-header"?g(ge.payload):y(ge.payload)),en=h.copyrightStartYear===null?"created-date":"option",et=h.copyrightStartYear??Pr(ye,r),tt=p(q?g(q):y(J||ue(qe.updatedAt))),rt=t.forceAuthorUpdate===!0,tn=t.forceLastModifiedAuthorUpdate===!0,nt=await mi(D,x,P),ot=tn||nt.edited,it=i(N=>_r({absoluteFilePath:x,language:h.language,syntaxOptions:P,projectRoot:h.projectRoot,projectName:h.projectName,createdByName:rt?h.authorName:Ve.authorName||h.authorName,createdByEmail:rt?h.authorEmail:Ve.authorEmail||h.authorEmail,lastModifiedByName:ot?h.authorName:Je.authorName||h.authorName,lastModifiedByEmail:ot?h.authorEmail:Je.authorEmail||h.authorEmail,authorName:h.authorName,authorEmail:h.authorEmail,createdAt:ye,lastModifiedAt:N,copyrightStartYear:et,companyName:h.companyName,currentYear:b}),"renderHeader"),st=it(tt),at=pe(D,st,x,P),rn=nt.edited&&q!==null&&J!==null&&q.timestamp<J.timestamp,te=at.changed||rn,ct=te?p(y(ue(new Date))):tt,nn=te?"current-time-on-change":Qr,on=te?it(ct):st,L=te?pe(D,on,x,P):at,re={file:S,changed:L.changed};if(c){let N=Ir(F,{gitCreated:Ze,gitLastModified:J,filesystemCreated:Xe},{strictCreatedDate:t.strictCreatedDate===!0}),K=N.filter(z=>z.advisory).length;re.dateIssues=N,G+=K,U+=N.length>K?1:0}if(t.sampleOutput===!0&&L.changed){let N=F.length>0?F.trimEnd():null,K=S.replace(/\\/g,"/"),z=L.written,sn=L.nextContent.slice(0,L.nextContent.indexOf(z)).split(`
|
|
32
|
+
`).length-1;re.sample={previousValue:N,newValue:z,diff:Jr(N,z,{fromFile:`a/${K}`,toFile:`b/${K}`,lineOffset:sn}),issues:Ur(N,z),detectedValues:{projectName:h.projectName,projectNameSource:h.projectNameSource,language:h.language,projectRoot:h.projectRoot,marker:h.marker,authorName:h.authorName,authorEmail:h.authorEmail,companyName:h.companyName,companyNameSource:h.companyNameSource,copyrightStartYear:et,copyrightStartYearSource:en,createdAtSource:Qe,lastModifiedAtSource:nn,createdAt:ye,lastModifiedAt:ct}}}if(L.extraCopyrights.length>0){re.extraCopyrights=L.extraCopyrights;for(let N of L.extraCopyrights)Y.push({file:S,copyright:N})}$.push(re),L.changed&&(E+=1,l||await si(x,L.nextContent,"utf8"))}return{metadata:a,detectedProjects:Array.from(R),filesScanned:w.length-C.length,filesUpdated:E,filesSkipped:C.length,dryRun:l,check:c,...c?{filesWithDateDrift:U,dateAdvisories:G}:{},copyrightWarnings:Y,changes:$,skipped:C}}i(Kr,"fixHeaders");function pi(e){return Kr(e)}i(pi,"fixHeaders");var pc=pi;export{pc as default,pi as fixHeaders};
|
|
33
33
|
//# sourceMappingURL=index.mjs.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cldmv/fix-headers",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.6",
|
|
4
4
|
"description": "Multi-language project header normalizer with auto-detection and override support.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
"dist/",
|
|
11
11
|
"!dist/**/*.map",
|
|
12
12
|
"types/",
|
|
13
|
-
"!types/devcheck.d.mts",
|
|
14
13
|
"bin/",
|
|
15
14
|
"!bin/**/*.map"
|
|
16
15
|
],
|
|
@@ -64,7 +63,14 @@
|
|
|
64
63
|
},
|
|
65
64
|
"homepage": "https://github.com/CLDMV/fix-headers#readme",
|
|
66
65
|
"engines": {
|
|
67
|
-
"node": ">=
|
|
66
|
+
"node": ">=18.0.0"
|
|
67
|
+
},
|
|
68
|
+
"devEngines": {
|
|
69
|
+
"runtime": {
|
|
70
|
+
"name": "node",
|
|
71
|
+
"version": ">=22.22.0",
|
|
72
|
+
"onFail": "error"
|
|
73
|
+
}
|
|
68
74
|
},
|
|
69
75
|
"author": {
|
|
70
76
|
"name": "Shinrai",
|
|
@@ -101,14 +107,14 @@
|
|
|
101
107
|
"@vitest/coverage-v8": "^5.0.0",
|
|
102
108
|
"esbuild": "^0.28.2",
|
|
103
109
|
"eslint": "^10.11.0",
|
|
104
|
-
"globals": "^17.
|
|
110
|
+
"globals": "^17.14.0",
|
|
105
111
|
"prettier": "^3.9.9",
|
|
106
|
-
"tsup": "^
|
|
112
|
+
"tsup": "^9.0.0",
|
|
107
113
|
"typescript": "^6.0.3",
|
|
108
114
|
"vitest": "^5.0.0"
|
|
109
115
|
},
|
|
110
116
|
"dependencies": {
|
|
111
|
-
"ignore": "^7.0.
|
|
117
|
+
"ignore": "^7.0.14"
|
|
112
118
|
},
|
|
113
119
|
"overrides": {
|
|
114
120
|
"esbuild": "$esbuild",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|