@wp-playground/wordpress 0.9.34 → 0.9.36

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 (2) hide show
  1. package/index.js +9 -9
  2. package/package.json +6 -6
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import{joinPaths as o,phpVar as d}from"@php-wasm/util";import{unzipFile as l}from"@wp-playground/common";import{PHPRequestHandler as f,withPHPIniValues as g,PHP as w,setPhpIniEntries as _,writeFiles as m,proxyFileSystem as h,rotatePHPRuntime as $}from"@php-wasm/universal";async function k(e){async function a(n,s){const r=new w(await e.createPhpRuntime());return e.sapiName&&r.setSapiName(e.sapiName),n&&(r.requestHandler=n),e.phpIniEntries&&_(r,e.phpIniEntries),s?(await L(r),await m(r,"/",e.createFiles||{}),await S(r,o(new URL(e.siteUrl).pathname,"phpinfo.php"))):h(await n.getPrimaryPhp(),r,["/tmp",n.documentRoot,"/internal/shared"]),e.spawnHandler&&await r.setSpawnHandler(e.spawnHandler(n.processManager)),$({php:r,cwd:n.documentRoot,recreateRuntime:e.createPhpRuntime,maxRequests:400}),r}const i=new f({phpFactory:async({isPrimary:n})=>a(i,n),documentRoot:e.documentRoot||"/wordpress",absoluteUrl:e.siteUrl,rewriteRules:E,getFileNotFoundAction:e.getFileNotFoundAction??b}),t=await i.getPrimaryPhp();if(e.hooks?.beforeWordPressFiles&&await e.hooks.beforeWordPressFiles(t),e.wordPressZip&&await I(t,await e.wordPressZip),e.constants)for(const n in e.constants)t.defineConstant(n,e.constants[n]);if(t.defineConstant("WP_HOME",e.siteUrl),t.defineConstant("WP_SITEURL",e.siteUrl),e.hooks?.beforeDatabaseSetup&&await e.hooks.beforeDatabaseSetup(t),e.sqliteIntegrationPluginZip&&await R(t,await e.sqliteIntegrationPluginZip),await c(t)||await P(t),!await c(t))throw new Error("WordPress installation has failed.");return i}async function c(e){return(await e.run({code:`<?php
1
+ import{joinPaths as a,phpVar as d}from"@php-wasm/util";import{unzipFile as l}from"@wp-playground/common";import{PHPRequestHandler as f,withPHPIniValues as g,PHP as w,setPhpIniEntries as _,writeFiles as m,proxyFileSystem as h,rotatePHPRuntime as $}from"@php-wasm/universal";async function k(e){async function r(n,o){const s=new w(await e.createPhpRuntime());return e.sapiName&&s.setSapiName(e.sapiName),n&&(s.requestHandler=n),e.phpIniEntries&&_(s,e.phpIniEntries),o?(await L(s),await m(s,"/",e.createFiles||{}),await S(s,a(new URL(e.siteUrl).pathname,"phpinfo.php"))):h(await n.getPrimaryPhp(),s,["/tmp",n.documentRoot,"/internal/shared"]),e.spawnHandler&&await s.setSpawnHandler(e.spawnHandler(n.processManager)),$({php:s,cwd:n.documentRoot,recreateRuntime:e.createPhpRuntime,maxRequests:400}),s}const t=new f({phpFactory:async({isPrimary:n})=>r(t,n),documentRoot:e.documentRoot||"/wordpress",absoluteUrl:e.siteUrl,rewriteRules:E,getFileNotFoundAction:e.getFileNotFoundAction??b}),i=await t.getPrimaryPhp();if(e.hooks?.beforeWordPressFiles&&await e.hooks.beforeWordPressFiles(i),e.wordPressZip&&await F(i,await e.wordPressZip),e.constants)for(const n in e.constants)i.defineConstant(n,e.constants[n]);if(i.defineConstant("WP_HOME",e.siteUrl),i.defineConstant("WP_SITEURL",e.siteUrl),e.hooks?.beforeDatabaseSetup&&await e.hooks.beforeDatabaseSetup(i),e.sqliteIntegrationPluginZip&&await R(i,await e.sqliteIntegrationPluginZip),await c(i)||await P(i),!await c(i))throw new Error("WordPress installation has failed.");return t}async function c(e){return(await e.run({code:`<?php
2
2
  $wp_load = getenv('DOCUMENT_ROOT') . '/wp-load.php';
3
3
  if (!file_exists($wp_load)) {
4
4
  echo '0';
@@ -6,10 +6,10 @@ if (!file_exists($wp_load)) {
6
6
  }
7
7
  require $wp_load;
8
8
  echo is_blog_installed() ? '1' : '0';
9
- `,env:{DOCUMENT_ROOT:e.documentRoot}})).text==="1"}async function P(e){await g(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"}}))}function b(e){return{type:"internal-redirect",uri:"/index.php"}}async function q(e){const t=(await(await e.getPrimaryPhp()).run({code:`<?php
9
+ `,env:{DOCUMENT_ROOT:e.documentRoot}})).text==="1"}async function P(e){await g(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"}}))}function b(e){return{type:"internal-redirect",uri:"/index.php"}}async function q(e){const i=(await(await e.getPrimaryPhp()).run({code:`<?php
10
10
  require '${e.documentRoot}/wp-includes/version.php';
11
11
  echo $wp_version;
12
- `})).text;if(!t)throw new Error("Unable to read loaded WordPress version.");return y(t)}function y(e){if(/-(alpha|beta|RC)\d*-\d+$/.test(e))return"nightly";if(/-(beta|RC)\d*$/.test(e))return"beta";const t=e.match(/^(\d+\.\d+)(?:\.\d+)?$/);return t!==null?t[1]:e}const E=[{match:/^\/(.*?)(\/wp-(content|admin|includes)\/.*)/g,replacement:"$2"}];async function L(e){await e.mkdir("/internal/shared/mu-plugins"),await e.writeFile("/internal/shared/preload/env.php",`<?php
12
+ `})).text;if(!i)throw new Error("Unable to read loaded WordPress version.");return y(i)}function y(e){if(/-(alpha|beta|RC)\d*-\d+$/.test(e))return"nightly";if(/-(beta|RC)\d*$/.test(e))return"beta";const i=e.match(/^(\d+\.\d+)(?:\.\d+)?$/);return i!==null?i[1]:e}const E=[{match:/^\/(.*?)(\/wp-(content|admin|includes)\/.*)/g,replacement:"$2"}];async function L(e){await e.mkdir("/internal/shared/mu-plugins"),await e.writeFile("/internal/shared/preload/env.php",`<?php
13
13
 
14
14
  // Allow adding filters/actions prior to loading WordPress.
15
15
  // $function_to_add MUST be a string.
@@ -116,18 +116,18 @@ echo is_blog_installed() ? '1' : '0';
116
116
  }
117
117
  return false;
118
118
  });
119
- })();`)}async function S(e,a="/phpinfo.php"){await e.writeFile("/internal/shared/preload/phpinfo.php",`<?php
119
+ })();`)}async function S(e,r="/phpinfo.php"){await e.writeFile("/internal/shared/preload/phpinfo.php",`<?php
120
120
  // Render PHPInfo if the requested page is /phpinfo.php
121
- if ( ${d(a)} === $_SERVER['REQUEST_URI'] ) {
121
+ if ( ${d(r)} === $_SERVER['REQUEST_URI'] ) {
122
122
  phpinfo();
123
123
  exit;
124
124
  }
125
- `)}async function R(e,a){await e.isDir("/tmp/sqlite-database-integration")&&await e.rmdir("/tmp/sqlite-database-integration",{recursive:!0}),await e.mkdir("/tmp/sqlite-database-integration"),await l(e,a,"/tmp/sqlite-database-integration");const i="/internal/shared/sqlite-database-integration",t=await e.isDir("/tmp/sqlite-database-integration/sqlite-database-integration-main")?"/tmp/sqlite-database-integration/sqlite-database-integration-main":"/tmp/sqlite-database-integration/sqlite-database-integration-develop";await e.mv(t,i),await e.defineConstant("SQLITE_MAIN_FILE","1");const s=(await e.readFileAsText(o(i,"db.copy"))).replace("'{SQLITE_IMPLEMENTATION_FOLDER_PATH}'",d(i)).replace("'{SQLITE_PLUGIN}'",d(o(i,"load.php"))),r=o(await e.documentRoot,"wp-content/db.php"),p=`<?php
125
+ `)}async function R(e,r){await e.isDir("/tmp/sqlite-database-integration")&&await e.rmdir("/tmp/sqlite-database-integration",{recursive:!0}),await e.mkdir("/tmp/sqlite-database-integration"),await l(e,r,"/tmp/sqlite-database-integration");const t="/internal/shared/sqlite-database-integration",i=await e.isDir("/tmp/sqlite-database-integration/sqlite-database-integration-main")?"/tmp/sqlite-database-integration/sqlite-database-integration-main":"/tmp/sqlite-database-integration/sqlite-database-integration-develop";await e.mv(i,t),await e.defineConstant("SQLITE_MAIN_FILE","1");const o=(await e.readFileAsText(a(t,"db.copy"))).replace("'{SQLITE_IMPLEMENTATION_FOLDER_PATH}'",d(t)).replace("'{SQLITE_PLUGIN}'",d(a(t,"load.php"))),s=a(await e.documentRoot,"wp-content/db.php"),p=`<?php
126
126
  // Do not preload this if WordPress comes with a custom db.php file.
127
- if(file_exists(${d(r)})) {
127
+ if(file_exists(${d(s)})) {
128
128
  return;
129
129
  }
130
- ?>`,u="/internal/shared/mu-plugins/sqlite-database-integration.php";await e.writeFile(u,p+s),await e.writeFile("/internal/shared/preload/0-sqlite.php",p+`<?php
130
+ ?>`,u="/internal/shared/mu-plugins/sqlite-database-integration.php";await e.writeFile(u,p+o),await e.writeFile("/internal/shared/preload/0-sqlite.php",p+`<?php
131
131
 
132
132
  /**
133
133
  * Loads the SQLite integration plugin before WordPress is loaded
@@ -199,4 +199,4 @@ if(!function_exists('mysqli_connect')) {
199
199
  var_dump(isset($wpdb));
200
200
  die("SQLite integration not loaded " . get_class($wpdb));
201
201
  }
202
- `)}async function I(e,a){e.mkdir("/tmp/unzipped-wordpress"),await l(e,a,"/tmp/unzipped-wordpress"),e.fileExists("/tmp/unzipped-wordpress/wordpress.zip")&&await l(e,"/tmp/unzipped-wordpress/wordpress.zip","/tmp/unzipped-wordpress");const i=e.fileExists("/tmp/unzipped-wordpress/wordpress")?"/tmp/unzipped-wordpress/wordpress":e.fileExists("/tmp/unzipped-wordpress/build")?"/tmp/unzipped-wordpress/build":"/tmp/unzipped-wordpress";if(e.isDir(e.documentRoot)&&F(e.documentRoot,e)){for(const t of e.listFiles(i)){const n=o(i,t),s=o(e.documentRoot,t);e.mv(n,s)}e.rmdir(i,{recursive:!0})}else e.mv(i,e.documentRoot);!e.fileExists(o(e.documentRoot,"wp-config.php"))&&e.fileExists(o(e.documentRoot,"wp-config-sample.php"))&&e.writeFile(o(e.documentRoot,"wp-config.php"),e.readFileAsText(o(e.documentRoot,"/wp-config-sample.php")))}function F(e,a){const i=a.listFiles(e);return i.length===0||i.length===1&&i[0]==="playground-site-metadata.json"}export{k as bootWordPress,b as getFileNotFoundActionForWordPress,q as getLoadedWordPressVersion,S as preloadPhpInfoRoute,R as preloadSqliteIntegration,L as setupPlatformLevelMuPlugins,I as unzipWordPress,y as versionStringToLoadedWordPressVersion,E as wordPressRewriteRules};
202
+ `)}async function F(e,r){e.mkdir("/tmp/unzipped-wordpress"),await l(e,r,"/tmp/unzipped-wordpress"),e.fileExists("/tmp/unzipped-wordpress/wordpress.zip")&&await l(e,"/tmp/unzipped-wordpress/wordpress.zip","/tmp/unzipped-wordpress");let t=e.fileExists("/tmp/unzipped-wordpress/wordpress")?"/tmp/unzipped-wordpress/wordpress":e.fileExists("/tmp/unzipped-wordpress/build")?"/tmp/unzipped-wordpress/build":"/tmp/unzipped-wordpress";if(!e.fileExists(a(t,"wp-config-sample.php"))){const i=e.listFiles(t);if(i.length){const n=i[0];e.fileExists(a(t,n,"wp-config-sample.php"))&&(t=a(t,n))}}if(e.isDir(e.documentRoot)&&I(e.documentRoot,e)){for(const i of e.listFiles(t)){const n=a(t,i),o=a(e.documentRoot,i);e.mv(n,o)}e.rmdir(t,{recursive:!0})}else e.mv(t,e.documentRoot);!e.fileExists(a(e.documentRoot,"wp-config.php"))&&e.fileExists(a(e.documentRoot,"wp-config-sample.php"))&&e.writeFile(a(e.documentRoot,"wp-config.php"),e.readFileAsText(a(e.documentRoot,"/wp-config-sample.php")))}function I(e,r){const t=r.listFiles(e);return t.length===0||t.length===1&&t[0]==="playground-site-metadata.json"}export{k as bootWordPress,b as getFileNotFoundActionForWordPress,q as getLoadedWordPressVersion,S as preloadPhpInfoRoute,R as preloadSqliteIntegration,L as setupPlatformLevelMuPlugins,F as unzipWordPress,y as versionStringToLoadedWordPressVersion,E as wordPressRewriteRules};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wp-playground/wordpress",
3
- "version": "0.9.34",
3
+ "version": "0.9.36",
4
4
  "description": "WordPress-related plumbing for WordPress Playground",
5
5
  "repository": {
6
6
  "type": "git",
@@ -28,16 +28,16 @@
28
28
  "access": "public",
29
29
  "directory": "../../../dist/packages/playground/wordpress"
30
30
  },
31
- "gitHead": "7bb2d07709cc230bf3c940b80ef39fa643e53916",
31
+ "gitHead": "7e69767d7998d57224cbbc5a1de986cef93cee0f",
32
32
  "dependencies": {
33
33
  "comlink": "^4.4.1",
34
34
  "express": "4.19.2",
35
35
  "ini": "4.1.2",
36
36
  "ws": "8.18.0",
37
37
  "yargs": "17.7.2",
38
- "@php-wasm/universal": "0.9.34",
39
- "@php-wasm/util": "0.9.34",
40
- "@wp-playground/common": "0.9.34",
41
- "@php-wasm/node": "0.9.34"
38
+ "@php-wasm/universal": "0.9.36",
39
+ "@php-wasm/util": "0.9.36",
40
+ "@wp-playground/common": "0.9.36",
41
+ "@php-wasm/node": "0.9.36"
42
42
  }
43
43
  }