@cldmv/fix-headers 2.2.7 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -33
- package/bin/fix-headers.mjs +29 -25
- package/dist/index.cjs +2 -2
- package/dist/index.mjs +32 -28
- package/package.json +1 -1
- package/types/src/detectors/c.d.mts +18 -0
- package/types/src/detectors/index.d.mts +4 -3
- package/types/src/detectors/node.d.mts +1 -0
- package/types/src/header/fields.d.mts +2 -2
- package/types/src/utils/diff.d.mts +2 -2
- package/types/src/utils/text.d.mts +2 -2
- package/types/src/utils/time.d.mts +2 -2
package/bin/fix-headers.mjs
CHANGED
|
@@ -1,36 +1,40 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
`)
|
|
5
|
-
`)
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
`)
|
|
2
|
+
var yr=Object.defineProperty;var s=(e,t)=>yr(e,"name",{value:t,configurable:!0});import{realpathSync as or}from"node:fs";import{fileURLToPath as Mi,pathToFileURL as Ii}from"node:url";import{readFile as xr}from"node:fs/promises";import{createRequire as wr}from"node:module";import{dirname as br,isAbsolute as kr,resolve as dt}from"node:path";var Er=3e4,$r=new Set(["localhost","127.0.0.1","[::1]"]);function we(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}s(we,"isPlainObject");function be(e,t){let n={...e};for(let[r,o]of Object.entries(t))r!=="__proto__"&&(n[r]=we(n[r])&&we(o)?be(n[r],o):o);return n}s(be,"mergeConfig");function mt(e){return e.kind==="file"?e.path:e.href}s(mt,"describeSource");async function Sr(e){if(e.kind==="file")return{text:await xr(e.path,"utf8"),source:e};let t;try{t=await fetch(e.href,{cache:"no-store",redirect:"follow",signal:AbortSignal.timeout(Er)})}catch(n){let r=n.cause instanceof Error?n.cause.message:n.message;throw new Error(`Failed to fetch config ${e.href}: ${r}`,{cause:n})}if(!t.ok)throw new Error(`Failed to fetch config ${e.href}: HTTP ${t.status} ${t.statusText}`);return{text:await t.text(),source:{kind:"url",href:t.url}}}s(Sr,"readSource");function ft(e){if(e.protocol==="http:"&&!$r.has(e.hostname))throw new Error(`Refusing to fetch config over plain http: ${e.href} (use https)`);return{kind:"url",href:e.href}}s(ft,"toUrlSource");function Ar(e,t){if(/^https?:\/\//i.test(e))return ft(new URL(e));if(/^[a-z][a-z\d+.-]+:\/\//i.test(e))throw new Error(`Unsupported extends URL "${e}" in ${mt(t)}; use https, a file path or a package path`);let n=/^\.{1,2}[\\/]/.test(e);if(t.kind==="url"){if(n||e.startsWith("/"))return ft(new URL(e,t.href));throw new Error(`Cannot extend package "${e}" from the remote config ${t.href}; use a URL or a relative path`)}if(n||kr(e))return{kind:"file",path:dt(br(t.path),e)};try{return{kind:"file",path:wr(t.path).resolve(e)}}catch(r){throw new Error(`Cannot resolve extends "${e}" from ${t.path}: ${r.message}`,{cause:r})}}s(Ar,"resolveReference");function Cr(e,t){if(e===void 0)return[];let n=Array.isArray(e)?e:[e];if(!n.every(r=>typeof r=="string"&&r.trim().length>0))throw new Error(`Config "extends" must be a string or an array of strings: ${t}`);return n.map(r=>r.trim())}s(Cr,"readExtends");async function pt(e,t){let n=mt(e);if(t.includes(n))throw new Error(`Config extends cycle: ${[...t,n].join(" -> ")}`);let{text:r,source:o}=await Sr(e),i;try{i=JSON.parse(r)}catch(f){throw new Error(`Config ${n} is not valid JSON: ${f.message}`,{cause:f})}if(!we(i))throw new Error(`Config file must contain a JSON object: ${n}`);let{extends:a,...c}=i,l={};for(let f of Cr(a,n))l=be(l,await pt(Ar(f,o),[...t,n]));return be(l,c)}s(pt,"loadSource");function Dr(e,t=process.cwd()){return pt({kind:"file",path:dt(t,e)},[])}s(Dr,"loadConfigFile");async function re(e,t){let n=typeof e[t]=="string"?e[t].trim():"";if(n.length===0)return e;let r=typeof e.cwd=="string"&&e.cwd.length>0?e.cwd:process.cwd(),o={...await Dr(n,r),...e};return delete o[t],o}s(re,"applyConfigOption");import{readFile as $i,stat as Si,writeFile as Ai}from"node:fs/promises";import{relative as Ve,resolve as tr}from"node:path";import{extname as ke}from"node:path";import{extname as vr}from"node:path";var gt=[".c",".h",".cc",".cpp",".cxx",".hh",".hpp",".hxx"],Fr=400,Nr=/\bcopyright\b|\blicen[cs]e[ds]?\b|SPDX-License-Identifier|\bpublic domain\b/i,ht=/^[\s*/]*@(?:Project|Filename):/m;function Lr(e){let t=vr(e).toLowerCase();return gt.includes(t)?{kind:"block",blockStart:"/*",blockLinePrefix:" * ",blockEnd:" */"}:null}s(Lr,"resolveCCommentSyntax");function jr(e){let t=e.replace(/^\uFEFF/,"").split(`
|
|
3
|
+
`).slice(0,Fr),n=[],r=null,o=null,i=!1;for(let a of t){let c=a.replace(/\r$/,"");if(r){r.push(c),c.includes("*/")&&(n.push(r.join(`
|
|
4
|
+
`)),r=null);continue}if(i){i=c.endsWith("\\");continue}let l=c.trim();if(o&&!l.startsWith("//")&&(n.push(o.join(`
|
|
5
|
+
`)),o=null),l.length!==0){if(l.startsWith("//")){(o??=[]).push(l);continue}if(l.startsWith("/*")){let f=l.indexOf("*/",2);if(f===-1){r=[l];continue}if(n.push(l.slice(0,f+2)),l.slice(f+2).trim().length>0)break;continue}if(l.startsWith("#")){i=l.endsWith("\\");continue}break}}return o&&n.push(o.join(`
|
|
6
|
+
`)),n}s(jr,"prologueComments");var yt={id:"c",extensions:gt,enabledByDefault:!0,resolveContentSkipReason(e){let t=jr(e);return t.length>0&&ht.test(t[0])?null:t.some(n=>!ht.test(n)&&Nr.test(n))?"the file starts with a license or copyright notice that is not a fix-headers header (third-party code)":null},resolveCommentSyntax(e){return Lr(e)}};import{extname as Rr}from"node:path";var xt=[".css"];function Mr(e){let t=Rr(e).toLowerCase();return xt.includes(t)?{kind:"block",blockStart:"/*",blockLinePrefix:" * ",blockEnd:" */"}:null}s(Mr,"resolveCssCommentSyntax");var wt={id:"css",extensions:xt,enabledByDefault:!0,keepsAboveHeader:s((e,t)=>t===0&&/^@charset "[^"]*";/.test(e),"keepsAboveHeader"),resolveCommentSyntax(e){return Mr(e)}};import{extname as Tr}from"node:path";var Ir=/^(?:#|\/\/|\/\*+|<!--)[ \t]+(vi|vim(?:[<=>]?\d+)?|Vim|ex):(.*)$/,Pr=/^[a-z]+(?:[!&]|[+^-]?=(?:\\.|[^\s:\\])*)?$/,Or=new Set(["et","expandtab","ai","autoindent","si","smartindent","ro","readonly","bin","binary","noet","noexpandtab","noai","noautoindent","nosi","nosmartindent","noro","noreadonly","nobin","nobinary","nowrap","nolist","nospell","nofen","nofoldenable","noeol","nofixeol","nofixendofline"]);function oe(e){let t=e.match(Ir);if(!t)return!1;let n=t[2].trim();if(n.endsWith("-->"))n=n.slice(0,-3).trimEnd();else if(n.endsWith("*/")){let i=n.length-2;for(;i>0&&n[i-1]==="*";)i-=1;n=n.slice(0,i).trimEnd()}let r=n.match(/^se(?:t)?[ \t]((?:\\.|[^:\\])*):/);if(!r&&t[1]==="Vim")return!1;let o=r?r[1].match(/(?:\\.|[^\s\\])+/g):n.match(/(?:\\.|[^\s:\\])+/g);return o!==null&&o.every(i=>Pr.test(i))&&o.some(i=>i.includes("=")||Or.has(i))}s(oe,"isModeline");function ie(e,t){return t===0&&e.startsWith("#!")}s(ie,"isShebang");function se(e,t,n=0){let r=0,o=n;for(;r<e.length;){let i=e.indexOf(`
|
|
7
|
+
`,r),a=i===-1?e.length:i+1;if(!t(e.slice(r,a).replace(/\r?\n$/,""),o))break;r=a,o+=1}return e.slice(0,r)}s(se,"takeTopLines");var kt=[".go"];function Hr(e){let t=Tr(e).toLowerCase();return kt.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}s(Hr,"resolveGoCommentSyntax");var bt=/^\/\/(?:go:build|\s*\+build)\s/;function _r(e,t){let n=se(t,o=>bt.test(o)||oe(o));if(!n.split(/\r?\n/).some(o=>bt.test(o)))return"";let r=t.slice(n.length);return`${n}${r.slice(0,r.length-r.replace(/^(?:[ \t]*\r?\n)*/,"").length)}`}s(_r,"resolveGoPreservedPrefix");var Et={id:"go",extensions:kt,enabledByDefault:!0,resolvePreservedPrefix(e,t){return _r(e,t)},resolveCommentSyntax(e){return Hr(e)}};import{extname as Ur}from"node:path";var $t=[".html",".htm"];function Wr(e){let t=Ur(e).toLowerCase();return $t.includes(t)?{kind:"html",blockStart:"<!--",blockLinePrefix:" ",blockEnd:"-->"}:null}s(Wr,"resolveHtmlCommentSyntax");var St={id:"html",extensions:$t,enabledByDefault:!0,resolveCommentSyntax(e){return Wr(e)}};import{extname as Br}from"node:path";var At=[".jsonv",".jsonc",".json5"];function zr(e){let t=Br(e).toLowerCase();return At.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}s(zr,"resolveJsonCommentSyntax");var Ct={id:"json",extensions:At,enabledByDefault:!0,resolveCommentSyntax(e){return zr(e)}};import{extname as Gr}from"node:path";var Dt=[".md",".markdown"];function Yr(e){let t=Gr(e).toLowerCase();return Dt.includes(t)?{kind:"html",blockStart:"<!--",blockLinePrefix:" ",blockEnd:"-->"}:null}s(Yr,"resolveMarkdownCommentSyntax");function Vr(e,t){let n=t.match(/^---\r?\n[\s\S]*?\r?\n---[ \t]*(?:\r?\n|$)/);return n?n[0]:""}s(Vr,"resolveMarkdownPreservedPrefix");var vt={id:"markdown",extensions:Dt,enabledByDefault:!1,requiresForce:!0,resolvePreservedPrefix(e,t){return Vr(e,t)},resolveCommentSyntax(e){return Yr(e)}};import{basename as Ft,extname as Jr}from"node:path";var Nt=[".js",".mjs",".cjs",".ts",".mts",".cts",".tsx",".jsx"];function Kr(e){let t=Jr(e).toLowerCase();return Nt.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}s(Kr,"resolveNodeCommentSyntax");var qr=/^(.+)\.d\.(ts|mts|cts)$/i,Xr={ts:[".ts",".tsx",".js",".jsx"],mts:[".mts",".mjs"],cts:[".cts",".cjs"]};function Zr(e){let t=/^\s*\/\*[\s\S]*?\*\//.exec(e.replace(/^\uFEFF/,""));if(!t)return null;let n=/^[\s*]*@Filename:[ \t]*(\S+)/m.exec(t[0]);return n?n[1]:null}s(Zr,"leadingHeaderFilename");function Qr(e,t){let n=qr.exec(Ft(t));if(!n)return null;let r=Zr(e);if(r===null)return null;let o=Ft(r),[,i,a]=n;return Xr[a.toLowerCase()].some(l=>o===`${i}${l}`)?`the file is a declaration generated from ${o} and carries its header (tsc copies it)`:null}s(Qr,"declarationCopySkipReason");var Lt={id:"node",extensions:Nt,enabledByDefault:!0,keepsAboveHeader:ie,resolveContentSkipReason(e,t){return Qr(e,t)},resolveCommentSyntax(e){return Kr(e)}};import{extname as eo}from"node:path";var Rt=[".php"];function to(e){let t=eo(e).toLowerCase();return Rt.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}s(to,"resolvePhpCommentSyntax");var jt=/^<\?php(?:\s|$)/i,Mt={id:"php",extensions:Rt,enabledByDefault:!0,keepsAboveHeader:s((e,t)=>t===0&&jt.test(e),"keepsAboveHeader"),resolveContentSkipReason(e){return jt.test(e.replace(/^\uFEFF/,""))?null:"the file does not start with <?php, so a comment at the top would be output as text"},resolveCommentSyntax(e){return to(e)}};import{extname as no}from"node:path";var It=[".py"],ro=/^#.*?(?<![A-Za-z])coding[:=]\s*[-\w.]+/;function oo(e,t){return ie(e,t)||t<=1&&ro.test(e)}s(oo,"keepsAboveHeader");var Pt={id:"python",extensions:It,enabledByDefault:!0,keepsAboveHeader:oo,resolveCommentSyntax(e){let t=no(e).toLowerCase();return It.includes(t)?{kind:"line",linePrefix:"#"}:null}};import{extname as io}from"node:path";var Ot=[".rs"];function so(e){let t=io(e).toLowerCase();return Ot.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}s(so,"resolveRustCommentSyntax");var Tt={id:"rust",extensions:Ot,enabledByDefault:!0,keepsAboveHeader:s((e,t)=>t===0&&e.startsWith("#!")&&!/^#!\s*\[/.test(e),"keepsAboveHeader"),resolveCommentSyntax(e){return so(e)}};import{extname as ao}from"node:path";var Ht=[".yaml",".yml"];function co(e){let t=ao(e).toLowerCase();return Ht.includes(t)?{kind:"line",linePrefix:"#"}:null}s(co,"resolveYamlCommentSyntax");var _t={id:"yaml",extensions:Ht,enabledByDefault:!0,keepsAboveHeader:s((e,t)=>t===0&&/^#cloud-config\s*$/.test(e),"keepsAboveHeader"),resolveCommentSyntax(e){return co(e)}};var ae=[yt,wt,Et,St,Ct,vt,Lt,Mt,Pt,Tt,_t],lo=new Map(ae.map(e=>[e.id,e]));function uo(e,t){return!t||typeof t!="object"?e:e.kind==="line"?{...e,linePrefix:typeof t.linePrefix=="string"&&t.linePrefix.length>0?t.linePrefix:e.linePrefix,lineSeparator:typeof t.lineSeparator=="string"?t.lineSeparator:e.lineSeparator}:{...e,blockStart:typeof t.blockStart=="string"&&t.blockStart.length>0?t.blockStart:e.blockStart,blockLinePrefix:typeof t.blockLinePrefix=="string"&&t.blockLinePrefix.length>0?t.blockLinePrefix:e.blockLinePrefix,blockEnd:typeof t.blockEnd=="string"&&t.blockEnd.length>0?t.blockEnd:e.blockEnd}}s(uo,"applySyntaxOverride");function Ut(e){if(e==null)return[];if(!Array.isArray(e)||e.some(n=>typeof n!="string"))throw new Error(`forcedDetectors must be an array of detector ids, got ${JSON.stringify(e)}`);let t=ae.filter(n=>n.requiresForce===!0).map(n=>n.id);for(let n of e){if(!lo.has(n))throw new Error(`forcedDetectors: unknown detector "${n}" (force-only detectors: ${t.join(", ")})`);if(!t.includes(n))throw new Error(`forcedDetectors: "${n}" does not need forcing (force-only detectors: ${t.join(", ")})`)}return Array.from(new Set(e))}s(Ut,"resolveForcedDetectors");function O(e={}){let t=new Set(Array.isArray(e.enabledDetectors)?e.enabledDetectors:[]),n=new Set(Array.isArray(e.disabledDetectors)?e.disabledDetectors:[]),r=new Set(Array.isArray(e.forcedDetectors)?e.forcedDetectors:[]);return ae.filter(o=>o.requiresForce===!0?r.has(o.id)&&!n.has(o.id):t.size>0?t.has(o.id):n.has(o.id)?!1:o.enabledByDefault)}s(O,"getEnabledDetectors");function Wt(e={}){if(Array.isArray(e.includeExtensions)&&e.includeExtensions.length>0)return new Set(e.includeExtensions.map(n=>n.toLowerCase()));let t=O(e);return new Set(t.flatMap(n=>n.extensions))}s(Wt,"getAllowedExtensions");function Bt(e,t={}){let n=ke(e).toLowerCase();if(O(t).some(a=>a.extensions.includes(n)&&a.resolveCommentSyntax(e)!==null))return null;if(n.length===0)return"the file has no extension, so its comment syntax is unknown";let o=new Set(Array.isArray(t.forcedDetectors)?t.forcedDetectors:[]),i=ae.find(a=>a.requiresForce===!0&&a.extensions.includes(n)&&!o.has(a.id));return i?`${n} files get a header only when forced (--force-detector ${i.id} / forcedDetectors: ["${i.id}"])`:`no enabled detector handles ${n} files`}s(Bt,"getHeaderSkipReason");function zt(e,t={}){let n=ke(e).toLowerCase(),r=Array.isArray(t.detectors)?t.detectors:O(t);for(let o of r){if(!o.extensions.includes(n))continue;let i=o.resolveCommentSyntax(e);if(i){let a=t.detectorSyntaxOverrides&&typeof t.detectorSyntaxOverrides=="object"?t.detectorSyntaxOverrides:{};return uo(i,a[o.id])}}return{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}}s(zt,"getCommentSyntaxForFile");function Gt(e,t){let n=ke(e).toLowerCase();return O(t).find(r=>r.extensions.includes(n))}s(Gt,"detectorForFile");function ce(e,t,n={}){let r=Gt(e,n);if(!r)return"";let o=typeof r.resolvePreservedPrefix=="function"?r.resolvePreservedPrefix(e,t):"",i=r.keepsAboveHeader,a=se(t.slice(o.length),(c,l)=>oe(c)||typeof i=="function"&&i(c,l),o.split(`
|
|
8
|
+
`).length-1);return`${o}${a}`}s(ce,"getPreservedPrefixForFile");function Yt(e,t,n={}){let r=Gt(e,n);return r&&typeof r.resolveContentSkipReason=="function"?r.resolveContentSkipReason(t,e):null}s(Yt,"getContentSkipReason");var Vt=200,X=1,le=2;function T(e,t,n){if(e==null)return n;if(typeof e!="number"||!Number.isInteger(e)||e<0)throw new Error(`${t} must be a whole number of 0 or more, got ${JSON.stringify(e)}`);return e}s(T,"resolveLayoutCount");import{existsSync as $o}from"node:fs";import{join as Fe,relative as an,resolve as Ne,sep as De}from"node:path";import{realpath as So,stat as Ao}from"node:fs/promises";import{access as fo,readdir as mo,readFile as na,stat as po}from"node:fs/promises";import{constants as ho}from"node:fs";import{dirname as ia,join as go,resolve as sa}from"node:path";async function Ee(e){try{return await fo(e,ho.F_OK),!0}catch{return!1}}s(Ee,"pathExists");async function $e(e,t){let n=[],r=await mo(e,{withFileTypes:!0});for(let o of r){let i=go(e,o.name);if(o.isDirectory()&&t.recursive===!1||o.isDirectory()&&t.ignoreFolders.has(o.name)||o.isDirectory()&&await t.shouldSkipDirectory?.(i,o.name)===!0)continue;if(o.isDirectory()){let l=await $e(i,t);n.push(...l);continue}if(!o.isFile())continue;let a=o.name.lastIndexOf(".");if(a===-1)continue;let c=o.name.slice(a).toLowerCase();t.allowedExtensions.has(c)&&n.push(i)}return n}s($e,"walkFiles");async function Jt(e){let t=await po(e);return{createdAt:t.birthtimeMs>0&&t.birthtime<t.mtime?t.birthtime:t.mtime,updatedAt:t.mtime}}s(Jt,"readFileDates");function Kt(e){let t=e.indexOf("<");for(;t!==-1;){let n=e.indexOf(">",t+1);if(n===-1)return!1;if(n>t+1)return!0;t=e.indexOf("<",n+1)}return!1}s(Kt,"hasAngleTag");function qt(e){let t=e.length;for(;t>0&&e[t-1]==="/";)t-=1;return e.slice(0,t)}s(qt,"trimTrailingSlashes");import{execFile as yo}from"node:child_process";import{lstat as xo,readFile as wo}from"node:fs/promises";import{dirname as Xt,isAbsolute as bo,join as en,relative as tn,resolve as Se,sep as nn}from"node:path";import ko from"ignore";function Zt(e,t){return new Promise(n=>{yo("git",t,{cwd:e,encoding:"utf8",maxBuffer:Number.POSITIVE_INFINITY},(r,o)=>{if(!r){n({code:0,stdout:o});return}n({code:typeof r.code=="number"?r.code:-1,stdout:""})})})}s(Zt,"runGitCommand");function Ce(e,t){return tn(e,t).split(nn).join("/")}s(Ce,"toPosixRelative");async function rn(e){try{return ko().add(await wo(e,"utf8"))}catch{return null}}s(rn,"readIgnoreFile");async function Eo(e){return xo(en(e,".git")).then(()=>!0,()=>!1)}s(Eo,"hasGitEntry");function Qt(e,t,n){for(let r=e.length-1;r>=0;r--){let{base:o,rules:i}=e[r],a=i.test(`${Ce(o,t)}${n?"/":""}`);if(a.ignored||a.unignored)return a.ignored}return!1}s(Qt,"matchesRules");async function on(e,t){let n=await rn(en(e,".gitignore"));return{kind:"rules",nested:!0,excluded:!1,matchers:n?[...t,{base:e,rules:n}]:t}}s(on,"buildRulesContext");async function Ae(e){let[t,n]=await Promise.all([Zt(e,["check-ignore","-q","."]),Zt(e,["ls-files","--cached","--others","--exclude-standard","-z"])]);if(t.code!==1||n.code!==0)return on(e,[]);let r=new Set,o=new Set;for(let i of n.stdout.split("\0")){let a=i.endsWith("/")?i.slice(0,-1):i;if(a.length!==0){r.add(a);for(let c=a.indexOf("/");c!==-1;c=a.indexOf("/",c+1))o.add(a.slice(0,c))}}return{kind:"git",root:e,entries:r,dirs:o}}s(Ae,"resolveScopeContext");function sn(e){let t=Se(e.root),n=e.gitignore;if(n===!1)return{isIgnored:s(async()=>!1,"isIgnored")};let r=new Map,o=s(async()=>{if(typeof n!="string"&&!Array.isArray(n))return Ae(t);let c=typeof n=="string"?[n]:n.filter(f=>typeof f=="string"),l=[];for(let f of c){let u=await rn(Se(t,f));u&&l.push({base:t,rules:u})}return{kind:"rules",nested:!1,excluded:!1,matchers:l}},"buildRootContext"),i=s(c=>{let l=r.get(c);return l||(l=c===t?o():a(c),r.set(c,l)),l},"contextFor"),a=s(async c=>{let l=await i(Xt(c));return l.kind==="git"?l.entries.has(Ce(l.root,c))?Ae(c):l:!l.nested||l.excluded?l:Qt(l.matchers,c,!0)?{...l,excluded:!0}:await Eo(c)?Ae(c):on(c,l.matchers)},"deriveContext");return{async isIgnored(c,l){let f=Se(c),u=tn(t,f);if(u.length===0||u===".."||u.startsWith(`..${nn}`)||bo(u))return!1;let m=await i(Xt(f));if(m.kind==="git"){let h=Ce(m.root,f);return!(m.entries.has(h)||l&&m.dirs.has(h))}return m.excluded||Qt(m.matchers,f,l)}}}s(sn,"createIgnoreFilter");function Co(e){return Wt(e)}s(Co,"resolveExtensions");var Do=Object.freeze(["node_modules","bower_components","jspm_packages",".pnpm-store",".yarn"]),un=new Set([".git",...Do]),vo=Object.freeze(["autoload.php","modules.txt"]);function cn(e,t){return un.has(t)?!0:t==="vendor"&&vo.some(n=>$o(Fe(e,n)))}s(cn,"isNeverWalked");function ve(e){return qt(e.replace(/\\/g,"/").replace(/^\.\//,"").replace(/^\/+/,""))}s(ve,"normalizeFolderPath");function Fo(e){return Array.isArray(e)?e.map(t=>{if(typeof t=="string")return{path:t,recursive:!0};if(t&&typeof t=="object"&&typeof t.path=="string")return{path:t.path,recursive:t.recursive!==!1};throw new TypeError(`Invalid includeFolders entry: ${JSON.stringify(t)} (expected a path string or { path, recursive? })`)}):[]}s(Fo,"resolveIncludeFolders");function ln(e,t){let n=t instanceof Error?t.message:String(t);console.warn(`fix-headers: skipped include folder "${e}" (${n})`)}s(ln,"reportSkippedIncludeFolder");function No(e,t){if(!Array.isArray(t)||t.length===0)return()=>!1;let n=Ne(e),r=[],o=new Set;for(let i of t){if(typeof i!="string")continue;let a=ve(i);if(a.length!==0){if(a.includes("/")){r.push(Ne(n,a));continue}o.add(a)}}return(i,a)=>{if(o.has(a))return!0;for(let l of r)if(i===l||i.startsWith(`${l}/`))return!0;let c=ve(an(n,i));return r.some(l=>{let f=ve(an(n,l));return c===f||c.startsWith(`${f}/`)})}}s(No,"buildExclusionMatcher");async function Le(e){let t=Co(e),n=Fo(e.includeFolders),r=Array.isArray(e.excludeFolders)?e.excludeFolders:[],o=No(e.projectRoot,r),i=sn({root:e.projectRoot,gitignore:e.gitignore}),a=s(async(d,p)=>cn(d,p)||o(d,p)||await i.isIgnored(d,!0),"shouldSkipDirectory"),c=n.length>0?n.map(d=>({includeFolder:d.path,rootPath:Fe(e.projectRoot,d.path),recursive:d.recursive})):[{includeFolder:".",rootPath:e.projectRoot,recursive:!0}],l=[];for(let d of c){let p=await Ao(d.rootPath).catch(b=>b);if(p instanceof Error){if(p.code==="ENOENT"){ln(d.includeFolder,p);continue}throw p}if(!p.isDirectory()){ln(d.includeFolder,`path is not a directory: ${d.rootPath}`);continue}let w=await So(d.rootPath).catch(()=>Ne(d.rootPath));l.push({...d,realRoot:w})}let f=s((d,p)=>{if(d.realRoot===p.realRoot)return d.recursive||!p.recursive;let w=d.realRoot.endsWith(De)?d.realRoot:`${d.realRoot}${De}`;if(!d.recursive||!p.realRoot.startsWith(w))return!1;let b=d.rootPath;for(let $ of p.realRoot.slice(w.length).split(De))if(b=Fe(b,$),cn(b,$)||o(b,$))return!1;return!0},"covers"),u=[...l].sort((d,p)=>d.realRoot.length-p.realRoot.length||Number(p.recursive)-Number(d.recursive)),m=[];for(let d of u)m.some(p=>f(p,d))||m.push(d);let h=[];for(let d of l){if(!m.includes(d))continue;let p=await $e(d.rootPath,{allowedExtensions:t,ignoreFolders:un,shouldSkipDirectory:a,recursive:d.recursive});h.push(...p)}let y=[];for(let d of new Set(h))!o(d,d.split("/").at(-1)||"")&&!await i.isIgnored(d,!1)&&y.push(d);return y}s(Le,"discoverFiles");import{basename as ni,dirname as ri,extname as oi,resolve as Oe}from"node:path";import{dirname as En,isAbsolute as Uo,join as $n,relative as Wo,resolve as Sn,sep as Bo}from"node:path";import{readFile as Lo}from"node:fs/promises";import{join as jo}from"node:path";async function Ro(e){try{return await Lo(e,"utf8")}catch{return null}}s(Ro,"readManifest");async function j(e,t){let n=[];for(let r of t){let o=await Ro(jo(e,r));o!==null&&n.push({file:r,content:o})}return n.length>0?{dir:e,manifest:n[0].file,files:n}:null}s(j,"detectManifests");function H(e,t){return e.files.find(n=>n.file===t)?.content??null}s(H,"manifestContent");function C(e){return typeof e=="string"&&e.trim().length>0?e.trim():void 0}s(C,"cleanName");function je(e){if(typeof e!="string")return;let t=e.search(/[<(]/);return C(t===-1?e:e.slice(0,t))}s(je,"personName");function ue(e){try{return JSON.parse(e)}catch{return}}s(ue,"parseJsonManifest");function*Re(e,t){let n="";for(let r of e.split(/\r?\n/)){let o=r.trim();if(o.startsWith("[")){let i=o.match(/^\[([^[\]]+)\]/);n=i?i[1].split(".").map(a=>a.trim()).join("."):"";continue}n===t&&(yield o)}}s(Re,"sectionLines");function Z(e,t,n){let r=new RegExp(`^${n}\\s*=\\s*(?:"([^"\\\\]*)"|'([^']*)')`);for(let o of Re(e,t)){let i=o.match(r);if(i)return C(i[1]??i[2])}}s(Z,"readTomlString");function Me(e,t,n){let r=new RegExp(`^${n}\\s*[=:](.*)$`);for(let o of Re(e,t)){let i=o.match(r);if(i)return C(i[1])}}s(Me,"readIniValue");function Mo(e,t,n){let r=new RegExp(`^${n}\\s*=\\s*\\[`),o=null;for(let i of Re(e,t)){if(o!==null){o.push(i);continue}let a=i.match(r);a&&(o=[i.slice(a[0].length)])}return o===null?null:o.join(`
|
|
9
|
+
`)}s(Mo,"tomlArrayText");function Io(e,t){let n=t;for(;n<e.length;)if(e[n]==="#"){let r=e.indexOf(`
|
|
10
|
+
`,n);n=r===-1?e.length:r+1}else if(/\s/.test(e[n]))n+=1;else break;return n}s(Io,"skipTomlSpace");function Q(e,t){let n=Mo(e,t,"authors");if(n===null)return;let r=n.slice(Io(n,0)),o=r.match(/^(?:"([^"\\\n]*)"|'([^'\n]*)')/);if(o)return je(o[1]??o[2]);let a=r.match(/^\{([^}\n]*)\}/)?.[1].match(/(?:^|,)\s*name\s*=\s*(?:"([^"\\\n]*)"|'([^'\n]*)')/);return a?C(a[1]??a[2]):void 0}s(Q,"readTomlAuthor");var fn=["go.mod"];function Po(e){let t=e.match(/^\s*module\s+(.+)$/m);if(t)return C(t[1].replace(/\/\/.*$/,"").trim().replace(/^["`](.*)["`]$/,"$1"))}s(Po,"readModulePath");var dn={id:"go",languages:["go"],manifests:fn,detect(e){return j(e,fn)},read(e){return{name:Po(e.files[0].content)}}};var mn=["package.json"];function Oo(e){let t=C(e?.name),n=C(e?.publisher),r=typeof e?.engines?.vscode=="string";return t&&n&&r?`${n}.${t}`:t}s(Oo,"readPublishedName");function To(e){if(e!==null&&typeof e=="object"){let t=e;return C(t.company)??C(t.name)}return je(e)}s(To,"readAuthorCompany");var pn={id:"node",languages:["node"],manifests:mn,detect(e){return j(e,mn)},read(e){let t=ue(e.files[0].content);return{name:Oo(t),company:To(t?.author)}}};var hn=["composer.json"],gn={id:"php",languages:["php"],manifests:hn,detect(e){return j(e,hn)},read(e){let t=ue(e.files[0].content),n=t?.authors;return{name:C(t?.name),company:Array.isArray(n)?C(n[0]?.name):void 0}}};var yn=["pyproject.toml","setup.cfg","setup.py"];function xn(e,t){let n=e.indexOf("setup(");if(n===-1)return;let r=e.slice(n).match(new RegExp(`\\b${t}\\s*=\\s*(["'])([^"'\\n]+)\\1`));return r&&r[2].trim()||void 0}s(xn,"readSetupPyArgument");function Ho(e){let t=H(e,"pyproject.toml"),n=H(e,"setup.cfg"),r=H(e,"setup.py");return(t===null?void 0:Z(t,"project","name")??Z(t,"tool.poetry","name"))??(n===null?void 0:Me(n,"metadata","name"))??(r===null?void 0:xn(r,"name"))}s(Ho,"readPythonName");function _o(e){let t=H(e,"pyproject.toml"),n=H(e,"setup.cfg"),r=H(e,"setup.py");return(t===null?void 0:Q(t,"project")??Q(t,"tool.poetry"))??(n===null?void 0:Me(n,"metadata","author"))??(r===null?void 0:xn(r,"author"))}s(_o,"readPythonCompany");var wn={id:"python",languages:["python"],manifests:yn,detect(e){return j(e,yn)},read(e){return{name:Ho(e),company:_o(e)}}};var bn=["Cargo.toml"],kn={id:"rust",languages:["rust"],manifests:bn,detect(e){return j(e,bn)},read(e){let t=e.files[0].content;return{name:Z(t,"package","name"),company:Q(t,"package")}}};var zo=[pn,wn,gn,kn,dn],An=["name","company"];async function Ie(e,t,n){let o=(await Promise.all(t.map(async a=>({driver:a,detection:await a.detect(e)})))).filter(a=>a.detection!==null),i=o.filter(a=>typeof n=="string"&&a.driver.languages.includes(n));return[...i,...o.filter(a=>!i.includes(a))]}s(Ie,"claimFolder");function Go(e,t){let n=Wo(t,e);return n!==""&&n!==".."&&!n.startsWith(`..${Bo}`)&&!Uo(n)}s(Go,"isStrictlyInside");async function Cn(e,t={}){let n=Array.isArray(t.drivers)?t.drivers:zo,r=typeof t.scanRoot=="string"?Sn(t.scanRoot):null,o=Sn(e),i=await Ie(o,n,t.language);for(;i.length===0;){if(await Ee($n(o,".git")))return{root:o,marker:".git",drivers:[],fields:{},sources:{}};let u=En(o);if(u===o)return null;o=u,i=await Ie(o,n,t.language)}let a={},c={},l=o,f=i;for(;;){for(let{driver:m,detection:h}of f){let y=m.read(h);for(let d of An)a[d]===void 0&&y[d]!==void 0&&(a[d]=y[d],c[d]={driver:m.id,manifest:h.manifest,dir:l})}if(An.every(m=>a[m]!==void 0)||r===null||!Go(l,r)||await Ee($n(l,".git")))break;l=En(l),f=await Ie(l,n,t.language)}return{root:o,marker:i[0].detection.manifest,drivers:i.map(u=>u.driver.id),fields:a,sources:c}}s(Cn,"resolveManifestProject");import{execFile as Yo}from"node:child_process";import{basename as Vo,dirname as Jo}from"node:path";import{promisify as Ko}from"node:util";var Pe=Ko(Yo);async function N(e,t){try{let{stdout:n}=await Pe("git",t,{cwd:e}),r=n.trim();return r.length>0?r:null}catch{return null}}s(N,"runGit");function Dn(e,t){let n=0;for(let r=t-1;r>=0&&e[r]==="\\";r--)n++;return n%2===1}s(Dn,"isEscaped");function qo(e){let t=e.trim();if(!t.endsWith(")")||Dn(t,t.length-1))return t;let n=0;for(let r=t.length-1;r>=0;r--){let o=t[r];if(!(o!=="("&&o!==")"||Dn(t,r))&&(n+=o===")"?1:-1,n===0))return t.slice(0,r).trim()}return t}s(qo,"stripUidComment");function Xo(e){let t=e.trim();if(t.length===0)return{authorName:null,authorEmail:null};let n=t.match(/<([^>\n]+)>\s*$/),r=n?.[1]?.trim()||null,o=(n?t.slice(0,n.index):t).trim();return{authorName:qo(o)||o||null,authorEmail:r}}s(Xo,"parseSignerUid");async function Zo(e,t){try{let{stdout:n}=await Pe(e,t),r=n.trim();return r.length>0?r:null}catch{return null}}s(Zo,"runProgram");function Qo(e){return e.replace(/\\x([0-9a-fA-F]{2})/g,(t,n)=>String.fromCharCode(Number.parseInt(n,16)))}s(Qo,"decodeColonField");async function ei(e){let t=await N(e,["config","--get","gpg.format"]);if(t!==null&&t!=="openpgp")return null;let n=await N(e,["config","--get","user.signingkey"]);if(!n)return null;let r=await N(e,["config","--get","gpg.openpgp.program"])||await N(e,["config","--get","gpg.program"])||"gpg",o=await Zo(r,["--batch","--with-colons","--list-keys",n]);if(!o)return null;for(let i of o.split(`
|
|
11
|
+
`)){let a=i.split(":");if(a[0]==="uid"&&a[1]!=="r"&&a[1]!=="e"&&a[9])return Qo(a[9])}return null}s(ei,"readSigningKeyUid");async function vn(e,t={}){let n=await N(e,["config","--get","user.name"]),r=await N(e,["config","--get","user.email"]);if(t.useGpgSignerAuthor===!0){let o=await ei(e)||await N(e,["log","-1","--format=%GS"]),i=Xo(o||"");n=i.authorName||n,r=r||i.authorEmail}if(!n||!r){let o=await N(e,["log","-1","--format=%an|%ae"]);if(o){let[i,a]=o.split("|");n=n||i||null,r=r||a||null}}return{authorName:n,authorEmail:r}}s(vn,"detectGitAuthor");function Fn(e){return e.replace(/z$/i,"+00:00")}s(Fn,"canonicalGitDate");async function Nn(e,t){let n=await N(e,["log","--follow","--format=%aI|%at","--reverse","--",t]);if(!n)return null;let r=n.split(`
|
|
12
|
+
`)[0],[o,i]=r.split("|");if(!o||!i)return null;let a=Number.parseInt(i,10);return Number.isNaN(a)?null:{date:Fn(o),timestamp:a}}s(Nn,"getGitCreationDate");async function Ln(e,t){let n=await N(e,["log","-1","--format=%aI|%at","--",t]);if(!n)return null;let[r,o]=n.split("|");if(!r||!o)return null;let i=Number.parseInt(o,10);return Number.isNaN(i)?null:{date:Fn(r),timestamp:i}}s(Ln,"getGitLastModifiedDate");var ti=256*1024*1024;async function jn(e){let t=Jo(e);if(await N(t,["rev-parse","--is-inside-work-tree"])!=="true")return{state:"no-git",content:null};try{let{stdout:n}=await Pe("git",["show",`HEAD:./${Vo(e)}`],{cwd:t,encoding:"utf8",maxBuffer:ti});return{state:"tracked",content:n}}catch{return{state:"untracked",content:null}}}s(jn,"readGitHeadFile");function ii(e){return ni(e)||"project"}s(ii,"folderName");function si(e,t){if(typeof t!="string")return e;let n=t.trim();return n.length===0||Kt(e)?e:`${e} <${n}>`}s(si,"formatAuthorNameWithCompany");async function ai(e,t={}){let n=Array.isArray(t.detectors)?t.detectors:O(t),r=typeof t.preferredExtension=="string"?t.preferredExtension.trim().toLowerCase():"",o=r.length>0?n.find(f=>f.extensions.includes(r)):void 0,i=await Cn(e,{drivers:t.drivers,language:o?.id,scanRoot:t.scanRoot}),a=i?i.root:Oe(e),c=i?.sources.name,l=i?.sources.company;return{language:o?.id??i?.drivers[0]??"unknown",rootDir:a,marker:i?i.marker:null,projectName:i?.fields.name??ii(a),projectNameSource:c?{from:"manifest",...c}:{from:"folder",dir:a},companyName:i?.fields.company??null,companyNameSource:l?{from:"manifest",...l}:{from:"none"},drivers:i?i.drivers:[]}}s(ai,"detectProjectFromMarkers");async function Te(e={}){let t=e.targetFilePath||e.cwd||process.cwd(),n=Oe(t),r=O(e),o=e.targetFilePath?ri(n):n,i=e.targetFilePath?oi(n).toLowerCase():"",a=Oe(e.projectRoot||e.cwd||process.cwd()),c=await ai(o,{detectors:r,preferredExtension:i,scanRoot:a}),l=await vn(c.rootDir,{useGpgSignerAuthor:e.useGpgSignerAuthor===!0}),f=e.authorName||l.authorName||"Unknown Author",u=typeof e.companyName=="string"?e.companyName.trim():"";return{projectName:e.projectName||c.projectName,projectNameSource:e.projectName?{from:"option"}:c.projectNameSource,language:e.language||c.language,projectRoot:e.projectRoot||c.rootDir,marker:e.marker===void 0?c.marker:e.marker,authorName:si(f,e.company),authorEmail:e.authorEmail||l.authorEmail||"unknown@example.com",companyName:u||c.companyName,companyNameSource:u?{from:"option"}:c.companyNameSource,copyrightStartYear:Number.isInteger(e.copyrightStartYear)?Number(e.copyrightStartYear):null}}s(Te,"resolveProjectMetadata");function ci(e){return He({year:e.getFullYear(),month:e.getMonth()+1,day:e.getDate(),hour:e.getHours(),minute:e.getMinutes(),second:e.getSeconds(),offsetMinutes:-e.getTimezoneOffset()})}s(ci,"formatDateWithTimezone");function He(e){return`${Pn(e," ")} ${On(e.offsetMinutes)}`}s(He,"formatSpaceDate");function Mn(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{In(e)}catch(t){throw new Error(`Unknown time zone "${e}": expected an IANA time zone name, such as "America/Los_Angeles" or "UTC"`,{cause:t})}return e}s(Mn,"assertTimeZone");var Rn=new Map;function In(e){let t=Rn.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"}),Rn.set(e,t)),t}s(In,"getZoneFormatter");function _e(e,t){let n={};for(let o of In(t).formatToParts(new Date(e*1e3)))n[o.type]=Number(o.value);let r=Date.UTC(n.year,n.month-1,n.day,n.hour,n.minute,n.second)/1e3;return{year:n.year,month:n.month,day:n.day,hour:n.hour,minute:n.minute,second:n.second,offsetMinutes:(r-e)/60}}s(_e,"toZonedDateParts");function Pn(e,t){let n=s(r=>String(r).padStart(2,"0"),"pad");return`${String(e.year).padStart(4,"0")}-${n(e.month)}-${n(e.day)}${t}${n(e.hour)}:${n(e.minute)}:${n(e.second)}`}s(Pn,"formatWallClock");function On(e){let t=s(r=>String(r).padStart(2,"0"),"pad"),n=Math.abs(e);return`${e>=0?"+":"-"}${t(Math.floor(n/60))}:${t(n%60)}`}s(On,"formatOffset");function fe(e=new Date){return{date:ci(e),timestamp:Math.floor(e.getTime()/1e3)}}s(fe,"toDatePayload");var li=/^(\d{4})-(\d{2})-(\d{2})(?:T|\s+)(\d{2}):(\d{2}):(\d{2})(?:\.\d+)?\s*(?:(Z)|([+-])(\d{2}):?(\d{2}))$/i;function _(e){let t=li.exec(e.trim());if(!t)return null;let[n,r,o,i,a,c]=t.slice(1,7).map(Number),l=t[7]?0:Number(t[9])*60+Number(t[10]),f=t[8]==="-"?-l:l,u=new Date(Date.UTC(n,r-1,o,i,a,c));return!(u.getUTCFullYear()===n&&u.getUTCMonth()===r-1&&u.getUTCDate()===o&&u.getUTCHours()===i&&u.getUTCMinutes()===a&&u.getUTCSeconds()===c)||Number(t[10]??0)>59?null:{year:n,month:r,day:o,hour:i,minute:a,second:c,offsetMinutes:f,timestamp:Math.floor(u.getTime()/1e3)-f*60}}s(_,"parseHeaderDate");function Ue(e){return`${Pn(e,"T")}${On(e.offsetMinutes)}`}s(Ue,"formatIsoDate");var ui={"git-created":"git first commit","filesystem-created":"filesystem creation time"};function Tn(e,t){let n=e.match(new RegExp(`${t}:[^\\S\\n]*(.*)$`,"m"));return n?n[1].trim():null}s(Tn,"readHeaderField");function We(e){let t=null;for(let{source:n,payload:r}of e)r&&(!t||r.timestamp<t.payload.timestamp)&&(t={source:n,payload:r});return t}s(We,"pickOldestDate");function _n({existing:e,gitCreated:t,filesystemCreated:n,fixCreatedDate:r=!1}){let o=[{source:"git-created",payload:t},{source:"filesystem-created",payload:n}];if(!e)return We(o);if(!r)return{source:"existing-header",payload:e};let i=_(e.date)?e:null;return We([{source:"existing-header",payload:i},...o])}s(_n,"resolveCreatedDate");function Un(e,t=null){if(t)return _e(e.timestamp,t).year;let n=_(e.date);return n?n.year:new Date(e.timestamp*1e3).getFullYear()}s(Un,"dateYear");function Hn(e,t,n,r){let o=e.match(/^(.+?)\s*\((\d+)\)$/),i=o?_(o[1]):null;if(!o||!i)return r.push({check:`${n}-format`,field:t,advisory:!1,value:e,message:`${t} value "${e}" is not a "<datetime> (<epoch>)" pair with a recognised datetime`}),null;let a=Number.parseInt(o[2],10);return a!==i.timestamp&&r.push({check:`${n}-epoch`,field:t,advisory:!1,value:e,expected:`${o[1]} (${i.timestamp})`,message:`${t} epoch ${a} does not match ${o[1]} (expected ${i.timestamp})`}),{text:o[1],timestamp:i.timestamp}}s(Hn,"checkDateValue");function Wn(e,t={},n={}){let r=[],o=Tn(e,"@Date"),i=o===null?null:Hn(o,"@Date","created",r),a=We([{source:"git-created",payload:t.gitCreated},{source:"filesystem-created",payload:t.filesystemCreated}]);if(i&&a&&i.timestamp>a.payload.timestamp){let u=ui[a.source];r.push({check:"created-newer-than-source",field:"@Date",advisory:n.strictCreatedDate!==!0,value:o,expected:`${a.payload.date} (${a.payload.timestamp})`,source:a.source,message:`@Date ${i.text} is later than the ${u} ${a.payload.date} (${a.payload.timestamp})`})}let c=Tn(e,"@Last modified time"),l=c===null?null:Hn(c,"@Last modified time","modified",r),f=t.gitLastModified;return l&&f&&l.timestamp!==f.timestamp&&r.push({check:"modified-git",field:"@Last modified time",advisory:!0,value:c,expected:`${f.date} (${f.timestamp})`,message:`@Last modified time ${l.text} does not match the git last commit ${f.date} (${f.timestamp})`}),r}s(Wn,"checkHeaderDates");function Be(e){if(!e)return null;let t=_(e.date);return t&&t.timestamp!==e.timestamp?{date:e.date,timestamp:t.timestamp}:e}s(Be,"repairDateEpoch");function Bn(e){let t=_(e.date);return t?{date:Ue(t),timestamp:t.timestamp}:e}s(Bn,"normalizeDatePayload");function zn(e,t){let n=_(e.date);if(!n)return e;let r=_e(n.timestamp,t);return r.offsetMinutes===n.offsetMinutes||!Number.isInteger(r.offsetMinutes)?e:{date:/^\d{4}-\d{2}-\d{2}T/i.test(e.date.trim())?Ue(r):He(r),timestamp:n.timestamp}}s(zn,"convertDatePayload");import{relative as di}from"node:path";import{extname as fi}from"node:path";function U(e,t={}){let n=fi(e).toLowerCase(),r=T(t.spacing,"spacing",X);return n.length===0?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */",spacing:r}:{...zt(e,t),spacing:r}}s(U,"getHeaderSyntaxForFile");function Gn(e,t){let n=e.spacing??X;if(e.kind==="line"){let c=e.linePrefix||"#",l=typeof e.lineSeparator=="string"?e.lineSeparator:" ",f=Array.from({length:n},()=>c);return[...f,...t.map(u=>`${c}${l}${u}`),...f].join(`
|
|
9
13
|
`)}let r=e.blockStart||(e.kind==="html"?"<!--":"/**"),o=e.blockLinePrefix||(e.kind==="html"?" ":" * "),i=e.blockEnd||(e.kind==="html"?"-->":" */"),a=Array.from({length:n},()=>o.trimEnd());return[r,...a,...t.map(c=>`${o}${c}`),...a,i].join(`
|
|
10
|
-
`)}s(
|
|
14
|
+
`)}s(Gn,"renderHeaderLines");function Yn(e){let t=di(e.projectRoot,e.absoluteFilePath).replace(/\\/g,"/"),n=U(e.absoluteFilePath,e.syntaxOptions||{language:e.language}),r=e.createdByName||e.authorName,o=e.createdByEmail||e.authorEmail,i=e.lastModifiedByName||e.authorName,a=e.lastModifiedByEmail||e.authorEmail,c=typeof e.companyName=="string"?e.companyName.trim():"",l=c.length>0?`${c} `:"",f=[`@Project: ${e.projectName}`,`@Filename: ${t}`,`@Date: ${e.createdAt.date} (${e.createdAt.timestamp})`,`@Author: ${r}`,`@Email: <${o}>`,"-----",`@Last modified by: ${i} (${a})`,`@Last modified time: ${e.lastModifiedAt.date} (${e.lastModifiedAt.timestamp})`,"-----",`@Copyright: Copyright (c) ${e.copyrightStartYear}-${e.currentYear} ${l}All rights reserved.`];return Gn(n,f)}s(Yn,"buildHeader");var mi=Object.freeze(["projectName","filename","createdAt","authorName","authorEmail","lastModifiedByName","lastModifiedByEmail","lastModifiedAt","copyrightStartYear","copyrightEndYear","companyName"]);function P(e,t){let n=e.match(new RegExp(`@${t}:[ \\t]*(.*)$`,"m")),r=n?n[1].trim():"";return r.length>0?r:null}s(P,"readTag");function pi(e){if(e===null)return{name:null,email:null};if(!e.endsWith(")"))return{name:e,email:null};let t=e.slice(0,-1),n=t.indexOf("(",t.lastIndexOf(")")+1);return n===-1?{name:e,email:null}:{name:t.slice(0,n).trimEnd()||null,email:t.slice(n+1)||null}}s(pi,"splitLastModifiedBy");function hi(e){let t={startYear:null,endYear:null,companyName:null},n=e?.match(/^Copyright\s+\(c\)\s+(\d{4})/i);if(!n)return t;let r=e.slice(n[0].length),o=r.match(/^\s*-\s*(\d{4})/);o&&(r=r.slice(o[0].length));let i=r.toLowerCase(),a=i.endsWith("all rights reserved.")?20:i.endsWith("all rights reserved")?19:0;return a===0||!/^\s/.test(r)?t:{startYear:n[1],endYear:o?o[1]:null,companyName:r.slice(0,-a).trim()||null}}s(hi,"splitCopyright");function Vn(e){let t=pi(P(e,"Last modified by")),n=hi(P(e,"Copyright")),r=P(e,"Email");return{projectName:P(e,"Project"),filename:P(e,"Filename"),createdAt:P(e,"Date"),authorName:P(e,"Author"),authorEmail:r===null?null:r.replace(/^<(.*)>$/,"$1"),lastModifiedByName:t.name,lastModifiedByEmail:t.email,lastModifiedAt:P(e,"Last modified time"),copyrightStartYear:n.startYear,copyrightEndYear:n.endYear,companyName:n.companyName}}s(Vn,"parseHeaderFields");function Jn(e,t){let n=Vn(e??""),r=Vn(t);return mi.filter(o=>n[o]!==r[o]).map(o=>({field:o,previous:n[o],detected:r[o]}))}s(Jn,"compareHeaderFields");function ee(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}s(ee,"escapeRegex");function ze(e,t,n={}){let r=t.startsWith("\uFEFF")?"\uFEFF":"",o=t.slice(r.length),i=`${r}${ce(e,o,n)}`;return{prefix:i,body:t.slice(i.length)}}s(ze,"splitPreservedPrefix");function de(e){let t=e.indexOf(`
|
|
11
15
|
`);return t===-1?null:t>0&&e[t-1]==="\r"?`\r
|
|
12
16
|
`:`
|
|
13
|
-
`}s(de,"lineEnding");function
|
|
17
|
+
`}s(de,"lineEnding");function z(e,t){if(t.kind==="html"){let r=ee(t.blockStart||"<!--"),o=ee(t.blockEnd||"-->");return e.match(new RegExp(`^${r}[\\s\\S]*?${o}(?:\\r?\\n)*`))}if(t.kind==="line"){let r=ee(t.linePrefix||"#");return e.match(new RegExp(`^(?:${r}[^\\n]*\\n)+(?:\\r?\\n)*`))}let n=ee((t.blockEnd||" */").trim());return e.match(new RegExp(`^/\\*[\\s\\S]*?${n}(?:\\r?\\n)*`))}s(z,"matchHeaderSegment");var Xn=/^@(Project|Filename|Date|Author|Email|Last modified by|Last modified time|Copyright):/,gi="Moved out of the file header by fix-headers:";function Zn(e){return e.some(t=>/^@(?:Project|Filename):/.test(t.text))}s(Zn,"isFileHeader");function Ge(e,t){let n=e.replace(/(?:\r?\n)+$/,"");if(t.kind==="line"){let u=new RegExp(`^${ee(t.linePrefix||"#")}[ \\t]*`);return n.split(`
|
|
14
18
|
`).map(m=>{let h=m.replace(/\r$/,"");return{raw:h,text:h.replace(u,"").trim()}})}let r=t.kind==="html",o=r?n.replace(/^<!--/,"").replace(/--!?>\s*$/,""):n.replace(/^\/\*+/,"").replace(/\*+\/\s*$/,""),i=t.blockLinePrefix||(r?" ":" * "),a=r?/^\s*/:/^\s*\*?[ \t]*/,c=o.split(`
|
|
15
|
-
`).map((u,m)=>({raw:m===0&&u.trim()!==""?`${i}${u.trim()}`:u.trimEnd(),text:(m===0?u:u.replace(a,"")).trim()})),l=c[0].raw===""?1:0,f=c.length>l&&c[c.length-1].raw.trim()===""?c.length-1:c.length;return c.slice(l,f)}s(Ge,"segmentLines");function
|
|
19
|
+
`).map((u,m)=>({raw:m===0&&u.trim()!==""?`${i}${u.trim()}`:u.trimEnd(),text:(m===0?u:u.replace(a,"")).trim()})),l=c[0].raw===""?1:0,f=c.length>l&&c[c.length-1].raw.trim()===""?c.length-1:c.length;return c.slice(l,f)}s(Ge,"segmentLines");function yi(e,t){let n=e.map(o=>{let i=o.text.match(Xn);return o.text===""?"blank":i&&i[1]==="Copyright"?t.copyright?"copyright":(t.copyright=!0,"field"):i?"field":/^-{3,}$/.test(o.text)?"dash":"text"}),r=s((o,i)=>{for(let a=o+i;a>=0&&a<n.length;a+=i)if(n[a]!=="blank"&&n[a]!=="dash")return n[a]==="copyright"?"field":n[a]},"neighbour");return n.map((o,i)=>o==="dash"?r(i,-1)==="field"||r(i,1)==="field"?"separator":"text":o)}s(yi,"classifyLines");function xi(e,t="",n={}){let r=U(t,n),o=[],i=[],a={copyright:!1},c=e,l=z(c,r),f=!0;for(;l&&l[0].length>0;){let p=Ge(l[0],r),w=yi(p,a),b=p.findIndex($=>$.text!=="");!f&&b!==-1&&p[b].text===gi&&(w[b]="separator"),p.forEach(($,D)=>{w[D]==="copyright"&&i.push($.text.replace(Xn,"").trim()),o.push({raw:$.raw,kind:w[D]})}),c=c.slice(l[0].length),l=z(c,r),f=!1}let u=o.findIndex(p=>p.kind==="text");if(u===-1)return{foreign:[],copyrights:i};let m=o.map(p=>p.kind).lastIndexOf("text"),h=[],y=[],d=!1;for(let p of o.slice(u,m+1))p.kind==="text"?(h.push(...d?[]:y,p.raw),y=[],d=!1):p.kind==="blank"?y.push(p.raw):d=!0;return{foreign:h,copyrights:i}}s(xi,"splitHeaderText");function wi(e,t,n){let r=t.kind==="html";return t.kind==="line"?e.join(n):[t.blockStart||(r?"<!--":"/**"),...e,t.blockEnd||(r?"-->":" */")].join(n)}s(wi,"renderForeignBlock");function bi(e,t,n){let r=e.split(`
|
|
16
20
|
`),o=n.kind==="html",i=n.kind==="line"?n.linePrefix||"#":(n.blockLinePrefix||(o?" ":" * ")).trimEnd(),a=Math.min(r.length-1,(n.spacing??1)+(n.kind==="line"?0:1)),c=r.length-a;return[...r.slice(0,c),i,...t,...r.slice(c)].join(`
|
|
17
|
-
`)}s(
|
|
18
|
-
`.includes(t[a-1]);)a-=1;return t.slice(0,a).split(/\s+/).filter(Boolean).join(" ").toLowerCase()}s(
|
|
21
|
+
`)}s(bi,"appendToHeader");function Kn(e){let t=e.trim(),n=t.match(/^copyright\b/i);t=n?t.slice(n[0].length).trimStart():t;for(let c=t.match(/^(?:\(c\)|©)/i);c;c=t.match(/^(?:\(c\)|©)/i))t=t.slice(c[0].length).trimStart();let r=t.match(/^\d{4}(?:\s*[-–,]\s*\d{4})*/);t=r?t.slice(r[0].length):t,t=t.trimEnd();let o=t.toLowerCase(),i=o.endsWith("all rights reserved.")?20:o.endsWith("all rights reserved")?19:0;t=t.slice(0,t.length-i);let a=t.length;for(;a>0&&`.,; \r
|
|
22
|
+
`.includes(t[a-1]);)a-=1;return t.slice(0,a).split(/\s+/).filter(Boolean).join(" ").toLowerCase()}s(Kn,"copyrightHolder");function ki(e,t){let n=e.split(`
|
|
19
23
|
`),r=n.findIndex(c=>c.includes("@Copyright:")),o=n.map(c=>/@[A-Za-z][A-Za-z ]*:/.test(c)).lastIndexOf(!0),i=r!==-1?r:o;if(t.length===0||i===-1)return e;let a=n[i].slice(0,n[i].indexOf("@"));return[...n.slice(0,i+1),...t.map(c=>`${a}@Copyright: ${c}`),...n.slice(i+1)].join(`
|
|
20
|
-
`)}s(
|
|
24
|
+
`)}s(ki,"insertCopyrights");function qn(e,t){let n=0,r=z(e,t);for(;r&&r[0].length>0&&Zn(Ge(r[0],t));)n+=r[0].length,r=z(e.slice(n),t);return n}s(qn,"leadingHeadersLength");function me(e,t="",n={}){let r=e.startsWith("\uFEFF")?"\uFEFF":"",o=e.slice(r.length),i=ce(t,o,n),a=U(t,n),c=i.length,l=qn(o.slice(c),a);if(l===0)return e;let f=r===""&&c===0&&o.startsWith("\uFEFF",l);f&&(r="\uFEFF",o=`${o.slice(0,l)}${o.slice(l+1)}`,l+=qn(o.slice(l),a));let u=o.slice(c,c+l),m=o.slice(c+l),h=ce(t,`${i}${m}`,n),y=h.length>i.length?h.slice(i.length):"";if(y===""&&!f)return e;let d=y===""||y.endsWith(`
|
|
21
25
|
`)?y:`${y}${de(e)??`
|
|
22
|
-
`}`;return`${r}${i}${d}${u}${m.slice(y.length)}`}s(me,"restoreTopLines");function pe(e,t="",n={}){let{prefix:r,body:o}=
|
|
23
|
-
`).slice(0,
|
|
24
|
-
`),a=U(t,n);if(!
|
|
25
|
-
`?E:E.replace(/\r?\n/g,S),"withEol");if(!i){let{prefix:E,body:S}=
|
|
26
|
-
`,
|
|
27
|
-
`)?A:"",
|
|
28
|
-
`).find(E=>E.includes("@Copyright:")),d=new Set(y===void 0?[]:[
|
|
29
|
-
`,b=w.repeat(l+1),$=r.strictHeaderBlock!==!1,
|
|
26
|
+
`}`;return`${r}${i}${d}${u}${m.slice(y.length)}`}s(me,"restoreTopLines");function pe(e,t="",n={}){let{prefix:r,body:o}=ze(t,e,n),i=o.split(`
|
|
27
|
+
`).slice(0,Vt).join(`
|
|
28
|
+
`),a=U(t,n);if(!z(i,a))return null;let l=0,f=0;for(;;){let u=i.slice(l),m=z(u,a);if(!m||!Zn(Ge(m[0],a)))break;l+=m[0].length,f=l}return f===0?null:{start:r.length,end:r.length+f}}s(pe,"findProjectHeader");function he(e,t,n="",r={}){let o=me(e,n,r),i=pe(o,n,r),a=U(n,r),c=T(r.margin,"margin",le),l=a.kind==="line"?Math.max(1,c):c,f=s((E,S)=>S===`
|
|
29
|
+
`?E:E.replace(/\r?\n/g,S),"withEol");if(!i){let{prefix:E,body:S}=ze(n,o,r),A=de(o)??`
|
|
30
|
+
`,M=f(t,A),V=S.replace(/^(?:\r?\n)+/,""),g=E.replace(/^\uFEFF/,"")!==""&&!E.endsWith(`
|
|
31
|
+
`)?A:"",I=`${E}${g}${V.trim()===""?`${M}${A}`:`${M}${A.repeat(l+1)}${V}`}`;return{nextContent:I,changed:I!==e,header:M,written:M,extraCopyrights:[]}}let u=o.slice(i.start,i.end),{foreign:m,copyrights:h}=xi(u,n,r),y=t.split(`
|
|
32
|
+
`).find(E=>E.includes("@Copyright:")),d=new Set(y===void 0?[]:[Kn(y.slice(y.indexOf("@Copyright:")+11))]),p=[];for(let E of h){let S=Kn(E);d.has(S)||(d.add(S),p.push(E))}let w=de(o.slice(i.end))??de(u)??`
|
|
33
|
+
`,b=w.repeat(l+1),$=r.strictHeaderBlock!==!1,D=ki(t,p),R=f(m.length>0&&!$?bi(D,m,a):D,w),k=m.length>0&&$?wi(m,a,w):"",W=o.slice(i.end).replace(/^(?:\r?\n)+/,""),G=k===""?W:`${k}${W.trim()===""?w:`${b}${W}`}`,Y=`${o.slice(0,i.start)}${G.trim()===""?`${R}${w}`:`${R}${b}${G}`}`,x=`${R}${k===""?"":`${b}${k}`}`;return{nextContent:Y,changed:Y!==e,header:R,written:x,extraCopyrights:p}}s(he,"replaceOrInsertHeader");function Ye(e,t="",n={}){let r=me(e,t,n),o=pe(r,t,n);if(o){let l=r.slice(0,o.start),u=he(r,"",t,{...n,strictHeaderBlock:!0}).nextContent.slice(l.length).replace(/^(?:\r?\n)+/,"");return`${l}${u.trim()===""?"":u}`}let{prefix:i,body:a}=ze(t,r,n),c=a.replace(/^(?:\r?\n)+/,"");return`${i}${c.trim()===""?"":c}`}s(Ye,"extractHeaderlessBody");function Ei(e,t){let n=e.length,r=t.length,o=Array.from({length:n+1},()=>new Array(r+1).fill(0));for(let l=n-1;l>=0;l-=1)for(let f=r-1;f>=0;f-=1)o[l][f]=e[l]===t[f]?o[l+1][f+1]+1:Math.max(o[l+1][f],o[l][f+1]);let i=[],a=0,c=0;for(;a<n&&c<r;)e[a]===t[c]?(i.push({type:" ",line:e[a]}),a+=1,c+=1):o[a+1][c]>=o[a][c+1]?(i.push({type:"-",line:e[a]}),a+=1):(i.push({type:"+",line:t[c]}),c+=1);for(;a<n;a+=1)i.push({type:"-",line:e[a]});for(;c<r;c+=1)i.push({type:"+",line:t[c]});return i}s(Ei,"diffLines");function Qn(e,t){return`${t===0?e:e+1},${t}`}s(Qn,"formatRange");function er(e,t,n={}){let r=e===null?[]:e.split(`
|
|
30
34
|
`),o=t.split(`
|
|
31
|
-
`),i=
|
|
32
|
-
`)}s(
|
|
33
|
-
`).length-1;ne.sample={previousValue:
|
|
35
|
+
`),i=Ei(r,o),a=Math.max(0,n.context??3),c=n.lineOffset??0,l=[];if(i.forEach((h,y)=>{if(h.type===" ")return;let d=l[l.length-1];d&&y-d.last<=a*2+1?d.last=y:l.push({first:y,last:y})}),l.length===0)return"";let f=n.fromFile??"a",u=n.toFile??"b",m=[`--- ${e===null?"/dev/null":f}`,`+++ ${u}`];for(let h of l){let y=Math.max(0,h.first-a),d=Math.min(i.length,h.last+a+1),p=i.slice(0,y),w=i.slice(y,d),b=p.filter(k=>k.type!=="+").length+c,$=p.filter(k=>k.type!=="-").length+c,D=w.filter(k=>k.type!=="+").length,R=w.filter(k=>k.type!=="-").length;m.push(`@@ -${Qn(b,D)} +${Qn($,R)} @@`);for(let k of w)m.push(`${k.type}${k.line}`)}return m.join(`
|
|
36
|
+
`)}s(er,"createUnifiedDiff");function Ci(e){return re(e,"configFile")}s(Ci,"resolveRuntimeOptions");function Di(e){if(e==null)return[];let t=Array.isArray(e)?e:[e];if(t.some(n=>typeof n!="string"))throw new Error(`input must be a path or an array of paths, got ${JSON.stringify(e)}`);return t.filter(n=>n.trim().length>0)}s(Di,"resolveInputs");function vi(e){let t=e.match(/@Author:\s*(.+)$/m),n=e.match(/@Email:\s*<([^>\n]+)>/m);return{authorName:t?.[1]?.trim(),authorEmail:n?.[1]?.trim()}}s(vi,"extractHeaderAuthorIdentity");function Fi(e){let t=e.match(/@Last modified by:\s*(.+?)\s*\(([^)\n]+)\)\s*$/m);return{authorName:t?.[1]?.trim(),authorEmail:t?.[2]?.trim()}}s(Fi,"extractHeaderLastModifiedIdentity");function Ni(e){let t=e.match(/@Date:\s*(.+?)\s*\((\d+)\)$/m);if(!t||!t[1]||!t[2])return null;let n=Number.parseInt(t[2],10);return Number.isNaN(n)?null:{date:t[1].trim(),timestamp:n}}s(Ni,"extractHeaderCreatedAt");function Li(e){let t=e.match(/@Last modified time:\s*(.+?)\s*\((\d+)\)$/m);if(!t||!t[1]||!t[2])return null;let n=Number.parseInt(t[2],10);return Number.isNaN(n)?null:{date:t[1].trim(),timestamp:n}}s(Li,"extractHeaderLastModifiedAt");async function ji(e,t,n){let r=await jn(t);return r.state!=="tracked"?{edited:r.state==="untracked",state:r.state}:{edited:Ye(r.content,t,n)!==Ye(e,t,n),state:"tracked"}}s(ji,"detectContentEdit");async function nr(e={}){let t=await Ci(e),n=t.timezone===void 0||t.timezone===null?null:Mn(t.timezone),r=t.convertTimezone===!0;if(r&&!n)throw new Error("convertTimezone requires timezone: set timezone (CLI --timezone <name>) to the IANA zone to convert header dates into");let o=Ut(t.forcedDetectors),i=tr(t.projectRoot||t.cwd||process.cwd()),a=await Te({...t,cwd:i});T(t.spacing,"spacing",X),T(t.margin,"margin",le);let c=t.check===!0,l=c||t.dryRun===!0,f=t.fixCreatedDate===!0,u=s(x=>x,"keepDate"),m=t.normalizeDateFormat===!0?Bn:u,h=n?x=>zn(x,n):u,y=r?h:u,d={language:a.language,enabledDetectors:t.enabledDetectors,disabledDetectors:t.disabledDetectors,forcedDetectors:o,includeFolders:t.includeFolders,excludeFolders:t.excludeFolders,includeExtensions:t.includeExtensions,gitignore:t.gitignore},p=Di(t.input),w;if(p.length>0){let x=new Set;for(let E of p){let S=tr(i,E),A=await Si(S).catch(()=>null);if(!A)throw new Error(`Input path does not exist: ${E}`);if(A.isFile())x.add(S);else if(A.isDirectory())for(let M of await Le({...d,projectRoot:S}))x.add(M);else throw new Error(`Input path must be a file or directory: ${E}`)}w=Array.from(x)}else w=await Le({...d,projectRoot:i});let b=new Date().getFullYear(),$=[],D=[],R=new Set,k=0,W=0,G=0,Y=[];for(let x of w){let E=Bt(x,{enabledDetectors:t.enabledDetectors,disabledDetectors:t.disabledDetectors,forcedDetectors:o});if(E!==null){D.push({file:Ve(i,x),reason:E});continue}let S=Ve(i,x),A=await $i(x,"utf8"),M={enabledDetectors:t.enabledDetectors,disabledDetectors:t.disabledDetectors,forcedDetectors:o,detectorSyntaxOverrides:t.detectorSyntaxOverrides},V=Yt(x,me(A,x,M),M);if(V!==null){D.push({file:S,reason:V});continue}let g=await Te({...t,cwd:i,targetFilePath:x});R.add(`${g.language}:${g.projectRoot}`);let I={language:g.language,enabledDetectors:t.enabledDetectors,disabledDetectors:t.disabledDetectors,forcedDetectors:o,detectorSyntaxOverrides:t.detectorSyntaxOverrides,spacing:t.spacing,margin:t.margin,strictHeaderBlock:t.strictHeaderBlock!==!1},ge=pe(A,x,I),v=ge?A.slice(ge.start,ge.end):"",Ke=v.length>0?vi(v):{},qe=v.length>0?Fi(v):{},cr=v.length>0?Ni(v):null,lr=v.length>0?Li(v):null,Xe=await Jt(x),Ze=Ve(g.projectRoot,x),Qe=await Nn(g.projectRoot,Ze),J=await Ln(g.projectRoot,Ze),et=fe(Xe.createdAt),ye=_n({existing:Be(cr),gitCreated:Qe,filesystemCreated:et,fixCreatedDate:f}),K=Be(lr),tt=ye.source,ur=K?"existing-header":J?"git-last-modified":"filesystem-updated",xe=m(tt==="existing-header"?y(ye.payload):h(ye.payload)),fr=g.copyrightStartYear===null?"created-date":"option",nt=g.copyrightStartYear??Un(xe,n),rt=m(K?y(K):h(J||fe(Xe.updatedAt))),ot=t.forceAuthorUpdate===!0,dr=t.forceLastModifiedAuthorUpdate===!0,it=await ji(A,x,I),st=dr||it.edited,at=s(F=>Yn({absoluteFilePath:x,language:g.language,syntaxOptions:I,projectRoot:g.projectRoot,projectName:g.projectName,createdByName:ot?g.authorName:Ke.authorName||g.authorName,createdByEmail:ot?g.authorEmail:Ke.authorEmail||g.authorEmail,lastModifiedByName:st?g.authorName:qe.authorName||g.authorName,lastModifiedByEmail:st?g.authorEmail:qe.authorEmail||g.authorEmail,authorName:g.authorName,authorEmail:g.authorEmail,createdAt:xe,lastModifiedAt:F,copyrightStartYear:nt,companyName:g.companyName,currentYear:b}),"renderHeader"),ct=at(rt),lt=he(A,ct,x,I),mr=it.edited&&K!==null&&J!==null&&K.timestamp<J.timestamp,te=lt.changed||mr,ut=te?m(h(fe(new Date))):rt,pr=te?"current-time-on-change":ur,hr=te?at(ut):ct,L=te?he(A,hr,x,I):lt,ne={file:S,changed:L.changed};if(c){let F=Wn(v,{gitCreated:Qe,gitLastModified:J,filesystemCreated:et},{strictCreatedDate:t.strictCreatedDate===!0}),q=F.filter(B=>B.advisory).length;ne.dateIssues=F,G+=q,W+=F.length>q?1:0}if(t.sampleOutput===!0&&L.changed){let F=v.length>0?v.trimEnd():null,q=S.replace(/\\/g,"/"),B=L.written,gr=L.nextContent.slice(0,L.nextContent.indexOf(B)).split(`
|
|
37
|
+
`).length-1;ne.sample={previousValue:F,newValue:B,diff:er(F,B,{fromFile:`a/${q}`,toFile:`b/${q}`,lineOffset:gr}),issues:Jn(F,B),detectedValues:{projectName:g.projectName,projectNameSource:g.projectNameSource,language:g.language,projectRoot:g.projectRoot,marker:g.marker,authorName:g.authorName,authorEmail:g.authorEmail,companyName:g.companyName,companyNameSource:g.companyNameSource,copyrightStartYear:nt,copyrightStartYearSource:fr,createdAtSource:tt,lastModifiedAtSource:pr,createdAt:xe,lastModifiedAt:ut}}}if(L.extraCopyrights.length>0){ne.extraCopyrights=L.extraCopyrights;for(let F of L.extraCopyrights)Y.push({file:S,copyright:F})}$.push(ne),L.changed&&(k+=1,l||await Ai(x,L.nextContent,"utf8"))}return{metadata:a,detectedProjects:Array.from(R),filesScanned:w.length-D.length,filesUpdated:k,filesSkipped:D.length,dryRun:l,check:c,...c?{filesWithDateDrift:W,dateAdvisories:G}:{},copyrightWarnings:Y,changes:$,skipped:D}}s(nr,"fixHeaders");function Ri(e){return nr(e)}s(Ri,"fixHeaders");var rr=Ri;var Pi=`fix-headers CLI
|
|
34
38
|
|
|
35
39
|
Usage:
|
|
36
40
|
fix-headers [options]
|
|
@@ -81,5 +85,5 @@ Examples:
|
|
|
81
85
|
fix-headers --check --verbose
|
|
82
86
|
fix-headers --timezone America/Los_Angeles --convert-timezone
|
|
83
87
|
fix-headers --project-name @scope/pkg --company-name "Catalyzed Motivation Inc."
|
|
84
|
-
`;function
|
|
88
|
+
`;function Oi(e){return e.replace(/-([a-z])/g,(t,n)=>n.toUpperCase())}s(Oi,"toCamelCase");function Ti(e){let t={},n={help:!1,json:!1,diff:!1},r={"include-folder":"includeFolders","exclude-folder":"excludeFolders","include-extension":"includeExtensions","enable-detector":"enabledDetectors","disable-detector":"disabledDetectors","force-detector":"forcedDetectors",input:"input"},o={cwd:"cwd","project-name":"projectName",language:"language","project-root":"projectRoot",marker:"marker","author-name":"authorName","author-email":"authorEmail",company:"company","company-name":"companyName","copyright-start-year":"copyrightStartYear",spacing:"spacing",margin:"margin",timezone:"timezone",config:"config"};for(let i=0;i<e.length;i+=1){let a=e[i];if(a==="-h"||a==="--help"){n.help=!0;continue}if(a==="--json"){n.json=!0;continue}if(a==="--diff"){n.diff=!0;continue}if(a==="--verbose"){t.verbose=!0;continue}if(a==="--dry-run"){t.dryRun=!0;continue}if(a==="--check"){t.check=!0;continue}if(a==="--fix-created-date"){t.fixCreatedDate=!0;continue}if(a==="--strict-created-date"){t.strictCreatedDate=!0;continue}if(a==="--strict-header-block"){let u=e[i+1];(u==="true"||u==="false")&&(i+=1),t.strictHeaderBlock=u!=="false";continue}if(a==="--no-strict-header-block"){t.strictHeaderBlock=!1;continue}if(a==="--normalize-date-format"){t.normalizeDateFormat=!0;continue}if(a==="--convert-timezone"){t.convertTimezone=!0;continue}if(a==="--sample-output"){t.sampleOutput=!0;continue}if(a==="--force-author-update"){t.forceAuthorUpdate=!0;continue}if(a==="--force-last-modified-author-update"){t.forceLastModifiedAuthorUpdate=!0;continue}if(a==="--use-gpg-signer-author"){t.useGpgSignerAuthor=!0;continue}if(!a.startsWith("--"))throw new Error(`Unexpected argument: ${a}`);let c=a.slice(2);if(c==="include-folder-non-recursive"){let u=e[i+1];if(!u||u.startsWith("--"))throw new Error(`Missing value for --${c}`);i+=1;let m=Array.isArray(t.includeFolders)?t.includeFolders:[];t.includeFolders=[...m,{path:u,recursive:!1}];continue}if(r[c]){let u=e[i+1];if(!u||u.startsWith("--"))throw new Error(`Missing value for --${c}`);i+=1;let m=r[c],h=Array.isArray(t[m])?t[m]:[];t[m]=Array.from(new Set([...h,u]));continue}if(o[c]){let u=e[i+1];if(!u||u.startsWith("--"))throw new Error(`Missing value for --${c}`);i+=1;let m=o[c];if(m==="copyrightStartYear"||m==="spacing"||m==="margin"){if(t[m]=Number.parseInt(u,10),Number.isNaN(t[m]))throw new Error(`Invalid number for --${c}: ${u}`)}else m==="marker"&&u==="null"?t[m]=null:t[m]=u;continue}let l=Oi(c),f=e[i+1];if(!f||f.startsWith("--"))throw new Error(`Unknown or malformed flag: --${c}`);i+=1,t[l]=f}return{options:t,help:n.help,json:n.json,diff:n.diff}}s(Ti,"parseCliArgs");function Hi(e){return re(e,"config")}s(Hi,"applyConfigFile");function Je(e){if(!e||typeof e!="object")return[];let t=e;return(Array.isArray(t.changes)?t.changes:[]).filter(r=>r&&r.changed===!0&&r.sample&&typeof r.sample.newValue=="string")}s(Je,"getSampledChanges");function ir(e){return typeof e=="string"?`"${e}"`:"(missing)"}s(ir,"formatIssueValue");function _i(e,t){for(let n of Je(t)){let r=Array.isArray(n.sample.issues)?n.sample.issues:[];if(e(`issues: ${n.file||"<unknown-file>"}`),r.length===0){e(" (no field differences; header formatting only)");continue}for(let o of r)e(` ${o?.field||"<unknown-field>"}: found ${ir(o?.previous)}, expected ${ir(o?.detected)}`)}}s(_i,"printIssues");function Ui(e,t){for(let n of Je(t))typeof n.sample.diff=="string"&&n.sample.diff.length>0&&e(n.sample.diff)}s(Ui,"printDiffs");function Wi(e,t){for(let n of Je(t))e(`sample: ${n.file||"<unknown-file>"}`),e("previous:"),e(n.sample.previousValue===null?"(none)":String(n.sample.previousValue)),e("new:"),e(n.sample.newValue),n.sample.detectedValues&&typeof n.sample.detectedValues=="object"&&(e("detected-values:"),e(JSON.stringify(n.sample.detectedValues,null,2)))}s(Wi,"printSampleOutput");function Bi(e,t){if(!t||typeof t!="object")return;let n=t,o=(Array.isArray(n.changes)?n.changes:[]).filter(i=>i&&i.changed===!0).map(i=>i.file||"<unknown-file>");for(let i of o)e(`updated: ${i}`)}s(Bi,"printChangedFiles");function sr(e,t){let n=Array.isArray(t.copyrightWarnings)?t.copyrightWarnings:[];for(let r of n)e(`warning: ${r?.file||"<unknown-file>"} keeps an additional @Copyright: ${r?.copyright??""}`)}s(sr,"printCopyrightWarnings");function zi(e,t){let n=Array.isArray(t.skipped)?t.skipped:[];for(let r of n)e(`skipped: ${r?.file||"<unknown-file>"} (${r?.reason||"no reason given"})`)}s(zi,"printSkipped");function ar(e,t,n,r){let o=n.sampleOutput===!0||r;n.verbose===!0&&(Bi(e,t),o&&_i(e,t)),n.sampleOutput===!0&&Wi(e,t),r&&Ui(e,t)}s(ar,"printDetails");function Gi(e,t,n){let r=Array.isArray(t.changes)?t.changes:[];for(let o of r){let i=Array.isArray(o?.dateIssues)?o.dateIssues:[];for(let a of i)a.advisory===!0&&!n||e(`${a.advisory===!0?"advisory":"drift"}: ${o.file||"<unknown-file>"}: ${a.message}`)}}s(Gi,"printDateIssues");async function Yi(e,t={}){let n=t.runner||rr,r=t.stdout||console.log,o=t.stderr||console.error;try{let i=Ti(e);if(i.help)return r(Pi),0;let a=await Hi(i.options),c=await n(i.diff?{...a,sampleOutput:!0}:a),l=c&&typeof c=="object"&&c.check===!0?c:null,f=l&&Number(l.filesWithDateDrift)>0?1:0;if(i.json)return r(JSON.stringify(c,null,2)),f;if(l)return r(`fix-headers check: scanned=${l.filesScanned??0}, drift=${l.filesWithDateDrift??0}, advisories=${l.dateAdvisories??0}`),Gi(r,l,a.verbose===!0),sr(r,c),f;if(c&&typeof c=="object"){let u=c,m=Number(u.filesSkipped)>0?`, skipped=${u.filesSkipped}`:"",h=Array.isArray(u.copyrightWarnings)&&u.copyrightWarnings.length>0?`, warnings=${u.copyrightWarnings.length}`:"";r(`fix-headers complete: scanned=${u.filesScanned??0}, updated=${u.filesUpdated??0}${m}${h}, dryRun=${u.dryRun===!0}`),zi(r,u),sr(r,u),ar(r,c,a,i.diff)}else ar(r,c,a,i.diff),r("fix-headers complete");return 0}catch(i){let a=i instanceof Error?i.message:String(i);return o(`fix-headers failed: ${a}`),1}}s(Yi,"runCli");function Vi(e=process.argv,t=import.meta.url,n=Yi){let r=!1;if(e[1])try{let o=or(e[1]),i=or(Mi(t));r=o===i}catch{r=t===Ii(e[1]).href}return r?(n(e.slice(2)).then(o=>{process.exitCode=o}),!0):!1}s(Vi,"runCliAsMain");Vi();export{Hi as applyConfigFile,Ti as parseCliArgs,Yi as runCli,Vi as runCliAsMain};
|
|
85
89
|
//# sourceMappingURL=fix-headers.mjs.map
|
package/dist/index.cjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
*
|
|
3
3
|
* @Project: @cldmv/fix-headers
|
|
4
|
-
* @Filename:
|
|
4
|
+
* @Filename: src/index.cjs
|
|
5
5
|
* @Date: 2026-09-28T06:56:09-07:00 (1790603769)
|
|
6
6
|
* @Author: Nate Corcoran <CLDMV>
|
|
7
7
|
* @Email: <Shinrai@users.noreply.github.com>
|
|
8
8
|
* -----
|
|
9
9
|
* @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
|
|
10
|
-
* @Last modified time: 2026-11-
|
|
10
|
+
* @Last modified time: 2026-11-25T13:07:26-08:00 (1795640846)
|
|
11
11
|
* -----
|
|
12
12
|
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
13
|
*
|