@cldmv/fix-headers 2.1.3 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,19 +1,19 @@
1
1
  #!/usr/bin/env node
2
- var Nr=Object.defineProperty;var i=(e,t)=>Nr(e,"name",{value:t,configurable:!0});import{realpathSync as wr}from"node:fs";import{fileURLToPath as ho,pathToFileURL as go}from"node:url";import{readFile as Cr}from"node:fs/promises";import{createRequire as Fr}from"node:module";import{dirname as jr,isAbsolute as Lr,resolve as ze}from"node:path";var Mr=3e4,Pr=new Set(["localhost","127.0.0.1","[::1]"]);function ie(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}i(ie,"isPlainObject");function ae(e,t){let r={...e};for(let[n,o]of Object.entries(t))n!=="__proto__"&&(r[n]=ie(r[n])&&ie(o)?ae(r[n],o):o);return r}i(ae,"mergeConfig");function Be(e){return e.kind==="file"?e.path:e.href}i(Be,"describeSource");async function Rr(e){if(e.kind==="file")return{text:await Cr(e.path,"utf8"),source:e};let t;try{t=await fetch(e.href,{cache:"no-store",redirect:"follow",signal:AbortSignal.timeout(Mr)})}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(Rr,"readSource");function He(e){if(e.protocol==="http:"&&!Pr.has(e.hostname))throw new Error(`Refusing to fetch config over plain http: ${e.href} (use https)`);return{kind:"url",href:e.href}}i(He,"toUrlSource");function Ir(e,t){if(/^https?:\/\//i.test(e))return He(new URL(e));if(/^[a-z][a-z\d+.-]+:\/\//i.test(e))throw new Error(`Unsupported extends URL "${e}" in ${Be(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 He(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||Lr(e))return{kind:"file",path:ze(jr(t.path),e)};try{return{kind:"file",path:Fr(t.path).resolve(e)}}catch(n){throw new Error(`Cannot resolve extends "${e}" from ${t.path}: ${n.message}`,{cause:n})}}i(Ir,"resolveReference");function Or(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(Or,"readExtends");async function We(e,t){let r=Be(e);if(t.includes(r))throw new Error(`Config extends cycle: ${[...t,r].join(" -> ")}`);let{text:n,source:o}=await Rr(e),a;try{a=JSON.parse(n)}catch(u){throw new Error(`Config ${r} is not valid JSON: ${u.message}`,{cause:u})}if(!ie(a))throw new Error(`Config file must contain a JSON object: ${r}`);let{extends:s,...c}=a,l={};for(let u of Or(s,r))l=ae(l,await We(Ir(u,o),[...t,r]));return ae(l,c)}i(We,"loadSource");function Tr(e,t=process.cwd()){return We({kind:"file",path:ze(t,e)},[])}i(Tr,"loadConfigFile");async function V(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 Tr(r,n),...e};return delete o[t],o}i(V,"applyConfigOption");import{readFile as io,stat as ao,writeFile as so}from"node:fs/promises";import{relative as gr,resolve as yr}from"node:path";import{extname as lt}from"node:path";import{extname as Ur}from"node:path";var Ye=[".css"];function _r(e){let t=Ur(e).toLowerCase();return Ye.includes(t)?{kind:"block",blockStart:"/*",blockLinePrefix:" * ",blockEnd:" */"}:null}i(_r,"resolveCssCommentSyntax");var Ge={id:"css",extensions:Ye,enabledByDefault:!0,resolveCommentSyntax(e){return _r(e)}};import{extname as Hr}from"node:path";var Ve=[".go"];function zr(e){let t=Hr(e).toLowerCase();return Ve.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}i(zr,"resolveGoCommentSyntax");var Je={id:"go",extensions:Ve,enabledByDefault:!0,resolveCommentSyntax(e){return zr(e)}};import{extname as Br}from"node:path";var Ke=[".html",".htm"];function Wr(e){let t=Br(e).toLowerCase();return Ke.includes(t)?{kind:"html",blockStart:"<!--",blockLinePrefix:" ",blockEnd:"-->"}:null}i(Wr,"resolveHtmlCommentSyntax");var qe={id:"html",extensions:Ke,enabledByDefault:!0,resolveCommentSyntax(e){return Wr(e)}};import{extname as Yr}from"node:path";var Xe=[".jsonv",".jsonc",".json5"];function Gr(e){let t=Yr(e).toLowerCase();return Xe.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}i(Gr,"resolveJsonCommentSyntax");var Ze={id:"json",extensions:Xe,enabledByDefault:!0,resolveCommentSyntax(e){return Gr(e)}};import{extname as Vr}from"node:path";var Qe=[".js",".mjs",".cjs",".ts",".tsx",".jsx"];function Jr(e){let t=Vr(e).toLowerCase();return Qe.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}i(Jr,"resolveNodeCommentSyntax");function Kr(e,t){let r=t.match(/^#!.*\b(node|bun|deno|tsx|ts-node)\b.*(?:\r?\n|$)/);return r?r[0]:""}i(Kr,"resolveNodePreservedPrefix");var et={id:"node",extensions:Qe,enabledByDefault:!0,resolvePreservedPrefix(e,t){return Kr(e,t)},resolveCommentSyntax(e){return Jr(e)}};import{extname as qr}from"node:path";var tt=[".php"];function Xr(e){let t=qr(e).toLowerCase();return tt.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}i(Xr,"resolvePhpCommentSyntax");var rt={id:"php",extensions:tt,enabledByDefault:!0,resolveCommentSyntax(e){return Xr(e)}};import{extname as Zr}from"node:path";var nt=[".py"];function Qr(e,t){let r=t.match(/^#!.*\bpython(?:\d+(?:\.\d+)*)?\b.*(?:\r?\n|$)/);return r?r[0]:""}i(Qr,"resolvePythonPreservedPrefix");var ot={id:"python",extensions:nt,enabledByDefault:!0,resolvePreservedPrefix(e,t){return Qr(e,t)},resolveCommentSyntax(e){let t=Zr(e).toLowerCase();return nt.includes(t)?{kind:"line",linePrefix:"#"}:null}};import{extname as en}from"node:path";var it=[".rs"];function tn(e){let t=en(e).toLowerCase();return it.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}i(tn,"resolveRustCommentSyntax");var at={id:"rust",extensions:it,enabledByDefault:!0,resolveCommentSyntax(e){return tn(e)}};import{extname as rn}from"node:path";var st=[".yaml",".yml"];function nn(e){let t=rn(e).toLowerCase();return st.includes(t)?{kind:"line",linePrefix:"#"}:null}i(nn,"resolveYamlCommentSyntax");var ct={id:"yaml",extensions:st,enabledByDefault:!0,resolveCommentSyntax(e){return nn(e)}};var ut=[Ge,Je,qe,Ze,et,rt,ot,at,ct],yi=new Map(ut.map(e=>[e.id,e]));function on(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(on,"applySyntaxOverride");function L(e={}){let t=new Set(Array.isArray(e.enabledDetectors)?e.enabledDetectors:[]),r=new Set(Array.isArray(e.disabledDetectors)?e.disabledDetectors:[]);return ut.filter(n=>t.size>0?t.has(n.id):r.has(n.id)?!1:n.enabledByDefault)}i(L,"getEnabledDetectors");function dt(e={}){if(Array.isArray(e.includeExtensions)&&e.includeExtensions.length>0)return new Set(e.includeExtensions.map(r=>r.toLowerCase()));let t=L(e);return new Set(t.flatMap(r=>r.extensions))}i(dt,"getAllowedExtensions");function ft(e,t={}){let r=lt(e).toLowerCase(),n=Array.isArray(t.detectors)?t.detectors:L(t);for(let o of n){if(!o.extensions.includes(r))continue;let a=o.resolveCommentSyntax(e);if(a){let s=t.detectorSyntaxOverrides&&typeof t.detectorSyntaxOverrides=="object"?t.detectorSyntaxOverrides:{};return on(a,s[o.id])}}return{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}}i(ft,"getCommentSyntaxForFile");function mt(e,t,r={}){let n=lt(e).toLowerCase(),o=L(r);for(let a of o)if(a.extensions.includes(n))return typeof a.resolvePreservedPrefix=="function"?a.resolvePreservedPrefix(e,t):"";return""}i(mt,"getPreservedPrefixForFile");var pt=200,R=1,J=2;function N(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(N,"resolveLayoutCount");import{join as At,relative as $t,resolve as pe,sep as fe}from"node:path";import{realpath as yn,stat as xn}from"node:fs/promises";import{access as an,readdir as sn,readFile as Di,stat as cn}from"node:fs/promises";import{constants as ln}from"node:fs";import{dirname as $i,join as un,resolve as vi}from"node:path";async function se(e){try{return await an(e,ln.F_OK),!0}catch{return!1}}i(se,"pathExists");async function ce(e,t){let r=[],n=await sn(e,{withFileTypes:!0});for(let o of n){let a=un(e,o.name);if(o.isDirectory()&&t.recursive===!1||o.isDirectory()&&t.ignoreFolders.has(o.name)||o.isDirectory()&&await t.shouldSkipDirectory?.(a,o.name)===!0)continue;if(o.isDirectory()){let l=await ce(a,t);r.push(...l);continue}if(!o.isFile())continue;let s=o.name.lastIndexOf(".");if(s===-1)continue;let c=o.name.slice(s).toLowerCase();t.allowedExtensions.has(c)&&r.push(a)}return r}i(ce,"walkFiles");async function ht(e){let t=await cn(e);return{createdAt:t.birthtimeMs>0&&t.birthtime<t.mtime?t.birthtime:t.mtime,updatedAt:t.mtime}}i(ht,"readFileDates");import{execFile as dn}from"node:child_process";import{lstat as fn,readFile as mn}from"node:fs/promises";import{dirname as gt,isAbsolute as pn,join as bt,relative as wt,resolve as le,sep as Et}from"node:path";import hn from"ignore";function yt(e,t){return new Promise(r=>{dn("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(yt,"runGitCommand");function de(e,t){return wt(e,t).split(Et).join("/")}i(de,"toPosixRelative");async function St(e){try{return hn().add(await mn(e,"utf8"))}catch{return null}}i(St,"readIgnoreFile");async function gn(e){return fn(bt(e,".git")).then(()=>!0,()=>!1)}i(gn,"hasGitEntry");function xt(e,t,r){for(let n=e.length-1;n>=0;n--){let{base:o,rules:a}=e[n],s=a.test(`${de(o,t)}${r?"/":""}`);if(s.ignored||s.unignored)return s.ignored}return!1}i(xt,"matchesRules");async function Dt(e,t){let r=await St(bt(e,".gitignore"));return{kind:"rules",nested:!0,excluded:!1,matchers:r?[...t,{base:e,rules:r}]:t}}i(Dt,"buildRulesContext");async function ue(e){let[t,r]=await Promise.all([yt(e,["check-ignore","-q","."]),yt(e,["ls-files","--cached","--others","--exclude-standard","-z"])]);if(t.code!==1||r.code!==0)return Dt(e,[]);let n=new Set,o=new Set;for(let a of r.stdout.split("\0")){let s=a.endsWith("/")?a.slice(0,-1):a;if(s.length!==0){n.add(s);for(let c=s.indexOf("/");c!==-1;c=s.indexOf("/",c+1))o.add(s.slice(0,c))}}return{kind:"git",root:e,entries:n,dirs:o}}i(ue,"resolveScopeContext");function kt(e){let t=le(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 ue(t);let c=typeof r=="string"?[r]:r.filter(u=>typeof u=="string"),l=[];for(let u of c){let f=await St(le(t,u));f&&l.push({base:t,rules:f})}return{kind:"rules",nested:!1,excluded:!1,matchers:l}},"buildRootContext"),a=i(c=>{let l=n.get(c);return l||(l=c===t?o():s(c),n.set(c,l)),l},"contextFor"),s=i(async c=>{let l=await a(gt(c));return l.kind==="git"?l.entries.has(de(l.root,c))?ue(c):l:!l.nested||l.excluded?l:xt(l.matchers,c,!0)?{...l,excluded:!0}:await gn(c)?ue(c):Dt(c,l.matchers)},"deriveContext");return{async isIgnored(c,l){let u=le(c),f=wt(t,u);if(f.length===0||f===".."||f.startsWith(`..${Et}`)||pn(f))return!1;let p=await a(gt(u));if(p.kind==="git"){let g=de(p.root,u);return!(p.entries.has(g)||l&&p.dirs.has(g))}return p.excluded||xt(p.matchers,u,l)}}}i(kt,"createIgnoreFilter");function bn(e){return dt(e)}i(bn,"resolveExtensions");var vt=new Set([".git"]);function me(e){return e.replace(/\\/g,"/").replace(/^\.\//,"").replace(/^\/+/,"").replace(/\/+$/,"")}i(me,"normalizeFolderPath");function wn(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(wn,"resolveIncludeFolders");function Nt(e,t){let r=t instanceof Error?t.message:String(t);console.warn(`fix-headers: skipped include folder "${e}" (${r})`)}i(Nt,"reportSkippedIncludeFolder");function En(e,t){if(!Array.isArray(t)||t.length===0)return()=>!1;let r=pe(e),n=[],o=new Set;for(let a of t){if(typeof a!="string")continue;let s=me(a);if(s.length!==0){if(s.includes("/")){n.push(pe(r,s));continue}o.add(s)}}return(a,s)=>{if(o.has(s))return!0;for(let l of n)if(a===l||a.startsWith(`${l}/`))return!0;let c=me($t(r,a));return n.some(l=>{let u=me($t(r,l));return c===u||c.startsWith(`${u}/`)})}}i(En,"buildExclusionMatcher");async function he(e){let t=bn(e),r=wn(e.includeFolders),n=Array.isArray(e.excludeFolders)?e.excludeFolders:[],o=En(e.projectRoot,n),a=kt({root:e.projectRoot,gitignore:e.gitignore}),s=i(async(m,h)=>o(m,h)||await a.isIgnored(m,!0),"shouldSkipDirectory"),c=r.length>0?r.map(m=>({includeFolder:m.path,rootPath:At(e.projectRoot,m.path),recursive:m.recursive})):[{includeFolder:".",rootPath:e.projectRoot,recursive:!0}],l=[];for(let m of c){let h=await xn(m.rootPath).catch(S=>S);if(h instanceof Error){if(h.code==="ENOENT"){Nt(m.includeFolder,h);continue}throw h}if(!h.isDirectory()){Nt(m.includeFolder,`path is not a directory: ${m.rootPath}`);continue}let w=await yn(m.rootPath).catch(()=>pe(m.rootPath));l.push({...m,realRoot:w})}let u=i((m,h)=>{if(m.realRoot===h.realRoot)return m.recursive||!h.recursive;let w=m.realRoot.endsWith(fe)?m.realRoot:`${m.realRoot}${fe}`;if(!m.recursive||!h.realRoot.startsWith(w))return!1;let S=m.rootPath;for(let A of h.realRoot.slice(w.length).split(fe))if(S=At(S,A),vt.has(A)||o(S,A))return!1;return!0},"covers"),f=[...l].sort((m,h)=>m.realRoot.length-h.realRoot.length||Number(h.recursive)-Number(m.recursive)),p=[];for(let m of f)p.some(h=>u(h,m))||p.push(m);let g=[];for(let m of l){if(!p.includes(m))continue;let h=await ce(m.rootPath,{allowedExtensions:t,ignoreFolders:vt,shouldSkipDirectory:s,recursive:m.recursive});g.push(...h)}let y=[];for(let m of new Set(g))!o(m,m.split("/").at(-1)||"")&&!await a.isIgnored(m,!1)&&y.push(m);return y}i(he,"discoverFiles");import{basename as Wn,dirname as Yn,extname as Gn,resolve as we}from"node:path";import{dirname as _t,isAbsolute as Ln,join as Ht,relative as Mn,resolve as zt,sep as Pn}from"node:path";import{readFile as Sn}from"node:fs/promises";import{join as Dn}from"node:path";async function kn(e){try{return await Sn(e,"utf8")}catch{return null}}i(kn,"readManifest");async function D(e,t){let r=[];for(let n of t){let o=await kn(Dn(e,n));o!==null&&r.push({file:n,content:o})}return r.length>0?{dir:e,manifest:r[0].file,files:r}:null}i(D,"detectManifests");function C(e,t){return e.files.find(r=>r.file===t)?.content??null}i(C,"manifestContent");function b(e){return typeof e=="string"&&e.trim().length>0?e.trim():void 0}i(b,"cleanName");function ge(e){if(typeof e!="string")return;let t=e.search(/[<(]/);return b(t===-1?e:e.slice(0,t))}i(ge,"personName");function K(e){try{return JSON.parse(e)}catch{return}}i(K,"parseJsonManifest");function*ye(e,t){let r="";for(let n of e.split(/\r?\n/)){let o=n.trim();if(o.startsWith("[")){let a=o.match(/^\[([^[\]]+)\]/);r=a?a[1].split(".").map(s=>s.trim()).join("."):"";continue}r===t&&(yield o)}}i(ye,"sectionLines");function I(e,t,r){let n=new RegExp(`^${r}\\s*=\\s*(?:"([^"\\\\]*)"|'([^']*)')`);for(let o of ye(e,t)){let a=o.match(n);if(a)return b(a[1]??a[2])}}i(I,"readTomlString");function xe(e,t,r){let n=new RegExp(`^${r}\\s*[=:](.*)$`);for(let o of ye(e,t)){let a=o.match(n);if(a)return b(a[1])}}i(xe,"readIniValue");function An(e,t,r){let n=new RegExp(`^${r}\\s*=\\s*\\[`),o=null;for(let a of ye(e,t)){if(o!==null){o.push(a);continue}let s=a.match(n);s&&(o=[a.slice(s[0].length)])}return o===null?null:o.join(`
3
- `)}i(An,"tomlArrayText");function $n(e,t){let r=t;for(;r<e.length;)if(e[r]==="#"){let n=e.indexOf(`
4
- `,r);r=n===-1?e.length:n+1}else if(/\s/.test(e[r]))r+=1;else break;return r}i($n,"skipTomlSpace");function O(e,t){let r=An(e,t,"authors");if(r===null)return;let n=r.slice($n(r,0)),o=n.match(/^(?:"([^"\\\n]*)"|'([^'\n]*)')/);if(o)return ge(o[1]??o[2]);let s=n.match(/^\{([^}\n]*)\}/)?.[1].match(/(?:^|,)\s*name\s*=\s*(?:"([^"\\\n]*)"|'([^'\n]*)')/);return s?b(s[1]??s[2]):void 0}i(O,"readTomlAuthor");var Ct=["go.mod"];function vn(e){let t=e.match(/^\s*module\s+(.+)$/m);if(t)return b(t[1].replace(/\/\/.*$/,"").trim().replace(/^["`](.*)["`]$/,"$1"))}i(vn,"readModulePath");var Ft={id:"go",languages:["go"],manifests:Ct,detect(e){return D(e,Ct)},read(e){return{name:vn(e.files[0].content)}}};var jt=["package.json"];function Nn(e){let t=b(e?.name),r=b(e?.publisher),n=typeof e?.engines?.vscode=="string";return t&&r&&n?`${r}.${t}`:t}i(Nn,"readPublishedName");function Cn(e){if(e!==null&&typeof e=="object"){let t=e;return b(t.company)??b(t.name)}return ge(e)}i(Cn,"readAuthorCompany");var Lt={id:"node",languages:["node"],manifests:jt,detect(e){return D(e,jt)},read(e){let t=K(e.files[0].content);return{name:Nn(t),company:Cn(t?.author)}}};var Mt=["composer.json"],Pt={id:"php",languages:["php"],manifests:Mt,detect(e){return D(e,Mt)},read(e){let t=K(e.files[0].content),r=t?.authors;return{name:b(t?.name),company:Array.isArray(r)?b(r[0]?.name):void 0}}};var Rt=["pyproject.toml","setup.cfg","setup.py"];function It(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(It,"readSetupPyArgument");function Fn(e){let t=C(e,"pyproject.toml"),r=C(e,"setup.cfg"),n=C(e,"setup.py");return(t===null?void 0:I(t,"project","name")??I(t,"tool.poetry","name"))??(r===null?void 0:xe(r,"metadata","name"))??(n===null?void 0:It(n,"name"))}i(Fn,"readPythonName");function jn(e){let t=C(e,"pyproject.toml"),r=C(e,"setup.cfg"),n=C(e,"setup.py");return(t===null?void 0:O(t,"project")??O(t,"tool.poetry"))??(r===null?void 0:xe(r,"metadata","author"))??(n===null?void 0:It(n,"author"))}i(jn,"readPythonCompany");var Ot={id:"python",languages:["python"],manifests:Rt,detect(e){return D(e,Rt)},read(e){return{name:Fn(e),company:jn(e)}}};var Tt=["Cargo.toml"],Ut={id:"rust",languages:["rust"],manifests:Tt,detect(e){return D(e,Tt)},read(e){let t=e.files[0].content;return{name:I(t,"package","name"),company:O(t,"package")}}};var Rn=[Lt,Ot,Pt,Ut,Ft],Bt=["name","company"];async function be(e,t,r){let o=(await Promise.all(t.map(async s=>({driver:s,detection:await s.detect(e)})))).filter(s=>s.detection!==null),a=o.filter(s=>typeof r=="string"&&s.driver.languages.includes(r));return[...a,...o.filter(s=>!a.includes(s))]}i(be,"claimFolder");function In(e,t){let r=Mn(t,e);return r!==""&&r!==".."&&!r.startsWith(`..${Pn}`)&&!Ln(r)}i(In,"isStrictlyInside");async function Wt(e,t={}){let r=Array.isArray(t.drivers)?t.drivers:Rn,n=typeof t.scanRoot=="string"?zt(t.scanRoot):null,o=zt(e),a=await be(o,r,t.language);for(;a.length===0;){if(await se(Ht(o,".git")))return{root:o,marker:".git",drivers:[],fields:{},sources:{}};let f=_t(o);if(f===o)return null;o=f,a=await be(o,r,t.language)}let s={},c={},l=o,u=a;for(;;){for(let{driver:p,detection:g}of u){let y=p.read(g);for(let m of Bt)s[m]===void 0&&y[m]!==void 0&&(s[m]=y[m],c[m]={driver:p.id,manifest:g.manifest,dir:l})}if(Bt.every(p=>s[p]!==void 0)||n===null||!In(l,n)||await se(Ht(l,".git")))break;l=_t(l),u=await be(l,r,t.language)}return{root:o,marker:a[0].detection.manifest,drivers:a.map(f=>f.driver.id),fields:s,sources:c}}i(Wt,"resolveManifestProject");import{execFile as On}from"node:child_process";import{promisify as Tn}from"node:util";var Gt=Tn(On);async function k(e,t){try{let{stdout:r}=await Gt("git",t,{cwd:e}),n=r.trim();return n.length>0?n:null}catch{return null}}i(k,"runGit");function Yt(e,t){let r=0;for(let n=t-1;n>=0&&e[n]==="\\";n--)r++;return r%2===1}i(Yt,"isEscaped");function Un(e){let t=e.trim();if(!t.endsWith(")")||Yt(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!==")"||Yt(t,n))&&(r+=o===")"?1:-1,r===0))return t.slice(0,n).trim()}return t}i(Un,"stripUidComment");function _n(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:Un(o)||o||null,authorEmail:n}}i(_n,"parseSignerUid");async function Hn(e,t){try{let{stdout:r}=await Gt(e,t),n=r.trim();return n.length>0?n:null}catch{return null}}i(Hn,"runProgram");function zn(e){return e.replace(/\\x([0-9a-fA-F]{2})/g,(t,r)=>String.fromCharCode(Number.parseInt(r,16)))}i(zn,"decodeColonField");async function Bn(e){let t=await k(e,["config","--get","gpg.format"]);if(t!==null&&t!=="openpgp")return null;let r=await k(e,["config","--get","user.signingkey"]);if(!r)return null;let n=await k(e,["config","--get","gpg.openpgp.program"])||await k(e,["config","--get","gpg.program"])||"gpg",o=await Hn(n,["--batch","--with-colons","--list-keys",r]);if(!o)return null;for(let a of o.split(`
5
- `)){let s=a.split(":");if(s[0]==="uid"&&s[1]!=="r"&&s[1]!=="e"&&s[9])return zn(s[9])}return null}i(Bn,"readSigningKeyUid");async function Vt(e,t={}){let r=await k(e,["config","--get","user.name"]),n=await k(e,["config","--get","user.email"]);if(t.useGpgSignerAuthor===!0){let o=await Bn(e)||await k(e,["log","-1","--format=%GS"]),a=_n(o||"");r=a.authorName||r,n=n||a.authorEmail}if(!r||!n){let o=await k(e,["log","-1","--format=%an|%ae"]);if(o){let[a,s]=o.split("|");r=r||a||null,n=n||s||null}}return{authorName:r,authorEmail:n}}i(Vt,"detectGitAuthor");function Jt(e){return e.replace(/z$/i,"+00:00")}i(Jt,"canonicalGitDate");async function Kt(e,t){let r=await k(e,["log","--follow","--format=%aI|%at","--reverse","--",t]);if(!r)return null;let n=r.split(`
6
- `)[0],[o,a]=n.split("|");if(!o||!a)return null;let s=Number.parseInt(a,10);return Number.isNaN(s)?null:{date:Jt(o),timestamp:s}}i(Kt,"getGitCreationDate");async function qt(e,t){let r=await k(e,["log","-1","--format=%aI|%at","--",t]);if(!r)return null;let[n,o]=r.split("|");if(!n||!o)return null;let a=Number.parseInt(o,10);return Number.isNaN(a)?null:{date:Jt(n),timestamp:a}}i(qt,"getGitLastModifiedDate");function Vn(e){return Wn(e)||"project"}i(Vn,"folderName");function Jn(e,t){if(typeof t!="string")return e;let r=t.trim();return r.length===0||/<[^>]+>/.test(e)?e:`${e} <${r}>`}i(Jn,"formatAuthorNameWithCompany");async function Kn(e,t={}){let r=Array.isArray(t.detectors)?t.detectors:L(t),n=typeof t.preferredExtension=="string"?t.preferredExtension.trim().toLowerCase():"",o=n.length>0?r.find(u=>u.extensions.includes(n)):void 0,a=await Wt(e,{drivers:t.drivers,language:o?.id,scanRoot:t.scanRoot}),s=a?a.root:we(e),c=a?.sources.name,l=a?.sources.company;return{language:o?.id??a?.drivers[0]??"unknown",rootDir:s,marker:a?a.marker:null,projectName:a?.fields.name??Vn(s),projectNameSource:c?{from:"manifest",...c}:{from:"folder",dir:s},companyName:a?.fields.company??null,companyNameSource:l?{from:"manifest",...l}:{from:"none"},drivers:a?a.drivers:[]}}i(Kn,"detectProjectFromMarkers");async function Ee(e={}){let t=e.targetFilePath||e.cwd||process.cwd(),r=we(t),n=L(e),o=e.targetFilePath?Yn(r):r,a=e.targetFilePath?Gn(r).toLowerCase():"",s=we(e.projectRoot||e.cwd||process.cwd()),c=await Kn(o,{detectors:n,preferredExtension:a,scanRoot:s}),l=await Vt(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:Jn(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(Ee,"resolveProjectMetadata");function qn(e){return Se({year:e.getFullYear(),month:e.getMonth()+1,day:e.getDate(),hour:e.getHours(),minute:e.getMinutes(),second:e.getSeconds(),offsetMinutes:-e.getTimezoneOffset()})}i(qn,"formatDateWithTimezone");function Se(e){return`${er(e," ")} ${tr(e.offsetMinutes)}`}i(Se,"formatSpaceDate");function Zt(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{Qt(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(Zt,"assertTimeZone");var Xt=new Map;function Qt(e){let t=Xt.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"}),Xt.set(e,t)),t}i(Qt,"getZoneFormatter");function De(e,t){let r={};for(let o of Qt(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(De,"toZonedDateParts");function er(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(er,"formatWallClock");function tr(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(tr,"formatOffset");function q(e=new Date){return{date:qn(e),timestamp:Math.floor(e.getTime()/1e3)}}i(q,"toDatePayload");var Xn=/^(\d{4})-(\d{2})-(\d{2})(?:T|\s+)(\d{2}):(\d{2}):(\d{2})(?:\.\d+)?\s*(?:(Z)|([+-])(\d{2}):?(\d{2}))$/i;function F(e){let t=Xn.exec(e.trim());if(!t)return null;let[r,n,o,a,s,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,a,s,c));return!(f.getUTCFullYear()===r&&f.getUTCMonth()===n-1&&f.getUTCDate()===o&&f.getUTCHours()===a&&f.getUTCMinutes()===s&&f.getUTCSeconds()===c)||Number(t[10]??0)>59?null:{year:r,month:n,day:o,hour:a,minute:s,second:c,offsetMinutes:u,timestamp:Math.floor(f.getTime()/1e3)-u*60}}i(F,"parseHeaderDate");function ke(e){return`${er(e,"T")}${tr(e.offsetMinutes)}`}i(ke,"formatIsoDate");var Zn={"git-created":"git first commit","filesystem-created":"filesystem creation time"};function rr(e,t){let r=e.match(new RegExp(`${t}:[^\\S\\n]*(.*)$`,"m"));return r?r[1].trim():null}i(rr,"readHeaderField");function Ae(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(Ae,"pickOldestDate");function or({existing:e,gitCreated:t,filesystemCreated:r,fixCreatedDate:n=!1}){let o=[{source:"git-created",payload:t},{source:"filesystem-created",payload:r}];if(!e)return Ae(o);if(!n)return{source:"existing-header",payload:e};let a=F(e.date)?e:null;return Ae([{source:"existing-header",payload:a},...o])}i(or,"resolveCreatedDate");function ir(e,t=null){if(t)return De(e.timestamp,t).year;let r=F(e.date);return r?r.year:new Date(e.timestamp*1e3).getFullYear()}i(ir,"dateYear");function nr(e,t,r,n){let o=e.match(/^(.+?)\s*\((\d+)\)$/),a=o?F(o[1]):null;if(!o||!a)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 s=Number.parseInt(o[2],10);return s!==a.timestamp&&n.push({check:`${r}-epoch`,field:t,advisory:!1,value:e,expected:`${o[1]} (${a.timestamp})`,message:`${t} epoch ${s} does not match ${o[1]} (expected ${a.timestamp})`}),{text:o[1],timestamp:a.timestamp}}i(nr,"checkDateValue");function ar(e,t={},r={}){let n=[],o=rr(e,"@Date"),a=o===null?null:nr(o,"@Date","created",n),s=Ae([{source:"git-created",payload:t.gitCreated},{source:"filesystem-created",payload:t.filesystemCreated}]);if(a&&s&&a.timestamp>s.payload.timestamp){let f=Zn[s.source];n.push({check:"created-newer-than-source",field:"@Date",advisory:r.strictCreatedDate!==!0,value:o,expected:`${s.payload.date} (${s.payload.timestamp})`,source:s.source,message:`@Date ${a.text} is later than the ${f} ${s.payload.date} (${s.payload.timestamp})`})}let c=rr(e,"@Last modified time"),l=c===null?null:nr(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(ar,"checkHeaderDates");function $e(e){if(!e)return null;let t=F(e.date);return t&&t.timestamp!==e.timestamp?{date:e.date,timestamp:t.timestamp}:e}i($e,"repairDateEpoch");function sr(e){let t=F(e.date);return t?{date:ke(t),timestamp:t.timestamp}:e}i(sr,"normalizeDatePayload");function cr(e,t){let r=F(e.date);if(!r)return e;let n=De(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())?ke(n):Se(n),timestamp:r.timestamp}}i(cr,"convertDatePayload");import{relative as eo}from"node:path";import{extname as Qn}from"node:path";function T(e,t={}){let r=Qn(e).toLowerCase(),n=N(t.spacing,"spacing",R);return r.length===0?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */",spacing:n}:{...ft(e,t),spacing:n}}i(T,"getHeaderSyntaxForFile");function lr(e,t){let r=e.spacing??R;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(`
2
+ var Yr=Object.defineProperty;var i=(e,t)=>Yr(e,"name",{value:t,configurable:!0});import{realpathSync as Pr}from"node:fs";import{fileURLToPath as Wo,pathToFileURL as Yo}from"node:url";import{readFile as Gr}from"node:fs/promises";import{createRequire as Vr}from"node:module";import{dirname as Jr,isAbsolute as qr,resolve as rt}from"node:path";var Kr=3e4,Xr=new Set(["localhost","127.0.0.1","[::1]"]);function se(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}i(se,"isPlainObject");function ce(e,t){let r={...e};for(let[n,o]of Object.entries(t))n!=="__proto__"&&(r[n]=se(r[n])&&se(o)?ce(r[n],o):o);return r}i(ce,"mergeConfig");function nt(e){return e.kind==="file"?e.path:e.href}i(nt,"describeSource");async function Zr(e){if(e.kind==="file")return{text:await Gr(e.path,"utf8"),source:e};let t;try{t=await fetch(e.href,{cache:"no-store",redirect:"follow",signal:AbortSignal.timeout(Kr)})}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(Zr,"readSource");function tt(e){if(e.protocol==="http:"&&!Xr.has(e.hostname))throw new Error(`Refusing to fetch config over plain http: ${e.href} (use https)`);return{kind:"url",href:e.href}}i(tt,"toUrlSource");function Qr(e,t){if(/^https?:\/\//i.test(e))return tt(new URL(e));if(/^[a-z][a-z\d+.-]+:\/\//i.test(e))throw new Error(`Unsupported extends URL "${e}" in ${nt(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 tt(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||qr(e))return{kind:"file",path:rt(Jr(t.path),e)};try{return{kind:"file",path:Vr(t.path).resolve(e)}}catch(n){throw new Error(`Cannot resolve extends "${e}" from ${t.path}: ${n.message}`,{cause:n})}}i(Qr,"resolveReference");function en(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(en,"readExtends");async function ot(e,t){let r=nt(e);if(t.includes(r))throw new Error(`Config extends cycle: ${[...t,r].join(" -> ")}`);let{text:n,source:o}=await Zr(e),a;try{a=JSON.parse(n)}catch(u){throw new Error(`Config ${r} is not valid JSON: ${u.message}`,{cause:u})}if(!se(a))throw new Error(`Config file must contain a JSON object: ${r}`);let{extends:s,...c}=a,l={};for(let u of en(s,r))l=ce(l,await ot(Qr(u,o),[...t,r]));return ce(l,c)}i(ot,"loadSource");function tn(e,t=process.cwd()){return ot({kind:"file",path:rt(t,e)},[])}i(tn,"loadConfigFile");async function q(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 tn(r,n),...e};return delete o[t],o}i(q,"applyConfigOption");import{readFile as Mo,stat as Ro,writeFile as Po}from"node:fs/promises";import{relative as Pe,resolve as Lr}from"node:path";import{extname as le}from"node:path";import{extname as rn}from"node:path";var it=[".css"];function nn(e){let t=rn(e).toLowerCase();return it.includes(t)?{kind:"block",blockStart:"/*",blockLinePrefix:" * ",blockEnd:" */"}:null}i(nn,"resolveCssCommentSyntax");var at={id:"css",extensions:it,enabledByDefault:!0,resolveCommentSyntax(e){return nn(e)}};import{extname as on}from"node:path";var st=[".go"];function an(e){let t=on(e).toLowerCase();return st.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}i(an,"resolveGoCommentSyntax");var ct={id:"go",extensions:st,enabledByDefault:!0,resolveCommentSyntax(e){return an(e)}};import{extname as sn}from"node:path";var lt=[".html",".htm"];function cn(e){let t=sn(e).toLowerCase();return lt.includes(t)?{kind:"html",blockStart:"<!--",blockLinePrefix:" ",blockEnd:"-->"}:null}i(cn,"resolveHtmlCommentSyntax");var ut={id:"html",extensions:lt,enabledByDefault:!0,resolveCommentSyntax(e){return cn(e)}};import{extname as ln}from"node:path";var ft=[".jsonv",".jsonc",".json5"];function un(e){let t=ln(e).toLowerCase();return ft.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}i(un,"resolveJsonCommentSyntax");var dt={id:"json",extensions:ft,enabledByDefault:!0,resolveCommentSyntax(e){return un(e)}};import{extname as fn}from"node:path";var mt=[".md",".markdown"];function dn(e){let t=fn(e).toLowerCase();return mt.includes(t)?{kind:"html",blockStart:"<!--",blockLinePrefix:" ",blockEnd:"-->"}:null}i(dn,"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 pt={id:"markdown",extensions:mt,enabledByDefault:!1,requiresForce:!0,resolvePreservedPrefix(e,t){return mn(e,t)},resolveCommentSyntax(e){return dn(e)}};import{extname as pn}from"node:path";var ht=[".js",".mjs",".cjs",".ts",".tsx",".jsx"];function hn(e){let t=pn(e).toLowerCase();return ht.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}i(hn,"resolveNodeCommentSyntax");function gn(e,t){let r=t.match(/^#!.*\b(node|bun|deno|tsx|ts-node)\b.*(?:\r?\n|$)/);return r?r[0]:""}i(gn,"resolveNodePreservedPrefix");var gt={id:"node",extensions:ht,enabledByDefault:!0,resolvePreservedPrefix(e,t){return gn(e,t)},resolveCommentSyntax(e){return hn(e)}};import{extname as yn}from"node:path";var yt=[".php"];function xn(e){let t=yn(e).toLowerCase();return yt.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}i(xn,"resolvePhpCommentSyntax");var xt={id:"php",extensions:yt,enabledByDefault:!0,resolveCommentSyntax(e){return xn(e)}};import{extname as wn}from"node:path";var wt=[".py"];function bn(e,t){let r=t.match(/^#!.*\bpython(?:\d+(?:\.\d+)*)?\b.*(?:\r?\n|$)/);return r?r[0]:""}i(bn,"resolvePythonPreservedPrefix");var bt={id:"python",extensions:wt,enabledByDefault:!0,resolvePreservedPrefix(e,t){return bn(e,t)},resolveCommentSyntax(e){let t=wn(e).toLowerCase();return wt.includes(t)?{kind:"line",linePrefix:"#"}:null}};import{extname as kn}from"node:path";var kt=[".rs"];function En(e){let t=kn(e).toLowerCase();return kt.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}i(En,"resolveRustCommentSyntax");var Et={id:"rust",extensions:kt,enabledByDefault:!0,resolveCommentSyntax(e){return En(e)}};import{extname as Sn}from"node:path";var St=[".yaml",".yml"];function $n(e){let t=Sn(e).toLowerCase();return St.includes(t)?{kind:"line",linePrefix:"#"}:null}i($n,"resolveYamlCommentSyntax");var $t={id:"yaml",extensions:St,enabledByDefault:!0,resolveCommentSyntax(e){return $n(e)}};var K=[at,ct,ut,dt,pt,gt,xt,bt,Et,$t],An=new Map(K.map(e=>[e.id,e]));function Dn(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(Dn,"applySyntaxOverride");function At(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=K.filter(r=>r.requiresForce===!0).map(r=>r.id);for(let r of e){if(!An.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(At,"resolveForcedDetectors");function F(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 K.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(F,"getEnabledDetectors");function Dt(e={}){if(Array.isArray(e.includeExtensions)&&e.includeExtensions.length>0)return new Set(e.includeExtensions.map(r=>r.toLowerCase()));let t=F(e);return new Set(t.flatMap(r=>r.extensions))}i(Dt,"getAllowedExtensions");function vt(e,t={}){let r=le(e).toLowerCase();if(F(t).some(s=>s.extensions.includes(r)&&s.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:[]),a=K.find(s=>s.requiresForce===!0&&s.extensions.includes(r)&&!o.has(s.id));return a?`${r} files get a header only when forced (--force-detector ${a.id} / forcedDetectors: ["${a.id}"])`:`no enabled detector handles ${r} files`}i(vt,"getHeaderSkipReason");function Ct(e,t={}){let r=le(e).toLowerCase(),n=Array.isArray(t.detectors)?t.detectors:F(t);for(let o of n){if(!o.extensions.includes(r))continue;let a=o.resolveCommentSyntax(e);if(a){let s=t.detectorSyntaxOverrides&&typeof t.detectorSyntaxOverrides=="object"?t.detectorSyntaxOverrides:{};return Dn(a,s[o.id])}}return{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}}i(Ct,"getCommentSyntaxForFile");function Nt(e,t,r={}){let n=le(e).toLowerCase(),o=F(r);for(let a of o)if(a.extensions.includes(n))return typeof a.resolvePreservedPrefix=="function"?a.resolvePreservedPrefix(e,t):"";return""}i(Nt,"getPreservedPrefixForFile");var Ft=200,B=1,X=2;function j(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(j,"resolveLayoutCount");import{existsSync as Tn}from"node:fs";import{join as ye,relative as Ut,resolve as xe,sep as he}from"node:path";import{realpath as Hn,stat as _n}from"node:fs/promises";import{access as vn,readdir as Cn,readFile as ra,stat as Nn}from"node:fs/promises";import{constants as Fn}from"node:fs";import{dirname as ia,join as jn,resolve as aa}from"node:path";async function ue(e){try{return await vn(e,Fn.F_OK),!0}catch{return!1}}i(ue,"pathExists");async function fe(e,t){let r=[],n=await Cn(e,{withFileTypes:!0});for(let o of n){let a=jn(e,o.name);if(o.isDirectory()&&t.recursive===!1||o.isDirectory()&&t.ignoreFolders.has(o.name)||o.isDirectory()&&await t.shouldSkipDirectory?.(a,o.name)===!0)continue;if(o.isDirectory()){let l=await fe(a,t);r.push(...l);continue}if(!o.isFile())continue;let s=o.name.lastIndexOf(".");if(s===-1)continue;let c=o.name.slice(s).toLowerCase();t.allowedExtensions.has(c)&&r.push(a)}return r}i(fe,"walkFiles");async function jt(e){let t=await Nn(e);return{createdAt:t.birthtimeMs>0&&t.birthtime<t.mtime?t.birthtime:t.mtime,updatedAt:t.mtime}}i(jt,"readFileDates");import{execFile as Ln}from"node:child_process";import{lstat as Mn,readFile as Rn}from"node:fs/promises";import{dirname as Lt,isAbsolute as Pn,join as Pt,relative as It,resolve as de,sep as Ot}from"node:path";import In from"ignore";function Mt(e,t){return new Promise(r=>{Ln("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(Mt,"runGitCommand");function pe(e,t){return It(e,t).split(Ot).join("/")}i(pe,"toPosixRelative");async function Tt(e){try{return In().add(await Rn(e,"utf8"))}catch{return null}}i(Tt,"readIgnoreFile");async function On(e){return Mn(Pt(e,".git")).then(()=>!0,()=>!1)}i(On,"hasGitEntry");function Rt(e,t,r){for(let n=e.length-1;n>=0;n--){let{base:o,rules:a}=e[n],s=a.test(`${pe(o,t)}${r?"/":""}`);if(s.ignored||s.unignored)return s.ignored}return!1}i(Rt,"matchesRules");async function Ht(e,t){let r=await Tt(Pt(e,".gitignore"));return{kind:"rules",nested:!0,excluded:!1,matchers:r?[...t,{base:e,rules:r}]:t}}i(Ht,"buildRulesContext");async function me(e){let[t,r]=await Promise.all([Mt(e,["check-ignore","-q","."]),Mt(e,["ls-files","--cached","--others","--exclude-standard","-z"])]);if(t.code!==1||r.code!==0)return Ht(e,[]);let n=new Set,o=new Set;for(let a of r.stdout.split("\0")){let s=a.endsWith("/")?a.slice(0,-1):a;if(s.length!==0){n.add(s);for(let c=s.indexOf("/");c!==-1;c=s.indexOf("/",c+1))o.add(s.slice(0,c))}}return{kind:"git",root:e,entries:n,dirs:o}}i(me,"resolveScopeContext");function _t(e){let t=de(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 me(t);let c=typeof r=="string"?[r]:r.filter(u=>typeof u=="string"),l=[];for(let u of c){let f=await Tt(de(t,u));f&&l.push({base:t,rules:f})}return{kind:"rules",nested:!1,excluded:!1,matchers:l}},"buildRootContext"),a=i(c=>{let l=n.get(c);return l||(l=c===t?o():s(c),n.set(c,l)),l},"contextFor"),s=i(async c=>{let l=await a(Lt(c));return l.kind==="git"?l.entries.has(pe(l.root,c))?me(c):l:!l.nested||l.excluded?l:Rt(l.matchers,c,!0)?{...l,excluded:!0}:await On(c)?me(c):Ht(c,l.matchers)},"deriveContext");return{async isIgnored(c,l){let u=de(c),f=It(t,u);if(f.length===0||f===".."||f.startsWith(`..${Ot}`)||Pn(f))return!1;let m=await a(Lt(u));if(m.kind==="git"){let g=pe(m.root,u);return!(m.entries.has(g)||l&&m.dirs.has(g))}return m.excluded||Rt(m.matchers,u,l)}}}i(_t,"createIgnoreFilter");function Un(e){return Dt(e)}i(Un,"resolveExtensions");var zn=Object.freeze(["node_modules","bower_components","jspm_packages",".pnpm-store",".yarn"]),Wt=new Set([".git",...zn]),Bn=Object.freeze(["autoload.php","modules.txt"]);function zt(e,t){return Wt.has(t)?!0:t==="vendor"&&Bn.some(r=>Tn(ye(e,r)))}i(zt,"isNeverWalked");function ge(e){return e.replace(/\\/g,"/").replace(/^\.\//,"").replace(/^\/+/,"").replace(/\/+$/,"")}i(ge,"normalizeFolderPath");function Wn(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(Wn,"resolveIncludeFolders");function Bt(e,t){let r=t instanceof Error?t.message:String(t);console.warn(`fix-headers: skipped include folder "${e}" (${r})`)}i(Bt,"reportSkippedIncludeFolder");function Yn(e,t){if(!Array.isArray(t)||t.length===0)return()=>!1;let r=xe(e),n=[],o=new Set;for(let a of t){if(typeof a!="string")continue;let s=ge(a);if(s.length!==0){if(s.includes("/")){n.push(xe(r,s));continue}o.add(s)}}return(a,s)=>{if(o.has(s))return!0;for(let l of n)if(a===l||a.startsWith(`${l}/`))return!0;let c=ge(Ut(r,a));return n.some(l=>{let u=ge(Ut(r,l));return c===u||c.startsWith(`${u}/`)})}}i(Yn,"buildExclusionMatcher");async function we(e){let t=Un(e),r=Wn(e.includeFolders),n=Array.isArray(e.excludeFolders)?e.excludeFolders:[],o=Yn(e.projectRoot,n),a=_t({root:e.projectRoot,gitignore:e.gitignore}),s=i(async(d,h)=>zt(d,h)||o(d,h)||await a.isIgnored(d,!0),"shouldSkipDirectory"),c=r.length>0?r.map(d=>({includeFolder:d.path,rootPath:ye(e.projectRoot,d.path),recursive:d.recursive})):[{includeFolder:".",rootPath:e.projectRoot,recursive:!0}],l=[];for(let d of c){let h=await _n(d.rootPath).catch($=>$);if(h instanceof Error){if(h.code==="ENOENT"){Bt(d.includeFolder,h);continue}throw h}if(!h.isDirectory()){Bt(d.includeFolder,`path is not a directory: ${d.rootPath}`);continue}let b=await Hn(d.rootPath).catch(()=>xe(d.rootPath));l.push({...d,realRoot:b})}let u=i((d,h)=>{if(d.realRoot===h.realRoot)return d.recursive||!h.recursive;let b=d.realRoot.endsWith(he)?d.realRoot:`${d.realRoot}${he}`;if(!d.recursive||!h.realRoot.startsWith(b))return!1;let $=d.rootPath;for(let v of h.realRoot.slice(b.length).split(he))if($=ye($,v),zt($,v)||o($,v))return!1;return!0},"covers"),f=[...l].sort((d,h)=>d.realRoot.length-h.realRoot.length||Number(h.recursive)-Number(d.recursive)),m=[];for(let d of f)m.some(h=>u(h,d))||m.push(d);let g=[];for(let d of l){if(!m.includes(d))continue;let h=await fe(d.rootPath,{allowedExtensions:t,ignoreFolders:Wt,shouldSkipDirectory:s,recursive:d.recursive});g.push(...h)}let x=[];for(let d of new Set(g))!o(d,d.split("/").at(-1)||"")&&!await a.isIgnored(d,!1)&&x.push(d);return x}i(we,"discoverFiles");import{basename as xo,dirname as wo,extname as bo,resolve as Ae}from"node:path";import{dirname as rr,isAbsolute as ro,join as nr,relative as no,resolve as or,sep as oo}from"node:path";import{readFile as Gn}from"node:fs/promises";import{join as Vn}from"node:path";async function Jn(e){try{return await Gn(e,"utf8")}catch{return null}}i(Jn,"readManifest");async function A(e,t){let r=[];for(let n of t){let o=await Jn(Vn(e,n));o!==null&&r.push({file:n,content:o})}return r.length>0?{dir:e,manifest:r[0].file,files:r}:null}i(A,"detectManifests");function L(e,t){return e.files.find(r=>r.file===t)?.content??null}i(L,"manifestContent");function w(e){return typeof e=="string"&&e.trim().length>0?e.trim():void 0}i(w,"cleanName");function be(e){if(typeof e!="string")return;let t=e.search(/[<(]/);return w(t===-1?e:e.slice(0,t))}i(be,"personName");function Z(e){try{return JSON.parse(e)}catch{return}}i(Z,"parseJsonManifest");function*ke(e,t){let r="";for(let n of e.split(/\r?\n/)){let o=n.trim();if(o.startsWith("[")){let a=o.match(/^\[([^[\]]+)\]/);r=a?a[1].split(".").map(s=>s.trim()).join("."):"";continue}r===t&&(yield o)}}i(ke,"sectionLines");function W(e,t,r){let n=new RegExp(`^${r}\\s*=\\s*(?:"([^"\\\\]*)"|'([^']*)')`);for(let o of ke(e,t)){let a=o.match(n);if(a)return w(a[1]??a[2])}}i(W,"readTomlString");function Ee(e,t,r){let n=new RegExp(`^${r}\\s*[=:](.*)$`);for(let o of ke(e,t)){let a=o.match(n);if(a)return w(a[1])}}i(Ee,"readIniValue");function qn(e,t,r){let n=new RegExp(`^${r}\\s*=\\s*\\[`),o=null;for(let a of ke(e,t)){if(o!==null){o.push(a);continue}let s=a.match(n);s&&(o=[a.slice(s[0].length)])}return o===null?null:o.join(`
3
+ `)}i(qn,"tomlArrayText");function Kn(e,t){let r=t;for(;r<e.length;)if(e[r]==="#"){let n=e.indexOf(`
4
+ `,r);r=n===-1?e.length:n+1}else if(/\s/.test(e[r]))r+=1;else break;return r}i(Kn,"skipTomlSpace");function Y(e,t){let r=qn(e,t,"authors");if(r===null)return;let n=r.slice(Kn(r,0)),o=n.match(/^(?:"([^"\\\n]*)"|'([^'\n]*)')/);if(o)return be(o[1]??o[2]);let s=n.match(/^\{([^}\n]*)\}/)?.[1].match(/(?:^|,)\s*name\s*=\s*(?:"([^"\\\n]*)"|'([^'\n]*)')/);return s?w(s[1]??s[2]):void 0}i(Y,"readTomlAuthor");var Yt=["go.mod"];function Xn(e){let t=e.match(/^\s*module\s+(.+)$/m);if(t)return w(t[1].replace(/\/\/.*$/,"").trim().replace(/^["`](.*)["`]$/,"$1"))}i(Xn,"readModulePath");var Gt={id:"go",languages:["go"],manifests:Yt,detect(e){return A(e,Yt)},read(e){return{name:Xn(e.files[0].content)}}};var Vt=["package.json"];function Zn(e){let t=w(e?.name),r=w(e?.publisher),n=typeof e?.engines?.vscode=="string";return t&&r&&n?`${r}.${t}`:t}i(Zn,"readPublishedName");function Qn(e){if(e!==null&&typeof e=="object"){let t=e;return w(t.company)??w(t.name)}return be(e)}i(Qn,"readAuthorCompany");var Jt={id:"node",languages:["node"],manifests:Vt,detect(e){return A(e,Vt)},read(e){let t=Z(e.files[0].content);return{name:Zn(t),company:Qn(t?.author)}}};var qt=["composer.json"],Kt={id:"php",languages:["php"],manifests:qt,detect(e){return A(e,qt)},read(e){let t=Z(e.files[0].content),r=t?.authors;return{name:w(t?.name),company:Array.isArray(r)?w(r[0]?.name):void 0}}};var Xt=["pyproject.toml","setup.cfg","setup.py"];function Zt(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(Zt,"readSetupPyArgument");function eo(e){let t=L(e,"pyproject.toml"),r=L(e,"setup.cfg"),n=L(e,"setup.py");return(t===null?void 0:W(t,"project","name")??W(t,"tool.poetry","name"))??(r===null?void 0:Ee(r,"metadata","name"))??(n===null?void 0:Zt(n,"name"))}i(eo,"readPythonName");function to(e){let t=L(e,"pyproject.toml"),r=L(e,"setup.cfg"),n=L(e,"setup.py");return(t===null?void 0:Y(t,"project")??Y(t,"tool.poetry"))??(r===null?void 0:Ee(r,"metadata","author"))??(n===null?void 0:Zt(n,"author"))}i(to,"readPythonCompany");var Qt={id:"python",languages:["python"],manifests:Xt,detect(e){return A(e,Xt)},read(e){return{name:eo(e),company:to(e)}}};var er=["Cargo.toml"],tr={id:"rust",languages:["rust"],manifests:er,detect(e){return A(e,er)},read(e){let t=e.files[0].content;return{name:W(t,"package","name"),company:Y(t,"package")}}};var io=[Jt,Qt,Kt,tr,Gt],ir=["name","company"];async function Se(e,t,r){let o=(await Promise.all(t.map(async s=>({driver:s,detection:await s.detect(e)})))).filter(s=>s.detection!==null),a=o.filter(s=>typeof r=="string"&&s.driver.languages.includes(r));return[...a,...o.filter(s=>!a.includes(s))]}i(Se,"claimFolder");function ao(e,t){let r=no(t,e);return r!==""&&r!==".."&&!r.startsWith(`..${oo}`)&&!ro(r)}i(ao,"isStrictlyInside");async function ar(e,t={}){let r=Array.isArray(t.drivers)?t.drivers:io,n=typeof t.scanRoot=="string"?or(t.scanRoot):null,o=or(e),a=await Se(o,r,t.language);for(;a.length===0;){if(await ue(nr(o,".git")))return{root:o,marker:".git",drivers:[],fields:{},sources:{}};let f=rr(o);if(f===o)return null;o=f,a=await Se(o,r,t.language)}let s={},c={},l=o,u=a;for(;;){for(let{driver:m,detection:g}of u){let x=m.read(g);for(let d of ir)s[d]===void 0&&x[d]!==void 0&&(s[d]=x[d],c[d]={driver:m.id,manifest:g.manifest,dir:l})}if(ir.every(m=>s[m]!==void 0)||n===null||!ao(l,n)||await ue(nr(l,".git")))break;l=rr(l),u=await Se(l,r,t.language)}return{root:o,marker:a[0].detection.manifest,drivers:a.map(f=>f.driver.id),fields:s,sources:c}}i(ar,"resolveManifestProject");import{execFile as so}from"node:child_process";import{basename as co,dirname as lo}from"node:path";import{promisify as uo}from"node:util";var $e=uo(so);async function S(e,t){try{let{stdout:r}=await $e("git",t,{cwd:e}),n=r.trim();return n.length>0?n:null}catch{return null}}i(S,"runGit");function sr(e,t){let r=0;for(let n=t-1;n>=0&&e[n]==="\\";n--)r++;return r%2===1}i(sr,"isEscaped");function fo(e){let t=e.trim();if(!t.endsWith(")")||sr(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!==")"||sr(t,n))&&(r+=o===")"?1:-1,r===0))return t.slice(0,n).trim()}return t}i(fo,"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:fo(o)||o||null,authorEmail:n}}i(mo,"parseSignerUid");async function po(e,t){try{let{stdout:r}=await $e(e,t),n=r.trim();return n.length>0?n:null}catch{return null}}i(po,"runProgram");function ho(e){return e.replace(/\\x([0-9a-fA-F]{2})/g,(t,r)=>String.fromCharCode(Number.parseInt(r,16)))}i(ho,"decodeColonField");async function go(e){let t=await S(e,["config","--get","gpg.format"]);if(t!==null&&t!=="openpgp")return null;let r=await S(e,["config","--get","user.signingkey"]);if(!r)return null;let n=await S(e,["config","--get","gpg.openpgp.program"])||await S(e,["config","--get","gpg.program"])||"gpg",o=await po(n,["--batch","--with-colons","--list-keys",r]);if(!o)return null;for(let a of o.split(`
5
+ `)){let s=a.split(":");if(s[0]==="uid"&&s[1]!=="r"&&s[1]!=="e"&&s[9])return ho(s[9])}return null}i(go,"readSigningKeyUid");async function cr(e,t={}){let r=await S(e,["config","--get","user.name"]),n=await S(e,["config","--get","user.email"]);if(t.useGpgSignerAuthor===!0){let o=await go(e)||await S(e,["log","-1","--format=%GS"]),a=mo(o||"");r=a.authorName||r,n=n||a.authorEmail}if(!r||!n){let o=await S(e,["log","-1","--format=%an|%ae"]);if(o){let[a,s]=o.split("|");r=r||a||null,n=n||s||null}}return{authorName:r,authorEmail:n}}i(cr,"detectGitAuthor");function lr(e){return e.replace(/z$/i,"+00:00")}i(lr,"canonicalGitDate");async function ur(e,t){let r=await S(e,["log","--follow","--format=%aI|%at","--reverse","--",t]);if(!r)return null;let n=r.split(`
6
+ `)[0],[o,a]=n.split("|");if(!o||!a)return null;let s=Number.parseInt(a,10);return Number.isNaN(s)?null:{date:lr(o),timestamp:s}}i(ur,"getGitCreationDate");async function fr(e,t){let r=await S(e,["log","-1","--format=%aI|%at","--",t]);if(!r)return null;let[n,o]=r.split("|");if(!n||!o)return null;let a=Number.parseInt(o,10);return Number.isNaN(a)?null:{date:lr(n),timestamp:a}}i(fr,"getGitLastModifiedDate");var yo=256*1024*1024;async function dr(e){let t=lo(e);if(await S(t,["rev-parse","--is-inside-work-tree"])!=="true")return{state:"no-git",content:null};try{let{stdout:r}=await $e("git",["show",`HEAD:./${co(e)}`],{cwd:t,encoding:"utf8",maxBuffer:yo});return{state:"tracked",content:r}}catch{return{state:"untracked",content:null}}}i(dr,"readGitHeadFile");function ko(e){return xo(e)||"project"}i(ko,"folderName");function Eo(e,t){if(typeof t!="string")return e;let r=t.trim();return r.length===0||/<[^>]+>/.test(e)?e:`${e} <${r}>`}i(Eo,"formatAuthorNameWithCompany");async function So(e,t={}){let r=Array.isArray(t.detectors)?t.detectors:F(t),n=typeof t.preferredExtension=="string"?t.preferredExtension.trim().toLowerCase():"",o=n.length>0?r.find(u=>u.extensions.includes(n)):void 0,a=await ar(e,{drivers:t.drivers,language:o?.id,scanRoot:t.scanRoot}),s=a?a.root:Ae(e),c=a?.sources.name,l=a?.sources.company;return{language:o?.id??a?.drivers[0]??"unknown",rootDir:s,marker:a?a.marker:null,projectName:a?.fields.name??ko(s),projectNameSource:c?{from:"manifest",...c}:{from:"folder",dir:s},companyName:a?.fields.company??null,companyNameSource:l?{from:"manifest",...l}:{from:"none"},drivers:a?a.drivers:[]}}i(So,"detectProjectFromMarkers");async function De(e={}){let t=e.targetFilePath||e.cwd||process.cwd(),r=Ae(t),n=F(e),o=e.targetFilePath?wo(r):r,a=e.targetFilePath?bo(r).toLowerCase():"",s=Ae(e.projectRoot||e.cwd||process.cwd()),c=await So(o,{detectors:n,preferredExtension:a,scanRoot:s}),l=await cr(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:Eo(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(De,"resolveProjectMetadata");function $o(e){return ve({year:e.getFullYear(),month:e.getMonth()+1,day:e.getDate(),hour:e.getHours(),minute:e.getMinutes(),second:e.getSeconds(),offsetMinutes:-e.getTimezoneOffset()})}i($o,"formatDateWithTimezone");function ve(e){return`${gr(e," ")} ${yr(e.offsetMinutes)}`}i(ve,"formatSpaceDate");function pr(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{hr(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(pr,"assertTimeZone");var mr=new Map;function hr(e){let t=mr.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"}),mr.set(e,t)),t}i(hr,"getZoneFormatter");function Ce(e,t){let r={};for(let o of hr(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(Ce,"toZonedDateParts");function gr(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(gr,"formatWallClock");function yr(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(yr,"formatOffset");function Q(e=new Date){return{date:$o(e),timestamp:Math.floor(e.getTime()/1e3)}}i(Q,"toDatePayload");var Ao=/^(\d{4})-(\d{2})-(\d{2})(?:T|\s+)(\d{2}):(\d{2}):(\d{2})(?:\.\d+)?\s*(?:(Z)|([+-])(\d{2}):?(\d{2}))$/i;function M(e){let t=Ao.exec(e.trim());if(!t)return null;let[r,n,o,a,s,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,a,s,c));return!(f.getUTCFullYear()===r&&f.getUTCMonth()===n-1&&f.getUTCDate()===o&&f.getUTCHours()===a&&f.getUTCMinutes()===s&&f.getUTCSeconds()===c)||Number(t[10]??0)>59?null:{year:r,month:n,day:o,hour:a,minute:s,second:c,offsetMinutes:u,timestamp:Math.floor(f.getTime()/1e3)-u*60}}i(M,"parseHeaderDate");function Ne(e){return`${gr(e,"T")}${yr(e.offsetMinutes)}`}i(Ne,"formatIsoDate");var Do={"git-created":"git first commit","filesystem-created":"filesystem creation time"};function xr(e,t){let r=e.match(new RegExp(`${t}:[^\\S\\n]*(.*)$`,"m"));return r?r[1].trim():null}i(xr,"readHeaderField");function Fe(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(Fe,"pickOldestDate");function br({existing:e,gitCreated:t,filesystemCreated:r,fixCreatedDate:n=!1}){let o=[{source:"git-created",payload:t},{source:"filesystem-created",payload:r}];if(!e)return Fe(o);if(!n)return{source:"existing-header",payload:e};let a=M(e.date)?e:null;return Fe([{source:"existing-header",payload:a},...o])}i(br,"resolveCreatedDate");function kr(e,t=null){if(t)return Ce(e.timestamp,t).year;let r=M(e.date);return r?r.year:new Date(e.timestamp*1e3).getFullYear()}i(kr,"dateYear");function wr(e,t,r,n){let o=e.match(/^(.+?)\s*\((\d+)\)$/),a=o?M(o[1]):null;if(!o||!a)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 s=Number.parseInt(o[2],10);return s!==a.timestamp&&n.push({check:`${r}-epoch`,field:t,advisory:!1,value:e,expected:`${o[1]} (${a.timestamp})`,message:`${t} epoch ${s} does not match ${o[1]} (expected ${a.timestamp})`}),{text:o[1],timestamp:a.timestamp}}i(wr,"checkDateValue");function Er(e,t={},r={}){let n=[],o=xr(e,"@Date"),a=o===null?null:wr(o,"@Date","created",n),s=Fe([{source:"git-created",payload:t.gitCreated},{source:"filesystem-created",payload:t.filesystemCreated}]);if(a&&s&&a.timestamp>s.payload.timestamp){let f=Do[s.source];n.push({check:"created-newer-than-source",field:"@Date",advisory:r.strictCreatedDate!==!0,value:o,expected:`${s.payload.date} (${s.payload.timestamp})`,source:s.source,message:`@Date ${a.text} is later than the ${f} ${s.payload.date} (${s.payload.timestamp})`})}let c=xr(e,"@Last modified time"),l=c===null?null:wr(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(Er,"checkHeaderDates");function je(e){if(!e)return null;let t=M(e.date);return t&&t.timestamp!==e.timestamp?{date:e.date,timestamp:t.timestamp}:e}i(je,"repairDateEpoch");function Sr(e){let t=M(e.date);return t?{date:Ne(t),timestamp:t.timestamp}:e}i(Sr,"normalizeDatePayload");function $r(e,t){let r=M(e.date);if(!r)return e;let n=Ce(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())?Ne(n):ve(n),timestamp:r.timestamp}}i($r,"convertDatePayload");import{relative as Co}from"node:path";import{extname as vo}from"node:path";function G(e,t={}){let r=vo(e).toLowerCase(),n=j(t.spacing,"spacing",B);return r.length===0?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */",spacing:n}:{...Ct(e,t),spacing:n}}i(G,"getHeaderSyntaxForFile");function Ar(e,t){let r=e.spacing??B;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(`
7
7
  `)}let n=e.blockStart||(e.kind==="html"?"<!--":"/**"),o=e.blockLinePrefix||(e.kind==="html"?" ":" * "),a=e.blockEnd||(e.kind==="html"?"-->":" */"),s=Array.from({length:r},()=>o.trimEnd());return[n,...s,...t.map(c=>`${o}${c}`),...s,a].join(`
8
- `)}i(lr,"renderHeaderLines");function ve(e){let t=`/${eo(e.projectRoot,e.absoluteFilePath).replace(/\\/g,"/")}`,r=T(e.absoluteFilePath,e.syntaxOptions||{language:e.language}),n=e.createdByName||e.authorName,o=e.createdByEmail||e.authorEmail,a=e.lastModifiedByName||e.authorName,s=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: ${a} (${s})`,`@Last modified time: ${e.lastModifiedAt.date} (${e.lastModifiedAt.timestamp})`,"-----",`@Copyright: Copyright (c) ${e.copyrightStartYear}-${e.currentYear} ${l}All rights reserved.`];return lr(r,u)}i(ve,"buildHeader");var to=Object.freeze(["projectName","filename","createdAt","authorName","authorEmail","lastModifiedByName","lastModifiedByEmail","lastModifiedAt","copyrightStartYear","copyrightEndYear","companyName"]);function $(e,t){let r=e.match(new RegExp(`@${t}:[ \\t]*(.*)$`,"m")),n=r?r[1].trim():"";return n.length>0?n:null}i($,"readTag");function ro(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(ro,"splitLastModifiedBy");function no(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 a=n.toLowerCase(),s=a.endsWith("all rights reserved.")?20:a.endsWith("all rights reserved")?19:0;return s===0||!/^\s/.test(n)?t:{startYear:r[1],endYear:o?o[1]:null,companyName:n.slice(0,-s).trim()||null}}i(no,"splitCopyright");function ur(e){let t=ro($(e,"Last modified by")),r=no($(e,"Copyright")),n=$(e,"Email");return{projectName:$(e,"Project"),filename:$(e,"Filename"),createdAt:$(e,"Date"),authorName:$(e,"Author"),authorEmail:n===null?null:n.replace(/^<(.*)>$/,"$1"),lastModifiedByName:t.name,lastModifiedByEmail:t.email,lastModifiedAt:$(e,"Last modified time"),copyrightStartYear:r.startYear,copyrightEndYear:r.endYear,companyName:r.companyName}}i(ur,"parseHeaderFields");function dr(e,t){let r=ur(e??""),n=ur(t);return to.filter(o=>r[o]!==n[o]).map(o=>({field:o,previous:r[o],detected:n[o]}))}i(dr,"compareHeaderFields");function X(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}i(X,"escapeRegex");function mr(e,t,r={}){let n=mt(e,t,r);return n.length===0?{prefix:"",body:t}:{prefix:n,body:t.slice(n.length)}}i(mr,"splitPreservedPrefix");function fr(e,t){if(t.kind==="html"){let n=X(t.blockStart||"<!--"),o=X(t.blockEnd||"-->");return e.match(new RegExp(`^${n}[\\s\\S]*?${o}\\n*`))}if(t.kind==="line"){let n=X(t.linePrefix||"#");return e.match(new RegExp(`^(?:${n}.*\\n)+\\n*`))}let r=X((t.blockEnd||" */").trim());return e.match(new RegExp(`^/\\*[\\s\\S]*?${r}\\n*`))}i(fr,"matchHeaderSegment");function Ne(e,t="",r={}){let{prefix:n,body:o}=mr(t,e,r),a=o.split(`
9
- `).slice(0,pt).join(`
10
- `),s=T(t,r);if(!fr(a,s))return null;let l=0,u=0;for(;;){let f=a.slice(l),p=fr(f,s);if(!p||!p[0].includes("@Project:"))break;l+=p[0].length,u=l}return u===0?null:{start:n.length,end:n.length+u}}i(Ne,"findProjectHeader");function Ce(e,t,r="",n={}){let o=Ne(e,r,n),a=N(n.margin,"margin",J),s=T(r,n).kind==="line"?Math.max(1,a):a,c=`
8
+ `)}i(Ar,"renderHeaderLines");function Dr(e){let t=`/${Co(e.projectRoot,e.absoluteFilePath).replace(/\\/g,"/")}`,r=G(e.absoluteFilePath,e.syntaxOptions||{language:e.language}),n=e.createdByName||e.authorName,o=e.createdByEmail||e.authorEmail,a=e.lastModifiedByName||e.authorName,s=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: ${a} (${s})`,`@Last modified time: ${e.lastModifiedAt.date} (${e.lastModifiedAt.timestamp})`,"-----",`@Copyright: Copyright (c) ${e.copyrightStartYear}-${e.currentYear} ${l}All rights reserved.`];return Ar(r,u)}i(Dr,"buildHeader");var No=Object.freeze(["projectName","filename","createdAt","authorName","authorEmail","lastModifiedByName","lastModifiedByEmail","lastModifiedAt","copyrightStartYear","copyrightEndYear","companyName"]);function C(e,t){let r=e.match(new RegExp(`@${t}:[ \\t]*(.*)$`,"m")),n=r?r[1].trim():"";return n.length>0?n:null}i(C,"readTag");function Fo(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(Fo,"splitLastModifiedBy");function jo(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 a=n.toLowerCase(),s=a.endsWith("all rights reserved.")?20:a.endsWith("all rights reserved")?19:0;return s===0||!/^\s/.test(n)?t:{startYear:r[1],endYear:o?o[1]:null,companyName:n.slice(0,-s).trim()||null}}i(jo,"splitCopyright");function vr(e){let t=Fo(C(e,"Last modified by")),r=jo(C(e,"Copyright")),n=C(e,"Email");return{projectName:C(e,"Project"),filename:C(e,"Filename"),createdAt:C(e,"Date"),authorName:C(e,"Author"),authorEmail:n===null?null:n.replace(/^<(.*)>$/,"$1"),lastModifiedByName:t.name,lastModifiedByEmail:t.email,lastModifiedAt:C(e,"Last modified time"),copyrightStartYear:r.startYear,copyrightEndYear:r.endYear,companyName:r.companyName}}i(vr,"parseHeaderFields");function Cr(e,t){let r=vr(e??""),n=vr(t);return No.filter(o=>r[o]!==n[o]).map(o=>({field:o,previous:r[o],detected:n[o]}))}i(Cr,"compareHeaderFields");function ee(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}i(ee,"escapeRegex");function Le(e,t,r={}){let n=Nt(e,t,r);return n.length===0?{prefix:"",body:t}:{prefix:n,body:t.slice(n.length)}}i(Le,"splitPreservedPrefix");function Nr(e,t){if(t.kind==="html"){let n=ee(t.blockStart||"<!--"),o=ee(t.blockEnd||"-->");return e.match(new RegExp(`^${n}[\\s\\S]*?${o}\\n*`))}if(t.kind==="line"){let n=ee(t.linePrefix||"#");return e.match(new RegExp(`^(?:${n}.*\\n)+\\n*`))}let r=ee((t.blockEnd||" */").trim());return e.match(new RegExp(`^/\\*[\\s\\S]*?${r}\\n*`))}i(Nr,"matchHeaderSegment");function te(e,t="",r={}){let{prefix:n,body:o}=Le(t,e,r),a=o.split(`
9
+ `).slice(0,Ft).join(`
10
+ `),s=G(t,r);if(!Nr(a,s))return null;let l=0,u=0;for(;;){let f=a.slice(l),m=Nr(f,s);if(!m||!m[0].includes("@Project:"))break;l+=m[0].length,u=l}return u===0?null:{start:n.length,end:n.length+u}}i(te,"findProjectHeader");function Me(e,t,r="",n={}){let o=te(e,r,n),a=j(n.margin,"margin",X),s=G(r,n).kind==="line"?Math.max(1,a):a,c=`
11
11
  `.repeat(s+1),l=i(g=>g.trim()===""?`${t}
12
- `:`${t}${c}${g}`,"join");if(!o){let{prefix:g,body:y}=mr(r,e,n),m=`${g}${l(y.replace(/^\n+/,""))}`;return{nextContent:m,changed:m!==e}}let u=e.slice(0,o.start),f=e.slice(o.end).replace(/^\n+/,""),p=`${u}${l(f)}`;return{nextContent:p,changed:p!==e}}i(Ce,"replaceOrInsertHeader");function oo(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 a=[],s=0,c=0;for(;s<r&&c<n;)e[s]===t[c]?(a.push({type:" ",line:e[s]}),s+=1,c+=1):o[s+1][c]>=o[s][c+1]?(a.push({type:"-",line:e[s]}),s+=1):(a.push({type:"+",line:t[c]}),c+=1);for(;s<r;s+=1)a.push({type:"-",line:e[s]});for(;c<n;c+=1)a.push({type:"+",line:t[c]});return a}i(oo,"diffLines");function pr(e,t){return`${t===0?e:e+1},${t}`}i(pr,"formatRange");function hr(e,t,r={}){let n=e===null?[]:e.split(`
12
+ `:`${t}${c}${g}`,"join");if(!o){let{prefix:g,body:x}=Le(r,e,n),d=`${g}${l(x.replace(/^\n+/,""))}`;return{nextContent:d,changed:d!==e}}let u=e.slice(0,o.start),f=e.slice(o.end).replace(/^\n+/,""),m=`${u}${l(f)}`;return{nextContent:m,changed:m!==e}}i(Me,"replaceOrInsertHeader");function Re(e,t="",r={}){let n=te(e,t,r),{prefix:o,body:a}=n?{prefix:e.slice(0,n.start),body:e.slice(n.end)}:Le(t,e,r),s=a.replace(/^\n+/,"");return`${o}${s.trim()===""?"":s}`}i(Re,"extractHeaderlessBody");function Lo(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 a=[],s=0,c=0;for(;s<r&&c<n;)e[s]===t[c]?(a.push({type:" ",line:e[s]}),s+=1,c+=1):o[s+1][c]>=o[s][c+1]?(a.push({type:"-",line:e[s]}),s+=1):(a.push({type:"+",line:t[c]}),c+=1);for(;s<r;s+=1)a.push({type:"-",line:e[s]});for(;c<n;c+=1)a.push({type:"+",line:t[c]});return a}i(Lo,"diffLines");function Fr(e,t){return`${t===0?e:e+1},${t}`}i(Fr,"formatRange");function jr(e,t,r={}){let n=e===null?[]:e.split(`
13
13
  `),o=t.split(`
14
- `),a=oo(n,o),s=Math.max(0,r.context??3),c=r.lineOffset??0,l=[];if(a.forEach((g,y)=>{if(g.type===" ")return;let m=l[l.length-1];m&&y-m.last<=s*2+1?m.last=y:l.push({first:y,last:y})}),l.length===0)return"";let u=r.fromFile??"a",f=r.toFile??"b",p=[`--- ${e===null?"/dev/null":u}`,`+++ ${f}`];for(let g of l){let y=Math.max(0,g.first-s),m=Math.min(a.length,g.last+s+1),h=a.slice(0,y),w=a.slice(y,m),S=h.filter(d=>d.type!=="+").length+c,A=h.filter(d=>d.type!=="-").length+c,U=w.filter(d=>d.type!=="+").length,x=w.filter(d=>d.type!=="-").length;p.push(`@@ -${pr(S,U)} +${pr(A,x)} @@`);for(let d of w)p.push(`${d.type}${d.line}`)}return p.join(`
15
- `)}i(hr,"createUnifiedDiff");function co(e){return V(e,"configFile")}i(co,"resolveRuntimeOptions");function lo(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(lo,"extractHeaderAuthorIdentity");function uo(e){let t=e.match(/@Last modified by:\s*(.+?)\s*\(([^)\n]+)\)\s*$/m);return{authorName:t?.[1]?.trim(),authorEmail:t?.[2]?.trim()}}i(uo,"extractHeaderLastModifiedIdentity");function fo(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(fo,"extractHeaderCreatedAt");function mo(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(mo,"extractHeaderLastModifiedAt");async function xr(e={}){let t=await co(e),r=t.timezone===void 0||t.timezone===null?null:Zt(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=yr(t.projectRoot||t.cwd||process.cwd()),a=await Ee({...t,cwd:o});N(t.spacing,"spacing",R),N(t.margin,"margin",J);let s=t.check===!0,c=s||t.dryRun===!0,l=t.fixCreatedDate===!0,u=i(x=>x,"keepDate"),f=t.normalizeDateFormat===!0?sr:u,p=r?x=>cr(x,r):u,g=n?p:u,y;if(typeof t.input=="string"&&t.input.trim().length>0){let x=yr(o,t.input),d=await ao(x).catch(()=>null);if(!d)throw new Error(`Input path does not exist: ${t.input}`);if(d.isFile())y=[x];else if(d.isDirectory())y=await he({projectRoot:x,language:a.language,enabledDetectors:t.enabledDetectors,disabledDetectors:t.disabledDetectors,includeFolders:t.includeFolders,excludeFolders:t.excludeFolders,includeExtensions:t.includeExtensions,gitignore:t.gitignore});else throw new Error(`Input path must be a file or directory: ${t.input}`)}else y=await he({projectRoot:o,language:a.language,enabledDetectors:t.enabledDetectors,disabledDetectors:t.disabledDetectors,includeFolders:t.includeFolders,excludeFolders:t.excludeFolders,includeExtensions:t.includeExtensions,gitignore:t.gitignore});let m=new Date().getFullYear(),h=[],w=new Set,S=0,A=0,U=0;for(let x of y){let d=await Ee({...t,cwd:o,targetFilePath:x});w.add(`${d.language}:${d.projectRoot}`);let je=gr(o,x),_=await io(x,"utf8"),Z=Ne(_,x,{language:d.language,enabledDetectors:t.enabledDetectors,disabledDetectors:t.disabledDetectors,detectorSyntaxOverrides:t.detectorSyntaxOverrides,spacing:t.spacing,margin:t.margin}),E=Z?_.slice(Z.start,Z.end):"",H=E.length>0?lo(E):{},z=E.length>0?uo(E):{},Dr=E.length>0?fo(E):null,kr=E.length>0?mo(E):null,Le=await ht(x),Me=gr(d.projectRoot,x),Pe=await Kt(d.projectRoot,Me),Q=await qt(d.projectRoot,Me),Re=q(Le.createdAt),ee=or({existing:$e(Dr),gitCreated:Pe,filesystemCreated:Re,fixCreatedDate:l}),te=$e(kr),Ie=ee.source,Ar=te?"existing-header":Q?"git-last-modified":"filesystem-updated",B=f(Ie==="existing-header"?g(ee.payload):p(ee.payload)),$r=d.copyrightStartYear===null?"created-date":"option",re=d.copyrightStartYear??ir(B,r),Oe=f(te?g(te):p(Q||q(Le.updatedAt))),W=t.forceAuthorUpdate===!0,Y=t.forceLastModifiedAuthorUpdate===!0,Te=ve({absoluteFilePath:x,language:d.language,syntaxOptions:{language:d.language,enabledDetectors:t.enabledDetectors,disabledDetectors:t.disabledDetectors,detectorSyntaxOverrides:t.detectorSyntaxOverrides,spacing:t.spacing,margin:t.margin},projectRoot:d.projectRoot,projectName:d.projectName,createdByName:W?d.authorName:H.authorName||d.authorName,createdByEmail:W?d.authorEmail:H.authorEmail||d.authorEmail,lastModifiedByName:Y?d.authorName:z.authorName||d.authorName,lastModifiedByEmail:Y?d.authorEmail:z.authorEmail||d.authorEmail,authorName:d.authorName,authorEmail:d.authorEmail,createdAt:B,lastModifiedAt:Oe,copyrightStartYear:re,companyName:d.companyName,currentYear:m}),Ue=Ce(_,Te,x,{language:d.language,enabledDetectors:t.enabledDetectors,disabledDetectors:t.disabledDetectors,detectorSyntaxOverrides:t.detectorSyntaxOverrides,spacing:t.spacing,margin:t.margin}),G=Ue.changed,_e=G?f(p(q(new Date))):Oe,vr=G?"current-time-on-change":Ar,M=G?ve({absoluteFilePath:x,language:d.language,syntaxOptions:{language:d.language,enabledDetectors:t.enabledDetectors,disabledDetectors:t.disabledDetectors,detectorSyntaxOverrides:t.detectorSyntaxOverrides,spacing:t.spacing,margin:t.margin},projectRoot:d.projectRoot,projectName:d.projectName,createdByName:W?d.authorName:H.authorName||d.authorName,createdByEmail:W?d.authorEmail:H.authorEmail||d.authorEmail,lastModifiedByName:Y?d.authorName:z.authorName||d.authorName,lastModifiedByEmail:Y?d.authorEmail:z.authorEmail||d.authorEmail,authorName:d.authorName,authorEmail:d.authorEmail,createdAt:B,lastModifiedAt:_e,copyrightStartYear:re,companyName:d.companyName,currentYear:m}):Te,j=G?Ce(_,M,x,{language:d.language,enabledDetectors:t.enabledDetectors,disabledDetectors:t.disabledDetectors,detectorSyntaxOverrides:t.detectorSyntaxOverrides,spacing:t.spacing,margin:t.margin}):Ue,ne={file:je,changed:j.changed};if(s){let v=ar(E,{gitCreated:Pe,gitLastModified:Q,filesystemCreated:Re},{strictCreatedDate:t.strictCreatedDate===!0}),P=v.filter(oe=>oe.advisory).length;ne.dateIssues=v,U+=P,A+=v.length>P?1:0}if(t.sampleOutput===!0&&j.changed){let v=E.length>0?E.trimEnd():null,P=je.replace(/\\/g,"/"),oe=j.nextContent.slice(0,j.nextContent.indexOf(M)).split(`
16
- `).length-1;ne.sample={previousValue:v,newValue:M,diff:hr(v,M,{fromFile:`a/${P}`,toFile:`b/${P}`,lineOffset:oe}),issues:dr(v,M),detectedValues:{projectName:d.projectName,projectNameSource:d.projectNameSource,language:d.language,projectRoot:d.projectRoot,marker:d.marker,authorName:d.authorName,authorEmail:d.authorEmail,companyName:d.companyName,companyNameSource:d.companyNameSource,copyrightStartYear:re,copyrightStartYearSource:$r,createdAtSource:Ie,lastModifiedAtSource:vr,createdAt:B,lastModifiedAt:_e}}}h.push(ne),j.changed&&(S+=1,c||await so(x,j.nextContent,"utf8"))}return{metadata:a,detectedProjects:Array.from(w),filesScanned:y.length,filesUpdated:S,dryRun:c,check:s,...s?{filesWithDateDrift:A,dateAdvisories:U}:{},changes:h}}i(xr,"fixHeaders");function po(e){return xr(e)}i(po,"fixHeaders");var br=po;var yo=`fix-headers CLI
14
+ `),a=Lo(n,o),s=Math.max(0,r.context??3),c=r.lineOffset??0,l=[];if(a.forEach((g,x)=>{if(g.type===" ")return;let d=l[l.length-1];d&&x-d.last<=s*2+1?d.last=x:l.push({first:x,last:x})}),l.length===0)return"";let u=r.fromFile??"a",f=r.toFile??"b",m=[`--- ${e===null?"/dev/null":u}`,`+++ ${f}`];for(let g of l){let x=Math.max(0,g.first-s),d=Math.min(a.length,g.last+s+1),h=a.slice(0,x),b=a.slice(x,d),$=h.filter(k=>k.type!=="+").length+c,v=h.filter(k=>k.type!=="-").length+c,R=b.filter(k=>k.type!=="+").length,V=b.filter(k=>k.type!=="-").length;m.push(`@@ -${Fr($,R)} +${Fr(v,V)} @@`);for(let k of b)m.push(`${k.type}${k.line}`)}return m.join(`
15
+ `)}i(jr,"createUnifiedDiff");function Io(e){return q(e,"configFile")}i(Io,"resolveRuntimeOptions");function Oo(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(Oo,"resolveInputs");function To(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(To,"extractHeaderAuthorIdentity");function Ho(e){let t=e.match(/@Last modified by:\s*(.+?)\s*\(([^)\n]+)\)\s*$/m);return{authorName:t?.[1]?.trim(),authorEmail:t?.[2]?.trim()}}i(Ho,"extractHeaderLastModifiedIdentity");function _o(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(_o,"extractHeaderCreatedAt");function Uo(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(Uo,"extractHeaderLastModifiedAt");async function zo(e,t,r){let n=await dr(t);return n.state!=="tracked"?{edited:n.state==="untracked",state:n.state}:{edited:Re(n.content,t,r)!==Re(e,t,r),state:"tracked"}}i(zo,"detectContentEdit");async function Mr(e={}){let t=await Io(e),r=t.timezone===void 0||t.timezone===null?null:pr(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=At(t.forcedDetectors),a=Lr(t.projectRoot||t.cwd||process.cwd()),s=await De({...t,cwd:a});j(t.spacing,"spacing",B),j(t.margin,"margin",X);let c=t.check===!0,l=c||t.dryRun===!0,u=t.fixCreatedDate===!0,f=i(y=>y,"keepDate"),m=t.normalizeDateFormat===!0?Sr:f,g=r?y=>$r(y,r):f,x=n?g:f,d={language:s.language,enabledDetectors:t.enabledDetectors,disabledDetectors:t.disabledDetectors,forcedDetectors:o,includeFolders:t.includeFolders,excludeFolders:t.excludeFolders,includeExtensions:t.includeExtensions,gitignore:t.gitignore},h=Oo(t.input),b;if(h.length>0){let y=new Set;for(let P of h){let p=Lr(a,P),I=await Ro(p).catch(()=>null);if(!I)throw new Error(`Input path does not exist: ${P}`);if(I.isFile())y.add(p);else if(I.isDirectory())for(let N of await we({...d,projectRoot:p}))y.add(N);else throw new Error(`Input path must be a file or directory: ${P}`)}b=Array.from(y)}else b=await we({...d,projectRoot:a});let $=new Date().getFullYear(),v=[],R=[],V=new Set,k=0,Oe=0,Te=0;for(let y of b){let P=vt(y,{enabledDetectors:t.enabledDetectors,disabledDetectors:t.disabledDetectors,forcedDetectors:o});if(P!==null){R.push({file:Pe(a,y),reason:P});continue}let p=await De({...t,cwd:a,targetFilePath:y});V.add(`${p.language}:${p.projectRoot}`);let I=Pe(a,y),N=await Mo(y,"utf8"),T={language:p.language,enabledDetectors:t.enabledDetectors,disabledDetectors:t.disabledDetectors,forcedDetectors:o,detectorSyntaxOverrides:t.detectorSyntaxOverrides,spacing:t.spacing,margin:t.margin},re=te(N,y,T),E=re?N.slice(re.start,re.end):"",He=E.length>0?To(E):{},_e=E.length>0?Ho(E):{},Tr=E.length>0?_o(E):null,Hr=E.length>0?Uo(E):null,Ue=await jt(y),ze=Pe(p.projectRoot,y),Be=await ur(p.projectRoot,ze),H=await fr(p.projectRoot,ze),We=Q(Ue.createdAt),ne=br({existing:je(Tr),gitCreated:Be,filesystemCreated:We,fixCreatedDate:u}),_=je(Hr),Ye=ne.source,_r=_?"existing-header":H?"git-last-modified":"filesystem-updated",oe=m(Ye==="existing-header"?x(ne.payload):g(ne.payload)),Ur=p.copyrightStartYear===null?"created-date":"option",Ge=p.copyrightStartYear??kr(oe,r),Ve=m(_?x(_):g(H||Q(Ue.updatedAt))),Je=t.forceAuthorUpdate===!0,zr=t.forceLastModifiedAuthorUpdate===!0,qe=await zo(N,y,T),Ke=zr||qe.edited,Xe=i(D=>Dr({absoluteFilePath:y,language:p.language,syntaxOptions:T,projectRoot:p.projectRoot,projectName:p.projectName,createdByName:Je?p.authorName:He.authorName||p.authorName,createdByEmail:Je?p.authorEmail:He.authorEmail||p.authorEmail,lastModifiedByName:Ke?p.authorName:_e.authorName||p.authorName,lastModifiedByEmail:Ke?p.authorEmail:_e.authorEmail||p.authorEmail,authorName:p.authorName,authorEmail:p.authorEmail,createdAt:oe,lastModifiedAt:D,copyrightStartYear:Ge,companyName:p.companyName,currentYear:$}),"renderHeader"),Ze=Xe(Ve),Qe=Me(N,Ze,y,T),Br=qe.edited&&_!==null&&H!==null&&_.timestamp<H.timestamp,J=Qe.changed||Br,et=J?m(g(Q(new Date))):Ve,Wr=J?"current-time-on-change":_r,U=J?Xe(et):Ze,O=J?Me(N,U,y,T):Qe,ie={file:I,changed:O.changed};if(c){let D=Er(E,{gitCreated:Be,gitLastModified:H,filesystemCreated:We},{strictCreatedDate:t.strictCreatedDate===!0}),z=D.filter(ae=>ae.advisory).length;ie.dateIssues=D,Te+=z,Oe+=D.length>z?1:0}if(t.sampleOutput===!0&&O.changed){let D=E.length>0?E.trimEnd():null,z=I.replace(/\\/g,"/"),ae=O.nextContent.slice(0,O.nextContent.indexOf(U)).split(`
16
+ `).length-1;ie.sample={previousValue:D,newValue:U,diff:jr(D,U,{fromFile:`a/${z}`,toFile:`b/${z}`,lineOffset:ae}),issues:Cr(D,U),detectedValues:{projectName:p.projectName,projectNameSource:p.projectNameSource,language:p.language,projectRoot:p.projectRoot,marker:p.marker,authorName:p.authorName,authorEmail:p.authorEmail,companyName:p.companyName,companyNameSource:p.companyNameSource,copyrightStartYear:Ge,copyrightStartYearSource:Ur,createdAtSource:Ye,lastModifiedAtSource:Wr,createdAt:oe,lastModifiedAt:et}}}v.push(ie),O.changed&&(k+=1,l||await Po(y,O.nextContent,"utf8"))}return{metadata:s,detectedProjects:Array.from(V),filesScanned:b.length-R.length,filesUpdated:k,filesSkipped:R.length,dryRun:l,check:c,...c?{filesWithDateDrift:Oe,dateAdvisories:Te}:{},changes:v,skipped:R}}i(Mr,"fixHeaders");function Bo(e){return Mr(e)}i(Bo,"fixHeaders");var Rr=Bo;var Go=`fix-headers CLI
17
17
 
18
18
  Usage:
19
19
  fix-headers [options]
@@ -31,17 +31,18 @@ Options:
31
31
  --verbose Print updated file paths in summary mode; with --sample-output or --diff, also print each file's field differences
32
32
  --sample-output Show previous/new header sample for changed files
33
33
  --diff Print a unified diff of each changed file's header (implies sample output)
34
- --force-author-update Always update @Author/@Email to detected/current values
35
- --force-last-modified-author-update Always update @Last modified by to detected/current values
34
+ --force-author-update Replace an existing @Author/@Email with the detected/current values
35
+ --force-last-modified-author-update Write the detected identity as @Last modified by on every file, edited or not
36
36
  --use-gpg-signer-author Use signed-commit UID (%GS) for detected @Author
37
37
  --cwd <path> Working directory for project detection
38
- --input <path> Single file or folder input
38
+ --input <path> File or folder to process instead of the whole project (repeatable)
39
39
  --include-folder <path> Include folder (repeatable)
40
40
  --include-folder-non-recursive <path> Include only a folder's own files, not its subfolders (repeatable)
41
41
  --exclude-folder <path> Exclude folder name/path (repeatable)
42
42
  --include-extension <ext> Include extension (repeatable)
43
43
  --enable-detector <id> Enable only specific detector (repeatable)
44
44
  --disable-detector <id> Disable detector by id (repeatable)
45
+ --force-detector <id> Use a force-only detector, e.g. markdown (HTML-comment headers in .md files) (repeatable)
45
46
  --project-name <name> Override project name
46
47
  --language <id> Override language id
47
48
  --project-root <path> Override project root
@@ -61,5 +62,5 @@ Examples:
61
62
  fix-headers --check --verbose
62
63
  fix-headers --timezone America/Los_Angeles --convert-timezone
63
64
  fix-headers --project-name @scope/pkg --company-name "Catalyzed Motivation Inc."
64
- `;function xo(e){return e.replace(/-([a-z])/g,(t,r)=>r.toUpperCase())}i(xo,"toCamelCase");function bo(e){let t={},r={help:!1,json:!1,diff:!1},n={"include-folder":"includeFolders","exclude-folder":"excludeFolders","include-extension":"includeExtensions","enable-detector":"enabledDetectors","disable-detector":"disabledDetectors"},o={cwd:"cwd",input:"input","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 a=0;a<e.length;a+=1){let s=e[a];if(s==="-h"||s==="--help"){r.help=!0;continue}if(s==="--json"){r.json=!0;continue}if(s==="--diff"){r.diff=!0;continue}if(s==="--verbose"){t.verbose=!0;continue}if(s==="--dry-run"){t.dryRun=!0;continue}if(s==="--check"){t.check=!0;continue}if(s==="--fix-created-date"){t.fixCreatedDate=!0;continue}if(s==="--strict-created-date"){t.strictCreatedDate=!0;continue}if(s==="--normalize-date-format"){t.normalizeDateFormat=!0;continue}if(s==="--convert-timezone"){t.convertTimezone=!0;continue}if(s==="--sample-output"){t.sampleOutput=!0;continue}if(s==="--force-author-update"){t.forceAuthorUpdate=!0;continue}if(s==="--force-last-modified-author-update"){t.forceLastModifiedAuthorUpdate=!0;continue}if(s==="--use-gpg-signer-author"){t.useGpgSignerAuthor=!0;continue}if(!s.startsWith("--"))throw new Error(`Unexpected argument: ${s}`);let c=s.slice(2);if(c==="include-folder-non-recursive"){let f=e[a+1];if(!f||f.startsWith("--"))throw new Error(`Missing value for --${c}`);a+=1;let p=Array.isArray(t.includeFolders)?t.includeFolders:[];t.includeFolders=[...p,{path:f,recursive:!1}];continue}if(n[c]){let f=e[a+1];if(!f||f.startsWith("--"))throw new Error(`Missing value for --${c}`);a+=1;let p=n[c],g=Array.isArray(t[p])?t[p]:[];t[p]=Array.from(new Set([...g,f]));continue}if(o[c]){let f=e[a+1];if(!f||f.startsWith("--"))throw new Error(`Missing value for --${c}`);a+=1;let p=o[c];if(p==="copyrightStartYear"||p==="spacing"||p==="margin"){if(t[p]=Number.parseInt(f,10),Number.isNaN(t[p]))throw new Error(`Invalid number for --${c}: ${f}`)}else p==="marker"&&f==="null"?t[p]=null:t[p]=f;continue}let l=xo(c),u=e[a+1];if(!u||u.startsWith("--"))throw new Error(`Unknown or malformed flag: --${c}`);a+=1,t[l]=u}return{options:t,help:r.help,json:r.json,diff:r.diff}}i(bo,"parseCliArgs");function wo(e){return V(e,"config")}i(wo,"applyConfigFile");function Fe(e){if(!e||typeof e!="object")return[];let t=e;return(Array.isArray(t.changes)?t.changes:[]).filter(n=>n&&n.changed===!0&&n.sample&&typeof n.sample.newValue=="string")}i(Fe,"getSampledChanges");function Er(e){return typeof e=="string"?`"${e}"`:"(missing)"}i(Er,"formatIssueValue");function Eo(e,t){for(let r of Fe(t)){let n=Array.isArray(r.sample.issues)?r.sample.issues:[];if(e(`issues: ${r.file||"<unknown-file>"}`),n.length===0){e(" (no field differences; header formatting only)");continue}for(let o of n)e(` ${o?.field||"<unknown-field>"}: found ${Er(o?.previous)}, expected ${Er(o?.detected)}`)}}i(Eo,"printIssues");function So(e,t){for(let r of Fe(t))typeof r.sample.diff=="string"&&r.sample.diff.length>0&&e(r.sample.diff)}i(So,"printDiffs");function Do(e,t){for(let r of Fe(t))e(`sample: ${r.file||"<unknown-file>"}`),e("previous:"),e(r.sample.previousValue===null?"(none)":String(r.sample.previousValue)),e("new:"),e(r.sample.newValue),r.sample.detectedValues&&typeof r.sample.detectedValues=="object"&&(e("detected-values:"),e(JSON.stringify(r.sample.detectedValues,null,2)))}i(Do,"printSampleOutput");function ko(e,t){if(!t||typeof t!="object")return;let r=t,o=(Array.isArray(r.changes)?r.changes:[]).filter(a=>a&&a.changed===!0).map(a=>a.file||"<unknown-file>");for(let a of o)e(`updated: ${a}`)}i(ko,"printChangedFiles");function Sr(e,t,r,n){let o=r.sampleOutput===!0||n;r.verbose===!0&&(ko(e,t),o&&Eo(e,t)),r.sampleOutput===!0&&Do(e,t),n&&So(e,t)}i(Sr,"printDetails");function Ao(e,t,r){let n=Array.isArray(t.changes)?t.changes:[];for(let o of n){let a=Array.isArray(o?.dateIssues)?o.dateIssues:[];for(let s of a)s.advisory===!0&&!r||e(`${s.advisory===!0?"advisory":"drift"}: ${o.file||"<unknown-file>"}: ${s.message}`)}}i(Ao,"printDateIssues");async function $o(e,t={}){let r=t.runner||br,n=t.stdout||console.log,o=t.stderr||console.error;try{let a=bo(e);if(a.help)return n(yo),0;let s=await wo(a.options),c=await r(a.diff?{...s,sampleOutput:!0}:s),l=c&&typeof c=="object"&&c.check===!0?c:null,u=l&&Number(l.filesWithDateDrift)>0?1:0;if(a.json)return n(JSON.stringify(c,null,2)),u;if(l)return n(`fix-headers check: scanned=${l.filesScanned??0}, drift=${l.filesWithDateDrift??0}, advisories=${l.dateAdvisories??0}`),Ao(n,l,s.verbose===!0),u;if(c&&typeof c=="object"){let f=c;n(`fix-headers complete: scanned=${f.filesScanned??0}, updated=${f.filesUpdated??0}, dryRun=${f.dryRun===!0}`),Sr(n,c,s,a.diff)}else Sr(n,c,s,a.diff),n("fix-headers complete");return 0}catch(a){let s=a instanceof Error?a.message:String(a);return o(`fix-headers failed: ${s}`),1}}i($o,"runCli");function vo(e=process.argv,t=import.meta.url,r=$o){let n=!1;if(e[1])try{let o=wr(e[1]),a=wr(ho(t));n=o===a}catch{n=t===go(e[1]).href}return n?(r(e.slice(2)).then(o=>{process.exitCode=o}),!0):!1}i(vo,"runCliAsMain");vo();export{wo as applyConfigFile,bo as parseCliArgs,$o as runCli,vo as runCliAsMain};
65
+ `;function Vo(e){return e.replace(/-([a-z])/g,(t,r)=>r.toUpperCase())}i(Vo,"toCamelCase");function Jo(e){let t={},r={help:!1,json:!1,diff:!1},n={"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 a=0;a<e.length;a+=1){let s=e[a];if(s==="-h"||s==="--help"){r.help=!0;continue}if(s==="--json"){r.json=!0;continue}if(s==="--diff"){r.diff=!0;continue}if(s==="--verbose"){t.verbose=!0;continue}if(s==="--dry-run"){t.dryRun=!0;continue}if(s==="--check"){t.check=!0;continue}if(s==="--fix-created-date"){t.fixCreatedDate=!0;continue}if(s==="--strict-created-date"){t.strictCreatedDate=!0;continue}if(s==="--normalize-date-format"){t.normalizeDateFormat=!0;continue}if(s==="--convert-timezone"){t.convertTimezone=!0;continue}if(s==="--sample-output"){t.sampleOutput=!0;continue}if(s==="--force-author-update"){t.forceAuthorUpdate=!0;continue}if(s==="--force-last-modified-author-update"){t.forceLastModifiedAuthorUpdate=!0;continue}if(s==="--use-gpg-signer-author"){t.useGpgSignerAuthor=!0;continue}if(!s.startsWith("--"))throw new Error(`Unexpected argument: ${s}`);let c=s.slice(2);if(c==="include-folder-non-recursive"){let f=e[a+1];if(!f||f.startsWith("--"))throw new Error(`Missing value for --${c}`);a+=1;let m=Array.isArray(t.includeFolders)?t.includeFolders:[];t.includeFolders=[...m,{path:f,recursive:!1}];continue}if(n[c]){let f=e[a+1];if(!f||f.startsWith("--"))throw new Error(`Missing value for --${c}`);a+=1;let m=n[c],g=Array.isArray(t[m])?t[m]:[];t[m]=Array.from(new Set([...g,f]));continue}if(o[c]){let f=e[a+1];if(!f||f.startsWith("--"))throw new Error(`Missing value for --${c}`);a+=1;let m=o[c];if(m==="copyrightStartYear"||m==="spacing"||m==="margin"){if(t[m]=Number.parseInt(f,10),Number.isNaN(t[m]))throw new Error(`Invalid number for --${c}: ${f}`)}else m==="marker"&&f==="null"?t[m]=null:t[m]=f;continue}let l=Vo(c),u=e[a+1];if(!u||u.startsWith("--"))throw new Error(`Unknown or malformed flag: --${c}`);a+=1,t[l]=u}return{options:t,help:r.help,json:r.json,diff:r.diff}}i(Jo,"parseCliArgs");function qo(e){return q(e,"config")}i(qo,"applyConfigFile");function Ie(e){if(!e||typeof e!="object")return[];let t=e;return(Array.isArray(t.changes)?t.changes:[]).filter(n=>n&&n.changed===!0&&n.sample&&typeof n.sample.newValue=="string")}i(Ie,"getSampledChanges");function Ir(e){return typeof e=="string"?`"${e}"`:"(missing)"}i(Ir,"formatIssueValue");function Ko(e,t){for(let r of Ie(t)){let n=Array.isArray(r.sample.issues)?r.sample.issues:[];if(e(`issues: ${r.file||"<unknown-file>"}`),n.length===0){e(" (no field differences; header formatting only)");continue}for(let o of n)e(` ${o?.field||"<unknown-field>"}: found ${Ir(o?.previous)}, expected ${Ir(o?.detected)}`)}}i(Ko,"printIssues");function Xo(e,t){for(let r of Ie(t))typeof r.sample.diff=="string"&&r.sample.diff.length>0&&e(r.sample.diff)}i(Xo,"printDiffs");function Zo(e,t){for(let r of Ie(t))e(`sample: ${r.file||"<unknown-file>"}`),e("previous:"),e(r.sample.previousValue===null?"(none)":String(r.sample.previousValue)),e("new:"),e(r.sample.newValue),r.sample.detectedValues&&typeof r.sample.detectedValues=="object"&&(e("detected-values:"),e(JSON.stringify(r.sample.detectedValues,null,2)))}i(Zo,"printSampleOutput");function Qo(e,t){if(!t||typeof t!="object")return;let r=t,o=(Array.isArray(r.changes)?r.changes:[]).filter(a=>a&&a.changed===!0).map(a=>a.file||"<unknown-file>");for(let a of o)e(`updated: ${a}`)}i(Qo,"printChangedFiles");function ei(e,t){let r=Array.isArray(t.skipped)?t.skipped:[];for(let n of r)e(`skipped: ${n?.file||"<unknown-file>"} (${n?.reason||"no reason given"})`)}i(ei,"printSkipped");function Or(e,t,r,n){let o=r.sampleOutput===!0||n;r.verbose===!0&&(Qo(e,t),o&&Ko(e,t)),r.sampleOutput===!0&&Zo(e,t),n&&Xo(e,t)}i(Or,"printDetails");function ti(e,t,r){let n=Array.isArray(t.changes)?t.changes:[];for(let o of n){let a=Array.isArray(o?.dateIssues)?o.dateIssues:[];for(let s of a)s.advisory===!0&&!r||e(`${s.advisory===!0?"advisory":"drift"}: ${o.file||"<unknown-file>"}: ${s.message}`)}}i(ti,"printDateIssues");async function ri(e,t={}){let r=t.runner||Rr,n=t.stdout||console.log,o=t.stderr||console.error;try{let a=Jo(e);if(a.help)return n(Go),0;let s=await qo(a.options),c=await r(a.diff?{...s,sampleOutput:!0}:s),l=c&&typeof c=="object"&&c.check===!0?c:null,u=l&&Number(l.filesWithDateDrift)>0?1:0;if(a.json)return n(JSON.stringify(c,null,2)),u;if(l)return n(`fix-headers check: scanned=${l.filesScanned??0}, drift=${l.filesWithDateDrift??0}, advisories=${l.dateAdvisories??0}`),ti(n,l,s.verbose===!0),u;if(c&&typeof c=="object"){let f=c,m=Number(f.filesSkipped)>0?`, skipped=${f.filesSkipped}`:"";n(`fix-headers complete: scanned=${f.filesScanned??0}, updated=${f.filesUpdated??0}${m}, dryRun=${f.dryRun===!0}`),ei(n,f),Or(n,c,s,a.diff)}else Or(n,c,s,a.diff),n("fix-headers complete");return 0}catch(a){let s=a instanceof Error?a.message:String(a);return o(`fix-headers failed: ${s}`),1}}i(ri,"runCli");function ni(e=process.argv,t=import.meta.url,r=ri){let n=!1;if(e[1])try{let o=Pr(e[1]),a=Pr(Wo(t));n=o===a}catch{n=t===Yo(e[1]).href}return n?(r(e.slice(2)).then(o=>{process.exitCode=o}),!0):!1}i(ni,"runCliAsMain");ni();export{qo as applyConfigFile,Jo as parseCliArgs,ri as runCli,ni as runCliAsMain};
65
66
  //# sourceMappingURL=fix-headers.mjs.map
package/dist/index.cjs CHANGED
@@ -21,10 +21,22 @@
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 / 22.12) would fail with a bare
25
+ * ERR_REQUIRE_ESM, so the check below fails early with a message that says what to do
26
+ * instead.
27
+ *
24
28
  * tsup copies this folder verbatim into dist/ (`publicDir` in tsup.config.mjs); it
25
29
  * never passes through esbuild, so it stays this small however much the library grows.
26
30
  * @module fix-headers/cjs-entry
27
31
  */
28
32
  "use strict";
29
33
 
34
+ if (!process.features?.require_module) {
35
+ const error = new Error(
36
+ `@cldmv/fix-headers: require() needs Node.js ^20.19.0 or >=22.12.0 (this is ${process.version}). On older Node.js, load the package with import() instead.`
37
+ );
38
+ error.code = "ERR_REQUIRE_ESM";
39
+ throw error;
40
+ }
41
+
30
42
  module.exports = require("./index.mjs").default;