@wp-playground/client 0.9.19 → 0.9.20

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 CHANGED
@@ -529,8 +529,8 @@ echo json_encode($deactivated_plugins);
529
529
 
530
530
  // Publish the changeset, which publishes the starter content.
531
531
  wp_publish_post( $wp_customize->changeset_post_id() );
532
- `})},Hr="/tmp/file.zip",hi=async(e,t,r)=>{if(t instanceof File){const s=t;t=Hr,await e.writeFile(t,new Uint8Array(await s.arrayBuffer()))}const n=Zt({zipPath:t,extractToPath:r});await e.run({code:`<?php
533
- function unzip($zipPath, $extractTo, $overwrite = true)
532
+ `})},Hr="/tmp/file.zip",hi=async(e,t,r,n=!0)=>{if(t instanceof File){const i=t;t=Hr,await e.writeFile(t,new Uint8Array(await i.arrayBuffer()))}const s=Zt({zipPath:t,extractToPath:r,overwriteFiles:n});await e.run({code:`<?php
533
+ function unzip($zipPath, $extractTo, $overwriteFiles = true)
534
534
  {
535
535
  if (!is_dir($extractTo)) {
536
536
  mkdir($extractTo, 0777, true);
@@ -538,14 +538,23 @@ echo json_encode($deactivated_plugins);
538
538
  $zip = new ZipArchive;
539
539
  $res = $zip->open($zipPath);
540
540
  if ($res === TRUE) {
541
- $zip->extractTo($extractTo);
542
- $zip->close();
543
- chmod($extractTo, 0777);
541
+ for ($i = 0; $i < $zip->numFiles; $i++) {
542
+ $filename = $zip->getNameIndex($i);
543
+ $fileinfo = pathinfo($filename);
544
+ $extractFilePath = rtrim($extractTo, '/') . '/' . $filename;
545
+ // Check if file exists and $overwriteFiles is false
546
+ if (!file_exists($extractFilePath) || $overwriteFiles) {
547
+ // Extract file
548
+ $zip->extractTo($extractTo, $filename);
549
+ }
550
+ }
551
+ $zip->close();
552
+ chmod($extractTo, 0777);
544
553
  } else {
545
554
  throw new Exception("Could not unzip file");
546
555
  }
547
556
  }
548
- unzip(${n.zipPath}, ${n.extractToPath});
557
+ unzip(${s.zipPath}, ${s.extractToPath}, ${s.overwriteFiles});
549
558
  `}),await e.fileExists(Hr)&&await e.unlink(Hr)},Dr=async(e,{zipFile:t,zipPath:r,extractToPath:n})=>{if(r)he.warn('The "zipPath" option of the unzip() Blueprint step is deprecated and will be removed. Use "zipFile" instead.');else if(!t)throw new Error("Either zipPath or zipFile must be provided");await hi(e,t||r,n)},mi=async(e,{wordPressFilesZip:t,pathInZip:r=""})=>{const n=await e.documentRoot;let s=de("/tmp","import");await e.mkdir(s),await Dr(e,{zipFile:t,extractToPath:s}),s=de(s,r);const i=de(s,"wp-content"),o=de(n,"wp-content");for(const d of pn){const p=de(i,d);await bs(e,p);const _=de(o,d);await e.fileExists(_)&&(await e.mkdir(Xs(p)),await e.mv(_,p))}const u=de(s,"wp-content","database");await e.fileExists(u)||await e.mv(de(n,"wp-content","database"),u);const f=await e.listFiles(s);for(const d of f)await bs(e,de(n,d)),await e.mv(de(s,d),de(n,d));await e.rmdir(s),await $n(e,{siteUrl:await e.absoluteUrl});const l=ae(de(n,"wp-admin","upgrade.php"));await e.run({code:`<?php
550
559
  $_GET['step'] = 'upgrade_db';
551
560
  require ${l};
@@ -729,4 +738,4 @@ for existing apps using this option.`}},required:["consts","step"]},{type:"objec
729
738
  * @license
730
739
  * Copyright 2019 Google LLC
731
740
  * SPDX-License-Identifier: Apache-2.0
732
- */const mo=Symbol("Comlink.proxy"),Id=Symbol("Comlink.endpoint"),jd=Symbol("Comlink.releaseProxy"),Xr=Symbol("Comlink.finalizer"),wr=Symbol("Comlink.thrown"),yo=e=>typeof e=="object"&&e!==null||typeof e=="function",Ad={canHandle:e=>yo(e)&&e[mo],serialize(e){const{port1:t,port2:r}=new MessageChannel;return is(e,t),[r,[r]]},deserialize(e){return e.start(),os(e)}},Dd={canHandle:e=>yo(e)&&wr 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}},Tt=new Map([["proxy",Ad],["throw",Dd]]);function Md(e,t){for(const r of e)if(t===r||r==="*"||r instanceof RegExp&&r.test(t))return!0;return!1}function is(e,t=globalThis,r=["*"]){t.addEventListener("message",function n(s){if(!s||!s.data)return;if(!Md(r,s.origin)){console.warn(`Invalid origin '${s.origin}' for comlink proxy`);return}const{id:i,type:o,path:u}=Object.assign({path:[]},s.data),f=(s.data.argumentList||[]).map(lt);let l;try{const d=u.slice(0,-1).reduce((_,b)=>_[b],e),p=u.reduce((_,b)=>_[b],e);switch(o){case"GET":l=p;break;case"SET":d[u.slice(-1)[0]]=lt(s.data.value),l=!0;break;case"APPLY":l=p.apply(d,f);break;case"CONSTRUCT":{const _=new p(...f);l=wo(_)}break;case"ENDPOINT":{const{port1:_,port2:b}=new MessageChannel;is(e,b),l=zd(_,[_])}break;case"RELEASE":l=void 0;break;default:return}}catch(d){l={value:d,[wr]:0}}Promise.resolve(l).catch(d=>({value:d,[wr]:0})).then(d=>{const[p,_]=jr(d);t.postMessage(Object.assign(Object.assign({},p),{id:i}),_),o==="RELEASE"&&(t.removeEventListener("message",n),go(t),Xr in e&&typeof e[Xr]=="function"&&e[Xr]())}).catch(d=>{const[p,_]=jr({value:new TypeError("Unserializable return value"),[wr]:0});t.postMessage(Object.assign(Object.assign({},p),{id:i}),_)})}),t.start&&t.start()}function Ld(e){return e.constructor.name==="MessagePort"}function go(e){Ld(e)&&e.close()}function os(e,t){return fn(e,[],t)}function hr(e){if(e)throw new Error("Proxy has been released and is not useable")}function $o(e){return St(e,{type:"RELEASE"}).then(()=>{go(e)})}const Nr=new WeakMap,Ir="FinalizationRegistry"in globalThis&&new FinalizationRegistry(e=>{const t=(Nr.get(e)||0)-1;Nr.set(e,t),t===0&&$o(e)});function Fd(e,t){const r=(Nr.get(t)||0)+1;Nr.set(t,r),Ir&&Ir.register(e,t,e)}function qd(e){Ir&&Ir.unregister(e)}function fn(e,t=[],r=function(){}){let n=!1;const s=new Proxy(r,{get(i,o){if(hr(n),o===jd)return()=>{qd(s),$o(e),n=!0};if(o==="then"){if(t.length===0)return{then:()=>s};const u=St(e,{type:"GET",path:t.map(f=>f.toString())}).then(lt);return u.then.bind(u)}return fn(e,[...t,o])},set(i,o,u){hr(n);const[f,l]=jr(u);return St(e,{type:"SET",path:[...t,o].map(d=>d.toString()),value:f},l).then(lt)},apply(i,o,u){hr(n);const f=t[t.length-1];if(f===Id)return St(e,{type:"ENDPOINT"}).then(lt);if(f==="bind")return fn(e,t.slice(0,-1));const[l,d]=Ks(u);return St(e,{type:"APPLY",path:t.map(p=>p.toString()),argumentList:l},d).then(lt)},construct(i,o){hr(n);const[u,f]=Ks(o);return St(e,{type:"CONSTRUCT",path:t.map(l=>l.toString()),argumentList:u},f).then(lt)}});return Fd(s,e),s}function Ud(e){return Array.prototype.concat.apply([],e)}function Ks(e){const t=e.map(jr);return[t.map(r=>r[0]),Ud(t.map(r=>r[1]))]}const _o=new WeakMap;function zd(e,t){return _o.set(e,t),e}function wo(e){return Object.assign(e,{[mo]:!0})}function Vd(e,t=globalThis,r="*"){return{postMessage:(n,s)=>e.postMessage(n,r,s),addEventListener:t.addEventListener.bind(t),removeEventListener:t.removeEventListener.bind(t)}}function jr(e){for(const[t,r]of Tt)if(r.canHandle(e)){const[n,s]=r.serialize(e);return[{type:"HANDLER",name:t,value:n},s]}return[{type:"RAW",value:e},_o.get(e)||[]]}function lt(e){switch(e.type){case"HANDLER":return Tt.get(e.name).deserialize(e.value);case"RAW":return e.value}}function St(e,t,r){return new Promise(n=>{const s=Wd();e.addEventListener("message",function i(o){!o.data||!o.data.id||o.data.id!==s||(e.removeEventListener("message",i),n(o.data))}),e.start&&e.start(),e.postMessage(Object.assign({id:s},t),r)})}function Wd(){return new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-")}function vo(e,t=void 0){Hd();const r=e instanceof Worker?e:Vd(e,t),n=os(r),s=bo(n);return new Proxy(s,{get:(i,o)=>o==="isConnected"?async()=>{for(;;)try{await xd(n.isConnected(),200);break}catch{}}:n[o]})}async function xd(e,t){return new Promise((r,n)=>{setTimeout(n,t),e.then(r)})}let Js=!1;function Hd(){if(Js)return;Js=!0,Tt.set("EVENT",{canHandle:r=>r instanceof CustomEvent,serialize:r=>[{detail:r.detail},[]],deserialize:r=>r}),Tt.set("FUNCTION",{canHandle:r=>typeof r=="function",serialize(r){const{port1:n,port2:s}=new MessageChannel;return is(r,n),[s,[s]]},deserialize(r){return r.start(),os(r)}}),Tt.set("PHPResponse",{canHandle:r=>typeof r=="object"&&r!==null&&"headers"in r&&"bytes"in r&&"errors"in r&&"exitCode"in r&&"httpStatusCode"in r,serialize(r){return[r.toRawData(),[]]},deserialize(r){return Sr.fromRawData(r)}});const e=Tt.get("throw"),t=e==null?void 0:e.serialize;e.serialize=({value:r})=>{const n=t({value:r});return r.response&&(n[0].value.response=r.response),r.source&&(n[0].value.source=r.source),n}}function bo(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]:bo(t[r]);case"undefined":case"number":case"string":return t[r];default:return wo(t[r])}}})}async function Eo({iframe:e,blueprint:t,remoteUrl:r,progressTracker:n=new Lr,disableProgressBar:s,onBlueprintStepCompleted:i,onClientConnected:o=()=>{},sapiName:u,onBeforeBlueprint:f,siteSlug:l}){if(Gd(r),Bd(e),r=en(r,{progressbar:!s}),n.setCaption("Preparing WordPress"),!t){const _=await Qs(e,en(r,{"php-extension":"kitchen-sink","site-slug":l}),n);return o(_),_}const d=po(t,{progress:n.stage(.5),onStepCompleted:i}),p=await Qs(e,en(r,{php:d.versions.php,wp:d.versions.wp,"sapi-name":u,"php-extension":d.phpExtensions,networking:d.features.networking?"yes":"no","site-slug":l}),n);return Jo(he,p),o(p),f&&await f(),await ho(d,p),n.finish(),p}function Bd(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 Qs(e,t,r){await new Promise(i=>{e.src=t,e.addEventListener("load",i,!1)});const n=vo(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 vr="https://playground.wordpress.net";function Gd(e){const t=new URL(e,vr);if((t.origin===vr||t.hostname==="localhost")&&t.pathname!=="/remote.html")throw new Error(`Invalid remote URL: ${t}. Expected origin to be ${vr}/remote.html.`)}function en(e,t){const r=new URL(e,vr),n=new URLSearchParams(r.search);for(const[s,i]of Object.entries(t))if(i!=null&&i!==!1)if(Array.isArray(i))for(const o of i)n.append(s,o.toString());else n.set(s,i.toString());return r.search=n.toString(),r.toString()}async function Kd(e,t){if(he.warn("`connectPlayground` is deprecated and will be removed. Use `startPlayground` instead."),t!=null&&t.loadRemote)return Eo({iframe:e,remoteUrl:t.loadRemote});const r=vo(e.contentWindow,e.ownerDocument.defaultView);return await r.isConnected(),r}exports.LatestSupportedPHPVersion=Ri;exports.SupportedPHPVersions=Fr;exports.SupportedPHPVersionsList=ha;exports.activatePlugin=Ar;exports.activateTheme=hn;exports.compileBlueprint=po;exports.connectPlayground=Kd;exports.cp=li;exports.defineSiteUrl=$n;exports.defineWpConfigConsts=Qt;exports.enableMultisite=ci;exports.exportWXR=yi;exports.importThemeStarterContent=_n;exports.importWordPressFiles=mi;exports.importWxr=pi;exports.installPlugin=$i;exports.installTheme=_i;exports.login=Er;exports.mkdir=di;exports.mv=ui;exports.phpVar=ae;exports.phpVars=Zt;exports.request=br;exports.resetData=wi;exports.rm=mn;exports.rmdir=fi;exports.runBlueprintSteps=ho;exports.runPHP=ni;exports.runPHPWithOptions=si;exports.runSql=ii;exports.runWpInstallationWizard=vi;exports.setPhpIniEntries=pa;exports.setPluginProxyURL=Nd;exports.setSiteLanguage=Pi;exports.setSiteOptions=yn;exports.startPlaygroundWeb=Eo;exports.unzip=Dr;exports.updateUserMeta=oi;exports.wpCLI=Ei;exports.wpContentFilesExcludedFromExport=pn;exports.writeFile=gn;exports.zipWpContent=bi;
741
+ */const mo=Symbol("Comlink.proxy"),Id=Symbol("Comlink.endpoint"),jd=Symbol("Comlink.releaseProxy"),Xr=Symbol("Comlink.finalizer"),wr=Symbol("Comlink.thrown"),yo=e=>typeof e=="object"&&e!==null||typeof e=="function",Ad={canHandle:e=>yo(e)&&e[mo],serialize(e){const{port1:t,port2:r}=new MessageChannel;return is(e,t),[r,[r]]},deserialize(e){return e.start(),os(e)}},Dd={canHandle:e=>yo(e)&&wr 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}},Tt=new Map([["proxy",Ad],["throw",Dd]]);function Md(e,t){for(const r of e)if(t===r||r==="*"||r instanceof RegExp&&r.test(t))return!0;return!1}function is(e,t=globalThis,r=["*"]){t.addEventListener("message",function n(s){if(!s||!s.data)return;if(!Md(r,s.origin)){console.warn(`Invalid origin '${s.origin}' for comlink proxy`);return}const{id:i,type:o,path:u}=Object.assign({path:[]},s.data),f=(s.data.argumentList||[]).map(lt);let l;try{const d=u.slice(0,-1).reduce((_,b)=>_[b],e),p=u.reduce((_,b)=>_[b],e);switch(o){case"GET":l=p;break;case"SET":d[u.slice(-1)[0]]=lt(s.data.value),l=!0;break;case"APPLY":l=p.apply(d,f);break;case"CONSTRUCT":{const _=new p(...f);l=wo(_)}break;case"ENDPOINT":{const{port1:_,port2:b}=new MessageChannel;is(e,b),l=zd(_,[_])}break;case"RELEASE":l=void 0;break;default:return}}catch(d){l={value:d,[wr]:0}}Promise.resolve(l).catch(d=>({value:d,[wr]:0})).then(d=>{const[p,_]=jr(d);t.postMessage(Object.assign(Object.assign({},p),{id:i}),_),o==="RELEASE"&&(t.removeEventListener("message",n),go(t),Xr in e&&typeof e[Xr]=="function"&&e[Xr]())}).catch(d=>{const[p,_]=jr({value:new TypeError("Unserializable return value"),[wr]:0});t.postMessage(Object.assign(Object.assign({},p),{id:i}),_)})}),t.start&&t.start()}function Ld(e){return e.constructor.name==="MessagePort"}function go(e){Ld(e)&&e.close()}function os(e,t){return fn(e,[],t)}function hr(e){if(e)throw new Error("Proxy has been released and is not useable")}function $o(e){return St(e,{type:"RELEASE"}).then(()=>{go(e)})}const Nr=new WeakMap,Ir="FinalizationRegistry"in globalThis&&new FinalizationRegistry(e=>{const t=(Nr.get(e)||0)-1;Nr.set(e,t),t===0&&$o(e)});function Fd(e,t){const r=(Nr.get(t)||0)+1;Nr.set(t,r),Ir&&Ir.register(e,t,e)}function qd(e){Ir&&Ir.unregister(e)}function fn(e,t=[],r=function(){}){let n=!1;const s=new Proxy(r,{get(i,o){if(hr(n),o===jd)return()=>{qd(s),$o(e),n=!0};if(o==="then"){if(t.length===0)return{then:()=>s};const u=St(e,{type:"GET",path:t.map(f=>f.toString())}).then(lt);return u.then.bind(u)}return fn(e,[...t,o])},set(i,o,u){hr(n);const[f,l]=jr(u);return St(e,{type:"SET",path:[...t,o].map(d=>d.toString()),value:f},l).then(lt)},apply(i,o,u){hr(n);const f=t[t.length-1];if(f===Id)return St(e,{type:"ENDPOINT"}).then(lt);if(f==="bind")return fn(e,t.slice(0,-1));const[l,d]=Ks(u);return St(e,{type:"APPLY",path:t.map(p=>p.toString()),argumentList:l},d).then(lt)},construct(i,o){hr(n);const[u,f]=Ks(o);return St(e,{type:"CONSTRUCT",path:t.map(l=>l.toString()),argumentList:u},f).then(lt)}});return Fd(s,e),s}function Ud(e){return Array.prototype.concat.apply([],e)}function Ks(e){const t=e.map(jr);return[t.map(r=>r[0]),Ud(t.map(r=>r[1]))]}const _o=new WeakMap;function zd(e,t){return _o.set(e,t),e}function wo(e){return Object.assign(e,{[mo]:!0})}function Vd(e,t=globalThis,r="*"){return{postMessage:(n,s)=>e.postMessage(n,r,s),addEventListener:t.addEventListener.bind(t),removeEventListener:t.removeEventListener.bind(t)}}function jr(e){for(const[t,r]of Tt)if(r.canHandle(e)){const[n,s]=r.serialize(e);return[{type:"HANDLER",name:t,value:n},s]}return[{type:"RAW",value:e},_o.get(e)||[]]}function lt(e){switch(e.type){case"HANDLER":return Tt.get(e.name).deserialize(e.value);case"RAW":return e.value}}function St(e,t,r){return new Promise(n=>{const s=Wd();e.addEventListener("message",function i(o){!o.data||!o.data.id||o.data.id!==s||(e.removeEventListener("message",i),n(o.data))}),e.start&&e.start(),e.postMessage(Object.assign({id:s},t),r)})}function Wd(){return new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-")}function vo(e,t=void 0){Hd();const r=e instanceof Worker?e:Vd(e,t),n=os(r),s=bo(n);return new Proxy(s,{get:(i,o)=>o==="isConnected"?async()=>{for(;;)try{await xd(n.isConnected(),200);break}catch{}}:n[o]})}async function xd(e,t){return new Promise((r,n)=>{setTimeout(n,t),e.then(r)})}let Js=!1;function Hd(){if(Js)return;Js=!0,Tt.set("EVENT",{canHandle:r=>r instanceof CustomEvent,serialize:r=>[{detail:r.detail},[]],deserialize:r=>r}),Tt.set("FUNCTION",{canHandle:r=>typeof r=="function",serialize(r){const{port1:n,port2:s}=new MessageChannel;return is(r,n),[s,[s]]},deserialize(r){return r.start(),os(r)}}),Tt.set("PHPResponse",{canHandle:r=>typeof r=="object"&&r!==null&&"headers"in r&&"bytes"in r&&"errors"in r&&"exitCode"in r&&"httpStatusCode"in r,serialize(r){return[r.toRawData(),[]]},deserialize(r){return Sr.fromRawData(r)}});const e=Tt.get("throw"),t=e==null?void 0:e.serialize;e.serialize=({value:r})=>{const n=t({value:r});return r.response&&(n[0].value.response=r.response),r.source&&(n[0].value.source=r.source),n}}function bo(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]:bo(t[r]);case"undefined":case"number":case"string":return t[r];default:return wo(t[r])}}})}new Promise(e=>{});async function Eo({iframe:e,blueprint:t,remoteUrl:r,progressTracker:n=new Lr,disableProgressBar:s,onBlueprintStepCompleted:i,onClientConnected:o=()=>{},sapiName:u,onBeforeBlueprint:f,siteSlug:l}){if(Gd(r),Bd(e),r=en(r,{progressbar:!s}),n.setCaption("Preparing WordPress"),!t){const _=await Qs(e,en(r,{"php-extension":"kitchen-sink","site-slug":l}),n);return o(_),_}const d=po(t,{progress:n.stage(.5),onStepCompleted:i}),p=await Qs(e,en(r,{php:d.versions.php,wp:d.versions.wp,"sapi-name":u,"php-extension":d.phpExtensions,networking:d.features.networking?"yes":"no","site-slug":l}),n);return Jo(he,p),o(p),f&&await f(),await ho(d,p),n.finish(),p}function Bd(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 Qs(e,t,r){await new Promise(i=>{e.src=t,e.addEventListener("load",i,!1)});const n=vo(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 vr="https://playground.wordpress.net";function Gd(e){const t=new URL(e,vr);if((t.origin===vr||t.hostname==="localhost")&&t.pathname!=="/remote.html")throw new Error(`Invalid remote URL: ${t}. Expected origin to be ${vr}/remote.html.`)}function en(e,t){const r=new URL(e,vr),n=new URLSearchParams(r.search);for(const[s,i]of Object.entries(t))if(i!=null&&i!==!1)if(Array.isArray(i))for(const o of i)n.append(s,o.toString());else n.set(s,i.toString());return r.search=n.toString(),r.toString()}async function Kd(e,t){if(he.warn("`connectPlayground` is deprecated and will be removed. Use `startPlayground` instead."),t!=null&&t.loadRemote)return Eo({iframe:e,remoteUrl:t.loadRemote});const r=vo(e.contentWindow,e.ownerDocument.defaultView);return await r.isConnected(),r}exports.LatestSupportedPHPVersion=Ri;exports.SupportedPHPVersions=Fr;exports.SupportedPHPVersionsList=ha;exports.activatePlugin=Ar;exports.activateTheme=hn;exports.compileBlueprint=po;exports.connectPlayground=Kd;exports.cp=li;exports.defineSiteUrl=$n;exports.defineWpConfigConsts=Qt;exports.enableMultisite=ci;exports.exportWXR=yi;exports.importThemeStarterContent=_n;exports.importWordPressFiles=mi;exports.importWxr=pi;exports.installPlugin=$i;exports.installTheme=_i;exports.login=Er;exports.mkdir=di;exports.mv=ui;exports.phpVar=ae;exports.phpVars=Zt;exports.request=br;exports.resetData=wi;exports.rm=mn;exports.rmdir=fi;exports.runBlueprintSteps=ho;exports.runPHP=ni;exports.runPHPWithOptions=si;exports.runSql=ii;exports.runWpInstallationWizard=vi;exports.setPhpIniEntries=pa;exports.setPluginProxyURL=Nd;exports.setSiteLanguage=Pi;exports.setSiteOptions=yn;exports.startPlaygroundWeb=Eo;exports.unzip=Dr;exports.updateUserMeta=oi;exports.wpCLI=Ei;exports.wpContentFilesExcludedFromExport=pn;exports.writeFile=gn;exports.zipWpContent=bi;
package/index.d.ts CHANGED
@@ -2605,6 +2605,7 @@ declare class PlaygroundWorkerEndpoint extends PHPWorker {
2605
2605
  bindOpfs(options: Omit<BindOpfsOptions, "php" | "onProgress">, onProgress?: SyncProgressCallback): Promise<void>;
2606
2606
  journalFSEvents(root: string, callback: (op: FilesystemOperation) => void): Promise<() => any>;
2607
2607
  replayFSJournal(events: FilesystemOperation[]): Promise<void>;
2608
+ backfillStaticFilesRemovedFromMinifiedBuild(): Promise<void>;
2608
2609
  }
2609
2610
  export interface ProgressBarOptions {
2610
2611
  caption?: string;
@@ -2649,6 +2650,7 @@ export interface WebClientMixin extends ProgressReceiver {
2649
2650
  replayFSJournal: PlaygroundWorkerEndpoint["replayFSJournal"];
2650
2651
  addEventListener: PlaygroundWorkerEndpoint["addEventListener"];
2651
2652
  removeEventListener: PlaygroundWorkerEndpoint["removeEventListener"];
2653
+ backfillStaticFilesRemovedFromMinifiedBuild: PlaygroundWorkerEndpoint["backfillStaticFilesRemovedFromMinifiedBuild"];
2652
2654
  /** @inheritDoc @php-wasm/universal!UniversalPHP.onMessage */
2653
2655
  onMessage: PlaygroundWorkerEndpoint["onMessage"];
2654
2656
  bindOpfs(options: Omit<BindOpfsOptions, "php" | "onProgress">, onProgress?: SyncProgressCallback): Promise<void>;
package/index.js CHANGED
@@ -1161,21 +1161,22 @@ const Lo = async (e, { fromPath: t, toPath: r }) => {
1161
1161
  wp_publish_post( $wp_customize->changeset_post_id() );
1162
1162
  `
1163
1163
  });
1164
- }, Ur = "/tmp/file.zip", si = async (e, t, r) => {
1164
+ }, Ur = "/tmp/file.zip", si = async (e, t, r, n = !0) => {
1165
1165
  if (t instanceof File) {
1166
- const s = t;
1166
+ const i = t;
1167
1167
  t = Ur, await e.writeFile(
1168
1168
  t,
1169
- new Uint8Array(await s.arrayBuffer())
1169
+ new Uint8Array(await i.arrayBuffer())
1170
1170
  );
1171
1171
  }
1172
- const n = Nr({
1172
+ const s = Nr({
1173
1173
  zipPath: t,
1174
- extractToPath: r
1174
+ extractToPath: r,
1175
+ overwriteFiles: n
1175
1176
  });
1176
1177
  await e.run({
1177
1178
  code: `<?php
1178
- function unzip($zipPath, $extractTo, $overwrite = true)
1179
+ function unzip($zipPath, $extractTo, $overwriteFiles = true)
1179
1180
  {
1180
1181
  if (!is_dir($extractTo)) {
1181
1182
  mkdir($extractTo, 0777, true);
@@ -1183,14 +1184,23 @@ const Lo = async (e, { fromPath: t, toPath: r }) => {
1183
1184
  $zip = new ZipArchive;
1184
1185
  $res = $zip->open($zipPath);
1185
1186
  if ($res === TRUE) {
1186
- $zip->extractTo($extractTo);
1187
- $zip->close();
1188
- chmod($extractTo, 0777);
1187
+ for ($i = 0; $i < $zip->numFiles; $i++) {
1188
+ $filename = $zip->getNameIndex($i);
1189
+ $fileinfo = pathinfo($filename);
1190
+ $extractFilePath = rtrim($extractTo, '/') . '/' . $filename;
1191
+ // Check if file exists and $overwriteFiles is false
1192
+ if (!file_exists($extractFilePath) || $overwriteFiles) {
1193
+ // Extract file
1194
+ $zip->extractTo($extractTo, $filename);
1195
+ }
1196
+ }
1197
+ $zip->close();
1198
+ chmod($extractTo, 0777);
1189
1199
  } else {
1190
1200
  throw new Exception("Could not unzip file");
1191
1201
  }
1192
1202
  }
1193
- unzip(${n.zipPath}, ${n.extractToPath});
1203
+ unzip(${s.zipPath}, ${s.extractToPath}, ${s.overwriteFiles});
1194
1204
  `
1195
1205
  }), await e.fileExists(Ur) && await e.unlink(Ur);
1196
1206
  }, dn = async (e, { zipFile: t, zipPath: r, extractToPath: n }) => {
@@ -9422,6 +9432,8 @@ function Xi(e) {
9422
9432
  }
9423
9433
  });
9424
9434
  }
9435
+ new Promise((e) => {
9436
+ });
9425
9437
  async function Vd({
9426
9438
  iframe: e,
9427
9439
  blueprint: t,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wp-playground/client",
3
- "version": "0.9.19",
3
+ "version": "0.9.20",
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": "aafbbcdc4b0644885bd55d0ed67381952f0b16b6",
40
+ "gitHead": "f619fcb719128d247bec296b9339aff52101e948",
41
41
  "engines": {
42
42
  "node": ">=18.18.0",
43
43
  "npm": ">=8.11.0"