@wp-playground/client 0.1.37 → 0.1.38

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/README.md CHANGED
@@ -3,15 +3,13 @@
3
3
  Provides a [PlaygroundClient](https://wordpress.github.io/wordpress-playground/interfaces/_wp_playground_client.PlaygroundClient.html) that can be used to control a WordPress Playground iframe:
4
4
 
5
5
  ```ts
6
- import { connectPlayground } from '@wp-playground/client';
6
+ import { startPlaygroundWeb } from '@wp-playground/client';
7
7
 
8
- const client = await connectPlayground(
9
- // An iframe pointing to https://playground.wordpress.net/remote.html
10
- document.getElementById('wp')! as HTMLIFrameElement
11
- );
12
- // client is now a PlaygroundClient instance
13
- await client.isReady();
14
- await client.goTo('/wp-admin/');
8
+ const client = await startPlaygroundWeb({
9
+ // An iframe pointing to https://playground.wordpress.net/remote.html:
10
+ iframe: document.getElementById('wp'),
11
+ remoteUrl: `https://playground.wordpress.net/remote.html`,
12
+ });
15
13
 
16
14
  const response = await client.run({
17
15
  code: '<?php echo "Hi!"; ',
@@ -24,14 +22,14 @@ Using TypeScript is highly recommended as this package ships with comprehensive
24
22
  Once you have a [PlaygroundClient](https://wordpress.github.io/wordpress-playground/interfaces/_wp_playground_client.PlaygroundClient.html) instance, you can use it to control the playground:
25
23
 
26
24
  ```ts
27
- client.writeFile('/index.php', '<?php echo "Hi!"; ');
28
- client.run({
25
+ await client.writeFile('/index.php', '<?php echo "Hi!"; ');
26
+ await client.run({
29
27
  scriptPath: '/index.php',
30
28
  });
31
29
 
32
- console.log(client.readFileAsText('/index.php'));
30
+ console.log(await client.readFileAsText('/index.php'));
33
31
 
34
- client.request({
32
+ await client.request({
35
33
  url: '/index.php',
36
34
  method: 'POST',
37
35
  formData: {
@@ -41,14 +39,3 @@ client.request({
41
39
  ```
42
40
 
43
41
  To see all the available methods, check out the [PlaygroundClient](https://wordpress.github.io/wordpress-playground/interfaces/_wp_playground_client.PlaygroundClient.html) interface.
44
-
45
- ## Helpers
46
-
47
- The `@wp-playground/client` package also provides a few helpers:
48
-
49
- - [login](https://wordpress.github.io/wordpress-playground/functions/_wp_playground_client.login.html) - Logs the user in to wp-admin.
50
- - [installPlugin](https://wordpress.github.io/wordpress-playground/functions/_wp_playground_client.installPlugin.html) - Installs a plugin from a given zip file.
51
- - [installPluginsFromDirectory](https://wordpress.github.io/wordpress-playground/functions/_wp_playground_client.installPluginsFromDirectory.html) - Downloads and installs one or more plugins from the WordPress Plugin Directory.
52
- - [activatePlugin](https://wordpress.github.io/wordpress-playground/functions/_wp_playground_client.activatePlugin.html) - Activates a specific plugin.
53
- - [installTheme](https://wordpress.github.io/wordpress-playground/functions/_wp_playground_client.installTheme.html) - Installs a theme from a given zip file.
54
- - [installThemeFromDirectory](https://wordpress.github.io/wordpress-playground/functions/_wp_playground_client.installThemeFromDirectory.html) - Downloads and installs a theme with a specific name from the WordPress Theme Directory.
package/index.cjs CHANGED
@@ -96,7 +96,7 @@ function delTree($dir)
96
96
  `),a=i.substring(0,o).trim(),l=i.substring(o+4).trim(),c=a.match(/name="([^"]+)"/);if(c){const u=c[1];e[u]=l}}),e}function ot(t){switch(t.split(".").pop()){case"css":return"text/css";case"js":return"application/javascript";case"png":return"image/png";case"jpg":case"jpeg":return"image/jpeg";case"gif":return"image/gif";case"svg":return"image/svg+xml";case"woff":return"font/woff";case"woff2":return"font/woff2";case"ttf":return"font/ttf";case"otf":return"font/otf";case"eot":return"font/eot";case"ico":return"image/x-icon";case"html":return"text/html";case"json":return"application/json";case"xml":return"application/xml";case"txt":case"md":return"text/plain";default:return"application-octet-stream"}}const Q={0:"No error occurred. System call completed successfully.",1:"Argument list too long.",2:"Permission denied.",3:"Address in use.",4:"Address not available.",5:"Address family not supported.",6:"Resource unavailable, or operation would block.",7:"Connection already in progress.",8:"Bad file descriptor.",9:"Bad message.",10:"Device or resource busy.",11:"Operation canceled.",12:"No child processes.",13:"Connection aborted.",14:"Connection refused.",15:"Connection reset.",16:"Resource deadlock would occur.",17:"Destination address required.",18:"Mathematics argument out of domain of function.",19:"Reserved.",20:"File exists.",21:"Bad address.",22:"File too large.",23:"Host is unreachable.",24:"Identifier removed.",25:"Illegal byte sequence.",26:"Operation in progress.",27:"Interrupted function.",28:"Invalid argument.",29:"I/O error.",30:"Socket is connected.",31:"There is a directory under that path.",32:"Too many levels of symbolic links.",33:"File descriptor value too large.",34:"Too many links.",35:"Message too large.",36:"Reserved.",37:"Filename too long.",38:"Network is down.",39:"Connection aborted by network.",40:"Network unreachable.",41:"Too many files open in system.",42:"No buffer space available.",43:"No such device.",44:"There is no such file or directory OR the parent directory does not exist.",45:"Executable file format error.",46:"No locks available.",47:"Reserved.",48:"Not enough space.",49:"No message of the desired type.",50:"Protocol not available.",51:"No space left on device.",52:"Function not supported.",53:"The socket is not connected.",54:"Not a directory or a symbolic link to a directory.",55:"Directory not empty.",56:"State not recoverable.",57:"Not a socket.",58:"Not supported, or operation not supported on socket.",59:"Inappropriate I/O control operation.",60:"No such device or address.",61:"Value too large to be stored in data type.",62:"Previous owner died.",63:"Operation not permitted.",64:"Broken pipe.",65:"Protocol error.",66:"Protocol not supported.",67:"Protocol wrong type for socket.",68:"Result too large.",69:"Read-only file system.",70:"Invalid seek.",71:"No such process.",72:"Reserved.",73:"Connection timed out.",74:"Text file busy.",75:"Cross-device link.",76:"Extension: Capabilities insufficient."};function m(t=""){return function(r,s,n){const i=n.value;n.value=function(...o){try{return i.apply(this,o)}catch(a){const l=typeof a=="object"?a?.errno:null;if(l in Q){const c=Q[l],u=typeof o[0]=="string"?o[0]:null,d=u!==null?t.replaceAll("{path}",u):t;throw new Error(`${d}: ${c}`,{cause:a})}throw a}}}}const at=[];function ct(t){return at[t]}(function(){return typeof window<"u"&&!{}.TEST?"WEB":typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope?"WORKER":"NODE"})();var lt=Object.defineProperty,ut=Object.getOwnPropertyDescriptor,w=(t,e,r,s)=>{for(var n=s>1?void 0:s?ut(e,r):e,i=t.length-1,o;i>=0;i--)(o=t[i])&&(n=(s?o(e,r,n):o(n))||n);return s&&n&&lt(e,r,n),n};const f="string",S="number",h=Symbol("__private__dont__use");class g{constructor(e,r){this.#e=[],this.#t=!1,e!==void 0&&this.initializeRuntime(e),r&&(this.requestHandler=new tt(new nt(this,r)))}#e;#t;get absoluteUrl(){return this.requestHandler.requestHandler.absoluteUrl}get documentRoot(){return this.requestHandler.requestHandler.documentRoot}pathToInternalUrl(e){return this.requestHandler.requestHandler.pathToInternalUrl(e)}internalUrlToPath(e){return this.requestHandler.requestHandler.internalUrlToPath(e)}initializeRuntime(e){if(this[h])throw new Error("PHP runtime already initialized.");const r=ct(e);if(!r)throw new Error("Invalid PHP runtime id.");this[h]=r}setPhpIniPath(e){if(this.#t)throw new Error("Cannot set PHP ini path after calling run().");this[h].ccall("wasm_set_phpini_path",null,["string"],[e])}setPhpIniEntry(e,r){if(this.#t)throw new Error("Cannot set PHP ini entries after calling run().");this.#e.push([e,r])}chdir(e){this[h].FS.chdir(e)}async request(e,r){if(!this.requestHandler)throw new Error("No request handler available.");return this.requestHandler.request(e,r)}async run(e){this.#t||(this.#n(),this.#t=!0),this.#l(e.scriptPath||""),this.#i(e.relativeUri||""),this.#o(e.method||"GET");const{host:r,...s}={host:"example.com:443",...Fe(e.headers||{})};if(this.#r(r,e.protocol||"http"),this.#a(s),e.body&&this.#c(e.body),e.fileInfos)for(const n of e.fileInfos)this.#u(n);return e.code&&this.#h(" ?>"+e.code),await this.#d()}#n(){if(this.#e.length>0){const e=this.#e.map(([r,s])=>`${r}=${s}`).join(`
97
97
  `)+`
98
98
 
99
- `;this[h].ccall("wasm_set_phpini_entries",null,[f],[e])}this[h].ccall("php_wasm_init",null,[],[])}#s(){const e="/tmp/headers.json";if(!this.fileExists(e))throw new Error("SAPI Error: Could not find response headers file.");const r=JSON.parse(this.readFileAsText(e)),s={};for(const n of r.headers){if(!n.includes(": "))continue;const i=n.indexOf(": "),o=n.substring(0,i).toLowerCase(),a=n.substring(i+2);o in s||(s[o]=[]),s[o].push(a)}return{headers:s,httpStatusCode:r.status}}#i(e){if(this[h].ccall("wasm_set_request_uri",null,[f],[e]),e.includes("?")){const r=e.substring(e.indexOf("?")+1);this[h].ccall("wasm_set_query_string",null,[f],[r])}}#r(e,r){this[h].ccall("wasm_set_request_host",null,[f],[e]);let s;try{s=parseInt(new URL(e).port,10)}catch{}(!s||isNaN(s)||s===80)&&(s=r==="https"?443:80),this[h].ccall("wasm_set_request_port",null,[S],[s]),(r==="https"||!r&&s===443)&&this.addServerGlobalEntry("HTTPS","on")}#o(e){this[h].ccall("wasm_set_request_method",null,[f],[e])}#a(e){e.cookie&&this[h].ccall("wasm_set_cookies",null,[f],[e.cookie]),e["content-type"]&&this[h].ccall("wasm_set_content_type",null,[f],[e["content-type"]]),e["content-length"]&&this[h].ccall("wasm_set_content_length",null,[S],[parseInt(e["content-length"],10)]);for(const r in e)this.addServerGlobalEntry(`HTTP_${r.toUpperCase().replace(/-/g,"_")}`,e[r])}#c(e){this[h].ccall("wasm_set_request_body",null,[f],[e]),this[h].ccall("wasm_set_content_length",null,[S],[e.length])}#l(e){this[h].ccall("wasm_set_path_translated",null,[f],[e])}addServerGlobalEntry(e,r){this[h].ccall("wasm_add_SERVER_entry",null,[f,f],[e,r])}#u(e){const{key:r,name:s,type:n,data:i}=e,o=`/tmp/${Math.random().toFixed(20)}`;this.writeFile(o,i);const a=0;this[h].ccall("wasm_add_uploaded_file",null,[f,f,f,f,S,S],[r,s,n,o,a,i.byteLength])}#h(e){this[h].ccall("wasm_set_php_code",null,[f],[e])}async#d(){const e=await await this[h].ccall("wasm_sapi_handle_request",S,[],[]),{headers:r,httpStatusCode:s}=this.#s();return new v(s,r,this.readFileAsBuffer("/tmp/stdout"),this.readFileAsText("/tmp/stderr"),e)}mkdir(e){this[h].FS.mkdirTree(e)}mkdirTree(e){this.mkdir(e)}readFileAsText(e){return new TextDecoder().decode(this.readFileAsBuffer(e))}readFileAsBuffer(e){return this[h].FS.readFile(e)}writeFile(e,r){this[h].FS.writeFile(e,r)}unlink(e){this[h].FS.unlink(e)}mv(e,r){this[h].FS.mv(e,r)}rmdir(e,r={recursive:!0}){r?.recursive&&this.listFiles(e).forEach(s=>{const n=`${e}/${s}`;this.isDir(n)?this.rmdir(n,r):this.unlink(n)}),this[h].FS.rmdir(e)}listFiles(e){if(!this.fileExists(e))return[];try{return this[h].FS.readdir(e).filter(r=>r!=="."&&r!=="..")}catch(r){return console.error(r,{path:e}),[]}}isDir(e){return this.fileExists(e)?this[h].FS.isDir(this[h].FS.lookupPath(e).node.mode):!1}fileExists(e){try{return this[h].FS.lookupPath(e),!0}catch{return!1}}}w([m('Could not create directory "{path}"')],g.prototype,"mkdir",1);w([m('Could not create directory "{path}"')],g.prototype,"mkdirTree",1);w([m('Could not read "{path}"')],g.prototype,"readFileAsText",1);w([m('Could not read "{path}"')],g.prototype,"readFileAsBuffer",1);w([m('Could not write to "{path}"')],g.prototype,"writeFile",1);w([m('Could not unlink "{path}"')],g.prototype,"unlink",1);w([m('Could not move "{path}"')],g.prototype,"mv",1);w([m('Could not remove directory "{path}"')],g.prototype,"rmdir",1);w([m('Could not list files in "{path}"')],g.prototype,"listFiles",1);w([m('Could not stat "{path}"')],g.prototype,"isDir",1);w([m('Could not stat "{path}"')],g.prototype,"fileExists",1);function Fe(t){const e={};for(const r in t)e[r.toLowerCase()]=t[r];return e}const ht=["vfs","literal","wordpress.org/themes","wordpress.org/plugins","url"];function dt(t){return t&&typeof t=="object"&&typeof t.resource=="string"&&ht.includes(t.resource)}class _{static create(e,{semaphore:r,progress:s}){let n;switch(e.resource){case"vfs":n=new pt(e,s);break;case"literal":n=new ft(e,s);break;case"wordpress.org/themes":n=new yt(e,s);break;case"wordpress.org/plugins":n=new Pt(e,s);break;case"url":n=new wt(e,s);break;default:throw new Error(`Invalid resource: ${e}`)}return n=new bt(n),r&&(n=new _t(n,r)),n}setPlayground(e){this.playground=e}get isAsync(){return!1}}class pt extends _{constructor(e,r){super(),this.resource=e,this.progress=r}async resolve(){const e=await this.playground.readFileAsBuffer(this.resource.path);return this.progress?.set(100),new File([e],this.name)}get name(){return this.resource.path}}class ft extends _{constructor(e,r){super(),this.resource=e,this.progress=r}async resolve(){return this.progress?.set(100),new File([this.resource.contents],this.resource.name)}get name(){return this.resource.name}}class q extends _{constructor(e){super(),this.progress=e}async resolve(){this.progress?.setCaption(this.caption);const e=this.getURL();let r=await fetch(e);if(r=await Ze(r,this.progress?.loadingListener??mt),r.status!==200)throw new Error(`Could not download "${e}"`);return new File([await r.blob()],this.name)}get caption(){return`Downloading ${this.name}`}get name(){return this.getURL()}get isAsync(){return!0}}const mt=()=>{};class wt extends q{constructor(e,r){super(r),this.resource=e}getURL(){return this.resource.url}get caption(){return this.resource.caption??super.caption}}let M="/plugin-proxy";function gt(t){M=t}class yt extends q{constructor(e,r){super(r),this.resource=e}get name(){return L(this.resource.slug)}getURL(){const e=ke(this.resource.slug);return`${M}?theme=`+e}}class Pt extends q{constructor(e,r){super(r),this.resource=e}get name(){return L(this.resource.slug)}getURL(){const e=ke(this.resource.slug);return`${M}?plugin=`+e}}function ke(t){return!t||t.endsWith(".zip")?t:t+".latest-stable.zip"}class Oe extends _{constructor(e){super(),this.resource=e}async resolve(){return this.resource.resolve()}async setPlayground(e){return this.resource.setPlayground(e)}get progress(){return this.resource.progress}set progress(e){this.resource.progress=e}get name(){return this.resource.name}get isAsync(){return this.resource.isAsync}}class bt extends Oe{async resolve(){return this.promise||(this.promise=super.resolve()),this.promise}}class _t extends Oe{constructor(e,r){super(e),this.semaphore=r}async resolve(){return this.isAsync?this.semaphore.run(()=>super.resolve()):super.resolve()}}const St=["6.2","6.1","6.0","5.9"];function Ue(t,{progress:e=new H,semaphore:r=new ge({concurrency:3}),onStepCompleted:s=()=>{}}={}){const n=(t.steps||[]).filter($t),i=n.reduce((a,l)=>a+(l.progress?.weight||1),0),o=n.map(a=>vt(a,{semaphore:r,rootProgressTracker:e,totalProgressWeight:i}));return{versions:{php:X(t.preferredVersions?.php,I,Ce),wp:X(t.preferredVersions?.wp,St,"6.2")},run:async a=>{try{for(const{resources:l}of o)for(const c of l)c.setPlayground(a),c.isAsync&&c.resolve();for(const{run:l,step:c}of o){const u=await l(a);s(u,c)}try{await a.goTo(t.landingPage||"/")}catch{}}finally{e.finish()}}}}function X(t,e,r){return t&&e.includes(t)?t:r}function $t(t){return!!(typeof t=="object"&&t)}function vt(t,{semaphore:e,rootProgressTracker:r,totalProgressWeight:s}){const n=r.stage((t.progress?.weight||1)/s),i={};for(const u of Object.keys(t)){let d=t[u];dt(d)&&(d=_.create(d,{semaphore:e})),i[u]=d}const o=async u=>{try{return n.fillSlowly(),await Qe[t.step](u,await Et(i),{tracker:n,initialCaption:t.progress?.caption})}finally{n.finish()}},a=Z(i),l=Z(i).filter(u=>u.isAsync),c=1/(l.length+1);for(const u of l)u.progress=n.stage(c);return{run:o,step:t,resources:a}}function Z(t){const e=[];for(const r in t){const s=t[r];s instanceof _&&e.push(s)}return e}async function Et(t){const e={};for(const r in t){const s=t[r];s instanceof _?e[r]=await s.resolve():e[r]=s}return e}async function Le(t,e){await t.run(e)}/**
99
+ `;this[h].ccall("wasm_set_phpini_entries",null,[f],[e])}this[h].ccall("php_wasm_init",null,[],[])}#s(){const e="/tmp/headers.json";if(!this.fileExists(e))throw new Error("SAPI Error: Could not find response headers file.");const r=JSON.parse(this.readFileAsText(e)),s={};for(const n of r.headers){if(!n.includes(": "))continue;const i=n.indexOf(": "),o=n.substring(0,i).toLowerCase(),a=n.substring(i+2);o in s||(s[o]=[]),s[o].push(a)}return{headers:s,httpStatusCode:r.status}}#i(e){if(this[h].ccall("wasm_set_request_uri",null,[f],[e]),e.includes("?")){const r=e.substring(e.indexOf("?")+1);this[h].ccall("wasm_set_query_string",null,[f],[r])}}#r(e,r){this[h].ccall("wasm_set_request_host",null,[f],[e]);let s;try{s=parseInt(new URL(e).port,10)}catch{}(!s||isNaN(s)||s===80)&&(s=r==="https"?443:80),this[h].ccall("wasm_set_request_port",null,[S],[s]),(r==="https"||!r&&s===443)&&this.addServerGlobalEntry("HTTPS","on")}#o(e){this[h].ccall("wasm_set_request_method",null,[f],[e])}#a(e){e.cookie&&this[h].ccall("wasm_set_cookies",null,[f],[e.cookie]),e["content-type"]&&this[h].ccall("wasm_set_content_type",null,[f],[e["content-type"]]),e["content-length"]&&this[h].ccall("wasm_set_content_length",null,[S],[parseInt(e["content-length"],10)]);for(const r in e)this.addServerGlobalEntry(`HTTP_${r.toUpperCase().replace(/-/g,"_")}`,e[r])}#c(e){this[h].ccall("wasm_set_request_body",null,[f],[e]),this[h].ccall("wasm_set_content_length",null,[S],[e.length])}#l(e){this[h].ccall("wasm_set_path_translated",null,[f],[e])}addServerGlobalEntry(e,r){this[h].ccall("wasm_add_SERVER_entry",null,[f,f],[e,r])}#u(e){const{key:r,name:s,type:n,data:i}=e,o=`/tmp/${Math.random().toFixed(20)}`;this.writeFile(o,i);const a=0;this[h].ccall("wasm_add_uploaded_file",null,[f,f,f,f,S,S],[r,s,n,o,a,i.byteLength])}#h(e){this[h].ccall("wasm_set_php_code",null,[f],[e])}async#d(){const e=await await this[h].ccall("wasm_sapi_handle_request",S,[],[]),{headers:r,httpStatusCode:s}=this.#s();return new v(s,r,this.readFileAsBuffer("/tmp/stdout"),this.readFileAsText("/tmp/stderr"),e)}mkdir(e){this[h].FS.mkdirTree(e)}mkdirTree(e){this.mkdir(e)}readFileAsText(e){return new TextDecoder().decode(this.readFileAsBuffer(e))}readFileAsBuffer(e){return this[h].FS.readFile(e)}writeFile(e,r){this[h].FS.writeFile(e,r)}unlink(e){this[h].FS.unlink(e)}mv(e,r){this[h].FS.mv(e,r)}rmdir(e,r={recursive:!0}){r?.recursive&&this.listFiles(e).forEach(s=>{const n=`${e}/${s}`;this.isDir(n)?this.rmdir(n,r):this.unlink(n)}),this[h].FS.rmdir(e)}listFiles(e){if(!this.fileExists(e))return[];try{return this[h].FS.readdir(e).filter(r=>r!=="."&&r!=="..")}catch(r){return console.error(r,{path:e}),[]}}isDir(e){return this.fileExists(e)?this[h].FS.isDir(this[h].FS.lookupPath(e).node.mode):!1}fileExists(e){try{return this[h].FS.lookupPath(e),!0}catch{return!1}}}w([m('Could not create directory "{path}"')],g.prototype,"mkdir",1);w([m('Could not create directory "{path}"')],g.prototype,"mkdirTree",1);w([m('Could not read "{path}"')],g.prototype,"readFileAsText",1);w([m('Could not read "{path}"')],g.prototype,"readFileAsBuffer",1);w([m('Could not write to "{path}"')],g.prototype,"writeFile",1);w([m('Could not unlink "{path}"')],g.prototype,"unlink",1);w([m('Could not move "{path}"')],g.prototype,"mv",1);w([m('Could not remove directory "{path}"')],g.prototype,"rmdir",1);w([m('Could not list files in "{path}"')],g.prototype,"listFiles",1);w([m('Could not stat "{path}"')],g.prototype,"isDir",1);w([m('Could not stat "{path}"')],g.prototype,"fileExists",1);function Fe(t){const e={};for(const r in t)e[r.toLowerCase()]=t[r];return e}const ht=["vfs","literal","wordpress.org/themes","wordpress.org/plugins","url"];function dt(t){return t&&typeof t=="object"&&typeof t.resource=="string"&&ht.includes(t.resource)}class _{static create(e,{semaphore:r,progress:s}){let n;switch(e.resource){case"vfs":n=new pt(e,s);break;case"literal":n=new ft(e,s);break;case"wordpress.org/themes":n=new yt(e,s);break;case"wordpress.org/plugins":n=new Pt(e,s);break;case"url":n=new wt(e,s);break;default:throw new Error(`Invalid resource: ${e}`)}return n=new bt(n),r&&(n=new _t(n,r)),n}setPlayground(e){this.playground=e}get isAsync(){return!1}}class pt extends _{constructor(e,r){super(),this.resource=e,this.progress=r}async resolve(){const e=await this.playground.readFileAsBuffer(this.resource.path);return this.progress?.set(100),new File([e],this.name)}get name(){return this.resource.path}}class ft extends _{constructor(e,r){super(),this.resource=e,this.progress=r}async resolve(){return this.progress?.set(100),new File([this.resource.contents],this.resource.name)}get name(){return this.resource.name}}class q extends _{constructor(e){super(),this.progress=e}async resolve(){this.progress?.setCaption(this.caption);const e=this.getURL();let r=await fetch(e);if(r=await Ze(r,this.progress?.loadingListener??mt),r.status!==200)throw new Error(`Could not download "${e}"`);return new File([await r.blob()],this.name)}get caption(){return`Downloading ${this.name}`}get name(){return this.getURL()}get isAsync(){return!0}}const mt=()=>{};class wt extends q{constructor(e,r){super(r),this.resource=e}getURL(){return this.resource.url}get caption(){return this.resource.caption??super.caption}}let M="https://playground.wordpress.net/plugin-proxy";function gt(t){M=t}class yt extends q{constructor(e,r){super(r),this.resource=e}get name(){return L(this.resource.slug)}getURL(){const e=ke(this.resource.slug);return`${M}?theme=`+e}}class Pt extends q{constructor(e,r){super(r),this.resource=e}get name(){return L(this.resource.slug)}getURL(){const e=ke(this.resource.slug);return`${M}?plugin=`+e}}function ke(t){return!t||t.endsWith(".zip")?t:t+".latest-stable.zip"}class Oe extends _{constructor(e){super(),this.resource=e}async resolve(){return this.resource.resolve()}async setPlayground(e){return this.resource.setPlayground(e)}get progress(){return this.resource.progress}set progress(e){this.resource.progress=e}get name(){return this.resource.name}get isAsync(){return this.resource.isAsync}}class bt extends Oe{async resolve(){return this.promise||(this.promise=super.resolve()),this.promise}}class _t extends Oe{constructor(e,r){super(e),this.semaphore=r}async resolve(){return this.isAsync?this.semaphore.run(()=>super.resolve()):super.resolve()}}const St=["6.2","6.1","6.0","5.9"];function Ue(t,{progress:e=new H,semaphore:r=new ge({concurrency:3}),onStepCompleted:s=()=>{}}={}){const n=(t.steps||[]).filter($t),i=n.reduce((a,l)=>a+(l.progress?.weight||1),0),o=n.map(a=>vt(a,{semaphore:r,rootProgressTracker:e,totalProgressWeight:i}));return{versions:{php:X(t.preferredVersions?.php,I,Ce),wp:X(t.preferredVersions?.wp,St,"6.2")},run:async a=>{try{for(const{resources:l}of o)for(const c of l)c.setPlayground(a),c.isAsync&&c.resolve();for(const{run:l,step:c}of o){const u=await l(a);s(u,c)}try{await a.goTo(t.landingPage||"/")}catch{}}finally{e.finish()}}}}function X(t,e,r){return t&&e.includes(t)?t:r}function $t(t){return!!(typeof t=="object"&&t)}function vt(t,{semaphore:e,rootProgressTracker:r,totalProgressWeight:s}){const n=r.stage((t.progress?.weight||1)/s),i={};for(const u of Object.keys(t)){let d=t[u];dt(d)&&(d=_.create(d,{semaphore:e})),i[u]=d}const o=async u=>{try{return n.fillSlowly(),await Qe[t.step](u,await Et(i),{tracker:n,initialCaption:t.progress?.caption})}finally{n.finish()}},a=Z(i),l=Z(i).filter(u=>u.isAsync),c=1/(l.length+1);for(const u of l)u.progress=n.stage(c);return{run:o,step:t,resources:a}}function Z(t){const e=[];for(const r in t){const s=t[r];s instanceof _&&e.push(s)}return e}async function Et(t){const e={};for(const r in t){const s=t[r];s instanceof _?e[r]=await s.resolve():e[r]=s}return e}async function Le(t,e){await t.run(e)}/**
100
100
  * @license
101
101
  * Copyright 2019 Google LLC
102
102
  * SPDX-License-Identifier: Apache-2.0
package/index.js CHANGED
@@ -1662,7 +1662,7 @@ class dt extends q {
1662
1662
  return this.resource.caption ?? super.caption;
1663
1663
  }
1664
1664
  }
1665
- let W = "/plugin-proxy";
1665
+ let W = "https://playground.wordpress.net/plugin-proxy";
1666
1666
  function Dt(t) {
1667
1667
  W = t;
1668
1668
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wp-playground/client",
3
- "version": "0.1.37",
3
+ "version": "0.1.38",
4
4
  "description": "WordPress Playground client",
5
5
  "repository": {
6
6
  "type": "git",
@@ -37,5 +37,5 @@
37
37
  "main": "./index.cjs",
38
38
  "module": "./index.js",
39
39
  "types": "index.d.ts",
40
- "gitHead": "278ae7717090b6ee837b43c7d60df94dcdcaec3f"
40
+ "gitHead": "533995a666105306bab5f92a94fb5d433e8a426b"
41
41
  }