@weadmin/weixin-minigame-helper-mcp 0.1.21 → 0.1.23
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/mcp/game-bundler-worker.js +2879 -1
- package/mcp/index.js +27833 -7
- package/media/wx-compat.js +12441 -1
- package/media/wx-compat.js.map +7 -0
- package/package.json +2 -1
- package/templates/preview.html +2 -2
|
@@ -1 +1,2879 @@
|
|
|
1
|
-
'use strict';const _0x2e685d=_0x2c37,_0x44347e=_0x2c37;(function(_0x28d6e5,_0x9f8e0){const _0x4989c0=_0x2c37,_0x5f12f3=_0x2c37,_0x2c504c=_0x28d6e5();while(!![]){try{const _0x35d7b4=parseInt(_0x4989c0(0x1e8,'W)wg'))/0x1+-parseInt(_0x5f12f3(0x1f3,'XOao'))/0x2*(-parseInt(_0x4989c0(0x21a,'ct&r'))/0x3)+parseInt(_0x5f12f3(0x1f0,'Wk&A'))/0x4*(-parseInt(_0x4989c0(0x147,']cL7'))/0x5)+parseInt(_0x5f12f3(0xf8,'MD&m'))/0x6+-parseInt(_0x4989c0(0x18e,'&yuJ'))/0x7*(parseInt(_0x4989c0(0x108,'5sH5'))/0x8)+parseInt(_0x5f12f3(0x10f,'GpuU'))/0x9*(-parseInt(_0x5f12f3(0x208,'W3UF'))/0xa)+-parseInt(_0x5f12f3(0x135,'(tvz'))/0xb;if(_0x35d7b4===_0x9f8e0)break;else _0x2c504c['push'](_0x2c504c['shift']());}catch(_0x33c77f){_0x2c504c['push'](_0x2c504c['shift']());}}}(_0x392a,0x5d3ad));var path,fs,os,import_child_process,CI_PACKAGE,CI_VERSION,_installDir,_extensionDir,_installing,_statusInfo,_statusListeners,__create=Object[_0x2e685d(0x1a0,'My&w')],__defProp=Object[_0x2e685d(0x1cb,'&yuJ')],__getOwnPropDesc=Object[_0x44347e(0x127,'(tvz')],__getOwnPropNames=Object[_0x2e685d(0x1fc,'J@Q]')],__getProtoOf=Object['getPrototypeOf'],__hasOwnProp=Object[_0x2e685d(0x156,'&NZs')][_0x2e685d(0x180,'wID%')],__esm=(_0x1eceb3,_0x36cf03)=>function(){const _0x3b1264=_0x2e685d,_0x3a2bed={'IjHGv':function(_0x2a0f78,_0x1576cf){return _0x2a0f78(_0x1576cf);}};return _0x1eceb3&&(_0x36cf03=(0x0,_0x1eceb3[_0x3a2bed[_0x3b1264(0x19c,'bjD[')](__getOwnPropNames,_0x1eceb3)[0x0]])(_0x1eceb3=0x0)),_0x36cf03;},__export=(_0x239fa1,_0x5bd66f)=>{const _0x257156=_0x44347e,_0x204ea4={'JysFA':function(_0x1e6003,_0x51d006,_0x46ece8,_0x51cc57){return _0x1e6003(_0x51d006,_0x46ece8,_0x51cc57);}};for(var name in _0x5bd66f)_0x204ea4[_0x257156(0x162,'w#R#')](__defProp,_0x239fa1,name,{'get':_0x5bd66f[name],'enumerable':!0x0});},__copyProps=(_0x56450e,_0x49bf6a,_0x311871,desc)=>{const _0x48b4ae=_0x2e685d,_0x3dbc9b=_0x2e685d,_0x500e37={'tSqVZ':function(_0x1c3655,_0x2a22c2){return _0x1c3655==_0x2a22c2;},'lHKPx':function(_0x58a17e,_0x2539ce,_0x381f53,_0x30312a){return _0x58a17e(_0x2539ce,_0x381f53,_0x30312a);}};if(_0x49bf6a&&'object'==typeof _0x49bf6a||_0x500e37[_0x48b4ae(0x1dd,'GpuU')](_0x3dbc9b(0x218,'$$mt'),typeof _0x49bf6a)){for(let _0x4ee462 of __getOwnPropNames(_0x49bf6a))__hasOwnProp[_0x3dbc9b(0x13b,'tIj)')](_0x56450e,_0x4ee462)||_0x4ee462===_0x311871||_0x500e37[_0x3dbc9b(0x105,'fgU*')](__defProp,_0x56450e,_0x4ee462,{'get':()=>_0x49bf6a[_0x4ee462],'enumerable':!(desc=__getOwnPropDesc(_0x49bf6a,_0x4ee462))||desc[_0x3dbc9b(0x1ee,'ct&r')]});}return _0x56450e;},__toESM=(_0x3778dc,_0x192ee8,_0x2dfc4c)=>(_0x2dfc4c=null!=_0x3778dc?__create(__getProtoOf(_0x3778dc)):{},__copyProps(!_0x192ee8&&_0x3778dc&&_0x3778dc[_0x44347e(0x20e,'GpuU')]?_0x2dfc4c:__defProp(_0x2dfc4c,'default',{'value':_0x3778dc,'enumerable':!0x0}),_0x3778dc)),__toCommonJS=_0x4a152a=>__copyProps(__defProp({},_0x2e685d(0x150,'bING'),{'value':!0x0}),_0x4a152a),ci_installer_exports={};function setStatus(_0x379cea){_statusInfo=_0x379cea;for(const _0x17424f of _statusListeners)try{_0x17424f(_0x379cea);}catch{}}function onCiInstallStatusChange(_0x1433a6){const _0x20f215=_0x44347e;_statusListeners['add'](_0x1433a6);try{_0x1433a6(_statusInfo);}catch{}return()=>_statusListeners[_0x20f215(0x1e6,'&NZs')](_0x1433a6);}function getCiInstallStatus(){return _statusInfo;}function setCiDepsDir(_0x59c8ba){const _0x257b49=_0x2e685d,_0x1ca205=_0x44347e,_0x1ff98b={'lygWP':function(_0x8262f1){return _0x8262f1();},'FPAfl':function(_0x5d09d1,_0x239d3e){return _0x5d09d1!==_0x239d3e;},'RrkPo':function(_0x4bff58,_0x3c6240){return _0x4bff58(_0x3c6240);},'HVYul':'installed'};_installDir=_0x59c8ba,_0x1ff98b['lygWP'](isCiInstalled)&&_0x1ff98b[_0x257b49(0xf3,'S9f[')](_0x1ca205(0x134,'0!#E'),_statusInfo['status'])&&_0x1ff98b['RrkPo'](setStatus,{'status':_0x1ff98b[_0x257b49(0xf1,'$dAL')],'message':'miniprogram-ci\x20已安装'});}function setCiExtensionDir(_0x495975){_extensionDir=_0x495975;}async function ensureCiInstalled(_0x4c6969){const _0x165438=_0x2e685d,_0x38c4fc=_0x2e685d,_0x1474a1={'kFeTS':'node_modules','wTRvt':function(_0x2c0f92,_0x1d155c){return _0x2c0f92!==_0x1d155c;},'uJwhA':function(_0x542793,_0x180c65){return _0x542793(_0x180c65);},'BjfCz':'installed'},_0xef5b37=getBundledCiPath();if(_0xef5b37)return _0xef5b37;const _0x246daf=getDepsDir(),_0x14b229=path['join'](_0x246daf,_0x1474a1[_0x165438(0x17d,'g8hX')],CI_PACKAGE);if(fs[_0x38c4fc(0x22a,'tzF3')](path['join'](_0x14b229,_0x38c4fc(0x11a,'XOao'))))return _0x1474a1[_0x165438(0x1f5,'bING')](_0x165438(0x1ec,'My&w'),_statusInfo['status'])&&_0x1474a1['uJwhA'](setStatus,{'status':_0x1474a1['BjfCz'],'message':_0x165438(0x1d8,'tDG9')}),_0x14b229;if(_installing)return _installing;_installing=doInstall(_0x246daf,_0x4c6969);try{return await _installing;}finally{_installing=null;}}async function retryCiInstall(_0x459796){const _0x4f3636=_0x2e685d,_0x53f453=_0x44347e,_0xda7c75={'VrQTr':'failed','VLEva':function(_0x1523b0,_0x1297eb){return _0x1523b0(_0x1297eb);}};return _installing||(_0xda7c75[_0x4f3636(0x14a,'(tvz')]===_statusInfo[_0x4f3636(0x21c,'3Xhc')]&&_0xda7c75['VLEva'](setStatus,{'status':_0x4f3636(0x10e,'5sH5')}),_0xda7c75['VLEva'](ensureCiInstalled,_0x459796));}function isCiInstalled(){const _0x5d2b19=_0x2e685d,_0x2ffaac=_0x44347e,_0x218647={'MIGrN':function(_0x18cfcf,_0x3c45ff){return _0x18cfcf(_0x3c45ff);},'Twutb':function(_0x2d0ed7){return _0x2d0ed7();},'HBBSg':'node_modules','HhAPa':'mukwX'};try{if(_0x218647[_0x5d2b19(0x19e,'$$mt')](getBundledCiPath))return!0x0;const _0x55bad7=_0x218647['Twutb'](getDepsDir);return fs['existsSync'](path['join'](_0x55bad7,_0x218647[_0x5d2b19(0x203,'5$N[')],CI_PACKAGE,_0x2ffaac(0x1eb,'R7n3')));}catch{if(_0x218647[_0x5d2b19(0x16c,'[Xin')]==='mukwX')return!0x1;else _0x218647['MIGrN'](_0x2ac023,_0xf90d4);}}function _0x2c37(_0x4bccbc,_0x40caeb){_0x4bccbc=_0x4bccbc-0xea;const _0x392a31=_0x392a();let _0x2c375a=_0x392a31[_0x4bccbc];if(_0x2c37['gJZdsA']===undefined){var _0x127b5e=function(_0x21a73a){const _0x5e5610='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x4fc4d1='',_0x11dd07='';for(let _0x3ffffe=0x0,_0x1c50dc,_0x34c2f3,_0x1729b2=0x0;_0x34c2f3=_0x21a73a['charAt'](_0x1729b2++);~_0x34c2f3&&(_0x1c50dc=_0x3ffffe%0x4?_0x1c50dc*0x40+_0x34c2f3:_0x34c2f3,_0x3ffffe++%0x4)?_0x4fc4d1+=String['fromCharCode'](0xff&_0x1c50dc>>(-0x2*_0x3ffffe&0x6)):0x0){_0x34c2f3=_0x5e5610['indexOf'](_0x34c2f3);}for(let _0x1676c9=0x0,_0x1972d8=_0x4fc4d1['length'];_0x1676c9<_0x1972d8;_0x1676c9++){_0x11dd07+='%'+('00'+_0x4fc4d1['charCodeAt'](_0x1676c9)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x11dd07);};const _0x4db7ce=function(_0x25d69a,_0x48a0b5){let _0x1744c5=[],_0x3be0be=0x0,_0x1d9036,_0x69dc93='';_0x25d69a=_0x127b5e(_0x25d69a);let _0x23aff7;for(_0x23aff7=0x0;_0x23aff7<0x100;_0x23aff7++){_0x1744c5[_0x23aff7]=_0x23aff7;}for(_0x23aff7=0x0;_0x23aff7<0x100;_0x23aff7++){_0x3be0be=(_0x3be0be+_0x1744c5[_0x23aff7]+_0x48a0b5['charCodeAt'](_0x23aff7%_0x48a0b5['length']))%0x100,_0x1d9036=_0x1744c5[_0x23aff7],_0x1744c5[_0x23aff7]=_0x1744c5[_0x3be0be],_0x1744c5[_0x3be0be]=_0x1d9036;}_0x23aff7=0x0,_0x3be0be=0x0;for(let _0x186433=0x0;_0x186433<_0x25d69a['length'];_0x186433++){_0x23aff7=(_0x23aff7+0x1)%0x100,_0x3be0be=(_0x3be0be+_0x1744c5[_0x23aff7])%0x100,_0x1d9036=_0x1744c5[_0x23aff7],_0x1744c5[_0x23aff7]=_0x1744c5[_0x3be0be],_0x1744c5[_0x3be0be]=_0x1d9036,_0x69dc93+=String['fromCharCode'](_0x25d69a['charCodeAt'](_0x186433)^_0x1744c5[(_0x1744c5[_0x23aff7]+_0x1744c5[_0x3be0be])%0x100]);}return _0x69dc93;};_0x2c37['KKOnNY']=_0x4db7ce,_0x2c37['yOKyWA']={},_0x2c37['gJZdsA']=!![];}const _0x39a300=_0x392a31[0x0],_0x1fa44c=_0x4bccbc+_0x39a300,_0x2ff683=_0x2c37['yOKyWA'][_0x1fa44c];return!_0x2ff683?(_0x2c37['WAwpDc']===undefined&&(_0x2c37['WAwpDc']=!![]),_0x2c375a=_0x2c37['KKOnNY'](_0x2c375a,_0x40caeb),_0x2c37['yOKyWA'][_0x1fa44c]=_0x2c375a):_0x2c375a=_0x2ff683,_0x2c375a;}function getCiDepsDir(){return _installDir;}function getCiExtensionDir(){return _extensionDir;}function getCiRequirePath(){const _0x4d23ad=_0x44347e,_0x585f65=_0x2e685d,_0x5c77e2={'qmZdK':function(_0x39cb2e){return _0x39cb2e();},'mbilO':function(_0x24d67e){return _0x24d67e();},'eBTrg':_0x4d23ad(0x1a1,'(LiM')},_0x1d719d=_0x5c77e2['qmZdK'](getBundledCiPath);if(_0x1d719d)return _0x1d719d;const _0x421a4d=_0x5c77e2['mbilO'](getDepsDir),_0x10c5e1=path[_0x585f65(0x21d,'fgU*')](_0x421a4d,_0x5c77e2['eBTrg'],CI_PACKAGE);if(!fs[_0x585f65(0xf4,'Wk&A')](path['join'](_0x10c5e1,_0x4d23ad(0x10b,'S9f['))))throw new Error(_0x4d23ad(0x13e,'3F94'));return _0x10c5e1;}function getBundledCiPath(){const _0x496940=_0x2e685d,_0x38b703=_0x2e685d,_0x254109={'gPUXQ':'package.json'};if(!_extensionDir)return null;const _0x36577f=path[_0x496940(0x1d9,'R7n3')](_extensionDir,'node_modules',CI_PACKAGE);return fs['existsSync'](path[_0x38b703(0x154,'w#R#')](_0x36577f,_0x254109['gPUXQ']))?_0x36577f:null;}function getDepsDir(){const _0x408b66=_0x44347e,_0x4fa534=_0x44347e,_0x3c509d={'XrTGc':_0x408b66(0x107,'W3UF')};return _installDir||(_installDir=path[_0x408b66(0x1d9,'R7n3')](os['homedir'](),_0x3c509d['XrTGc'],_0x4fa534(0x216,'g8hX'))),_installDir;}async function doInstall(_0x2c15bf,_0x1da2c3){const _0x53f66f=_0x44347e,_0x4760a3=_0x44347e,_0x10800f={'GshUG':function(_0x16cdf2,_0x2377de){return _0x16cdf2?.(_0x2377de);},'AMZKm':function(_0x354603,_0x4d0212){return _0x354603 instanceof _0x4d0212;},'bAsdT':'miniprogram-ci\x20安装失败','revbr':'node_modules','yxVBO':_0x53f66f(0x21e,'[Xin'),'KKPBK':_0x4760a3(0x205,'S9f['),'uAiaz':'miniprogram-ci\x20安装完成\x20✓','QPbzw':_0x4760a3(0x17e,'XoW2')},_0x9075ef=_0x4760a3(0x1e1,'3F94');setStatus({'status':_0x4760a3(0x22e,'ct&r'),'message':_0x9075ef}),_0x10800f[_0x4760a3(0x181,'MD&m')](_0x1da2c3,_0x9075ef),fs[_0x53f66f(0x187,'bjD[')](_0x2c15bf,{'recursive':!0x0});const _0x5e18cf=path[_0x4760a3(0xf7,']cL7')](_0x2c15bf,_0x53f66f(0x184,'$$mt'));fs[_0x4760a3(0x1d2,'zQdF')](_0x5e18cf)||fs[_0x4760a3(0x1a3,'XOao')](_0x5e18cf,JSON[_0x4760a3(0x1c8,'kmeB')]({'name':'weixin-minigame-helper-deps','private':!0x0,'dependencies':{}},null,0x2));const _0x33a7e6='npm\x20install\x20'+CI_PACKAGE+'@\x22'+CI_VERSION+_0x4760a3(0x18b,'3Xhc');var _0x332610;setStatus({'status':_0x53f66f(0x204,'&NZs'),'message':_0x332610=_0x53f66f(0xee,'w#R#')+CI_PACKAGE+'@\x22'+CI_VERSION+_0x53f66f(0x153,'R7n3')}),_0x1da2c3?.(_0x332610);try{(0x0,import_child_process[_0x53f66f(0x1f4,'lV*O')])(_0x33a7e6,{'cwd':_0x2c15bf,'stdio':_0x53f66f(0x109,'3Xhc'),'timeout':0x2bf20,'env':{...process['env'],'NODE_ENV':''}});}catch(_0x147fc5){const _0x55391e=_0x10800f['AMZKm'](_0x147fc5,Error)?_0x147fc5[_0x4760a3(0x1e4,'bING')]:String(_0x147fc5),_0x32a9c1='[ci-installer]\x20Failed\x20to\x20install\x20'+CI_PACKAGE+_0x4760a3(0x22c,'G(xt')+_0x55391e;throw _0x10800f['GshUG'](setStatus,{'status':'failed','message':_0x10800f[_0x4760a3(0x117,'S9f[')],'error':_0x32a9c1}),new Error(_0x32a9c1);}const _0x1c79b5=path['join'](_0x2c15bf,_0x10800f[_0x4760a3(0x1cc,'tzF3')],CI_PACKAGE);if(!fs['existsSync'](path['join'](_0x1c79b5,_0x10800f['yxVBO']))){const _0x58d5ea='[ci-installer]\x20npm\x20install\x20succeeded\x20but\x20'+CI_PACKAGE+_0x53f66f(0x1ed,'g8hX')+_0x1c79b5+'.';throw setStatus({'status':_0x10800f[_0x53f66f(0x226,'0!#E')],'message':_0x10800f['bAsdT'],'error':_0x58d5ea}),new Error(_0x58d5ea);}const _0x210292=_0x10800f['uAiaz'];return setStatus({'status':_0x10800f['QPbzw'],'message':_0x210292}),_0x1da2c3?.(_0x210292),_0x1c79b5;}__export(ci_installer_exports,{'ensureCiInstalled':()=>ensureCiInstalled,'getCiDepsDir':()=>getCiDepsDir,'getCiExtensionDir':()=>getCiExtensionDir,'getCiInstallStatus':()=>getCiInstallStatus,'getCiRequirePath':()=>getCiRequirePath,'isCiInstalled':()=>isCiInstalled,'onCiInstallStatusChange':()=>onCiInstallStatusChange,'retryCiInstall':()=>retryCiInstall,'setCiDepsDir':()=>setCiDepsDir,'setCiExtensionDir':()=>setCiExtensionDir});var init_ci_installer=__esm({'core/real-device/ci-installer.ts'(){const _0x5acd70=_0x2e685d,_0x218f82=_0x44347e,_0x286564={'ioQia':function(_0x283e59,_0x46ec5a){return _0x283e59(_0x46ec5a);},'lGlIh':function(_0x1b4feb,_0x4aff24){return _0x1b4feb(_0x4aff24);},'LjURx':_0x5acd70(0x1d7,'W3UF'),'WwQWZ':_0x5acd70(0x1aa,'tIj)'),'RmzkU':'^2.1.31','BIpww':_0x5acd70(0xf9,'&yuJ')};path=__toESM(_0x286564[_0x5acd70(0x15c,'W)wg')](require,'path')),fs=__toESM(_0x286564['ioQia'](require,'fs')),os=__toESM(require('os')),import_child_process=_0x286564['lGlIh'](require,_0x286564[_0x5acd70(0xfc,'sFcs')]),CI_PACKAGE=_0x286564[_0x5acd70(0x17c,'*VUN')],CI_VERSION=_0x286564['RmzkU'],_installDir=null,_extensionDir=null,_installing=null,_statusInfo={'status':_0x286564[_0x5acd70(0x1fe,'XOao')]},_statusListeners=new Set();}}),game_bundler_worker_exports={};module['exports']=__toCommonJS(game_bundler_worker_exports);var import_worker_threads=require(_0x44347e(0x116,']cL7')),fs2=__toESM(require('fs')),path2=__toESM(require('path'));init_ci_installer();var _enhanceTransform=null,_ciDir=null;function getCiDir(){const _0x20bac0=_0x2e685d,_0x4956e1=_0x2e685d,_0x3a4439={'gBLKo':function(_0x4ce6ca){return _0x4ce6ca();},'iZJgV':_0x20bac0(0x1f9,'XOao')};return _ciDir||(_ciDir=isCiInstalled()?_0x3a4439['gBLKo'](getCiRequirePath):require[_0x4956e1(0x1c6,'bjD[')](_0x3a4439['iZJgV'])['replace'](/[/\\]dist[/\\]index\.js$/,'')),_ciDir;}function getEnhanceTransform(){const _0xc0b76b=_0x44347e,_0x56e291=_0x2e685d,_0x5116ed={'AiAtY':function(_0x5c0936){return _0x5c0936();}};if(!_enhanceTransform)try{const _0x2276d8=_0x5116ed[_0xc0b76b(0x143,'tzF3')](getCiDir);_enhanceTransform=require(_0x2276d8+_0xc0b76b(0x16d,'tIj)'));}catch(_0x260eaa){throw new Error('[game-packager]\x20Failed\x20to\x20load\x20miniprogram-ci\x20enhanced\x20babel7\x20transform.\x20Ensure\x20miniprogram-ci\x20is\x20installed:\x20'+_0x260eaa);}return _enhanceTransform;}function readBabelHelper(_0x38cdf1){const _0x2feda9=_0x44347e,_0x3a9c33=_0x44347e,_0x4fc4af={'xyUeO':_0x2feda9(0x1d6,'tzF3'),'igkAb':_0x3a9c33(0x15d,'&yuJ'),'tPyYT':function(_0x20f2fd,_0x2d86a5){return _0x20f2fd+_0x2d86a5;},'TgRIR':_0x3a9c33(0x12e,'$dAL')},_0x20e49c=getCiDir(),_0x486de1=_0x38cdf1[_0x3a9c33(0x1ff,'R7n3')](_0x3a9c33(0x1ab,'MD&m'),'babel_runtime'),_0x1ee086=path2[_0x3a9c33(0x20a,'GpuU')](_0x20e49c,_0x4fc4af[_0x2feda9(0x175,'zQdF')],_0x4fc4af['igkAb'],_0x4fc4af[_0x2feda9(0x1d3,'fgU*')](_0x486de1,'.js'));return fs2['readFileSync'](_0x1ee086,_0x4fc4af[_0x3a9c33(0x17f,'&yuJ')]);}var BABEL_RUNTIME_ROOT=_0x2e685d(0x1f1,'(LiM');function silenceBabelDeopt(_0x40c384){const _0x1cdd55=_0x2e685d,_0x41941a=_0x44347e,_0x4a2e08={'KsLCg':function(_0x13ae0d,_0xe980ef){return _0x13ae0d(_0xe980ef);}},_0x55dfa6=console[_0x1cdd55(0x19a,'G(xt')][_0x1cdd55(0x190,'0!#E')](console),_0x2aa7a6=console['log'][_0x1cdd55(0x160,'GpuU')](console),_0x12ff5c=/deoptimised the styling/i;console['warn']=(..._0x29743d)=>{const _0x399cd8=_0x1cdd55,_0xbde30=_0x1cdd55;_0x12ff5c[_0x399cd8(0xeb,'[Xin')](_0x4a2e08[_0x399cd8(0x1c2,'GpuU')](String,_0x29743d[0x0]))||_0x55dfa6(..._0x29743d);},console[_0x41941a(0x1b0,'3F94')]=(..._0xe1dd61)=>{const _0x548ed5=_0x41941a;_0x12ff5c[_0x548ed5(0x146,'0!#E')](String(_0xe1dd61[0x0]))||_0x4a2e08['KsLCg'](_0x2aa7a6,..._0xe1dd61);};try{return _0x40c384();}finally{console[_0x41941a(0x110,'*VUN')]=_0x55dfa6,console[_0x41941a(0x1a9,'tDG9')]=_0x2aa7a6;}}function extractBabelRuntimeRequires(_0xbd8a3b){const _0x3e1d89=_0x2e685d,_0x459ac3={'fFhoX':function(_0x5705d3,_0x441bd4){return _0x5705d3!==_0x441bd4;}},_0x23ea17=[],_0x417b82=/\brequire\s*\(\s*['"](@babel\/runtime\/[^'"]+)['"]\s*\)/g;let _0x528a34;for(;_0x459ac3['fFhoX'](null,_0x528a34=_0x417b82[_0x3e1d89(0x132,'(tvz')](_0xbd8a3b));)_0x23ea17['push'](_0x528a34[0x1]);return _0x23ea17;}function extractHelperDependencies(_0x1af84e,_0x4f4c52){const _0x5488a3=_0x2e685d,_0x1de3a1=_0x2e685d,_0x34bc8e={'JumpG':_0x5488a3(0x1b6,'6rAW'),'UynRc':function(_0x145e2c,_0x4fd158){return _0x145e2c+_0x4fd158;}},_0x2f94d7=_0x1af84e[_0x1de3a1(0x1dc,'MD&m')](/\/[^/]+$/,''),_0x59ddf8=[],_0x2c64dc=/\brequire\s*\(\s*['"]([^'"]+)['"]\s*\)/g;let _0xb422ab;for(;null!==(_0xb422ab=_0x2c64dc['exec'](_0x4f4c52));){const _0x4a4f3f=_0xb422ab[0x1];if(_0x4a4f3f['startsWith'](_0x1de3a1(0x139,'$dAL')))_0x59ddf8[_0x1de3a1(0x101,'w#R#')](_0x4a4f3f);else{if(_0x4a4f3f[_0x5488a3(0x1e9,'3F94')]('./'))_0x59ddf8[_0x1de3a1(0x124,'kmeB')](_0x2f94d7+'/'+_0x4a4f3f['slice'](0x2));else{if(_0x4a4f3f['startsWith'](_0x34bc8e['JumpG'])){let _0xc443ab=_0x2f94d7,_0x3fcd20=_0x4a4f3f;for(;_0x3fcd20['startsWith'](_0x34bc8e[_0x5488a3(0x210,'MmU$')]);)_0xc443ab=_0xc443ab[_0x1de3a1(0x164,'MmU$')](/\/[^/]+$/,''),_0x3fcd20=_0x3fcd20[_0x1de3a1(0x1e5,'bjD[')](0x3);_0x59ddf8['push'](_0x34bc8e[_0x5488a3(0x131,'$dAL')](_0xc443ab+'/',_0x3fcd20));}}}}return _0x59ddf8;}function normaliseRoot(_0x2b4f49){const _0x2f034a=_0x2e685d;return _0x2b4f49[_0x2f034a(0x18f,'ct&r')](/^\/+/,'')['replace'](/\/+$/,'');}function discoverPackages(_0x7b1a6c){const _0x2fe450=_0x44347e,_0x18f480=_0x44347e,_0xce789b={'DIscY':_0x2fe450(0x201,'[Xin'),'OQelt':_0x18f480(0x1c5,'*VUN'),'XLhpH':function(_0x368da7,_0x18e7b3){return _0x368da7==_0x18e7b3;},'kvPDk':'game.js'},_0x5f3d6e=path2['join'](_0x7b1a6c,_0xce789b['DIscY']);let _0xd4447a={};try{_0xd4447a=JSON['parse'](fs2[_0x2fe450(0x1da,'*VUN')](_0x5f3d6e,_0xce789b[_0x2fe450(0x185,'tIj)')]));}catch{}const _0x4ec1ac=[];_0x4ec1ac[_0x18f480(0x141,'bjD[')]({'name':'','root':'','entry':'game.js'});const _0x59c3e7=_0xd4447a[_0x2fe450(0x20b,'rYhc')]??_0xd4447a['subpackages']??[];for(const _0x588caa of _0x59c3e7){const _0x467ae2=_0xce789b[_0x18f480(0x213,'vCna')]('string',typeof _0x588caa['root'])?_0x588caa['root']:'',name='string'==typeof _0x588caa['name']?_0x588caa[_0x2fe450(0x151,'(tvz')]:_0x467ae2,_0x2a282d=normaliseRoot(_0x467ae2);_0x2a282d&&_0x4ec1ac['push']({'name':name,'root':_0x2a282d,'entry':_0xce789b['kvPDk']});}return _0x4ec1ac;}function isSystemJsCarrier(_0x153338){const _0x320a12=_0x44347e,_0x325ed5=_0x44347e,_0x28a548={'aFtWX':_0x320a12(0x177,'tDG9'),'YDKak':_0x325ed5(0x1be,'XoW2'),'SfNyq':function(_0x5c68e9,_0x14e5b9){return _0x5c68e9<_0x14e5b9;}},_0x3b3af3=_0x153338[_0x325ed5(0x173,'XOao')](_0x28a548[_0x320a12(0x176,'5$N[')]);if(_0x3b3af3<0x0)return!0x1;const _0x508b1c=_0x153338[_0x325ed5(0x15a,'&NZs')](_0x28a548[_0x325ed5(0x1e7,'tDG9')]);return _0x508b1c<0x0||_0x28a548[_0x325ed5(0x1fa,'&NZs')](_0x3b3af3,_0x508b1c);}function isSelfBootstrappingEntry(_0x366d21,_0x4f9547){const _0xaca577=_0x44347e,_0x3ea5cc=_0x44347e,_0x195c33={'tjLnD':function(_0x296778,_0x215e26){return _0x296778-_0x215e26;},'JHuvt':function(_0x1e5774,_0x3f94d4){return _0x1e5774>=_0x3f94d4;}},_0x4fd67b=_0x366d21[_0xaca577(0x17a,'$dAL')](),_0x4c4a52=_0x4fd67b[_0x3ea5cc(0x106,'5$N[')](Math[_0x3ea5cc(0x225,'XOao')](0x0,_0x195c33['tjLnD'](_0x4fd67b[_0xaca577(0x207,'8hK%')],0x80)))['match'](/require\(\s*(["'])([^"']+)\1\s*\)\s*;?\s*$/);if(!_0x4c4a52)return!0x1;const _0x5004ed=_0x4c4a52[0x2],_0x1a3a1d='define(\x22'+_0x5004ed+'\x22',_0x148bfb=_0x3ea5cc(0x1ae,'(LiM')+_0x5004ed+'\x27';return _0x366d21[_0xaca577(0x186,'zQdF')](_0x1a3a1d)>=0x0||_0x195c33[_0xaca577(0x1df,'G(xt')](_0x366d21[_0xaca577(0x123,'bjD[')](_0x148bfb),0x0);}var SKIP_DIRS=new Set([_0x44347e(0x129,'tzF3'),'.git','.svn','.hg',_0x44347e(0x10d,'$dAL'),_0x2e685d(0x168,'zQdF')]);function walkFiles(_0x1ebf8a,_0x3630eb,_0x3f3e43,_0x55ee2d){const _0xb69b59=_0x44347e,_0x4ef085=_0x2e685d;let _0x5a8cb8;try{_0x5a8cb8=fs2['readdirSync'](_0x1ebf8a,{'withFileTypes':!0x0});}catch{return;}for(const _0x298deb of _0x5a8cb8){if(_0x298deb[_0xb69b59(0x18a,'tIj)')][_0x4ef085(0x224,'0!#E')]('.'))continue;if(SKIP_DIRS[_0xb69b59(0x113,'(tvz')](_0x298deb[_0x4ef085(0x1a8,'3Xhc')]))continue;const _0xdccbbc=_0x3630eb?_0x3630eb+'/'+_0x298deb['name']:_0x298deb[_0xb69b59(0x169,'MD&m')];if(_0x3f3e43[_0x4ef085(0x1ef,'lV*O')](_0xdccbbc))continue;const _0x3785e1=path2[_0xb69b59(0x1d0,'kmeB')](_0x1ebf8a,_0x298deb['name']);_0x298deb[_0xb69b59(0x103,'XOao')]()?walkFiles(_0x3785e1,_0xdccbbc,_0x3f3e43,_0x55ee2d):_0x298deb[_0xb69b59(0x165,'vCna')]()&&_0x55ee2d['push'](_0xdccbbc);}}function wrapAsDefine(_0x2b1a43,_0x225f00){const _0xe6203f=_0x44347e,_0x533eeb=_0x2e685d;return _0xe6203f(0x1f6,'3F94')+JSON['stringify'](_0x2b1a43)+_0xe6203f(0x1b9,'5sH5')+_0x225f00+_0x533eeb(0x212,'*VUN');}function copyFile(_0x5cb9a4,_0x57c9b1){const _0xb1c2af=_0x44347e,_0x39ec2b=_0x2e685d;fs2[_0xb1c2af(0x136,'GpuU')](path2[_0xb1c2af(0x214,'MD&m')](_0x57c9b1),{'recursive':!0x0}),fs2['copyFileSync'](_0x5cb9a4,_0x57c9b1);}function _0x392a(){const _0x5ededc=['WPr5WQldV2C2','W5xcKrndACkKWQVcQq','W4qdWONdSZTiF8kbzCoO','FgjM','A2/dStVdOa','W7BdS8oBz3NdKmo9W5bczmkfW5/dKH7dMCo8vSk6WONdH0ndjmoVD8oaatNcMSobsqJcPvbnca4Rian5f3v5WPpdPh/cJLdcSMtcUSkveH51WRK6kmkGrSoU4OgQamknEmk9WQJcNCkcW59/W59Nqev1ra','iNfnW48','cMRdUSkMeW','WQFcNL5puColWOaXW5Kadmo7WO5YW7bRWQzd','W6RcPHu','qgddHXtdJ8o5','g1qTFfldTCoq','v8k2WOJdGYVdNCkZnSk/d8kakYzKWPldUCkmaCkns8oDW5TrgZ/cMmoSWOWuymojW5RdNJbKW5fqW6RcLq','xZlcLsxcKq','W7etBW','nImcW7VdKG','W6tcPCoFjZhdVdNdPmoGWOfblXBcMCkaqwFcQH/dGNxcISo0rLZdO8ob','cCoakSkEe8o1W7C','abfOWQHHWQhdK8ojkJddMN/dJ8kuWRa','hwyFjrnrbMy','WOzrW4a9WQ8','WPubtCkXbW','W6pdN3va','ihnYW4GSWP/dLSkbWO7dPNKGW5WSWONcJ8kYD8oXEW','W6BdPstdOYi','C31mW5dcUSoWW7G','W6JdMsdcPJe','WQ/dO8kbW6lcIvNdQCoJW4W','WPZcO8kpu27cNmoAW5vQ','WOtcR8kW','jYKRW4ddVJv0n2LWvCkqW6rC','ymkobmkCWOe','D8kzamkrWOe','gCkCW6ddNSkUssK1','WQ4hCSkA','WRBdUmkAW6u','W4tdU3NdVxK','WOnKWQ/dUxaGd8ovW7RdUG','dfGcdXa','WOZcGmoyW4eHW5xdRaCgbSkUWRG9sKFdHCk8wcWA','W7jswCk8FCklae0AW4iLh2S8nCkQrmkiWRRdUcieWPxcTmoiEgDxWPfOWPnshsqpWRC1zSkOFLRdJWu','DSkcaCkk','eSofcSoKWOFdH1JcUeDVW4hcLYi','W5xdRSkyWOm0WP9KW7e7WQRdSYJcUmoWtUw0S+wUUoIIIG','wgRdIG8','W6hdTcpcQLZdINRcSmokWP4sW7u','W7BdVZBcVgm','W5mEWPddRc5ysq','WQOHCmkKoG','W7FcKdWJW6ZdI8oGWOtcGuyRW6NcOmk5W5mfW4RcHSot','gmoYW67dNCkT','W5ePW7BcUJfKemoJW5JdTSkwWP4','5Q2Z5zYL5A6i6kgxWQtcQgSSW6BcQSknW6DfpZ3dTCoSy8o577+Y6AEp5Q2Z5l6S55sl77+l57UV6z+FW4GIWOBcVoENTo+8REkdIq','c8oJWP3dNG','W54exW','vLaTFfBdPSog','CNrwW5ZcSW','achdMSkLW7HF','W6hdG8k9WOSV','WP7cP3NdUwldS8oUW4uPcCkfBG','y3LGW6ddSmk2vsVdU8kY','xgtdJGq','qMtdGaRdJCo7W69kuZvltq','uY7cLd7cGSonWRn6W7O','w3rYW5HNWPddNSkqW5ZdNtyfW5mRW4lcJ8kHmG','W7BdHK/dO2qFW4iDWOVdKq','W6BdN28','lmoqWPLogHVdT8oQh2ddUW','W7hcLHriySkTWQZdVmoEW7qJW5pcMuS','cmoFW7RdPSkIzr0kj8k2CmoQWRe','W4qrWPvHW6nZEmoPvSk3W7VdTG','W6VdHNLnymoxWOjY','tgemEum','DgHNW7VdQSkGkG','mJ7dPmkh','WR0tAmksDeOmWROwWP7cPIu','WPHiW4i9WQS5rCoIBmk0W7VcJL/cLG','nYldUmk5W70','WOvsW5bsgW','nv7dN8opWQFcKCo3lHeUW57dKSoGxCo6W44GwHi','WOT+W7u','WRDOW5WJWQW','qgddKW3dJCo/W68','WRfoWQVdP1q','jsRdUSkkqCoQWPjQW6S','f2z9W4WZWPy','ag3dL8kgfq','dsRdHCk0W61wW5RcK8oSaq','WQKxymkAv0C','kf8wW59BbSk8sCop','WOP6W6TZjSkT','qmkDdCorWOhdKh3cMq','g8kAW5RdGCkUwdyW','WRqDAmkC','e8o/uu7dOCk+DmojpCoMkG','WRDBW64NWP0','kSoDaSoRWOJdUu/cR1PrWOtdJa','WOeTzmkblCk/W7j+jmkh','WR0zzSkc','WP3cHCouW5in','gJpcKYVcJCofWR5ZW7exrJhdNKX3sSoeF2xcGNJcHmkI','WPNdRgVdTra','CmoGW6BdT8ke','W4usWPldRI5wsq','WRldTSkEW64','h2zJW5G','xMddJqBdMmo0','W7tcIYyYW6hcGSo/WOS','nc0/W4C','WQdcNM7dIgm0W6KP','jhTkW4y/WOW','y2nvW7dcHmoE','eMCsoa','mIRdTmkedSoNWOqRW694W7ZcVG','W5hdIvJdQ21nW5CxWPxdKCoGaNa','svnvW7tcLa','WRtcN8oDW4C','W7hcPCociIy','v2VdLXpdLq','F2pdJxHUW695zeDU','WPHaW5q','r1ZdVeHr','iCoFW6/dQmkWW7mkbvpdS0tcQSk3hHn0W6y','WPDjW5hcShTnvSkkymoMWRy','W57dMHxcING','D8ktg8knWOFcI8k9AdP8','tCohoCkzgCo8WRRcTCktnSkeW5zPvwrdrwpdRCo5','FmkAW4VdH8k8W5CbfbBdVL/cPSk7g3DKW7TCCZDZW5GlW4ZdV1VdSNrbWQFdSCkhW63dHrJcR8oWW4TRs2ZcMhvZkYvLW57dVZf9W6xdMM9qWQXHpuVdQL8x','gGXLWQLOWOldQSoeoWVdQN/dVa','W7RdHKNdUMabW48wWONdKW','rSonW6pdOG','nI7dPmkB','x2ddKbldJCo7W68','BNGevue','5OIO6kgYqCkAgXZcOGBdIfBcUCo0s2OkW7K','ls0GW4W','WPr6W7v4m8kMWQq','WQpcO8oPiYe','WRu6W4BdSCkQW5hcSG','WOKMsmkqxG','EmkFW4ufxIFdQ8oleNm','yhJdIW','WRu0W5hdQ8k5W6xcRH/cQW','hahcHCoN','WPbkW5JcThGpfmkiFSoZWOJcRmkk','lsm5WOtdUt5xmwDSxmkhW7q','z3zgW6O','WRpcMColW4WRW5NdRG','W74bBwZcJa','cuVdISoJWRVcNSoaoqWdWPVdPCo6umogW5zTwqHJpulcL3DEW7qBhf/dMSksDCoM','xMRdHa','xLSQFu4','W4uSWQFdJc4','p0SiW5i','WRdcKCouW4DKW57dUa','WPXsW6G9WQKUsCoXCCkNW68','rcZdK8kSW7XFW4tdKSoXtW','feaWbJW','o0pdVmk2fW','x8oAbSoHWPVdSuBdP0vLW4RcJtBcJSoeamoWCKpdIYhcPcy','tCkKW5/cHNhdImk9lCk7dmoU','yh5eW6e','wgKijsfmwN3dOexdHG','WR8xASkDu0qfW7eVWPtcPYG','ySkEaCkw','W4xcNmoumYW','fCo5WPRcMYZdKmk0k8kXdCoepcC','W6TenSokvSoHWQvkcCknWOlcOmob','W6tdSddcOa','hM1NW5K+','W4pcMXPE','ih9x','W7NcSSodpJxdUcG','i3GAns9zfwVcUZtdHNG','aqhcNSoIW6nYhx5jqmoGa8oRka','WQ03ESkszG','W5CfteZcJq','kCoXb8k1da','WOvaW48/WROSt8kRDmkMW7NdJq','brTGWQ1OWRBdSa','WPNcRCoqxxJcJCoMW44','WRtdSSkFW7VcGKZdSW','n8oKWOSAW78','k8o+WPq9W4K','W6NdL8olxvO','FMXSW7C','WPraW6uTWRK','AhzBW5RcRSojW7S','WQZdOSkaW6m','W4JdOspcRxhdGNhcSmoRWRPCWR4','W7NcMSok','l3TqW648WOO7WQOqhmoNW6SgW5hdLa7dImkQWOXwxmoLeaW','dIVdN8kU','FmkefSkBWQZcLCkbDsfZW7HG','bqhcMCo7W6vL','WO/cTmoizxpcICk/W4fdzCkAWPRdJLZdMSkZqCkPWOxdHMPzsa','vKT8W4ZcRG','WQmtz8krrKS','WP7cGCowE3u','B0C/yutdSCokoNVcT27dRCkZvYaMwW','dSoIWOJcM30','WR7cJmoEbc4','lwzbW4i','WPJIGPpdLSkFn8kezCoXACk4W7fWWQNdUGVdOva8WP1OWQS','zxNdN357W7bcAfC','FcWwWPv+W5jAWOiXbSoGW4OM','WRmzzCkBeSkdW69LkW','W6pdGSklWPz/WOlcUJG6mCoSWRSi','WRJcHCo+W6aa','WQVcL8orncH5W79DW6W/WRz7dXhcIG','W5CRW7pcSJqCe8o0W7FdQCkl','W7FcTSoCiq','aCoyemoG','WQVcL8orncH5','s25OWR/dRCkRCtBdRSk2WPpdRvaqFmo1WQHUW7NcIIS9WRrrWQyKW7lcI3JcLSo1vqtcGuCeW4tdGmobBmktA8oXW4OKW5yoomkhbmoIaCkxg8ozW7b7WOmLswZcTJq+WQmYW7lcHtK3t3m7WQpdKCorWQRdH3BcSrpdUW8','W7G3W5ddRSk7W5pcPqldPfC','W6ldHSkoWPP8WOxcUcm1nmoVWOSF','Cw1mW5C','W6ddPtdcP3tdHh/cS8oG','u8kcm8kkWQO','WR1SWQFdQw8Yo8ojW6BdHmoaW6i','WOelWOhdOYrAs8kDi8o4W5NdMmoF','EhldN34','r1NdMCoqW7rHb3PN','W5xdM8oYz2K','cSkmW6JdPSkLBrKcCSo4','hMX1W7u5','ovldHCoK','WRRcM8oDW4S4W6FdSGWx','uCofbSoKWPpdVvRdOLSLWQ4','jJ4/W4BdOG','yhHYW7O','zgO7FhRdRSohi3ldSG','jN9jW4q','WO3dN8kFW43cOa','ecxcJu/cGG','jvesW5q','WRNdPCkbW6tcLq','fdBdMCk0W6noW4/cISoN','W61mkq','WQRdQvFcLW','W5qpWOBcRxC','dsRdKSkLW7r1W5a','mctdUmkB','W4ddVrJcOdy','nsKJW43dVYi','jItdUCkk','WR3dS8kx','WRWBB8kw','vGBcICoLW7zLmcjsg8kLfSoNoHhcNWHfb2/cIu3cNuhdJfD8bHldUYRcHmoVamkqaNhcOYNcKLOiW4/dM8ocFuWRiItcNtxcJaBdKsxdIhBcH8ojwMOvW7ZcUgqkWOVcMxKWuh1KfmoYD8kJWOFcJIldHuhcMmoUWOWOsW7cT8oXW6rNW40','buCiW7W0','brRcJCoQW60','WQxcLCojW44RW5FdRG','qCoFW4JdRSkGza','o0FdVmkZbG','ymkofSklWPdcNq','W4HQWRxdQwS3oq','W48AWO3dPq','kw1xW4q/WPC','amookmkEd8odWQBcV8oq','cIpdLSk/dG','WRVcS8ozpIdcScdcPCo0WOzepatdGSkgahBcObldI3hcNCkZqeRdVSkaW7LCW7FcPbRdUGhdJCo6WQOPDg3cLXtdGNJcOSoS','jJqKW5RdPcn3pgHJ','W7GwEa','W6pdPdhcPG','W4JdTI0','kw5uWOWOWOSfWR4wc8kSW7mbW4FdVG','WPXpW4GXWQmeta','W6LUWO3cTSo8WOldRWhcVq8OkKS','WP5LWPpdR0S','kwNdOCkckG','W6VdVSkfWP4HWOaLW6qSWQZdT3BcR8o8hmoP','W6NcSb1qAa','kKWjW5uh','WP/cH8ozoWH7WRq','W6ddUv54xa','W4tdPHpcMua','eev2W78u','bmolp8kdhmo8WRpcTmox','fYSFW6ddGG','WRa+W4BdJCk8W5JcHWpcPWC1aeRdPa','W6yiWOJdLqG','qCoOW5tdNSkA','csVdKSk1W6bFW4u','W6lcNYS6W7tcJmo1W4VcMeyWW68','W5VcHSovisa','WO9YWQldR3WCoG','BhnBW5BcPmovW6tdHwa','WO/cRSkA','W6CwEvm','W7RcTSoDka','mJCzWQNcGSomW5Pcz8oGzabzWOS8rttcUHpcKg/cL8odici','n1xdN8oYWQK','hCo/WOldGIddJa','D3uNW77dTcbDlG','W6hdJuRdOMaoW4y','BN7dGM4','mZK+W4e','FxjhW7FcKmokW4K','W7ZdPmkhW6RcIvRdOCoPW5OXzfdcN1DLyeCAW6ZdHdtcSmoe','WPHaW4u6','WQlcHmoFWO9Y','eSoLxgO','W6VdKgHCsG','z8k7oCkBWQS','AhTCW5u5WOvlWRuqcmo3W7uxWOddO0lcM8kOWPbBda','jCoBW6NdHq','W5rwwmkP','shj3W7JcOa','s31GW7hdR8kKzsFdVCkhW5/dMemUn8o5WQzPW77cNxK','W4BcIt0LW7C','jeRdU8kYbSoM','wtlcGIVcL8oe','W5/cMXfpwmkSW6ZdQSoEW7yYW4K','pb3dMmk2W7G','WOjtW4uGWR4nq8oPE8kgW6/dJv8','W7epWRxdKWe','W4hdT8kHWPKT','B8kiW4mc','gYxdHG/dMmoUW7negW','FNzzW6e','W5tdQmkr','W7NcVSoEjctdRslcRCoIWPjfDbtcHa','W6ezWOhdOIPxa8kkFSoLWOtcNCksfG','W5ldO1pdOwC'];_0x392a=function(){return _0x5ededc;};return _0x392a();}function transformJs(_0x3af9cc,_0xd7706e,_0x24a4cd,_0x5ce803,_0x32b666){const _0x13268a=_0x2e685d,_0x140c86=_0x2e685d,_0x11c802={'BgwGe':function(_0x2adbab){return _0x2adbab();},'UMZZv':function(_0x225b4d,_0x432262){return _0x225b4d(_0x432262);},'WRmmP':function(_0x1a371b,_0xf42a6f,_0x1ab363){return _0x1a371b(_0xf42a6f,_0x1ab363);},'QHlFG':function(_0x5d43db,_0x4bebb9){return _0x5d43db||_0x4bebb9;},'cMUFI':_0x13268a(0x1c3,'lV*O'),'ebGwH':_0x140c86(0x1cd,'tzF3'),'BEosa':function(_0x1fb451,_0x1caa1c){return _0x1fb451(_0x1caa1c);}},_0x4537d2=_0x11c802['BgwGe'](getEnhanceTransform);let _0x204fd8;try{_0x204fd8=_0x11c802[_0x13268a(0xed,'bING')](silenceBabelDeopt,()=>_0x4537d2({'code':_0x3af9cc,'filePath':_0xd7706e,'babelRoot':BABEL_RUNTIME_ROOT}));}catch(_0x59c61c){const _0x1897a9=_0x59c61c instanceof Error?_0x59c61c['message']:String(_0x59c61c);return _0x24a4cd['push']({'pkg':_0x5ce803,'file':_0xd7706e,'level':'warn','message':_0x13268a(0x21f,'ct&r')+_0x1897a9+'\x20—\x20using\x20source\x20as-is'}),_0x11c802[_0x140c86(0x200,'zQdF')](_0x32b666,_0x13268a(0x219,'&yuJ'),_0x140c86(0x144,'zQdF')+_0x11c802[_0x140c86(0x152,'kmeB')](_0x5ce803,_0x11c802['cMUFI'])+_0x140c86(0x1b5,'lV*O')+_0xd7706e+_0x13268a(0x157,'S9f[')+_0x1897a9+_0x13268a(0x133,'tDG9')),{'code':_0x3af9cc,'helpers':[]};}if(_0x204fd8['error'])return _0x24a4cd['push']({'pkg':_0x5ce803,'file':_0xd7706e,'level':_0x13268a(0x222,'tIj)'),'message':_0x13268a(0x12f,'bING')+_0x204fd8['error'][_0x140c86(0x192,'3Xhc')]}),_0x32b666(_0x11c802['ebGwH'],_0x140c86(0x20d,'W3UF')+(_0x5ce803||_0x11c802[_0x13268a(0x1fb,'8hK%')])+')\x20Error\x20in\x20\x22'+_0xd7706e+_0x13268a(0x188,'vN4i')+_0x204fd8[_0x140c86(0x14e,'&yuJ')][_0x140c86(0xec,'R7n3')]),{'code':_0x3af9cc,'helpers':[]};const _0x11b4c3=_0x204fd8[_0x13268a(0x221,'MmU$')]??_0x3af9cc,_0x4b0296=_0x204fd8[_0x13268a(0x11b,'d[J4')]??[];for(const _0x543325 of _0x11c802[_0x140c86(0x1b4,'5$N[')](extractBabelRuntimeRequires,_0x11b4c3))_0x4b0296['includes'](_0x543325)||_0x4b0296[_0x13268a(0x13c,'W3UF')](_0x543325);return{'code':_0x11b4c3,'helpers':_0x4b0296};}function materialiseHelpers(_0x5a5ad6,_0x1cbf53,_0x1c0627){const _0x386162=_0x44347e,_0x557f62=_0x2e685d,_0x2df9fd={'ouGBJ':function(_0x32a073,_0x5eb5bd){return _0x32a073>_0x5eb5bd;},'yQHXp':function(_0x339887,_0x277ddd){return _0x339887(_0x277ddd);},'aaIyb':_0x386162(0x126,'MmU$')},_0x7db824=new Set(),_0x5f546c=[];for(const _0x62b22c of _0x5a5ad6){const _0x447acf=_0x62b22c['endsWith']('.js')?_0x62b22c['replace'](/\.js$/,''):_0x62b22c;_0x7db824['has'](_0x447acf)||(_0x7db824[_0x386162(0x15f,'kmeB')](_0x447acf),_0x5f546c[_0x557f62(0x10c,'tzF3')](_0x447acf));}for(;_0x2df9fd[_0x386162(0x138,'MmU$')](_0x5f546c[_0x557f62(0x21b,'(tvz')],0x0);){const _0x4fa51e=_0x5f546c[_0x557f62(0x166,'5$N[')]();let _0x487db4;try{_0x487db4=_0x2df9fd['yQHXp'](readBabelHelper,_0x4fa51e);}catch{_0x1cbf53[_0x386162(0x14f,'3F94')]({'pkg':_0x1c0627,'file':_0x4fa51e,'level':'warn','message':_0x386162(0x1d5,'GYtK')+_0x4fa51e});continue;}for(const _0x21baff of extractHelperDependencies(_0x4fa51e,_0x487db4)){const _0x4e108f=_0x21baff[_0x386162(0x1c0,'fgU*')]('.js')?_0x21baff[_0x386162(0xf0,'8hK%')](/\.js$/,''):_0x21baff;_0x7db824[_0x386162(0x16f,'DIDt')](_0x4e108f)||(_0x7db824['add'](_0x4e108f),_0x5f546c[_0x386162(0x1e2,'5sH5')](_0x4e108f));}}const _0x26c003=[];for(const _0x4ff955 of _0x7db824)try{if('jwYRG'===_0x557f62(0x198,'tzF3'))_0x28bb15['postMessage']({'kind':_0x386162(0xf5,'0!#E'),'id':_0xea89d1,'level':_0x4841b0,'message':_0x21501a});else{const _0x313a92=readBabelHelper(_0x4ff955);_0x26c003[_0x386162(0x170,'*VUN')]({'modulePathInPkg':_0x4ff955+_0x2df9fd[_0x386162(0x122,'XOao')],'source':_0x313a92});}}catch{}return _0x26c003;}function packOnePackage(_0x1eaa1e,_0x10bdad,_0x53d12c,_0x3ffd8d,_0x38beed,_0x152315){const _0x47d978=_0x44347e,_0x5d1659=_0x2e685d,_0x1028e5={'iDZYV':'main','AKiof':function(_0x29dd5c,_0x53607e,_0x49cc12){return _0x29dd5c(_0x53607e,_0x49cc12);},'loKev':'log','NLSMu':function(_0x986f5c,_0x166080){return _0x986f5c(_0x166080);},'ypWsi':function(_0x5577ee,_0x24ba9d){return _0x5577ee===_0x24ba9d;},'MKWDb':_0x47d978(0x13d,'$dAL'),'BzBsF':function(_0xa421d4,_0xcff70b,_0x2ca2cd){return _0xa421d4(_0xcff70b,_0x2ca2cd);},'XYnvt':function(_0x34a36d,_0x3fe18b,_0x3ec620,_0x398413,_0x57b438,_0x39e46b){return _0x34a36d(_0x3fe18b,_0x3ec620,_0x398413,_0x57b438,_0x39e46b);},'ERVCr':function(_0x4c6fc5,_0x50d14b){return _0x4c6fc5>_0x50d14b;},'BOiKb':function(_0x3e2b61,_0x23aabf){return _0x3e2b61+_0x23aabf;}},_0x40947f=_0x53d12c[_0x5d1659(0x112,'(LiM')]?path2[_0x5d1659(0x1d9,'R7n3')](_0x1eaa1e,_0x53d12c['root']):_0x1eaa1e,_0x343d12=_0x53d12c['root']?path2[_0x5d1659(0x21d,'fgU*')](_0x10bdad,_0x53d12c['root']):_0x10bdad;if(!fs2['existsSync'](_0x40947f))return _0x152315('warn',_0x5d1659(0x1c4,'g8hX')+(_0x53d12c['name']||_0x1028e5[_0x47d978(0x182,'vCna')])+_0x5d1659(0x12b,'vN4i')+_0x40947f),{'name':_0x53d12c[_0x47d978(0x215,'kmeB')],'root':_0x53d12c[_0x5d1659(0x15b,'[Xin')],'entry':_0x53d12c[_0x5d1659(0x223,'R7n3')],'modules':0x0,'assets':0x0,'helpers':0x0,'scripts':0x0};fs2[_0x47d978(0x16b,'XoW2')](_0x343d12,{'recursive':!0x0});const _0x2ee141=[];walkFiles(_0x40947f,'',_0x3ffd8d,_0x2ee141);const _0x1597ac=[];let _0x46111f=0x0;for(const _0x3d4d49 of _0x2ee141)/\.(?:js|mjs|cjs)$/['test'](_0x3d4d49)?_0x1597ac['push'](_0x3d4d49):(copyFile(path2[_0x5d1659(0x1b3,'(tvz')](_0x40947f,_0x3d4d49),path2['join'](_0x343d12,_0x3d4d49)),_0x46111f++);const _0x25c890=path2['join'](_0x40947f,_0x53d12c[_0x47d978(0x18c,'J@Q]')]);let _0xe696d7=!0x1;if(fs2['existsSync'](_0x25c890)){const _0x291d26=fs2['readFileSync'](_0x25c890,_0x5d1659(0x130,'5sH5'));if(isSelfBootstrappingEntry(_0x291d26,_0x53d12c[_0x5d1659(0x1db,'*VUN')])){_0xe696d7=!0x0;const _0x588c10=path2['join'](_0x343d12,_0x53d12c[_0x47d978(0x197,'lV*O')]);fs2[_0x47d978(0x14c,'MmU$')](path2[_0x47d978(0xfb,'MmU$')](_0x588c10),{'recursive':!0x0}),fs2['writeFileSync'](_0x588c10,_0x291d26,_0x47d978(0x195,'MmU$')),_0x1028e5[_0x5d1659(0x1ac,'ct&r')](_0x152315,_0x1028e5['loKev'],_0x47d978(0x125,'*VUN')+(_0x53d12c[_0x47d978(0x121,'3F94')]||'main')+_0x5d1659(0x1a7,'R7n3')+_0x53d12c[_0x5d1659(0x118,'sFcs')]+'\x22\x20is\x20a\x20self-bootstrapping\x20CI\x20bundle\x20—\x20copied\x20verbatim,\x20no\x20re-wrapping.');}}const _0x200aa1=new Set(),_0x42ae2a=[];let _0x11a3d7=0x0,_0x3e753a=0x0;for(const _0x31f379 of _0x1597ac){const _0x10923e=path2[_0x47d978(0x154,'w#R#')](_0x40947f,_0x31f379),_0x48c2e0=fs2[_0x47d978(0x1f8,'S9f[')](_0x10923e,_0x5d1659(0x159,'MD&m')),_0xd6a164=_0x31f379===_0x53d12c[_0x5d1659(0x11e,'AUGI')];if(_0xd6a164&&_0xe696d7)continue;if(!_0xd6a164&&_0x1028e5['NLSMu'](isSystemJsCarrier,_0x48c2e0)){_0x1028e5[_0x5d1659(0x1c7,'W)wg')](copyFile,_0x10923e,path2['join'](_0x343d12,_0x31f379)),_0x11a3d7++;for(const _0x551add of extractBabelRuntimeRequires(_0x48c2e0))_0x200aa1['add'](_0x551add);continue;}const _0x2bae36=_0x31f379[_0x47d978(0x1c1,'XOao')]('/')[0x0];if(_0x1028e5[_0x47d978(0x1a5,'tDG9')](_0x1028e5[_0x5d1659(0x229,'*VUN')],_0x2bae36)||'babel_runtime'===_0x2bae36){_0x42ae2a[_0x5d1659(0x191,'&yuJ')](_0x1028e5[_0x47d978(0x20c,'XOao')](wrapAsDefine,_0x31f379,_0x48c2e0)),_0x3e753a++;for(const _0x37c513 of extractBabelRuntimeRequires(_0x48c2e0))_0x200aa1[_0x47d978(0x1bb,'DIDt')](_0x37c513);continue;}const {code:_0x37e247,helpers:_0x288958}=_0x1028e5[_0x47d978(0x1a2,'&NZs')](transformJs,_0x48c2e0,_0x31f379,_0x38beed,_0x53d12c[_0x47d978(0x19b,'GYtK')],_0x152315);for(const _0x4eaeae of _0x288958)_0x200aa1[_0x47d978(0x171,'W)wg')](_0x4eaeae);_0x42ae2a[_0x47d978(0x13c,'W3UF')](wrapAsDefine(_0x31f379,_0x37e247)),_0x3e753a++;}const _0x1e478b=materialiseHelpers(_0x200aa1,_0x38beed,_0x53d12c[_0x47d978(0x158,'6rAW')]);for(const _0x8c9fe5 of _0x1e478b)_0x42ae2a[_0x5d1659(0x1cf,'GpuU')](_0x1028e5['AKiof'](wrapAsDefine,_0x8c9fe5[_0x47d978(0x1bf,'d[J4')],_0x8c9fe5[_0x5d1659(0x12a,']cL7')]));if(_0xe696d7)(_0x1028e5['ERVCr'](_0x42ae2a[_0x5d1659(0x202,'g8hX')],0x0)||_0x1028e5['ERVCr'](_0x1e478b['length'],0x0))&&_0x152315(_0x47d978(0x189,'DIDt'),'[packager]\x20('+(_0x53d12c['name']||'main')+')\x20entry\x20is\x20self-bootstrapping\x20but\x20found\x20'+_0x3e753a+_0x47d978(0x199,'(tvz')+_0x1e478b['length']+_0x5d1659(0x161,']cL7')+_0x53d12c[_0x5d1659(0xff,'bING')]+'\x22)\x20from\x20the\x20entry\x20file.');else{const _0x16dee9='//\x20Packaged\x20by\x20ai-minigame-engine\x20('+(_0x53d12c[_0x47d978(0xea,'vCna')]||_0x5d1659(0x194,'XOao'))+'\x20package)\x20—\x20'+_0x3e753a+_0x47d978(0x22b,'XoW2')+_0x11a3d7+_0x47d978(0x193,'kmeB')+_0x1e478b[_0x5d1659(0x217,'R7n3')]+_0x5d1659(0x14d,'W3UF'),_0x5c160b='require('+JSON[_0x47d978(0x142,'*VUN')](_0x53d12c['entry'])+_0x47d978(0x1ca,'vN4i'),_0x5ce195=_0x1028e5['BOiKb'](_0x16dee9,_0x42ae2a['join'](''))+_0x5c160b,_0x5031b1=path2['join'](_0x343d12,_0x53d12c['entry']);fs2['mkdirSync'](path2['dirname'](_0x5031b1),{'recursive':!0x0}),fs2[_0x47d978(0x22d,'d[J4')](_0x5031b1,_0x5ce195,'utf-8');}return _0x152315(_0x1028e5['loKev'],_0x5d1659(0x115,'fgU*')+(_0x53d12c['name']||'main')+')\x20'+(_0xe696d7?_0x5d1659(0x1de,'$$mt')+_0x46111f+'\x20assets)':_0x3e753a+'\x20bundled,\x20'+_0x11a3d7+_0x47d978(0x1f2,'vCna')+_0x1e478b[_0x5d1659(0x12d,'S9f[')]+_0x5d1659(0x13f,'wID%')+_0x46111f+_0x5d1659(0x1b8,'bING'))),{'name':_0x53d12c[_0x47d978(0x1ea,'R7n3')],'root':_0x53d12c[_0x5d1659(0x20f,'S9f[')],'entry':_0x53d12c[_0x5d1659(0x111,'g8hX')],'modules':_0x3e753a,'assets':_0x46111f,'helpers':_0x1e478b[_0x5d1659(0x19f,'5$N[')],'scripts':_0x11a3d7};}function packageGameToDir(_0x920d7b,_0x1e5754,_0x575a71){const _0x3e5e77=_0x2e685d,_0x6cacd6=_0x44347e,_0x287cbd={'YjRZL':function(_0x612c84,_0x5adc66){return _0x612c84===_0x5adc66;},'nGBVo':function(_0x3dd41d,_0x182430){return _0x3dd41d===_0x182430;},'XDhzo':_0x3e5e77(0xfa,'3Xhc'),'ZIPaa':'project.config.json','xfmGp':_0x6cacd6(0x1bd,'tIj)'),'WSCsx':function(_0x252c83,_0x43183b,_0x13032a){return _0x252c83(_0x43183b,_0x13032a);},'DCqWF':function(_0x48e9fa,_0x22fb5e,_0x56a497,_0xe42127,_0x3cbc1e,_0x267301,_0x212c0f){return _0x48e9fa(_0x22fb5e,_0x56a497,_0xe42127,_0x3cbc1e,_0x267301,_0x212c0f);},'HKjKB':_0x6cacd6(0x155,'kmeB'),'DTKBq':function(_0x3f3fb9,_0x3cfd6d){return _0x3f3fb9-_0x3cfd6d;},'xIHai':_0x3e5e77(0x1e3,'sFcs')},_0x5e223e=Date['now'](),_0x2c69be=_0x575a71??((_0x73ffd0,_0x511b8a)=>{const _0xc853ae=_0x6cacd6,_0x201c8b=_0x3e5e77;_0x287cbd[_0xc853ae(0x1b1,'R7n3')](_0x201c8b(0x1ba,'My&w'),_0x73ffd0)?console[_0x201c8b(0x179,'w#R#')](_0x511b8a):_0x287cbd[_0x201c8b(0x17b,'lV*O')](_0x287cbd[_0x201c8b(0x178,'(LiM')],_0x73ffd0)?console['warn'](_0x511b8a):console[_0x201c8b(0xfe,'R7n3')](_0x511b8a);});if(_0x2c69be('log',_0x3e5e77(0x19d,'3F94')+_0x920d7b+'\x20→\x20'+_0x1e5754),!fs2[_0x6cacd6(0x16e,'&yuJ')](path2[_0x3e5e77(0x128,'&NZs')](_0x920d7b,'game.js')))throw new Error(_0x3e5e77(0xfd,'J@Q]')+path2['join'](_0x920d7b,_0x6cacd6(0x102,'MmU$')));fs2['rmSync'](_0x1e5754,{'recursive':!0x0,'force':!0x0}),fs2[_0x3e5e77(0xf6,'wID%')](_0x1e5754,{'recursive':!0x0});for(const name of[_0x6cacd6(0x206,'w#R#'),_0x287cbd['ZIPaa'],_0x287cbd['xfmGp'],_0x3e5e77(0x172,'(tvz')]){const _0x1010af=path2['join'](_0x920d7b,name);fs2[_0x3e5e77(0x1af,'MD&m')](_0x1010af)&&_0x287cbd[_0x6cacd6(0x12c,'bjD[')](copyFile,_0x1010af,path2['join'](_0x1e5754,name));}const _0x1d1362=discoverPackages(_0x920d7b),_0x1101f2=new Set(_0x1d1362[_0x3e5e77(0x18d,'5sH5')](_0x45c1f3=>''!==_0x45c1f3[_0x3e5e77(0x1a6,'Wk&A')])[_0x6cacd6(0x1fd,'8hK%')](_0x3cc6dd=>_0x3cc6dd['root'])),_0x83c607=[],_0x336c04=[];for(const _0x2e2694 of _0x1d1362){const _0x41c533=''===_0x2e2694[_0x3e5e77(0x196,'rYhc')]?_0x1101f2:new Set();try{_0x336c04[_0x6cacd6(0x170,'*VUN')](_0x287cbd[_0x3e5e77(0x120,'vN4i')](packOnePackage,_0x920d7b,_0x1e5754,_0x2e2694,_0x41c533,_0x83c607,_0x2c69be));}catch(_0x5ab3bf){const _0x4c095b=_0x5ab3bf instanceof Error?_0x5ab3bf[_0x3e5e77(0x114,'tIj)')]:String(_0x5ab3bf);throw _0x287cbd[_0x6cacd6(0x1d1,'ct&r')](_0x2c69be,'error',_0x3e5e77(0x1d4,'MmU$')+(_0x2e2694[_0x3e5e77(0xef,'&yuJ')]||'main')+_0x3e5e77(0x149,'vCna')+_0x4c095b),_0x83c607[_0x3e5e77(0x1f7,'[Xin')]({'pkg':_0x2e2694['name'],'file':'<package>','level':_0x287cbd[_0x3e5e77(0x220,'bjD[')],'message':_0x4c095b}),_0x5ab3bf;}}const _0x3ba2bf=_0x287cbd[_0x3e5e77(0x119,'XoW2')](Date['now'](),_0x5e223e),_0x5ea1e8=_0x336c04[_0x3e5e77(0x1ad,'zQdF')]((_0x4ae74a,_0x474e0d)=>_0x4ae74a+_0x474e0d[_0x3e5e77(0x183,'&NZs')],0x0),_0x2684cb=_0x336c04[_0x6cacd6(0x167,'tzF3')]((_0x4287dc,_0x3e1209)=>_0x4287dc+_0x3e1209[_0x3e5e77(0x16a,'(tvz')],0x0),_0x45a1bd=_0x336c04[_0x3e5e77(0x1b7,'R7n3')]((_0x3c9180,_0x1a37d1)=>_0x3c9180+_0x1a37d1[_0x3e5e77(0x11d,'kmeB')],0x0),_0x255ed9=_0x336c04['reduce']((_0x557ae9,_0x203f66)=>_0x557ae9+_0x203f66['scripts'],0x0);return _0x2c69be(_0x287cbd['xIHai'],'[packager]\x20Done\x20in\x20'+_0x3ba2bf+'ms\x20—\x20'+_0x336c04['length']+_0x3e5e77(0x145,'MD&m')+_0x5ea1e8+'\x20bundled\x20module(s),\x20'+_0x255ed9+_0x3e5e77(0x211,'My&w')+_0x2684cb+_0x6cacd6(0x10a,'fgU*')+_0x45a1bd+_0x6cacd6(0x104,'&NZs')),{'packages':_0x336c04,'diagnostics':_0x83c607,'elapsed':_0x3ba2bf};}if(import_worker_threads['parentPort']){const e=import_worker_threads['parentPort'];e['on']('message',_0x1d910c=>{const _0x2a787b=_0x2e685d,_0x1bd180=_0x2e685d,_0x38c138={'ytkUO':function(_0x49c6a4,_0x4136b2){return _0x49c6a4!==_0x4136b2;},'uoORB':'run','dWGLa':function(_0x1684c6,_0x110f52){return _0x1684c6||_0x110f52;},'PtUSN':function(_0xfea436,_0x48eb4c){return _0xfea436(_0x48eb4c);},'VnApB':function(_0x4c2623,_0x3355e0){return _0x4c2623(_0x3355e0);}};if(!_0x1d910c||_0x38c138[_0x2a787b(0x11f,'AUGI')](_0x38c138[_0x2a787b(0x1bc,'&yuJ')],_0x1d910c[_0x1bd180(0x14b,'J@Q]')]))return;const {id:_0xc554cf,gameDir:_0x3e90c5,outputDir:_0x179aa0,ciDepsDir:_0x452359,ciExtensionDir:_0x43fef6}=_0x1d910c;if(_0x38c138[_0x2a787b(0x100,'MD&m')](_0x43fef6,_0x452359)){const _0x58b6f8=(init_ci_installer(),_0x38c138[_0x1bd180(0x1a4,'MD&m')](__toCommonJS,ci_installer_exports));_0x43fef6&&_0x58b6f8[_0x2a787b(0x227,'G(xt')](_0x43fef6),_0x452359&&_0x58b6f8['setCiDepsDir'](_0x452359);}const _0x47259e=(_0x4e2da6,_0x457065)=>{e['postMessage']({'kind':'log','id':_0xc554cf,'level':_0x4e2da6,'message':_0x457065});};try{if('xOHmu'===_0x2a787b(0x148,'vN4i')){const _0x5c7160=packageGameToDir(_0x3e90c5,_0x179aa0,_0x47259e);e['postMessage']({'kind':_0x1bd180(0x15e,'[Xin'),'id':_0xc554cf,'result':_0x5c7160});}else _0x2c0916['mkdirSync'](_0x367c5a['dirname'](_0x3bcebb),{'recursive':!0x0}),_0x4e7763['copyFileSync'](_0x19d6eb,_0x18c7f3);}catch(_0x4111b1){const _0x37cef9=_0x4111b1 instanceof Error?_0x4111b1[_0x1bd180(0xf2,'wID%')]:_0x38c138['VnApB'](String,_0x4111b1),_0x4f9a2b=_0x4111b1 instanceof Error?_0x4111b1[_0x2a787b(0x163,']cL7')]:void 0x0;e['postMessage']({'kind':'error','id':_0xc554cf,'message':_0x37cef9,'stack':_0x4f9a2b});}});}else console['warn'](_0x44347e(0x1b2,'vN4i'));
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __esm = (fn, res) => function __init() {
|
|
9
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
10
|
+
};
|
|
11
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
12
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
13
|
+
};
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
27
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
28
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
29
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
30
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
31
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
32
|
+
mod
|
|
33
|
+
));
|
|
34
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
35
|
+
|
|
36
|
+
// core/real-device/ci-installer.ts
|
|
37
|
+
var ci_installer_exports = {};
|
|
38
|
+
__export(ci_installer_exports, {
|
|
39
|
+
ensureCiInstalled: () => ensureCiInstalled,
|
|
40
|
+
getCiDepsDir: () => getCiDepsDir,
|
|
41
|
+
getCiExtensionDir: () => getCiExtensionDir,
|
|
42
|
+
getCiInstallStatus: () => getCiInstallStatus,
|
|
43
|
+
getCiRequirePath: () => getCiRequirePath,
|
|
44
|
+
isCiInstalled: () => isCiInstalled,
|
|
45
|
+
onCiInstallStatusChange: () => onCiInstallStatusChange,
|
|
46
|
+
retryCiInstall: () => retryCiInstall,
|
|
47
|
+
setCiDepsDir: () => setCiDepsDir,
|
|
48
|
+
setCiExtensionDir: () => setCiExtensionDir
|
|
49
|
+
});
|
|
50
|
+
function setStatus(next) {
|
|
51
|
+
_statusInfo = next;
|
|
52
|
+
for (const l of _statusListeners) {
|
|
53
|
+
try {
|
|
54
|
+
l(next);
|
|
55
|
+
} catch {
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function onCiInstallStatusChange(listener) {
|
|
60
|
+
_statusListeners.add(listener);
|
|
61
|
+
try {
|
|
62
|
+
listener(_statusInfo);
|
|
63
|
+
} catch {
|
|
64
|
+
}
|
|
65
|
+
return () => _statusListeners.delete(listener);
|
|
66
|
+
}
|
|
67
|
+
function getCiInstallStatus() {
|
|
68
|
+
return _statusInfo;
|
|
69
|
+
}
|
|
70
|
+
function setCiDepsDir(dir) {
|
|
71
|
+
_installDir = dir;
|
|
72
|
+
if (isCiInstalled()) {
|
|
73
|
+
if (_statusInfo.status !== "installed") {
|
|
74
|
+
setStatus({ status: "installed", message: "miniprogram-ci \u5DF2\u5B89\u88C5" });
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function setCiExtensionDir(dir) {
|
|
79
|
+
_extensionDir = dir;
|
|
80
|
+
}
|
|
81
|
+
async function ensureCiInstalled(onProgress) {
|
|
82
|
+
const bundled = getBundledCiPath();
|
|
83
|
+
if (bundled) return bundled;
|
|
84
|
+
const dir = getDepsDir();
|
|
85
|
+
const ciPath = path.join(dir, "node_modules", CI_PACKAGE);
|
|
86
|
+
if (fs.existsSync(path.join(ciPath, "package.json"))) {
|
|
87
|
+
if (_statusInfo.status !== "installed") {
|
|
88
|
+
setStatus({ status: "installed", message: "miniprogram-ci \u5DF2\u5B89\u88C5" });
|
|
89
|
+
}
|
|
90
|
+
return ciPath;
|
|
91
|
+
}
|
|
92
|
+
if (_installing) return _installing;
|
|
93
|
+
_installing = doInstall(dir, onProgress);
|
|
94
|
+
try {
|
|
95
|
+
return await _installing;
|
|
96
|
+
} finally {
|
|
97
|
+
_installing = null;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
async function retryCiInstall(onProgress) {
|
|
101
|
+
if (_installing) return _installing;
|
|
102
|
+
if (_statusInfo.status === "failed") {
|
|
103
|
+
setStatus({ status: "not-installed" });
|
|
104
|
+
}
|
|
105
|
+
return ensureCiInstalled(onProgress);
|
|
106
|
+
}
|
|
107
|
+
function isCiInstalled() {
|
|
108
|
+
try {
|
|
109
|
+
if (getBundledCiPath()) return true;
|
|
110
|
+
const dir = getDepsDir();
|
|
111
|
+
return fs.existsSync(
|
|
112
|
+
path.join(dir, "node_modules", CI_PACKAGE, "package.json")
|
|
113
|
+
);
|
|
114
|
+
} catch {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function getCiDepsDir() {
|
|
119
|
+
return _installDir;
|
|
120
|
+
}
|
|
121
|
+
function getCiExtensionDir() {
|
|
122
|
+
return _extensionDir;
|
|
123
|
+
}
|
|
124
|
+
function getCiRequirePath() {
|
|
125
|
+
const bundled = getBundledCiPath();
|
|
126
|
+
if (bundled) return bundled;
|
|
127
|
+
const dir = getDepsDir();
|
|
128
|
+
const ciPath = path.join(dir, "node_modules", CI_PACKAGE);
|
|
129
|
+
if (!fs.existsSync(path.join(ciPath, "package.json"))) {
|
|
130
|
+
throw new Error(
|
|
131
|
+
`[ci-installer] miniprogram-ci is not installed yet. Call ensureCiInstalled() first.`
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
return ciPath;
|
|
135
|
+
}
|
|
136
|
+
function getBundledCiPath() {
|
|
137
|
+
if (!_extensionDir) return null;
|
|
138
|
+
const bundledPath = path.join(_extensionDir, "node_modules", CI_PACKAGE);
|
|
139
|
+
if (fs.existsSync(path.join(bundledPath, "package.json"))) {
|
|
140
|
+
return bundledPath;
|
|
141
|
+
}
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
function getDepsDir() {
|
|
145
|
+
if (!_installDir) {
|
|
146
|
+
_installDir = path.join(os.homedir(), ".weixin-minigame-helper", "deps");
|
|
147
|
+
}
|
|
148
|
+
return _installDir;
|
|
149
|
+
}
|
|
150
|
+
async function doInstall(dir, onProgress) {
|
|
151
|
+
const initialMsg = "\u6B63\u5728\u5B89\u88C5 miniprogram-ci\uFF08\u9996\u6B21\u4F7F\u7528\uFF0C\u7EA6\u9700 30 \u79D2\uFF09\u2026";
|
|
152
|
+
setStatus({ status: "installing", message: initialMsg });
|
|
153
|
+
onProgress?.(initialMsg);
|
|
154
|
+
const reportProgress = (msg) => {
|
|
155
|
+
setStatus({ status: "installing", message: msg });
|
|
156
|
+
onProgress?.(msg);
|
|
157
|
+
};
|
|
158
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
159
|
+
const pkgPath = path.join(dir, "package.json");
|
|
160
|
+
if (!fs.existsSync(pkgPath)) {
|
|
161
|
+
fs.writeFileSync(
|
|
162
|
+
pkgPath,
|
|
163
|
+
JSON.stringify(
|
|
164
|
+
{ name: "weixin-minigame-helper-deps", private: true, dependencies: {} },
|
|
165
|
+
null,
|
|
166
|
+
2
|
|
167
|
+
)
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
const cmd = `npm install ${CI_PACKAGE}@"${CI_VERSION}" --save --prefer-offline`;
|
|
171
|
+
reportProgress(`\u6267\u884C: npm install ${CI_PACKAGE}@"${CI_VERSION}" ...`);
|
|
172
|
+
try {
|
|
173
|
+
(0, import_child_process.execSync)(cmd, {
|
|
174
|
+
cwd: dir,
|
|
175
|
+
stdio: "pipe",
|
|
176
|
+
timeout: 18e4,
|
|
177
|
+
// 3 min timeout
|
|
178
|
+
env: { ...process.env, NODE_ENV: "" }
|
|
179
|
+
// ensure devDependencies aren't skipped
|
|
180
|
+
});
|
|
181
|
+
} catch (err) {
|
|
182
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
183
|
+
const errorText = `[ci-installer] Failed to install ${CI_PACKAGE}. Please check your network connection and npm configuration.
|
|
184
|
+
${message}`;
|
|
185
|
+
setStatus({ status: "failed", message: "miniprogram-ci \u5B89\u88C5\u5931\u8D25", error: errorText });
|
|
186
|
+
throw new Error(errorText);
|
|
187
|
+
}
|
|
188
|
+
const ciPath = path.join(dir, "node_modules", CI_PACKAGE);
|
|
189
|
+
if (!fs.existsSync(path.join(ciPath, "package.json"))) {
|
|
190
|
+
const errorText = `[ci-installer] npm install succeeded but ${CI_PACKAGE} was not found at ${ciPath}.`;
|
|
191
|
+
setStatus({ status: "failed", message: "miniprogram-ci \u5B89\u88C5\u5931\u8D25", error: errorText });
|
|
192
|
+
throw new Error(errorText);
|
|
193
|
+
}
|
|
194
|
+
const doneMsg = "miniprogram-ci \u5B89\u88C5\u5B8C\u6210 \u2713";
|
|
195
|
+
setStatus({ status: "installed", message: doneMsg });
|
|
196
|
+
onProgress?.(doneMsg);
|
|
197
|
+
return ciPath;
|
|
198
|
+
}
|
|
199
|
+
var path, fs, os, import_child_process, CI_PACKAGE, CI_VERSION, _installDir, _extensionDir, _installing, _statusInfo, _statusListeners;
|
|
200
|
+
var init_ci_installer = __esm({
|
|
201
|
+
"core/real-device/ci-installer.ts"() {
|
|
202
|
+
"use strict";
|
|
203
|
+
path = __toESM(require("path"));
|
|
204
|
+
fs = __toESM(require("fs"));
|
|
205
|
+
os = __toESM(require("os"));
|
|
206
|
+
import_child_process = require("child_process");
|
|
207
|
+
CI_PACKAGE = "miniprogram-ci";
|
|
208
|
+
CI_VERSION = "^2.1.31";
|
|
209
|
+
_installDir = null;
|
|
210
|
+
_extensionDir = null;
|
|
211
|
+
_installing = null;
|
|
212
|
+
_statusInfo = { status: "not-installed" };
|
|
213
|
+
_statusListeners = /* @__PURE__ */ new Set();
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
// node_modules/esbuild/lib/main.js
|
|
218
|
+
var require_main = __commonJS({
|
|
219
|
+
"node_modules/esbuild/lib/main.js"(exports2, module2) {
|
|
220
|
+
"use strict";
|
|
221
|
+
var __defProp2 = Object.defineProperty;
|
|
222
|
+
var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
|
|
223
|
+
var __getOwnPropNames2 = Object.getOwnPropertyNames;
|
|
224
|
+
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
225
|
+
var __export2 = (target, all) => {
|
|
226
|
+
for (var name in all)
|
|
227
|
+
__defProp2(target, name, { get: all[name], enumerable: true });
|
|
228
|
+
};
|
|
229
|
+
var __copyProps2 = (to, from, except, desc) => {
|
|
230
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
231
|
+
for (let key of __getOwnPropNames2(from))
|
|
232
|
+
if (!__hasOwnProp2.call(to, key) && key !== except)
|
|
233
|
+
__defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
|
|
234
|
+
}
|
|
235
|
+
return to;
|
|
236
|
+
};
|
|
237
|
+
var __toCommonJS2 = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
|
|
238
|
+
var node_exports = {};
|
|
239
|
+
__export2(node_exports, {
|
|
240
|
+
analyzeMetafile: () => analyzeMetafile,
|
|
241
|
+
analyzeMetafileSync: () => analyzeMetafileSync,
|
|
242
|
+
build: () => build,
|
|
243
|
+
buildSync: () => buildSync,
|
|
244
|
+
context: () => context,
|
|
245
|
+
default: () => node_default,
|
|
246
|
+
formatMessages: () => formatMessages,
|
|
247
|
+
formatMessagesSync: () => formatMessagesSync,
|
|
248
|
+
initialize: () => initialize,
|
|
249
|
+
stop: () => stop,
|
|
250
|
+
transform: () => transform,
|
|
251
|
+
transformSync: () => transformSync,
|
|
252
|
+
version: () => version
|
|
253
|
+
});
|
|
254
|
+
module2.exports = __toCommonJS2(node_exports);
|
|
255
|
+
function encodePacket(packet) {
|
|
256
|
+
let visit = (value) => {
|
|
257
|
+
if (value === null) {
|
|
258
|
+
bb.write8(0);
|
|
259
|
+
} else if (typeof value === "boolean") {
|
|
260
|
+
bb.write8(1);
|
|
261
|
+
bb.write8(+value);
|
|
262
|
+
} else if (typeof value === "number") {
|
|
263
|
+
bb.write8(2);
|
|
264
|
+
bb.write32(value | 0);
|
|
265
|
+
} else if (typeof value === "string") {
|
|
266
|
+
bb.write8(3);
|
|
267
|
+
bb.write(encodeUTF8(value));
|
|
268
|
+
} else if (value instanceof Uint8Array) {
|
|
269
|
+
bb.write8(4);
|
|
270
|
+
bb.write(value);
|
|
271
|
+
} else if (value instanceof Array) {
|
|
272
|
+
bb.write8(5);
|
|
273
|
+
bb.write32(value.length);
|
|
274
|
+
for (let item of value) {
|
|
275
|
+
visit(item);
|
|
276
|
+
}
|
|
277
|
+
} else {
|
|
278
|
+
let keys = Object.keys(value);
|
|
279
|
+
bb.write8(6);
|
|
280
|
+
bb.write32(keys.length);
|
|
281
|
+
for (let key of keys) {
|
|
282
|
+
bb.write(encodeUTF8(key));
|
|
283
|
+
visit(value[key]);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
let bb = new ByteBuffer();
|
|
288
|
+
bb.write32(0);
|
|
289
|
+
bb.write32(packet.id << 1 | +!packet.isRequest);
|
|
290
|
+
visit(packet.value);
|
|
291
|
+
writeUInt32LE(bb.buf, bb.len - 4, 0);
|
|
292
|
+
return bb.buf.subarray(0, bb.len);
|
|
293
|
+
}
|
|
294
|
+
function decodePacket(bytes) {
|
|
295
|
+
let visit = () => {
|
|
296
|
+
switch (bb.read8()) {
|
|
297
|
+
case 0:
|
|
298
|
+
return null;
|
|
299
|
+
case 1:
|
|
300
|
+
return !!bb.read8();
|
|
301
|
+
case 2:
|
|
302
|
+
return bb.read32();
|
|
303
|
+
case 3:
|
|
304
|
+
return decodeUTF8(bb.read());
|
|
305
|
+
case 4:
|
|
306
|
+
return bb.read();
|
|
307
|
+
case 5: {
|
|
308
|
+
let count = bb.read32();
|
|
309
|
+
let value2 = [];
|
|
310
|
+
for (let i = 0; i < count; i++) {
|
|
311
|
+
value2.push(visit());
|
|
312
|
+
}
|
|
313
|
+
return value2;
|
|
314
|
+
}
|
|
315
|
+
case 6: {
|
|
316
|
+
let count = bb.read32();
|
|
317
|
+
let value2 = {};
|
|
318
|
+
for (let i = 0; i < count; i++) {
|
|
319
|
+
value2[decodeUTF8(bb.read())] = visit();
|
|
320
|
+
}
|
|
321
|
+
return value2;
|
|
322
|
+
}
|
|
323
|
+
default:
|
|
324
|
+
throw new Error("Invalid packet");
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
let bb = new ByteBuffer(bytes);
|
|
328
|
+
let id = bb.read32();
|
|
329
|
+
let isRequest = (id & 1) === 0;
|
|
330
|
+
id >>>= 1;
|
|
331
|
+
let value = visit();
|
|
332
|
+
if (bb.ptr !== bytes.length) {
|
|
333
|
+
throw new Error("Invalid packet");
|
|
334
|
+
}
|
|
335
|
+
return { id, isRequest, value };
|
|
336
|
+
}
|
|
337
|
+
var ByteBuffer = class {
|
|
338
|
+
constructor(buf = new Uint8Array(1024)) {
|
|
339
|
+
this.buf = buf;
|
|
340
|
+
this.len = 0;
|
|
341
|
+
this.ptr = 0;
|
|
342
|
+
}
|
|
343
|
+
_write(delta) {
|
|
344
|
+
if (this.len + delta > this.buf.length) {
|
|
345
|
+
let clone = new Uint8Array((this.len + delta) * 2);
|
|
346
|
+
clone.set(this.buf);
|
|
347
|
+
this.buf = clone;
|
|
348
|
+
}
|
|
349
|
+
this.len += delta;
|
|
350
|
+
return this.len - delta;
|
|
351
|
+
}
|
|
352
|
+
write8(value) {
|
|
353
|
+
let offset = this._write(1);
|
|
354
|
+
this.buf[offset] = value;
|
|
355
|
+
}
|
|
356
|
+
write32(value) {
|
|
357
|
+
let offset = this._write(4);
|
|
358
|
+
writeUInt32LE(this.buf, value, offset);
|
|
359
|
+
}
|
|
360
|
+
write(bytes) {
|
|
361
|
+
let offset = this._write(4 + bytes.length);
|
|
362
|
+
writeUInt32LE(this.buf, bytes.length, offset);
|
|
363
|
+
this.buf.set(bytes, offset + 4);
|
|
364
|
+
}
|
|
365
|
+
_read(delta) {
|
|
366
|
+
if (this.ptr + delta > this.buf.length) {
|
|
367
|
+
throw new Error("Invalid packet");
|
|
368
|
+
}
|
|
369
|
+
this.ptr += delta;
|
|
370
|
+
return this.ptr - delta;
|
|
371
|
+
}
|
|
372
|
+
read8() {
|
|
373
|
+
return this.buf[this._read(1)];
|
|
374
|
+
}
|
|
375
|
+
read32() {
|
|
376
|
+
return readUInt32LE(this.buf, this._read(4));
|
|
377
|
+
}
|
|
378
|
+
read() {
|
|
379
|
+
let length = this.read32();
|
|
380
|
+
let bytes = new Uint8Array(length);
|
|
381
|
+
let ptr = this._read(bytes.length);
|
|
382
|
+
bytes.set(this.buf.subarray(ptr, ptr + length));
|
|
383
|
+
return bytes;
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
var encodeUTF8;
|
|
387
|
+
var decodeUTF8;
|
|
388
|
+
var encodeInvariant;
|
|
389
|
+
if (typeof TextEncoder !== "undefined" && typeof TextDecoder !== "undefined") {
|
|
390
|
+
let encoder = new TextEncoder();
|
|
391
|
+
let decoder = new TextDecoder();
|
|
392
|
+
encodeUTF8 = (text) => encoder.encode(text);
|
|
393
|
+
decodeUTF8 = (bytes) => decoder.decode(bytes);
|
|
394
|
+
encodeInvariant = 'new TextEncoder().encode("")';
|
|
395
|
+
} else if (typeof Buffer !== "undefined") {
|
|
396
|
+
encodeUTF8 = (text) => Buffer.from(text);
|
|
397
|
+
decodeUTF8 = (bytes) => {
|
|
398
|
+
let { buffer, byteOffset, byteLength } = bytes;
|
|
399
|
+
return Buffer.from(buffer, byteOffset, byteLength).toString();
|
|
400
|
+
};
|
|
401
|
+
encodeInvariant = 'Buffer.from("")';
|
|
402
|
+
} else {
|
|
403
|
+
throw new Error("No UTF-8 codec found");
|
|
404
|
+
}
|
|
405
|
+
if (!(encodeUTF8("") instanceof Uint8Array))
|
|
406
|
+
throw new Error(`Invariant violation: "${encodeInvariant} instanceof Uint8Array" is incorrectly false
|
|
407
|
+
|
|
408
|
+
This indicates that your JavaScript environment is broken. You cannot use
|
|
409
|
+
esbuild in this environment because esbuild relies on this invariant. This
|
|
410
|
+
is not a problem with esbuild. You need to fix your environment instead.
|
|
411
|
+
`);
|
|
412
|
+
function readUInt32LE(buffer, offset) {
|
|
413
|
+
return buffer[offset++] | buffer[offset++] << 8 | buffer[offset++] << 16 | buffer[offset++] << 24;
|
|
414
|
+
}
|
|
415
|
+
function writeUInt32LE(buffer, value, offset) {
|
|
416
|
+
buffer[offset++] = value;
|
|
417
|
+
buffer[offset++] = value >> 8;
|
|
418
|
+
buffer[offset++] = value >> 16;
|
|
419
|
+
buffer[offset++] = value >> 24;
|
|
420
|
+
}
|
|
421
|
+
var quote = JSON.stringify;
|
|
422
|
+
var buildLogLevelDefault = "warning";
|
|
423
|
+
var transformLogLevelDefault = "silent";
|
|
424
|
+
function validateTarget(target) {
|
|
425
|
+
validateStringValue(target, "target");
|
|
426
|
+
if (target.indexOf(",") >= 0) throw new Error(`Invalid target: ${target}`);
|
|
427
|
+
return target;
|
|
428
|
+
}
|
|
429
|
+
var canBeAnything = () => null;
|
|
430
|
+
var mustBeBoolean = (value) => typeof value === "boolean" ? null : "a boolean";
|
|
431
|
+
var mustBeString = (value) => typeof value === "string" ? null : "a string";
|
|
432
|
+
var mustBeRegExp = (value) => value instanceof RegExp ? null : "a RegExp object";
|
|
433
|
+
var mustBeInteger = (value) => typeof value === "number" && value === (value | 0) ? null : "an integer";
|
|
434
|
+
var mustBeFunction = (value) => typeof value === "function" ? null : "a function";
|
|
435
|
+
var mustBeArray = (value) => Array.isArray(value) ? null : "an array";
|
|
436
|
+
var mustBeObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? null : "an object";
|
|
437
|
+
var mustBeEntryPoints = (value) => typeof value === "object" && value !== null ? null : "an array or an object";
|
|
438
|
+
var mustBeWebAssemblyModule = (value) => value instanceof WebAssembly.Module ? null : "a WebAssembly.Module";
|
|
439
|
+
var mustBeObjectOrNull = (value) => typeof value === "object" && !Array.isArray(value) ? null : "an object or null";
|
|
440
|
+
var mustBeStringOrBoolean = (value) => typeof value === "string" || typeof value === "boolean" ? null : "a string or a boolean";
|
|
441
|
+
var mustBeStringOrObject = (value) => typeof value === "string" || typeof value === "object" && value !== null && !Array.isArray(value) ? null : "a string or an object";
|
|
442
|
+
var mustBeStringOrArray = (value) => typeof value === "string" || Array.isArray(value) ? null : "a string or an array";
|
|
443
|
+
var mustBeStringOrUint8Array = (value) => typeof value === "string" || value instanceof Uint8Array ? null : "a string or a Uint8Array";
|
|
444
|
+
var mustBeStringOrURL = (value) => typeof value === "string" || value instanceof URL ? null : "a string or a URL";
|
|
445
|
+
function getFlag(object, keys, key, mustBeFn) {
|
|
446
|
+
let value = object[key];
|
|
447
|
+
keys[key + ""] = true;
|
|
448
|
+
if (value === void 0) return void 0;
|
|
449
|
+
let mustBe = mustBeFn(value);
|
|
450
|
+
if (mustBe !== null) throw new Error(`${quote(key)} must be ${mustBe}`);
|
|
451
|
+
return value;
|
|
452
|
+
}
|
|
453
|
+
function checkForInvalidFlags(object, keys, where) {
|
|
454
|
+
for (let key in object) {
|
|
455
|
+
if (!(key in keys)) {
|
|
456
|
+
throw new Error(`Invalid option ${where}: ${quote(key)}`);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
function validateInitializeOptions(options) {
|
|
461
|
+
let keys = /* @__PURE__ */ Object.create(null);
|
|
462
|
+
let wasmURL = getFlag(options, keys, "wasmURL", mustBeStringOrURL);
|
|
463
|
+
let wasmModule = getFlag(options, keys, "wasmModule", mustBeWebAssemblyModule);
|
|
464
|
+
let worker = getFlag(options, keys, "worker", mustBeBoolean);
|
|
465
|
+
checkForInvalidFlags(options, keys, "in initialize() call");
|
|
466
|
+
return {
|
|
467
|
+
wasmURL,
|
|
468
|
+
wasmModule,
|
|
469
|
+
worker
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
function validateMangleCache(mangleCache) {
|
|
473
|
+
let validated;
|
|
474
|
+
if (mangleCache !== void 0) {
|
|
475
|
+
validated = /* @__PURE__ */ Object.create(null);
|
|
476
|
+
for (let key in mangleCache) {
|
|
477
|
+
let value = mangleCache[key];
|
|
478
|
+
if (typeof value === "string" || value === false) {
|
|
479
|
+
validated[key] = value;
|
|
480
|
+
} else {
|
|
481
|
+
throw new Error(`Expected ${quote(key)} in mangle cache to map to either a string or false`);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
return validated;
|
|
486
|
+
}
|
|
487
|
+
function pushLogFlags(flags, options, keys, isTTY2, logLevelDefault) {
|
|
488
|
+
let color = getFlag(options, keys, "color", mustBeBoolean);
|
|
489
|
+
let logLevel = getFlag(options, keys, "logLevel", mustBeString);
|
|
490
|
+
let logLimit = getFlag(options, keys, "logLimit", mustBeInteger);
|
|
491
|
+
if (color !== void 0) flags.push(`--color=${color}`);
|
|
492
|
+
else if (isTTY2) flags.push(`--color=true`);
|
|
493
|
+
flags.push(`--log-level=${logLevel || logLevelDefault}`);
|
|
494
|
+
flags.push(`--log-limit=${logLimit || 0}`);
|
|
495
|
+
}
|
|
496
|
+
function validateStringValue(value, what, key) {
|
|
497
|
+
if (typeof value !== "string") {
|
|
498
|
+
throw new Error(`Expected value for ${what}${key !== void 0 ? " " + quote(key) : ""} to be a string, got ${typeof value} instead`);
|
|
499
|
+
}
|
|
500
|
+
return value;
|
|
501
|
+
}
|
|
502
|
+
function pushCommonFlags(flags, options, keys) {
|
|
503
|
+
let legalComments = getFlag(options, keys, "legalComments", mustBeString);
|
|
504
|
+
let sourceRoot = getFlag(options, keys, "sourceRoot", mustBeString);
|
|
505
|
+
let sourcesContent = getFlag(options, keys, "sourcesContent", mustBeBoolean);
|
|
506
|
+
let target = getFlag(options, keys, "target", mustBeStringOrArray);
|
|
507
|
+
let format = getFlag(options, keys, "format", mustBeString);
|
|
508
|
+
let globalName = getFlag(options, keys, "globalName", mustBeString);
|
|
509
|
+
let mangleProps = getFlag(options, keys, "mangleProps", mustBeRegExp);
|
|
510
|
+
let reserveProps = getFlag(options, keys, "reserveProps", mustBeRegExp);
|
|
511
|
+
let mangleQuoted = getFlag(options, keys, "mangleQuoted", mustBeBoolean);
|
|
512
|
+
let minify = getFlag(options, keys, "minify", mustBeBoolean);
|
|
513
|
+
let minifySyntax = getFlag(options, keys, "minifySyntax", mustBeBoolean);
|
|
514
|
+
let minifyWhitespace = getFlag(options, keys, "minifyWhitespace", mustBeBoolean);
|
|
515
|
+
let minifyIdentifiers = getFlag(options, keys, "minifyIdentifiers", mustBeBoolean);
|
|
516
|
+
let lineLimit = getFlag(options, keys, "lineLimit", mustBeInteger);
|
|
517
|
+
let drop = getFlag(options, keys, "drop", mustBeArray);
|
|
518
|
+
let dropLabels = getFlag(options, keys, "dropLabels", mustBeArray);
|
|
519
|
+
let charset = getFlag(options, keys, "charset", mustBeString);
|
|
520
|
+
let treeShaking = getFlag(options, keys, "treeShaking", mustBeBoolean);
|
|
521
|
+
let ignoreAnnotations = getFlag(options, keys, "ignoreAnnotations", mustBeBoolean);
|
|
522
|
+
let jsx = getFlag(options, keys, "jsx", mustBeString);
|
|
523
|
+
let jsxFactory = getFlag(options, keys, "jsxFactory", mustBeString);
|
|
524
|
+
let jsxFragment = getFlag(options, keys, "jsxFragment", mustBeString);
|
|
525
|
+
let jsxImportSource = getFlag(options, keys, "jsxImportSource", mustBeString);
|
|
526
|
+
let jsxDev = getFlag(options, keys, "jsxDev", mustBeBoolean);
|
|
527
|
+
let jsxSideEffects = getFlag(options, keys, "jsxSideEffects", mustBeBoolean);
|
|
528
|
+
let define = getFlag(options, keys, "define", mustBeObject);
|
|
529
|
+
let logOverride = getFlag(options, keys, "logOverride", mustBeObject);
|
|
530
|
+
let supported = getFlag(options, keys, "supported", mustBeObject);
|
|
531
|
+
let pure = getFlag(options, keys, "pure", mustBeArray);
|
|
532
|
+
let keepNames = getFlag(options, keys, "keepNames", mustBeBoolean);
|
|
533
|
+
let platform = getFlag(options, keys, "platform", mustBeString);
|
|
534
|
+
let tsconfigRaw = getFlag(options, keys, "tsconfigRaw", mustBeStringOrObject);
|
|
535
|
+
if (legalComments) flags.push(`--legal-comments=${legalComments}`);
|
|
536
|
+
if (sourceRoot !== void 0) flags.push(`--source-root=${sourceRoot}`);
|
|
537
|
+
if (sourcesContent !== void 0) flags.push(`--sources-content=${sourcesContent}`);
|
|
538
|
+
if (target) {
|
|
539
|
+
if (Array.isArray(target)) flags.push(`--target=${Array.from(target).map(validateTarget).join(",")}`);
|
|
540
|
+
else flags.push(`--target=${validateTarget(target)}`);
|
|
541
|
+
}
|
|
542
|
+
if (format) flags.push(`--format=${format}`);
|
|
543
|
+
if (globalName) flags.push(`--global-name=${globalName}`);
|
|
544
|
+
if (platform) flags.push(`--platform=${platform}`);
|
|
545
|
+
if (tsconfigRaw) flags.push(`--tsconfig-raw=${typeof tsconfigRaw === "string" ? tsconfigRaw : JSON.stringify(tsconfigRaw)}`);
|
|
546
|
+
if (minify) flags.push("--minify");
|
|
547
|
+
if (minifySyntax) flags.push("--minify-syntax");
|
|
548
|
+
if (minifyWhitespace) flags.push("--minify-whitespace");
|
|
549
|
+
if (minifyIdentifiers) flags.push("--minify-identifiers");
|
|
550
|
+
if (lineLimit) flags.push(`--line-limit=${lineLimit}`);
|
|
551
|
+
if (charset) flags.push(`--charset=${charset}`);
|
|
552
|
+
if (treeShaking !== void 0) flags.push(`--tree-shaking=${treeShaking}`);
|
|
553
|
+
if (ignoreAnnotations) flags.push(`--ignore-annotations`);
|
|
554
|
+
if (drop) for (let what of drop) flags.push(`--drop:${validateStringValue(what, "drop")}`);
|
|
555
|
+
if (dropLabels) flags.push(`--drop-labels=${Array.from(dropLabels).map((what) => validateStringValue(what, "dropLabels")).join(",")}`);
|
|
556
|
+
if (mangleProps) flags.push(`--mangle-props=${mangleProps.source}`);
|
|
557
|
+
if (reserveProps) flags.push(`--reserve-props=${reserveProps.source}`);
|
|
558
|
+
if (mangleQuoted !== void 0) flags.push(`--mangle-quoted=${mangleQuoted}`);
|
|
559
|
+
if (jsx) flags.push(`--jsx=${jsx}`);
|
|
560
|
+
if (jsxFactory) flags.push(`--jsx-factory=${jsxFactory}`);
|
|
561
|
+
if (jsxFragment) flags.push(`--jsx-fragment=${jsxFragment}`);
|
|
562
|
+
if (jsxImportSource) flags.push(`--jsx-import-source=${jsxImportSource}`);
|
|
563
|
+
if (jsxDev) flags.push(`--jsx-dev`);
|
|
564
|
+
if (jsxSideEffects) flags.push(`--jsx-side-effects`);
|
|
565
|
+
if (define) {
|
|
566
|
+
for (let key in define) {
|
|
567
|
+
if (key.indexOf("=") >= 0) throw new Error(`Invalid define: ${key}`);
|
|
568
|
+
flags.push(`--define:${key}=${validateStringValue(define[key], "define", key)}`);
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
if (logOverride) {
|
|
572
|
+
for (let key in logOverride) {
|
|
573
|
+
if (key.indexOf("=") >= 0) throw new Error(`Invalid log override: ${key}`);
|
|
574
|
+
flags.push(`--log-override:${key}=${validateStringValue(logOverride[key], "log override", key)}`);
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
if (supported) {
|
|
578
|
+
for (let key in supported) {
|
|
579
|
+
if (key.indexOf("=") >= 0) throw new Error(`Invalid supported: ${key}`);
|
|
580
|
+
const value = supported[key];
|
|
581
|
+
if (typeof value !== "boolean") throw new Error(`Expected value for supported ${quote(key)} to be a boolean, got ${typeof value} instead`);
|
|
582
|
+
flags.push(`--supported:${key}=${value}`);
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
if (pure) for (let fn of pure) flags.push(`--pure:${validateStringValue(fn, "pure")}`);
|
|
586
|
+
if (keepNames) flags.push(`--keep-names`);
|
|
587
|
+
}
|
|
588
|
+
function flagsForBuildOptions(callName, options, isTTY2, logLevelDefault, writeDefault) {
|
|
589
|
+
var _a2;
|
|
590
|
+
let flags = [];
|
|
591
|
+
let entries = [];
|
|
592
|
+
let keys = /* @__PURE__ */ Object.create(null);
|
|
593
|
+
let stdinContents = null;
|
|
594
|
+
let stdinResolveDir = null;
|
|
595
|
+
pushLogFlags(flags, options, keys, isTTY2, logLevelDefault);
|
|
596
|
+
pushCommonFlags(flags, options, keys);
|
|
597
|
+
let sourcemap = getFlag(options, keys, "sourcemap", mustBeStringOrBoolean);
|
|
598
|
+
let bundle = getFlag(options, keys, "bundle", mustBeBoolean);
|
|
599
|
+
let splitting = getFlag(options, keys, "splitting", mustBeBoolean);
|
|
600
|
+
let preserveSymlinks = getFlag(options, keys, "preserveSymlinks", mustBeBoolean);
|
|
601
|
+
let metafile = getFlag(options, keys, "metafile", mustBeBoolean);
|
|
602
|
+
let outfile = getFlag(options, keys, "outfile", mustBeString);
|
|
603
|
+
let outdir = getFlag(options, keys, "outdir", mustBeString);
|
|
604
|
+
let outbase = getFlag(options, keys, "outbase", mustBeString);
|
|
605
|
+
let tsconfig = getFlag(options, keys, "tsconfig", mustBeString);
|
|
606
|
+
let resolveExtensions = getFlag(options, keys, "resolveExtensions", mustBeArray);
|
|
607
|
+
let nodePathsInput = getFlag(options, keys, "nodePaths", mustBeArray);
|
|
608
|
+
let mainFields = getFlag(options, keys, "mainFields", mustBeArray);
|
|
609
|
+
let conditions = getFlag(options, keys, "conditions", mustBeArray);
|
|
610
|
+
let external = getFlag(options, keys, "external", mustBeArray);
|
|
611
|
+
let packages = getFlag(options, keys, "packages", mustBeString);
|
|
612
|
+
let alias = getFlag(options, keys, "alias", mustBeObject);
|
|
613
|
+
let loader = getFlag(options, keys, "loader", mustBeObject);
|
|
614
|
+
let outExtension = getFlag(options, keys, "outExtension", mustBeObject);
|
|
615
|
+
let publicPath = getFlag(options, keys, "publicPath", mustBeString);
|
|
616
|
+
let entryNames = getFlag(options, keys, "entryNames", mustBeString);
|
|
617
|
+
let chunkNames = getFlag(options, keys, "chunkNames", mustBeString);
|
|
618
|
+
let assetNames = getFlag(options, keys, "assetNames", mustBeString);
|
|
619
|
+
let inject = getFlag(options, keys, "inject", mustBeArray);
|
|
620
|
+
let banner = getFlag(options, keys, "banner", mustBeObject);
|
|
621
|
+
let footer = getFlag(options, keys, "footer", mustBeObject);
|
|
622
|
+
let entryPoints = getFlag(options, keys, "entryPoints", mustBeEntryPoints);
|
|
623
|
+
let absWorkingDir = getFlag(options, keys, "absWorkingDir", mustBeString);
|
|
624
|
+
let stdin = getFlag(options, keys, "stdin", mustBeObject);
|
|
625
|
+
let write = (_a2 = getFlag(options, keys, "write", mustBeBoolean)) != null ? _a2 : writeDefault;
|
|
626
|
+
let allowOverwrite = getFlag(options, keys, "allowOverwrite", mustBeBoolean);
|
|
627
|
+
let mangleCache = getFlag(options, keys, "mangleCache", mustBeObject);
|
|
628
|
+
keys.plugins = true;
|
|
629
|
+
checkForInvalidFlags(options, keys, `in ${callName}() call`);
|
|
630
|
+
if (sourcemap) flags.push(`--sourcemap${sourcemap === true ? "" : `=${sourcemap}`}`);
|
|
631
|
+
if (bundle) flags.push("--bundle");
|
|
632
|
+
if (allowOverwrite) flags.push("--allow-overwrite");
|
|
633
|
+
if (splitting) flags.push("--splitting");
|
|
634
|
+
if (preserveSymlinks) flags.push("--preserve-symlinks");
|
|
635
|
+
if (metafile) flags.push(`--metafile`);
|
|
636
|
+
if (outfile) flags.push(`--outfile=${outfile}`);
|
|
637
|
+
if (outdir) flags.push(`--outdir=${outdir}`);
|
|
638
|
+
if (outbase) flags.push(`--outbase=${outbase}`);
|
|
639
|
+
if (tsconfig) flags.push(`--tsconfig=${tsconfig}`);
|
|
640
|
+
if (packages) flags.push(`--packages=${packages}`);
|
|
641
|
+
if (resolveExtensions) {
|
|
642
|
+
let values = [];
|
|
643
|
+
for (let value of resolveExtensions) {
|
|
644
|
+
validateStringValue(value, "resolve extension");
|
|
645
|
+
if (value.indexOf(",") >= 0) throw new Error(`Invalid resolve extension: ${value}`);
|
|
646
|
+
values.push(value);
|
|
647
|
+
}
|
|
648
|
+
flags.push(`--resolve-extensions=${values.join(",")}`);
|
|
649
|
+
}
|
|
650
|
+
if (publicPath) flags.push(`--public-path=${publicPath}`);
|
|
651
|
+
if (entryNames) flags.push(`--entry-names=${entryNames}`);
|
|
652
|
+
if (chunkNames) flags.push(`--chunk-names=${chunkNames}`);
|
|
653
|
+
if (assetNames) flags.push(`--asset-names=${assetNames}`);
|
|
654
|
+
if (mainFields) {
|
|
655
|
+
let values = [];
|
|
656
|
+
for (let value of mainFields) {
|
|
657
|
+
validateStringValue(value, "main field");
|
|
658
|
+
if (value.indexOf(",") >= 0) throw new Error(`Invalid main field: ${value}`);
|
|
659
|
+
values.push(value);
|
|
660
|
+
}
|
|
661
|
+
flags.push(`--main-fields=${values.join(",")}`);
|
|
662
|
+
}
|
|
663
|
+
if (conditions) {
|
|
664
|
+
let values = [];
|
|
665
|
+
for (let value of conditions) {
|
|
666
|
+
validateStringValue(value, "condition");
|
|
667
|
+
if (value.indexOf(",") >= 0) throw new Error(`Invalid condition: ${value}`);
|
|
668
|
+
values.push(value);
|
|
669
|
+
}
|
|
670
|
+
flags.push(`--conditions=${values.join(",")}`);
|
|
671
|
+
}
|
|
672
|
+
if (external) for (let name of external) flags.push(`--external:${validateStringValue(name, "external")}`);
|
|
673
|
+
if (alias) {
|
|
674
|
+
for (let old in alias) {
|
|
675
|
+
if (old.indexOf("=") >= 0) throw new Error(`Invalid package name in alias: ${old}`);
|
|
676
|
+
flags.push(`--alias:${old}=${validateStringValue(alias[old], "alias", old)}`);
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
if (banner) {
|
|
680
|
+
for (let type in banner) {
|
|
681
|
+
if (type.indexOf("=") >= 0) throw new Error(`Invalid banner file type: ${type}`);
|
|
682
|
+
flags.push(`--banner:${type}=${validateStringValue(banner[type], "banner", type)}`);
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
if (footer) {
|
|
686
|
+
for (let type in footer) {
|
|
687
|
+
if (type.indexOf("=") >= 0) throw new Error(`Invalid footer file type: ${type}`);
|
|
688
|
+
flags.push(`--footer:${type}=${validateStringValue(footer[type], "footer", type)}`);
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
if (inject) for (let path32 of inject) flags.push(`--inject:${validateStringValue(path32, "inject")}`);
|
|
692
|
+
if (loader) {
|
|
693
|
+
for (let ext in loader) {
|
|
694
|
+
if (ext.indexOf("=") >= 0) throw new Error(`Invalid loader extension: ${ext}`);
|
|
695
|
+
flags.push(`--loader:${ext}=${validateStringValue(loader[ext], "loader", ext)}`);
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
if (outExtension) {
|
|
699
|
+
for (let ext in outExtension) {
|
|
700
|
+
if (ext.indexOf("=") >= 0) throw new Error(`Invalid out extension: ${ext}`);
|
|
701
|
+
flags.push(`--out-extension:${ext}=${validateStringValue(outExtension[ext], "out extension", ext)}`);
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
if (entryPoints) {
|
|
705
|
+
if (Array.isArray(entryPoints)) {
|
|
706
|
+
for (let i = 0, n = entryPoints.length; i < n; i++) {
|
|
707
|
+
let entryPoint = entryPoints[i];
|
|
708
|
+
if (typeof entryPoint === "object" && entryPoint !== null) {
|
|
709
|
+
let entryPointKeys = /* @__PURE__ */ Object.create(null);
|
|
710
|
+
let input = getFlag(entryPoint, entryPointKeys, "in", mustBeString);
|
|
711
|
+
let output = getFlag(entryPoint, entryPointKeys, "out", mustBeString);
|
|
712
|
+
checkForInvalidFlags(entryPoint, entryPointKeys, "in entry point at index " + i);
|
|
713
|
+
if (input === void 0) throw new Error('Missing property "in" for entry point at index ' + i);
|
|
714
|
+
if (output === void 0) throw new Error('Missing property "out" for entry point at index ' + i);
|
|
715
|
+
entries.push([output, input]);
|
|
716
|
+
} else {
|
|
717
|
+
entries.push(["", validateStringValue(entryPoint, "entry point at index " + i)]);
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
} else {
|
|
721
|
+
for (let key in entryPoints) {
|
|
722
|
+
entries.push([key, validateStringValue(entryPoints[key], "entry point", key)]);
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
if (stdin) {
|
|
727
|
+
let stdinKeys = /* @__PURE__ */ Object.create(null);
|
|
728
|
+
let contents = getFlag(stdin, stdinKeys, "contents", mustBeStringOrUint8Array);
|
|
729
|
+
let resolveDir = getFlag(stdin, stdinKeys, "resolveDir", mustBeString);
|
|
730
|
+
let sourcefile = getFlag(stdin, stdinKeys, "sourcefile", mustBeString);
|
|
731
|
+
let loader2 = getFlag(stdin, stdinKeys, "loader", mustBeString);
|
|
732
|
+
checkForInvalidFlags(stdin, stdinKeys, 'in "stdin" object');
|
|
733
|
+
if (sourcefile) flags.push(`--sourcefile=${sourcefile}`);
|
|
734
|
+
if (loader2) flags.push(`--loader=${loader2}`);
|
|
735
|
+
if (resolveDir) stdinResolveDir = resolveDir;
|
|
736
|
+
if (typeof contents === "string") stdinContents = encodeUTF8(contents);
|
|
737
|
+
else if (contents instanceof Uint8Array) stdinContents = contents;
|
|
738
|
+
}
|
|
739
|
+
let nodePaths = [];
|
|
740
|
+
if (nodePathsInput) {
|
|
741
|
+
for (let value of nodePathsInput) {
|
|
742
|
+
value += "";
|
|
743
|
+
nodePaths.push(value);
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
return {
|
|
747
|
+
entries,
|
|
748
|
+
flags,
|
|
749
|
+
write,
|
|
750
|
+
stdinContents,
|
|
751
|
+
stdinResolveDir,
|
|
752
|
+
absWorkingDir,
|
|
753
|
+
nodePaths,
|
|
754
|
+
mangleCache: validateMangleCache(mangleCache)
|
|
755
|
+
};
|
|
756
|
+
}
|
|
757
|
+
function flagsForTransformOptions(callName, options, isTTY2, logLevelDefault) {
|
|
758
|
+
let flags = [];
|
|
759
|
+
let keys = /* @__PURE__ */ Object.create(null);
|
|
760
|
+
pushLogFlags(flags, options, keys, isTTY2, logLevelDefault);
|
|
761
|
+
pushCommonFlags(flags, options, keys);
|
|
762
|
+
let sourcemap = getFlag(options, keys, "sourcemap", mustBeStringOrBoolean);
|
|
763
|
+
let sourcefile = getFlag(options, keys, "sourcefile", mustBeString);
|
|
764
|
+
let loader = getFlag(options, keys, "loader", mustBeString);
|
|
765
|
+
let banner = getFlag(options, keys, "banner", mustBeString);
|
|
766
|
+
let footer = getFlag(options, keys, "footer", mustBeString);
|
|
767
|
+
let mangleCache = getFlag(options, keys, "mangleCache", mustBeObject);
|
|
768
|
+
checkForInvalidFlags(options, keys, `in ${callName}() call`);
|
|
769
|
+
if (sourcemap) flags.push(`--sourcemap=${sourcemap === true ? "external" : sourcemap}`);
|
|
770
|
+
if (sourcefile) flags.push(`--sourcefile=${sourcefile}`);
|
|
771
|
+
if (loader) flags.push(`--loader=${loader}`);
|
|
772
|
+
if (banner) flags.push(`--banner=${banner}`);
|
|
773
|
+
if (footer) flags.push(`--footer=${footer}`);
|
|
774
|
+
return {
|
|
775
|
+
flags,
|
|
776
|
+
mangleCache: validateMangleCache(mangleCache)
|
|
777
|
+
};
|
|
778
|
+
}
|
|
779
|
+
function createChannel(streamIn) {
|
|
780
|
+
const requestCallbacksByKey = {};
|
|
781
|
+
const closeData = { didClose: false, reason: "" };
|
|
782
|
+
let responseCallbacks = {};
|
|
783
|
+
let nextRequestID = 0;
|
|
784
|
+
let nextBuildKey = 0;
|
|
785
|
+
let stdout = new Uint8Array(16 * 1024);
|
|
786
|
+
let stdoutUsed = 0;
|
|
787
|
+
let readFromStdout = (chunk) => {
|
|
788
|
+
let limit = stdoutUsed + chunk.length;
|
|
789
|
+
if (limit > stdout.length) {
|
|
790
|
+
let swap = new Uint8Array(limit * 2);
|
|
791
|
+
swap.set(stdout);
|
|
792
|
+
stdout = swap;
|
|
793
|
+
}
|
|
794
|
+
stdout.set(chunk, stdoutUsed);
|
|
795
|
+
stdoutUsed += chunk.length;
|
|
796
|
+
let offset = 0;
|
|
797
|
+
while (offset + 4 <= stdoutUsed) {
|
|
798
|
+
let length = readUInt32LE(stdout, offset);
|
|
799
|
+
if (offset + 4 + length > stdoutUsed) {
|
|
800
|
+
break;
|
|
801
|
+
}
|
|
802
|
+
offset += 4;
|
|
803
|
+
handleIncomingPacket(stdout.subarray(offset, offset + length));
|
|
804
|
+
offset += length;
|
|
805
|
+
}
|
|
806
|
+
if (offset > 0) {
|
|
807
|
+
stdout.copyWithin(0, offset, stdoutUsed);
|
|
808
|
+
stdoutUsed -= offset;
|
|
809
|
+
}
|
|
810
|
+
};
|
|
811
|
+
let afterClose = (error) => {
|
|
812
|
+
closeData.didClose = true;
|
|
813
|
+
if (error) closeData.reason = ": " + (error.message || error);
|
|
814
|
+
const text = "The service was stopped" + closeData.reason;
|
|
815
|
+
for (let id in responseCallbacks) {
|
|
816
|
+
responseCallbacks[id](text, null);
|
|
817
|
+
}
|
|
818
|
+
responseCallbacks = {};
|
|
819
|
+
};
|
|
820
|
+
let sendRequest = (refs, value, callback) => {
|
|
821
|
+
if (closeData.didClose) return callback("The service is no longer running" + closeData.reason, null);
|
|
822
|
+
let id = nextRequestID++;
|
|
823
|
+
responseCallbacks[id] = (error, response) => {
|
|
824
|
+
try {
|
|
825
|
+
callback(error, response);
|
|
826
|
+
} finally {
|
|
827
|
+
if (refs) refs.unref();
|
|
828
|
+
}
|
|
829
|
+
};
|
|
830
|
+
if (refs) refs.ref();
|
|
831
|
+
streamIn.writeToStdin(encodePacket({ id, isRequest: true, value }));
|
|
832
|
+
};
|
|
833
|
+
let sendResponse = (id, value) => {
|
|
834
|
+
if (closeData.didClose) throw new Error("The service is no longer running" + closeData.reason);
|
|
835
|
+
streamIn.writeToStdin(encodePacket({ id, isRequest: false, value }));
|
|
836
|
+
};
|
|
837
|
+
let handleRequest = async (id, request) => {
|
|
838
|
+
try {
|
|
839
|
+
if (request.command === "ping") {
|
|
840
|
+
sendResponse(id, {});
|
|
841
|
+
return;
|
|
842
|
+
}
|
|
843
|
+
if (typeof request.key === "number") {
|
|
844
|
+
const requestCallbacks = requestCallbacksByKey[request.key];
|
|
845
|
+
if (!requestCallbacks) {
|
|
846
|
+
return;
|
|
847
|
+
}
|
|
848
|
+
const callback = requestCallbacks[request.command];
|
|
849
|
+
if (callback) {
|
|
850
|
+
await callback(id, request);
|
|
851
|
+
return;
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
throw new Error(`Invalid command: ` + request.command);
|
|
855
|
+
} catch (e) {
|
|
856
|
+
const errors = [extractErrorMessageV8(e, streamIn, null, void 0, "")];
|
|
857
|
+
try {
|
|
858
|
+
sendResponse(id, { errors });
|
|
859
|
+
} catch {
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
};
|
|
863
|
+
let isFirstPacket = true;
|
|
864
|
+
let handleIncomingPacket = (bytes) => {
|
|
865
|
+
if (isFirstPacket) {
|
|
866
|
+
isFirstPacket = false;
|
|
867
|
+
let binaryVersion = String.fromCharCode(...bytes);
|
|
868
|
+
if (binaryVersion !== "0.21.5") {
|
|
869
|
+
throw new Error(`Cannot start service: Host version "${"0.21.5"}" does not match binary version ${quote(binaryVersion)}`);
|
|
870
|
+
}
|
|
871
|
+
return;
|
|
872
|
+
}
|
|
873
|
+
let packet = decodePacket(bytes);
|
|
874
|
+
if (packet.isRequest) {
|
|
875
|
+
handleRequest(packet.id, packet.value);
|
|
876
|
+
} else {
|
|
877
|
+
let callback = responseCallbacks[packet.id];
|
|
878
|
+
delete responseCallbacks[packet.id];
|
|
879
|
+
if (packet.value.error) callback(packet.value.error, {});
|
|
880
|
+
else callback(null, packet.value);
|
|
881
|
+
}
|
|
882
|
+
};
|
|
883
|
+
let buildOrContext = ({ callName, refs, options, isTTY: isTTY2, defaultWD: defaultWD2, callback }) => {
|
|
884
|
+
let refCount = 0;
|
|
885
|
+
const buildKey = nextBuildKey++;
|
|
886
|
+
const requestCallbacks = {};
|
|
887
|
+
const buildRefs = {
|
|
888
|
+
ref() {
|
|
889
|
+
if (++refCount === 1) {
|
|
890
|
+
if (refs) refs.ref();
|
|
891
|
+
}
|
|
892
|
+
},
|
|
893
|
+
unref() {
|
|
894
|
+
if (--refCount === 0) {
|
|
895
|
+
delete requestCallbacksByKey[buildKey];
|
|
896
|
+
if (refs) refs.unref();
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
};
|
|
900
|
+
requestCallbacksByKey[buildKey] = requestCallbacks;
|
|
901
|
+
buildRefs.ref();
|
|
902
|
+
buildOrContextImpl(
|
|
903
|
+
callName,
|
|
904
|
+
buildKey,
|
|
905
|
+
sendRequest,
|
|
906
|
+
sendResponse,
|
|
907
|
+
buildRefs,
|
|
908
|
+
streamIn,
|
|
909
|
+
requestCallbacks,
|
|
910
|
+
options,
|
|
911
|
+
isTTY2,
|
|
912
|
+
defaultWD2,
|
|
913
|
+
(err, res) => {
|
|
914
|
+
try {
|
|
915
|
+
callback(err, res);
|
|
916
|
+
} finally {
|
|
917
|
+
buildRefs.unref();
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
);
|
|
921
|
+
};
|
|
922
|
+
let transform2 = ({ callName, refs, input, options, isTTY: isTTY2, fs: fs32, callback }) => {
|
|
923
|
+
const details = createObjectStash();
|
|
924
|
+
let start = (inputPath) => {
|
|
925
|
+
try {
|
|
926
|
+
if (typeof input !== "string" && !(input instanceof Uint8Array))
|
|
927
|
+
throw new Error('The input to "transform" must be a string or a Uint8Array');
|
|
928
|
+
let {
|
|
929
|
+
flags,
|
|
930
|
+
mangleCache
|
|
931
|
+
} = flagsForTransformOptions(callName, options, isTTY2, transformLogLevelDefault);
|
|
932
|
+
let request = {
|
|
933
|
+
command: "transform",
|
|
934
|
+
flags,
|
|
935
|
+
inputFS: inputPath !== null,
|
|
936
|
+
input: inputPath !== null ? encodeUTF8(inputPath) : typeof input === "string" ? encodeUTF8(input) : input
|
|
937
|
+
};
|
|
938
|
+
if (mangleCache) request.mangleCache = mangleCache;
|
|
939
|
+
sendRequest(refs, request, (error, response) => {
|
|
940
|
+
if (error) return callback(new Error(error), null);
|
|
941
|
+
let errors = replaceDetailsInMessages(response.errors, details);
|
|
942
|
+
let warnings = replaceDetailsInMessages(response.warnings, details);
|
|
943
|
+
let outstanding = 1;
|
|
944
|
+
let next = () => {
|
|
945
|
+
if (--outstanding === 0) {
|
|
946
|
+
let result = {
|
|
947
|
+
warnings,
|
|
948
|
+
code: response.code,
|
|
949
|
+
map: response.map,
|
|
950
|
+
mangleCache: void 0,
|
|
951
|
+
legalComments: void 0
|
|
952
|
+
};
|
|
953
|
+
if ("legalComments" in response) result.legalComments = response == null ? void 0 : response.legalComments;
|
|
954
|
+
if (response.mangleCache) result.mangleCache = response == null ? void 0 : response.mangleCache;
|
|
955
|
+
callback(null, result);
|
|
956
|
+
}
|
|
957
|
+
};
|
|
958
|
+
if (errors.length > 0) return callback(failureErrorWithLog("Transform failed", errors, warnings), null);
|
|
959
|
+
if (response.codeFS) {
|
|
960
|
+
outstanding++;
|
|
961
|
+
fs32.readFile(response.code, (err, contents) => {
|
|
962
|
+
if (err !== null) {
|
|
963
|
+
callback(err, null);
|
|
964
|
+
} else {
|
|
965
|
+
response.code = contents;
|
|
966
|
+
next();
|
|
967
|
+
}
|
|
968
|
+
});
|
|
969
|
+
}
|
|
970
|
+
if (response.mapFS) {
|
|
971
|
+
outstanding++;
|
|
972
|
+
fs32.readFile(response.map, (err, contents) => {
|
|
973
|
+
if (err !== null) {
|
|
974
|
+
callback(err, null);
|
|
975
|
+
} else {
|
|
976
|
+
response.map = contents;
|
|
977
|
+
next();
|
|
978
|
+
}
|
|
979
|
+
});
|
|
980
|
+
}
|
|
981
|
+
next();
|
|
982
|
+
});
|
|
983
|
+
} catch (e) {
|
|
984
|
+
let flags = [];
|
|
985
|
+
try {
|
|
986
|
+
pushLogFlags(flags, options, {}, isTTY2, transformLogLevelDefault);
|
|
987
|
+
} catch {
|
|
988
|
+
}
|
|
989
|
+
const error = extractErrorMessageV8(e, streamIn, details, void 0, "");
|
|
990
|
+
sendRequest(refs, { command: "error", flags, error }, () => {
|
|
991
|
+
error.detail = details.load(error.detail);
|
|
992
|
+
callback(failureErrorWithLog("Transform failed", [error], []), null);
|
|
993
|
+
});
|
|
994
|
+
}
|
|
995
|
+
};
|
|
996
|
+
if ((typeof input === "string" || input instanceof Uint8Array) && input.length > 1024 * 1024) {
|
|
997
|
+
let next = start;
|
|
998
|
+
start = () => fs32.writeFile(input, next);
|
|
999
|
+
}
|
|
1000
|
+
start(null);
|
|
1001
|
+
};
|
|
1002
|
+
let formatMessages2 = ({ callName, refs, messages, options, callback }) => {
|
|
1003
|
+
if (!options) throw new Error(`Missing second argument in ${callName}() call`);
|
|
1004
|
+
let keys = {};
|
|
1005
|
+
let kind = getFlag(options, keys, "kind", mustBeString);
|
|
1006
|
+
let color = getFlag(options, keys, "color", mustBeBoolean);
|
|
1007
|
+
let terminalWidth = getFlag(options, keys, "terminalWidth", mustBeInteger);
|
|
1008
|
+
checkForInvalidFlags(options, keys, `in ${callName}() call`);
|
|
1009
|
+
if (kind === void 0) throw new Error(`Missing "kind" in ${callName}() call`);
|
|
1010
|
+
if (kind !== "error" && kind !== "warning") throw new Error(`Expected "kind" to be "error" or "warning" in ${callName}() call`);
|
|
1011
|
+
let request = {
|
|
1012
|
+
command: "format-msgs",
|
|
1013
|
+
messages: sanitizeMessages(messages, "messages", null, "", terminalWidth),
|
|
1014
|
+
isWarning: kind === "warning"
|
|
1015
|
+
};
|
|
1016
|
+
if (color !== void 0) request.color = color;
|
|
1017
|
+
if (terminalWidth !== void 0) request.terminalWidth = terminalWidth;
|
|
1018
|
+
sendRequest(refs, request, (error, response) => {
|
|
1019
|
+
if (error) return callback(new Error(error), null);
|
|
1020
|
+
callback(null, response.messages);
|
|
1021
|
+
});
|
|
1022
|
+
};
|
|
1023
|
+
let analyzeMetafile2 = ({ callName, refs, metafile, options, callback }) => {
|
|
1024
|
+
if (options === void 0) options = {};
|
|
1025
|
+
let keys = {};
|
|
1026
|
+
let color = getFlag(options, keys, "color", mustBeBoolean);
|
|
1027
|
+
let verbose = getFlag(options, keys, "verbose", mustBeBoolean);
|
|
1028
|
+
checkForInvalidFlags(options, keys, `in ${callName}() call`);
|
|
1029
|
+
let request = {
|
|
1030
|
+
command: "analyze-metafile",
|
|
1031
|
+
metafile
|
|
1032
|
+
};
|
|
1033
|
+
if (color !== void 0) request.color = color;
|
|
1034
|
+
if (verbose !== void 0) request.verbose = verbose;
|
|
1035
|
+
sendRequest(refs, request, (error, response) => {
|
|
1036
|
+
if (error) return callback(new Error(error), null);
|
|
1037
|
+
callback(null, response.result);
|
|
1038
|
+
});
|
|
1039
|
+
};
|
|
1040
|
+
return {
|
|
1041
|
+
readFromStdout,
|
|
1042
|
+
afterClose,
|
|
1043
|
+
service: {
|
|
1044
|
+
buildOrContext,
|
|
1045
|
+
transform: transform2,
|
|
1046
|
+
formatMessages: formatMessages2,
|
|
1047
|
+
analyzeMetafile: analyzeMetafile2
|
|
1048
|
+
}
|
|
1049
|
+
};
|
|
1050
|
+
}
|
|
1051
|
+
function buildOrContextImpl(callName, buildKey, sendRequest, sendResponse, refs, streamIn, requestCallbacks, options, isTTY2, defaultWD2, callback) {
|
|
1052
|
+
const details = createObjectStash();
|
|
1053
|
+
const isContext = callName === "context";
|
|
1054
|
+
const handleError = (e, pluginName) => {
|
|
1055
|
+
const flags = [];
|
|
1056
|
+
try {
|
|
1057
|
+
pushLogFlags(flags, options, {}, isTTY2, buildLogLevelDefault);
|
|
1058
|
+
} catch {
|
|
1059
|
+
}
|
|
1060
|
+
const message = extractErrorMessageV8(e, streamIn, details, void 0, pluginName);
|
|
1061
|
+
sendRequest(refs, { command: "error", flags, error: message }, () => {
|
|
1062
|
+
message.detail = details.load(message.detail);
|
|
1063
|
+
callback(failureErrorWithLog(isContext ? "Context failed" : "Build failed", [message], []), null);
|
|
1064
|
+
});
|
|
1065
|
+
};
|
|
1066
|
+
let plugins;
|
|
1067
|
+
if (typeof options === "object") {
|
|
1068
|
+
const value = options.plugins;
|
|
1069
|
+
if (value !== void 0) {
|
|
1070
|
+
if (!Array.isArray(value)) return handleError(new Error(`"plugins" must be an array`), "");
|
|
1071
|
+
plugins = value;
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
if (plugins && plugins.length > 0) {
|
|
1075
|
+
if (streamIn.isSync) return handleError(new Error("Cannot use plugins in synchronous API calls"), "");
|
|
1076
|
+
handlePlugins(
|
|
1077
|
+
buildKey,
|
|
1078
|
+
sendRequest,
|
|
1079
|
+
sendResponse,
|
|
1080
|
+
refs,
|
|
1081
|
+
streamIn,
|
|
1082
|
+
requestCallbacks,
|
|
1083
|
+
options,
|
|
1084
|
+
plugins,
|
|
1085
|
+
details
|
|
1086
|
+
).then(
|
|
1087
|
+
(result) => {
|
|
1088
|
+
if (!result.ok) return handleError(result.error, result.pluginName);
|
|
1089
|
+
try {
|
|
1090
|
+
buildOrContextContinue(result.requestPlugins, result.runOnEndCallbacks, result.scheduleOnDisposeCallbacks);
|
|
1091
|
+
} catch (e) {
|
|
1092
|
+
handleError(e, "");
|
|
1093
|
+
}
|
|
1094
|
+
},
|
|
1095
|
+
(e) => handleError(e, "")
|
|
1096
|
+
);
|
|
1097
|
+
return;
|
|
1098
|
+
}
|
|
1099
|
+
try {
|
|
1100
|
+
buildOrContextContinue(null, (result, done) => done([], []), () => {
|
|
1101
|
+
});
|
|
1102
|
+
} catch (e) {
|
|
1103
|
+
handleError(e, "");
|
|
1104
|
+
}
|
|
1105
|
+
function buildOrContextContinue(requestPlugins, runOnEndCallbacks, scheduleOnDisposeCallbacks) {
|
|
1106
|
+
const writeDefault = streamIn.hasFS;
|
|
1107
|
+
const {
|
|
1108
|
+
entries,
|
|
1109
|
+
flags,
|
|
1110
|
+
write,
|
|
1111
|
+
stdinContents,
|
|
1112
|
+
stdinResolveDir,
|
|
1113
|
+
absWorkingDir,
|
|
1114
|
+
nodePaths,
|
|
1115
|
+
mangleCache
|
|
1116
|
+
} = flagsForBuildOptions(callName, options, isTTY2, buildLogLevelDefault, writeDefault);
|
|
1117
|
+
if (write && !streamIn.hasFS) throw new Error(`The "write" option is unavailable in this environment`);
|
|
1118
|
+
const request = {
|
|
1119
|
+
command: "build",
|
|
1120
|
+
key: buildKey,
|
|
1121
|
+
entries,
|
|
1122
|
+
flags,
|
|
1123
|
+
write,
|
|
1124
|
+
stdinContents,
|
|
1125
|
+
stdinResolveDir,
|
|
1126
|
+
absWorkingDir: absWorkingDir || defaultWD2,
|
|
1127
|
+
nodePaths,
|
|
1128
|
+
context: isContext
|
|
1129
|
+
};
|
|
1130
|
+
if (requestPlugins) request.plugins = requestPlugins;
|
|
1131
|
+
if (mangleCache) request.mangleCache = mangleCache;
|
|
1132
|
+
const buildResponseToResult = (response, callback2) => {
|
|
1133
|
+
const result = {
|
|
1134
|
+
errors: replaceDetailsInMessages(response.errors, details),
|
|
1135
|
+
warnings: replaceDetailsInMessages(response.warnings, details),
|
|
1136
|
+
outputFiles: void 0,
|
|
1137
|
+
metafile: void 0,
|
|
1138
|
+
mangleCache: void 0
|
|
1139
|
+
};
|
|
1140
|
+
const originalErrors = result.errors.slice();
|
|
1141
|
+
const originalWarnings = result.warnings.slice();
|
|
1142
|
+
if (response.outputFiles) result.outputFiles = response.outputFiles.map(convertOutputFiles);
|
|
1143
|
+
if (response.metafile) result.metafile = JSON.parse(response.metafile);
|
|
1144
|
+
if (response.mangleCache) result.mangleCache = response.mangleCache;
|
|
1145
|
+
if (response.writeToStdout !== void 0) console.log(decodeUTF8(response.writeToStdout).replace(/\n$/, ""));
|
|
1146
|
+
runOnEndCallbacks(result, (onEndErrors, onEndWarnings) => {
|
|
1147
|
+
if (originalErrors.length > 0 || onEndErrors.length > 0) {
|
|
1148
|
+
const error = failureErrorWithLog("Build failed", originalErrors.concat(onEndErrors), originalWarnings.concat(onEndWarnings));
|
|
1149
|
+
return callback2(error, null, onEndErrors, onEndWarnings);
|
|
1150
|
+
}
|
|
1151
|
+
callback2(null, result, onEndErrors, onEndWarnings);
|
|
1152
|
+
});
|
|
1153
|
+
};
|
|
1154
|
+
let latestResultPromise;
|
|
1155
|
+
let provideLatestResult;
|
|
1156
|
+
if (isContext)
|
|
1157
|
+
requestCallbacks["on-end"] = (id, request2) => new Promise((resolve) => {
|
|
1158
|
+
buildResponseToResult(request2, (err, result, onEndErrors, onEndWarnings) => {
|
|
1159
|
+
const response = {
|
|
1160
|
+
errors: onEndErrors,
|
|
1161
|
+
warnings: onEndWarnings
|
|
1162
|
+
};
|
|
1163
|
+
if (provideLatestResult) provideLatestResult(err, result);
|
|
1164
|
+
latestResultPromise = void 0;
|
|
1165
|
+
provideLatestResult = void 0;
|
|
1166
|
+
sendResponse(id, response);
|
|
1167
|
+
resolve();
|
|
1168
|
+
});
|
|
1169
|
+
});
|
|
1170
|
+
sendRequest(refs, request, (error, response) => {
|
|
1171
|
+
if (error) return callback(new Error(error), null);
|
|
1172
|
+
if (!isContext) {
|
|
1173
|
+
return buildResponseToResult(response, (err, res) => {
|
|
1174
|
+
scheduleOnDisposeCallbacks();
|
|
1175
|
+
return callback(err, res);
|
|
1176
|
+
});
|
|
1177
|
+
}
|
|
1178
|
+
if (response.errors.length > 0) {
|
|
1179
|
+
return callback(failureErrorWithLog("Context failed", response.errors, response.warnings), null);
|
|
1180
|
+
}
|
|
1181
|
+
let didDispose = false;
|
|
1182
|
+
const result = {
|
|
1183
|
+
rebuild: () => {
|
|
1184
|
+
if (!latestResultPromise) latestResultPromise = new Promise((resolve, reject) => {
|
|
1185
|
+
let settlePromise;
|
|
1186
|
+
provideLatestResult = (err, result2) => {
|
|
1187
|
+
if (!settlePromise) settlePromise = () => err ? reject(err) : resolve(result2);
|
|
1188
|
+
};
|
|
1189
|
+
const triggerAnotherBuild = () => {
|
|
1190
|
+
const request2 = {
|
|
1191
|
+
command: "rebuild",
|
|
1192
|
+
key: buildKey
|
|
1193
|
+
};
|
|
1194
|
+
sendRequest(refs, request2, (error2, response2) => {
|
|
1195
|
+
if (error2) {
|
|
1196
|
+
reject(new Error(error2));
|
|
1197
|
+
} else if (settlePromise) {
|
|
1198
|
+
settlePromise();
|
|
1199
|
+
} else {
|
|
1200
|
+
triggerAnotherBuild();
|
|
1201
|
+
}
|
|
1202
|
+
});
|
|
1203
|
+
};
|
|
1204
|
+
triggerAnotherBuild();
|
|
1205
|
+
});
|
|
1206
|
+
return latestResultPromise;
|
|
1207
|
+
},
|
|
1208
|
+
watch: (options2 = {}) => new Promise((resolve, reject) => {
|
|
1209
|
+
if (!streamIn.hasFS) throw new Error(`Cannot use the "watch" API in this environment`);
|
|
1210
|
+
const keys = {};
|
|
1211
|
+
checkForInvalidFlags(options2, keys, `in watch() call`);
|
|
1212
|
+
const request2 = {
|
|
1213
|
+
command: "watch",
|
|
1214
|
+
key: buildKey
|
|
1215
|
+
};
|
|
1216
|
+
sendRequest(refs, request2, (error2) => {
|
|
1217
|
+
if (error2) reject(new Error(error2));
|
|
1218
|
+
else resolve(void 0);
|
|
1219
|
+
});
|
|
1220
|
+
}),
|
|
1221
|
+
serve: (options2 = {}) => new Promise((resolve, reject) => {
|
|
1222
|
+
if (!streamIn.hasFS) throw new Error(`Cannot use the "serve" API in this environment`);
|
|
1223
|
+
const keys = {};
|
|
1224
|
+
const port = getFlag(options2, keys, "port", mustBeInteger);
|
|
1225
|
+
const host = getFlag(options2, keys, "host", mustBeString);
|
|
1226
|
+
const servedir = getFlag(options2, keys, "servedir", mustBeString);
|
|
1227
|
+
const keyfile = getFlag(options2, keys, "keyfile", mustBeString);
|
|
1228
|
+
const certfile = getFlag(options2, keys, "certfile", mustBeString);
|
|
1229
|
+
const fallback = getFlag(options2, keys, "fallback", mustBeString);
|
|
1230
|
+
const onRequest = getFlag(options2, keys, "onRequest", mustBeFunction);
|
|
1231
|
+
checkForInvalidFlags(options2, keys, `in serve() call`);
|
|
1232
|
+
const request2 = {
|
|
1233
|
+
command: "serve",
|
|
1234
|
+
key: buildKey,
|
|
1235
|
+
onRequest: !!onRequest
|
|
1236
|
+
};
|
|
1237
|
+
if (port !== void 0) request2.port = port;
|
|
1238
|
+
if (host !== void 0) request2.host = host;
|
|
1239
|
+
if (servedir !== void 0) request2.servedir = servedir;
|
|
1240
|
+
if (keyfile !== void 0) request2.keyfile = keyfile;
|
|
1241
|
+
if (certfile !== void 0) request2.certfile = certfile;
|
|
1242
|
+
if (fallback !== void 0) request2.fallback = fallback;
|
|
1243
|
+
sendRequest(refs, request2, (error2, response2) => {
|
|
1244
|
+
if (error2) return reject(new Error(error2));
|
|
1245
|
+
if (onRequest) {
|
|
1246
|
+
requestCallbacks["serve-request"] = (id, request3) => {
|
|
1247
|
+
onRequest(request3.args);
|
|
1248
|
+
sendResponse(id, {});
|
|
1249
|
+
};
|
|
1250
|
+
}
|
|
1251
|
+
resolve(response2);
|
|
1252
|
+
});
|
|
1253
|
+
}),
|
|
1254
|
+
cancel: () => new Promise((resolve) => {
|
|
1255
|
+
if (didDispose) return resolve();
|
|
1256
|
+
const request2 = {
|
|
1257
|
+
command: "cancel",
|
|
1258
|
+
key: buildKey
|
|
1259
|
+
};
|
|
1260
|
+
sendRequest(refs, request2, () => {
|
|
1261
|
+
resolve();
|
|
1262
|
+
});
|
|
1263
|
+
}),
|
|
1264
|
+
dispose: () => new Promise((resolve) => {
|
|
1265
|
+
if (didDispose) return resolve();
|
|
1266
|
+
didDispose = true;
|
|
1267
|
+
const request2 = {
|
|
1268
|
+
command: "dispose",
|
|
1269
|
+
key: buildKey
|
|
1270
|
+
};
|
|
1271
|
+
sendRequest(refs, request2, () => {
|
|
1272
|
+
resolve();
|
|
1273
|
+
scheduleOnDisposeCallbacks();
|
|
1274
|
+
refs.unref();
|
|
1275
|
+
});
|
|
1276
|
+
})
|
|
1277
|
+
};
|
|
1278
|
+
refs.ref();
|
|
1279
|
+
callback(null, result);
|
|
1280
|
+
});
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn, requestCallbacks, initialOptions, plugins, details) => {
|
|
1284
|
+
let onStartCallbacks = [];
|
|
1285
|
+
let onEndCallbacks = [];
|
|
1286
|
+
let onResolveCallbacks = {};
|
|
1287
|
+
let onLoadCallbacks = {};
|
|
1288
|
+
let onDisposeCallbacks = [];
|
|
1289
|
+
let nextCallbackID = 0;
|
|
1290
|
+
let i = 0;
|
|
1291
|
+
let requestPlugins = [];
|
|
1292
|
+
let isSetupDone = false;
|
|
1293
|
+
plugins = [...plugins];
|
|
1294
|
+
for (let item of plugins) {
|
|
1295
|
+
let keys = {};
|
|
1296
|
+
if (typeof item !== "object") throw new Error(`Plugin at index ${i} must be an object`);
|
|
1297
|
+
const name = getFlag(item, keys, "name", mustBeString);
|
|
1298
|
+
if (typeof name !== "string" || name === "") throw new Error(`Plugin at index ${i} is missing a name`);
|
|
1299
|
+
try {
|
|
1300
|
+
let setup = getFlag(item, keys, "setup", mustBeFunction);
|
|
1301
|
+
if (typeof setup !== "function") throw new Error(`Plugin is missing a setup function`);
|
|
1302
|
+
checkForInvalidFlags(item, keys, `on plugin ${quote(name)}`);
|
|
1303
|
+
let plugin = {
|
|
1304
|
+
name,
|
|
1305
|
+
onStart: false,
|
|
1306
|
+
onEnd: false,
|
|
1307
|
+
onResolve: [],
|
|
1308
|
+
onLoad: []
|
|
1309
|
+
};
|
|
1310
|
+
i++;
|
|
1311
|
+
let resolve = (path32, options = {}) => {
|
|
1312
|
+
if (!isSetupDone) throw new Error('Cannot call "resolve" before plugin setup has completed');
|
|
1313
|
+
if (typeof path32 !== "string") throw new Error(`The path to resolve must be a string`);
|
|
1314
|
+
let keys2 = /* @__PURE__ */ Object.create(null);
|
|
1315
|
+
let pluginName = getFlag(options, keys2, "pluginName", mustBeString);
|
|
1316
|
+
let importer = getFlag(options, keys2, "importer", mustBeString);
|
|
1317
|
+
let namespace = getFlag(options, keys2, "namespace", mustBeString);
|
|
1318
|
+
let resolveDir = getFlag(options, keys2, "resolveDir", mustBeString);
|
|
1319
|
+
let kind = getFlag(options, keys2, "kind", mustBeString);
|
|
1320
|
+
let pluginData = getFlag(options, keys2, "pluginData", canBeAnything);
|
|
1321
|
+
let importAttributes = getFlag(options, keys2, "with", mustBeObject);
|
|
1322
|
+
checkForInvalidFlags(options, keys2, "in resolve() call");
|
|
1323
|
+
return new Promise((resolve2, reject) => {
|
|
1324
|
+
const request = {
|
|
1325
|
+
command: "resolve",
|
|
1326
|
+
path: path32,
|
|
1327
|
+
key: buildKey,
|
|
1328
|
+
pluginName: name
|
|
1329
|
+
};
|
|
1330
|
+
if (pluginName != null) request.pluginName = pluginName;
|
|
1331
|
+
if (importer != null) request.importer = importer;
|
|
1332
|
+
if (namespace != null) request.namespace = namespace;
|
|
1333
|
+
if (resolveDir != null) request.resolveDir = resolveDir;
|
|
1334
|
+
if (kind != null) request.kind = kind;
|
|
1335
|
+
else throw new Error(`Must specify "kind" when calling "resolve"`);
|
|
1336
|
+
if (pluginData != null) request.pluginData = details.store(pluginData);
|
|
1337
|
+
if (importAttributes != null) request.with = sanitizeStringMap(importAttributes, "with");
|
|
1338
|
+
sendRequest(refs, request, (error, response) => {
|
|
1339
|
+
if (error !== null) reject(new Error(error));
|
|
1340
|
+
else resolve2({
|
|
1341
|
+
errors: replaceDetailsInMessages(response.errors, details),
|
|
1342
|
+
warnings: replaceDetailsInMessages(response.warnings, details),
|
|
1343
|
+
path: response.path,
|
|
1344
|
+
external: response.external,
|
|
1345
|
+
sideEffects: response.sideEffects,
|
|
1346
|
+
namespace: response.namespace,
|
|
1347
|
+
suffix: response.suffix,
|
|
1348
|
+
pluginData: details.load(response.pluginData)
|
|
1349
|
+
});
|
|
1350
|
+
});
|
|
1351
|
+
});
|
|
1352
|
+
};
|
|
1353
|
+
let promise = setup({
|
|
1354
|
+
initialOptions,
|
|
1355
|
+
resolve,
|
|
1356
|
+
onStart(callback) {
|
|
1357
|
+
let registeredText = `This error came from the "onStart" callback registered here:`;
|
|
1358
|
+
let registeredNote = extractCallerV8(new Error(registeredText), streamIn, "onStart");
|
|
1359
|
+
onStartCallbacks.push({ name, callback, note: registeredNote });
|
|
1360
|
+
plugin.onStart = true;
|
|
1361
|
+
},
|
|
1362
|
+
onEnd(callback) {
|
|
1363
|
+
let registeredText = `This error came from the "onEnd" callback registered here:`;
|
|
1364
|
+
let registeredNote = extractCallerV8(new Error(registeredText), streamIn, "onEnd");
|
|
1365
|
+
onEndCallbacks.push({ name, callback, note: registeredNote });
|
|
1366
|
+
plugin.onEnd = true;
|
|
1367
|
+
},
|
|
1368
|
+
onResolve(options, callback) {
|
|
1369
|
+
let registeredText = `This error came from the "onResolve" callback registered here:`;
|
|
1370
|
+
let registeredNote = extractCallerV8(new Error(registeredText), streamIn, "onResolve");
|
|
1371
|
+
let keys2 = {};
|
|
1372
|
+
let filter = getFlag(options, keys2, "filter", mustBeRegExp);
|
|
1373
|
+
let namespace = getFlag(options, keys2, "namespace", mustBeString);
|
|
1374
|
+
checkForInvalidFlags(options, keys2, `in onResolve() call for plugin ${quote(name)}`);
|
|
1375
|
+
if (filter == null) throw new Error(`onResolve() call is missing a filter`);
|
|
1376
|
+
let id = nextCallbackID++;
|
|
1377
|
+
onResolveCallbacks[id] = { name, callback, note: registeredNote };
|
|
1378
|
+
plugin.onResolve.push({ id, filter: filter.source, namespace: namespace || "" });
|
|
1379
|
+
},
|
|
1380
|
+
onLoad(options, callback) {
|
|
1381
|
+
let registeredText = `This error came from the "onLoad" callback registered here:`;
|
|
1382
|
+
let registeredNote = extractCallerV8(new Error(registeredText), streamIn, "onLoad");
|
|
1383
|
+
let keys2 = {};
|
|
1384
|
+
let filter = getFlag(options, keys2, "filter", mustBeRegExp);
|
|
1385
|
+
let namespace = getFlag(options, keys2, "namespace", mustBeString);
|
|
1386
|
+
checkForInvalidFlags(options, keys2, `in onLoad() call for plugin ${quote(name)}`);
|
|
1387
|
+
if (filter == null) throw new Error(`onLoad() call is missing a filter`);
|
|
1388
|
+
let id = nextCallbackID++;
|
|
1389
|
+
onLoadCallbacks[id] = { name, callback, note: registeredNote };
|
|
1390
|
+
plugin.onLoad.push({ id, filter: filter.source, namespace: namespace || "" });
|
|
1391
|
+
},
|
|
1392
|
+
onDispose(callback) {
|
|
1393
|
+
onDisposeCallbacks.push(callback);
|
|
1394
|
+
},
|
|
1395
|
+
esbuild: streamIn.esbuild
|
|
1396
|
+
});
|
|
1397
|
+
if (promise) await promise;
|
|
1398
|
+
requestPlugins.push(plugin);
|
|
1399
|
+
} catch (e) {
|
|
1400
|
+
return { ok: false, error: e, pluginName: name };
|
|
1401
|
+
}
|
|
1402
|
+
}
|
|
1403
|
+
requestCallbacks["on-start"] = async (id, request) => {
|
|
1404
|
+
let response = { errors: [], warnings: [] };
|
|
1405
|
+
await Promise.all(onStartCallbacks.map(async ({ name, callback, note }) => {
|
|
1406
|
+
try {
|
|
1407
|
+
let result = await callback();
|
|
1408
|
+
if (result != null) {
|
|
1409
|
+
if (typeof result !== "object") throw new Error(`Expected onStart() callback in plugin ${quote(name)} to return an object`);
|
|
1410
|
+
let keys = {};
|
|
1411
|
+
let errors = getFlag(result, keys, "errors", mustBeArray);
|
|
1412
|
+
let warnings = getFlag(result, keys, "warnings", mustBeArray);
|
|
1413
|
+
checkForInvalidFlags(result, keys, `from onStart() callback in plugin ${quote(name)}`);
|
|
1414
|
+
if (errors != null) response.errors.push(...sanitizeMessages(errors, "errors", details, name, void 0));
|
|
1415
|
+
if (warnings != null) response.warnings.push(...sanitizeMessages(warnings, "warnings", details, name, void 0));
|
|
1416
|
+
}
|
|
1417
|
+
} catch (e) {
|
|
1418
|
+
response.errors.push(extractErrorMessageV8(e, streamIn, details, note && note(), name));
|
|
1419
|
+
}
|
|
1420
|
+
}));
|
|
1421
|
+
sendResponse(id, response);
|
|
1422
|
+
};
|
|
1423
|
+
requestCallbacks["on-resolve"] = async (id, request) => {
|
|
1424
|
+
let response = {}, name = "", callback, note;
|
|
1425
|
+
for (let id2 of request.ids) {
|
|
1426
|
+
try {
|
|
1427
|
+
({ name, callback, note } = onResolveCallbacks[id2]);
|
|
1428
|
+
let result = await callback({
|
|
1429
|
+
path: request.path,
|
|
1430
|
+
importer: request.importer,
|
|
1431
|
+
namespace: request.namespace,
|
|
1432
|
+
resolveDir: request.resolveDir,
|
|
1433
|
+
kind: request.kind,
|
|
1434
|
+
pluginData: details.load(request.pluginData),
|
|
1435
|
+
with: request.with
|
|
1436
|
+
});
|
|
1437
|
+
if (result != null) {
|
|
1438
|
+
if (typeof result !== "object") throw new Error(`Expected onResolve() callback in plugin ${quote(name)} to return an object`);
|
|
1439
|
+
let keys = {};
|
|
1440
|
+
let pluginName = getFlag(result, keys, "pluginName", mustBeString);
|
|
1441
|
+
let path32 = getFlag(result, keys, "path", mustBeString);
|
|
1442
|
+
let namespace = getFlag(result, keys, "namespace", mustBeString);
|
|
1443
|
+
let suffix = getFlag(result, keys, "suffix", mustBeString);
|
|
1444
|
+
let external = getFlag(result, keys, "external", mustBeBoolean);
|
|
1445
|
+
let sideEffects = getFlag(result, keys, "sideEffects", mustBeBoolean);
|
|
1446
|
+
let pluginData = getFlag(result, keys, "pluginData", canBeAnything);
|
|
1447
|
+
let errors = getFlag(result, keys, "errors", mustBeArray);
|
|
1448
|
+
let warnings = getFlag(result, keys, "warnings", mustBeArray);
|
|
1449
|
+
let watchFiles = getFlag(result, keys, "watchFiles", mustBeArray);
|
|
1450
|
+
let watchDirs = getFlag(result, keys, "watchDirs", mustBeArray);
|
|
1451
|
+
checkForInvalidFlags(result, keys, `from onResolve() callback in plugin ${quote(name)}`);
|
|
1452
|
+
response.id = id2;
|
|
1453
|
+
if (pluginName != null) response.pluginName = pluginName;
|
|
1454
|
+
if (path32 != null) response.path = path32;
|
|
1455
|
+
if (namespace != null) response.namespace = namespace;
|
|
1456
|
+
if (suffix != null) response.suffix = suffix;
|
|
1457
|
+
if (external != null) response.external = external;
|
|
1458
|
+
if (sideEffects != null) response.sideEffects = sideEffects;
|
|
1459
|
+
if (pluginData != null) response.pluginData = details.store(pluginData);
|
|
1460
|
+
if (errors != null) response.errors = sanitizeMessages(errors, "errors", details, name, void 0);
|
|
1461
|
+
if (warnings != null) response.warnings = sanitizeMessages(warnings, "warnings", details, name, void 0);
|
|
1462
|
+
if (watchFiles != null) response.watchFiles = sanitizeStringArray(watchFiles, "watchFiles");
|
|
1463
|
+
if (watchDirs != null) response.watchDirs = sanitizeStringArray(watchDirs, "watchDirs");
|
|
1464
|
+
break;
|
|
1465
|
+
}
|
|
1466
|
+
} catch (e) {
|
|
1467
|
+
response = { id: id2, errors: [extractErrorMessageV8(e, streamIn, details, note && note(), name)] };
|
|
1468
|
+
break;
|
|
1469
|
+
}
|
|
1470
|
+
}
|
|
1471
|
+
sendResponse(id, response);
|
|
1472
|
+
};
|
|
1473
|
+
requestCallbacks["on-load"] = async (id, request) => {
|
|
1474
|
+
let response = {}, name = "", callback, note;
|
|
1475
|
+
for (let id2 of request.ids) {
|
|
1476
|
+
try {
|
|
1477
|
+
({ name, callback, note } = onLoadCallbacks[id2]);
|
|
1478
|
+
let result = await callback({
|
|
1479
|
+
path: request.path,
|
|
1480
|
+
namespace: request.namespace,
|
|
1481
|
+
suffix: request.suffix,
|
|
1482
|
+
pluginData: details.load(request.pluginData),
|
|
1483
|
+
with: request.with
|
|
1484
|
+
});
|
|
1485
|
+
if (result != null) {
|
|
1486
|
+
if (typeof result !== "object") throw new Error(`Expected onLoad() callback in plugin ${quote(name)} to return an object`);
|
|
1487
|
+
let keys = {};
|
|
1488
|
+
let pluginName = getFlag(result, keys, "pluginName", mustBeString);
|
|
1489
|
+
let contents = getFlag(result, keys, "contents", mustBeStringOrUint8Array);
|
|
1490
|
+
let resolveDir = getFlag(result, keys, "resolveDir", mustBeString);
|
|
1491
|
+
let pluginData = getFlag(result, keys, "pluginData", canBeAnything);
|
|
1492
|
+
let loader = getFlag(result, keys, "loader", mustBeString);
|
|
1493
|
+
let errors = getFlag(result, keys, "errors", mustBeArray);
|
|
1494
|
+
let warnings = getFlag(result, keys, "warnings", mustBeArray);
|
|
1495
|
+
let watchFiles = getFlag(result, keys, "watchFiles", mustBeArray);
|
|
1496
|
+
let watchDirs = getFlag(result, keys, "watchDirs", mustBeArray);
|
|
1497
|
+
checkForInvalidFlags(result, keys, `from onLoad() callback in plugin ${quote(name)}`);
|
|
1498
|
+
response.id = id2;
|
|
1499
|
+
if (pluginName != null) response.pluginName = pluginName;
|
|
1500
|
+
if (contents instanceof Uint8Array) response.contents = contents;
|
|
1501
|
+
else if (contents != null) response.contents = encodeUTF8(contents);
|
|
1502
|
+
if (resolveDir != null) response.resolveDir = resolveDir;
|
|
1503
|
+
if (pluginData != null) response.pluginData = details.store(pluginData);
|
|
1504
|
+
if (loader != null) response.loader = loader;
|
|
1505
|
+
if (errors != null) response.errors = sanitizeMessages(errors, "errors", details, name, void 0);
|
|
1506
|
+
if (warnings != null) response.warnings = sanitizeMessages(warnings, "warnings", details, name, void 0);
|
|
1507
|
+
if (watchFiles != null) response.watchFiles = sanitizeStringArray(watchFiles, "watchFiles");
|
|
1508
|
+
if (watchDirs != null) response.watchDirs = sanitizeStringArray(watchDirs, "watchDirs");
|
|
1509
|
+
break;
|
|
1510
|
+
}
|
|
1511
|
+
} catch (e) {
|
|
1512
|
+
response = { id: id2, errors: [extractErrorMessageV8(e, streamIn, details, note && note(), name)] };
|
|
1513
|
+
break;
|
|
1514
|
+
}
|
|
1515
|
+
}
|
|
1516
|
+
sendResponse(id, response);
|
|
1517
|
+
};
|
|
1518
|
+
let runOnEndCallbacks = (result, done) => done([], []);
|
|
1519
|
+
if (onEndCallbacks.length > 0) {
|
|
1520
|
+
runOnEndCallbacks = (result, done) => {
|
|
1521
|
+
(async () => {
|
|
1522
|
+
const onEndErrors = [];
|
|
1523
|
+
const onEndWarnings = [];
|
|
1524
|
+
for (const { name, callback, note } of onEndCallbacks) {
|
|
1525
|
+
let newErrors;
|
|
1526
|
+
let newWarnings;
|
|
1527
|
+
try {
|
|
1528
|
+
const value = await callback(result);
|
|
1529
|
+
if (value != null) {
|
|
1530
|
+
if (typeof value !== "object") throw new Error(`Expected onEnd() callback in plugin ${quote(name)} to return an object`);
|
|
1531
|
+
let keys = {};
|
|
1532
|
+
let errors = getFlag(value, keys, "errors", mustBeArray);
|
|
1533
|
+
let warnings = getFlag(value, keys, "warnings", mustBeArray);
|
|
1534
|
+
checkForInvalidFlags(value, keys, `from onEnd() callback in plugin ${quote(name)}`);
|
|
1535
|
+
if (errors != null) newErrors = sanitizeMessages(errors, "errors", details, name, void 0);
|
|
1536
|
+
if (warnings != null) newWarnings = sanitizeMessages(warnings, "warnings", details, name, void 0);
|
|
1537
|
+
}
|
|
1538
|
+
} catch (e) {
|
|
1539
|
+
newErrors = [extractErrorMessageV8(e, streamIn, details, note && note(), name)];
|
|
1540
|
+
}
|
|
1541
|
+
if (newErrors) {
|
|
1542
|
+
onEndErrors.push(...newErrors);
|
|
1543
|
+
try {
|
|
1544
|
+
result.errors.push(...newErrors);
|
|
1545
|
+
} catch {
|
|
1546
|
+
}
|
|
1547
|
+
}
|
|
1548
|
+
if (newWarnings) {
|
|
1549
|
+
onEndWarnings.push(...newWarnings);
|
|
1550
|
+
try {
|
|
1551
|
+
result.warnings.push(...newWarnings);
|
|
1552
|
+
} catch {
|
|
1553
|
+
}
|
|
1554
|
+
}
|
|
1555
|
+
}
|
|
1556
|
+
done(onEndErrors, onEndWarnings);
|
|
1557
|
+
})();
|
|
1558
|
+
};
|
|
1559
|
+
}
|
|
1560
|
+
let scheduleOnDisposeCallbacks = () => {
|
|
1561
|
+
for (const cb of onDisposeCallbacks) {
|
|
1562
|
+
setTimeout(() => cb(), 0);
|
|
1563
|
+
}
|
|
1564
|
+
};
|
|
1565
|
+
isSetupDone = true;
|
|
1566
|
+
return {
|
|
1567
|
+
ok: true,
|
|
1568
|
+
requestPlugins,
|
|
1569
|
+
runOnEndCallbacks,
|
|
1570
|
+
scheduleOnDisposeCallbacks
|
|
1571
|
+
};
|
|
1572
|
+
};
|
|
1573
|
+
function createObjectStash() {
|
|
1574
|
+
const map = /* @__PURE__ */ new Map();
|
|
1575
|
+
let nextID = 0;
|
|
1576
|
+
return {
|
|
1577
|
+
load(id) {
|
|
1578
|
+
return map.get(id);
|
|
1579
|
+
},
|
|
1580
|
+
store(value) {
|
|
1581
|
+
if (value === void 0) return -1;
|
|
1582
|
+
const id = nextID++;
|
|
1583
|
+
map.set(id, value);
|
|
1584
|
+
return id;
|
|
1585
|
+
}
|
|
1586
|
+
};
|
|
1587
|
+
}
|
|
1588
|
+
function extractCallerV8(e, streamIn, ident) {
|
|
1589
|
+
let note;
|
|
1590
|
+
let tried = false;
|
|
1591
|
+
return () => {
|
|
1592
|
+
if (tried) return note;
|
|
1593
|
+
tried = true;
|
|
1594
|
+
try {
|
|
1595
|
+
let lines = (e.stack + "").split("\n");
|
|
1596
|
+
lines.splice(1, 1);
|
|
1597
|
+
let location = parseStackLinesV8(streamIn, lines, ident);
|
|
1598
|
+
if (location) {
|
|
1599
|
+
note = { text: e.message, location };
|
|
1600
|
+
return note;
|
|
1601
|
+
}
|
|
1602
|
+
} catch {
|
|
1603
|
+
}
|
|
1604
|
+
};
|
|
1605
|
+
}
|
|
1606
|
+
function extractErrorMessageV8(e, streamIn, stash, note, pluginName) {
|
|
1607
|
+
let text = "Internal error";
|
|
1608
|
+
let location = null;
|
|
1609
|
+
try {
|
|
1610
|
+
text = (e && e.message || e) + "";
|
|
1611
|
+
} catch {
|
|
1612
|
+
}
|
|
1613
|
+
try {
|
|
1614
|
+
location = parseStackLinesV8(streamIn, (e.stack + "").split("\n"), "");
|
|
1615
|
+
} catch {
|
|
1616
|
+
}
|
|
1617
|
+
return { id: "", pluginName, text, location, notes: note ? [note] : [], detail: stash ? stash.store(e) : -1 };
|
|
1618
|
+
}
|
|
1619
|
+
function parseStackLinesV8(streamIn, lines, ident) {
|
|
1620
|
+
let at = " at ";
|
|
1621
|
+
if (streamIn.readFileSync && !lines[0].startsWith(at) && lines[1].startsWith(at)) {
|
|
1622
|
+
for (let i = 1; i < lines.length; i++) {
|
|
1623
|
+
let line = lines[i];
|
|
1624
|
+
if (!line.startsWith(at)) continue;
|
|
1625
|
+
line = line.slice(at.length);
|
|
1626
|
+
while (true) {
|
|
1627
|
+
let match = /^(?:new |async )?\S+ \((.*)\)$/.exec(line);
|
|
1628
|
+
if (match) {
|
|
1629
|
+
line = match[1];
|
|
1630
|
+
continue;
|
|
1631
|
+
}
|
|
1632
|
+
match = /^eval at \S+ \((.*)\)(?:, \S+:\d+:\d+)?$/.exec(line);
|
|
1633
|
+
if (match) {
|
|
1634
|
+
line = match[1];
|
|
1635
|
+
continue;
|
|
1636
|
+
}
|
|
1637
|
+
match = /^(\S+):(\d+):(\d+)$/.exec(line);
|
|
1638
|
+
if (match) {
|
|
1639
|
+
let contents;
|
|
1640
|
+
try {
|
|
1641
|
+
contents = streamIn.readFileSync(match[1], "utf8");
|
|
1642
|
+
} catch {
|
|
1643
|
+
break;
|
|
1644
|
+
}
|
|
1645
|
+
let lineText = contents.split(/\r\n|\r|\n|\u2028|\u2029/)[+match[2] - 1] || "";
|
|
1646
|
+
let column = +match[3] - 1;
|
|
1647
|
+
let length = lineText.slice(column, column + ident.length) === ident ? ident.length : 0;
|
|
1648
|
+
return {
|
|
1649
|
+
file: match[1],
|
|
1650
|
+
namespace: "file",
|
|
1651
|
+
line: +match[2],
|
|
1652
|
+
column: encodeUTF8(lineText.slice(0, column)).length,
|
|
1653
|
+
length: encodeUTF8(lineText.slice(column, column + length)).length,
|
|
1654
|
+
lineText: lineText + "\n" + lines.slice(1).join("\n"),
|
|
1655
|
+
suggestion: ""
|
|
1656
|
+
};
|
|
1657
|
+
}
|
|
1658
|
+
break;
|
|
1659
|
+
}
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
return null;
|
|
1663
|
+
}
|
|
1664
|
+
function failureErrorWithLog(text, errors, warnings) {
|
|
1665
|
+
let limit = 5;
|
|
1666
|
+
text += errors.length < 1 ? "" : ` with ${errors.length} error${errors.length < 2 ? "" : "s"}:` + errors.slice(0, limit + 1).map((e, i) => {
|
|
1667
|
+
if (i === limit) return "\n...";
|
|
1668
|
+
if (!e.location) return `
|
|
1669
|
+
error: ${e.text}`;
|
|
1670
|
+
let { file, line, column } = e.location;
|
|
1671
|
+
let pluginText = e.pluginName ? `[plugin: ${e.pluginName}] ` : "";
|
|
1672
|
+
return `
|
|
1673
|
+
${file}:${line}:${column}: ERROR: ${pluginText}${e.text}`;
|
|
1674
|
+
}).join("");
|
|
1675
|
+
let error = new Error(text);
|
|
1676
|
+
for (const [key, value] of [["errors", errors], ["warnings", warnings]]) {
|
|
1677
|
+
Object.defineProperty(error, key, {
|
|
1678
|
+
configurable: true,
|
|
1679
|
+
enumerable: true,
|
|
1680
|
+
get: () => value,
|
|
1681
|
+
set: (value2) => Object.defineProperty(error, key, {
|
|
1682
|
+
configurable: true,
|
|
1683
|
+
enumerable: true,
|
|
1684
|
+
value: value2
|
|
1685
|
+
})
|
|
1686
|
+
});
|
|
1687
|
+
}
|
|
1688
|
+
return error;
|
|
1689
|
+
}
|
|
1690
|
+
function replaceDetailsInMessages(messages, stash) {
|
|
1691
|
+
for (const message of messages) {
|
|
1692
|
+
message.detail = stash.load(message.detail);
|
|
1693
|
+
}
|
|
1694
|
+
return messages;
|
|
1695
|
+
}
|
|
1696
|
+
function sanitizeLocation(location, where, terminalWidth) {
|
|
1697
|
+
if (location == null) return null;
|
|
1698
|
+
let keys = {};
|
|
1699
|
+
let file = getFlag(location, keys, "file", mustBeString);
|
|
1700
|
+
let namespace = getFlag(location, keys, "namespace", mustBeString);
|
|
1701
|
+
let line = getFlag(location, keys, "line", mustBeInteger);
|
|
1702
|
+
let column = getFlag(location, keys, "column", mustBeInteger);
|
|
1703
|
+
let length = getFlag(location, keys, "length", mustBeInteger);
|
|
1704
|
+
let lineText = getFlag(location, keys, "lineText", mustBeString);
|
|
1705
|
+
let suggestion = getFlag(location, keys, "suggestion", mustBeString);
|
|
1706
|
+
checkForInvalidFlags(location, keys, where);
|
|
1707
|
+
if (lineText) {
|
|
1708
|
+
const relevantASCII = lineText.slice(
|
|
1709
|
+
0,
|
|
1710
|
+
(column && column > 0 ? column : 0) + (length && length > 0 ? length : 0) + (terminalWidth && terminalWidth > 0 ? terminalWidth : 80)
|
|
1711
|
+
);
|
|
1712
|
+
if (!/[\x7F-\uFFFF]/.test(relevantASCII) && !/\n/.test(lineText)) {
|
|
1713
|
+
lineText = relevantASCII;
|
|
1714
|
+
}
|
|
1715
|
+
}
|
|
1716
|
+
return {
|
|
1717
|
+
file: file || "",
|
|
1718
|
+
namespace: namespace || "",
|
|
1719
|
+
line: line || 0,
|
|
1720
|
+
column: column || 0,
|
|
1721
|
+
length: length || 0,
|
|
1722
|
+
lineText: lineText || "",
|
|
1723
|
+
suggestion: suggestion || ""
|
|
1724
|
+
};
|
|
1725
|
+
}
|
|
1726
|
+
function sanitizeMessages(messages, property, stash, fallbackPluginName, terminalWidth) {
|
|
1727
|
+
let messagesClone = [];
|
|
1728
|
+
let index = 0;
|
|
1729
|
+
for (const message of messages) {
|
|
1730
|
+
let keys = {};
|
|
1731
|
+
let id = getFlag(message, keys, "id", mustBeString);
|
|
1732
|
+
let pluginName = getFlag(message, keys, "pluginName", mustBeString);
|
|
1733
|
+
let text = getFlag(message, keys, "text", mustBeString);
|
|
1734
|
+
let location = getFlag(message, keys, "location", mustBeObjectOrNull);
|
|
1735
|
+
let notes = getFlag(message, keys, "notes", mustBeArray);
|
|
1736
|
+
let detail = getFlag(message, keys, "detail", canBeAnything);
|
|
1737
|
+
let where = `in element ${index} of "${property}"`;
|
|
1738
|
+
checkForInvalidFlags(message, keys, where);
|
|
1739
|
+
let notesClone = [];
|
|
1740
|
+
if (notes) {
|
|
1741
|
+
for (const note of notes) {
|
|
1742
|
+
let noteKeys = {};
|
|
1743
|
+
let noteText = getFlag(note, noteKeys, "text", mustBeString);
|
|
1744
|
+
let noteLocation = getFlag(note, noteKeys, "location", mustBeObjectOrNull);
|
|
1745
|
+
checkForInvalidFlags(note, noteKeys, where);
|
|
1746
|
+
notesClone.push({
|
|
1747
|
+
text: noteText || "",
|
|
1748
|
+
location: sanitizeLocation(noteLocation, where, terminalWidth)
|
|
1749
|
+
});
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1752
|
+
messagesClone.push({
|
|
1753
|
+
id: id || "",
|
|
1754
|
+
pluginName: pluginName || fallbackPluginName,
|
|
1755
|
+
text: text || "",
|
|
1756
|
+
location: sanitizeLocation(location, where, terminalWidth),
|
|
1757
|
+
notes: notesClone,
|
|
1758
|
+
detail: stash ? stash.store(detail) : -1
|
|
1759
|
+
});
|
|
1760
|
+
index++;
|
|
1761
|
+
}
|
|
1762
|
+
return messagesClone;
|
|
1763
|
+
}
|
|
1764
|
+
function sanitizeStringArray(values, property) {
|
|
1765
|
+
const result = [];
|
|
1766
|
+
for (const value of values) {
|
|
1767
|
+
if (typeof value !== "string") throw new Error(`${quote(property)} must be an array of strings`);
|
|
1768
|
+
result.push(value);
|
|
1769
|
+
}
|
|
1770
|
+
return result;
|
|
1771
|
+
}
|
|
1772
|
+
function sanitizeStringMap(map, property) {
|
|
1773
|
+
const result = /* @__PURE__ */ Object.create(null);
|
|
1774
|
+
for (const key in map) {
|
|
1775
|
+
const value = map[key];
|
|
1776
|
+
if (typeof value !== "string") throw new Error(`key ${quote(key)} in object ${quote(property)} must be a string`);
|
|
1777
|
+
result[key] = value;
|
|
1778
|
+
}
|
|
1779
|
+
return result;
|
|
1780
|
+
}
|
|
1781
|
+
function convertOutputFiles({ path: path32, contents, hash }) {
|
|
1782
|
+
let text = null;
|
|
1783
|
+
return {
|
|
1784
|
+
path: path32,
|
|
1785
|
+
contents,
|
|
1786
|
+
hash,
|
|
1787
|
+
get text() {
|
|
1788
|
+
const binary = this.contents;
|
|
1789
|
+
if (text === null || binary !== contents) {
|
|
1790
|
+
contents = binary;
|
|
1791
|
+
text = decodeUTF8(binary);
|
|
1792
|
+
}
|
|
1793
|
+
return text;
|
|
1794
|
+
}
|
|
1795
|
+
};
|
|
1796
|
+
}
|
|
1797
|
+
var fs3 = require("fs");
|
|
1798
|
+
var os2 = require("os");
|
|
1799
|
+
var path3 = require("path");
|
|
1800
|
+
var ESBUILD_BINARY_PATH = process.env.ESBUILD_BINARY_PATH || ESBUILD_BINARY_PATH;
|
|
1801
|
+
var isValidBinaryPath = (x) => !!x && x !== "/usr/bin/esbuild";
|
|
1802
|
+
var packageDarwin_arm64 = "@esbuild/darwin-arm64";
|
|
1803
|
+
var packageDarwin_x64 = "@esbuild/darwin-x64";
|
|
1804
|
+
var knownWindowsPackages = {
|
|
1805
|
+
"win32 arm64 LE": "@esbuild/win32-arm64",
|
|
1806
|
+
"win32 ia32 LE": "@esbuild/win32-ia32",
|
|
1807
|
+
"win32 x64 LE": "@esbuild/win32-x64"
|
|
1808
|
+
};
|
|
1809
|
+
var knownUnixlikePackages = {
|
|
1810
|
+
"aix ppc64 BE": "@esbuild/aix-ppc64",
|
|
1811
|
+
"android arm64 LE": "@esbuild/android-arm64",
|
|
1812
|
+
"darwin arm64 LE": "@esbuild/darwin-arm64",
|
|
1813
|
+
"darwin x64 LE": "@esbuild/darwin-x64",
|
|
1814
|
+
"freebsd arm64 LE": "@esbuild/freebsd-arm64",
|
|
1815
|
+
"freebsd x64 LE": "@esbuild/freebsd-x64",
|
|
1816
|
+
"linux arm LE": "@esbuild/linux-arm",
|
|
1817
|
+
"linux arm64 LE": "@esbuild/linux-arm64",
|
|
1818
|
+
"linux ia32 LE": "@esbuild/linux-ia32",
|
|
1819
|
+
"linux mips64el LE": "@esbuild/linux-mips64el",
|
|
1820
|
+
"linux ppc64 LE": "@esbuild/linux-ppc64",
|
|
1821
|
+
"linux riscv64 LE": "@esbuild/linux-riscv64",
|
|
1822
|
+
"linux s390x BE": "@esbuild/linux-s390x",
|
|
1823
|
+
"linux x64 LE": "@esbuild/linux-x64",
|
|
1824
|
+
"linux loong64 LE": "@esbuild/linux-loong64",
|
|
1825
|
+
"netbsd x64 LE": "@esbuild/netbsd-x64",
|
|
1826
|
+
"openbsd x64 LE": "@esbuild/openbsd-x64",
|
|
1827
|
+
"sunos x64 LE": "@esbuild/sunos-x64"
|
|
1828
|
+
};
|
|
1829
|
+
var knownWebAssemblyFallbackPackages = {
|
|
1830
|
+
"android arm LE": "@esbuild/android-arm",
|
|
1831
|
+
"android x64 LE": "@esbuild/android-x64"
|
|
1832
|
+
};
|
|
1833
|
+
function pkgAndSubpathForCurrentPlatform() {
|
|
1834
|
+
let pkg;
|
|
1835
|
+
let subpath;
|
|
1836
|
+
let isWASM = false;
|
|
1837
|
+
let platformKey = `${process.platform} ${os2.arch()} ${os2.endianness()}`;
|
|
1838
|
+
if (platformKey in knownWindowsPackages) {
|
|
1839
|
+
pkg = knownWindowsPackages[platformKey];
|
|
1840
|
+
subpath = "esbuild.exe";
|
|
1841
|
+
} else if (platformKey in knownUnixlikePackages) {
|
|
1842
|
+
pkg = knownUnixlikePackages[platformKey];
|
|
1843
|
+
subpath = "bin/esbuild";
|
|
1844
|
+
} else if (platformKey in knownWebAssemblyFallbackPackages) {
|
|
1845
|
+
pkg = knownWebAssemblyFallbackPackages[platformKey];
|
|
1846
|
+
subpath = "bin/esbuild";
|
|
1847
|
+
isWASM = true;
|
|
1848
|
+
} else {
|
|
1849
|
+
throw new Error(`Unsupported platform: ${platformKey}`);
|
|
1850
|
+
}
|
|
1851
|
+
return { pkg, subpath, isWASM };
|
|
1852
|
+
}
|
|
1853
|
+
function pkgForSomeOtherPlatform() {
|
|
1854
|
+
const libMainJS = require.resolve("esbuild");
|
|
1855
|
+
const nodeModulesDirectory = path3.dirname(path3.dirname(path3.dirname(libMainJS)));
|
|
1856
|
+
if (path3.basename(nodeModulesDirectory) === "node_modules") {
|
|
1857
|
+
for (const unixKey in knownUnixlikePackages) {
|
|
1858
|
+
try {
|
|
1859
|
+
const pkg = knownUnixlikePackages[unixKey];
|
|
1860
|
+
if (fs3.existsSync(path3.join(nodeModulesDirectory, pkg))) return pkg;
|
|
1861
|
+
} catch {
|
|
1862
|
+
}
|
|
1863
|
+
}
|
|
1864
|
+
for (const windowsKey in knownWindowsPackages) {
|
|
1865
|
+
try {
|
|
1866
|
+
const pkg = knownWindowsPackages[windowsKey];
|
|
1867
|
+
if (fs3.existsSync(path3.join(nodeModulesDirectory, pkg))) return pkg;
|
|
1868
|
+
} catch {
|
|
1869
|
+
}
|
|
1870
|
+
}
|
|
1871
|
+
}
|
|
1872
|
+
return null;
|
|
1873
|
+
}
|
|
1874
|
+
function downloadedBinPath(pkg, subpath) {
|
|
1875
|
+
const esbuildLibDir = path3.dirname(require.resolve("esbuild"));
|
|
1876
|
+
return path3.join(esbuildLibDir, `downloaded-${pkg.replace("/", "-")}-${path3.basename(subpath)}`);
|
|
1877
|
+
}
|
|
1878
|
+
function generateBinPath() {
|
|
1879
|
+
if (isValidBinaryPath(ESBUILD_BINARY_PATH)) {
|
|
1880
|
+
if (!fs3.existsSync(ESBUILD_BINARY_PATH)) {
|
|
1881
|
+
console.warn(`[esbuild] Ignoring bad configuration: ESBUILD_BINARY_PATH=${ESBUILD_BINARY_PATH}`);
|
|
1882
|
+
} else {
|
|
1883
|
+
return { binPath: ESBUILD_BINARY_PATH, isWASM: false };
|
|
1884
|
+
}
|
|
1885
|
+
}
|
|
1886
|
+
const { pkg, subpath, isWASM } = pkgAndSubpathForCurrentPlatform();
|
|
1887
|
+
let binPath;
|
|
1888
|
+
try {
|
|
1889
|
+
binPath = require.resolve(`${pkg}/${subpath}`);
|
|
1890
|
+
} catch (e) {
|
|
1891
|
+
binPath = downloadedBinPath(pkg, subpath);
|
|
1892
|
+
if (!fs3.existsSync(binPath)) {
|
|
1893
|
+
try {
|
|
1894
|
+
require.resolve(pkg);
|
|
1895
|
+
} catch {
|
|
1896
|
+
const otherPkg = pkgForSomeOtherPlatform();
|
|
1897
|
+
if (otherPkg) {
|
|
1898
|
+
let suggestions = `
|
|
1899
|
+
Specifically the "${otherPkg}" package is present but this platform
|
|
1900
|
+
needs the "${pkg}" package instead. People often get into this
|
|
1901
|
+
situation by installing esbuild on Windows or macOS and copying "node_modules"
|
|
1902
|
+
into a Docker image that runs Linux, or by copying "node_modules" between
|
|
1903
|
+
Windows and WSL environments.
|
|
1904
|
+
|
|
1905
|
+
If you are installing with npm, you can try not copying the "node_modules"
|
|
1906
|
+
directory when you copy the files over, and running "npm ci" or "npm install"
|
|
1907
|
+
on the destination platform after the copy. Or you could consider using yarn
|
|
1908
|
+
instead of npm which has built-in support for installing a package on multiple
|
|
1909
|
+
platforms simultaneously.
|
|
1910
|
+
|
|
1911
|
+
If you are installing with yarn, you can try listing both this platform and the
|
|
1912
|
+
other platform in your ".yarnrc.yml" file using the "supportedArchitectures"
|
|
1913
|
+
feature: https://yarnpkg.com/configuration/yarnrc/#supportedArchitectures
|
|
1914
|
+
Keep in mind that this means multiple copies of esbuild will be present.
|
|
1915
|
+
`;
|
|
1916
|
+
if (pkg === packageDarwin_x64 && otherPkg === packageDarwin_arm64 || pkg === packageDarwin_arm64 && otherPkg === packageDarwin_x64) {
|
|
1917
|
+
suggestions = `
|
|
1918
|
+
Specifically the "${otherPkg}" package is present but this platform
|
|
1919
|
+
needs the "${pkg}" package instead. People often get into this
|
|
1920
|
+
situation by installing esbuild with npm running inside of Rosetta 2 and then
|
|
1921
|
+
trying to use it with node running outside of Rosetta 2, or vice versa (Rosetta
|
|
1922
|
+
2 is Apple's on-the-fly x86_64-to-arm64 translation service).
|
|
1923
|
+
|
|
1924
|
+
If you are installing with npm, you can try ensuring that both npm and node are
|
|
1925
|
+
not running under Rosetta 2 and then reinstalling esbuild. This likely involves
|
|
1926
|
+
changing how you installed npm and/or node. For example, installing node with
|
|
1927
|
+
the universal installer here should work: https://nodejs.org/en/download/. Or
|
|
1928
|
+
you could consider using yarn instead of npm which has built-in support for
|
|
1929
|
+
installing a package on multiple platforms simultaneously.
|
|
1930
|
+
|
|
1931
|
+
If you are installing with yarn, you can try listing both "arm64" and "x64"
|
|
1932
|
+
in your ".yarnrc.yml" file using the "supportedArchitectures" feature:
|
|
1933
|
+
https://yarnpkg.com/configuration/yarnrc/#supportedArchitectures
|
|
1934
|
+
Keep in mind that this means multiple copies of esbuild will be present.
|
|
1935
|
+
`;
|
|
1936
|
+
}
|
|
1937
|
+
throw new Error(`
|
|
1938
|
+
You installed esbuild for another platform than the one you're currently using.
|
|
1939
|
+
This won't work because esbuild is written with native code and needs to
|
|
1940
|
+
install a platform-specific binary executable.
|
|
1941
|
+
${suggestions}
|
|
1942
|
+
Another alternative is to use the "esbuild-wasm" package instead, which works
|
|
1943
|
+
the same way on all platforms. But it comes with a heavy performance cost and
|
|
1944
|
+
can sometimes be 10x slower than the "esbuild" package, so you may also not
|
|
1945
|
+
want to do that.
|
|
1946
|
+
`);
|
|
1947
|
+
}
|
|
1948
|
+
throw new Error(`The package "${pkg}" could not be found, and is needed by esbuild.
|
|
1949
|
+
|
|
1950
|
+
If you are installing esbuild with npm, make sure that you don't specify the
|
|
1951
|
+
"--no-optional" or "--omit=optional" flags. The "optionalDependencies" feature
|
|
1952
|
+
of "package.json" is used by esbuild to install the correct binary executable
|
|
1953
|
+
for your current platform.`);
|
|
1954
|
+
}
|
|
1955
|
+
throw e;
|
|
1956
|
+
}
|
|
1957
|
+
}
|
|
1958
|
+
if (/\.zip\//.test(binPath)) {
|
|
1959
|
+
let pnpapi;
|
|
1960
|
+
try {
|
|
1961
|
+
pnpapi = require("pnpapi");
|
|
1962
|
+
} catch (e) {
|
|
1963
|
+
}
|
|
1964
|
+
if (pnpapi) {
|
|
1965
|
+
const root = pnpapi.getPackageInformation(pnpapi.topLevel).packageLocation;
|
|
1966
|
+
const binTargetPath = path3.join(
|
|
1967
|
+
root,
|
|
1968
|
+
"node_modules",
|
|
1969
|
+
".cache",
|
|
1970
|
+
"esbuild",
|
|
1971
|
+
`pnpapi-${pkg.replace("/", "-")}-${"0.21.5"}-${path3.basename(subpath)}`
|
|
1972
|
+
);
|
|
1973
|
+
if (!fs3.existsSync(binTargetPath)) {
|
|
1974
|
+
fs3.mkdirSync(path3.dirname(binTargetPath), { recursive: true });
|
|
1975
|
+
fs3.copyFileSync(binPath, binTargetPath);
|
|
1976
|
+
fs3.chmodSync(binTargetPath, 493);
|
|
1977
|
+
}
|
|
1978
|
+
return { binPath: binTargetPath, isWASM };
|
|
1979
|
+
}
|
|
1980
|
+
}
|
|
1981
|
+
return { binPath, isWASM };
|
|
1982
|
+
}
|
|
1983
|
+
var child_process = require("child_process");
|
|
1984
|
+
var crypto = require("crypto");
|
|
1985
|
+
var path22 = require("path");
|
|
1986
|
+
var fs22 = require("fs");
|
|
1987
|
+
var os22 = require("os");
|
|
1988
|
+
var tty = require("tty");
|
|
1989
|
+
var worker_threads;
|
|
1990
|
+
if (process.env.ESBUILD_WORKER_THREADS !== "0") {
|
|
1991
|
+
try {
|
|
1992
|
+
worker_threads = require("worker_threads");
|
|
1993
|
+
} catch {
|
|
1994
|
+
}
|
|
1995
|
+
let [major, minor] = process.versions.node.split(".");
|
|
1996
|
+
if (
|
|
1997
|
+
// <v12.17.0 does not work
|
|
1998
|
+
+major < 12 || +major === 12 && +minor < 17 || +major === 13 && +minor < 13
|
|
1999
|
+
) {
|
|
2000
|
+
worker_threads = void 0;
|
|
2001
|
+
}
|
|
2002
|
+
}
|
|
2003
|
+
var _a;
|
|
2004
|
+
var isInternalWorkerThread = ((_a = worker_threads == null ? void 0 : worker_threads.workerData) == null ? void 0 : _a.esbuildVersion) === "0.21.5";
|
|
2005
|
+
var esbuildCommandAndArgs = () => {
|
|
2006
|
+
if ((!ESBUILD_BINARY_PATH || false) && (path22.basename(__filename) !== "main.js" || path22.basename(__dirname) !== "lib")) {
|
|
2007
|
+
throw new Error(
|
|
2008
|
+
`The esbuild JavaScript API cannot be bundled. Please mark the "esbuild" package as external so it's not included in the bundle.
|
|
2009
|
+
|
|
2010
|
+
More information: The file containing the code for esbuild's JavaScript API (${__filename}) does not appear to be inside the esbuild package on the file system, which usually means that the esbuild package was bundled into another file. This is problematic because the API needs to run a binary executable inside the esbuild package which is located using a relative path from the API code to the executable. If the esbuild package is bundled, the relative path will be incorrect and the executable won't be found.`
|
|
2011
|
+
);
|
|
2012
|
+
}
|
|
2013
|
+
if (false) {
|
|
2014
|
+
return ["node", [path22.join(__dirname, "..", "bin", "esbuild")]];
|
|
2015
|
+
} else {
|
|
2016
|
+
const { binPath, isWASM } = generateBinPath();
|
|
2017
|
+
if (isWASM) {
|
|
2018
|
+
return ["node", [binPath]];
|
|
2019
|
+
} else {
|
|
2020
|
+
return [binPath, []];
|
|
2021
|
+
}
|
|
2022
|
+
}
|
|
2023
|
+
};
|
|
2024
|
+
var isTTY = () => tty.isatty(2);
|
|
2025
|
+
var fsSync = {
|
|
2026
|
+
readFile(tempFile, callback) {
|
|
2027
|
+
try {
|
|
2028
|
+
let contents = fs22.readFileSync(tempFile, "utf8");
|
|
2029
|
+
try {
|
|
2030
|
+
fs22.unlinkSync(tempFile);
|
|
2031
|
+
} catch {
|
|
2032
|
+
}
|
|
2033
|
+
callback(null, contents);
|
|
2034
|
+
} catch (err) {
|
|
2035
|
+
callback(err, null);
|
|
2036
|
+
}
|
|
2037
|
+
},
|
|
2038
|
+
writeFile(contents, callback) {
|
|
2039
|
+
try {
|
|
2040
|
+
let tempFile = randomFileName();
|
|
2041
|
+
fs22.writeFileSync(tempFile, contents);
|
|
2042
|
+
callback(tempFile);
|
|
2043
|
+
} catch {
|
|
2044
|
+
callback(null);
|
|
2045
|
+
}
|
|
2046
|
+
}
|
|
2047
|
+
};
|
|
2048
|
+
var fsAsync = {
|
|
2049
|
+
readFile(tempFile, callback) {
|
|
2050
|
+
try {
|
|
2051
|
+
fs22.readFile(tempFile, "utf8", (err, contents) => {
|
|
2052
|
+
try {
|
|
2053
|
+
fs22.unlink(tempFile, () => callback(err, contents));
|
|
2054
|
+
} catch {
|
|
2055
|
+
callback(err, contents);
|
|
2056
|
+
}
|
|
2057
|
+
});
|
|
2058
|
+
} catch (err) {
|
|
2059
|
+
callback(err, null);
|
|
2060
|
+
}
|
|
2061
|
+
},
|
|
2062
|
+
writeFile(contents, callback) {
|
|
2063
|
+
try {
|
|
2064
|
+
let tempFile = randomFileName();
|
|
2065
|
+
fs22.writeFile(tempFile, contents, (err) => err !== null ? callback(null) : callback(tempFile));
|
|
2066
|
+
} catch {
|
|
2067
|
+
callback(null);
|
|
2068
|
+
}
|
|
2069
|
+
}
|
|
2070
|
+
};
|
|
2071
|
+
var version = "0.21.5";
|
|
2072
|
+
var build = (options) => ensureServiceIsRunning().build(options);
|
|
2073
|
+
var context = (buildOptions) => ensureServiceIsRunning().context(buildOptions);
|
|
2074
|
+
var transform = (input, options) => ensureServiceIsRunning().transform(input, options);
|
|
2075
|
+
var formatMessages = (messages, options) => ensureServiceIsRunning().formatMessages(messages, options);
|
|
2076
|
+
var analyzeMetafile = (messages, options) => ensureServiceIsRunning().analyzeMetafile(messages, options);
|
|
2077
|
+
var buildSync = (options) => {
|
|
2078
|
+
if (worker_threads && !isInternalWorkerThread) {
|
|
2079
|
+
if (!workerThreadService) workerThreadService = startWorkerThreadService(worker_threads);
|
|
2080
|
+
return workerThreadService.buildSync(options);
|
|
2081
|
+
}
|
|
2082
|
+
let result;
|
|
2083
|
+
runServiceSync((service) => service.buildOrContext({
|
|
2084
|
+
callName: "buildSync",
|
|
2085
|
+
refs: null,
|
|
2086
|
+
options,
|
|
2087
|
+
isTTY: isTTY(),
|
|
2088
|
+
defaultWD,
|
|
2089
|
+
callback: (err, res) => {
|
|
2090
|
+
if (err) throw err;
|
|
2091
|
+
result = res;
|
|
2092
|
+
}
|
|
2093
|
+
}));
|
|
2094
|
+
return result;
|
|
2095
|
+
};
|
|
2096
|
+
var transformSync = (input, options) => {
|
|
2097
|
+
if (worker_threads && !isInternalWorkerThread) {
|
|
2098
|
+
if (!workerThreadService) workerThreadService = startWorkerThreadService(worker_threads);
|
|
2099
|
+
return workerThreadService.transformSync(input, options);
|
|
2100
|
+
}
|
|
2101
|
+
let result;
|
|
2102
|
+
runServiceSync((service) => service.transform({
|
|
2103
|
+
callName: "transformSync",
|
|
2104
|
+
refs: null,
|
|
2105
|
+
input,
|
|
2106
|
+
options: options || {},
|
|
2107
|
+
isTTY: isTTY(),
|
|
2108
|
+
fs: fsSync,
|
|
2109
|
+
callback: (err, res) => {
|
|
2110
|
+
if (err) throw err;
|
|
2111
|
+
result = res;
|
|
2112
|
+
}
|
|
2113
|
+
}));
|
|
2114
|
+
return result;
|
|
2115
|
+
};
|
|
2116
|
+
var formatMessagesSync = (messages, options) => {
|
|
2117
|
+
if (worker_threads && !isInternalWorkerThread) {
|
|
2118
|
+
if (!workerThreadService) workerThreadService = startWorkerThreadService(worker_threads);
|
|
2119
|
+
return workerThreadService.formatMessagesSync(messages, options);
|
|
2120
|
+
}
|
|
2121
|
+
let result;
|
|
2122
|
+
runServiceSync((service) => service.formatMessages({
|
|
2123
|
+
callName: "formatMessagesSync",
|
|
2124
|
+
refs: null,
|
|
2125
|
+
messages,
|
|
2126
|
+
options,
|
|
2127
|
+
callback: (err, res) => {
|
|
2128
|
+
if (err) throw err;
|
|
2129
|
+
result = res;
|
|
2130
|
+
}
|
|
2131
|
+
}));
|
|
2132
|
+
return result;
|
|
2133
|
+
};
|
|
2134
|
+
var analyzeMetafileSync = (metafile, options) => {
|
|
2135
|
+
if (worker_threads && !isInternalWorkerThread) {
|
|
2136
|
+
if (!workerThreadService) workerThreadService = startWorkerThreadService(worker_threads);
|
|
2137
|
+
return workerThreadService.analyzeMetafileSync(metafile, options);
|
|
2138
|
+
}
|
|
2139
|
+
let result;
|
|
2140
|
+
runServiceSync((service) => service.analyzeMetafile({
|
|
2141
|
+
callName: "analyzeMetafileSync",
|
|
2142
|
+
refs: null,
|
|
2143
|
+
metafile: typeof metafile === "string" ? metafile : JSON.stringify(metafile),
|
|
2144
|
+
options,
|
|
2145
|
+
callback: (err, res) => {
|
|
2146
|
+
if (err) throw err;
|
|
2147
|
+
result = res;
|
|
2148
|
+
}
|
|
2149
|
+
}));
|
|
2150
|
+
return result;
|
|
2151
|
+
};
|
|
2152
|
+
var stop = () => {
|
|
2153
|
+
if (stopService) stopService();
|
|
2154
|
+
if (workerThreadService) workerThreadService.stop();
|
|
2155
|
+
return Promise.resolve();
|
|
2156
|
+
};
|
|
2157
|
+
var initializeWasCalled = false;
|
|
2158
|
+
var initialize = (options) => {
|
|
2159
|
+
options = validateInitializeOptions(options || {});
|
|
2160
|
+
if (options.wasmURL) throw new Error(`The "wasmURL" option only works in the browser`);
|
|
2161
|
+
if (options.wasmModule) throw new Error(`The "wasmModule" option only works in the browser`);
|
|
2162
|
+
if (options.worker) throw new Error(`The "worker" option only works in the browser`);
|
|
2163
|
+
if (initializeWasCalled) throw new Error('Cannot call "initialize" more than once');
|
|
2164
|
+
ensureServiceIsRunning();
|
|
2165
|
+
initializeWasCalled = true;
|
|
2166
|
+
return Promise.resolve();
|
|
2167
|
+
};
|
|
2168
|
+
var defaultWD = process.cwd();
|
|
2169
|
+
var longLivedService;
|
|
2170
|
+
var stopService;
|
|
2171
|
+
var ensureServiceIsRunning = () => {
|
|
2172
|
+
if (longLivedService) return longLivedService;
|
|
2173
|
+
let [command, args] = esbuildCommandAndArgs();
|
|
2174
|
+
let child = child_process.spawn(command, args.concat(`--service=${"0.21.5"}`, "--ping"), {
|
|
2175
|
+
windowsHide: true,
|
|
2176
|
+
stdio: ["pipe", "pipe", "inherit"],
|
|
2177
|
+
cwd: defaultWD
|
|
2178
|
+
});
|
|
2179
|
+
let { readFromStdout, afterClose, service } = createChannel({
|
|
2180
|
+
writeToStdin(bytes) {
|
|
2181
|
+
child.stdin.write(bytes, (err) => {
|
|
2182
|
+
if (err) afterClose(err);
|
|
2183
|
+
});
|
|
2184
|
+
},
|
|
2185
|
+
readFileSync: fs22.readFileSync,
|
|
2186
|
+
isSync: false,
|
|
2187
|
+
hasFS: true,
|
|
2188
|
+
esbuild: node_exports
|
|
2189
|
+
});
|
|
2190
|
+
child.stdin.on("error", afterClose);
|
|
2191
|
+
child.on("error", afterClose);
|
|
2192
|
+
const stdin = child.stdin;
|
|
2193
|
+
const stdout = child.stdout;
|
|
2194
|
+
stdout.on("data", readFromStdout);
|
|
2195
|
+
stdout.on("end", afterClose);
|
|
2196
|
+
stopService = () => {
|
|
2197
|
+
stdin.destroy();
|
|
2198
|
+
stdout.destroy();
|
|
2199
|
+
child.kill();
|
|
2200
|
+
initializeWasCalled = false;
|
|
2201
|
+
longLivedService = void 0;
|
|
2202
|
+
stopService = void 0;
|
|
2203
|
+
};
|
|
2204
|
+
let refCount = 0;
|
|
2205
|
+
child.unref();
|
|
2206
|
+
if (stdin.unref) {
|
|
2207
|
+
stdin.unref();
|
|
2208
|
+
}
|
|
2209
|
+
if (stdout.unref) {
|
|
2210
|
+
stdout.unref();
|
|
2211
|
+
}
|
|
2212
|
+
const refs = {
|
|
2213
|
+
ref() {
|
|
2214
|
+
if (++refCount === 1) child.ref();
|
|
2215
|
+
},
|
|
2216
|
+
unref() {
|
|
2217
|
+
if (--refCount === 0) child.unref();
|
|
2218
|
+
}
|
|
2219
|
+
};
|
|
2220
|
+
longLivedService = {
|
|
2221
|
+
build: (options) => new Promise((resolve, reject) => {
|
|
2222
|
+
service.buildOrContext({
|
|
2223
|
+
callName: "build",
|
|
2224
|
+
refs,
|
|
2225
|
+
options,
|
|
2226
|
+
isTTY: isTTY(),
|
|
2227
|
+
defaultWD,
|
|
2228
|
+
callback: (err, res) => err ? reject(err) : resolve(res)
|
|
2229
|
+
});
|
|
2230
|
+
}),
|
|
2231
|
+
context: (options) => new Promise((resolve, reject) => service.buildOrContext({
|
|
2232
|
+
callName: "context",
|
|
2233
|
+
refs,
|
|
2234
|
+
options,
|
|
2235
|
+
isTTY: isTTY(),
|
|
2236
|
+
defaultWD,
|
|
2237
|
+
callback: (err, res) => err ? reject(err) : resolve(res)
|
|
2238
|
+
})),
|
|
2239
|
+
transform: (input, options) => new Promise((resolve, reject) => service.transform({
|
|
2240
|
+
callName: "transform",
|
|
2241
|
+
refs,
|
|
2242
|
+
input,
|
|
2243
|
+
options: options || {},
|
|
2244
|
+
isTTY: isTTY(),
|
|
2245
|
+
fs: fsAsync,
|
|
2246
|
+
callback: (err, res) => err ? reject(err) : resolve(res)
|
|
2247
|
+
})),
|
|
2248
|
+
formatMessages: (messages, options) => new Promise((resolve, reject) => service.formatMessages({
|
|
2249
|
+
callName: "formatMessages",
|
|
2250
|
+
refs,
|
|
2251
|
+
messages,
|
|
2252
|
+
options,
|
|
2253
|
+
callback: (err, res) => err ? reject(err) : resolve(res)
|
|
2254
|
+
})),
|
|
2255
|
+
analyzeMetafile: (metafile, options) => new Promise((resolve, reject) => service.analyzeMetafile({
|
|
2256
|
+
callName: "analyzeMetafile",
|
|
2257
|
+
refs,
|
|
2258
|
+
metafile: typeof metafile === "string" ? metafile : JSON.stringify(metafile),
|
|
2259
|
+
options,
|
|
2260
|
+
callback: (err, res) => err ? reject(err) : resolve(res)
|
|
2261
|
+
}))
|
|
2262
|
+
};
|
|
2263
|
+
return longLivedService;
|
|
2264
|
+
};
|
|
2265
|
+
var runServiceSync = (callback) => {
|
|
2266
|
+
let [command, args] = esbuildCommandAndArgs();
|
|
2267
|
+
let stdin = new Uint8Array();
|
|
2268
|
+
let { readFromStdout, afterClose, service } = createChannel({
|
|
2269
|
+
writeToStdin(bytes) {
|
|
2270
|
+
if (stdin.length !== 0) throw new Error("Must run at most one command");
|
|
2271
|
+
stdin = bytes;
|
|
2272
|
+
},
|
|
2273
|
+
isSync: true,
|
|
2274
|
+
hasFS: true,
|
|
2275
|
+
esbuild: node_exports
|
|
2276
|
+
});
|
|
2277
|
+
callback(service);
|
|
2278
|
+
let stdout = child_process.execFileSync(command, args.concat(`--service=${"0.21.5"}`), {
|
|
2279
|
+
cwd: defaultWD,
|
|
2280
|
+
windowsHide: true,
|
|
2281
|
+
input: stdin,
|
|
2282
|
+
// We don't know how large the output could be. If it's too large, the
|
|
2283
|
+
// command will fail with ENOBUFS. Reserve 16mb for now since that feels
|
|
2284
|
+
// like it should be enough. Also allow overriding this with an environment
|
|
2285
|
+
// variable.
|
|
2286
|
+
maxBuffer: +process.env.ESBUILD_MAX_BUFFER || 16 * 1024 * 1024
|
|
2287
|
+
});
|
|
2288
|
+
readFromStdout(stdout);
|
|
2289
|
+
afterClose(null);
|
|
2290
|
+
};
|
|
2291
|
+
var randomFileName = () => {
|
|
2292
|
+
return path22.join(os22.tmpdir(), `esbuild-${crypto.randomBytes(32).toString("hex")}`);
|
|
2293
|
+
};
|
|
2294
|
+
var workerThreadService = null;
|
|
2295
|
+
var startWorkerThreadService = (worker_threads2) => {
|
|
2296
|
+
let { port1: mainPort, port2: workerPort } = new worker_threads2.MessageChannel();
|
|
2297
|
+
let worker = new worker_threads2.Worker(__filename, {
|
|
2298
|
+
workerData: { workerPort, defaultWD, esbuildVersion: "0.21.5" },
|
|
2299
|
+
transferList: [workerPort],
|
|
2300
|
+
// From node's documentation: https://nodejs.org/api/worker_threads.html
|
|
2301
|
+
//
|
|
2302
|
+
// Take care when launching worker threads from preload scripts (scripts loaded
|
|
2303
|
+
// and run using the `-r` command line flag). Unless the `execArgv` option is
|
|
2304
|
+
// explicitly set, new Worker threads automatically inherit the command line flags
|
|
2305
|
+
// from the running process and will preload the same preload scripts as the main
|
|
2306
|
+
// thread. If the preload script unconditionally launches a worker thread, every
|
|
2307
|
+
// thread spawned will spawn another until the application crashes.
|
|
2308
|
+
//
|
|
2309
|
+
execArgv: []
|
|
2310
|
+
});
|
|
2311
|
+
let nextID = 0;
|
|
2312
|
+
let fakeBuildError = (text) => {
|
|
2313
|
+
let error = new Error(`Build failed with 1 error:
|
|
2314
|
+
error: ${text}`);
|
|
2315
|
+
let errors = [{ id: "", pluginName: "", text, location: null, notes: [], detail: void 0 }];
|
|
2316
|
+
error.errors = errors;
|
|
2317
|
+
error.warnings = [];
|
|
2318
|
+
return error;
|
|
2319
|
+
};
|
|
2320
|
+
let validateBuildSyncOptions = (options) => {
|
|
2321
|
+
if (!options) return;
|
|
2322
|
+
let plugins = options.plugins;
|
|
2323
|
+
if (plugins && plugins.length > 0) throw fakeBuildError(`Cannot use plugins in synchronous API calls`);
|
|
2324
|
+
};
|
|
2325
|
+
let applyProperties = (object, properties) => {
|
|
2326
|
+
for (let key in properties) {
|
|
2327
|
+
object[key] = properties[key];
|
|
2328
|
+
}
|
|
2329
|
+
};
|
|
2330
|
+
let runCallSync = (command, args) => {
|
|
2331
|
+
let id = nextID++;
|
|
2332
|
+
let sharedBuffer = new SharedArrayBuffer(8);
|
|
2333
|
+
let sharedBufferView = new Int32Array(sharedBuffer);
|
|
2334
|
+
let msg = { sharedBuffer, id, command, args };
|
|
2335
|
+
worker.postMessage(msg);
|
|
2336
|
+
let status = Atomics.wait(sharedBufferView, 0, 0);
|
|
2337
|
+
if (status !== "ok" && status !== "not-equal") throw new Error("Internal error: Atomics.wait() failed: " + status);
|
|
2338
|
+
let { message: { id: id2, resolve, reject, properties } } = worker_threads2.receiveMessageOnPort(mainPort);
|
|
2339
|
+
if (id !== id2) throw new Error(`Internal error: Expected id ${id} but got id ${id2}`);
|
|
2340
|
+
if (reject) {
|
|
2341
|
+
applyProperties(reject, properties);
|
|
2342
|
+
throw reject;
|
|
2343
|
+
}
|
|
2344
|
+
return resolve;
|
|
2345
|
+
};
|
|
2346
|
+
worker.unref();
|
|
2347
|
+
return {
|
|
2348
|
+
buildSync(options) {
|
|
2349
|
+
validateBuildSyncOptions(options);
|
|
2350
|
+
return runCallSync("build", [options]);
|
|
2351
|
+
},
|
|
2352
|
+
transformSync(input, options) {
|
|
2353
|
+
return runCallSync("transform", [input, options]);
|
|
2354
|
+
},
|
|
2355
|
+
formatMessagesSync(messages, options) {
|
|
2356
|
+
return runCallSync("formatMessages", [messages, options]);
|
|
2357
|
+
},
|
|
2358
|
+
analyzeMetafileSync(metafile, options) {
|
|
2359
|
+
return runCallSync("analyzeMetafile", [metafile, options]);
|
|
2360
|
+
},
|
|
2361
|
+
stop() {
|
|
2362
|
+
worker.terminate();
|
|
2363
|
+
workerThreadService = null;
|
|
2364
|
+
}
|
|
2365
|
+
};
|
|
2366
|
+
};
|
|
2367
|
+
var startSyncServiceWorker = () => {
|
|
2368
|
+
let workerPort = worker_threads.workerData.workerPort;
|
|
2369
|
+
let parentPort2 = worker_threads.parentPort;
|
|
2370
|
+
let extractProperties = (object) => {
|
|
2371
|
+
let properties = {};
|
|
2372
|
+
if (object && typeof object === "object") {
|
|
2373
|
+
for (let key in object) {
|
|
2374
|
+
properties[key] = object[key];
|
|
2375
|
+
}
|
|
2376
|
+
}
|
|
2377
|
+
return properties;
|
|
2378
|
+
};
|
|
2379
|
+
try {
|
|
2380
|
+
let service = ensureServiceIsRunning();
|
|
2381
|
+
defaultWD = worker_threads.workerData.defaultWD;
|
|
2382
|
+
parentPort2.on("message", (msg) => {
|
|
2383
|
+
(async () => {
|
|
2384
|
+
let { sharedBuffer, id, command, args } = msg;
|
|
2385
|
+
let sharedBufferView = new Int32Array(sharedBuffer);
|
|
2386
|
+
try {
|
|
2387
|
+
switch (command) {
|
|
2388
|
+
case "build":
|
|
2389
|
+
workerPort.postMessage({ id, resolve: await service.build(args[0]) });
|
|
2390
|
+
break;
|
|
2391
|
+
case "transform":
|
|
2392
|
+
workerPort.postMessage({ id, resolve: await service.transform(args[0], args[1]) });
|
|
2393
|
+
break;
|
|
2394
|
+
case "formatMessages":
|
|
2395
|
+
workerPort.postMessage({ id, resolve: await service.formatMessages(args[0], args[1]) });
|
|
2396
|
+
break;
|
|
2397
|
+
case "analyzeMetafile":
|
|
2398
|
+
workerPort.postMessage({ id, resolve: await service.analyzeMetafile(args[0], args[1]) });
|
|
2399
|
+
break;
|
|
2400
|
+
default:
|
|
2401
|
+
throw new Error(`Invalid command: ${command}`);
|
|
2402
|
+
}
|
|
2403
|
+
} catch (reject) {
|
|
2404
|
+
workerPort.postMessage({ id, reject, properties: extractProperties(reject) });
|
|
2405
|
+
}
|
|
2406
|
+
Atomics.add(sharedBufferView, 0, 1);
|
|
2407
|
+
Atomics.notify(sharedBufferView, 0, Infinity);
|
|
2408
|
+
})();
|
|
2409
|
+
});
|
|
2410
|
+
} catch (reject) {
|
|
2411
|
+
parentPort2.on("message", (msg) => {
|
|
2412
|
+
let { sharedBuffer, id } = msg;
|
|
2413
|
+
let sharedBufferView = new Int32Array(sharedBuffer);
|
|
2414
|
+
workerPort.postMessage({ id, reject, properties: extractProperties(reject) });
|
|
2415
|
+
Atomics.add(sharedBufferView, 0, 1);
|
|
2416
|
+
Atomics.notify(sharedBufferView, 0, Infinity);
|
|
2417
|
+
});
|
|
2418
|
+
}
|
|
2419
|
+
};
|
|
2420
|
+
if (isInternalWorkerThread) {
|
|
2421
|
+
startSyncServiceWorker();
|
|
2422
|
+
}
|
|
2423
|
+
var node_default = node_exports;
|
|
2424
|
+
}
|
|
2425
|
+
});
|
|
2426
|
+
|
|
2427
|
+
// core/bundler/game-bundler-worker.ts
|
|
2428
|
+
var game_bundler_worker_exports = {};
|
|
2429
|
+
module.exports = __toCommonJS(game_bundler_worker_exports);
|
|
2430
|
+
var import_worker_threads = require("worker_threads");
|
|
2431
|
+
|
|
2432
|
+
// core/bundler/game-packager.ts
|
|
2433
|
+
var fs2 = __toESM(require("fs"));
|
|
2434
|
+
var path2 = __toESM(require("path"));
|
|
2435
|
+
init_ci_installer();
|
|
2436
|
+
var _esbuild = null;
|
|
2437
|
+
function getEsbuild() {
|
|
2438
|
+
if (!_esbuild) {
|
|
2439
|
+
try {
|
|
2440
|
+
_esbuild = require_main();
|
|
2441
|
+
} catch (e) {
|
|
2442
|
+
throw new Error(
|
|
2443
|
+
`[game-packager] Failed to load esbuild fallback transpiler. Ensure esbuild is installed: ${e}`
|
|
2444
|
+
);
|
|
2445
|
+
}
|
|
2446
|
+
}
|
|
2447
|
+
return _esbuild;
|
|
2448
|
+
}
|
|
2449
|
+
var _enhanceTransform = null;
|
|
2450
|
+
var _ciDir = null;
|
|
2451
|
+
function getCiDir() {
|
|
2452
|
+
if (!_ciDir) {
|
|
2453
|
+
if (isCiInstalled()) {
|
|
2454
|
+
_ciDir = getCiRequirePath();
|
|
2455
|
+
} else {
|
|
2456
|
+
_ciDir = require.resolve("miniprogram-ci").replace(/[/\\]dist[/\\]index\.js$/, "");
|
|
2457
|
+
}
|
|
2458
|
+
}
|
|
2459
|
+
return _ciDir;
|
|
2460
|
+
}
|
|
2461
|
+
function getEnhanceTransform() {
|
|
2462
|
+
if (!_enhanceTransform) {
|
|
2463
|
+
try {
|
|
2464
|
+
const ciDir = getCiDir();
|
|
2465
|
+
_enhanceTransform = require(`${ciDir}/dist/modules/corecompiler/original/js/enhance`);
|
|
2466
|
+
} catch (e) {
|
|
2467
|
+
throw new Error(
|
|
2468
|
+
`[game-packager] Failed to load miniprogram-ci enhanced babel7 transform. Ensure miniprogram-ci is installed: ${e}`
|
|
2469
|
+
);
|
|
2470
|
+
}
|
|
2471
|
+
}
|
|
2472
|
+
return _enhanceTransform;
|
|
2473
|
+
}
|
|
2474
|
+
function readBabelHelper(helperPath) {
|
|
2475
|
+
const ciDir = getCiDir();
|
|
2476
|
+
const vendorRelative = helperPath.replace("@babel/runtime", "babel_runtime");
|
|
2477
|
+
const absPath = path2.join(ciDir, "dist", "vendor", vendorRelative + ".js");
|
|
2478
|
+
return fs2.readFileSync(absPath, "utf-8");
|
|
2479
|
+
}
|
|
2480
|
+
var BABEL_RUNTIME_ROOT = "@babel/runtime";
|
|
2481
|
+
function silenceBabelDeopt(fn) {
|
|
2482
|
+
const _origWarn = console.warn.bind(console);
|
|
2483
|
+
const _origLog = console.log.bind(console);
|
|
2484
|
+
const _noteRe = /deoptimised the styling/i;
|
|
2485
|
+
console.warn = (...args) => {
|
|
2486
|
+
if (!_noteRe.test(String(args[0]))) _origWarn(...args);
|
|
2487
|
+
};
|
|
2488
|
+
console.log = (...args) => {
|
|
2489
|
+
if (!_noteRe.test(String(args[0]))) _origLog(...args);
|
|
2490
|
+
};
|
|
2491
|
+
try {
|
|
2492
|
+
return fn();
|
|
2493
|
+
} finally {
|
|
2494
|
+
console.warn = _origWarn;
|
|
2495
|
+
console.log = _origLog;
|
|
2496
|
+
}
|
|
2497
|
+
}
|
|
2498
|
+
function extractBabelRuntimeRequires(source) {
|
|
2499
|
+
const results = [];
|
|
2500
|
+
const re = /\brequire\s*\(\s*['"](@babel\/runtime\/[^'"]+)['"]\s*\)/g;
|
|
2501
|
+
let m;
|
|
2502
|
+
while ((m = re.exec(source)) !== null) results.push(m[1]);
|
|
2503
|
+
return results;
|
|
2504
|
+
}
|
|
2505
|
+
function extractHelperDependencies(currentHelperPath, source) {
|
|
2506
|
+
const dir = currentHelperPath.replace(/\/[^/]+$/, "");
|
|
2507
|
+
const results = [];
|
|
2508
|
+
const re = /\brequire\s*\(\s*['"]([^'"]+)['"]\s*\)/g;
|
|
2509
|
+
let m;
|
|
2510
|
+
while ((m = re.exec(source)) !== null) {
|
|
2511
|
+
const spec = m[1];
|
|
2512
|
+
if (spec.startsWith("@babel/runtime/")) {
|
|
2513
|
+
results.push(spec);
|
|
2514
|
+
} else if (spec.startsWith("./")) {
|
|
2515
|
+
results.push(dir + "/" + spec.slice(2));
|
|
2516
|
+
} else if (spec.startsWith("../")) {
|
|
2517
|
+
let base = dir;
|
|
2518
|
+
let rest = spec;
|
|
2519
|
+
while (rest.startsWith("../")) {
|
|
2520
|
+
base = base.replace(/\/[^/]+$/, "");
|
|
2521
|
+
rest = rest.slice(3);
|
|
2522
|
+
}
|
|
2523
|
+
results.push(base + "/" + rest);
|
|
2524
|
+
}
|
|
2525
|
+
}
|
|
2526
|
+
return results;
|
|
2527
|
+
}
|
|
2528
|
+
function normaliseRoot(raw) {
|
|
2529
|
+
return raw.replace(/^\/+/, "").replace(/\/+$/, "");
|
|
2530
|
+
}
|
|
2531
|
+
function discoverPackages(gameDir) {
|
|
2532
|
+
const gameJsonPath = path2.join(gameDir, "game.json");
|
|
2533
|
+
let gameJson = {};
|
|
2534
|
+
try {
|
|
2535
|
+
gameJson = JSON.parse(fs2.readFileSync(gameJsonPath, "utf-8"));
|
|
2536
|
+
} catch {
|
|
2537
|
+
}
|
|
2538
|
+
const packages = [];
|
|
2539
|
+
packages.push({ name: "", root: "", entry: "game.js" });
|
|
2540
|
+
const rawSubs = gameJson["subPackages"] ?? gameJson["subpackages"] ?? [];
|
|
2541
|
+
for (const sp of rawSubs) {
|
|
2542
|
+
const rawRoot = typeof sp.root === "string" ? sp.root : "";
|
|
2543
|
+
const name = typeof sp.name === "string" ? sp.name : rawRoot;
|
|
2544
|
+
const root = normaliseRoot(rawRoot);
|
|
2545
|
+
if (!root) continue;
|
|
2546
|
+
packages.push({ name, root, entry: "game.js" });
|
|
2547
|
+
}
|
|
2548
|
+
return packages;
|
|
2549
|
+
}
|
|
2550
|
+
function isSystemJsCarrier(source) {
|
|
2551
|
+
const sysIdx = source.indexOf("System.register(");
|
|
2552
|
+
if (sysIdx < 0) return false;
|
|
2553
|
+
const defIdx = source.indexOf("define(");
|
|
2554
|
+
if (defIdx < 0) return true;
|
|
2555
|
+
return sysIdx < defIdx;
|
|
2556
|
+
}
|
|
2557
|
+
function isSelfBootstrappingEntry(source, _entry) {
|
|
2558
|
+
const tail = source.trimEnd();
|
|
2559
|
+
const tailSlice = tail.slice(Math.max(0, tail.length - 128));
|
|
2560
|
+
const m = tailSlice.match(/require\(\s*(["'])([^"']+)\1\s*\)\s*;?\s*$/);
|
|
2561
|
+
if (!m) return false;
|
|
2562
|
+
const bootId = m[2];
|
|
2563
|
+
const defSig1 = `define("${bootId}"`;
|
|
2564
|
+
const defSig2 = `define('${bootId}'`;
|
|
2565
|
+
return source.indexOf(defSig1) >= 0 || source.indexOf(defSig2) >= 0;
|
|
2566
|
+
}
|
|
2567
|
+
var SKIP_DIRS = /* @__PURE__ */ new Set([
|
|
2568
|
+
"node_modules",
|
|
2569
|
+
".git",
|
|
2570
|
+
".svn",
|
|
2571
|
+
".hg",
|
|
2572
|
+
".idea",
|
|
2573
|
+
".vscode"
|
|
2574
|
+
]);
|
|
2575
|
+
function walkFiles(absDir, relDirFromPkgRoot, excludeRoots, out) {
|
|
2576
|
+
let entries;
|
|
2577
|
+
try {
|
|
2578
|
+
entries = fs2.readdirSync(absDir, { withFileTypes: true });
|
|
2579
|
+
} catch {
|
|
2580
|
+
return;
|
|
2581
|
+
}
|
|
2582
|
+
for (const entry of entries) {
|
|
2583
|
+
if (entry.name.startsWith(".")) continue;
|
|
2584
|
+
if (SKIP_DIRS.has(entry.name)) continue;
|
|
2585
|
+
const nextRel = relDirFromPkgRoot ? `${relDirFromPkgRoot}/${entry.name}` : entry.name;
|
|
2586
|
+
if (excludeRoots.has(nextRel)) continue;
|
|
2587
|
+
const childAbs = path2.join(absDir, entry.name);
|
|
2588
|
+
if (entry.isDirectory()) {
|
|
2589
|
+
walkFiles(childAbs, nextRel, excludeRoots, out);
|
|
2590
|
+
} else if (entry.isFile()) {
|
|
2591
|
+
out.push(nextRel);
|
|
2592
|
+
}
|
|
2593
|
+
}
|
|
2594
|
+
}
|
|
2595
|
+
function wrapAsDefine(modulePathInPkg, body) {
|
|
2596
|
+
const key = JSON.stringify(modulePathInPkg);
|
|
2597
|
+
return `define(${key}, function(require, module, exports) {
|
|
2598
|
+
${body}
|
|
2599
|
+
});
|
|
2600
|
+
`;
|
|
2601
|
+
}
|
|
2602
|
+
function copyFile(srcAbs, dstAbs) {
|
|
2603
|
+
fs2.mkdirSync(path2.dirname(dstAbs), { recursive: true });
|
|
2604
|
+
fs2.copyFileSync(srcAbs, dstAbs);
|
|
2605
|
+
}
|
|
2606
|
+
function transformJs(src, relPath, diagnostics, pkgName, log) {
|
|
2607
|
+
const transform = getEnhanceTransform();
|
|
2608
|
+
let result;
|
|
2609
|
+
try {
|
|
2610
|
+
result = silenceBabelDeopt(
|
|
2611
|
+
() => transform({
|
|
2612
|
+
code: src,
|
|
2613
|
+
filePath: relPath,
|
|
2614
|
+
babelRoot: BABEL_RUNTIME_ROOT
|
|
2615
|
+
})
|
|
2616
|
+
);
|
|
2617
|
+
} catch (e) {
|
|
2618
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
2619
|
+
diagnostics.push({ pkg: pkgName, file: relPath, level: "warn", message: `Babel threw: ${msg} \u2014 trying esbuild fallback` });
|
|
2620
|
+
log("warn", `[packager] (${pkgName || "main"}) Babel threw on "${relPath}": ${msg} \u2014 trying esbuild fallback`);
|
|
2621
|
+
return esbuildFallbackTransform(src, relPath, diagnostics, pkgName, log);
|
|
2622
|
+
}
|
|
2623
|
+
if (result.error) {
|
|
2624
|
+
diagnostics.push({
|
|
2625
|
+
pkg: pkgName,
|
|
2626
|
+
file: relPath,
|
|
2627
|
+
level: "warn",
|
|
2628
|
+
message: `Babel transpile error: ${result.error.message} \u2014 trying esbuild fallback`
|
|
2629
|
+
});
|
|
2630
|
+
log("warn", `[packager] (${pkgName || "main"}) Babel error in "${relPath}": ${result.error.message} \u2014 trying esbuild fallback`);
|
|
2631
|
+
return esbuildFallbackTransform(src, relPath, diagnostics, pkgName, log);
|
|
2632
|
+
}
|
|
2633
|
+
const code = result.code ?? src;
|
|
2634
|
+
const helpers = result.helpers ?? [];
|
|
2635
|
+
for (const h of extractBabelRuntimeRequires(code)) {
|
|
2636
|
+
if (!helpers.includes(h)) helpers.push(h);
|
|
2637
|
+
}
|
|
2638
|
+
return { code, helpers };
|
|
2639
|
+
}
|
|
2640
|
+
function esbuildFallbackTransform(src, relPath, diagnostics, pkgName, log) {
|
|
2641
|
+
try {
|
|
2642
|
+
const esb = getEsbuild();
|
|
2643
|
+
const result = esb.transformSync(src, {
|
|
2644
|
+
loader: "js",
|
|
2645
|
+
// Target ES2015 to ensure compatibility with `new Function()` + `with()` in sandboxExec.
|
|
2646
|
+
// ES2015 removes most syntax that causes issues (optional chaining, nullish coalescing, etc.)
|
|
2647
|
+
// while still being broadly parseable.
|
|
2648
|
+
target: "es2015",
|
|
2649
|
+
format: "cjs",
|
|
2650
|
+
sourcefile: relPath,
|
|
2651
|
+
// Avoid injecting "use strict" which conflicts with `with()` statement
|
|
2652
|
+
banner: "/* esbuild-fallback */"
|
|
2653
|
+
});
|
|
2654
|
+
log("log", `[packager] (${pkgName || "main"}) esbuild fallback succeeded for "${relPath}"`);
|
|
2655
|
+
const code = result.code.replace(/^\s*"use strict";\s*\n?/m, "");
|
|
2656
|
+
return { code, helpers: [] };
|
|
2657
|
+
} catch (e) {
|
|
2658
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
2659
|
+
diagnostics.push({
|
|
2660
|
+
pkg: pkgName,
|
|
2661
|
+
file: relPath,
|
|
2662
|
+
level: "error",
|
|
2663
|
+
message: `esbuild fallback also failed: ${msg} \u2014 using source as-is (may cause SyntaxError at runtime)`
|
|
2664
|
+
});
|
|
2665
|
+
log("error", `[packager] (${pkgName || "main"}) esbuild fallback failed for "${relPath}": ${msg} \u2014 using source as-is`);
|
|
2666
|
+
return { code: src, helpers: [] };
|
|
2667
|
+
}
|
|
2668
|
+
}
|
|
2669
|
+
function materialiseHelpers(initial, diagnostics, pkgName) {
|
|
2670
|
+
const all = /* @__PURE__ */ new Set();
|
|
2671
|
+
const queue = [];
|
|
2672
|
+
for (const h of initial) {
|
|
2673
|
+
const norm = h.endsWith(".js") ? h.replace(/\.js$/, "") : h;
|
|
2674
|
+
if (!all.has(norm)) {
|
|
2675
|
+
all.add(norm);
|
|
2676
|
+
queue.push(norm);
|
|
2677
|
+
}
|
|
2678
|
+
}
|
|
2679
|
+
while (queue.length > 0) {
|
|
2680
|
+
const h = queue.shift();
|
|
2681
|
+
let src;
|
|
2682
|
+
try {
|
|
2683
|
+
src = readBabelHelper(h);
|
|
2684
|
+
} catch {
|
|
2685
|
+
diagnostics.push({ pkg: pkgName, file: h, level: "warn", message: `Helper not found in miniprogram-ci vendor: ${h}` });
|
|
2686
|
+
continue;
|
|
2687
|
+
}
|
|
2688
|
+
for (const dep of extractHelperDependencies(h, src)) {
|
|
2689
|
+
const norm = dep.endsWith(".js") ? dep.replace(/\.js$/, "") : dep;
|
|
2690
|
+
if (!all.has(norm)) {
|
|
2691
|
+
all.add(norm);
|
|
2692
|
+
queue.push(norm);
|
|
2693
|
+
}
|
|
2694
|
+
}
|
|
2695
|
+
}
|
|
2696
|
+
const out = [];
|
|
2697
|
+
for (const h of all) {
|
|
2698
|
+
try {
|
|
2699
|
+
const src = readBabelHelper(h);
|
|
2700
|
+
out.push({ modulePathInPkg: h + ".js", source: src });
|
|
2701
|
+
} catch {
|
|
2702
|
+
}
|
|
2703
|
+
}
|
|
2704
|
+
return out;
|
|
2705
|
+
}
|
|
2706
|
+
function packOnePackage(gameDir, outRoot, spec, excludeRoots, diagnostics, log) {
|
|
2707
|
+
const pkgAbsSrc = spec.root ? path2.join(gameDir, spec.root) : gameDir;
|
|
2708
|
+
const pkgAbsDst = spec.root ? path2.join(outRoot, spec.root) : outRoot;
|
|
2709
|
+
if (!fs2.existsSync(pkgAbsSrc)) {
|
|
2710
|
+
log("warn", `[packager] Package "${spec.name || "main"}" root does not exist: ${pkgAbsSrc}`);
|
|
2711
|
+
return { name: spec.name, root: spec.root, entry: spec.entry, modules: 0, assets: 0, helpers: 0, scripts: 0 };
|
|
2712
|
+
}
|
|
2713
|
+
fs2.mkdirSync(pkgAbsDst, { recursive: true });
|
|
2714
|
+
const files = [];
|
|
2715
|
+
walkFiles(pkgAbsSrc, "", excludeRoots, files);
|
|
2716
|
+
const jsFiles = [];
|
|
2717
|
+
let assetCount = 0;
|
|
2718
|
+
for (const rel of files) {
|
|
2719
|
+
if (/\.(?:js|mjs|cjs)$/.test(rel)) {
|
|
2720
|
+
jsFiles.push(rel);
|
|
2721
|
+
} else {
|
|
2722
|
+
const srcAbs = path2.join(pkgAbsSrc, rel);
|
|
2723
|
+
const dstAbs = path2.join(pkgAbsDst, rel);
|
|
2724
|
+
copyFile(srcAbs, dstAbs);
|
|
2725
|
+
assetCount++;
|
|
2726
|
+
}
|
|
2727
|
+
}
|
|
2728
|
+
const entryAbsSrc = path2.join(pkgAbsSrc, spec.entry);
|
|
2729
|
+
let entryPassthrough = false;
|
|
2730
|
+
if (fs2.existsSync(entryAbsSrc)) {
|
|
2731
|
+
const entrySrc = fs2.readFileSync(entryAbsSrc, "utf-8");
|
|
2732
|
+
if (isSelfBootstrappingEntry(entrySrc, spec.entry)) {
|
|
2733
|
+
entryPassthrough = true;
|
|
2734
|
+
const entryAbsDst = path2.join(pkgAbsDst, spec.entry);
|
|
2735
|
+
fs2.mkdirSync(path2.dirname(entryAbsDst), { recursive: true });
|
|
2736
|
+
fs2.writeFileSync(entryAbsDst, entrySrc, "utf-8");
|
|
2737
|
+
log(
|
|
2738
|
+
"log",
|
|
2739
|
+
`[packager] (${spec.name || "main"}) entry "${spec.entry}" is a self-bootstrapping CI bundle \u2014 copied verbatim, no re-wrapping.`
|
|
2740
|
+
);
|
|
2741
|
+
}
|
|
2742
|
+
}
|
|
2743
|
+
const collectedHelpers = /* @__PURE__ */ new Set();
|
|
2744
|
+
const moduleChunks = [];
|
|
2745
|
+
let scriptCount = 0;
|
|
2746
|
+
let moduleCount = 0;
|
|
2747
|
+
for (const rel of jsFiles) {
|
|
2748
|
+
const srcAbs = path2.join(pkgAbsSrc, rel);
|
|
2749
|
+
const src = fs2.readFileSync(srcAbs, "utf-8");
|
|
2750
|
+
const isEntryFile = rel === spec.entry;
|
|
2751
|
+
if (isEntryFile && entryPassthrough) continue;
|
|
2752
|
+
if (!isEntryFile && isSystemJsCarrier(src)) {
|
|
2753
|
+
const dstAbs = path2.join(pkgAbsDst, rel);
|
|
2754
|
+
copyFile(srcAbs, dstAbs);
|
|
2755
|
+
scriptCount++;
|
|
2756
|
+
for (const h of extractBabelRuntimeRequires(src)) collectedHelpers.add(h);
|
|
2757
|
+
continue;
|
|
2758
|
+
}
|
|
2759
|
+
const first = rel.split("/")[0];
|
|
2760
|
+
const alreadyCompiled = first === "@babel" || first === "babel_runtime";
|
|
2761
|
+
if (alreadyCompiled) {
|
|
2762
|
+
moduleChunks.push(wrapAsDefine(rel, src));
|
|
2763
|
+
moduleCount++;
|
|
2764
|
+
for (const h of extractBabelRuntimeRequires(src)) collectedHelpers.add(h);
|
|
2765
|
+
continue;
|
|
2766
|
+
}
|
|
2767
|
+
const { code, helpers } = transformJs(src, rel, diagnostics, spec.name, log);
|
|
2768
|
+
for (const h of helpers) collectedHelpers.add(h);
|
|
2769
|
+
moduleChunks.push(wrapAsDefine(rel, code));
|
|
2770
|
+
moduleCount++;
|
|
2771
|
+
}
|
|
2772
|
+
const helperEntries = materialiseHelpers(collectedHelpers, diagnostics, spec.name);
|
|
2773
|
+
for (const h of helperEntries) {
|
|
2774
|
+
moduleChunks.push(wrapAsDefine(h.modulePathInPkg, h.source));
|
|
2775
|
+
}
|
|
2776
|
+
if (!entryPassthrough) {
|
|
2777
|
+
const banner = `// Packaged by ai-minigame-engine (${spec.name || "main"} package) \u2014 ${moduleCount} bundled module(s), ${scriptCount} standalone script(s), ${helperEntries.length} helper(s)
|
|
2778
|
+
`;
|
|
2779
|
+
const footer = `require(${JSON.stringify(spec.entry)});
|
|
2780
|
+
`;
|
|
2781
|
+
const payload = banner + moduleChunks.join("") + footer;
|
|
2782
|
+
const entryAbsDst = path2.join(pkgAbsDst, spec.entry);
|
|
2783
|
+
fs2.mkdirSync(path2.dirname(entryAbsDst), { recursive: true });
|
|
2784
|
+
fs2.writeFileSync(entryAbsDst, payload, "utf-8");
|
|
2785
|
+
} else if (moduleChunks.length > 0 || helperEntries.length > 0) {
|
|
2786
|
+
log(
|
|
2787
|
+
"warn",
|
|
2788
|
+
`[packager] (${spec.name || "main"}) entry is self-bootstrapping but found ${moduleCount} extra module(s) and ${helperEntries.length} helper(s) that will be ignored. Remove them from the package or remove the trailing require("${spec.entry}") from the entry file.`
|
|
2789
|
+
);
|
|
2790
|
+
}
|
|
2791
|
+
log(
|
|
2792
|
+
"log",
|
|
2793
|
+
`[packager] (${spec.name || "main"}) ` + (entryPassthrough ? `entry passthrough (${assetCount} assets)` : `${moduleCount} bundled, ${scriptCount} standalone, ${helperEntries.length} helpers, ${assetCount} assets`)
|
|
2794
|
+
);
|
|
2795
|
+
return {
|
|
2796
|
+
name: spec.name,
|
|
2797
|
+
root: spec.root,
|
|
2798
|
+
entry: spec.entry,
|
|
2799
|
+
modules: moduleCount,
|
|
2800
|
+
assets: assetCount,
|
|
2801
|
+
helpers: helperEntries.length,
|
|
2802
|
+
scripts: scriptCount
|
|
2803
|
+
};
|
|
2804
|
+
}
|
|
2805
|
+
function packageGameToDir(gameDir, outputDir, logger) {
|
|
2806
|
+
const start = Date.now();
|
|
2807
|
+
const log = logger ?? ((level, msg) => {
|
|
2808
|
+
if (level === "error") console.error(msg);
|
|
2809
|
+
else if (level === "warn") console.warn(msg);
|
|
2810
|
+
else console.log(msg);
|
|
2811
|
+
});
|
|
2812
|
+
log("log", `[packager] Packaging ${gameDir} \u2192 ${outputDir}`);
|
|
2813
|
+
if (!fs2.existsSync(path2.join(gameDir, "game.js"))) {
|
|
2814
|
+
throw new Error(`[packager] Entry file not found: ${path2.join(gameDir, "game.js")}`);
|
|
2815
|
+
}
|
|
2816
|
+
fs2.rmSync(outputDir, { recursive: true, force: true });
|
|
2817
|
+
fs2.mkdirSync(outputDir, { recursive: true });
|
|
2818
|
+
for (const name of ["game.json", "project.config.json", "project.private.config.json", "app-config.json"]) {
|
|
2819
|
+
const src = path2.join(gameDir, name);
|
|
2820
|
+
if (fs2.existsSync(src)) {
|
|
2821
|
+
copyFile(src, path2.join(outputDir, name));
|
|
2822
|
+
}
|
|
2823
|
+
}
|
|
2824
|
+
const packages = discoverPackages(gameDir);
|
|
2825
|
+
const mainExcludeRoots = new Set(
|
|
2826
|
+
packages.filter((p) => p.root !== "").map((p) => p.root)
|
|
2827
|
+
);
|
|
2828
|
+
const diagnostics = [];
|
|
2829
|
+
const results = [];
|
|
2830
|
+
for (const spec of packages) {
|
|
2831
|
+
const excludeRoots = spec.root === "" ? mainExcludeRoots : /* @__PURE__ */ new Set();
|
|
2832
|
+
try {
|
|
2833
|
+
results.push(packOnePackage(gameDir, outputDir, spec, excludeRoots, diagnostics, log));
|
|
2834
|
+
} catch (e) {
|
|
2835
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
2836
|
+
log("error", `[packager] Package "${spec.name || "main"}" failed: ${msg}`);
|
|
2837
|
+
diagnostics.push({ pkg: spec.name, file: "<package>", level: "error", message: msg });
|
|
2838
|
+
throw e;
|
|
2839
|
+
}
|
|
2840
|
+
}
|
|
2841
|
+
const elapsed = Date.now() - start;
|
|
2842
|
+
const modulesSum = results.reduce((a, r) => a + r.modules, 0);
|
|
2843
|
+
const assetsSum = results.reduce((a, r) => a + r.assets, 0);
|
|
2844
|
+
const helpersSum = results.reduce((a, r) => a + r.helpers, 0);
|
|
2845
|
+
const scriptsSum = results.reduce((a, r) => a + r.scripts, 0);
|
|
2846
|
+
log(
|
|
2847
|
+
"log",
|
|
2848
|
+
`[packager] Done in ${elapsed}ms \u2014 ${results.length} package(s), ${modulesSum} bundled module(s), ${scriptsSum} standalone script(s), ${assetsSum} asset(s), ${helpersSum} helper(s)`
|
|
2849
|
+
);
|
|
2850
|
+
return { packages: results, diagnostics, elapsed };
|
|
2851
|
+
}
|
|
2852
|
+
|
|
2853
|
+
// core/bundler/game-bundler-worker.ts
|
|
2854
|
+
if (!import_worker_threads.parentPort) {
|
|
2855
|
+
console.warn("[game-bundler-worker] Loaded outside a worker_threads context \u2014 doing nothing.");
|
|
2856
|
+
} else {
|
|
2857
|
+
const port = import_worker_threads.parentPort;
|
|
2858
|
+
port.on("message", (msg) => {
|
|
2859
|
+
if (!msg || msg.kind !== "run") return;
|
|
2860
|
+
const { id, gameDir, outputDir, ciDepsDir, ciExtensionDir } = msg;
|
|
2861
|
+
if (ciExtensionDir || ciDepsDir) {
|
|
2862
|
+
const installer = (init_ci_installer(), __toCommonJS(ci_installer_exports));
|
|
2863
|
+
if (ciExtensionDir) installer.setCiExtensionDir(ciExtensionDir);
|
|
2864
|
+
if (ciDepsDir) installer.setCiDepsDir(ciDepsDir);
|
|
2865
|
+
}
|
|
2866
|
+
const logger = (level, message) => {
|
|
2867
|
+
port.postMessage({ kind: "log", id, level, message });
|
|
2868
|
+
};
|
|
2869
|
+
try {
|
|
2870
|
+
const result = packageGameToDir(gameDir, outputDir, logger);
|
|
2871
|
+
port.postMessage({ kind: "done", id, result });
|
|
2872
|
+
} catch (err) {
|
|
2873
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
2874
|
+
const stack = err instanceof Error ? err.stack : void 0;
|
|
2875
|
+
port.postMessage({ kind: "error", id, message, stack });
|
|
2876
|
+
}
|
|
2877
|
+
});
|
|
2878
|
+
}
|
|
2879
|
+
//# sourceMappingURL=game-bundler-worker.js.map
|