@wp-playground/blueprints 0.1.58 → 0.1.60

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.
Files changed (3) hide show
  1. package/index.cjs +8 -6
  2. package/index.js +27 -25
  3. package/package.json +2 -2
package/index.cjs CHANGED
@@ -1,4 +1,5 @@
1
1
  "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const x=async(s,{pluginPath:e,pluginName:t},r)=>{r?.tracker.setCaption(`Activating ${t||e}`);const i=[`${await s.documentRoot}/wp-load.php`,`${await s.documentRoot}/wp-admin/includes/plugin.php`];if(!i.every(a=>s.fileExists(a)))throw new Error(`Required WordPress files do not exist: ${i.join(", ")}`);if((await s.run({code:`<?php
2
+ define( 'WP_ADMIN', true );
2
3
  ${i.map(a=>`require_once( '${a}' );`).join(`
3
4
  `)}
4
5
  $plugin_path = '${e}';
@@ -16,9 +17,10 @@ foreach ( ( glob( $plugin_path . '/*.php' ) ?: array() ) as $file ) {
16
17
  }
17
18
  echo 'NO_ENTRY_FILE';
18
19
  `})).text.endsWith("NO_ENTRY_FILE"))throw new Error("Could not find plugin entry file.")},F=async(s,{themeFolderName:e},t)=>{t?.tracker.setCaption(`Activating ${e}`);const r=`${await s.documentRoot}/wp-load.php`;if(!s.fileExists(r))throw new Error(`Required WordPress file does not exist: ${r}`);await s.run({code:`<?php
19
- require_once( '${r}' );
20
- switch_theme( '${e}' );
21
- `})};function b(s){const e=s.split(".").shift().replace(/-/g," ");return e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()}async function P(s,e,t){let r="";await s.fileExists(e)&&(r=await s.readFileAsText(e)),await s.writeFile(e,t(r))}async function xe(s){return new Uint8Array(await s.arrayBuffer())}class Fe extends File{constructor(e,t){super(e,t),this.buffers=e}async arrayBuffer(){return this.buffers[0]}}const T=File.prototype.arrayBuffer instanceof Function?File:Fe,X=async(s,e)=>{const t=new Te(s,e.siteUrl,e.wordpressPath||"/wordpress");e.patchSqlitePlugin!==!1&&await t.patchSqlitePlugin(),e.addPhpInfo!==!1&&await t.addPhpInfo(),e.patchSiteUrl!==!1&&await t.patchSiteUrl(),e.disableSiteHealth!==!1&&await t.disableSiteHealth(),e.disableWpNewBlogNotification!==!1&&await t.disableWpNewBlogNotification()};class Te{constructor(e,t,r){this.php=e,this.scopedSiteUrl=t,this.wordpressPath=r}async patchSqlitePlugin(){await P(this.php,`${this.wordpressPath}/wp-content/plugins/sqlite-database-integration/wp-includes/sqlite/class-wp-sqlite-translator.php`,e=>e.replace("if ( false === strtotime( $value ) )",'if ( $value === "0000-00-00 00:00:00" || false === strtotime( $value ) )'))}async addPhpInfo(){await this.php.writeFile(`${this.wordpressPath}/phpinfo.php`,"<?php phpinfo(); ")}async patchSiteUrl(){await P(this.php,`${this.wordpressPath}/wp-config.php`,e=>`<?php
20
+ define( 'WP_ADMIN', true );
21
+ require_once( '${r}' );
22
+ switch_theme( '${e}' );
23
+ `})};function b(s){const e=s.split(".").shift().replace(/-/g," ");return e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()}async function P(s,e,t){let r="";await s.fileExists(e)&&(r=await s.readFileAsText(e)),await s.writeFile(e,t(r))}async function xe(s){return new Uint8Array(await s.arrayBuffer())}class Fe extends File{constructor(e,t){super(e,t),this.buffers=e}async arrayBuffer(){return this.buffers[0]}}const T=File.prototype.arrayBuffer instanceof Function?File:Fe,X=async(s,e)=>{const t=new Te(s,e.siteUrl,e.wordpressPath||"/wordpress");e.patchSqlitePlugin!==!1&&await t.patchSqlitePlugin(),e.addPhpInfo!==!1&&await t.addPhpInfo(),e.patchSiteUrl!==!1&&await t.patchSiteUrl(),e.disableSiteHealth!==!1&&await t.disableSiteHealth(),e.disableWpNewBlogNotification!==!1&&await t.disableWpNewBlogNotification()};class Te{constructor(e,t,r){this.php=e,this.scopedSiteUrl=t,this.wordpressPath=r}async patchSqlitePlugin(){await P(this.php,`${this.wordpressPath}/wp-content/plugins/sqlite-database-integration/wp-includes/sqlite/class-wp-sqlite-translator.php`,e=>e.replace("if ( false === strtotime( $value ) )",'if ( $value === "0000-00-00 00:00:00" || false === strtotime( $value ) )'))}async addPhpInfo(){await this.php.writeFile(`${this.wordpressPath}/phpinfo.php`,"<?php phpinfo(); ")}async patchSiteUrl(){await P(this.php,`${this.wordpressPath}/wp-config.php`,e=>`<?php
22
24
  if(!defined('WP_HOME')) {
23
25
  define('WP_HOME', "${this.scopedSiteUrl}");
24
26
  define('WP_SITEURL', "${this.scopedSiteUrl}");
@@ -97,7 +99,7 @@ function delTree($dir)
97
99
  define('WP_HOME', ${n.absoluteUrl});
98
100
  define('WP_SITEURL', ${n.absoluteUrl});
99
101
  }
100
- ?>${o}`)},v=async(s,{zipPath:e,extractToPath:t})=>{const r=A({zipPath:e,extractToPath:t});await fe(s,`unzip(${r.zipPath}, ${r.extractToPath});`)},de=async(s,{file:e})=>{const t=await s.request({url:"/wp-admin/admin.php?import=wordpress"}),r=z(t).getElementById("import-upload-form")?.getAttribute("action"),i=await s.request({url:`/wp-admin/${r}`,method:"POST",files:{import:e}}),n=z(i).querySelector("#wpbody-content form");if(!n)throw console.log(i.text),new Error("Could not find an importer form in response. See the response text above for details.");const o=Ce(n);o.fetch_attachments="1";for(const a in o)if(a.startsWith("user_map[")){const l="user_new["+a.slice(9,-1)+"]";o[l]="1"}await s.request({url:n.action,method:"POST",formData:o})};function z(s){return new DOMParser().parseFromString(s.text,"text/html")}function Ce(s){return Object.fromEntries(new FormData(s).entries())}async function Ae(s,e,t){await s.writeFile(e,t(await s.readFileAsText(e)))}async function fe(s,e){const t=await s.run({code:I+e});if(t.exitCode!==0)throw console.log(I+e),console.log(e+""),console.log(t.errors),t.errors;return t}async function me(s,{targetPath:e,zipFile:t}){const r=t.name,i=r.replace(/\.zip$/,""),n=`/tmp/assets/${i}`,o=`/tmp/${r}`,a=()=>s.rmdir(n,{recursive:!0});await s.fileExists(n)&&await a(),await k(s,{path:o,data:t});const l=()=>Promise.all([a,()=>s.unlink(o)]);try{await v(s,{zipPath:o,extractToPath:n});const c=await s.listFiles(n,{prependPath:!0}),u=c.length===1&&await s.isDir(c[0]);let d,E="";u?(E=c[0],d=c[0].split("/").pop()):(E=n,d=i);const H=`${e}/${d}`;return await s.mv(E,H),await l(),{assetFolderPath:H,assetFolderName:d}}catch(c){throw await l(),c}}const we=async(s,{pluginZipFile:e,options:t={}},r)=>{const i=e.name.split("/").pop()||"plugin.zip",n=b(i);r?.tracker.setCaption(`Installing the ${n} plugin`);try{const{assetFolderPath:o}=await me(s,{zipFile:e,targetPath:`${await s.documentRoot}/wp-content/plugins`});("activate"in t?t.activate:!0)&&await x(s,{pluginPath:o,pluginName:n},r),await Ue(s)}catch(o){console.error(`Proceeding without the ${n} plugin. Could not install it in wp-admin. The original error was: ${o}`),console.error(o)}};async function Ue(s){await s.isDir("/wordpress/wp-content/plugins/gutenberg")&&!await s.fileExists("/wordpress/.gutenberg-patched")&&(await s.writeFile("/wordpress/.gutenberg-patched","1"),await q(s,"/wordpress/wp-content/plugins/gutenberg/build/block-editor/index.js",e=>e.replace(/srcDoc:("[^"]+"|[^,]+)/g,'src:"/wp-includes/empty.html"')),await q(s,"/wordpress/wp-content/plugins/gutenberg/build/block-editor/index.min.js",e=>e.replace(/srcDoc:("[^"]+"|[^,]+)/g,'src:"/wp-includes/empty.html"')))}async function q(s,e,t){return await s.writeFile(e,t(await s.readFileAsText(e)))}const ge=async(s,{themeZipFile:e,options:t={}},r)=>{const i=b(e.name);r?.tracker.setCaption(`Installing the ${i} theme`);try{const{assetFolderName:n}=await me(s,{zipFile:e,targetPath:`${await s.documentRoot}/wp-content/themes`});("activate"in t?t.activate:!0)&&await F(s,{themeFolderName:n},r)}catch(n){console.error(`Proceeding without the ${i} theme. Could not install it in wp-admin. The original error was: ${n}`),console.error(n)}},ye=async(s,{username:e="admin",password:t="password"}={},r)=>{r?.tracker.setCaption(r?.initialCaption||"Logging in"),await s.request({url:"/wp-login.php"}),await s.request({url:"/wp-login.php",method:"POST",formData:{log:e,pwd:t,rememberme:"forever"}})},Pe=async(s,{options:e})=>{await s.request({url:"/wp-admin/install.php?step=2",method:"POST",formData:{language:"en",prefix:"wp_",weblog_title:"My WordPress Website",user_name:e.adminPassword||"admin",admin_password:e.adminPassword||"password",admin_password2:e.adminPassword||"password",Submit:"Install WordPress",pw_weak:"1",admin_email:"admin@localhost.com"}})},_e=async(s,{options:e})=>{const t=`<?php
102
+ ?>${o}`)},v=async(s,{zipPath:e,extractToPath:t})=>{const r=A({zipPath:e,extractToPath:t});await fe(s,`unzip(${r.zipPath}, ${r.extractToPath});`)},de=async(s,{file:e})=>{const t=await s.request({url:"/wp-admin/admin.php?import=wordpress"}),r=z(t).getElementById("import-upload-form")?.getAttribute("action"),i=await s.request({url:`/wp-admin/${r}`,method:"POST",files:{import:e}}),n=z(i).querySelector("#wpbody-content form");if(!n)throw console.log(i.text),new Error("Could not find an importer form in response. See the response text above for details.");const o=Ce(n);o.fetch_attachments="1";for(const a in o)if(a.startsWith("user_map[")){const l="user_new["+a.slice(9,-1)+"]";o[l]="1"}await s.request({url:n.action,method:"POST",formData:o})};function z(s){return new DOMParser().parseFromString(s.text,"text/html")}function Ce(s){return Object.fromEntries(new FormData(s).entries())}async function Ae(s,e,t){await s.writeFile(e,t(await s.readFileAsText(e)))}async function fe(s,e){const t=await s.run({code:I+e});if(t.exitCode!==0)throw console.log(I+e),console.log(e+""),console.log(t.errors),t.errors;return t}async function me(s,{targetPath:e,zipFile:t}){const r=t.name,i=r.replace(/\.zip$/,""),n=`/tmp/assets/${i}`,o=`/tmp/${r}`,a=()=>s.rmdir(n,{recursive:!0});await s.fileExists(n)&&await a(),await k(s,{path:o,data:t});const l=()=>Promise.all([a,()=>s.unlink(o)]);try{await v(s,{zipPath:o,extractToPath:n});const c=await s.listFiles(n,{prependPath:!0}),u=c.length===1&&await s.isDir(c[0]);let d,E="";u?(E=c[0],d=c[0].split("/").pop()):(E=n,d=i);const H=`${e}/${d}`;return await s.mv(E,H),await l(),{assetFolderPath:H,assetFolderName:d}}catch(c){throw await l(),c}}const we=async(s,{pluginZipFile:e,options:t={}},r)=>{const i=e.name.split("/").pop()||"plugin.zip",n=b(i);r?.tracker.setCaption(`Installing the ${n} plugin`);try{const{assetFolderPath:o}=await me(s,{zipFile:e,targetPath:`${await s.documentRoot}/wp-content/plugins`});("activate"in t?t.activate:!0)&&await x(s,{pluginPath:o,pluginName:n},r),await Ue(s)}catch(o){console.error(`Proceeding without the ${n} plugin. Could not install it in wp-admin. The original error was: ${o}`),console.error(o)}};async function Ue(s){await s.isDir("/wordpress/wp-content/plugins/gutenberg")&&!await s.fileExists("/wordpress/.gutenberg-patched")&&(await s.writeFile("/wordpress/.gutenberg-patched","1"),await M(s,"/wordpress/wp-content/plugins/gutenberg/build/block-editor/index.js",e=>e.replace(/srcDoc:("[^"]+"|[^,]+)/g,'src:"/wp-includes/empty.html"')),await M(s,"/wordpress/wp-content/plugins/gutenberg/build/block-editor/index.min.js",e=>e.replace(/srcDoc:("[^"]+"|[^,]+)/g,'src:"/wp-includes/empty.html"')))}async function M(s,e,t){return await s.writeFile(e,t(await s.readFileAsText(e)))}const ge=async(s,{themeZipFile:e,options:t={}},r)=>{const i=b(e.name);r?.tracker.setCaption(`Installing the ${i} theme`);try{const{assetFolderName:n}=await me(s,{zipFile:e,targetPath:`${await s.documentRoot}/wp-content/themes`});("activate"in t?t.activate:!0)&&await F(s,{themeFolderName:n},r)}catch(n){console.error(`Proceeding without the ${i} theme. Could not install it in wp-admin. The original error was: ${n}`),console.error(n)}},ye=async(s,{username:e="admin",password:t="password"}={},r)=>{r?.tracker.setCaption(r?.initialCaption||"Logging in"),await s.request({url:"/wp-login.php"}),await s.request({url:"/wp-login.php",method:"POST",formData:{log:e,pwd:t,rememberme:"forever"}})},Pe=async(s,{options:e})=>{await s.request({url:"/wp-admin/install.php?step=2",method:"POST",formData:{language:"en",prefix:"wp_",weblog_title:"My WordPress Website",user_name:e.adminPassword||"admin",admin_password:e.adminPassword||"password",admin_password2:e.adminPassword||"password",Submit:"Install WordPress",pw_weak:"1",admin_email:"admin@localhost.com"}})},_e=async(s,{options:e})=>{const t=`<?php
101
103
  include 'wordpress/wp-load.php';
102
104
  $site_options = ${$(e)};
103
105
  foreach($site_options as $name => $value) {
@@ -111,13 +113,13 @@ function delTree($dir)
111
113
  update_user_meta(${$(t)}, $name, $value);
112
114
  }
113
115
  echo "Success";
114
- `,i=await s.run({code:r});return be(i),{code:r,result:i}};async function be(s){if(s.text!=="Success")throw console.log(s),new Error(`Failed to run code: ${s.text} ${s.errors}`)}const Oe=Object.freeze(Object.defineProperty({__proto__:null,activatePlugin:x,activateTheme:F,applyWordPressPatches:X,cp:ie,defineSiteUrl:le,defineWpConfigConsts:C,importFile:de,installPlugin:we,installTheme:ge,login:ye,mkdir:oe,mv:ne,replaceSite:pe,request:re,rm:ae,rmdir:ce,runPHP:ee,runPHPWithOptions:te,runWpInstallationWizard:Pe,setPhpIniEntry:se,setSiteOptions:_e,unzip:v,updateUserMeta:$e,writeFile:k,zipEntireSite:ue},Symbol.toStringTag,{value:"Module"})),Ne=5*1024*1024;function Le(s,e){const t=s.headers.get("content-length")||"",r=parseInt(t,10)||Ne;function i(n,o){e(new CustomEvent("progress",{detail:{loaded:n,total:o}}))}return new Response(new ReadableStream({async start(n){if(!s.body){n.close();return}const o=s.body.getReader();let a=0;for(;;)try{const{done:l,value:c}=await o.read();if(c&&(a+=c.byteLength),l){i(a,a),n.close();break}else i(a,r),n.enqueue(c)}catch(l){console.error({e:l}),n.error(l);break}}}),{status:s.status,statusText:s.statusText,headers:s.headers})}const S=1e-5;class U extends EventTarget{constructor({weight:e=1,caption:t="",fillTime:r=4}={}){super(),this._selfWeight=1,this._selfDone=!1,this._selfProgress=0,this._selfCaption="",this._isFilling=!1,this._subTrackers=[],this._weight=e,this._selfCaption=t,this._fillTime=r}stage(e,t=""){if(e||(e=this._selfWeight),this._selfWeight-e<-S)throw new Error(`Cannot add a stage with weight ${e} as the total weight of registered stages would exceed 1.`);this._selfWeight-=e;const r=new U({caption:t,weight:e,fillTime:this._fillTime});return this._subTrackers.push(r),r.addEventListener("progress",()=>this.notifyProgress()),r.addEventListener("done",()=>{this.done&&this.notifyDone()}),r}fillSlowly({stopBeforeFinishing:e=!0}={}){if(this._isFilling)return;this._isFilling=!0;const t=100,r=this._fillTime/t;this._fillInterval=setInterval(()=>{this.set(this._selfProgress+1),e&&this._selfProgress>=99&&clearInterval(this._fillInterval)},r)}set(e){this._selfProgress=Math.min(e,100),this.notifyProgress(),this._selfProgress+S>=100&&this.finish()}finish(){this._fillInterval&&clearInterval(this._fillInterval),this._selfDone=!0,this._selfProgress=100,this._isFilling=!1,this._fillInterval=void 0,this.notifyProgress(),this.notifyDone()}get caption(){for(let e=this._subTrackers.length-1;e>=0;e--)if(!this._subTrackers[e].done){const t=this._subTrackers[e].caption;if(t)return t}return this._selfCaption}setCaption(e){this._selfCaption=e,this.notifyProgress()}get done(){return this.progress+S>=100}get progress(){if(this._selfDone)return 100;const e=this._subTrackers.reduce((t,r)=>t+r.progress*r.weight,this._selfProgress*this._selfWeight);return Math.round(e*1e4)/1e4}get weight(){return this._weight}get observer(){return this._progressObserver||(this._progressObserver=e=>{this.set(e)}),this._progressObserver}get loadingListener(){return this._loadingListener||(this._loadingListener=e=>{this.set(e.detail.loaded/e.detail.total*100)}),this._loadingListener}pipe(e){e.setProgress({progress:this.progress,caption:this.caption}),this.addEventListener("progress",t=>{e.setProgress({progress:t.detail.progress,caption:t.detail.caption})}),this.addEventListener("done",()=>{e.setLoaded()})}addEventListener(e,t){super.addEventListener(e,t)}removeEventListener(e,t){super.removeEventListener(e,t)}notifyProgress(){const e=this;this.dispatchEvent(new CustomEvent("progress",{detail:{get progress(){return e.progress},get caption(){return e.caption}}}))}notifyDone(){this.dispatchEvent(new CustomEvent("done"))}}const M=Symbol("error"),D=Symbol("message");class O extends Event{constructor(e,t={}){super(e),this[M]=t.error===void 0?null:t.error,this[D]=t.message===void 0?"":t.message}get error(){return this[M]}get message(){return this[D]}}Object.defineProperty(O.prototype,"error",{enumerable:!0});Object.defineProperty(O.prototype,"message",{enumerable:!0});const He=typeof globalThis.ErrorEvent=="function"?globalThis.ErrorEvent:O;class We extends EventTarget{constructor(){super(...arguments),this.listenersCount=0}addEventListener(e,t){++this.listenersCount,super.addEventListener(e,t)}removeEventListener(e,t){--this.listenersCount,super.removeEventListener(e,t)}hasListeners(){return this.listenersCount>0}}function Ie(s){s.asm={...s.asm};const e=new We;for(const t in s.asm)if(typeof s.asm[t]=="function"){const r=s.asm[t];s.asm[t]=function(...i){try{return r(...i)}catch(n){if(!(n instanceof Error))throw n;if("exitCode"in n&&n?.exitCode===0)return;const o=qe(n,s.lastAsyncifyStackSource?.stack);if(s.lastAsyncifyStackSource&&(n.cause=s.lastAsyncifyStackSource),!e.hasListeners())throw Be(o),n;e.dispatchEvent(new He("error",{error:n,message:o}))}}}return e}let R=[];function ze(){return R}function qe(s,e){if(s.message==="unreachable"){let t=Me;e||(t+=`
116
+ `,i=await s.run({code:r});return be(i),{code:r,result:i}};async function be(s){if(s.text!=="Success")throw console.log(s),new Error(`Failed to run code: ${s.text} ${s.errors}`)}const Oe=Object.freeze(Object.defineProperty({__proto__:null,activatePlugin:x,activateTheme:F,applyWordPressPatches:X,cp:ie,defineSiteUrl:le,defineWpConfigConsts:C,importFile:de,installPlugin:we,installTheme:ge,login:ye,mkdir:oe,mv:ne,replaceSite:pe,request:re,rm:ae,rmdir:ce,runPHP:ee,runPHPWithOptions:te,runWpInstallationWizard:Pe,setPhpIniEntry:se,setSiteOptions:_e,unzip:v,updateUserMeta:$e,writeFile:k,zipEntireSite:ue},Symbol.toStringTag,{value:"Module"})),Ne=5*1024*1024;function Le(s,e){const t=s.headers.get("content-length")||"",r=parseInt(t,10)||Ne;function i(n,o){e(new CustomEvent("progress",{detail:{loaded:n,total:o}}))}return new Response(new ReadableStream({async start(n){if(!s.body){n.close();return}const o=s.body.getReader();let a=0;for(;;)try{const{done:l,value:c}=await o.read();if(c&&(a+=c.byteLength),l){i(a,a),n.close();break}else i(a,r),n.enqueue(c)}catch(l){console.error({e:l}),n.error(l);break}}}),{status:s.status,statusText:s.statusText,headers:s.headers})}const S=1e-5;class U extends EventTarget{constructor({weight:e=1,caption:t="",fillTime:r=4}={}){super(),this._selfWeight=1,this._selfDone=!1,this._selfProgress=0,this._selfCaption="",this._isFilling=!1,this._subTrackers=[],this._weight=e,this._selfCaption=t,this._fillTime=r}stage(e,t=""){if(e||(e=this._selfWeight),this._selfWeight-e<-S)throw new Error(`Cannot add a stage with weight ${e} as the total weight of registered stages would exceed 1.`);this._selfWeight-=e;const r=new U({caption:t,weight:e,fillTime:this._fillTime});return this._subTrackers.push(r),r.addEventListener("progress",()=>this.notifyProgress()),r.addEventListener("done",()=>{this.done&&this.notifyDone()}),r}fillSlowly({stopBeforeFinishing:e=!0}={}){if(this._isFilling)return;this._isFilling=!0;const t=100,r=this._fillTime/t;this._fillInterval=setInterval(()=>{this.set(this._selfProgress+1),e&&this._selfProgress>=99&&clearInterval(this._fillInterval)},r)}set(e){this._selfProgress=Math.min(e,100),this.notifyProgress(),this._selfProgress+S>=100&&this.finish()}finish(){this._fillInterval&&clearInterval(this._fillInterval),this._selfDone=!0,this._selfProgress=100,this._isFilling=!1,this._fillInterval=void 0,this.notifyProgress(),this.notifyDone()}get caption(){for(let e=this._subTrackers.length-1;e>=0;e--)if(!this._subTrackers[e].done){const t=this._subTrackers[e].caption;if(t)return t}return this._selfCaption}setCaption(e){this._selfCaption=e,this.notifyProgress()}get done(){return this.progress+S>=100}get progress(){if(this._selfDone)return 100;const e=this._subTrackers.reduce((t,r)=>t+r.progress*r.weight,this._selfProgress*this._selfWeight);return Math.round(e*1e4)/1e4}get weight(){return this._weight}get observer(){return this._progressObserver||(this._progressObserver=e=>{this.set(e)}),this._progressObserver}get loadingListener(){return this._loadingListener||(this._loadingListener=e=>{this.set(e.detail.loaded/e.detail.total*100)}),this._loadingListener}pipe(e){e.setProgress({progress:this.progress,caption:this.caption}),this.addEventListener("progress",t=>{e.setProgress({progress:t.detail.progress,caption:t.detail.caption})}),this.addEventListener("done",()=>{e.setLoaded()})}addEventListener(e,t){super.addEventListener(e,t)}removeEventListener(e,t){super.removeEventListener(e,t)}notifyProgress(){const e=this;this.dispatchEvent(new CustomEvent("progress",{detail:{get progress(){return e.progress},get caption(){return e.caption}}}))}notifyDone(){this.dispatchEvent(new CustomEvent("done"))}}const q=Symbol("error"),D=Symbol("message");class O extends Event{constructor(e,t={}){super(e),this[q]=t.error===void 0?null:t.error,this[D]=t.message===void 0?"":t.message}get error(){return this[q]}get message(){return this[D]}}Object.defineProperty(O.prototype,"error",{enumerable:!0});Object.defineProperty(O.prototype,"message",{enumerable:!0});const He=typeof globalThis.ErrorEvent=="function"?globalThis.ErrorEvent:O;class We extends EventTarget{constructor(){super(...arguments),this.listenersCount=0}addEventListener(e,t){++this.listenersCount,super.addEventListener(e,t)}removeEventListener(e,t){--this.listenersCount,super.removeEventListener(e,t)}hasListeners(){return this.listenersCount>0}}function Ie(s){s.asm={...s.asm};const e=new We;for(const t in s.asm)if(typeof s.asm[t]=="function"){const r=s.asm[t];s.asm[t]=function(...i){try{return r(...i)}catch(n){if(!(n instanceof Error))throw n;if("exitCode"in n&&n?.exitCode===0)return;const o=Me(n,s.lastAsyncifyStackSource?.stack);if(s.lastAsyncifyStackSource&&(n.cause=s.lastAsyncifyStackSource),!e.hasListeners())throw Be(o),n;e.dispatchEvent(new He("error",{error:n,message:o}))}}}return e}let R=[];function ze(){return R}function Me(s,e){if(s.message==="unreachable"){let t=qe;e||(t+=`
115
117
 
116
118
  This stack trace is lacking. For a better one initialize
117
119
  the PHP runtime with { debug: true }, e.g. PHPNode.load('8.1', { debug: true }).
118
120
 
119
121
  `),R=je(e||s.stack||"");for(const r of R)t+=` * ${r}
120
- `;return t}return s.message}const Me=`
122
+ `;return t}return s.message}const qe=`
121
123
  "unreachable" WASM instruction executed.
122
124
 
123
125
  The typical reason is a PHP function missing from the ASYNCIFY_ONLY
package/index.js CHANGED
@@ -12,6 +12,7 @@ const J = async (s, { pluginPath: e, pluginName: t }, r) => {
12
12
  );
13
13
  if ((await s.run({
14
14
  code: `<?php
15
+ define( 'WP_ADMIN', true );
15
16
  ${i.map((a) => `require_once( '${a}' );`).join(`
16
17
  `)}
17
18
  $plugin_path = '${e}';
@@ -40,9 +41,10 @@ echo 'NO_ENTRY_FILE';
40
41
  );
41
42
  await s.run({
42
43
  code: `<?php
43
- require_once( '${r}' );
44
- switch_theme( '${e}' );
45
- `
44
+ define( 'WP_ADMIN', true );
45
+ require_once( '${r}' );
46
+ switch_theme( '${e}' );
47
+ `
46
48
  });
47
49
  };
48
50
  function b(s) {
@@ -140,9 +142,9 @@ const ue = async (s, { code: e }) => await s.run({ code: e }), pe = async (s, {
140
142
  await s.rmdir(e);
141
143
  }, Z = async (s, { path: e, data: t }) => {
142
144
  t instanceof File && (t = await ae(t)), await s.writeFile(e, t);
143
- }, O = "/vfs-blueprints", Q = async (s, { consts: e, virtualize: t = !1 }) => {
144
- const r = await s.documentRoot, i = t ? O : r, n = `${i}/playground-consts.json`, o = `${i}/wp-config.php`;
145
- return t && (s.mkdir(O), s.setPhpIniEntry("auto_prepend_file", o)), await P(
145
+ }, N = "/vfs-blueprints", Q = async (s, { consts: e, virtualize: t = !1 }) => {
146
+ const r = await s.documentRoot, i = t ? N : r, n = `${i}/playground-consts.json`, o = `${i}/wp-config.php`;
147
+ return t && (s.mkdir(N), s.setPhpIniEntry("auto_prepend_file", o)), await P(
146
148
  s,
147
149
  n,
148
150
  (a) => JSON.stringify({
@@ -210,7 +212,7 @@ function x(s) {
210
212
  e[t] = $(s[t]);
211
213
  return e;
212
214
  }
213
- const N = `<?php
215
+ const O = `<?php
214
216
 
215
217
  function zipDir($dir, $output, $additionalFiles = array())
216
218
  {
@@ -354,10 +356,10 @@ async function Re(s, e, t) {
354
356
  }
355
357
  async function ee(s, e) {
356
358
  const t = await s.run({
357
- code: N + e
359
+ code: O + e
358
360
  });
359
361
  if (t.exitCode !== 0)
360
- throw console.log(N + e), console.log(e + ""), console.log(t.errors), t.errors;
362
+ throw console.log(O + e), console.log(e + ""), console.log(t.errors), t.errors;
361
363
  return t;
362
364
  }
363
365
  async function te(s, { targetPath: e, zipFile: t }) {
@@ -511,7 +513,7 @@ async function se(s) {
511
513
  if (s.text !== "Success")
512
514
  throw console.log(s), new Error(`Failed to run code: ${s.text} ${s.errors}`);
513
515
  }
514
- const Oe = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
516
+ const Ne = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
515
517
  __proto__: null,
516
518
  activatePlugin: J,
517
519
  activateTheme: K,
@@ -538,9 +540,9 @@ const Oe = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
538
540
  updateUserMeta: Ue,
539
541
  writeFile: Z,
540
542
  zipEntireSite: be
541
- }, Symbol.toStringTag, { value: "Module" })), Ne = 5 * 1024 * 1024;
543
+ }, Symbol.toStringTag, { value: "Module" })), Oe = 5 * 1024 * 1024;
542
544
  function Le(s, e) {
543
- const t = s.headers.get("content-length") || "", r = parseInt(t, 10) || Ne;
545
+ const t = s.headers.get("content-length") || "", r = parseInt(t, 10) || Oe;
544
546
  function i(n, o) {
545
547
  e(
546
548
  new CustomEvent("progress", {
@@ -800,7 +802,7 @@ function We(s) {
800
802
  throw n;
801
803
  if ("exitCode" in n && n?.exitCode === 0)
802
804
  return;
803
- const o = ze(
805
+ const o = qe(
804
806
  n,
805
807
  s.lastAsyncifyStackSource?.stack
806
808
  );
@@ -818,12 +820,12 @@ function We(s) {
818
820
  return e;
819
821
  }
820
822
  let S = [];
821
- function qe() {
823
+ function De() {
822
824
  return S;
823
825
  }
824
- function ze(s, e) {
826
+ function qe(s, e) {
825
827
  if (s.message === "unreachable") {
826
- let t = De;
828
+ let t = ze;
827
829
  e || (t += `
828
830
 
829
831
  This stack trace is lacking. For a better one initialize
@@ -839,7 +841,7 @@ the PHP runtime with { debug: true }, e.g. PHPNode.load('8.1', { debug: true }).
839
841
  }
840
842
  return s.message;
841
843
  }
842
- const De = `
844
+ const ze = `
843
845
  "unreachable" WASM instruction executed.
844
846
 
845
847
  The typical reason is a PHP function missing from the ASYNCIFY_ONLY
@@ -863,17 +865,17 @@ the Dockerfile, you'll need to trigger this error again with long stack
863
865
  traces enabled. In node.js, you can do it using the --stack-trace-limit=100
864
866
  CLI option:
865
867
 
866
- `, q = "\x1B[41m", Me = "\x1B[1m", z = "\x1B[0m", D = "\x1B[K";
868
+ `, D = "\x1B[41m", Me = "\x1B[1m", q = "\x1B[0m", z = "\x1B[K";
867
869
  let M = !1;
868
870
  function Be(s) {
869
871
  if (!M) {
870
- M = !0, console.log(`${q}
871
- ${D}
872
- ${Me} WASM ERROR${z}${q}`);
872
+ M = !0, console.log(`${D}
873
+ ${z}
874
+ ${Me} WASM ERROR${q}${D}`);
873
875
  for (const e of s.split(`
874
876
  `))
875
- console.log(`${D} ${e} `);
876
- console.log(`${z}`);
877
+ console.log(`${z} ${e} `);
878
+ console.log(`${q}`);
877
879
  }
878
880
  }
879
881
  function je(s) {
@@ -1649,7 +1651,7 @@ class w {
1649
1651
  "PHP runtime has crashed – see the earlier error for details."
1650
1652
  );
1651
1653
  });
1652
- this.functionsMaybeMissingFromAsyncify = qe();
1654
+ this.functionsMaybeMissingFromAsyncify = De();
1653
1655
  const o = n, a = "betterMessage" in o ? o.betterMessage : o.message, l = new Error(a);
1654
1656
  throw l.cause = o, l;
1655
1657
  } finally {
@@ -2058,7 +2060,7 @@ function mt(s, {
2058
2060
  }
2059
2061
  const o = async (u) => {
2060
2062
  try {
2061
- return i.fillSlowly(), await Oe[s.step](
2063
+ return i.fillSlowly(), await Ne[s.step](
2062
2064
  u,
2063
2065
  await wt(n),
2064
2066
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wp-playground/blueprints",
3
- "version": "0.1.58",
3
+ "version": "0.1.60",
4
4
  "exports": {
5
5
  ".": {
6
6
  "import": "./index.js",
@@ -21,5 +21,5 @@
21
21
  "access": "public",
22
22
  "directory": "../../../dist/packages/playground/blueprints"
23
23
  },
24
- "gitHead": "dbc77ed4c0b0a2625cfbe08722fade036c69a425"
24
+ "gitHead": "3046803036b19d2c73c63cb01dfb37b1c222d847"
25
25
  }