@remotex-labs/xbuild 1.0.0 → 1.1.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.
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Import will remove at compile time
3
3
  */
4
- import type { EntryPoints } from "../configuration/interfaces/configuration.interface.ts";
4
+ import type { EntryPoints } from "../configuration/interfaces/configuration.interface";
5
5
  /**
6
6
  * Maps an array of file paths to an object where the keys are filenames (without extensions)
7
7
  * and the values are the corresponding file paths.
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Import will remove at compile time
3
3
  */
4
- import type { ConfigurationInterface } from "./interfaces/configuration.interface.ts";
4
+ import type { ConfigurationInterface } from "./interfaces/configuration.interface";
5
5
  /**
6
6
  * The default configuration options for the build.
7
7
  *
@@ -3,7 +3,7 @@
3
3
  */
4
4
  import type { BuildOptions } from 'esbuild';
5
5
  import type { IncomingMessage, ServerResponse } from 'http';
6
- import type { OnEndType, OnLoadType, OnResolveType, OnStartType } from "../../providers/interfaces/plugins.interfaces.ts";
6
+ import type { OnEndType, OnLoadType, OnResolveType, OnStartType } from "../../providers/interfaces/plugins.interfaces";
7
7
  /**
8
8
  * Represents the format for specifying entry points in TypeScript declaration generation.
9
9
  *
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Import will remove at compile time
3
3
  */
4
- import type { ConfigurationInterface } from "./interfaces/configuration.interface.ts";
4
+ import type { ConfigurationInterface } from "./interfaces/configuration.interface";
5
5
  /**
6
6
  * Parses a configuration file and returns a wrapped `ConfigurationInterface` object.
7
7
  *
@@ -5,7 +5,7 @@ import type { Message } from 'esbuild';
5
5
  /**
6
6
  * Imports
7
7
  */
8
- import { BaseError } from "./base.error.ts";
8
+ import { BaseError } from ".//base.error";
9
9
  /**
10
10
  * Represents an error that occurs during the esbuild process.
11
11
  *
@@ -5,7 +5,7 @@ import type { SourceService } from '@remotex-labs/xmap';
5
5
  /**
6
6
  * Imports
7
7
  */
8
- import { BaseError } from "./base.error.ts";
8
+ import { BaseError } from ".//base.error";
9
9
  /**
10
10
  * A custom error class to handle errors occurring within a virtual machine (VM) execution context.
11
11
  *
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Imports
3
3
  */
4
- import { BaseError } from "./base.error.ts";
4
+ import { BaseError } from ".//base.error";
5
5
  /**
6
6
  * Represents an error specific to the xBuild process.
7
7
  *
package/dist/index.d.ts CHANGED
@@ -2,5 +2,5 @@
2
2
  /**
3
3
  * Exports
4
4
  */
5
- export type * from "./configuration/interfaces/configuration.interface.ts";
5
+ export type * from "./configuration/interfaces/configuration.interface";
6
6
  export type { BuildResult, OnLoadArgs, OnLoadResult, OnResolveArgs, OnResolveResult, PluginBuild } from 'esbuild';
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- "use strict";var ge=Object.create;var M=Object.defineProperty;var me=Object.getOwnPropertyDescriptor;var he=Object.getOwnPropertyNames;var ye=Object.getPrototypeOf,ve=Object.prototype.hasOwnProperty;var j=(o,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of he(e))!ve.call(o,i)&&i!==t&&M(o,i,{get:()=>e[i],enumerable:!(r=me(e,i))||r.enumerable});return o};var E=(o,e,t)=>(t=o!=null?ge(ye(o)):{},j(e||!o||!o.__esModule?M(t,"default",{value:o,enumerable:!0}):t,o)),Se=o=>j(M({},"__esModule",{value:!0}),o);var Le={};module.exports=Se(Le);var H=require("path"),V=require("fs");function c(o,e,t=__ACTIVE_COLOR){return t?`${o}${e}\x1B[0m`:e}var v=require("@remotex-labs/xmap"),be=__dirname,xe=(0,V.readFileSync)((0,H.join)(be,"index.js.map")),W=new v.SourceService(JSON.parse(xe.toString()));process.on("uncaughtException",o=>{o instanceof Error?console.error(o.toString()):console.error(o)});process.on("unhandledRejection",o=>{o instanceof Error?console.error(o.toString()):console.error(o)});function Ce(o,e){return o.file.includes("evalmachine")||o.file.includes("node:vm")?e.getSourcePosition(o.line,o.column):W.getSourcePosition(o.line,o.column)}var d=class o extends Error{constructor(t,r=W){super(t);this.sourceMap=r;global.__ACTIVE_COLOR||(global.__ACTIVE_COLOR=!0),Error.captureStackTrace&&Error.captureStackTrace(this,o),this.name="Error"}stackArray=[];blockCode=null;toString(){let t=__ACTIVE_COLOR?"\x1B[0m":"";return t+=`
2
+ "use strict";var he=Object.create;var F=Object.defineProperty;var ye=Object.getOwnPropertyDescriptor;var ve=Object.getOwnPropertyNames;var Se=Object.getPrototypeOf,be=Object.prototype.hasOwnProperty;var j=(o,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of ve(e))!be.call(o,i)&&i!==t&&F(o,i,{get:()=>e[i],enumerable:!(r=ye(e,i))||r.enumerable});return o};var O=(o,e,t)=>(t=o!=null?he(Se(o)):{},j(e||!o||!o.__esModule?F(t,"default",{value:o,enumerable:!0}):t,o)),xe=o=>j(F({},"__esModule",{value:!0}),o);var De={};module.exports=xe(De);var H=require("path"),W=require("fs");function c(o,e,t=__ACTIVE_COLOR){return t?`${o}${e}\x1B[0m`:e}var v=require("@remotex-labs/xmap"),Ce=__dirname,we=(0,W.readFileSync)((0,H.join)(Ce,"index.js.map")),V=new v.SourceService(JSON.parse(we.toString()));process.on("uncaughtException",o=>{o instanceof Error?console.error(o.toString()):console.error(o)});process.on("unhandledRejection",o=>{o instanceof Error?console.error(o.toString()):console.error(o)});function Ee(o,e){return o.file.includes("evalmachine")||o.file.includes("node:vm")?e.getSourcePosition(o.line,o.column):V.getSourcePosition(o.line,o.column)}var m=class o extends Error{constructor(t,r=V){super(t);this.sourceMap=r;global.__ACTIVE_COLOR||(global.__ACTIVE_COLOR=!0),Error.captureStackTrace&&Error.captureStackTrace(this,o),this.name="Error"}stackArray=[];blockCode=null;toString(){let t=__ACTIVE_COLOR?"\x1B[0m":"";return t+=`
3
3
  ${this.name}:
4
4
  ${this.message}
5
5
 
@@ -8,19 +8,19 @@ ${this.message}
8
8
  `),this.stackArray.length>0&&(t+=`Enhanced Stack Trace:
9
9
  ${this.stackArray.join(`
10
10
  `)}
11
- `),t}reformatStack(t){if(!t||!this.sourceMap)return t;let r=(0,v.parseErrorStack)(t||"");return this.stackArray=this.getFormattedStackEntries(r,this.sourceMap),this.toString()}getFormattedStackEntries(t,r){let i=[];return t.forEach(n=>{let a=Ce(n,r);if(a){this.updateBlockCodeIfNecessary(a);let l=this.getFilePathWithSourceRoot(a),h=a.name?`${a.name} `:"";i.push(`at ${h}${c("\x1B[38;5;238m",l)} ${c("\x1B[38;5;243m",`[${a.line}:${a.column}]`)}`)}else!n.executor&&!n.at.includes("anonymous")&&i.push(`at ${n.at} ${c("\x1B[38;5;238m",n.file)} ${c("\x1B[38;5;243m",`[${n.line}:${n.column}]`)}`)}),i}updateBlockCodeIfNecessary(t){if(!this.blockCode){let r=__ACTIVE_COLOR?(0,v.highlightCode)(t.code):t.code;this.blockCode=(0,v.formatErrorCode)({...t,code:r},{color:__ACTIVE_COLOR?"\x1B[38;5;197m":"",reset:__ACTIVE_COLOR?"\x1B[0m":""})}}getFilePathWithSourceRoot(t){let r=t.source;return t.sourceRoot&&(r=r.replace("../",t.sourceRoot)+`#L${t.line}`),r}};var G=E(require("yargs")),J=require("yargs/helpers");var we=`
11
+ `),t}reformatStack(t){if(!t||!this.sourceMap)return t;let r=(0,v.parseErrorStack)(t||"");return this.stackArray=this.getFormattedStackEntries(r,this.sourceMap),this.toString()}getFormattedStackEntries(t,r){let i=[];return t.forEach(n=>{let s=Ee(n,r);if(s){this.updateBlockCodeIfNecessary(s);let l=this.getFilePathWithSourceRoot(s),f=s.name?`${s.name} `:"";i.push(`at ${f}${c("\x1B[38;5;238m",l)} ${c("\x1B[38;5;243m",`[${s.line}:${s.column}]`)}`)}else!n.executor&&!n.at.includes("anonymous")&&i.push(`at ${n.at} ${c("\x1B[38;5;238m",n.file)} ${c("\x1B[38;5;243m",`[${n.line}:${n.column}]`)}`)}),i}updateBlockCodeIfNecessary(t){if(!this.blockCode){let r=__ACTIVE_COLOR?(0,v.highlightCode)(t.code):t.code;this.blockCode=(0,v.formatErrorCode)({...t,code:r},{color:__ACTIVE_COLOR?"\x1B[38;5;197m":"",reset:__ACTIVE_COLOR?"\x1B[0m":""})}}getFilePathWithSourceRoot(t){let r=t.source;return t.sourceRoot&&(r=r.replace("../",t.sourceRoot)+`#L${t.line}`),r}};var G=O(require("yargs")),J=require("yargs/helpers");var Oe=`
12
12
  ______ _ _ _
13
13
  | ___ \\ (_) | | |
14
14
  __ _| |_/ /_ _ _| | __| |
15
15
  \\ \\/ / ___ \\ | | | | |/ _\` |
16
16
  > <| |_/ / |_| | | | (_| |
17
17
  /_/\\_\\____/ \\__,_|_|_|\\__,_|
18
- `;function C(o=!0){return`
19
- \r${c("\x1B[38;5;208m",we,o)}
20
- \rVersion: ${c("\x1B[38;5;197m","v1.0.0",o)}
21
- \r`}function f(){return c("\x1B[38;5;203m","[xBuild]")}function Y(o){let e=(0,G.default)((0,J.hideBin)(o)).command("$0 [file]","A versatile JavaScript and TypeScript toolchain build system.",t=>{t.positional("entryPoints",{describe:"The file entryPoints to build",type:"string"}).option("node",{alias:"n",describe:"Build for node platform",type:"boolean",default:!1}).option("dev",{alias:"d",describe:"Array entryPoints to run as development in Node.js",type:"array"}).option("debug",{alias:"db",describe:"Array entryPoints to run in Node.js with debug state",type:"array"}).option("serve",{alias:"s",describe:"Serve the build folder over HTTP",type:"boolean",default:!1}).option("outdir",{alias:"o",describe:"Output directory",type:"string",default:"dist"}).option("declaration",{alias:"de",describe:"Add TypeScript declarations",type:"boolean",default:!1}).option("watch",{alias:"w",describe:"Watch for file changes",type:"boolean",default:!1}).option("config",{alias:"c",describe:"Build configuration file (js/ts)",type:"string",default:"xbuild.config.ts"}).option("tsconfig",{alias:"tc",describe:"Set TypeScript configuration file to use",type:"string",default:"tsconfig.json"}).option("minify",{alias:"m",describe:"Minify the code",type:"boolean",default:!1}).option("bundle",{alias:"b",describe:"Bundle the code",type:"boolean",default:!1}).option("noTypeChecker",{alias:"ntc",describe:"Skip TypeScript type checking",type:"boolean",default:!1}).option("buildOnError",{alias:"boe",describe:"Continue building even if there are TypeScript type errors",type:"boolean",default:!1}).option("version",{alias:"v",describe:"Show version number",type:"boolean",default:!1,conflicts:"help"})}).help().alias("help","h").version(!1).middleware(t=>{t.version&&(console.log(C()),process.exit(0))});return e.showHelp(t=>{(process.argv.includes("--help")||process.argv.includes("-h"))&&(console.log(C()),console.log(t+`
18
+ `;function w(o=!0){return`
19
+ \r${c("\x1B[38;5;208m",Oe,o)}
20
+ \rVersion: ${c("\x1B[38;5;197m","v1.1.0",o)}
21
+ \r`}function u(){return c("\x1B[38;5;203m","[xBuild]")}function Y(o){let e=(0,G.default)((0,J.hideBin)(o)).command("$0 [file]","A versatile JavaScript and TypeScript toolchain build system.",t=>{t.positional("entryPoints",{describe:"The file entryPoints to build",type:"string"}).option("node",{alias:"n",describe:"Build for node platform",type:"boolean",default:!1}).option("dev",{alias:"d",describe:"Array entryPoints to run as development in Node.js",type:"array"}).option("debug",{alias:"db",describe:"Array entryPoints to run in Node.js with debug state",type:"array"}).option("serve",{alias:"s",describe:"Serve the build folder over HTTP",type:"boolean",default:!1}).option("outdir",{alias:"o",describe:"Output directory",type:"string",default:"dist"}).option("declaration",{alias:"de",describe:"Add TypeScript declarations",type:"boolean",default:!1}).option("watch",{alias:"w",describe:"Watch for file changes",type:"boolean",default:!1}).option("config",{alias:"c",describe:"Build configuration file (js/ts)",type:"string",default:"xbuild.config.ts"}).option("tsconfig",{alias:"tc",describe:"Set TypeScript configuration file to use",type:"string",default:"tsconfig.json"}).option("minify",{alias:"m",describe:"Minify the code",type:"boolean",default:!1}).option("bundle",{alias:"b",describe:"Bundle the code",type:"boolean",default:!1}).option("noTypeChecker",{alias:"ntc",describe:"Skip TypeScript type checking",type:"boolean",default:!1}).option("buildOnError",{alias:"boe",describe:"Continue building even if there are TypeScript type errors",type:"boolean",default:!1}).option("version",{alias:"v",describe:"Show version number",type:"boolean",default:!1,conflicts:"help"})}).help().alias("help","h").version(!1).middleware(t=>{t.version&&(console.log(w()),process.exit(0))});return e.showHelp(t=>{(process.argv.includes("--help")||process.argv.includes("-h"))&&(console.log(w()),console.log(t+`
22
22
 
23
- `),process.exit(0))}),e}var N=require("path"),D=require("esbuild");var q=require("child_process");function U(o,e){let t=["--enable-source-maps",o];e&&t.unshift("--inspect-brk=0.0.0.0:0");let r=(0,q.spawn)("node",t);return r.stdout.on("data",i=>{console.log(i.toString())}),r.stderr.on("data",i=>{console.error(i.toString())}),r}var g=class o extends d{constructor(e,t){super(e),Error.captureStackTrace&&Error.captureStackTrace(this,o),t&&Object.assign(this,t),this.name="xBuildError",this.stack=this.reformatStack(this.stack)}setStack(e){this.blockCode=null,this.stack=this.reformatStack(e)}};var k=require("@remotex-labs/xmap"),O=class o extends d{constructor(e){if(super(e.text),Error.captureStackTrace&&Error.captureStackTrace(this,o),this.name="EsbuildError",!e.location)return;let t=e.location;this.stackArray=this.getFormattedStackEntries([{at:"",line:t.line,column:t.column,file:t.file}],this.sourceMap);let r=__ACTIVE_COLOR?(0,k.highlightCode)(t.lineText):t.lineText;this.blockCode=(0,k.formatErrorCode)({line:t.line,name:null,column:t.column,source:t.file,endLine:t.line+1,startLine:t.line-1,sourceRoot:t.file,code:r},{color:__ACTIVE_COLOR?"\x1B[38;5;197m":"",reset:__ACTIVE_COLOR?"\x1B[0m":""})}};var K=E(require("http")),Q=E(require("https"));var z=`<!DOCTYPE html>
23
+ `),process.exit(0))}),e}var b=require("path"),B=require("esbuild");var q=require("child_process");function U(o,e){let t=["--enable-source-maps",o];e&&t.unshift("--inspect-brk=0.0.0.0:0");let r=(0,q.spawn)("node",t);return r.stdout.on("data",i=>{console.log(i.toString())}),r.stderr.on("data",i=>{console.error(i.toString())}),r}var h=class o extends m{constructor(e,t){super(e),Error.captureStackTrace&&Error.captureStackTrace(this,o),t&&Object.assign(this,t),this.name="xBuildError",this.stack=this.reformatStack(this.stack)}setStack(e){this.blockCode=null,this.stack=this.reformatStack(e)}};var P=require("@remotex-labs/xmap"),k=class o extends m{constructor(e){if(super(e.text),Error.captureStackTrace&&Error.captureStackTrace(this,o),this.name="EsbuildError",!e.location)return;let t=e.location;this.stackArray=this.getFormattedStackEntries([{at:"",line:t.line,column:t.column,file:t.file}],this.sourceMap);let r=__ACTIVE_COLOR?(0,P.highlightCode)(t.lineText):t.lineText;this.blockCode=(0,P.formatErrorCode)({line:t.line,name:null,column:t.column+1,source:t.file,endLine:t.line+1,startLine:t.line-1,sourceRoot:t.file,code:r},{color:__ACTIVE_COLOR?"\x1B[38;5;197m":"",reset:__ACTIVE_COLOR?"\x1B[0m":""})}};var K=O(require("http")),Q=O(require("https"));var z=`<!DOCTYPE html>
24
24
  <html>
25
25
  <head>
26
26
  <meta charset="UTF-8">
@@ -77,10 +77,10 @@ __ _| |_/ /_ _ _| | __| |
77
77
  <ul>\${ fileList }</ul>
78
78
  </body>
79
79
  </html>
80
- `;var S=require("path");var u=require("fs"),P=class{constructor(e,t){this.dir=t;this.config=e,this.isHttps=this.config.keyfile&&this.config.certfile?(0,u.existsSync)(this.config.keyfile)&&(0,u.existsSync)(this.config.certfile):!1}isHttps;config;start(){if(this.isHttps)return this.startHttpsServer();this.startHttpServer()}startHttpServer(){K.createServer((t,r)=>{this.handleRequest(t,r,()=>this.defaultResponse(t,r))}).listen(this.config.port,()=>{console.log(`${f()}HTTP server is running at http://localhost:${this.config.port}`)})}startHttpsServer(){let e={key:(0,u.readFileSync)(this.config.keyfile),cert:(0,u.readFileSync)(this.config.certfile)};Q.createServer(e,(r,i)=>{this.handleRequest(r,i,()=>this.defaultResponse(r,i))}).listen(this.config.port,()=>{let r=c("\x1B[38;5;227m",`https://${this.config.host}:${this.config.port}`);console.log(`${f()} HTTPS server is running at ${r}`)})}handleRequest(e,t,r){try{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",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=(0,S.resolve)(this.dir),i=e.url==="/"?"":e.url?.replace(/^\/+/,"")||"",n=(0,S.join)(r,i);try{let a=await this.promisifyStat(n);a.isDirectory()?this.handleDirectory(n,i,t):a.isFile()&&this.handleFile(n,t)}catch(a){let l=a.message;l.includes("favicon")||console.log(f(),l),this.sendNotFound(t)}}promisifyStat(e){return new Promise((t,r)=>{(0,u.stat)(e,(i,n)=>i?r(i):t(n))})}handleDirectory(e,t,r){(0,u.readdir)(e,(i,n)=>{if(i)return this.sendError(r,i);let a={html:{icon:"fa-file-code",color:"#d1a65f"},css:{icon:"fa-file-css",color:"#264de4"},js:{icon:"fa-file-code",color:"#f7df1e"},json:{icon:"fa-file-json",color:"#b41717"},png:{icon:"fa-file-image",color:"#53a8e4"},jpg:{icon:"fa-file-image",color:"#53a8e4"},jpeg:{icon:"fa-file-image",color:"#53a8e4"},gif:{icon:"fa-file-image",color:"#53a8e4"},txt:{icon:"fa-file-alt",color:"#8e8e8e"},folder:{icon:"fa-folder",color:"#ffb800"}},l=n.map(h=>{let B=(0,S.extname)(h).slice(1)||"folder",{icon:$,color:de}=a[B]||a.folder;return`<li><i class="fas ${$}" style="color: ${de};"></i> <a href="${(0,S.join)(t,h)}">${h}</a></li>`}).join("");r.writeHead(200,{"Content-Type":"text/html"}),r.end(z.replace("${ fileList }",l))})}handleFile(e,t){let r=(0,S.extname)(e).slice(1)||"txt",i=this.getContentType(r);(0,u.readFile)(e,(n,a)=>{if(n)return this.sendError(t,n);t.writeHead(200,{"Content-Type":i}),t.end(a)})}sendNotFound(e){e.writeHead(404,{"Content-Type":"text/plain"}),e.end("Not Found")}sendError(e,t){console.error(`${f()}`,t.toString()),e.writeHead(500,{"Content-Type":"text/plain"}),e.end("Internal Server Error")}};var X=require("fs"),Z=require("path"),R=class{onEndHooks=[];onLoadHooks=[];onStartHooks=[];onResolveHooks=[];registerOnStart(e){e&&this.onStartHooks.push(e)}registerOnEnd(e){e&&this.onEndHooks.push(e)}registerOnResolve(e){e&&this.onResolveHooks.push(e)}registerOnLoad(e){e&&this.onLoadHooks.push(e)}setup(){return{name:"middleware-plugin",setup:e=>{e.initialOptions.metafile=!0,e.onEnd(this.handleOnEnd.bind(this)),e.onStart(this.handleOnStart.bind(this,e)),e.onLoad({filter:/.*/},this.handleOnLoad.bind(this)),e.onResolve({filter:/.*/},this.handleOnResolve.bind(this))}}}async handleOnStart(e){for(let t of this.onStartHooks)await t(e)}async handleOnEnd(e){for(let t of this.onEndHooks)await t(e)}async handleOnResolve(e){let t={};for(let r of this.onResolveHooks){let i=await r(e);i&&(t={...t,...i,path:i.path||t.path})}return t.path?t:null}async handleOnLoad(e){let t={contents:void 0,loader:"default"},r=(0,Z.resolve)(e.path);t.contents||(t.contents=await X.promises.readFile(r,"utf8"));for(let i of this.onLoadHooks){let n=await i(t.contents??"",t.loader,e);n&&(t={...t,...n,contents:n.contents||t.contents,loader:n.loader||t.loader})}return t.contents?t:null}};function ee(o,e){return o.replace(/\/\/\s?ifdef (\w+)[\s\S]*?\/\/\s?endif/g,(t,r)=>e[r]?t:"")}var te=require("process"),F=require("esbuild");var Oe={write:!1,bundle:!0,minify:!1,format:"cjs",target:"esnext",platform:"node",sourcemap:!0,sourcesContent:!0,preserveSymlinks:!0};function ke(o){let e=/\/\/# sourceMappingURL=data:application\/json;base64,([^'"\s]+)/,t=o.match(e);if(!t||!t[1])throw new g("Source map URL not found in the output.");let r=t[1];return{code:o.replace(e,""),sourceMap:r}}async function re(o,e={}){let t={absWorkingDir:(0,te.cwd)(),...Oe,...e,entryPoints:[o]},i=(await(0,F.build)(t)).outputFiles?.pop()?.text??"";return ke(i)}async function oe(o,e="browser"){return(await(0,F.build)({entryPoints:o,bundle:!0,write:!1,metafile:!0,platform:e,logLevel:"silent",outdir:"dist"})).metafile}var T=class o extends Error{constructor(e,t){super(e),this.name="TypesError",Object.setPrototypeOf(this,o.prototype),t?.cause&&(this.cause=t.cause)}};var y=require("path");function Pe(o){let e={};return o.forEach(t=>{let r=t.substring(0,t.lastIndexOf("."));e[r]=t}),e}function _(o){if(Array.isArray(o)){let e={};return o.length>0&&typeof o[0]=="object"?o.forEach(t=>{e[t.out]=t.in}):typeof o[0]=="string"&&(e=Pe(o)),e}else if(o&&typeof o=="object")return o;throw new Error("Unsupported entry points format")}var s=require("typescript"),I=class{constructor(e,t,r=!0){this.tsConfig=e;this.outDir=t;this.activeColor=r;this.options={...this.tsConfig.options,outDir:this.outDir}}options;typeCheck(e=!1){let t=(0,s.createProgram)(this.tsConfig.fileNames,{...this.options,noEmit:!0,skipLibCheck:!0});this.handleDiagnostics((0,s.getPreEmitDiagnostics)(t),e)}generateDeclarations(e){let t=Object.values(_(e));(0,s.createProgram)(t,{...this.options,declaration:!0,skipLibCheck:!0,emitDeclarationOnly:!0}).emit(void 0,void 0,void 0,!0,{afterDeclarations:[this.createTransformerFactory()]})}isImportOrExportDeclaration(e){return(0,s.isImportDeclaration)(e)||(0,s.isExportDeclaration)(e)}hasStringLiteralModuleSpecifier(e){return e.moduleSpecifier&&(0,s.isStringLiteral)(e.moduleSpecifier)}resolveModuleFileName(e,t){let r,i=(0,s.resolveModuleName)(e,t.baseUrl,t,s.sys);if(i.resolvedModule&&t.rootDir){if(i.resolvedModule.resolvedFileName.includes("node_modules"))return r;r=(0,y.resolve)(i.resolvedModule.resolvedFileName).replace((0,y.resolve)(t.rootDir),".")}return r}getRelativePathToOutDir(e,t){e=(0,y.resolve)(e).replace((0,y.resolve)(this.options.rootDir??""),".");let r=(0,y.relative)((0,y.dirname)(e),t).replace(/\\/g,"/");return r.startsWith("..")?r:"./"+r}updateModuleSpecifier(e,t){let r=s.factory.createStringLiteral(t);return(0,s.isImportDeclaration)(e)?s.factory.updateImportDeclaration(e,e.modifiers,e.importClause,r,void 0):(0,s.isExportDeclaration)(e)?s.factory.updateExportDeclaration(e,e.modifiers,e.isTypeOnly,e.exportClause,r,void 0):e}createVisitor(e,t){let r=i=>{if(this.isImportOrExportDeclaration(i)&&this.hasStringLiteralModuleSpecifier(i)){let n=i.moduleSpecifier.text,a=this.resolveModuleFileName(n,this.options);if(a){let l=this.getRelativePathToOutDir(e.fileName,a);return this.updateModuleSpecifier(i,l)}}return(0,s.visitEachChild)(i,r,t)};return r}createTransformerFactory(){return e=>({transformSourceFile:t=>(0,s.visitEachChild)(t,this.createVisitor(t,e),e),transformBundle:t=>t})}handleDiagnostics(e,t=!1){if(e.length!==0&&(e.forEach(r=>{if(r.file&&r.start!==void 0){let{line:i,character:n}=r.file.getLineAndCharacterOfPosition(r.start),a=(0,s.flattenDiagnosticMessageText)(r.messageText,`
81
- `),l=c("\x1B[38;5;81m",r.file.fileName,this.activeColor),h=c("\x1B[38;5;230m",`${i+1}:${n+1}`,this.activeColor),B=c("\x1B[38;5;9m","error",this.activeColor),$=c("\x1B[38;5;243m",`TS${r.code}`,this.activeColor);console.log(`${f()} ${l}:${h} - ${B} ${$}:${a}`)}else console.error((0,s.flattenDiagnosticMessageText)(r.messageText,`
80
+ `;var S=require("path");var p=require("fs"),R=class{constructor(e,t){this.dir=t;this.config=e,this.isHttps=this.config.keyfile&&this.config.certfile?(0,p.existsSync)(this.config.keyfile)&&(0,p.existsSync)(this.config.certfile):!1}isHttps;config;start(){if(this.isHttps)return this.startHttpsServer();this.startHttpServer()}startHttpServer(){K.createServer((t,r)=>{this.handleRequest(t,r,()=>this.defaultResponse(t,r))}).listen(this.config.port,this.config.host,()=>{console.log(`${u()}HTTP server is running at http://${this.config.host}:${this.config.port}`)})}startHttpsServer(){let e={key:(0,p.readFileSync)(this.config.keyfile),cert:(0,p.readFileSync)(this.config.certfile)};Q.createServer(e,(r,i)=>{this.handleRequest(r,i,()=>this.defaultResponse(r,i))}).listen(this.config.port,this.config.host,()=>{let r=c("\x1B[38;5;227m",`https://${this.config.host}:${this.config.port}`);console.log(`${u()} HTTPS server is running at ${r}`)})}handleRequest(e,t,r){try{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",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=(0,S.resolve)(this.dir),i=e.url==="/"?"":e.url?.replace(/^\/+/,"")||"",n=(0,S.join)(r,i);try{let s=await this.promisifyStat(n);s.isDirectory()?this.handleDirectory(n,i,t):s.isFile()&&this.handleFile(n,t)}catch(s){let l=s.message;l.includes("favicon")||console.log(u(),l),this.sendNotFound(t)}}promisifyStat(e){return new Promise((t,r)=>{(0,p.stat)(e,(i,n)=>i?r(i):t(n))})}handleDirectory(e,t,r){(0,p.readdir)(e,(i,n)=>{if(i)return this.sendError(r,i);let s={html:{icon:"fa-file-code",color:"#d1a65f"},css:{icon:"fa-file-css",color:"#264de4"},js:{icon:"fa-file-code",color:"#f7df1e"},json:{icon:"fa-file-json",color:"#b41717"},png:{icon:"fa-file-image",color:"#53a8e4"},jpg:{icon:"fa-file-image",color:"#53a8e4"},jpeg:{icon:"fa-file-image",color:"#53a8e4"},gif:{icon:"fa-file-image",color:"#53a8e4"},txt:{icon:"fa-file-alt",color:"#8e8e8e"},folder:{icon:"fa-folder",color:"#ffb800"}},l=n.map(f=>{let $=(0,S.extname)(f).slice(1)||"folder",{icon:M,color:me}=s[$]||s.folder;return`<li><i class="fas ${M}" style="color: ${me};"></i> <a href="${(0,S.join)(t,f)}">${f}</a></li>`}).join("");r.writeHead(200,{"Content-Type":"text/html"}),r.end(z.replace("${ fileList }",l))})}handleFile(e,t){let r=(0,S.extname)(e).slice(1)||"txt",i=this.getContentType(r);(0,p.readFile)(e,(n,s)=>{if(n)return this.sendError(t,n);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){console.error(`${u()}`,t.toString()),e.writeHead(500,{"Content-Type":"text/plain"}),e.end("Internal Server Error")}};var X=require("fs"),Z=require("path"),T=class{onEndHooks=[];onLoadHooks=[];onStartHooks=[];onResolveHooks=[];registerOnStart(e){e&&this.onStartHooks.push(e)}registerOnEnd(e){e&&this.onEndHooks.push(e)}registerOnResolve(e){e&&this.onResolveHooks.push(e)}registerOnLoad(e){e&&this.onLoadHooks.push(e)}setup(){return{name:"middleware-plugin",setup:e=>{e.initialOptions.metafile=!0,e.onEnd(this.handleOnEnd.bind(this)),e.onStart(this.handleOnStart.bind(this,e)),e.onLoad({filter:/.*/},this.handleOnLoad.bind(this)),e.onResolve({filter:/.*/},this.handleOnResolve.bind(this))}}}async handleOnStart(e){for(let t of this.onStartHooks)await t(e)}async handleOnEnd(e){for(let t of this.onEndHooks)await t(e)}async handleOnResolve(e){let t={};for(let r of this.onResolveHooks){let i=await r(e);i&&(t={...t,...i,path:i.path||t.path})}return t.path?t:null}async handleOnLoad(e){let t={contents:void 0,loader:"default"},r=(0,Z.resolve)(e.path);t.contents||(t.contents=await X.promises.readFile(r,"utf8"));for(let i of this.onLoadHooks){let n=await i(t.contents??"",t.loader,e);n&&(t={...t,...n,contents:n.contents||t.contents,loader:n.loader||t.loader})}return t.contents?t:null}};function ee(o,e){return o.replace(/\/\/\s?ifdef\s?(\w+)([\s\S]*?)\/\/\s?endif/g,(t,r,i)=>e[r]?i:"")}var te=require("path");function re(o,e,t,r){let i=/(?:import|export)\s.*?\sfrom\s+['"]([^'"]+)['"]/g;for(let n in t){let s=(0,te.relative)(e,t[n]).replace(/\\/g,"/");s.startsWith("..")||(s=`./${s}`),o=o.replaceAll(n,`${s}/`),r&&(o=o.replace(i,(l,f)=>l.replace(f,f.endsWith(".js")?f:`${f}.js`)))}return o}var oe=require("process"),N=require("esbuild");var Pe={write:!1,bundle:!0,minify:!1,format:"cjs",target:"esnext",platform:"node",sourcemap:!0,sourcesContent:!0,preserveSymlinks:!0};function Re(o){let e=/\/\/# sourceMappingURL=data:application\/json;base64,([^'"\s]+)/,t=o.match(e);if(!t||!t[1])throw new h("Source map URL not found in the output.");let r=t[1];return{code:o.replace(e,""),sourceMap:r}}async function ie(o,e={}){let t={absWorkingDir:(0,oe.cwd)(),...Pe,...e,entryPoints:[o]},i=(await(0,N.build)(t)).outputFiles?.pop()?.text??"";return Re(i)}async function ne(o,e="browser"){return(await(0,N.build)({entryPoints:o,bundle:!0,write:!1,metafile:!0,platform:e,logLevel:"silent",outdir:"dist"})).metafile}var _=class o extends Error{constructor(e,t){super(e),this.name="TypesError",Object.setPrototypeOf(this,o.prototype),t?.cause&&(this.cause=t.cause)}};var g=require("path");function Te(o){let e={};return o.forEach(t=>{let r=t.substring(0,t.lastIndexOf("."));e[r]=t}),e}function A(o){if(Array.isArray(o)){let e={};return o.length>0&&typeof o[0]=="object"?o.forEach(t=>{e[t.out]=t.in}):typeof o[0]=="string"&&(e=Te(o)),e}else if(o&&typeof o=="object")return o;throw new Error("Unsupported entry points format")}var a=require("typescript"),I=class{constructor(e,t,r=!0){this.tsConfig=e;this.outDir=t;this.activeColor=r;this.options={...this.tsConfig.options,outDir:this.outDir}}options;typeCheck(e=!1){let t=(0,a.createProgram)(this.tsConfig.fileNames,{...this.options,noEmit:!0,skipLibCheck:!0});this.handleDiagnostics((0,a.getPreEmitDiagnostics)(t),e)}generateDeclarations(e){let t=Object.values(A(e));(0,a.createProgram)(t,{...this.options,declaration:!0,skipLibCheck:!0,emitDeclarationOnly:!0}).emit(void 0,void 0,void 0,!0,{afterDeclarations:[this.createTransformerFactory()]})}isImportOrExportDeclaration(e){return(0,a.isImportDeclaration)(e)||(0,a.isExportDeclaration)(e)}hasStringLiteralModuleSpecifier(e){return e.moduleSpecifier&&(0,a.isStringLiteral)(e.moduleSpecifier)}resolveModuleFileName(e,t){let r,i=(0,a.resolveModuleName)(e,t.baseUrl,t,a.sys);if(i.resolvedModule&&t.rootDir){if(i.resolvedModule.resolvedFileName.includes("node_modules"))return r;r=(0,g.resolve)(i.resolvedModule.resolvedFileName).replace((0,g.resolve)(t.rootDir),".")}return r}getRelativePathToOutDir(e,t){e=(0,g.resolve)(e).replace((0,g.resolve)(this.options.rootDir??""),".");let r=(0,g.relative)((0,g.dirname)(e),t).replace(/\\/g,"/"),i=(0,g.parse)(r);return i.dir.startsWith("..")||(i.dir=`./${i.dir}`),`${i.dir}/${i.name}`}updateModuleSpecifier(e,t){let r=a.factory.createStringLiteral(t);return(0,a.isImportDeclaration)(e)?a.factory.updateImportDeclaration(e,e.modifiers,e.importClause,r,void 0):(0,a.isExportDeclaration)(e)?a.factory.updateExportDeclaration(e,e.modifiers,e.isTypeOnly,e.exportClause,r,void 0):e}createVisitor(e,t){let r=i=>{if(this.isImportOrExportDeclaration(i)&&this.hasStringLiteralModuleSpecifier(i)){let n=i.moduleSpecifier.text,s=this.resolveModuleFileName(n,this.options);if(s){let l=this.getRelativePathToOutDir(e.fileName,s);return this.updateModuleSpecifier(i,l)}}return(0,a.visitEachChild)(i,r,t)};return r}createTransformerFactory(){return e=>({transformSourceFile:t=>(0,a.visitEachChild)(t,this.createVisitor(t,e),e),transformBundle:t=>t})}handleDiagnostics(e,t=!1){if(e.length!==0&&(e.forEach(r=>{if(r.file&&r.start!==void 0){let{line:i,character:n}=r.file.getLineAndCharacterOfPosition(r.start),s=(0,a.flattenDiagnosticMessageText)(r.messageText,`
81
+ `),l=c("\x1B[38;5;81m",r.file.fileName,this.activeColor),f=c("\x1B[38;5;230m",`${i+1}:${n+1}`,this.activeColor),$=c("\x1B[38;5;9m","error",this.activeColor),M=c("\x1B[38;5;243m",`TS${r.code}`,this.activeColor);console.log(`${u()} ${l}:${f} - ${$} ${M}:${s}`)}else console.error((0,a.flattenDiagnosticMessageText)(r.messageText,`
82
82
  `))}),console.log(`
83
- `),!t))throw new T("Type checking failed due to errors.")}};var m=E(require("typescript")),fe=require("path"),w=require("fs");var ie=require("process"),p={dev:!1,watch:!1,declaration:!1,buildOnError:!1,noTypeChecker:!1,define:{},esbuild:{write:!0,bundle:!0,minify:!0,format:"cjs",outdir:"dist",platform:"browser",absWorkingDir:(0,ie.cwd)(),loader:{".js":"ts"}},serve:{port:3e3,host:"localhost",active:!1}};var se=require("@remotex-labs/xmap");var L=require("vm");function ne(o,e={}){e.console=console;let t=new L.Script(o),r=(0,L.createContext)(e);return t.runInContext(r,{breakOnSigint:!0})}var b=class o extends d{originalError;constructor(e,t){super(e.message,t),Error.captureStackTrace&&Error.captureStackTrace(this,o),this.originalError=e,this.name="VMRuntimeError",this.stack=this.reformatStack(e.stack)}};function ae(o,e){for(let t in o)if(Object.prototype.hasOwnProperty.call(o,t)){let r=o[t];typeof r=="function"?o[t]=Re(r,e):typeof r=="object"&&r!==null&&ae(r,e)}return o}function Re(o,e){return(...t)=>{try{return o(...t)}catch(r){throw new b(r,e)}}}function Te(o,e){return ae(o,e)}async function ce(o){let{code:e,sourceMap:t}=await re(o,{banner:{js:"(function(module, exports) {"},footer:{js:"})(module, module.exports);"}}),r={exports:{}},i=new se.SourceService(JSON.parse(atob(t)));try{await ne(e,{require,module:r})}catch(n){throw new b(n,i)}return Te(r.exports.default,i)}var le=JSON.stringify({compilerOptions:{strict:!0,target:"ESNext",module:"ESNext",outDir:"dist",skipLibCheck:!0,isolatedModules:!1,esModuleInterop:!1,moduleDetection:"force",moduleResolution:"node",resolveJsonModule:!0,allowSyntheticDefaultImports:!0,forceConsistentCasingInFileNames:!0}});function _e(o){let e=o.argv,t={...p,dev:e.dev??p.dev,watch:e.watch??p.watch,declaration:e.declaration??p.declaration,esbuild:{...p.esbuild,bundle:e.bundle??p.esbuild.bundle,minify:e.minify??p.esbuild.minify,outdir:e.outdir??p.esbuild.outdir,tsconfig:e.tsconfig??p.esbuild.tsconfig},serve:{...p.serve,active:e.serve??p.serve.active}};return e.file&&(t.esbuild.entryPoints=[e.file]),e.node&&(t.esbuild.target=[`node${process.version.slice(1)}`],t.esbuild.platform="node"),t}function ue(o){let e=le,t=o.tsconfig??"";t&&(0,w.existsSync)(t)?e=(0,w.readFileSync)(t,"utf8"):(delete o.tsconfig,o.tsconfigRaw=le);let r=m.default.parseConfigFileTextToJson(t,e);if(r.error)throw new g(m.default.formatDiagnosticsWithColorAndContext([r.error],{getCurrentDirectory:m.default.sys.getCurrentDirectory,getCanonicalFileName:n=>n,getNewLine:()=>m.default.sys.newLine}));let i=m.default.parseJsonConfigFileContent(r.config,m.default.sys,(0,fe.dirname)(t));if(i.errors.length>0)throw new g(m.default.formatDiagnosticsWithColorAndContext(i.errors,{getCurrentDirectory:m.default.sys.getCurrentDirectory,getCanonicalFileName:n=>n,getNewLine:()=>m.default.sys.newLine}));return i}async function pe(o,e){let t=_e(e);if((0,w.existsSync)(o)){let r=await ce(o);r&&(t={...t,...r,esbuild:{...t.esbuild,...r.esbuild},serve:{...t.serve,...r.serve}})}if(!t.esbuild.entryPoints)throw new g("entryPoints cannot be undefined.");return t}var A=class{constructor(e){this.config=e;this.config.esbuild.logLevel="silent",this.typeScriptProvider=new I(ue(this.config.esbuild),this.config.esbuild.outdir??"dist"),this.config.dev!==!1&&(!Array.isArray(this.config.dev)||this.config.dev.length<1)&&(this.config.dev=["index"]),this.pluginsProvider=new R,this.pluginsProvider.registerOnEnd(this.end.bind(this)),this.pluginsProvider.registerOnStart(this.start.bind(this)),this.pluginsProvider.registerOnLoad((t,r,i)=>{if(i.path.endsWith(".ts"))return{loader:"ts",contents:ee(t.toString(),this.config.define)}})}typeScriptProvider;activePossess=[];pluginsProvider;async runDebug(e){try{this.config.dev=!1,this.config.watch=!1;let t=await this.build();this.spawnDev(t.metafile,e,!0)}catch(t){this.handleErrors(t)}}async serve(){let e=new P(this.config.serve,this.config.esbuild.outdir??"");try{e.start(),await(await this.build()).watch()}catch(t){this.handleErrors(t)}}async run(){try{let e=await this.build();(this.config.watch||this.config.dev)&&await e.watch()}catch(e){this.handleErrors(e)}}handleErrors(e){let t=e.errors;for(let r of t){if(!r.detail)return console.log(new O(r).toString());if(r.detail.name!=="TypesError"){if(r.detail.name){if(r.detail.name==="VMRuntimeError")return console.log(r.detail.toString());if(r.detail.name==="Error"){let i=new g(r.text);return i.setStack(r.detail.stack),console.log(i.toString())}}return console.error(r.text)}}}async build(){let e=this.config.esbuild;this.config.hooks&&(this.pluginsProvider.registerOnEnd(this.config.hooks.onEnd),this.pluginsProvider.registerOnLoad(this.config.hooks.onLoad),this.pluginsProvider.registerOnStart(this.config.hooks.onStart),this.pluginsProvider.registerOnResolve(this.config.hooks.onResolve)),e.define||(e.define={});for(let t in this.config.define)e.define[t]=JSON.stringify(this.config.define[t]);return this.config.esbuild.bundle||await this.processEntryPoints(),e.plugins=[this.pluginsProvider.setup()],this.config.watch||this.config.dev||this.config.serve.active?await(0,D.context)(e):await(0,D.build)(e)}spawnDev(e,t,r=!1){if(Array.isArray(t))for(let i in e.outputs)i.includes("map")||!t.some(n=>i.includes(`/${n}.`))||this.activePossess.push(U(i,r))}async start(){try{console.log(`${f()} StartBuild`),this.config.noTypeChecker||this.typeScriptProvider.typeCheck(this.config.buildOnError),this.config.declaration&&this.typeScriptProvider.generateDeclarations(this.config.esbuild.entryPoints)}finally{for(;this.activePossess.length>0;){let e=this.activePossess.pop();e&&e.kill("SIGTERM")}}}async end(e){e.errors.length>0||(console.log(`
84
- ${f()} ${c("\x1B[38;5;166m","Build completed!")}`),console.log(`${f()} ${Object.keys(e.metafile.outputs).length} Modules:`),Object.keys(e.metafile.outputs).forEach(t=>{let r=e.metafile.outputs[t].bytes;console.log(`${f()} ${c("\x1B[38;5;227m",t)}: ${c("\x1B[38;5;208m",r.toString())} bytes`)}),console.log(`
85
- `),this.config.dev&&this.spawnDev(e.metafile,this.config.dev))}async processEntryPoints(){let e=this.config.esbuild,t=await oe(e.entryPoints,e.platform),r=(0,N.resolve)(this.typeScriptProvider.options.rootDir??""),i=_(e.entryPoints),n=Object.values(i);Array.isArray(e.entryPoints)&&typeof e.entryPoints[0]=="string"&&(i={},n=[]);for(let a in t.inputs){if(n.includes(a))continue;let l=(0,N.resolve)(a).replace(r+"\\",""),h=l.substring(0,l.lastIndexOf("."));i[h]=a}e.entryPoints=i}};global.__ACTIVE_COLOR=!0;console.log(C());async function Ie(){let o=Y(process.argv),e=o.argv,t=await pe(e.config,o),r=new A(t);if(Array.isArray(e.debug))return e.debug.length<1&&(e.debug=["index"]),await r.runDebug(e.debug);if(e.serve)return await r.serve();await r.run()}Ie().catch(o=>{if(o instanceof d)return console.log(o.toString());console.log(new b(o).toString())});
83
+ `),!t))throw new _("Type checking failed due to errors.")}};var y=O(require("typescript")),pe=require("path"),E=require("fs");var se=require("process"),d={dev:!1,watch:!1,declaration:!1,buildOnError:!1,noTypeChecker:!1,define:{},esbuild:{write:!0,bundle:!0,minify:!0,format:"cjs",outdir:"dist",platform:"browser",absWorkingDir:(0,se.cwd)(),loader:{".js":"ts"}},serve:{port:3e3,host:"localhost",active:!1}};var ce=require("@remotex-labs/xmap");var L=require("vm");function ae(o,e={}){e.console=console;let t=new L.Script(o),r=(0,L.createContext)(e);return t.runInContext(r,{breakOnSigint:!0})}var x=class o extends m{originalError;constructor(e,t){super(e.message,t),Error.captureStackTrace&&Error.captureStackTrace(this,o),this.originalError=e,this.name="VMRuntimeError",this.stack=this.reformatStack(e.stack)}};function le(o,e){for(let t in o)if(Object.prototype.hasOwnProperty.call(o,t)){let r=o[t];typeof r=="function"?o[t]=_e(r,e):typeof r=="object"&&r!==null&&le(r,e)}return o}function _e(o,e){return(...t)=>{try{return o(...t)}catch(r){throw new x(r,e)}}}function Ae(o,e){return le(o,e)}async function fe(o){let{code:e,sourceMap:t}=await ie(o,{banner:{js:"(function(module, exports) {"},footer:{js:"})(module, module.exports);"}}),r={exports:{}},i=new ce.SourceService(JSON.parse(atob(t)));try{await ae(e,{require,module:r})}catch(n){throw new x(n,i)}return Ae(r.exports.default,i)}var ue=JSON.stringify({compilerOptions:{strict:!0,target:"ESNext",module:"ESNext",outDir:"dist",skipLibCheck:!0,isolatedModules:!1,esModuleInterop:!1,moduleDetection:"force",moduleResolution:"node",resolveJsonModule:!0,allowSyntheticDefaultImports:!0,forceConsistentCasingInFileNames:!0}});function Ie(o){let e=o.argv,t={...d,dev:e.dev??d.dev,watch:e.watch??d.watch,declaration:e.declaration??d.declaration,esbuild:{...d.esbuild,bundle:e.bundle??d.esbuild.bundle,minify:e.minify??d.esbuild.minify,outdir:e.outdir??d.esbuild.outdir,tsconfig:e.tsconfig??d.esbuild.tsconfig},serve:{...d.serve,active:e.serve??d.serve.active}};return e.file&&(t.esbuild.entryPoints=[e.file]),e.node&&(t.esbuild.target=[`node${process.version.slice(1)}`],t.esbuild.platform="node"),t}function de(o){let e=ue,t=o.tsconfig??"";t&&(0,E.existsSync)(t)?e=(0,E.readFileSync)(t,"utf8"):(delete o.tsconfig,o.tsconfigRaw=ue);let r=y.default.parseConfigFileTextToJson(t,e);if(r.error)throw new h(y.default.formatDiagnosticsWithColorAndContext([r.error],{getCurrentDirectory:y.default.sys.getCurrentDirectory,getCanonicalFileName:n=>n,getNewLine:()=>y.default.sys.newLine}));let i=y.default.parseJsonConfigFileContent(r.config,y.default.sys,(0,pe.dirname)(t));if(i.errors.length>0)throw new h(y.default.formatDiagnosticsWithColorAndContext(i.errors,{getCurrentDirectory:y.default.sys.getCurrentDirectory,getCanonicalFileName:n=>n,getNewLine:()=>y.default.sys.newLine}));return i}async function ge(o,e){let t=Ie(e);if((0,E.existsSync)(o)){let r=await fe(o);r&&(t={...t,...r,esbuild:{...t.esbuild,...r.esbuild},serve:{...t.serve,...r.serve}})}if(!t.esbuild.entryPoints)throw new h("entryPoints cannot be undefined.");return t}var D=class{constructor(e){this.config=e;this.config.esbuild.logLevel="silent",this.typeScriptProvider=new I(de(this.config.esbuild),this.config.esbuild.outdir??"dist"),this.config.dev!==!1&&(!Array.isArray(this.config.dev)||this.config.dev.length<1)&&(this.config.dev=["index"]);let t=(0,b.resolve)(this.typeScriptProvider.options.rootDir??""),r=this.generatePathAlias(t);this.pluginsProvider=new T,this.pluginsProvider.registerOnEnd(this.end.bind(this)),this.pluginsProvider.registerOnStart(this.start.bind(this)),this.pluginsProvider.registerOnLoad((i,n,s)=>{if(s.path.endsWith(".ts")){if(!this.config.esbuild.bundle){let l=(0,b.dirname)((0,b.resolve)(s.path).replace(t,"."));i=re(i.toString(),l,r,this.config.esbuild.format==="esm")}return{loader:"ts",contents:ee(i.toString(),this.config.define)}}})}typeScriptProvider;activePossess=[];pluginsProvider;async runDebug(e){try{this.config.dev=!1,this.config.watch=!1;let t=await this.build();this.spawnDev(t.metafile,e,!0)}catch(t){this.handleErrors(t)}}async serve(){let e=new R(this.config.serve,this.config.esbuild.outdir??"");try{e.start(),await(await this.build()).watch()}catch(t){this.handleErrors(t)}}async run(){try{let e=await this.build();(this.config.watch||this.config.dev)&&await e.watch()}catch(e){this.handleErrors(e)}}generatePathAlias(e){let t=this.typeScriptProvider.options.paths,r={};for(let i in t){let n=t[i];if(n.length>0){let s=i.replace("*","");r[s]=(0,b.resolve)(n[0].replace("*","")).replace(e,".")}}return r}handleErrors(e){let t=e.errors;for(let r of t){if(!r.detail)return console.log(new k(r).toString());if(r.detail.name!=="TypesError"){if(r.detail.name){if(r.detail.name==="VMRuntimeError")return console.log(r.detail.toString());if(r.detail.name==="Error"){let i=new h(r.text);return i.setStack(r.detail.stack),console.log(i.toString())}}return console.error(r.text)}}}async build(){let e=this.config.esbuild;this.config.hooks&&(this.pluginsProvider.registerOnEnd(this.config.hooks.onEnd),this.pluginsProvider.registerOnLoad(this.config.hooks.onLoad),this.pluginsProvider.registerOnStart(this.config.hooks.onStart),this.pluginsProvider.registerOnResolve(this.config.hooks.onResolve)),e.define||(e.define={});for(let t in this.config.define)e.define[t]=JSON.stringify(this.config.define[t]);return this.config.esbuild.bundle||await this.processEntryPoints(),e.plugins=[this.pluginsProvider.setup()],this.config.watch||this.config.dev||this.config.serve.active?await(0,B.context)(e):await(0,B.build)(e)}spawnDev(e,t,r=!1){if(Array.isArray(t))for(let i in e.outputs)i.includes("map")||!t.some(n=>i.includes(`/${n}.`))||this.activePossess.push(U(i,r))}async start(){try{console.log(`${u()} StartBuild`),this.config.noTypeChecker||this.typeScriptProvider.typeCheck(this.config.buildOnError),this.config.declaration&&this.typeScriptProvider.generateDeclarations(this.config.esbuild.entryPoints)}finally{for(;this.activePossess.length>0;){let e=this.activePossess.pop();e&&e.kill("SIGTERM")}}}async end(e){e.errors.length>0||(console.log(`
84
+ ${u()} ${c("\x1B[38;5;166m","Build completed!")}`),console.log(`${u()} ${Object.keys(e.metafile.outputs).length} Modules:`),Object.keys(e.metafile.outputs).forEach(t=>{let r=e.metafile.outputs[t].bytes;console.log(`${u()} ${c("\x1B[38;5;227m",t)}: ${c("\x1B[38;5;208m",r.toString())} bytes`)}),console.log(`
85
+ `),this.config.dev&&this.spawnDev(e.metafile,this.config.dev))}async processEntryPoints(){let e=this.config.esbuild,t=await ne(e.entryPoints,e.platform),r=(0,b.resolve)(this.typeScriptProvider.options.rootDir??""),i=A(e.entryPoints),n=Object.values(i);Array.isArray(e.entryPoints)&&typeof e.entryPoints[0]=="string"&&(i={},n=[]);for(let s in t.inputs){if(n.includes(s))continue;let l=(0,b.resolve)(s).replace(r+"\\",""),f=l.substring(0,l.lastIndexOf("."));i[f]=s}e.entryPoints=i}};global.__ACTIVE_COLOR=!0;console.log(w());async function Le(){let o=Y(process.argv),e=o.argv,t=await ge(e.config,o),r=new D(t);if(Array.isArray(e.debug))return e.debug.length<1&&(e.debug=["index"]),await r.runDebug(e.debug);if(e.serve)return await r.serve();await r.run()}Le().catch(o=>{if(o instanceof m)return console.log(o.toString());console.log(new x(o).toString())});
86
86
  //# sourceMappingURL=index.js.map