@pictogrammers/element-esbuild 0.0.26 → 0.0.28
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/bin/element-build.js +7 -7
- package/bin/element-start.js +7 -7
- package/package.json +1 -1
- package/scripts/resolveExternal.ts +16 -4
package/bin/element-build.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
3
|
-
import{fileURLToPath as
|
|
4
|
-
`),loader:"js"}})}}}var
|
|
5
|
-
`),resolveDir
|
|
3
|
+
import{fileURLToPath as we,pathToFileURL as be}from"node:url";import{build as ve}from"esbuild";import{sep as S}from"node:path";import{readFile as ce}from"node:fs/promises";function B(e){return e.replace(/-([a-z])/g,r=>r[1].toUpperCase())}var le=process.cwd(),pe=le.split(S).length,me=e=>`\x1B[31m${e}\x1B[0m`;function Z({localNamespaces:e,externalNamespaces:r}){return{name:"html-dependents-plugin",setup(i){i.onLoad({filter:/\.html$/},async u=>{let g=u.path.split(S).splice(pe),[x,C,h,l,...P]=g,w=await ce(u.path,"utf8"),o=w.matchAll(/<\/(?<namespace>\w+)-(?<value>[^>]+)/g),t=new Map;for(let p of o){let{namespace:f,value:c}=p.groups,n=B(c);t.set(`${f}-${n}`,[f,n])}let m=[];return t.forEach(([p,f])=>{let c=g.length-4,n=new Array(c).fill("..");if(p===h){if(f===l)return;m.push(`import './${n.join("/")}/${f}/${f}';`)}else if(e.includes(p))m.push(`import './${n.join("/")}/${p}/${f}/${f}';`);else if(r.has(p)){n.push(".."),n.push(".."),n.push("..");let s=r.get(p);m.push(`import '${s}/${p}/${f}/${f}';`)}else console.log(me(`Unable to find namespace folder "${p}". Possibly missing 'external' in element.config.ts`)),process.exit()}),m.push(`export default \`${w}\`;`),{contents:m.join(`
|
|
4
|
+
`),loader:"js"}})}}}var ue=e=>`\x1B[32m${e}\x1B[0m`,H={name:"rebuild-notify",setup(e){e.onEnd(r=>{r.errors.length>0?console.error(`Build ended with ${r.errors.length} errors`):console.log(ue("Build succeeded!"))})}};import{access as fe}from"node:fs/promises";import{constants as de}from"node:fs";async function b(e){try{return await fe(e,de.F_OK),!0}catch{return!1}}import{copyFile as Y,writeFile as _e}from"node:fs/promises";import{dirname as De,join as _}from"node:path";import{join as y}from"node:path";import{readdir as ge}from"node:fs/promises";async function E(e){let r=[];try{let i=await ge(e,{withFileTypes:!0});for(let u of i)u.isDirectory()&&r.push(u.name)}catch(i){console.error("Error reading directory:",i)}return r}import{access as he}from"node:fs/promises";import{constants as $e}from"node:fs";async function J(e){try{return await he(e,$e.F_OK),!0}catch{return!1}}import{readFile as K}from"node:fs/promises";function N(e){return e&&e.charAt(0).toUpperCase()+e.slice(1)}function T(e){return e.replace(/([a-zA-Z])(?=[A-Z])/g,"$1-").toLowerCase()}var L=e=>`\x1B[31m${e}\x1B[0m`,pt=process.cwd();var M="src",v="components";function W(e){return{name:"playground-plugin",setup(r){let i="playground-entry",u="playground-module";r.onResolve({filter:new RegExp(`^${i}$`)},g=>({path:i,namespace:u})),r.onLoad({filter:/.*/,namespace:u},async g=>{let x=[],C=await E(y(M,v));C.length===0&&(console.log(L('Missing at least 1 namespace folder under "src/components/"')),process.exit());let h=[];for(let l of C){let P={namespace:l,components:[]};h.push(P);let w=y(M,v,l),o=await E(w);for(let t of o)if(await b(y(M,v,l,t,`${t}.ts`))){let m="";await b(y(M,v,l,t,"README.md"))&&(m=await K(y(M,v,l,t,"README.md"),"utf8"));let p={namespace:l,component:t,tag:`${l}-${T(t)}`,examples:[],className:"",classExtends:"",readme:m};if(x.push(`import '${v}/${l}/${t}/${t}';`),await J(y(w,t,"__examples__"))){let n=await E(y(w,t,"__examples__"));for(let s of n)await b(y(w,t,"__examples__",s,`${s}.ts`))?(x.push(`import '${v}/${l}/${t}/__examples__/${s}/${s}';`),p.examples.push({namespace:l,component:t,example:s,tag:`x-${l}-${T(t)}-${T(s)}`,className:`X${N(l)}${N(t)}${N(s)}`})):console.log(L(`Missing ${v}/${l}/${t}/__examples__/${s}/${s}.ts`))}let c=(await K(y(M,v,l,t,`${t}.ts`),"utf8")).match(/class (\w+) extends (\w+)/);c||(console.log(L(`Component "${l}-${t}" must extend HtmlElement or base class`)),process.exit()),p.className=c[1],p.classExtends=c[2],P.components.push(p)}}return e.after(h),{contents:x.join(`
|
|
5
|
+
`),resolveDir:y(process.cwd(),M)}})}}}import{join as U}from"node:path";import{readFile as k}from"node:fs/promises";async function X({mode:e,rootDir:r,srcDir:i,indexFile:u,defaultDir:g,playgroundFile:x,title:C,repo:h,repoComponent:l,navigation:P,namespaces:w}){let o="";await b(U(r,i,u))?o=await k(U(r,i,u),"utf8"):o=await k(U(g,x),"utf8"),o=o.replace("<title>Default</title>",`<title>${C??"Default"}</title>`),o=o.replace("<h1>Default</h1>",`<h1>${C??"Default"}</h1>`);let t=structuredClone(P??[]);for(let c of t)c.items=[];let m;t.length===0?(m={label:"Components",items:[]},t.push(m)):(m=t.find(c=>!c.extends&&!c.components&&!c.namespaces),m||(m={label:"Other",items:[]},t.push(m)));let p=new Map;if(w.forEach(({components:c})=>{c.forEach(({component:n,namespace:s,tag:d,readme:A,examples:F,className:$,classExtends:I})=>{p.set($,{className:$,classExtends:I,component:n,namespace:s,tag:d,readme:A,examples:F.map(a=>a.className)}),F.forEach(a=>{p.set(a.className,{className:a.className,classExtends:a.classExtends,component:a.component,namespace:a.namespace,tag:a.tag,example:a.example})});for(let a of t)if(a.include&&a.include.includes($)){a.items.push({namespace:s,component:n,className:$,tag:d});return}for(let a of t)if(a!==m&&!(a.exclude&&a.exclude.includes($))&&!(a.namespaces&&!a.namespaces.includes(s))&&!(a.extends&&!a.extends.includes(I))){a.items.push({namespace:s,component:n,className:$,tag:d});return}m.items.push({namespace:s,component:n,examples:F,className:$,tag:d})})}),o=o.replace(/([ ]*)<!-- \[Navigation\] -->/,(c,n)=>t.map(({label:s,items:d})=>[n,`<div>${s}</div>`,"<ul>",d.map(({component:A,namespace:F,tag:$,className:I})=>[`<li data-tag="${$}" data-class-name="${I}" data-component="${A}"><a href="#${$}">${A}</a></li>`].join(`
|
|
6
6
|
${n}`)).join(`
|
|
7
7
|
${n}`),"</ul>"].join(`
|
|
8
8
|
${n}`)).join(`
|
|
9
|
-
${n}`)),
|
|
10
|
-
${
|
|
11
|
-
${n}`)));let f=[...
|
|
12
|
-
`)),o=o.replace(/([ ]*)const navigation = \[\];/,(
|
|
9
|
+
${n}`)),h){let s=h.includes("github.com")?"M12,2A10,10 0 0,0 2,12C2,16.42 4.87,20.17 8.84,21.5C9.34,21.58 9.5,21.27 9.5,21C9.5,20.77 9.5,20.14 9.5,19.31C6.73,19.91 6.14,17.97 6.14,17.97C5.68,16.81 5.03,16.5 5.03,16.5C4.12,15.88 5.1,15.9 5.1,15.9C6.1,15.97 6.63,16.93 6.63,16.93C7.5,18.45 8.97,18 9.54,17.76C9.63,17.11 9.89,16.67 10.17,16.42C7.95,16.17 5.62,15.31 5.62,11.5C5.62,10.39 6,9.5 6.65,8.79C6.55,8.54 6.2,7.5 6.75,6.15C6.75,6.15 7.59,5.88 9.5,7.17C10.29,6.95 11.15,6.84 12,6.84C12.85,6.84 13.71,6.95 14.5,7.17C16.41,5.88 17.25,6.15 17.25,6.15C17.8,7.5 17.45,8.54 17.35,8.79C18,9.5 18.38,10.39 18.38,11.5C18.38,15.32 16.04,16.16 13.81,16.41C14.17,16.72 14.5,17.33 14.5,18.26C14.5,19.6 14.5,20.68 14.5,21C14.5,21.27 14.66,21.59 15.17,21.5C19.14,20.16 22,16.42 22,12A10,10 0 0,0 12,2Z":"M6,2H18A2,2 0 0,1 20,4V20A2,2 0 0,1 18,22H6A2,2 0 0,1 4,20V4A2,2 0 0,1 6,2M12.75,13.5C15.5,13.5 16.24,11.47 16.43,10.4C17.34,10.11 18,9.26 18,8.25C18,7 17,6 15.75,6C14.5,6 13.5,7 13.5,8.25C13.5,9.19 14.07,10 14.89,10.33C14.67,11 14,12 12,12C10.62,12 9.66,12.35 9,12.84V8.87C9.87,8.56 10.5,7.73 10.5,6.75C10.5,5.5 9.5,4.5 8.25,4.5C7,4.5 6,5.5 6,6.75C6,7.73 6.63,8.56 7.5,8.87V15.13C6.63,15.44 6,16.27 6,17.25C6,18.5 7,19.5 8.25,19.5C9.5,19.5 10.5,18.5 10.5,17.25C10.5,16.32 9.94,15.5 9.13,15.18C9.41,14.5 10.23,13.5 12.75,13.5M8.25,16.5A0.75,0.75 0 0,1 9,17.25A0.75,0.75 0 0,1 8.25,18A0.75,0.75 0 0,1 7.5,17.25A0.75,0.75 0 0,1 8.25,16.5M8.25,6A0.75,0.75 0 0,1 9,6.75A0.75,0.75 0 0,1 8.25,7.5A0.75,0.75 0 0,1 7.5,6.75A0.75,0.75 0 0,1 8.25,6M15.75,7.5A0.75,0.75 0 0,1 16.5,8.25A0.75,0.75 0 0,1 15.75,9A0.75,0.75 0 0,1 15,8.25A0.75,0.75 0 0,1 15.75,7.5Z";o=o.replace(/([ ]*)<!-- \[Repo\] -->/,(d,A)=>[A,`<a href="${h}">`,' <svg viewBox="0 0 24 24">',` <path fill="currentColor" d="${s}" />`," </svg>"," <span>View Repo</span>","</a>"].join(`
|
|
10
|
+
${A}`)),o=o.replace(/const repo = '';/,d=>`const repo = '${h}';`),o=o.replace(/const repoComponent = '';/,d=>`const repoComponent = '${l.replace(/\$repo/g,h)}';`),o=o.replace(/const repoIcon = '';/,d=>`const repoIcon = '${s}';`)}e==="dev"&&(o=o.replace(/([ ]*)<!-- \[info\] -->/,(c,n)=>[n,"<p>This page is generated from <code>npm start</code>. To render only specific components use <code>npm start c-button</code>.</p>"].join(`
|
|
11
|
+
${n}`)));let f=[...p.keys()];return o=o.replace(/([ ]*)const componentMap = new Map\(\);/,(c,n)=>[`${n}const componentMap = new Map();`,...f.map(s=>{let d=p.get(s);return`componentMap.set('${s}', ${JSON.stringify(d)});`})].join(`${n}
|
|
12
|
+
`)),o=o.replace(/([ ]*)const navigation = \[\];/,(c,n)=>`${n}const navigation = ${JSON.stringify(t,null," ")};`),o}import{existsSync as ye}from"node:fs";import{join as xe,resolve as q,sep as Ce}from"node:path";var G=process.env.INIT_CWD,V="";G?V=xe(G,"node_modules"):(console.log("INIT_CWD not available. The script was likely not run via `npm run`."),process.exit());function Q({external:e}){return{name:"resolve-external",setup(r){e.forEach(i=>{r.onResolve({filter:new RegExp(`^${i}/`)},u=>{let g=q(V,...i.split("/"),u.path.substring(`${i}/`.length));if(!ye(`${g}.ts`)){let x=u.path.substring(`${i}/`.length),C=x.split(Ce);g=q(V,...i.split("/"),x,C[C.length-1])}return{path:g}})})}}}var O=[H],z=[],Ae=e=>`\x1B[32m${e}\x1B[0m`,Ee=e=>`\x1B[31m${e}\x1B[0m`,ee="node_modules",Me="playground.html",Pe=we(import.meta.url),je=De(Pe),oe=_(je,"..","default"),te="index.html";var j="src",se="components",re="element.config.ts",D=process.cwd(),R="build",Fe=be(re);await b(re)||(console.log(Ee("Missing element.config.ts in root."),"Add with content:"),console.log("export default {"),console.log(" namespace: 'hello',"),console.log("}"),process.exit());var Ie=await import(Fe.href),{namespace:ne,title:Ne,repo:Te,repoComponent:Re,navigation:Oe,external:ae}=Ie.default,Le=await E(_(D,j,se)),ie=new Map;for(let e of ae??[])(await E(_(D,ee,...e.split("/")))).forEach(i=>{i!==ee&&ie.set(i,e)});O.push(Q({external:ae??[]}));O.push(Z({localNamespaces:Le,externalNamespaces:ie}));ne?(console.log(Ae("Building app...")),z.push(`./${j}/${se}/${ne}/app/app.ts`)):(z.push("playground-entry"),O.push(W({after:async e=>{let r=await X({mode:"production",rootDir:D,srcDir:j,indexFile:te,defaultDir:oe,playgroundFile:Me,title:Ne,repo:Te,repoComponent:Re,navigation:Oe,namespaces:e});await _e(_(D,R,te),r)}})));ve({entryPoints:z,bundle:!0,platform:"browser",outfile:`./${R}/main.js`,sourcemap:!1,minify:!0,format:"esm",target:"es2024",loader:{".html":"text",".css":"text"},plugins:O}).then(async()=>{let e="favicon.svg";await b(_(D,j,e))?await Y(_(D,j,e),_(D,R,e)):await Y(_(oe,e),_(D,R,e))}).catch(e=>{process.stderr.write(e.stderr),process.exit(1)});
|
package/bin/element-start.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
3
|
-
import{context as as}from"esbuild";import{EventEmitter as Ae}from"node:events";import{stat as Fe}from"node:fs";import{readdir as Ne,stat as Se}from"node:fs/promises";import*as m from"node:path";import{lstat as Pt,readdir as se,realpath as ie,stat as ne}from"node:fs/promises";import{join as re,relative as oe,resolve as xt,sep as ae}from"node:path";import{Readable as ce}from"node:stream";var A={FILE_TYPE:"files",DIR_TYPE:"directories",FILE_DIR_TYPE:"files_directories",EVERYTHING_TYPE:"all"},at={root:".",fileFilter:i=>!0,directoryFilter:i=>!0,type:A.FILE_TYPE,lstat:!1,depth:2147483648,alwaysStat:!1,highWaterMark:4096};Object.freeze(at);var Rt="READDIRP_RECURSIVE_ERROR",le=new Set(["ENOENT","EPERM","EACCES","ELOOP",Rt]),bt=[A.DIR_TYPE,A.EVERYTHING_TYPE,A.FILE_DIR_TYPE,A.FILE_TYPE],he=new Set([A.DIR_TYPE,A.EVERYTHING_TYPE,A.FILE_DIR_TYPE]),fe=new Set([A.EVERYTHING_TYPE,A.FILE_DIR_TYPE,A.FILE_TYPE]),de=i=>le.has(i.code),pe=process.platform==="win32",Dt=i=>!0,vt=i=>{if(i===void 0)return Dt;if(typeof i=="function")return i;if(typeof i=="string"){let t=i.trim();return e=>e.basename===t}if(Array.isArray(i)){let t=i.map(e=>e.trim());return e=>t.some(n=>e.basename===n)}return Dt},ct=class extends ce{parents;reading;parent;_stat;_maxDepth;_wantsDir;_wantsFile;_wantsEverything;_root;_isDirent;_statsProp;_rdOptions;_fileFilter;_directoryFilter;constructor(t={}){super({objectMode:!0,autoDestroy:!0,highWaterMark:t.highWaterMark});let e={...at,...t},{root:n,type:s}=e;this._fileFilter=vt(e.fileFilter),this._directoryFilter=vt(e.directoryFilter);let a=e.lstat?Pt:ne;pe?this._stat=c=>a(c,{bigint:!0}):this._stat=a,this._maxDepth=e.depth!=null&&Number.isSafeInteger(e.depth)?e.depth:at.depth,this._wantsDir=s?he.has(s):!1,this._wantsFile=s?fe.has(s):!1,this._wantsEverything=s===A.EVERYTHING_TYPE,this._root=xt(n),this._isDirent=!e.alwaysStat,this._statsProp=this._isDirent?"dirent":"stats",this._rdOptions={encoding:"utf8",withFileTypes:this._isDirent},this.parents=[this._exploreDir(n,1)],this.reading=!1,this.parent=void 0}async _read(t){if(!this.reading){this.reading=!0;try{for(;!this.destroyed&&t>0;){let e=this.parent,n=e&&e.files;if(n&&n.length>0){let{path:s,depth:a}=e,c=n.splice(0,t).map(r=>this._formatEntry(r,s)),o=await Promise.all(c);for(let r of o){if(!r)continue;if(this.destroyed)return;let d=await this._getEntryType(r);d==="directory"&&this._directoryFilter(r)?(a<=this._maxDepth&&this.parents.push(this._exploreDir(r.fullPath,a+1)),this._wantsDir&&(this.push(r),t--)):(d==="file"||this._includeAsFile(r))&&this._fileFilter(r)&&this._wantsFile&&(this.push(r),t--)}}else{let s=this.parents.pop();if(!s){this.push(null);break}if(this.parent=await s,this.destroyed)return}}}catch(e){this.destroy(e)}finally{this.reading=!1}}}async _exploreDir(t,e){let n;try{n=await se(t,this._rdOptions)}catch(s){this._onError(s)}return{files:n,depth:e,path:t}}async _formatEntry(t,e){let n,s=this._isDirent?t.name:t;try{let a=xt(re(e,s));n={path:oe(this._root,a),fullPath:a,basename:s},n[this._statsProp]=this._isDirent?t:await this._stat(a)}catch(a){this._onError(a);return}return n}_onError(t){de(t)&&!this.destroyed?this.emit("warn",t):this.destroy(t)}async _getEntryType(t){if(!t&&this._statsProp in t)return"";let e=t[this._statsProp];if(e.isFile())return"file";if(e.isDirectory())return"directory";if(e&&e.isSymbolicLink()){let n=t.fullPath;try{let s=await ie(n),a=await Pt(s);if(a.isFile())return"file";if(a.isDirectory()){let c=s.length;if(n.startsWith(s)&&n.substr(c,1)===ae){let o=new Error(`Circular symlink detected: "${n}" points to "${s}"`);return o.code=Rt,this._onError(o)}return"directory"}}catch(s){return this._onError(s),""}}}_includeAsFile(t){let e=t&&t[this._statsProp];return e&&this._wantsEverything&&!e.isDirectory()}};function Ct(i,t={}){let e=t.entryType||t.type;if(e==="both"&&(e=A.FILE_DIR_TYPE),e&&(t.type=e),i){if(typeof i!="string")throw new TypeError("readdirp: root argument must be a string. Usage: readdirp(root, options)");if(e&&!bt.includes(e))throw new Error(`readdirp: Invalid type passed. Use one of ${bt.join(", ")}`)}else throw new Error("readdirp: root argument is required. Usage: readdirp(root, options)");return t.root=i,new ct(t)}import{watch as ue,unwatchFile as It,watchFile as me}from"node:fs";import{realpath as lt,lstat as _e,open as we,stat as $t}from"node:fs/promises";import{type as ge}from"node:os";import*as b from"node:path";var ye="data",dt="end",At="close",X=()=>{};var Q=process.platform,pt=Q==="win32",Ee=Q==="darwin",Pe=Q==="linux",xe=Q==="freebsd",Ft=ge()==="OS400",D={ALL:"all",READY:"ready",ADD:"add",CHANGE:"change",ADD_DIR:"addDir",UNLINK:"unlink",UNLINK_DIR:"unlinkDir",RAW:"raw",ERROR:"error"},N=D,be="watch",De={lstat:_e,stat:$t},L="listeners",K="errHandlers",Y="rawEmitters",ve=[L,K,Y],Re=new Set(["3dm","3ds","3g2","3gp","7z","a","aac","adp","afdesign","afphoto","afpub","ai","aif","aiff","alz","ape","apk","appimage","ar","arj","asf","au","avi","bak","baml","bh","bin","bk","bmp","btif","bz2","bzip2","cab","caf","cgm","class","cmx","cpio","cr2","cur","dat","dcm","deb","dex","djvu","dll","dmg","dng","doc","docm","docx","dot","dotm","dra","DS_Store","dsk","dts","dtshd","dvb","dwg","dxf","ecelp4800","ecelp7470","ecelp9600","egg","eol","eot","epub","exe","f4v","fbs","fh","fla","flac","flatpak","fli","flv","fpx","fst","fvt","g3","gh","gif","graffle","gz","gzip","h261","h263","h264","icns","ico","ief","img","ipa","iso","jar","jpeg","jpg","jpgv","jpm","jxr","key","ktx","lha","lib","lvp","lz","lzh","lzma","lzo","m3u","m4a","m4v","mar","mdi","mht","mid","midi","mj2","mka","mkv","mmr","mng","mobi","mov","movie","mp3","mp4","mp4a","mpeg","mpg","mpga","mxu","nef","npx","numbers","nupkg","o","odp","ods","odt","oga","ogg","ogv","otf","ott","pages","pbm","pcx","pdb","pdf","pea","pgm","pic","png","pnm","pot","potm","potx","ppa","ppam","ppm","pps","ppsm","ppsx","ppt","pptm","pptx","psd","pya","pyc","pyo","pyv","qt","rar","ras","raw","resources","rgb","rip","rlc","rmf","rmvb","rpm","rtf","rz","s3m","s7z","scpt","sgi","shar","snap","sil","sketch","slk","smv","snk","so","stl","suo","sub","swf","tar","tbz","tbz2","tga","tgz","thmx","tif","tiff","tlz","ttc","ttf","txz","udf","uvh","uvi","uvm","uvp","uvs","uvu","viv","vob","war","wav","wax","wbmp","wdp","weba","webm","webp","whl","wim","wm","wma","wmv","wmx","woff","woff2","wrm","wvx","xbm","xif","xla","xlam","xls","xlsb","xlsm","xlsx","xlt","xltm","xltx","xm","xmind","xpi","xpm","xwd","xz","z","zip","zipx"]),Ce=i=>Re.has(b.extname(i).slice(1).toLowerCase()),ft=(i,t)=>{i instanceof Set?i.forEach(t):t(i)},U=(i,t,e)=>{let n=i[t];n instanceof Set||(i[t]=n=new Set([n])),n.add(e)},Ie=i=>t=>{let e=i[t];e instanceof Set?e.clear():delete i[t]},G=(i,t,e)=>{let n=i[t];n instanceof Set?n.delete(e):n===e&&delete i[t]},Nt=i=>i instanceof Set?i.size===0:!i,Z=new Map;function Tt(i,t,e,n,s){let a=(c,o)=>{e(i),s(c,o,{watchedPath:i}),o&&i!==o&&q(b.resolve(i,o),L,b.join(i,o))};try{return ue(i,{persistent:t.persistent},a)}catch(c){n(c);return}}var q=(i,t,e,n,s)=>{let a=Z.get(i);a&&ft(a[t],c=>{c(e,n,s)})},Te=(i,t,e,n)=>{let{listener:s,errHandler:a,rawEmitter:c}=n,o=Z.get(t),r;if(!e.persistent)return r=Tt(i,e,s,a,c),r?r.close.bind(r):void 0;if(o)U(o,L,s),U(o,K,a),U(o,Y,c);else{if(r=Tt(i,e,q.bind(null,t,L),a,q.bind(null,t,Y)),!r)return;r.on(N.ERROR,async d=>{let f=q.bind(null,t,K);if(o&&(o.watcherUnusable=!0),pt&&d.code==="EPERM")try{await(await we(i,"r")).close(),f(d)}catch{}else f(d)}),o={listeners:s,errHandlers:a,rawEmitters:c,watcher:r},Z.set(t,o)}return()=>{G(o,L,s),G(o,K,a),G(o,Y,c),Nt(o.listeners)&&(o.watcher.close(),Z.delete(t),ve.forEach(Ie(o)),o.watcher=void 0,Object.freeze(o))}},ht=new Map,$e=(i,t,e,n)=>{let{listener:s,rawEmitter:a}=n,c=ht.get(t),o=c&&c.options;return o&&(o.persistent<e.persistent||o.interval>e.interval)&&(It(t),c=void 0),c?(U(c,L,s),U(c,Y,a)):(c={listeners:s,rawEmitters:a,options:e,watcher:me(t,e,(r,d)=>{ft(c.rawEmitters,h=>{h(N.CHANGE,t,{curr:r,prev:d})});let f=r.mtimeMs;(r.size!==d.size||f>d.mtimeMs||f===0)&&ft(c.listeners,h=>h(i,r))})},ht.set(t,c)),()=>{G(c,L,s),G(c,Y,a),Nt(c.listeners)&&(ht.delete(t),It(t),c.options=c.watcher=void 0,Object.freeze(c))}},J=class{fsw;_boundHandleError;constructor(t){this.fsw=t,this._boundHandleError=e=>t._handleError(e)}_watchWithNodeFs(t,e){let n=this.fsw.options,s=b.dirname(t),a=b.basename(t);this.fsw._getWatchedDir(s).add(a);let o=b.resolve(t),r={persistent:n.persistent};e||(e=X);let d;if(n.usePolling){let f=n.interval!==n.binaryInterval;r.interval=f&&Ce(a)?n.binaryInterval:n.interval,d=$e(t,o,r,{listener:e,rawEmitter:this.fsw._emitRaw})}else d=Te(t,o,r,{listener:e,errHandler:this._boundHandleError,rawEmitter:this.fsw._emitRaw});return d}_handleFile(t,e,n){if(this.fsw.closed)return;let s=b.dirname(t),a=b.basename(t),c=this.fsw._getWatchedDir(s),o=e;if(c.has(a))return;let r=async(f,h)=>{if(this.fsw._throttle(be,t,5)){if(!h||h.mtimeMs===0)try{let l=await $t(t);if(this.fsw.closed)return;let p=l.atimeMs,u=l.mtimeMs;if((!p||p<=u||u!==o.mtimeMs)&&this.fsw._emit(N.CHANGE,t,l),(Ee||Pe||xe)&&o.ino!==l.ino){this.fsw._closeFile(f),o=l;let g=this._watchWithNodeFs(t,r);g&&this.fsw._addPathCloser(f,g)}else o=l}catch{this.fsw._remove(s,a)}else if(c.has(a)){let l=h.atimeMs,p=h.mtimeMs;(!l||l<=p||p!==o.mtimeMs)&&this.fsw._emit(N.CHANGE,t,h),o=h}}},d=this._watchWithNodeFs(t,r);if(!(n&&this.fsw.options.ignoreInitial)&&this.fsw._isntIgnored(t)){if(!this.fsw._throttle(N.ADD,t,0))return;this.fsw._emit(N.ADD,t,e)}return d}async _handleSymlink(t,e,n,s){if(this.fsw.closed)return;let a=t.fullPath,c=this.fsw._getWatchedDir(e);if(!this.fsw.options.followSymlinks){this.fsw._incrReadyCount();let o;try{o=await lt(n)}catch{return this.fsw._emitReady(),!0}return this.fsw.closed?void 0:(c.has(s)?this.fsw._symlinkPaths.get(a)!==o&&(this.fsw._symlinkPaths.set(a,o),this.fsw._emit(N.CHANGE,n,t.stats)):(c.add(s),this.fsw._symlinkPaths.set(a,o),this.fsw._emit(N.ADD,n,t.stats)),this.fsw._emitReady(),!0)}if(this.fsw._symlinkPaths.has(a))return!0;this.fsw._symlinkPaths.set(a,!0)}_handleRead(t,e,n,s,a,c,o){t=b.join(t,"");let r=s?`${t}:${s}`:t;if(o=this.fsw._throttle("readdir",r,1e3),!o)return;let d=this.fsw._getWatchedDir(n.path),f=new Set,h=this.fsw._readdirp(t,{fileFilter:l=>n.filterPath(l),directoryFilter:l=>n.filterDir(l)});if(h)return h.on(ye,async l=>{if(this.fsw.closed){h=void 0;return}let p=l.path,u=b.join(t,p);if(f.add(p),!(l.stats.isSymbolicLink()&&await this._handleSymlink(l,t,u,p))){if(this.fsw.closed){h=void 0;return}(p===s||!s&&!d.has(p))&&(this.fsw._incrReadyCount(),u=b.join(a,b.relative(a,u)),this._addToNodeFs(u,e,n,c+1))}}).on(N.ERROR,this._boundHandleError),new Promise((l,p)=>{if(!h)return p();h.once(dt,()=>{if(this.fsw.closed){h=void 0;return}let u=o?o.clear():!1;l(void 0),d.getChildren().filter(g=>g!==t&&!f.has(g)).forEach(g=>{this.fsw._remove(t,g)}),h=void 0,u&&this._handleRead(t,!1,n,s,a,c,o)})})}async _handleDir(t,e,n,s,a,c,o){let r=this.fsw._getWatchedDir(b.dirname(t)),d=r.has(b.basename(t));!(n&&this.fsw.options.ignoreInitial)&&!a&&!d&&this.fsw._emit(N.ADD_DIR,t,e),r.add(b.basename(t)),this.fsw._getWatchedDir(t);let f,h,l=this.fsw.options.depth;if((l==null||s<=l)&&!this.fsw._symlinkPaths.has(o)){if(!a&&(await this._handleRead(t,n,c,a,t,s,f),this.fsw.closed))return;h=this._watchWithNodeFs(t,(p,u)=>{u&&u.mtimeMs===0||this._handleRead(p,!1,c,a,t,s,f)})}return h}async _addToNodeFs(t,e,n,s,a){let c=this.fsw._emitReady;if(this.fsw._isIgnored(t)||this.fsw.closed)return c(),!1;let o=this.fsw._getWatchHelpers(t);n&&(o.filterPath=r=>n.filterPath(r),o.filterDir=r=>n.filterDir(r));try{let r=await De[o.statMethod](o.watchPath);if(this.fsw.closed)return;if(this.fsw._isIgnored(o.watchPath,r))return c(),!1;let d=this.fsw.options.followSymlinks,f;if(r.isDirectory()){let h=b.resolve(t),l=d?await lt(t):t;if(this.fsw.closed||(f=await this._handleDir(o.watchPath,r,e,s,a,o,l),this.fsw.closed))return;h!==l&&l!==void 0&&this.fsw._symlinkPaths.set(h,l)}else if(r.isSymbolicLink()){let h=d?await lt(t):t;if(this.fsw.closed)return;let l=b.dirname(o.watchPath);if(this.fsw._getWatchedDir(l).add(o.watchPath),this.fsw._emit(N.ADD,o.watchPath,r),f=await this._handleDir(l,r,e,s,t,o,h),this.fsw.closed)return;h!==void 0&&this.fsw._symlinkPaths.set(b.resolve(t),h)}else f=this._handleFile(o.watchPath,r,e);return c(),f&&this.fsw._addPathCloser(t,f),!1}catch(r){if(this.fsw._handleError(r))return c(),t}}};var ut="/",Me="//",Lt=".",We="..",ke="string",Le=/\\/g,jt=/\/\//g,je=/\..*\.(sw[px])$|~$|\.subl.*\.tmp/,Oe=/^\.[/\\]/;function tt(i){return Array.isArray(i)?i:[i]}var mt=i=>typeof i=="object"&&i!==null&&!(i instanceof RegExp);function ze(i){return typeof i=="function"?i:typeof i=="string"?t=>i===t:i instanceof RegExp?t=>i.test(t):typeof i=="object"&&i!==null?t=>{if(i.path===t)return!0;if(i.recursive){let e=m.relative(i.path,t);return e?!e.startsWith("..")&&!m.isAbsolute(e):!1}return!1}:()=>!1}function He(i){if(typeof i!="string")throw new Error("string expected");i=m.normalize(i),i=i.replace(/\\/g,"/");let t=!1;return i.startsWith("//")&&(t=!0),i=i.replace(jt,"/"),t&&(i="/"+i),i}function St(i,t,e){let n=He(t);for(let s=0;s<i.length;s++){let a=i[s];if(a(n,e))return!0}return!1}function Ye(i,t){if(i==null)throw new TypeError("anymatch: specify first argument");let n=tt(i).map(s=>ze(s));return t==null?(s,a)=>St(n,s,a):St(n,t)}var Mt=i=>{let t=tt(i).flat();if(!t.every(e=>typeof e===ke))throw new TypeError(`Non-string provided as watch path: ${t}`);return t.map(Ot)},Wt=i=>{let t=i.replace(Le,ut),e=!1;return t.startsWith(Me)&&(e=!0),t=t.replace(jt,ut),e&&(t=ut+t),t},Ot=i=>Wt(m.normalize(Wt(i))),kt=(i="")=>t=>typeof t=="string"?Ot(m.isAbsolute(t)?t:m.join(i,t)):t,Ue=(i,t)=>m.isAbsolute(i)?i:m.join(t,i),Ge=Object.freeze(new Set),_t=class{path;_removeWatcher;items;constructor(t,e){this.path=t,this._removeWatcher=e,this.items=new Set}add(t){let{items:e}=this;e&&t!==Lt&&t!==We&&e.add(t)}async remove(t){let{items:e}=this;if(!e||(e.delete(t),e.size>0))return;let n=this.path;try{await Ne(n)}catch{this._removeWatcher&&this._removeWatcher(m.dirname(n),m.basename(n))}}has(t){let{items:e}=this;if(e)return e.has(t)}getChildren(){let{items:t}=this;return t?[...t.values()]:[]}dispose(){this.items.clear(),this.path="",this._removeWatcher=X,this.items=Ge,Object.freeze(this)}},Ve="stat",Be="lstat",wt=class{fsw;path;watchPath;fullWatchPath;dirParts;followSymlinks;statMethod;constructor(t,e,n){this.fsw=n;let s=t;this.path=t=t.replace(Oe,""),this.watchPath=s,this.fullWatchPath=m.resolve(s),this.dirParts=[],this.dirParts.forEach(a=>{a.length>1&&a.pop()}),this.followSymlinks=e,this.statMethod=e?Ve:Be}entryPath(t){return m.join(this.watchPath,m.relative(this.watchPath,t.fullPath))}filterPath(t){let{stats:e}=t;if(e&&e.isSymbolicLink())return this.filterDir(t);let n=this.entryPath(t);return this.fsw._isntIgnored(n,e)&&this.fsw._hasReadPermissions(e)}filterDir(t){return this.fsw._isntIgnored(this.entryPath(t),t.stats)}},et=class extends Ae{closed;options;_closers;_ignoredPaths;_throttled;_streams;_symlinkPaths;_watched;_pendingWrites;_pendingUnlinks;_readyCount;_emitReady;_closePromise;_userIgnored;_readyEmitted;_emitRaw;_boundRemove;_nodeFsHandler;constructor(t={}){super(),this.closed=!1,this._closers=new Map,this._ignoredPaths=new Set,this._throttled=new Map,this._streams=new Set,this._symlinkPaths=new Map,this._watched=new Map,this._pendingWrites=new Map,this._pendingUnlinks=new Map,this._readyCount=0,this._readyEmitted=!1;let e=t.awaitWriteFinish,n={stabilityThreshold:2e3,pollInterval:100},s={persistent:!0,ignoreInitial:!1,ignorePermissionErrors:!1,interval:100,binaryInterval:300,followSymlinks:!0,usePolling:!1,atomic:!0,...t,ignored:t.ignored?tt(t.ignored):tt([]),awaitWriteFinish:e===!0?n:typeof e=="object"?{...n,...e}:!1};Ft&&(s.usePolling=!0),s.atomic===void 0&&(s.atomic=!s.usePolling);let a=process.env.CHOKIDAR_USEPOLLING;if(a!==void 0){let r=a.toLowerCase();r==="false"||r==="0"?s.usePolling=!1:r==="true"||r==="1"?s.usePolling=!0:s.usePolling=!!r}let c=process.env.CHOKIDAR_INTERVAL;c&&(s.interval=Number.parseInt(c,10));let o=0;this._emitReady=()=>{o++,o>=this._readyCount&&(this._emitReady=X,this._readyEmitted=!0,process.nextTick(()=>this.emit(D.READY)))},this._emitRaw=(...r)=>this.emit(D.RAW,...r),this._boundRemove=this._remove.bind(this),this.options=s,this._nodeFsHandler=new J(this),Object.freeze(s)}_addIgnoredPath(t){if(mt(t)){for(let e of this._ignoredPaths)if(mt(e)&&e.path===t.path&&e.recursive===t.recursive)return}this._ignoredPaths.add(t)}_removeIgnoredPath(t){if(this._ignoredPaths.delete(t),typeof t=="string")for(let e of this._ignoredPaths)mt(e)&&e.path===t&&this._ignoredPaths.delete(e)}add(t,e,n){let{cwd:s}=this.options;this.closed=!1,this._closePromise=void 0;let a=Mt(t);return s&&(a=a.map(c=>Ue(c,s))),a.forEach(c=>{this._removeIgnoredPath(c)}),this._userIgnored=void 0,this._readyCount||(this._readyCount=0),this._readyCount+=a.length,Promise.all(a.map(async c=>{let o=await this._nodeFsHandler._addToNodeFs(c,!n,void 0,0,e);return o&&this._emitReady(),o})).then(c=>{this.closed||c.forEach(o=>{o&&this.add(m.dirname(o),m.basename(e||o))})}),this}unwatch(t){if(this.closed)return this;let e=Mt(t),{cwd:n}=this.options;return e.forEach(s=>{!m.isAbsolute(s)&&!this._closers.has(s)&&(n&&(s=m.join(n,s)),s=m.resolve(s)),this._closePath(s),this._addIgnoredPath(s),this._watched.has(s)&&this._addIgnoredPath({path:s,recursive:!0}),this._userIgnored=void 0}),this}close(){if(this._closePromise)return this._closePromise;this.closed=!0,this.removeAllListeners();let t=[];return this._closers.forEach(e=>e.forEach(n=>{let s=n();s instanceof Promise&&t.push(s)})),this._streams.forEach(e=>e.destroy()),this._userIgnored=void 0,this._readyCount=0,this._readyEmitted=!1,this._watched.forEach(e=>e.dispose()),this._closers.clear(),this._watched.clear(),this._streams.clear(),this._symlinkPaths.clear(),this._throttled.clear(),this._closePromise=t.length?Promise.all(t).then(()=>{}):Promise.resolve(),this._closePromise}getWatched(){let t={};return this._watched.forEach((e,n)=>{let a=(this.options.cwd?m.relative(this.options.cwd,n):n)||Lt;t[a]=e.getChildren().sort()}),t}emitWithAll(t,e){this.emit(t,...e),t!==D.ERROR&&this.emit(D.ALL,t,...e)}async _emit(t,e,n){if(this.closed)return;let s=this.options;pt&&(e=m.normalize(e)),s.cwd&&(e=m.relative(s.cwd,e));let a=[e];n!=null&&a.push(n);let c=s.awaitWriteFinish,o;if(c&&(o=this._pendingWrites.get(e)))return o.lastChange=new Date,this;if(s.atomic){if(t===D.UNLINK)return this._pendingUnlinks.set(e,[t,...a]),setTimeout(()=>{this._pendingUnlinks.forEach((r,d)=>{this.emit(...r),this.emit(D.ALL,...r),this._pendingUnlinks.delete(d)})},typeof s.atomic=="number"?s.atomic:100),this;t===D.ADD&&this._pendingUnlinks.has(e)&&(t=D.CHANGE,this._pendingUnlinks.delete(e))}if(c&&(t===D.ADD||t===D.CHANGE)&&this._readyEmitted){let r=(d,f)=>{d?(t=D.ERROR,a[0]=d,this.emitWithAll(t,a)):f&&(a.length>1?a[1]=f:a.push(f),this.emitWithAll(t,a))};return this._awaitWriteFinish(e,c.stabilityThreshold,t,r),this}if(t===D.CHANGE&&!this._throttle(D.CHANGE,e,50))return this;if(s.alwaysStat&&n===void 0&&(t===D.ADD||t===D.ADD_DIR||t===D.CHANGE)){let r=s.cwd?m.join(s.cwd,e):e,d;try{d=await Se(r)}catch{}if(!d||this.closed)return;a.push(d)}return this.emitWithAll(t,a),this}_handleError(t){let e=t&&t.code;return t&&e!=="ENOENT"&&e!=="ENOTDIR"&&(!this.options.ignorePermissionErrors||e!=="EPERM"&&e!=="EACCES")&&this.emit(D.ERROR,t),t||this.closed}_throttle(t,e,n){this._throttled.has(t)||this._throttled.set(t,new Map);let s=this._throttled.get(t);if(!s)throw new Error("invalid throttle");let a=s.get(e);if(a)return a.count++,!1;let c,o=()=>{let d=s.get(e),f=d?d.count:0;return s.delete(e),clearTimeout(c),d&&clearTimeout(d.timeoutObject),f};c=setTimeout(o,n);let r={timeoutObject:c,clear:o,count:0};return s.set(e,r),r}_incrReadyCount(){return this._readyCount++}_awaitWriteFinish(t,e,n,s){let a=this.options.awaitWriteFinish;if(typeof a!="object")return;let c=a.pollInterval,o,r=t;this.options.cwd&&!m.isAbsolute(t)&&(r=m.join(this.options.cwd,t));let d=new Date,f=this._pendingWrites;function h(l){Fe(r,(p,u)=>{if(p||!f.has(t)){p&&p.code!=="ENOENT"&&s(p);return}let g=Number(new Date);l&&u.size!==l.size&&(f.get(t).lastChange=g);let x=f.get(t);g-x.lastChange>=e?(f.delete(t),s(void 0,u)):o=setTimeout(h,c,u)})}f.has(t)||(f.set(t,{lastChange:d,cancelWait:()=>(f.delete(t),clearTimeout(o),n)}),o=setTimeout(h,c))}_isIgnored(t,e){if(this.options.atomic&&je.test(t))return!0;if(!this._userIgnored){let{cwd:n}=this.options,a=(this.options.ignored||[]).map(kt(n)),o=[...[...this._ignoredPaths].map(kt(n)),...a];this._userIgnored=Ye(o,void 0)}return this._userIgnored(t,e)}_isntIgnored(t,e){return!this._isIgnored(t,e)}_getWatchHelpers(t){return new wt(t,this.options.followSymlinks,this)}_getWatchedDir(t){let e=m.resolve(t);return this._watched.has(e)||this._watched.set(e,new _t(e,this._boundRemove)),this._watched.get(e)}_hasReadPermissions(t){return this.options.ignorePermissionErrors?!0:!!(Number(t.mode)&256)}_remove(t,e,n){let s=m.join(t,e),a=m.resolve(s);if(n=n??(this._watched.has(s)||this._watched.has(a)),!this._throttle("remove",s,100))return;!n&&this._watched.size===1&&this.add(t,e,!0),this._getWatchedDir(s).getChildren().forEach(l=>this._remove(s,l));let r=this._getWatchedDir(t),d=r.has(e);r.remove(e),this._symlinkPaths.has(a)&&this._symlinkPaths.delete(a);let f=s;if(this.options.cwd&&(f=m.relative(this.options.cwd,s)),this.options.awaitWriteFinish&&this._pendingWrites.has(f)&&this._pendingWrites.get(f).cancelWait()===D.ADD)return;this._watched.delete(s),this._watched.delete(a);let h=n?D.UNLINK_DIR:D.UNLINK;d&&!this._isIgnored(s)&&this._emit(h,s),this._closePath(s)}_closePath(t){this._closeFile(t);let e=m.dirname(t);this._getWatchedDir(e).remove(m.basename(t))}_closeFile(t){let e=this._closers.get(t);e&&(e.forEach(n=>n()),this._closers.delete(t))}_addPathCloser(t,e){if(!e)return;let n=this._closers.get(t);n||(n=[],this._closers.set(t,n)),n.push(e)}_readdirp(t,e){if(this.closed)return;let n={type:D.ALL,alwaysStat:!0,lstat:!0,...e,depth:0},s=Ct(t,n);return this._streams.add(s),s.once(At,()=>{s=void 0}),s.once(dt,()=>{s&&(this._streams.delete(s),s=void 0)}),s}};function Ke(i,t={}){let e=new et(t);return e.add(i),e}var zt={watch:Ke,FSWatcher:et};import{pathToFileURL as cs,fileURLToPath as ls}from"node:url";import{join as P,sep as Et,dirname as Qt}from"node:path";import{copyFile as V,cp as hs,mkdir as fs,readFile as ds,writeFile as te}from"node:fs/promises";import{access as Ze}from"node:fs/promises";import{constants as qe}from"node:fs";async function S(i){try{return await Ze(i,qe.F_OK),!0}catch{return!1}}import{access as Je}from"node:fs/promises";import{constants as Xe}from"node:fs";async function j(i){try{return await Je(i,Xe.F_OK),!0}catch{return!1}}import{join as M}from"node:path";import{readdir as Qe}from"node:fs/promises";async function O(i){let t=[];try{let e=await Qe(i,{withFileTypes:!0});for(let n of e)n.isDirectory()&&t.push(n.name)}catch(e){console.error("Error reading directory:",e)}return t}import{readFile as Ht}from"node:fs/promises";function st(i){return i&&i.charAt(0).toUpperCase()+i.slice(1)}function it(i){return i.replace(/([a-zA-Z])(?=[A-Z])/g,"$1-").toLowerCase()}var gt=i=>`\x1B[31m${i}\x1B[0m`,qs=process.cwd();var z="src",k="components";function Yt(i){return{name:"playground-plugin",setup(t){let e="playground-entry",n="playground-module";t.onResolve({filter:new RegExp(`^${e}$`)},s=>({path:e,namespace:n})),t.onLoad({filter:/.*/,namespace:n},async s=>{let a=[],c=await O(M(z,k));c.length===0&&(console.log(gt('Missing at least 1 namespace folder under "src/components/"')),process.exit());let o=[];for(let r of c){let d={namespace:r,components:[]};o.push(d);let f=M(z,k,r),h=await O(f);for(let l of h)if(await S(M(z,k,r,l,`${l}.ts`))){let p="";await S(M(z,k,r,l,"README.md"))&&(p=await Ht(M(z,k,r,l,"README.md"),"utf8"));let u={namespace:r,component:l,tag:`${r}-${it(l)}`,examples:[],className:"",classExtends:"",readme:p};if(a.push(`import '${k}/${r}/${l}/${l}';`),await j(M(f,l,"__examples__"))){let _=await O(M(f,l,"__examples__"));for(let w of _)await S(M(f,l,"__examples__",w,`${w}.ts`))?(a.push(`import '${k}/${r}/${l}/__examples__/${w}/${w}';`),u.examples.push({namespace:r,component:l,example:w,tag:`x-${r}-${it(l)}-${it(w)}`,className:`X${st(r)}${st(l)}${st(w)}`})):console.log(gt(`Missing ${k}/${r}/${l}/__examples__/${w}/${w}.ts`))}let x=(await Ht(M(z,k,r,l,`${l}.ts`),"utf8")).match(/class (\w+) extends (\w+)/);x||(console.log(gt(`Component "${r}-${l}" must extend HtmlElement or base class`)),process.exit()),u.className=x[1],u.classExtends=x[2],d.components.push(u)}}return i.after(o),{contents:a.join(`
|
|
4
|
-
`),resolveDir:M(process.cwd(),z)}})}}}import{sep as
|
|
5
|
-
`),loader:"js"}})}}}var
|
|
3
|
+
import{context as ls}from"esbuild";import{EventEmitter as Fe}from"node:events";import{stat as Se}from"node:fs";import{readdir as Ne,stat as Me}from"node:fs/promises";import*as m from"node:path";import{lstat as Pt,readdir as ie,realpath as ne,stat as re}from"node:fs/promises";import{join as oe,relative as ae,resolve as bt,sep as ce}from"node:path";import{Readable as le}from"node:stream";var A={FILE_TYPE:"files",DIR_TYPE:"directories",FILE_DIR_TYPE:"files_directories",EVERYTHING_TYPE:"all"},at={root:".",fileFilter:i=>!0,directoryFilter:i=>!0,type:A.FILE_TYPE,lstat:!1,depth:2147483648,alwaysStat:!1,highWaterMark:4096};Object.freeze(at);var Ct="READDIRP_RECURSIVE_ERROR",he=new Set(["ENOENT","EPERM","EACCES","ELOOP",Ct]),Dt=[A.DIR_TYPE,A.EVERYTHING_TYPE,A.FILE_DIR_TYPE,A.FILE_TYPE],fe=new Set([A.DIR_TYPE,A.EVERYTHING_TYPE,A.FILE_DIR_TYPE]),de=new Set([A.EVERYTHING_TYPE,A.FILE_DIR_TYPE,A.FILE_TYPE]),pe=i=>he.has(i.code),ue=process.platform==="win32",Rt=i=>!0,vt=i=>{if(i===void 0)return Rt;if(typeof i=="function")return i;if(typeof i=="string"){let t=i.trim();return e=>e.basename===t}if(Array.isArray(i)){let t=i.map(e=>e.trim());return e=>t.some(n=>e.basename===n)}return Rt},ct=class extends le{parents;reading;parent;_stat;_maxDepth;_wantsDir;_wantsFile;_wantsEverything;_root;_isDirent;_statsProp;_rdOptions;_fileFilter;_directoryFilter;constructor(t={}){super({objectMode:!0,autoDestroy:!0,highWaterMark:t.highWaterMark});let e={...at,...t},{root:n,type:s}=e;this._fileFilter=vt(e.fileFilter),this._directoryFilter=vt(e.directoryFilter);let o=e.lstat?Pt:re;ue?this._stat=c=>o(c,{bigint:!0}):this._stat=o,this._maxDepth=e.depth!=null&&Number.isSafeInteger(e.depth)?e.depth:at.depth,this._wantsDir=s?fe.has(s):!1,this._wantsFile=s?de.has(s):!1,this._wantsEverything=s===A.EVERYTHING_TYPE,this._root=bt(n),this._isDirent=!e.alwaysStat,this._statsProp=this._isDirent?"dirent":"stats",this._rdOptions={encoding:"utf8",withFileTypes:this._isDirent},this.parents=[this._exploreDir(n,1)],this.reading=!1,this.parent=void 0}async _read(t){if(!this.reading){this.reading=!0;try{for(;!this.destroyed&&t>0;){let e=this.parent,n=e&&e.files;if(n&&n.length>0){let{path:s,depth:o}=e,c=n.splice(0,t).map(r=>this._formatEntry(r,s)),a=await Promise.all(c);for(let r of a){if(!r)continue;if(this.destroyed)return;let d=await this._getEntryType(r);d==="directory"&&this._directoryFilter(r)?(o<=this._maxDepth&&this.parents.push(this._exploreDir(r.fullPath,o+1)),this._wantsDir&&(this.push(r),t--)):(d==="file"||this._includeAsFile(r))&&this._fileFilter(r)&&this._wantsFile&&(this.push(r),t--)}}else{let s=this.parents.pop();if(!s){this.push(null);break}if(this.parent=await s,this.destroyed)return}}}catch(e){this.destroy(e)}finally{this.reading=!1}}}async _exploreDir(t,e){let n;try{n=await ie(t,this._rdOptions)}catch(s){this._onError(s)}return{files:n,depth:e,path:t}}async _formatEntry(t,e){let n,s=this._isDirent?t.name:t;try{let o=bt(oe(e,s));n={path:ae(this._root,o),fullPath:o,basename:s},n[this._statsProp]=this._isDirent?t:await this._stat(o)}catch(o){this._onError(o);return}return n}_onError(t){pe(t)&&!this.destroyed?this.emit("warn",t):this.destroy(t)}async _getEntryType(t){if(!t&&this._statsProp in t)return"";let e=t[this._statsProp];if(e.isFile())return"file";if(e.isDirectory())return"directory";if(e&&e.isSymbolicLink()){let n=t.fullPath;try{let s=await ne(n),o=await Pt(s);if(o.isFile())return"file";if(o.isDirectory()){let c=s.length;if(n.startsWith(s)&&n.substr(c,1)===ce){let a=new Error(`Circular symlink detected: "${n}" points to "${s}"`);return a.code=Ct,this._onError(a)}return"directory"}}catch(s){return this._onError(s),""}}}_includeAsFile(t){let e=t&&t[this._statsProp];return e&&this._wantsEverything&&!e.isDirectory()}};function It(i,t={}){let e=t.entryType||t.type;if(e==="both"&&(e=A.FILE_DIR_TYPE),e&&(t.type=e),i){if(typeof i!="string")throw new TypeError("readdirp: root argument must be a string. Usage: readdirp(root, options)");if(e&&!Dt.includes(e))throw new Error(`readdirp: Invalid type passed. Use one of ${Dt.join(", ")}`)}else throw new Error("readdirp: root argument is required. Usage: readdirp(root, options)");return t.root=i,new ct(t)}import{watch as me,unwatchFile as $t,watchFile as _e}from"node:fs";import{realpath as lt,lstat as we,open as ge,stat as At}from"node:fs/promises";import{type as ye}from"node:os";import*as b from"node:path";var Ee="data",dt="end",Ft="close",X=()=>{};var Q=process.platform,pt=Q==="win32",xe=Q==="darwin",Pe=Q==="linux",be=Q==="freebsd",St=ye()==="OS400",D={ALL:"all",READY:"ready",ADD:"add",CHANGE:"change",ADD_DIR:"addDir",UNLINK:"unlink",UNLINK_DIR:"unlinkDir",RAW:"raw",ERROR:"error"},S=D,De="watch",Re={lstat:we,stat:At},k="listeners",K="errHandlers",Y="rawEmitters",ve=[k,K,Y],Ce=new Set(["3dm","3ds","3g2","3gp","7z","a","aac","adp","afdesign","afphoto","afpub","ai","aif","aiff","alz","ape","apk","appimage","ar","arj","asf","au","avi","bak","baml","bh","bin","bk","bmp","btif","bz2","bzip2","cab","caf","cgm","class","cmx","cpio","cr2","cur","dat","dcm","deb","dex","djvu","dll","dmg","dng","doc","docm","docx","dot","dotm","dra","DS_Store","dsk","dts","dtshd","dvb","dwg","dxf","ecelp4800","ecelp7470","ecelp9600","egg","eol","eot","epub","exe","f4v","fbs","fh","fla","flac","flatpak","fli","flv","fpx","fst","fvt","g3","gh","gif","graffle","gz","gzip","h261","h263","h264","icns","ico","ief","img","ipa","iso","jar","jpeg","jpg","jpgv","jpm","jxr","key","ktx","lha","lib","lvp","lz","lzh","lzma","lzo","m3u","m4a","m4v","mar","mdi","mht","mid","midi","mj2","mka","mkv","mmr","mng","mobi","mov","movie","mp3","mp4","mp4a","mpeg","mpg","mpga","mxu","nef","npx","numbers","nupkg","o","odp","ods","odt","oga","ogg","ogv","otf","ott","pages","pbm","pcx","pdb","pdf","pea","pgm","pic","png","pnm","pot","potm","potx","ppa","ppam","ppm","pps","ppsm","ppsx","ppt","pptm","pptx","psd","pya","pyc","pyo","pyv","qt","rar","ras","raw","resources","rgb","rip","rlc","rmf","rmvb","rpm","rtf","rz","s3m","s7z","scpt","sgi","shar","snap","sil","sketch","slk","smv","snk","so","stl","suo","sub","swf","tar","tbz","tbz2","tga","tgz","thmx","tif","tiff","tlz","ttc","ttf","txz","udf","uvh","uvi","uvm","uvp","uvs","uvu","viv","vob","war","wav","wax","wbmp","wdp","weba","webm","webp","whl","wim","wm","wma","wmv","wmx","woff","woff2","wrm","wvx","xbm","xif","xla","xlam","xls","xlsb","xlsm","xlsx","xlt","xltm","xltx","xm","xmind","xpi","xpm","xwd","xz","z","zip","zipx"]),Ie=i=>Ce.has(b.extname(i).slice(1).toLowerCase()),ft=(i,t)=>{i instanceof Set?i.forEach(t):t(i)},U=(i,t,e)=>{let n=i[t];n instanceof Set||(i[t]=n=new Set([n])),n.add(e)},$e=i=>t=>{let e=i[t];e instanceof Set?e.clear():delete i[t]},G=(i,t,e)=>{let n=i[t];n instanceof Set?n.delete(e):n===e&&delete i[t]},Nt=i=>i instanceof Set?i.size===0:!i,Z=new Map;function Tt(i,t,e,n,s){let o=(c,a)=>{e(i),s(c,a,{watchedPath:i}),a&&i!==a&&q(b.resolve(i,a),k,b.join(i,a))};try{return me(i,{persistent:t.persistent},o)}catch(c){n(c);return}}var q=(i,t,e,n,s)=>{let o=Z.get(i);o&&ft(o[t],c=>{c(e,n,s)})},Te=(i,t,e,n)=>{let{listener:s,errHandler:o,rawEmitter:c}=n,a=Z.get(t),r;if(!e.persistent)return r=Tt(i,e,s,o,c),r?r.close.bind(r):void 0;if(a)U(a,k,s),U(a,K,o),U(a,Y,c);else{if(r=Tt(i,e,q.bind(null,t,k),o,q.bind(null,t,Y)),!r)return;r.on(S.ERROR,async d=>{let f=q.bind(null,t,K);if(a&&(a.watcherUnusable=!0),pt&&d.code==="EPERM")try{await(await ge(i,"r")).close(),f(d)}catch{}else f(d)}),a={listeners:s,errHandlers:o,rawEmitters:c,watcher:r},Z.set(t,a)}return()=>{G(a,k,s),G(a,K,o),G(a,Y,c),Nt(a.listeners)&&(a.watcher.close(),Z.delete(t),ve.forEach($e(a)),a.watcher=void 0,Object.freeze(a))}},ht=new Map,Ae=(i,t,e,n)=>{let{listener:s,rawEmitter:o}=n,c=ht.get(t),a=c&&c.options;return a&&(a.persistent<e.persistent||a.interval>e.interval)&&($t(t),c=void 0),c?(U(c,k,s),U(c,Y,o)):(c={listeners:s,rawEmitters:o,options:e,watcher:_e(t,e,(r,d)=>{ft(c.rawEmitters,h=>{h(S.CHANGE,t,{curr:r,prev:d})});let f=r.mtimeMs;(r.size!==d.size||f>d.mtimeMs||f===0)&&ft(c.listeners,h=>h(i,r))})},ht.set(t,c)),()=>{G(c,k,s),G(c,Y,o),Nt(c.listeners)&&(ht.delete(t),$t(t),c.options=c.watcher=void 0,Object.freeze(c))}},J=class{fsw;_boundHandleError;constructor(t){this.fsw=t,this._boundHandleError=e=>t._handleError(e)}_watchWithNodeFs(t,e){let n=this.fsw.options,s=b.dirname(t),o=b.basename(t);this.fsw._getWatchedDir(s).add(o);let a=b.resolve(t),r={persistent:n.persistent};e||(e=X);let d;if(n.usePolling){let f=n.interval!==n.binaryInterval;r.interval=f&&Ie(o)?n.binaryInterval:n.interval,d=Ae(t,a,r,{listener:e,rawEmitter:this.fsw._emitRaw})}else d=Te(t,a,r,{listener:e,errHandler:this._boundHandleError,rawEmitter:this.fsw._emitRaw});return d}_handleFile(t,e,n){if(this.fsw.closed)return;let s=b.dirname(t),o=b.basename(t),c=this.fsw._getWatchedDir(s),a=e;if(c.has(o))return;let r=async(f,h)=>{if(this.fsw._throttle(De,t,5)){if(!h||h.mtimeMs===0)try{let l=await At(t);if(this.fsw.closed)return;let p=l.atimeMs,u=l.mtimeMs;if((!p||p<=u||u!==a.mtimeMs)&&this.fsw._emit(S.CHANGE,t,l),(xe||Pe||be)&&a.ino!==l.ino){this.fsw._closeFile(f),a=l;let g=this._watchWithNodeFs(t,r);g&&this.fsw._addPathCloser(f,g)}else a=l}catch{this.fsw._remove(s,o)}else if(c.has(o)){let l=h.atimeMs,p=h.mtimeMs;(!l||l<=p||p!==a.mtimeMs)&&this.fsw._emit(S.CHANGE,t,h),a=h}}},d=this._watchWithNodeFs(t,r);if(!(n&&this.fsw.options.ignoreInitial)&&this.fsw._isntIgnored(t)){if(!this.fsw._throttle(S.ADD,t,0))return;this.fsw._emit(S.ADD,t,e)}return d}async _handleSymlink(t,e,n,s){if(this.fsw.closed)return;let o=t.fullPath,c=this.fsw._getWatchedDir(e);if(!this.fsw.options.followSymlinks){this.fsw._incrReadyCount();let a;try{a=await lt(n)}catch{return this.fsw._emitReady(),!0}return this.fsw.closed?void 0:(c.has(s)?this.fsw._symlinkPaths.get(o)!==a&&(this.fsw._symlinkPaths.set(o,a),this.fsw._emit(S.CHANGE,n,t.stats)):(c.add(s),this.fsw._symlinkPaths.set(o,a),this.fsw._emit(S.ADD,n,t.stats)),this.fsw._emitReady(),!0)}if(this.fsw._symlinkPaths.has(o))return!0;this.fsw._symlinkPaths.set(o,!0)}_handleRead(t,e,n,s,o,c,a){t=b.join(t,"");let r=s?`${t}:${s}`:t;if(a=this.fsw._throttle("readdir",r,1e3),!a)return;let d=this.fsw._getWatchedDir(n.path),f=new Set,h=this.fsw._readdirp(t,{fileFilter:l=>n.filterPath(l),directoryFilter:l=>n.filterDir(l)});if(h)return h.on(Ee,async l=>{if(this.fsw.closed){h=void 0;return}let p=l.path,u=b.join(t,p);if(f.add(p),!(l.stats.isSymbolicLink()&&await this._handleSymlink(l,t,u,p))){if(this.fsw.closed){h=void 0;return}(p===s||!s&&!d.has(p))&&(this.fsw._incrReadyCount(),u=b.join(o,b.relative(o,u)),this._addToNodeFs(u,e,n,c+1))}}).on(S.ERROR,this._boundHandleError),new Promise((l,p)=>{if(!h)return p();h.once(dt,()=>{if(this.fsw.closed){h=void 0;return}let u=a?a.clear():!1;l(void 0),d.getChildren().filter(g=>g!==t&&!f.has(g)).forEach(g=>{this.fsw._remove(t,g)}),h=void 0,u&&this._handleRead(t,!1,n,s,o,c,a)})})}async _handleDir(t,e,n,s,o,c,a){let r=this.fsw._getWatchedDir(b.dirname(t)),d=r.has(b.basename(t));!(n&&this.fsw.options.ignoreInitial)&&!o&&!d&&this.fsw._emit(S.ADD_DIR,t,e),r.add(b.basename(t)),this.fsw._getWatchedDir(t);let f,h,l=this.fsw.options.depth;if((l==null||s<=l)&&!this.fsw._symlinkPaths.has(a)){if(!o&&(await this._handleRead(t,n,c,o,t,s,f),this.fsw.closed))return;h=this._watchWithNodeFs(t,(p,u)=>{u&&u.mtimeMs===0||this._handleRead(p,!1,c,o,t,s,f)})}return h}async _addToNodeFs(t,e,n,s,o){let c=this.fsw._emitReady;if(this.fsw._isIgnored(t)||this.fsw.closed)return c(),!1;let a=this.fsw._getWatchHelpers(t);n&&(a.filterPath=r=>n.filterPath(r),a.filterDir=r=>n.filterDir(r));try{let r=await Re[a.statMethod](a.watchPath);if(this.fsw.closed)return;if(this.fsw._isIgnored(a.watchPath,r))return c(),!1;let d=this.fsw.options.followSymlinks,f;if(r.isDirectory()){let h=b.resolve(t),l=d?await lt(t):t;if(this.fsw.closed||(f=await this._handleDir(a.watchPath,r,e,s,o,a,l),this.fsw.closed))return;h!==l&&l!==void 0&&this.fsw._symlinkPaths.set(h,l)}else if(r.isSymbolicLink()){let h=d?await lt(t):t;if(this.fsw.closed)return;let l=b.dirname(a.watchPath);if(this.fsw._getWatchedDir(l).add(a.watchPath),this.fsw._emit(S.ADD,a.watchPath,r),f=await this._handleDir(l,r,e,s,t,a,h),this.fsw.closed)return;h!==void 0&&this.fsw._symlinkPaths.set(b.resolve(t),h)}else f=this._handleFile(a.watchPath,r,e);return c(),f&&this.fsw._addPathCloser(t,f),!1}catch(r){if(this.fsw._handleError(r))return c(),t}}};var ut="/",We="//",jt=".",Le="..",ke="string",je=/\\/g,Ot=/\/\//g,Oe=/\..*\.(sw[px])$|~$|\.subl.*\.tmp/,ze=/^\.[/\\]/;function tt(i){return Array.isArray(i)?i:[i]}var mt=i=>typeof i=="object"&&i!==null&&!(i instanceof RegExp);function He(i){return typeof i=="function"?i:typeof i=="string"?t=>i===t:i instanceof RegExp?t=>i.test(t):typeof i=="object"&&i!==null?t=>{if(i.path===t)return!0;if(i.recursive){let e=m.relative(i.path,t);return e?!e.startsWith("..")&&!m.isAbsolute(e):!1}return!1}:()=>!1}function Ye(i){if(typeof i!="string")throw new Error("string expected");i=m.normalize(i),i=i.replace(/\\/g,"/");let t=!1;return i.startsWith("//")&&(t=!0),i=i.replace(Ot,"/"),t&&(i="/"+i),i}function Mt(i,t,e){let n=Ye(t);for(let s=0;s<i.length;s++){let o=i[s];if(o(n,e))return!0}return!1}function Ue(i,t){if(i==null)throw new TypeError("anymatch: specify first argument");let n=tt(i).map(s=>He(s));return t==null?(s,o)=>Mt(n,s,o):Mt(n,t)}var Wt=i=>{let t=tt(i).flat();if(!t.every(e=>typeof e===ke))throw new TypeError(`Non-string provided as watch path: ${t}`);return t.map(zt)},Lt=i=>{let t=i.replace(je,ut),e=!1;return t.startsWith(We)&&(e=!0),t=t.replace(Ot,ut),e&&(t=ut+t),t},zt=i=>Lt(m.normalize(Lt(i))),kt=(i="")=>t=>typeof t=="string"?zt(m.isAbsolute(t)?t:m.join(i,t)):t,Ge=(i,t)=>m.isAbsolute(i)?i:m.join(t,i),Ve=Object.freeze(new Set),_t=class{path;_removeWatcher;items;constructor(t,e){this.path=t,this._removeWatcher=e,this.items=new Set}add(t){let{items:e}=this;e&&t!==jt&&t!==Le&&e.add(t)}async remove(t){let{items:e}=this;if(!e||(e.delete(t),e.size>0))return;let n=this.path;try{await Ne(n)}catch{this._removeWatcher&&this._removeWatcher(m.dirname(n),m.basename(n))}}has(t){let{items:e}=this;if(e)return e.has(t)}getChildren(){let{items:t}=this;return t?[...t.values()]:[]}dispose(){this.items.clear(),this.path="",this._removeWatcher=X,this.items=Ve,Object.freeze(this)}},Be="stat",Ke="lstat",wt=class{fsw;path;watchPath;fullWatchPath;dirParts;followSymlinks;statMethod;constructor(t,e,n){this.fsw=n;let s=t;this.path=t=t.replace(ze,""),this.watchPath=s,this.fullWatchPath=m.resolve(s),this.dirParts=[],this.dirParts.forEach(o=>{o.length>1&&o.pop()}),this.followSymlinks=e,this.statMethod=e?Be:Ke}entryPath(t){return m.join(this.watchPath,m.relative(this.watchPath,t.fullPath))}filterPath(t){let{stats:e}=t;if(e&&e.isSymbolicLink())return this.filterDir(t);let n=this.entryPath(t);return this.fsw._isntIgnored(n,e)&&this.fsw._hasReadPermissions(e)}filterDir(t){return this.fsw._isntIgnored(this.entryPath(t),t.stats)}},et=class extends Fe{closed;options;_closers;_ignoredPaths;_throttled;_streams;_symlinkPaths;_watched;_pendingWrites;_pendingUnlinks;_readyCount;_emitReady;_closePromise;_userIgnored;_readyEmitted;_emitRaw;_boundRemove;_nodeFsHandler;constructor(t={}){super(),this.closed=!1,this._closers=new Map,this._ignoredPaths=new Set,this._throttled=new Map,this._streams=new Set,this._symlinkPaths=new Map,this._watched=new Map,this._pendingWrites=new Map,this._pendingUnlinks=new Map,this._readyCount=0,this._readyEmitted=!1;let e=t.awaitWriteFinish,n={stabilityThreshold:2e3,pollInterval:100},s={persistent:!0,ignoreInitial:!1,ignorePermissionErrors:!1,interval:100,binaryInterval:300,followSymlinks:!0,usePolling:!1,atomic:!0,...t,ignored:t.ignored?tt(t.ignored):tt([]),awaitWriteFinish:e===!0?n:typeof e=="object"?{...n,...e}:!1};St&&(s.usePolling=!0),s.atomic===void 0&&(s.atomic=!s.usePolling);let o=process.env.CHOKIDAR_USEPOLLING;if(o!==void 0){let r=o.toLowerCase();r==="false"||r==="0"?s.usePolling=!1:r==="true"||r==="1"?s.usePolling=!0:s.usePolling=!!r}let c=process.env.CHOKIDAR_INTERVAL;c&&(s.interval=Number.parseInt(c,10));let a=0;this._emitReady=()=>{a++,a>=this._readyCount&&(this._emitReady=X,this._readyEmitted=!0,process.nextTick(()=>this.emit(D.READY)))},this._emitRaw=(...r)=>this.emit(D.RAW,...r),this._boundRemove=this._remove.bind(this),this.options=s,this._nodeFsHandler=new J(this),Object.freeze(s)}_addIgnoredPath(t){if(mt(t)){for(let e of this._ignoredPaths)if(mt(e)&&e.path===t.path&&e.recursive===t.recursive)return}this._ignoredPaths.add(t)}_removeIgnoredPath(t){if(this._ignoredPaths.delete(t),typeof t=="string")for(let e of this._ignoredPaths)mt(e)&&e.path===t&&this._ignoredPaths.delete(e)}add(t,e,n){let{cwd:s}=this.options;this.closed=!1,this._closePromise=void 0;let o=Wt(t);return s&&(o=o.map(c=>Ge(c,s))),o.forEach(c=>{this._removeIgnoredPath(c)}),this._userIgnored=void 0,this._readyCount||(this._readyCount=0),this._readyCount+=o.length,Promise.all(o.map(async c=>{let a=await this._nodeFsHandler._addToNodeFs(c,!n,void 0,0,e);return a&&this._emitReady(),a})).then(c=>{this.closed||c.forEach(a=>{a&&this.add(m.dirname(a),m.basename(e||a))})}),this}unwatch(t){if(this.closed)return this;let e=Wt(t),{cwd:n}=this.options;return e.forEach(s=>{!m.isAbsolute(s)&&!this._closers.has(s)&&(n&&(s=m.join(n,s)),s=m.resolve(s)),this._closePath(s),this._addIgnoredPath(s),this._watched.has(s)&&this._addIgnoredPath({path:s,recursive:!0}),this._userIgnored=void 0}),this}close(){if(this._closePromise)return this._closePromise;this.closed=!0,this.removeAllListeners();let t=[];return this._closers.forEach(e=>e.forEach(n=>{let s=n();s instanceof Promise&&t.push(s)})),this._streams.forEach(e=>e.destroy()),this._userIgnored=void 0,this._readyCount=0,this._readyEmitted=!1,this._watched.forEach(e=>e.dispose()),this._closers.clear(),this._watched.clear(),this._streams.clear(),this._symlinkPaths.clear(),this._throttled.clear(),this._closePromise=t.length?Promise.all(t).then(()=>{}):Promise.resolve(),this._closePromise}getWatched(){let t={};return this._watched.forEach((e,n)=>{let o=(this.options.cwd?m.relative(this.options.cwd,n):n)||jt;t[o]=e.getChildren().sort()}),t}emitWithAll(t,e){this.emit(t,...e),t!==D.ERROR&&this.emit(D.ALL,t,...e)}async _emit(t,e,n){if(this.closed)return;let s=this.options;pt&&(e=m.normalize(e)),s.cwd&&(e=m.relative(s.cwd,e));let o=[e];n!=null&&o.push(n);let c=s.awaitWriteFinish,a;if(c&&(a=this._pendingWrites.get(e)))return a.lastChange=new Date,this;if(s.atomic){if(t===D.UNLINK)return this._pendingUnlinks.set(e,[t,...o]),setTimeout(()=>{this._pendingUnlinks.forEach((r,d)=>{this.emit(...r),this.emit(D.ALL,...r),this._pendingUnlinks.delete(d)})},typeof s.atomic=="number"?s.atomic:100),this;t===D.ADD&&this._pendingUnlinks.has(e)&&(t=D.CHANGE,this._pendingUnlinks.delete(e))}if(c&&(t===D.ADD||t===D.CHANGE)&&this._readyEmitted){let r=(d,f)=>{d?(t=D.ERROR,o[0]=d,this.emitWithAll(t,o)):f&&(o.length>1?o[1]=f:o.push(f),this.emitWithAll(t,o))};return this._awaitWriteFinish(e,c.stabilityThreshold,t,r),this}if(t===D.CHANGE&&!this._throttle(D.CHANGE,e,50))return this;if(s.alwaysStat&&n===void 0&&(t===D.ADD||t===D.ADD_DIR||t===D.CHANGE)){let r=s.cwd?m.join(s.cwd,e):e,d;try{d=await Me(r)}catch{}if(!d||this.closed)return;o.push(d)}return this.emitWithAll(t,o),this}_handleError(t){let e=t&&t.code;return t&&e!=="ENOENT"&&e!=="ENOTDIR"&&(!this.options.ignorePermissionErrors||e!=="EPERM"&&e!=="EACCES")&&this.emit(D.ERROR,t),t||this.closed}_throttle(t,e,n){this._throttled.has(t)||this._throttled.set(t,new Map);let s=this._throttled.get(t);if(!s)throw new Error("invalid throttle");let o=s.get(e);if(o)return o.count++,!1;let c,a=()=>{let d=s.get(e),f=d?d.count:0;return s.delete(e),clearTimeout(c),d&&clearTimeout(d.timeoutObject),f};c=setTimeout(a,n);let r={timeoutObject:c,clear:a,count:0};return s.set(e,r),r}_incrReadyCount(){return this._readyCount++}_awaitWriteFinish(t,e,n,s){let o=this.options.awaitWriteFinish;if(typeof o!="object")return;let c=o.pollInterval,a,r=t;this.options.cwd&&!m.isAbsolute(t)&&(r=m.join(this.options.cwd,t));let d=new Date,f=this._pendingWrites;function h(l){Se(r,(p,u)=>{if(p||!f.has(t)){p&&p.code!=="ENOENT"&&s(p);return}let g=Number(new Date);l&&u.size!==l.size&&(f.get(t).lastChange=g);let P=f.get(t);g-P.lastChange>=e?(f.delete(t),s(void 0,u)):a=setTimeout(h,c,u)})}f.has(t)||(f.set(t,{lastChange:d,cancelWait:()=>(f.delete(t),clearTimeout(a),n)}),a=setTimeout(h,c))}_isIgnored(t,e){if(this.options.atomic&&Oe.test(t))return!0;if(!this._userIgnored){let{cwd:n}=this.options,o=(this.options.ignored||[]).map(kt(n)),a=[...[...this._ignoredPaths].map(kt(n)),...o];this._userIgnored=Ue(a,void 0)}return this._userIgnored(t,e)}_isntIgnored(t,e){return!this._isIgnored(t,e)}_getWatchHelpers(t){return new wt(t,this.options.followSymlinks,this)}_getWatchedDir(t){let e=m.resolve(t);return this._watched.has(e)||this._watched.set(e,new _t(e,this._boundRemove)),this._watched.get(e)}_hasReadPermissions(t){return this.options.ignorePermissionErrors?!0:!!(Number(t.mode)&256)}_remove(t,e,n){let s=m.join(t,e),o=m.resolve(s);if(n=n??(this._watched.has(s)||this._watched.has(o)),!this._throttle("remove",s,100))return;!n&&this._watched.size===1&&this.add(t,e,!0),this._getWatchedDir(s).getChildren().forEach(l=>this._remove(s,l));let r=this._getWatchedDir(t),d=r.has(e);r.remove(e),this._symlinkPaths.has(o)&&this._symlinkPaths.delete(o);let f=s;if(this.options.cwd&&(f=m.relative(this.options.cwd,s)),this.options.awaitWriteFinish&&this._pendingWrites.has(f)&&this._pendingWrites.get(f).cancelWait()===D.ADD)return;this._watched.delete(s),this._watched.delete(o);let h=n?D.UNLINK_DIR:D.UNLINK;d&&!this._isIgnored(s)&&this._emit(h,s),this._closePath(s)}_closePath(t){this._closeFile(t);let e=m.dirname(t);this._getWatchedDir(e).remove(m.basename(t))}_closeFile(t){let e=this._closers.get(t);e&&(e.forEach(n=>n()),this._closers.delete(t))}_addPathCloser(t,e){if(!e)return;let n=this._closers.get(t);n||(n=[],this._closers.set(t,n)),n.push(e)}_readdirp(t,e){if(this.closed)return;let n={type:D.ALL,alwaysStat:!0,lstat:!0,...e,depth:0},s=It(t,n);return this._streams.add(s),s.once(Ft,()=>{s=void 0}),s.once(dt,()=>{s&&(this._streams.delete(s),s=void 0)}),s}};function Ze(i,t={}){let e=new et(t);return e.add(i),e}var Ht={watch:Ze,FSWatcher:et};import{pathToFileURL as hs,fileURLToPath as fs}from"node:url";import{join as x,sep as xt,dirname as te}from"node:path";import{copyFile as V,cp as ds,mkdir as ps,readFile as us,writeFile as ee}from"node:fs/promises";import{access as qe}from"node:fs/promises";import{constants as Je}from"node:fs";async function N(i){try{return await qe(i,Je.F_OK),!0}catch{return!1}}import{access as Xe}from"node:fs/promises";import{constants as Qe}from"node:fs";async function j(i){try{return await Xe(i,Qe.F_OK),!0}catch{return!1}}import{join as M}from"node:path";import{readdir as ts}from"node:fs/promises";async function O(i){let t=[];try{let e=await ts(i,{withFileTypes:!0});for(let n of e)n.isDirectory()&&t.push(n.name)}catch(e){console.error("Error reading directory:",e)}return t}import{readFile as Yt}from"node:fs/promises";function st(i){return i&&i.charAt(0).toUpperCase()+i.slice(1)}function it(i){return i.replace(/([a-zA-Z])(?=[A-Z])/g,"$1-").toLowerCase()}var gt=i=>`\x1B[31m${i}\x1B[0m`,Xs=process.cwd();var z="src",L="components";function Ut(i){return{name:"playground-plugin",setup(t){let e="playground-entry",n="playground-module";t.onResolve({filter:new RegExp(`^${e}$`)},s=>({path:e,namespace:n})),t.onLoad({filter:/.*/,namespace:n},async s=>{let o=[],c=await O(M(z,L));c.length===0&&(console.log(gt('Missing at least 1 namespace folder under "src/components/"')),process.exit());let a=[];for(let r of c){let d={namespace:r,components:[]};a.push(d);let f=M(z,L,r),h=await O(f);for(let l of h)if(await N(M(z,L,r,l,`${l}.ts`))){let p="";await N(M(z,L,r,l,"README.md"))&&(p=await Yt(M(z,L,r,l,"README.md"),"utf8"));let u={namespace:r,component:l,tag:`${r}-${it(l)}`,examples:[],className:"",classExtends:"",readme:p};if(o.push(`import '${L}/${r}/${l}/${l}';`),await j(M(f,l,"__examples__"))){let _=await O(M(f,l,"__examples__"));for(let w of _)await N(M(f,l,"__examples__",w,`${w}.ts`))?(o.push(`import '${L}/${r}/${l}/__examples__/${w}/${w}';`),u.examples.push({namespace:r,component:l,example:w,tag:`x-${r}-${it(l)}-${it(w)}`,className:`X${st(r)}${st(l)}${st(w)}`})):console.log(gt(`Missing ${L}/${r}/${l}/__examples__/${w}/${w}.ts`))}let P=(await Yt(M(z,L,r,l,`${l}.ts`),"utf8")).match(/class (\w+) extends (\w+)/);P||(console.log(gt(`Component "${r}-${l}" must extend HtmlElement or base class`)),process.exit()),u.className=P[1],u.classExtends=P[2],d.components.push(u)}}return i.after(a),{contents:o.join(`
|
|
4
|
+
`),resolveDir:M(process.cwd(),z)}})}}}import{sep as Vt}from"node:path";import{readFile as es}from"node:fs/promises";function Gt(i){return i.replace(/-([a-z])/g,t=>t[1].toUpperCase())}var ss=process.cwd(),is=ss.split(Vt).length,ns=i=>`\x1B[31m${i}\x1B[0m`;function Bt({localNamespaces:i,externalNamespaces:t}){return{name:"html-dependents-plugin",setup(e){e.onLoad({filter:/\.html$/},async n=>{let s=n.path.split(Vt).splice(is),[o,c,a,r,...d]=s,f=await es(n.path,"utf8"),h=f.matchAll(/<\/(?<namespace>\w+)-(?<value>[^>]+)/g),l=new Map;for(let u of h){let{namespace:g,value:P}=u.groups,_=Gt(P);l.set(`${g}-${_}`,[g,_])}let p=[];return l.forEach(([u,g])=>{let P=s.length-4,_=new Array(P).fill("..");if(u===a){if(g===r)return;p.push(`import './${_.join("/")}/${g}/${g}';`)}else if(i.includes(u))p.push(`import './${_.join("/")}/${u}/${g}/${g}';`);else if(t.has(u)){_.push(".."),_.push(".."),_.push("..");let w=t.get(u);p.push(`import '${w}/${u}/${g}/${g}';`)}else console.log(ns(`Unable to find namespace folder "${u}". Possibly missing 'external' in element.config.ts`)),process.exit()}),p.push(`export default \`${f}\`;`),{contents:p.join(`
|
|
5
|
+
`),loader:"js"}})}}}var rs=i=>`\x1B[32m${i}\x1B[0m`,Kt={name:"rebuild-notify",setup(i){i.onEnd(t=>{t.errors.length>0?console.error(`Build ended with ${t.errors.length} errors`):console.log(rs("Build succeeded!"))})}};import{join as yt}from"node:path";import{readFile as Zt}from"node:fs/promises";async function qt({mode:i,rootDir:t,srcDir:e,indexFile:n,defaultDir:s,playgroundFile:o,title:c,repo:a,repoComponent:r,navigation:d,namespaces:f}){let h="";await N(yt(t,e,n))?h=await Zt(yt(t,e,n),"utf8"):h=await Zt(yt(s,o),"utf8"),h=h.replace("<title>Default</title>",`<title>${c??"Default"}</title>`),h=h.replace("<h1>Default</h1>",`<h1>${c??"Default"}</h1>`);let l=structuredClone(d??[]);for(let P of l)P.items=[];let p;l.length===0?(p={label:"Components",items:[]},l.push(p)):(p=l.find(P=>!P.extends&&!P.components&&!P.namespaces),p||(p={label:"Other",items:[]},l.push(p)));let u=new Map;if(f.forEach(({components:P})=>{P.forEach(({component:_,namespace:w,tag:I,readme:C,examples:v,className:$,classExtends:H})=>{u.set($,{className:$,classExtends:H,component:_,namespace:w,tag:I,readme:C,examples:v.map(E=>E.className)}),v.forEach(E=>{u.set(E.className,{className:E.className,classExtends:E.classExtends,component:E.component,namespace:E.namespace,tag:E.tag,example:E.example})});for(let E of l)if(E.include&&E.include.includes($)){E.items.push({namespace:w,component:_,className:$,tag:I});return}for(let E of l)if(E!==p&&!(E.exclude&&E.exclude.includes($))&&!(E.namespaces&&!E.namespaces.includes(w))&&!(E.extends&&!E.extends.includes(H))){E.items.push({namespace:w,component:_,className:$,tag:I});return}p.items.push({namespace:w,component:_,examples:v,className:$,tag:I})})}),h=h.replace(/([ ]*)<!-- \[Navigation\] -->/,(P,_)=>l.map(({label:w,items:I})=>[_,`<div>${w}</div>`,"<ul>",I.map(({component:C,namespace:v,tag:$,className:H})=>[`<li data-tag="${$}" data-class-name="${H}" data-component="${C}"><a href="#${$}">${C}</a></li>`].join(`
|
|
6
6
|
${_}`)).join(`
|
|
7
7
|
${_}`),"</ul>"].join(`
|
|
8
8
|
${_}`)).join(`
|
|
9
|
-
${_}`)),
|
|
10
|
-
${C}`)),h=h.replace(/const repo = '';/,I=>`const repo = '${
|
|
11
|
-
${_}`)));let g=[...u.keys()];return h=h.replace(/([ ]*)const componentMap = new Map\(\);/,(
|
|
12
|
-
`)),h=h.replace(/([ ]*)const navigation = \[\];/,(
|
|
9
|
+
${_}`)),a){let w=a.includes("github.com")?"M12,2A10,10 0 0,0 2,12C2,16.42 4.87,20.17 8.84,21.5C9.34,21.58 9.5,21.27 9.5,21C9.5,20.77 9.5,20.14 9.5,19.31C6.73,19.91 6.14,17.97 6.14,17.97C5.68,16.81 5.03,16.5 5.03,16.5C4.12,15.88 5.1,15.9 5.1,15.9C6.1,15.97 6.63,16.93 6.63,16.93C7.5,18.45 8.97,18 9.54,17.76C9.63,17.11 9.89,16.67 10.17,16.42C7.95,16.17 5.62,15.31 5.62,11.5C5.62,10.39 6,9.5 6.65,8.79C6.55,8.54 6.2,7.5 6.75,6.15C6.75,6.15 7.59,5.88 9.5,7.17C10.29,6.95 11.15,6.84 12,6.84C12.85,6.84 13.71,6.95 14.5,7.17C16.41,5.88 17.25,6.15 17.25,6.15C17.8,7.5 17.45,8.54 17.35,8.79C18,9.5 18.38,10.39 18.38,11.5C18.38,15.32 16.04,16.16 13.81,16.41C14.17,16.72 14.5,17.33 14.5,18.26C14.5,19.6 14.5,20.68 14.5,21C14.5,21.27 14.66,21.59 15.17,21.5C19.14,20.16 22,16.42 22,12A10,10 0 0,0 12,2Z":"M6,2H18A2,2 0 0,1 20,4V20A2,2 0 0,1 18,22H6A2,2 0 0,1 4,20V4A2,2 0 0,1 6,2M12.75,13.5C15.5,13.5 16.24,11.47 16.43,10.4C17.34,10.11 18,9.26 18,8.25C18,7 17,6 15.75,6C14.5,6 13.5,7 13.5,8.25C13.5,9.19 14.07,10 14.89,10.33C14.67,11 14,12 12,12C10.62,12 9.66,12.35 9,12.84V8.87C9.87,8.56 10.5,7.73 10.5,6.75C10.5,5.5 9.5,4.5 8.25,4.5C7,4.5 6,5.5 6,6.75C6,7.73 6.63,8.56 7.5,8.87V15.13C6.63,15.44 6,16.27 6,17.25C6,18.5 7,19.5 8.25,19.5C9.5,19.5 10.5,18.5 10.5,17.25C10.5,16.32 9.94,15.5 9.13,15.18C9.41,14.5 10.23,13.5 12.75,13.5M8.25,16.5A0.75,0.75 0 0,1 9,17.25A0.75,0.75 0 0,1 8.25,18A0.75,0.75 0 0,1 7.5,17.25A0.75,0.75 0 0,1 8.25,16.5M8.25,6A0.75,0.75 0 0,1 9,6.75A0.75,0.75 0 0,1 8.25,7.5A0.75,0.75 0 0,1 7.5,6.75A0.75,0.75 0 0,1 8.25,6M15.75,7.5A0.75,0.75 0 0,1 16.5,8.25A0.75,0.75 0 0,1 15.75,9A0.75,0.75 0 0,1 15,8.25A0.75,0.75 0 0,1 15.75,7.5Z";h=h.replace(/([ ]*)<!-- \[Repo\] -->/,(I,C)=>[C,`<a href="${a}">`,' <svg viewBox="0 0 24 24">',` <path fill="currentColor" d="${w}" />`," </svg>"," <span>View Repo</span>","</a>"].join(`
|
|
10
|
+
${C}`)),h=h.replace(/const repo = '';/,I=>`const repo = '${a}';`),h=h.replace(/const repoComponent = '';/,I=>`const repoComponent = '${r.replace(/\$repo/g,a)}';`),h=h.replace(/const repoIcon = '';/,I=>`const repoIcon = '${w}';`)}i==="dev"&&(h=h.replace(/([ ]*)<!-- \[info\] -->/,(P,_)=>[_,"<p>This page is generated from <code>npm start</code>. To render only specific components use <code>npm start c-button</code>.</p>"].join(`
|
|
11
|
+
${_}`)));let g=[...u.keys()];return h=h.replace(/([ ]*)const componentMap = new Map\(\);/,(P,_)=>[`${_}const componentMap = new Map();`,...g.map(w=>{let I=u.get(w);return`componentMap.set('${w}', ${JSON.stringify(I)});`})].join(`${_}
|
|
12
|
+
`)),h=h.replace(/([ ]*)const navigation = \[\];/,(P,_)=>`${_}const navigation = ${JSON.stringify(l,null," ")};`),h}import{existsSync as os}from"node:fs";import{join as as,resolve as Jt,sep as cs}from"node:path";var Xt=process.env.INIT_CWD,Et="";Xt?Et=as(Xt,"node_modules"):(console.log("INIT_CWD not available. The script was likely not run via `npm run`."),process.exit());function Qt({external:i}){return{name:"resolve-external",setup(t){i.forEach(e=>{t.onResolve({filter:new RegExp(`^${e}/`)},n=>{let s=Jt(Et,...e.split("/"),n.path.substring(`${e}/`.length));if(!os(`${s}.ts`)){let o=n.path.substring(`${e}/`.length),c=o.split(cs);s=Jt(Et,...e.split("/"),o,c[c.length-1])}return{path:s}})})}}}(async()=>{let i=[Kt],t=R=>`\x1B[1m${R}\x1B[0m`,e=R=>`\x1B[32m${R}\x1B[0m`,n=R=>`\x1B[31m${R}\x1B[0m`,s=fs(import.meta.url),o=te(s),c=x(o,"..","default"),a="element.config.ts",r=process.cwd(),d="publish",f=hs(a);await N(a)||(console.log(n("Missing element.config.ts in root."),"Add with content:"),console.log("export default {"),console.log(" namespace: 'hello',"),console.log("}"),process.exit());let h=await import(f.href),{namespace:l,external:p,title:u,navigation:g,repo:P,repoComponent:_,copy:w}=h.default,I="node_modules",C="dist",v="src",$="components",H=await O(x(r,v,$)),E=new Map;for(let R of p??[])(await O(x(r,I,...R.split("/")))).forEach(y=>{y!==I&&E.set(y,R)});i.push(Qt({external:p??[]})),i.push(Bt({localNamespaces:H,externalNamespaces:E}));let nt=[];if(l){console.log(e("Building app...")),nt.push(`./${v}/${$}/${l}/app/app.ts`);let R="index.html";if(await N(x(r,v,R)))await V(x(r,v,R),x(r,C,R));else{let y=await us(x(c,R),"utf8");y=y.replace("<title>Default</title>",`<title>${u??"Default"}</title>`),y=y.replace("<namespace-app></namespace-app>",`<${l}-app></${l}-app>`),await ee(x(r,C,R),y)}let T="favicon.svg";await N(x(r,v,T))?await V(x(r,v,T),x(r,C,T)):await V(x(c,T),x(r,C,T))}else{console.log(e("Building components...")),await j(x(v,$))||(console.log(n('Missing required "src/components" directory.')),process.exit());let R="playground.html",T="index.html";nt.push("playground-entry"),i.push(Ut({after:async y=>{let F=await qt({mode:"dev",rootDir:r,srcDir:v,indexFile:T,defaultDir:c,playgroundFile:R,title:u,repo:P,repoComponent:_,navigation:g,namespaces:y});await ee(x(r,C,T),F)}}))}let rt=await ls({entryPoints:nt,outfile:`./${C}/main.js`,bundle:!0,format:"esm",target:"es2024",sourcemap:!0,minify:!1,loader:{".css":"text"},plugins:i});await rt.rebuild(),(w??[]).forEach(async({from:R,to:T,exclude:y})=>{let F=T.split(xt),W=R.split(xt);if(W[W.length-1]===""&&(console.log(n('element.config.ts "copy" "from" should not end with a "/". Ex: "assets" not "assets/".')),process.exit()),F[F.length-1]===""&&(console.log(n('element.config.ts "copy" "to" should not end with a "/". Ex: "assets" not "assets/".')),process.exit()),y){let ot=W.join("/");for(let B of y)if(ot.includes(B))return}await j(x(r,v,...W))?await ds(x(r,v,...W),x(r,C,...F),{recursive:!0}):await N(x(r,v,...W))&&await V(x(r,v,...W),x(r,C,...F))}),Ht.watch("src",{ignoreInitial:!0}).on("all",async(R,T)=>{if(!l){let y=T.split(xt);if(y.length>4&&y[0]===v&&y[1]===$){let F=te(x(r,d,...y.slice(2)));await j(F)||(console.log(`Creating publish/"${y.slice(2,-1).join("/")}"`),await ps(F,{recursive:!0})),console.log(`Copy "${y.slice(2).join("/")}" to publish/*`),await V(x(r,...y),x(r,d,...y.slice(2)))}(R==="change"||R==="add")&&((w??[]).forEach(async({from:F,to:W,exclude:ot})=>{let B=y.slice(1).join("/");B.startsWith(F)&&console.log("copy after",B,F,W,ot)}),await j(x(r,...y)))}try{await rt.rebuild()}catch(y){console.error("Rebuild failed:",y)}});let{port:se}=await rt.serve({servedir:C});console.log(e("Dev server started at"),`localhost:${se}`)})();
|
|
13
13
|
/*! Bundled license information:
|
|
14
14
|
|
|
15
15
|
chokidar/index.js:
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// This is very dumb, when npm link is used esbuild won't resolve
|
|
2
2
|
// the local packages so this gets around that.
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { existsSync } from 'node:fs';
|
|
5
|
+
import { join, resolve, sep } from 'node:path';
|
|
5
6
|
|
|
6
7
|
const projectRoot = process.env.INIT_CWD;
|
|
7
8
|
let rootNodeModules: string = '';
|
|
@@ -13,7 +14,7 @@ if (projectRoot) {
|
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
interface PluginOptions {
|
|
16
|
-
external:
|
|
17
|
+
external: string[];
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
export function resolveExternal({ external }: PluginOptions) {
|
|
@@ -22,8 +23,19 @@ export function resolveExternal({ external }: PluginOptions) {
|
|
|
22
23
|
setup(build: any) {
|
|
23
24
|
external.forEach((pkgName) => {
|
|
24
25
|
build.onResolve({ filter: new RegExp(`^${pkgName}/`) }, (args: any) => {
|
|
25
|
-
// Resolve the path relative to the current working directory,
|
|
26
|
-
|
|
26
|
+
// Resolve the path relative to the current working directory,
|
|
27
|
+
let resolvedPath = resolve(rootNodeModules, ...pkgName.split('/'), args.path.substring(`${pkgName}/`.length));
|
|
28
|
+
// also resolve external/namespace/comp shorthand
|
|
29
|
+
if (!existsSync(`${resolvedPath}.ts`)) {
|
|
30
|
+
const path = args.path.substring(`${pkgName}/`.length);
|
|
31
|
+
const parts = path.split(sep);
|
|
32
|
+
resolvedPath = resolve(
|
|
33
|
+
rootNodeModules,
|
|
34
|
+
...pkgName.split('/'),
|
|
35
|
+
path,
|
|
36
|
+
parts[parts.length - 1]
|
|
37
|
+
);
|
|
38
|
+
}
|
|
27
39
|
return { path: resolvedPath };
|
|
28
40
|
});
|
|
29
41
|
});
|