@wp-playground/wordpress 0.9.22 → 0.9.24

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/boot.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { FileTree, PHP, PHPProcessManager, PHPRequestHandler, SpawnHandler } from '../../../php-wasm/universal/src/index.ts';
1
+ import { FileNotFoundAction, FileNotFoundGetActionCallback, FileTree, PHP, PHPProcessManager, PHPRequestHandler, SpawnHandler } from '../../../php-wasm/universal/src/index.ts';
2
2
  export type PhpIniOptions = Record<string, string>;
3
3
  export type Hook = (php: PHP) => void | Promise<void>;
4
4
  export interface Hooks {
@@ -61,6 +61,11 @@ export interface BootOptions {
61
61
  * ```
62
62
  */
63
63
  createFiles?: FileTree;
64
+ /**
65
+ * A callback that decides how to handle a file-not-found condition for a
66
+ * given request URI.
67
+ */
68
+ getFileNotFoundAction?: FileNotFoundGetActionCallback;
64
69
  }
65
70
  /**
66
71
  * Boots a WordPress instance with the given options.
@@ -78,3 +83,4 @@ export interface BootOptions {
78
83
  * @return PHPRequestHandler instance with WordPress installed.
79
84
  */
80
85
  export declare function bootWordPress(options: BootOptions): Promise<PHPRequestHandler>;
86
+ export declare function getFileNotFoundActionForWordPress(relativeUri: string): FileNotFoundAction;
package/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { PHP, UniversalPHP } from '../../../php-wasm/universal/src/index.ts';
2
- export { bootWordPress } from './boot';
2
+ export { bootWordPress, getFileNotFoundActionForWordPress } from './boot';
3
+ export { getLoadedWordPressVersion } from './version-detect';
3
4
  export * from './version-detect';
4
5
  export * from './rewrite-rules';
5
6
  /**
package/index.js CHANGED
@@ -1,10 +1,10 @@
1
- import{joinPaths as s,phpVar as o}from"@php-wasm/util";import{unzipFile as l}from"@wp-playground/common";import{PHPRequestHandler as c,withPHPIniValues as f,PHP as w,setPhpIniEntries as _,writeFiles as g,proxyFileSystem as m,rotatePHPRuntime as h}from"@php-wasm/universal";async function T(e){async function r(i,d){const n=new w(await e.createPhpRuntime());return e.sapiName&&n.setSapiName(e.sapiName),i&&(n.requestHandler=i),e.phpIniEntries&&_(n,e.phpIniEntries),d?(await y(n),await g(n,"/",e.createFiles||{}),await L(n,s(new URL(e.siteUrl).pathname,"phpinfo.php"))):m(await i.getPrimaryPhp(),n,["/tmp",i.documentRoot,"/internal/shared"]),e.spawnHandler&&await n.setSpawnHandler(e.spawnHandler(i.processManager)),h({php:n,cwd:i.documentRoot,recreateRuntime:e.createPhpRuntime,maxRequests:400}),n}const a=new c({phpFactory:async({isPrimary:i})=>r(a,i),documentRoot:e.documentRoot||"/wordpress",absoluteUrl:e.siteUrl,rewriteRules:b}),t=await a.getPrimaryPhp();if(e.hooks?.beforeWordPressFiles&&await e.hooks.beforeWordPressFiles(t),e.wordPressZip&&await R(t,await e.wordPressZip),e.constants)for(const i in e.constants)t.defineConstant(i,e.constants[i]);if(t.defineConstant("WP_HOME",e.siteUrl),t.defineConstant("WP_SITEURL",e.siteUrl),e.hooks?.beforeDatabaseSetup&&await e.hooks.beforeDatabaseSetup(t),e.sqliteIntegrationPluginZip&&await E(t,await e.sqliteIntegrationPluginZip),await u(t)||await $(t),!await u(t))throw new Error("WordPress installation has failed.");return a}async function u(e){return(await e.run({code:`<?php
1
+ import{joinPaths as o,phpVar as s}from"@php-wasm/util";import{unzipFile as l}from"@wp-playground/common";import{PHPRequestHandler as c,withPHPIniValues as f,PHP as w,setPhpIniEntries as g,writeFiles as _,proxyFileSystem as m,rotatePHPRuntime as h}from"@php-wasm/universal";async function T(e){async function r(i,d){const n=new w(await e.createPhpRuntime());return e.sapiName&&n.setSapiName(e.sapiName),i&&(n.requestHandler=i),e.phpIniEntries&&g(n,e.phpIniEntries),d?(await L(n),await _(n,"/",e.createFiles||{}),await E(n,o(new URL(e.siteUrl).pathname,"phpinfo.php"))):m(await i.getPrimaryPhp(),n,["/tmp",i.documentRoot,"/internal/shared"]),e.spawnHandler&&await n.setSpawnHandler(e.spawnHandler(i.processManager)),h({php:n,cwd:i.documentRoot,recreateRuntime:e.createPhpRuntime,maxRequests:400}),n}const a=new c({phpFactory:async({isPrimary:i})=>r(a,i),documentRoot:e.documentRoot||"/wordpress",absoluteUrl:e.siteUrl,rewriteRules:y,getFileNotFoundAction:e.getFileNotFoundAction??P}),t=await a.getPrimaryPhp();if(e.hooks?.beforeWordPressFiles&&await e.hooks.beforeWordPressFiles(t),e.wordPressZip&&await R(t,await e.wordPressZip),e.constants)for(const i in e.constants)t.defineConstant(i,e.constants[i]);if(t.defineConstant("WP_HOME",e.siteUrl),t.defineConstant("WP_SITEURL",e.siteUrl),e.hooks?.beforeDatabaseSetup&&await e.hooks.beforeDatabaseSetup(t),e.sqliteIntegrationPluginZip&&await S(t,await e.sqliteIntegrationPluginZip),await u(t)||await $(t),!await u(t))throw new Error("WordPress installation has failed.");return a}async function u(e){return(await e.run({code:`<?php
2
2
  require '${e.documentRoot}/wp-load.php';
3
3
  echo is_blog_installed() ? '1' : '0';
4
- `})).text==="1"}async function $(e){await f(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"}}))}async function x(e){const t=(await(await e.getPrimaryPhp()).run({code:`<?php
4
+ `})).text==="1"}async function $(e){await f(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 P(e){return{type:"internal-redirect",uri:"/index.php"}}async function x(e){const t=(await(await e.getPrimaryPhp()).run({code:`<?php
5
5
  require '${e.documentRoot}/wp-includes/version.php';
6
6
  echo $wp_version;
7
- `})).text;if(!t)throw new Error("Unable to read loaded WordPress version.");return P(t)}function P(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 b=[{match:/^\/(.*?)(\/wp-(content|admin|includes)\/.*)/g,replacement:"$2"}];async function y(e){await e.mkdir("/internal/shared/mu-plugins"),await e.writeFile("/internal/shared/preload/env.php",`<?php
7
+ `})).text;if(!t)throw new Error("Unable to read loaded WordPress version.");return b(t)}function b(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 y=[{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
8
8
 
9
9
  // Allow adding filters/actions prior to loading WordPress.
10
10
  // $function_to_add MUST be a string.
@@ -32,14 +32,6 @@ import{joinPaths as s,phpVar as o}from"@php-wasm/util";import{unzipFile as l}fro
32
32
  }
33
33
  }
34
34
  `),await e.writeFile("/internal/shared/mu-plugins/0-playground.php",`<?php
35
- // Redirect /wp-admin to /wp-admin/
36
- add_filter( 'redirect_canonical', function( $redirect_url ) {
37
- if ( '/wp-admin' === $redirect_url ) {
38
- return $redirect_url . '/';
39
- }
40
- return $redirect_url;
41
- } );
42
-
43
35
  // Needed because gethostbyname( 'wordpress.org' ) returns
44
36
  // a private network IP address for some reason.
45
37
  add_filter( 'allowed_redirect_hosts', function( $deprecated = '' ) {
@@ -108,15 +100,15 @@ import{joinPaths as s,phpVar as o}from"@php-wasm/util";import{unzipFile as l}fro
108
100
  }
109
101
  return false;
110
102
  });
111
- })();`)}async function L(e,r="/phpinfo.php"){await e.writeFile("/internal/shared/preload/phpinfo.php",`<?php
103
+ })();`)}async function E(e,r="/phpinfo.php"){await e.writeFile("/internal/shared/preload/phpinfo.php",`<?php
112
104
  // Render PHPInfo if the requested page is /phpinfo.php
113
- if ( ${o(r)} === $_SERVER['REQUEST_URI'] ) {
105
+ if ( ${s(r)} === $_SERVER['REQUEST_URI'] ) {
114
106
  phpinfo();
115
107
  exit;
116
108
  }
117
- `)}async function E(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 a="/internal/shared/sqlite-database-integration";await e.mv("/tmp/sqlite-database-integration/sqlite-database-integration-main",a),await e.defineConstant("SQLITE_MAIN_FILE","1");const i=(await e.readFileAsText(s(a,"db.copy"))).replace("'{SQLITE_IMPLEMENTATION_FOLDER_PATH}'",o(a)).replace("'{SQLITE_PLUGIN}'",o(s(a,"load.php"))),d=s(await e.documentRoot,"wp-content/db.php"),n=`<?php
109
+ `)}async function S(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 a="/internal/shared/sqlite-database-integration";await e.mv("/tmp/sqlite-database-integration/sqlite-database-integration-main",a),await e.defineConstant("SQLITE_MAIN_FILE","1");const i=(await e.readFileAsText(o(a,"db.copy"))).replace("'{SQLITE_IMPLEMENTATION_FOLDER_PATH}'",s(a)).replace("'{SQLITE_PLUGIN}'",s(o(a,"load.php"))),d=o(await e.documentRoot,"wp-content/db.php"),n=`<?php
118
110
  // Do not preload this if WordPress comes with a custom db.php file.
119
- if(file_exists(${o(d)})) {
111
+ if(file_exists(${s(d)})) {
120
112
  return;
121
113
  }
122
114
  ?>`,p="/internal/shared/mu-plugins/sqlite-database-integration.php";await e.writeFile(p,n+i),await e.writeFile("/internal/shared/preload/0-sqlite.php",n+`<?php
@@ -169,7 +161,7 @@ class Playground_SQLite_Integration_Loader {
169
161
  $GLOBALS['wpdb']->$name = $value;
170
162
  }
171
163
  protected function load_sqlite_integration() {
172
- require_once ${o(p)};
164
+ require_once ${s(p)};
173
165
  }
174
166
  }
175
167
  $wpdb = $GLOBALS['wpdb'] = new Playground_SQLite_Integration_Loader();
@@ -191,4 +183,4 @@ if(!function_exists('mysqli_connect')) {
191
183
  var_dump(isset($wpdb));
192
184
  die("SQLite integration not loaded " . get_class($wpdb));
193
185
  }
194
- `)}async function R(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");const a=e.fileExists("/tmp/unzipped-wordpress/wordpress")?"/tmp/unzipped-wordpress/wordpress":e.fileExists("/tmp/unzipped-wordpress/build")?"/tmp/unzipped-wordpress/build":"/tmp/unzipped-wordpress";e.mv(a,e.documentRoot),!e.fileExists(s(e.documentRoot,"wp-config.php"))&&e.fileExists(s(e.documentRoot,"wp-config-sample.php"))&&e.writeFile(s(e.documentRoot,"wp-config.php"),e.readFileAsText(s(e.documentRoot,"/wp-config-sample.php")))}export{T as bootWordPress,x as getLoadedWordPressVersion,L as preloadPhpInfoRoute,E as preloadSqliteIntegration,y as setupPlatformLevelMuPlugins,R as unzipWordPress,P as versionStringToLoadedWordPressVersion,b as wordPressRewriteRules};
186
+ `)}async function R(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");const a=e.fileExists("/tmp/unzipped-wordpress/wordpress")?"/tmp/unzipped-wordpress/wordpress":e.fileExists("/tmp/unzipped-wordpress/build")?"/tmp/unzipped-wordpress/build":"/tmp/unzipped-wordpress";e.mv(a,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")))}export{T as bootWordPress,P as getFileNotFoundActionForWordPress,x as getLoadedWordPressVersion,E as preloadPhpInfoRoute,S as preloadSqliteIntegration,L as setupPlatformLevelMuPlugins,R as unzipWordPress,b as versionStringToLoadedWordPressVersion,y as wordPressRewriteRules};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wp-playground/wordpress",
3
- "version": "0.9.22",
3
+ "version": "0.9.24",
4
4
  "description": "WordPress-related plumbing for WordPress Playground",
5
5
  "repository": {
6
6
  "type": "git",
@@ -28,17 +28,16 @@
28
28
  "access": "public",
29
29
  "directory": "../../../dist/packages/playground/wordpress"
30
30
  },
31
- "gitHead": "aac882e3528d0de9d928e8630a01c03b15b1a14b",
31
+ "gitHead": "350e0a867ea1a5fe8d51fc8b6ce2408b48f56ec9",
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.13.0",
37
37
  "yargs": "17.7.2",
38
- "@php-wasm/universal": "0.9.22",
39
- "@php-wasm/util": "0.9.22",
40
- "@wp-playground/common": "0.9.22",
41
- "@wp-playground/wordpress-builds": "0.9.22",
42
- "@php-wasm/node": "0.9.22"
38
+ "@php-wasm/universal": "0.9.24",
39
+ "@php-wasm/util": "0.9.24",
40
+ "@wp-playground/common": "0.9.24",
41
+ "@php-wasm/node": "0.9.24"
43
42
  }
44
43
  }