@wp-playground/client 0.9.38 → 0.9.40
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/index.cjs +3 -3
- package/index.d.ts +8 -8
- package/index.js +31 -31
- package/package.json +8 -8
package/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Kr=function(){var r;return typeof process<"u"&&((r=process.release)==null?void 0:r.name)==="node"?"NODE":typeof window<"u"?"WEB":typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope?"WORKER":"NODE"}();if(Kr==="NODE"){let r=function(n){return new Promise(function(p,l){n.onload=n.onerror=function(i){n.onload=n.onerror=null,i.type==="load"?p(n.result):l(new Error("Failed to read the blob/file"))}})},t=function(){const n=new Uint8Array([1,2,3,4]),l=new File([n],"test").stream();try{return l.getReader({mode:"byob"}),!0}catch{return!1}};if(typeof File>"u"){class n extends Blob{constructor(l,i,e){super(l);let f;e!=null&&e.lastModified&&(f=new Date),(!f||isNaN(f.getFullYear()))&&(f=new Date),this.lastModifiedDate=f,this.lastModified=f.getMilliseconds(),this.name=i||""}}global.File=n}typeof Blob.prototype.arrayBuffer>"u"&&(Blob.prototype.arrayBuffer=function(){const p=new FileReader;return p.readAsArrayBuffer(this),r(p)}),typeof Blob.prototype.text>"u"&&(Blob.prototype.text=function(){const p=new FileReader;return p.readAsText(this),r(p)}),(typeof Blob.prototype.stream>"u"||!t())&&(Blob.prototype.stream=function(){let n=0;const p=this;return new ReadableStream({type:"bytes",autoAllocateChunkSize:512*1024,async pull(l){const i=l.byobRequest.view,f=await p.slice(n,n+i.byteLength).arrayBuffer(),h=new Uint8Array(f);new Uint8Array(i.buffer).set(h);const b=h.byteLength;l.byobRequest.respond(b),n+=b,n>=p.size&&l.close()}})})}if(Kr==="NODE"&&typeof CustomEvent>"u"){class r extends Event{constructor(n,p={}){super(n,p),this.detail=p.detail}initCustomEvent(){}}globalThis.CustomEvent=r}const Ar=["db.php","plugins/akismet","plugins/hello.php","plugins/wordpress-importer","mu-plugins/sqlite-database-integration","mu-plugins/playground-includes","mu-plugins/0-playground.php","mu-plugins/0-sqlite.php","themes/twentytwenty","themes/twentytwentyone","themes/twentytwentytwo","themes/twentytwentythree","themes/twentytwentyfour","themes/twentytwentyfive","themes/twentytwentysix"],Xr=Symbol("SleepFinished");function zt(r){return new Promise(t=>{setTimeout(()=>t(Xr),r)})}class Vt extends Error{constructor(){super("Acquiring lock timed out")}}class Ht{constructor({concurrency:t,timeout:n}){this._running=0,this.concurrency=t,this.timeout=n,this.queue=[]}get remaining(){return this.concurrency-this.running}get running(){return this._running}async acquire(){for(;;)if(this._running>=this.concurrency){const t=new Promise(n=>{this.queue.push(n)});this.timeout!==void 0?await Promise.race([t,zt(this.timeout)]).then(n=>{if(n===Xr)throw new Vt}):await t}else{this._running++;let t=!1;return()=>{t||(t=!0,this._running--,this.queue.length>0&&this.queue.shift()())}}}async run(t){const n=await this.acquire();try{return await t()}finally{n()}}}function ie(...r){function t(i){return i.substring(i.length-1)==="/"}let n=r.join("/");const p=n[0]==="/",l=t(n);return n=rt(n),!n&&!p&&(n="."),n&&l&&!t(n)&&(n+="/"),n}function et(r){if(r==="/")return"/";r=rt(r);const t=r.lastIndexOf("/");return t===-1?"":t===0?"/":r.substr(0,t)}function rt(r){const t=r[0]==="/";return r=Gt(r.split("/").filter(n=>!!n),!t).join("/"),(t?"/":"")+r.replace(/\/$/,"")}function Gt(r,t){let n=0;for(let p=r.length-1;p>=0;p--){const l=r[p];l==="."?r.splice(p,1):l===".."?(r.splice(p,1),n++):n&&(r.splice(p,1),n--)}if(t)for(;n;n--)r.unshift("..");return r}function tt(r=36,t="!@#$%^&*()_+=-[]/.,<>?"){const n="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"+t;let p="";for(let l=r;l>0;--l)p+=n[Math.floor(Math.random()*n.length)];return p}function Yt(){return tt(36,"-_")}function se(r){return`json_decode(base64_decode('${Zt(JSON.stringify(r))}'), true)`}function We(r){const t={};for(const n in r)t[n]=se(r[n]);return t}function Zt(r){return Qt(new TextEncoder().encode(r))}function Qt(r){const t=String.fromCodePoint(...r);return btoa(t)}const Jt="playground-log",Dr=(r,...t)=>{ae.dispatchEvent(new CustomEvent(Jt,{detail:{log:r,args:t}}))},Kt=(r,...t)=>{switch(typeof r.message=="string"?Reflect.set(r,"message",$r(r.message)):r.message.message&&typeof r.message.message=="string"&&Reflect.set(r.message,"message",$r(r.message.message)),r.severity){case"Debug":console.debug(r.message,...t);break;case"Info":console.info(r.message,...t);break;case"Warn":console.warn(r.message,...t);break;case"Error":console.error(r.message,...t);break;case"Fatal":console.error(r.message,...t);break;default:console.log(r.message,...t)}},Xt=r=>r instanceof Error?[r.message,r.stack].join(`
|
|
2
|
-
`):JSON.stringify(r,null,2),st=[],Mr=r=>{st.push(r)},Er=r=>{if(r.raw===!0)Mr(r.message);else{const t=
|
|
2
|
+
`):JSON.stringify(r,null,2),st=[],Mr=r=>{st.push(r)},Er=r=>{if(r.raw===!0)Mr(r.message);else{const t=is(typeof r.message=="object"?Xt(r.message):r.message,r.severity??"Info",r.prefix??"JavaScript");Mr(t)}};let wr=0;const Br="/wordpress/wp-content/debug.log",es=async r=>await r.fileExists(Br)?await r.readFileAsText(Br):"",rs=(r,t)=>{t.addEventListener("request.end",async()=>{const n=await es(t);if(n.length>wr){const p=n.substring(wr);r.logMessage({message:p,raw:!0}),wr=n.length}}),t.addEventListener("request.error",n=>{n=n,n.error&&(r.logMessage({message:`${n.error.message} ${n.error.stack}`,severity:"Fatal",prefix:n.source==="request"?"PHP":"WASM Crash"}),r.dispatchEvent(new CustomEvent(r.fatalErrorEvent,{detail:{logs:r.getLogs(),source:n.source}})))})};class ts extends EventTarget{constructor(t=[]){super(),this.handlers=t,this.fatalErrorEvent="playground-fatal-error"}getLogs(){return this.handlers.includes(Er)?[...st]:(this.error(`Logs aren't stored because the logToMemory handler isn't registered.
|
|
3
3
|
If you're using a custom logger instance, make sure to register logToMemory handler.
|
|
4
|
-
`),[])}logMessage(t,...n){for(const p of this.handlers)p(t,...n)}log(t,...n){this.logMessage({message:t,severity:void 0,prefix:"JavaScript",raw:!1},...n)}debug(t,...n){this.logMessage({message:t,severity:"Debug",prefix:"JavaScript",raw:!1},...n)}info(t,...n){this.logMessage({message:t,severity:"Info",prefix:"JavaScript",raw:!1},...n)}warn(t,...n){this.logMessage({message:t,severity:"Warn",prefix:"JavaScript",raw:!1},...n)}error(t,...n){this.logMessage({message:t,severity:"Error",prefix:"JavaScript",raw:!1},...n)}}const
|
|
4
|
+
`),[])}logMessage(t,...n){for(const p of this.handlers)p(t,...n)}log(t,...n){this.logMessage({message:t,severity:void 0,prefix:"JavaScript",raw:!1},...n)}debug(t,...n){this.logMessage({message:t,severity:"Debug",prefix:"JavaScript",raw:!1},...n)}info(t,...n){this.logMessage({message:t,severity:"Info",prefix:"JavaScript",raw:!1},...n)}warn(t,...n){this.logMessage({message:t,severity:"Warn",prefix:"JavaScript",raw:!1},...n)}error(t,...n){this.logMessage({message:t,severity:"Error",prefix:"JavaScript",raw:!1},...n)}}const ss=()=>{try{if(process.env.NODE_ENV==="test")return[Er,Dr]}catch{}return[Er,Kt,Dr]},ae=new ts(ss()),$r=r=>r.replace(/\t/g,""),is=(r,t,n)=>{const p=new Date,l=new Intl.DateTimeFormat("en-GB",{year:"numeric",month:"short",day:"2-digit",timeZone:"UTC"}).format(p).replace(/ /g,"-"),i=new Intl.DateTimeFormat("en-GB",{hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1,timeZone:"UTC",timeZoneName:"short"}).format(p),e=l+" "+i;return r=$r(r),`[${e}] ${n} ${t}: ${r}`},dr=async(r,{pluginPath:t,pluginName:n},p)=>{p==null||p.tracker.setCaption(`Activating ${n||t}`);const l=await r.documentRoot,i=await r.run({code:`<?php
|
|
5
5
|
define( 'WP_ADMIN', true );
|
|
6
6
|
require_once( ${se(l)}. "/wp-load.php" );
|
|
7
7
|
require_once( ${se(l)}. "/wp-admin/includes/plugin.php" );
|
|
@@ -738,4 +738,4 @@ for existing apps using this option.`}},required:["consts","step"]},{type:"objec
|
|
|
738
738
|
* @license
|
|
739
739
|
* Copyright 2019 Google LLC
|
|
740
740
|
* SPDX-License-Identifier: Apache-2.0
|
|
741
|
-
*/const Ft=Symbol("Comlink.proxy"),Hs=Symbol("Comlink.endpoint"),Gs=Symbol("Comlink.releaseProxy"),Or=Symbol("Comlink.finalizer"),sr=Symbol("Comlink.thrown"),Ct=r=>typeof r=="object"&&r!==null||typeof r=="function",Ys={canHandle:r=>Ct(r)&&r[Ft],serialize(r){const{port1:t,port2:n}=new MessageChannel;return Cr(r,t),[n,[n]]},deserialize(r){return r.start(),Ir(r)}},Zs={canHandle:r=>Ct(r)&&sr in r,serialize({value:r}){let t;return r instanceof Error?t={isError:!0,value:{message:r.message,name:r.name,stack:r.stack}}:t={isError:!1,value:r},[t,[]]},deserialize(r){throw r.isError?Object.assign(new Error(r.value.message),r.value):r.value}},xe=new Map([["proxy",Ys],["throw",Zs]]);function Qs(r,t){for(const n of r)if(t===n||n==="*"||n instanceof RegExp&&n.test(t))return!0;return!1}function Cr(r,t=globalThis,n=["*"]){t.addEventListener("message",function p(l){if(!l||!l.data)return;if(!Qs(n,l.origin)){console.warn(`Invalid origin '${l.origin}' for comlink proxy`);return}const{id:i,type:e,path:f}=Object.assign({path:[]},l.data),h=(l.data.argumentList||[]).map(Re);let b;try{const k=f.slice(0,-1).reduce((w,S)=>w[S],r),m=f.reduce((w,S)=>w[S],r);switch(e){case"GET":b=m;break;case"SET":k[f.slice(-1)[0]]=Re(l.data.value),b=!0;break;case"APPLY":b=m.apply(k,h);break;case"CONSTRUCT":{const w=new m(...h);b=Mt(w)}break;case"ENDPOINT":{const{port1:w,port2:S}=new MessageChannel;Cr(r,S),b=ri(w,[w])}break;case"RELEASE":b=void 0;break;default:return}}catch(k){b={value:k,[sr]:0}}Promise.resolve(b).catch(k=>({value:k,[sr]:0})).then(k=>{const[m,w]=ur(k);t.postMessage(Object.assign(Object.assign({},m),{id:i}),w),e==="RELEASE"&&(t.removeEventListener("message",p),It(t),Or in r&&typeof r[Or]=="function"&&r[Or]())}).catch(k=>{const[m,w]=ur({value:new TypeError("Unserializable return value"),[sr]:0});t.postMessage(Object.assign(Object.assign({},m),{id:i}),w)})}),t.start&&t.start()}function Js(r){return r.constructor.name==="MessagePort"}function It(r){Js(r)&&r.close()}function Ir(r,t){return jr(r,[],t)}function er(r){if(r)throw new Error("Proxy has been released and is not useable")}function Wt(r){return Se(r,{type:"RELEASE"}).then(()=>{It(r)})}const lr=new WeakMap,fr="FinalizationRegistry"in globalThis&&new FinalizationRegistry(r=>{const t=(lr.get(r)||0)-1;lr.set(r,t),t===0&&Wt(r)});function Ks(r,t){const n=(lr.get(t)||0)+1;lr.set(t,n),fr&&fr.register(r,t,r)}function Xs(r){fr&&fr.unregister(r)}function jr(r,t=[],n=function(){}){let p=!1;const l=new Proxy(n,{get(i,e){if(er(p),e===Gs)return()=>{Xs(l),Wt(r),p=!0};if(e==="then"){if(t.length===0)return{then:()=>l};const f=Se(r,{type:"GET",path:t.map(h=>h.toString())}).then(Re);return f.then.bind(f)}return jr(r,[...t,e])},set(i,e,f){er(p);const[h,b]=ur(f);return Se(r,{type:"SET",path:[...t,e].map(k=>k.toString()),value:h},b).then(Re)},apply(i,e,f){er(p);const h=t[t.length-1];if(h===Hs)return Se(r,{type:"ENDPOINT"}).then(Re);if(h==="bind")return jr(r,t.slice(0,-1));const[b,k]=Qr(f);return Se(r,{type:"APPLY",path:t.map(m=>m.toString()),argumentList:b},k).then(Re)},construct(i,e){er(p);const[f,h]=Qr(e);return Se(r,{type:"CONSTRUCT",path:t.map(b=>b.toString()),argumentList:f},h).then(Re)}});return Ks(l,r),l}function ei(r){return Array.prototype.concat.apply([],r)}function Qr(r){const t=r.map(ur);return[t.map(n=>n[0]),ei(t.map(n=>n[1]))]}const Dt=new WeakMap;function ri(r,t){return Dt.set(r,t),r}function Mt(r){return Object.assign(r,{[Ft]:!0})}function ti(r,t=globalThis,n="*"){return{postMessage:(p,l)=>r.postMessage(p,n,l),addEventListener:t.addEventListener.bind(t),removeEventListener:t.removeEventListener.bind(t)}}function ur(r){for(const[t,n]of xe)if(n.canHandle(r)){const[p,l]=n.serialize(r);return[{type:"HANDLER",name:t,value:p},l]}return[{type:"RAW",value:r},Dt.get(r)||[]]}function Re(r){switch(r.type){case"HANDLER":return xe.get(r.name).deserialize(r.value);case"RAW":return r.value}}function Se(r,t,n){return new Promise(p=>{const l=si();r.addEventListener("message",function i(e){!e.data||!e.data.id||e.data.id!==l||(r.removeEventListener("message",i),p(e.data))}),r.start&&r.start(),r.postMessage(Object.assign({id:l},t),n)})}function si(){return new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-")}function ii(r,t=void 0){oi();const n=r instanceof Worker?r:ti(r,t),p=Ir(n),l=Bt(p);return new Proxy(l,{get:(i,e)=>e==="isConnected"?async()=>{for(;;)try{await ni(p.isConnected(),200);break}catch{}}:p[e]})}async function ni(r,t){return new Promise((n,p)=>{setTimeout(p,t),r.then(n)})}let Jr=!1;function oi(){if(Jr)return;Jr=!0,xe.set("EVENT",{canHandle:n=>n instanceof CustomEvent,serialize:n=>[{detail:n.detail},[]],deserialize:n=>n}),xe.set("FUNCTION",{canHandle:n=>typeof n=="function",serialize(n){const{port1:p,port2:l}=new MessageChannel;return Cr(n,p),[l,[l]]},deserialize(n){return n.start(),Ir(n)}}),xe.set("PHPResponse",{canHandle:n=>typeof n=="object"&&n!==null&&"headers"in n&&"bytes"in n&&"errors"in n&&"exitCode"in n&&"httpStatusCode"in n,serialize(n){return[n.toRawData(),[]]},deserialize(n){return pr.fromRawData(n)}});const r=xe.get("throw"),t=r==null?void 0:r.serialize;r.serialize=({value:n})=>{const p=t({value:n});return n.response&&(p[0].value.response=n.response),n.source&&(p[0].value.source=n.source),p}}function Bt(r){return new Proxy(r,{get(t,n){switch(typeof t[n]){case"function":return(...p)=>t[n](...p);case"object":return t[n]===null?t[n]:Bt(t[n]);case"undefined":case"number":case"string":return t[n];default:return Mt(t[n])}}})}new Promise(r=>{});async function ai({iframe:r,blueprint:t,remoteUrl:n,progressTracker:p=new yr,disableProgressBar:l,onBlueprintStepCompleted:i,onClientConnected:e=()=>{},sapiName:f,onBeforeBlueprint:h,mounts:b,shouldInstallWordPress:k}){li(n),pi(r),n=fi(n,{progressbar:!l}),p.setCaption("Preparing WordPress"),t||(t={phpExtensionBundles:["kitchen-sink"]});const m=xt(t,{progress:p.stage(.5),onStepCompleted:i});await new Promise(W=>{r.src=n,r.addEventListener("load",W,!1)});const w=ii(r.contentWindow,r.ownerDocument.defaultView);await w.isConnected(),p.pipe(w);const S=p.stage();return await w.onDownloadProgress(S.loadingListener),await w.boot({mounts:b,sapiName:f,shouldInstallWordPress:k,phpVersion:m.versions.php,wpVersion:m.versions.wp,phpExtensions:m.phpExtensions,withNetworking:m.features.networking}),await w.isReady(),S.finish(),
|
|
741
|
+
*/const Ft=Symbol("Comlink.proxy"),Hs=Symbol("Comlink.endpoint"),Gs=Symbol("Comlink.releaseProxy"),Or=Symbol("Comlink.finalizer"),sr=Symbol("Comlink.thrown"),Ct=r=>typeof r=="object"&&r!==null||typeof r=="function",Ys={canHandle:r=>Ct(r)&&r[Ft],serialize(r){const{port1:t,port2:n}=new MessageChannel;return Cr(r,t),[n,[n]]},deserialize(r){return r.start(),Ir(r)}},Zs={canHandle:r=>Ct(r)&&sr in r,serialize({value:r}){let t;return r instanceof Error?t={isError:!0,value:{message:r.message,name:r.name,stack:r.stack}}:t={isError:!1,value:r},[t,[]]},deserialize(r){throw r.isError?Object.assign(new Error(r.value.message),r.value):r.value}},xe=new Map([["proxy",Ys],["throw",Zs]]);function Qs(r,t){for(const n of r)if(t===n||n==="*"||n instanceof RegExp&&n.test(t))return!0;return!1}function Cr(r,t=globalThis,n=["*"]){t.addEventListener("message",function p(l){if(!l||!l.data)return;if(!Qs(n,l.origin)){console.warn(`Invalid origin '${l.origin}' for comlink proxy`);return}const{id:i,type:e,path:f}=Object.assign({path:[]},l.data),h=(l.data.argumentList||[]).map(Re);let b;try{const k=f.slice(0,-1).reduce((w,S)=>w[S],r),m=f.reduce((w,S)=>w[S],r);switch(e){case"GET":b=m;break;case"SET":k[f.slice(-1)[0]]=Re(l.data.value),b=!0;break;case"APPLY":b=m.apply(k,h);break;case"CONSTRUCT":{const w=new m(...h);b=Mt(w)}break;case"ENDPOINT":{const{port1:w,port2:S}=new MessageChannel;Cr(r,S),b=ri(w,[w])}break;case"RELEASE":b=void 0;break;default:return}}catch(k){b={value:k,[sr]:0}}Promise.resolve(b).catch(k=>({value:k,[sr]:0})).then(k=>{const[m,w]=ur(k);t.postMessage(Object.assign(Object.assign({},m),{id:i}),w),e==="RELEASE"&&(t.removeEventListener("message",p),It(t),Or in r&&typeof r[Or]=="function"&&r[Or]())}).catch(k=>{const[m,w]=ur({value:new TypeError("Unserializable return value"),[sr]:0});t.postMessage(Object.assign(Object.assign({},m),{id:i}),w)})}),t.start&&t.start()}function Js(r){return r.constructor.name==="MessagePort"}function It(r){Js(r)&&r.close()}function Ir(r,t){return jr(r,[],t)}function er(r){if(r)throw new Error("Proxy has been released and is not useable")}function Wt(r){return Se(r,{type:"RELEASE"}).then(()=>{It(r)})}const lr=new WeakMap,fr="FinalizationRegistry"in globalThis&&new FinalizationRegistry(r=>{const t=(lr.get(r)||0)-1;lr.set(r,t),t===0&&Wt(r)});function Ks(r,t){const n=(lr.get(t)||0)+1;lr.set(t,n),fr&&fr.register(r,t,r)}function Xs(r){fr&&fr.unregister(r)}function jr(r,t=[],n=function(){}){let p=!1;const l=new Proxy(n,{get(i,e){if(er(p),e===Gs)return()=>{Xs(l),Wt(r),p=!0};if(e==="then"){if(t.length===0)return{then:()=>l};const f=Se(r,{type:"GET",path:t.map(h=>h.toString())}).then(Re);return f.then.bind(f)}return jr(r,[...t,e])},set(i,e,f){er(p);const[h,b]=ur(f);return Se(r,{type:"SET",path:[...t,e].map(k=>k.toString()),value:h},b).then(Re)},apply(i,e,f){er(p);const h=t[t.length-1];if(h===Hs)return Se(r,{type:"ENDPOINT"}).then(Re);if(h==="bind")return jr(r,t.slice(0,-1));const[b,k]=Qr(f);return Se(r,{type:"APPLY",path:t.map(m=>m.toString()),argumentList:b},k).then(Re)},construct(i,e){er(p);const[f,h]=Qr(e);return Se(r,{type:"CONSTRUCT",path:t.map(b=>b.toString()),argumentList:f},h).then(Re)}});return Ks(l,r),l}function ei(r){return Array.prototype.concat.apply([],r)}function Qr(r){const t=r.map(ur);return[t.map(n=>n[0]),ei(t.map(n=>n[1]))]}const Dt=new WeakMap;function ri(r,t){return Dt.set(r,t),r}function Mt(r){return Object.assign(r,{[Ft]:!0})}function ti(r,t=globalThis,n="*"){return{postMessage:(p,l)=>r.postMessage(p,n,l),addEventListener:t.addEventListener.bind(t),removeEventListener:t.removeEventListener.bind(t)}}function ur(r){for(const[t,n]of xe)if(n.canHandle(r)){const[p,l]=n.serialize(r);return[{type:"HANDLER",name:t,value:p},l]}return[{type:"RAW",value:r},Dt.get(r)||[]]}function Re(r){switch(r.type){case"HANDLER":return xe.get(r.name).deserialize(r.value);case"RAW":return r.value}}function Se(r,t,n){return new Promise(p=>{const l=si();r.addEventListener("message",function i(e){!e.data||!e.data.id||e.data.id!==l||(r.removeEventListener("message",i),p(e.data))}),r.start&&r.start(),r.postMessage(Object.assign({id:l},t),n)})}function si(){return new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-")}function ii(r,t=void 0){oi();const n=r instanceof Worker?r:ti(r,t),p=Ir(n),l=Bt(p);return new Proxy(l,{get:(i,e)=>e==="isConnected"?async()=>{for(;;)try{await ni(p.isConnected(),200);break}catch{}}:p[e]})}async function ni(r,t){return new Promise((n,p)=>{setTimeout(p,t),r.then(n)})}let Jr=!1;function oi(){if(Jr)return;Jr=!0,xe.set("EVENT",{canHandle:n=>n instanceof CustomEvent,serialize:n=>[{detail:n.detail},[]],deserialize:n=>n}),xe.set("FUNCTION",{canHandle:n=>typeof n=="function",serialize(n){const{port1:p,port2:l}=new MessageChannel;return Cr(n,p),[l,[l]]},deserialize(n){return n.start(),Ir(n)}}),xe.set("PHPResponse",{canHandle:n=>typeof n=="object"&&n!==null&&"headers"in n&&"bytes"in n&&"errors"in n&&"exitCode"in n&&"httpStatusCode"in n,serialize(n){return[n.toRawData(),[]]},deserialize(n){return pr.fromRawData(n)}});const r=xe.get("throw"),t=r==null?void 0:r.serialize;r.serialize=({value:n})=>{const p=t({value:n});return n.response&&(p[0].value.response=n.response),n.source&&(p[0].value.source=n.source),p}}function Bt(r){return new Proxy(r,{get(t,n){switch(typeof t[n]){case"function":return(...p)=>t[n](...p);case"object":return t[n]===null?t[n]:Bt(t[n]);case"undefined":case"number":case"string":return t[n];default:return Mt(t[n])}}})}new Promise(r=>{});async function ai({iframe:r,blueprint:t,remoteUrl:n,progressTracker:p=new yr,disableProgressBar:l,onBlueprintStepCompleted:i,onClientConnected:e=()=>{},sapiName:f,onBeforeBlueprint:h,mounts:b,shouldInstallWordPress:k}){li(n),pi(r),n=fi(n,{progressbar:!l}),p.setCaption("Preparing WordPress"),t||(t={phpExtensionBundles:["kitchen-sink"]});const m=xt(t,{progress:p.stage(.5),onStepCompleted:i});await new Promise(W=>{r.src=n,r.addEventListener("load",W,!1)});const w=ii(r.contentWindow,r.ownerDocument.defaultView);await w.isConnected(),p.pipe(w);const S=p.stage();return await w.onDownloadProgress(S.loadingListener),await w.boot({mounts:b,sapiName:f,shouldInstallWordPress:k,phpVersion:m.versions.php,wpVersion:m.versions.wp,phpExtensions:m.phpExtensions,withNetworking:m.features.networking}),await w.isReady(),S.finish(),rs(ae,w),e(w),h&&await h(),await Nt(m,w),p.finish(),w}function pi(r){var t,n;(t=r.sandbox)!=null&&t.length&&!((n=r.sandbox)!=null&&n.contains("allow-storage-access-by-user-activation"))&&r.sandbox.add("allow-storage-access-by-user-activation")}const ir="https://playground.wordpress.net";function li(r){const t=new URL(r,ir);if((t.origin===ir||t.hostname==="localhost")&&t.pathname!=="/remote.html")throw new Error(`Invalid remote URL: ${t}. Expected origin to be ${ir}/remote.html.`)}function fi(r,t){const n=new URL(r,ir),p=new URLSearchParams(n.search);for(const[l,i]of Object.entries(t))if(i!=null&&i!==!1)if(Array.isArray(i))for(const e of i)p.append(l,e.toString());else p.set(l,i.toString());return n.search=p.toString(),n.toString()}exports.LatestSupportedPHPVersion=jt;exports.SupportedPHPVersions=hr;exports.SupportedPHPVersionsList=Ps;exports.activatePlugin=dr;exports.activateTheme=qr;exports.compileBlueprint=xt;exports.cp=ft;exports.defineSiteUrl=xr;exports.defineWpConfigConsts=Ie;exports.enableMultisite=lt;exports.exportWXR=gt;exports.importThemeStarterContent=Nr;exports.importWordPressFiles=ht;exports.importWxr=mt;exports.installPlugin=wt;exports.installTheme=vt;exports.login=or;exports.mkdir=dt;exports.mv=ut;exports.phpVar=se;exports.phpVars=We;exports.request=nr;exports.resetData=Pt;exports.rm=Rr;exports.rmdir=ct;exports.runBlueprintSteps=Nt;exports.runPHP=it;exports.runPHPWithOptions=nt;exports.runSql=ot;exports.runWpInstallationWizard=_t;exports.setPhpIniEntries=vs;exports.setPluginProxyURL=Vs;exports.setSiteLanguage=Et;exports.setSiteOptions=Lr;exports.startPlaygroundWeb=ai;exports.unzip=cr;exports.updateUserMeta=at;exports.wpCLI=Ot;exports.wpContentFilesExcludedFromExport=Ar;exports.writeFile=Sr;exports.zipWpContent=kt;
|
package/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export * from '
|
|
2
|
-
export type { HTTPMethod, PHPRunOptions, PHPRequest, PHPResponse, UniversalPHP, PHPOutput, PHPResponseData, ErrnoError, PHPRequestHandler, PHPRequestHandlerConfiguration, PHPRequestHeaders, SupportedPHPVersion, RmDirOptions, RuntimeType, } from '
|
|
3
|
-
export { setPhpIniEntries, SupportedPHPVersions, SupportedPHPVersionsList, LatestSupportedPHPVersion, } from '
|
|
4
|
-
export type { PlaygroundClient, MountDescriptor } from '
|
|
5
|
-
export { phpVar, phpVars } from '
|
|
6
|
-
import { Blueprint, OnStepCompleted } from '
|
|
7
|
-
import { ProgressTracker } from '
|
|
8
|
-
import type { MountDescriptor, PlaygroundClient } from '
|
|
1
|
+
export * from '@wp-playground/blueprints';
|
|
2
|
+
export type { HTTPMethod, PHPRunOptions, PHPRequest, PHPResponse, UniversalPHP, PHPOutput, PHPResponseData, ErrnoError, PHPRequestHandler, PHPRequestHandlerConfiguration, PHPRequestHeaders, SupportedPHPVersion, RmDirOptions, RuntimeType, } from '@php-wasm/universal';
|
|
3
|
+
export { setPhpIniEntries, SupportedPHPVersions, SupportedPHPVersionsList, LatestSupportedPHPVersion, } from '@php-wasm/universal';
|
|
4
|
+
export type { PlaygroundClient, MountDescriptor } from '@wp-playground/remote';
|
|
5
|
+
export { phpVar, phpVars } from '@php-wasm/util';
|
|
6
|
+
import { Blueprint, OnStepCompleted } from '@wp-playground/blueprints';
|
|
7
|
+
import { ProgressTracker } from '@php-wasm/progress';
|
|
8
|
+
import type { MountDescriptor, PlaygroundClient } from '@wp-playground/remote';
|
|
9
9
|
export interface StartPlaygroundOptions {
|
|
10
10
|
iframe: HTMLIFrameElement;
|
|
11
11
|
remoteUrl: string;
|
package/index.js
CHANGED
|
@@ -239,7 +239,7 @@ const At = "playground-log", Sr = (r, ...t) => {
|
|
|
239
239
|
if (r.raw === !0)
|
|
240
240
|
xr(r.message);
|
|
241
241
|
else {
|
|
242
|
-
const t =
|
|
242
|
+
const t = Ft(
|
|
243
243
|
typeof r.message == "object" ? Rt(r.message) : r.message,
|
|
244
244
|
r.severity ?? "Info",
|
|
245
245
|
r.prefix ?? "JavaScript"
|
|
@@ -247,7 +247,33 @@ const At = "playground-log", Sr = (r, ...t) => {
|
|
|
247
247
|
xr(t);
|
|
248
248
|
}
|
|
249
249
|
};
|
|
250
|
-
|
|
250
|
+
let mr = 0;
|
|
251
|
+
const Nr = "/wordpress/wp-content/debug.log", Lt = async (r) => await r.fileExists(Nr) ? await r.readFileAsText(Nr) : "", St = (r, t) => {
|
|
252
|
+
t.addEventListener("request.end", async () => {
|
|
253
|
+
const o = await Lt(t);
|
|
254
|
+
if (o.length > mr) {
|
|
255
|
+
const p = o.substring(mr);
|
|
256
|
+
r.logMessage({
|
|
257
|
+
message: p,
|
|
258
|
+
raw: !0
|
|
259
|
+
}), mr = o.length;
|
|
260
|
+
}
|
|
261
|
+
}), t.addEventListener("request.error", (o) => {
|
|
262
|
+
o = o, o.error && (r.logMessage({
|
|
263
|
+
message: `${o.error.message} ${o.error.stack}`,
|
|
264
|
+
severity: "Fatal",
|
|
265
|
+
prefix: o.source === "request" ? "PHP" : "WASM Crash"
|
|
266
|
+
}), r.dispatchEvent(
|
|
267
|
+
new CustomEvent(r.fatalErrorEvent, {
|
|
268
|
+
detail: {
|
|
269
|
+
logs: r.getLogs(),
|
|
270
|
+
source: o.source
|
|
271
|
+
}
|
|
272
|
+
})
|
|
273
|
+
));
|
|
274
|
+
});
|
|
275
|
+
};
|
|
276
|
+
class xt extends EventTarget {
|
|
251
277
|
// constructor
|
|
252
278
|
constructor(t = []) {
|
|
253
279
|
super(), this.handlers = t, this.fatalErrorEvent = "playground-fatal-error";
|
|
@@ -359,14 +385,14 @@ class Lt extends EventTarget {
|
|
|
359
385
|
);
|
|
360
386
|
}
|
|
361
387
|
}
|
|
362
|
-
const
|
|
388
|
+
const Nt = () => {
|
|
363
389
|
try {
|
|
364
390
|
if (process.env.NODE_ENV === "test")
|
|
365
391
|
return [vr, Sr];
|
|
366
392
|
} catch {
|
|
367
393
|
}
|
|
368
394
|
return [vr, qt, Sr];
|
|
369
|
-
}, ae = new
|
|
395
|
+
}, ae = new xt(Nt()), Pr = (r) => r.replace(/\t/g, ""), Ft = (r, t, o) => {
|
|
370
396
|
const p = /* @__PURE__ */ new Date(), l = new Intl.DateTimeFormat("en-GB", {
|
|
371
397
|
year: "numeric",
|
|
372
398
|
month: "short",
|
|
@@ -381,32 +407,6 @@ const St = () => {
|
|
|
381
407
|
timeZoneName: "short"
|
|
382
408
|
}).format(p), e = l + " " + i;
|
|
383
409
|
return r = Pr(r), `[${e}] ${o} ${t}: ${r}`;
|
|
384
|
-
};
|
|
385
|
-
let mr = 0;
|
|
386
|
-
const Nr = "/wordpress/wp-content/debug.log", Nt = async (r) => await r.fileExists(Nr) ? await r.readFileAsText(Nr) : "", Ft = (r, t) => {
|
|
387
|
-
t.addEventListener("request.end", async () => {
|
|
388
|
-
const o = await Nt(t);
|
|
389
|
-
if (o.length > mr) {
|
|
390
|
-
const p = o.substring(mr);
|
|
391
|
-
r.logMessage({
|
|
392
|
-
message: p,
|
|
393
|
-
raw: !0
|
|
394
|
-
}), mr = o.length;
|
|
395
|
-
}
|
|
396
|
-
}), t.addEventListener("request.error", (o) => {
|
|
397
|
-
o = o, o.error && (r.logMessage({
|
|
398
|
-
message: `${o.error.message} ${o.error.stack}`,
|
|
399
|
-
severity: "Fatal",
|
|
400
|
-
prefix: o.source === "request" ? "PHP" : "WASM Crash"
|
|
401
|
-
}), r.dispatchEvent(
|
|
402
|
-
new CustomEvent(r.fatalErrorEvent, {
|
|
403
|
-
detail: {
|
|
404
|
-
logs: r.getLogs(),
|
|
405
|
-
source: o.source
|
|
406
|
-
}
|
|
407
|
-
})
|
|
408
|
-
));
|
|
409
|
-
});
|
|
410
410
|
}, $r = async (r, { pluginPath: t, pluginName: o }, p) => {
|
|
411
411
|
p == null || p.tracker.setCaption(`Activating ${o || t}`);
|
|
412
412
|
const l = await r.documentRoot, i = await r.run({
|
|
@@ -13069,7 +13069,7 @@ async function fi({
|
|
|
13069
13069
|
wpVersion: m.versions.wp,
|
|
13070
13070
|
phpExtensions: m.phpExtensions,
|
|
13071
13071
|
withNetworking: m.features.networking
|
|
13072
|
-
}), await w.isReady(), S.finish(),
|
|
13072
|
+
}), await w.isReady(), S.finish(), St(ae, w), e(w), h && await h(), await Bs(m, w), p.finish(), w;
|
|
13073
13073
|
}
|
|
13074
13074
|
function ii(r) {
|
|
13075
13075
|
var t, o;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wp-playground/client",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.40",
|
|
4
4
|
"description": "WordPress Playground client",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"main": "./index.cjs",
|
|
38
38
|
"module": "./index.js",
|
|
39
39
|
"types": "index.d.ts",
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "f2cae683a18c3fe90148b712eeab8f2f714c6ec2",
|
|
41
41
|
"engines": {
|
|
42
42
|
"node": ">=18.18.0",
|
|
43
43
|
"npm": ">=8.11.0"
|
|
@@ -47,11 +47,11 @@
|
|
|
47
47
|
"comlink": "^4.4.1",
|
|
48
48
|
"ini": "4.1.2",
|
|
49
49
|
"octokit": "3.1.1",
|
|
50
|
-
"@wp-playground/blueprints": "0.9.
|
|
51
|
-
"@php-wasm/universal": "0.9.
|
|
52
|
-
"@php-wasm/util": "0.9.
|
|
53
|
-
"@php-wasm/web": "0.9.
|
|
54
|
-
"@php-wasm/progress": "0.9.
|
|
55
|
-
"@php-wasm/logger": "0.9.
|
|
50
|
+
"@wp-playground/blueprints": "0.9.40",
|
|
51
|
+
"@php-wasm/universal": "0.9.40",
|
|
52
|
+
"@php-wasm/util": "0.9.40",
|
|
53
|
+
"@php-wasm/web": "0.9.40",
|
|
54
|
+
"@php-wasm/progress": "0.9.40",
|
|
55
|
+
"@php-wasm/logger": "0.9.40"
|
|
56
56
|
}
|
|
57
57
|
}
|