@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/dist/index.mjs
CHANGED
|
@@ -1,25 +1,33 @@
|
|
|
1
|
-
var Ur=Object.defineProperty;var i=(e,t)=>Ur(e,"name",{value:t,configurable:!0});import{readFile as _o,stat as Oo,writeFile as Bo}from"node:fs/promises";import{relative as Ie,resolve as Lr}from"node:path";import{readFile as zr}from"node:fs/promises";import{createRequire as Yr}from"node:module";import{dirname as Gr,isAbsolute as Wr,resolve as et}from"node:path";var Vr=3e4,Jr=new Set(["localhost","127.0.0.1","[::1]"]);function le(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}i(le,"isPlainObject");function ue(e,t){let r={...e};for(let[n,o]of Object.entries(t))n!=="__proto__"&&(r[n]=le(r[n])&&le(o)?ue(r[n],o):o);return r}i(ue,"mergeConfig");function tt(e){return e.kind==="file"?e.path:e.href}i(tt,"describeSource");async function qr(e){if(e.kind==="file")return{text:await zr(e.path,"utf8"),source:e};let t;try{t=await fetch(e.href,{cache:"no-store",redirect:"follow",signal:AbortSignal.timeout(Vr)})}catch(r){let n=r.cause instanceof Error?r.cause.message:r.message;throw new Error(`Failed to fetch config ${e.href}: ${n}`,{cause:r})}if(!t.ok)throw new Error(`Failed to fetch config ${e.href}: HTTP ${t.status} ${t.statusText}`);return{text:await t.text(),source:{kind:"url",href:t.url}}}i(qr,"readSource");function Qe(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}}i(Qe,"toUrlSource");function Kr(e,t){if(/^https?:\/\//i.test(e))return Qe(new URL(e));if(/^[a-z][a-z\d+.-]+:\/\//i.test(e))throw new Error(`Unsupported extends URL "${e}" in ${tt(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 Qe(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||Wr(e))return{kind:"file",path:et(Gr(t.path),e)};try{return{kind:"file",path:Yr(t.path).resolve(e)}}catch(n){throw new Error(`Cannot resolve extends "${e}" from ${t.path}: ${n.message}`,{cause:n})}}i(Kr,"resolveReference");function Xr(e,t){if(e===void 0)return[];let r=Array.isArray(e)?e:[e];if(!r.every(n=>typeof n=="string"&&n.trim().length>0))throw new Error(`Config "extends" must be a string or an array of strings: ${t}`);return r.map(n=>n.trim())}i(Xr,"readExtends");async function rt(e,t){let r=tt(e);if(t.includes(r))throw new Error(`Config extends cycle: ${[...t,r].join(" -> ")}`);let{text:n,source:o}=await qr(e),s;try{s=JSON.parse(n)}catch(u){throw new Error(`Config ${r} is not valid JSON: ${u.message}`,{cause:u})}if(!le(s))throw new Error(`Config file must contain a JSON object: ${r}`);let{extends:a,...c}=s,l={};for(let u of Xr(a,r))l=ue(l,await rt(Kr(u,o),[...t,r]));return ue(l,c)}i(rt,"loadSource");function Zr(e,t=process.cwd()){return rt({kind:"file",path:et(t,e)},[])}i(Zr,"loadConfigFile");async function nt(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 Zr(r,n),...e};return delete o[t],o}i(nt,"applyConfigOption");import{extname as de}from"node:path";import{extname as Qr}from"node:path";var ot=[".css"];function en(e){let t=Qr(e).toLowerCase();return ot.includes(t)?{kind:"block",blockStart:"/*",blockLinePrefix:" * ",blockEnd:" */"}:null}i(en,"resolveCssCommentSyntax");var it={id:"css",extensions:ot,enabledByDefault:!0,resolveCommentSyntax(e){return en(e)}};import{extname as tn}from"node:path";var st=[".go"];function rn(e){let t=tn(e).toLowerCase();return st.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}i(rn,"resolveGoCommentSyntax");var at={id:"go",extensions:st,enabledByDefault:!0,resolveCommentSyntax(e){return rn(e)}};import{extname as nn}from"node:path";var ct=[".html",".htm"];function on(e){let t=nn(e).toLowerCase();return ct.includes(t)?{kind:"html",blockStart:"<!--",blockLinePrefix:" ",blockEnd:"-->"}:null}i(on,"resolveHtmlCommentSyntax");var lt={id:"html",extensions:ct,enabledByDefault:!0,resolveCommentSyntax(e){return on(e)}};import{extname as sn}from"node:path";var ut=[".jsonv",".jsonc",".json5"];function an(e){let t=sn(e).toLowerCase();return ut.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}i(an,"resolveJsonCommentSyntax");var dt={id:"json",extensions:ut,enabledByDefault:!0,resolveCommentSyntax(e){return an(e)}};import{extname as cn}from"node:path";var ft=[".md",".markdown"];function ln(e){let t=cn(e).toLowerCase();return ft.includes(t)?{kind:"html",blockStart:"<!--",blockLinePrefix:" ",blockEnd:"-->"}:null}i(ln,"resolveMarkdownCommentSyntax");function un(e,t){let r=t.match(/^---\r?\n[\s\S]*?\r?\n---[ \t]*(?:\r?\n|$)/);return r?r[0]:""}i(un,"resolveMarkdownPreservedPrefix");var mt={id:"markdown",extensions:ft,enabledByDefault:!1,requiresForce:!0,resolvePreservedPrefix(e,t){return un(e,t)},resolveCommentSyntax(e){return ln(e)}};import{extname as dn}from"node:path";var pt=[".js",".mjs",".cjs",".ts",".tsx",".jsx"];function fn(e){let t=dn(e).toLowerCase();return pt.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}i(fn,"resolveNodeCommentSyntax");function mn(e,t){let r=t.match(/^#!.*\b(node|bun|deno|tsx|ts-node)\b.*(?:\r?\n|$)/);return r?r[0]:""}i(mn,"resolveNodePreservedPrefix");var ht={id:"node",extensions:pt,enabledByDefault:!0,resolvePreservedPrefix(e,t){return mn(e,t)},resolveCommentSyntax(e){return fn(e)}};import{extname as pn}from"node:path";var gt=[".php"];function hn(e){let t=pn(e).toLowerCase();return gt.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}i(hn,"resolvePhpCommentSyntax");var yt={id:"php",extensions:gt,enabledByDefault:!0,resolveCommentSyntax(e){return hn(e)}};import{extname as gn}from"node:path";var xt=[".py"];function yn(e,t){let r=t.match(/^#!.*\bpython(?:\d+(?:\.\d+)*)?\b.*(?:\r?\n|$)/);return r?r[0]:""}i(yn,"resolvePythonPreservedPrefix");var wt={id:"python",extensions:xt,enabledByDefault:!0,resolvePreservedPrefix(e,t){return yn(e,t)},resolveCommentSyntax(e){let t=gn(e).toLowerCase();return xt.includes(t)?{kind:"line",linePrefix:"#"}:null}};import{extname as xn}from"node:path";var bt=[".rs"];function wn(e){let t=xn(e).toLowerCase();return bt.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}i(wn,"resolveRustCommentSyntax");var Et={id:"rust",extensions:bt,enabledByDefault:!0,resolveCommentSyntax(e){return wn(e)}};import{extname as bn}from"node:path";var kt=[".yaml",".yml"];function En(e){let t=bn(e).toLowerCase();return kt.includes(t)?{kind:"line",linePrefix:"#"}:null}i(En,"resolveYamlCommentSyntax");var $t={id:"yaml",extensions:kt,enabledByDefault:!0,resolveCommentSyntax(e){return En(e)}};var Z=[it,at,lt,dt,mt,ht,yt,wt,Et,$t],kn=new Map(Z.map(e=>[e.id,e]));function $n(e,t){return!t||typeof t!="object"?e:e.kind==="line"?{...e,linePrefix:typeof t.linePrefix=="string"&&t.linePrefix.length>0?t.linePrefix:e.linePrefix,lineSeparator:typeof t.lineSeparator=="string"?t.lineSeparator:e.lineSeparator}:{...e,blockStart:typeof t.blockStart=="string"&&t.blockStart.length>0?t.blockStart:e.blockStart,blockLinePrefix:typeof t.blockLinePrefix=="string"&&t.blockLinePrefix.length>0?t.blockLinePrefix:e.blockLinePrefix,blockEnd:typeof t.blockEnd=="string"&&t.blockEnd.length>0?t.blockEnd:e.blockEnd}}i($n,"applySyntaxOverride");function St(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=Z.filter(r=>r.requiresForce===!0).map(r=>r.id);for(let r of e){if(!kn.has(r))throw new Error(`forcedDetectors: unknown detector "${r}" (force-only detectors: ${t.join(", ")})`);if(!t.includes(r))throw new Error(`forcedDetectors: "${r}" does not need forcing (force-only detectors: ${t.join(", ")})`)}return Array.from(new Set(e))}i(St,"resolveForcedDetectors");function P(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 Z.filter(o=>o.requiresForce===!0?n.has(o.id)&&!r.has(o.id):t.size>0?t.has(o.id):r.has(o.id)?!1:o.enabledByDefault)}i(P,"getEnabledDetectors");function Dt(e={}){if(Array.isArray(e.includeExtensions)&&e.includeExtensions.length>0)return new Set(e.includeExtensions.map(r=>r.toLowerCase()));let t=P(e);return new Set(t.flatMap(r=>r.extensions))}i(Dt,"getAllowedExtensions");function At(e,t={}){let r=de(e).toLowerCase();if(P(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:[]),s=Z.find(a=>a.requiresForce===!0&&a.extensions.includes(r)&&!o.has(a.id));return s?`${r} files get a header only when forced (--force-detector ${s.id} / forcedDetectors: ["${s.id}"])`:`no enabled detector handles ${r} files`}i(At,"getHeaderSkipReason");function Nt(e,t={}){let r=de(e).toLowerCase(),n=Array.isArray(t.detectors)?t.detectors:P(t);for(let o of n){if(!o.extensions.includes(r))continue;let s=o.resolveCommentSyntax(e);if(s){let a=t.detectorSyntaxOverrides&&typeof t.detectorSyntaxOverrides=="object"?t.detectorSyntaxOverrides:{};return $n(s,a[o.id])}}return{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}}i(Nt,"getCommentSyntaxForFile");function Ct(e,t,r={}){let n=de(e).toLowerCase(),o=P(r);for(let s of o)if(s.extensions.includes(n))return typeof s.resolvePreservedPrefix=="function"?s.resolvePreservedPrefix(e,t):"";return""}i(Ct,"getPreservedPrefixForFile");var vt=200,V=1,Q=2;function M(e,t,r){if(e==null)return r;if(typeof e!="number"||!Number.isInteger(e)||e<0)throw new Error(`${t} must be a whole number of 0 or more, got ${JSON.stringify(e)}`);return e}i(M,"resolveLayoutCount");import{existsSync as Rn}from"node:fs";import{join as we,relative as Ot,resolve as be,sep as ye}from"node:path";import{realpath as In,stat as Tn}from"node:fs/promises";import{access as Sn,readdir as Dn,readFile as Ji,stat as An}from"node:fs/promises";import{constants as Nn}from"node:fs";import{dirname as Xi,join as Cn,resolve as Zi}from"node:path";async function fe(e){try{return await Sn(e,Nn.F_OK),!0}catch{return!1}}i(fe,"pathExists");async function me(e,t){let r=[],n=await Dn(e,{withFileTypes:!0});for(let o of n){let s=Cn(e,o.name);if(o.isDirectory()&&t.recursive===!1||o.isDirectory()&&t.ignoreFolders.has(o.name)||o.isDirectory()&&await t.shouldSkipDirectory?.(s,o.name)===!0)continue;if(o.isDirectory()){let l=await me(s,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(s)}return r}i(me,"walkFiles");async function Ft(e){let t=await An(e);return{createdAt:t.birthtimeMs>0&&t.birthtime<t.mtime?t.birthtime:t.mtime,updatedAt:t.mtime}}i(Ft,"readFileDates");import{execFile as vn}from"node:child_process";import{lstat as Fn,readFile as Ln}from"node:fs/promises";import{dirname as Lt,isAbsolute as Pn,join as jt,relative as Rt,resolve as pe,sep as It}from"node:path";import Mn from"ignore";function Pt(e,t){return new Promise(r=>{vn("git",t,{cwd:e,encoding:"utf8",maxBuffer:Number.POSITIVE_INFINITY},(n,o)=>{if(!n){r({code:0,stdout:o});return}r({code:typeof n.code=="number"?n.code:-1,stdout:""})})})}i(Pt,"runGitCommand");function ge(e,t){return Rt(e,t).split(It).join("/")}i(ge,"toPosixRelative");async function Tt(e){try{return Mn().add(await Ln(e,"utf8"))}catch{return null}}i(Tt,"readIgnoreFile");async function jn(e){return Fn(jt(e,".git")).then(()=>!0,()=>!1)}i(jn,"hasGitEntry");function Mt(e,t,r){for(let n=e.length-1;n>=0;n--){let{base:o,rules:s}=e[n],a=s.test(`${ge(o,t)}${r?"/":""}`);if(a.ignored||a.unignored)return a.ignored}return!1}i(Mt,"matchesRules");async function Ht(e,t){let r=await Tt(jt(e,".gitignore"));return{kind:"rules",nested:!0,excluded:!1,matchers:r?[...t,{base:e,rules:r}]:t}}i(Ht,"buildRulesContext");async function he(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 s of r.stdout.split("\0")){let a=s.endsWith("/")?s.slice(0,-1):s;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}}i(he,"resolveScopeContext");function _t(e){let t=pe(e.root),r=e.gitignore;if(r===!1)return{isIgnored:i(async()=>!1,"isIgnored")};let n=new Map,o=i(async()=>{if(typeof r!="string"&&!Array.isArray(r))return he(t);let c=typeof r=="string"?[r]:r.filter(u=>typeof u=="string"),l=[];for(let u of c){let f=await Tt(pe(t,u));f&&l.push({base:t,rules:f})}return{kind:"rules",nested:!1,excluded:!1,matchers:l}},"buildRootContext"),s=i(c=>{let l=n.get(c);return l||(l=c===t?o():a(c),n.set(c,l)),l},"contextFor"),a=i(async c=>{let l=await s(Lt(c));return l.kind==="git"?l.entries.has(ge(l.root,c))?he(c):l:!l.nested||l.excluded?l:Mt(l.matchers,c,!0)?{...l,excluded:!0}:await jn(c)?he(c):Ht(c,l.matchers)},"deriveContext");return{async isIgnored(c,l){let u=pe(c),f=Rt(t,u);if(f.length===0||f===".."||f.startsWith(`..${It}`)||Pn(f))return!1;let m=await s(Lt(u));if(m.kind==="git"){let y=ge(m.root,u);return!(m.entries.has(y)||l&&m.dirs.has(y))}return m.excluded||Mt(m.matchers,u,l)}}}i(_t,"createIgnoreFilter");function Hn(e){return Dt(e)}i(Hn,"resolveExtensions");var _n=Object.freeze(["node_modules","bower_components","jspm_packages",".pnpm-store",".yarn"]),zt=new Set([".git",..._n]),On=Object.freeze(["autoload.php","modules.txt"]);function Bt(e,t){return zt.has(t)?!0:t==="vendor"&&On.some(r=>Rn(we(e,r)))}i(Bt,"isNeverWalked");function xe(e){return e.replace(/\\/g,"/").replace(/^\.\//,"").replace(/^\/+/,"").replace(/\/+$/,"")}i(xe,"normalizeFolderPath");function Bn(e){return Array.isArray(e)?e.map(t=>{if(typeof t=="string")return{path:t,recursive:!0};if(t&&typeof t=="object"&&typeof t.path=="string")return{path:t.path,recursive:t.recursive!==!1};throw new TypeError(`Invalid includeFolders entry: ${JSON.stringify(t)} (expected a path string or { path, recursive? })`)}):[]}i(Bn,"resolveIncludeFolders");function Ut(e,t){let r=t instanceof Error?t.message:String(t);console.warn(`fix-headers: skipped include folder "${e}" (${r})`)}i(Ut,"reportSkippedIncludeFolder");function Un(e,t){if(!Array.isArray(t)||t.length===0)return()=>!1;let r=be(e),n=[],o=new Set;for(let s of t){if(typeof s!="string")continue;let a=xe(s);if(a.length!==0){if(a.includes("/")){n.push(be(r,a));continue}o.add(a)}}return(s,a)=>{if(o.has(a))return!0;for(let l of n)if(s===l||s.startsWith(`${l}/`))return!0;let c=xe(Ot(r,s));return n.some(l=>{let u=xe(Ot(r,l));return c===u||c.startsWith(`${u}/`)})}}i(Un,"buildExclusionMatcher");async function Ee(e){let t=Hn(e),r=Bn(e.includeFolders),n=Array.isArray(e.excludeFolders)?e.excludeFolders:[],o=Un(e.projectRoot,n),s=_t({root:e.projectRoot,gitignore:e.gitignore}),a=i(async(d,p)=>Bt(d,p)||o(d,p)||await s.isIgnored(d,!0),"shouldSkipDirectory"),c=r.length>0?r.map(d=>({includeFolder:d.path,rootPath:we(e.projectRoot,d.path),recursive:d.recursive})):[{includeFolder:".",rootPath:e.projectRoot,recursive:!0}],l=[];for(let d of c){let p=await Tn(d.rootPath).catch(b=>b);if(p instanceof Error){if(p.code==="ENOENT"){Ut(d.includeFolder,p);continue}throw p}if(!p.isDirectory()){Ut(d.includeFolder,`path is not a directory: ${d.rootPath}`);continue}let w=await In(d.rootPath).catch(()=>be(d.rootPath));l.push({...d,realRoot:w})}let u=i((d,p)=>{if(d.realRoot===p.realRoot)return d.recursive||!p.recursive;let w=d.realRoot.endsWith(ye)?d.realRoot:`${d.realRoot}${ye}`;if(!d.recursive||!p.realRoot.startsWith(w))return!1;let b=d.rootPath;for(let $ of p.realRoot.slice(w.length).split(ye))if(b=we(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 me(d.rootPath,{allowedExtensions:t,ignoreFolders:zt,shouldSkipDirectory:a,recursive:d.recursive});y.push(...p)}let h=[];for(let d of new Set(y))!o(d,d.split("/").at(-1)||"")&&!await s.isIgnored(d,!1)&&h.push(d);return h}i(Ee,"discoverFiles");import{basename as ho,dirname as go,extname as yo,resolve as Ne}from"node:path";import{dirname as tr,isAbsolute as Qn,join as rr,relative as eo,resolve as nr,sep as to}from"node:path";import{readFile as zn}from"node:fs/promises";import{join as Yn}from"node:path";async function Gn(e){try{return await zn(e,"utf8")}catch{return null}}i(Gn,"readManifest");async function A(e,t){let r=[];for(let n of t){let o=await Gn(Yn(e,n));o!==null&&r.push({file:n,content:o})}return r.length>0?{dir:e,manifest:r[0].file,files:r}:null}i(A,"detectManifests");function j(e,t){return e.files.find(r=>r.file===t)?.content??null}i(j,"manifestContent");function k(e){return typeof e=="string"&&e.trim().length>0?e.trim():void 0}i(k,"cleanName");function ke(e){if(typeof e!="string")return;let t=e.search(/[<(]/);return k(t===-1?e:e.slice(0,t))}i(ke,"personName");function ee(e){try{return JSON.parse(e)}catch{return}}i(ee,"parseJsonManifest");function*$e(e,t){let r="";for(let n of e.split(/\r?\n/)){let o=n.trim();if(o.startsWith("[")){let s=o.match(/^\[([^[\]]+)\]/);r=s?s[1].split(".").map(a=>a.trim()).join("."):"";continue}r===t&&(yield o)}}i($e,"sectionLines");function J(e,t,r){let n=new RegExp(`^${r}\\s*=\\s*(?:"([^"\\\\]*)"|'([^']*)')`);for(let o of $e(e,t)){let s=o.match(n);if(s)return k(s[1]??s[2])}}i(J,"readTomlString");function Se(e,t,r){let n=new RegExp(`^${r}\\s*[=:](.*)$`);for(let o of $e(e,t)){let s=o.match(n);if(s)return k(s[1])}}i(Se,"readIniValue");function Wn(e,t,r){let n=new RegExp(`^${r}\\s*=\\s*\\[`),o=null;for(let s of $e(e,t)){if(o!==null){o.push(s);continue}let a=s.match(n);a&&(o=[s.slice(a[0].length)])}return o===null?null:o.join(`
|
|
2
|
-
`)}i(
|
|
3
|
-
|
|
4
|
-
`)
|
|
5
|
-
|
|
1
|
+
var cn=Object.defineProperty;var i=(e,t)=>cn(e,"name",{value:t,configurable:!0});import{readFile as ii,stat as si,writeFile as ai}from"node:fs/promises";import{relative as Ye,resolve as qr}from"node:path";import{readFile as ln}from"node:fs/promises";import{createRequire as un}from"node:module";import{dirname as dn,isAbsolute as fn,resolve as ut}from"node:path";var mn=3e4,pn=new Set(["localhost","127.0.0.1","[::1]"]);function xe(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}i(xe,"isPlainObject");function we(e,t){let r={...e};for(let[n,o]of Object.entries(t))n!=="__proto__"&&(r[n]=xe(r[n])&&xe(o)?we(r[n],o):o);return r}i(we,"mergeConfig");function dt(e){return e.kind==="file"?e.path:e.href}i(dt,"describeSource");async function hn(e){if(e.kind==="file")return{text:await ln(e.path,"utf8"),source:e};let t;try{t=await fetch(e.href,{cache:"no-store",redirect:"follow",signal:AbortSignal.timeout(mn)})}catch(r){let n=r.cause instanceof Error?r.cause.message:r.message;throw new Error(`Failed to fetch config ${e.href}: ${n}`,{cause:r})}if(!t.ok)throw new Error(`Failed to fetch config ${e.href}: HTTP ${t.status} ${t.statusText}`);return{text:await t.text(),source:{kind:"url",href:t.url}}}i(hn,"readSource");function lt(e){if(e.protocol==="http:"&&!pn.has(e.hostname))throw new Error(`Refusing to fetch config over plain http: ${e.href} (use https)`);return{kind:"url",href:e.href}}i(lt,"toUrlSource");function gn(e,t){if(/^https?:\/\//i.test(e))return lt(new URL(e));if(/^[a-z][a-z\d+.-]+:\/\//i.test(e))throw new Error(`Unsupported extends URL "${e}" in ${dt(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 lt(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||fn(e))return{kind:"file",path:ut(dn(t.path),e)};try{return{kind:"file",path:un(t.path).resolve(e)}}catch(n){throw new Error(`Cannot resolve extends "${e}" from ${t.path}: ${n.message}`,{cause:n})}}i(gn,"resolveReference");function yn(e,t){if(e===void 0)return[];let r=Array.isArray(e)?e:[e];if(!r.every(n=>typeof n=="string"&&n.trim().length>0))throw new Error(`Config "extends" must be a string or an array of strings: ${t}`);return r.map(n=>n.trim())}i(yn,"readExtends");async function ft(e,t){let r=dt(e);if(t.includes(r))throw new Error(`Config extends cycle: ${[...t,r].join(" -> ")}`);let{text:n,source:o}=await hn(e),s;try{s=JSON.parse(n)}catch(u){throw new Error(`Config ${r} is not valid JSON: ${u.message}`,{cause:u})}if(!xe(s))throw new Error(`Config file must contain a JSON object: ${r}`);let{extends:a,...c}=s,l={};for(let u of yn(a,r))l=we(l,await ft(gn(u,o),[...t,r]));return we(l,c)}i(ft,"loadSource");function xn(e,t=process.cwd()){return ft({kind:"file",path:ut(t,e)},[])}i(xn,"loadConfigFile");async function mt(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 xn(r,n),...e};return delete o[t],o}i(mt,"applyConfigOption");import{extname as be}from"node:path";import{extname as wn}from"node:path";var pt=[".css"];function bn(e){let t=wn(e).toLowerCase();return pt.includes(t)?{kind:"block",blockStart:"/*",blockLinePrefix:" * ",blockEnd:" */"}:null}i(bn,"resolveCssCommentSyntax");var ht={id:"css",extensions:pt,enabledByDefault:!0,keepsAboveHeader:i((e,t)=>t===0&&/^@charset "[^"]*";/.test(e),"keepsAboveHeader"),resolveCommentSyntax(e){return bn(e)}};import{extname as Sn}from"node:path";var En=/^(?:#|\/\/|\/\*+|<!--)[ \t]+(vi|vim(?:[<=>]?\d+)?|Vim|ex):(.*)$/,kn=/^[a-z]+(?:[!&]|[+^-]?=(?:\\.|[^\s:\\])*)?$/,$n=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 ne(e){let t=e.match(En);if(!t)return!1;let r=t[2].trim();if(r.endsWith("-->"))r=r.slice(0,-3).trimEnd();else if(r.endsWith("*/")){let s=r.length-2;for(;s>0&&r[s-1]==="*";)s-=1;r=r.slice(0,s).trimEnd()}let n=r.match(/^se(?:t)?[ \t]((?:\\.|[^:\\])*):/);if(!n&&t[1]==="Vim")return!1;let o=n?n[1].match(/(?:\\.|[^\s\\])+/g):r.match(/(?:\\.|[^\s:\\])+/g);return o!==null&&o.every(s=>kn.test(s))&&o.some(s=>s.includes("=")||$n.has(s))}i(ne,"isModeline");function oe(e,t){return t===0&&e.startsWith("#!")}i(oe,"isShebang");function ie(e,t,r=0){let n=0,o=r;for(;n<e.length;){let s=e.indexOf(`
|
|
2
|
+
`,n),a=s===-1?e.length:s+1;if(!t(e.slice(n,a).replace(/\r?\n$/,""),o))break;n=a,o+=1}return e.slice(0,n)}i(ie,"takeTopLines");var yt=[".go"];function Dn(e){let t=Sn(e).toLowerCase();return yt.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}i(Dn,"resolveGoCommentSyntax");var gt=/^\/\/(?:go:build|\s*\+build)\s/;function An(e,t){let r=ie(t,o=>gt.test(o)||ne(o));if(!r.split(/\r?\n/).some(o=>gt.test(o)))return"";let n=t.slice(r.length);return`${r}${n.slice(0,n.length-n.replace(/^(?:[ \t]*\r?\n)*/,"").length)}`}i(An,"resolveGoPreservedPrefix");var xt={id:"go",extensions:yt,enabledByDefault:!0,resolvePreservedPrefix(e,t){return An(e,t)},resolveCommentSyntax(e){return Dn(e)}};import{extname as Cn}from"node:path";var wt=[".html",".htm"];function Fn(e){let t=Cn(e).toLowerCase();return wt.includes(t)?{kind:"html",blockStart:"<!--",blockLinePrefix:" ",blockEnd:"-->"}:null}i(Fn,"resolveHtmlCommentSyntax");var bt={id:"html",extensions:wt,enabledByDefault:!0,resolveCommentSyntax(e){return Fn(e)}};import{extname as Nn}from"node:path";var Et=[".jsonv",".jsonc",".json5"];function vn(e){let t=Nn(e).toLowerCase();return Et.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}i(vn,"resolveJsonCommentSyntax");var kt={id:"json",extensions:Et,enabledByDefault:!0,resolveCommentSyntax(e){return vn(e)}};import{extname as Ln}from"node:path";var $t=[".md",".markdown"];function Mn(e){let t=Ln(e).toLowerCase();return $t.includes(t)?{kind:"html",blockStart:"<!--",blockLinePrefix:" ",blockEnd:"-->"}:null}i(Mn,"resolveMarkdownCommentSyntax");function Rn(e,t){let r=t.match(/^---\r?\n[\s\S]*?\r?\n---[ \t]*(?:\r?\n|$)/);return r?r[0]:""}i(Rn,"resolveMarkdownPreservedPrefix");var St={id:"markdown",extensions:$t,enabledByDefault:!1,requiresForce:!0,resolvePreservedPrefix(e,t){return Rn(e,t)},resolveCommentSyntax(e){return Mn(e)}};import{extname as jn}from"node:path";var Dt=[".js",".mjs",".cjs",".ts",".tsx",".jsx"];function Pn(e){let t=jn(e).toLowerCase();return Dt.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}i(Pn,"resolveNodeCommentSyntax");var At={id:"node",extensions:Dt,enabledByDefault:!0,keepsAboveHeader:oe,resolveCommentSyntax(e){return Pn(e)}};import{extname as In}from"node:path";var Ft=[".php"];function Tn(e){let t=In(e).toLowerCase();return Ft.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}i(Tn,"resolvePhpCommentSyntax");var Ct=/^<\?php(?:\s|$)/i,Nt={id:"php",extensions:Ft,enabledByDefault:!0,keepsAboveHeader:i((e,t)=>t===0&&Ct.test(e),"keepsAboveHeader"),resolveContentSkipReason(e){return Ct.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 Tn(e)}};import{extname as On}from"node:path";var vt=[".py"],Hn=/^#.*?(?<![A-Za-z])coding[:=]\s*[-\w.]+/;function _n(e,t){return oe(e,t)||t<=1&&Hn.test(e)}i(_n,"keepsAboveHeader");var Lt={id:"python",extensions:vt,enabledByDefault:!0,keepsAboveHeader:_n,resolveCommentSyntax(e){let t=On(e).toLowerCase();return vt.includes(t)?{kind:"line",linePrefix:"#"}:null}};import{extname as Bn}from"node:path";var Mt=[".rs"];function Un(e){let t=Bn(e).toLowerCase();return Mt.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}i(Un,"resolveRustCommentSyntax");var Rt={id:"rust",extensions:Mt,enabledByDefault:!0,keepsAboveHeader:i((e,t)=>t===0&&e.startsWith("#!")&&!/^#!\s*\[/.test(e),"keepsAboveHeader"),resolveCommentSyntax(e){return Un(e)}};import{extname as zn}from"node:path";var jt=[".yaml",".yml"];function Wn(e){let t=zn(e).toLowerCase();return jt.includes(t)?{kind:"line",linePrefix:"#"}:null}i(Wn,"resolveYamlCommentSyntax");var Pt={id:"yaml",extensions:jt,enabledByDefault:!0,keepsAboveHeader:i((e,t)=>t===0&&/^#cloud-config\s*$/.test(e),"keepsAboveHeader"),resolveCommentSyntax(e){return Wn(e)}};var se=[ht,xt,bt,kt,St,At,Nt,Lt,Rt,Pt],Gn=new Map(se.map(e=>[e.id,e]));function Yn(e,t){return!t||typeof t!="object"?e:e.kind==="line"?{...e,linePrefix:typeof t.linePrefix=="string"&&t.linePrefix.length>0?t.linePrefix:e.linePrefix,lineSeparator:typeof t.lineSeparator=="string"?t.lineSeparator:e.lineSeparator}:{...e,blockStart:typeof t.blockStart=="string"&&t.blockStart.length>0?t.blockStart:e.blockStart,blockLinePrefix:typeof t.blockLinePrefix=="string"&&t.blockLinePrefix.length>0?t.blockLinePrefix:e.blockLinePrefix,blockEnd:typeof t.blockEnd=="string"&&t.blockEnd.length>0?t.blockEnd:e.blockEnd}}i(Yn,"applySyntaxOverride");function It(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=se.filter(r=>r.requiresForce===!0).map(r=>r.id);for(let r of e){if(!Gn.has(r))throw new Error(`forcedDetectors: unknown detector "${r}" (force-only detectors: ${t.join(", ")})`);if(!t.includes(r))throw new Error(`forcedDetectors: "${r}" does not need forcing (force-only detectors: ${t.join(", ")})`)}return Array.from(new Set(e))}i(It,"resolveForcedDetectors");function T(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 se.filter(o=>o.requiresForce===!0?n.has(o.id)&&!r.has(o.id):t.size>0?t.has(o.id):r.has(o.id)?!1:o.enabledByDefault)}i(T,"getEnabledDetectors");function Tt(e={}){if(Array.isArray(e.includeExtensions)&&e.includeExtensions.length>0)return new Set(e.includeExtensions.map(r=>r.toLowerCase()));let t=T(e);return new Set(t.flatMap(r=>r.extensions))}i(Tt,"getAllowedExtensions");function Ot(e,t={}){let r=be(e).toLowerCase();if(T(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:[]),s=se.find(a=>a.requiresForce===!0&&a.extensions.includes(r)&&!o.has(a.id));return s?`${r} files get a header only when forced (--force-detector ${s.id} / forcedDetectors: ["${s.id}"])`:`no enabled detector handles ${r} files`}i(Ot,"getHeaderSkipReason");function Ht(e,t={}){let r=be(e).toLowerCase(),n=Array.isArray(t.detectors)?t.detectors:T(t);for(let o of n){if(!o.extensions.includes(r))continue;let s=o.resolveCommentSyntax(e);if(s){let a=t.detectorSyntaxOverrides&&typeof t.detectorSyntaxOverrides=="object"?t.detectorSyntaxOverrides:{};return Yn(s,a[o.id])}}return{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}}i(Ht,"getCommentSyntaxForFile");function _t(e,t){let r=be(e).toLowerCase();return T(t).find(n=>n.extensions.includes(r))}i(_t,"detectorForFile");function ae(e,t,r={}){let n=_t(e,r);if(!n)return"";let o=typeof n.resolvePreservedPrefix=="function"?n.resolvePreservedPrefix(e,t):"",s=n.keepsAboveHeader,a=ie(t.slice(o.length),(c,l)=>ne(c)||typeof s=="function"&&s(c,l),o.split(`
|
|
3
|
+
`).length-1);return`${o}${a}`}i(ae,"getPreservedPrefixForFile");function Bt(e,t,r={}){let n=_t(e,r);return n&&typeof n.resolveContentSkipReason=="function"?n.resolveContentSkipReason(t):null}i(Bt,"getContentSkipReason");var Ut=200,Z=1,ce=2;function O(e,t,r){if(e==null)return r;if(typeof e!="number"||!Number.isInteger(e)||e<0)throw new Error(`${t} must be a whole number of 0 or more, got ${JSON.stringify(e)}`);return e}i(O,"resolveLayoutCount");import{existsSync as oo}from"node:fs";import{join as Fe,relative as tr,resolve as Ne,sep as Ae}from"node:path";import{realpath as io,stat as so}from"node:fs/promises";import{access as Vn,readdir as Jn,readFile as bs,stat as qn}from"node:fs/promises";import{constants as Kn}from"node:fs";import{dirname as $s,join as Zn,resolve as Ss}from"node:path";async function Ee(e){try{return await Vn(e,Kn.F_OK),!0}catch{return!1}}i(Ee,"pathExists");async function ke(e,t){let r=[],n=await Jn(e,{withFileTypes:!0});for(let o of n){let s=Zn(e,o.name);if(o.isDirectory()&&t.recursive===!1||o.isDirectory()&&t.ignoreFolders.has(o.name)||o.isDirectory()&&await t.shouldSkipDirectory?.(s,o.name)===!0)continue;if(o.isDirectory()){let l=await ke(s,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(s)}return r}i(ke,"walkFiles");async function zt(e){let t=await qn(e);return{createdAt:t.birthtimeMs>0&&t.birthtime<t.mtime?t.birthtime:t.mtime,updatedAt:t.mtime}}i(zt,"readFileDates");function Wt(e){let t=e.indexOf("<");for(;t!==-1;){let r=e.indexOf(">",t+1);if(r===-1)return!1;if(r>t+1)return!0;t=e.indexOf("<",r+1)}return!1}i(Wt,"hasAngleTag");function Gt(e){let t=e.length;for(;t>0&&e[t-1]==="/";)t-=1;return e.slice(0,t)}i(Gt,"trimTrailingSlashes");import{execFile as Xn}from"node:child_process";import{lstat as Qn,readFile as eo}from"node:fs/promises";import{dirname as Yt,isAbsolute as to,join as qt,relative as Kt,resolve as $e,sep as Zt}from"node:path";import ro from"ignore";function Vt(e,t){return new Promise(r=>{Xn("git",t,{cwd:e,encoding:"utf8",maxBuffer:Number.POSITIVE_INFINITY},(n,o)=>{if(!n){r({code:0,stdout:o});return}r({code:typeof n.code=="number"?n.code:-1,stdout:""})})})}i(Vt,"runGitCommand");function De(e,t){return Kt(e,t).split(Zt).join("/")}i(De,"toPosixRelative");async function Xt(e){try{return ro().add(await eo(e,"utf8"))}catch{return null}}i(Xt,"readIgnoreFile");async function no(e){return Qn(qt(e,".git")).then(()=>!0,()=>!1)}i(no,"hasGitEntry");function Jt(e,t,r){for(let n=e.length-1;n>=0;n--){let{base:o,rules:s}=e[n],a=s.test(`${De(o,t)}${r?"/":""}`);if(a.ignored||a.unignored)return a.ignored}return!1}i(Jt,"matchesRules");async function Qt(e,t){let r=await Xt(qt(e,".gitignore"));return{kind:"rules",nested:!0,excluded:!1,matchers:r?[...t,{base:e,rules:r}]:t}}i(Qt,"buildRulesContext");async function Se(e){let[t,r]=await Promise.all([Vt(e,["check-ignore","-q","."]),Vt(e,["ls-files","--cached","--others","--exclude-standard","-z"])]);if(t.code!==1||r.code!==0)return Qt(e,[]);let n=new Set,o=new Set;for(let s of r.stdout.split("\0")){let a=s.endsWith("/")?s.slice(0,-1):s;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}}i(Se,"resolveScopeContext");function er(e){let t=$e(e.root),r=e.gitignore;if(r===!1)return{isIgnored:i(async()=>!1,"isIgnored")};let n=new Map,o=i(async()=>{if(typeof r!="string"&&!Array.isArray(r))return Se(t);let c=typeof r=="string"?[r]:r.filter(u=>typeof u=="string"),l=[];for(let u of c){let f=await Xt($e(t,u));f&&l.push({base:t,rules:f})}return{kind:"rules",nested:!1,excluded:!1,matchers:l}},"buildRootContext"),s=i(c=>{let l=n.get(c);return l||(l=c===t?o():a(c),n.set(c,l)),l},"contextFor"),a=i(async c=>{let l=await s(Yt(c));return l.kind==="git"?l.entries.has(De(l.root,c))?Se(c):l:!l.nested||l.excluded?l:Jt(l.matchers,c,!0)?{...l,excluded:!0}:await no(c)?Se(c):Qt(c,l.matchers)},"deriveContext");return{async isIgnored(c,l){let u=$e(c),f=Kt(t,u);if(f.length===0||f===".."||f.startsWith(`..${Zt}`)||to(f))return!1;let p=await s(Yt(u));if(p.kind==="git"){let y=De(p.root,u);return!(p.entries.has(y)||l&&p.dirs.has(y))}return p.excluded||Jt(p.matchers,u,l)}}}i(er,"createIgnoreFilter");function ao(e){return Tt(e)}i(ao,"resolveExtensions");var co=Object.freeze(["node_modules","bower_components","jspm_packages",".pnpm-store",".yarn"]),or=new Set([".git",...co]),lo=Object.freeze(["autoload.php","modules.txt"]);function rr(e,t){return or.has(t)?!0:t==="vendor"&&lo.some(r=>oo(Fe(e,r)))}i(rr,"isNeverWalked");function Ce(e){return Gt(e.replace(/\\/g,"/").replace(/^\.\//,"").replace(/^\/+/,""))}i(Ce,"normalizeFolderPath");function uo(e){return Array.isArray(e)?e.map(t=>{if(typeof t=="string")return{path:t,recursive:!0};if(t&&typeof t=="object"&&typeof t.path=="string")return{path:t.path,recursive:t.recursive!==!1};throw new TypeError(`Invalid includeFolders entry: ${JSON.stringify(t)} (expected a path string or { path, recursive? })`)}):[]}i(uo,"resolveIncludeFolders");function nr(e,t){let r=t instanceof Error?t.message:String(t);console.warn(`fix-headers: skipped include folder "${e}" (${r})`)}i(nr,"reportSkippedIncludeFolder");function fo(e,t){if(!Array.isArray(t)||t.length===0)return()=>!1;let r=Ne(e),n=[],o=new Set;for(let s of t){if(typeof s!="string")continue;let a=Ce(s);if(a.length!==0){if(a.includes("/")){n.push(Ne(r,a));continue}o.add(a)}}return(s,a)=>{if(o.has(a))return!0;for(let l of n)if(s===l||s.startsWith(`${l}/`))return!0;let c=Ce(tr(r,s));return n.some(l=>{let u=Ce(tr(r,l));return c===u||c.startsWith(`${u}/`)})}}i(fo,"buildExclusionMatcher");async function ve(e){let t=ao(e),r=uo(e.includeFolders),n=Array.isArray(e.excludeFolders)?e.excludeFolders:[],o=fo(e.projectRoot,n),s=er({root:e.projectRoot,gitignore:e.gitignore}),a=i(async(d,m)=>rr(d,m)||o(d,m)||await s.isIgnored(d,!0),"shouldSkipDirectory"),c=r.length>0?r.map(d=>({includeFolder:d.path,rootPath:Fe(e.projectRoot,d.path),recursive:d.recursive})):[{includeFolder:".",rootPath:e.projectRoot,recursive:!0}],l=[];for(let d of c){let m=await so(d.rootPath).catch(b=>b);if(m instanceof Error){if(m.code==="ENOENT"){nr(d.includeFolder,m);continue}throw m}if(!m.isDirectory()){nr(d.includeFolder,`path is not a directory: ${d.rootPath}`);continue}let w=await io(d.rootPath).catch(()=>Ne(d.rootPath));l.push({...d,realRoot:w})}let u=i((d,m)=>{if(d.realRoot===m.realRoot)return d.recursive||!m.recursive;let w=d.realRoot.endsWith(Ae)?d.realRoot:`${d.realRoot}${Ae}`;if(!d.recursive||!m.realRoot.startsWith(w))return!1;let b=d.rootPath;for(let $ of m.realRoot.slice(w.length).split(Ae))if(b=Fe(b,$),rr(b,$)||o(b,$))return!1;return!0},"covers"),f=[...l].sort((d,m)=>d.realRoot.length-m.realRoot.length||Number(m.recursive)-Number(d.recursive)),p=[];for(let d of f)p.some(m=>u(m,d))||p.push(d);let y=[];for(let d of l){if(!p.includes(d))continue;let m=await ke(d.rootPath,{allowedExtensions:t,ignoreFolders:or,shouldSkipDirectory:a,recursive:d.recursive});y.push(...m)}let g=[];for(let d of new Set(y))!o(d,d.split("/").at(-1)||"")&&!await s.isIgnored(d,!1)&&g.push(d);return g}i(ve,"discoverFiles");import{basename as Oo,dirname as Ho,extname as _o,resolve as Ie}from"node:path";import{dirname as gr,isAbsolute as $o,join as yr,relative as So,resolve as xr,sep as Do}from"node:path";import{readFile as mo}from"node:fs/promises";import{join as po}from"node:path";async function ho(e){try{return await mo(e,"utf8")}catch{return null}}i(ho,"readManifest");async function M(e,t){let r=[];for(let n of t){let o=await ho(po(e,n));o!==null&&r.push({file:n,content:o})}return r.length>0?{dir:e,manifest:r[0].file,files:r}:null}i(M,"detectManifests");function H(e,t){return e.files.find(r=>r.file===t)?.content??null}i(H,"manifestContent");function A(e){return typeof e=="string"&&e.trim().length>0?e.trim():void 0}i(A,"cleanName");function Le(e){if(typeof e!="string")return;let t=e.search(/[<(]/);return A(t===-1?e:e.slice(0,t))}i(Le,"personName");function le(e){try{return JSON.parse(e)}catch{return}}i(le,"parseJsonManifest");function*Me(e,t){let r="";for(let n of e.split(/\r?\n/)){let o=n.trim();if(o.startsWith("[")){let s=o.match(/^\[([^[\]]+)\]/);r=s?s[1].split(".").map(a=>a.trim()).join("."):"";continue}r===t&&(yield o)}}i(Me,"sectionLines");function X(e,t,r){let n=new RegExp(`^${r}\\s*=\\s*(?:"([^"\\\\]*)"|'([^']*)')`);for(let o of Me(e,t)){let s=o.match(n);if(s)return A(s[1]??s[2])}}i(X,"readTomlString");function Re(e,t,r){let n=new RegExp(`^${r}\\s*[=:](.*)$`);for(let o of Me(e,t)){let s=o.match(n);if(s)return A(s[1])}}i(Re,"readIniValue");function go(e,t,r){let n=new RegExp(`^${r}\\s*=\\s*\\[`),o=null;for(let s of Me(e,t)){if(o!==null){o.push(s);continue}let a=s.match(n);a&&(o=[s.slice(a[0].length)])}return o===null?null:o.join(`
|
|
4
|
+
`)}i(go,"tomlArrayText");function yo(e,t){let r=t;for(;r<e.length;)if(e[r]==="#"){let n=e.indexOf(`
|
|
5
|
+
`,r);r=n===-1?e.length:n+1}else if(/\s/.test(e[r]))r+=1;else break;return r}i(yo,"skipTomlSpace");function Q(e,t){let r=go(e,t,"authors");if(r===null)return;let n=r.slice(yo(r,0)),o=n.match(/^(?:"([^"\\\n]*)"|'([^'\n]*)')/);if(o)return Le(o[1]??o[2]);let a=n.match(/^\{([^}\n]*)\}/)?.[1].match(/(?:^|,)\s*name\s*=\s*(?:"([^"\\\n]*)"|'([^'\n]*)')/);return a?A(a[1]??a[2]):void 0}i(Q,"readTomlAuthor");var ir=["go.mod"];function xo(e){let t=e.match(/^\s*module\s+(.+)$/m);if(t)return A(t[1].replace(/\/\/.*$/,"").trim().replace(/^["`](.*)["`]$/,"$1"))}i(xo,"readModulePath");var sr={id:"go",languages:["go"],manifests:ir,detect(e){return M(e,ir)},read(e){return{name:xo(e.files[0].content)}}};var ar=["package.json"];function wo(e){let t=A(e?.name),r=A(e?.publisher),n=typeof e?.engines?.vscode=="string";return t&&r&&n?`${r}.${t}`:t}i(wo,"readPublishedName");function bo(e){if(e!==null&&typeof e=="object"){let t=e;return A(t.company)??A(t.name)}return Le(e)}i(bo,"readAuthorCompany");var cr={id:"node",languages:["node"],manifests:ar,detect(e){return M(e,ar)},read(e){let t=le(e.files[0].content);return{name:wo(t),company:bo(t?.author)}}};var lr=["composer.json"],ur={id:"php",languages:["php"],manifests:lr,detect(e){return M(e,lr)},read(e){let t=le(e.files[0].content),r=t?.authors;return{name:A(t?.name),company:Array.isArray(r)?A(r[0]?.name):void 0}}};var dr=["pyproject.toml","setup.cfg","setup.py"];function fr(e,t){let r=e.indexOf("setup(");if(r===-1)return;let n=e.slice(r).match(new RegExp(`\\b${t}\\s*=\\s*(["'])([^"'\\n]+)\\1`));return n&&n[2].trim()||void 0}i(fr,"readSetupPyArgument");function Eo(e){let t=H(e,"pyproject.toml"),r=H(e,"setup.cfg"),n=H(e,"setup.py");return(t===null?void 0:X(t,"project","name")??X(t,"tool.poetry","name"))??(r===null?void 0:Re(r,"metadata","name"))??(n===null?void 0:fr(n,"name"))}i(Eo,"readPythonName");function ko(e){let t=H(e,"pyproject.toml"),r=H(e,"setup.cfg"),n=H(e,"setup.py");return(t===null?void 0:Q(t,"project")??Q(t,"tool.poetry"))??(r===null?void 0:Re(r,"metadata","author"))??(n===null?void 0:fr(n,"author"))}i(ko,"readPythonCompany");var mr={id:"python",languages:["python"],manifests:dr,detect(e){return M(e,dr)},read(e){return{name:Eo(e),company:ko(e)}}};var pr=["Cargo.toml"],hr={id:"rust",languages:["rust"],manifests:pr,detect(e){return M(e,pr)},read(e){let t=e.files[0].content;return{name:X(t,"package","name"),company:Q(t,"package")}}};var Ao=[cr,mr,ur,hr,sr],wr=["name","company"];async function je(e,t,r){let o=(await Promise.all(t.map(async a=>({driver:a,detection:await a.detect(e)})))).filter(a=>a.detection!==null),s=o.filter(a=>typeof r=="string"&&a.driver.languages.includes(r));return[...s,...o.filter(a=>!s.includes(a))]}i(je,"claimFolder");function Co(e,t){let r=So(t,e);return r!==""&&r!==".."&&!r.startsWith(`..${Do}`)&&!$o(r)}i(Co,"isStrictlyInside");async function br(e,t={}){let r=Array.isArray(t.drivers)?t.drivers:Ao,n=typeof t.scanRoot=="string"?xr(t.scanRoot):null,o=xr(e),s=await je(o,r,t.language);for(;s.length===0;){if(await Ee(yr(o,".git")))return{root:o,marker:".git",drivers:[],fields:{},sources:{}};let f=gr(o);if(f===o)return null;o=f,s=await je(o,r,t.language)}let a={},c={},l=o,u=s;for(;;){for(let{driver:p,detection:y}of u){let g=p.read(y);for(let d of wr)a[d]===void 0&&g[d]!==void 0&&(a[d]=g[d],c[d]={driver:p.id,manifest:y.manifest,dir:l})}if(wr.every(p=>a[p]!==void 0)||n===null||!Co(l,n)||await Ee(yr(l,".git")))break;l=gr(l),u=await je(l,r,t.language)}return{root:o,marker:s[0].detection.manifest,drivers:s.map(f=>f.driver.id),fields:a,sources:c}}i(br,"resolveManifestProject");import{execFile as Fo}from"node:child_process";import{basename as No,dirname as vo}from"node:path";import{promisify as Lo}from"node:util";var Pe=Lo(Fo);async function v(e,t){try{let{stdout:r}=await Pe("git",t,{cwd:e}),n=r.trim();return n.length>0?n:null}catch{return null}}i(v,"runGit");function Er(e,t){let r=0;for(let n=t-1;n>=0&&e[n]==="\\";n--)r++;return r%2===1}i(Er,"isEscaped");function Mo(e){let t=e.trim();if(!t.endsWith(")")||Er(t,t.length-1))return t;let r=0;for(let n=t.length-1;n>=0;n--){let o=t[n];if(!(o!=="("&&o!==")"||Er(t,n))&&(r+=o===")"?1:-1,r===0))return t.slice(0,n).trim()}return t}i(Mo,"stripUidComment");function Ro(e){let t=e.trim();if(t.length===0)return{authorName:null,authorEmail:null};let r=t.match(/<([^>\n]+)>\s*$/),n=r?.[1]?.trim()||null,o=(r?t.slice(0,r.index):t).trim();return{authorName:Mo(o)||o||null,authorEmail:n}}i(Ro,"parseSignerUid");async function jo(e,t){try{let{stdout:r}=await Pe(e,t),n=r.trim();return n.length>0?n:null}catch{return null}}i(jo,"runProgram");function Po(e){return e.replace(/\\x([0-9a-fA-F]{2})/g,(t,r)=>String.fromCharCode(Number.parseInt(r,16)))}i(Po,"decodeColonField");async function Io(e){let t=await v(e,["config","--get","gpg.format"]);if(t!==null&&t!=="openpgp")return null;let r=await v(e,["config","--get","user.signingkey"]);if(!r)return null;let n=await v(e,["config","--get","gpg.openpgp.program"])||await v(e,["config","--get","gpg.program"])||"gpg",o=await jo(n,["--batch","--with-colons","--list-keys",r]);if(!o)return null;for(let s of o.split(`
|
|
6
|
+
`)){let a=s.split(":");if(a[0]==="uid"&&a[1]!=="r"&&a[1]!=="e"&&a[9])return Po(a[9])}return null}i(Io,"readSigningKeyUid");async function kr(e,t={}){let r=await v(e,["config","--get","user.name"]),n=await v(e,["config","--get","user.email"]);if(t.useGpgSignerAuthor===!0){let o=await Io(e)||await v(e,["log","-1","--format=%GS"]),s=Ro(o||"");r=s.authorName||r,n=n||s.authorEmail}if(!r||!n){let o=await v(e,["log","-1","--format=%an|%ae"]);if(o){let[s,a]=o.split("|");r=r||s||null,n=n||a||null}}return{authorName:r,authorEmail:n}}i(kr,"detectGitAuthor");function $r(e){return e.replace(/z$/i,"+00:00")}i($r,"canonicalGitDate");async function Sr(e,t){let r=await v(e,["log","--follow","--format=%aI|%at","--reverse","--",t]);if(!r)return null;let n=r.split(`
|
|
7
|
+
`)[0],[o,s]=n.split("|");if(!o||!s)return null;let a=Number.parseInt(s,10);return Number.isNaN(a)?null:{date:$r(o),timestamp:a}}i(Sr,"getGitCreationDate");async function Dr(e,t){let r=await v(e,["log","-1","--format=%aI|%at","--",t]);if(!r)return null;let[n,o]=r.split("|");if(!n||!o)return null;let s=Number.parseInt(o,10);return Number.isNaN(s)?null:{date:$r(n),timestamp:s}}i(Dr,"getGitLastModifiedDate");var To=256*1024*1024;async function Ar(e){let t=vo(e);if(await v(t,["rev-parse","--is-inside-work-tree"])!=="true")return{state:"no-git",content:null};try{let{stdout:r}=await Pe("git",["show",`HEAD:./${No(e)}`],{cwd:t,encoding:"utf8",maxBuffer:To});return{state:"tracked",content:r}}catch{return{state:"untracked",content:null}}}i(Ar,"readGitHeadFile");function Bo(e){return Oo(e)||"project"}i(Bo,"folderName");function Uo(e,t){if(typeof t!="string")return e;let r=t.trim();return r.length===0||Wt(e)?e:`${e} <${r}>`}i(Uo,"formatAuthorNameWithCompany");async function zo(e,t={}){let r=Array.isArray(t.detectors)?t.detectors:T(t),n=typeof t.preferredExtension=="string"?t.preferredExtension.trim().toLowerCase():"",o=n.length>0?r.find(u=>u.extensions.includes(n)):void 0,s=await br(e,{drivers:t.drivers,language:o?.id,scanRoot:t.scanRoot}),a=s?s.root:Ie(e),c=s?.sources.name,l=s?.sources.company;return{language:o?.id??s?.drivers[0]??"unknown",rootDir:a,marker:s?s.marker:null,projectName:s?.fields.name??Bo(a),projectNameSource:c?{from:"manifest",...c}:{from:"folder",dir:a},companyName:s?.fields.company??null,companyNameSource:l?{from:"manifest",...l}:{from:"none"},drivers:s?s.drivers:[]}}i(zo,"detectProjectFromMarkers");async function Te(e={}){let t=e.targetFilePath||e.cwd||process.cwd(),r=Ie(t),n=T(e),o=e.targetFilePath?Ho(r):r,s=e.targetFilePath?_o(r).toLowerCase():"",a=Ie(e.projectRoot||e.cwd||process.cwd()),c=await zo(o,{detectors:n,preferredExtension:s,scanRoot:a}),l=await kr(c.rootDir,{useGpgSignerAuthor:e.useGpgSignerAuthor===!0}),u=e.authorName||l.authorName||"Unknown Author",f=typeof e.companyName=="string"?e.companyName.trim():"";return{projectName:e.projectName||c.projectName,projectNameSource:e.projectName?{from:"option"}:c.projectNameSource,language:e.language||c.language,projectRoot:e.projectRoot||c.rootDir,marker:e.marker===void 0?c.marker:e.marker,authorName:Uo(u,e.company),authorEmail:e.authorEmail||l.authorEmail||"unknown@example.com",companyName:f||c.companyName,companyNameSource:f?{from:"option"}:c.companyNameSource,copyrightStartYear:Number.isInteger(e.copyrightStartYear)?Number(e.copyrightStartYear):null}}i(Te,"resolveProjectMetadata");function Wo(e){return Oe({year:e.getFullYear(),month:e.getMonth()+1,day:e.getDate(),hour:e.getHours(),minute:e.getMinutes(),second:e.getSeconds(),offsetMinutes:-e.getTimezoneOffset()})}i(Wo,"formatDateWithTimezone");function Oe(e){return`${vr(e," ")} ${Lr(e.offsetMinutes)}`}i(Oe,"formatSpaceDate");function Fr(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{Nr(e)}catch(t){throw new Error(`Unknown time zone "${e}": expected an IANA time zone name, such as "America/Los_Angeles" or "UTC"`,{cause:t})}return e}i(Fr,"assertTimeZone");var Cr=new Map;function Nr(e){let t=Cr.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"}),Cr.set(e,t)),t}i(Nr,"getZoneFormatter");function He(e,t){let r={};for(let o of Nr(t).formatToParts(new Date(e*1e3)))r[o.type]=Number(o.value);let n=Date.UTC(r.year,r.month-1,r.day,r.hour,r.minute,r.second)/1e3;return{year:r.year,month:r.month,day:r.day,hour:r.hour,minute:r.minute,second:r.second,offsetMinutes:(n-e)/60}}i(He,"toZonedDateParts");function vr(e,t){let r=i(n=>String(n).padStart(2,"0"),"pad");return`${String(e.year).padStart(4,"0")}-${r(e.month)}-${r(e.day)}${t}${r(e.hour)}:${r(e.minute)}:${r(e.second)}`}i(vr,"formatWallClock");function Lr(e){let t=i(n=>String(n).padStart(2,"0"),"pad"),r=Math.abs(e);return`${e>=0?"+":"-"}${t(Math.floor(r/60))}:${t(r%60)}`}i(Lr,"formatOffset");function ue(e=new Date){return{date:Wo(e),timestamp:Math.floor(e.getTime()/1e3)}}i(ue,"toDatePayload");var Go=/^(\d{4})-(\d{2})-(\d{2})(?:T|\s+)(\d{2}):(\d{2}):(\d{2})(?:\.\d+)?\s*(?:(Z)|([+-])(\d{2}):?(\d{2}))$/i;function _(e){let t=Go.exec(e.trim());if(!t)return null;let[r,n,o,s,a,c]=t.slice(1,7).map(Number),l=t[7]?0:Number(t[9])*60+Number(t[10]),u=t[8]==="-"?-l:l,f=new Date(Date.UTC(r,n-1,o,s,a,c));return!(f.getUTCFullYear()===r&&f.getUTCMonth()===n-1&&f.getUTCDate()===o&&f.getUTCHours()===s&&f.getUTCMinutes()===a&&f.getUTCSeconds()===c)||Number(t[10]??0)>59?null:{year:r,month:n,day:o,hour:s,minute:a,second:c,offsetMinutes:u,timestamp:Math.floor(f.getTime()/1e3)-u*60}}i(_,"parseHeaderDate");function _e(e){return`${vr(e,"T")}${Lr(e.offsetMinutes)}`}i(_e,"formatIsoDate");var Yo={"git-created":"git first commit","filesystem-created":"filesystem creation time"};function Mr(e,t){let r=e.match(new RegExp(`${t}:[^\\S\\n]*(.*)$`,"m"));return r?r[1].trim():null}i(Mr,"readHeaderField");function Be(e){let t=null;for(let{source:r,payload:n}of e)n&&(!t||n.timestamp<t.payload.timestamp)&&(t={source:r,payload:n});return t}i(Be,"pickOldestDate");function jr({existing:e,gitCreated:t,filesystemCreated:r,fixCreatedDate:n=!1}){let o=[{source:"git-created",payload:t},{source:"filesystem-created",payload:r}];if(!e)return Be(o);if(!n)return{source:"existing-header",payload:e};let s=_(e.date)?e:null;return Be([{source:"existing-header",payload:s},...o])}i(jr,"resolveCreatedDate");function Pr(e,t=null){if(t)return He(e.timestamp,t).year;let r=_(e.date);return r?r.year:new Date(e.timestamp*1e3).getFullYear()}i(Pr,"dateYear");function Rr(e,t,r,n){let o=e.match(/^(.+?)\s*\((\d+)\)$/),s=o?_(o[1]):null;if(!o||!s)return n.push({check:`${r}-format`,field:t,advisory:!1,value:e,message:`${t} value "${e}" is not a "<datetime> (<epoch>)" pair with a recognised datetime`}),null;let a=Number.parseInt(o[2],10);return a!==s.timestamp&&n.push({check:`${r}-epoch`,field:t,advisory:!1,value:e,expected:`${o[1]} (${s.timestamp})`,message:`${t} epoch ${a} does not match ${o[1]} (expected ${s.timestamp})`}),{text:o[1],timestamp:s.timestamp}}i(Rr,"checkDateValue");function Ir(e,t={},r={}){let n=[],o=Mr(e,"@Date"),s=o===null?null:Rr(o,"@Date","created",n),a=Be([{source:"git-created",payload:t.gitCreated},{source:"filesystem-created",payload:t.filesystemCreated}]);if(s&&a&&s.timestamp>a.payload.timestamp){let f=Yo[a.source];n.push({check:"created-newer-than-source",field:"@Date",advisory:r.strictCreatedDate!==!0,value:o,expected:`${a.payload.date} (${a.payload.timestamp})`,source:a.source,message:`@Date ${s.text} is later than the ${f} ${a.payload.date} (${a.payload.timestamp})`})}let c=Mr(e,"@Last modified time"),l=c===null?null:Rr(c,"@Last modified time","modified",n),u=t.gitLastModified;return l&&u&&l.timestamp!==u.timestamp&&n.push({check:"modified-git",field:"@Last modified time",advisory:!0,value:c,expected:`${u.date} (${u.timestamp})`,message:`@Last modified time ${l.text} does not match the git last commit ${u.date} (${u.timestamp})`}),n}i(Ir,"checkHeaderDates");function Ue(e){if(!e)return null;let t=_(e.date);return t&&t.timestamp!==e.timestamp?{date:e.date,timestamp:t.timestamp}:e}i(Ue,"repairDateEpoch");function Tr(e){let t=_(e.date);return t?{date:_e(t),timestamp:t.timestamp}:e}i(Tr,"normalizeDatePayload");function Or(e,t){let r=_(e.date);if(!r)return e;let n=He(r.timestamp,t);return n.offsetMinutes===r.offsetMinutes||!Number.isInteger(n.offsetMinutes)?e:{date:/^\d{4}-\d{2}-\d{2}T/i.test(e.date.trim())?_e(n):Oe(n),timestamp:r.timestamp}}i(Or,"convertDatePayload");import{relative as Jo}from"node:path";import{extname as Vo}from"node:path";function B(e,t={}){let r=Vo(e).toLowerCase(),n=O(t.spacing,"spacing",Z);return r.length===0?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */",spacing:n}:{...Ht(e,t),spacing:n}}i(B,"getHeaderSyntaxForFile");function Hr(e,t){let r=e.spacing??Z;if(e.kind==="line"){let c=e.linePrefix||"#",l=typeof e.lineSeparator=="string"?e.lineSeparator:" ",u=Array.from({length:r},()=>c);return[...u,...t.map(f=>`${c}${l}${f}`),...u].join(`
|
|
6
8
|
`)}let n=e.blockStart||(e.kind==="html"?"<!--":"/**"),o=e.blockLinePrefix||(e.kind==="html"?" ":" * "),s=e.blockEnd||(e.kind==="html"?"-->":" */"),a=Array.from({length:r},()=>o.trimEnd());return[n,...a,...t.map(c=>`${o}${c}`),...a,s].join(`
|
|
7
|
-
`)}i(
|
|
8
|
-
`)
|
|
9
|
-
`).map((f,m)=>({raw:m===0&&f.trim()!==""?`${s}${f.trim()}`:f.trimEnd(),text:(m===0?f:f.replace(a,"")).trim()})),l=c[0].raw===""?1:0,u=c.length>l&&c[c.length-1].raw.trim()===""?c.length-1:c.length;return c.slice(l,u)}i(Cr,"segmentLines");function jo(e){let t=new Set,r=e.map(o=>{let s=o.text.match(vo);return o.text===""?"blank":s&&!t.has(s[1])?(t.add(s[1]),"field"):/^-{3,}$/.test(o.text)?"dash":"text"}),n=i((o,s)=>{for(let a=o+s;a>=0&&a<r.length;a+=s)if(r[a]!=="blank"&&r[a]!=="dash")return r[a]},"neighbour");return r.map((o,s)=>o==="dash"?n(s,-1)==="field"||n(s,1)==="field"?"separator":"text":o)}i(jo,"classifyLines");function Ro(e,t="",r={},n=0){let o=O(t,r),s=[],a=[],c=e,l=re(c,o),u=!0;for(;l&&l[0].length>0;){let h=Cr(l[0],o),d=jo(h),p=0;if(u&&o.kind==="line"){let w=i(b=>Fo.test(h[b].raw)||n+b<=1&&Lo.test(h[b].raw),"isDirective");for(;p<h.length&&d[p]==="text"&&w(p);)s.push(h[p].raw),p+=1}h.slice(p).forEach((w,b)=>a.push({raw:w.raw,kind:d[p+b]})),c=c.slice(l[0].length),l=re(c,o),u=!1}let f=a.findIndex(h=>h.kind==="text");if(f===-1)return{above:s,foreign:[]};let m=a.map(h=>h.kind).lastIndexOf("text"),y=a.slice(f,m+1).filter(h=>h.kind==="text"||h.kind==="blank").map(h=>h.raw);return{above:s,foreign:y}}i(Ro,"splitHeaderText");function Io(e,t,r){let n=t.kind==="html",o=t.kind==="line"?`${t.linePrefix||"#"}${typeof t.lineSeparator=="string"?t.lineSeparator:" "}`:t.blockLinePrefix||(n?" ":" * "),s=t.kind==="line"?new RegExp(`^${B(t.linePrefix||"#")}[ \\t]*`):n?/^\s*/:/^\s*\*?[ \t]*/,a=e.map(u=>u.replace(s,"").trim()).find(u=>u!==""),l=a!==void 0&&a.startsWith("@Project:")?[`${o}${Po}`,...e]:e;return t.kind==="line"?l.join(r):[t.blockStart||(n?"<!--":"/**"),...l,t.blockEnd||(n?"-->":" */")].join(r)}i(Io,"renderForeignBlock");function To(e,t,r){let n=e.split(`
|
|
10
|
-
`),o=r.kind==="html",s=r.kind==="line"?r.linePrefix||"#":(r.blockLinePrefix||(o?" ":" * ")).trimEnd(),a=Math.min(n.length-1,(r.spacing??1)+(r.kind==="line"?0:1)),c=n.length-a;return[...n.slice(0,c),s,...t,...n.slice(c)].join(`
|
|
11
|
-
`)}i(To,"appendToHeader");function ne(e,t="",r={}){let{prefix:n,body:o}=je(t,e,r),s=o.split(`
|
|
12
|
-
`).slice(0,vt).join(`
|
|
13
|
-
`),a=O(t,r);if(!re(s,a))return null;let l=0,u=0;for(;;){let f=s.slice(l),m=re(f,a);if(!m||!(l===0?m[0].includes("@Project:"):Mo(m[0],a)))break;l+=m[0].length,u=l}return u===0?null:{start:n.length,end:n.length+u}}i(ne,"findProjectHeader");function oe(e,t,r="",n={}){let o=ne(e,r,n),s=O(r,n),a=M(n.margin,"margin",Q),c=s.kind==="line"?Math.max(1,a):a,l=`
|
|
14
|
-
`.repeat(c+1);if(!o){let{prefix:E,body:K}=je(r,e,n),U=K.replace(/^\n+/,""),x=`${E}${U.trim()===""?`${t}
|
|
15
|
-
`:`${t}${l}${U}`}`;return{nextContent:x,changed:x!==e,header:t,written:t}}let u=e.slice(o.start,o.end),{above:f,foreign:m}=Ro(u,r,n,e.slice(0,o.start).split(`
|
|
16
|
-
`).length-1),y=u.includes(`\r
|
|
17
|
-
`)?`\r
|
|
9
|
+
`)}i(Hr,"renderHeaderLines");function _r(e){let t=`/${Jo(e.projectRoot,e.absoluteFilePath).replace(/\\/g,"/")}`,r=B(e.absoluteFilePath,e.syntaxOptions||{language:e.language}),n=e.createdByName||e.authorName,o=e.createdByEmail||e.authorEmail,s=e.lastModifiedByName||e.authorName,a=e.lastModifiedByEmail||e.authorEmail,c=typeof e.companyName=="string"?e.companyName.trim():"",l=c.length>0?`${c} `:"",u=[`@Project: ${e.projectName}`,`@Filename: ${t}`,`@Date: ${e.createdAt.date} (${e.createdAt.timestamp})`,`@Author: ${n}`,`@Email: <${o}>`,"-----",`@Last modified by: ${s} (${a})`,`@Last modified time: ${e.lastModifiedAt.date} (${e.lastModifiedAt.timestamp})`,"-----",`@Copyright: Copyright (c) ${e.copyrightStartYear}-${e.currentYear} ${l}All rights reserved.`];return Hr(r,u)}i(_r,"buildHeader");var qo=Object.freeze(["projectName","filename","createdAt","authorName","authorEmail","lastModifiedByName","lastModifiedByEmail","lastModifiedAt","copyrightStartYear","copyrightEndYear","companyName"]);function I(e,t){let r=e.match(new RegExp(`@${t}:[ \\t]*(.*)$`,"m")),n=r?r[1].trim():"";return n.length>0?n:null}i(I,"readTag");function Ko(e){if(e===null)return{name:null,email:null};if(!e.endsWith(")"))return{name:e,email:null};let t=e.slice(0,-1),r=t.indexOf("(",t.lastIndexOf(")")+1);return r===-1?{name:e,email:null}:{name:t.slice(0,r).trimEnd()||null,email:t.slice(r+1)||null}}i(Ko,"splitLastModifiedBy");function Zo(e){let t={startYear:null,endYear:null,companyName:null},r=e?.match(/^Copyright\s+\(c\)\s+(\d{4})/i);if(!r)return t;let n=e.slice(r[0].length),o=n.match(/^\s*-\s*(\d{4})/);o&&(n=n.slice(o[0].length));let s=n.toLowerCase(),a=s.endsWith("all rights reserved.")?20:s.endsWith("all rights reserved")?19:0;return a===0||!/^\s/.test(n)?t:{startYear:r[1],endYear:o?o[1]:null,companyName:n.slice(0,-a).trim()||null}}i(Zo,"splitCopyright");function Br(e){let t=Ko(I(e,"Last modified by")),r=Zo(I(e,"Copyright")),n=I(e,"Email");return{projectName:I(e,"Project"),filename:I(e,"Filename"),createdAt:I(e,"Date"),authorName:I(e,"Author"),authorEmail:n===null?null:n.replace(/^<(.*)>$/,"$1"),lastModifiedByName:t.name,lastModifiedByEmail:t.email,lastModifiedAt:I(e,"Last modified time"),copyrightStartYear:r.startYear,copyrightEndYear:r.endYear,companyName:r.companyName}}i(Br,"parseHeaderFields");function Ur(e,t){let r=Br(e??""),n=Br(t);return qo.filter(o=>r[o]!==n[o]).map(o=>({field:o,previous:r[o],detected:n[o]}))}i(Ur,"compareHeaderFields");function ee(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}i(ee,"escapeRegex");function ze(e,t,r={}){let n=t.startsWith("\uFEFF")?"\uFEFF":"",o=t.slice(n.length),s=`${n}${ae(e,o,r)}`;return{prefix:s,body:t.slice(s.length)}}i(ze,"splitPreservedPrefix");function de(e){let t=e.indexOf(`
|
|
10
|
+
`);return t===-1?null:t>0&&e[t-1]==="\r"?`\r
|
|
18
11
|
`:`
|
|
19
|
-
|
|
20
|
-
|
|
12
|
+
`}i(de,"lineEnding");function W(e,t){if(t.kind==="html"){let n=ee(t.blockStart||"<!--"),o=ee(t.blockEnd||"-->");return e.match(new RegExp(`^${n}[\\s\\S]*?${o}(?:\\r?\\n)*`))}if(t.kind==="line"){let n=ee(t.linePrefix||"#");return e.match(new RegExp(`^(?:${n}[^\\n]*\\n)+(?:\\r?\\n)*`))}let r=ee((t.blockEnd||" */").trim());return e.match(new RegExp(`^/\\*[\\s\\S]*?${r}(?:\\r?\\n)*`))}i(W,"matchHeaderSegment");var Gr=/^@(Project|Filename|Date|Author|Email|Last modified by|Last modified time|Copyright):/,Xo="Moved out of the file header by fix-headers:";function Yr(e){return e.some(t=>/^@(?:Project|Filename):/.test(t.text))}i(Yr,"isFileHeader");function We(e,t){let r=e.replace(/(?:\r?\n)+$/,"");if(t.kind==="line"){let f=new RegExp(`^${ee(t.linePrefix||"#")}[ \\t]*`);return r.split(`
|
|
13
|
+
`).map(p=>{let y=p.replace(/\r$/,"");return{raw:y,text:y.replace(f,"").trim()}})}let n=t.kind==="html",o=n?r.replace(/^<!--/,"").replace(/--!?>\s*$/,""):r.replace(/^\/\*+/,"").replace(/\*+\/\s*$/,""),s=t.blockLinePrefix||(n?" ":" * "),a=n?/^\s*/:/^\s*\*?[ \t]*/,c=o.split(`
|
|
14
|
+
`).map((f,p)=>({raw:p===0&&f.trim()!==""?`${s}${f.trim()}`:f.trimEnd(),text:(p===0?f:f.replace(a,"")).trim()})),l=c[0].raw===""?1:0,u=c.length>l&&c[c.length-1].raw.trim()===""?c.length-1:c.length;return c.slice(l,u)}i(We,"segmentLines");function Qo(e,t){let r=e.map(o=>{let s=o.text.match(Gr);return o.text===""?"blank":s&&s[1]==="Copyright"?t.copyright?"copyright":(t.copyright=!0,"field"):s?"field":/^-{3,}$/.test(o.text)?"dash":"text"}),n=i((o,s)=>{for(let a=o+s;a>=0&&a<r.length;a+=s)if(r[a]!=="blank"&&r[a]!=="dash")return r[a]==="copyright"?"field":r[a]},"neighbour");return r.map((o,s)=>o==="dash"?n(s,-1)==="field"||n(s,1)==="field"?"separator":"text":o)}i(Qo,"classifyLines");function ei(e,t="",r={}){let n=B(t,r),o=[],s=[],a={copyright:!1},c=e,l=W(c,n),u=!0;for(;l&&l[0].length>0;){let m=We(l[0],n),w=Qo(m,a),b=m.findIndex($=>$.text!=="");!u&&b!==-1&&m[b].text===Xo&&(w[b]="separator"),m.forEach(($,C)=>{w[C]==="copyright"&&s.push($.text.replace(Gr,"").trim()),o.push({raw:$.raw,kind:w[C]})}),c=c.slice(l[0].length),l=W(c,n),u=!1}let f=o.findIndex(m=>m.kind==="text");if(f===-1)return{foreign:[],copyrights:s};let p=o.map(m=>m.kind).lastIndexOf("text"),y=[],g=[],d=!1;for(let m of o.slice(f,p+1))m.kind==="text"?(y.push(...d?[]:g,m.raw),g=[],d=!1):m.kind==="blank"?g.push(m.raw):d=!0;return{foreign:y,copyrights:s}}i(ei,"splitHeaderText");function ti(e,t,r){let n=t.kind==="html";return t.kind==="line"?e.join(r):[t.blockStart||(n?"<!--":"/**"),...e,t.blockEnd||(n?"-->":" */")].join(r)}i(ti,"renderForeignBlock");function ri(e,t,r){let n=e.split(`
|
|
15
|
+
`),o=r.kind==="html",s=r.kind==="line"?r.linePrefix||"#":(r.blockLinePrefix||(o?" ":" * ")).trimEnd(),a=Math.min(n.length-1,(r.spacing??1)+(r.kind==="line"?0:1)),c=n.length-a;return[...n.slice(0,c),s,...t,...n.slice(c)].join(`
|
|
16
|
+
`)}i(ri,"appendToHeader");function zr(e){let t=e.trim(),r=t.match(/^copyright\b/i);t=r?t.slice(r[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 n=t.match(/^\d{4}(?:\s*[-–,]\s*\d{4})*/);t=n?t.slice(n[0].length):t,t=t.trimEnd();let o=t.toLowerCase(),s=o.endsWith("all rights reserved.")?20:o.endsWith("all rights reserved")?19:0;t=t.slice(0,t.length-s);let a=t.length;for(;a>0&&`.,; \r
|
|
17
|
+
`.includes(t[a-1]);)a-=1;return t.slice(0,a).split(/\s+/).filter(Boolean).join(" ").toLowerCase()}i(zr,"copyrightHolder");function ni(e,t){let r=e.split(`
|
|
18
|
+
`),n=r.findIndex(c=>c.includes("@Copyright:")),o=r.map(c=>/@[A-Za-z][A-Za-z ]*:/.test(c)).lastIndexOf(!0),s=n!==-1?n:o;if(t.length===0||s===-1)return e;let a=r[s].slice(0,r[s].indexOf("@"));return[...r.slice(0,s+1),...t.map(c=>`${a}@Copyright: ${c}`),...r.slice(s+1)].join(`
|
|
19
|
+
`)}i(ni,"insertCopyrights");function Wr(e,t){let r=0,n=W(e,t);for(;n&&n[0].length>0&&Yr(We(n[0],t));)r+=n[0].length,n=W(e.slice(r),t);return r}i(Wr,"leadingHeadersLength");function fe(e,t="",r={}){let n=e.startsWith("\uFEFF")?"\uFEFF":"",o=e.slice(n.length),s=ae(t,o,r),a=B(t,r),c=s.length,l=Wr(o.slice(c),a);if(l===0)return e;let u=n===""&&c===0&&o.startsWith("\uFEFF",l);u&&(n="\uFEFF",o=`${o.slice(0,l)}${o.slice(l+1)}`,l+=Wr(o.slice(l),a));let f=o.slice(c,c+l),p=o.slice(c+l),y=ae(t,`${s}${p}`,r),g=y.length>s.length?y.slice(s.length):"";if(g===""&&!u)return e;let d=g===""||g.endsWith(`
|
|
20
|
+
`)?g:`${g}${de(e)??`
|
|
21
|
+
`}`;return`${n}${s}${d}${f}${p.slice(g.length)}`}i(fe,"restoreTopLines");function me(e,t="",r={}){let{prefix:n,body:o}=ze(t,e,r),s=o.split(`
|
|
22
|
+
`).slice(0,Ut).join(`
|
|
23
|
+
`),a=B(t,r);if(!W(s,a))return null;let l=0,u=0;for(;;){let f=s.slice(l),p=W(f,a);if(!p||!Yr(We(p[0],a)))break;l+=p[0].length,u=l}return u===0?null:{start:n.length,end:n.length+u}}i(me,"findProjectHeader");function pe(e,t,r="",n={}){let o=fe(e,r,n),s=me(o,r,n),a=B(r,n),c=O(n.margin,"margin",ce),l=a.kind==="line"?Math.max(1,c):c,u=i((k,S)=>S===`
|
|
24
|
+
`?k:k.replace(/\r?\n/g,S),"withEol");if(!s){let{prefix:k,body:S}=ze(r,o,n),D=de(o)??`
|
|
25
|
+
`,j=u(t,D),V=S.replace(/^(?:\r?\n)+/,""),h=k.replace(/^\uFEFF/,"")!==""&&!k.endsWith(`
|
|
26
|
+
`)?D:"",P=`${k}${h}${V.trim()===""?`${j}${D}`:`${j}${D.repeat(l+1)}${V}`}`;return{nextContent:P,changed:P!==e,header:j,written:j,extraCopyrights:[]}}let f=o.slice(s.start,s.end),{foreign:p,copyrights:y}=ei(f,r,n),g=t.split(`
|
|
27
|
+
`).find(k=>k.includes("@Copyright:")),d=new Set(g===void 0?[]:[zr(g.slice(g.indexOf("@Copyright:")+11))]),m=[];for(let k of y){let S=zr(k);d.has(S)||(d.add(S),m.push(k))}let w=de(o.slice(s.end))??de(f)??`
|
|
28
|
+
`,b=w.repeat(l+1),$=n.strictHeaderBlock!==!1,C=ni(t,m),R=u(p.length>0&&!$?ri(C,p,a):C,w),E=p.length>0&&$?ti(p,a,w):"",U=o.slice(s.end).replace(/^(?:\r?\n)+/,""),G=E===""?U:`${E}${U.trim()===""?w:`${b}${U}`}`,Y=`${o.slice(0,s.start)}${G.trim()===""?`${R}${w}`:`${R}${b}${G}`}`,x=`${R}${E===""?"":`${b}${E}`}`;return{nextContent:Y,changed:Y!==e,header:R,written:x,extraCopyrights:m}}i(pe,"replaceOrInsertHeader");function Ge(e,t="",r={}){let n=fe(e,t,r),o=me(n,t,r);if(o){let l=n.slice(0,o.start),f=pe(n,"",t,{...r,strictHeaderBlock:!0}).nextContent.slice(l.length).replace(/^(?:\r?\n)+/,"");return`${l}${f.trim()===""?"":f}`}let{prefix:s,body:a}=ze(t,n,r),c=a.replace(/^(?:\r?\n)+/,"");return`${s}${c.trim()===""?"":c}`}i(Ge,"extractHeaderlessBody");function oi(e,t){let r=e.length,n=t.length,o=Array.from({length:r+1},()=>new Array(n+1).fill(0));for(let l=r-1;l>=0;l-=1)for(let u=n-1;u>=0;u-=1)o[l][u]=e[l]===t[u]?o[l+1][u+1]+1:Math.max(o[l+1][u],o[l][u+1]);let s=[],a=0,c=0;for(;a<r&&c<n;)e[a]===t[c]?(s.push({type:" ",line:e[a]}),a+=1,c+=1):o[a+1][c]>=o[a][c+1]?(s.push({type:"-",line:e[a]}),a+=1):(s.push({type:"+",line:t[c]}),c+=1);for(;a<r;a+=1)s.push({type:"-",line:e[a]});for(;c<n;c+=1)s.push({type:"+",line:t[c]});return s}i(oi,"diffLines");function Vr(e,t){return`${t===0?e:e+1},${t}`}i(Vr,"formatRange");function Jr(e,t,r={}){let n=e===null?[]:e.split(`
|
|
21
29
|
`),o=t.split(`
|
|
22
|
-
`),s=
|
|
23
|
-
`)}i(
|
|
24
|
-
`).length-1;
|
|
30
|
+
`),s=oi(n,o),a=Math.max(0,r.context??3),c=r.lineOffset??0,l=[];if(s.forEach((y,g)=>{if(y.type===" ")return;let d=l[l.length-1];d&&g-d.last<=a*2+1?d.last=g:l.push({first:g,last:g})}),l.length===0)return"";let u=r.fromFile??"a",f=r.toFile??"b",p=[`--- ${e===null?"/dev/null":u}`,`+++ ${f}`];for(let y of l){let g=Math.max(0,y.first-a),d=Math.min(s.length,y.last+a+1),m=s.slice(0,g),w=s.slice(g,d),b=m.filter(E=>E.type!=="+").length+c,$=m.filter(E=>E.type!=="-").length+c,C=w.filter(E=>E.type!=="+").length,R=w.filter(E=>E.type!=="-").length;p.push(`@@ -${Vr(b,C)} +${Vr($,R)} @@`);for(let E of w)p.push(`${E.type}${E.line}`)}return p.join(`
|
|
31
|
+
`)}i(Jr,"createUnifiedDiff");function ci(e){return mt(e,"configFile")}i(ci,"resolveRuntimeOptions");function li(e){if(e==null)return[];let t=Array.isArray(e)?e:[e];if(t.some(r=>typeof r!="string"))throw new Error(`input must be a path or an array of paths, got ${JSON.stringify(e)}`);return t.filter(r=>r.trim().length>0)}i(li,"resolveInputs");function ui(e){let t=e.match(/@Author:\s*(.+)$/m),r=e.match(/@Email:\s*<([^>\n]+)>/m);return{authorName:t?.[1]?.trim(),authorEmail:r?.[1]?.trim()}}i(ui,"extractHeaderAuthorIdentity");function di(e){let t=e.match(/@Last modified by:\s*(.+?)\s*\(([^)\n]+)\)\s*$/m);return{authorName:t?.[1]?.trim(),authorEmail:t?.[2]?.trim()}}i(di,"extractHeaderLastModifiedIdentity");function fi(e){let t=e.match(/@Date:\s*(.+?)\s*\((\d+)\)$/m);if(!t||!t[1]||!t[2])return null;let r=Number.parseInt(t[2],10);return Number.isNaN(r)?null:{date:t[1].trim(),timestamp:r}}i(fi,"extractHeaderCreatedAt");function mi(e){let t=e.match(/@Last modified time:\s*(.+?)\s*\((\d+)\)$/m);if(!t||!t[1]||!t[2])return null;let r=Number.parseInt(t[2],10);return Number.isNaN(r)?null:{date:t[1].trim(),timestamp:r}}i(mi,"extractHeaderLastModifiedAt");async function pi(e,t,r){let n=await Ar(t);return n.state!=="tracked"?{edited:n.state==="untracked",state:n.state}:{edited:Ge(n.content,t,r)!==Ge(e,t,r),state:"tracked"}}i(pi,"detectContentEdit");async function Kr(e={}){let t=await ci(e),r=t.timezone===void 0||t.timezone===null?null:Fr(t.timezone),n=t.convertTimezone===!0;if(n&&!r)throw new Error("convertTimezone requires timezone: set timezone (CLI --timezone <name>) to the IANA zone to convert header dates into");let o=It(t.forcedDetectors),s=qr(t.projectRoot||t.cwd||process.cwd()),a=await Te({...t,cwd:s});O(t.spacing,"spacing",Z),O(t.margin,"margin",ce);let c=t.check===!0,l=c||t.dryRun===!0,u=t.fixCreatedDate===!0,f=i(x=>x,"keepDate"),p=t.normalizeDateFormat===!0?Tr:f,y=r?x=>Or(x,r):f,g=n?y:f,d={language:a.language,enabledDetectors:t.enabledDetectors,disabledDetectors:t.disabledDetectors,forcedDetectors:o,includeFolders:t.includeFolders,excludeFolders:t.excludeFolders,includeExtensions:t.includeExtensions,gitignore:t.gitignore},m=li(t.input),w;if(m.length>0){let x=new Set;for(let k of m){let S=qr(s,k),D=await si(S).catch(()=>null);if(!D)throw new Error(`Input path does not exist: ${k}`);if(D.isFile())x.add(S);else if(D.isDirectory())for(let j of await ve({...d,projectRoot:S}))x.add(j);else throw new Error(`Input path must be a file or directory: ${k}`)}w=Array.from(x)}else w=await ve({...d,projectRoot:s});let b=new Date().getFullYear(),$=[],C=[],R=new Set,E=0,U=0,G=0,Y=[];for(let x of w){let k=Ot(x,{enabledDetectors:t.enabledDetectors,disabledDetectors:t.disabledDetectors,forcedDetectors:o});if(k!==null){C.push({file:Ye(s,x),reason:k});continue}let S=Ye(s,x),D=await ii(x,"utf8"),j={enabledDetectors:t.enabledDetectors,disabledDetectors:t.disabledDetectors,forcedDetectors:o,detectorSyntaxOverrides:t.detectorSyntaxOverrides},V=Bt(x,fe(D,x,j),j);if(V!==null){C.push({file:S,reason:V});continue}let h=await Te({...t,cwd:s,targetFilePath:x});R.add(`${h.language}:${h.projectRoot}`);let P={language:h.language,enabledDetectors:t.enabledDetectors,disabledDetectors:t.disabledDetectors,forcedDetectors:o,detectorSyntaxOverrides:t.detectorSyntaxOverrides,spacing:t.spacing,margin:t.margin,strictHeaderBlock:t.strictHeaderBlock!==!1},he=me(D,x,P),F=he?D.slice(he.start,he.end):"",Ve=F.length>0?ui(F):{},Je=F.length>0?di(F):{},Xr=F.length>0?fi(F):null,Qr=F.length>0?mi(F):null,qe=await zt(x),Ke=Ye(h.projectRoot,x),Ze=await Sr(h.projectRoot,Ke),J=await Dr(h.projectRoot,Ke),Xe=ue(qe.createdAt),ge=jr({existing:Ue(Xr),gitCreated:Ze,filesystemCreated:Xe,fixCreatedDate:u}),q=Ue(Qr),Qe=ge.source,en=q?"existing-header":J?"git-last-modified":"filesystem-updated",ye=p(Qe==="existing-header"?g(ge.payload):y(ge.payload)),tn=h.copyrightStartYear===null?"created-date":"option",et=h.copyrightStartYear??Pr(ye,r),tt=p(q?g(q):y(J||ue(qe.updatedAt))),rt=t.forceAuthorUpdate===!0,rn=t.forceLastModifiedAuthorUpdate===!0,nt=await pi(D,x,P),ot=rn||nt.edited,it=i(N=>_r({absoluteFilePath:x,language:h.language,syntaxOptions:P,projectRoot:h.projectRoot,projectName:h.projectName,createdByName:rt?h.authorName:Ve.authorName||h.authorName,createdByEmail:rt?h.authorEmail:Ve.authorEmail||h.authorEmail,lastModifiedByName:ot?h.authorName:Je.authorName||h.authorName,lastModifiedByEmail:ot?h.authorEmail:Je.authorEmail||h.authorEmail,authorName:h.authorName,authorEmail:h.authorEmail,createdAt:ye,lastModifiedAt:N,copyrightStartYear:et,companyName:h.companyName,currentYear:b}),"renderHeader"),st=it(tt),at=pe(D,st,x,P),nn=nt.edited&&q!==null&&J!==null&&q.timestamp<J.timestamp,te=at.changed||nn,ct=te?p(y(ue(new Date))):tt,on=te?"current-time-on-change":en,sn=te?it(ct):st,L=te?pe(D,sn,x,P):at,re={file:S,changed:L.changed};if(c){let N=Ir(F,{gitCreated:Ze,gitLastModified:J,filesystemCreated:Xe},{strictCreatedDate:t.strictCreatedDate===!0}),K=N.filter(z=>z.advisory).length;re.dateIssues=N,G+=K,U+=N.length>K?1:0}if(t.sampleOutput===!0&&L.changed){let N=F.length>0?F.trimEnd():null,K=S.replace(/\\/g,"/"),z=L.written,an=L.nextContent.slice(0,L.nextContent.indexOf(z)).split(`
|
|
32
|
+
`).length-1;re.sample={previousValue:N,newValue:z,diff:Jr(N,z,{fromFile:`a/${K}`,toFile:`b/${K}`,lineOffset:an}),issues:Ur(N,z),detectedValues:{projectName:h.projectName,projectNameSource:h.projectNameSource,language:h.language,projectRoot:h.projectRoot,marker:h.marker,authorName:h.authorName,authorEmail:h.authorEmail,companyName:h.companyName,companyNameSource:h.companyNameSource,copyrightStartYear:et,copyrightStartYearSource:tn,createdAtSource:Qe,lastModifiedAtSource:on,createdAt:ye,lastModifiedAt:ct}}}if(L.extraCopyrights.length>0){re.extraCopyrights=L.extraCopyrights;for(let N of L.extraCopyrights)Y.push({file:S,copyright:N})}$.push(re),L.changed&&(E+=1,l||await ai(x,L.nextContent,"utf8"))}return{metadata:a,detectedProjects:Array.from(R),filesScanned:w.length-C.length,filesUpdated:E,filesSkipped:C.length,dryRun:l,check:c,...c?{filesWithDateDrift:U,dateAdvisories:G}:{},copyrightWarnings:Y,changes:$,skipped:C}}i(Kr,"fixHeaders");var Zr=typeof process>"u"?void 0:process.getBuiltinModule?.("node:module");if(Zr)try{Zr.createRequire(import.meta.url)("../devcheck.mjs")}catch(e){if(e?.code!=="MODULE_NOT_FOUND")throw e}function hi(e){return Kr(e)}i(hi,"fixHeaders");var hc=hi;export{hc as default,hi as fixHeaders};
|
|
25
33
|
//# sourceMappingURL=index.mjs.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cldmv/fix-headers",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.4",
|
|
4
4
|
"description": "Multi-language project header normalizer with auto-detection and override support.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"dist/",
|
|
11
11
|
"!dist/**/*.map",
|
|
12
12
|
"types/",
|
|
13
|
+
"!types/devcheck.d.mts",
|
|
13
14
|
"bin/",
|
|
14
15
|
"!bin/**/*.map"
|
|
15
16
|
],
|
|
@@ -17,7 +18,8 @@
|
|
|
17
18
|
".": {
|
|
18
19
|
"fix-headers-dev": {
|
|
19
20
|
"types": "./types/index.d.mts",
|
|
20
|
-
"import": "./src/
|
|
21
|
+
"import": "./src/index.mjs",
|
|
22
|
+
"require": "./src/index.cjs"
|
|
21
23
|
},
|
|
22
24
|
"types": "./types/index.d.mts",
|
|
23
25
|
"import": "./dist/index.mjs",
|
|
@@ -31,13 +33,13 @@
|
|
|
31
33
|
"scripts": {
|
|
32
34
|
"build:ci": "npm run lint --if-present && npm run format:check --if-present && npm run types:check && npm run types:build && npm run build",
|
|
33
35
|
"test": "node tests/run-vitest.mjs && npm run test:cjs",
|
|
34
|
-
"test:cjs": "npm run build && node --test tests/cjs/entry.test.cjs",
|
|
36
|
+
"test:cjs": "npm run build && node --conditions=fix-headers-dev --test tests/cjs/entry.test.cjs",
|
|
35
37
|
"test:watch": "vitest --config .configs/vitest.config.mjs",
|
|
36
38
|
"coverage": "node tests/run-vitest.mjs --coverage-quiet && npm run test:cjs",
|
|
37
39
|
"ci:coverage": "npm run coverage",
|
|
38
40
|
"types:build": "tsc -p .configs/tsconfig.json --noCheck",
|
|
39
41
|
"types:check": "tsc -p .configs/tsconfig.json --noEmit",
|
|
40
|
-
"cli": "node ./src/cli.mjs",
|
|
42
|
+
"cli": "node --conditions=fix-headers-dev ./src/cli.mjs",
|
|
41
43
|
"build": "node -e \"for (const d of ['dist', 'bin']) require('node:fs').rmSync(d, { recursive: true, force: true })\" && tsup",
|
|
42
44
|
"prepack": "node -e \"const fs=require('node:fs');const hasTsup=fs.existsSync('node_modules/.bin/tsup')||fs.existsSync('node_modules/.bin/tsup.cmd');if(hasTsup){require('node:child_process').execSync('npm run build',{stdio:'inherit'})}else if(!fs.existsSync('dist/index.mjs')){throw new Error('dist/ is missing and tsup is unavailable to build it (expected in a bare package-contents publish dir with a prebuilt dist/; unexpected anywhere else)')}\"",
|
|
43
45
|
"lint": "eslint --config .configs/eslint.config.mjs .",
|
|
@@ -45,7 +47,7 @@
|
|
|
45
47
|
"format": "prettier --config .configs/.prettierrc --write .",
|
|
46
48
|
"format:check": "prettier --config .configs/.prettierrc --check .",
|
|
47
49
|
"prepare": "node -e \"import('./.githooks/install.mjs').catch(()=>{})\"",
|
|
48
|
-
"fix:headers": "node ./src/cli.mjs --config .configs/fix-headers.json"
|
|
50
|
+
"fix:headers": "node --conditions=fix-headers-dev ./src/cli.mjs --config .configs/fix-headers.json"
|
|
49
51
|
},
|
|
50
52
|
"keywords": [
|
|
51
53
|
"headers",
|
|
@@ -62,7 +64,7 @@
|
|
|
62
64
|
},
|
|
63
65
|
"homepage": "https://github.com/CLDMV/fix-headers#readme",
|
|
64
66
|
"engines": {
|
|
65
|
-
"node": ">=22.
|
|
67
|
+
"node": ">=22.13.0"
|
|
66
68
|
},
|
|
67
69
|
"author": {
|
|
68
70
|
"name": "Shinrai",
|
|
@@ -109,6 +111,8 @@
|
|
|
109
111
|
"ignore": "^7.0.5"
|
|
110
112
|
},
|
|
111
113
|
"overrides": {
|
|
112
|
-
"esbuild": "$esbuild"
|
|
114
|
+
"esbuild": "$esbuild",
|
|
115
|
+
"katex": ">=0.19.1 <1.0.0",
|
|
116
|
+
"minimatch": "^11.0.3"
|
|
113
117
|
}
|
|
114
118
|
}
|
package/types/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./src/
|
|
2
|
-
export { default } from "./src/
|
|
1
|
+
export * from "./src/index.mjs";
|
|
2
|
+
export { default } from "./src/index.mjs";
|
|
@@ -91,8 +91,14 @@ export type DateRewrite = (payload: {
|
|
|
91
91
|
* Files whose format cannot carry the header comment are not processed: each is listed in
|
|
92
92
|
* `skipped` as `{ file, reason }` and counted in `filesSkipped`, not in `filesScanned` or
|
|
93
93
|
* `changes`. That covers strict `.json`, files with no extension or an extension no enabled
|
|
94
|
-
* detector handles (for example one added through `includeExtensions`),
|
|
95
|
-
* `forcedDetectors` includes `"markdown"`.
|
|
94
|
+
* detector handles (for example one added through `includeExtensions`), Markdown unless
|
|
95
|
+
* `forcedDetectors` includes `"markdown"`, and a `.php` file that does not open with `<?php`.
|
|
96
|
+
*
|
|
97
|
+
* `copyrightWarnings` lists, as `{ file, copyright }`, every additional `@Copyright` a header
|
|
98
|
+
* keeps: a `@Copyright` line after the header's own (in the header or a stacked copy of it)
|
|
99
|
+
* that names another holder. The same values are on the file's entry in `changes` as
|
|
100
|
+
* `extraCopyrights`. A warning is reported on every run that finds it and changes nothing on
|
|
101
|
+
* its own.
|
|
96
102
|
*/
|
|
97
103
|
export type FixHeadersResult = {
|
|
98
104
|
metadata: {
|
|
@@ -119,9 +125,14 @@ export type FixHeadersResult = {
|
|
|
119
125
|
check: boolean;
|
|
120
126
|
filesWithDateDrift?: number;
|
|
121
127
|
dateAdvisories?: number;
|
|
128
|
+
copyrightWarnings: Array<{
|
|
129
|
+
file: string;
|
|
130
|
+
copyright: string;
|
|
131
|
+
}>;
|
|
122
132
|
changes: Array<{
|
|
123
133
|
file: string;
|
|
124
134
|
changed: boolean;
|
|
135
|
+
extraCopyrights?: string[];
|
|
125
136
|
dateIssues?: import("../header/dates.mjs").DateCheckIssue[];
|
|
126
137
|
sample?: {
|
|
127
138
|
previousValue: string | null;
|
|
@@ -2,6 +2,7 @@ export namespace detector {
|
|
|
2
2
|
export let id: string;
|
|
3
3
|
export { extensions };
|
|
4
4
|
export let enabledByDefault: boolean;
|
|
5
|
+
export function keepsAboveHeader(line: any, index: any): boolean;
|
|
5
6
|
export function resolveCommentSyntax(filePath: any): {
|
|
6
7
|
kind: "block";
|
|
7
8
|
blockStart: string;
|
|
@@ -2,6 +2,7 @@ export namespace detector {
|
|
|
2
2
|
export let id: string;
|
|
3
3
|
export { extensions };
|
|
4
4
|
export let enabledByDefault: boolean;
|
|
5
|
+
export function resolvePreservedPrefix(filePath: any, content: any): string;
|
|
5
6
|
export function resolveCommentSyntax(filePath: any): {
|
|
6
7
|
kind: "block";
|
|
7
8
|
blockStart: string;
|
|
@@ -80,9 +80,11 @@ export function getCommentSyntaxForFile(filePath: string, options?: {
|
|
|
80
80
|
blockEnd?: string;
|
|
81
81
|
};
|
|
82
82
|
/**
|
|
83
|
-
* Resolves
|
|
83
|
+
* Resolves the content at the top of a file that stays above the header: the detector's
|
|
84
|
+
* leading block (front matter), then the run of lines at the very top whose position matters
|
|
85
|
+
* (see {@link DetectorProfile}). A line further down is never part of it.
|
|
84
86
|
* @param {string} filePath - File path.
|
|
85
|
-
* @param {string} content -
|
|
87
|
+
* @param {string} content - File content, without a byte order mark.
|
|
86
88
|
* @param {{ language?: string, enabledDetectors?: string[], disabledDetectors?: string[], forcedDetectors?: string[] }} [options={}] - Runtime options.
|
|
87
89
|
* @returns {string} Preserved prefix (possibly empty).
|
|
88
90
|
*/
|
|
@@ -92,6 +94,19 @@ export function getPreservedPrefixForFile(filePath: string, content: string, opt
|
|
|
92
94
|
disabledDetectors?: string[];
|
|
93
95
|
forcedDetectors?: string[];
|
|
94
96
|
}): string;
|
|
97
|
+
/**
|
|
98
|
+
* Says why a file's content cannot carry a header (a PHP file that does not open with `<?php`,
|
|
99
|
+
* where a comment at the top would be output as text), or null when it can.
|
|
100
|
+
* @param {string} filePath - File path.
|
|
101
|
+
* @param {string} content - File content.
|
|
102
|
+
* @param {{ enabledDetectors?: string[], disabledDetectors?: string[], forcedDetectors?: string[] }} [options={}] - Runtime options.
|
|
103
|
+
* @returns {string | null} Skip reason, or null.
|
|
104
|
+
*/
|
|
105
|
+
export function getContentSkipReason(filePath: string, content: string, options?: {
|
|
106
|
+
enabledDetectors?: string[];
|
|
107
|
+
disabledDetectors?: string[];
|
|
108
|
+
forcedDetectors?: string[];
|
|
109
|
+
}): string | null;
|
|
95
110
|
/**
|
|
96
111
|
* @fileoverview Detector registry and shared selector helpers.
|
|
97
112
|
* @module fix-headers/detectors
|
|
@@ -103,10 +118,15 @@ export function getPreservedPrefixForFile(filePath: string, content: string, opt
|
|
|
103
118
|
* enabledByDefault: boolean,
|
|
104
119
|
* requiresForce?: boolean,
|
|
105
120
|
* resolveCommentSyntax: (filePath: string) => ({kind: "block" | "line" | "html", linePrefix?: string, lineSeparator?: string, blockStart?: string, blockLinePrefix?: string, blockEnd?: string} | null),
|
|
106
|
-
* resolvePreservedPrefix?: (filePath: string, content: string) => string
|
|
121
|
+
* resolvePreservedPrefix?: (filePath: string, content: string) => string,
|
|
122
|
+
* keepsAboveHeader?: (line: string, index: number) => boolean,
|
|
123
|
+
* resolveContentSkipReason?: (content: string) => string | null
|
|
107
124
|
* }} DetectorProfile
|
|
108
|
-
* A file-type detector: which extensions it handles and the comment syntax
|
|
109
|
-
*
|
|
125
|
+
* A file-type detector: which extensions it handles and the comment syntax of those files, and
|
|
126
|
+
* what stays above the header: `resolvePreservedPrefix` takes a leading block (front matter),
|
|
127
|
+
* and `keepsAboveHeader` accepts each line of the run at the very top of the file that keeps its
|
|
128
|
+
* place (a shebang, an encoding declaration; editor modelines are accepted for every detector).
|
|
129
|
+
* `resolveContentSkipReason` says why a file's content cannot carry a header at all. Which project a file belongs to is resolved separately,
|
|
110
130
|
* from the manifest drivers in `src/drivers/`. A detector with `requiresForce: true` is used only
|
|
111
131
|
* when its id is listed in the `forcedDetectors` option (see {@link getEnabledDetectors}).
|
|
112
132
|
*/
|
|
@@ -119,8 +139,11 @@ export function getPreservedPrefixForFile(filePath: string, content: string, opt
|
|
|
119
139
|
*/
|
|
120
140
|
export const DETECTOR_PROFILES: DetectorProfile[];
|
|
121
141
|
/**
|
|
122
|
-
* A file-type detector: which extensions it handles and the comment syntax
|
|
123
|
-
*
|
|
142
|
+
* A file-type detector: which extensions it handles and the comment syntax of those files, and
|
|
143
|
+
* what stays above the header: `resolvePreservedPrefix` takes a leading block (front matter),
|
|
144
|
+
* and `keepsAboveHeader` accepts each line of the run at the very top of the file that keeps its
|
|
145
|
+
* place (a shebang, an encoding declaration; editor modelines are accepted for every detector).
|
|
146
|
+
* `resolveContentSkipReason` says why a file's content cannot carry a header at all. Which project a file belongs to is resolved separately,
|
|
124
147
|
* from the manifest drivers in `src/drivers/`. A detector with `requiresForce: true` is used only
|
|
125
148
|
* when its id is listed in the `forcedDetectors` option (see {@link getEnabledDetectors}).
|
|
126
149
|
*/
|
|
@@ -138,4 +161,6 @@ export type DetectorProfile = {
|
|
|
138
161
|
blockEnd?: string;
|
|
139
162
|
} | null);
|
|
140
163
|
resolvePreservedPrefix?: (filePath: string, content: string) => string;
|
|
164
|
+
keepsAboveHeader?: (line: string, index: number) => boolean;
|
|
165
|
+
resolveContentSkipReason?: (content: string) => string | null;
|
|
141
166
|
};
|