@wp-playground/client 0.6.5 → 0.6.6
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 +1 -1
- package/index.js +11 -9
- package/package.json +2 -2
package/index.cjs
CHANGED
|
@@ -615,4 +615,4 @@ for existing apps using this option.`}},required:["consts","step"]},{type:"objec
|
|
|
615
615
|
* @license
|
|
616
616
|
* Copyright 2019 Google LLC
|
|
617
617
|
* SPDX-License-Identifier: Apache-2.0
|
|
618
|
-
*/const proxyMarker=Symbol("Comlink.proxy"),createEndpoint=Symbol("Comlink.endpoint"),releaseProxy=Symbol("Comlink.releaseProxy"),finalizer=Symbol("Comlink.finalizer"),throwMarker=Symbol("Comlink.thrown"),isObject=e=>typeof e=="object"&&e!==null||typeof e=="function",proxyTransferHandler={canHandle:e=>isObject(e)&&e[proxyMarker],serialize(e){const{port1:t,port2:r}=new MessageChannel;return expose(e,t),[r,[r]]},deserialize(e){return e.start(),wrap(e)}},throwTransferHandler={canHandle:e=>isObject(e)&&throwMarker in e,serialize({value:e}){let t;return e instanceof Error?t={isError:!0,value:{message:e.message,name:e.name,stack:e.stack}}:t={isError:!1,value:e},[t,[]]},deserialize(e){throw e.isError?Object.assign(new Error(e.value.message),e.value):e.value}},transferHandlers=new Map([["proxy",proxyTransferHandler],["throw",throwTransferHandler]]);function isAllowedOrigin(e,t){for(const r of e)if(t===r||r==="*"||r instanceof RegExp&&r.test(t))return!0;return!1}function expose(e,t=globalThis,r=["*"]){t.addEventListener("message",function n(s){if(!s||!s.data)return;if(!isAllowedOrigin(r,s.origin)){console.warn(`Invalid origin '${s.origin}' for comlink proxy`);return}const{id:o,type:i,path:c}=Object.assign({path:[]},s.data),d=(s.data.argumentList||[]).map(fromWireValue);let u;try{const p=c.slice(0,-1).reduce((R,O)=>R[O],e),_=c.reduce((R,O)=>R[O],e);switch(i){case"GET":u=_;break;case"SET":p[c.slice(-1)[0]]=fromWireValue(s.data.value),u=!0;break;case"APPLY":u=_.apply(p,d);break;case"CONSTRUCT":{const R=new _(...d);u=proxy(R)}break;case"ENDPOINT":{const{port1:R,port2:O}=new MessageChannel;expose(e,O),u=transfer(R,[R])}break;case"RELEASE":u=void 0;break;default:return}}catch(p){u={value:p,[throwMarker]:0}}Promise.resolve(u).catch(p=>({value:p,[throwMarker]:0})).then(p=>{const[_,R]=toWireValue(p);t.postMessage(Object.assign(Object.assign({},_),{id:o}),R),i==="RELEASE"&&(t.removeEventListener("message",n),closeEndPoint(t),finalizer in e&&typeof e[finalizer]=="function"&&e[finalizer]())}).catch(p=>{const[_,R]=toWireValue({value:new TypeError("Unserializable return value"),[throwMarker]:0});t.postMessage(Object.assign(Object.assign({},_),{id:o}),R)})}),t.start&&t.start()}function isMessagePort(e){return e.constructor.name==="MessagePort"}function closeEndPoint(e){isMessagePort(e)&&e.close()}function wrap(e,t){return createProxy(e,[],t)}function throwIfProxyReleased(e){if(e)throw new Error("Proxy has been released and is not useable")}function releaseEndpoint(e){return requestResponseMessage(e,{type:"RELEASE"}).then(()=>{closeEndPoint(e)})}const proxyCounter=new WeakMap,proxyFinalizers="FinalizationRegistry"in globalThis&&new FinalizationRegistry(e=>{const t=(proxyCounter.get(e)||0)-1;proxyCounter.set(e,t),t===0&&releaseEndpoint(e)});function registerProxy(e,t){const r=(proxyCounter.get(t)||0)+1;proxyCounter.set(t,r),proxyFinalizers&&proxyFinalizers.register(e,t,e)}function unregisterProxy(e){proxyFinalizers&&proxyFinalizers.unregister(e)}function createProxy(e,t=[],r=function(){}){let n=!1;const s=new Proxy(r,{get(o,i){if(throwIfProxyReleased(n),i===releaseProxy)return()=>{unregisterProxy(s),releaseEndpoint(e),n=!0};if(i==="then"){if(t.length===0)return{then:()=>s};const c=requestResponseMessage(e,{type:"GET",path:t.map(d=>d.toString())}).then(fromWireValue);return c.then.bind(c)}return createProxy(e,[...t,i])},set(o,i,c){throwIfProxyReleased(n);const[d,u]=toWireValue(c);return requestResponseMessage(e,{type:"SET",path:[...t,i].map(p=>p.toString()),value:d},u).then(fromWireValue)},apply(o,i,c){throwIfProxyReleased(n);const d=t[t.length-1];if(d===createEndpoint)return requestResponseMessage(e,{type:"ENDPOINT"}).then(fromWireValue);if(d==="bind")return createProxy(e,t.slice(0,-1));const[u,p]=processArguments(c);return requestResponseMessage(e,{type:"APPLY",path:t.map(_=>_.toString()),argumentList:u},p).then(fromWireValue)},construct(o,i){throwIfProxyReleased(n);const[c,d]=processArguments(i);return requestResponseMessage(e,{type:"CONSTRUCT",path:t.map(u=>u.toString()),argumentList:c},d).then(fromWireValue)}});return registerProxy(s,e),s}function myFlat(e){return Array.prototype.concat.apply([],e)}function processArguments(e){const t=e.map(toWireValue);return[t.map(r=>r[0]),myFlat(t.map(r=>r[1]))]}const transferCache=new WeakMap;function transfer(e,t){return transferCache.set(e,t),e}function proxy(e){return Object.assign(e,{[proxyMarker]:!0})}function windowEndpoint(e,t=globalThis,r="*"){return{postMessage:(n,s)=>e.postMessage(n,r,s),addEventListener:t.addEventListener.bind(t),removeEventListener:t.removeEventListener.bind(t)}}function toWireValue(e){for(const[t,r]of transferHandlers)if(r.canHandle(e)){const[n,s]=r.serialize(e);return[{type:"HANDLER",name:t,value:n},s]}return[{type:"RAW",value:e},transferCache.get(e)||[]]}function fromWireValue(e){switch(e.type){case"HANDLER":return transferHandlers.get(e.name).deserialize(e.value);case"RAW":return e.value}}function requestResponseMessage(e,t,r){return new Promise(n=>{const s=generateUUID();e.addEventListener("message",function o(i){!i.data||!i.data.id||i.data.id!==s||(e.removeEventListener("message",o),n(i.data))}),e.start&&e.start(),e.postMessage(Object.assign({id:s},t),r)})}function generateUUID(){return new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-")}function consumeAPI(e){setupTransferHandlers();const t=e instanceof Worker?e:windowEndpoint(e),r=wrap(t),n=proxyClone(r);return new Proxy(n,{get:(s,o)=>o==="isConnected"?async()=>{for(let i=0;i<10;i++)try{await runWithTimeout(r.isConnected(),200);break}catch{}}:r[o]})}async function runWithTimeout(e,t){return new Promise((r,n)=>{setTimeout(n,t),e.then(r)})}let isTransferHandlersSetup=!1;function setupTransferHandlers(){isTransferHandlersSetup||(isTransferHandlersSetup=!0,transferHandlers.set("EVENT",{canHandle:e=>e instanceof CustomEvent,serialize:e=>[{detail:e.detail},[]],deserialize:e=>e}),transferHandlers.set("FUNCTION",{canHandle:e=>typeof e=="function",serialize(e){console.debug("[Comlink][Performance] Proxying a function");const{port1:t,port2:r}=new MessageChannel;return expose(e,t),[r,[r]]},deserialize(e){return e.start(),wrap(e)}}),transferHandlers.set("PHPResponse",{canHandle:e=>typeof e=="object"&&e!==null&&"headers"in e&&"bytes"in e&&"errors"in e&&"exitCode"in e&&"httpStatusCode"in e,serialize(e){return[e.toRawData(),[]]},deserialize(e){return PHPResponse.fromRawData(e)}}))}function proxyClone(e){return new Proxy(e,{get(t,r){switch(typeof t[r]){case"function":return(...n)=>t[r](...n);case"object":return t[r]===null?t[r]:proxyClone(t[r]);case"undefined":case"number":case"string":return t[r];default:return proxy(t[r])}}})}class Logger{constructor(t){this.LOG_PREFIX="Playground",this.windowConnected=!1,this.lastPHPLogLength=0,this.errorLogPath="/wordpress/wp-content/debug.log",t&&(this.errorLogPath=t)}async getRequestPhpErrorLog(t){return await t.fileExists(this.errorLogPath)?await t.readFileAsText(this.errorLogPath):""}logWindowError(t){this.log(`${t.message} in ${t.filename} on line ${t.lineno}:${t.colno}`,"fatal")}logUnhandledRejection(t){this.log(`${t.reason.stack}`,"fatal")}addWindowErrorListener(){this.windowConnected||typeof window>"u"||(window.addEventListener("error",this.logWindowError.bind(this)),window.addEventListener("unhandledrejection",this.logUnhandledRejection.bind(this)),window.addEventListener("rejectionhandled",this.logUnhandledRejection.bind(this)),this.windowConnected=!0)}addPlaygroundRequestEndListener(t){t.addEventListener("request.end",async()=>{const r=await this.getRequestPhpErrorLog(t);r.length>this.lastPHPLogLength&&(this.logRaw(r.substring(this.lastPHPLogLength)),this.lastPHPLogLength=r.length)})}formatLogDate(t){const r=new Intl.DateTimeFormat("en-GB",{year:"numeric",month:"short",day:"2-digit",timeZone:"UTC"}).format(t).replace(/ /g,"-"),n=new Intl.DateTimeFormat("en-GB",{hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1,timeZone:"UTC",timeZoneName:"short"}).format(t);return r+" "+n}formatMessage(t,r){return`[${this.formatLogDate(new Date)}] ${this.LOG_PREFIX} ${r}: ${t}`}log(t,r){r===void 0&&(r="info");const n=this.formatMessage(t,r);this.logRaw(n)}logRaw(t){console.debug(t)}}const logger=new Logger;function collectPhpLogs(e,t){e.addPlaygroundRequestEndListener(t)}async function startPlaygroundWeb({iframe:e,blueprint:t,remoteUrl:r,progressTracker:n=new ProgressTracker,disableProgressBar:s,onBlueprintStepCompleted:o,sapiName:i}){if(assertValidRemote(r),allowStorageAccessByUserActivation(e),r=setQueryParams(r,{progressbar:!s}),n.setCaption("Preparing WordPress"),!t)return doStartPlaygroundWeb(e,r,n);const c=compileBlueprint(t,{progress:n.stage(.5),onStepCompleted:o}),d=await doStartPlaygroundWeb(e,setQueryParams(r,{php:c.versions.php,wp:c.versions.wp,"sapi-name":i,"php-extension":c.phpExtensions,networking:c.features.networking?"yes":"no"}),n);return collectPhpLogs(logger,d),await runBlueprintSteps(c,d),n.finish(),d}function allowStorageAccessByUserActivation(e){var t,r;(t=e.sandbox)!=null&&t.length&&!((r=e.sandbox)!=null&&r.contains("allow-storage-access-by-user-activation"))&&e.sandbox.add("allow-storage-access-by-user-activation")}async function doStartPlaygroundWeb(e,t,r){await new Promise(o=>{e.src=t,e.addEventListener("load",o,!1)});const n=consumeAPI(e.contentWindow);await n.isConnected(),r.pipe(n);const s=r.stage();return await n.onDownloadProgress(s.loadingListener),await n.isReady(),s.finish(),n}const officialRemoteOrigin="https://playground.wordpress.net";function assertValidRemote(e){const t=new URL(e,officialRemoteOrigin);if((t.origin===officialRemoteOrigin||t.hostname==="localhost")&&t.pathname!=="/remote.html")throw new Error(`Invalid remote URL: ${t}. Expected origin to be ${officialRemoteOrigin}/remote.html.`)}function setQueryParams(e,t){const r=new URL(e,officialRemoteOrigin),n=new URLSearchParams(r.search);for(const[s,o]of Object.entries(t))if(o!=null&&o!==!1)if(Array.isArray(o))for(const i of o)n.append(s,i.toString());else n.set(s,o.toString());return r.search=n.toString(),r.toString()}async function connectPlayground(e,t){if(console.warn("`connectPlayground` is deprecated and will be removed. Use `startPlayground` instead."),t!=null&&t.loadRemote)return startPlaygroundWeb({iframe:e,remoteUrl:t.loadRemote});const r=consumeAPI(e.contentWindow);return await r.isConnected(),r}exports.LatestSupportedPHPVersion=LatestSupportedPHPVersion;exports.SupportedPHPVersions=SupportedPHPVersions;exports.SupportedPHPVersionsList=SupportedPHPVersionsList;exports.activatePlugin=activatePlugin;exports.activateTheme=activateTheme;exports.compileBlueprint=compileBlueprint;exports.connectPlayground=connectPlayground;exports.cp=cp;exports.defineSiteUrl=defineSiteUrl;exports.defineWpConfigConsts=defineWpConfigConsts;exports.enableMultisite=enableMultisite;exports.exportWXR=exportWXR;exports.exportWXZ=exportWXZ;exports.importFile=importFile;exports.importWordPressFiles=importWordPressFiles;exports.installPlugin=installPlugin;exports.installTheme=installTheme;exports.login=login;exports.mkdir=mkdir;exports.mv=mv;exports.phpVar=phpVar;exports.phpVars=phpVars;exports.request=request;exports.rm=rm;exports.rmdir=rmdir;exports.runBlueprintSteps=runBlueprintSteps;exports.runPHP=runPHP;exports.runPHPWithOptions=runPHPWithOptions;exports.runSql=runSql;exports.runWpInstallationWizard=runWpInstallationWizard;exports.setPhpIniEntry=setPhpIniEntry;exports.setPluginProxyURL=setPluginProxyURL;exports.setSiteOptions=setSiteOptions;exports.startPlaygroundWeb=startPlaygroundWeb;exports.unzip=unzip;exports.updateUserMeta=updateUserMeta;exports.wpCLI=wpCLI$1;exports.wpContentFilesExcludedFromExport=wpContentFilesExcludedFromExport;exports.writeFile=writeFile;exports.zipWpContent=zipWpContent;
|
|
618
|
+
*/const proxyMarker=Symbol("Comlink.proxy"),createEndpoint=Symbol("Comlink.endpoint"),releaseProxy=Symbol("Comlink.releaseProxy"),finalizer=Symbol("Comlink.finalizer"),throwMarker=Symbol("Comlink.thrown"),isObject=e=>typeof e=="object"&&e!==null||typeof e=="function",proxyTransferHandler={canHandle:e=>isObject(e)&&e[proxyMarker],serialize(e){const{port1:t,port2:r}=new MessageChannel;return expose(e,t),[r,[r]]},deserialize(e){return e.start(),wrap(e)}},throwTransferHandler={canHandle:e=>isObject(e)&&throwMarker in e,serialize({value:e}){let t;return e instanceof Error?t={isError:!0,value:{message:e.message,name:e.name,stack:e.stack}}:t={isError:!1,value:e},[t,[]]},deserialize(e){throw e.isError?Object.assign(new Error(e.value.message),e.value):e.value}},transferHandlers=new Map([["proxy",proxyTransferHandler],["throw",throwTransferHandler]]);function isAllowedOrigin(e,t){for(const r of e)if(t===r||r==="*"||r instanceof RegExp&&r.test(t))return!0;return!1}function expose(e,t=globalThis,r=["*"]){t.addEventListener("message",function n(s){if(!s||!s.data)return;if(!isAllowedOrigin(r,s.origin)){console.warn(`Invalid origin '${s.origin}' for comlink proxy`);return}const{id:o,type:i,path:c}=Object.assign({path:[]},s.data),d=(s.data.argumentList||[]).map(fromWireValue);let u;try{const p=c.slice(0,-1).reduce((R,O)=>R[O],e),_=c.reduce((R,O)=>R[O],e);switch(i){case"GET":u=_;break;case"SET":p[c.slice(-1)[0]]=fromWireValue(s.data.value),u=!0;break;case"APPLY":u=_.apply(p,d);break;case"CONSTRUCT":{const R=new _(...d);u=proxy(R)}break;case"ENDPOINT":{const{port1:R,port2:O}=new MessageChannel;expose(e,O),u=transfer(R,[R])}break;case"RELEASE":u=void 0;break;default:return}}catch(p){u={value:p,[throwMarker]:0}}Promise.resolve(u).catch(p=>({value:p,[throwMarker]:0})).then(p=>{const[_,R]=toWireValue(p);t.postMessage(Object.assign(Object.assign({},_),{id:o}),R),i==="RELEASE"&&(t.removeEventListener("message",n),closeEndPoint(t),finalizer in e&&typeof e[finalizer]=="function"&&e[finalizer]())}).catch(p=>{const[_,R]=toWireValue({value:new TypeError("Unserializable return value"),[throwMarker]:0});t.postMessage(Object.assign(Object.assign({},_),{id:o}),R)})}),t.start&&t.start()}function isMessagePort(e){return e.constructor.name==="MessagePort"}function closeEndPoint(e){isMessagePort(e)&&e.close()}function wrap(e,t){return createProxy(e,[],t)}function throwIfProxyReleased(e){if(e)throw new Error("Proxy has been released and is not useable")}function releaseEndpoint(e){return requestResponseMessage(e,{type:"RELEASE"}).then(()=>{closeEndPoint(e)})}const proxyCounter=new WeakMap,proxyFinalizers="FinalizationRegistry"in globalThis&&new FinalizationRegistry(e=>{const t=(proxyCounter.get(e)||0)-1;proxyCounter.set(e,t),t===0&&releaseEndpoint(e)});function registerProxy(e,t){const r=(proxyCounter.get(t)||0)+1;proxyCounter.set(t,r),proxyFinalizers&&proxyFinalizers.register(e,t,e)}function unregisterProxy(e){proxyFinalizers&&proxyFinalizers.unregister(e)}function createProxy(e,t=[],r=function(){}){let n=!1;const s=new Proxy(r,{get(o,i){if(throwIfProxyReleased(n),i===releaseProxy)return()=>{unregisterProxy(s),releaseEndpoint(e),n=!0};if(i==="then"){if(t.length===0)return{then:()=>s};const c=requestResponseMessage(e,{type:"GET",path:t.map(d=>d.toString())}).then(fromWireValue);return c.then.bind(c)}return createProxy(e,[...t,i])},set(o,i,c){throwIfProxyReleased(n);const[d,u]=toWireValue(c);return requestResponseMessage(e,{type:"SET",path:[...t,i].map(p=>p.toString()),value:d},u).then(fromWireValue)},apply(o,i,c){throwIfProxyReleased(n);const d=t[t.length-1];if(d===createEndpoint)return requestResponseMessage(e,{type:"ENDPOINT"}).then(fromWireValue);if(d==="bind")return createProxy(e,t.slice(0,-1));const[u,p]=processArguments(c);return requestResponseMessage(e,{type:"APPLY",path:t.map(_=>_.toString()),argumentList:u},p).then(fromWireValue)},construct(o,i){throwIfProxyReleased(n);const[c,d]=processArguments(i);return requestResponseMessage(e,{type:"CONSTRUCT",path:t.map(u=>u.toString()),argumentList:c},d).then(fromWireValue)}});return registerProxy(s,e),s}function myFlat(e){return Array.prototype.concat.apply([],e)}function processArguments(e){const t=e.map(toWireValue);return[t.map(r=>r[0]),myFlat(t.map(r=>r[1]))]}const transferCache=new WeakMap;function transfer(e,t){return transferCache.set(e,t),e}function proxy(e){return Object.assign(e,{[proxyMarker]:!0})}function windowEndpoint(e,t=globalThis,r="*"){return{postMessage:(n,s)=>e.postMessage(n,r,s),addEventListener:t.addEventListener.bind(t),removeEventListener:t.removeEventListener.bind(t)}}function toWireValue(e){for(const[t,r]of transferHandlers)if(r.canHandle(e)){const[n,s]=r.serialize(e);return[{type:"HANDLER",name:t,value:n},s]}return[{type:"RAW",value:e},transferCache.get(e)||[]]}function fromWireValue(e){switch(e.type){case"HANDLER":return transferHandlers.get(e.name).deserialize(e.value);case"RAW":return e.value}}function requestResponseMessage(e,t,r){return new Promise(n=>{const s=generateUUID();e.addEventListener("message",function o(i){!i.data||!i.data.id||i.data.id!==s||(e.removeEventListener("message",o),n(i.data))}),e.start&&e.start(),e.postMessage(Object.assign({id:s},t),r)})}function generateUUID(){return new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-")}function consumeAPI(e,t=void 0){setupTransferHandlers();const r=e instanceof Worker?e:windowEndpoint(e,t),n=wrap(r),s=proxyClone(n);return new Proxy(s,{get:(o,i)=>i==="isConnected"?async()=>{for(;;)try{await runWithTimeout(n.isConnected(),200);break}catch{}}:n[i]})}async function runWithTimeout(e,t){return new Promise((r,n)=>{setTimeout(n,t),e.then(r)})}let isTransferHandlersSetup=!1;function setupTransferHandlers(){isTransferHandlersSetup||(isTransferHandlersSetup=!0,transferHandlers.set("EVENT",{canHandle:e=>e instanceof CustomEvent,serialize:e=>[{detail:e.detail},[]],deserialize:e=>e}),transferHandlers.set("FUNCTION",{canHandle:e=>typeof e=="function",serialize(e){console.debug("[Comlink][Performance] Proxying a function");const{port1:t,port2:r}=new MessageChannel;return expose(e,t),[r,[r]]},deserialize(e){return e.start(),wrap(e)}}),transferHandlers.set("PHPResponse",{canHandle:e=>typeof e=="object"&&e!==null&&"headers"in e&&"bytes"in e&&"errors"in e&&"exitCode"in e&&"httpStatusCode"in e,serialize(e){return[e.toRawData(),[]]},deserialize(e){return PHPResponse.fromRawData(e)}}))}function proxyClone(e){return new Proxy(e,{get(t,r){switch(typeof t[r]){case"function":return(...n)=>t[r](...n);case"object":return t[r]===null?t[r]:proxyClone(t[r]);case"undefined":case"number":case"string":return t[r];default:return proxy(t[r])}}})}class Logger{constructor(t){this.LOG_PREFIX="Playground",this.windowConnected=!1,this.lastPHPLogLength=0,this.errorLogPath="/wordpress/wp-content/debug.log",t&&(this.errorLogPath=t)}async getRequestPhpErrorLog(t){return await t.fileExists(this.errorLogPath)?await t.readFileAsText(this.errorLogPath):""}logWindowError(t){this.log(`${t.message} in ${t.filename} on line ${t.lineno}:${t.colno}`,"fatal")}logUnhandledRejection(t){this.log(`${t.reason.stack}`,"fatal")}addWindowErrorListener(){this.windowConnected||typeof window>"u"||(window.addEventListener("error",this.logWindowError.bind(this)),window.addEventListener("unhandledrejection",this.logUnhandledRejection.bind(this)),window.addEventListener("rejectionhandled",this.logUnhandledRejection.bind(this)),this.windowConnected=!0)}addPlaygroundRequestEndListener(t){t.addEventListener("request.end",async()=>{const r=await this.getRequestPhpErrorLog(t);r.length>this.lastPHPLogLength&&(this.logRaw(r.substring(this.lastPHPLogLength)),this.lastPHPLogLength=r.length)})}formatLogDate(t){const r=new Intl.DateTimeFormat("en-GB",{year:"numeric",month:"short",day:"2-digit",timeZone:"UTC"}).format(t).replace(/ /g,"-"),n=new Intl.DateTimeFormat("en-GB",{hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1,timeZone:"UTC",timeZoneName:"short"}).format(t);return r+" "+n}formatMessage(t,r){return`[${this.formatLogDate(new Date)}] ${this.LOG_PREFIX} ${r}: ${t}`}log(t,r){r===void 0&&(r="info");const n=this.formatMessage(t,r);this.logRaw(n)}logRaw(t){console.debug(t)}}const logger=new Logger;function collectPhpLogs(e,t){e.addPlaygroundRequestEndListener(t)}async function startPlaygroundWeb({iframe:e,blueprint:t,remoteUrl:r,progressTracker:n=new ProgressTracker,disableProgressBar:s,onBlueprintStepCompleted:o,sapiName:i}){if(assertValidRemote(r),allowStorageAccessByUserActivation(e),r=setQueryParams(r,{progressbar:!s}),n.setCaption("Preparing WordPress"),!t)return doStartPlaygroundWeb(e,r,n);const c=compileBlueprint(t,{progress:n.stage(.5),onStepCompleted:o}),d=await doStartPlaygroundWeb(e,setQueryParams(r,{php:c.versions.php,wp:c.versions.wp,"sapi-name":i,"php-extension":c.phpExtensions,networking:c.features.networking?"yes":"no"}),n);return collectPhpLogs(logger,d),await runBlueprintSteps(c,d),n.finish(),d}function allowStorageAccessByUserActivation(e){var t,r;(t=e.sandbox)!=null&&t.length&&!((r=e.sandbox)!=null&&r.contains("allow-storage-access-by-user-activation"))&&e.sandbox.add("allow-storage-access-by-user-activation")}async function doStartPlaygroundWeb(e,t,r){await new Promise(o=>{e.src=t,e.addEventListener("load",o,!1)});const n=consumeAPI(e.contentWindow,e.ownerDocument.defaultView);await n.isConnected(),r.pipe(n);const s=r.stage();return await n.onDownloadProgress(s.loadingListener),await n.isReady(),s.finish(),n}const officialRemoteOrigin="https://playground.wordpress.net";function assertValidRemote(e){const t=new URL(e,officialRemoteOrigin);if((t.origin===officialRemoteOrigin||t.hostname==="localhost")&&t.pathname!=="/remote.html")throw new Error(`Invalid remote URL: ${t}. Expected origin to be ${officialRemoteOrigin}/remote.html.`)}function setQueryParams(e,t){const r=new URL(e,officialRemoteOrigin),n=new URLSearchParams(r.search);for(const[s,o]of Object.entries(t))if(o!=null&&o!==!1)if(Array.isArray(o))for(const i of o)n.append(s,i.toString());else n.set(s,o.toString());return r.search=n.toString(),r.toString()}async function connectPlayground(e,t){if(console.warn("`connectPlayground` is deprecated and will be removed. Use `startPlayground` instead."),t!=null&&t.loadRemote)return startPlaygroundWeb({iframe:e,remoteUrl:t.loadRemote});const r=consumeAPI(e.contentWindow,e.ownerDocument.defaultView);return await r.isConnected(),r}exports.LatestSupportedPHPVersion=LatestSupportedPHPVersion;exports.SupportedPHPVersions=SupportedPHPVersions;exports.SupportedPHPVersionsList=SupportedPHPVersionsList;exports.activatePlugin=activatePlugin;exports.activateTheme=activateTheme;exports.compileBlueprint=compileBlueprint;exports.connectPlayground=connectPlayground;exports.cp=cp;exports.defineSiteUrl=defineSiteUrl;exports.defineWpConfigConsts=defineWpConfigConsts;exports.enableMultisite=enableMultisite;exports.exportWXR=exportWXR;exports.exportWXZ=exportWXZ;exports.importFile=importFile;exports.importWordPressFiles=importWordPressFiles;exports.installPlugin=installPlugin;exports.installTheme=installTheme;exports.login=login;exports.mkdir=mkdir;exports.mv=mv;exports.phpVar=phpVar;exports.phpVars=phpVars;exports.request=request;exports.rm=rm;exports.rmdir=rmdir;exports.runBlueprintSteps=runBlueprintSteps;exports.runPHP=runPHP;exports.runPHPWithOptions=runPHPWithOptions;exports.runSql=runSql;exports.runWpInstallationWizard=runWpInstallationWizard;exports.setPhpIniEntry=setPhpIniEntry;exports.setPluginProxyURL=setPluginProxyURL;exports.setSiteOptions=setSiteOptions;exports.startPlaygroundWeb=startPlaygroundWeb;exports.unzip=unzip;exports.updateUserMeta=updateUserMeta;exports.wpCLI=wpCLI$1;exports.wpContentFilesExcludedFromExport=wpContentFilesExcludedFromExport;exports.writeFile=writeFile;exports.zipWpContent=zipWpContent;
|
package/index.js
CHANGED
|
@@ -9555,18 +9555,18 @@ function requestResponseMessage(e, t, r) {
|
|
|
9555
9555
|
function generateUUID() {
|
|
9556
9556
|
return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
|
|
9557
9557
|
}
|
|
9558
|
-
function consumeAPI(e) {
|
|
9558
|
+
function consumeAPI(e, t = void 0) {
|
|
9559
9559
|
setupTransferHandlers();
|
|
9560
|
-
const
|
|
9561
|
-
return new Proxy(
|
|
9562
|
-
get: (
|
|
9563
|
-
for (
|
|
9560
|
+
const r = e instanceof Worker ? e : windowEndpoint(e, t), n = wrap(r), s = proxyClone(n);
|
|
9561
|
+
return new Proxy(s, {
|
|
9562
|
+
get: (i, o) => o === "isConnected" ? async () => {
|
|
9563
|
+
for (; ; )
|
|
9564
9564
|
try {
|
|
9565
|
-
await runWithTimeout(
|
|
9565
|
+
await runWithTimeout(n.isConnected(), 200);
|
|
9566
9566
|
break;
|
|
9567
9567
|
} catch {
|
|
9568
9568
|
}
|
|
9569
|
-
} :
|
|
9569
|
+
} : n[o]
|
|
9570
9570
|
});
|
|
9571
9571
|
}
|
|
9572
9572
|
async function runWithTimeout(e, t) {
|
|
@@ -9767,7 +9767,8 @@ async function doStartPlaygroundWeb(e, t, r) {
|
|
|
9767
9767
|
e.src = t, e.addEventListener("load", i, !1);
|
|
9768
9768
|
});
|
|
9769
9769
|
const n = consumeAPI(
|
|
9770
|
-
e.contentWindow
|
|
9770
|
+
e.contentWindow,
|
|
9771
|
+
e.ownerDocument.defaultView
|
|
9771
9772
|
);
|
|
9772
9773
|
await n.isConnected(), r.pipe(n);
|
|
9773
9774
|
const s = r.stage();
|
|
@@ -9801,7 +9802,8 @@ async function connectPlayground(e, t) {
|
|
|
9801
9802
|
remoteUrl: t.loadRemote
|
|
9802
9803
|
});
|
|
9803
9804
|
const r = consumeAPI(
|
|
9804
|
-
e.contentWindow
|
|
9805
|
+
e.contentWindow,
|
|
9806
|
+
e.ownerDocument.defaultView
|
|
9805
9807
|
);
|
|
9806
9808
|
return await r.isConnected(), r;
|
|
9807
9809
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wp-playground/client",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.6",
|
|
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": "90f82ca946f8573b358c1320be0b6b8674f67cfc",
|
|
41
41
|
"engines": {
|
|
42
42
|
"node": ">=18.18.2",
|
|
43
43
|
"npm": ">=8.11.0"
|