@cldmv/fix-headers 2.5.0 → 2.6.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.
Files changed (84) hide show
  1. package/README.md +11 -6
  2. package/dist/cli.mjs +57 -0
  3. package/dist/config/load.mjs +2 -0
  4. package/dist/constants.mjs +2 -0
  5. package/dist/core/declaration-sources.mjs +4 -0
  6. package/dist/core/file-discovery.mjs +2 -0
  7. package/dist/core/fix-headers.mjs +3 -0
  8. package/dist/core/ignore-rules.mjs +2 -0
  9. package/dist/detect/project.mjs +2 -0
  10. package/dist/detectors/c.mjs +6 -0
  11. package/dist/detectors/css.mjs +2 -0
  12. package/dist/detectors/go.mjs +2 -0
  13. package/dist/detectors/html.mjs +2 -0
  14. package/dist/detectors/index.mjs +3 -0
  15. package/dist/detectors/json.mjs +2 -0
  16. package/dist/detectors/markdown.mjs +2 -0
  17. package/dist/detectors/node.mjs +2 -0
  18. package/dist/detectors/php.mjs +2 -0
  19. package/dist/detectors/python.mjs +2 -0
  20. package/dist/detectors/rust.mjs +2 -0
  21. package/dist/detectors/top-lines.mjs +3 -0
  22. package/dist/detectors/yaml.mjs +2 -0
  23. package/dist/drivers/go.mjs +2 -0
  24. package/dist/drivers/index.mjs +2 -0
  25. package/dist/drivers/node.mjs +2 -0
  26. package/dist/drivers/php.mjs +2 -0
  27. package/dist/drivers/python.mjs +2 -0
  28. package/dist/drivers/rust.mjs +2 -0
  29. package/dist/drivers/shared.mjs +4 -0
  30. package/dist/header/dates.mjs +2 -0
  31. package/dist/header/fields.mjs +2 -0
  32. package/dist/header/parser.mjs +21 -0
  33. package/dist/header/syntax.mjs +4 -0
  34. package/dist/header/template.mjs +2 -0
  35. package/dist/index.cjs +16 -16
  36. package/dist/index.mjs +2 -37
  37. package/dist/utils/diff.mjs +5 -0
  38. package/dist/utils/fs.mjs +2 -0
  39. package/dist/utils/git.mjs +4 -0
  40. package/dist/utils/text.mjs +2 -0
  41. package/dist/utils/time.mjs +2 -0
  42. package/package.json +9 -12
  43. package/types/src/cli.d.mts +15 -0
  44. package/types/src/config/load.d.mts +15 -0
  45. package/types/src/constants.d.mts +15 -0
  46. package/types/src/core/declaration-sources.d.mts +58 -0
  47. package/types/src/core/file-discovery.d.mts +15 -0
  48. package/types/src/core/fix-headers.d.mts +16 -0
  49. package/types/src/core/ignore-rules.d.mts +15 -0
  50. package/types/src/detect/project.d.mts +15 -0
  51. package/types/src/detectors/c.d.mts +15 -0
  52. package/types/src/detectors/css.d.mts +15 -0
  53. package/types/src/detectors/go.d.mts +15 -0
  54. package/types/src/detectors/html.d.mts +15 -0
  55. package/types/src/detectors/index.d.mts +15 -0
  56. package/types/src/detectors/json.d.mts +15 -0
  57. package/types/src/detectors/markdown.d.mts +15 -0
  58. package/types/src/detectors/node.d.mts +15 -0
  59. package/types/src/detectors/php.d.mts +15 -0
  60. package/types/src/detectors/python.d.mts +15 -0
  61. package/types/src/detectors/rust.d.mts +15 -0
  62. package/types/src/detectors/top-lines.d.mts +15 -0
  63. package/types/src/detectors/yaml.d.mts +15 -0
  64. package/types/src/drivers/go.d.mts +15 -0
  65. package/types/src/drivers/index.d.mts +15 -0
  66. package/types/src/drivers/node.d.mts +15 -0
  67. package/types/src/drivers/php.d.mts +15 -0
  68. package/types/src/drivers/python.d.mts +15 -0
  69. package/types/src/drivers/rust.d.mts +15 -0
  70. package/types/src/drivers/shared.d.mts +15 -0
  71. package/types/src/header/dates.d.mts +15 -0
  72. package/types/src/header/fields.d.mts +15 -0
  73. package/types/src/header/parser.d.mts +15 -0
  74. package/types/src/header/syntax.d.mts +15 -0
  75. package/types/src/header/template.d.mts +15 -0
  76. package/types/src/index.d.mts +15 -0
  77. package/types/src/utils/diff.d.mts +2 -1
  78. package/types/src/utils/fs.d.mts +15 -0
  79. package/types/src/utils/git.d.mts +15 -0
  80. package/types/src/utils/text.d.mts +2 -1
  81. package/types/src/utils/time.d.mts +2 -1
  82. package/bin/fix-headers.mjs +0 -91
  83. package/types/devcheck.d.mts +0 -1
  84. package/types/index.d.mts +0 -2
@@ -1,91 +0,0 @@
1
- #!/usr/bin/env node
2
- var Ar=Object.defineProperty;var s=(e,t)=>Ar(e,"name",{value:t,configurable:!0});import{realpathSync as mr}from"node:fs";import{fileURLToPath as Ui,pathToFileURL as Wi}from"node:url";import{readFile as Dr}from"node:fs/promises";import{createRequire as vr}from"node:module";import{dirname as Fr,isAbsolute as Nr,resolve as bt}from"node:path";var Lr=3e4,jr=new Set(["localhost","127.0.0.1","[::1]"]);function ke(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}s(ke,"isPlainObject");function Ee(e,t){let n={...e};for(let[r,o]of Object.entries(t))r!=="__proto__"&&(n[r]=ke(n[r])&&ke(o)?Ee(n[r],o):o);return n}s(Ee,"mergeConfig");function kt(e){return e.kind==="file"?e.path:e.href}s(kt,"describeSource");async function Rr(e){if(e.kind==="file")return{text:await Dr(e.path,"utf8"),source:e};let t;try{t=await fetch(e.href,{cache:"no-store",redirect:"follow",signal:AbortSignal.timeout(Lr)})}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(Rr,"readSource");function wt(e){if(e.protocol==="http:"&&!jr.has(e.hostname))throw new Error(`Refusing to fetch config over plain http: ${e.href} (use https)`);return{kind:"url",href:e.href}}s(wt,"toUrlSource");function Mr(e,t){if(/^https?:\/\//i.test(e))return wt(new URL(e));if(/^[a-z][a-z\d+.-]+:\/\//i.test(e))throw new Error(`Unsupported extends URL "${e}" in ${kt(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 wt(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||Nr(e))return{kind:"file",path:bt(Fr(t.path),e)};try{return{kind:"file",path:vr(t.path).resolve(e)}}catch(r){throw new Error(`Cannot resolve extends "${e}" from ${t.path}: ${r.message}`,{cause:r})}}s(Mr,"resolveReference");function Ir(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(Ir,"readExtends");async function Et(e,t){let n=kt(e);if(t.includes(n))throw new Error(`Config extends cycle: ${[...t,n].join(" -> ")}`);let{text:r,source:o}=await Rr(e),i;try{i=JSON.parse(r)}catch(d){throw new Error(`Config ${n} is not valid JSON: ${d.message}`,{cause:d})}if(!ke(i))throw new Error(`Config file must contain a JSON object: ${n}`);let{extends:a,...c}=i,l={};for(let d of Ir(a,n))l=Ee(l,await Et(Mr(d,o),[...t,n]));return Ee(l,c)}s(Et,"loadSource");function Pr(e,t=process.cwd()){return Et({kind:"file",path:bt(t,e)},[])}s(Pr,"loadConfigFile");async function oe(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 Pr(n,r),...e};return delete o[t],o}s(oe,"applyConfigOption");import{readFile as Ni,stat as Li,writeFile as ji}from"node:fs/promises";import{relative as Xe,resolve as ur}from"node:path";import{extname as Ce}from"node:path";import{extname as Or}from"node:path";var $t=[".c",".h",".cc",".cpp",".cxx",".hh",".hpp",".hxx"],Tr=400,Hr=/\bcopyright\b|\blicen[cs]e[ds]?\b|SPDX-License-Identifier|\bpublic domain\b/i,St=/^[\s*/]*@(?:Project|Filename):/m;function _r(e){let t=Or(e).toLowerCase();return $t.includes(t)?{kind:"block",blockStart:"/*",blockLinePrefix:" * ",blockEnd:" */"}:null}s(_r,"resolveCCommentSyntax");function Ur(e){let t=e.replace(/^\uFEFF/,"").split(`
3
- `).slice(0,Tr),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 d=l.indexOf("*/",2);if(d===-1){r=[l];continue}if(n.push(l.slice(0,d+2)),l.slice(d+2).trim().length>0)break;continue}if(l.startsWith("#")){i=l.endsWith("\\");continue}break}}return o&&n.push(o.join(`
6
- `)),n}s(Ur,"prologueComments");var Ct={id:"c",extensions:$t,enabledByDefault:!0,resolveContentSkipReason(e){let t=Ur(e);return t.length>0&&St.test(t[0])?null:t.some(n=>!St.test(n)&&Hr.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 _r(e)}};import{extname as Wr}from"node:path";var At=[".css"];function Br(e){let t=Wr(e).toLowerCase();return At.includes(t)?{kind:"block",blockStart:"/*",blockLinePrefix:" * ",blockEnd:" */"}:null}s(Br,"resolveCssCommentSyntax");var Dt={id:"css",extensions:At,enabledByDefault:!0,keepsAboveHeader:s((e,t)=>t===0&&/^@charset "[^"]*";/.test(e),"keepsAboveHeader"),resolveCommentSyntax(e){return Br(e)}};import{extname as Vr}from"node:path";var zr=/^(?:#|\/\/|\/\*+|<!--)[ \t]+(vi|vim(?:[<=>]?\d+)?|Vim|ex):(.*)$/,Gr=/^[a-z]+(?:[!&]|[+^-]?=(?:\\.|[^\s:\\])*)?$/,Yr=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 ie(e){let t=e.match(zr);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=>Gr.test(i))&&o.some(i=>i.includes("=")||Yr.has(i))}s(ie,"isModeline");function se(e,t){return t===0&&e.startsWith("#!")}s(se,"isShebang");function ae(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(ae,"takeTopLines");var Ft=[".go"];function Jr(e){let t=Vr(e).toLowerCase();return Ft.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}s(Jr,"resolveGoCommentSyntax");var vt=/^\/\/(?:go:build|\s*\+build)\s/;function Kr(e,t){let n=ae(t,o=>vt.test(o)||ie(o));if(!n.split(/\r?\n/).some(o=>vt.test(o)))return"";let r=t.slice(n.length);return`${n}${r.slice(0,r.length-r.replace(/^(?:[ \t]*\r?\n)*/,"").length)}`}s(Kr,"resolveGoPreservedPrefix");var Nt={id:"go",extensions:Ft,enabledByDefault:!0,resolvePreservedPrefix(e,t){return Kr(e,t)},resolveCommentSyntax(e){return Jr(e)}};import{extname as qr}from"node:path";var Lt=[".html",".htm"];function Xr(e){let t=qr(e).toLowerCase();return Lt.includes(t)?{kind:"html",blockStart:"<!--",blockLinePrefix:" ",blockEnd:"-->"}:null}s(Xr,"resolveHtmlCommentSyntax");var jt={id:"html",extensions:Lt,enabledByDefault:!0,resolveCommentSyntax(e){return Xr(e)}};import{extname as Zr}from"node:path";var Rt=[".jsonv",".jsonc",".json5"];function Qr(e){let t=Zr(e).toLowerCase();return Rt.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}s(Qr,"resolveJsonCommentSyntax");var Mt={id:"json",extensions:Rt,enabledByDefault:!0,resolveCommentSyntax(e){return Qr(e)}};import{extname as eo}from"node:path";var It=[".md",".markdown"];function to(e){let t=eo(e).toLowerCase();return It.includes(t)?{kind:"html",blockStart:"<!--",blockLinePrefix:" ",blockEnd:"-->"}:null}s(to,"resolveMarkdownCommentSyntax");function no(e,t){let n=t.match(/^---\r?\n[\s\S]*?\r?\n---[ \t]*(?:\r?\n|$)/);return n?n[0]:""}s(no,"resolveMarkdownPreservedPrefix");var Pt={id:"markdown",extensions:It,enabledByDefault:!1,requiresForce:!0,resolvePreservedPrefix(e,t){return no(e,t)},resolveCommentSyntax(e){return to(e)}};import{basename as Se,extname as ro}from"node:path";var Ot=[".js",".mjs",".cjs",".ts",".mts",".cts",".tsx",".jsx"];function oo(e){let t=ro(e).toLowerCase();return Ot.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}s(oo,"resolveNodeCommentSyntax");var Tt=/^(.+)\.d\.(ts|mts|cts)$/i,io={ts:[".ts",".tsx",".js",".jsx"],mts:[".mts",".mjs"],cts:[".cts",".cjs"]};function so(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(so,"leadingHeaderFilename");function Ht(e){return Tt.test(Se(e))}s(Ht,"isDeclarationFile");function $e(e,t){let n=Tt.exec(Se(t));if(!n)return null;let r=so(e);if(r===null)return null;let o=Se(r),[,i,a]=n;return io[a.toLowerCase()].some(l=>o===`${i}${l}`)?`the file is a declaration generated from ${o} and carries its header (tsc copies it)`:null}s($e,"declarationCopySkipReason");var _t={id:"node",extensions:Ot,enabledByDefault:!0,keepsAboveHeader:se,resolveContentSkipReason(e,t){return $e(e,t)},resolveCommentSyntax(e){return oo(e)}};import{extname as ao}from"node:path";var Wt=[".php"];function co(e){let t=ao(e).toLowerCase();return Wt.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}s(co,"resolvePhpCommentSyntax");var Ut=/^<\?php(?:\s|$)/i,Bt={id:"php",extensions:Wt,enabledByDefault:!0,keepsAboveHeader:s((e,t)=>t===0&&Ut.test(e),"keepsAboveHeader"),resolveContentSkipReason(e){return Ut.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 co(e)}};import{extname as lo}from"node:path";var zt=[".py"],uo=/^#.*?(?<![A-Za-z])coding[:=]\s*[-\w.]+/;function fo(e,t){return se(e,t)||t<=1&&uo.test(e)}s(fo,"keepsAboveHeader");var Gt={id:"python",extensions:zt,enabledByDefault:!0,keepsAboveHeader:fo,resolveCommentSyntax(e){let t=lo(e).toLowerCase();return zt.includes(t)?{kind:"line",linePrefix:"#"}:null}};import{extname as mo}from"node:path";var Yt=[".rs"];function po(e){let t=mo(e).toLowerCase();return Yt.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}s(po,"resolveRustCommentSyntax");var Vt={id:"rust",extensions:Yt,enabledByDefault:!0,keepsAboveHeader:s((e,t)=>t===0&&e.startsWith("#!")&&!/^#!\s*\[/.test(e),"keepsAboveHeader"),resolveCommentSyntax(e){return po(e)}};import{extname as ho}from"node:path";var Jt=[".yaml",".yml"];function go(e){let t=ho(e).toLowerCase();return Jt.includes(t)?{kind:"line",linePrefix:"#"}:null}s(go,"resolveYamlCommentSyntax");var Kt={id:"yaml",extensions:Jt,enabledByDefault:!0,keepsAboveHeader:s((e,t)=>t===0&&/^#cloud-config\s*$/.test(e),"keepsAboveHeader"),resolveCommentSyntax(e){return go(e)}};var ce=[Ct,Dt,Nt,jt,Mt,Pt,_t,Bt,Gt,Vt,Kt],yo=new Map(ce.map(e=>[e.id,e]));function xo(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(xo,"applySyntaxOverride");function qt(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=ce.filter(n=>n.requiresForce===!0).map(n=>n.id);for(let n of e){if(!yo.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(qt,"resolveForcedDetectors");function P(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 ce.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(P,"getEnabledDetectors");function Xt(e={}){if(Array.isArray(e.includeExtensions)&&e.includeExtensions.length>0)return new Set(e.includeExtensions.map(n=>n.toLowerCase()));let t=P(e);return new Set(t.flatMap(n=>n.extensions))}s(Xt,"getAllowedExtensions");function Zt(e,t={}){let n=Ce(e).toLowerCase();if(P(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=ce.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(Zt,"getHeaderSkipReason");function Qt(e,t={}){let n=Ce(e).toLowerCase(),r=Array.isArray(t.detectors)?t.detectors:P(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 xo(i,a[o.id])}}return{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}}s(Qt,"getCommentSyntaxForFile");function en(e,t){let n=Ce(e).toLowerCase();return P(t).find(r=>r.extensions.includes(n))}s(en,"detectorForFile");function le(e,t,n={}){let r=en(e,n);if(!r)return"";let o=typeof r.resolvePreservedPrefix=="function"?r.resolvePreservedPrefix(e,t):"",i=r.keepsAboveHeader,a=ae(t.slice(o.length),(c,l)=>ie(c)||typeof i=="function"&&i(c,l),o.split(`
8
- `).length-1);return`${o}${a}`}s(le,"getPreservedPrefixForFile");function tn(e,t,n={}){let r=en(e,n);return r&&typeof r.resolveContentSkipReason=="function"?r.resolveContentSkipReason(t,e):null}s(tn,"getContentSkipReason");var nn=200,X=1,ue=2;function O(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(O,"resolveLayoutCount");import{existsSync as No}from"node:fs";import{join as Re,relative as gn,resolve as Me,sep as Le}from"node:path";import{realpath as Lo,stat as jo}from"node:fs/promises";import{access as wo,readdir as bo,readFile as ua,stat as ko}from"node:fs/promises";import{constants as Eo}from"node:fs";import{dirname as ma,join as So,resolve as pa}from"node:path";async function Ae(e){try{return await wo(e,Eo.F_OK),!0}catch{return!1}}s(Ae,"pathExists");async function De(e,t){let n=[],r=await bo(e,{withFileTypes:!0});for(let o of r){let i=So(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 De(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(De,"walkFiles");async function rn(e){let t=await ko(e);return{createdAt:t.birthtimeMs>0&&t.birthtime<t.mtime?t.birthtime:t.mtime,updatedAt:t.mtime}}s(rn,"readFileDates");function on(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(on,"hasAngleTag");function sn(e){let t=e.length;for(;t>0&&e[t-1]==="/";)t-=1;return e.slice(0,t)}s(sn,"trimTrailingSlashes");import{execFile as $o}from"node:child_process";import{lstat as Co,readFile as Ao}from"node:fs/promises";import{dirname as an,isAbsolute as Do,join as un,relative as dn,resolve as ve,sep as fn}from"node:path";import vo from"ignore";function cn(e,t){return new Promise(n=>{$o("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(cn,"runGitCommand");function Ne(e,t){return dn(e,t).split(fn).join("/")}s(Ne,"toPosixRelative");async function mn(e){try{return vo().add(await Ao(e,"utf8"))}catch{return null}}s(mn,"readIgnoreFile");async function Fo(e){return Co(un(e,".git")).then(()=>!0,()=>!1)}s(Fo,"hasGitEntry");function ln(e,t,n){for(let r=e.length-1;r>=0;r--){let{base:o,rules:i}=e[r],a=i.test(`${Ne(o,t)}${n?"/":""}`);if(a.ignored||a.unignored)return a.ignored}return!1}s(ln,"matchesRules");async function pn(e,t){let n=await mn(un(e,".gitignore"));return{kind:"rules",nested:!0,excluded:!1,matchers:n?[...t,{base:e,rules:n}]:t}}s(pn,"buildRulesContext");async function Fe(e){let[t,n]=await Promise.all([cn(e,["check-ignore","-q","."]),cn(e,["ls-files","--cached","--others","--exclude-standard","-z"])]);if(t.code!==1||n.code!==0)return pn(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(Fe,"resolveScopeContext");function hn(e){let t=ve(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 Fe(t);let c=typeof n=="string"?[n]:n.filter(d=>typeof d=="string"),l=[];for(let d of c){let u=await mn(ve(t,d));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(an(c));return l.kind==="git"?l.entries.has(Ne(l.root,c))?Fe(c):l:!l.nested||l.excluded?l:ln(l.matchers,c,!0)?{...l,excluded:!0}:await Fo(c)?Fe(c):pn(c,l.matchers)},"deriveContext");return{async isIgnored(c,l){let d=ve(c),u=dn(t,d);if(u.length===0||u===".."||u.startsWith(`..${fn}`)||Do(u))return!1;let m=await i(an(d));if(m.kind==="git"){let g=Ne(m.root,d);return!(m.entries.has(g)||l&&m.dirs.has(g))}return m.excluded||ln(m.matchers,d,l)}}}s(hn,"createIgnoreFilter");function Ro(e){return Xt(e)}s(Ro,"resolveExtensions");var Mo=Object.freeze(["node_modules","bower_components","jspm_packages",".pnpm-store",".yarn"]),wn=new Set([".git",...Mo]),Io=Object.freeze(["autoload.php","modules.txt"]);function yn(e,t){return wn.has(t)?!0:t==="vendor"&&Io.some(n=>No(Re(e,n)))}s(yn,"isNeverWalked");function je(e){return sn(e.replace(/\\/g,"/").replace(/^\.\//,"").replace(/^\/+/,""))}s(je,"normalizeFolderPath");function Po(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(Po,"resolveIncludeFolders");function xn(e,t){let n=t instanceof Error?t.message:String(t);console.warn(`fix-headers: skipped include folder "${e}" (${n})`)}s(xn,"reportSkippedIncludeFolder");function Oo(e,t){if(!Array.isArray(t)||t.length===0)return()=>!1;let n=Me(e),r=[],o=new Set;for(let i of t){if(typeof i!="string")continue;let a=je(i);if(a.length!==0){if(a.includes("/")){r.push(Me(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=je(gn(n,i));return r.some(l=>{let d=je(gn(n,l));return c===d||c.startsWith(`${d}/`)})}}s(Oo,"buildExclusionMatcher");async function Ie(e){let t=Ro(e),n=Po(e.includeFolders),r=Array.isArray(e.excludeFolders)?e.excludeFolders:[],o=Oo(e.projectRoot,r),i=hn({root:e.projectRoot,gitignore:e.gitignore}),a=s(async(f,p)=>yn(f,p)||o(f,p)||await i.isIgnored(f,!0),"shouldSkipDirectory"),c=n.length>0?n.map(f=>({includeFolder:f.path,rootPath:Re(e.projectRoot,f.path),recursive:f.recursive})):[{includeFolder:".",rootPath:e.projectRoot,recursive:!0}],l=[];for(let f of c){let p=await jo(f.rootPath).catch(b=>b);if(p instanceof Error){if(p.code==="ENOENT"){xn(f.includeFolder,p);continue}throw p}if(!p.isDirectory()){xn(f.includeFolder,`path is not a directory: ${f.rootPath}`);continue}let w=await Lo(f.rootPath).catch(()=>Me(f.rootPath));l.push({...f,realRoot:w})}let d=s((f,p)=>{if(f.realRoot===p.realRoot)return f.recursive||!p.recursive;let w=f.realRoot.endsWith(Le)?f.realRoot:`${f.realRoot}${Le}`;if(!f.recursive||!p.realRoot.startsWith(w))return!1;let b=f.rootPath;for(let E of p.realRoot.slice(w.length).split(Le))if(b=Re(b,E),yn(b,E)||o(b,E))return!1;return!0},"covers"),u=[...l].sort((f,p)=>f.realRoot.length-p.realRoot.length||Number(p.recursive)-Number(f.recursive)),m=[];for(let f of u)m.some(p=>d(p,f))||m.push(f);let g=[];for(let f of l){if(!m.includes(f))continue;let p=await De(f.rootPath,{allowedExtensions:t,ignoreFolders:wn,shouldSkipDirectory:a,recursive:f.recursive});g.push(...p)}let y=[];for(let f of new Set(g))!o(f,f.split("/").at(-1)||"")&&!await i.isIgnored(f,!1)&&y.push(f);return y}s(Ie,"discoverFiles");import{basename as li,dirname as ui,extname as di,resolve as Ue}from"node:path";import{dirname as Ln,isAbsolute as Jo,join as jn,relative as Ko,resolve as Rn,sep as qo}from"node:path";import{readFile as To}from"node:fs/promises";import{join as Ho}from"node:path";async function _o(e){try{return await To(e,"utf8")}catch{return null}}s(_o,"readManifest");async function R(e,t){let n=[];for(let r of t){let o=await _o(Ho(e,r));o!==null&&n.push({file:r,content:o})}return n.length>0?{dir:e,manifest:n[0].file,files:n}:null}s(R,"detectManifests");function T(e,t){return e.files.find(n=>n.file===t)?.content??null}s(T,"manifestContent");function C(e){return typeof e=="string"&&e.trim().length>0?e.trim():void 0}s(C,"cleanName");function Pe(e){if(typeof e!="string")return;let t=e.search(/[<(]/);return C(t===-1?e:e.slice(0,t))}s(Pe,"personName");function de(e){try{return JSON.parse(e)}catch{return}}s(de,"parseJsonManifest");function*Oe(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(Oe,"sectionLines");function Z(e,t,n){let r=new RegExp(`^${n}\\s*=\\s*(?:"([^"\\\\]*)"|'([^']*)')`);for(let o of Oe(e,t)){let i=o.match(r);if(i)return C(i[1]??i[2])}}s(Z,"readTomlString");function Te(e,t,n){let r=new RegExp(`^${n}\\s*[=:](.*)$`);for(let o of Oe(e,t)){let i=o.match(r);if(i)return C(i[1])}}s(Te,"readIniValue");function Uo(e,t,n){let r=new RegExp(`^${n}\\s*=\\s*\\[`),o=null;for(let i of Oe(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(Uo,"tomlArrayText");function Wo(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(Wo,"skipTomlSpace");function Q(e,t){let n=Uo(e,t,"authors");if(n===null)return;let r=n.slice(Wo(n,0)),o=r.match(/^(?:"([^"\\\n]*)"|'([^'\n]*)')/);if(o)return Pe(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 bn=["go.mod"];function Bo(e){let t=e.match(/^\s*module\s+(.+)$/m);if(t)return C(t[1].replace(/\/\/.*$/,"").trim().replace(/^["`](.*)["`]$/,"$1"))}s(Bo,"readModulePath");var kn={id:"go",languages:["go"],manifests:bn,detect(e){return R(e,bn)},read(e){return{name:Bo(e.files[0].content)}}};var En=["package.json"];function zo(e){let t=C(e?.name),n=C(e?.publisher),r=typeof e?.engines?.vscode=="string";return t&&n&&r?`${n}.${t}`:t}s(zo,"readPublishedName");function Go(e){if(e!==null&&typeof e=="object"){let t=e;return C(t.company)??C(t.name)}return Pe(e)}s(Go,"readAuthorCompany");var Sn={id:"node",languages:["node"],manifests:En,detect(e){return R(e,En)},read(e){let t=de(e.files[0].content);return{name:zo(t),company:Go(t?.author)}}};var $n=["composer.json"],Cn={id:"php",languages:["php"],manifests:$n,detect(e){return R(e,$n)},read(e){let t=de(e.files[0].content),n=t?.authors;return{name:C(t?.name),company:Array.isArray(n)?C(n[0]?.name):void 0}}};var An=["pyproject.toml","setup.cfg","setup.py"];function Dn(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(Dn,"readSetupPyArgument");function Yo(e){let t=T(e,"pyproject.toml"),n=T(e,"setup.cfg"),r=T(e,"setup.py");return(t===null?void 0:Z(t,"project","name")??Z(t,"tool.poetry","name"))??(n===null?void 0:Te(n,"metadata","name"))??(r===null?void 0:Dn(r,"name"))}s(Yo,"readPythonName");function Vo(e){let t=T(e,"pyproject.toml"),n=T(e,"setup.cfg"),r=T(e,"setup.py");return(t===null?void 0:Q(t,"project")??Q(t,"tool.poetry"))??(n===null?void 0:Te(n,"metadata","author"))??(r===null?void 0:Dn(r,"author"))}s(Vo,"readPythonCompany");var vn={id:"python",languages:["python"],manifests:An,detect(e){return R(e,An)},read(e){return{name:Yo(e),company:Vo(e)}}};var Fn=["Cargo.toml"],Nn={id:"rust",languages:["rust"],manifests:Fn,detect(e){return R(e,Fn)},read(e){let t=e.files[0].content;return{name:Z(t,"package","name"),company:Q(t,"package")}}};var Xo=[Sn,vn,Cn,Nn,kn],Mn=["name","company"];async function He(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(He,"claimFolder");function Zo(e,t){let n=Ko(t,e);return n!==""&&n!==".."&&!n.startsWith(`..${qo}`)&&!Jo(n)}s(Zo,"isStrictlyInside");async function In(e,t={}){let n=Array.isArray(t.drivers)?t.drivers:Xo,r=typeof t.scanRoot=="string"?Rn(t.scanRoot):null,o=Rn(e),i=await He(o,n,t.language);for(;i.length===0;){if(await Ae(jn(o,".git")))return{root:o,marker:".git",drivers:[],fields:{},sources:{}};let u=Ln(o);if(u===o)return null;o=u,i=await He(o,n,t.language)}let a={},c={},l=o,d=i;for(;;){for(let{driver:m,detection:g}of d){let y=m.read(g);for(let f of Mn)a[f]===void 0&&y[f]!==void 0&&(a[f]=y[f],c[f]={driver:m.id,manifest:g.manifest,dir:l})}if(Mn.every(m=>a[m]!==void 0)||r===null||!Zo(l,r)||await Ae(jn(l,".git")))break;l=Ln(l),d=await He(l,n,t.language)}return{root:o,marker:i[0].detection.manifest,drivers:i.map(u=>u.driver.id),fields:a,sources:c}}s(In,"resolveManifestProject");import{execFile as Qo}from"node:child_process";import{basename as ei,dirname as ti}from"node:path";import{promisify as ni}from"node:util";var _e=ni(Qo);async function N(e,t){try{let{stdout:n}=await _e("git",t,{cwd:e}),r=n.trim();return r.length>0?r:null}catch{return null}}s(N,"runGit");function Pn(e,t){let n=0;for(let r=t-1;r>=0&&e[r]==="\\";r--)n++;return n%2===1}s(Pn,"isEscaped");function ri(e){let t=e.trim();if(!t.endsWith(")")||Pn(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!==")"||Pn(t,r))&&(n+=o===")"?1:-1,n===0))return t.slice(0,r).trim()}return t}s(ri,"stripUidComment");function oi(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:ri(o)||o||null,authorEmail:r}}s(oi,"parseSignerUid");async function ii(e,t){try{let{stdout:n}=await _e(e,t),r=n.trim();return r.length>0?r:null}catch{return null}}s(ii,"runProgram");function si(e){return e.replace(/\\x([0-9a-fA-F]{2})/g,(t,n)=>String.fromCharCode(Number.parseInt(n,16)))}s(si,"decodeColonField");async function ai(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 ii(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 si(a[9])}return null}s(ai,"readSigningKeyUid");async function On(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 ai(e)||await N(e,["log","-1","--format=%GS"]),i=oi(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(On,"detectGitAuthor");function Tn(e){return e.replace(/z$/i,"+00:00")}s(Tn,"canonicalGitDate");async function Hn(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:Tn(o),timestamp:a}}s(Hn,"getGitCreationDate");async function _n(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:Tn(r),timestamp:i}}s(_n,"getGitLastModifiedDate");var ci=256*1024*1024;async function Un(e){let t=ti(e);if(await N(t,["rev-parse","--is-inside-work-tree"])!=="true")return{state:"no-git",content:null};try{let{stdout:n}=await _e("git",["show",`HEAD:./${ei(e)}`],{cwd:t,encoding:"utf8",maxBuffer:ci});return{state:"tracked",content:n}}catch{return{state:"untracked",content:null}}}s(Un,"readGitHeadFile");function fi(e){return li(e)||"project"}s(fi,"folderName");function mi(e,t){if(typeof t!="string")return e;let n=t.trim();return n.length===0||on(e)?e:`${e} <${n}>`}s(mi,"formatAuthorNameWithCompany");async function pi(e,t={}){let n=Array.isArray(t.detectors)?t.detectors:P(t),r=typeof t.preferredExtension=="string"?t.preferredExtension.trim().toLowerCase():"",o=r.length>0?n.find(d=>d.extensions.includes(r)):void 0,i=await In(e,{drivers:t.drivers,language:o?.id,scanRoot:t.scanRoot}),a=i?i.root:Ue(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??fi(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(pi,"detectProjectFromMarkers");async function We(e={}){let t=e.targetFilePath||e.cwd||process.cwd(),n=Ue(t),r=P(e),o=e.targetFilePath?ui(n):n,i=e.targetFilePath?di(n).toLowerCase():"",a=Ue(e.projectRoot||e.cwd||process.cwd()),c=await pi(o,{detectors:r,preferredExtension:i,scanRoot:a}),l=await On(c.rootDir,{useGpgSignerAuthor:e.useGpgSignerAuthor===!0}),d=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:mi(d,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(We,"resolveProjectMetadata");function hi(e){return Be({year:e.getFullYear(),month:e.getMonth()+1,day:e.getDate(),hour:e.getHours(),minute:e.getMinutes(),second:e.getSeconds(),offsetMinutes:-e.getTimezoneOffset()})}s(hi,"formatDateWithTimezone");function Be(e){return`${Gn(e," ")} ${Yn(e.offsetMinutes)}`}s(Be,"formatSpaceDate");function Bn(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{zn(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(Bn,"assertTimeZone");var Wn=new Map;function zn(e){let t=Wn.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"}),Wn.set(e,t)),t}s(zn,"getZoneFormatter");function ze(e,t){let n={};for(let o of zn(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(ze,"toZonedDateParts");function Gn(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(Gn,"formatWallClock");function Yn(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(Yn,"formatOffset");function fe(e=new Date){return{date:hi(e),timestamp:Math.floor(e.getTime()/1e3)}}s(fe,"toDatePayload");var gi=/^(\d{4})-(\d{2})-(\d{2})(?:T|\s+)(\d{2}):(\d{2}):(\d{2})(?:\.\d+)?\s*(?:(Z)|([+-])(\d{2}):?(\d{2}))$/i;function H(e){let t=gi.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]),d=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:d,timestamp:Math.floor(u.getTime()/1e3)-d*60}}s(H,"parseHeaderDate");function Ge(e){return`${Gn(e,"T")}${Yn(e.offsetMinutes)}`}s(Ge,"formatIsoDate");var yi={"git-created":"git first commit","filesystem-created":"filesystem creation time"};function Vn(e,t){let n=e.match(new RegExp(`${t}:[^\\S\\n]*(.*)$`,"m"));return n?n[1].trim():null}s(Vn,"readHeaderField");function Ye(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(Ye,"pickOldestDate");function Kn({existing:e,gitCreated:t,filesystemCreated:n,fixCreatedDate:r=!1}){let o=[{source:"git-created",payload:t},{source:"filesystem-created",payload:n}];if(!e)return Ye(o);if(!r)return{source:"existing-header",payload:e};let i=H(e.date)?e:null;return Ye([{source:"existing-header",payload:i},...o])}s(Kn,"resolveCreatedDate");function qn(e,t=null){if(t)return ze(e.timestamp,t).year;let n=H(e.date);return n?n.year:new Date(e.timestamp*1e3).getFullYear()}s(qn,"dateYear");function Jn(e,t,n,r){let o=e.match(/^(.+?)\s*\((\d+)\)$/),i=o?H(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(Jn,"checkDateValue");function Xn(e,t={},n={}){let r=[],o=Vn(e,"@Date"),i=o===null?null:Jn(o,"@Date","created",r),a=Ye([{source:"git-created",payload:t.gitCreated},{source:"filesystem-created",payload:t.filesystemCreated}]);if(i&&a&&i.timestamp>a.payload.timestamp){let u=yi[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=Vn(e,"@Last modified time"),l=c===null?null:Jn(c,"@Last modified time","modified",r),d=t.gitLastModified;return l&&d&&l.timestamp!==d.timestamp&&r.push({check:"modified-git",field:"@Last modified time",advisory:!0,value:c,expected:`${d.date} (${d.timestamp})`,message:`@Last modified time ${l.text} does not match the git last commit ${d.date} (${d.timestamp})`}),r}s(Xn,"checkHeaderDates");function Ve(e){if(!e)return null;let t=H(e.date);return t&&t.timestamp!==e.timestamp?{date:e.date,timestamp:t.timestamp}:e}s(Ve,"repairDateEpoch");function Zn(e){let t=H(e.date);return t?{date:Ge(t),timestamp:t.timestamp}:e}s(Zn,"normalizeDatePayload");function Qn(e,t){let n=H(e.date);if(!n)return e;let r=ze(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())?Ge(r):Be(r),timestamp:n.timestamp}}s(Qn,"convertDatePayload");import{relative as wi}from"node:path";import{extname as xi}from"node:path";function _(e,t={}){let n=xi(e).toLowerCase(),r=O(t.spacing,"spacing",X);return n.length===0?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */",spacing:r}:{...Qt(e,t),spacing:r}}s(_,"getHeaderSyntaxForFile");function er(e,t){let n=e.spacing??X;if(e.kind==="line"){let c=e.linePrefix||"#",l=typeof e.lineSeparator=="string"?e.lineSeparator:" ",d=Array.from({length:n},()=>c);return[...d,...t.map(u=>`${c}${l}${u}`),...d].join(`
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(`
14
- `)}s(er,"renderHeaderLines");function tr(e){let t=wi(e.projectRoot,e.absoluteFilePath).replace(/\\/g,"/"),n=_(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} `:"",d=[`@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 er(n,d)}s(tr,"buildHeader");var bi=Object.freeze(["projectName","filename","createdAt","authorName","authorEmail","lastModifiedByName","lastModifiedByEmail","lastModifiedAt","copyrightStartYear","copyrightEndYear","companyName"]);function M(e,t){let n=e.match(new RegExp(`@${t}:[ \\t]*(.*)$`,"m")),r=n?n[1].trim():"";return r.length>0?r:null}s(M,"readTag");function ki(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(ki,"splitLastModifiedBy");function Ei(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(Ei,"splitCopyright");function nr(e){let t=ki(M(e,"Last modified by")),n=Ei(M(e,"Copyright")),r=M(e,"Email");return{projectName:M(e,"Project"),filename:M(e,"Filename"),createdAt:M(e,"Date"),authorName:M(e,"Author"),authorEmail:r===null?null:r.replace(/^<(.*)>$/,"$1"),lastModifiedByName:t.name,lastModifiedByEmail:t.email,lastModifiedAt:M(e,"Last modified time"),copyrightStartYear:n.startYear,copyrightEndYear:n.endYear,companyName:n.companyName}}s(nr,"parseHeaderFields");function rr(e,t){let n=nr(e??""),r=nr(t);return bi.filter(o=>n[o]!==r[o]).map(o=>({field:o,previous:n[o],detected:r[o]}))}s(rr,"compareHeaderFields");function ee(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}s(ee,"escapeRegex");function Je(e,t,n={}){let r=t.startsWith("\uFEFF")?"\uFEFF":"",o=t.slice(r.length),i=`${r}${le(e,o,n)}`;return{prefix:i,body:t.slice(i.length)}}s(Je,"splitPreservedPrefix");function me(e){let t=e.indexOf(`
15
- `);return t===-1?null:t>0&&e[t-1]==="\r"?`\r
16
- `:`
17
- `}s(me,"lineEnding");function G(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(G,"matchHeaderSegment");var sr=/^@(Project|Filename|Date|Author|Email|Last modified by|Last modified time|Copyright):/,Si="Moved out of the file header by fix-headers:";function ar(e){return e.some(t=>/^@(?:Project|Filename):/.test(t.text))}s(ar,"isFileHeader");function Ke(e,t){let n=e.replace(/(?:\r?\n)+$/,"");if(t.kind==="line"){let u=new RegExp(`^${ee(t.linePrefix||"#")}[ \\t]*`);return n.split(`
18
- `).map(m=>{let g=m.replace(/\r$/,"");return{raw:g,text:g.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(`
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,d=c.length>l&&c[c.length-1].raw.trim()===""?c.length-1:c.length;return c.slice(l,d)}s(Ke,"segmentLines");function $i(e,t){let n=e.map(o=>{let i=o.text.match(sr);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($i,"classifyLines");function Ci(e,t="",n={}){let r=_(t,n),o=[],i=[],a={copyright:!1},c=e,l=G(c,r),d=!0;for(;l&&l[0].length>0;){let p=Ke(l[0],r),w=$i(p,a),b=p.findIndex(E=>E.text!=="");!d&&b!==-1&&p[b].text===Si&&(w[b]="separator"),p.forEach((E,L)=>{w[L]==="copyright"&&i.push(E.text.replace(sr,"").trim()),o.push({raw:E.raw,kind:w[L]})}),c=c.slice(l[0].length),l=G(c,r),d=!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"),g=[],y=[],f=!1;for(let p of o.slice(u,m+1))p.kind==="text"?(g.push(...f?[]:y,p.raw),y=[],f=!1):p.kind==="blank"?y.push(p.raw):f=!0;return{foreign:g,copyrights:i}}s(Ci,"splitHeaderText");function Ai(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(Ai,"renderForeignBlock");function Di(e,t,n){let r=e.split(`
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(`
21
- `)}s(Di,"appendToHeader");function or(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(or,"copyrightHolder");function vi(e,t){let n=e.split(`
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(`
24
- `)}s(vi,"insertCopyrights");function ir(e,t){let n=0,r=G(e,t);for(;r&&r[0].length>0&&ar(Ke(r[0],t));)n+=r[0].length,r=G(e.slice(n),t);return n}s(ir,"leadingHeadersLength");function pe(e,t="",n={}){let r=e.startsWith("\uFEFF")?"\uFEFF":"",o=e.slice(r.length),i=le(t,o,n),a=_(t,n),c=i.length,l=ir(o.slice(c),a);if(l===0)return e;let d=r===""&&c===0&&o.startsWith("\uFEFF",l);d&&(r="\uFEFF",o=`${o.slice(0,l)}${o.slice(l+1)}`,l+=ir(o.slice(l),a));let u=o.slice(c,c+l),m=o.slice(c+l),g=le(t,`${i}${m}`,n),y=g.length>i.length?g.slice(i.length):"";if(y===""&&!d)return e;let f=y===""||y.endsWith(`
25
- `)?y:`${y}${me(e)??`
26
- `}`;return`${r}${i}${f}${u}${m.slice(y.length)}`}s(pe,"restoreTopLines");function he(e,t="",n={}){let{prefix:r,body:o}=Je(t,e,n),i=o.split(`
27
- `).slice(0,nn).join(`
28
- `),a=_(t,n);if(!G(i,a))return null;let l=0,d=0;for(;;){let u=i.slice(l),m=G(u,a);if(!m||!ar(Ke(m[0],a)))break;l+=m[0].length,d=l}return d===0?null:{start:r.length,end:r.length+d}}s(he,"findProjectHeader");function ge(e,t,n="",r={}){let o=pe(e,n,r),i=he(o,n,r),a=_(n,r),c=O(r.margin,"margin",ue),l=a.kind==="line"?Math.max(1,c):c,d=s((h,$)=>$===`
29
- `?h:h.replace(/\r?\n/g,$),"withEol");if(!i){let{prefix:h,body:$}=Je(n,o,r),A=me(o)??`
30
- `,S=d(t,A),I=$.replace(/^(?:\r?\n)+/,""),ne=h.replace(/^\uFEFF/,"")!==""&&!h.endsWith(`
31
- `)?A:"",W=`${h}${ne}${I.trim()===""?`${S}${A}`:`${S}${A.repeat(l+1)}${I}`}`;return{nextContent:W,changed:W!==e,header:S,written:S,extraCopyrights:[]}}let u=o.slice(i.start,i.end),{foreign:m,copyrights:g}=Ci(u,n,r),y=t.split(`
32
- `).find(h=>h.includes("@Copyright:")),f=new Set(y===void 0?[]:[or(y.slice(y.indexOf("@Copyright:")+11))]),p=[];for(let h of g){let $=or(h);f.has($)||(f.add($),p.push(h))}let w=me(o.slice(i.end))??me(u)??`
33
- `,b=w.repeat(l+1),E=r.strictHeaderBlock!==!1,L=vi(t,p),D=d(m.length>0&&!E?Di(L,m,a):L,w),k=m.length>0&&E?Ai(m,a,w):"",U=o.slice(i.end).replace(/^(?:\r?\n)+/,""),Y=k===""?U:`${k}${U.trim()===""?w:`${b}${U}`}`,V=`${o.slice(0,i.start)}${Y.trim()===""?`${D}${w}`:`${D}${b}${Y}`}`,te=`${D}${k===""?"":`${b}${k}`}`;return{nextContent:V,changed:V!==e,header:D,written:te,extraCopyrights:p}}s(ge,"replaceOrInsertHeader");function qe(e,t="",n={}){let r=pe(e,t,n),o=he(r,t,n);if(o){let l=r.slice(0,o.start),u=ge(r,"",t,{...n,strictHeaderBlock:!0}).nextContent.slice(l.length).replace(/^(?:\r?\n)+/,"");return`${l}${u.trim()===""?"":u}`}let{prefix:i,body:a}=Je(t,r,n),c=a.replace(/^(?:\r?\n)+/,"");return`${i}${c.trim()===""?"":c}`}s(qe,"extractHeaderlessBody");function Fi(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 d=r-1;d>=0;d-=1)o[l][d]=e[l]===t[d]?o[l+1][d+1]+1:Math.max(o[l+1][d],o[l][d+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(Fi,"diffLines");function cr(e,t){return`${t===0?e:e+1},${t}`}s(cr,"formatRange");function lr(e,t,n={}){let r=e===null?[]:e.split(`
34
- `),o=t.split(`
35
- `),i=Fi(r,o),a=Math.max(0,n.context??3),c=n.lineOffset??0,l=[];if(i.forEach((g,y)=>{if(g.type===" ")return;let f=l[l.length-1];f&&y-f.last<=a*2+1?f.last=y:l.push({first:y,last:y})}),l.length===0)return"";let d=n.fromFile??"a",u=n.toFile??"b",m=[`--- ${e===null?"/dev/null":d}`,`+++ ${u}`];for(let g of l){let y=Math.max(0,g.first-a),f=Math.min(i.length,g.last+a+1),p=i.slice(0,y),w=i.slice(y,f),b=p.filter(k=>k.type!=="+").length+c,E=p.filter(k=>k.type!=="-").length+c,L=w.filter(k=>k.type!=="+").length,D=w.filter(k=>k.type!=="-").length;m.push(`@@ -${cr(b,L)} +${cr(E,D)} @@`);for(let k of w)m.push(`${k.type}${k.line}`)}return m.join(`
36
- `)}s(lr,"createUnifiedDiff");function Ri(e){return oe(e,"configFile")}s(Ri,"resolveRuntimeOptions");function Mi(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(Mi,"resolveInputs");function Ii(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(Ii,"extractHeaderAuthorIdentity");function Pi(e){let t=e.match(/@Last modified by:\s*(.+?)\s*\(([^)\n]+)\)\s*$/m);return{authorName:t?.[1]?.trim(),authorEmail:t?.[2]?.trim()}}s(Pi,"extractHeaderLastModifiedIdentity");function Oi(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(Oi,"extractHeaderCreatedAt");function Ti(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(Ti,"extractHeaderLastModifiedAt");async function Hi(e,t,n){let r=await Un(t);return r.state!=="tracked"?{edited:r.state==="untracked",state:r.state}:{edited:qe(r.content,t,n)!==qe(e,t,n),state:"tracked"}}s(Hi,"detectContentEdit");async function dr(e={}){let t=await Ri(e),n=t.timezone===void 0||t.timezone===null?null:Bn(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=qt(t.forcedDetectors),i=ur(t.projectRoot||t.cwd||process.cwd()),a=await We({...t,cwd:i});O(t.spacing,"spacing",X),O(t.margin,"margin",ue);let c=t.check===!0,l=c||t.dryRun===!0,d=t.fixCreatedDate===!0,u=t.rewriteDeclarationCopies!==!1,m=s(h=>h,"keepDate"),g=t.normalizeDateFormat===!0?Zn:m,y=n?h=>Qn(h,n):m,f=r?y:m,p={language:a.language,enabledDetectors:t.enabledDetectors,disabledDetectors:t.disabledDetectors,forcedDetectors:o,includeFolders:t.includeFolders,excludeFolders:t.excludeFolders,includeExtensions:t.includeExtensions,gitignore:t.gitignore},w=Mi(t.input),b;if(w.length>0){let h=new Set;for(let $ of w){let A=ur(i,$),S=await Li(A).catch(()=>null);if(!S)throw new Error(`Input path does not exist: ${$}`);if(S.isFile())h.add(A);else if(S.isDirectory())for(let I of await Ie({...p,projectRoot:A}))h.add(I);else throw new Error(`Input path must be a file or directory: ${$}`)}b=Array.from(h)}else b=await Ie({...p,projectRoot:i});let E=new Date().getFullYear(),L=[],D=[],k=new Set,U=0,Y=0,V=0,te=[];for(let h of b){let $=Zt(h,{enabledDetectors:t.enabledDetectors,disabledDetectors:t.disabledDetectors,forcedDetectors:o});if($!==null){D.push({file:Xe(i,h),reason:$});continue}let A=Xe(i,h),S=await Ni(h,"utf8"),I={enabledDetectors:t.enabledDetectors,disabledDetectors:t.disabledDetectors,forcedDetectors:o,detectorSyntaxOverrides:t.detectorSyntaxOverrides},ne=pe(S,h,I),W=u&&$e(ne,h)!==null,Qe=W?null:tn(h,ne,I);if(Qe!==null){D.push({file:A,reason:Qe});continue}let x=await We({...t,cwd:i,targetFilePath:h});k.add(`${x.language}:${x.projectRoot}`);let J={language:x.language,enabledDetectors:t.enabledDetectors,disabledDetectors:t.disabledDetectors,forcedDetectors:o,detectorSyntaxOverrides:t.detectorSyntaxOverrides,spacing:t.spacing,margin:t.margin,strictHeaderBlock:t.strictHeaderBlock!==!1},ye=he(S,h,J),v=ye?S.slice(ye.start,ye.end):"",et=v.length>0?Ii(v):{},tt=v.length>0?Pi(v):{},yr=v.length>0?Oi(v):null,xr=v.length>0?Ti(v):null,nt=await rn(h),rt=Xe(x.projectRoot,h),ot=await Hn(x.projectRoot,rt),K=await _n(x.projectRoot,rt),it=fe(nt.createdAt),xe=Kn({existing:Ve(yr),gitCreated:ot,filesystemCreated:it,fixCreatedDate:d}),B=Ve(xr),st=xe.source,wr=B?"existing-header":K?"git-last-modified":"filesystem-updated",we=g(st==="existing-header"?f(xe.payload):y(xe.payload)),br=x.copyrightStartYear===null?"created-date":"option",at=x.copyrightStartYear??qn(we,n),ct=g(B?f(B):y(K||fe(nt.updatedAt))),lt=t.forceAuthorUpdate===!0,kr=t.forceLastModifiedAuthorUpdate===!0,ut=W?null:await Hi(S,h,J),dt=W||u&&ut?.state==="untracked"&&v.length>0&&Ht(h),ft=dt?{edited:!1,state:"no-git"}:ut,mt=kr||ft.edited,pt=s(F=>tr({absoluteFilePath:h,language:x.language,syntaxOptions:J,projectRoot:x.projectRoot,projectName:x.projectName,createdByName:lt?x.authorName:et.authorName||x.authorName,createdByEmail:lt?x.authorEmail:et.authorEmail||x.authorEmail,lastModifiedByName:mt?x.authorName:tt.authorName||x.authorName,lastModifiedByEmail:mt?x.authorEmail:tt.authorEmail||x.authorEmail,authorName:x.authorName,authorEmail:x.authorEmail,createdAt:we,lastModifiedAt:F,copyrightStartYear:at,companyName:x.companyName,currentYear:E}),"renderHeader"),ht=pt(ct),gt=ge(S,ht,h,J),Er=ft.edited&&B!==null&&K!==null&&B.timestamp<K.timestamp,yt=gt.changed||Er,be=yt&&!(dt&&B!==null),xt=be?g(y(fe(new Date))):ct,Sr=be?"current-time-on-change":wr,$r=be?pt(xt):ht,j=yt?ge(S,$r,h,J):gt,re={file:A,changed:j.changed};if(c){let F=Xn(v,{gitCreated:ot,gitLastModified:K,filesystemCreated:it},{strictCreatedDate:t.strictCreatedDate===!0}),q=F.filter(z=>z.advisory).length;re.dateIssues=F,V+=q,Y+=F.length>q?1:0}if(t.sampleOutput===!0&&j.changed){let F=v.length>0?v.trimEnd():null,q=A.replace(/\\/g,"/"),z=j.written,Cr=j.nextContent.slice(0,j.nextContent.indexOf(z)).split(`
37
- `).length-1;re.sample={previousValue:F,newValue:z,diff:lr(F,z,{fromFile:`a/${q}`,toFile:`b/${q}`,lineOffset:Cr}),issues:rr(F,z),detectedValues:{projectName:x.projectName,projectNameSource:x.projectNameSource,language:x.language,projectRoot:x.projectRoot,marker:x.marker,authorName:x.authorName,authorEmail:x.authorEmail,companyName:x.companyName,companyNameSource:x.companyNameSource,copyrightStartYear:at,copyrightStartYearSource:br,createdAtSource:st,lastModifiedAtSource:Sr,createdAt:we,lastModifiedAt:xt}}}if(j.extraCopyrights.length>0){re.extraCopyrights=j.extraCopyrights;for(let F of j.extraCopyrights)te.push({file:A,copyright:F})}L.push(re),j.changed&&(U+=1,l||await ji(h,j.nextContent,"utf8"))}return{metadata:a,detectedProjects:Array.from(k),filesScanned:b.length-D.length,filesUpdated:U,filesSkipped:D.length,dryRun:l,check:c,...c?{filesWithDateDrift:Y,dateAdvisories:V}:{},copyrightWarnings:te,changes:L,skipped:D}}s(dr,"fixHeaders");function _i(e){return dr(e)}s(_i,"fixHeaders");var fr=_i;var Bi=`fix-headers CLI
38
-
39
- Usage:
40
- fix-headers [options]
41
-
42
- Options:
43
- -h, --help Show help
44
- --dry-run Compute changes without writing files
45
- --check Validate header dates without writing; exit 1 on date drift
46
- --fix-created-date Move an existing @Date back to the oldest of git first commit / file creation
47
- --strict-created-date With --check, fail when @Date is later than git first commit / file creation
48
- --rewrite-declaration-copies [true|false] Restamp .d.ts/.d.mts/.d.cts files carrying tsc's copy of their source's header, keeping its dates (default: true)
49
- --no-rewrite-declaration-copies Skip those declarations and leave tsc's copied header as it is
50
- --strict-header-block [true|false] Move non-field text found in a header to its own block below it (default: true)
51
- --no-strict-header-block Keep non-field text found in a header inside it, after the fields
52
- --normalize-date-format Write every header date in the ISO 8601 T-form (git %aI)
53
- --timezone <name> Write new dates in an IANA time zone (e.g. America/Los_Angeles, UTC); the instant never changes
54
- --convert-timezone With --timezone, also rewrite existing @Date/@Last modified time values into that zone
55
- --json Print JSON output
56
- --verbose Print updated file paths in summary mode; with --sample-output or --diff, also print each file's field differences
57
- --sample-output Show previous/new header sample for changed files
58
- --diff Print a unified diff of each changed file's header (implies sample output)
59
- --force-author-update Replace an existing @Author/@Email with the detected/current values
60
- --force-last-modified-author-update Write the detected identity as @Last modified by on every file, edited or not
61
- --use-gpg-signer-author Use signed-commit UID (%GS) for detected @Author
62
- --cwd <path> Working directory for project detection
63
- --input <path> File or folder to process instead of the whole project (repeatable)
64
- --include-folder <path> Include folder (repeatable)
65
- --include-folder-non-recursive <path> Include only a folder's own files, not its subfolders (repeatable)
66
- --exclude-folder <path> Exclude folder name/path (repeatable)
67
- --include-extension <ext> Include extension (repeatable)
68
- --enable-detector <id> Enable only specific detector (repeatable)
69
- --disable-detector <id> Disable detector by id (repeatable)
70
- --force-detector <id> Use a force-only detector, e.g. markdown (HTML-comment headers in .md files) (repeatable)
71
- --project-name <name> Override project name
72
- --language <id> Override language id
73
- --project-root <path> Override project root
74
- --marker <name|null> Override marker filename
75
- --author-name <name> Override author name
76
- --author-email <email> Override author email
77
- --company <name> Append company suffix to @Author (Name <Company>)
78
- --company-name <name> @Copyright holder (default: the project manifest's author; omitted when none)
79
- --copyright-start-year <year> Set the copyright start year (default: each file's @Date year)
80
- --spacing <n> Empty comment lines just inside the header's opening and closing (default: 1)
81
- --margin <n> Blank lines between the header and the file's next content (default: 2)
82
- --config <path> Load JSON options file; its 'extends' can pull in shared configs (URL, package or path)
83
-
84
- Examples:
85
- fix-headers --dry-run --include-folder src
86
- fix-headers --dry-run --diff --verbose
87
- fix-headers --check --verbose
88
- fix-headers --timezone America/Los_Angeles --convert-timezone
89
- fix-headers --project-name @scope/pkg --company-name "Catalyzed Motivation Inc."
90
- `;function zi(e){return e.replace(/-([a-z])/g,(t,n)=>n.toUpperCase())}s(zi,"toCamelCase");function Gi(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==="--rewrite-declaration-copies"){let u=e[i+1];(u==="true"||u==="false")&&(i+=1),t.rewriteDeclarationCopies=u!=="false";continue}if(a==="--no-rewrite-declaration-copies"){t.rewriteDeclarationCopies=!1;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],g=Array.isArray(t[m])?t[m]:[];t[m]=Array.from(new Set([...g,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=zi(c),d=e[i+1];if(!d||d.startsWith("--"))throw new Error(`Unknown or malformed flag: --${c}`);i+=1,t[l]=d}return{options:t,help:n.help,json:n.json,diff:n.diff}}s(Gi,"parseCliArgs");function Yi(e){return oe(e,"config")}s(Yi,"applyConfigFile");function Ze(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(Ze,"getSampledChanges");function pr(e){return typeof e=="string"?`"${e}"`:"(missing)"}s(pr,"formatIssueValue");function Vi(e,t){for(let n of Ze(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 ${pr(o?.previous)}, expected ${pr(o?.detected)}`)}}s(Vi,"printIssues");function Ji(e,t){for(let n of Ze(t))typeof n.sample.diff=="string"&&n.sample.diff.length>0&&e(n.sample.diff)}s(Ji,"printDiffs");function Ki(e,t){for(let n of Ze(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(Ki,"printSampleOutput");function qi(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(qi,"printChangedFiles");function hr(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(hr,"printCopyrightWarnings");function Xi(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(Xi,"printSkipped");function gr(e,t,n,r){let o=n.sampleOutput===!0||r;n.verbose===!0&&(qi(e,t),o&&Vi(e,t)),n.sampleOutput===!0&&Ki(e,t),r&&Ji(e,t)}s(gr,"printDetails");function Zi(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(Zi,"printDateIssues");async function Qi(e,t={}){let n=t.runner||fr,r=t.stdout||console.log,o=t.stderr||console.error;try{let i=Gi(e);if(i.help)return r(Bi),0;let a=await Yi(i.options),c=await n(i.diff?{...a,sampleOutput:!0}:a),l=c&&typeof c=="object"&&c.check===!0?c:null,d=l&&Number(l.filesWithDateDrift)>0?1:0;if(i.json)return r(JSON.stringify(c,null,2)),d;if(l)return r(`fix-headers check: scanned=${l.filesScanned??0}, drift=${l.filesWithDateDrift??0}, advisories=${l.dateAdvisories??0}`),Zi(r,l,a.verbose===!0),hr(r,c),d;if(c&&typeof c=="object"){let u=c,m=Number(u.filesSkipped)>0?`, skipped=${u.filesSkipped}`:"",g=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}${g}, dryRun=${u.dryRun===!0}`),Xi(r,u),hr(r,u),gr(r,c,a,i.diff)}else gr(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(Qi,"runCli");function es(e=process.argv,t=import.meta.url,n=Qi){let r=!1;if(e[1])try{let o=mr(e[1]),i=mr(Ui(t));r=o===i}catch{r=t===Wi(e[1]).href}return r?(n(e.slice(2)).then(o=>{process.exitCode=o}),!0):!1}s(es,"runCliAsMain");es();export{Yi as applyConfigFile,Gi as parseCliArgs,Qi as runCli,es as runCliAsMain};
91
- //# sourceMappingURL=fix-headers.mjs.map
@@ -1 +0,0 @@
1
- export {};
package/types/index.d.mts DELETED
@@ -1,2 +0,0 @@
1
- export * from "./src/index.mjs";
2
- export { default } from "./src/index.mjs";