@wp-playground/wordpress
Advanced tools
Comparing version 0.9.1 to 0.9.4
@@ -81,3 +81,3 @@ const SleepFinished=Symbol("SleepFinished");function sleep(e){return new Promise(t=>{setTimeout(()=>t(SleepFinished),e)})}class AcquireTimeoutError extends Error{constructor(){super("Acquiring lock timed out")}}class Semaphore{constructor({concurrency:t,timeout:s}){this._running=0,this.concurrency=t,this.timeout=s,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(s=>{this.queue.push(s)});this.timeout!==void 0?await Promise.race([t,sleep(this.timeout)]).then(s=>{if(s===SleepFinished)throw new AcquireTimeoutError}):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 s=await this.acquire();try{return await t()}finally{s()}}}function joinPaths(...e){let t=e.join("/");const s=t[0]==="/",r=t.substring(t.length-1)==="/";return t=normalizePath(t),!t&&!s&&(t="."),t&&r&&(t+="/"),t}function dirname(e){if(e==="/")return"/";e=normalizePath(e);const t=e.lastIndexOf("/");return t===-1?"":t===0?"/":e.substr(0,t)}function normalizePath(e){const t=e[0]==="/";return e=normalizePathsArray(e.split("/").filter(s=>!!s),!t).join("/"),(t?"/":"")+e.replace(/\/$/,"")}function normalizePathsArray(e,t){let s=0;for(let r=e.length-1;r>=0;r--){const n=e[r];n==="."?e.splice(r,1):n===".."?(e.splice(r,1),s++):s&&(e.splice(r,1),s--)}if(t)for(;s;s--)e.unshift("..");return e}function splitShellCommand(e){let r=0,n="";const i=[];let o="";for(let a=0;a<e.length;a++){const c=e[a];c==="\\"?((e[a+1]==='"'||e[a+1]==="'")&&a++,o+=e[a]):r===0?c==='"'||c==="'"?(r=1,n=c):c.match(/\s/)?(o.trim().length&&i.push(o.trim()),o=c):i.length&&!o?o=i.pop()+c:o+=c:r===1&&(c===n?(r=0,n=""):o+=c)}return o&&i.push(o.trim()),i}function createSpawnHandler(e){return function(t,s=[],r={}){const n=new ChildProcess,i=new ProcessApi(n);return setTimeout(async()=>{let o=[];if(s.length)o=[t,...s];else if(typeof t=="string")o=splitShellCommand(t);else if(Array.isArray(t))o=t;else throw new Error("Invalid command ",t);try{await e(o,i,r)}catch(a){n.emit("error",a),typeof a=="object"&&a!==null&&"message"in a&&typeof a.message=="string"&&i.stderr(a.message),i.exit(1)}n.emit("spawn",!0)}),n}}class EventEmitter{constructor(){this.listeners={}}emit(t,s){this.listeners[t]&&this.listeners[t].forEach(function(r){r(s)})}on(t,s){this.listeners[t]||(this.listeners[t]=[]),this.listeners[t].push(s)}}class ProcessApi extends EventEmitter{constructor(t){super(),this.childProcess=t,this.exited=!1,this.stdinData=[],t.on("stdin",s=>{this.stdinData?this.stdinData.push(s.slice()):this.emit("stdin",s)})}stdout(t){typeof t=="string"&&(t=new TextEncoder().encode(t)),this.childProcess.stdout.emit("data",t)}stdoutEnd(){this.childProcess.stdout.emit("end",{})}stderr(t){typeof t=="string"&&(t=new TextEncoder().encode(t)),this.childProcess.stderr.emit("data",t)}stderrEnd(){this.childProcess.stderr.emit("end",{})}exit(t){this.exited||(this.exited=!0,this.childProcess.emit("exit",t))}flushStdin(){if(this.stdinData)for(let t=0;t<this.stdinData.length;t++)this.emit("stdin",this.stdinData[t]);this.stdinData=null}}let lastPid=9743;class ChildProcess extends EventEmitter{constructor(t=lastPid++){super(),this.pid=t,this.stdout=new EventEmitter,this.stderr=new EventEmitter;const s=this;this.stdin={write:r=>{s.emit("stdin",r)}}}}function phpVar(e){return`json_decode(base64_decode('${stringToBase64(JSON.stringify(e))}'), true)`}function phpVars(e){const t={};for(const s in e)t[s]=phpVar(e[s]);return t}function stringToBase64(e){return bytesToBase64(new TextEncoder().encode(e))}function bytesToBase64(e){const t=String.fromCodePoint(...e);return btoa(t)}const tmpPath="/tmp/file.zip",unzipFile=async(e,t,s)=>{if(t instanceof File){const n=t;t=tmpPath,await e.writeFile(t,new Uint8Array(await n.arrayBuffer()))}const r=phpVars({zipPath:t,extractToPath:s});await e.run({code:`<?php | ||
echo is_blog_installed() ? '1' : '0'; | ||
`})).text==="1"}async function installWordPress(e){await withPHPIniValues(e,{disable_functions:"fsockopen",allow_url_fopen:"0"},async()=>await e.request({url:"/wp-admin/install.php?step=2",method:"POST",body:{language:"en",prefix:"wp_",weblog_title:"My WordPress Website",user_name:"admin",admin_password:"password",admin_password2:"password",Submit:"Install WordPress",pw_weak:"1",admin_email:"admin@localhost.com"}}))}const nightly="nightly",beta="6.6-RC1",SupportedWordPressVersions={nightly,beta,"6.5":"6.5.5","6.4":"6.4.5","6.3":"6.3.5","6.2":"6.2.6"},SupportedWordPressVersionsList=Object.keys(SupportedWordPressVersions);SupportedWordPressVersionsList.filter(e=>e.match(/^\d/))[0];async function getLoadedWordPressVersion(e){const r=(await(await e.getPrimaryPhp()).run({code:`<?php | ||
`})).text==="1"}async function installWordPress(e){await withPHPIniValues(e,{disable_functions:"fsockopen",allow_url_fopen:"0"},async()=>await e.request({url:"/wp-admin/install.php?step=2",method:"POST",body:{language:"en",prefix:"wp_",weblog_title:"My WordPress Website",user_name:"admin",admin_password:"password",admin_password2:"password",Submit:"Install WordPress",pw_weak:"1",admin_email:"admin@localhost.com"}}))}const nightly="nightly",beta="6.6-RC2",SupportedWordPressVersions={nightly,beta,"6.5":"6.5.5","6.4":"6.4.5","6.3":"6.3.5","6.2":"6.2.6"},SupportedWordPressVersionsList=Object.keys(SupportedWordPressVersions);SupportedWordPressVersionsList.filter(e=>e.match(/^\d/))[0];async function getLoadedWordPressVersion(e){const r=(await(await e.getPrimaryPhp()).run({code:`<?php | ||
require '${e.documentRoot}/wp-includes/version.php'; | ||
@@ -84,0 +84,0 @@ echo $wp_version; |
{ | ||
"name": "@wp-playground/wordpress", | ||
"version": "0.9.1", | ||
"version": "0.9.4", | ||
"description": "WordPress-related plumbing for WordPress Playground", | ||
@@ -30,3 +30,3 @@ "repository": { | ||
}, | ||
"gitHead": "1097764159c71f5fd9f215f46385d1c83428fe01" | ||
"gitHead": "702bb9bed9c153ea23651059592aea19c1ba9be4" | ||
} |
26816214