提交 8ee22b9b 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

chore(automator): 修复 page.setData 失败

上级 c7e4bf0f
......@@ -12,4 +12,4 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
function __spreadArrays(){for(var s=0,i=0,il=arguments.length;i<il;i++)s+=arguments[i].length;var r=Array(s),k=0;for(i=0;i<il;i++)for(var a=arguments[i],j=0,jl=a.length;j<jl;j++,k++)r[k]=a[j];return r}var getRandomValues="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto),rnds8=new Uint8Array(16);function rng(){if(!getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return getRandomValues(rnds8)}for(var byteToHex=[],i=0;i<256;++i)byteToHex[i]=(i+256).toString(16).substr(1);function v4(options,buf,offset){var i=buf&&offset||0;"string"==typeof options&&(buf="binary"===options?new Array(16):null,options=null);var rnds=(options=options||{}).random||(options.rng||rng)();if(rnds[6]=15&rnds[6]|64,rnds[8]=63&rnds[8]|128,buf)for(var ii=0;ii<16;++ii)buf[i+ii]=rnds[ii];return buf||function(buf,offset){var i=offset||0,bth=byteToHex;return[bth[buf[i++]],bth[buf[i++]],bth[buf[i++]],bth[buf[i++]],"-",bth[buf[i++]],bth[buf[i++]],"-",bth[buf[i++]],bth[buf[i++]],"-",bth[buf[i++]],bth[buf[i++]],"-",bth[buf[i++]],bth[buf[i++]],bth[buf[i++]],bth[buf[i++]],bth[buf[i++]],bth[buf[i++]]].join("")}(rnds)}var hasOwnProperty=Object.prototype.hasOwnProperty,isArray=Array.isArray,PATH_RE=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;function getPaths(path,data){if(isArray(path))return path;if(data&&(val=data,key=path,hasOwnProperty.call(val,key)))return[path];var val,key,res=[];return path.replace(PATH_RE,(function(match,p1,offset,string){return res.push(offset?string.replace(/\\(\\)?/g,"$1"):p1||match),string})),res}function getDataByPath(data,path){var dataPath,paths=getPaths(path,data);for(dataPath=paths.shift();null!=dataPath;){if(null==(data=data[dataPath]))return;dataPath=paths.shift()}return data}var elementMap=new Map;function transEl(el){if(!function(el){if(el){var tagName=el.tagName;return 0===tagName.indexOf("UNI-")||"BODY"===tagName}return!1}(el))throw Error("no such element");var element,elementId,elem={elementId:(element=el,elementId=element._id,elementId||(elementId=v4(),element._id=elementId,elementMap.set(elementId,{id:elementId,element:element})),elementId),tagName:el.tagName.toLocaleLowerCase().replace("uni-","")},vm=el.__vue__;return vm&&(vm.$parent&&vm.$parent.$el===el&&(vm=vm.$parent),vm&&!vm.$options.isReserved&&(elem.nodeId=function(vm){if(vm._$weex)return vm._uid;if(vm._$id)return vm._$id;var parent_1=function(vm){for(var parent=vm.$parent;parent;){if(parent._$id)return parent;parent=parent.$parent}}(vm);if(!vm.$parent)return"-1";var vnode=vm.$vnode,context=vnode.context;return context&&context!==parent_1&&context._$id?context._$id+";"+parent_1._$id+","+vnode.data.attrs._i:parent_1._$id+","+vnode.data.attrs._i}(vm))),"video"===elem.tagName&&(elem.videoId=elem.nodeId),elem}var FUNCTIONS={input:{input:function(el,value){var vm=el.__vue__;vm.valueSync=value,vm.$triggerInput({},{value:value})}},textarea:{input:function(el,value){var vm=el.__vue__;vm.valueSync=value,vm.$triggerInput({},{value:value})}},"scroll-view":{scrollTo:function(el,x,y){var main=el.__vue__.$refs.main;main.scrollLeft=x,main.scrollTop=y},scrollTop:function(el){return el.__vue__.$refs.main.scrollTop},scrollLeft:function(el){return el.__vue__.$refs.main.scrollLeft},scrollWidth:function(el){return el.__vue__.$refs.main.scrollWidth},scrollHeight:function(el){return el.__vue__.$refs.main.scrollHeight}},swiper:{swipeTo:function(el,index){el.__vue__.current=index}},"movable-view":{moveTo:function(el,x,y){el.__vue__._animationTo(x,y)}},switch:{tap:function(el){el.click()}},slider:{slideTo:function(el,value){var vm=el.__vue__,slider=vm.$refs["uni-slider"],offsetWidth=slider.offsetWidth,boxLeft=slider.getBoundingClientRect().left;vm.value=value,vm._onClick({x:(value-vm.min)*offsetWidth/(vm.max-vm.min)+boxLeft})}}};function createTouchList(touchInits){var _a,touches=touchInits.map((function(touch){return function(touch){if(document.createTouch)return document.createTouch(window,touch.target,touch.identifier,touch.pageX,touch.pageY,touch.screenX,touch.screenY);return new Touch(touch)}(touch)}));return document.createTouchList?(_a=document).createTouchList.apply(_a,touches):touches}var WebAdapter={getWindow:function(pageId){return window},getDocument:function(pageId){return document},getEl:function(elementId){var element=elementMap.get(elementId);if(!element)throw Error("element destroyed");return element.element},getOffset:function(node){var rect=node.getBoundingClientRect();return Promise.resolve({left:rect.left+window.pageXOffset,top:rect.top+window.pageYOffset})},querySelector:function(context,selector){return"page"===selector&&(selector="body"),Promise.resolve(transEl(context.querySelector(selector)))},querySelectorAll:function(context,selector){var elements=[],nodeList=document.querySelectorAll(selector);return[].forEach.call(nodeList,(function(node){try{elements.push(transEl(node))}catch(e){}})),Promise.resolve({elements:elements})},queryProperties:function(context,names){return Promise.resolve({properties:names.map((function(name){var value=getDataByPath(context,name);return"document.documentElement.scrollTop"===name&&0===value&&(value=getDataByPath(context,"document.body.scrollTop")),value}))})},queryAttributes:function(context,names){return Promise.resolve({attributes:names.map((function(name){return String(context.getAttribute(name))}))})},queryStyles:function(context,names){var style=getComputedStyle(context);return Promise.resolve({styles:names.map((function(name){return style[name]}))})},queryHTML:function(context,type){return Promise.resolve({html:(html="outer"===type?context.outerHTML:context.innerHTML,html.replace(/\n/g,"").replace(/(<uni-text[^>]*>)(<span[^>]*>[^<]*<\/span>)(.*?<\/uni-text>)/g,"$1$3").replace(/<\/?[^>]*>/g,(function(replacement){return-1<replacement.indexOf("<body")?"<page>":"</body>"===replacement?"</page>":0!==replacement.indexOf("<uni-")&&0!==replacement.indexOf("</uni-")?"":replacement.replace(/uni-/g,"").replace(/ role=""/g,"").replace(/ aria-label=""/g,"")})))});var html},dispatchTapEvent:function(el){return el.click(),Promise.resolve()},dispatchLongpressEvent:function(el){return Promise.resolve()},dispatchTouchEvent:function(el,type,eventInitDict){eventInitDict||(eventInitDict={}),eventInitDict.touches||(eventInitDict.touches=[]),eventInitDict.changedTouches||(eventInitDict.changedTouches=[]),eventInitDict.touches.length||eventInitDict.touches.push({identifier:Date.now(),target:el});var touches=createTouchList(eventInitDict.touches),changedTouches=createTouchList(eventInitDict.changedTouches),targetTouches=createTouchList([]);return el.dispatchEvent(new TouchEvent(type,{cancelable:!0,bubbles:!0,touches:touches,targetTouches:targetTouches,changedTouches:changedTouches})),Promise.resolve()},callFunction:function(el,functionName,args){var fn=getDataByPath(FUNCTIONS,functionName);return fn?Promise.resolve({result:fn.apply(null,__spreadArrays([el],args))}):Promise.reject(Error(functionName+" not exists"))},triggerEvent:function(el,type,detail){var vm=el.__vue__;return vm.$trigger&&vm.$trigger(type,{},detail),Promise.resolve()}};var Api=Object.assign({},function(adapter){return{"Page.getElement":function(params){return adapter.querySelector(adapter.getDocument(params.pageId),params.selector)},"Page.getElements":function(params){return adapter.querySelectorAll(adapter.getDocument(params.pageId),params.selector)},"Page.getWindowProperties":function(params){return adapter.queryProperties(adapter.getWindow(params.pageId),params.names)}}}(WebAdapter),function(adapter){var getEl=function(params){return adapter.getEl(params.elementId,params.pageId)};return{"Element.getElement":function(params){return adapter.querySelector(getEl(params),params.selector)},"Element.getElements":function(params){return adapter.querySelectorAll(getEl(params),params.selector)},"Element.getDOMProperties":function(params){return adapter.queryProperties(getEl(params),params.names)},"Element.getProperties":function(params){var el=getEl(params),ctx=el.__vue__||el.attr||{};return adapter.queryProperties(ctx,params.names)},"Element.getOffset":function(params){return adapter.getOffset(getEl(params))},"Element.getAttributes":function(params){return adapter.queryAttributes(getEl(params),params.names)},"Element.getStyles":function(params){return adapter.queryStyles(getEl(params),params.names)},"Element.getHTML":function(params){return adapter.queryHTML(getEl(params),params.type)},"Element.tap":function(params){return adapter.dispatchTapEvent(getEl(params))},"Element.longpress":function(params){return adapter.dispatchLongpressEvent(getEl(params))},"Element.touchstart":function(params){return adapter.dispatchTouchEvent(getEl(params),"touchstart",params)},"Element.touchmove":function(params){return adapter.dispatchTouchEvent(getEl(params),"touchmove",params)},"Element.touchend":function(params){return adapter.dispatchTouchEvent(getEl(params),"touchend",params)},"Element.callFunction":function(params){return adapter.callFunction(getEl(params),params.functionName,params.args)},"Element.triggerEvent":function(params){return adapter.triggerEvent(getEl(params),params.type,params.detail)}}}(WebAdapter));function send(data){return UniViewJSBridge.publishHandler("onAutoMessageReceive",data)}UniViewJSBridge.subscribe("sendAutoMessage",(function(_a){var id=_a.id,method=_a.method,params=_a.params,data={id:id},fn=Api[method];if(!fn)return data.error={message:method+" unimplemented"},send(data);try{fn(params).then((function(res){res&&(data.result=res)})).catch((function(err){data.error={message:err.message}})).finally((function(){send(data)}))}catch(err){data.error={message:err.message},send(data)}}));
function __spreadArrays(){for(var s=0,i=0,il=arguments.length;i<il;i++)s+=arguments[i].length;var r=Array(s),k=0;for(i=0;i<il;i++)for(var a=arguments[i],j=0,jl=a.length;j<jl;j++,k++)r[k]=a[j];return r}var getRandomValues="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto),rnds8=new Uint8Array(16);function rng(){if(!getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return getRandomValues(rnds8)}for(var byteToHex=[],i=0;i<256;++i)byteToHex[i]=(i+256).toString(16).substr(1);function v4(options,buf,offset){var i=buf&&offset||0;"string"==typeof options&&(buf="binary"===options?new Array(16):null,options=null);var rnds=(options=options||{}).random||(options.rng||rng)();if(rnds[6]=15&rnds[6]|64,rnds[8]=63&rnds[8]|128,buf)for(var ii=0;ii<16;++ii)buf[i+ii]=rnds[ii];return buf||function(buf,offset){var i=offset||0,bth=byteToHex;return[bth[buf[i++]],bth[buf[i++]],bth[buf[i++]],bth[buf[i++]],"-",bth[buf[i++]],bth[buf[i++]],"-",bth[buf[i++]],bth[buf[i++]],"-",bth[buf[i++]],bth[buf[i++]],"-",bth[buf[i++]],bth[buf[i++]],bth[buf[i++]],bth[buf[i++]],bth[buf[i++]],bth[buf[i++]]].join("")}(rnds)}var hasOwnProperty=Object.prototype.hasOwnProperty,isArray=Array.isArray,PATH_RE=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;function getPaths(path,data){if(isArray(path))return path;if(data&&(val=data,key=path,hasOwnProperty.call(val,key)))return[path];var val,key,res=[];return path.replace(PATH_RE,(function(match,p1,offset,string){return res.push(offset?string.replace(/\\(\\)?/g,"$1"):p1||match),string})),res}function getDataByPath(data,path){var dataPath,paths=getPaths(path,data);for(dataPath=paths.shift();null!=dataPath;){if(null==(data=data[dataPath]))return;dataPath=paths.shift()}return data}function getVmNodeId(vm){if(vm._$weex)return vm._uid;if(vm._$id)return vm._$id;var parent_1=function(vm){for(var parent=vm.$parent;parent;){if(parent._$id)return parent;parent=parent.$parent}}(vm);if(!vm.$parent)return"-1";var vnode=vm.$vnode,context=vnode.context;return context&&context!==parent_1&&context._$id?context._$id+";"+parent_1._$id+","+vnode.data.attrs._i:parent_1._$id+","+vnode.data.attrs._i}var elementMap=new Map;function transEl(el){var _a;if(!function(el){if(el){var tagName=el.tagName;return 0===tagName.indexOf("UNI-")||"BODY"===tagName}return!1}(el))throw Error("no such element");var element,elementId,vm,elem={elementId:(element=el,elementId=element._id,elementId||(elementId=v4(),element._id=elementId,elementMap.set(elementId,{id:elementId,element:element})),elementId),tagName:el.tagName.toLocaleLowerCase().replace("uni-","")};el.__vue__?(vm=el.__vue__)&&(vm.$parent&&vm.$parent.$el===el&&(vm=vm.$parent),vm&&!(null===(_a=vm.$options)||void 0===_a?void 0:_a.isReserved)&&(elem.nodeId=getVmNodeId(vm))):(vm=el.__vnode)&&(vm.el===el&&(vm=vm.ctx.parent),vm&&(elem.nodeId=getVmNodeId(vm)));return"video"===elem.tagName&&(elem.videoId=elem.nodeId),elem}var FUNCTIONS={input:{input:function(el,value){var vm=el.__vue__;vm.valueSync=value,vm.$triggerInput({},{value:value})}},textarea:{input:function(el,value){var vm=el.__vue__;vm.valueSync=value,vm.$triggerInput({},{value:value})}},"scroll-view":{scrollTo:function(el,x,y){var main=el.__vue__.$refs.main;main.scrollLeft=x,main.scrollTop=y},scrollTop:function(el){return el.__vue__.$refs.main.scrollTop},scrollLeft:function(el){return el.__vue__.$refs.main.scrollLeft},scrollWidth:function(el){return el.__vue__.$refs.main.scrollWidth},scrollHeight:function(el){return el.__vue__.$refs.main.scrollHeight}},swiper:{swipeTo:function(el,index){el.__vue__.current=index}},"movable-view":{moveTo:function(el,x,y){el.__vue__._animationTo(x,y)}},switch:{tap:function(el){el.click()}},slider:{slideTo:function(el,value){var vm=el.__vue__,slider=vm.$refs["uni-slider"],offsetWidth=slider.offsetWidth,boxLeft=slider.getBoundingClientRect().left;vm.value=value,vm._onClick({x:(value-vm.min)*offsetWidth/(vm.max-vm.min)+boxLeft})}}};function createTouchList(touchInits){var _a,touches=touchInits.map((function(touch){return function(touch){if(document.createTouch)return document.createTouch(window,touch.target,touch.identifier,touch.pageX,touch.pageY,touch.screenX,touch.screenY);return new Touch(touch)}(touch)}));return document.createTouchList?(_a=document).createTouchList.apply(_a,touches):touches}var WebAdapter={getWindow:function(pageId){return window},getDocument:function(pageId){return document},getEl:function(elementId){var element=elementMap.get(elementId);if(!element)throw Error("element destroyed");return element.element},getOffset:function(node){var rect=node.getBoundingClientRect();return Promise.resolve({left:rect.left+window.pageXOffset,top:rect.top+window.pageYOffset})},querySelector:function(context,selector){return"page"===selector&&(selector="body"),Promise.resolve(transEl(context.querySelector(selector)))},querySelectorAll:function(context,selector){var elements=[],nodeList=document.querySelectorAll(selector);return[].forEach.call(nodeList,(function(node){try{elements.push(transEl(node))}catch(e){}})),Promise.resolve({elements:elements})},queryProperties:function(context,names){return Promise.resolve({properties:names.map((function(name){var value=getDataByPath(context,name);return"document.documentElement.scrollTop"===name&&0===value&&(value=getDataByPath(context,"document.body.scrollTop")),value}))})},queryAttributes:function(context,names){return Promise.resolve({attributes:names.map((function(name){return String(context.getAttribute(name))}))})},queryStyles:function(context,names){var style=getComputedStyle(context);return Promise.resolve({styles:names.map((function(name){return style[name]}))})},queryHTML:function(context,type){return Promise.resolve({html:(html="outer"===type?context.outerHTML:context.innerHTML,html.replace(/\n/g,"").replace(/(<uni-text[^>]*>)(<span[^>]*>[^<]*<\/span>)(.*?<\/uni-text>)/g,"$1$3").replace(/<\/?[^>]*>/g,(function(replacement){return-1<replacement.indexOf("<body")?"<page>":"</body>"===replacement?"</page>":0!==replacement.indexOf("<uni-")&&0!==replacement.indexOf("</uni-")?"":replacement.replace(/uni-/g,"").replace(/ role=""/g,"").replace(/ aria-label=""/g,"")})))});var html},dispatchTapEvent:function(el){return el.click(),Promise.resolve()},dispatchLongpressEvent:function(el){return Promise.resolve()},dispatchTouchEvent:function(el,type,eventInitDict){eventInitDict||(eventInitDict={}),eventInitDict.touches||(eventInitDict.touches=[]),eventInitDict.changedTouches||(eventInitDict.changedTouches=[]),eventInitDict.touches.length||eventInitDict.touches.push({identifier:Date.now(),target:el});var touches=createTouchList(eventInitDict.touches),changedTouches=createTouchList(eventInitDict.changedTouches),targetTouches=createTouchList([]);return el.dispatchEvent(new TouchEvent(type,{cancelable:!0,bubbles:!0,touches:touches,targetTouches:targetTouches,changedTouches:changedTouches})),Promise.resolve()},callFunction:function(el,functionName,args){var fn=getDataByPath(FUNCTIONS,functionName);return fn?Promise.resolve({result:fn.apply(null,__spreadArrays([el],args))}):Promise.reject(Error(functionName+" not exists"))},triggerEvent:function(el,type,detail){var vm=el.__vue__;return vm.$trigger&&vm.$trigger(type,{},detail),Promise.resolve()}};var Api=Object.assign({},function(adapter){return{"Page.getElement":function(params){return adapter.querySelector(adapter.getDocument(params.pageId),params.selector)},"Page.getElements":function(params){return adapter.querySelectorAll(adapter.getDocument(params.pageId),params.selector)},"Page.getWindowProperties":function(params){return adapter.queryProperties(adapter.getWindow(params.pageId),params.names)}}}(WebAdapter),function(adapter){var getEl=function(params){return adapter.getEl(params.elementId,params.pageId)};return{"Element.getElement":function(params){return adapter.querySelector(getEl(params),params.selector)},"Element.getElements":function(params){return adapter.querySelectorAll(getEl(params),params.selector)},"Element.getDOMProperties":function(params){return adapter.queryProperties(getEl(params),params.names)},"Element.getProperties":function(params){var el=getEl(params),ctx=el.__vue__||el.attr||{};return adapter.queryProperties(ctx,params.names)},"Element.getOffset":function(params){return adapter.getOffset(getEl(params))},"Element.getAttributes":function(params){return adapter.queryAttributes(getEl(params),params.names)},"Element.getStyles":function(params){return adapter.queryStyles(getEl(params),params.names)},"Element.getHTML":function(params){return adapter.queryHTML(getEl(params),params.type)},"Element.tap":function(params){return adapter.dispatchTapEvent(getEl(params))},"Element.longpress":function(params){return adapter.dispatchLongpressEvent(getEl(params))},"Element.touchstart":function(params){return adapter.dispatchTouchEvent(getEl(params),"touchstart",params)},"Element.touchmove":function(params){return adapter.dispatchTouchEvent(getEl(params),"touchmove",params)},"Element.touchend":function(params){return adapter.dispatchTouchEvent(getEl(params),"touchend",params)},"Element.callFunction":function(params){return adapter.callFunction(getEl(params),params.functionName,params.args)},"Element.triggerEvent":function(params){return adapter.triggerEvent(getEl(params),params.type,params.detail)}}}(WebAdapter));function send(data){return UniViewJSBridge.publishHandler("onAutoMessageReceive",data)}UniViewJSBridge.subscribe("sendAutoMessage",(function(_a){var id=_a.id,method=_a.method,params=_a.params,data={id:id},fn=Api[method];if(!fn)return data.error={message:method+" unimplemented"},send(data);try{fn(params).then((function(res){res&&(data.result=res)})).catch((function(err){data.error={message:err.message}})).finally((function(){send(data)}))}catch(err){data.error={message:err.message},send(data)}}));
此差异已折叠。
"use strict";var e=require("os"),t=require("path"),s=require("debug"),r=require("licia/isWindows"),a=require("fs"),n=require("child_process"),o=require("licia/sleep"),i=require("licia/toStr"),c=require("licia/waitUntil"),l=require("licia/concat"),u=require("licia/getPort"),p=require("licia/dateFormat"),d=require("ws"),m=require("events"),f=require("licia/uuid"),h=require("licia/stringify");function g(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var w=g(e),y=g(t),v=g(s),E=g(r),b=g(a),P=g(n),j=g(o),M=g(i),$=g(c),O=g(l),A=g(u),q=g(p),C=g(d),S=g(f),T=g(h);const H=/(^[a-z][a-z0-9-]*)/i,L=/^navigator/i,R=/^swan-nav$/i;var N;!function(e){e.SELECTOR="selector",e.TAGNAME="tagName"}(N||(N={}));const k={[N.SELECTOR]:[{test:L,processor:e=>e.replace(L,"nav")},{test:H,processor:e=>`swan-${e}`}],[N.TAGNAME]:[{test:R,processor:e=>e.replace(R,"swan-navigator")},{test:H,processor:e=>e.toLocaleLowerCase().replace("swan-","")}]},D=e=>t=>{const s=(k[e]||[]).filter((e=>e.test.test(t)));for(const e of s)t=e.processor(t);return t},x=D(N.SELECTOR),I=D(N.TAGNAME),F=e=>Object.assign({},e,{type:"id",info:{id:e.elementId}});/^win/.test(process.platform);class _ extends m.EventEmitter{constructor(e){super(),this.ws=e,this.ws.addEventListener("message",(e=>{this.emit("message",e.data)})),this.ws.addEventListener("close",(()=>{this.emit("close")}))}send(e){this.ws.send(e)}close(){this.ws.close()}}const U=new Map,W=new Map,B="Connection closed";class G extends m.EventEmitter{constructor(e,t,s){super(),this.puppet=t,this.namespace=s,this.callbacks=new Map,this.transport=e,this.isAlive=!0,this.id=Date.now(),this.debug=v.default("automator:protocol:"+this.namespace),this.onMessage=e=>{var t,s;if(this.isAlive=!0,"true"===process.env.UNI_APP_X&&e.includes("pong"))return;this.debug(`${q.default("yyyy-mm-dd HH:MM:ss:l")} ◀ RECV ${e}`);const{id:r,method:a,error:n,result:o,params:i}=JSON.parse(e);if(null===(t=null==o?void 0:o.method)||void 0===t?void 0:t.startsWith("on"))return void((e,t)=>{const s=U.get(e.method);(null==s?void 0:s.has(t))&&s.get(t)(e.data)})(o,r);if(null===(s=null==o?void 0:o.method)||void 0===s?void 0:s.startsWith("Socket.")){return void((e,t,s)=>{const r=W.get(t);(null==r?void 0:r.has(e))&&r.get(e)(s)})(o.method.replace("Socket.",""),o.id,o.data)}if(!r)return this.puppet.emit(a,i);const{callbacks:c}=this;if(r&&c.has(r)){const e=c.get(r);c.delete(r),n?e.reject(Error(n.message||n.detailMessage||n.errMsg)):e.resolve(o)}},this.onClose=()=>{this.callbacks.forEach((e=>{e.reject(Error(B))}))},this.transport.on("message",this.onMessage),this.transport.on("close",this.onClose)}send(e,t={},s=!0){if(s&&this.puppet.adapter.has(e))return this.puppet.adapter.send(this,e,t);const r=S.default(),a=T.default({id:r,method:e,params:t});return"ping"!==e&&this.debug(`${q.default("yyyy-mm-dd HH:MM:ss:l")} SEND ► ${a}`),new Promise(((e,t)=>{try{this.transport.send(a)}catch(e){t(Error(B))}this.callbacks.set(r,{resolve:e,reject:t})}))}dispose(){this.transport.close()}startHeartbeat(){if("true"===process.env.UNI_APP_X&&"android"===process.env.UNI_APP_PLATFORM){const e=new Map,t=function(e){try{return require(e)}catch(t){return require(require.resolve(e,{paths:[process.cwd()]}))}}("adbkit"),s=5e3,r=w.default.platform();let a="",n="";"darwin"===r?(a='dumpsys activity | grep "Run"',n=`logcat -b crash | grep -C 10 ${"io.dcloud.uniappx"}`):"win32"===r&&(a='dumpsys activity | findstr "Run"',n="logcat | findstr UncaughtExceptionHandler"),e.set(this.id,setInterval((async()=>{if(!this.isAlive){const s=t.createClient(),r=await s.listDevices();if(!r.length)throw Error("Device not found");const o=r[0].id;return s.shell(o,a).then((function(e){let t,s="";e.on("data",(function(e){s+=e.toString(),t&&clearTimeout(t),t=setTimeout((()=>{s.includes("io.dcloud.uniapp")||console.log("Stop the test process.")}),50)}))})),s.shell(o,n).then((e=>{let t,s="";e.on("data",(e=>{s+=e.toString(),t&&clearTimeout(t),t=setTimeout((()=>{console.log(`crash log: ${s}`)}),50)}))})),clearInterval(e.get(this.id)),e.delete(this.id),void this.dispose()}this.send("ping"),this.isAlive=!1}),s))}}static createDevtoolConnection(e,t){return new Promise(((s,r)=>{const a=new C.default(e);a.addEventListener("open",(()=>{s(new G(new _(a),t,"devtool"))})),a.addEventListener("error",r)}))}static createRuntimeConnection(e,t,s){return new Promise(((r,a)=>{v.default("automator:runtime")(`${q.default("yyyy-mm-dd HH:MM:ss:l")} port=${e}`);const n=new C.default.Server({port:e});$.default((async()=>{if(t.runtimeConnection)return!0}),s,1e3).catch((()=>{n.close(),a("Failed to connect to runtime, please make sure the project is running")})),n.on("connection",(function(e){v.default("automator:runtime")(`${q.default("yyyy-mm-dd HH:MM:ss:l")} connected`);const s=new G(new _(e),t,"runtime");t.setRuntimeConnection(s),s.startHeartbeat(),r(s)})),t.setRuntimeServer(n)}))}}const z=v.default("automator:devtool");async function X(e,t,s){const{port:r,cliPath:a,timeout:n,cwd:o="",account:i="",args:c=[],launch:l=!0}=t;let u=!1,p=!1;if(!1!==l){const t={stdio:"ignore"};o&&(t.cwd=o);let s=O.default(c,[]);s=O.default(s,["--auto"]),s=O.default(s,[e,"--auto-port",M.default(r)]),i&&(s=O.default(s,["--auto-account",i]));try{z("%s %o %o",a,s,t);const e=P.default.spawn(a,s,t);e.on("error",(e=>{u=!0})),e.on("exit",(()=>{setTimeout((()=>{p=!0}),15e3)})),e.unref()}catch(e){u=!1}}else setTimeout((()=>{p=!0}),15e3);const d=await $.default((async()=>{try{if(u||p)return!0;const e=await async function(e,t){let s;try{s=await G.createDevtoolConnection(e.wsEndpoint,t)}catch(t){throw Error(`Failed connecting to ${e.wsEndpoint}, check if target project window is opened with automation enabled`)}return s}({wsEndpoint:`ws://127.0.0.1:${r}`},s);return e}catch(e){}}),n,1e3);if(u)throw Error(`Failed to launch ${s.devtools.name}, please make sure cliPath is correctly specified`);if(p)throw Error(`Failed to launch ${s.devtools.name} , please make sure http port is open`);return await j.default(5e3),z(`${q.default("yyyy-mm-dd HH:MM:ss:l")} connected`),d}const J=[];["","-rc"].forEach((e=>{E.default?(J.push(y.default.join(w.default.homedir(),`AppData/Local/Programs/swan-ide-gui${e}/cli.bat`)),J.push(`C:/Program Files/swan-ide-gui${e}/cli.bat`)):J.push(`/Applications/百度开发者工具${e}.app/Contents/MacOS/cli`)}));const V={devtools:{name:"Baidu DevTools",remote:!0,automator:!0,paths:J,required:["project.swan.json","app.json","app.js"],defaultPort:9430,validate:async function(e,t){const s=function(e,t){const s=t.devtools.paths.slice(0);e&&s.unshift(e);for(const e of s)if(b.default.existsSync(e))return e;throw Error(`${t.devtools.name} not found, please specify executablePath option`)}(e.executablePath,t);let r=e.port||t.devtools.defaultPort;if(!1!==e.launch)try{r=await async function(e,t){const s=await A.default(e||t);if(e&&s!==e)throw Error(`Port ${e} is in use, please specify another port`);return s}(r)}catch(t){e.launch=!1}else{r===await A.default(r)&&(e.launch=!0)}return Object.assign(Object.assign({},e),{port:r,cliPath:s})},async create(e,t,s){const r=await X(e,t,s);return s.compiled?v.default("automator:devtool")("Waiting for runtime automator"):(v.default("automator:devtool")("initRuntimeAutomator"),r.send("smartapp.swan",{api:"$$initRuntimeAutomator",params:[]})),r}},adapter:{"Tool.enableRemoteDebug":{reflect:async e=>({qrCode:(await e("Tool.enablePreview")).url})},"App.exit":{reflect:async()=>Promise.resolve()},"Page.getElement":{reflect:async(e,t)=>(await e("Page.getElements",t)).elements[0]},"Page.getElements":{reflect:async(e,t)=>{return{elements:(await e("smartapp.element.getBySelector",Object.assign(Object.assign({},t),{properties:["id","tagName"],selector:(s=t.selector,s.split(" ").map((e=>x(e))).join(" "))}))).map((e=>{const t=e.properties;return{elementId:t.id,nodeId:t.id,tagName:I(t.tagName)}}))};var s}},"Page.getWindowProperties":{reflect:async(e,t)=>{const s=t.names.map((e=>e.replace("document.documentElement.",""))),r=(await e("smartapp.element.getBySelector",{properties:s,selector:"html"}))[0];return{properties:s.map((e=>r.properties[e]))}}},"Element.getHTML":{reflect:async(e,t)=>{const s=[t.type+"HTML"];return{html:(await e("Element.getDOMProperties",Object.assign(Object.assign({},t),{names:s}))).properties[0]}}},"Element.getElement":{reflect:async(e,t)=>(await e("Element.getElements",t)).elements[0]},"Element.getElements":{reflect:async(e,t)=>{const{elements:s}=await e("Page.getElements",Object.assign(Object.assign({},t),{selector:`#${t.elementId} ${t.selector}`}));return s.forEach((e=>{e.nodeId=e.id})),{elements:s}}},"Element.getAttributes":{reflect:async(e,t)=>{const s=[];for(const r of t.names)s.push(await e("smartapp.element.getAttribute",Object.assign({attribute:r},t)));return{attributes:s}},params:F},"Element.getStyles":{reflect:async(e,t)=>{const s=[];for(const r of t.names)s.push(await e("smartapp.element.getComputedStyle",Object.assign({style:r},t)));return{styles:s}},params:F},"Element.getDOMProperties":{reflect:async(e,t)=>{const s=[];for(const r of t.names)s.push(await e("smartapp.element.getProperty",Object.assign({property:r},t)));return{properties:s}},params:F},"Element.getProperties":{reflect:async(e,t)=>{const s=[];for(const r of t.names)s.push(await e("smartapp.element.getAttribute",Object.assign({attribute:r},t)));return{properties:s}},params:F},"Element.getOffset":{reflect:async(e,t)=>({left:await e("smartapp.element.getProperty",Object.assign({property:"offsetLeft"},t)),top:await e("smartapp.element.getProperty",Object.assign({property:"offsetTop"},t))}),params:F},"Element.tap":{reflect:"smartapp.element.touch",params:F}}};module.exports=V;
"use strict";var e=require("os"),t=require("path"),s=require("debug"),r=require("licia/isWindows"),a=require("fs"),n=require("child_process"),o=require("licia/sleep"),i=require("licia/toStr"),c=require("licia/waitUntil"),l=require("licia/concat"),u=require("licia/getPort"),p=require("licia/dateFormat"),d=require("ws"),m=require("events"),f=require("licia/uuid"),h=require("licia/stringify");function g(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var w=g(e),y=g(t),v=g(s),E=g(r),b=g(a),P=g(n),j=g(o),M=g(i),$=g(c),O=g(l),A=g(u),q=g(p),C=g(d),S=g(f),T=g(h);const H=/(^[a-z][a-z0-9-]*)/i,L=/^navigator/i,R=/^swan-nav$/i;var N;!function(e){e.SELECTOR="selector",e.TAGNAME="tagName"}(N||(N={}));const k={[N.SELECTOR]:[{test:L,processor:e=>e.replace(L,"nav")},{test:H,processor:e=>`swan-${e}`}],[N.TAGNAME]:[{test:R,processor:e=>e.replace(R,"swan-navigator")},{test:H,processor:e=>e.toLocaleLowerCase().replace("swan-","")}]},D=e=>t=>{const s=(k[e]||[]).filter((e=>e.test.test(t)));for(const e of s)t=e.processor(t);return t},x=D(N.SELECTOR),I=D(N.TAGNAME),F=e=>Object.assign({},e,{type:"id",info:{id:e.elementId}});/^win/.test(process.platform);class _ extends m.EventEmitter{constructor(e){super(),this.ws=e,this.ws.addEventListener("message",(e=>{this.emit("message",e.data)})),this.ws.addEventListener("close",(()=>{this.emit("close")}))}send(e){this.ws.send(e)}close(){this.ws.close()}}const U=new Map,W=new Map,B="Connection closed";class G extends m.EventEmitter{constructor(e,t,s){super(),this.puppet=t,this.namespace=s,this.callbacks=new Map,this.transport=e,this.isAlive=!0,this.id=Date.now(),this.debug=v.default("automator:protocol:"+this.namespace),this.onMessage=e=>{var t,s;if(this.isAlive=!0,"true"===process.env.UNI_APP_X&&e.includes("pong"))return;this.debug(`${q.default("yyyy-mm-dd HH:MM:ss:l")} ◀ RECV ${e}`);const{id:r,method:a,error:n,result:o,params:i}=JSON.parse(e);if(null===(t=null==o?void 0:o.method)||void 0===t?void 0:t.startsWith("on"))return void((e,t)=>{const s=U.get(e.method);(null==s?void 0:s.has(t))&&s.get(t)(e.data)})(o,r);if(null===(s=null==o?void 0:o.method)||void 0===s?void 0:s.startsWith("Socket.")){return void((e,t,s)=>{const r=W.get(t);(null==r?void 0:r.has(e))&&r.get(e)(s)})(o.method.replace("Socket.",""),o.id,o.data)}if(!r)return this.puppet.emit(a,i);const{callbacks:c}=this;if(r&&c.has(r)){const e=c.get(r);c.delete(r),n?e.reject(Error(n.message||n.detailMessage||n.errMsg)):e.resolve(o)}},this.onClose=()=>{this.callbacks.forEach((e=>{e.reject(Error(B))}))},this.transport.on("message",this.onMessage),this.transport.on("close",this.onClose)}send(e,t={},s=!0){if(s&&this.puppet.adapter.has(e))return this.puppet.adapter.send(this,e,t);const r=S.default(),a=T.default({id:r,method:e,params:t});return"ping"!==e&&this.debug(`${q.default("yyyy-mm-dd HH:MM:ss:l")} SEND ► ${a}`),new Promise(((e,t)=>{try{this.transport.send(a)}catch(e){t(Error(B))}this.callbacks.set(r,{resolve:e,reject:t})}))}dispose(){this.transport.close()}startHeartbeat(){if("true"===process.env.UNI_APP_X&&"android"===process.env.UNI_APP_PLATFORM){const e=new Map,t=function(e){try{return require(e)}catch(t){return require(require.resolve(e,{paths:[process.cwd()]}))}}("adbkit"),s=9e3,r=w.default.platform();let a="",n="";"darwin"===r?(a='dumpsys activity | grep "Run"',n=`logcat -b crash | grep -C 10 ${"io.dcloud.uniappx"}`):"win32"===r&&(a='dumpsys activity | findstr "Run"',n="logcat | findstr UncaughtExceptionHandler"),e.set(this.id,setInterval((async()=>{if(!this.isAlive){const s=t.createClient(),r=await s.listDevices();if(!r.length)throw Error("Device not found");const o=r[0].id;return s.shell(o,a).then((function(e){let t,s="";e.on("data",(function(e){s+=e.toString(),t&&clearTimeout(t),t=setTimeout((()=>{s.includes("io.dcloud.uniapp")||console.log("Stop the test process.")}),50)}))})),s.shell(o,n).then((e=>{let t,s="";e.on("data",(e=>{s+=e.toString(),t&&clearTimeout(t),t=setTimeout((()=>{console.log(`crash log: ${s}`)}),50)}))})),clearInterval(e.get(this.id)),e.delete(this.id),void this.dispose()}this.send("ping"),this.isAlive=!1}),s))}}static createDevtoolConnection(e,t){return new Promise(((s,r)=>{const a=new C.default(e);a.addEventListener("open",(()=>{s(new G(new _(a),t,"devtool"))})),a.addEventListener("error",r)}))}static createRuntimeConnection(e,t,s){return new Promise(((r,a)=>{v.default("automator:runtime")(`${q.default("yyyy-mm-dd HH:MM:ss:l")} port=${e}`);const n=new C.default.Server({port:e});$.default((async()=>{if(t.runtimeConnection)return!0}),s,1e3).catch((()=>{n.close(),a("Failed to connect to runtime, please make sure the project is running")})),n.on("connection",(function(e){v.default("automator:runtime")(`${q.default("yyyy-mm-dd HH:MM:ss:l")} connected`);const s=new G(new _(e),t,"runtime");t.setRuntimeConnection(s),s.startHeartbeat(),r(s)})),t.setRuntimeServer(n)}))}}const z=v.default("automator:devtool");async function X(e,t,s){const{port:r,cliPath:a,timeout:n,cwd:o="",account:i="",args:c=[],launch:l=!0}=t;let u=!1,p=!1;if(!1!==l){const t={stdio:"ignore"};o&&(t.cwd=o);let s=O.default(c,[]);s=O.default(s,["--auto"]),s=O.default(s,[e,"--auto-port",M.default(r)]),i&&(s=O.default(s,["--auto-account",i]));try{z("%s %o %o",a,s,t);const e=P.default.spawn(a,s,t);e.on("error",(e=>{u=!0})),e.on("exit",(()=>{setTimeout((()=>{p=!0}),15e3)})),e.unref()}catch(e){u=!1}}else setTimeout((()=>{p=!0}),15e3);const d=await $.default((async()=>{try{if(u||p)return!0;const e=await async function(e,t){let s;try{s=await G.createDevtoolConnection(e.wsEndpoint,t)}catch(t){throw Error(`Failed connecting to ${e.wsEndpoint}, check if target project window is opened with automation enabled`)}return s}({wsEndpoint:`ws://127.0.0.1:${r}`},s);return e}catch(e){}}),n,1e3);if(u)throw Error(`Failed to launch ${s.devtools.name}, please make sure cliPath is correctly specified`);if(p)throw Error(`Failed to launch ${s.devtools.name} , please make sure http port is open`);return await j.default(5e3),z(`${q.default("yyyy-mm-dd HH:MM:ss:l")} connected`),d}const J=[];["","-rc"].forEach((e=>{E.default?(J.push(y.default.join(w.default.homedir(),`AppData/Local/Programs/swan-ide-gui${e}/cli.bat`)),J.push(`C:/Program Files/swan-ide-gui${e}/cli.bat`)):J.push(`/Applications/百度开发者工具${e}.app/Contents/MacOS/cli`)}));const V={devtools:{name:"Baidu DevTools",remote:!0,automator:!0,paths:J,required:["project.swan.json","app.json","app.js"],defaultPort:9430,validate:async function(e,t){const s=function(e,t){const s=t.devtools.paths.slice(0);e&&s.unshift(e);for(const e of s)if(b.default.existsSync(e))return e;throw Error(`${t.devtools.name} not found, please specify executablePath option`)}(e.executablePath,t);let r=e.port||t.devtools.defaultPort;if(!1!==e.launch)try{r=await async function(e,t){const s=await A.default(e||t);if(e&&s!==e)throw Error(`Port ${e} is in use, please specify another port`);return s}(r)}catch(t){e.launch=!1}else{r===await A.default(r)&&(e.launch=!0)}return Object.assign(Object.assign({},e),{port:r,cliPath:s})},async create(e,t,s){const r=await X(e,t,s);return s.compiled?v.default("automator:devtool")("Waiting for runtime automator"):(v.default("automator:devtool")("initRuntimeAutomator"),r.send("smartapp.swan",{api:"$$initRuntimeAutomator",params:[]})),r}},adapter:{"Tool.enableRemoteDebug":{reflect:async e=>({qrCode:(await e("Tool.enablePreview")).url})},"App.exit":{reflect:async()=>Promise.resolve()},"Page.getElement":{reflect:async(e,t)=>(await e("Page.getElements",t)).elements[0]},"Page.getElements":{reflect:async(e,t)=>{return{elements:(await e("smartapp.element.getBySelector",Object.assign(Object.assign({},t),{properties:["id","tagName"],selector:(s=t.selector,s.split(" ").map((e=>x(e))).join(" "))}))).map((e=>{const t=e.properties;return{elementId:t.id,nodeId:t.id,tagName:I(t.tagName)}}))};var s}},"Page.getWindowProperties":{reflect:async(e,t)=>{const s=t.names.map((e=>e.replace("document.documentElement.",""))),r=(await e("smartapp.element.getBySelector",{properties:s,selector:"html"}))[0];return{properties:s.map((e=>r.properties[e]))}}},"Element.getHTML":{reflect:async(e,t)=>{const s=[t.type+"HTML"];return{html:(await e("Element.getDOMProperties",Object.assign(Object.assign({},t),{names:s}))).properties[0]}}},"Element.getElement":{reflect:async(e,t)=>(await e("Element.getElements",t)).elements[0]},"Element.getElements":{reflect:async(e,t)=>{const{elements:s}=await e("Page.getElements",Object.assign(Object.assign({},t),{selector:`#${t.elementId} ${t.selector}`}));return s.forEach((e=>{e.nodeId=e.id})),{elements:s}}},"Element.getAttributes":{reflect:async(e,t)=>{const s=[];for(const r of t.names)s.push(await e("smartapp.element.getAttribute",Object.assign({attribute:r},t)));return{attributes:s}},params:F},"Element.getStyles":{reflect:async(e,t)=>{const s=[];for(const r of t.names)s.push(await e("smartapp.element.getComputedStyle",Object.assign({style:r},t)));return{styles:s}},params:F},"Element.getDOMProperties":{reflect:async(e,t)=>{const s=[];for(const r of t.names)s.push(await e("smartapp.element.getProperty",Object.assign({property:r},t)));return{properties:s}},params:F},"Element.getProperties":{reflect:async(e,t)=>{const s=[];for(const r of t.names)s.push(await e("smartapp.element.getAttribute",Object.assign({attribute:r},t)));return{properties:s}},params:F},"Element.getOffset":{reflect:async(e,t)=>({left:await e("smartapp.element.getProperty",Object.assign({property:"offsetLeft"},t)),top:await e("smartapp.element.getProperty",Object.assign({property:"offsetTop"},t))}),params:F},"Element.tap":{reflect:"smartapp.element.touch",params:F}}};module.exports=V;
"use strict";var e=require("debug"),t=require("licia/isWindows"),o=require("licia/getPort"),n=require("qrcode-reader"),r=require("fs"),a=require("child_process"),s=require("licia/sleep"),i=require("licia/toStr"),c=require("licia/waitUntil"),l=require("licia/concat"),u=require("licia/dateFormat"),d=require("ws"),p=require("events"),h=require("licia/uuid"),f=require("licia/stringify"),m=require("os");function w(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var v=w(e),g=w(t),y=w(o),b=w(n),E=w(r),q=w(a),M=w(s),P=w(i),$=w(c),j=w(l),C=w(u),x=w(d),A=w(h),H=w(f),k=w(m);/^win/.test(process.platform);class S extends p.EventEmitter{constructor(e){super(),this.ws=e,this.ws.addEventListener("message",(e=>{this.emit("message",e.data)})),this.ws.addEventListener("close",(()=>{this.emit("close")}))}send(e){this.ws.send(e)}close(){this.ws.close()}}const T=new Map,R=new Map,D="Connection closed";class F extends p.EventEmitter{constructor(e,t,o){super(),this.puppet=t,this.namespace=o,this.callbacks=new Map,this.transport=e,this.isAlive=!0,this.id=Date.now(),this.debug=v.default("automator:protocol:"+this.namespace),this.onMessage=e=>{var t,o;if(this.isAlive=!0,"true"===process.env.UNI_APP_X&&e.includes("pong"))return;this.debug(`${C.default("yyyy-mm-dd HH:MM:ss:l")} ◀ RECV ${e}`);const{id:n,method:r,error:a,result:s,params:i}=JSON.parse(e);if(null===(t=null==s?void 0:s.method)||void 0===t?void 0:t.startsWith("on"))return void((e,t)=>{const o=T.get(e.method);(null==o?void 0:o.has(t))&&o.get(t)(e.data)})(s,n);if(null===(o=null==s?void 0:s.method)||void 0===o?void 0:o.startsWith("Socket.")){return void((e,t,o)=>{const n=R.get(t);(null==n?void 0:n.has(e))&&n.get(e)(o)})(s.method.replace("Socket.",""),s.id,s.data)}if(!n)return this.puppet.emit(r,i);const{callbacks:c}=this;if(n&&c.has(n)){const e=c.get(n);c.delete(n),a?e.reject(Error(a.message||a.detailMessage||a.errMsg)):e.resolve(s)}},this.onClose=()=>{this.callbacks.forEach((e=>{e.reject(Error(D))}))},this.transport.on("message",this.onMessage),this.transport.on("close",this.onClose)}send(e,t={},o=!0){if(o&&this.puppet.adapter.has(e))return this.puppet.adapter.send(this,e,t);const n=A.default(),r=H.default({id:n,method:e,params:t});return"ping"!==e&&this.debug(`${C.default("yyyy-mm-dd HH:MM:ss:l")} SEND ► ${r}`),new Promise(((e,t)=>{try{this.transport.send(r)}catch(e){t(Error(D))}this.callbacks.set(n,{resolve:e,reject:t})}))}dispose(){this.transport.close()}startHeartbeat(){if("true"===process.env.UNI_APP_X&&"android"===process.env.UNI_APP_PLATFORM){const e=new Map,t=function(e){try{return require(e)}catch(t){return require(require.resolve(e,{paths:[process.cwd()]}))}}("adbkit"),o=5e3,n=k.default.platform();let r="",a="";"darwin"===n?(r='dumpsys activity | grep "Run"',a=`logcat -b crash | grep -C 10 ${"io.dcloud.uniappx"}`):"win32"===n&&(r='dumpsys activity | findstr "Run"',a="logcat | findstr UncaughtExceptionHandler"),e.set(this.id,setInterval((async()=>{if(!this.isAlive){const o=t.createClient(),n=await o.listDevices();if(!n.length)throw Error("Device not found");const s=n[0].id;return o.shell(s,r).then((function(e){let t,o="";e.on("data",(function(e){o+=e.toString(),t&&clearTimeout(t),t=setTimeout((()=>{o.includes("io.dcloud.uniapp")||console.log("Stop the test process.")}),50)}))})),o.shell(s,a).then((e=>{let t,o="";e.on("data",(e=>{o+=e.toString(),t&&clearTimeout(t),t=setTimeout((()=>{console.log(`crash log: ${o}`)}),50)}))})),clearInterval(e.get(this.id)),e.delete(this.id),void this.dispose()}this.send("ping"),this.isAlive=!1}),o))}}static createDevtoolConnection(e,t){return new Promise(((o,n)=>{const r=new x.default(e);r.addEventListener("open",(()=>{o(new F(new S(r),t,"devtool"))})),r.addEventListener("error",n)}))}static createRuntimeConnection(e,t,o){return new Promise(((n,r)=>{v.default("automator:runtime")(`${C.default("yyyy-mm-dd HH:MM:ss:l")} port=${e}`);const a=new x.default.Server({port:e});$.default((async()=>{if(t.runtimeConnection)return!0}),o,1e3).catch((()=>{a.close(),r("Failed to connect to runtime, please make sure the project is running")})),a.on("connection",(function(e){v.default("automator:runtime")(`${C.default("yyyy-mm-dd HH:MM:ss:l")} connected`);const o=new F(new S(e),t,"runtime");t.setRuntimeConnection(o),o.startHeartbeat(),n(o)})),t.setRuntimeServer(a)}))}}const L=v.default("automator:devtool");async function O(e,t,o){const{port:n,cliPath:r,timeout:a,cwd:s="",account:i="",args:c=[],launch:l=!0}=t;let u=!1,d=!1;if(!1!==l){const t={stdio:"ignore",detached:!0};s&&(t.cwd=s);let o=j.default(c,[]);o=j.default(o,["auto","--project"]),o=j.default(o,[e,"--auto-port",P.default(n)]),i&&(o=j.default(o,["--auto-account",i]));try{L("%s %o %o",r,o,t);const e=q.default.spawn(r,o,t);e.on("error",(e=>{u=!0})),e.on("exit",(()=>{setTimeout((()=>{d=!0}),15e3)})),e.unref()}catch(e){u=!1}}else setTimeout((()=>{d=!0}),15e3);const p=await $.default((async()=>{try{if(u||d)return!0;const e=await async function(e,t){let o;try{o=await F.createDevtoolConnection(e.wsEndpoint,t)}catch(t){throw Error(`Failed connecting to ${e.wsEndpoint}, check if target project window is opened with automation enabled`)}return o}({wsEndpoint:`ws://127.0.0.1:${n}`},o);return e}catch(e){}}),a,1e3);if(u)throw Error(`Failed to launch ${o.devtools.name}, please make sure cliPath is correctly specified`);if(d)throw Error(`Failed to launch ${o.devtools.name} , please make sure http port is open`);return await M.default(5e3),L(`${C.default("yyyy-mm-dd HH:MM:ss:l")} connected`),p}const W={devtools:{name:"Wechat web devTools",remote:!0,automator:!0,paths:[g.default?"C:/Program Files (x86)/Tencent/微信web开发者工具/cli.bat":"/Applications/wechatwebdevtools.app/Contents/MacOS/cli"],required:["project.config.json","app.json","app.js"],defaultPort:9420,validate:async function(e,t){const o=function(e,t){const o=t.devtools.paths.slice(0);e&&o.unshift(e);for(const e of o)if(E.default.existsSync(e))return e;throw Error(`${t.devtools.name} not found, please specify executablePath option`)}(e.executablePath,t);let n=e.port||t.devtools.defaultPort;if(!1!==e.launch)try{n=await async function(e,t){const o=await y.default(e||t);if(e&&o!==e)throw Error(`Port ${e} is in use, please specify another port`);return o}(n)}catch(t){e.launch=!1}else{n===await y.default(n)&&(e.launch=!0)}return Object.assign(Object.assign({},e),{port:n,cliPath:o})},async create(e,t,o){const n=await O(e,t,o);return o.compiled?v.default("automator:devtool")("Waiting for runtime automator"):(v.default("automator:devtool")("initRuntimeAutomator"),n.send("App.callWxMethod",{method:"$$initRuntimeAutomator",args:[]})),n}},adapter:{"Tool.enableRemoteDebug":{reflect:async(e,t)=>{let{qrCode:o}=await e("Tool.enableRemoteDebug",t,!1);return o&&(o=await function(e){const t=new Buffer(e,"base64");return new Promise((async(e,o)=>{const n=await require("jimp").read(t),r=new b.default;r.callback=function(t,n){if(t)return o(t);e(n.result)},r.decode(n.bitmap)}))}(o)),{qrCode:o}}},"App.callFunction":{reflect:async(e,t)=>{return e("App.callFunction",Object.assign(Object.assign({},t),{functionDeclaration:(o=t.functionDeclaration,"}"===o[o.length-1]?o.replace("{","{\nvar uni = wx;\n"):o.replace("=>","=>{\nvar uni = wx;\nreturn ")+"}")}),!1);var o}},"Element.getHTML":{reflect:async(e,t)=>({html:(await e("Element.getWXML",t,!1)).wxml})}}};module.exports=W;
"use strict";var e=require("debug"),t=require("licia/isWindows"),o=require("licia/getPort"),n=require("qrcode-reader"),r=require("fs"),a=require("child_process"),s=require("licia/sleep"),i=require("licia/toStr"),c=require("licia/waitUntil"),l=require("licia/concat"),u=require("licia/dateFormat"),d=require("ws"),p=require("events"),h=require("licia/uuid"),f=require("licia/stringify"),m=require("os");function w(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var v=w(e),g=w(t),y=w(o),b=w(n),E=w(r),q=w(a),M=w(s),P=w(i),$=w(c),j=w(l),C=w(u),x=w(d),A=w(h),H=w(f),k=w(m);/^win/.test(process.platform);class S extends p.EventEmitter{constructor(e){super(),this.ws=e,this.ws.addEventListener("message",(e=>{this.emit("message",e.data)})),this.ws.addEventListener("close",(()=>{this.emit("close")}))}send(e){this.ws.send(e)}close(){this.ws.close()}}const T=new Map,R=new Map,D="Connection closed";class F extends p.EventEmitter{constructor(e,t,o){super(),this.puppet=t,this.namespace=o,this.callbacks=new Map,this.transport=e,this.isAlive=!0,this.id=Date.now(),this.debug=v.default("automator:protocol:"+this.namespace),this.onMessage=e=>{var t,o;if(this.isAlive=!0,"true"===process.env.UNI_APP_X&&e.includes("pong"))return;this.debug(`${C.default("yyyy-mm-dd HH:MM:ss:l")} ◀ RECV ${e}`);const{id:n,method:r,error:a,result:s,params:i}=JSON.parse(e);if(null===(t=null==s?void 0:s.method)||void 0===t?void 0:t.startsWith("on"))return void((e,t)=>{const o=T.get(e.method);(null==o?void 0:o.has(t))&&o.get(t)(e.data)})(s,n);if(null===(o=null==s?void 0:s.method)||void 0===o?void 0:o.startsWith("Socket.")){return void((e,t,o)=>{const n=R.get(t);(null==n?void 0:n.has(e))&&n.get(e)(o)})(s.method.replace("Socket.",""),s.id,s.data)}if(!n)return this.puppet.emit(r,i);const{callbacks:c}=this;if(n&&c.has(n)){const e=c.get(n);c.delete(n),a?e.reject(Error(a.message||a.detailMessage||a.errMsg)):e.resolve(s)}},this.onClose=()=>{this.callbacks.forEach((e=>{e.reject(Error(D))}))},this.transport.on("message",this.onMessage),this.transport.on("close",this.onClose)}send(e,t={},o=!0){if(o&&this.puppet.adapter.has(e))return this.puppet.adapter.send(this,e,t);const n=A.default(),r=H.default({id:n,method:e,params:t});return"ping"!==e&&this.debug(`${C.default("yyyy-mm-dd HH:MM:ss:l")} SEND ► ${r}`),new Promise(((e,t)=>{try{this.transport.send(r)}catch(e){t(Error(D))}this.callbacks.set(n,{resolve:e,reject:t})}))}dispose(){this.transport.close()}startHeartbeat(){if("true"===process.env.UNI_APP_X&&"android"===process.env.UNI_APP_PLATFORM){const e=new Map,t=function(e){try{return require(e)}catch(t){return require(require.resolve(e,{paths:[process.cwd()]}))}}("adbkit"),o=9e3,n=k.default.platform();let r="",a="";"darwin"===n?(r='dumpsys activity | grep "Run"',a=`logcat -b crash | grep -C 10 ${"io.dcloud.uniappx"}`):"win32"===n&&(r='dumpsys activity | findstr "Run"',a="logcat | findstr UncaughtExceptionHandler"),e.set(this.id,setInterval((async()=>{if(!this.isAlive){const o=t.createClient(),n=await o.listDevices();if(!n.length)throw Error("Device not found");const s=n[0].id;return o.shell(s,r).then((function(e){let t,o="";e.on("data",(function(e){o+=e.toString(),t&&clearTimeout(t),t=setTimeout((()=>{o.includes("io.dcloud.uniapp")||console.log("Stop the test process.")}),50)}))})),o.shell(s,a).then((e=>{let t,o="";e.on("data",(e=>{o+=e.toString(),t&&clearTimeout(t),t=setTimeout((()=>{console.log(`crash log: ${o}`)}),50)}))})),clearInterval(e.get(this.id)),e.delete(this.id),void this.dispose()}this.send("ping"),this.isAlive=!1}),o))}}static createDevtoolConnection(e,t){return new Promise(((o,n)=>{const r=new x.default(e);r.addEventListener("open",(()=>{o(new F(new S(r),t,"devtool"))})),r.addEventListener("error",n)}))}static createRuntimeConnection(e,t,o){return new Promise(((n,r)=>{v.default("automator:runtime")(`${C.default("yyyy-mm-dd HH:MM:ss:l")} port=${e}`);const a=new x.default.Server({port:e});$.default((async()=>{if(t.runtimeConnection)return!0}),o,1e3).catch((()=>{a.close(),r("Failed to connect to runtime, please make sure the project is running")})),a.on("connection",(function(e){v.default("automator:runtime")(`${C.default("yyyy-mm-dd HH:MM:ss:l")} connected`);const o=new F(new S(e),t,"runtime");t.setRuntimeConnection(o),o.startHeartbeat(),n(o)})),t.setRuntimeServer(a)}))}}const L=v.default("automator:devtool");async function O(e,t,o){const{port:n,cliPath:r,timeout:a,cwd:s="",account:i="",args:c=[],launch:l=!0}=t;let u=!1,d=!1;if(!1!==l){const t={stdio:"ignore",detached:!0};s&&(t.cwd=s);let o=j.default(c,[]);o=j.default(o,["auto","--project"]),o=j.default(o,[e,"--auto-port",P.default(n)]),i&&(o=j.default(o,["--auto-account",i]));try{L("%s %o %o",r,o,t);const e=q.default.spawn(r,o,t);e.on("error",(e=>{u=!0})),e.on("exit",(()=>{setTimeout((()=>{d=!0}),15e3)})),e.unref()}catch(e){u=!1}}else setTimeout((()=>{d=!0}),15e3);const p=await $.default((async()=>{try{if(u||d)return!0;const e=await async function(e,t){let o;try{o=await F.createDevtoolConnection(e.wsEndpoint,t)}catch(t){throw Error(`Failed connecting to ${e.wsEndpoint}, check if target project window is opened with automation enabled`)}return o}({wsEndpoint:`ws://127.0.0.1:${n}`},o);return e}catch(e){}}),a,1e3);if(u)throw Error(`Failed to launch ${o.devtools.name}, please make sure cliPath is correctly specified`);if(d)throw Error(`Failed to launch ${o.devtools.name} , please make sure http port is open`);return await M.default(5e3),L(`${C.default("yyyy-mm-dd HH:MM:ss:l")} connected`),p}const W={devtools:{name:"Wechat web devTools",remote:!0,automator:!0,paths:[g.default?"C:/Program Files (x86)/Tencent/微信web开发者工具/cli.bat":"/Applications/wechatwebdevtools.app/Contents/MacOS/cli"],required:["project.config.json","app.json","app.js"],defaultPort:9420,validate:async function(e,t){const o=function(e,t){const o=t.devtools.paths.slice(0);e&&o.unshift(e);for(const e of o)if(E.default.existsSync(e))return e;throw Error(`${t.devtools.name} not found, please specify executablePath option`)}(e.executablePath,t);let n=e.port||t.devtools.defaultPort;if(!1!==e.launch)try{n=await async function(e,t){const o=await y.default(e||t);if(e&&o!==e)throw Error(`Port ${e} is in use, please specify another port`);return o}(n)}catch(t){e.launch=!1}else{n===await y.default(n)&&(e.launch=!0)}return Object.assign(Object.assign({},e),{port:n,cliPath:o})},async create(e,t,o){const n=await O(e,t,o);return o.compiled?v.default("automator:devtool")("Waiting for runtime automator"):(v.default("automator:devtool")("initRuntimeAutomator"),n.send("App.callWxMethod",{method:"$$initRuntimeAutomator",args:[]})),n}},adapter:{"Tool.enableRemoteDebug":{reflect:async(e,t)=>{let{qrCode:o}=await e("Tool.enableRemoteDebug",t,!1);return o&&(o=await function(e){const t=new Buffer(e,"base64");return new Promise((async(e,o)=>{const n=await require("jimp").read(t),r=new b.default;r.callback=function(t,n){if(t)return o(t);e(n.result)},r.decode(n.bitmap)}))}(o)),{qrCode:o}}},"App.callFunction":{reflect:async(e,t)=>{return e("App.callFunction",Object.assign(Object.assign({},t),{functionDeclaration:(o=t.functionDeclaration,"}"===o[o.length-1]?o.replace("{","{\nvar uni = wx;\n"):o.replace("=>","=>{\nvar uni = wx;\nreturn ")+"}")}),!1);var o}},"Element.getHTML":{reflect:async(e,t)=>({html:(await e("Element.getWXML",t,!1)).wxml})}}};module.exports=W;
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册