@wp-playground/wordpress 3.1.15 → 3.1.16

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/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("@php-wasm/util"),p=require("@wp-playground/common"),f=require("@php-wasm/logger"),d=require("@php-wasm/universal"),$=`<?php
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("@php-wasm/util"),p=require("@wp-playground/common"),_=require("@php-wasm/logger"),d=require("@php-wasm/universal"),$=`<?php
2
2
 
3
3
  /**
4
4
  * Transforms the "wp-config.php" file.
@@ -483,7 +483,7 @@ class WP_Config_Transformer {
483
483
  $transformer = WP_Config_Transformer::from_file($wp_config_path);
484
484
  $transformer->define_constants(${i.constants});
485
485
  $transformer->to_file($wp_config_path);
486
- `})).errors.length>0)throw new Error("Failed to rewrite constants in wp-config.php.")}async function x(t){const e=await w(t);return await m(e,t),e}async function m(t,e){var c,o;const n=await t.getPrimaryPhp();if((c=e.hooks)!=null&&c.beforeWordPressFiles&&await e.hooks.beforeWordPressFiles(n),e.wordPressZip&&await R(n,await e.wordPressZip),e.constants)for(const l in e.constants)n.defineConstant(l,e.constants[l]);e.dataSqlPath&&(n.defineConstant("DB_DIR",r.dirname(e.dataSqlPath)),n.defineConstant("DB_FILE",r.basename(e.dataSqlPath))),n.defineConstant("WP_HOME",e.siteUrl),n.defineConstant("WP_SITEURL",e.siteUrl),await g(n,t.documentRoot),(o=e.hooks)!=null&&o.beforeDatabaseSetup&&await e.hooks.beforeDatabaseSetup(n);let i=!1;e.sqliteIntegrationPluginZip&&(i=!0,await E(n,await e.sqliteIntegrationPluginZip));const a=e.wordpressInstallMode??"download-and-install",s=!!e.dataSqlPath;if(["download-and-install","install-from-existing-files"].includes(a)){await _(t,{usesSqlite:i,hasCustomDatabasePath:s});try{await h(n)}catch(l){throw s||await u(t),l}s||await u(t)}else if(a==="install-from-existing-files-if-needed"){if(await _(t,{usesSqlite:i,hasCustomDatabasePath:s}),!await P(n))try{await h(n)}catch(l){throw s||await u(t),l}s||await u(t)}return t}async function _(t,{usesSqlite:e,hasCustomDatabasePath:n}){const i=await t.getPrimaryPhp();if(i.isFile("/internal/shared/preload/0-sqlite.php"))return;const a=r.joinPaths(t.documentRoot,"wp-content/mu-plugins/sqlite-database-integration");if(!i.isDir(a)&&!e&&!n)throw new Error("Error connecting to the MySQL database.")}async function u(t){const e=await t.getPrimaryPhp();if(await L(e))return;if(e.isFile("/internal/shared/preload/0-sqlite.php"))throw new Error("Error connecting to the SQLite database.");const i=r.joinPaths(t.documentRoot,"wp-content/mu-plugins/sqlite-database-integration");throw e.isDir(i)?new Error("Error connecting to the SQLite database."):new Error("Error connecting to the MySQL database.")}async function w(t){const e=t.spawnHandler??d.sandboxedSpawnHandlerFactory;async function n(a,s=!1){const c=await t.createPhpRuntime(s),o=new d.PHP(c);if(t.sapiName&&o.setSapiName(t.sapiName),a&&(o.requestHandler=a),t.phpIniEntries&&d.setPhpIniEntries(o,t.phpIniEntries),o.defineConstant("WP_SQLITE_AST_DRIVER",!0),t.constants)for(const l in t.constants)o.defineConstant(l,t.constants[l]);return s&&!o.isFile("/internal/.boot-files-written")&&(await T(o),await d.writeFiles(o,"/",t.createFiles||{}),await v(o,r.joinPaths(new URL(t.siteUrl).pathname,"phpinfo.php")),await d.writeFiles(o,"/internal",{".boot-files-written":""})),e&&await o.setSpawnHandler(e(a?()=>a.instanceManager.acquirePHPInstance():void 0)),o.enableRuntimeRotation({recreateRuntime:t.createPhpRuntime,maxRequests:400}),t.onPHPInstanceCreated&&await t.onPHPInstanceCreated(o,{isPrimary:s}),o}const i=new d.PHPRequestHandler({documentRoot:t.documentRoot||"/wordpress",absoluteUrl:t.siteUrl,rewriteRules:b,pathAliases:t.pathAliases,getFileNotFoundAction:t.getFileNotFoundAction??k,cookieStore:t.cookieStore,php:t.maxPhpInstances===1?await n(void 0,!0):void 0,phpFactory:t.maxPhpInstances!==1?async({isPrimary:a})=>n(i,a):void 0,maxPhpInstances:t.maxPhpInstances});return i}async function P(t){return(await t.run({code:`<?php
486
+ `})).errors.length>0)throw new Error("Failed to rewrite constants in wp-config.php.")}async function x(t){const e=await w(t);return await m(e,t),e}async function m(t,e){var c,o;const n=await t.getPrimaryPhp();if((c=e.hooks)!=null&&c.beforeWordPressFiles&&await e.hooks.beforeWordPressFiles(n),e.wordPressZip&&await R(n,await e.wordPressZip),e.constants)for(const l in e.constants)n.defineConstant(l,e.constants[l]);e.dataSqlPath&&(n.defineConstant("DB_DIR",r.dirname(e.dataSqlPath)),n.defineConstant("DB_FILE",r.basename(e.dataSqlPath))),n.defineConstant("WP_HOME",e.siteUrl),n.defineConstant("WP_SITEURL",e.siteUrl),await g(n,t.documentRoot),(o=e.hooks)!=null&&o.beforeDatabaseSetup&&await e.hooks.beforeDatabaseSetup(n);let i=!1;e.sqliteIntegrationPluginZip&&(i=!0,await E(n,await e.sqliteIntegrationPluginZip));const a=e.wordpressInstallMode??"download-and-install",s=!!e.dataSqlPath;if(["download-and-install","install-from-existing-files"].includes(a)){await f(t,{usesSqlite:i,hasCustomDatabasePath:s});try{await h(n)}catch(l){throw s||await u(t),l}s||await u(t)}else if(a==="install-from-existing-files-if-needed"){if(await f(t,{usesSqlite:i,hasCustomDatabasePath:s}),!await P(n))try{await h(n)}catch(l){throw s||await u(t),l}s||await u(t)}return t}async function f(t,{usesSqlite:e,hasCustomDatabasePath:n}){const i=await t.getPrimaryPhp();if(i.isFile("/internal/shared/preload/0-sqlite.php"))return;const a=r.joinPaths(t.documentRoot,"wp-content/mu-plugins/sqlite-database-integration");if(!i.isDir(a)&&!e&&!n&&!L(i))throw new Error("Error connecting to the MySQL database.")}async function u(t){const e=await t.getPrimaryPhp();if(await C(e))return;if(e.isFile("/internal/shared/preload/0-sqlite.php"))throw new Error("Error connecting to the SQLite database.");const i=r.joinPaths(t.documentRoot,"wp-content/mu-plugins/sqlite-database-integration");throw e.isDir(i)?new Error("Error connecting to the SQLite database."):new Error("Error connecting to the MySQL database.")}async function w(t){const e=t.spawnHandler??d.sandboxedSpawnHandlerFactory;async function n(a,s=!1){const c=await t.createPhpRuntime(s),o=new d.PHP(c);if(t.sapiName&&o.setSapiName(t.sapiName),a&&(o.requestHandler=a),t.phpIniEntries&&d.setPhpIniEntries(o,t.phpIniEntries),o.defineConstant("WP_SQLITE_AST_DRIVER",!0),t.constants)for(const l in t.constants)o.defineConstant(l,t.constants[l]);return s&&!o.isFile("/internal/.boot-files-written")&&(await T(o),await d.writeFiles(o,"/",t.createFiles||{}),await v(o,r.joinPaths(new URL(t.siteUrl).pathname,"phpinfo.php")),await d.writeFiles(o,"/internal",{".boot-files-written":""})),e&&await o.setSpawnHandler(e(a?()=>a.instanceManager.acquirePHPInstance():void 0)),o.enableRuntimeRotation({recreateRuntime:t.createPhpRuntime,maxRequests:400}),t.onPHPInstanceCreated&&await t.onPHPInstanceCreated(o,{isPrimary:s}),o}const i=new d.PHPRequestHandler({documentRoot:t.documentRoot||"/wordpress",absoluteUrl:t.siteUrl,rewriteRules:b,pathAliases:t.pathAliases,getFileNotFoundAction:t.getFileNotFoundAction??k,cookieStore:t.cookieStore,php:t.maxPhpInstances===1?await n(void 0,!0):void 0,phpFactory:t.maxPhpInstances!==1?async({isPrimary:a})=>n(i,a):void 0,maxPhpInstances:t.maxPhpInstances});return i}async function P(t){return(await t.run({code:`<?php
487
487
  ob_start();
488
488
  $wp_load = getenv('DOCUMENT_ROOT') . '/wp-load.php';
489
489
  if (!file_exists($wp_load)) {
@@ -514,7 +514,7 @@ class WP_Config_Transformer {
514
514
  echo '0';
515
515
  }
516
516
  ob_end_flush();
517
- `,env:{DOCUMENT_ROOT:t.documentRoot}})).text!=="1"&&f.logger.warn("Failed to default to pretty permalinks after WP install.")}function k(t){return{type:"internal-redirect",uri:"/index.php"}}async function L(t){return(await t.run({code:`<?php
517
+ `,env:{DOCUMENT_ROOT:t.documentRoot}})).text!=="1"&&_.logger.warn("Failed to default to pretty permalinks after WP install.")}function k(t){return{type:"internal-redirect",uri:"/index.php"}}function L(t){const e=r.joinPaths(t.documentRoot,"wp-config.php");if(!t.isFile(e))return!1;const n=t.readFileAsText(e),i=n.match(/define\s*\(\s*['"]DB_NAME['"]\s*,\s*['"]([^'"]*)['"]/),a=n.match(/define\s*\(\s*['"]DB_USER['"]\s*,\s*['"]([^'"]*)['"]/);return!i||!a?!1:i[1]!=="database_name_here"&&a[1]!=="username_here"}async function C(t){return(await t.run({code:`<?php
518
518
  ob_start();
519
519
  $wp_load = getenv('DOCUMENT_ROOT') . '/wp-load.php';
520
520
  if (!file_exists($wp_load)) {
@@ -525,7 +525,7 @@ class WP_Config_Transformer {
525
525
  ob_clean();
526
526
  echo $wpdb->check_connection( false ) ? '1' : '0';
527
527
  ob_end_flush();
528
- `,env:{DOCUMENT_ROOT:t.documentRoot}})).text==="1"}async function C(t){const{php:e,reap:n}=await t.instanceManager.acquirePHPInstance();try{const a=(await e.run({code:`<?php
528
+ `,env:{DOCUMENT_ROOT:t.documentRoot}})).text==="1"}async function W(t){const{php:e,reap:n}=await t.instanceManager.acquirePHPInstance();try{const a=(await e.run({code:`<?php
529
529
  require '${t.documentRoot}/wp-includes/version.php';
530
530
  echo $wp_version;
531
531
  `})).text;if(!a)throw new Error("Unable to read loaded WordPress version.");return y(a)}finally{n()}}function y(t){if(/-(alpha|beta|RC)\d*-\d+$/.test(t))return"trunk";if(/-(beta|RC)\d*$/.test(t))return"beta";const i=t.match(/^(\d+\.\d+)(?:\.\d+)?$/);return i!==null?i[1]:t}const b=[{match:new RegExp("^(/[_0-9a-zA-Z-]+)?(/wp-(content|admin|includes)/.*)"),replacement:"$2"}];async function T(t){await t.mkdir("/internal/shared/mu-plugins"),await t.writeFile("/internal/shared/preload/env.php",`<?php
@@ -947,5 +947,5 @@ if(!function_exists('mysqli_connect')) {
947
947
  var_dump(isset($wpdb));
948
948
  die("SQLite integration not loaded " . get_class($wpdb));
949
949
  }
950
- `)}async function R(t,e){t.mkdir("/tmp/unzipped-wordpress"),await p.unzipFile(t,e,"/tmp/unzipped-wordpress"),t.fileExists("/tmp/unzipped-wordpress/wordpress.zip")&&await p.unzipFile(t,"/tmp/unzipped-wordpress/wordpress.zip","/tmp/unzipped-wordpress");let n=t.fileExists("/tmp/unzipped-wordpress/wordpress")?"/tmp/unzipped-wordpress/wordpress":t.fileExists("/tmp/unzipped-wordpress/build")?"/tmp/unzipped-wordpress/build":"/tmp/unzipped-wordpress";if(!t.fileExists(r.joinPaths(n,"wp-config-sample.php"))){const a=t.listFiles(n);if(a.length){const s=a[0];t.fileExists(r.joinPaths(n,s,"wp-config-sample.php"))&&(n=r.joinPaths(n,s))}}const i=(a,s,c)=>{if(c.isDir(a)&&c.isDir(s))for(const o of c.listFiles(a)){const l=r.joinPaths(a,o),S=r.joinPaths(s,o);i(l,S,c)}else{if(c.fileExists(s)){const o=a.replace(/^\/tmp\/unzipped-wordpress\//,"/");f.logger.warn(`Cannot unzip WordPress files at ${s}: ${o} already exists.`);return}c.mv(a,s)}};i(n,t.documentRoot,t),t.fileExists(n)&&t.rmdir(n,{recursive:!0}),!t.fileExists(r.joinPaths(t.documentRoot,"wp-config.php"))&&t.fileExists(r.joinPaths(t.documentRoot,"wp-config-sample.php"))&&t.writeFile(r.joinPaths(t.documentRoot,"wp-config.php"),t.readFileAsText(r.joinPaths(t.documentRoot,"/wp-config-sample.php")))}const W=p.createMemoizedFetch(fetch),O="https://github.com/WordPress/WordPress/archive/refs/heads/master.zip";async function q(t="latest"){if(t===null)t="latest";else if(t.startsWith("https://")||t.startsWith("http://")){const i=await crypto.subtle.digest("SHA-1",new TextEncoder().encode(t)),a=Array.from(new Uint8Array(i)).map(s=>s.toString(16).padStart(2,"0")).join("");return{releaseUrl:t,version:"custom-"+a.substring(0,8),source:"inferred"}}else if(t==="trunk"||t==="nightly"){const i=new Date().toISOString().split("T")[0];return{releaseUrl:`${O}?ts=${i}`,version:"trunk",source:"inferred"}}let n=await(await W("https://api.wordpress.org/core/version-check/1.7/?channel=beta")).json();n=n.offers.filter(i=>i.response==="autoupdate");for(const i of n){if(t==="beta"&&(i.version.includes("beta")||i.version.includes("RC")))return{releaseUrl:i.download,version:i.version,source:"api"};if(t==="latest"&&!i.version.includes("beta")&&!i.version.includes("RC"))return{releaseUrl:i.download,version:i.version,source:"api"};if(i.version.substring(0,t.length)===t)return{releaseUrl:i.download,version:i.version,source:"api"}}return t.match(/^\d+\.\d+\.0$/)&&(t=t.split(".").slice(0,2).join(".")),{releaseUrl:`https://wordpress.org/wordpress-${t}.zip`,version:t,source:"inferred"}}exports.bootRequestHandler=w;exports.bootWordPress=m;exports.bootWordPressAndRequestHandler=x;exports.defineWpConfigConstants=I;exports.ensureWpConfig=g;exports.getFileNotFoundActionForWordPress=k;exports.getLoadedWordPressVersion=C;exports.preloadPhpInfoRoute=v;exports.preloadSqliteIntegration=E;exports.resolveWordPressRelease=q;exports.setupPlatformLevelMuPlugins=T;exports.unzipWordPress=R;exports.versionStringToLoadedWordPressVersion=y;exports.wordPressRewriteRules=b;
950
+ `)}async function R(t,e){t.mkdir("/tmp/unzipped-wordpress"),await p.unzipFile(t,e,"/tmp/unzipped-wordpress"),t.fileExists("/tmp/unzipped-wordpress/wordpress.zip")&&await p.unzipFile(t,"/tmp/unzipped-wordpress/wordpress.zip","/tmp/unzipped-wordpress");let n=t.fileExists("/tmp/unzipped-wordpress/wordpress")?"/tmp/unzipped-wordpress/wordpress":t.fileExists("/tmp/unzipped-wordpress/build")?"/tmp/unzipped-wordpress/build":"/tmp/unzipped-wordpress";if(!t.fileExists(r.joinPaths(n,"wp-config-sample.php"))){const a=t.listFiles(n);if(a.length){const s=a[0];t.fileExists(r.joinPaths(n,s,"wp-config-sample.php"))&&(n=r.joinPaths(n,s))}}const i=(a,s,c)=>{if(c.isDir(a)&&c.isDir(s))for(const o of c.listFiles(a)){const l=r.joinPaths(a,o),S=r.joinPaths(s,o);i(l,S,c)}else{if(c.fileExists(s)){const o=a.replace(/^\/tmp\/unzipped-wordpress\//,"/");_.logger.warn(`Cannot unzip WordPress files at ${s}: ${o} already exists.`);return}c.mv(a,s)}};i(n,t.documentRoot,t),t.fileExists(n)&&t.rmdir(n,{recursive:!0}),!t.fileExists(r.joinPaths(t.documentRoot,"wp-config.php"))&&t.fileExists(r.joinPaths(t.documentRoot,"wp-config-sample.php"))&&t.writeFile(r.joinPaths(t.documentRoot,"wp-config.php"),t.readFileAsText(r.joinPaths(t.documentRoot,"/wp-config-sample.php")))}const O=p.createMemoizedFetch(fetch),q="https://github.com/WordPress/WordPress/archive/refs/heads/master.zip";async function A(t="latest"){if(t===null)t="latest";else if(t.startsWith("https://")||t.startsWith("http://")){const i=await crypto.subtle.digest("SHA-1",new TextEncoder().encode(t)),a=Array.from(new Uint8Array(i)).map(s=>s.toString(16).padStart(2,"0")).join("");return{releaseUrl:t,version:"custom-"+a.substring(0,8),source:"inferred"}}else if(t==="trunk"||t==="nightly"){const i=new Date().toISOString().split("T")[0];return{releaseUrl:`${q}?ts=${i}`,version:"trunk",source:"inferred"}}let n=await(await O("https://api.wordpress.org/core/version-check/1.7/?channel=beta")).json();n=n.offers.filter(i=>i.response==="autoupdate");for(const i of n){if(t==="beta"&&(i.version.includes("beta")||i.version.includes("RC")))return{releaseUrl:i.download,version:i.version,source:"api"};if(t==="latest"&&!i.version.includes("beta")&&!i.version.includes("RC"))return{releaseUrl:i.download,version:i.version,source:"api"};if(i.version.substring(0,t.length)===t)return{releaseUrl:i.download,version:i.version,source:"api"}}return t.match(/^\d+\.\d+\.0$/)&&(t=t.split(".").slice(0,2).join(".")),{releaseUrl:`https://wordpress.org/wordpress-${t}.zip`,version:t,source:"inferred"}}exports.bootRequestHandler=w;exports.bootWordPress=m;exports.bootWordPressAndRequestHandler=x;exports.defineWpConfigConstants=I;exports.ensureWpConfig=g;exports.getFileNotFoundActionForWordPress=k;exports.getLoadedWordPressVersion=W;exports.preloadPhpInfoRoute=v;exports.preloadSqliteIntegration=E;exports.resolveWordPressRelease=A;exports.setupPlatformLevelMuPlugins=T;exports.unzipWordPress=R;exports.versionStringToLoadedWordPressVersion=y;exports.wordPressRewriteRules=b;
951
951
  //# sourceMappingURL=index.cjs.map
package/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { phpVars as $, joinPaths as s, dirname as y, basename as b, phpVar as d } from "@php-wasm/util";
2
2
  import { createMemoizedFetch as P, unzipFile as p } from "@wp-playground/common";
3
3
  import { logger as g } from "@php-wasm/logger";
4
- import { sandboxedSpawnHandlerFactory as T, PHPRequestHandler as E, PHP as v, setPhpIniEntries as S, writeFiles as _, withPHPIniValues as R } from "@php-wasm/universal";
4
+ import { sandboxedSpawnHandlerFactory as T, PHPRequestHandler as E, PHP as v, setPhpIniEntries as S, writeFiles as f, withPHPIniValues as R } from "@php-wasm/universal";
5
5
  const m = `<?php
6
6
 
7
7
  /**
@@ -500,7 +500,7 @@ async function I(t, e) {
500
500
  })).errors.length > 0)
501
501
  throw new Error("Failed to auto-configure wp-config.php.");
502
502
  }
503
- async function Q(t, e, n) {
503
+ async function j(t, e, n) {
504
504
  const i = $({ wpConfigPath: e, constants: n });
505
505
  if ((await t.run({
506
506
  code: `${m}
@@ -512,19 +512,19 @@ async function Q(t, e, n) {
512
512
  })).errors.length > 0)
513
513
  throw new Error("Failed to rewrite constants in wp-config.php.");
514
514
  }
515
- async function j(t) {
515
+ async function V(t) {
516
516
  const e = await L(t);
517
517
  return await x(e, t), e;
518
518
  }
519
519
  async function x(t, e) {
520
520
  var c, r;
521
521
  const n = await t.getPrimaryPhp();
522
- if ((c = e.hooks) != null && c.beforeWordPressFiles && await e.hooks.beforeWordPressFiles(n), e.wordPressZip && await N(n, await e.wordPressZip), e.constants)
522
+ if ((c = e.hooks) != null && c.beforeWordPressFiles && await e.hooks.beforeWordPressFiles(n), e.wordPressZip && await D(n, await e.wordPressZip), e.constants)
523
523
  for (const l in e.constants)
524
524
  n.defineConstant(l, e.constants[l]);
525
525
  e.dataSqlPath && (n.defineConstant("DB_DIR", y(e.dataSqlPath)), n.defineConstant("DB_FILE", b(e.dataSqlPath))), n.defineConstant("WP_HOME", e.siteUrl), n.defineConstant("WP_SITEURL", e.siteUrl), await I(n, t.documentRoot), (r = e.hooks) != null && r.beforeDatabaseSetup && await e.hooks.beforeDatabaseSetup(n);
526
526
  let i = !1;
527
- e.sqliteIntegrationPluginZip && (i = !0, await F(
527
+ e.sqliteIntegrationPluginZip && (i = !0, await N(
528
528
  n,
529
529
  await e.sqliteIntegrationPluginZip
530
530
  ));
@@ -532,7 +532,7 @@ async function x(t, e) {
532
532
  if (["download-and-install", "install-from-existing-files"].includes(
533
533
  a
534
534
  )) {
535
- await f(t, {
535
+ await _(t, {
536
536
  usesSqlite: i,
537
537
  hasCustomDatabasePath: o
538
538
  });
@@ -543,7 +543,7 @@ async function x(t, e) {
543
543
  }
544
544
  o || await u(t);
545
545
  } else if (a === "install-from-existing-files-if-needed") {
546
- if (await f(t, {
546
+ if (await _(t, {
547
547
  usesSqlite: i,
548
548
  hasCustomDatabasePath: o
549
549
  }), !await w(n))
@@ -556,7 +556,7 @@ async function x(t, e) {
556
556
  }
557
557
  return t;
558
558
  }
559
- async function f(t, {
559
+ async function _(t, {
560
560
  usesSqlite: e,
561
561
  hasCustomDatabasePath: n
562
562
  }) {
@@ -567,12 +567,12 @@ async function f(t, {
567
567
  t.documentRoot,
568
568
  "wp-content/mu-plugins/sqlite-database-integration"
569
569
  );
570
- if (!i.isDir(a) && !e && !n)
570
+ if (!i.isDir(a) && !e && !n && !O(i))
571
571
  throw new Error("Error connecting to the MySQL database.");
572
572
  }
573
573
  async function u(t) {
574
574
  const e = await t.getPrimaryPhp();
575
- if (await O(e))
575
+ if (await A(e))
576
576
  return;
577
577
  if (e.isFile("/internal/shared/preload/0-sqlite.php"))
578
578
  throw new Error("Error connecting to the SQLite database.");
@@ -599,10 +599,10 @@ async function L(t) {
599
599
  * mechanism. It works, because secondary workers are only booted
600
600
  * once the primary worker has fully booted.
601
601
  */
602
- !r.isFile("/internal/.boot-files-written") && (await q(r), await _(r, "/", t.createFiles || {}), await U(
602
+ !r.isFile("/internal/.boot-files-written") && (await q(r), await f(r, "/", t.createFiles || {}), await F(
603
603
  r,
604
604
  s(new URL(t.siteUrl).pathname, "phpinfo.php")
605
- ), await _(r, "/internal", {
605
+ ), await f(r, "/internal", {
606
606
  ".boot-files-written": ""
607
607
  })), e && await r.setSpawnHandler(
608
608
  e(
@@ -616,7 +616,7 @@ async function L(t) {
616
616
  const i = new E({
617
617
  documentRoot: t.documentRoot || "/wordpress",
618
618
  absoluteUrl: t.siteUrl,
619
- rewriteRules: W,
619
+ rewriteRules: U,
620
620
  pathAliases: t.pathAliases,
621
621
  getFileNotFoundAction: t.getFileNotFoundAction ?? C,
622
622
  cookieStore: t.cookieStore,
@@ -720,7 +720,17 @@ function C(t) {
720
720
  uri: "/index.php"
721
721
  };
722
722
  }
723
- async function O(t) {
723
+ function O(t) {
724
+ const e = s(t.documentRoot, "wp-config.php");
725
+ if (!t.isFile(e)) return !1;
726
+ const n = t.readFileAsText(e), i = n.match(
727
+ /define\s*\(\s*['"]DB_NAME['"]\s*,\s*['"]([^'"]*)['"]/
728
+ ), a = n.match(
729
+ /define\s*\(\s*['"]DB_USER['"]\s*,\s*['"]([^'"]*)['"]/
730
+ );
731
+ return !i || !a ? !1 : i[1] !== "database_name_here" && a[1] !== "username_here";
732
+ }
733
+ async function A(t) {
724
734
  return (await t.run({
725
735
  code: `<?php
726
736
  ob_start();
@@ -739,7 +749,7 @@ async function O(t) {
739
749
  }
740
750
  })).text === "1";
741
751
  }
742
- async function V(t) {
752
+ async function Z(t) {
743
753
  const { php: e, reap: n } = await t.instanceManager.acquirePHPInstance();
744
754
  try {
745
755
  const a = (await e.run({
@@ -750,12 +760,12 @@ async function V(t) {
750
760
  })).text;
751
761
  if (!a)
752
762
  throw new Error("Unable to read loaded WordPress version.");
753
- return A(a);
763
+ return W(a);
754
764
  } finally {
755
765
  n();
756
766
  }
757
767
  }
758
- function A(t) {
768
+ function W(t) {
759
769
  if (/-(alpha|beta|RC)\d*-\d+$/.test(t))
760
770
  return "trunk";
761
771
  if (/-(beta|RC)\d*$/.test(t))
@@ -763,7 +773,7 @@ function A(t) {
763
773
  const i = t.match(/^(\d+\.\d+)(?:\.\d+)?$/);
764
774
  return i !== null ? i[1] : t;
765
775
  }
766
- const W = [
776
+ const U = [
767
777
  /**
768
778
  * Substitutes the multisite WordPress rewrite rule:
769
779
  *
@@ -1124,7 +1134,7 @@ async function q(t) {
1124
1134
  })();`
1125
1135
  );
1126
1136
  }
1127
- async function U(t, e = "/phpinfo.php") {
1137
+ async function F(t, e = "/phpinfo.php") {
1128
1138
  await t.writeFile(
1129
1139
  "/internal/shared/preload/phpinfo.php",
1130
1140
  `<?php
@@ -1138,7 +1148,7 @@ async function U(t, e = "/phpinfo.php") {
1138
1148
  `
1139
1149
  );
1140
1150
  }
1141
- async function F(t, e) {
1151
+ async function N(t, e) {
1142
1152
  await t.isDir("/tmp/sqlite-database-integration") && await t.rmdir("/tmp/sqlite-database-integration", {
1143
1153
  recursive: !0
1144
1154
  }), await t.mkdir("/tmp/sqlite-database-integration"), await p(t, e, "/tmp/sqlite-database-integration");
@@ -1247,7 +1257,7 @@ if(!function_exists('mysqli_connect')) {
1247
1257
  `
1248
1258
  );
1249
1259
  }
1250
- async function N(t, e) {
1260
+ async function D(t, e) {
1251
1261
  t.mkdir("/tmp/unzipped-wordpress"), await p(t, e, "/tmp/unzipped-wordpress"), t.fileExists("/tmp/unzipped-wordpress/wordpress.zip") && await p(
1252
1262
  t,
1253
1263
  "/tmp/unzipped-wordpress/wordpress.zip",
@@ -1290,8 +1300,8 @@ async function N(t, e) {
1290
1300
  )
1291
1301
  );
1292
1302
  }
1293
- const D = P(fetch), M = "https://github.com/WordPress/WordPress/archive/refs/heads/master.zip";
1294
- async function Z(t = "latest") {
1303
+ const M = P(fetch), G = "https://github.com/WordPress/WordPress/archive/refs/heads/master.zip";
1304
+ async function Y(t = "latest") {
1295
1305
  if (t === null)
1296
1306
  t = "latest";
1297
1307
  else if (t.startsWith("https://") || t.startsWith("http://")) {
@@ -1307,12 +1317,12 @@ async function Z(t = "latest") {
1307
1317
  } else if (t === "trunk" || t === "nightly") {
1308
1318
  const i = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
1309
1319
  return {
1310
- releaseUrl: `${M}?ts=${i}`,
1320
+ releaseUrl: `${G}?ts=${i}`,
1311
1321
  version: "trunk",
1312
1322
  source: "inferred"
1313
1323
  };
1314
1324
  }
1315
- let n = await (await D(
1325
+ let n = await (await M(
1316
1326
  "https://api.wordpress.org/core/version-check/1.7/?channel=beta"
1317
1327
  )).json();
1318
1328
  n = n.offers.filter(
@@ -1347,17 +1357,17 @@ async function Z(t = "latest") {
1347
1357
  export {
1348
1358
  L as bootRequestHandler,
1349
1359
  x as bootWordPress,
1350
- j as bootWordPressAndRequestHandler,
1351
- Q as defineWpConfigConstants,
1360
+ V as bootWordPressAndRequestHandler,
1361
+ j as defineWpConfigConstants,
1352
1362
  I as ensureWpConfig,
1353
1363
  C as getFileNotFoundActionForWordPress,
1354
- V as getLoadedWordPressVersion,
1355
- U as preloadPhpInfoRoute,
1356
- F as preloadSqliteIntegration,
1357
- Z as resolveWordPressRelease,
1364
+ Z as getLoadedWordPressVersion,
1365
+ F as preloadPhpInfoRoute,
1366
+ N as preloadSqliteIntegration,
1367
+ Y as resolveWordPressRelease,
1358
1368
  q as setupPlatformLevelMuPlugins,
1359
- N as unzipWordPress,
1360
- A as versionStringToLoadedWordPressVersion,
1361
- W as wordPressRewriteRules
1369
+ D as unzipWordPress,
1370
+ W as versionStringToLoadedWordPressVersion,
1371
+ U as wordPressRewriteRules
1362
1372
  };
1363
1373
  //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wp-playground/wordpress",
3
- "version": "3.1.15",
3
+ "version": "3.1.16",
4
4
  "description": "WordPress-related plumbing for WordPress Playground",
5
5
  "repository": {
6
6
  "type": "git",
@@ -35,7 +35,7 @@
35
35
  "access": "public",
36
36
  "directory": "../../../dist/packages/playground/wordpress"
37
37
  },
38
- "gitHead": "65a430c046c86341e7dc3cf6f30c9a5aeb8aa67d",
38
+ "gitHead": "19d0494cc31cfb83b895010fd756063bdbf6ff1f",
39
39
  "dependencies": {
40
40
  "express": "4.22.0",
41
41
  "fast-xml-parser": "^5.5.1",
@@ -45,11 +45,11 @@
45
45
  "wasm-feature-detect": "1.8.0",
46
46
  "ws": "8.18.3",
47
47
  "yargs": "17.7.2",
48
- "@php-wasm/universal": "3.1.15",
49
- "@php-wasm/util": "3.1.15",
50
- "@php-wasm/logger": "3.1.15",
51
- "@wp-playground/common": "3.1.15",
52
- "@php-wasm/node": "3.1.15"
48
+ "@php-wasm/universal": "3.1.16",
49
+ "@php-wasm/util": "3.1.16",
50
+ "@php-wasm/logger": "3.1.16",
51
+ "@wp-playground/common": "3.1.16",
52
+ "@php-wasm/node": "3.1.16"
53
53
  },
54
54
  "packageManager": "npm@10.9.2",
55
55
  "overrides": {