@wp-playground/wordpress 2.0.2 → 2.0.3

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 (4) hide show
  1. package/index.cjs +15 -15
  2. package/index.js +111 -104
  3. package/index.js.map +1 -1
  4. package/package.json +7 -7
package/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@php-wasm/util"),l=require("@wp-playground/common"),d=require("@php-wasm/universal"),k=require("@php-wasm/logger"),E=`<?php
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@php-wasm/util"),p=require("@wp-playground/common"),_=require("@php-wasm/logger"),d=require("@php-wasm/universal"),T=`<?php
2
2
 
3
3
  /**
4
4
  * Rewrites the wp-config.php file to ensure specific constants are defined
@@ -343,16 +343,16 @@ function skip_whitespace($tokens) {
343
343
  }
344
344
  return $output;
345
345
  }
346
- `;async function _(e,i,n,t="rewrite"){const r=o.phpVars({wpConfigPath:i,constants:n,whenAlreadyDefined:t});if((await e.run({code:`<?php ob_start(); ?>
347
- ${E}
348
- $wp_config_path = ${r.wpConfigPath};
346
+ `;async function c(e,r,n,t="rewrite"){const i=o.phpVars({wpConfigPath:r,constants:n,whenAlreadyDefined:t});if((await e.run({code:`<?php ob_start(); ?>
347
+ ${T}
348
+ $wp_config_path = ${i.wpConfigPath};
349
349
  $wp_config = file_get_contents($wp_config_path);
350
- $new_wp_config = rewrite_wp_config_to_define_constants($wp_config, ${r.constants}, ${r.whenAlreadyDefined});
350
+ $new_wp_config = rewrite_wp_config_to_define_constants($wp_config, ${i.constants}, ${i.whenAlreadyDefined});
351
351
  $return_value = file_put_contents($wp_config_path, $new_wp_config);
352
352
  ob_clean();
353
353
  echo false === $return_value ? '0' : '1';
354
354
  ob_end_flush();
355
- `})).text!=="1")throw new Error("Failed to rewrite constants in wp-config.php.")}async function c(e,i){const n=o.joinPaths(i,"wp-config.php"),t={DB_NAME:"wordpress"};!e.fileExists(n)&&e.fileExists(o.joinPaths(i,"wp-config-sample.php"))&&await e.writeFile(n,await e.readFileAsBuffer(o.joinPaths(i,"wp-config-sample.php"))),await _(e,n,t,"skip")}async function R(e){var t,r;const i=await h(e),n=await i.getPrimaryPhp();if((t=e.hooks)!=null&&t.beforeWordPressFiles&&await e.hooks.beforeWordPressFiles(n),e.wordPressZip&&await P(n,await e.wordPressZip),e.constants)for(const s in e.constants)n.defineConstant(s,e.constants[s]);if(e.dataSqlPath&&(n.defineConstant("DB_DIR",o.dirname(e.dataSqlPath)),n.defineConstant("DB_FILE",o.basename(e.dataSqlPath))),n.defineConstant("WP_HOME",e.siteUrl),n.defineConstant("WP_SITEURL",e.siteUrl),await c(n,i.documentRoot),(r=e.hooks)!=null&&r.beforeDatabaseSetup&&await e.hooks.beforeDatabaseSetup(n),e.sqliteIntegrationPluginZip&&await y(n,await e.sqliteIntegrationPluginZip),!e.dataSqlPath&&(await f(n)||await T(n),!await f(n)))throw new Error("WordPress installation has failed.");return i}async function h(e){const i=e.spawnHandler??d.sandboxedSpawnHandlerFactory;async function n(r,s){const a=new d.PHP(await e.createPhpRuntime());return e.sapiName&&a.setSapiName(e.sapiName),r&&(a.requestHandler=r),e.phpIniEntries&&d.setPhpIniEntries(a,e.phpIniEntries),s?(await m(a),await d.writeFiles(a,"/",e.createFiles||{}),await b(a,o.joinPaths(new URL(e.siteUrl).pathname,"phpinfo.php"))):d.proxyFileSystem(await r.getPrimaryPhp(),a,["/tmp",r.documentRoot,"/internal/shared"]),i&&await a.setSpawnHandler(i(r.processManager)),d.rotatePHPRuntime({php:a,cwd:r.documentRoot,recreateRuntime:e.createPhpRuntime,maxRequests:400}),e.onPHPInstanceCreated&&await e.onPHPInstanceCreated(a),a}const t=new d.PHPRequestHandler({phpFactory:async({isPrimary:r})=>n(t,r),documentRoot:e.documentRoot||"/wordpress",absoluteUrl:e.siteUrl,rewriteRules:w,getFileNotFoundAction:e.getFileNotFoundAction??g,cookieStore:e.cookieStore});return t}async function f(e){return(await e.run({code:`<?php
355
+ `})).text!=="1")throw new Error("Failed to rewrite constants in wp-config.php.")}async function h(e,r){const n=o.joinPaths(r,"wp-config.php"),t={DB_NAME:"wordpress"};!e.fileExists(n)&&e.fileExists(o.joinPaths(r,"wp-config-sample.php"))&&await e.writeFile(n,await e.readFileAsBuffer(o.joinPaths(r,"wp-config-sample.php"))),await c(e,n,t,"skip")}async function S(e){var t,i;const r=await g(e),n=await r.getPrimaryPhp();if((t=e.hooks)!=null&&t.beforeWordPressFiles&&await e.hooks.beforeWordPressFiles(n),e.wordPressZip&&await k(n,await e.wordPressZip),e.constants)for(const s in e.constants)n.defineConstant(s,e.constants[s]);if(e.dataSqlPath&&(n.defineConstant("DB_DIR",o.dirname(e.dataSqlPath)),n.defineConstant("DB_FILE",o.basename(e.dataSqlPath))),n.defineConstant("WP_HOME",e.siteUrl),n.defineConstant("WP_SITEURL",e.siteUrl),await h(n,r.documentRoot),(i=e.hooks)!=null&&i.beforeDatabaseSetup&&await e.hooks.beforeDatabaseSetup(n),e.sqliteIntegrationPluginZip&&await P(n,await e.sqliteIntegrationPluginZip),!e.dataSqlPath&&(await f(n)||await R(n),!await f(n)))throw new Error("WordPress installation has failed.");return r}async function g(e){const r=e.spawnHandler??d.sandboxedSpawnHandlerFactory;async function n(i,s){const a=new d.PHP(await e.createPhpRuntime());return e.sapiName&&a.setSapiName(e.sapiName),i&&(a.requestHandler=i),e.phpIniEntries&&d.setPhpIniEntries(a,e.phpIniEntries),s?(await b(a),await d.writeFiles(a,"/",e.createFiles||{}),await y(a,o.joinPaths(new URL(e.siteUrl).pathname,"phpinfo.php"))):d.proxyFileSystem(await i.getPrimaryPhp(),a,["/tmp",i.documentRoot,"/internal/shared"]),r&&await a.setSpawnHandler(r(i.processManager)),d.rotatePHPRuntime({php:a,cwd:i.documentRoot,recreateRuntime:e.createPhpRuntime,maxRequests:400}),e.onPHPInstanceCreated&&await e.onPHPInstanceCreated(a),a}const t=new d.PHPRequestHandler({phpFactory:async({isPrimary:i})=>n(t,i),documentRoot:e.documentRoot||"/wordpress",absoluteUrl:e.siteUrl,rewriteRules:m,getFileNotFoundAction:e.getFileNotFoundAction??$,cookieStore:e.cookieStore});return t}async function f(e){return(await e.run({code:`<?php
356
356
  ob_start();
357
357
  $wp_load = getenv('DOCUMENT_ROOT') . '/wp-load.php';
358
358
  if (!file_exists($wp_load)) {
@@ -363,7 +363,7 @@ function skip_whitespace($tokens) {
363
363
  ob_clean();
364
364
  echo is_blog_installed() ? '1' : '0';
365
365
  ob_end_flush();
366
- `,env:{DOCUMENT_ROOT:e.documentRoot}})).text==="1"}async function T(e){await d.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"}})),(await e.run({code:`<?php
366
+ `,env:{DOCUMENT_ROOT:e.documentRoot}})).text==="1"}async function R(e){await d.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"}})),(await e.run({code:`<?php
367
367
  ob_start();
368
368
  $wp_load = getenv('DOCUMENT_ROOT') . '/wp-load.php';
369
369
  if (!file_exists($wp_load)) {
@@ -378,10 +378,10 @@ function skip_whitespace($tokens) {
378
378
  ob_clean();
379
379
  echo $option_result ? '1' : '0';
380
380
  ob_end_flush();
381
- `,env:{DOCUMENT_ROOT:e.documentRoot}})).text!=="1"&&k.logger.warn("Failed to default to pretty permalinks after WP install.")}function g(e){return{type:"internal-redirect",uri:"/index.php"}}async function S(e){const{php:i,reap:n}=await e.processManager.acquirePHPInstance({considerPrimary:!0});try{const r=(await i.run({code:`<?php
381
+ `,env:{DOCUMENT_ROOT:e.documentRoot}})).text!=="1"&&_.logger.warn("Failed to default to pretty permalinks after WP install.")}function $(e){return{type:"internal-redirect",uri:"/index.php"}}async function v(e){const{php:r,reap:n}=await e.processManager.acquirePHPInstance({considerPrimary:!0});try{const i=(await r.run({code:`<?php
382
382
  require '${e.documentRoot}/wp-includes/version.php';
383
383
  echo $wp_version;
384
- `})).text;if(!r)throw new Error("Unable to read loaded WordPress version.");return $(r)}finally{n()}}function $(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 w=[{match:/^\/(.*?)(\/wp-(content|admin|includes)\/.*)/g,replacement:"$2"}];async function m(e){await e.mkdir("/internal/shared/mu-plugins"),await e.writeFile("/internal/shared/preload/env.php",`<?php
384
+ `})).text;if(!i)throw new Error("Unable to read loaded WordPress version.");return w(i)}finally{n()}}function w(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 m=[{match:/^\/(.*?)(\/wp-(content|admin|includes)\/.*)/g,replacement:"$2"}];async function b(e){await e.mkdir("/internal/shared/mu-plugins"),await e.writeFile("/internal/shared/preload/env.php",`<?php
385
385
 
386
386
  // Allow adding filters/actions prior to loading WordPress.
387
387
  // $function_to_add MUST be a string.
@@ -609,18 +609,18 @@ function skip_whitespace($tokens) {
609
609
  }
610
610
  return false;
611
611
  });
612
- })();`)}async function b(e,i="/phpinfo.php"){await e.writeFile("/internal/shared/preload/phpinfo.php",`<?php
612
+ })();`)}async function y(e,r="/phpinfo.php"){await e.writeFile("/internal/shared/preload/phpinfo.php",`<?php
613
613
  // Render PHPInfo if the requested page is /phpinfo.php
614
- if ( isset($_SERVER['REQUEST_URI']) && ${o.phpVar(i)} === $_SERVER['REQUEST_URI'] ) {
614
+ if ( isset($_SERVER['REQUEST_URI']) && ${o.phpVar(r)} === $_SERVER['REQUEST_URI'] ) {
615
615
  phpinfo();
616
616
  exit;
617
617
  }
618
- `)}async function y(e,i){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.unzipFile(e,i,"/tmp/sqlite-database-integration");const n="/internal/shared/sqlite-database-integration",t=`/tmp/sqlite-database-integration/${(await e.listFiles("/tmp/sqlite-database-integration"))[0]}`;await e.mv(t,n),e.defineConstant("WP_SQLITE_AST_DRIVER",!0),await e.defineConstant("SQLITE_MAIN_FILE","1");const s=(await e.readFileAsText(o.joinPaths(n,"db.copy"))).replace("'{SQLITE_IMPLEMENTATION_FOLDER_PATH}'",o.phpVar(n)).replace("'{SQLITE_PLUGIN}'",o.phpVar(o.joinPaths(n,"load.php"))),a=o.joinPaths(await e.documentRoot,"wp-content/db.php"),u=`<?php
618
+ `)}async function P(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 p.unzipFile(e,r,"/tmp/sqlite-database-integration");const n="/internal/shared/sqlite-database-integration",t=`/tmp/sqlite-database-integration/${(await e.listFiles("/tmp/sqlite-database-integration"))[0]}`;await e.mv(t,n),e.defineConstant("WP_SQLITE_AST_DRIVER",!0),await e.defineConstant("SQLITE_MAIN_FILE","1");const s=(await e.readFileAsText(o.joinPaths(n,"db.copy"))).replace("'{SQLITE_IMPLEMENTATION_FOLDER_PATH}'",o.phpVar(n)).replace("'{SQLITE_PLUGIN}'",o.phpVar(o.joinPaths(n,"load.php"))),a=o.joinPaths(await e.documentRoot,"wp-content/db.php"),l=`<?php
619
619
  // Do not preload this if WordPress comes with a custom db.php file.
620
620
  if(file_exists(${o.phpVar(a)})) {
621
621
  return;
622
622
  }
623
- ?>`,p="/internal/shared/mu-plugins/sqlite-database-integration.php";await e.writeFile(p,u+s),await e.writeFile("/internal/shared/preload/0-sqlite.php",u+`<?php
623
+ ?>`,u="/internal/shared/mu-plugins/sqlite-database-integration.php";await e.writeFile(u,l+s),await e.writeFile("/internal/shared/preload/0-sqlite.php",l+`<?php
624
624
 
625
625
  /**
626
626
  * Loads the SQLite integration plugin before WordPress is loaded
@@ -670,7 +670,7 @@ class Playground_SQLite_Integration_Loader {
670
670
  $GLOBALS['wpdb']->$name = $value;
671
671
  }
672
672
  protected function load_sqlite_integration() {
673
- require_once ${o.phpVar(p)};
673
+ require_once ${o.phpVar(u)};
674
674
  }
675
675
  }
676
676
  $wpdb = $GLOBALS['wpdb'] = new Playground_SQLite_Integration_Loader();
@@ -692,5 +692,5 @@ if(!function_exists('mysqli_connect')) {
692
692
  var_dump(isset($wpdb));
693
693
  die("SQLite integration not loaded " . get_class($wpdb));
694
694
  }
695
- `)}async function P(e,i){e.mkdir("/tmp/unzipped-wordpress"),await l.unzipFile(e,i,"/tmp/unzipped-wordpress"),e.fileExists("/tmp/unzipped-wordpress/wordpress.zip")&&await l.unzipFile(e,"/tmp/unzipped-wordpress/wordpress.zip","/tmp/unzipped-wordpress");let n=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(o.joinPaths(n,"wp-config-sample.php"))){const t=e.listFiles(n);if(t.length){const r=t[0];e.fileExists(o.joinPaths(n,r,"wp-config-sample.php"))&&(n=o.joinPaths(n,r))}}if(e.isDir(e.documentRoot)&&v(e.documentRoot,e)){for(const t of e.listFiles(n)){const r=o.joinPaths(n,t),s=o.joinPaths(e.documentRoot,t);e.mv(r,s)}e.rmdir(n,{recursive:!0})}else e.mv(n,e.documentRoot);!e.fileExists(o.joinPaths(e.documentRoot,"wp-config.php"))&&e.fileExists(o.joinPaths(e.documentRoot,"wp-config-sample.php"))&&e.writeFile(o.joinPaths(e.documentRoot,"wp-config.php"),e.readFileAsText(o.joinPaths(e.documentRoot,"/wp-config-sample.php")))}function v(e,i){const n=i.listFiles(e);return n.length===0||n.length===1&&n[0]==="playground-site-metadata.json"}const L=l.createMemoizedFetch(fetch);async function x(e="latest"){if(e.startsWith("https://")||e.startsWith("http://")){const t=await crypto.subtle.digest("SHA-1",new TextEncoder().encode(e)),r=Array.from(new Uint8Array(t)).map(s=>s.toString(16).padStart(2,"0")).join("");return{releaseUrl:e,version:"custom-"+r.substring(0,8),source:"inferred"}}else if(e==="trunk"||e==="nightly")return{releaseUrl:"https://wordpress.org/nightly-builds/wordpress-latest.zip",version:"nightly-"+new Date().toISOString().split("T")[0],source:"inferred"};let n=await(await L("https://api.wordpress.org/core/version-check/1.7/?channel=beta")).json();n=n.offers.filter(t=>t.response==="autoupdate");for(const t of n){if(e==="beta"&&t.version.includes("beta"))return{releaseUrl:t.download,version:t.version,source:"api"};if(e==="latest"&&!t.version.includes("beta"))return{releaseUrl:t.download,version:t.version,source:"api"};if(t.version.substring(0,e.length)===e)return{releaseUrl:t.download,version:t.version,source:"api"}}return{releaseUrl:`https://wordpress.org/wordpress-${e}.zip`,version:e,source:"inferred"}}exports.bootRequestHandler=h;exports.bootWordPress=R;exports.defineWpConfigConstants=_;exports.ensureWpConfig=c;exports.getFileNotFoundActionForWordPress=g;exports.getLoadedWordPressVersion=S;exports.preloadPhpInfoRoute=b;exports.preloadSqliteIntegration=y;exports.resolveWordPressRelease=x;exports.setupPlatformLevelMuPlugins=m;exports.unzipWordPress=P;exports.versionStringToLoadedWordPressVersion=$;exports.wordPressRewriteRules=w;
695
+ `)}async function k(e,r){e.mkdir("/tmp/unzipped-wordpress"),await p.unzipFile(e,r,"/tmp/unzipped-wordpress"),e.fileExists("/tmp/unzipped-wordpress/wordpress.zip")&&await p.unzipFile(e,"/tmp/unzipped-wordpress/wordpress.zip","/tmp/unzipped-wordpress");let n=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(o.joinPaths(n,"wp-config-sample.php"))){const i=e.listFiles(n);if(i.length){const s=i[0];e.fileExists(o.joinPaths(n,s,"wp-config-sample.php"))&&(n=o.joinPaths(n,s))}}const t=(i,s,a)=>{if(a.isDir(i)&&a.isDir(s))for(const l of a.listFiles(i)){const u=o.joinPaths(i,l),E=o.joinPaths(s,l);t(u,E,a)}else{if(a.fileExists(s)){const l=i.replace(/^\/tmp\/unzipped-wordpress\//,"/");_.logger.warn(`Skipping ${l} because something exists at the target path.`);return}a.mv(i,s)}};t(n,e.documentRoot,e),e.fileExists(n)&&e.rmdir(n,{recursive:!0}),!e.fileExists(o.joinPaths(e.documentRoot,"wp-config.php"))&&e.fileExists(o.joinPaths(e.documentRoot,"wp-config-sample.php"))&&e.writeFile(o.joinPaths(e.documentRoot,"wp-config.php"),e.readFileAsText(o.joinPaths(e.documentRoot,"/wp-config-sample.php")))}const L=p.createMemoizedFetch(fetch);async function x(e="latest"){if(e.startsWith("https://")||e.startsWith("http://")){const t=await crypto.subtle.digest("SHA-1",new TextEncoder().encode(e)),i=Array.from(new Uint8Array(t)).map(s=>s.toString(16).padStart(2,"0")).join("");return{releaseUrl:e,version:"custom-"+i.substring(0,8),source:"inferred"}}else if(e==="trunk"||e==="nightly")return{releaseUrl:"https://wordpress.org/nightly-builds/wordpress-latest.zip",version:"nightly-"+new Date().toISOString().split("T")[0],source:"inferred"};let n=await(await L("https://api.wordpress.org/core/version-check/1.7/?channel=beta")).json();n=n.offers.filter(t=>t.response==="autoupdate");for(const t of n){if(e==="beta"&&t.version.includes("beta"))return{releaseUrl:t.download,version:t.version,source:"api"};if(e==="latest"&&!t.version.includes("beta"))return{releaseUrl:t.download,version:t.version,source:"api"};if(t.version.substring(0,e.length)===e)return{releaseUrl:t.download,version:t.version,source:"api"}}return{releaseUrl:`https://wordpress.org/wordpress-${e}.zip`,version:e,source:"inferred"}}exports.bootRequestHandler=g;exports.bootWordPress=S;exports.defineWpConfigConstants=c;exports.ensureWpConfig=h;exports.getFileNotFoundActionForWordPress=$;exports.getLoadedWordPressVersion=v;exports.preloadPhpInfoRoute=y;exports.preloadSqliteIntegration=P;exports.resolveWordPressRelease=x;exports.setupPlatformLevelMuPlugins=b;exports.unzipWordPress=k;exports.versionStringToLoadedWordPressVersion=w;exports.wordPressRewriteRules=m;
696
696
  //# sourceMappingURL=index.cjs.map
package/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import { phpVars as _, joinPaths as a, dirname as c, basename as h, phpVar as d } from "@php-wasm/util";
2
- import { createMemoizedFetch as g, unzipFile as l } from "@wp-playground/common";
3
- import { sandboxedSpawnHandlerFactory as $, PHPRequestHandler as w, withPHPIniValues as m, PHP as b, setPhpIniEntries as y, writeFiles as k, proxyFileSystem as P, rotatePHPRuntime as E } from "@php-wasm/universal";
4
- import { logger as T } from "@php-wasm/logger";
1
+ import { phpVars as h, joinPaths as s, dirname as $, basename as g, phpVar as l } from "@php-wasm/util";
2
+ import { createMemoizedFetch as w, unzipFile as p } from "@wp-playground/common";
3
+ import { logger as _ } from "@php-wasm/logger";
4
+ import { sandboxedSpawnHandlerFactory as m, PHPRequestHandler as b, withPHPIniValues as y, PHP as k, setPhpIniEntries as P, writeFiles as E, proxyFileSystem as T, rotatePHPRuntime as S } from "@php-wasm/universal";
5
5
  const R = `<?php
6
6
 
7
7
  /**
@@ -348,14 +348,14 @@ function skip_whitespace($tokens) {
348
348
  return $output;
349
349
  }
350
350
  `;
351
- async function S(e, i, n, t = "rewrite") {
352
- const r = _({ wpConfigPath: i, constants: n, whenAlreadyDefined: t });
351
+ async function v(e, r, n, t = "rewrite") {
352
+ const i = h({ wpConfigPath: r, constants: n, whenAlreadyDefined: t });
353
353
  if ((await e.run({
354
354
  code: `<?php ob_start(); ?>
355
355
  ${R}
356
- $wp_config_path = ${r.wpConfigPath};
356
+ $wp_config_path = ${i.wpConfigPath};
357
357
  $wp_config = file_get_contents($wp_config_path);
358
- $new_wp_config = rewrite_wp_config_to_define_constants($wp_config, ${r.constants}, ${r.whenAlreadyDefined});
358
+ $new_wp_config = rewrite_wp_config_to_define_constants($wp_config, ${i.constants}, ${i.whenAlreadyDefined});
359
359
  $return_value = file_put_contents($wp_config_path, $new_wp_config);
360
360
  ob_clean();
361
361
  echo false === $return_value ? '0' : '1';
@@ -364,56 +364,56 @@ async function S(e, i, n, t = "rewrite") {
364
364
  })).text !== "1")
365
365
  throw new Error("Failed to rewrite constants in wp-config.php.");
366
366
  }
367
- async function v(e, i) {
368
- const n = a(i, "wp-config.php"), t = {
367
+ async function x(e, r) {
368
+ const n = s(r, "wp-config.php"), t = {
369
369
  DB_NAME: "wordpress"
370
370
  };
371
- !e.fileExists(n) && e.fileExists(a(i, "wp-config-sample.php")) && await e.writeFile(
371
+ !e.fileExists(n) && e.fileExists(s(r, "wp-config-sample.php")) && await e.writeFile(
372
372
  n,
373
373
  await e.readFileAsBuffer(
374
- a(i, "wp-config-sample.php")
374
+ s(r, "wp-config-sample.php")
375
375
  )
376
- ), await S(e, n, t, "skip");
376
+ ), await v(e, n, t, "skip");
377
377
  }
378
- async function H(e) {
379
- var t, r;
380
- const i = await x(e), n = await i.getPrimaryPhp();
381
- if ((t = e.hooks) != null && t.beforeWordPressFiles && await e.hooks.beforeWordPressFiles(n), e.wordPressZip && await A(n, await e.wordPressZip), e.constants)
382
- for (const s in e.constants)
383
- n.defineConstant(s, e.constants[s]);
384
- if (e.dataSqlPath && (n.defineConstant("DB_DIR", c(e.dataSqlPath)), n.defineConstant("DB_FILE", h(e.dataSqlPath))), n.defineConstant("WP_HOME", e.siteUrl), n.defineConstant("WP_SITEURL", e.siteUrl), await v(n, i.documentRoot), (r = e.hooks) != null && r.beforeDatabaseSetup && await e.hooks.beforeDatabaseSetup(n), e.sqliteIntegrationPluginZip && await D(
378
+ async function M(e) {
379
+ var t, i;
380
+ const r = await L(e), n = await r.getPrimaryPhp();
381
+ if ((t = e.hooks) != null && t.beforeWordPressFiles && await e.hooks.beforeWordPressFiles(n), e.wordPressZip && await F(n, await e.wordPressZip), e.constants)
382
+ for (const o in e.constants)
383
+ n.defineConstant(o, e.constants[o]);
384
+ if (e.dataSqlPath && (n.defineConstant("DB_DIR", $(e.dataSqlPath)), n.defineConstant("DB_FILE", g(e.dataSqlPath))), n.defineConstant("WP_HOME", e.siteUrl), n.defineConstant("WP_SITEURL", e.siteUrl), await x(n, r.documentRoot), (i = e.hooks) != null && i.beforeDatabaseSetup && await e.hooks.beforeDatabaseSetup(n), e.sqliteIntegrationPluginZip && await A(
385
385
  n,
386
386
  await e.sqliteIntegrationPluginZip
387
- ), !e.dataSqlPath && (await f(n) || await L(n), !await f(n)))
387
+ ), !e.dataSqlPath && (await f(n) || await I(n), !await f(n)))
388
388
  throw new Error("WordPress installation has failed.");
389
- return i;
389
+ return r;
390
390
  }
391
- async function x(e) {
392
- const i = e.spawnHandler ?? $;
393
- async function n(r, s) {
394
- const o = new b(await e.createPhpRuntime());
395
- return e.sapiName && o.setSapiName(e.sapiName), r && (o.requestHandler = r), e.phpIniEntries && y(o, e.phpIniEntries), s ? (await O(o), await k(o, "/", e.createFiles || {}), await C(
396
- o,
397
- a(new URL(e.siteUrl).pathname, "phpinfo.php")
398
- )) : P(await r.getPrimaryPhp(), o, [
391
+ async function L(e) {
392
+ const r = e.spawnHandler ?? m;
393
+ async function n(i, o) {
394
+ const a = new k(await e.createPhpRuntime());
395
+ return e.sapiName && a.setSapiName(e.sapiName), i && (a.requestHandler = i), e.phpIniEntries && P(a, e.phpIniEntries), o ? (await C(a), await E(a, "/", e.createFiles || {}), await D(
396
+ a,
397
+ s(new URL(e.siteUrl).pathname, "phpinfo.php")
398
+ )) : T(await i.getPrimaryPhp(), a, [
399
399
  "/tmp",
400
- r.documentRoot,
400
+ i.documentRoot,
401
401
  "/internal/shared"
402
- ]), i && await o.setSpawnHandler(
403
- i(r.processManager)
404
- ), E({
405
- php: o,
406
- cwd: r.documentRoot,
402
+ ]), r && await a.setSpawnHandler(
403
+ r(i.processManager)
404
+ ), S({
405
+ php: a,
406
+ cwd: i.documentRoot,
407
407
  recreateRuntime: e.createPhpRuntime,
408
408
  maxRequests: 400
409
- }), e.onPHPInstanceCreated && await e.onPHPInstanceCreated(o), o;
409
+ }), e.onPHPInstanceCreated && await e.onPHPInstanceCreated(a), a;
410
410
  }
411
- const t = new w({
412
- phpFactory: async ({ isPrimary: r }) => n(t, r),
411
+ const t = new b({
412
+ phpFactory: async ({ isPrimary: i }) => n(t, i),
413
413
  documentRoot: e.documentRoot || "/wordpress",
414
414
  absoluteUrl: e.siteUrl,
415
- rewriteRules: W,
416
- getFileNotFoundAction: e.getFileNotFoundAction ?? I,
415
+ rewriteRules: O,
416
+ getFileNotFoundAction: e.getFileNotFoundAction ?? U,
417
417
  cookieStore: e.cookieStore
418
418
  });
419
419
  return t;
@@ -437,8 +437,8 @@ async function f(e) {
437
437
  }
438
438
  })).text === "1";
439
439
  }
440
- async function L(e) {
441
- await m(
440
+ async function I(e) {
441
+ await y(
442
442
  e,
443
443
  {
444
444
  disable_functions: "fsockopen",
@@ -480,33 +480,33 @@ async function L(e) {
480
480
  env: {
481
481
  DOCUMENT_ROOT: e.documentRoot
482
482
  }
483
- })).text !== "1" && T.warn("Failed to default to pretty permalinks after WP install.");
483
+ })).text !== "1" && _.warn("Failed to default to pretty permalinks after WP install.");
484
484
  }
485
- function I(e) {
485
+ function U(e) {
486
486
  return {
487
487
  type: "internal-redirect",
488
488
  uri: "/index.php"
489
489
  };
490
490
  }
491
491
  async function z(e) {
492
- const { php: i, reap: n } = await e.processManager.acquirePHPInstance({
492
+ const { php: r, reap: n } = await e.processManager.acquirePHPInstance({
493
493
  considerPrimary: !0
494
494
  });
495
495
  try {
496
- const r = (await i.run({
496
+ const i = (await r.run({
497
497
  code: `<?php
498
498
  require '${e.documentRoot}/wp-includes/version.php';
499
499
  echo $wp_version;
500
500
  `
501
501
  })).text;
502
- if (!r)
502
+ if (!i)
503
503
  throw new Error("Unable to read loaded WordPress version.");
504
- return U(r);
504
+ return W(i);
505
505
  } finally {
506
506
  n();
507
507
  }
508
508
  }
509
- function U(e) {
509
+ function W(e) {
510
510
  if (/-(alpha|beta|RC)\d*-\d+$/.test(e))
511
511
  return "nightly";
512
512
  if (/-(beta|RC)\d*$/.test(e))
@@ -514,13 +514,13 @@ function U(e) {
514
514
  const t = e.match(/^(\d+\.\d+)(?:\.\d+)?$/);
515
515
  return t !== null ? t[1] : e;
516
516
  }
517
- const W = [
517
+ const O = [
518
518
  {
519
519
  match: /^\/(.*?)(\/wp-(content|admin|includes)\/.*)/g,
520
520
  replacement: "$2"
521
521
  }
522
522
  ];
523
- async function O(e) {
523
+ async function C(e) {
524
524
  await e.mkdir("/internal/shared/mu-plugins"), await e.writeFile(
525
525
  "/internal/shared/preload/env.php",
526
526
  `<?php
@@ -763,13 +763,13 @@ async function O(e) {
763
763
  })();`
764
764
  );
765
765
  }
766
- async function C(e, i = "/phpinfo.php") {
766
+ async function D(e, r = "/phpinfo.php") {
767
767
  await e.writeFile(
768
768
  "/internal/shared/preload/phpinfo.php",
769
769
  `<?php
770
770
  // Render PHPInfo if the requested page is /phpinfo.php
771
- if ( isset($_SERVER['REQUEST_URI']) && ${d(
772
- i
771
+ if ( isset($_SERVER['REQUEST_URI']) && ${l(
772
+ r
773
773
  )} === $_SERVER['REQUEST_URI'] ) {
774
774
  phpinfo();
775
775
  exit;
@@ -777,29 +777,29 @@ async function C(e, i = "/phpinfo.php") {
777
777
  `
778
778
  );
779
779
  }
780
- async function D(e, i) {
780
+ async function A(e, r) {
781
781
  await e.isDir("/tmp/sqlite-database-integration") && await e.rmdir("/tmp/sqlite-database-integration", {
782
782
  recursive: !0
783
- }), await e.mkdir("/tmp/sqlite-database-integration"), await l(e, i, "/tmp/sqlite-database-integration");
783
+ }), await e.mkdir("/tmp/sqlite-database-integration"), await p(e, r, "/tmp/sqlite-database-integration");
784
784
  const n = "/internal/shared/sqlite-database-integration", t = `/tmp/sqlite-database-integration/${(await e.listFiles("/tmp/sqlite-database-integration"))[0]}`;
785
785
  await e.mv(t, n), e.defineConstant("WP_SQLITE_AST_DRIVER", !0), await e.defineConstant("SQLITE_MAIN_FILE", "1");
786
- const s = (await e.readFileAsText(
787
- a(n, "db.copy")
786
+ const o = (await e.readFileAsText(
787
+ s(n, "db.copy")
788
788
  )).replace(
789
789
  "'{SQLITE_IMPLEMENTATION_FOLDER_PATH}'",
790
- d(n)
790
+ l(n)
791
791
  ).replace(
792
792
  "'{SQLITE_PLUGIN}'",
793
- d(a(n, "load.php"))
794
- ), o = a(await e.documentRoot, "wp-content/db.php"), u = `<?php
793
+ l(s(n, "load.php"))
794
+ ), a = s(await e.documentRoot, "wp-content/db.php"), d = `<?php
795
795
  // Do not preload this if WordPress comes with a custom db.php file.
796
- if(file_exists(${d(o)})) {
796
+ if(file_exists(${l(a)})) {
797
797
  return;
798
798
  }
799
- ?>`, p = "/internal/shared/mu-plugins/sqlite-database-integration.php";
800
- await e.writeFile(p, u + s), await e.writeFile(
799
+ ?>`, u = "/internal/shared/mu-plugins/sqlite-database-integration.php";
800
+ await e.writeFile(u, d + o), await e.writeFile(
801
801
  "/internal/shared/preload/0-sqlite.php",
802
- u + `<?php
802
+ d + `<?php
803
803
 
804
804
  /**
805
805
  * Loads the SQLite integration plugin before WordPress is loaded
@@ -849,7 +849,7 @@ class Playground_SQLite_Integration_Loader {
849
849
  $GLOBALS['wpdb']->$name = $value;
850
850
  }
851
851
  protected function load_sqlite_integration() {
852
- require_once ${d(p)};
852
+ require_once ${l(u)};
853
853
  }
854
854
  }
855
855
  $wpdb = $GLOBALS['wpdb'] = new Playground_SQLite_Integration_Loader();
@@ -877,52 +877,59 @@ if(!function_exists('mysqli_connect')) {
877
877
  `
878
878
  );
879
879
  }
880
- async function A(e, i) {
881
- e.mkdir("/tmp/unzipped-wordpress"), await l(e, i, "/tmp/unzipped-wordpress"), e.fileExists("/tmp/unzipped-wordpress/wordpress.zip") && await l(
880
+ async function F(e, r) {
881
+ e.mkdir("/tmp/unzipped-wordpress"), await p(e, r, "/tmp/unzipped-wordpress"), e.fileExists("/tmp/unzipped-wordpress/wordpress.zip") && await p(
882
882
  e,
883
883
  "/tmp/unzipped-wordpress/wordpress.zip",
884
884
  "/tmp/unzipped-wordpress"
885
885
  );
886
886
  let n = e.fileExists("/tmp/unzipped-wordpress/wordpress") ? "/tmp/unzipped-wordpress/wordpress" : e.fileExists("/tmp/unzipped-wordpress/build") ? "/tmp/unzipped-wordpress/build" : "/tmp/unzipped-wordpress";
887
- if (!e.fileExists(a(n, "wp-config-sample.php"))) {
888
- const t = e.listFiles(n);
889
- if (t.length) {
890
- const r = t[0];
887
+ if (!e.fileExists(s(n, "wp-config-sample.php"))) {
888
+ const i = e.listFiles(n);
889
+ if (i.length) {
890
+ const o = i[0];
891
891
  e.fileExists(
892
- a(n, r, "wp-config-sample.php")
893
- ) && (n = a(n, r));
892
+ s(n, o, "wp-config-sample.php")
893
+ ) && (n = s(n, o));
894
894
  }
895
895
  }
896
- if (e.isDir(e.documentRoot) && F(e.documentRoot, e)) {
897
- for (const t of e.listFiles(n)) {
898
- const r = a(n, t), s = a(e.documentRoot, t);
899
- e.mv(r, s);
896
+ const t = (i, o, a) => {
897
+ if (a.isDir(i) && a.isDir(o))
898
+ for (const d of a.listFiles(i)) {
899
+ const u = s(i, d), c = s(o, d);
900
+ t(u, c, a);
901
+ }
902
+ else {
903
+ if (a.fileExists(o)) {
904
+ const d = i.replace(
905
+ /^\/tmp\/unzipped-wordpress\//,
906
+ "/"
907
+ );
908
+ _.warn(
909
+ `Skipping ${d} because something exists at the target path.`
910
+ );
911
+ return;
912
+ }
913
+ a.mv(i, o);
900
914
  }
901
- e.rmdir(n, { recursive: !0 });
902
- } else
903
- e.mv(n, e.documentRoot);
904
- !e.fileExists(a(e.documentRoot, "wp-config.php")) && e.fileExists(a(e.documentRoot, "wp-config-sample.php")) && e.writeFile(
905
- a(e.documentRoot, "wp-config.php"),
915
+ };
916
+ t(n, e.documentRoot, e), e.fileExists(n) && e.rmdir(n, { recursive: !0 }), !e.fileExists(s(e.documentRoot, "wp-config.php")) && e.fileExists(s(e.documentRoot, "wp-config-sample.php")) && e.writeFile(
917
+ s(e.documentRoot, "wp-config.php"),
906
918
  e.readFileAsText(
907
- a(e.documentRoot, "/wp-config-sample.php")
919
+ s(e.documentRoot, "/wp-config-sample.php")
908
920
  )
909
921
  );
910
922
  }
911
- function F(e, i) {
912
- const n = i.listFiles(e);
913
- return n.length === 0 || n.length === 1 && // TODO: use a constant from a site storage package
914
- n[0] === "playground-site-metadata.json";
915
- }
916
- const G = g(fetch);
923
+ const G = w(fetch);
917
924
  async function Q(e = "latest") {
918
925
  if (e.startsWith("https://") || e.startsWith("http://")) {
919
926
  const t = await crypto.subtle.digest(
920
927
  "SHA-1",
921
928
  new TextEncoder().encode(e)
922
- ), r = Array.from(new Uint8Array(t)).map((s) => s.toString(16).padStart(2, "0")).join("");
929
+ ), i = Array.from(new Uint8Array(t)).map((o) => o.toString(16).padStart(2, "0")).join("");
923
930
  return {
924
931
  releaseUrl: e,
925
- version: "custom-" + r.substring(0, 8),
932
+ version: "custom-" + i.substring(0, 8),
926
933
  source: "inferred"
927
934
  };
928
935
  } else if (e === "trunk" || e === "nightly")
@@ -964,18 +971,18 @@ async function Q(e = "latest") {
964
971
  };
965
972
  }
966
973
  export {
967
- x as bootRequestHandler,
968
- H as bootWordPress,
969
- S as defineWpConfigConstants,
970
- v as ensureWpConfig,
971
- I as getFileNotFoundActionForWordPress,
974
+ L as bootRequestHandler,
975
+ M as bootWordPress,
976
+ v as defineWpConfigConstants,
977
+ x as ensureWpConfig,
978
+ U as getFileNotFoundActionForWordPress,
972
979
  z as getLoadedWordPressVersion,
973
- C as preloadPhpInfoRoute,
974
- D as preloadSqliteIntegration,
980
+ D as preloadPhpInfoRoute,
981
+ A as preloadSqliteIntegration,
975
982
  Q as resolveWordPressRelease,
976
- O as setupPlatformLevelMuPlugins,
977
- A as unzipWordPress,
978
- U as versionStringToLoadedWordPressVersion,
979
- W as wordPressRewriteRules
983
+ C as setupPlatformLevelMuPlugins,
984
+ F as unzipWordPress,
985
+ W as versionStringToLoadedWordPressVersion,
986
+ O as wordPressRewriteRules
980
987
  };
981
988
  //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wp-playground/wordpress",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
4
4
  "description": "WordPress-related plumbing for WordPress Playground",
5
5
  "repository": {
6
6
  "type": "git",
@@ -35,18 +35,18 @@
35
35
  "access": "public",
36
36
  "directory": "../../../dist/packages/playground/wordpress"
37
37
  },
38
- "gitHead": "8418e46be011a4a0f4d16d55fbf8e887476fea64",
38
+ "gitHead": "6355c320ae2de93d4a0176e45ded2ad4cc6f4ae2",
39
39
  "dependencies": {
40
40
  "express": "4.21.2",
41
41
  "ini": "4.1.2",
42
42
  "wasm-feature-detect": "1.8.0",
43
43
  "ws": "8.18.1",
44
44
  "yargs": "17.7.2",
45
- "@php-wasm/universal": "2.0.2",
46
- "@php-wasm/util": "2.0.2",
47
- "@php-wasm/logger": "2.0.2",
48
- "@wp-playground/common": "2.0.2",
49
- "@php-wasm/node": "2.0.2"
45
+ "@php-wasm/universal": "2.0.3",
46
+ "@php-wasm/util": "2.0.3",
47
+ "@php-wasm/logger": "2.0.3",
48
+ "@wp-playground/common": "2.0.3",
49
+ "@php-wasm/node": "2.0.3"
50
50
  },
51
51
  "overrides": {
52
52
  "rollup": "^4.34.6",