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