@peripheries/engine 0.17.1 → 0.17.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peripheries/engine",
3
- "version": "0.17.1",
3
+ "version": "0.17.2",
4
4
  "description": "Build, check, knowledge and deploy for peripheries component repos",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",
@@ -1 +1 @@
1
- const FORBIDDEN=[[/[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[a-z]{2,}\b/,"an email address"],[/\bsb_(secret|publishable)_[A-Za-z0-9_-]+/,"a Supabase key"],[/\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}/,"a JWT"],[/\b[a-z]{20}\.supabase\.(co|in)\b/,"a Supabase project URL"],[/https?:\/\/(localhost|127\.0\.0\.1)(:\d+)?/,"a localhost URL"],[/\/Users\/[A-Za-z0-9._-]+/,"a local path"],[/sourceMappingURL=/,"a source map reference"]];const TEXT=/\.(m?js|css|json|svg|txt|html)$/i;const normalize=s=>s.toLowerCase().replace(/[\s_-]+/g," ").trim();const escape=s=>s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");const namePattern=name=>new RegExp(`\\b${normalize(name).split(" ").map(escape).join("[\\s_-]+")}\\b`,"gi");function jsComments(code,ts){const sf=ts.createSourceFile("bundle.js",code,ts.ScriptTarget.Latest,true,ts.ScriptKind.JS);const found=new Set;const visit=node=>{for(const r of[...ts.getLeadingCommentRanges(code,node.pos)??[],...ts.getTrailingCommentRanges(code,node.end)??[]])found.add(code.slice(r.pos,r.end));ts.forEachChild(node,visit)};visit(sf);for(const r of ts.getLeadingCommentRanges(code,sf.endOfFileToken.pos)??[])found.add(code.slice(r.pos,r.end));return[...found]}function cssComments(css){const bare=css.replace(/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'/g,'""');return bare.match(/\/\*[\s\S]*?\*\//g)??[]}function fileProblems(name,text,{ts,otherNames=[],allowNames=[]}){const out=[];if(/\.map$/i.test(name))return[`a source map (${name}); build with \`engine build\`, which writes none`];if(/\.m?js$/i.test(name))for(const c of jsComments(text,ts))out.push(`a comment: ${c.slice(0,60)}`);if(/\.css$/i.test(name))for(const c of cssComments(text))out.push(`a comment: ${c.slice(0,60)}`);if(/\.svg$/i.test(name)&&/<!--/.test(text))out.push("a comment: <!-- \u2026 -->");for(const[re,what]of FORBIDDEN){const m=text.match(re);if(m)out.push(`${what}: ${m[0].slice(0,80)}`)}const allowed=new Set(allowNames.map(normalize));for(const other of otherNames){if(allowed.has(normalize(other)))continue;const m=text.match(namePattern(other));if(m&&!out.includes(`an org name: ${m[0]}`))out.push(`an org name: ${m[0]}`)}return out}function auditBundle(files,{ts,read,otherNames=[],allowNames=[]}){const out=[];for(const f of files){if(!TEXT.test(f.remote)&&!/\.map$/i.test(f.remote))continue;for(const p of fileProblems(f.remote,read(f.local),{ts,otherNames,allowNames}))out.push(`${f.remote}: ${p}`)}return out}function otherOrgNames(rows,ownOrgId){const out=new Set;for(const r of rows){if(r.id===ownOrgId||!r.slug||r.slug==="stack")continue;for(const n of[r.name,r.slug])if(typeof n==="string"&&normalize(n).replace(/ /g,"").length>=4)out.add(n)}return[...out]}export{auditBundle,cssComments,fileProblems,jsComments,otherOrgNames};
1
+ const FORBIDDEN=[[/\bsb_(secret|publishable)_[A-Za-z0-9_-]+/,"a Supabase key"],[/\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}/,"a JWT"],[/\b[a-z]{20}\.supabase\.(co|in)\b/,"a Supabase project URL"],[/https?:\/\/(localhost|127\.0\.0\.1)(:\d+)?/,"a localhost URL"],[/\/Users\/[A-Za-z0-9._-]+/,"a local path"],[/sourceMappingURL=/,"a source map reference"]];const EMAIL=/[A-Za-z0-9._%+-]+@([A-Za-z0-9.-]+\.[a-z]{2,})\b/gi;const RESERVED=/(^|\.)(example\.(com|org|net)|[^.]+\.(test|example|invalid))$|^(test|example|invalid)$/i;function realEmail(text){for(const m of text.matchAll(EMAIL))if(!RESERVED.test(m[1]))return m[0];return void 0}const TEXT=/\.(m?js|css|json|svg|txt|html)$/i;const normalize=s=>s.toLowerCase().replace(/[\s_-]+/g," ").trim();const escape=s=>s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");const namePattern=name=>new RegExp(`\\b${normalize(name).split(" ").map(escape).join("[\\s_-]+")}\\b`,"gi");function jsComments(code,ts){const sf=ts.createSourceFile("bundle.js",code,ts.ScriptTarget.Latest,true,ts.ScriptKind.JS);const found=new Set;const visit=node=>{for(const r of[...ts.getLeadingCommentRanges(code,node.pos)??[],...ts.getTrailingCommentRanges(code,node.end)??[]])found.add(code.slice(r.pos,r.end));ts.forEachChild(node,visit)};visit(sf);for(const r of ts.getLeadingCommentRanges(code,sf.endOfFileToken.pos)??[])found.add(code.slice(r.pos,r.end));return[...found]}function cssComments(css){const bare=css.replace(/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'/g,'""');return bare.match(/\/\*[\s\S]*?\*\//g)??[]}function fileProblems(name,text,{ts,otherNames=[],allowNames=[]}){const out=[];if(/\.map$/i.test(name))return[`a source map (${name}); build with \`engine build\`, which writes none`];if(/\.m?js$/i.test(name))for(const c of jsComments(text,ts))out.push(`a comment: ${c.slice(0,60)}`);if(/\.css$/i.test(name))for(const c of cssComments(text))out.push(`a comment: ${c.slice(0,60)}`);if(/\.svg$/i.test(name)&&/<!--/.test(text))out.push("a comment: <!-- \u2026 -->");const email=realEmail(text);if(email)out.push(`an email address: ${email}`);for(const[re,what]of FORBIDDEN){const m=text.match(re);if(m)out.push(`${what}: ${m[0].slice(0,80)}`)}const allowed=new Set(allowNames.map(normalize));for(const other of otherNames){if(allowed.has(normalize(other)))continue;const m=text.match(namePattern(other));if(m&&!out.includes(`an org name: ${m[0]}`))out.push(`an org name: ${m[0]}`)}return out}function auditBundle(files,{ts,read,otherNames=[],allowNames=[]}){const out=[];for(const f of files){if(!TEXT.test(f.remote)&&!/\.map$/i.test(f.remote))continue;for(const p of fileProblems(f.remote,read(f.local),{ts,otherNames,allowNames}))out.push(`${f.remote}: ${p}`)}return out}function otherOrgNames(rows,ownOrgId){const out=new Set;for(const r of rows){if(r.id===ownOrgId||!r.slug||r.slug==="stack")continue;for(const n of[r.name,r.slug])if(typeof n==="string"&&normalize(n).replace(/ /g,"").length>=4)out.add(n)}return[...out]}export{auditBundle,cssComments,fileProblems,jsComments,otherOrgNames,realEmail};