@remotex-labs/xbuild 2.5.0 → 3.0.0
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 +30 -4
- package/dist/bash.d.ts +3135 -0
- package/dist/bash.js +41 -66
- package/dist/bash.js.map +1 -1
- package/dist/index.d.ts +2774 -4978
- package/dist/index.js +23 -27
- package/dist/index.js.map +1 -1
- package/package.json +26 -16
package/dist/index.js
CHANGED
|
@@ -1,38 +1,34 @@
|
|
|
1
|
-
var
|
|
2
|
-
${
|
|
3
|
-
|
|
4
|
-
`);return{getPositionWithCode:(s,a,c,l)=>{let f=l?.linesBefore??3,p=l?.linesAfter??3,d=Math.max(s-f,0),m=Math.min(s+p,o.length);return{line:s,column:a+1,code:o.slice(d,m).join(`
|
|
5
|
-
`),source:r,name:null,startLine:d,endLine:m,sourceRoot:null,sourceIndex:-1,generatedLine:-1,generatedColumn:-1}}}}function er(r){return r instanceof Error?Ge(r):r.detail instanceof Error?Ge(r.detail):r.location?{name:"esBuildMessage",message:r.text??"",rawStack:"",stack:[{source:`@${r.location.file}`,line:r.location.line,column:r.location.column,fileName:r.location.file,eval:!1,async:!1,native:!1,constructor:!1}]}:{stack:[],name:"esBuildMessage",message:r.text??"",rawStack:""}}function _(r,e){let t=u(b),i=u(x).getValue(s=>s.verbose)??!1,n=er(r),o=Jt(n,{...e,withNativeFrames:i||(e?.withFrameworkFrames??!1),getSource(s){return Zt(s)}});return o.stack.filter(s=>{if(!(e?.withFrameworkFrames??!1)&&t.isFrameworkFile(s))return!1;!o.formatCode&&s.code&&(o.formatCode=Yt({code:Qt(s.code),line:s.line??0,column:s.column??0,startLine:s.stratLine??0},{color:Ce.brightPink}))}),o}function z(r,e,t,i=[]){let n=[`
|
|
6
|
-
${e}: ${Ce.lightCoral(t)}`];for(let o of i??[])o.text&&n.push(`
|
|
7
|
-
`+Ce.gray(o.text));return r.formatCode&&n.push(`
|
|
8
|
-
|
|
9
|
-
${r.formatCode}`),r.stack.length&&n.push(`
|
|
10
|
-
|
|
11
|
-
Enhanced Stack Trace:
|
|
12
|
-
${r.stack.map(o=>o.format).join(`
|
|
13
|
-
`)}
|
|
14
|
-
`),n.join("")}var I=class extends Error{errorMetadata;formattedStack;constructor(e,t="xBuildBaseError"){super(e),Object.setPrototypeOf(this,new.target.prototype),this.name=t,Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}get metadata(){return this.errorMetadata}[Symbol.for("nodejs.util.inspect.custom")](){return this.formattedStack||this.stack}reformatStack(e,t){this.errorMetadata=_(e,t),this.formattedStack=z(this.errorMetadata,e.name,e.message)}};var w=class extends I{constructor(e,t={withFrameworkFrames:!0}){super(e),this.reformatStack(this,t)}};var B=class extends I{id;constructor(e,t){super(e.text??"","esBuildError"),this.id=e.id??"",e.detail instanceof Error?(this.stack=e.detail.stack,this.message=e.detail.message,this.reformatStack(e.detail,t)):(this.errorMetadata=_(e,{withFrameworkFrames:!0}),this.stack=z(this.errorMetadata,this.name,this.message,e.notes))}};function tr(r){if(r instanceof I)return r;if(r.detail instanceof I||r.detail instanceof j)return r.detail;if(r.detail instanceof Error)return new B(r,{withFrameworkFrames:!0});if(r.location)return new B(r);if(r.text)return new w(r.text)}function re(r=[],e){for(let t of r){let i=tr(t);i&&e.push(i)}}function Ie(r){let e={errors:[],warnings:[],metafile:r.metafile,outputFiles:r.outputFiles,mangleCache:r.mangleCache};return re(r.errors,e.errors),re(r.warnings,e.warnings),e}function U(r){return typeof r=="object"&&r!==null&&"errors"in r}import*as Qe from"http";import*as Ze from"https";import{extname as Je}from"path";import{readFileSync as Ye}from"fs";var Xe=`<!doctype html><html lang="en"><head><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1"/><title>Dark File Browser \u2014 FTP-like</title><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.0.1/css/all.min.css" integrity="sha512-2SwdPD6INVrV/lHTZbO2nodKhrnDdJK9/kg2XD1r9uGqPo1cUbujc+IYdlYdEErWNu69gVcYgdxlmVmzTWnetw==" crossorigin="anonymous" referrerpolicy="no-referrer" /><style>:root{--bg:#0b0f14;--panel:#0f1720;--muted:#9aa4b2;--accent:#E5C07B;--glass:rgba(255,255,255,0.03);--card:#0c1116;--radius:12px;--gap:12px;--shadow:0 6px 18px rgba(0,0,0,0.4);--file-icon-size:40px;font-family:Inter,ui-sans-serif,system-ui,-apple-system,'Segoe UI',Roboto,'Helvetica Neue',Arial}*{box-sizing:border-box;font-style:normal !important}html,body{height:100%;margin:0;font-size:14px;color:#dce7ef;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;background:radial-gradient(1200px 600px at 10% 10%,rgba(110,231,183,0.04),transparent 8%),linear-gradient(180deg,rgba(255,255,255,0.01),transparent 20%),var(--bg);padding:28px;display:flex;gap:20px;align-items:flex-start;justify-content:center}.app{width:1100px;max-width:98vw;display:flex;gap:18px;padding:18px;border-radius:16px;box-shadow:var(--shadow);border:1px solid rgba(255,255,255,0.03);background:linear-gradient(180deg,rgba(255,255,255,0.02),rgba(255,255,255,0));overflow:hidden}.sidebar{width:260px;background:linear-gradient(180deg,rgba(255,255,255,0.01),transparent);border-radius:var(--radius);padding:14px}.brand{display:flex;gap:12px;align-items:center;margin-bottom:10px}.logo{width:46px;height:46px;border-radius:10px;background:linear-gradient(135deg,#b65b9f 0%,#804b8f 100%);display:flex;align-items:center;justify-content:center;font-weight:700}.brand h1{font-size:16px;margin:0}.muted{color:var(--muted);font-size:13px}.search{margin:12px 0}.search input{width:100%;padding:10px 12px;border-radius:10px;border:1px solid rgba(255,255,255,0.03);background:var(--glass);color:inherit}.quick-list{margin-top:12px}.quick-list a{display:flex;align-items:center;gap:10px;padding:8px 10px;border-radius:8px;background:transparent;color:var(--muted);text-decoration:none;cursor:pointer;transition:color 0.15s ease}.quick-list a:hover{color:var(--accent)}.main{flex:1;display:flex;flex-direction:column}.topbar{display:flex;align-items:center;gap:12px;padding-bottom:12px}.breadcrumbs{list-style:none;display:flex;gap:8px;align-items:center;background:var(--glass);padding:8px 12px;border-radius:var(--radius);margin:0}.breadcrumbs li{display:flex;align-items:center}.breadcrumbs li:not(:last-child)::after{content:'>';margin-left:8px;color:var(--muted)}.breadcrumbs a{color:var(--muted);text-decoration:none;transition:color 0.15s ease}.breadcrumbs a:hover{color:var(--accent)}.list{margin-top:14px;display:grid;grid-template-columns:1fr;gap:10px}.list a{display:flex;text-decoration:none;color:inherit}.folder-row,.file-row{display:flex;gap:12px;align-items:center;padding:10px;border-radius:10px;background:linear-gradient(180deg,rgba(255,255,255,0.01),transparent);border:1px solid rgba(255,255,255,0.02);transition:color 0.25s ease}.icon{width:var(--file-icon-size);height:var(--file-icon-size);border-radius:10px;display:flex;align-items:center;justify-content:center;background:rgba(255,255,255,0.02);flex-shrink:0;transition:background 0.25s ease,color 0.25s ease}.folder-row:hover,.file-row:hover{color:var(--accent)}.folder-row:hover .icon{background:rgba(152,195,121,0.2)}.file-row:hover .icon{background:rgba(224,108,117,0.2)}.folder-row:hover .icon i{color:#98C379}.file-row:hover .icon i{color:#e09c6c}.meta{display:flex;flex-direction:column}.name{font-weight:600}.sub{color:var(--muted);font-size:13px}.empty{padding:40px;text-align:center;color:var(--muted)}@media (max-width:880px){.app{flex-direction:column;padding:12px}.sidebar,.main{width:100%}}</style></head><body><div class="app"><aside class="sidebar"><div class="brand"><div class="logo">F</div><div><h1>xBuildFTP</h1><div class="muted">Browse & serve files</div></div></div><div class="search"><input placeholder="Search files & folders..."/></div><div class="quick-list"><a href="/">\u{1F3E0} Home</a><a href="\${ up }">\u2B06\uFE0F Up</a></div></aside><main class="main"><div class="topbar"><div class="topbar"><ul class="breadcrumbs"> \${ paths } </ul></div></div> \${ fileList } </main></div></body><script> const searchInput = document.querySelector('.search input'); const listItems = document.querySelectorAll('.list > .folder-row, .list > .file-row'); const emptyMessage = document.querySelector('.empty'); searchInput.addEventListener('input', () => { const query = searchInput.value.toLowerCase(); let anyVisible = false; listItems.forEach(item => { const name = item.querySelector('.name').textContent.toLowerCase(); if (name.includes(query)) { item.style.display = 'flex'; anyVisible = true; } else { item.style.display = 'none'; } }); emptyMessage.style.display = anyVisible ? 'none' : 'block'; }); </script></html>`;import{resolve as nr,join as ie}from"@remotex-labs/xmap";import{xterm as ir}from"@remotex-labs/xansi/xterm.component";function H(){return ir.lightCoral("[xBuild]")}import{readdir as or,stat as sr,readFile as ar}from"fs/promises";import{xterm as ne}from"@remotex-labs/xansi/xterm.component";var Ee=class{constructor(e,t){this.config=e;this.rootDir=nr(t),this.config.port||=0,this.config.host||="localhost"}config;server;rootDir;framework=u(b);async start(){if(this.config.https)return await this.startHttpsServer();await this.startHttpServer()}async stop(){if(!this.server){console.log(H(),ne.gray("No server is currently running."));return}await new Promise((e,t)=>{this.server.close(i=>{i?t(i):e()})}),console.log(H(),ne.dim("Server stopped.")),this.server=void 0}async restart(){console.log(H(),ne.burntOrange("Restarting server...")),await this.stop(),await this.start()}setActualPort(){if(this.config.port===0){let e=this.server.address();e&&typeof e=="object"&&e.port&&(this.config.port=e.port)}}startHttpServer(){return new Promise(e=>{this.server=Qe.createServer((t,i)=>{this.handleRequest(t,i,()=>this.defaultResponse(t,i))}),this.server.listen(this.config.port,this.config.host,()=>{this.setActualPort(),this.config.onStart?.({host:this.config.host,port:this.config.port,url:`http://${this.config.host}:${this.config.port}`}),e()})})}startHttpsServer(){return new Promise(e=>{let t={key:Ye(this.config.key??ie(this.framework.distPath,"..","certs","server.key")),cert:Ye(this.config.cert??ie(this.framework.distPath,"..","certs","server.crt"))};this.server=Ze.createServer(t,(i,n)=>{this.handleRequest(i,n,()=>this.defaultResponse(i,n))}),this.server.listen(this.config.port,this.config.host,()=>{this.setActualPort(),this.config.onStart?.({host:this.config.host,port:this.config.port,url:`https://${this.config.host}:${this.config.port}`}),e()})})}handleRequest(e,t,i){try{this.config.verbose&&console.log(`${H()} Request ${ne.lightCoral(e.url?.toString()??"")}`),this.config.onRequest?this.config.onRequest(e,t,i):i()}catch(n){this.sendError(t,n)}}getContentType(e){return{html:"text/html",css:"text/css",js:"application/javascript",cjs:"application/javascript",mjs:"application/javascript",ts:"text/plain",map:"application/json",json:"application/json",png:"image/png",jpg:"image/jpeg",gif:"image/gif",txt:"text/plain"}[e]||"application/octet-stream"}async defaultResponse(e,t){let i=e.url==="/"?"":e.url?.replace(/^\/+/,"")||"",n=ie(this.rootDir,i);if(!n.startsWith(this.rootDir)){t.statusCode=403,t.end();return}try{let o=await sr(n);o.isDirectory()?await this.handleDirectory(n,i,t):o.isFile()&&await this.handleFile(n,t)}catch(o){let s=o.message;s.includes("favicon")||console.log(H(),s),this.sendNotFound(t)}}async handleDirectory(e,t,i){let o=(await or(e)).map(l=>{let f=ie(t,l),p=Je(l).slice(1)||"folder";return p==="folder"?`
|
|
15
|
-
<a href="/${f}" class="folder-row">
|
|
1
|
+
var W=Object.defineProperty;var ee=Object.getOwnPropertyDescriptor;var te=(o,e,t)=>e in o?W(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t;var y=(o,e,t,r)=>{for(var i=r>1?void 0:r?ee(e,t):e,s=o.length-1,n;s>=0;s--)(n=o[s])&&(i=(r?n(e,t,i):n(i))||i);return r&&i&&W(e,t,i),i};var k=(o,e,t)=>te(o,typeof e!="symbol"?e+"":e,t);import*as Q from"http";import*as X from"https";import{extname as U}from"path";import{readFileSync as K}from"fs";var V=`<!doctype html><html lang="en"><head><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1"/><title>Dark File Browser \u2014 FTP-like</title><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.0.1/css/all.min.css" integrity="sha512-2SwdPD6INVrV/lHTZbO2nodKhrnDdJK9/kg2XD1r9uGqPo1cUbujc+IYdlYdEErWNu69gVcYgdxlmVmzTWnetw==" crossorigin="anonymous" referrerpolicy="no-referrer" /><style>:root{--bg:#0b0f14;--panel:#0f1720;--muted:#9aa4b2;--accent:#E5C07B;--glass:rgba(255,255,255,0.03);--card:#0c1116;--radius:12px;--gap:12px;--shadow:0 6px 18px rgba(0,0,0,0.4);--file-icon-size:40px;font-family:Inter,ui-sans-serif,system-ui,-apple-system,'Segoe UI',Roboto,'Helvetica Neue',Arial}*{box-sizing:border-box;font-style:normal !important}html,body{height:100%;margin:0;font-size:14px;color:#dce7ef;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;background:radial-gradient(1200px 600px at 10% 10%,rgba(110,231,183,0.04),transparent 8%),linear-gradient(180deg,rgba(255,255,255,0.01),transparent 20%),var(--bg);padding:28px;display:flex;gap:20px;align-items:flex-start;justify-content:center}.app{width:1100px;max-width:98vw;display:flex;gap:18px;padding:18px;border-radius:16px;box-shadow:var(--shadow);border:1px solid rgba(255,255,255,0.03);background:linear-gradient(180deg,rgba(255,255,255,0.02),rgba(255,255,255,0));overflow:hidden}.sidebar{width:260px;background:linear-gradient(180deg,rgba(255,255,255,0.01),transparent);border-radius:var(--radius);padding:14px}.brand{display:flex;gap:12px;align-items:center;margin-bottom:10px}.logo{width:46px;height:46px;border-radius:10px;background:linear-gradient(135deg,#b65b9f 0%,#804b8f 100%);display:flex;align-items:center;justify-content:center;font-weight:700}.brand h1{font-size:16px;margin:0}.muted{color:var(--muted);font-size:13px}.search{margin:12px 0}.search input{width:100%;padding:10px 12px;border-radius:10px;border:1px solid rgba(255,255,255,0.03);background:var(--glass);color:inherit}.quick-list{margin-top:12px}.quick-list a{display:flex;align-items:center;gap:10px;padding:8px 10px;border-radius:8px;background:transparent;color:var(--muted);text-decoration:none;cursor:pointer;transition:color 0.15s ease}.quick-list a:hover{color:var(--accent)}.main{flex:1;display:flex;flex-direction:column}.topbar{display:flex;align-items:center;gap:12px;padding-bottom:12px}.breadcrumbs{list-style:none;display:flex;gap:8px;align-items:center;background:var(--glass);padding:8px 12px;border-radius:var(--radius);margin:0}.breadcrumbs li{display:flex;align-items:center}.breadcrumbs li:not(:last-child)::after{content:'>';margin-left:8px;color:var(--muted)}.breadcrumbs a{color:var(--muted);text-decoration:none;transition:color 0.15s ease}.breadcrumbs a:hover{color:var(--accent)}.list{margin-top:14px;display:grid;grid-template-columns:1fr;gap:10px}.list a{display:flex;text-decoration:none;color:inherit}.folder-row,.file-row{display:flex;gap:12px;align-items:center;padding:10px;border-radius:10px;background:linear-gradient(180deg,rgba(255,255,255,0.01),transparent);border:1px solid rgba(255,255,255,0.02);transition:color 0.25s ease}.icon{width:var(--file-icon-size);height:var(--file-icon-size);border-radius:10px;display:flex;align-items:center;justify-content:center;background:rgba(255,255,255,0.02);flex-shrink:0;transition:background 0.25s ease,color 0.25s ease}.folder-row:hover,.file-row:hover{color:var(--accent)}.folder-row:hover .icon{background:rgba(152,195,121,0.2)}.file-row:hover .icon{background:rgba(224,108,117,0.2)}.folder-row:hover .icon i{color:#98C379}.file-row:hover .icon i{color:#e09c6c}.meta{display:flex;flex-direction:column}.name{font-weight:600}.sub{color:var(--muted);font-size:13px}.empty{padding:40px;text-align:center;color:var(--muted)}@media (max-width:880px){.app{flex-direction:column;padding:12px}.sidebar,.main{width:100%}}</style></head><body><div class="app"><aside class="sidebar"><div class="brand"><div class="logo">F</div><div><h1>xBuildFTP</h1><div class="muted">Browse & serve files</div></div></div><div class="search"><input placeholder="Search files & folders..."/></div><div class="quick-list"><a href="/">\u{1F3E0} Home</a><a href="\${ up }">\u2B06\uFE0F Up</a></div></aside><main class="main"><div class="topbar"><div class="topbar"><ul class="breadcrumbs"> \${ paths } </ul></div></div> \${ fileList } </main></div></body><script> const searchInput = document.querySelector('.search input'); const listItems = document.querySelectorAll('.list > .folder-row, .list > .file-row'); const emptyMessage = document.querySelector('.empty'); searchInput.addEventListener('input', () => { const query = searchInput.value.toLowerCase(); let anyVisible = false; listItems.forEach(item => { const name = item.querySelector('.name').textContent.toLowerCase(); if (name.includes(query)) { item.style.display = 'flex'; anyVisible = true; } else { item.style.display = 'none'; } }); emptyMessage.style.display = anyVisible ? 'none' : 'block'; }); </script></html>`;import{join as C}from"@remotex-labs/xmap";import{inject as ue}from"@remotex-labs/xinject";import{Subject as he}from"@remotex-labs/xobservable";import{readdir as me,stat as ge,readFile as ve}from"fs/promises";import{cwd as ae}from"process";import{readFileSync as ce}from"fs";import{readFileSync as ie,statSync as se}from"fs";import{resolve as ne}from"@remotex-labs/xmap";import{Injectable as oe}from"@remotex-labs/xinject";var v=class{resolved=new Map;cache=new Map;clear(){this.cache.clear(),this.resolved.clear()}getSnapshot(e){return this.cache.get(this.resolve(e))}touch(e,t){let r=this.resolve(e);return this.cache.get(r)??this.sync(r,this.stat(r),t)}refresh(e,t,r){let i=this.resolve(e);return this.sync(i,t??this.stat(i),r)}refreshAll(e){let t=e??this.cache.keys();for(let r of t)this.refresh(r)}resolve(e){let t=this.resolved.get(e);return t===void 0&&this.resolved.set(e,t=ne(e)),t}sync(e,t,r="utf-8"){let i=this.cache.get(e);return t?.isFile()?i?.mtimeMs===t.mtimeMs?i:this.store(e,{mtimeMs:t.mtimeMs,version:(i?.version??0)+1,snapshot:this.snapshot(ie(e,r))}):i&&!i.snapshot?i:this.store(e,{mtimeMs:0,snapshot:void 0,version:(i?.version??0)+1})}changeRange(e,t){let r=e.length,i=t.length,s=Math.min(r,i),n=0;for(;n<s&&e.charCodeAt(n)===t.charCodeAt(n);)n++;let a=0;for(;a<s-n&&e.charCodeAt(r-1-a)===t.charCodeAt(i-1-a);)a++;return{span:{start:n,length:r-n-a},newLength:i-n-a}}snapshot(e){return{text:e,getText:(t,r)=>e.slice(t,r),getLength:()=>e.length,getChangeRange:t=>this.changeRange(t.getText(0,t.getLength()),e)}}store(e,t){return this.cache.set(e,t),t}stat(e){return se(e,{throwIfNoEntry:!1})}};v=y([oe({scope:"singleton"})],v);import{inject as le,Injectable as pe}from"@remotex-labs/xinject";import{normalize as T,SourceService as fe}from"@remotex-labs/xmap";var G=/xbuild(?!\.config)/i,de=/"mappings"\s*:\s*""/,f=class{frameworkFile;frameworkRoot;projectRoot;sourceMaps=new Map;constructor(){this.projectRoot=T(ae()),this.frameworkFile=T(import.meta.filename),this.frameworkRoot=T(import.meta.dirname),this.loadSourceMap(this.frameworkFile)}static resolve(e){return(f.files??=le(v)).resolve(e)}isFrameworkFile(e){return G.test(e.source??"")||G.test(e.sourceRoot??"")}getSourceMap(e){return this.sourceMaps.get(f.resolve(e))}addSourceMap(e,t,r=!1){let i=f.resolve(e);!r&&this.sourceMaps.has(i)||this.register(i,t)}loadSourceMap(e){if(!e)return;let t=f.resolve(e);if(this.sourceMaps.has(t))return;let r;try{r=ce(`${t}.map`,"utf-8")}catch(i){throw f.failure(t,i)}this.register(t,r)}static failure(e,t){return new Error(`Failed to load source map for: ${e}
|
|
2
|
+
${t instanceof Error?t.message:String(t)}`)}register(e,t){if(!de.test(t))try{this.sourceMaps.set(e,new fe(t,e))}catch(r){throw f.failure(e,r)}}};k(f,"files"),f=y([pe({scope:"singleton"})],f);var Y=class{constructor(e,t){this.config=e;this.rootDir=f.resolve(t),this.config.port||=0,this.config.host||="localhost"}config;server;events$=new he;rootDir;framework=ue(f);get pipe(){return this.events$.pipe.bind(this.events$)}get subscribe(){return this.events$.subscribe.bind(this.events$)}async start(){if(this.config.https)return await this.startHttpsServer();await this.startHttpServer()}async stop(){if(!this.server)return this.events$.next({type:"stop",running:!1});await new Promise((e,t)=>{this.server.close(r=>{r?t(r):e()})}),this.server=void 0,this.events$.next({type:"stop",running:!0})}async restart(){await this.stop(),await this.start()}setActualPort(){if(this.config.port===0){let e=this.server.address();e&&typeof e=="object"&&e.port&&(this.config.port=e.port)}}startHttpServer(){return new Promise(e=>{this.server=Q.createServer((t,r)=>{this.handleRequest(t,r,()=>this.defaultResponse(t,r))}),this.server.listen(this.config.port,this.config.host,()=>{this.setActualPort();let t={host:this.config.host,port:this.config.port,url:`http://${this.config.host}:${this.config.port}`};this.config.onStart?.(t),this.events$.next({...t,type:"start"}),e()})})}startHttpsServer(){return new Promise(e=>{let t={key:K(this.config.key??C(this.framework.frameworkRoot,"..","certs","server.key")),cert:K(this.config.cert??C(this.framework.frameworkRoot,"..","certs","server.crt"))};this.server=X.createServer(t,(r,i)=>{this.handleRequest(r,i,()=>this.defaultResponse(r,i))}),this.server.listen(this.config.port,this.config.host,()=>{this.setActualPort();let r={host:this.config.host,port:this.config.port,url:`https://${this.config.host}:${this.config.port}`};this.config.onStart?.(r),this.events$.next({...r,type:"start"}),e()})})}handleRequest(e,t,r){try{this.events$.next({type:"request",url:e.url??""}),this.config.onRequest?this.config.onRequest(e,t,r):r()}catch(i){this.sendError(t,i)}}getContentType(e){return{html:"text/html",css:"text/css",js:"application/javascript",cjs:"application/javascript",mjs:"application/javascript",ts:"text/plain",map:"application/json",json:"application/json",png:"image/png",jpg:"image/jpeg",gif:"image/gif",txt:"text/plain"}[e]||"application/octet-stream"}async defaultResponse(e,t){let r=e.url==="/"?"":e.url?.replace(/^\/+/,"")||"",i=C(this.rootDir,r);if(!i.startsWith(this.rootDir)){t.statusCode=403,t.end();return}try{let s=await ge(i);s.isDirectory()?await this.handleDirectory(i,r,t):s.isFile()&&await this.handleFile(i,t)}catch(s){this.events$.next({type:"error",error:s,url:e.url}),this.sendNotFound(t)}}async handleDirectory(e,t,r){let s=(await me(e)).map(l=>{let u=C(t,l),m=U(l).slice(1)||"folder";return m==="folder"?`
|
|
3
|
+
<a href="/${u}" class="folder-row">
|
|
16
4
|
<div class="icon"><i class="fa-solid fa-folder"></i></div>
|
|
17
5
|
<div class="meta"><div class="name">${l}</div><div class="sub">Folder</div></div>
|
|
18
6
|
</a>
|
|
19
7
|
`:`
|
|
20
|
-
<a href="/${
|
|
8
|
+
<a href="/${u}" class="file-row">
|
|
21
9
|
<div class="icon"><i class="fa-solid fa-file-code"></i></div>
|
|
22
|
-
<div class="meta"><div class="name">${l}</div><div class="sub">${
|
|
10
|
+
<div class="meta"><div class="name">${l}</div><div class="sub">${m}</div></div>
|
|
23
11
|
</a>
|
|
24
|
-
`}).join("");
|
|
12
|
+
`}).join("");s?s=`<div class="list">${s}</div>`:s='<div class="empty">No files or folders here.</div>';let n="/",a=t.split("/").map(l=>(n+=`${l}/`,`<li><a href="${n}">${l}</a></li>`)).join(""),c=V.replace("${ fileList }",s).replace("${ paths }",'<li><a href="/">root</a></li>'+a).replace("${ up }","/"+t.split("/").slice(0,-1).join("/"));r.writeHead(200,{"Content-Type":"text/html"}),r.end(c)}async handleFile(e,t){let r=U(e).slice(1)||"txt",i=this.getContentType(r),s=await ve(e);t.writeHead(200,{"Content-Type":i}),t.end(s)}sendNotFound(e){e.writeHead(404,{"Content-Type":"text/plain"}),e.end("Not Found")}sendError(e,t){this.events$.next({type:"error",error:t}),e.writeHead(500,{"Content-Type":"text/plain"}),e.end("Internal Server Error")}};import{Injectable as De}from"@remotex-labs/xinject";import{Subject as Ee}from"@remotex-labs/xobservable";import{join as kt}from"@remotex-labs/xmap";var F={64:")",43:")+",42:")*",63:")?"};function $(o){return".+^$()|\\{}[]*?".includes(o)?"\\"+o:o}function d(o,e){return o.charCodeAt(e)}function ye(o,e){return(e===0||d(o,e-1)===47)&&(e+2===o.length||d(o,e+2)===47)}function I(o){return`(?:${o})`}function B(o,e){let t=e+1,r=d(o,t);for((r===33||r===94)&&t++,d(o,t)===93&&t++;t<o.length&&d(o,t)!==93;)t+=d(o,t)===92?2:1;return t}function xe(o,e){for(let t=e,r=0;t<o.length;t++){let i=d(o,t);if(i===92)t++;else if(i===40)r++;else{if(i===41&&--r===0)return t;i===91&&(t=B(o,t))}}return-1}function be(o,e){let t=!1;for(let r=e+1,i=0;r<o.length;r++){let s=d(o,r);if(s===92)r++;else if(s===123)i++;else if(s===125){if(i===0)return t?r:-1;i--}else s===44&&i===0?t=!0:s===91&&(r=B(o,r))}return-1}function Se(o,e){let t=B(o,e);if(t>=o.length)return["\\[",e+1];let r=e+1,i="[",s=d(o,r);for((s===33||s===94)&&(i+="^/",r++),d(o,r)===93&&(i+="\\]",r++);r<t;r++)d(o,r)===92?i+="\\"+o[++r]:d(o,r)===94?i+="\\^":i+=o[r];return[i+"]",t+1]}function we(o,e){for(let t=e;t<o.length;t++){if(d(o,t)===47)return t;d(o,t)===92&&t++}return o.length}function D(o,e=!1,t=0,r={}){let{dot:i=!1}=r,s="",n=0,a=e,c=i?"":"(?!\\.)",l=c+"[^/]"+"+",u=I(l+"(?:/"+l+")*")+"?";for(;n<o.length;){let m=d(o,n),w=d(o,n+1);if(w===40&&(m===33||F[m])){let p=xe(o,n+1);if(m!==33){let b=p===-1?o.length:p,E=D(o.slice(n+2,b),a,124,r);s+="(?:"+E+F[m],n=b+1;continue}if(p!==-1){let b=D(o.slice(n+2,p),a,124,r),E=we(o,p+1),q=D(o.slice(p+1,E),!1,0,r);s+=I((a?c:"")+`(?!${I(b)+q+"(?:$|/)"})`+"[^/]*?"+q),n=E;continue}}switch(m){case 47:s+="/",n++,a=!0;break;case 92:s+=n+1<o.length?$(o[n+1]):"\\\\",n+=2;break;case 63:s+=a&&!i?"[^./]":"[^/]",n++;break;case 42:if(w===42&&t!==124&&(n>0||e)&&ye(o,n)){let p=n===0&&t===0?"(?:[A-Za-z]:)?/?":"";d(o,n+2)===47?(s+=p+I(l+"/")+"*",n+=3,a=!0):(s+=p+u,n+=2)}else s+=(a?c:"")+"[^/]*",n++;break;case 123:{let p=be(o,n);p===-1?(s+="\\{",n++):(s+=I(D(o.slice(n+1,p),a,44,r)),n=p+1);break}case 91:{let[p,b]=Se(o,n);s+=(a&&!i&&p!=="\\["?"(?!\\.)":"")+p,n=b;break}case 124:case 44:t===m?(s+="|",a=e):s+=$(o[n]),n++;break;default:s+=$(o[n]),n++}}return s}function Ie(o,e={}){return new RegExp("^"+D(o,!0,0,e)+"$",e.flags)}function A(o,e={}){let t=[],r=[];for(let i of o){let s=!1;for(;d(i,0)===33&&d(i,1)!==40;)s=!s,i=i.slice(1);(s?r:t).push(Ie(i,e))}return i=>(t.length===0||t.some(s=>s.test(i)))&&!r.some(s=>s.test(i))}import{resolve as ke,join as J,relative as Ce}from"@remotex-labs/xmap";import{watch as Ae,realpathSync as Pe,readdirSync as Re,lstatSync as Me,statSync as Te}from"fs";var P=class extends Ee{constructor(t,r){super();this.options=r;this.base=ke(t),this.matcher=A(this.options?.filter??[],{dot:this.options?.dot??!1})}options;base;matcher;watchers=new Map;pending=new Map;subscriptions=0;timer;subscribe(t,r,i){let s=super.subscribe(t,r,i);return++this.subscriptions===1&&this.start(),this.toUnsubscribe(()=>{s(),--this.subscriptions===0&&this.stop()})}get debounce(){return this.options?.debounce??150}start(){this.watch(this.base,this.ignored.bind(this),this.options?.recursive),this.options?.followSymlinks&&this.watchSymlinks(this.base)}stop(){this.timer&&clearTimeout(this.timer);for(let t of this.watchers.values())t.close();this.timer=void 0,this.pending.clear(),this.watchers.clear()}flush(){if(this.timer=void 0,this.pending.size===0)return;let t=Object.fromEntries(this.pending);this.pending.clear();try{this.next(t)}catch{}}watcherClose(t){let r=this.watchers.get(t);r&&(r.close(),this.watchers.delete(t))}watcherEvent(t,r){let i=Ce(this.base,r),s=Me(r,{throwIfNoEntry:!1}),n=s?.isSymbolicLink()?Te(r,{throwIfNoEntry:!1}):s;if(s?.isSymbolicLink()){if(!n)return;t==="rename"&&this.watcherClose(r),n.isFile()&&this.matcher(r)?this.watch(r):n.isDirectory()&&this.options?.recursive&&this.watch(r,this.ignored.bind(this),!0)}if(!this.matcher(i))return;this.timer?this.timer.refresh():this.timer=setTimeout(this.flush.bind(this),this.debounce);let a;n?a=n.birthtimeMs===n.mtimeMs?0:1:(this.watcherClose(r),a=2),this.pending.set(i,{type:a,stats:n})}watch(t,r,i=!1){if(this.watchers.has(t)||this.ignored(t))return;let s=Ae(Pe(t),{recursive:i,ignore:r},(n,a)=>{if(!a)return;let c=t.includes(a)?t:J(t,a);this.watcherEvent(n,c)});s.on("error",n=>{this.watcherClose(t),this.error(n)}),this.watchers.set(t,s)}ignored(t){return!!(!t||t.endsWith("~")||!this.options?.dot&&t&&t.split(/[/\\]/).some(r=>r.startsWith(".")))}watchSymlinks(t){let r=[t];for(;r.length;){let i=r.pop(),s;try{s=Re(i,{withFileTypes:!0})}catch{continue}for(let n of s){let a=J(n.parentPath??i,n.name);this.ignored(a)||(n.isSymbolicLink()?this.watch(a,this.ignored.bind(this),this.options?.recursive):this.options?.recursive&&n.isDirectory()&&r.push(a))}}}};P=y([De({scope:"singleton"})],P);import{inject as N}from"@remotex-labs/xinject";import{resolveError as je}from"@remotex-labs/xmap";import{xterm as L}from"@remotex-labs/xansi/xterm.component";import{parseErrorStack as Z}from"@remotex-labs/xmap/parser.component";import{formatErrorCode as Fe}from"@remotex-labs/xmap/formatter.component";import{highlightCode as $e}from"@remotex-labs/xmap/highlighter.component";function Be(o=""){let t=N(f).getSourceMap(o);if(t)return t;let r=N(v).touch(o),i=r.snapshot?.text;if(!r||!i)return null;let s=i.split(`
|
|
13
|
+
`);return{getPositionWithCode:(n,a,c,l)=>{let u=l?.linesAfter??3,m=l?.linesBefore??3,w=Math.max(n-m,1),p=Math.min(n+u,s.length);return{line:n,name:null,code:s.slice(w-1,p).join(`
|
|
14
|
+
`),source:o,column:a,endLine:p,startLine:w,sourceRoot:null,sourceIndex:-1,generatedLine:-1,generatedColumn:-1}}}}function Ne(o){return o instanceof Error?Z(o):o.detail instanceof Error?Z(o.detail):o.location?{name:"esBuildMessage",message:o.text??"",rawStack:"",stack:[{source:`@${o.location.file}`,line:o.location.line,column:o.location.column||1,fileName:o.location.file,eval:!1,async:!1,native:!1,constructor:!1}]}:{stack:[],name:"esBuildMessage",message:o.text??"",rawStack:""}}function Yt(o,e,t=!1){let r=N(f),i=Ne(o),s=je(i,{...e,withNativeFrames:t||(e?.withFrameworkFrames??!1),getSource(n){return Be(n)}});return s.stack.filter(n=>{if(!(e?.withFrameworkFrames??!1)&&r.isFrameworkFile(n))return!1;!s.formatCode&&n.code&&(s.formatCode=Fe({code:$e(n.code),line:n.line??1,column:n.column??1,startLine:n.stratLine??1},{color:L.brightPink}))}),s}function Qt(o,e,t,r=[]){let i=[`
|
|
15
|
+
${e}: ${L.lightCoral(t)}`];for(let s of r??[])s.text&&i.push(`
|
|
16
|
+
`+L.gray(s.text));return o.formatCode&&i.push(`
|
|
17
|
+
|
|
18
|
+
${o.formatCode}`),o.stack.length&&i.push(`
|
|
19
|
+
|
|
20
|
+
Enhanced Stack Trace:
|
|
21
|
+
${o.stack.map(s=>s.format).join(`
|
|
22
|
+
`)}
|
|
23
|
+
`),i.join("")}import h from"typescript";import{Injectable as Ke}from"@remotex-labs/xinject";import{normalize as Ye,relative as Qe,dirname as Xe}from"@remotex-labs/xmap";import{existsSync as Le}from"fs";import{parseSync as Oe}from"oxc-parser";import{inject as He}from"@remotex-labs/xinject";import{mkdir as ze,writeFile as qe}from"fs/promises";import{isolatedDeclarationSync as We}from"oxc-transform";import{join as H,dirname as z,relative as Ve}from"@remotex-labs/xmap";function x(o,e,t){let r=o.end;for(;r<e.length;){let i=e.charCodeAt(r);if(i!==32&&i!==9)break;r++}e.charCodeAt(r)===13&&r++,e.charCodeAt(r)===10&&r++,t.push({start:o.start,end:r})}function O(o,e){if(e.length<1)return o;e.sort((s,n)=>s.start-n.start);let t=new Array(e.length*2+1),r=0,i=0;for(let s=0;s<e.length;s++){let n=e[s];n.start<i||(t[r++]=o.slice(i,n.start),t[r++]=n.text??"",i=n.end)}return t[r++]=o.slice(i),t.length=r,t.join("")}var _=`/**
|
|
25
24
|
* This file was automatically generated by xBuild.
|
|
26
25
|
* DO NOT EDIT MANUALLY.
|
|
27
26
|
*/
|
|
28
|
-
`;var
|
|
29
|
-
|
|
30
|
-
${f.join(`,
|
|
27
|
+
`;var R=class{constructor(e){this.ts=e}ts;cache=new Map;filesCache=He(v);emitted=new Map;clear(){this.cache.clear(),this.emitted.clear()}touch(e){let t=this.filesCache.resolve(e),r=this.filesCache.touch(t),i=this.cache.get(t);if(i?.version===r.version)return i;let s=this.build(t,r.snapshot?.text??"",r.version);return this.cache.set(t,s),s}async emit(e,t){let r=[],i=[],s=new Set,n=new Map;for(let[c,l]of Object.entries(e))n.set(this.filesCache.resolve(l),c);let a=[...n.keys()];for(;a.length>0;){let c=a.pop();if(s.has(c)||c.endsWith(".d.ts"))continue;s.add(c);let l=this.touch(c);for(let m of l.projectDependencies)s.has(m)||a.push(m);let u=this.outputPath(c,t,n.get(c));this.emitted.get(u)===l.version&&Le(u)||(this.emitted.set(u,l.version),r.push(u),i.push(l.declaration))}return this.write(r,i)}async emitBundle(e,t){let r=this.ts.config.options,i=this.filesCache.resolve(t??r.declarationDir??r.outDir??".");return this.write(Object.keys(e).map(s=>H(i,`${s}.d.ts`)),Object.values(e).map(s=>this.bundle(s)))}bundle(e){let t=this.filesCache.resolve(e),r=this.touch(t);return this.render(this.collectClosure(t,r),this.collectSurface(t,r))}async write(e,t){if(e.length<1)return e;let r=new Set(e.map(i=>z(i)));return await Promise.all([...r].map(i=>ze(i,{recursive:!0}))),await Promise.all(e.map((i,s)=>qe(i,t[s],"utf-8"))),e}outputPath(e,t,r){let{declarationDir:i,outDir:s,rootDir:n}=this.ts.config.options,a=t??i??s,c=a?this.filesCache.resolve(a):z(e);if(r)return H(c,`${r}.d.ts`);let l=n?this.filesCache.resolve(n):z(e);return H(c,Ve(l,e).replace(/\.([cm]?)tsx?$/,".d.$1ts"))}collectClosure(e,t){let r=new Set([e]),i=[],s=[...t.projectDependencies];for(;s.length>0;){let n=s.pop();if(r.has(n))continue;r.add(n);let a=this.touch(n);i.push(a);for(let c of a.projectDependencies)r.has(c)||s.push(c)}return i.push(t),i}collectSurface(e,t){let r=new Set,i=new Set,s=new Set([e]),n=[t];for(;n.length>0;){let a=n.pop();for(let c of a.projectExports.exports)r.add(this.clause(c));for(let[c,l]of Object.entries(a.packageExports)){l.star&&i.add(`export * from '${c}';`),l.named?.length&&i.add(`export { ${l.named.map(u=>this.clause(u)).join(", ")} } from '${c}';`);for(let u of l.namespaces??[])i.add(`export * as ${u} from '${c}';`)}for(let c of a.projectExports.star)s.has(c)||(s.add(c),n.push(this.touch(c)))}return{exports:r,statements:i}}mergeImports(e){let t=new Map;for(let r of e)for(let[i,s]of Object.entries(r.packageImports)){let n=t.get(i);n||t.set(i,n={side:!1,named:new Set,namespaces:new Set}),s.side&&(n.side=!0),n.default??=s.default;for(let a of s.namespaces??[])n.namespaces.add(a);for(let a of s.named??[])n.named.add(this.clause(a))}return t}renderImports(e){let t=[];for(let[r,i]of e){i.side&&t.push(`import '${r}';`);for(let n of i.namespaces)t.push(`import * as ${n} from '${r}';`);let s=[];i.default&&s.push(i.default),i.named.size>0&&s.push(`{ ${[...i.named].sort().join(", ")} }`),s.length>0&&t.push(`import ${s.join(", ")} from '${r}';`)}return t}render(e,t){let r=[_],i=this.renderImports(this.mergeImports(e));i.length>0&&r.push(...i,"");for(let s of e){let n=s.content.trim();n&&r.push(n,"")}return t.exports.size>0&&r.push(`export {
|
|
28
|
+
${[...t.exports].sort().join(`,
|
|
31
29
|
`)}
|
|
32
|
-
};`)
|
|
33
|
-
`)}
|
|
34
|
-
`),category:e.category};if(e.file&&e.start!==void 0){let{line:i,character:n}=e.file.getLineAndCharacterOfPosition(e.start);t.file=e.file.fileName,t.line=i+1,t.column=n+1,t.code=e.code}return t}};ke=T(null),P=O(ke,0,"TypescriptService",ot,P),F(ke,1,P);var W=P;import{cwd as Pe}from"process";import{build as st}from"esbuild";var jr={write:!1,bundle:!0,minify:!0,outdir:`${Pe()}`,format:"esm",target:"esnext",platform:"browser",sourcemap:"external",mangleQuoted:!0,sourcesContent:!0,preserveSymlinks:!0};async function at(r,e,t={}){return await st({absWorkingDir:Pe(),...jr,...t,stdin:{loader:"ts",contents:r,resolveDir:Pe(),sourcefile:e},write:!1,metafile:!0,logLevel:"silent",sourcemap:"external"})}async function ct(r,e={}){try{return await st({...e,outdir:"tmp",write:!1,bundle:!0,outfile:void 0,metafile:!0,packages:"external",logLevel:"silent",entryPoints:r})}catch(t){if(U(t)){let i=new AggregateError([],"Failed to analyze entryPoint");throw re(t.errors,i.errors),i}throw t}}import{relative as Vr,resolve as _r,join as ft,dirname as zr}from"@remotex-labs/xmap";function lt(r,e){if(Array.isArray(e)){let t={};return e.length>0&&typeof e[0]=="object"?e.forEach(i=>{t[i.out]=i.in}):typeof e[0]=="string"&&(t=Ue(r,e)),t}else{if(e&&typeof e=="object")return e;if(e===void 0)return}throw new w("Unsupported entry points format")}var ce=class{constructor(e,t,i,n={}){this.name=e;this.lifecycle=t;this.buildConfig=i;this.argv=n;if(!this.buildConfig?.esbuild)throw new w(`Variant '${this.name}' not found configuration`);this.tsConfigPath=this.buildConfig.esbuild.tsconfig??"tsconfig.json",this.typescriptModule=new W(this.tsConfigPath),this.buildConfig=this.initializeConfig(this.getConfig(this.buildConfig,this.configService.getValue().common)),this.lifecycle.onEnd(this.end.bind(this),`${this.name}-core`),this.lifecycle.onStart(this.start.bind(this),`${this.name}-core`),this.configUnsubscribe=this.configService.select(o=>({variantConfig:o.variants?.[this.name],commonConfig:o.common})).subscribe(this.handleConfigChange.bind(this),o=>{throw o})}name;lifecycle;buildConfig;argv;dependenciesFile;active=!0;tsConfigPath;typescriptModule;configUnsubscribe;configService=u(x);get typescript(){return this.typescriptModule}get config(){return this.buildConfig}get dependencies(){return this.dependenciesFile??{}}dispose(){this.configUnsubscribe(),this.typescriptModule.dispose(this.tsConfigPath)}touchFiles(e){this.typescriptModule.touchFiles(e)}async check(){return this.dependenciesFile||(this.dependenciesFile=await this.buildDependencyMap()),this.typescriptModule.check(Object.values(this.dependenciesFile))}async build(){if(!this.active)return;this.applyInjections();let e=Object.assign({},this.buildConfig.esbuild);if(this.dependenciesFile=await this.buildDependencyMap(),this.buildConfig.esbuild.bundle===!1&&Object.assign(e,{entryPoints:this.dependenciesFile}),this.config.define&&e.define)for(let[t,i]of Object.entries(this.config.define))typeof i=="function"&&(e.define[t]=JSON.stringify(i()));try{let t=await $r(e);return await this.packageTypeComponent(),t}catch(t){if(U(t)){if(t.errors.filter(n=>n.location).length>0)throw t;return{errors:t?.errors??[],warnings:t?.warnings??[]}}}}getConfig(e,t={}){return e?D({},t,e):null}async start(){let e={errors:[],warnings:[]};if(!this.buildConfig.types)return e;let t=this.typescriptModule.check(Object.values(this.dependenciesFile??{}));if(t.length===0)return e;if(typeof this.buildConfig.types=="object"&&!this.buildConfig.types.failOnError){let n=new j("Type checking failed",t);e.warnings?.push({detail:n,location:void 0})}else{let n=[],o=[],s=new j("Type checking failed",n),a=new j("Type checking failed",o);for(let c of t)(c.category===Br.DiagnosticCategory.Error?n:o).push(c);n.length&&e.errors?.push({detail:s,location:void 0}),o.length&&e.warnings?.push({detail:a,location:void 0})}return e}async end(e){if(e.buildResult.errors?.length>0)return;let t={errors:[],warnings:[]};if(typeof e.buildResult.metafile?.outputs=="object"){let s=Object.keys(e.buildResult.metafile?.outputs);for(let a of s){if(!a.endsWith(".map"))continue;let c=zr(a),l=await Hr(a,"utf8"),f=JSON.parse(l);f.sources=f.sources.map(p=>p.startsWith("http")?p:ft(c,p)),await pt(a,JSON.stringify(f),"utf8")}}if(!this.buildConfig.declaration)return;let i=this.buildConfig.declaration,n=typeof i=="object"?i.bundle!==!1:!0,o=typeof i=="object"?i.outDir:void 0;try{n?await this.typescriptModule.emitBundle(this.buildConfig.esbuild.entryPoints,o):await this.typescriptModule.emit(o)}catch(s){t.warnings?.push({detail:s,location:void 0})}return t}registerConfigHooks(e){if(!e)return;let{onStart:t,onResolve:i,onLoad:n,onEnd:o,onSuccess:s}=e;t&&this.lifecycle.onStart(t),i&&this.lifecycle.onResolve(i),n&&this.lifecycle.onLoad(n),o&&this.lifecycle.onEnd(o),s&&this.lifecycle.onSuccess(s)}async packageTypeComponent(){let e=this.buildConfig.esbuild.outdir??"dist",t=this.buildConfig.esbuild.format==="esm"?"module":"commonjs";await Lr(e,{recursive:!0}),await pt(ft(e,"package.json"),`{"type": "${t}"}`)}initializeConfig(e){if(!e)throw new w(`Variant '${this.name}' not found configuration`);if(!e.esbuild.entryPoints&&!e.esbuild.stdin)throw new w("Entry points are required in esbuild configuration");let t=e.define,i=t?Object.fromEntries(Object.entries(t).flatMap(([n,o])=>typeof o=="function"?[]:[[n,JSON.stringify(o)]])):void 0;return this.registerConfigHooks(e.lifecycle),e.esbuild.entryPoints=lt(this.typescriptModule.config.options.rootDir??process.cwd(),e.esbuild.entryPoints),e.esbuild=Object.assign({},e.esbuild,{define:i,logLevel:"silent",plugins:[this.lifecycle.create()]}),e}async handleConfigChange({variantConfig:e,commonConfig:t}){this.active=!1;let i=this.getConfig(e,t);i&&(this.active=!0,this.buildConfig=this.initializeConfig(i),i.esbuild.outdir&&i.esbuild.outfile&&(this.buildConfig.esbuild.outdir=void 0),i.esbuild.tsconfig&&i.esbuild.tsconfig!==this.tsConfigPath&&(this.typescriptModule.dispose(this.tsConfigPath),this.tsConfigPath=i.esbuild.tsconfig,this.typescriptModule=new W(this.tsConfigPath)))}stripExtension(e){let t=e.lastIndexOf(".");return t>0?e.substring(0,t):e}async buildDependencyMap(){let{esbuild:e}=this.buildConfig,t={...e,plugins:void 0},{metafile:i}=await ct(e.entryPoints,t),n={};for(let o of Object.keys(i.inputs)){let s=Vr(this.typescriptModule.config.options.rootDir,_r(o)),a=this.stripExtension(s);n[a]=o}return n}injectTextBlock(e){let t=this.buildConfig[e];if(!t)return;let i=this.buildConfig.esbuild;i[e]??={};for(let[n,o]of Object.entries(t))i[e][n]=typeof o=="function"?o(this.name,this.argv):o}applyInjections(){this.injectTextBlock("banner"),this.injectTextBlock("footer")}};import{readFile as Ur}from"fs/promises";import{resolve as Kr}from"@remotex-labs/xmap";var le=class{constructor(e,t){this.variantName=e;this.argv=t}variantName;argv;filesModel=u(v);endHooks=new Map;loadHooks=new Map;startHooks=new Map;successHooks=new Map;resolveHooks=new Map;onStart(e,t=this.variantName){e&&this.startHooks.set(t,e)}onEnd(e,t=this.variantName){e&&this.endHooks.set(t,e)}onSuccess(e,t=this.variantName){e&&this.successHooks.set(t,e)}onResolve(e,t=this.variantName){e&&this.resolveHooks.set(t,e)}onLoad(e,t=this.variantName){e&&this.loadHooks.set(t,e)}clearAll(){this.endHooks.clear(),this.loadHooks.clear(),this.startHooks.clear(),this.successHooks.clear(),this.resolveHooks.clear()}create(){return{name:this.variantName,setup:e=>{let t={argv:this.argv,options:e.initialOptions,variantName:this.variantName,stage:{startTime:new Date}};e.initialOptions.metafile=!0,this.startHooks.size>0&&e.onStart(this.executeStartHooks.bind(this,t,e)),(this.endHooks.size>0||this.successHooks.size>0)&&e.onEnd(this.executeEndHooks.bind(this,t)),this.resolveHooks.size>0&&e.onResolve({filter:/.*/},this.executeResolveHooks.bind(this,t)),this.loadHooks.size>0&&e.onLoad({filter:/.*/},this.executeLoadHooks.bind(this,t))}}}pushError(e,t,i,n=this.variantName){e.push({id:t,detail:i,location:null,pluginName:n})}async executeStartHooks(e,t){e.stage.startTime=new Date;let i=[],n=[],o={build:t,...e};for(let[s,a]of this.startHooks.entries())try{let c=await a(o);c?.errors&&i.push(...c.errors),c?.warnings&&n.push(...c.warnings)}catch(c){this.pushError(i,"startHook",c,s)}return{errors:i,warnings:n}}async executeEndHooks(e,t){let{errors:i,warnings:n}=t,o=Date.now()-e.stage.startTime.getTime(),s={buildResult:t,duration:o,...e};for(let[a,c]of this.endHooks.entries())try{let l=await c(s);l?.errors&&i.push(...l.errors),l?.warnings&&n.push(...l.warnings)}catch(l){this.pushError(i,"endHook",l,a)}if(t.errors.length===0)for(let[a,c]of this.successHooks.entries())try{await c(s)}catch(l){this.pushError(i,"endHook",l,a)}}async executeResolveHooks(e,t){let i={errors:[]},n={args:t,...e};for(let[o,s]of this.resolveHooks.entries())try{let a=await s(n);if(!a)continue;i={...i,...a}}catch(a){this.pushError(i.errors,"endResolve",a,o)}return i}async executeLoadHooks(e,t){let i=[],n=[],o="default",s=Kr(t.path),a=this.filesModel.getOrTouchFile(s),c;try{c=a?.contentSnapshot?a.contentSnapshot.text:await Ur(s,"utf8")}catch{return e.options.logOverride?.["lifecycle-file-ignored"]!=="silent"&&n.push({id:"",text:`${t.path} ignored`,pluginName:"lifecycle"}),{warnings:n,errors:i,loader:o}}for(let[l,f]of this.loadHooks.entries())try{let p=await f({contents:c,loader:o,args:t,...e});if(!p)continue;p.contents!==void 0&&(c=p.contents),p.loader&&(o=p.loader),p.errors&&i.push(...p.errors),p.warnings&&n.push(...p.warnings)}catch(p){this.pushError(i,"loadHook",p,l)}return{contents:c,loader:o,errors:i,warnings:n}}};import h from"typescript";import{createSourceFile as li}from"typescript";import{highlightCode as xt}from"@remotex-labs/xmap/highlighter.component";import M from"typescript";var qr="$$ifdef";function Wr(r,e,t,i=!1){let n=i?"export function ":"function ";return M.isArrowFunction(e)||M.isFunctionExpression(e)?Gr(r,e,t,n):`${i?"export const ":"const "}${r} = ${e.getText(t)};`}function Gr(r,e,t,i){let o=e.modifiers?.some(l=>l.kind===M.SyntaxKind.AsyncKeyword)??!1?"async ":"",s=e.parameters.map(l=>l.getText(t)).join(", "),a=e.type?`: ${e.type.getText(t)}`:"",c=Xr(e,t);return`${o}${i}${r}(${s})${a} ${c}`}function Xr(r,e){let t=r.body.getText(e);return M.isArrowFunction(r)&&!M.isBlock(r.body)?`{ return ${t}; }`:t}function Jr(r,e,t="",i="();"){return M.isArrowFunction(r)||M.isFunctionExpression(r)?`${r.modifiers?.some(s=>s.kind===M.SyntaxKind.AsyncKeyword)??!1?"async ":""}${t}(${r.getText(e)})${i}`:t?`${t}${r.getText(e)}`:`(() => { return ${r.getText(e)}; })${i}`}function ut(r,e,t){let i=r in t&&!!t[r];return e===qr===i}function dt(r,e,t,i){let[n,o]=e.arguments;if(!M.isStringLiteral(n))return!1;let s=e.expression.text,a=n.text;if(!ut(a,s,i.defines))return"undefined";let c=r.name.getText(i.sourceFile);return Wr(c,o,i.sourceFile,t)}function pe(r,e,t,i=!1,n){let[o,s]=r.arguments;if(!M.isStringLiteral(o))return!1;let a=o.text,c=r.expression.text;if(!ut(a,c,e.defines))return"";let l="",f=t?.name.getText(e.sourceFile);return f&&(l=i?`export const ${f} = `:`const ${f} = `),Jr(s,e.sourceFile,l,n)}import E from"typescript";import{createRequire as Zr}from"module";var fe=class extends I{constructor(e,t=0){super(e.message,"InlineError"),this.errorMetadata=_(e,{lineOffset:t}),this.stack=z(this.errorMetadata,this.name,this.message)}};import{Script as Yr,createContext as Qr}from"vm";async function mt(r,e={},t={}){let i=new Yr(r,t),n=Qr(e);return await i.runInContext(n,{breakOnSigint:!0,displayErrors:!1})}import{dirname as ei,relative as ti}from"@remotex-labs/xmap";async function gt(r,e,t){let[i,n]=(await at(r,e.sourceFile.fileName,{bundle:!0,format:"cjs",platform:"node",packages:"external"})).outputFiles;try{let o={exports:{}},s=Zr(e.sourceFile.fileName),a=ri(e.sourceFile.fileName,o,s);a.context=e.context;let c=await mt(n.text,a,{filename:e.sourceFile.fileName});return c===null?"undefined":typeof c=="number"||typeof c=="boolean"?String(c):JSON.stringify(c)}catch(o){ii(o,e,i.text,t)}return"undefined"}function ri(r,e,t){return{...globalThis,Error,RegExp,process,Buffer,module:e,require:t,console,setTimeout,setInterval,clearTimeout,clearInterval,ReferenceError,__dirname:ei(r),__filename:r}}function ii(r,e,t,i){(!r||typeof r!="object"||!("stack"in r))&&(r=new Error(String(r)));let n=i.getStart(e.sourceFile),{line:o}=e.sourceFile.getLineAndCharacterOfPosition(n);u(b).setSource(t,e.sourceFile.fileName);let s=new fe(r,o);e.errors.push({text:s.message,detail:s})}function ni(r,e){let t=null,i=n=>{if(!t){if(E.isFunctionDeclaration(n)&&n.name?.text===r){t=n;return}E.isVariableStatement(n)&&(t=oi(n,r),t)||E.forEachChild(n,i)}};return i(e),t}function oi(r,e){for(let t of r.declarationList.declarations)if(E.isIdentifier(t.name)&&t.name.text===e&&t.initializer&&(E.isArrowFunction(t.initializer)||E.isFunctionExpression(t.initializer)))return t.initializer;return null}function ht(r){return`module.exports = (${r})();`}function si(r){return r&E.NodeFlags.Const?"const":r&E.NodeFlags.Let?"let":"var"}function vt(r,e){return r?E.isIdentifier(r)?ai(r,e):E.isArrowFunction(r)||E.isFunctionExpression(r)?{node:r,data:ht(r.getText(e.sourceFile))}:{node:r,data:r.getText(e.sourceFile)}:null}function ai(r,e){let t=ni(r.text,e.sourceFile);return t?{node:t,data:ht(t.getText(e.sourceFile))}:(ci(r.text,e,r),{data:"",node:r})}function ci(r,e,t){let i=t.getStart(e.sourceFile),{line:n,character:o}=e.sourceFile.getLineAndCharacterOfPosition(i),s=ti(".",e.sourceFile.fileName);e.warnings.push({text:`Function $$inline(${r}); not found in ${s}`,location:{line:n+1,column:o,file:e.sourceFile.fileName,lineText:"asd"}})}async function yt(r,e,t,i,n){let o=t.arguments[0],s=vt(o,n);if(!s)return!1;let a=await gt(s.data,n,s.node),c=si(e.declarationList.flags),l=i?"export ":"",f=r.name.getText(n.sourceFile);return`${l}${c} ${f} = ${a};`}async function Me(r,e){let t=r[0],i=vt(t,e);return i?gt(i.data,e,i.node):!1}var L=["$$ifdef","$$ifndef","$$inline"];function Ae(r,e){return L.some(t=>r.getText(e).includes(t))}function bt(r){return r===L[2]?1:2}async function pi(r,e,t){let i=!1;for(let n of r.declarationList.declarations){let o="",s,a=n.initializer;if(!a||(h.isCallExpression(a)&&h.isIdentifier(a.expression)?s=a:h.isCallExpression(a)&&h.isCallExpression(a.expression)&&h.isIdentifier(a.expression.expression)?(s=a.expression,o=`(${a.arguments.map(p=>p.getText(t.sourceFile)).join(", ")})`):h.isAsExpression(a)&&h.isCallExpression(a.expression)&&h.isIdentifier(a.expression.expression)&&(s=a.expression),!s))continue;let c=s.expression.text;if(!L.includes(c))continue;if(s.arguments.length!==bt(c)){let{line:f,character:p}=t.sourceFile.getLineAndCharacterOfPosition(s.getStart(t.sourceFile));throw new B({text:`Invalid macro call: ${c} with ${s.arguments.length} arguments`,location:{file:t.sourceFile.fileName,line:f+1,column:p}})}let l=r.modifiers?.some(f=>f.kind===h.SyntaxKind.ExportKeyword)??!1;c===L[2]?i=await yt(n,r,s,l,t):o?i=pe(s,t,n,l,o):i=dt(n,s,l,t),i!==!1&&e.add({replacement:i,end:r.getEnd(),start:r.getStart(t.sourceFile)})}return i!==!1}async function fi(r,e,t){let i=r.expression;if(!i.expression||!h.isIdentifier(i.expression))return!1;let n=i.expression.text;if(!L.includes(n))return!1;if(i.arguments.length!==bt(n)){let{line:s,character:a}=t.sourceFile.getLineAndCharacterOfPosition(r.getStart(t.sourceFile));throw new B({text:`Invalid macro call: ${n} with ${i.arguments.length} arguments`,location:{file:t.sourceFile.fileName,line:s+1,column:a}})}let o=!1;return n==L[2]?(await Me(i.arguments,t),o="undefined"):o=pe(i,t),o!==!1&&e.add({replacement:o,end:i.getEnd(),start:i.getStart(t.sourceFile)}),o!==!1}async function ui(r,e,t){if(!h.isCallExpression(r)||!Ae(r,t.sourceFile))return!1;let i=r;if(!h.isIdentifier(i.expression))return!1;if(i.expression.text===L[2]){let s=await Me(i.arguments,t);return s===!1?!1:(e.add({start:r.getStart(t.sourceFile),end:r.getEnd(),replacement:s}),!0)}let o=pe(i,t);return o===!1?!1:(e.add({start:r.getStart(t.sourceFile),end:r.getEnd(),replacement:o}),!0)}async function di(r,e="unknow"){let t=r.stage.defineMetadata.disabledMacroNames,i=r.stage.defineMetadata.filesWithMacros.has(r.sourceFile.fileName);if(!i&&t.size===0)return r.contents;let n=[r.sourceFile],o=new Set;for(;n.length>0;){let c=n.pop(),l=c?.kind;if(!c||!l||i&&(l===h.SyntaxKind.VariableStatement&&await pi(c,o,r)||l===h.SyntaxKind.ExpressionStatement&&Ae(c,r.sourceFile)&&await fi(c,o,r)||l===h.SyntaxKind.CallExpression&&Ae(c,r.sourceFile)&&await ui(c,o,r)))continue;if(t.size>0){if(l===h.SyntaxKind.CallExpression){let p=c;h.isIdentifier(p.expression)&&t.has(p.expression.text)&&o.add({start:c.getStart(r.sourceFile),end:c.getEnd(),replacement:"undefined"})}else if(l===h.SyntaxKind.Identifier){let p=c;if(t.has(p.text)){let d=c.parent??c;if(d&&!h.isImportSpecifier(d)&&!h.isExportSpecifier(d)){let m=d?.getText(r.sourceFile);(!h.isCallExpression(d)||d.expression!==c)&&(!m||L.every(C=>!m.includes(C)))&&o.add({start:c.getStart(r.sourceFile),end:c.getEnd(),replacement:"undefined"})}}}}let f=c.getChildren(r.sourceFile);for(let p=f.length-1;p>=0;p--)n.push(f[p])}if(o.size===0)return r.contents;let s=Array.from(o);s.sort((c,l)=>l.start-c.start),r.stage.replacementInfo??={},r.stage.replacementInfo[e]??=[];let a=r.stage.replacementInfo[e];for(let{start:c,end:l,replacement:f}of s)a.push({source:xt(r.contents.slice(c,l)),replacement:xt(f)}),r.contents=r.contents.slice(0,c)+f+r.contents.slice(l);return r.contents}async function St(r,e){let{args:t,loader:i,stage:n,contents:o,variantName:s,options:a,argv:c}=e;if(t.path.includes("node_modules")||o.length<1)return;let l=t.path.slice(t.path.lastIndexOf("."));if(![".js",".ts"].includes(l))return;let f=r.typescript.languageHostService.getCompilationSettings(),p=li(t.path,o.toString(),f.target??h.ScriptTarget.Latest,!0),d={stage:n,errors:[],contents:o.toString(),warnings:[],defines:r.config.define??{},sourceFile:p,context:{argv:c,options:a,variantName:s}},m=await di(d,r.name);return r.config.esbuild.bundle||r.typescript.languageHostService.aliasRegex&&(m=r.typescript.languageHostService.resolveAliases(m,t.path,".js")),{loader:i,contents:m,warnings:d.warnings,errors:d.errors}}var wt="$$",Ct=/(?:(?:export\s+)?(?:const|let|var)\s+([\w$]+)\s*=\s*)?\$\$(ifdef|ifndef|inline)\s*\(\s*(?:['"]([^'"]+)['"])?/g;function mi(r,e,t,i){let n=1;for(let s=0;s<i;s++)r[s]===`
|
|
35
|
-
|
|
36
|
-
`,i-1)+1;return{file:t,line:n,column:r.indexOf(e,o)-o}}function gi(r,e){let t=r.lastIndexOf(`
|
|
37
|
-
`,e-1)+1;for(;t<e&&(r[t]===" "||r[t]===" ");)t++;if(t>=e)return!1;let i=r[t],n=r[t+1];return i==="/"&&(n==="/"||n==="*")||i==="*"}async function It(r,e){let t={disabledMacroNames:new Set,filesWithMacros:new Set};e.stage.defineMetadata=t;let i=[],n=u(v),o=r.config.define??{},s=Object.values(r.dependencies??{});for(let a of s){let c=n.getOrTouchFile(a)?.contentSnapshot?.text;if(!c)continue;let l=n.resolve(a);Ct.lastIndex=0;for(let f of c.matchAll(Ct)){let p=f.index;if(gi(c,p))continue;let[,d,m,C]=f;if(t.filesWithMacros.add(l),!d||(d.startsWith(wt)||i.push({text:`Macro function '${d}' not start with '${wt}' prefix to avoid conflicts`,location:mi(c,d,a,p)}),m==="inline"))continue;let R=!!o[C];m==="ifndef"===R&&t.disabledMacroNames.add(d)}}return{warnings:i}}var Re=class{constructor(e={}){this.argv=e;this.configuration.subscribe(this.parseVariants.bind(this))}argv;onEndCallback;onStartCallback;variants={};configuration=u(x);get config(){return this.configuration.getValue()}set onEnd(e){this.onEndCallback=e}set onStart(e){this.onStartCallback=e}reload({config:e,clearCache:t=!1}={}){t&&q.reload(),e&&this.configuration.reload(e),this.disposeVariants(this.compareKeys(this.config.variants,this.variants)),this.parseVariants()}touchFiles(e){for(let t of Object.values(this.variants))t.touchFiles(e)}setConfiguration(e){this.configuration.patch(e)}async typeChack(){let e={};for(let t of Object.values(this.variants))e[t.name]=await t.check();return e}async build(e){let t={cache:new Map,errors:[],results:{}};this.validateDependencies(e);let i=e??Object.keys(this.variants);if(await Promise.all(i.map(n=>this.buildVariant(n,t))),t.errors.length)throw new AggregateError(t.errors,"Build failed");return t.results}onEndTrigger(e){this.onEndCallback&&this.onEndCallback(e)}async onStartTrigger(e){try{let t=await It(this.variants[e.variantName],e);return this.onStartCallback&&this.onStartCallback(e),t}catch(t){let i=[];if(t instanceof AggregateError){for(let n of t.errors)i.push({detail:n,text:n.message});return{errors:i}}throw t}}disposeVariants(e){if(e.length)for(let t of e)this.variants[t].dispose(),delete this.variants[t]}compareKeys(e,t){return[...Object.keys(t).filter(o=>!(o in e))]}parseVariants(){if(!this.config.variants)throw new w("Variants are not defined in the configuration");for(let e of Object.keys(this.config.variants)){if(this.variants[e])continue;let t=new le(e,this.argv);t.onEnd(this.onEndTrigger.bind(this),"build-service"),t.onStart(this.onStartTrigger.bind(this),"build-service"),this.variants[e]=new ce(e,t,this.config.variants[e],this.argv),t.onLoad(St.bind({},this.variants[e]),"build-service")}}getDependOn(e){let{dependOn:t}=this.config.variants?.[e]??{};return t?Array.isArray(t)?t:[t]:[]}validateDependencies(e){let t=new Set,i=new Set,n=(o,s)=>{if(i.has(o))throw new w(`Circular dependency detected: ${[...s,o].join(" \u2192 ")}`);if(!t.has(o)){i.add(o);for(let a of this.getDependOn(o))this.variants[a]&&n(a,[...s,o]);i.delete(o),t.add(o)}};for(let o of e??Object.keys(this.variants))n(o,[])}async executeBuild(e,t){let i=this.getDependOn(e).filter(o=>this.variants[o]);await Promise.all(i.map(o=>this.buildVariant(o,t)));let n=this.variants[e];if(n)try{let o=await n.build();o&&(t.results[e]=Ie(o))}catch(o){U(o)||o instanceof AggregateError?t.errors.push(...Ie({errors:o.errors}).errors):t.errors.push(o instanceof Error?o:new Error(String(o)))}}buildVariant(e,t){let i=t.cache.get(e);if(i)return i;let n=this.executeBuild(e,t);return t.cache.set(e,n),n}};function Ws(r){u(x).reload(r)}function Gs(r){u(x).patch(r)}export{Re as BuildService,Ee as ServerModule,Te as WatchService,Ue as collectFilesFromGlob,Ie as enhancedBuildResult,U as isBuildResultError,Vt as isDirectoryExcluded,te as matchesAny,tr as normalizeMessageToError,Ws as overwriteConfig,Ht as parseGlobs,Gs as patchConfig,re as processEsbuildMessages,Ui as shouldIncludeFile};
|
|
30
|
+
};`),r.push(...t.statements),t.exports.size<1&&t.statements.size<1&&r.push("export {};"),`${r.join(`
|
|
31
|
+
`)}
|
|
32
|
+
`}clause(e){return e.alias?`${e.name} as ${e.alias}`:e.name}build(e,t,r){let i=We(e,t,{stripInternal:!0}).code,s={edits:[],target:e,parsed:Oe(e,i,{sourceType:"module"}),content:i,bundleEdits:[],packageImports:Object.create(null),packageExports:Object.create(null),projectExports:{star:new Set,exports:[],namespace:Object.create(null)},projectDependencies:new Set},n=[],{body:a}=s.parsed.program;for(let c of a)this.strip(c,s)&&n.push(c.start);return this.pruneComments(s,a,n),{version:r,content:O(i,s.bundleEdits),declaration:O(i,s.edits),packageImports:s.packageImports,packageExports:s.packageExports,projectExports:s.projectExports,projectDependencies:s.projectDependencies}}strip(e,t){switch(e.type){case"ImportDeclaration":return this.stripImport(e,t),!1;case"ExportAllDeclaration":return this.stripStarExport(e,t),!1;case"ExportNamedDeclaration":return this.stripNamedExport(e,t);case"ExportDefaultDeclaration":return this.stripDefaultExport(e,t);case"TSImportEqualsDeclaration":return this.stripImportEquals(e,t);case"TSExportAssignment":case"TSNamespaceExportDeclaration":return x(e,t.content,t.bundleEdits),!1;default:return!0}}stripImport(e,t){if(x(e,t.content,t.bundleEdits),this.link(e.source,t))return;let r=t.packageImports[e.source.value]??={};if(e.specifiers.length<1){r.side=!0;return}for(let i of e.specifiers)switch(i.type){case"ImportDefaultSpecifier":r.default??=i.local.name;break;case"ImportNamespaceSpecifier":(r.namespaces??=[]).push(i.local.name);break;default:(r.named??=[]).push(this.binding(this.nameOf(i.imported),i.local.name))}}stripImportEquals(e,t){let{moduleReference:r}=e;if(r.type!=="TSExternalModuleReference")return!0;x(e,t.content,t.bundleEdits);let i=r.expression;return this.link(i,t)||((t.packageImports[i.value]??={}).namespaces??=[]).push(e.id.name),!1}stripNamedExport(e,t){let{exports:r}=t.projectExports;if(e.declaration)return this.collectDeclared(e.declaration,r),t.bundleEdits.push({start:e.start,end:e.declaration.start}),!0;x(e,t.content,t.bundleEdits);let i=e.source&&!this.link(e.source,t)?(t.packageExports[e.source.value]??={}).named??=[]:r;for(let s of e.specifiers)i.push(this.binding(this.nameOf(s.local),this.nameOf(s.exported)));return!1}stripStarExport(e,t){x(e,t.content,t.bundleEdits);let r=this.link(e.source,t),i=e.exported?this.nameOf(e.exported):null;if(r){i?t.projectExports.namespace[i]=r:t.projectExports.star.add(r);return}let s=t.packageExports[e.source.value]??={};i?(s.namespaces??=[]).push(i):s.star=!0}stripDefaultExport(e,t){let{declaration:r}=e,i=this.defaultBinding(r);return i&&t.projectExports.exports.push({name:i,alias:"default"}),i&&r.type!=="Identifier"?(t.bundleEdits.push({start:e.start,end:r.start,text:"declare "}),!0):(x(e,t.content,t.bundleEdits),!1)}pruneComments(e,t,r){let{content:i,bundleEdits:s}=e,n=0,a=0;for(let c of e.parsed.comments)if(!(c.type!=="Block"||c.value.charCodeAt(0)!==42)){for(;n<t.length&&t[n].end<=c.start;)n++;if(!(n<t.length&&t[n].start<c.start)){for(;a<r.length&&r[a]<c.end;)a++;a<r.length&&this.blank(i,c.end,r[a])||x(c,i,s)}}}link(e,t){let r=this.ts.resolve(e.value,t.target);if(!r||r.isExternalLibraryImport)return null;let{extension:i,relativeFileName:s,resolvedFileName:n}=r,a=this.filesCache.resolve(n);return t.projectDependencies.add(a),t.edits.push({end:e.end,start:e.start,text:`'${i?s.slice(0,-i.length):s}.d.ts'`}),a}collectDeclared(e,t){if(e.type==="VariableDeclaration"){for(let r of e.declarations)r.id.type==="Identifier"&&t.push({name:r.id.name});return}"id"in e&&e.id&&"name"in e.id&&t.push({name:e.id.name})}defaultBinding(e){return e.type==="Identifier"?e.name:"id"in e?e.id?.name:void 0}nameOf(e){return"name"in e?e.name:JSON.stringify(e.value)}binding(e,t){return e===t?{name:e}:{name:e,alias:t}}blank(e,t,r){for(let i=t;i<r;i++){let s=e.charCodeAt(i);if(s!==32&&s!==9&&s!==10&&s!==13)return!1}return!0}};import S from"typescript";import{relative as Ge}from"@remotex-labs/xmap";import{inject as Ue}from"@remotex-labs/xinject";var M=class{constructor(e){this.config=e;this.reload()}config;filesCache=Ue(v);trackedFiles=new Set;exclusions=new Map;matches;get tracked(){return this.trackedFiles}get ignoreSourceFile(){return e=>this.isExcluded(e.fileName)}set options(e){this.config=e,this.reload()}clearTracked(){this.trackedFiles.clear(),this.refreshFiles(this.config.fileNames)}reload(){this.matches=this.compileExclude(this.config.raw?.exclude),this.exclusions.clear(),this.clearTracked()}refresh(e){return this.filesCache.refresh(this.track(e))}refreshFiles(e=this.trackedFiles){for(let t of e)this.isExcluded(t)||this.refresh(t)}getCompilationSettings(){return this.config.options}fileExists(e){return S.sys.fileExists(e)}readFile(e,t){return this.filesCache.touch(e,t).snapshot?.text}readDirectory(e,t,r,i,s){return S.sys.readDirectory(e,t,r,i,s)}getDirectories(e){return S.sys.getDirectories(e)}directoryExists(e){return S.sys.directoryExists(e)}getCurrentDirectory(){return S.sys.getCurrentDirectory()}getScriptFileNames(){return[...this.trackedFiles]}getDefaultLibFileName(e){return S.getDefaultLibFilePath(e)}getScriptVersion(e){return this.filesCache.touch(this.track(e)).version.toString()}getScriptSnapshot(e){return this.filesCache.touch(e).snapshot}realpath(e){return this.filesCache.resolve(e)}compileExclude(e){return e&&e.length>0?A(e):()=>!1}isExcluded(e){let t=this.filesCache.resolve(e),r=this.exclusions.get(t);return r===void 0&&this.exclusions.set(t,r=this.matches(Ge(process.cwd(),t))),r}track(e){let t=this.filesCache.resolve(e);return this.trackedFiles.add(t),t}};var g=class{constructor(e="tsconfig.json"){this.configPath=e;this.parsedConfig=this.parseConfig(),this.languageHostService=new M(this.parsedConfig),this.configVersion=this.languageHostService.filesCache.touch(this.configPath).version,this.resolutionCache=this.createResolutionCache(),this.languageService=h.createLanguageService(this.languageHostService,h.createDocumentRegistry(!0)),this.declaration=new R(this)}configPath;languageService;languageHostService;diagnosticsCache=new Map;builderHost={createHash:h.sys.createHash,readFile:(e,t)=>this.languageHostService.readFile(e,t),getCurrentDirectory:()=>h.sys.getCurrentDirectory(),useCaseSensitiveFileNames:()=>h.sys.useCaseSensitiveFileNames};declaration;parsedConfig;configVersion;resolutionCache;builder;static reload(e=!1){let t=[];for(let[r,i]of g.cache)i.instance.refresh(e)&&t.push(r);return t}get config(){return this.parsedConfig}check(e){let t=this.languageService.getProgram();if(!t)return[];let r=this.languageHostService.ignoreSourceFile,i=n=>n.fileName.includes("node_modules")?!0:r(n),s;for(this.builder=h.createEmitAndSemanticDiagnosticsBuilderProgram(t,this.builderHost,this.builder);s=this.builder.getSemanticDiagnosticsOfNextAffectedFile(void 0,i);)if("fileName"in s.affected){let n=s.affected;this.diagnosticsCache.set(n.fileName,[...s.result,...this.builder.getSyntacticDiagnostics(n),...this.languageService.getSuggestionDiagnostics(n.fileName)].map(a=>this.formatDiagnostic(a)))}return this.reconcileDiagnostics(t,e??this.diagnosticsCache.keys())}async emit(e,t){return t??=this.config.options.outDir??"dist",this.declaration.emit(e,t)}async emitBundle(e,t){return t??=this.config.options.outDir??"dist",this.declaration.emitBundle(e,t)}touchFiles(e){this.languageHostService.refreshFiles(e)}resolve(e,t){let r=t?this.languageHostService.filesCache.resolve(Xe(t)):process.cwd(),s=this.resolutionCache.getOrCreateCacheForDirectory(r).get(e,void 0)?.resolvedModule;if(s)return s;let n=h.resolveModuleName(e,t??"",this.parsedConfig.options,this.languageHostService,this.resolutionCache).resolvedModule;if(n){let a=Qe(r,n.resolvedFileName);n.container=r,n.relativeFileName=a.startsWith(".")?a:`./${a}`}return n}dispose(){let e=g.cache.get(this.configPath);e&&(e.refCount--,!(e.refCount>0)&&(this.languageService.dispose(),g.cache.delete(this.configPath)))}[Symbol.dispose??Symbol.for("Symbol.dispose")](){this.dispose()}static acquire(e="tsconfig.json"){let t=Ye(e),r=g.cache.get(t);if(r)return r.refCount++,r.instance;let i=new g(t);return g.cache.set(t,{instance:i,refCount:1}),i}refresh(e=!1){let{version:t}=this.languageHostService.filesCache.touch(this.configPath);return!e&&t===this.configVersion?!1:(this.configVersion=t,this.parsedConfig=this.parseConfig(),this.languageHostService.options=this.parsedConfig,this.resolutionCache=this.createResolutionCache(),this.declaration.clear(),this.diagnosticsCache.clear(),this.builder=void 0,!0)}createResolutionCache(){return h.createModuleResolutionCache(h.sys.getCurrentDirectory(),e=>this.languageHostService.realpath(e),this.parsedConfig.options)}reconcileDiagnostics(e,t){let r=this.languageHostService.filesCache,i=[];for(let s of t){let n=r.resolve(s),a=this.diagnosticsCache.get(n);a&&(e.getSourceFile(n)?i.push(...a):this.diagnosticsCache.delete(n))}return i}formatDiagnostic(e){let t={message:h.flattenDiagnosticMessageText(e.messageText,`
|
|
33
|
+
`),category:e.category};if(e.file&&e.start!==void 0){let{line:r,character:i}=e.file.getLineAndCharacterOfPosition(e.start);t.file=e.file.fileName,t.line=r+1,t.column=i+1,t.code=e.code}return t}parseConfig(){let e=h.getParsedCommandLineOfConfigFile(this.configPath,{sourceMap:!1,skipLibCheck:!0,stripInternal:!0,declarationMap:!1,emitDeclarationOnly:!0},{...h.sys,onUnRecoverableConfigFileDiagnostic:()=>{}});return e||(e={options:{strict:!0,target:h.ScriptTarget.ESNext,module:h.ModuleKind.NodeNext,sourceMap:!1,skipLibCheck:!0,stripInternal:!0,declarationMap:!1,emitDeclarationOnly:!0,moduleResolution:h.ModuleResolutionKind.NodeNext},errors:[],fileNames:[],projectReferences:void 0}),e.options={...e.options,noEmit:!0,rootDir:e.options?.rootDir??process.cwd(),isolatedModules:!1,useCaseSensitiveFileNames:!0},e}};k(g,"cache",new Map),g=y([Ke({factory(o){return g.acquire(o)}})],g);export{Y as ServerModule,g as Typescript,P as WatchService,Qt as formatStack,Yt as getErrorMetadata,Ne as getErrorStack,Be as getSource};
|
|
38
34
|
//# sourceMappingURL=index.js.map
|