@wp-playground/wordpress 3.0.17 → 3.0.19

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 (3) hide show
  1. package/index.cjs +4 -4
  2. package/index.js +7 -7
  3. 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"),p=require("@wp-playground/common"),c=require("@php-wasm/logger"),d=require("@php-wasm/universal"),v=`<?php
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@php-wasm/util"),p=require("@wp-playground/common"),c=require("@php-wasm/logger"),d=require("@php-wasm/universal"),R=`<?php
2
2
 
3
3
  /**
4
4
  * Rewrites the wp-config.php file to ensure specific constants are defined
@@ -344,7 +344,7 @@ function skip_whitespace($tokens) {
344
344
  return $output;
345
345
  }
346
346
  `;async function _(e,t,n,i="rewrite"){const r=o.phpVars({wpConfigPath:t,constants:n,whenAlreadyDefined:i});if((await e.run({code:`<?php ob_start(); ?>
347
- ${v}
347
+ ${R}
348
348
  $wp_config_path = ${r.wpConfigPath};
349
349
  $wp_config = file_get_contents($wp_config_path);
350
350
  $new_wp_config = rewrite_wp_config_to_define_constants($wp_config, ${r.constants}, ${r.whenAlreadyDefined});
@@ -352,7 +352,7 @@ function skip_whitespace($tokens) {
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 h(e,t){const n=o.joinPaths(t,"wp-config.php"),i={DB_NAME:"wordpress"};!e.fileExists(n)&&e.fileExists(o.joinPaths(t,"wp-config-sample.php"))&&await e.writeFile(n,await e.readFileAsBuffer(o.joinPaths(t,"wp-config-sample.php"))),await _(e,n,i,"skip")}async function R(e){const t=await w(e);return await g(t,e),t}async function g(e,t){var i,r;const n=await e.getPrimaryPhp();if((i=t.hooks)!=null&&i.beforeWordPressFiles&&await t.hooks.beforeWordPressFiles(n),t.wordPressZip&&await E(n,await t.wordPressZip),t.constants)for(const a in t.constants)n.defineConstant(a,t.constants[a]);if(t.dataSqlPath&&(n.defineConstant("DB_DIR",o.dirname(t.dataSqlPath)),n.defineConstant("DB_FILE",o.basename(t.dataSqlPath))),n.defineConstant("WP_HOME",t.siteUrl),n.defineConstant("WP_SITEURL",t.siteUrl),await h(n,e.documentRoot),(r=t.hooks)!=null&&r.beforeDatabaseSetup&&await t.hooks.beforeDatabaseSetup(n),t.sqliteIntegrationPluginZip&&await k(n,await t.sqliteIntegrationPluginZip),t.wordPressZip&&!t.dataSqlPath&&(await f(n)||await S(n),!await f(n))){if(await L(n))throw new Error("WordPress installation has failed.");if(n.isFile("/internal/shared/preload/0-sqlite.php"))throw new Error("Error connecting to the SQLite database.");if(!t.sqliteIntegrationPluginZip){const l=o.joinPaths(e.documentRoot,"wp-content/mu-plugins/sqlite-database-integration");if(n.isDir(l))throw new Error("Error connecting to the SQLite database.")}throw new Error("Error connecting to the MySQL database.")}return e}async function w(e){const t=e.spawnHandler??d.sandboxedSpawnHandlerFactory;async function n(r,a){const l=await e.createPhpRuntime(a),s=new d.PHP(l);return e.sapiName&&s.setSapiName(e.sapiName),r&&(s.requestHandler=r),e.phpIniEntries&&d.setPhpIniEntries(s,e.phpIniEntries),s.defineConstant("WP_SQLITE_AST_DRIVER",!0),a&&!s.isFile("/internal/.boot-files-written")&&(await y(s),await d.writeFiles(s,"/",e.createFiles||{}),await P(s,o.joinPaths(new URL(e.siteUrl).pathname,"phpinfo.php")),await d.writeFiles(s,"/internal",{".boot-files-written":""})),t&&await s.setSpawnHandler(t(r.processManager)),s.enableRuntimeRotation({recreateRuntime:e.createPhpRuntime,maxRequests:400}),e.onPHPInstanceCreated&&await e.onPHPInstanceCreated(s,{isPrimary:a}),s}const i=new d.PHPRequestHandler({phpFactory:async({isPrimary:r})=>n(i,r),documentRoot:e.documentRoot||"/wordpress",absoluteUrl:e.siteUrl,rewriteRules:b,getFileNotFoundAction:e.getFileNotFoundAction??$,cookieStore:e.cookieStore});return i}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,t){const n=o.joinPaths(t,"wp-config.php"),i={DB_NAME:"wordpress"};!e.fileExists(n)&&e.fileExists(o.joinPaths(t,"wp-config-sample.php"))&&await e.writeFile(n,await e.readFileAsBuffer(o.joinPaths(t,"wp-config-sample.php"))),await _(e,n,i,"skip")}async function v(e){const t=await w(e);return await g(t,e),t}async function g(e,t){var i,r;const n=await e.getPrimaryPhp();if((i=t.hooks)!=null&&i.beforeWordPressFiles&&await t.hooks.beforeWordPressFiles(n),t.wordPressZip&&await E(n,await t.wordPressZip),t.constants)for(const a in t.constants)n.defineConstant(a,t.constants[a]);if(t.dataSqlPath&&(n.defineConstant("DB_DIR",o.dirname(t.dataSqlPath)),n.defineConstant("DB_FILE",o.basename(t.dataSqlPath))),n.defineConstant("WP_HOME",t.siteUrl),n.defineConstant("WP_SITEURL",t.siteUrl),await h(n,e.documentRoot),(r=t.hooks)!=null&&r.beforeDatabaseSetup&&await t.hooks.beforeDatabaseSetup(n),t.sqliteIntegrationPluginZip&&await k(n,await t.sqliteIntegrationPluginZip),t.wordPressZip&&!t.dataSqlPath&&(await f(n)||await S(n),!await f(n))){if(await L(n))throw new Error("WordPress installation has failed.");if(n.isFile("/internal/shared/preload/0-sqlite.php"))throw new Error("Error connecting to the SQLite database.");if(!t.sqliteIntegrationPluginZip){const l=o.joinPaths(e.documentRoot,"wp-content/mu-plugins/sqlite-database-integration");if(n.isDir(l))throw new Error("Error connecting to the SQLite database.")}throw new Error("Error connecting to the MySQL database.")}return e}async function w(e){const t=e.spawnHandler??d.sandboxedSpawnHandlerFactory;async function n(r,a){const l=await e.createPhpRuntime(a),s=new d.PHP(l);return e.sapiName&&s.setSapiName(e.sapiName),r&&(s.requestHandler=r),e.phpIniEntries&&d.setPhpIniEntries(s,e.phpIniEntries),s.defineConstant("WP_SQLITE_AST_DRIVER",!0),a&&!s.isFile("/internal/.boot-files-written")&&(await y(s),await d.writeFiles(s,"/",e.createFiles||{}),await P(s,o.joinPaths(new URL(e.siteUrl).pathname,"phpinfo.php")),await d.writeFiles(s,"/internal",{".boot-files-written":""})),t&&await s.setSpawnHandler(t(r.processManager)),s.enableRuntimeRotation({recreateRuntime:e.createPhpRuntime,maxRequests:400}),e.onPHPInstanceCreated&&await e.onPHPInstanceCreated(s,{isPrimary:a}),s}const i=new d.PHPRequestHandler({phpFactory:async({isPrimary:r})=>n(i,r),documentRoot:e.documentRoot||"/wordpress",absoluteUrl:e.siteUrl,rewriteRules:b,getFileNotFoundAction:e.getFileNotFoundAction??$,cookieStore:e.cookieStore});return i}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)) {
@@ -755,5 +755,5 @@ if(!function_exists('mysqli_connect')) {
755
755
  var_dump(isset($wpdb));
756
756
  die("SQLite integration not loaded " . get_class($wpdb));
757
757
  }
758
- `)}async function E(e,t){e.mkdir("/tmp/unzipped-wordpress"),await p.unzipFile(e,t,"/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 r=e.listFiles(n);if(r.length){const a=r[0];e.fileExists(o.joinPaths(n,a,"wp-config-sample.php"))&&(n=o.joinPaths(n,a))}}const i=(r,a,l)=>{if(l.isDir(r)&&l.isDir(a))for(const s of l.listFiles(r)){const u=o.joinPaths(r,s),T=o.joinPaths(a,s);i(u,T,l)}else{if(l.fileExists(a)){const s=r.replace(/^\/tmp\/unzipped-wordpress\//,"/");c.logger.warn(`Cannot unzip WordPress files at ${a}: ${s} already exists.`);return}l.mv(r,a)}};i(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 I=p.createMemoizedFetch(fetch);async function W(e="latest"){if(e.startsWith("https://")||e.startsWith("http://")){const i=await crypto.subtle.digest("SHA-1",new TextEncoder().encode(e)),r=Array.from(new Uint8Array(i)).map(a=>a.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 I("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(e==="beta"&&i.version.includes("beta"))return{releaseUrl:i.download,version:i.version,source:"api"};if(e==="latest"&&!i.version.includes("beta"))return{releaseUrl:i.download,version:i.version,source:"api"};if(i.version.substring(0,e.length)===e)return{releaseUrl:i.download,version:i.version,source:"api"}}return{releaseUrl:`https://wordpress.org/wordpress-${e}.zip`,version:e,source:"inferred"}}exports.bootRequestHandler=w;exports.bootWordPress=g;exports.bootWordPressAndRequestHandler=R;exports.defineWpConfigConstants=_;exports.ensureWpConfig=h;exports.getFileNotFoundActionForWordPress=$;exports.getLoadedWordPressVersion=x;exports.preloadPhpInfoRoute=P;exports.preloadSqliteIntegration=k;exports.resolveWordPressRelease=W;exports.setupPlatformLevelMuPlugins=y;exports.unzipWordPress=E;exports.versionStringToLoadedWordPressVersion=m;exports.wordPressRewriteRules=b;
758
+ `)}async function E(e,t){e.mkdir("/tmp/unzipped-wordpress"),await p.unzipFile(e,t,"/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 r=e.listFiles(n);if(r.length){const a=r[0];e.fileExists(o.joinPaths(n,a,"wp-config-sample.php"))&&(n=o.joinPaths(n,a))}}const i=(r,a,l)=>{if(l.isDir(r)&&l.isDir(a))for(const s of l.listFiles(r)){const u=o.joinPaths(r,s),T=o.joinPaths(a,s);i(u,T,l)}else{if(l.fileExists(a)){const s=r.replace(/^\/tmp\/unzipped-wordpress\//,"/");c.logger.warn(`Cannot unzip WordPress files at ${a}: ${s} already exists.`);return}l.mv(r,a)}};i(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 I=p.createMemoizedFetch(fetch);async function W(e="latest"){if(e.startsWith("https://")||e.startsWith("http://")){const i=await crypto.subtle.digest("SHA-1",new TextEncoder().encode(e)),r=Array.from(new Uint8Array(i)).map(a=>a.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 I("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(e==="beta"&&i.version.includes("beta"))return{releaseUrl:i.download,version:i.version,source:"api"};if(e==="latest"&&!i.version.includes("beta"))return{releaseUrl:i.download,version:i.version,source:"api"};if(i.version.substring(0,e.length)===e)return{releaseUrl:i.download,version:i.version,source:"api"}}return e.match(/^\d+\.\d+\.0$/)&&(e=e.split(".").slice(0,2).join(".")),{releaseUrl:`https://wordpress.org/wordpress-${e}.zip`,version:e,source:"inferred"}}exports.bootRequestHandler=w;exports.bootWordPress=g;exports.bootWordPressAndRequestHandler=v;exports.defineWpConfigConstants=_;exports.ensureWpConfig=h;exports.getFileNotFoundActionForWordPress=$;exports.getLoadedWordPressVersion=x;exports.preloadPhpInfoRoute=P;exports.preloadSqliteIntegration=k;exports.resolveWordPressRelease=W;exports.setupPlatformLevelMuPlugins=y;exports.unzipWordPress=E;exports.versionStringToLoadedWordPressVersion=m;exports.wordPressRewriteRules=b;
759
759
  //# sourceMappingURL=index.cjs.map
package/index.js CHANGED
@@ -348,7 +348,7 @@ function skip_whitespace($tokens) {
348
348
  return $output;
349
349
  }
350
350
  `;
351
- async function v(e, t, n, i = "rewrite") {
351
+ async function R(e, t, n, i = "rewrite") {
352
352
  const r = g({ wpConfigPath: t, constants: n, whenAlreadyDefined: i });
353
353
  if ((await e.run({
354
354
  code: `<?php ob_start(); ?>
@@ -364,7 +364,7 @@ async function v(e, t, n, i = "rewrite") {
364
364
  })).text !== "1")
365
365
  throw new Error("Failed to rewrite constants in wp-config.php.");
366
366
  }
367
- async function R(e, t) {
367
+ async function v(e, t) {
368
368
  const n = s(t, "wp-config.php"), i = {
369
369
  DB_NAME: "wordpress"
370
370
  };
@@ -373,7 +373,7 @@ async function R(e, t) {
373
373
  await e.readFileAsBuffer(
374
374
  s(t, "wp-config-sample.php")
375
375
  )
376
- ), await v(e, n, i, "skip");
376
+ ), await R(e, n, i, "skip");
377
377
  }
378
378
  async function H(e) {
379
379
  const t = await x(e);
@@ -385,7 +385,7 @@ async function S(e, t) {
385
385
  if ((i = t.hooks) != null && i.beforeWordPressFiles && await t.hooks.beforeWordPressFiles(n), t.wordPressZip && await q(n, await t.wordPressZip), t.constants)
386
386
  for (const a in t.constants)
387
387
  n.defineConstant(a, t.constants[a]);
388
- if (t.dataSqlPath && (n.defineConstant("DB_DIR", $(t.dataSqlPath)), n.defineConstant("DB_FILE", w(t.dataSqlPath))), n.defineConstant("WP_HOME", t.siteUrl), n.defineConstant("WP_SITEURL", t.siteUrl), await R(n, e.documentRoot), (r = t.hooks) != null && r.beforeDatabaseSetup && await t.hooks.beforeDatabaseSetup(n), t.sqliteIntegrationPluginZip && await A(
388
+ if (t.dataSqlPath && (n.defineConstant("DB_DIR", $(t.dataSqlPath)), n.defineConstant("DB_FILE", w(t.dataSqlPath))), n.defineConstant("WP_HOME", t.siteUrl), n.defineConstant("WP_SITEURL", t.siteUrl), await v(n, e.documentRoot), (r = t.hooks) != null && r.beforeDatabaseSetup && await t.hooks.beforeDatabaseSetup(n), t.sqliteIntegrationPluginZip && await A(
389
389
  n,
390
390
  await t.sqliteIntegrationPluginZip
391
391
  ), t.wordPressZip && !t.dataSqlPath && (await c(n) || await L(n), !await c(n))) {
@@ -1060,7 +1060,7 @@ async function Q(e = "latest") {
1060
1060
  source: "api"
1061
1061
  };
1062
1062
  }
1063
- return {
1063
+ return e.match(/^\d+\.\d+\.0$/) && (e = e.split(".").slice(0, 2).join(".")), {
1064
1064
  releaseUrl: `https://wordpress.org/wordpress-${e}.zip`,
1065
1065
  version: e,
1066
1066
  source: "inferred"
@@ -1070,8 +1070,8 @@ export {
1070
1070
  x as bootRequestHandler,
1071
1071
  S as bootWordPress,
1072
1072
  H as bootWordPressAndRequestHandler,
1073
- v as defineWpConfigConstants,
1074
- R as ensureWpConfig,
1073
+ R as defineWpConfigConstants,
1074
+ v as ensureWpConfig,
1075
1075
  I as getFileNotFoundActionForWordPress,
1076
1076
  z as getLoadedWordPressVersion,
1077
1077
  D as preloadPhpInfoRoute,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wp-playground/wordpress",
3
- "version": "3.0.17",
3
+ "version": "3.0.19",
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": "11e92b1431bd01ee27049678aec2932b8b4d9f44",
38
+ "gitHead": "5d6cbf03fb33b4c58c587c43a4a7793d4b050885",
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.3",
44
44
  "yargs": "17.7.2",
45
- "@php-wasm/universal": "3.0.17",
46
- "@php-wasm/util": "3.0.17",
47
- "@php-wasm/logger": "3.0.17",
48
- "@wp-playground/common": "3.0.17",
49
- "@php-wasm/node": "3.0.17"
45
+ "@php-wasm/universal": "3.0.19",
46
+ "@php-wasm/util": "3.0.19",
47
+ "@php-wasm/logger": "3.0.19",
48
+ "@wp-playground/common": "3.0.19",
49
+ "@php-wasm/node": "3.0.19"
50
50
  },
51
51
  "packageManager": "npm@10.9.2",
52
52
  "overrides": {