@cldmv/fix-headers 2.1.3 → 2.1.4

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 Ur=Object.defineProperty;var i=(e,t)=>Ur(e,"name",{value:t,configurable:!0});import{realpathSync as jr}from"node:fs";import{fileURLToPath as Po,pathToFileURL as Ro}from"node:url";import{readFile as _r}from"node:fs/promises";import{createRequire as Hr}from"node:module";import{dirname as zr,isAbsolute as Br,resolve as Ze}from"node:path";var Wr=3e4,Yr=new Set(["localhost","127.0.0.1","[::1]"]);function fe(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}i(fe,"isPlainObject");function de(e,t){let r={...e};for(let[n,o]of Object.entries(t))n!=="__proto__"&&(r[n]=fe(r[n])&&fe(o)?de(r[n],o):o);return r}i(de,"mergeConfig");function Qe(e){return e.kind==="file"?e.path:e.href}i(Qe,"describeSource");async function Vr(e){if(e.kind==="file")return{text:await _r(e.path,"utf8"),source:e};let t;try{t=await fetch(e.href,{cache:"no-store",redirect:"follow",signal:AbortSignal.timeout(Wr)})}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(Vr,"readSource");function Xe(e){if(e.protocol==="http:"&&!Yr.has(e.hostname))throw new Error(`Refusing to fetch config over plain http: ${e.href} (use https)`);return{kind:"url",href:e.href}}i(Xe,"toUrlSource");function Gr(e,t){if(/^https?:\/\//i.test(e))return Xe(new URL(e));if(/^[a-z][a-z\d+.-]+:\/\//i.test(e))throw new Error(`Unsupported extends URL "${e}" in ${Qe(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 Xe(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||Br(e))return{kind:"file",path:Ze(zr(t.path),e)};try{return{kind:"file",path:Hr(t.path).resolve(e)}}catch(n){throw new Error(`Cannot resolve extends "${e}" from ${t.path}: ${n.message}`,{cause:n})}}i(Gr,"resolveReference");function Jr(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(Jr,"readExtends");async function et(e,t){let r=Qe(e);if(t.includes(r))throw new Error(`Config extends cycle: ${[...t,r].join(" -> ")}`);let{text:n,source:o}=await Vr(e),a;try{a=JSON.parse(n)}catch(u){throw new Error(`Config ${r} is not valid JSON: ${u.message}`,{cause:u})}if(!fe(a))throw new Error(`Config file must contain a JSON object: ${r}`);let{extends:s,...c}=a,l={};for(let u of Jr(s,r))l=de(l,await et(Gr(u,o),[...t,r]));return de(l,c)}i(et,"loadSource");function qr(e,t=process.cwd()){return et({kind:"file",path:Ze(t,e)},[])}i(qr,"loadConfigFile");async function Z(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 qr(r,n),...e};return delete o[t],o}i(Z,"applyConfigOption");import{readFile as $o,stat as Ao,writeFile as Do}from"node:fs/promises";import{relative as Te,resolve as vr}from"node:path";import{extname as me}from"node:path";import{extname as Kr}from"node:path";var tt=[".css"];function Xr(e){let t=Kr(e).toLowerCase();return tt.includes(t)?{kind:"block",blockStart:"/*",blockLinePrefix:" * ",blockEnd:" */"}:null}i(Xr,"resolveCssCommentSyntax");var rt={id:"css",extensions:tt,enabledByDefault:!0,resolveCommentSyntax(e){return Xr(e)}};import{extname as Zr}from"node:path";var nt=[".go"];function Qr(e){let t=Zr(e).toLowerCase();return nt.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}i(Qr,"resolveGoCommentSyntax");var ot={id:"go",extensions:nt,enabledByDefault:!0,resolveCommentSyntax(e){return Qr(e)}};import{extname as en}from"node:path";var it=[".html",".htm"];function tn(e){let t=en(e).toLowerCase();return it.includes(t)?{kind:"html",blockStart:"<!--",blockLinePrefix:" ",blockEnd:"-->"}:null}i(tn,"resolveHtmlCommentSyntax");var at={id:"html",extensions:it,enabledByDefault:!0,resolveCommentSyntax(e){return tn(e)}};import{extname as rn}from"node:path";var st=[".jsonv",".jsonc",".json5"];function nn(e){let t=rn(e).toLowerCase();return st.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}i(nn,"resolveJsonCommentSyntax");var ct={id:"json",extensions:st,enabledByDefault:!0,resolveCommentSyntax(e){return nn(e)}};import{extname as on}from"node:path";var lt=[".md",".markdown"];function an(e){let t=on(e).toLowerCase();return lt.includes(t)?{kind:"html",blockStart:"<!--",blockLinePrefix:" ",blockEnd:"-->"}:null}i(an,"resolveMarkdownCommentSyntax");function sn(e,t){let r=t.match(/^---\r?\n[\s\S]*?\r?\n---[ \t]*(?:\r?\n|$)/);return r?r[0]:""}i(sn,"resolveMarkdownPreservedPrefix");var ut={id:"markdown",extensions:lt,enabledByDefault:!1,requiresForce:!0,resolvePreservedPrefix(e,t){return sn(e,t)},resolveCommentSyntax(e){return an(e)}};import{extname as cn}from"node:path";var ft=[".js",".mjs",".cjs",".ts",".tsx",".jsx"];function ln(e){let t=cn(e).toLowerCase();return ft.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}i(ln,"resolveNodeCommentSyntax");function un(e,t){let r=t.match(/^#!.*\b(node|bun|deno|tsx|ts-node)\b.*(?:\r?\n|$)/);return r?r[0]:""}i(un,"resolveNodePreservedPrefix");var dt={id:"node",extensions:ft,enabledByDefault:!0,resolvePreservedPrefix(e,t){return un(e,t)},resolveCommentSyntax(e){return ln(e)}};import{extname as fn}from"node:path";var mt=[".php"];function dn(e){let t=fn(e).toLowerCase();return mt.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}i(dn,"resolvePhpCommentSyntax");var pt={id:"php",extensions:mt,enabledByDefault:!0,resolveCommentSyntax(e){return dn(e)}};import{extname as mn}from"node:path";var ht=[".py"];function pn(e,t){let r=t.match(/^#!.*\bpython(?:\d+(?:\.\d+)*)?\b.*(?:\r?\n|$)/);return r?r[0]:""}i(pn,"resolvePythonPreservedPrefix");var gt={id:"python",extensions:ht,enabledByDefault:!0,resolvePreservedPrefix(e,t){return pn(e,t)},resolveCommentSyntax(e){let t=mn(e).toLowerCase();return ht.includes(t)?{kind:"line",linePrefix:"#"}:null}};import{extname as hn}from"node:path";var yt=[".rs"];function gn(e){let t=hn(e).toLowerCase();return yt.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}i(gn,"resolveRustCommentSyntax");var xt={id:"rust",extensions:yt,enabledByDefault:!0,resolveCommentSyntax(e){return gn(e)}};import{extname as yn}from"node:path";var wt=[".yaml",".yml"];function xn(e){let t=yn(e).toLowerCase();return wt.includes(t)?{kind:"line",linePrefix:"#"}:null}i(xn,"resolveYamlCommentSyntax");var bt={id:"yaml",extensions:wt,enabledByDefault:!0,resolveCommentSyntax(e){return xn(e)}};var Q=[rt,ot,at,ct,ut,dt,pt,gt,xt,bt],wn=new Map(Q.map(e=>[e.id,e]));function bn(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(bn,"applySyntaxOverride");function Et(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=Q.filter(r=>r.requiresForce===!0).map(r=>r.id);for(let r of e){if(!wn.has(r))throw new Error(`forcedDetectors: unknown detector "${r}" (force-only detectors: ${t.join(", ")})`);if(!t.includes(r))throw new Error(`forcedDetectors: "${r}" does not need forcing (force-only detectors: ${t.join(", ")})`)}return Array.from(new Set(e))}i(Et,"resolveForcedDetectors");function C(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 Q.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(C,"getEnabledDetectors");function kt(e={}){if(Array.isArray(e.includeExtensions)&&e.includeExtensions.length>0)return new Set(e.includeExtensions.map(r=>r.toLowerCase()));let t=C(e);return new Set(t.flatMap(r=>r.extensions))}i(kt,"getAllowedExtensions");function St(e,t={}){let r=me(e).toLowerCase();if(C(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=Q.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(St,"getHeaderSkipReason");function $t(e,t={}){let r=me(e).toLowerCase(),n=Array.isArray(t.detectors)?t.detectors:C(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 bn(a,s[o.id])}}return{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}}i($t,"getCommentSyntaxForFile");function At(e,t,r={}){let n=me(e).toLowerCase(),o=C(r);for(let a of o)if(a.extensions.includes(n))return typeof a.resolvePreservedPrefix=="function"?a.resolvePreservedPrefix(e,t):"";return""}i(At,"getPreservedPrefixForFile");var Dt=200,H=1,ee=2;function F(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(F,"resolveLayoutCount");import{existsSync as Ln}from"node:fs";import{join as Ee,relative as Ot,resolve as ke,sep as we}from"node:path";import{realpath as Mn,stat as Pn}from"node:fs/promises";import{access as En,readdir as kn,readFile as Vi,stat as Sn}from"node:fs/promises";import{constants as $n}from"node:fs";import{dirname as qi,join as An,resolve as Ki}from"node:path";async function pe(e){try{return await En(e,$n.F_OK),!0}catch{return!1}}i(pe,"pathExists");async function he(e,t){let r=[],n=await kn(e,{withFileTypes:!0});for(let o of n){let a=An(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 he(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(he,"walkFiles");async function Nt(e){let t=await Sn(e);return{createdAt:t.birthtimeMs>0&&t.birthtime<t.mtime?t.birthtime:t.mtime,updatedAt:t.mtime}}i(Nt,"readFileDates");import{execFile as Dn}from"node:child_process";import{lstat as Nn,readFile as vn}from"node:fs/promises";import{dirname as vt,isAbsolute as Cn,join as jt,relative as Lt,resolve as ge,sep as Mt}from"node:path";import Fn from"ignore";function Ct(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(Ct,"runGitCommand");function xe(e,t){return Lt(e,t).split(Mt).join("/")}i(xe,"toPosixRelative");async function Pt(e){try{return Fn().add(await vn(e,"utf8"))}catch{return null}}i(Pt,"readIgnoreFile");async function jn(e){return Nn(jt(e,".git")).then(()=>!0,()=>!1)}i(jn,"hasGitEntry");function Ft(e,t,r){for(let n=e.length-1;n>=0;n--){let{base:o,rules:a}=e[n],s=a.test(`${xe(o,t)}${r?"/":""}`);if(s.ignored||s.unignored)return s.ignored}return!1}i(Ft,"matchesRules");async function Rt(e,t){let r=await Pt(jt(e,".gitignore"));return{kind:"rules",nested:!0,excluded:!1,matchers:r?[...t,{base:e,rules:r}]:t}}i(Rt,"buildRulesContext");async function ye(e){let[t,r]=await Promise.all([Ct(e,["check-ignore","-q","."]),Ct(e,["ls-files","--cached","--others","--exclude-standard","-z"])]);if(t.code!==1||r.code!==0)return Rt(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(ye,"resolveScopeContext");function It(e){let t=ge(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 ye(t);let c=typeof r=="string"?[r]:r.filter(u=>typeof u=="string"),l=[];for(let u of c){let f=await Pt(ge(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(vt(c));return l.kind==="git"?l.entries.has(xe(l.root,c))?ye(c):l:!l.nested||l.excluded?l:Ft(l.matchers,c,!0)?{...l,excluded:!0}:await jn(c)?ye(c):Rt(c,l.matchers)},"deriveContext");return{async isIgnored(c,l){let u=ge(c),f=Lt(t,u);if(f.length===0||f===".."||f.startsWith(`..${Mt}`)||Cn(f))return!1;let p=await a(vt(u));if(p.kind==="git"){let g=xe(p.root,u);return!(p.entries.has(g)||l&&p.dirs.has(g))}return p.excluded||Ft(p.matchers,u,l)}}}i(It,"createIgnoreFilter");function Rn(e){return kt(e)}i(Rn,"resolveExtensions");var In=Object.freeze(["node_modules","bower_components","jspm_packages",".pnpm-store",".yarn"]),_t=new Set([".git",...In]),On=Object.freeze(["autoload.php","modules.txt"]);function Tt(e,t){return _t.has(t)?!0:t==="vendor"&&On.some(r=>Ln(Ee(e,r)))}i(Tt,"isNeverWalked");function be(e){return e.replace(/\\/g,"/").replace(/^\.\//,"").replace(/^\/+/,"").replace(/\/+$/,"")}i(be,"normalizeFolderPath");function Tn(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(Tn,"resolveIncludeFolders");function Ut(e,t){let r=t instanceof Error?t.message:String(t);console.warn(`fix-headers: skipped include folder "${e}" (${r})`)}i(Ut,"reportSkippedIncludeFolder");function Un(e,t){if(!Array.isArray(t)||t.length===0)return()=>!1;let r=ke(e),n=[],o=new Set;for(let a of t){if(typeof a!="string")continue;let s=be(a);if(s.length!==0){if(s.includes("/")){n.push(ke(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=be(Ot(r,a));return n.some(l=>{let u=be(Ot(r,l));return c===u||c.startsWith(`${u}/`)})}}i(Un,"buildExclusionMatcher");async function Se(e){let t=Rn(e),r=Tn(e.includeFolders),n=Array.isArray(e.excludeFolders)?e.excludeFolders:[],o=Un(e.projectRoot,n),a=It({root:e.projectRoot,gitignore:e.gitignore}),s=i(async(d,h)=>Tt(d,h)||o(d,h)||await a.isIgnored(d,!0),"shouldSkipDirectory"),c=r.length>0?r.map(d=>({includeFolder:d.path,rootPath:Ee(e.projectRoot,d.path),recursive:d.recursive})):[{includeFolder:".",rootPath:e.projectRoot,recursive:!0}],l=[];for(let d of c){let h=await Pn(d.rootPath).catch(k=>k);if(h instanceof Error){if(h.code==="ENOENT"){Ut(d.includeFolder,h);continue}throw h}if(!h.isDirectory()){Ut(d.includeFolder,`path is not a directory: ${d.rootPath}`);continue}let b=await Mn(d.rootPath).catch(()=>ke(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(we)?d.realRoot:`${d.realRoot}${we}`;if(!d.recursive||!h.realRoot.startsWith(b))return!1;let k=d.rootPath;for(let D of h.realRoot.slice(b.length).split(we))if(k=Ee(k,D),Tt(k,D)||o(k,D))return!1;return!0},"covers"),f=[...l].sort((d,h)=>d.realRoot.length-h.realRoot.length||Number(h.recursive)-Number(d.recursive)),p=[];for(let d of f)p.some(h=>u(h,d))||p.push(d);let g=[];for(let d of l){if(!p.includes(d))continue;let h=await he(d.rootPath,{allowedExtensions:t,ignoreFolders:_t,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(Se,"discoverFiles");import{basename as co,dirname as lo,extname as uo,resolve as ve}from"node:path";import{dirname as Zt,isAbsolute as Kn,join as Qt,relative as Xn,resolve as er,sep as Zn}from"node:path";import{readFile as _n}from"node:fs/promises";import{join as Hn}from"node:path";async function zn(e){try{return await _n(e,"utf8")}catch{return null}}i(zn,"readManifest");async function $(e,t){let r=[];for(let n of t){let o=await zn(Hn(e,n));o!==null&&r.push({file:n,content:o})}return r.length>0?{dir:e,manifest:r[0].file,files:r}:null}i($,"detectManifests");function j(e,t){return e.files.find(r=>r.file===t)?.content??null}i(j,"manifestContent");function w(e){return typeof e=="string"&&e.trim().length>0?e.trim():void 0}i(w,"cleanName");function $e(e){if(typeof e!="string")return;let t=e.search(/[<(]/);return w(t===-1?e:e.slice(0,t))}i($e,"personName");function te(e){try{return JSON.parse(e)}catch{return}}i(te,"parseJsonManifest");function*Ae(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(Ae,"sectionLines");function z(e,t,r){let n=new RegExp(`^${r}\\s*=\\s*(?:"([^"\\\\]*)"|'([^']*)')`);for(let o of Ae(e,t)){let a=o.match(n);if(a)return w(a[1]??a[2])}}i(z,"readTomlString");function De(e,t,r){let n=new RegExp(`^${r}\\s*[=:](.*)$`);for(let o of Ae(e,t)){let a=o.match(n);if(a)return w(a[1])}}i(De,"readIniValue");function Bn(e,t,r){let n=new RegExp(`^${r}\\s*=\\s*\\[`),o=null;for(let a of Ae(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(Bn,"tomlArrayText");function Wn(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(Wn,"skipTomlSpace");function B(e,t){let r=Bn(e,t,"authors");if(r===null)return;let n=r.slice(Wn(r,0)),o=n.match(/^(?:"([^"\\\n]*)"|'([^'\n]*)')/);if(o)return $e(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(B,"readTomlAuthor");var Ht=["go.mod"];function Yn(e){let t=e.match(/^\s*module\s+(.+)$/m);if(t)return w(t[1].replace(/\/\/.*$/,"").trim().replace(/^["`](.*)["`]$/,"$1"))}i(Yn,"readModulePath");var zt={id:"go",languages:["go"],manifests:Ht,detect(e){return $(e,Ht)},read(e){return{name:Yn(e.files[0].content)}}};var Bt=["package.json"];function Vn(e){let t=w(e?.name),r=w(e?.publisher),n=typeof e?.engines?.vscode=="string";return t&&r&&n?`${r}.${t}`:t}i(Vn,"readPublishedName");function Gn(e){if(e!==null&&typeof e=="object"){let t=e;return w(t.company)??w(t.name)}return $e(e)}i(Gn,"readAuthorCompany");var Wt={id:"node",languages:["node"],manifests:Bt,detect(e){return $(e,Bt)},read(e){let t=te(e.files[0].content);return{name:Vn(t),company:Gn(t?.author)}}};var Yt=["composer.json"],Vt={id:"php",languages:["php"],manifests:Yt,detect(e){return $(e,Yt)},read(e){let t=te(e.files[0].content),r=t?.authors;return{name:w(t?.name),company:Array.isArray(r)?w(r[0]?.name):void 0}}};var Gt=["pyproject.toml","setup.cfg","setup.py"];function Jt(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(Jt,"readSetupPyArgument");function Jn(e){let t=j(e,"pyproject.toml"),r=j(e,"setup.cfg"),n=j(e,"setup.py");return(t===null?void 0:z(t,"project","name")??z(t,"tool.poetry","name"))??(r===null?void 0:De(r,"metadata","name"))??(n===null?void 0:Jt(n,"name"))}i(Jn,"readPythonName");function qn(e){let t=j(e,"pyproject.toml"),r=j(e,"setup.cfg"),n=j(e,"setup.py");return(t===null?void 0:B(t,"project")??B(t,"tool.poetry"))??(r===null?void 0:De(r,"metadata","author"))??(n===null?void 0:Jt(n,"author"))}i(qn,"readPythonCompany");var qt={id:"python",languages:["python"],manifests:Gt,detect(e){return $(e,Gt)},read(e){return{name:Jn(e),company:qn(e)}}};var Kt=["Cargo.toml"],Xt={id:"rust",languages:["rust"],manifests:Kt,detect(e){return $(e,Kt)},read(e){let t=e.files[0].content;return{name:z(t,"package","name"),company:B(t,"package")}}};var Qn=[Wt,qt,Vt,Xt,zt],tr=["name","company"];async function Ne(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(Ne,"claimFolder");function eo(e,t){let r=Xn(t,e);return r!==""&&r!==".."&&!r.startsWith(`..${Zn}`)&&!Kn(r)}i(eo,"isStrictlyInside");async function rr(e,t={}){let r=Array.isArray(t.drivers)?t.drivers:Qn,n=typeof t.scanRoot=="string"?er(t.scanRoot):null,o=er(e),a=await Ne(o,r,t.language);for(;a.length===0;){if(await pe(Qt(o,".git")))return{root:o,marker:".git",drivers:[],fields:{},sources:{}};let f=Zt(o);if(f===o)return null;o=f,a=await Ne(o,r,t.language)}let s={},c={},l=o,u=a;for(;;){for(let{driver:p,detection:g}of u){let x=p.read(g);for(let d of tr)s[d]===void 0&&x[d]!==void 0&&(s[d]=x[d],c[d]={driver:p.id,manifest:g.manifest,dir:l})}if(tr.every(p=>s[p]!==void 0)||n===null||!eo(l,n)||await pe(Qt(l,".git")))break;l=Zt(l),u=await Ne(l,r,t.language)}return{root:o,marker:a[0].detection.manifest,drivers:a.map(f=>f.driver.id),fields:s,sources:c}}i(rr,"resolveManifestProject");import{execFile as to}from"node:child_process";import{promisify as ro}from"node:util";var or=ro(to);async function A(e,t){try{let{stdout:r}=await or("git",t,{cwd:e}),n=r.trim();return n.length>0?n:null}catch{return null}}i(A,"runGit");function nr(e,t){let r=0;for(let n=t-1;n>=0&&e[n]==="\\";n--)r++;return r%2===1}i(nr,"isEscaped");function no(e){let t=e.trim();if(!t.endsWith(")")||nr(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!==")"||nr(t,n))&&(r+=o===")"?1:-1,r===0))return t.slice(0,n).trim()}return t}i(no,"stripUidComment");function oo(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:no(o)||o||null,authorEmail:n}}i(oo,"parseSignerUid");async function io(e,t){try{let{stdout:r}=await or(e,t),n=r.trim();return n.length>0?n:null}catch{return null}}i(io,"runProgram");function ao(e){return e.replace(/\\x([0-9a-fA-F]{2})/g,(t,r)=>String.fromCharCode(Number.parseInt(r,16)))}i(ao,"decodeColonField");async function so(e){let t=await A(e,["config","--get","gpg.format"]);if(t!==null&&t!=="openpgp")return null;let r=await A(e,["config","--get","user.signingkey"]);if(!r)return null;let n=await A(e,["config","--get","gpg.openpgp.program"])||await A(e,["config","--get","gpg.program"])||"gpg",o=await io(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 ao(s[9])}return null}i(so,"readSigningKeyUid");async function ir(e,t={}){let r=await A(e,["config","--get","user.name"]),n=await A(e,["config","--get","user.email"]);if(t.useGpgSignerAuthor===!0){let o=await so(e)||await A(e,["log","-1","--format=%GS"]),a=oo(o||"");r=a.authorName||r,n=n||a.authorEmail}if(!r||!n){let o=await A(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(ir,"detectGitAuthor");function ar(e){return e.replace(/z$/i,"+00:00")}i(ar,"canonicalGitDate");async function sr(e,t){let r=await A(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:ar(o),timestamp:s}}i(sr,"getGitCreationDate");async function cr(e,t){let r=await A(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:ar(n),timestamp:a}}i(cr,"getGitLastModifiedDate");function fo(e){return co(e)||"project"}i(fo,"folderName");function mo(e,t){if(typeof t!="string")return e;let r=t.trim();return r.length===0||/<[^>]+>/.test(e)?e:`${e} <${r}>`}i(mo,"formatAuthorNameWithCompany");async function po(e,t={}){let r=Array.isArray(t.detectors)?t.detectors:C(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 rr(e,{drivers:t.drivers,language:o?.id,scanRoot:t.scanRoot}),s=a?a.root:ve(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??fo(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(po,"detectProjectFromMarkers");async function Ce(e={}){let t=e.targetFilePath||e.cwd||process.cwd(),r=ve(t),n=C(e),o=e.targetFilePath?lo(r):r,a=e.targetFilePath?uo(r).toLowerCase():"",s=ve(e.projectRoot||e.cwd||process.cwd()),c=await po(o,{detectors:n,preferredExtension:a,scanRoot:s}),l=await ir(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:mo(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(Ce,"resolveProjectMetadata");function ho(e){return Fe({year:e.getFullYear(),month:e.getMonth()+1,day:e.getDate(),hour:e.getHours(),minute:e.getMinutes(),second:e.getSeconds(),offsetMinutes:-e.getTimezoneOffset()})}i(ho,"formatDateWithTimezone");function Fe(e){return`${dr(e," ")} ${mr(e.offsetMinutes)}`}i(Fe,"formatSpaceDate");function ur(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{fr(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(ur,"assertTimeZone");var lr=new Map;function fr(e){let t=lr.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"}),lr.set(e,t)),t}i(fr,"getZoneFormatter");function je(e,t){let r={};for(let o of fr(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(je,"toZonedDateParts");function dr(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(dr,"formatWallClock");function mr(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(mr,"formatOffset");function re(e=new Date){return{date:ho(e),timestamp:Math.floor(e.getTime()/1e3)}}i(re,"toDatePayload");var go=/^(\d{4})-(\d{2})-(\d{2})(?:T|\s+)(\d{2}):(\d{2}):(\d{2})(?:\.\d+)?\s*(?:(Z)|([+-])(\d{2}):?(\d{2}))$/i;function L(e){let t=go.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(L,"parseHeaderDate");function Le(e){return`${dr(e,"T")}${mr(e.offsetMinutes)}`}i(Le,"formatIsoDate");var yo={"git-created":"git first commit","filesystem-created":"filesystem creation time"};function pr(e,t){let r=e.match(new RegExp(`${t}:[^\\S\\n]*(.*)$`,"m"));return r?r[1].trim():null}i(pr,"readHeaderField");function Me(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(Me,"pickOldestDate");function gr({existing:e,gitCreated:t,filesystemCreated:r,fixCreatedDate:n=!1}){let o=[{source:"git-created",payload:t},{source:"filesystem-created",payload:r}];if(!e)return Me(o);if(!n)return{source:"existing-header",payload:e};let a=L(e.date)?e:null;return Me([{source:"existing-header",payload:a},...o])}i(gr,"resolveCreatedDate");function yr(e,t=null){if(t)return je(e.timestamp,t).year;let r=L(e.date);return r?r.year:new Date(e.timestamp*1e3).getFullYear()}i(yr,"dateYear");function hr(e,t,r,n){let o=e.match(/^(.+?)\s*\((\d+)\)$/),a=o?L(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(hr,"checkDateValue");function xr(e,t={},r={}){let n=[],o=pr(e,"@Date"),a=o===null?null:hr(o,"@Date","created",n),s=Me([{source:"git-created",payload:t.gitCreated},{source:"filesystem-created",payload:t.filesystemCreated}]);if(a&&s&&a.timestamp>s.payload.timestamp){let f=yo[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=pr(e,"@Last modified time"),l=c===null?null:hr(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(xr,"checkHeaderDates");function Pe(e){if(!e)return null;let t=L(e.date);return t&&t.timestamp!==e.timestamp?{date:e.date,timestamp:t.timestamp}:e}i(Pe,"repairDateEpoch");function wr(e){let t=L(e.date);return t?{date:Le(t),timestamp:t.timestamp}:e}i(wr,"normalizeDatePayload");function br(e,t){let r=L(e.date);if(!r)return e;let n=je(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())?Le(n):Fe(n),timestamp:r.timestamp}}i(br,"convertDatePayload");import{relative as wo}from"node:path";import{extname as xo}from"node:path";function W(e,t={}){let r=xo(e).toLowerCase(),n=F(t.spacing,"spacing",H);return r.length===0?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */",spacing:n}:{...$t(e,t),spacing:n}}i(W,"getHeaderSyntaxForFile");function Er(e,t){let r=e.spacing??H;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(Er,"renderHeaderLines");function Re(e){let t=`/${wo(e.projectRoot,e.absoluteFilePath).replace(/\\/g,"/")}`,r=W(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 Er(r,u)}i(Re,"buildHeader");var bo=Object.freeze(["projectName","filename","createdAt","authorName","authorEmail","lastModifiedByName","lastModifiedByEmail","lastModifiedAt","copyrightStartYear","copyrightEndYear","companyName"]);function N(e,t){let r=e.match(new RegExp(`@${t}:[ \\t]*(.*)$`,"m")),n=r?r[1].trim():"";return n.length>0?n:null}i(N,"readTag");function Eo(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(Eo,"splitLastModifiedBy");function ko(e){let t={startYear:null,endYear:null,companyName:null},r=e?.match(/^Copyright\s+\(c\)\s+(\d{4})/i);if(!r)return t;let n=e.slice(r[0].length),o=n.match(/^\s*-\s*(\d{4})/);o&&(n=n.slice(o[0].length));let 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(ko,"splitCopyright");function kr(e){let t=Eo(N(e,"Last modified by")),r=ko(N(e,"Copyright")),n=N(e,"Email");return{projectName:N(e,"Project"),filename:N(e,"Filename"),createdAt:N(e,"Date"),authorName:N(e,"Author"),authorEmail:n===null?null:n.replace(/^<(.*)>$/,"$1"),lastModifiedByName:t.name,lastModifiedByEmail:t.email,lastModifiedAt:N(e,"Last modified time"),copyrightStartYear:r.startYear,copyrightEndYear:r.endYear,companyName:r.companyName}}i(kr,"parseHeaderFields");function Sr(e,t){let r=kr(e??""),n=kr(t);return bo.filter(o=>r[o]!==n[o]).map(o=>({field:o,previous:r[o],detected:n[o]}))}i(Sr,"compareHeaderFields");function ne(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}i(ne,"escapeRegex");function Ar(e,t,r={}){let n=At(e,t,r);return n.length===0?{prefix:"",body:t}:{prefix:n,body:t.slice(n.length)}}i(Ar,"splitPreservedPrefix");function $r(e,t){if(t.kind==="html"){let n=ne(t.blockStart||"<!--"),o=ne(t.blockEnd||"-->");return e.match(new RegExp(`^${n}[\\s\\S]*?${o}\\n*`))}if(t.kind==="line"){let n=ne(t.linePrefix||"#");return e.match(new RegExp(`^(?:${n}.*\\n)+\\n*`))}let r=ne((t.blockEnd||" */").trim());return e.match(new RegExp(`^/\\*[\\s\\S]*?${r}\\n*`))}i($r,"matchHeaderSegment");function Ie(e,t="",r={}){let{prefix:n,body:o}=Ar(t,e,r),a=o.split(`
9
+ `).slice(0,Dt).join(`
10
+ `),s=W(t,r);if(!$r(a,s))return null;let l=0,u=0;for(;;){let f=a.slice(l),p=$r(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(Ie,"findProjectHeader");function Oe(e,t,r="",n={}){let o=Ie(e,r,n),a=F(n.margin,"margin",ee),s=W(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}=Ar(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+/,""),p=`${u}${l(f)}`;return{nextContent:p,changed:p!==e}}i(Oe,"replaceOrInsertHeader");function So(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(So,"diffLines");function Dr(e,t){return`${t===0?e:e+1},${t}`}i(Dr,"formatRange");function Nr(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=So(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",p=[`--- ${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),k=h.filter(E=>E.type!=="+").length+c,D=h.filter(E=>E.type!=="-").length+c,M=b.filter(E=>E.type!=="+").length,Y=b.filter(E=>E.type!=="-").length;p.push(`@@ -${Dr(k,M)} +${Dr(D,Y)} @@`);for(let E of b)p.push(`${E.type}${E.line}`)}return p.join(`
15
+ `)}i(Nr,"createUnifiedDiff");function No(e){return Z(e,"configFile")}i(No,"resolveRuntimeOptions");function vo(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(vo,"resolveInputs");function Co(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(Co,"extractHeaderAuthorIdentity");function Fo(e){let t=e.match(/@Last modified by:\s*(.+?)\s*\(([^)\n]+)\)\s*$/m);return{authorName:t?.[1]?.trim(),authorEmail:t?.[2]?.trim()}}i(Fo,"extractHeaderLastModifiedIdentity");function jo(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(jo,"extractHeaderCreatedAt");function Lo(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(Lo,"extractHeaderLastModifiedAt");async function Cr(e={}){let t=await No(e),r=t.timezone===void 0||t.timezone===null?null:ur(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=Et(t.forcedDetectors),a=vr(t.projectRoot||t.cwd||process.cwd()),s=await Ce({...t,cwd:a});F(t.spacing,"spacing",H),F(t.margin,"margin",ee);let c=t.check===!0,l=c||t.dryRun===!0,u=t.fixCreatedDate===!0,f=i(y=>y,"keepDate"),p=t.normalizeDateFormat===!0?wr:f,g=r?y=>br(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=vo(t.input),b;if(h.length>0){let y=new Set;for(let P of h){let m=vr(a,P),R=await Ao(m).catch(()=>null);if(!R)throw new Error(`Input path does not exist: ${P}`);if(R.isFile())y.add(m);else if(R.isDirectory())for(let I of await Se({...d,projectRoot:m}))y.add(I);else throw new Error(`Input path must be a file or directory: ${P}`)}b=Array.from(y)}else b=await Se({...d,projectRoot:a});let k=new Date().getFullYear(),D=[],M=[],Y=new Set,E=0,_e=0,He=0;for(let y of b){let P=St(y,{enabledDetectors:t.enabledDetectors,disabledDetectors:t.disabledDetectors,forcedDetectors:o});if(P!==null){M.push({file:Te(a,y),reason:P});continue}let m=await Ce({...t,cwd:a,targetFilePath:y});Y.add(`${m.language}:${m.projectRoot}`);let R=Te(a,y),I=await $o(y,"utf8"),T={language:m.language,enabledDetectors:t.enabledDetectors,disabledDetectors:t.disabledDetectors,forcedDetectors:o,detectorSyntaxOverrides:t.detectorSyntaxOverrides,spacing:t.spacing,margin:t.margin},oe=Ie(I,y,T),S=oe?I.slice(oe.start,oe.end):"",V=S.length>0?Co(S):{},G=S.length>0?Fo(S):{},Pr=S.length>0?jo(S):null,Rr=S.length>0?Lo(S):null,ze=await Nt(y),Be=Te(m.projectRoot,y),We=await sr(m.projectRoot,Be),ie=await cr(m.projectRoot,Be),Ye=re(ze.createdAt),ae=gr({existing:Pe(Pr),gitCreated:We,filesystemCreated:Ye,fixCreatedDate:u}),se=Pe(Rr),Ve=ae.source,Ir=se?"existing-header":ie?"git-last-modified":"filesystem-updated",J=p(Ve==="existing-header"?x(ae.payload):g(ae.payload)),Or=m.copyrightStartYear===null?"created-date":"option",ce=m.copyrightStartYear??yr(J,r),Ge=p(se?x(se):g(ie||re(ze.updatedAt))),q=t.forceAuthorUpdate===!0,K=t.forceLastModifiedAuthorUpdate===!0,Je=Re({absoluteFilePath:y,language:m.language,syntaxOptions:T,projectRoot:m.projectRoot,projectName:m.projectName,createdByName:q?m.authorName:V.authorName||m.authorName,createdByEmail:q?m.authorEmail:V.authorEmail||m.authorEmail,lastModifiedByName:K?m.authorName:G.authorName||m.authorName,lastModifiedByEmail:K?m.authorEmail:G.authorEmail||m.authorEmail,authorName:m.authorName,authorEmail:m.authorEmail,createdAt:J,lastModifiedAt:Ge,copyrightStartYear:ce,companyName:m.companyName,currentYear:k}),qe=Oe(I,Je,y,T),X=qe.changed,Ke=X?p(g(re(new Date))):Ge,Tr=X?"current-time-on-change":Ir,U=X?Re({absoluteFilePath:y,language:m.language,syntaxOptions:T,projectRoot:m.projectRoot,projectName:m.projectName,createdByName:q?m.authorName:V.authorName||m.authorName,createdByEmail:q?m.authorEmail:V.authorEmail||m.authorEmail,lastModifiedByName:K?m.authorName:G.authorName||m.authorName,lastModifiedByEmail:K?m.authorEmail:G.authorEmail||m.authorEmail,authorName:m.authorName,authorEmail:m.authorEmail,createdAt:J,lastModifiedAt:Ke,copyrightStartYear:ce,companyName:m.companyName,currentYear:k}):Je,O=X?Oe(I,U,y,T):qe,le={file:R,changed:O.changed};if(c){let v=xr(S,{gitCreated:We,gitLastModified:ie,filesystemCreated:Ye},{strictCreatedDate:t.strictCreatedDate===!0}),_=v.filter(ue=>ue.advisory).length;le.dateIssues=v,He+=_,_e+=v.length>_?1:0}if(t.sampleOutput===!0&&O.changed){let v=S.length>0?S.trimEnd():null,_=R.replace(/\\/g,"/"),ue=O.nextContent.slice(0,O.nextContent.indexOf(U)).split(`
16
+ `).length-1;le.sample={previousValue:v,newValue:U,diff:Nr(v,U,{fromFile:`a/${_}`,toFile:`b/${_}`,lineOffset:ue}),issues:Sr(v,U),detectedValues:{projectName:m.projectName,projectNameSource:m.projectNameSource,language:m.language,projectRoot:m.projectRoot,marker:m.marker,authorName:m.authorName,authorEmail:m.authorEmail,companyName:m.companyName,companyNameSource:m.companyNameSource,copyrightStartYear:ce,copyrightStartYearSource:Or,createdAtSource:Ve,lastModifiedAtSource:Tr,createdAt:J,lastModifiedAt:Ke}}}D.push(le),O.changed&&(E+=1,l||await Do(y,O.nextContent,"utf8"))}return{metadata:s,detectedProjects:Array.from(Y),filesScanned:b.length-M.length,filesUpdated:E,filesSkipped:M.length,dryRun:l,check:c,...c?{filesWithDateDrift:_e,dateAdvisories:He}:{},changes:D,skipped:M}}i(Cr,"fixHeaders");function Mo(e){return Cr(e)}i(Mo,"fixHeaders");var Fr=Mo;var Io=`fix-headers CLI
17
17
 
18
18
  Usage:
19
19
  fix-headers [options]
@@ -35,13 +35,14 @@ Options:
35
35
  --force-last-modified-author-update Always update @Last modified by to detected/current values
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 Oo(e){return e.replace(/-([a-z])/g,(t,r)=>r.toUpperCase())}i(Oo,"toCamelCase");function To(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 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=Oo(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(To,"parseCliArgs");function Uo(e){return Z(e,"config")}i(Uo,"applyConfigFile");function Ue(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(Ue,"getSampledChanges");function Lr(e){return typeof e=="string"?`"${e}"`:"(missing)"}i(Lr,"formatIssueValue");function _o(e,t){for(let r of Ue(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 ${Lr(o?.previous)}, expected ${Lr(o?.detected)}`)}}i(_o,"printIssues");function Ho(e,t){for(let r of Ue(t))typeof r.sample.diff=="string"&&r.sample.diff.length>0&&e(r.sample.diff)}i(Ho,"printDiffs");function zo(e,t){for(let r of Ue(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 Bo(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(Bo,"printChangedFiles");function Wo(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(Wo,"printSkipped");function Mr(e,t,r,n){let o=r.sampleOutput===!0||n;r.verbose===!0&&(Bo(e,t),o&&_o(e,t)),r.sampleOutput===!0&&zo(e,t),n&&Ho(e,t)}i(Mr,"printDetails");function Yo(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(Yo,"printDateIssues");async function Vo(e,t={}){let r=t.runner||Fr,n=t.stdout||console.log,o=t.stderr||console.error;try{let a=To(e);if(a.help)return n(Io),0;let s=await Uo(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}`),Yo(n,l,s.verbose===!0),u;if(c&&typeof c=="object"){let f=c,p=Number(f.filesSkipped)>0?`, skipped=${f.filesSkipped}`:"";n(`fix-headers complete: scanned=${f.filesScanned??0}, updated=${f.filesUpdated??0}${p}, dryRun=${f.dryRun===!0}`),Wo(n,f),Mr(n,c,s,a.diff)}else Mr(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(Vo,"runCli");function Go(e=process.argv,t=import.meta.url,r=Vo){let n=!1;if(e[1])try{let o=jr(e[1]),a=jr(Po(t));n=o===a}catch{n=t===Ro(e[1]).href}return n?(r(e.slice(2)).then(o=>{process.exitCode=o}),!0):!1}i(Go,"runCliAsMain");Go();export{Uo as applyConfigFile,To as parseCliArgs,Vo as runCli,Go 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;