@wp-playground/wordpress 0.9.1 → 0.9.10
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.
|
Binary file
|
|
Binary file
|
package/index.js
CHANGED
|
@@ -78,7 +78,7 @@ ${bold} WASM ERROR${reset}${redBg}`);for(const t of e.split(`
|
|
|
78
78
|
`);const i=n.reduce((c,l)=>c+l.length,0),o=new Uint8Array(i);let a=0;for(const c of n)o.set(typeof c=="string"?r.encode(c):c,a),a+=c.length;return{bytes:o,contentType:s}}function fileToUint8Array(e){return new Promise(t=>{const s=new FileReader;s.onload=()=>{t(new Uint8Array(s.result))},s.readAsArrayBuffer(e)})}const _default="application/octet-stream",asx="video/x-ms-asf",atom="application/atom+xml",avi="video/x-msvideo",avif="image/avif",bin="application/octet-stream",bmp="image/x-ms-bmp",cco="application/x-cocoa",css="text/css",data="application/octet-stream",deb="application/octet-stream",der="application/x-x509-ca-cert",dmg="application/octet-stream",doc="application/msword",docx="application/vnd.openxmlformats-officedocument.wordprocessingml.document",eot="application/vnd.ms-fontobject",flv="video/x-flv",gif="image/gif",gz="application/gzip",hqx="application/mac-binhex40",htc="text/x-component",html="text/html",ico="image/x-icon",iso="application/octet-stream",jad="text/vnd.sun.j2me.app-descriptor",jar="application/java-archive",jardiff="application/x-java-archive-diff",jng="image/x-jng",jnlp="application/x-java-jnlp-file",jpg="image/jpeg",jpeg="image/jpeg",js="application/javascript",json="application/json",kml="application/vnd.google-earth.kml+xml",kmz="application/vnd.google-earth.kmz",m3u8="application/vnd.apple.mpegurl",m4a="audio/x-m4a",m4v="video/x-m4v",md="text/plain",mid="audio/midi",mml="text/mathml",mng="video/x-mng",mov="video/quicktime",mp3="audio/mpeg",mp4="video/mp4",mpeg="video/mpeg",msi="application/octet-stream",odg="application/vnd.oasis.opendocument.graphics",odp="application/vnd.oasis.opendocument.presentation",ods="application/vnd.oasis.opendocument.spreadsheet",odt="application/vnd.oasis.opendocument.text",ogg="audio/ogg",otf="font/otf",pdf="application/pdf",pl="application/x-perl",png="image/png",ppt="application/vnd.ms-powerpoint",pptx="application/vnd.openxmlformats-officedocument.presentationml.presentation",prc="application/x-pilot",ps="application/postscript",ra="audio/x-realaudio",rar="application/x-rar-compressed",rpm="application/x-redhat-package-manager",rss="application/rss+xml",rtf="application/rtf",run="application/x-makeself",sea="application/x-sea",sit="application/x-stuffit",svg="image/svg+xml",swf="application/x-shockwave-flash",tcl="application/x-tcl",tar="application/x-tar",tif="image/tiff",ts="video/mp2t",ttf="font/ttf",txt="text/plain",wasm="application/wasm",wbmp="image/vnd.wap.wbmp",webm="video/webm",webp="image/webp",wml="text/vnd.wap.wml",wmlc="application/vnd.wap.wmlc",wmv="video/x-ms-wmv",woff="font/woff",woff2="font/woff2",xhtml="application/xhtml+xml",xls="application/vnd.ms-excel",xlsx="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",xml="text/xml",xpi="application/x-xpinstall",xspf="application/xspf+xml",zip="application/zip",mimeTypes={_default,"3gpp":"video/3gpp","7z":"application/x-7z-compressed",asx,atom,avi,avif,bin,bmp,cco,css,data,deb,der,dmg,doc,docx,eot,flv,gif,gz,hqx,htc,html,ico,iso,jad,jar,jardiff,jng,jnlp,jpg,jpeg,js,json,kml,kmz,m3u8,m4a,m4v,md,mid,mml,mng,mov,mp3,mp4,mpeg,msi,odg,odp,ods,odt,ogg,otf,pdf,pl,png,ppt,pptx,prc,ps,ra,rar,rpm,rss,rtf,run,sea,sit,svg,swf,tcl,tar,tif,ts,ttf,txt,wasm,wbmp,webm,webp,wml,wmlc,wmv,woff,woff2,xhtml,xls,xlsx,xml,xpi,xspf,zip};class PHPRequestHandler{#e;#r;#a;#s;#n;#t;#i;#o;constructor(t){const{documentRoot:s="/www/",absoluteUrl:r=typeof location=="object"?location?.href:"",rewriteRules:n=[]}=t;"processManager"in t?this.processManager=t.processManager:this.processManager=new PHPProcessManager({phpFactory:async a=>{const c=await t.phpFactory({...a,requestHandler:this});return c.requestHandler=this,c},maxPhpInstances:t.maxPhpInstances}),this.#o=new HttpCookieStore,this.#e=s;const i=new URL(r);this.#a=i.hostname,this.#s=i.port?Number(i.port):i.protocol==="https:"?443:80,this.#r=(i.protocol||"").replace(":","");const o=this.#s!==443&&this.#s!==80;this.#n=[this.#a,o?`:${this.#s}`:""].join(""),this.#t=i.pathname.replace(/\/+$/,""),this.#i=[`${this.#r}://`,this.#n,this.#t].join(""),this.rewriteRules=n}async getPrimaryPhp(){return await this.processManager.getPrimaryPhp()}pathToInternalUrl(t){return`${this.absoluteUrl}${t}`}internalUrlToPath(t){const s=new URL(t);return s.pathname.startsWith(this.#t)&&(s.pathname=s.pathname.slice(this.#t.length)),toRelativeUrl(s)}get absoluteUrl(){return this.#i}get documentRoot(){return this.#e}async request(t){const s=t.url.startsWith("http://")||t.url.startsWith("https://"),r=new URL(t.url.split("#")[0],s?void 0:DEFAULT_BASE_URL),n=applyRewriteRules(removePathPrefix(decodeURIComponent(r.pathname),this.#t),this.rewriteRules),i=joinPaths(this.#e,n);return seemsLikeAPHPRequestHandlerPath(i)?this.#c(t,r):this.#l(await this.processManager.getPrimaryPhp(),i)}#l(t,s){if(!t.fileExists(s))return new PHPResponse(404,{"x-file-type":["static"]},new TextEncoder().encode("404 File not found"));const r=t.readFileAsBuffer(s);return new PHPResponse(200,{"content-length":[`${r.byteLength}`],"content-type":[inferMimeType(s)],"accept-ranges":["bytes"],"cache-control":["public, max-age=0"]},r)}async#c(t,s){let r;try{r=await this.processManager.acquirePHPInstance()}catch(n){return n instanceof MaxPhpInstancesError?PHPResponse.forHttpCode(502):PHPResponse.forHttpCode(500)}try{return await this.#d(r.php,t,s)}finally{r.reap()}}async#d(t,s,r){let n="GET";const i={host:this.#n,...normalizeHeaders(s.headers||{}),cookie:this.#o.getCookieRequestHeader()};let o=s.body;if(typeof o=="object"&&!(o instanceof Uint8Array)){n="POST";const{bytes:c,contentType:l}=await encodeAsMultipart(o);o=c,i["content-type"]=l}let a;try{a=this.#p(t,decodeURIComponent(r.pathname))}catch{return PHPResponse.forHttpCode(404)}try{const c=await t.run({relativeUri:ensurePathPrefix(toRelativeUrl(r),this.#t),protocol:this.#r,method:s.method||n,$_SERVER:{REMOTE_ADDR:"127.0.0.1",DOCUMENT_ROOT:this.#e,HTTPS:this.#i.startsWith("https://")?"on":""},body:o,scriptPath:a,headers:i});return this.#o.rememberCookiesFromResponseHeaders(c.headers),c}catch(c){const l=c;if(l?.response)return l.response;throw c}}#p(t,s){let r=removePathPrefix(s,this.#t);r=applyRewriteRules(r,this.rewriteRules),r.includes(".php")?r=r.split(".php")[0]+".php":t.isDir(`${this.#e}${r}`)?(r.endsWith("/")||(r=`${r}/`),r=`${r}index.php`):r="/index.php";let n=`${this.#e}${r}`;if(t.fileExists(n)||(n=`${this.#e}/index.php`),t.fileExists(n))return n;throw new Error(`File not found: ${n}`)}}function inferMimeType(e){const t=e.split(".").pop();return mimeTypes[t]||mimeTypes._default}function seemsLikeAPHPRequestHandlerPath(e){return seemsLikeAPHPFile(e)||seemsLikeADirectoryRoot(e)}function seemsLikeAPHPFile(e){return e.endsWith(".php")||e.includes(".php/")}function seemsLikeADirectoryRoot(e){return!e.split("/").pop().includes(".")}function applyRewriteRules(e,t){for(const s of t)if(new RegExp(s.match).test(e))return e.replace(s.match,s.replacement);return e}function rotatePHPRuntime({php:e,cwd:t,recreateRuntime:s,maxRequests:r=400}){let n=0;async function i(){if(++n<r)return;n=0;const o=await e.semaphore.acquire();try{e.hotSwapPHPRuntime(await s(),t)}finally{o()}}return e.addEventListener("request.end",i),function(){e.removeEventListener("request.end",i)}}async function writeFiles(e,t,s,{rmRoot:r=!1}={}){r&&await e.isDir(t)&&await e.rmdir(t,{recursive:!0});for(const[n,i]of Object.entries(s)){const o=joinPaths(t,n);await e.fileExists(dirname(o))||await e.mkdir(dirname(o)),i instanceof Uint8Array||typeof i=="string"?await e.writeFile(o,i):await writeFiles(e,o,i)}}function proxyFileSystem(e,t,s){const r=Object.getOwnPropertySymbols(e)[0];for(const n of s)t.fileExists(n)||t.mkdir(n),e.fileExists(n)||e.mkdir(n),t[r].FS.mount(t[r].PROXYFS,{root:n,fs:e[r].FS},n)}async function bootWordPress(e){async function t(n,i){const o=new PHP(await e.createPhpRuntime());return e.sapiName&&o.setSapiName(e.sapiName),n&&(o.requestHandler=n),e.phpIniEntries&&setPhpIniEntries(o,e.phpIniEntries),i?(await setupPlatformLevelMuPlugins(o),await writeFiles(o,"/",e.createFiles||{}),await preloadPhpInfoRoute(o,joinPaths(new URL(e.siteUrl).pathname,"phpinfo.php"))):proxyFileSystem(await n.getPrimaryPhp(),o,["/tmp",n.documentRoot,"/internal/shared"]),e.spawnHandler&&await o.setSpawnHandler(e.spawnHandler(n.processManager)),rotatePHPRuntime({php:o,cwd:n.documentRoot,recreateRuntime:e.createPhpRuntime,maxRequests:400}),o}const s=new PHPRequestHandler({phpFactory:async({isPrimary:n})=>t(s,n),documentRoot:e.documentRoot||"/wordpress",absoluteUrl:e.siteUrl,rewriteRules:wordPressRewriteRules}),r=await s.getPrimaryPhp();if(e.hooks?.beforeWordPressFiles&&await e.hooks.beforeWordPressFiles(r),e.wordPressZip&&await unzipWordPress(r,await e.wordPressZip),e.constants)for(const n in e.constants)r.defineConstant(n,e.constants[n]);if(r.defineConstant("WP_HOME",e.siteUrl),r.defineConstant("WP_SITEURL",e.siteUrl),e.hooks?.beforeDatabaseSetup&&await e.hooks.beforeDatabaseSetup(r),e.sqliteIntegrationPluginZip&&await preloadSqliteIntegration(r,await e.sqliteIntegrationPluginZip),await isWordPressInstalled(r)||await installWordPress(r),!await isWordPressInstalled(r))throw new Error("WordPress installation has failed.");return s}async function isWordPressInstalled(e){return(await e.run({code:`<?php
|
|
79
79
|
require '${e.documentRoot}/wp-load.php';
|
|
80
80
|
echo is_blog_installed() ? '1' : '0';
|
|
81
|
-
`})).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-
|
|
81
|
+
`})).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
|
|
82
82
|
require '${e.documentRoot}/wp-includes/version.php';
|
|
83
83
|
echo $wp_version;
|
|
84
84
|
`})).text;if(!r)throw new Error("Unable to read loaded WordPress version.");return versionStringToLoadedWordPressVersion(r)}function versionStringToLoadedWordPressVersion(e){if(/-(alpha|beta|RC)\d*-\d+$/.test(e))return"nightly";if(/-(beta|RC)\d*$/.test(e))return"beta";const r=e.match(/^(\d+\.\d+)(?:\.\d+)?$/);return r!==null?r[1]:e}function isSupportedWordPressVersion(e){return Object.keys(SupportedWordPressVersions).includes(e)}const wordPressRewriteRules=[{match:/^\/(.*?)(\/wp-(content|admin|includes)\/.*)/g,replacement:"$2"}];async function setupPlatformLevelMuPlugins(e){await e.mkdir("/internal/shared/mu-plugins"),await e.writeFile("/internal/shared/preload/env.php",`<?php
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wp-playground/wordpress",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.10",
|
|
4
4
|
"description": "WordPress-related plumbing for WordPress Playground",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -27,5 +27,5 @@
|
|
|
27
27
|
"access": "public",
|
|
28
28
|
"directory": "../../../dist/packages/playground/wordpress"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "713ee9bb8310b399e232e66d65d11768c075cf93"
|
|
31
31
|
}
|