@cldmv/fix-headers 2.1.3 → 2.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +215 -68
- package/bin/fix-headers.mjs +15 -14
- package/dist/index.cjs +12 -0
- package/dist/index.mjs +13 -13
- package/package.json +4 -3
- package/types/src/core/file-discovery.d.mts +10 -0
- package/types/src/core/fix-headers.d.mts +13 -1
- package/types/src/detect/project.d.mts +4 -1
- package/types/src/detectors/index.d.mts +40 -7
- package/types/src/detectors/markdown.d.mts +21 -0
- package/types/src/header/parser.d.mts +4 -2
- package/types/src/header/syntax.d.mts +2 -1
- package/types/src/header/template.d.mts +2 -1
package/dist/index.mjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
var Dr=Object.defineProperty;var i=(e,t)=>Dr(e,"name",{value:t,configurable:!0});import{readFile as eo,stat as to,writeFile as ro}from"node:fs/promises";import{relative as gr,resolve as hr}from"node:path";import{readFile as Nr}from"node:fs/promises";import{createRequire as kr}from"node:module";import{dirname as $r,isAbsolute as Ar,resolve as _e}from"node:path";var Cr=3e4,vr=new Set(["localhost","127.0.0.1","[::1]"]);function oe(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}i(oe,"isPlainObject");function ie(e,t){let r={...e};for(let[n,o]of Object.entries(t))n!=="__proto__"&&(r[n]=oe(r[n])&&oe(o)?ie(r[n],o):o);return r}i(ie,"mergeConfig");function Ue(e){return e.kind==="file"?e.path:e.href}i(Ue,"describeSource");async function Fr(e){if(e.kind==="file")return{text:await Nr(e.path,"utf8"),source:e};let t;try{t=await fetch(e.href,{cache:"no-store",redirect:"follow",signal:AbortSignal.timeout(Cr)})}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(Fr,"readSource");function He(e){if(e.protocol==="http:"&&!vr.has(e.hostname))throw new Error(`Refusing to fetch config over plain http: ${e.href} (use https)`);return{kind:"url",href:e.href}}i(He,"toUrlSource");function Lr(e,t){if(/^https?:\/\//i.test(e))return He(new URL(e));if(/^[a-z][a-z\d+.-]+:\/\//i.test(e))throw new Error(`Unsupported extends URL "${e}" in ${Ue(t)}; use https, a file path or a package path`);let r=/^\.{1,2}[\\/]/.test(e);if(t.kind==="url"){if(r||e.startsWith("/"))return He(new URL(e,t.href));throw new Error(`Cannot extend package "${e}" from the remote config ${t.href}; use a URL or a relative path`)}if(r||Ar(e))return{kind:"file",path:_e($r(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})}}i(Lr,"resolveReference");function Pr(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(Pr,"readExtends");async function Be(e,t){let r=Ue(e);if(t.includes(r))throw new Error(`Config extends cycle: ${[...t,r].join(" -> ")}`);let{text:n,source:o}=await Fr(e),a;try{a=JSON.parse(n)}catch(m){throw new Error(`Config ${r} is not valid JSON: ${m.message}`,{cause:m})}if(!oe(a))throw new Error(`Config file must contain a JSON object: ${r}`);let{extends:s,...l}=a,c={};for(let m of Pr(s,r))c=ie(c,await Be(Lr(m,o),[...t,r]));return ie(c,l)}i(Be,"loadSource");function Mr(e,t=process.cwd()){return Be({kind:"file",path:_e(t,e)},[])}i(Mr,"loadConfigFile");async function ze(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 Mr(r,n),...e};return delete o[t],o}i(ze,"applyConfigOption");import{extname as ct}from"node:path";import{extname as jr}from"node:path";var Ye=[".css"];function Rr(e){let t=jr(e).toLowerCase();return Ye.includes(t)?{kind:"block",blockStart:"/*",blockLinePrefix:" * ",blockEnd:" */"}:null}i(Rr,"resolveCssCommentSyntax");var Ge={id:"css",extensions:Ye,enabledByDefault:!0,resolveCommentSyntax(e){return Rr(e)}};import{extname as Ir}from"node:path";var We=[".go"];function Tr(e){let t=Ir(e).toLowerCase();return We.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}i(Tr,"resolveGoCommentSyntax");var Ve={id:"go",extensions:We,enabledByDefault:!0,resolveCommentSyntax(e){return Tr(e)}};import{extname as Or}from"node:path";var Je=[".html",".htm"];function Hr(e){let t=Or(e).toLowerCase();return Je.includes(t)?{kind:"html",blockStart:"<!--",blockLinePrefix:" ",blockEnd:"-->"}:null}i(Hr,"resolveHtmlCommentSyntax");var Ke={id:"html",extensions:Je,enabledByDefault:!0,resolveCommentSyntax(e){return Hr(e)}};import{extname as _r}from"node:path";var qe=[".jsonv",".jsonc",".json5"];function Ur(e){let t=_r(e).toLowerCase();return qe.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}i(Ur,"resolveJsonCommentSyntax");var Xe={id:"json",extensions:qe,enabledByDefault:!0,resolveCommentSyntax(e){return Ur(e)}};import{extname as Br}from"node:path";var Ze=[".js",".mjs",".cjs",".ts",".tsx",".jsx"];function zr(e){let t=Br(e).toLowerCase();return Ze.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}i(zr,"resolveNodeCommentSyntax");function Yr(e,t){let r=t.match(/^#!.*\b(node|bun|deno|tsx|ts-node)\b.*(?:\r?\n|$)/);return r?r[0]:""}i(Yr,"resolveNodePreservedPrefix");var Qe={id:"node",extensions:Ze,enabledByDefault:!0,resolvePreservedPrefix(e,t){return Yr(e,t)},resolveCommentSyntax(e){return zr(e)}};import{extname as Gr}from"node:path";var et=[".php"];function Wr(e){let t=Gr(e).toLowerCase();return et.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}i(Wr,"resolvePhpCommentSyntax");var tt={id:"php",extensions:et,enabledByDefault:!0,resolveCommentSyntax(e){return Wr(e)}};import{extname as Vr}from"node:path";var rt=[".py"];function Jr(e,t){let r=t.match(/^#!.*\bpython(?:\d+(?:\.\d+)*)?\b.*(?:\r?\n|$)/);return r?r[0]:""}i(Jr,"resolvePythonPreservedPrefix");var nt={id:"python",extensions:rt,enabledByDefault:!0,resolvePreservedPrefix(e,t){return Jr(e,t)},resolveCommentSyntax(e){let t=Vr(e).toLowerCase();return rt.includes(t)?{kind:"line",linePrefix:"#"}:null}};import{extname as Kr}from"node:path";var ot=[".rs"];function qr(e){let t=Kr(e).toLowerCase();return ot.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}i(qr,"resolveRustCommentSyntax");var it={id:"rust",extensions:ot,enabledByDefault:!0,resolveCommentSyntax(e){return qr(e)}};import{extname as Xr}from"node:path";var at=[".yaml",".yml"];function Zr(e){let t=Xr(e).toLowerCase();return at.includes(t)?{kind:"line",linePrefix:"#"}:null}i(Zr,"resolveYamlCommentSyntax");var st={id:"yaml",extensions:at,enabledByDefault:!0,resolveCommentSyntax(e){return Zr(e)}};var lt=[Ge,Ve,Ke,Xe,Qe,tt,nt,it,st],Qo=new Map(lt.map(e=>[e.id,e]));function Qr(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(Qr,"applySyntaxOverride");function P(e={}){let t=new Set(Array.isArray(e.enabledDetectors)?e.enabledDetectors:[]),r=new Set(Array.isArray(e.disabledDetectors)?e.disabledDetectors:[]);return lt.filter(n=>t.size>0?t.has(n.id):r.has(n.id)?!1:n.enabledByDefault)}i(P,"getEnabledDetectors");function ut(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(ut,"getAllowedExtensions");function mt(e,t={}){let r=ct(e).toLowerCase(),n=Array.isArray(t.detectors)?t.detectors:P(t);for(let o of n){if(!o.extensions.includes(r))continue;let a=o.resolveCommentSyntax(e);if(a){let s=t.detectorSyntaxOverrides&&typeof t.detectorSyntaxOverrides=="object"?t.detectorSyntaxOverrides:{};return Qr(a,s[o.id])}}return{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}}i(mt,"getCommentSyntaxForFile");function dt(e,t,r={}){let n=ct(e).toLowerCase(),o=P(r);for(let a of o)if(a.extensions.includes(n))return typeof a.resolvePreservedPrefix=="function"?a.resolvePreservedPrefix(e,t):"";return""}i(dt,"getPreservedPrefixForFile");var ft=200,R=1,V=2;function C(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(C,"resolveLayoutCount");import{join as Nt,relative as kt,resolve as fe,sep as me}from"node:path";import{realpath as dn,stat as fn}from"node:fs/promises";import{access as en,readdir as tn,readFile as ii,stat as rn}from"node:fs/promises";import{constants as nn}from"node:fs";import{dirname as ci,join as on,resolve as li}from"node:path";async function ae(e){try{return await en(e,nn.F_OK),!0}catch{return!1}}i(ae,"pathExists");async function se(e,t){let r=[],n=await tn(e,{withFileTypes:!0});for(let o of n){let a=on(e,o.name);if(o.isDirectory()&&t.recursive===!1||o.isDirectory()&&t.ignoreFolders.has(o.name)||o.isDirectory()&&await t.shouldSkipDirectory?.(a,o.name)===!0)continue;if(o.isDirectory()){let c=await se(a,t);r.push(...c);continue}if(!o.isFile())continue;let s=o.name.lastIndexOf(".");if(s===-1)continue;let l=o.name.slice(s).toLowerCase();t.allowedExtensions.has(l)&&r.push(a)}return r}i(se,"walkFiles");async function pt(e){let t=await rn(e);return{createdAt:t.birthtimeMs>0&&t.birthtime<t.mtime?t.birthtime:t.mtime,updatedAt:t.mtime}}i(pt,"readFileDates");import{execFile as an}from"node:child_process";import{lstat as sn,readFile as cn}from"node:fs/promises";import{dirname as gt,isAbsolute as ln,join as xt,relative as bt,resolve as ce,sep as wt}from"node:path";import un from"ignore";function ht(e,t){return new Promise(r=>{an("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(ht,"runGitCommand");function ue(e,t){return bt(e,t).split(wt).join("/")}i(ue,"toPosixRelative");async function Et(e){try{return un().add(await cn(e,"utf8"))}catch{return null}}i(Et,"readIgnoreFile");async function mn(e){return sn(xt(e,".git")).then(()=>!0,()=>!1)}i(mn,"hasGitEntry");function yt(e,t,r){for(let n=e.length-1;n>=0;n--){let{base:o,rules:a}=e[n],s=a.test(`${ue(o,t)}${r?"/":""}`);if(s.ignored||s.unignored)return s.ignored}return!1}i(yt,"matchesRules");async function St(e,t){let r=await Et(xt(e,".gitignore"));return{kind:"rules",nested:!0,excluded:!1,matchers:r?[...t,{base:e,rules:r}]:t}}i(St,"buildRulesContext");async function le(e){let[t,r]=await Promise.all([ht(e,["check-ignore","-q","."]),ht(e,["ls-files","--cached","--others","--exclude-standard","-z"])]);if(t.code!==1||r.code!==0)return St(e,[]);let n=new Set,o=new Set;for(let a of r.stdout.split("\0")){let s=a.endsWith("/")?a.slice(0,-1):a;if(s.length!==0){n.add(s);for(let l=s.indexOf("/");l!==-1;l=s.indexOf("/",l+1))o.add(s.slice(0,l))}}return{kind:"git",root:e,entries:n,dirs:o}}i(le,"resolveScopeContext");function Dt(e){let t=ce(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 le(t);let l=typeof r=="string"?[r]:r.filter(m=>typeof m=="string"),c=[];for(let m of l){let f=await Et(ce(t,m));f&&c.push({base:t,rules:f})}return{kind:"rules",nested:!1,excluded:!1,matchers:c}},"buildRootContext"),a=i(l=>{let c=n.get(l);return c||(c=l===t?o():s(l),n.set(l,c)),c},"contextFor"),s=i(async l=>{let c=await a(gt(l));return c.kind==="git"?c.entries.has(ue(c.root,l))?le(l):c:!c.nested||c.excluded?c:yt(c.matchers,l,!0)?{...c,excluded:!0}:await mn(l)?le(l):St(l,c.matchers)},"deriveContext");return{async isIgnored(l,c){let m=ce(l),f=bt(t,m);if(f.length===0||f===".."||f.startsWith(`..${wt}`)||ln(f))return!1;let p=await a(gt(m));if(p.kind==="git"){let h=ue(p.root,m);return!(p.entries.has(h)||c&&p.dirs.has(h))}return p.excluded||yt(p.matchers,m,c)}}}i(Dt,"createIgnoreFilter");function pn(e){return ut(e)}i(pn,"resolveExtensions");var $t=new Set([".git"]);function de(e){return e.replace(/\\/g,"/").replace(/^\.\//,"").replace(/^\/+/,"").replace(/\/+$/,"")}i(de,"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? })`)}):[]}i(gn,"resolveIncludeFolders");function At(e,t){let r=t instanceof Error?t.message:String(t);console.warn(`fix-headers: skipped include folder "${e}" (${r})`)}i(At,"reportSkippedIncludeFolder");function hn(e,t){if(!Array.isArray(t)||t.length===0)return()=>!1;let r=fe(e),n=[],o=new Set;for(let a of t){if(typeof a!="string")continue;let s=de(a);if(s.length!==0){if(s.includes("/")){n.push(fe(r,s));continue}o.add(s)}}return(a,s)=>{if(o.has(s))return!0;for(let c of n)if(a===c||a.startsWith(`${c}/`))return!0;let l=de(kt(r,a));return n.some(c=>{let m=de(kt(r,c));return l===m||l.startsWith(`${m}/`)})}}i(hn,"buildExclusionMatcher");async function pe(e){let t=pn(e),r=gn(e.includeFolders),n=Array.isArray(e.excludeFolders)?e.excludeFolders:[],o=hn(e.projectRoot,n),a=Dt({root:e.projectRoot,gitignore:e.gitignore}),s=i(async(d,g)=>o(d,g)||await a.isIgnored(d,!0),"shouldSkipDirectory"),l=r.length>0?r.map(d=>({includeFolder:d.path,rootPath:Nt(e.projectRoot,d.path),recursive:d.recursive})):[{includeFolder:".",rootPath:e.projectRoot,recursive:!0}],c=[];for(let d of l){let g=await fn(d.rootPath).catch(S=>S);if(g instanceof Error){if(g.code==="ENOENT"){At(d.includeFolder,g);continue}throw g}if(!g.isDirectory()){At(d.includeFolder,`path is not a directory: ${d.rootPath}`);continue}let w=await dn(d.rootPath).catch(()=>fe(d.rootPath));c.push({...d,realRoot:w})}let m=i((d,g)=>{if(d.realRoot===g.realRoot)return d.recursive||!g.recursive;let w=d.realRoot.endsWith(me)?d.realRoot:`${d.realRoot}${me}`;if(!d.recursive||!g.realRoot.startsWith(w))return!1;let S=d.rootPath;for(let k of g.realRoot.slice(w.length).split(me))if(S=Nt(S,k),$t.has(k)||o(S,k))return!1;return!0},"covers"),f=[...c].sort((d,g)=>d.realRoot.length-g.realRoot.length||Number(g.recursive)-Number(d.recursive)),p=[];for(let d of f)p.some(g=>m(g,d))||p.push(d);let h=[];for(let d of c){if(!p.includes(d))continue;let g=await se(d.rootPath,{allowedExtensions:t,ignoreFolders:$t,shouldSkipDirectory:s,recursive:d.recursive});h.push(...g)}let y=[];for(let d of new Set(h))!o(d,d.split("/").at(-1)||"")&&!await a.isIgnored(d,!1)&&y.push(d);return y}i(pe,"discoverFiles");import{basename as Hn,dirname as _n,extname as Un,resolve as be}from"node:path";import{dirname as Ht,isAbsolute as An,join as _t,relative as Cn,resolve as Ut,sep as vn}from"node:path";import{readFile as yn}from"node:fs/promises";import{join as xn}from"node:path";async function bn(e){try{return await yn(e,"utf8")}catch{return null}}i(bn,"readManifest");async function D(e,t){let r=[];for(let n of t){let o=await bn(xn(e,n));o!==null&&r.push({file:n,content:o})}return r.length>0?{dir:e,manifest:r[0].file,files:r}:null}i(D,"detectManifests");function v(e,t){return e.files.find(r=>r.file===t)?.content??null}i(v,"manifestContent");function b(e){return typeof e=="string"&&e.trim().length>0?e.trim():void 0}i(b,"cleanName");function ge(e){if(typeof e!="string")return;let t=e.search(/[<(]/);return b(t===-1?e:e.slice(0,t))}i(ge,"personName");function J(e){try{return JSON.parse(e)}catch{return}}i(J,"parseJsonManifest");function*he(e,t){let r="";for(let n of e.split(/\r?\n/)){let o=n.trim();if(o.startsWith("[")){let a=o.match(/^\[([^[\]]+)\]/);r=a?a[1].split(".").map(s=>s.trim()).join("."):"";continue}r===t&&(yield o)}}i(he,"sectionLines");function I(e,t,r){let n=new RegExp(`^${r}\\s*=\\s*(?:"([^"\\\\]*)"|'([^']*)')`);for(let o of he(e,t)){let a=o.match(n);if(a)return b(a[1]??a[2])}}i(I,"readTomlString");function ye(e,t,r){let n=new RegExp(`^${r}\\s*[=:](.*)$`);for(let o of he(e,t)){let a=o.match(n);if(a)return b(a[1])}}i(ye,"readIniValue");function wn(e,t,r){let n=new RegExp(`^${r}\\s*=\\s*\\[`),o=null;for(let a of he(e,t)){if(o!==null){o.push(a);continue}let s=a.match(n);s&&(o=[a.slice(s[0].length)])}return o===null?null:o.join(`
|
|
2
|
-
`)}i(
|
|
3
|
-
`,r);r=n===-1?e.length:n+1}else if(/\s/.test(e[r]))r+=1;else break;return r}i(
|
|
4
|
-
`)){let s=a.split(":");if(s[0]==="uid"&&s[1]!=="r"&&s[1]!=="e"&&s[9])return
|
|
5
|
-
`)[0],[o,a]=n.split("|");if(!o||!a)return null;let s=Number.parseInt(a,10);return Number.isNaN(s)?null:{date:
|
|
1
|
+
var Rr=Object.defineProperty;var i=(e,t)=>Rr(e,"name",{value:t,configurable:!0});import{readFile as wo,stat as bo,writeFile as Eo}from"node:fs/promises";import{relative as Te,resolve as Ar}from"node:path";import{readFile as jr}from"node:fs/promises";import{createRequire as Ir}from"node:module";import{dirname as Tr,isAbsolute as Or,resolve as Ke}from"node:path";var _r=3e4,Hr=new Set(["localhost","127.0.0.1","[::1]"]);function ue(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}i(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}i(fe,"mergeConfig");function Xe(e){return e.kind==="file"?e.path:e.href}i(Xe,"describeSource");async function Ur(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(_r)})}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(Ur,"readSource");function qe(e){if(e.protocol==="http:"&&!Hr.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 Br(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 ${Xe(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||Or(e))return{kind:"file",path:Ke(Tr(t.path),e)};try{return{kind:"file",path:Ir(t.path).resolve(e)}}catch(n){throw new Error(`Cannot resolve extends "${e}" from ${t.path}: ${n.message}`,{cause:n})}}i(Br,"resolveReference");function zr(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(zr,"readExtends");async function Ze(e,t){let r=Xe(e);if(t.includes(r))throw new Error(`Config extends cycle: ${[...t,r].join(" -> ")}`);let{text:n,source:o}=await Ur(e),a;try{a=JSON.parse(n)}catch(u){throw new Error(`Config ${r} is not valid JSON: ${u.message}`,{cause:u})}if(!ue(a))throw new Error(`Config file must contain a JSON object: ${r}`);let{extends:s,...l}=a,c={};for(let u of zr(s,r))c=fe(c,await Ze(Br(u,o),[...t,r]));return fe(c,l)}i(Ze,"loadSource");function Yr(e,t=process.cwd()){return Ze({kind:"file",path:Ke(t,e)},[])}i(Yr,"loadConfigFile");async function Qe(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 Yr(r,n),...e};return delete o[t],o}i(Qe,"applyConfigOption");import{extname as me}from"node:path";import{extname as Gr}from"node:path";var et=[".css"];function Wr(e){let t=Gr(e).toLowerCase();return et.includes(t)?{kind:"block",blockStart:"/*",blockLinePrefix:" * ",blockEnd:" */"}:null}i(Wr,"resolveCssCommentSyntax");var tt={id:"css",extensions:et,enabledByDefault:!0,resolveCommentSyntax(e){return Wr(e)}};import{extname as Vr}from"node:path";var rt=[".go"];function Jr(e){let t=Vr(e).toLowerCase();return rt.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}i(Jr,"resolveGoCommentSyntax");var nt={id:"go",extensions:rt,enabledByDefault:!0,resolveCommentSyntax(e){return Jr(e)}};import{extname as qr}from"node:path";var ot=[".html",".htm"];function Kr(e){let t=qr(e).toLowerCase();return ot.includes(t)?{kind:"html",blockStart:"<!--",blockLinePrefix:" ",blockEnd:"-->"}:null}i(Kr,"resolveHtmlCommentSyntax");var it={id:"html",extensions:ot,enabledByDefault:!0,resolveCommentSyntax(e){return Kr(e)}};import{extname as Xr}from"node:path";var at=[".jsonv",".jsonc",".json5"];function Zr(e){let t=Xr(e).toLowerCase();return at.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}i(Zr,"resolveJsonCommentSyntax");var st={id:"json",extensions:at,enabledByDefault:!0,resolveCommentSyntax(e){return Zr(e)}};import{extname as Qr}from"node:path";var ct=[".md",".markdown"];function en(e){let t=Qr(e).toLowerCase();return ct.includes(t)?{kind:"html",blockStart:"<!--",blockLinePrefix:" ",blockEnd:"-->"}:null}i(en,"resolveMarkdownCommentSyntax");function tn(e,t){let r=t.match(/^---\r?\n[\s\S]*?\r?\n---[ \t]*(?:\r?\n|$)/);return r?r[0]:""}i(tn,"resolveMarkdownPreservedPrefix");var lt={id:"markdown",extensions:ct,enabledByDefault:!1,requiresForce:!0,resolvePreservedPrefix(e,t){return tn(e,t)},resolveCommentSyntax(e){return en(e)}};import{extname as rn}from"node:path";var ut=[".js",".mjs",".cjs",".ts",".tsx",".jsx"];function nn(e){let t=rn(e).toLowerCase();return ut.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}i(nn,"resolveNodeCommentSyntax");function on(e,t){let r=t.match(/^#!.*\b(node|bun|deno|tsx|ts-node)\b.*(?:\r?\n|$)/);return r?r[0]:""}i(on,"resolveNodePreservedPrefix");var ft={id:"node",extensions:ut,enabledByDefault:!0,resolvePreservedPrefix(e,t){return on(e,t)},resolveCommentSyntax(e){return nn(e)}};import{extname as an}from"node:path";var mt=[".php"];function sn(e){let t=an(e).toLowerCase();return mt.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}i(sn,"resolvePhpCommentSyntax");var dt={id:"php",extensions:mt,enabledByDefault:!0,resolveCommentSyntax(e){return sn(e)}};import{extname as cn}from"node:path";var pt=[".py"];function ln(e,t){let r=t.match(/^#!.*\bpython(?:\d+(?:\.\d+)*)?\b.*(?:\r?\n|$)/);return r?r[0]:""}i(ln,"resolvePythonPreservedPrefix");var ht={id:"python",extensions:pt,enabledByDefault:!0,resolvePreservedPrefix(e,t){return ln(e,t)},resolveCommentSyntax(e){let t=cn(e).toLowerCase();return pt.includes(t)?{kind:"line",linePrefix:"#"}:null}};import{extname as un}from"node:path";var gt=[".rs"];function fn(e){let t=un(e).toLowerCase();return gt.includes(t)?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}:null}i(fn,"resolveRustCommentSyntax");var yt={id:"rust",extensions:gt,enabledByDefault:!0,resolveCommentSyntax(e){return fn(e)}};import{extname as mn}from"node:path";var xt=[".yaml",".yml"];function dn(e){let t=mn(e).toLowerCase();return xt.includes(t)?{kind:"line",linePrefix:"#"}:null}i(dn,"resolveYamlCommentSyntax");var wt={id:"yaml",extensions:xt,enabledByDefault:!0,resolveCommentSyntax(e){return dn(e)}};var Z=[tt,nt,it,st,lt,ft,dt,ht,yt,wt],pn=new Map(Z.map(e=>[e.id,e]));function hn(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(hn,"applySyntaxOverride");function bt(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(!pn.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(bt,"resolveForcedDetectors");function v(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(v,"getEnabledDetectors");function Et(e={}){if(Array.isArray(e.includeExtensions)&&e.includeExtensions.length>0)return new Set(e.includeExtensions.map(r=>r.toLowerCase()));let t=v(e);return new Set(t.flatMap(r=>r.extensions))}i(Et,"getAllowedExtensions");function St(e,t={}){let r=me(e).toLowerCase();if(v(t).some(s=>s.extensions.includes(r)&&s.resolveCommentSyntax(e)!==null))return null;if(r.length===0)return"the file has no extension, so its comment syntax is unknown";let o=new Set(Array.isArray(t.forcedDetectors)?t.forcedDetectors:[]),a=Z.find(s=>s.requiresForce===!0&&s.extensions.includes(r)&&!o.has(s.id));return a?`${r} files get a header only when forced (--force-detector ${a.id} / forcedDetectors: ["${a.id}"])`:`no enabled detector handles ${r} files`}i(St,"getHeaderSkipReason");function kt(e,t={}){let r=me(e).toLowerCase(),n=Array.isArray(t.detectors)?t.detectors:v(t);for(let o of n){if(!o.extensions.includes(r))continue;let a=o.resolveCommentSyntax(e);if(a){let s=t.detectorSyntaxOverrides&&typeof t.detectorSyntaxOverrides=="object"?t.detectorSyntaxOverrides:{};return hn(a,s[o.id])}}return{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */"}}i(kt,"getCommentSyntaxForFile");function Dt(e,t,r={}){let n=me(e).toLowerCase(),o=v(r);for(let a of o)if(a.extensions.includes(n))return typeof a.resolvePreservedPrefix=="function"?a.resolvePreservedPrefix(e,t):"";return""}i(Dt,"getPreservedPrefixForFile");var $t=200,U=1,Q=2;function F(e,t,r){if(e==null)return r;if(typeof e!="number"||!Number.isInteger(e)||e<0)throw new Error(`${t} must be a whole number of 0 or more, got ${JSON.stringify(e)}`);return e}i(F,"resolveLayoutCount");import{existsSync as An}from"node:fs";import{join as be,relative as It,resolve as Ee,sep as xe}from"node:path";import{realpath as Cn,stat as vn}from"node:fs/promises";import{access as gn,readdir as yn,readFile as Ai,stat as xn}from"node:fs/promises";import{constants as wn}from"node:fs";import{dirname as Fi,join as bn,resolve as Pi}from"node:path";async function de(e){try{return await gn(e,wn.F_OK),!0}catch{return!1}}i(de,"pathExists");async function pe(e,t){let r=[],n=await yn(e,{withFileTypes:!0});for(let o of n){let a=bn(e,o.name);if(o.isDirectory()&&t.recursive===!1||o.isDirectory()&&t.ignoreFolders.has(o.name)||o.isDirectory()&&await t.shouldSkipDirectory?.(a,o.name)===!0)continue;if(o.isDirectory()){let c=await pe(a,t);r.push(...c);continue}if(!o.isFile())continue;let s=o.name.lastIndexOf(".");if(s===-1)continue;let l=o.name.slice(s).toLowerCase();t.allowedExtensions.has(l)&&r.push(a)}return r}i(pe,"walkFiles");async function Nt(e){let t=await xn(e);return{createdAt:t.birthtimeMs>0&&t.birthtime<t.mtime?t.birthtime:t.mtime,updatedAt:t.mtime}}i(Nt,"readFileDates");import{execFile as En}from"node:child_process";import{lstat as Sn,readFile as kn}from"node:fs/promises";import{dirname as At,isAbsolute as Dn,join as Ft,relative as Pt,resolve as he,sep as Lt}from"node:path";import $n from"ignore";function Ct(e,t){return new Promise(r=>{En("git",t,{cwd:e,encoding:"utf8",maxBuffer:Number.POSITIVE_INFINITY},(n,o)=>{if(!n){r({code:0,stdout:o});return}r({code:typeof n.code=="number"?n.code:-1,stdout:""})})})}i(Ct,"runGitCommand");function ye(e,t){return Pt(e,t).split(Lt).join("/")}i(ye,"toPosixRelative");async function Mt(e){try{return $n().add(await kn(e,"utf8"))}catch{return null}}i(Mt,"readIgnoreFile");async function Nn(e){return Sn(Ft(e,".git")).then(()=>!0,()=>!1)}i(Nn,"hasGitEntry");function vt(e,t,r){for(let n=e.length-1;n>=0;n--){let{base:o,rules:a}=e[n],s=a.test(`${ye(o,t)}${r?"/":""}`);if(s.ignored||s.unignored)return s.ignored}return!1}i(vt,"matchesRules");async function Rt(e,t){let r=await Mt(Ft(e,".gitignore"));return{kind:"rules",nested:!0,excluded:!1,matchers:r?[...t,{base:e,rules:r}]:t}}i(Rt,"buildRulesContext");async function ge(e){let[t,r]=await Promise.all([Ct(e,["check-ignore","-q","."]),Ct(e,["ls-files","--cached","--others","--exclude-standard","-z"])]);if(t.code!==1||r.code!==0)return Rt(e,[]);let n=new Set,o=new Set;for(let a of r.stdout.split("\0")){let s=a.endsWith("/")?a.slice(0,-1):a;if(s.length!==0){n.add(s);for(let l=s.indexOf("/");l!==-1;l=s.indexOf("/",l+1))o.add(s.slice(0,l))}}return{kind:"git",root:e,entries:n,dirs:o}}i(ge,"resolveScopeContext");function jt(e){let t=he(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 ge(t);let l=typeof r=="string"?[r]:r.filter(u=>typeof u=="string"),c=[];for(let u of l){let d=await Mt(he(t,u));d&&c.push({base:t,rules:d})}return{kind:"rules",nested:!1,excluded:!1,matchers:c}},"buildRootContext"),a=i(l=>{let c=n.get(l);return c||(c=l===t?o():s(l),n.set(l,c)),c},"contextFor"),s=i(async l=>{let c=await a(At(l));return c.kind==="git"?c.entries.has(ye(c.root,l))?ge(l):c:!c.nested||c.excluded?c:vt(c.matchers,l,!0)?{...c,excluded:!0}:await Nn(l)?ge(l):Rt(l,c.matchers)},"deriveContext");return{async isIgnored(l,c){let u=he(l),d=Pt(t,u);if(d.length===0||d===".."||d.startsWith(`..${Lt}`)||Dn(d))return!1;let p=await a(At(u));if(p.kind==="git"){let g=ye(p.root,u);return!(p.entries.has(g)||c&&p.dirs.has(g))}return p.excluded||vt(p.matchers,u,c)}}}i(jt,"createIgnoreFilter");function Fn(e){return Et(e)}i(Fn,"resolveExtensions");var Pn=Object.freeze(["node_modules","bower_components","jspm_packages",".pnpm-store",".yarn"]),_t=new Set([".git",...Pn]),Ln=Object.freeze(["autoload.php","modules.txt"]);function Tt(e,t){return _t.has(t)?!0:t==="vendor"&&Ln.some(r=>An(be(e,r)))}i(Tt,"isNeverWalked");function we(e){return e.replace(/\\/g,"/").replace(/^\.\//,"").replace(/^\/+/,"").replace(/\/+$/,"")}i(we,"normalizeFolderPath");function Mn(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(Mn,"resolveIncludeFolders");function Ot(e,t){let r=t instanceof Error?t.message:String(t);console.warn(`fix-headers: skipped include folder "${e}" (${r})`)}i(Ot,"reportSkippedIncludeFolder");function Rn(e,t){if(!Array.isArray(t)||t.length===0)return()=>!1;let r=Ee(e),n=[],o=new Set;for(let a of t){if(typeof a!="string")continue;let s=we(a);if(s.length!==0){if(s.includes("/")){n.push(Ee(r,s));continue}o.add(s)}}return(a,s)=>{if(o.has(s))return!0;for(let c of n)if(a===c||a.startsWith(`${c}/`))return!0;let l=we(It(r,a));return n.some(c=>{let u=we(It(r,c));return l===u||l.startsWith(`${u}/`)})}}i(Rn,"buildExclusionMatcher");async function Se(e){let t=Fn(e),r=Mn(e.includeFolders),n=Array.isArray(e.excludeFolders)?e.excludeFolders:[],o=Rn(e.projectRoot,n),a=jt({root:e.projectRoot,gitignore:e.gitignore}),s=i(async(f,h)=>Tt(f,h)||o(f,h)||await a.isIgnored(f,!0),"shouldSkipDirectory"),l=r.length>0?r.map(f=>({includeFolder:f.path,rootPath:be(e.projectRoot,f.path),recursive:f.recursive})):[{includeFolder:".",rootPath:e.projectRoot,recursive:!0}],c=[];for(let f of l){let h=await vn(f.rootPath).catch(S=>S);if(h instanceof Error){if(h.code==="ENOENT"){Ot(f.includeFolder,h);continue}throw h}if(!h.isDirectory()){Ot(f.includeFolder,`path is not a directory: ${f.rootPath}`);continue}let b=await Cn(f.rootPath).catch(()=>Ee(f.rootPath));c.push({...f,realRoot:b})}let u=i((f,h)=>{if(f.realRoot===h.realRoot)return f.recursive||!h.recursive;let b=f.realRoot.endsWith(xe)?f.realRoot:`${f.realRoot}${xe}`;if(!f.recursive||!h.realRoot.startsWith(b))return!1;let S=f.rootPath;for(let N of h.realRoot.slice(b.length).split(xe))if(S=be(S,N),Tt(S,N)||o(S,N))return!1;return!0},"covers"),d=[...c].sort((f,h)=>f.realRoot.length-h.realRoot.length||Number(h.recursive)-Number(f.recursive)),p=[];for(let f of d)p.some(h=>u(h,f))||p.push(f);let g=[];for(let f of c){if(!p.includes(f))continue;let h=await pe(f.rootPath,{allowedExtensions:t,ignoreFolders:_t,shouldSkipDirectory:s,recursive:f.recursive});g.push(...h)}let x=[];for(let f of new Set(g))!o(f,f.split("/").at(-1)||"")&&!await a.isIgnored(f,!1)&&x.push(f);return x}i(Se,"discoverFiles");import{basename as no,dirname as oo,extname as io,resolve as Ae}from"node:path";import{dirname as Xt,isAbsolute as Gn,join as Zt,relative as Wn,resolve as Qt,sep as Vn}from"node:path";import{readFile as jn}from"node:fs/promises";import{join as In}from"node:path";async function Tn(e){try{return await jn(e,"utf8")}catch{return null}}i(Tn,"readManifest");async function D(e,t){let r=[];for(let n of t){let o=await Tn(In(e,n));o!==null&&r.push({file:n,content:o})}return r.length>0?{dir:e,manifest:r[0].file,files:r}:null}i(D,"detectManifests");function P(e,t){return e.files.find(r=>r.file===t)?.content??null}i(P,"manifestContent");function w(e){return typeof e=="string"&&e.trim().length>0?e.trim():void 0}i(w,"cleanName");function ke(e){if(typeof e!="string")return;let t=e.search(/[<(]/);return w(t===-1?e:e.slice(0,t))}i(ke,"personName");function ee(e){try{return JSON.parse(e)}catch{return}}i(ee,"parseJsonManifest");function*De(e,t){let r="";for(let n of e.split(/\r?\n/)){let o=n.trim();if(o.startsWith("[")){let a=o.match(/^\[([^[\]]+)\]/);r=a?a[1].split(".").map(s=>s.trim()).join("."):"";continue}r===t&&(yield o)}}i(De,"sectionLines");function B(e,t,r){let n=new RegExp(`^${r}\\s*=\\s*(?:"([^"\\\\]*)"|'([^']*)')`);for(let o of De(e,t)){let a=o.match(n);if(a)return w(a[1]??a[2])}}i(B,"readTomlString");function $e(e,t,r){let n=new RegExp(`^${r}\\s*[=:](.*)$`);for(let o of De(e,t)){let a=o.match(n);if(a)return w(a[1])}}i($e,"readIniValue");function On(e,t,r){let n=new RegExp(`^${r}\\s*=\\s*\\[`),o=null;for(let a of De(e,t)){if(o!==null){o.push(a);continue}let s=a.match(n);s&&(o=[a.slice(s[0].length)])}return o===null?null:o.join(`
|
|
2
|
+
`)}i(On,"tomlArrayText");function _n(e,t){let r=t;for(;r<e.length;)if(e[r]==="#"){let n=e.indexOf(`
|
|
3
|
+
`,r);r=n===-1?e.length:n+1}else if(/\s/.test(e[r]))r+=1;else break;return r}i(_n,"skipTomlSpace");function z(e,t){let r=On(e,t,"authors");if(r===null)return;let n=r.slice(_n(r,0)),o=n.match(/^(?:"([^"\\\n]*)"|'([^'\n]*)')/);if(o)return ke(o[1]??o[2]);let s=n.match(/^\{([^}\n]*)\}/)?.[1].match(/(?:^|,)\s*name\s*=\s*(?:"([^"\\\n]*)"|'([^'\n]*)')/);return s?w(s[1]??s[2]):void 0}i(z,"readTomlAuthor");var Ht=["go.mod"];function Hn(e){let t=e.match(/^\s*module\s+(.+)$/m);if(t)return w(t[1].replace(/\/\/.*$/,"").trim().replace(/^["`](.*)["`]$/,"$1"))}i(Hn,"readModulePath");var Ut={id:"go",languages:["go"],manifests:Ht,detect(e){return D(e,Ht)},read(e){return{name:Hn(e.files[0].content)}}};var Bt=["package.json"];function Un(e){let t=w(e?.name),r=w(e?.publisher),n=typeof e?.engines?.vscode=="string";return t&&r&&n?`${r}.${t}`:t}i(Un,"readPublishedName");function Bn(e){if(e!==null&&typeof e=="object"){let t=e;return w(t.company)??w(t.name)}return ke(e)}i(Bn,"readAuthorCompany");var zt={id:"node",languages:["node"],manifests:Bt,detect(e){return D(e,Bt)},read(e){let t=ee(e.files[0].content);return{name:Un(t),company:Bn(t?.author)}}};var Yt=["composer.json"],Gt={id:"php",languages:["php"],manifests:Yt,detect(e){return D(e,Yt)},read(e){let t=ee(e.files[0].content),r=t?.authors;return{name:w(t?.name),company:Array.isArray(r)?w(r[0]?.name):void 0}}};var Wt=["pyproject.toml","setup.cfg","setup.py"];function Vt(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(Vt,"readSetupPyArgument");function zn(e){let t=P(e,"pyproject.toml"),r=P(e,"setup.cfg"),n=P(e,"setup.py");return(t===null?void 0:B(t,"project","name")??B(t,"tool.poetry","name"))??(r===null?void 0:$e(r,"metadata","name"))??(n===null?void 0:Vt(n,"name"))}i(zn,"readPythonName");function Yn(e){let t=P(e,"pyproject.toml"),r=P(e,"setup.cfg"),n=P(e,"setup.py");return(t===null?void 0:z(t,"project")??z(t,"tool.poetry"))??(r===null?void 0:$e(r,"metadata","author"))??(n===null?void 0:Vt(n,"author"))}i(Yn,"readPythonCompany");var Jt={id:"python",languages:["python"],manifests:Wt,detect(e){return D(e,Wt)},read(e){return{name:zn(e),company:Yn(e)}}};var qt=["Cargo.toml"],Kt={id:"rust",languages:["rust"],manifests:qt,detect(e){return D(e,qt)},read(e){let t=e.files[0].content;return{name:B(t,"package","name"),company:z(t,"package")}}};var Jn=[zt,Jt,Gt,Kt,Ut],er=["name","company"];async function Ne(e,t,r){let o=(await Promise.all(t.map(async s=>({driver:s,detection:await s.detect(e)})))).filter(s=>s.detection!==null),a=o.filter(s=>typeof r=="string"&&s.driver.languages.includes(r));return[...a,...o.filter(s=>!a.includes(s))]}i(Ne,"claimFolder");function qn(e,t){let r=Wn(t,e);return r!==""&&r!==".."&&!r.startsWith(`..${Vn}`)&&!Gn(r)}i(qn,"isStrictlyInside");async function tr(e,t={}){let r=Array.isArray(t.drivers)?t.drivers:Jn,n=typeof t.scanRoot=="string"?Qt(t.scanRoot):null,o=Qt(e),a=await Ne(o,r,t.language);for(;a.length===0;){if(await de(Zt(o,".git")))return{root:o,marker:".git",drivers:[],fields:{},sources:{}};let d=Xt(o);if(d===o)return null;o=d,a=await Ne(o,r,t.language)}let s={},l={},c=o,u=a;for(;;){for(let{driver:p,detection:g}of u){let x=p.read(g);for(let f of er)s[f]===void 0&&x[f]!==void 0&&(s[f]=x[f],l[f]={driver:p.id,manifest:g.manifest,dir:c})}if(er.every(p=>s[p]!==void 0)||n===null||!qn(c,n)||await de(Zt(c,".git")))break;c=Xt(c),u=await Ne(c,r,t.language)}return{root:o,marker:a[0].detection.manifest,drivers:a.map(d=>d.driver.id),fields:s,sources:l}}i(tr,"resolveManifestProject");import{execFile as Kn}from"node:child_process";import{promisify as Xn}from"node:util";var nr=Xn(Kn);async function $(e,t){try{let{stdout:r}=await nr("git",t,{cwd:e}),n=r.trim();return n.length>0?n:null}catch{return null}}i($,"runGit");function rr(e,t){let r=0;for(let n=t-1;n>=0&&e[n]==="\\";n--)r++;return r%2===1}i(rr,"isEscaped");function Zn(e){let t=e.trim();if(!t.endsWith(")")||rr(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!==")"||rr(t,n))&&(r+=o===")"?1:-1,r===0))return t.slice(0,n).trim()}return t}i(Zn,"stripUidComment");function Qn(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:Zn(o)||o||null,authorEmail:n}}i(Qn,"parseSignerUid");async function eo(e,t){try{let{stdout:r}=await nr(e,t),n=r.trim();return n.length>0?n:null}catch{return null}}i(eo,"runProgram");function to(e){return e.replace(/\\x([0-9a-fA-F]{2})/g,(t,r)=>String.fromCharCode(Number.parseInt(r,16)))}i(to,"decodeColonField");async function ro(e){let t=await $(e,["config","--get","gpg.format"]);if(t!==null&&t!=="openpgp")return null;let r=await $(e,["config","--get","user.signingkey"]);if(!r)return null;let n=await $(e,["config","--get","gpg.openpgp.program"])||await $(e,["config","--get","gpg.program"])||"gpg",o=await eo(n,["--batch","--with-colons","--list-keys",r]);if(!o)return null;for(let a of o.split(`
|
|
4
|
+
`)){let s=a.split(":");if(s[0]==="uid"&&s[1]!=="r"&&s[1]!=="e"&&s[9])return to(s[9])}return null}i(ro,"readSigningKeyUid");async function or(e,t={}){let r=await $(e,["config","--get","user.name"]),n=await $(e,["config","--get","user.email"]);if(t.useGpgSignerAuthor===!0){let o=await ro(e)||await $(e,["log","-1","--format=%GS"]),a=Qn(o||"");r=a.authorName||r,n=n||a.authorEmail}if(!r||!n){let o=await $(e,["log","-1","--format=%an|%ae"]);if(o){let[a,s]=o.split("|");r=r||a||null,n=n||s||null}}return{authorName:r,authorEmail:n}}i(or,"detectGitAuthor");function ir(e){return e.replace(/z$/i,"+00:00")}i(ir,"canonicalGitDate");async function ar(e,t){let r=await $(e,["log","--follow","--format=%aI|%at","--reverse","--",t]);if(!r)return null;let n=r.split(`
|
|
5
|
+
`)[0],[o,a]=n.split("|");if(!o||!a)return null;let s=Number.parseInt(a,10);return Number.isNaN(s)?null:{date:ir(o),timestamp:s}}i(ar,"getGitCreationDate");async function sr(e,t){let r=await $(e,["log","-1","--format=%aI|%at","--",t]);if(!r)return null;let[n,o]=r.split("|");if(!n||!o)return null;let a=Number.parseInt(o,10);return Number.isNaN(a)?null:{date:ir(n),timestamp:a}}i(sr,"getGitLastModifiedDate");function ao(e){return no(e)||"project"}i(ao,"folderName");function so(e,t){if(typeof t!="string")return e;let r=t.trim();return r.length===0||/<[^>]+>/.test(e)?e:`${e} <${r}>`}i(so,"formatAuthorNameWithCompany");async function co(e,t={}){let r=Array.isArray(t.detectors)?t.detectors:v(t),n=typeof t.preferredExtension=="string"?t.preferredExtension.trim().toLowerCase():"",o=n.length>0?r.find(u=>u.extensions.includes(n)):void 0,a=await tr(e,{drivers:t.drivers,language:o?.id,scanRoot:t.scanRoot}),s=a?a.root:Ae(e),l=a?.sources.name,c=a?.sources.company;return{language:o?.id??a?.drivers[0]??"unknown",rootDir:s,marker:a?a.marker:null,projectName:a?.fields.name??ao(s),projectNameSource:l?{from:"manifest",...l}:{from:"folder",dir:s},companyName:a?.fields.company??null,companyNameSource:c?{from:"manifest",...c}:{from:"none"},drivers:a?a.drivers:[]}}i(co,"detectProjectFromMarkers");async function Ce(e={}){let t=e.targetFilePath||e.cwd||process.cwd(),r=Ae(t),n=v(e),o=e.targetFilePath?oo(r):r,a=e.targetFilePath?io(r).toLowerCase():"",s=Ae(e.projectRoot||e.cwd||process.cwd()),l=await co(o,{detectors:n,preferredExtension:a,scanRoot:s}),c=await or(l.rootDir,{useGpgSignerAuthor:e.useGpgSignerAuthor===!0}),u=e.authorName||c.authorName||"Unknown Author",d=typeof e.companyName=="string"?e.companyName.trim():"";return{projectName:e.projectName||l.projectName,projectNameSource:e.projectName?{from:"option"}:l.projectNameSource,language:e.language||l.language,projectRoot:e.projectRoot||l.rootDir,marker:e.marker===void 0?l.marker:e.marker,authorName:so(u,e.company),authorEmail:e.authorEmail||c.authorEmail||"unknown@example.com",companyName:d||l.companyName,companyNameSource:d?{from:"option"}:l.companyNameSource,copyrightStartYear:Number.isInteger(e.copyrightStartYear)?Number(e.copyrightStartYear):null}}i(Ce,"resolveProjectMetadata");function lo(e){return ve({year:e.getFullYear(),month:e.getMonth()+1,day:e.getDate(),hour:e.getHours(),minute:e.getMinutes(),second:e.getSeconds(),offsetMinutes:-e.getTimezoneOffset()})}i(lo,"formatDateWithTimezone");function ve(e){return`${fr(e," ")} ${mr(e.offsetMinutes)}`}i(ve,"formatSpaceDate");function lr(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{ur(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(lr,"assertTimeZone");var cr=new Map;function ur(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(ur,"getZoneFormatter");function Fe(e,t){let r={};for(let o of ur(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(Fe,"toZonedDateParts");function fr(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(fr,"formatWallClock");function mr(e){let t=i(n=>String(n).padStart(2,"0"),"pad"),r=Math.abs(e);return`${e>=0?"+":"-"}${t(Math.floor(r/60))}:${t(r%60)}`}i(mr,"formatOffset");function te(e=new Date){return{date:lo(e),timestamp:Math.floor(e.getTime()/1e3)}}i(te,"toDatePayload");var uo=/^(\d{4})-(\d{2})-(\d{2})(?:T|\s+)(\d{2}):(\d{2}):(\d{2})(?:\.\d+)?\s*(?:(Z)|([+-])(\d{2}):?(\d{2}))$/i;function L(e){let t=uo.exec(e.trim());if(!t)return null;let[r,n,o,a,s,l]=t.slice(1,7).map(Number),c=t[7]?0:Number(t[9])*60+Number(t[10]),u=t[8]==="-"?-c:c,d=new Date(Date.UTC(r,n-1,o,a,s,l));return!(d.getUTCFullYear()===r&&d.getUTCMonth()===n-1&&d.getUTCDate()===o&&d.getUTCHours()===a&&d.getUTCMinutes()===s&&d.getUTCSeconds()===l)||Number(t[10]??0)>59?null:{year:r,month:n,day:o,hour:a,minute:s,second:l,offsetMinutes:u,timestamp:Math.floor(d.getTime()/1e3)-u*60}}i(L,"parseHeaderDate");function Pe(e){return`${fr(e,"T")}${mr(e.offsetMinutes)}`}i(Pe,"formatIsoDate");var fo={"git-created":"git first commit","filesystem-created":"filesystem creation time"};function dr(e,t){let r=e.match(new RegExp(`${t}:[^\\S\\n]*(.*)$`,"m"));return r?r[1].trim():null}i(dr,"readHeaderField");function Le(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(Le,"pickOldestDate");function hr({existing:e,gitCreated:t,filesystemCreated:r,fixCreatedDate:n=!1}){let o=[{source:"git-created",payload:t},{source:"filesystem-created",payload:r}];if(!e)return Le(o);if(!n)return{source:"existing-header",payload:e};let a=L(e.date)?e:null;return Le([{source:"existing-header",payload:a},...o])}i(hr,"resolveCreatedDate");function gr(e,t=null){if(t)return Fe(e.timestamp,t).year;let r=L(e.date);return r?r.year:new Date(e.timestamp*1e3).getFullYear()}i(gr,"dateYear");function pr(e,t,r,n){let o=e.match(/^(.+?)\s*\((\d+)\)$/),a=o?L(o[1]):null;if(!o||!a)return n.push({check:`${r}-format`,field:t,advisory:!1,value:e,message:`${t} value "${e}" is not a "<datetime> (<epoch>)" pair with a recognised datetime`}),null;let s=Number.parseInt(o[2],10);return s!==a.timestamp&&n.push({check:`${r}-epoch`,field:t,advisory:!1,value:e,expected:`${o[1]} (${a.timestamp})`,message:`${t} epoch ${s} does not match ${o[1]} (expected ${a.timestamp})`}),{text:o[1],timestamp:a.timestamp}}i(pr,"checkDateValue");function yr(e,t={},r={}){let n=[],o=dr(e,"@Date"),a=o===null?null:pr(o,"@Date","created",n),s=Le([{source:"git-created",payload:t.gitCreated},{source:"filesystem-created",payload:t.filesystemCreated}]);if(a&&s&&a.timestamp>s.payload.timestamp){let d=fo[s.source];n.push({check:"created-newer-than-source",field:"@Date",advisory:r.strictCreatedDate!==!0,value:o,expected:`${s.payload.date} (${s.payload.timestamp})`,source:s.source,message:`@Date ${a.text} is later than the ${d} ${s.payload.date} (${s.payload.timestamp})`})}let l=dr(e,"@Last modified time"),c=l===null?null:pr(l,"@Last modified time","modified",n),u=t.gitLastModified;return c&&u&&c.timestamp!==u.timestamp&&n.push({check:"modified-git",field:"@Last modified time",advisory:!0,value:l,expected:`${u.date} (${u.timestamp})`,message:`@Last modified time ${c.text} does not match the git last commit ${u.date} (${u.timestamp})`}),n}i(yr,"checkHeaderDates");function Me(e){if(!e)return null;let t=L(e.date);return t&&t.timestamp!==e.timestamp?{date:e.date,timestamp:t.timestamp}:e}i(Me,"repairDateEpoch");function xr(e){let t=L(e.date);return t?{date:Pe(t),timestamp:t.timestamp}:e}i(xr,"normalizeDatePayload");function wr(e,t){let r=L(e.date);if(!r)return e;let n=Fe(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())?Pe(n):ve(n),timestamp:r.timestamp}}i(wr,"convertDatePayload");import{relative as po}from"node:path";import{extname as mo}from"node:path";function Y(e,t={}){let r=mo(e).toLowerCase(),n=F(t.spacing,"spacing",U);return r.length===0?{kind:"block",blockStart:"/**",blockLinePrefix:" * ",blockEnd:" */",spacing:n}:{...kt(e,t),spacing:n}}i(Y,"getHeaderSyntaxForFile");function br(e,t){let r=e.spacing??U;if(e.kind==="line"){let l=e.linePrefix||"#",c=typeof e.lineSeparator=="string"?e.lineSeparator:" ",u=Array.from({length:r},()=>l);return[...u,...t.map(d=>`${l}${c}${d}`),...u].join(`
|
|
6
6
|
`)}let n=e.blockStart||(e.kind==="html"?"<!--":"/**"),o=e.blockLinePrefix||(e.kind==="html"?" ":" * "),a=e.blockEnd||(e.kind==="html"?"-->":" */"),s=Array.from({length:r},()=>o.trimEnd());return[n,...s,...t.map(l=>`${o}${l}`),...s,a].join(`
|
|
7
|
-
`)}i(
|
|
8
|
-
`).slice(0
|
|
9
|
-
`),s=
|
|
10
|
-
`.repeat(s+1),c=i(
|
|
11
|
-
`:`${t}${l}${
|
|
7
|
+
`)}i(br,"renderHeaderLines");function Re(e){let t=`/${po(e.projectRoot,e.absoluteFilePath).replace(/\\/g,"/")}`,r=Y(e.absoluteFilePath,e.syntaxOptions||{language:e.language}),n=e.createdByName||e.authorName,o=e.createdByEmail||e.authorEmail,a=e.lastModifiedByName||e.authorName,s=e.lastModifiedByEmail||e.authorEmail,l=typeof e.companyName=="string"?e.companyName.trim():"",c=l.length>0?`${l} `:"",u=[`@Project: ${e.projectName}`,`@Filename: ${t}`,`@Date: ${e.createdAt.date} (${e.createdAt.timestamp})`,`@Author: ${n}`,`@Email: <${o}>`,"-----",`@Last modified by: ${a} (${s})`,`@Last modified time: ${e.lastModifiedAt.date} (${e.lastModifiedAt.timestamp})`,"-----",`@Copyright: Copyright (c) ${e.copyrightStartYear}-${e.currentYear} ${c}All rights reserved.`];return br(r,u)}i(Re,"buildHeader");var ho=Object.freeze(["projectName","filename","createdAt","authorName","authorEmail","lastModifiedByName","lastModifiedByEmail","lastModifiedAt","copyrightStartYear","copyrightEndYear","companyName"]);function A(e,t){let r=e.match(new RegExp(`@${t}:[ \\t]*(.*)$`,"m")),n=r?r[1].trim():"";return n.length>0?n:null}i(A,"readTag");function go(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(go,"splitLastModifiedBy");function yo(e){let t={startYear:null,endYear:null,companyName:null},r=e?.match(/^Copyright\s+\(c\)\s+(\d{4})/i);if(!r)return t;let n=e.slice(r[0].length),o=n.match(/^\s*-\s*(\d{4})/);o&&(n=n.slice(o[0].length));let a=n.toLowerCase(),s=a.endsWith("all rights reserved.")?20:a.endsWith("all rights reserved")?19:0;return s===0||!/^\s/.test(n)?t:{startYear:r[1],endYear:o?o[1]:null,companyName:n.slice(0,-s).trim()||null}}i(yo,"splitCopyright");function Er(e){let t=go(A(e,"Last modified by")),r=yo(A(e,"Copyright")),n=A(e,"Email");return{projectName:A(e,"Project"),filename:A(e,"Filename"),createdAt:A(e,"Date"),authorName:A(e,"Author"),authorEmail:n===null?null:n.replace(/^<(.*)>$/,"$1"),lastModifiedByName:t.name,lastModifiedByEmail:t.email,lastModifiedAt:A(e,"Last modified time"),copyrightStartYear:r.startYear,copyrightEndYear:r.endYear,companyName:r.companyName}}i(Er,"parseHeaderFields");function Sr(e,t){let r=Er(e??""),n=Er(t);return ho.filter(o=>r[o]!==n[o]).map(o=>({field:o,previous:r[o],detected:n[o]}))}i(Sr,"compareHeaderFields");function re(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}i(re,"escapeRegex");function Dr(e,t,r={}){let n=Dt(e,t,r);return n.length===0?{prefix:"",body:t}:{prefix:n,body:t.slice(n.length)}}i(Dr,"splitPreservedPrefix");function kr(e,t){if(t.kind==="html"){let n=re(t.blockStart||"<!--"),o=re(t.blockEnd||"-->");return e.match(new RegExp(`^${n}[\\s\\S]*?${o}\\n*`))}if(t.kind==="line"){let n=re(t.linePrefix||"#");return e.match(new RegExp(`^(?:${n}.*\\n)+\\n*`))}let r=re((t.blockEnd||" */").trim());return e.match(new RegExp(`^/\\*[\\s\\S]*?${r}\\n*`))}i(kr,"matchHeaderSegment");function je(e,t="",r={}){let{prefix:n,body:o}=Dr(t,e,r),a=o.split(`
|
|
8
|
+
`).slice(0,$t).join(`
|
|
9
|
+
`),s=Y(t,r);if(!kr(a,s))return null;let c=0,u=0;for(;;){let d=a.slice(c),p=kr(d,s);if(!p||!p[0].includes("@Project:"))break;c+=p[0].length,u=c}return u===0?null:{start:n.length,end:n.length+u}}i(je,"findProjectHeader");function Ie(e,t,r="",n={}){let o=je(e,r,n),a=F(n.margin,"margin",Q),s=Y(r,n).kind==="line"?Math.max(1,a):a,l=`
|
|
10
|
+
`.repeat(s+1),c=i(g=>g.trim()===""?`${t}
|
|
11
|
+
`:`${t}${l}${g}`,"join");if(!o){let{prefix:g,body:x}=Dr(r,e,n),f=`${g}${c(x.replace(/^\n+/,""))}`;return{nextContent:f,changed:f!==e}}let u=e.slice(0,o.start),d=e.slice(o.end).replace(/^\n+/,""),p=`${u}${c(d)}`;return{nextContent:p,changed:p!==e}}i(Ie,"replaceOrInsertHeader");function xo(e,t){let r=e.length,n=t.length,o=Array.from({length:r+1},()=>new Array(n+1).fill(0));for(let c=r-1;c>=0;c-=1)for(let u=n-1;u>=0;u-=1)o[c][u]=e[c]===t[u]?o[c+1][u+1]+1:Math.max(o[c+1][u],o[c][u+1]);let a=[],s=0,l=0;for(;s<r&&l<n;)e[s]===t[l]?(a.push({type:" ",line:e[s]}),s+=1,l+=1):o[s+1][l]>=o[s][l+1]?(a.push({type:"-",line:e[s]}),s+=1):(a.push({type:"+",line:t[l]}),l+=1);for(;s<r;s+=1)a.push({type:"-",line:e[s]});for(;l<n;l+=1)a.push({type:"+",line:t[l]});return a}i(xo,"diffLines");function $r(e,t){return`${t===0?e:e+1},${t}`}i($r,"formatRange");function Nr(e,t,r={}){let n=e===null?[]:e.split(`
|
|
12
12
|
`),o=t.split(`
|
|
13
|
-
`),a=
|
|
14
|
-
`)}i(
|
|
15
|
-
`).length-1;
|
|
13
|
+
`),a=xo(n,o),s=Math.max(0,r.context??3),l=r.lineOffset??0,c=[];if(a.forEach((g,x)=>{if(g.type===" ")return;let f=c[c.length-1];f&&x-f.last<=s*2+1?f.last=x:c.push({first:x,last:x})}),c.length===0)return"";let u=r.fromFile??"a",d=r.toFile??"b",p=[`--- ${e===null?"/dev/null":u}`,`+++ ${d}`];for(let g of c){let x=Math.max(0,g.first-s),f=Math.min(a.length,g.last+s+1),h=a.slice(0,x),b=a.slice(x,f),S=h.filter(E=>E.type!=="+").length+l,N=h.filter(E=>E.type!=="-").length+l,M=b.filter(E=>E.type!=="+").length,G=b.filter(E=>E.type!=="-").length;p.push(`@@ -${$r(S,M)} +${$r(N,G)} @@`);for(let E of b)p.push(`${E.type}${E.line}`)}return p.join(`
|
|
14
|
+
`)}i(Nr,"createUnifiedDiff");function So(e){return Qe(e,"configFile")}i(So,"resolveRuntimeOptions");function ko(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(ko,"resolveInputs");function Do(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(Do,"extractHeaderAuthorIdentity");function $o(e){let t=e.match(/@Last modified by:\s*(.+?)\s*\(([^)\n]+)\)\s*$/m);return{authorName:t?.[1]?.trim(),authorEmail:t?.[2]?.trim()}}i($o,"extractHeaderLastModifiedIdentity");function No(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(No,"extractHeaderCreatedAt");function Ao(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(Ao,"extractHeaderLastModifiedAt");async function Cr(e={}){let t=await So(e),r=t.timezone===void 0||t.timezone===null?null:lr(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=bt(t.forcedDetectors),a=Ar(t.projectRoot||t.cwd||process.cwd()),s=await Ce({...t,cwd:a});F(t.spacing,"spacing",U),F(t.margin,"margin",Q);let l=t.check===!0,c=l||t.dryRun===!0,u=t.fixCreatedDate===!0,d=i(y=>y,"keepDate"),p=t.normalizeDateFormat===!0?xr:d,g=r?y=>wr(y,r):d,x=n?g:d,f={language:s.language,enabledDetectors:t.enabledDetectors,disabledDetectors:t.disabledDetectors,forcedDetectors:o,includeFolders:t.includeFolders,excludeFolders:t.excludeFolders,includeExtensions:t.includeExtensions,gitignore:t.gitignore},h=ko(t.input),b;if(h.length>0){let y=new Set;for(let R of h){let m=Ar(a,R),j=await bo(m).catch(()=>null);if(!j)throw new Error(`Input path does not exist: ${R}`);if(j.isFile())y.add(m);else if(j.isDirectory())for(let I of await Se({...f,projectRoot:m}))y.add(I);else throw new Error(`Input path must be a file or directory: ${R}`)}b=Array.from(y)}else b=await Se({...f,projectRoot:a});let S=new Date().getFullYear(),N=[],M=[],G=new Set,E=0,Oe=0,_e=0;for(let y of b){let R=St(y,{enabledDetectors:t.enabledDetectors,disabledDetectors:t.disabledDetectors,forcedDetectors:o});if(R!==null){M.push({file:Te(a,y),reason:R});continue}let m=await Ce({...t,cwd:a,targetFilePath:y});G.add(`${m.language}:${m.projectRoot}`);let j=Te(a,y),I=await wo(y,"utf8"),O={language:m.language,enabledDetectors:t.enabledDetectors,disabledDetectors:t.disabledDetectors,forcedDetectors:o,detectorSyntaxOverrides:t.detectorSyntaxOverrides,spacing:t.spacing,margin:t.margin},ne=je(I,y,O),k=ne?I.slice(ne.start,ne.end):"",W=k.length>0?Do(k):{},V=k.length>0?$o(k):{},vr=k.length>0?No(k):null,Fr=k.length>0?Ao(k):null,He=await Nt(y),Ue=Te(m.projectRoot,y),Be=await ar(m.projectRoot,Ue),oe=await sr(m.projectRoot,Ue),ze=te(He.createdAt),ie=hr({existing:Me(vr),gitCreated:Be,filesystemCreated:ze,fixCreatedDate:u}),ae=Me(Fr),Ye=ie.source,Pr=ae?"existing-header":oe?"git-last-modified":"filesystem-updated",J=p(Ye==="existing-header"?x(ie.payload):g(ie.payload)),Lr=m.copyrightStartYear===null?"created-date":"option",se=m.copyrightStartYear??gr(J,r),Ge=p(ae?x(ae):g(oe||te(He.updatedAt))),q=t.forceAuthorUpdate===!0,K=t.forceLastModifiedAuthorUpdate===!0,We=Re({absoluteFilePath:y,language:m.language,syntaxOptions:O,projectRoot:m.projectRoot,projectName:m.projectName,createdByName:q?m.authorName:W.authorName||m.authorName,createdByEmail:q?m.authorEmail:W.authorEmail||m.authorEmail,lastModifiedByName:K?m.authorName:V.authorName||m.authorName,lastModifiedByEmail:K?m.authorEmail:V.authorEmail||m.authorEmail,authorName:m.authorName,authorEmail:m.authorEmail,createdAt:J,lastModifiedAt:Ge,copyrightStartYear:se,companyName:m.companyName,currentYear:S}),Ve=Ie(I,We,y,O),X=Ve.changed,Je=X?p(g(te(new Date))):Ge,Mr=X?"current-time-on-change":Pr,_=X?Re({absoluteFilePath:y,language:m.language,syntaxOptions:O,projectRoot:m.projectRoot,projectName:m.projectName,createdByName:q?m.authorName:W.authorName||m.authorName,createdByEmail:q?m.authorEmail:W.authorEmail||m.authorEmail,lastModifiedByName:K?m.authorName:V.authorName||m.authorName,lastModifiedByEmail:K?m.authorEmail:V.authorEmail||m.authorEmail,authorName:m.authorName,authorEmail:m.authorEmail,createdAt:J,lastModifiedAt:Je,copyrightStartYear:se,companyName:m.companyName,currentYear:S}):We,T=X?Ie(I,_,y,O):Ve,ce={file:j,changed:T.changed};if(l){let C=yr(k,{gitCreated:Be,gitLastModified:oe,filesystemCreated:ze},{strictCreatedDate:t.strictCreatedDate===!0}),H=C.filter(le=>le.advisory).length;ce.dateIssues=C,_e+=H,Oe+=C.length>H?1:0}if(t.sampleOutput===!0&&T.changed){let C=k.length>0?k.trimEnd():null,H=j.replace(/\\/g,"/"),le=T.nextContent.slice(0,T.nextContent.indexOf(_)).split(`
|
|
15
|
+
`).length-1;ce.sample={previousValue:C,newValue:_,diff:Nr(C,_,{fromFile:`a/${H}`,toFile:`b/${H}`,lineOffset:le}),issues:Sr(C,_),detectedValues:{projectName:m.projectName,projectNameSource:m.projectNameSource,language:m.language,projectRoot:m.projectRoot,marker:m.marker,authorName:m.authorName,authorEmail:m.authorEmail,companyName:m.companyName,companyNameSource:m.companyNameSource,copyrightStartYear:se,copyrightStartYearSource:Lr,createdAtSource:Ye,lastModifiedAtSource:Mr,createdAt:J,lastModifiedAt:Je}}}N.push(ce),T.changed&&(E+=1,c||await Eo(y,T.nextContent,"utf8"))}return{metadata:s,detectedProjects:Array.from(G),filesScanned:b.length-M.length,filesUpdated:E,filesSkipped:M.length,dryRun:c,check:l,...l?{filesWithDateDrift:Oe,dateAdvisories:_e}:{},changes:N,skipped:M}}i(Cr,"fixHeaders");function Co(e){return Cr(e)}i(Co,"fixHeaders");var ys=Co;export{ys as default,Co as fixHeaders};
|
|
16
16
|
//# sourceMappingURL=index.mjs.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cldmv/fix-headers",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.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",
|
|
@@ -30,9 +30,10 @@
|
|
|
30
30
|
},
|
|
31
31
|
"scripts": {
|
|
32
32
|
"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
|
-
"test": "node tests/run-vitest.mjs",
|
|
33
|
+
"test": "node tests/run-vitest.mjs && npm run test:cjs",
|
|
34
|
+
"test:cjs": "npm run build && node --test tests/cjs/entry.test.cjs",
|
|
34
35
|
"test:watch": "vitest --config .configs/vitest.config.mjs",
|
|
35
|
-
"coverage": "node tests/run-vitest.mjs --coverage-quiet",
|
|
36
|
+
"coverage": "node tests/run-vitest.mjs --coverage-quiet && npm run test:cjs",
|
|
36
37
|
"ci:coverage": "npm run coverage",
|
|
37
38
|
"types:build": "tsc -p .configs/tsconfig.json --noCheck",
|
|
38
39
|
"types:check": "tsc -p .configs/tsconfig.json --noEmit",
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* includeExtensions?: string[],
|
|
7
7
|
* enabledDetectors?: string[],
|
|
8
8
|
* disabledDetectors?: string[],
|
|
9
|
+
* forcedDetectors?: string[],
|
|
9
10
|
* includeFolders?: IncludeFolderEntry[],
|
|
10
11
|
* excludeFolders?: string[],
|
|
11
12
|
* gitignore?: boolean | string | string[]
|
|
@@ -23,10 +24,19 @@ export function discoverFiles(options: {
|
|
|
23
24
|
includeExtensions?: string[];
|
|
24
25
|
enabledDetectors?: string[];
|
|
25
26
|
disabledDetectors?: string[];
|
|
27
|
+
forcedDetectors?: string[];
|
|
26
28
|
includeFolders?: IncludeFolderEntry[];
|
|
27
29
|
excludeFolders?: string[];
|
|
28
30
|
gitignore?: boolean | string | string[];
|
|
29
31
|
}): Promise<string[]>;
|
|
32
|
+
/**
|
|
33
|
+
* Package-manager dependency folders. They hold installed third-party code, never the project's
|
|
34
|
+
* own source, so discovery skips them at any depth whatever the ignore files say (a project with
|
|
35
|
+
* no `.gitignore`, a sub-package's own `node_modules`, a tracked dependency folder). A folder
|
|
36
|
+
* named explicitly through `includeFolders` / `input` is still processed.
|
|
37
|
+
* @type {readonly string[]}
|
|
38
|
+
*/
|
|
39
|
+
export const DEPENDENCY_FOLDERS: readonly string[];
|
|
30
40
|
/**
|
|
31
41
|
* An `includeFolders` entry: a project-relative folder path (walked recursively), or an object
|
|
32
42
|
* form that can switch recursion off so only the folder's own files are included.
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
export function fixHeaders(options?: FixHeadersOptions): Promise<FixHeadersResult>;
|
|
11
11
|
export type FixHeadersOptions = {
|
|
12
12
|
cwd?: string;
|
|
13
|
-
input?: string;
|
|
13
|
+
input?: string | string[];
|
|
14
14
|
dryRun?: boolean;
|
|
15
15
|
check?: boolean;
|
|
16
16
|
fixCreatedDate?: boolean;
|
|
@@ -25,6 +25,7 @@ export type FixHeadersOptions = {
|
|
|
25
25
|
useGpgSignerAuthor?: boolean;
|
|
26
26
|
enabledDetectors?: string[];
|
|
27
27
|
disabledDetectors?: string[];
|
|
28
|
+
forcedDetectors?: string[];
|
|
28
29
|
detectorSyntaxOverrides?: Record<string, {
|
|
29
30
|
linePrefix?: string;
|
|
30
31
|
lineSeparator?: string;
|
|
@@ -85,6 +86,12 @@ export type DateRewrite = (payload: {
|
|
|
85
86
|
* `"created-date"` (the year of the file's `@Date`).
|
|
86
87
|
*
|
|
87
88
|
* `metadata.copyrightStartYear` is the `copyrightStartYear` option, or null when it is not set.
|
|
89
|
+
*
|
|
90
|
+
* Files whose format cannot carry the header comment are not processed: each is listed in
|
|
91
|
+
* `skipped` as `{ file, reason }` and counted in `filesSkipped`, not in `filesScanned` or
|
|
92
|
+
* `changes`. That covers strict `.json`, files with no extension or an extension no enabled
|
|
93
|
+
* detector handles (for example one added through `includeExtensions`), and Markdown unless
|
|
94
|
+
* `forcedDetectors` includes `"markdown"`.
|
|
88
95
|
*/
|
|
89
96
|
export type FixHeadersResult = {
|
|
90
97
|
metadata: {
|
|
@@ -102,6 +109,11 @@ export type FixHeadersResult = {
|
|
|
102
109
|
detectedProjects: string[];
|
|
103
110
|
filesScanned: number;
|
|
104
111
|
filesUpdated: number;
|
|
112
|
+
filesSkipped: number;
|
|
113
|
+
skipped: Array<{
|
|
114
|
+
file: string;
|
|
115
|
+
reason: string;
|
|
116
|
+
}>;
|
|
105
117
|
dryRun: boolean;
|
|
106
118
|
check: boolean;
|
|
107
119
|
filesWithDateDrift?: number;
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* folder's name. The copyright holder (`companyName`) comes from the manifests' authors the same
|
|
10
10
|
* way, and is null when none of them provides one.
|
|
11
11
|
* @param {string} cwd - Starting directory (a file's folder, or the scan root).
|
|
12
|
-
* @param {{ detectors?: { id: string, extensions: string[] }[], enabledDetectors?: string[], disabledDetectors?: string[], preferredExtension?: string, drivers?: import("../drivers/index.mjs").ManifestDriver[], scanRoot?: string }} [options={}] - Detection options. `scanRoot` bounds how far values missing from the nearest manifests are looked up in ancestor folders; without it they aren't.
|
|
12
|
+
* @param {{ detectors?: { id: string, extensions: string[] }[], enabledDetectors?: string[], disabledDetectors?: string[], forcedDetectors?: string[], preferredExtension?: string, drivers?: import("../drivers/index.mjs").ManifestDriver[], scanRoot?: string }} [options={}] - Detection options. `scanRoot` bounds how far values missing from the nearest manifests are looked up in ancestor folders; without it they aren't.
|
|
13
13
|
* @returns {Promise<{
|
|
14
14
|
* language: string,
|
|
15
15
|
* rootDir: string,
|
|
@@ -28,6 +28,7 @@ export function detectProjectFromMarkers(cwd: string, options?: {
|
|
|
28
28
|
}[];
|
|
29
29
|
enabledDetectors?: string[];
|
|
30
30
|
disabledDetectors?: string[];
|
|
31
|
+
forcedDetectors?: string[];
|
|
31
32
|
preferredExtension?: string;
|
|
32
33
|
drivers?: import("../drivers/index.mjs").ManifestDriver[];
|
|
33
34
|
scanRoot?: string;
|
|
@@ -48,6 +49,7 @@ export function detectProjectFromMarkers(cwd: string, options?: {
|
|
|
48
49
|
* targetFilePath?: string,
|
|
49
50
|
* enabledDetectors?: string[],
|
|
50
51
|
* disabledDetectors?: string[],
|
|
52
|
+
* forcedDetectors?: string[],
|
|
51
53
|
* projectName?: string,
|
|
52
54
|
* language?: string,
|
|
53
55
|
* projectRoot?: string,
|
|
@@ -80,6 +82,7 @@ export function resolveProjectMetadata(options?: {
|
|
|
80
82
|
targetFilePath?: string;
|
|
81
83
|
enabledDetectors?: string[];
|
|
82
84
|
disabledDetectors?: string[];
|
|
85
|
+
forcedDetectors?: string[];
|
|
83
86
|
projectName?: string;
|
|
84
87
|
language?: string;
|
|
85
88
|
projectRoot?: string;
|
|
@@ -1,22 +1,49 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* Validates the `forcedDetectors` option: each id must name a force-only detector
|
|
3
|
+
* (`requiresForce: true`). Forcing a detector that is used without forcing, or one that does
|
|
4
|
+
* not exist, is reported instead of silently doing nothing.
|
|
5
|
+
* @param {unknown} value - Option value.
|
|
6
|
+
* @returns {string[]} De-duplicated detector ids (empty when unset).
|
|
7
|
+
*/
|
|
8
|
+
export function resolveForcedDetectors(value: unknown): string[];
|
|
9
|
+
/**
|
|
10
|
+
* Gets enabled detector profiles based on include/exclude options. A force-only detector
|
|
11
|
+
* (`requiresForce: true`) is enabled only when `forcedDetectors` names it, and then even when
|
|
12
|
+
* `enabledDetectors` does not; `disabledDetectors` still turns it off. Listing it in
|
|
13
|
+
* `enabledDetectors` alone does not force it.
|
|
14
|
+
* @param {{ enabledDetectors?: string[], disabledDetectors?: string[], forcedDetectors?: string[] }} [options={}] - Runtime options.
|
|
4
15
|
* @returns {typeof DETECTOR_PROFILES} Enabled detector list.
|
|
5
16
|
*/
|
|
6
17
|
export function getEnabledDetectors(options?: {
|
|
7
18
|
enabledDetectors?: string[];
|
|
8
19
|
disabledDetectors?: string[];
|
|
20
|
+
forcedDetectors?: string[];
|
|
9
21
|
}): typeof DETECTOR_PROFILES;
|
|
10
22
|
/**
|
|
11
23
|
* Gets allowed file extensions for enabled detectors.
|
|
12
|
-
* @param {{ enabledDetectors?: string[], disabledDetectors?: string[], includeExtensions?: string[] }} [options={}] - Runtime options.
|
|
24
|
+
* @param {{ enabledDetectors?: string[], disabledDetectors?: string[], forcedDetectors?: string[], includeExtensions?: string[] }} [options={}] - Runtime options.
|
|
13
25
|
* @returns {Set<string>} Allowed extensions.
|
|
14
26
|
*/
|
|
15
27
|
export function getAllowedExtensions(options?: {
|
|
16
28
|
enabledDetectors?: string[];
|
|
17
29
|
disabledDetectors?: string[];
|
|
30
|
+
forcedDetectors?: string[];
|
|
18
31
|
includeExtensions?: string[];
|
|
19
32
|
}): Set<string>;
|
|
33
|
+
/**
|
|
34
|
+
* Says why a file cannot be given a header, or returns null when it can. A file gets a header
|
|
35
|
+
* only when an enabled detector handles its extension and supplies a comment syntax; anything
|
|
36
|
+
* else (strict `.json`, `.txt`, extensionless files, a disabled detector's extensions, Markdown
|
|
37
|
+
* that is not forced) is skipped rather than given a comment its format cannot carry.
|
|
38
|
+
* @param {string} filePath - File path.
|
|
39
|
+
* @param {{ enabledDetectors?: string[], disabledDetectors?: string[], forcedDetectors?: string[] }} [options={}] - Runtime options.
|
|
40
|
+
* @returns {string | null} Skip reason, or null when the file can carry a header.
|
|
41
|
+
*/
|
|
42
|
+
export function getHeaderSkipReason(filePath: string, options?: {
|
|
43
|
+
enabledDetectors?: string[];
|
|
44
|
+
disabledDetectors?: string[];
|
|
45
|
+
forcedDetectors?: string[];
|
|
46
|
+
}): string | null;
|
|
20
47
|
/**
|
|
21
48
|
* Gets a detector by id.
|
|
22
49
|
* @param {string} id - Detector id.
|
|
@@ -26,13 +53,14 @@ export function getDetectorById(id: string): (typeof DETECTOR_PROFILES)[number]
|
|
|
26
53
|
/**
|
|
27
54
|
* Resolves comment syntax for a file path using detector-specific templates.
|
|
28
55
|
* @param {string} filePath - File path.
|
|
29
|
-
* @param {{ language?: string, enabledDetectors?: string[], disabledDetectors?: string[], detectors?: DetectorProfile[], detectorSyntaxOverrides?: Record<string, { linePrefix?: string, lineSeparator?: string, blockStart?: string, blockLinePrefix?: string, blockEnd?: string }>, spacing?: number, margin?: number }} [options={}] - Runtime options. `detectors` overrides the enabled-detector set (matching {@link detectProjectFromMarkers}).
|
|
56
|
+
* @param {{ language?: string, enabledDetectors?: string[], disabledDetectors?: string[], forcedDetectors?: string[], detectors?: DetectorProfile[], detectorSyntaxOverrides?: Record<string, { linePrefix?: string, lineSeparator?: string, blockStart?: string, blockLinePrefix?: string, blockEnd?: string }>, spacing?: number, margin?: number }} [options={}] - Runtime options. `detectors` overrides the enabled-detector set (matching {@link detectProjectFromMarkers}).
|
|
30
57
|
* @returns {{kind: "block" | "line" | "html", linePrefix?: string, lineSeparator?: string, blockStart?: string, blockLinePrefix?: string, blockEnd?: string}} Syntax descriptor.
|
|
31
58
|
*/
|
|
32
59
|
export function getCommentSyntaxForFile(filePath: string, options?: {
|
|
33
60
|
language?: string;
|
|
34
61
|
enabledDetectors?: string[];
|
|
35
62
|
disabledDetectors?: string[];
|
|
63
|
+
forcedDetectors?: string[];
|
|
36
64
|
detectors?: DetectorProfile[];
|
|
37
65
|
detectorSyntaxOverrides?: Record<string, {
|
|
38
66
|
linePrefix?: string;
|
|
@@ -55,13 +83,14 @@ export function getCommentSyntaxForFile(filePath: string, options?: {
|
|
|
55
83
|
* Resolves detector-specific leading content that must be preserved above inserted headers.
|
|
56
84
|
* @param {string} filePath - File path.
|
|
57
85
|
* @param {string} content - Full file content.
|
|
58
|
-
* @param {{ language?: string, enabledDetectors?: string[], disabledDetectors?: string[] }} [options={}] - Runtime options.
|
|
86
|
+
* @param {{ language?: string, enabledDetectors?: string[], disabledDetectors?: string[], forcedDetectors?: string[] }} [options={}] - Runtime options.
|
|
59
87
|
* @returns {string} Preserved prefix (possibly empty).
|
|
60
88
|
*/
|
|
61
89
|
export function getPreservedPrefixForFile(filePath: string, content: string, options?: {
|
|
62
90
|
language?: string;
|
|
63
91
|
enabledDetectors?: string[];
|
|
64
92
|
disabledDetectors?: string[];
|
|
93
|
+
forcedDetectors?: string[];
|
|
65
94
|
}): string;
|
|
66
95
|
/**
|
|
67
96
|
* @fileoverview Detector registry and shared selector helpers.
|
|
@@ -72,12 +101,14 @@ export function getPreservedPrefixForFile(filePath: string, content: string, opt
|
|
|
72
101
|
* id: string,
|
|
73
102
|
* extensions: string[],
|
|
74
103
|
* enabledByDefault: boolean,
|
|
104
|
+
* requiresForce?: boolean,
|
|
75
105
|
* resolveCommentSyntax: (filePath: string) => ({kind: "block" | "line" | "html", linePrefix?: string, lineSeparator?: string, blockStart?: string, blockLinePrefix?: string, blockEnd?: string} | null),
|
|
76
106
|
* resolvePreservedPrefix?: (filePath: string, content: string) => string
|
|
77
107
|
* }} DetectorProfile
|
|
78
108
|
* A file-type detector: which extensions it handles and the comment syntax (and preserved
|
|
79
109
|
* leading prefix) of those files. Which project a file belongs to is resolved separately,
|
|
80
|
-
* from the manifest drivers in `src/drivers/`.
|
|
110
|
+
* from the manifest drivers in `src/drivers/`. A detector with `requiresForce: true` is used only
|
|
111
|
+
* when its id is listed in the `forcedDetectors` option (see {@link getEnabledDetectors}).
|
|
81
112
|
*/
|
|
82
113
|
/**
|
|
83
114
|
* Registered detector profiles, in alphabetical order by module name. Imported
|
|
@@ -90,12 +121,14 @@ export const DETECTOR_PROFILES: DetectorProfile[];
|
|
|
90
121
|
/**
|
|
91
122
|
* A file-type detector: which extensions it handles and the comment syntax (and preserved
|
|
92
123
|
* leading prefix) of those files. Which project a file belongs to is resolved separately,
|
|
93
|
-
* from the manifest drivers in `src/drivers/`.
|
|
124
|
+
* from the manifest drivers in `src/drivers/`. A detector with `requiresForce: true` is used only
|
|
125
|
+
* when its id is listed in the `forcedDetectors` option (see {@link getEnabledDetectors}).
|
|
94
126
|
*/
|
|
95
127
|
export type DetectorProfile = {
|
|
96
128
|
id: string;
|
|
97
129
|
extensions: string[];
|
|
98
130
|
enabledByDefault: boolean;
|
|
131
|
+
requiresForce?: boolean;
|
|
99
132
|
resolveCommentSyntax: (filePath: string) => ({
|
|
100
133
|
kind: "block" | "line" | "html";
|
|
101
134
|
linePrefix?: string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export namespace detector {
|
|
2
|
+
export let id: string;
|
|
3
|
+
export { extensions };
|
|
4
|
+
export let enabledByDefault: boolean;
|
|
5
|
+
export let requiresForce: boolean;
|
|
6
|
+
export function resolvePreservedPrefix(filePath: any, content: any): string;
|
|
7
|
+
export function resolveCommentSyntax(filePath: any): {
|
|
8
|
+
kind: "html";
|
|
9
|
+
blockStart: string;
|
|
10
|
+
blockLinePrefix: string;
|
|
11
|
+
blockEnd: string;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* @fileoverview Markdown detector implementation. Force-only: Markdown files get a header
|
|
16
|
+
* only when this detector is named in `forcedDetectors` (CLI `--force-detector markdown`),
|
|
17
|
+
* and then as an HTML comment, which Markdown renderers do not display.
|
|
18
|
+
* @module fix-headers/detectors/markdown
|
|
19
|
+
*/
|
|
20
|
+
declare const extensions: string[];
|
|
21
|
+
export {};
|
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
* Finds the first top-level project header block in a file.
|
|
3
3
|
* @param {string} content - File content.
|
|
4
4
|
* @param {string} [filePath=""] - File path used for syntax selection.
|
|
5
|
-
* @param {{ language?: string, enabledDetectors?: string[], disabledDetectors?: string[], detectorSyntaxOverrides?: Record<string, { linePrefix?: string, lineSeparator?: string, blockStart?: string, blockLinePrefix?: string, blockEnd?: string }>, spacing?: number, margin?: number }} [syntaxOptions={}] - Syntax resolution options.
|
|
5
|
+
* @param {{ language?: string, enabledDetectors?: string[], disabledDetectors?: string[], forcedDetectors?: string[], detectorSyntaxOverrides?: Record<string, { linePrefix?: string, lineSeparator?: string, blockStart?: string, blockLinePrefix?: string, blockEnd?: string }>, spacing?: number, margin?: number }} [syntaxOptions={}] - Syntax resolution options.
|
|
6
6
|
* @returns {{start: number, end: number} | null} Header location.
|
|
7
7
|
*/
|
|
8
8
|
export function findProjectHeader(content: string, filePath?: string, syntaxOptions?: {
|
|
9
9
|
language?: string;
|
|
10
10
|
enabledDetectors?: string[];
|
|
11
11
|
disabledDetectors?: string[];
|
|
12
|
+
forcedDetectors?: string[];
|
|
12
13
|
detectorSyntaxOverrides?: Record<string, {
|
|
13
14
|
linePrefix?: string;
|
|
14
15
|
lineSeparator?: string;
|
|
@@ -27,13 +28,14 @@ export function findProjectHeader(content: string, filePath?: string, syntaxOpti
|
|
|
27
28
|
* @param {string} content - Original file content.
|
|
28
29
|
* @param {string} newHeader - Generated header text.
|
|
29
30
|
* @param {string} [filePath=""] - File path used for syntax selection.
|
|
30
|
-
* @param {{ language?: string, enabledDetectors?: string[], disabledDetectors?: string[], detectorSyntaxOverrides?: Record<string, { linePrefix?: string, lineSeparator?: string, blockStart?: string, blockLinePrefix?: string, blockEnd?: string }>, spacing?: number, margin?: number }} [syntaxOptions={}] - Syntax resolution options.
|
|
31
|
+
* @param {{ language?: string, enabledDetectors?: string[], disabledDetectors?: string[], forcedDetectors?: string[], detectorSyntaxOverrides?: Record<string, { linePrefix?: string, lineSeparator?: string, blockStart?: string, blockLinePrefix?: string, blockEnd?: string }>, spacing?: number, margin?: number }} [syntaxOptions={}] - Syntax resolution options.
|
|
31
32
|
* @returns {{nextContent: string, changed: boolean}} Updated content result.
|
|
32
33
|
*/
|
|
33
34
|
export function replaceOrInsertHeader(content: string, newHeader: string, filePath?: string, syntaxOptions?: {
|
|
34
35
|
language?: string;
|
|
35
36
|
enabledDetectors?: string[];
|
|
36
37
|
disabledDetectors?: string[];
|
|
38
|
+
forcedDetectors?: string[];
|
|
37
39
|
detectorSyntaxOverrides?: Record<string, {
|
|
38
40
|
linePrefix?: string;
|
|
39
41
|
lineSeparator?: string;
|
|
@@ -16,13 +16,14 @@
|
|
|
16
16
|
/**
|
|
17
17
|
* Resolves comment syntax for a file path based on extension.
|
|
18
18
|
* @param {string} filePath - Absolute or relative file path.
|
|
19
|
-
* @param {{ language?: string, enabledDetectors?: string[], disabledDetectors?: string[], detectorSyntaxOverrides?: Record<string, { linePrefix?: string, lineSeparator?: string, blockStart?: string, blockLinePrefix?: string, blockEnd?: string }>, spacing?: number }} [options={}] - Syntax resolution options. `spacing` is the number of empty comment lines just inside the header's opening and closing (default 1).
|
|
19
|
+
* @param {{ language?: string, enabledDetectors?: string[], disabledDetectors?: string[], forcedDetectors?: string[], detectorSyntaxOverrides?: Record<string, { linePrefix?: string, lineSeparator?: string, blockStart?: string, blockLinePrefix?: string, blockEnd?: string }>, spacing?: number }} [options={}] - Syntax resolution options. `spacing` is the number of empty comment lines just inside the header's opening and closing (default 1).
|
|
20
20
|
* @returns {HeaderSyntax} Header syntax descriptor.
|
|
21
21
|
*/
|
|
22
22
|
export function getHeaderSyntaxForFile(filePath: string, options?: {
|
|
23
23
|
language?: string;
|
|
24
24
|
enabledDetectors?: string[];
|
|
25
25
|
disabledDetectors?: string[];
|
|
26
|
+
forcedDetectors?: string[];
|
|
26
27
|
detectorSyntaxOverrides?: Record<string, {
|
|
27
28
|
linePrefix?: string;
|
|
28
29
|
lineSeparator?: string;
|