@wp-playground/client 0.9.20 → 0.9.21
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.d.ts +1 -0
- package/index.js +6 -3
- package/package.json +2 -2
package/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Ys=function(){var e;return typeof process<"u"&&((e=process.release)==null?void 0:e.name)==="node"?"NODE":typeof window<"u"?"WEB":typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope?"WORKER":"NODE"}();if(Ys==="NODE"){let e=function(r){return new Promise(function(n,s){r.onload=r.onerror=function(i){r.onload=r.onerror=null,i.type==="load"?n(r.result):s(new Error("Failed to read the blob/file"))}})},t=function(){const r=new Uint8Array([1,2,3,4]),s=new File([r],"test").stream();try{return s.getReader({mode:"byob"}),!0}catch{return!1}};if(typeof File>"u"){class r extends Blob{constructor(s,i,o){super(s);let u;o!=null&&o.lastModified&&(u=new Date),(!u||isNaN(u.getFullYear()))&&(u=new Date),this.lastModifiedDate=u,this.lastModified=u.getMilliseconds(),this.name=i||""}}global.File=r}typeof Blob.prototype.arrayBuffer>"u"&&(Blob.prototype.arrayBuffer=function(){const n=new FileReader;return n.readAsArrayBuffer(this),e(n)}),typeof Blob.prototype.text>"u"&&(Blob.prototype.text=function(){const n=new FileReader;return n.readAsText(this),e(n)}),(typeof Blob.prototype.stream>"u"||!t())&&(Blob.prototype.stream=function(){let r=0;const n=this;return new ReadableStream({type:"bytes",autoAllocateChunkSize:512*1024,async pull(s){const i=s.byobRequest.view,u=await n.slice(r,r+i.byteLength).arrayBuffer(),f=new Uint8Array(u);new Uint8Array(i.buffer).set(f);const l=f.byteLength;s.byobRequest.respond(l),r+=l,r>=n.size&&s.close()}})})}if(Ys==="NODE"&&typeof CustomEvent>"u"){class e extends Event{constructor(r,n={}){super(r,n),this.detail=n.detail}initCustomEvent(){}}globalThis.CustomEvent=e}const pn=["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"],Zs=Symbol("SleepFinished");function Do(e){return new Promise(t=>{setTimeout(()=>t(Zs),e)})}class Mo extends Error{constructor(){super("Acquiring lock timed out")}}class Lo{constructor({concurrency:t,timeout:r}){this._running=0,this.concurrency=t,this.timeout=r,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(r=>{this.queue.push(r)});this.timeout!==void 0?await Promise.race([t,Do(this.timeout)]).then(r=>{if(r===Zs)throw new Mo}):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 r=await this.acquire();try{return await t()}finally{r()}}}function de(...e){let
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Ys=function(){var e;return typeof process<"u"&&((e=process.release)==null?void 0:e.name)==="node"?"NODE":typeof window<"u"?"WEB":typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope?"WORKER":"NODE"}();if(Ys==="NODE"){let e=function(r){return new Promise(function(n,s){r.onload=r.onerror=function(i){r.onload=r.onerror=null,i.type==="load"?n(r.result):s(new Error("Failed to read the blob/file"))}})},t=function(){const r=new Uint8Array([1,2,3,4]),s=new File([r],"test").stream();try{return s.getReader({mode:"byob"}),!0}catch{return!1}};if(typeof File>"u"){class r extends Blob{constructor(s,i,o){super(s);let u;o!=null&&o.lastModified&&(u=new Date),(!u||isNaN(u.getFullYear()))&&(u=new Date),this.lastModifiedDate=u,this.lastModified=u.getMilliseconds(),this.name=i||""}}global.File=r}typeof Blob.prototype.arrayBuffer>"u"&&(Blob.prototype.arrayBuffer=function(){const n=new FileReader;return n.readAsArrayBuffer(this),e(n)}),typeof Blob.prototype.text>"u"&&(Blob.prototype.text=function(){const n=new FileReader;return n.readAsText(this),e(n)}),(typeof Blob.prototype.stream>"u"||!t())&&(Blob.prototype.stream=function(){let r=0;const n=this;return new ReadableStream({type:"bytes",autoAllocateChunkSize:512*1024,async pull(s){const i=s.byobRequest.view,u=await n.slice(r,r+i.byteLength).arrayBuffer(),f=new Uint8Array(u);new Uint8Array(i.buffer).set(f);const l=f.byteLength;s.byobRequest.respond(l),r+=l,r>=n.size&&s.close()}})})}if(Ys==="NODE"&&typeof CustomEvent>"u"){class e extends Event{constructor(r,n={}){super(r,n),this.detail=n.detail}initCustomEvent(){}}globalThis.CustomEvent=e}const pn=["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"],Zs=Symbol("SleepFinished");function Do(e){return new Promise(t=>{setTimeout(()=>t(Zs),e)})}class Mo extends Error{constructor(){super("Acquiring lock timed out")}}class Lo{constructor({concurrency:t,timeout:r}){this._running=0,this.concurrency=t,this.timeout=r,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(r=>{this.queue.push(r)});this.timeout!==void 0?await Promise.race([t,Do(this.timeout)]).then(r=>{if(r===Zs)throw new Mo}):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 r=await this.acquire();try{return await t()}finally{r()}}}function de(...e){function t(i){return i.substring(i.length-1)==="/"}let r=e.join("/");const n=r[0]==="/",s=t(r);return r=ei(r),!r&&!n&&(r="."),r&&s&&!t(r)&&(r+="/"),r}function Xs(e){if(e==="/")return"/";e=ei(e);const t=e.lastIndexOf("/");return t===-1?"":t===0?"/":e.substr(0,t)}function ei(e){const t=e[0]==="/";return e=Fo(e.split("/").filter(r=>!!r),!t).join("/"),(t?"/":"")+e.replace(/\/$/,"")}function Fo(e,t){let r=0;for(let n=e.length-1;n>=0;n--){const s=e[n];s==="."?e.splice(n,1):s===".."?(e.splice(n,1),r++):r&&(e.splice(n,1),r--)}if(t)for(;r;r--)e.unshift("..");return e}function ti(e=36,t="!@#$%^&*()_+=-[]/.,<>?"){const r="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"+t;let n="";for(let s=e;s>0;--s)n+=r[Math.floor(Math.random()*r.length)];return n}function qo(){return ti(36,"-_")}function ae(e){return`json_decode(base64_decode('${Uo(JSON.stringify(e))}'), true)`}function Zt(e){const t={};for(const r in e)t[r]=ae(e[r]);return t}function Uo(e){return zo(new TextEncoder().encode(e))}function zo(e){const t=String.fromCodePoint(...e);return btoa(t)}const Vo="playground-log",_s=(e,...t)=>{he.dispatchEvent(new CustomEvent(Vo,{detail:{log:e,args:t}}))},Wo=(e,...t)=>{switch(typeof e.message=="string"?e.message=rn(e.message):e.message.message&&typeof e.message.message=="string"&&(e.message.message=rn(e.message.message)),e.severity){case"Debug":console.debug(e.message,...t);break;case"Info":console.info(e.message,...t);break;case"Warn":console.warn(e.message,...t);break;case"Error":console.error(e.message,...t);break;case"Fatal":console.error(e.message,...t);break;default:console.log(e.message,...t)}},xo=e=>e instanceof Error?[e.message,e.stack].join(`
|
|
2
2
|
`):JSON.stringify(e,null,2),ri=[],ws=e=>{ri.push(e)},tn=e=>{if(e.raw===!0)ws(e.message);else{const t=Go(typeof e.message=="object"?xo(e.message):e.message,e.severity??"Info",e.prefix??"JavaScript");ws(t)}};class Ho extends EventTarget{constructor(t=[]){super(),this.handlers=t,this.fatalErrorEvent="playground-fatal-error"}getLogs(){return this.handlers.includes(tn)?[...ri]:(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
4
|
`),[])}logMessage(t,...r){for(const n of this.handlers)n(t,...r)}log(t,...r){this.logMessage({message:t,severity:void 0,prefix:"JavaScript",raw:!1},...r)}debug(t,...r){this.logMessage({message:t,severity:"Debug",prefix:"JavaScript",raw:!1},...r)}info(t,...r){this.logMessage({message:t,severity:"Info",prefix:"JavaScript",raw:!1},...r)}warn(t,...r){this.logMessage({message:t,severity:"Warn",prefix:"JavaScript",raw:!1},...r)}error(t,...r){this.logMessage({message:t,severity:"Error",prefix:"JavaScript",raw:!1},...r)}}const Bo=()=>{try{if(process.env.NODE_ENV==="test")return[tn,_s]}catch{}return[tn,Wo,_s]},he=new Ho(Bo()),rn=e=>e.replace(/\t/g,""),Go=(e,t,r)=>{const n=new Date,s=new Intl.DateTimeFormat("en-GB",{year:"numeric",month:"short",day:"2-digit",timeZone:"UTC"}).format(n).replace(/ /g,"-"),i=new Intl.DateTimeFormat("en-GB",{hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1,timeZone:"UTC",timeZoneName:"short"}).format(n),o=s+" "+i;return e=rn(e),`[${o}] ${r} ${t}: ${e}`};let xr=0;const vs="/wordpress/wp-content/debug.log",Ko=async e=>await e.fileExists(vs)?await e.readFileAsText(vs):"",Jo=(e,t)=>{t.addEventListener("request.end",async()=>{const r=await Ko(t);if(r.length>xr){const n=r.substring(xr);e.logMessage({message:n,raw:!0}),xr=r.length}}),t.addEventListener("request.error",r=>{r=r,r.error&&(e.logMessage({message:`${r.error.message} ${r.error.stack}`,severity:"Fatal",prefix:r.source==="request"?"PHP":"WASM Crash"}),e.dispatchEvent(new CustomEvent(e.fatalErrorEvent,{detail:{logs:e.getLogs(),source:r.source}})))})},Ar=async(e,{pluginPath:t,pluginName:r},n)=>{n==null||n.tracker.setCaption(`Activating ${r||t}`);const s=await e.documentRoot,i=await e.run({code:`<?php
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -139,9 +139,12 @@ class ho {
|
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
141
|
function ue(...e) {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
142
|
+
function t(i) {
|
|
143
|
+
return i.substring(i.length - 1) === "/";
|
|
144
|
+
}
|
|
145
|
+
let r = e.join("/");
|
|
146
|
+
const n = r[0] === "/", s = t(r);
|
|
147
|
+
return r = Ks(r), !r && !n && (r = "."), r && s && !t(r) && (r += "/"), r;
|
|
145
148
|
}
|
|
146
149
|
function Gs(e) {
|
|
147
150
|
if (e === "/")
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wp-playground/client",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.21",
|
|
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": "a497916495035caba2f28cfdef75a8a0f3732f0e",
|
|
41
41
|
"engines": {
|
|
42
42
|
"node": ">=18.18.0",
|
|
43
43
|
"npm": ">=8.11.0"
|