@remotex-labs/xbuild 2.3.2 → 2.4.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/dist/bash.js +6 -6
- package/dist/bash.js.map +1 -1
- package/dist/index.d.ts +1417 -1234
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var It=Object.create;var me=Object.defineProperty;var Tt=Object.getOwnPropertyDescriptor;var Be=(r,e)=>(e=Symbol[r])?e:Symbol.for("Symbol."+r),J=r=>{throw TypeError(r)};var Ft=(r,e,t)=>e in r?me(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var Ne=(r,e)=>me(r,"name",{value:e,configurable:!0});var T=r=>[,,,It(r?.[Be("metadata")]??null)],$e=["class","method","getter","setter","accessor","field","value","get","set"],X=r=>r!==void 0&&typeof r!="function"?J("Function expected"):r,Ot=(r,e,t,i,n)=>({kind:$e[r],name:e,metadata:i,addInitializer:o=>t._?J("Already initialized"):n.push(X(o||null))}),kt=(r,e)=>Ft(e,Be("metadata"),r[3]),F=(r,e,t,i)=>{for(var n=0,o=r[e>>1],s=o&&o.length;n<s;n++)e&1?o[n].call(t):i=o[n].call(t,i);return i},O=(r,e,t,i,n,o)=>{var s,a,c,l,f,p=e&7,d=!!(e&8),g=!!(e&16),I=p>3?r.length+1:p?d?1:2:0,
|
|
1
|
+
var It=Object.create;var me=Object.defineProperty;var Tt=Object.getOwnPropertyDescriptor;var Be=(r,e)=>(e=Symbol[r])?e:Symbol.for("Symbol."+r),J=r=>{throw TypeError(r)};var Ft=(r,e,t)=>e in r?me(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var Ne=(r,e)=>me(r,"name",{value:e,configurable:!0});var T=r=>[,,,It(r?.[Be("metadata")]??null)],$e=["class","method","getter","setter","accessor","field","value","get","set"],X=r=>r!==void 0&&typeof r!="function"?J("Function expected"):r,Ot=(r,e,t,i,n)=>({kind:$e[r],name:e,metadata:i,addInitializer:o=>t._?J("Already initialized"):n.push(X(o||null))}),kt=(r,e)=>Ft(e,Be("metadata"),r[3]),F=(r,e,t,i)=>{for(var n=0,o=r[e>>1],s=o&&o.length;n<s;n++)e&1?o[n].call(t):i=o[n].call(t,i);return i},O=(r,e,t,i,n,o)=>{var s,a,c,l,f,p=e&7,d=!!(e&8),g=!!(e&16),I=p>3?r.length+1:p?d?1:2:0,R=$e[p+5],A=p>3&&(r[I-1]=[]),ue=r[I]||(r[I]=[]),y=p&&(!g&&!d&&(n=n.prototype),p<5&&(p>3||!g)&&Tt(p<4?n:{get[t](){return De(this,o)},set[t](S){return je(this,o,S)}},t));p?g&&p<4&&Ne(o,(p>2?"set ":p>1?"get ":"")+t):Ne(n,t);for(var G=i.length-1;G>=0;G--)l=Ot(p,t,c={},r[3],ue),p&&(l.static=d,l.private=g,f=l.access={has:g?S=>Pt(n,S):S=>t in S},p^3&&(f.get=g?S=>(p^1?De:Mt)(S,n,p^4?o:y.get):S=>S[t]),p>2&&(f.set=g?(S,de)=>je(S,n,de,p^4?o:y.set):(S,de)=>S[t]=de)),a=(0,i[G])(p?p<4?g?o:y[R]:p>4?void 0:{get:y.get,set:y.set}:n,l),c._=1,p^4||a===void 0?X(a)&&(p>4?A.unshift(a):p?g?o=a:y[R]=a:n=a):typeof a!="object"||a===null?J("Object expected"):(X(s=a.get)&&(y.get=s),X(s=a.set)&&(y.set=s),X(s=a.init)&&A.unshift(s));return p||kt(r,n),y&&me(n,t,y),g?p^4?o:y:n};var ge=(r,e,t)=>e.has(r)||J("Cannot "+t),Pt=(r,e)=>Object(e)!==e?J('Cannot use the "in" operator on this value'):r.has(e),De=(r,e,t)=>(ge(r,e,"read from private field"),t?t.call(r):e.get(r));var je=(r,e,t,i)=>(ge(r,e,"write to private field"),i?i.call(r,t):e.set(r,t),t),Mt=(r,e,t)=>(ge(r,e,"access private method"),t);var he=new Map,Le=new Map;function At(r){return typeof r=="object"&&r!==null&&"useClass"in r}function Rt(r){return typeof r=="object"&&r!==null&&"useFactory"in r}function Nt(r){return typeof r=="object"&&r!==null&&"useValue"in r}function k(r){return function(e){Le.set(e,r||{})}}function ve(r,e=[]){if(!r)return e;let t=e;for(let i of r.slice(t.length))if(At(i))t.push(u(i.useClass,...ve(i.providers)));else if(Rt(i))t.push(i.useFactory(...ve(i.providers)));else if(Nt(i))t.push(i.useValue);else if(typeof i=="function")t.push(u(i));else throw new Error(`Unknown provider type: ${typeof i}`);return t}function u(r,...e){if(he.has(r))return he.get(r);let t=Le.get(r);if(!t)throw new Error(`Cannot inject ${r.name} \u2013 not marked @Injectable`);let i=ve(t.providers,e),n=t.factory?t.factory(...i):new r(...i);return t?.scope==="singleton"&&he.set(r,n),n}function He(r){return e=>new N(t=>e.subscribe({next:i=>{try{let n=r(i);t.next?.(n)}catch(n){t.error?.(n)}},error:i=>t.error?.(i),complete:()=>t.complete?.()}))}function Ve(r=(e,t)=>e===t){return e=>new N(t=>{let i=!1,n;return e.subscribe({next:o=>{try{if(!i){n=o,i=!0,t.next?.(o);return}r(n,o)||(n=o,t.next?.(o))}catch(s){t.error?.(s)}},error:o=>t.error?.(o),complete:()=>t.complete?.()})})}var N=class{constructor(e){this.handler=e}subscribe(e,t,i){let n=this.createSafeObserver(e,t,i),o;try{o=this.handler(n)}catch(s){return n.error?.(s),()=>{}}return()=>{try{o?.()}catch(s){n.error?.(s)}}}pipe(...e){return e.length===0?this:e.reduce((t,i)=>i(t),this)}createSafeObserver(e,t,i){return typeof e=="function"?{next:e,error:t,complete:i}:e||{}}};var Y=class extends N{isCompleted=!1;observers=new Set;constructor(){super(e=>{if(this.isCompleted){e.complete?.();return}return this.observers.add(e),()=>this.observers.delete(e)})}next(e){if(this.isCompleted)return;let t=[];for(let i of[...this.observers])try{i.next?.(e)}catch(n){t.push(n);try{i.error?.(n)}catch{}}if(t.length>0)throw new AggregateError(t,`${t.length} observer(s) failed in next()`)}error(e){if(this.isCompleted)return;let t=[];for(let i of[...this.observers])try{i.error?.(e)}catch(n){t.push(n)}if(t.length>0)throw new AggregateError(t,`${t.length} observer(s) failed in error()`)}complete(){if(this.isCompleted)return;let e=[];for(let t of[...this.observers])try{t.complete?.()}catch(i){e.push(i)}if(this.observers.clear(),this.isCompleted=!0,e.length>0)throw new AggregateError(e,`${e.length} observer(s) failed in complete()`)}};var Q=class extends Y{lastValue;constructor(e){super(),this.lastValue=typeof e=="function"?e():e}get value(){return this.lastValue}subscribe(e,t,i){if(this.isCompleted)return()=>{};let n=this.createSafeObserver(e,t,i),o=super.subscribe(n);return n.next?.(this.lastValue),o}next(e){this.isCompleted||(this.lastValue=e,super.next(e))}};function Z(r){return!!r&&typeof r=="object"&&!Array.isArray(r)}function D(r,...e){if(!e.length)return r;let t=e.shift();if(Z(r)&&Z(t)){for(let i in t){let n=t[i],o=r[i];Array.isArray(n)&&Array.isArray(o)?Object.assign(r,{[i]:[...o,...n]}):Z(n)?Object.assign(r,{[i]:D(Z(o)?o:{},n)}):Object.assign(r,{[i]:n})}return D(r,...e)}return r}function ee(r,e,t=!0){return r===e||Object.is(r,e)?!0:r===null||e===null?!1:r instanceof Date&&e instanceof Date?r.getTime()===e.getTime():r instanceof RegExp&&e instanceof RegExp?r.source===e.source&&r.flags===e.flags:URL&&r instanceof URL&&e instanceof URL?r.href===e.href:typeof r=="object"&&typeof e=="object"?jt(r,e,t):!1}function Dt(r,e){return r==null||typeof r!="object"&&typeof r!="function"?!1:e in r||Object.prototype.hasOwnProperty.call(r,e)}function jt(r,e,t=!0){if(Array.isArray(r)&&Array.isArray(e))return t&&r.length!==e.length?!1:r.every((o,s)=>ee(o,e[s],t));let i=Object.keys(r),n=Object.keys(e);if(t&&i.length!==n.length)return!1;for(let o of i)if(!Dt(e,o)||!ee(r[o],e[o],t))return!1;return!0}var _e=Object.freeze({verbose:!1,common:Object.freeze({types:!0,declaration:!0,esbuild:Object.freeze({write:!0,bundle:!0,minify:!0,format:"cjs",outdir:"dist",platform:"browser",absWorkingDir:process.cwd()})})});var ze,ye;ze=[k({scope:"singleton"})];var x=class{constructor(e=_e){this.initialConfig=e;this.config$=new Q(D({},e))}config$;getValue(e){return e?e(this.config$.value):this.config$.value}subscribe(e){return this.config$.subscribe(e)}select(e){return this.config$.pipe(He(e),Ve((t,i)=>ee(t,i)))}patch(e){let t=D({},this.config$.value,e);this.config$.next(t)}reload(e){this.config$.next(D({},this.initialConfig,e))}};ye=T(null),x=O(ye,0,"ConfigurationService",ze,x),F(ye,1,x);import{cwd as Bt}from"process";import{readdirSync as $t}from"fs";import{matchesGlob as xe}from"path";import{join as Lt}from"@remotex-labs/xmap";function Ht(r){let e=[],t=[];for(let i of r)i.startsWith("!")?t.push(i.slice(1)):e.push(i);return{include:e,exclude:t}}function te(r,e){for(let t of e)if(t.endsWith(r)||xe(r,t))return!0;return!1}function Vt(r,e){let t=r+"/**";for(let i of e)if(xe(r,i)||xe(t,i))return!0;return!1}function _i(r,e,t){return te(r,e)?!te(r,t):!1}function Ue(r,e){let{include:t,exclude:i}=Ht(e),n=Object.create(null),s=Bt().length+1,a=r.length+1,c=i.length>0;function l(f){let p;try{p=$t(f,{withFileTypes:!0})}catch{return}let d=p.length;for(let g=0;g<d;g++){let I=p[g],R=Lt(f,I.name),A=R.slice(a);if(I.isDirectory()){(!c||!Vt(A,i))&&l(R);continue}if(!(c&&te(A,i))&&te(A,t)){let ue=R.slice(s),y=A.lastIndexOf("."),G=y>0?A.slice(0,y):A;n[G]=ue}}}return l(r),n}var j=class r extends Error{diagnostics;constructor(e,t=[]){super(e),this.name="TypesError",this.diagnostics=t,Object.setPrototypeOf(this,r.prototype)}};import{resolveError as Jt}from"@remotex-labs/xmap";import{xterm as Ce}from"@remotex-labs/xansi/xterm.component";import _t from"typescript";import{resolve as zt}from"@remotex-labs/xmap";import{closeSync as Ut,fstatSync as Kt,openSync as qt,readFileSync as Wt}from"fs";var Ke,be;Ke=[k({scope:"singleton"})];var v=class{resolvedPathCache=new Map;snapshotsByPath=new Map;clear(){this.snapshotsByPath.clear(),this.resolvedPathCache.clear()}getSnapshot(e){return this.snapshotsByPath.get(this.resolve(e))}getOrTouchFile(e){return this.snapshotsByPath.get(this.resolve(e))??this.touchFile(e)}getTrackedFilePaths(){return[...this.snapshotsByPath.keys()]}touchFile(e){let t=this.resolve(e),i=this.snapshotsByPath.get(t)??this.createEntry(t);try{this.syncEntry(t,i)}catch{(i.contentSnapshot!==void 0||i.version>0)&&(i.version++,i.mtimeMs=0,i.contentSnapshot=void 0)}return{...i}}resolve(e){let t=this.resolvedPathCache.get(e);if(t)return t;let i=zt(e);return this.resolvedPathCache.set(e,i),i}createEntry(e){let t={version:0,mtimeMs:0,contentSnapshot:void 0};return this.snapshotsByPath.set(e,t),t}syncEntry(e,t){let i=qt(e,"r");try{let{mtimeMs:n}=Kt(i);if(n===t.mtimeMs)return;let o=Wt(i,"utf-8");t.version++,t.mtimeMs=n,t.contentSnapshot=o?_t.ScriptSnapshot.fromString(o):void 0}finally{Ut(i)}}};be=T(null),v=O(be,0,"FilesModel",Ke,v),F(be,1,v);import{readFileSync as Gt}from"fs";import{SourceService as Xt}from"@remotex-labs/xmap";import{resolve as Se,toPosix as qe}from"@remotex-labs/xmap";var We,we;We=[k({scope:"singleton"})];var b=class{filePath;distPath;rootPath;sourceMaps=new Map;constructor(){this.filePath=import.meta.filename,this.setSourceFile(this.filePath),this.rootPath=this.getRootDir(),this.distPath=this.getDistDir()}isFrameworkFile(e){let{source:t,sourceRoot:i}=e,n=t?.toLowerCase();return!!(t&&n.includes("xbuild")&&!n.includes("xbuild.config")||i&&i.includes("xBuild"))}getSourceMap(e){if(e=Se(e),this.sourceMaps.has(e))return this.sourceMaps.get(e)}setSource(e,t){let i=Se(t);try{return this.initializeSourceMap(e,i)}catch(n){throw new Error(`Failed to initialize SourceService: ${i}
|
|
2
2
|
${n instanceof Error?n.message:String(n)}`)}}setSourceFile(e){if(!e)return;let t=Se(e),i=`${e}.map`;if(!this.sourceMaps.has(t))try{let n=Gt(i,"utf-8");return this.initializeSourceMap(n,t)}catch(n){throw new Error(`Failed to initialize SourceService: ${t}
|
|
3
3
|
${n instanceof Error?n.message:String(n)}`)}}getRootDir(){return qe(process.cwd())}getDistDir(){return qe(import.meta.dirname)}initializeSourceMap(e,t){if(e?.includes('"mappings": ""'))return;let i=new Xt(e,t);this.sourceMaps.set(t,i)}};we=T(null),b=O(we,0,"FrameworkService",We,b),F(we,1,b);import{parseErrorStack as Ge}from"@remotex-labs/xmap/parser.component";import{formatErrorCode as Yt}from"@remotex-labs/xmap/formatter.component";import{highlightCode as Qt}from"@remotex-labs/xmap/highlighter.component";function Zt(r=""){let t=u(b).getSourceMap(r);if(t)return t;let i=u(v).getOrTouchFile(r),n=i?.contentSnapshot?.text;if(!i||!n)return null;let o=n.split(`
|
|
4
4
|
`);return{getPositionWithCode:(s,a,c,l)=>{let f=l?.linesBefore??3,p=l?.linesAfter??3,d=Math.max(s-f,0),g=Math.min(s+p,o.length);return{line:s,column:a+1,code:o.slice(d,g).join(`
|
|
@@ -30,9 +30,9 @@ Enhanced Stack Trace:
|
|
|
30
30
|
${f.join(`,
|
|
31
31
|
`)}
|
|
32
32
|
};`)}return l.length>0&&n.push(...l),n.join(`
|
|
33
|
-
`)}};import{dirname as Or}from"@remotex-labs/xmap";import{mkdir as kr,writeFile as Pr}from"fs/promises";import{xterm as Mr}from"@remotex-labs/xansi/xterm.component";var ae=class r{constructor(e,t){this.languageService=e;this.languageHostService=t}static emittedVersions=new Map;static clearCache(){this.emittedVersions.clear()}async emit(e){let t=this.languageService.getProgram();if(!t)throw new Error(`${Mr.deepOrange("[TS]")} Language service program is not available`);let i=this.languageHostService.getCompilationSettings();e&&(i={...i,outDir:e});let n=[],o=t.getSourceFiles();for(let s=0;s<o.length;s++){let a=o[s];this.shouldEmitFile(a,t,i)&&n.push(a)}n.length!==0&&await Promise.all(n.map(s=>this.emitSingleDeclaration(s,i)))}shouldEmitFile(e,t,i){if(e.isDeclarationFile||t.isSourceFileFromExternalLibrary(e))return!1;let n=Fe(e.fileName,i),o=r.emittedVersions.get(n),s=this.languageHostService.getScriptVersion(e.fileName);return!o||o!==s?(r.emittedVersions.set(n,s),!0):!1}async emitSingleDeclaration(e,t){let i=this.languageService.getEmitOutput(e.fileName,!0);if(i.emitSkipped)return;let n=i.outputFiles[0].text,o=Fe(e.fileName,t);n=oe(n),n=this.languageHostService.resolveAliases(n,e.fileName,".d.ts"),await kr(Or(o),{recursive:!0}),await Pr(o,n,"utf8")}};import K from"typescript";import{relative as
|
|
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 Nr={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(),...Nr,...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,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 Lr,resolve as Hr,join as ft,dirname as Vr}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;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.typescriptModule.languageHostService.touchFiles(Object.values(this.buildConfig.esbuild.entryPoints)),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})}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);this.dependenciesFile=await this.buildDependencyMap(),this.buildConfig.esbuild.bundle===!1&&Object.assign(e,{entryPoints:this.dependenciesFile});try{let t=await jr(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===Dr.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=Vr(a);$r(a,"utf8").then(l=>{let f=JSON.parse(l);f.sources=f.sources.map(p=>p.startsWith("http")?p:ft(c,p)),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 Br(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)throw new w("Entry points are required in esbuild configuration");let t=e.define,i=t?Object.fromEntries(Object.entries(t).map(([n,o])=>[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,{metafile:t}=await ct(e.entryPoints,{loader:e.loader,platform:e.platform}),i={};for(let n of Object.keys(t.inputs)){let o=Lr(this.typescriptModule.config.options.rootDir,Hr(n)),s=this.stripExtension(o);i[s]=n}return i}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 _r}from"fs/promises";import{resolve as zr}from"@remotex-labs/xmap";var le=class{constructor(e,t){this.variantName=e;this.argv=t}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=zr(t.path),a=this.filesModel.getSnapshot(s),c=a?.contentSnapshot?a.contentSnapshot.text:await _r(s,"utf8");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{highlightCode as xt}from"@remotex-labs/xmap/highlighter.component";import M from"typescript";var Ur="$$ifdef";function Kr(r,e,t,i=!1){let n=i?"export function ":"function ";return M.isArrowFunction(e)||M.isFunctionExpression(e)?qr(r,e,t,n):`${i?"export const ":"const "}${r} = ${e.getText(t)};`}function qr(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=Wr(e,t);return`${o}${i}${r}(${s})${a} ${c}`}function Wr(r,e){let t=r.body.getText(e);return M.isArrowFunction(r)&&!M.isBlock(r.body)?`{ return ${t}; }`:t}function Gr(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===Ur===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 Kr(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} = `),Gr(s,e.sourceFile,l,n)}import E from"typescript";import{createRequire as Yr}from"module";var fe=class extends C{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 Xr,createContext as Jr}from"vm";async function mt(r,e={},t={}){let i=new Xr(r,t),n=Jr(e);return await i.runInContext(n,{breakOnSigint:!0,displayErrors:!1})}import{dirname as Qr,relative as Zr}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=Yr(e.sourceFile.fileName),a=ei(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){ti(o,e,i.text,t)}return"undefined"}function ei(r,e,t){return{...globalThis,Error,RegExp,process,Buffer,module:e,require:t,console,setTimeout,setInterval,clearTimeout,clearInterval,ReferenceError,__dirname:Qr(r),__filename:r}}function ti(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 ri(r,e){let t=null,i=n=>{if(!t){if(E.isFunctionDeclaration(n)&&n.name?.text===r){t=n;return}E.isVariableStatement(n)&&(t=ii(n,r),t)||E.forEachChild(n,i)}};return i(e),t}function ii(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 ni(r){return r&E.NodeFlags.Const?"const":r&E.NodeFlags.Let?"let":"var"}function vt(r,e){return r?E.isIdentifier(r)?oi(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 oi(r,e){let t=ri(r.text,e.sourceFile);return t?{node:t,data:ht(t.getText(e.sourceFile))}:(si(r.text,e,r),{data:"",node:r})}function si(r,e,t){let i=t.getStart(e.sourceFile),{line:n,character:o}=e.sourceFile.getLineAndCharacterOfPosition(i),s=Zr(".",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=ni(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 ai=/\.(ts|js)$/,L=["$$ifdef","$$ifndef","$$inline"];function Re(r,e){return L.some(t=>r.getText(e).includes(t))}function bt(r){return r===L[2]?1:2}async function ci(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 li(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 pi(r,e,t){if(!h.isCallExpression(r)||!Re(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 fi(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 ci(c,o,r)||l===h.SyntaxKind.ExpressionStatement&&Re(c,r.sourceFile)&&await li(c,o,r)||l===h.SyntaxKind.CallExpression&&Re(c,r.sourceFile)&&await pi(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 g=d?.getText(r.sourceFile);(!h.isCallExpression(d)||d.expression!==c)&&(!g||L.every(I=>!g.includes(I)))&&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||!ai.test(t.path))return;let f=r.typescript.languageService.getProgram()?.getSourceFile(t.path);if(!f)return;let p={stage:n,errors:[],contents:o.toString(),warnings:[],defines:r.config.define??{},sourceFile:f,context:{argv:c,options:a,variantName:s}},d=await fi(p,r.name);return r.config.esbuild.bundle||r.typescript.languageHostService.aliasRegex&&(d=r.typescript.languageHostService.resolveAliases(d,t.path,".js")),{loader:i,contents:d,warnings:p.warnings,errors:p.errors}}var wt="$$",Ct=/(?:(?:export\s+)?(?:const|let|var)\s+([\w$]+)\s*=\s*)?\$\$(ifdef|ifndef|inline)\s*\(\s*(?:['"]([^'"]+)['"])?/g;function ui(r,e,t,i){let n=1;for(let s=0;s<i;s++)r[s]===`
|
|
33
|
+
`)}};import{dirname as Or}from"@remotex-labs/xmap";import{mkdir as kr,writeFile as Pr}from"fs/promises";import{xterm as Mr}from"@remotex-labs/xansi/xterm.component";var ae=class r{constructor(e,t){this.languageService=e;this.languageHostService=t}static emittedVersions=new Map;static clearCache(){this.emittedVersions.clear()}async emit(e){let t=this.languageService.getProgram();if(!t)throw new Error(`${Mr.deepOrange("[TS]")} Language service program is not available`);let i=this.languageHostService.getCompilationSettings();e&&(i={...i,outDir:e});let n=[],o=t.getSourceFiles();for(let s=0;s<o.length;s++){let a=o[s];this.shouldEmitFile(a,t,i)&&n.push(a)}n.length!==0&&await Promise.all(n.map(s=>this.emitSingleDeclaration(s,i)))}shouldEmitFile(e,t,i){if(e.isDeclarationFile||t.isSourceFileFromExternalLibrary(e))return!1;let n=Fe(e.fileName,i),o=r.emittedVersions.get(n),s=this.languageHostService.getScriptVersion(e.fileName);return!o||o!==s?(r.emittedVersions.set(n,s),!0):!1}async emitSingleDeclaration(e,t){let i=this.languageService.getEmitOutput(e.fileName,!0);if(i.emitSkipped)return;let n=i.outputFiles[0].text,o=Fe(e.fileName,t);n=oe(n),n=this.languageHostService.resolveAliases(n,e.fileName,".d.ts"),await kr(Or(o),{recursive:!0}),await Pr(o,n,"utf8")}};import K from"typescript";import{relative as Ar,dirname as Rr}from"@remotex-labs/xmap";var q=class r{constructor(e={}){this.compilerOptions=e;this.alias=r.generateAliasRegex(e),this.moduleResolutionCache=K.createModuleResolutionCache(process.cwd(),t=>t,this.compilerOptions)}static sys=K.sys;alias;aliasCache=new Map;moduleResolutionCache;trackFiles=new Set;filesCache=u(v);get aliasRegex(){return this.alias}set options(e){this.compilerOptions=e,this.alias=r.generateAliasRegex(e),this.moduleResolutionCache=K.createModuleResolutionCache(process.cwd(),t=>t,this.compilerOptions)}static reload(){let e=u(v);e.getTrackedFilePaths().map(t=>{e.touchFile(t)})}touchFile(e){return this.trackFiles.add(this.filesCache.resolve(e)),this.filesCache.touchFile(e)}touchFiles(e){for(let t of e)this.touchFile(t)}getCompilationSettings(){return this.compilerOptions}fileExists(e){return r.sys.fileExists(e)}readFile(e,t){return r.sys.readFile(e,t)}readDirectory(e,t,i,n,o){return r.sys.readDirectory(e,t,i,n,o)}getDirectories(e){return r.sys.getDirectories(e)}directoryExists(e){return r.sys.directoryExists(e)}getCurrentDirectory(){return r.sys.getCurrentDirectory()}getScriptFileNames(){return[...this.trackFiles]}getDefaultLibFileName(e){return K.getDefaultLibFilePath(e)}getScriptVersion(e){let t=this.filesCache.getSnapshot(e);return this.trackFiles.add(this.filesCache.resolve(e)),t?t.version.toString():"0"}hasScriptSnapshot(e){return this.trackFiles.has(this.filesCache.resolve(e))}getScriptSnapshot(e){let t=this.filesCache.getSnapshot(e);return this.trackFiles.add(this.filesCache.resolve(e)),t?t.contentSnapshot:this.touchFile(e).contentSnapshot}resolveModuleName(e,t){return K.resolveModuleName(e,t,this.compilerOptions,K.sys,this.moduleResolutionCache)}resolveModuleFileName(e,t){if(this.aliasCache.has(e))return this.aliasCache.get(e);let n=this.resolveModuleName(e,t).resolvedModule?.resolvedFileName;return this.aliasCache.set(e,n),n}resolveAliases(e,t,i=""){return this.alias?e.replace(this.alias,(n,o)=>{let s=this.resolveModuleFileName(o,t);if(!s)return n;let a=s.replace(/\.tsx?$/,i),c=Ar(Rr(t),a);return n.replace(o,c.startsWith(".")?c:"./"+c)}):e}static generateAliasRegex(e){let t=e.paths;if(!t||Object.keys(t).length<1)return;let i=Object.keys(t).map(n=>n.replace("/*","").replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join("|");return new RegExp(`(?:^|\\s)(?:import|export)\\s+(?:type\\s+)?(?:[^'"]*from\\s+)?['"]((${i})[^'"]*)['"];?`,"gm")}};var ot,ke;ot=[k({providers:[{useValue:"tsconfig.json"}]})];var P=class P{constructor(e="tsconfig.json"){this.configPath=e;let{config:t,host:i,service:n}=this.acquireLanguageService();this.config=t,this.languageService=n,this.languageHostService=i,this.languageHostService.touchFiles(this.config.fileNames),this.emitterService=new ae(n,i),this.bundlerService=new se(n,i)}config;languageService;languageHostService;static serviceCache=new Map;emitterService;bundlerService;check(e){let t=this.languageService.getProgram();if(!t)return[];let i=e&&e.length>0?e.map(n=>t.getSourceFile(n)):this.languageService.getProgram()?.getSourceFiles();return i?i.filter(n=>this.shouldCheckFile(n)).flatMap(n=>this.collectDiagnostics(n)):[]}touchFiles(e){for(let t of e)if(this.languageHostService.hasScriptSnapshot(t)&&this.languageHostService.touchFile(t),t.includes(this.configPath)){let i=P.serviceCache.get(this.configPath);i.config=this.parseConfig(),i.host.options=i.config.options}}async emitBundle(e,t){await this.bundlerService.emit(e,t)}async emit(e){await this.emitterService.emit(e)}dispose(e){let t=P.serviceCache.get(e);t&&(t.refCount--,P.cleanupUnusedServices())}static cleanupUnusedServices(){for(let[e,t]of this.serviceCache)t.refCount<1&&(t.service.dispose(),this.serviceCache.delete(e))}shouldCheckFile(e){return e&&!e.fileName.includes("node_modules")&&!e.isDeclarationFile}collectDiagnostics(e){return[...this.languageService.getSemanticDiagnostics(e.fileName),...this.languageService.getSyntacticDiagnostics(e.fileName),...this.languageService.getSuggestionDiagnostics(e.fileName)].map(t=>this.formatDiagnostic(t))}acquireLanguageService(){let e=P.serviceCache.get(this.configPath);return e?(e.refCount++,e):this.createLanguageService()}createLanguageService(){let e=this.parseConfig(),t=new q(e.options),i=$.createLanguageService(t,$.createDocumentRegistry()),n={config:e,host:t,service:i,refCount:1};return P.serviceCache.set(this.configPath,n),n}parseConfig(){let e=$.getParsedCommandLineOfConfigFile(this.configPath,{sourceMap:!1,skipLibCheck:!0,stripInternal:!0,declarationMap:!1,emitDeclarationOnly:!0},{...$.sys,onUnRecoverableConfigFileDiagnostic:()=>{}});return e||(e={options:{strict:!0,target:$.ScriptTarget.ESNext,module:$.ModuleKind.NodeNext,sourceMap:!1,skipLibCheck:!0,stripInternal:!0,declarationMap:!1,emitDeclarationOnly:!0,moduleResolution:$.ModuleResolutionKind.NodeNext},errors:[],fileNames:[],projectReferences:void 0}),e.options={...e.options,rootDir:e.options?.rootDir??process.cwd()},e}formatDiagnostic(e){let t={message:$.flattenDiagnosticMessageText(e.messageText,`
|
|
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 Nr={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(),...Nr,...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,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 Lr,resolve as Hr,join as ft,dirname as Vr}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;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.typescriptModule.languageHostService.touchFiles(Object.values(this.buildConfig.esbuild.entryPoints)),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})}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);this.dependenciesFile=await this.buildDependencyMap(),this.buildConfig.esbuild.bundle===!1&&Object.assign(e,{entryPoints:this.dependenciesFile});try{let t=await jr(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===Dr.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=Vr(a);$r(a,"utf8").then(l=>{let f=JSON.parse(l);f.sources=f.sources.map(p=>p.startsWith("http")?p:ft(c,p)),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 Br(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)throw new w("Entry points are required in esbuild configuration");let t=e.define,i=t?Object.fromEntries(Object.entries(t).map(([n,o])=>[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,{metafile:t}=await ct(e.entryPoints,{loader:e.loader,platform:e.platform}),i={};for(let n of Object.keys(t.inputs)){let o=Lr(this.typescriptModule.config.options.rootDir,Hr(n)),s=this.stripExtension(o);i[s]=n}return i}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 _r}from"fs/promises";import{resolve as zr}from"@remotex-labs/xmap";var le=class{constructor(e,t){this.variantName=e;this.argv=t}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=zr(t.path),a=this.filesModel.getSnapshot(s),c=a?.contentSnapshot?a.contentSnapshot.text:await _r(s,"utf8");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{highlightCode as xt}from"@remotex-labs/xmap/highlighter.component";import M from"typescript";var Ur="$$ifdef";function Kr(r,e,t,i=!1){let n=i?"export function ":"function ";return M.isArrowFunction(e)||M.isFunctionExpression(e)?qr(r,e,t,n):`${i?"export const ":"const "}${r} = ${e.getText(t)};`}function qr(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=Wr(e,t);return`${o}${i}${r}(${s})${a} ${c}`}function Wr(r,e){let t=r.body.getText(e);return M.isArrowFunction(r)&&!M.isBlock(r.body)?`{ return ${t}; }`:t}function Gr(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===Ur===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 Kr(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} = `),Gr(s,e.sourceFile,l,n)}import E from"typescript";import{createRequire as Yr}from"module";var fe=class extends C{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 Xr,createContext as Jr}from"vm";async function mt(r,e={},t={}){let i=new Xr(r,t),n=Jr(e);return await i.runInContext(n,{breakOnSigint:!0,displayErrors:!1})}import{dirname as Qr,relative as Zr}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=Yr(e.sourceFile.fileName),a=ei(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){ti(o,e,i.text,t)}return"undefined"}function ei(r,e,t){return{...globalThis,Error,RegExp,process,Buffer,module:e,require:t,console,setTimeout,setInterval,clearTimeout,clearInterval,ReferenceError,__dirname:Qr(r),__filename:r}}function ti(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 ri(r,e){let t=null,i=n=>{if(!t){if(E.isFunctionDeclaration(n)&&n.name?.text===r){t=n;return}E.isVariableStatement(n)&&(t=ii(n,r),t)||E.forEachChild(n,i)}};return i(e),t}function ii(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 ni(r){return r&E.NodeFlags.Const?"const":r&E.NodeFlags.Let?"let":"var"}function vt(r,e){return r?E.isIdentifier(r)?oi(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 oi(r,e){let t=ri(r.text,e.sourceFile);return t?{node:t,data:ht(t.getText(e.sourceFile))}:(si(r.text,e,r),{data:"",node:r})}function si(r,e,t){let i=t.getStart(e.sourceFile),{line:n,character:o}=e.sourceFile.getLineAndCharacterOfPosition(i),s=Zr(".",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=ni(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 ai=/\.(ts|js)$/,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 ci(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 li(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 pi(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 fi(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 ci(c,o,r)||l===h.SyntaxKind.ExpressionStatement&&Ae(c,r.sourceFile)&&await li(c,o,r)||l===h.SyntaxKind.CallExpression&&Ae(c,r.sourceFile)&&await pi(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 g=d?.getText(r.sourceFile);(!h.isCallExpression(d)||d.expression!==c)&&(!g||L.every(I=>!g.includes(I)))&&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||!ai.test(t.path))return;let f=r.typescript.languageService.getProgram()?.getSourceFile(t.path);if(!f)return;let p={stage:n,errors:[],contents:o.toString(),warnings:[],defines:r.config.define??{},sourceFile:f,context:{argv:c,options:a,variantName:s}},d=await fi(p,r.name);return r.config.esbuild.bundle||r.typescript.languageHostService.aliasRegex&&(d=r.typescript.languageHostService.resolveAliases(d,t.path,".js")),{loader:i,contents:d,warnings:p.warnings,errors:p.errors}}var wt="$$",Ct=/(?:(?:export\s+)?(?:const|let|var)\s+([\w$]+)\s*=\s*)?\$\$(ifdef|ifndef|inline)\s*\(\s*(?:['"]([^'"]+)['"])?/g;function ui(r,e,t,i){let n=1;for(let s=0;s<i;s++)r[s]===`
|
|
35
35
|
`&&n++;let o=r.lastIndexOf(`
|
|
36
36
|
`,i-1)+1;return{file:t,line:n,column:r.indexOf(e,o)-o}}function di(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 Et(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(di(c,p))continue;let[,d,g,I]=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:ui(c,d,a,p)}),g==="inline"))continue;let
|
|
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 Et(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(di(c,p))continue;let[,d,g,I]=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:ui(c,d,a,p)}),g==="inline"))continue;let R=!!o[I];g==="ifndef"===R&&t.disabledMacroNames.add(d)}}return{warnings:i}}var Re=class{constructor(e={}){this.argv=e;this.configuration.subscribe(this.parseVariants.bind(this))}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 Et(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]=Ee(o))}catch(o){U(o)||o instanceof AggregateError?t.errors.push(...Ee({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 _s(r){u(x).reload(r)}function zs(r){u(x).patch(r)}export{Re as BuildService,Ie as ServerModule,Te as WatchService,Ue as collectFilesFromGlob,Ee as enhancedBuildResult,U as isBuildResultError,Vt as isDirectoryExcluded,te as matchesAny,tr as normalizeMessageToError,_s as overwriteConfig,Ht as parseGlobs,zs as patchConfig,re as processEsbuildMessages,_i as shouldIncludeFile};
|
|
38
38
|
//# sourceMappingURL=index.js.map
|