@wp-playground/wordpress 0.9.16 → 0.9.18

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/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # playground-wordpress
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Building
6
+
7
+ Run `nx build playground-wordpress` to build the library.
8
+
9
+ ## Running unit tests
10
+
11
+ Run `nx test playground-wordpress` to execute the unit tests via [Jest](https://jestjs.io).
package/index.d.ts CHANGED
@@ -1050,7 +1050,6 @@ export interface BootOptions {
1050
1050
  */
1051
1051
  export declare function bootWordPress(options: BootOptions): Promise<PHPRequestHandler>;
1052
1052
  export declare function getLoadedWordPressVersion(requestHandler: PHPRequestHandler): Promise<string>;
1053
- export declare function isSupportedWordPressVersion(wpVersion: string): boolean;
1054
1053
  /**
1055
1054
  * The default rewrite rules for WordPress.
1056
1055
  */
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";import{SupportedWordPressVersions as $}from"@wp-playground/wordpress-builds";async function F(e){async function a(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 L(n),await g(n,"/",e.createFiles||{}),await E(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 r=new c({phpFactory:async({isPrimary:i})=>a(r,i),documentRoot:e.documentRoot||"/wordpress",absoluteUrl:e.siteUrl,rewriteRules:y}),t=await r.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 P(t),!await u(t))throw new Error("WordPress installation has failed.");return r}async function u(e){return(await e.run({code:`<?php
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
2
2
  require '${e.documentRoot}/wp-load.php';
3
3
  echo is_blog_installed() ? '1' : '0';
4
- `})).text==="1"}async function P(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 k(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"}}))}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 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}function q(e){return Object.keys($).includes(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
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
8
8
 
9
9
  // Allow adding filters/actions prior to loading WordPress.
10
10
  // $function_to_add MUST be a string.
@@ -108,13 +108,13 @@ import{joinPaths as s,phpVar as o}from"@php-wasm/util";import{unzipFile as l}fro
108
108
  }
109
109
  return false;
110
110
  });
111
- })();`)}async function E(e,a="/phpinfo.php"){await e.writeFile("/internal/shared/preload/phpinfo.php",`<?php
111
+ })();`)}async function L(e,r="/phpinfo.php"){await e.writeFile("/internal/shared/preload/phpinfo.php",`<?php
112
112
  // Render PHPInfo if the requested page is /phpinfo.php
113
- if ( ${o(a)} === $_SERVER['REQUEST_URI'] ) {
113
+ if ( ${o(r)} === $_SERVER['REQUEST_URI'] ) {
114
114
  phpinfo();
115
115
  exit;
116
116
  }
117
- `)}async function S(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 r="/internal/shared/sqlite-database-integration";await e.mv("/tmp/sqlite-database-integration/sqlite-database-integration-main",r),await e.defineConstant("SQLITE_MAIN_FILE","1");const i=(await e.readFileAsText(s(r,"db.copy"))).replace("'{SQLITE_IMPLEMENTATION_FOLDER_PATH}'",o(r)).replace("'{SQLITE_PLUGIN}'",o(s(r,"load.php"))),d=s(await e.documentRoot,"wp-content/db.php"),n=`<?php
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
118
118
  // Do not preload this if WordPress comes with a custom db.php file.
119
119
  if(file_exists(${o(d)})) {
120
120
  return;
@@ -191,4 +191,4 @@ if(!function_exists('mysqli_connect')) {
191
191
  var_dump(isset($wpdb));
192
192
  die("SQLite integration not loaded " . get_class($wpdb));
193
193
  }
194
- `)}async function R(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 r=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(r,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{F as bootWordPress,k as getLoadedWordPressVersion,q as isSupportedWordPressVersion,E as preloadPhpInfoRoute,S as preloadSqliteIntegration,L as setupPlatformLevelMuPlugins,R as unzipWordPress,y as wordPressRewriteRules};
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,b as wordPressRewriteRules};
package/package.json CHANGED
@@ -1,32 +1,44 @@
1
1
  {
2
- "name": "@wp-playground/wordpress",
3
- "version": "0.9.16",
4
- "description": "WordPress-related plumbing for WordPress Playground",
5
- "repository": {
6
- "type": "git",
7
- "url": "https://github.com/WordPress/wordpress-playground"
8
- },
9
- "homepage": "https://developer.wordpress.org/playground",
10
- "author": "The WordPress contributors",
11
- "contributors": [
12
- {
13
- "name": "Adam Zielinski",
14
- "email": "adam@adamziel.com",
15
- "url": "https://github.com/adamziel"
16
- }
17
- ],
18
- "type": "module",
19
- "types": "index.d.ts",
20
- "main": "./index.js",
21
- "typings": "./index.d.ts",
22
- "license": "GPL-2.0-or-later",
23
- "engines": {
24
- "node": ">=18.18.0",
25
- "npm": ">=8.11.0"
26
- },
27
- "publishConfig": {
28
- "access": "public",
29
- "directory": "../../../dist/packages/playground/wordpress"
30
- },
31
- "gitHead": "47110de9a9efc876f7b432c88d904ef081d1365c"
2
+ "name": "@wp-playground/wordpress",
3
+ "version": "0.9.18",
4
+ "description": "WordPress-related plumbing for WordPress Playground",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/WordPress/wordpress-playground"
8
+ },
9
+ "homepage": "https://developer.wordpress.org/playground",
10
+ "author": "The WordPress contributors",
11
+ "contributors": [
12
+ {
13
+ "name": "Adam Zielinski",
14
+ "email": "adam@adamziel.com",
15
+ "url": "https://github.com/adamziel"
16
+ }
17
+ ],
18
+ "type": "module",
19
+ "types": "index.d.ts",
20
+ "main": "./index.js",
21
+ "typings": "./index.d.ts",
22
+ "license": "GPL-2.0-or-later",
23
+ "engines": {
24
+ "node": ">=18.18.0",
25
+ "npm": ">=8.11.0"
26
+ },
27
+ "publishConfig": {
28
+ "access": "public",
29
+ "directory": "../../../dist/packages/playground/wordpress"
30
+ },
31
+ "gitHead": "13942923e970013ae9448c658e7c9ba8d4d85619",
32
+ "dependencies": {
33
+ "comlink": "^4.4.1",
34
+ "express": "4.19.2",
35
+ "ini": "4.1.2",
36
+ "ws": "8.13.0",
37
+ "yargs": "17.7.2",
38
+ "@php-wasm/universal": "0.9.18",
39
+ "@php-wasm/util": "0.9.18",
40
+ "@wp-playground/common": "0.9.18",
41
+ "@wp-playground/wordpress-builds": "0.9.18",
42
+ "@php-wasm/node": "0.9.18"
43
+ }
32
44
  }