@wp-playground/wordpress 2.0.22 → 3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/boot.d.ts +17 -4
- package/index.cjs +16 -16
- package/index.d.ts +2 -1
- package/index.js +114 -102
- package/index.js.map +1 -1
- package/package.json +7 -7
package/boot.d.ts
CHANGED
|
@@ -6,10 +6,14 @@ export interface Hooks {
|
|
|
6
6
|
beforeWordPressFiles?: Hook;
|
|
7
7
|
beforeDatabaseSetup?: Hook;
|
|
8
8
|
}
|
|
9
|
+
export type PHPInstanceCreatedHook = (php: PHP, { isPrimary }: {
|
|
10
|
+
isPrimary: boolean;
|
|
11
|
+
}) => Promise<void>;
|
|
9
12
|
export type DatabaseType = 'sqlite' | 'mysql' | 'custom';
|
|
13
|
+
export declare function bootWordPressAndRequestHandler(options: BootRequestHandlerOptions & BootWordPressOptions): Promise<PHPRequestHandler>;
|
|
10
14
|
export interface BootRequestHandlerOptions {
|
|
11
|
-
createPhpRuntime: () => Promise<number>;
|
|
12
|
-
onPHPInstanceCreated?:
|
|
15
|
+
createPhpRuntime: (isPrimary?: boolean) => Promise<number>;
|
|
16
|
+
onPHPInstanceCreated?: PHPInstanceCreatedHook;
|
|
13
17
|
/**
|
|
14
18
|
* PHP SAPI name to be returned by get_sapi_name(). Overriding
|
|
15
19
|
* it is useful for running programs that check for this value,
|
|
@@ -70,7 +74,7 @@ export interface BootRequestHandlerOptions {
|
|
|
70
74
|
*/
|
|
71
75
|
cookieStore?: CookieStore | false;
|
|
72
76
|
}
|
|
73
|
-
export interface
|
|
77
|
+
export interface BootWordPressOptions {
|
|
74
78
|
/**
|
|
75
79
|
* Mounting and Copying is handled via hooks for starters.
|
|
76
80
|
*
|
|
@@ -85,6 +89,15 @@ export interface BootOptions extends BootRequestHandlerOptions {
|
|
|
85
89
|
wordPressZip?: File | Promise<File> | undefined;
|
|
86
90
|
/** Preloaded SQLite integration plugin. */
|
|
87
91
|
sqliteIntegrationPluginZip?: File | Promise<File>;
|
|
92
|
+
/**
|
|
93
|
+
* PHP constants to define for every request.
|
|
94
|
+
*/
|
|
95
|
+
constants?: Record<string, string | number | boolean | null>;
|
|
96
|
+
/**
|
|
97
|
+
* URL to use as the site URL. This is used to set the WP_HOME
|
|
98
|
+
* and WP_SITEURL constants in WordPress.
|
|
99
|
+
*/
|
|
100
|
+
siteUrl: string;
|
|
88
101
|
}
|
|
89
102
|
/**
|
|
90
103
|
* Boots a WordPress instance with the given options.
|
|
@@ -101,7 +114,7 @@ export interface BootOptions extends BootRequestHandlerOptions {
|
|
|
101
114
|
* @param options Boot configuration options
|
|
102
115
|
* @return PHPRequestHandler instance with WordPress installed.
|
|
103
116
|
*/
|
|
104
|
-
export declare function bootWordPress(options:
|
|
117
|
+
export declare function bootWordPress(requestHandler: PHPRequestHandler, options: BootWordPressOptions): Promise<PHPRequestHandler>;
|
|
105
118
|
export declare function bootRequestHandler(options: BootRequestHandlerOptions): Promise<PHPRequestHandler>;
|
|
106
119
|
/**
|
|
107
120
|
* Checks if WordPress is installed by checking if the wp-load.php file exists
|
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"),
|
|
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"),l=require("@php-wasm/universal"),R=`<?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,
|
|
347
|
-
${
|
|
348
|
-
$wp_config_path = ${
|
|
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
|
+
${R}
|
|
348
|
+
$wp_config_path = ${r.wpConfigPath};
|
|
349
349
|
$wp_config = file_get_contents($wp_config_path);
|
|
350
|
-
$new_wp_config = rewrite_wp_config_to_define_constants($wp_config, ${
|
|
350
|
+
$new_wp_config = rewrite_wp_config_to_define_constants($wp_config, ${r.constants}, ${r.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 h(e,
|
|
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 s in t.constants)n.defineConstant(s,t.constants[s]);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 d=o.joinPaths(e.documentRoot,"wp-content/mu-plugins/sqlite-database-integration");if(n.isDir(d))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??l.sandboxedSpawnHandlerFactory;async function n(r,s){const d=await e.createPhpRuntime(s),a=new l.PHP(d);return e.sapiName&&a.setSapiName(e.sapiName),r&&(a.requestHandler=r),e.phpIniEntries&&l.setPhpIniEntries(a,e.phpIniEntries),a.defineConstant("WP_SQLITE_AST_DRIVER",!0),s&&!a.isFile("/internal/.boot-files-written")&&(await y(a),await l.writeFiles(a,"/",e.createFiles||{}),await P(a,o.joinPaths(new URL(e.siteUrl).pathname,"phpinfo.php")),await l.writeFiles(a,"/internal",{".boot-files-written":""})),t&&await a.setSpawnHandler(t(r.processManager)),a.enableRuntimeRotation({cwd:r.documentRoot,recreateRuntime:e.createPhpRuntime,maxRequests:400}),e.onPHPInstanceCreated&&await e.onPHPInstanceCreated(a,{isPrimary:s}),a}const i=new l.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)) {
|
|
@@ -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
|
|
366
|
+
`,env:{DOCUMENT_ROOT:e.documentRoot}})).text==="1"}async function S(e){await l.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,7 +378,7 @@ 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"&&c.logger.warn("Failed to default to pretty permalinks after WP install.")}function
|
|
381
|
+
`,env:{DOCUMENT_ROOT:e.documentRoot}})).text!=="1"&&c.logger.warn("Failed to default to pretty permalinks after WP install.")}function $(e){return{type:"internal-redirect",uri:"/index.php"}}async function L(e){return(await e.run({code:`<?php
|
|
382
382
|
ob_start();
|
|
383
383
|
$wp_load = getenv('DOCUMENT_ROOT') . '/wp-load.php';
|
|
384
384
|
if (!file_exists($wp_load)) {
|
|
@@ -389,10 +389,10 @@ function skip_whitespace($tokens) {
|
|
|
389
389
|
ob_clean();
|
|
390
390
|
echo $wpdb->check_connection( false) ? '1' : '0';
|
|
391
391
|
ob_end_flush();
|
|
392
|
-
`,env:{DOCUMENT_ROOT:e.documentRoot}})).text==="1"}async function x(e){const{php:
|
|
392
|
+
`,env:{DOCUMENT_ROOT:e.documentRoot}})).text==="1"}async function x(e){const{php:t,reap:n}=await e.processManager.acquirePHPInstance({considerPrimary:!0});try{const r=(await t.run({code:`<?php
|
|
393
393
|
require '${e.documentRoot}/wp-includes/version.php';
|
|
394
394
|
echo $wp_version;
|
|
395
|
-
`})).text;if(!
|
|
395
|
+
`})).text;if(!r)throw new Error("Unable to read loaded WordPress version.");return m(r)}finally{n()}}function m(e){if(/-(alpha|beta|RC)\d*-\d+$/.test(e))return"nightly";if(/-(beta|RC)\d*$/.test(e))return"beta";const i=e.match(/^(\d+\.\d+)(?:\.\d+)?$/);return i!==null?i[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
|
|
396
396
|
|
|
397
397
|
// Allow adding filters/actions prior to loading WordPress.
|
|
398
398
|
// $function_to_add MUST be a string.
|
|
@@ -663,18 +663,18 @@ function skip_whitespace($tokens) {
|
|
|
663
663
|
}
|
|
664
664
|
return false;
|
|
665
665
|
});
|
|
666
|
-
})();`)}async function
|
|
666
|
+
})();`)}async function P(e,t="/phpinfo.php"){await e.writeFile("/internal/shared/preload/phpinfo.php",`<?php
|
|
667
667
|
// Render PHPInfo if the requested page is /phpinfo.php
|
|
668
|
-
if ( isset($_SERVER['REQUEST_URI']) && ${o.phpVar(
|
|
668
|
+
if ( isset($_SERVER['REQUEST_URI']) && ${o.phpVar(t)} === $_SERVER['REQUEST_URI'] ) {
|
|
669
669
|
phpinfo();
|
|
670
670
|
exit;
|
|
671
671
|
}
|
|
672
|
-
`)}async function
|
|
672
|
+
`)}async function k(e,t){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,t,"/tmp/sqlite-database-integration");const n="/internal/shared/sqlite-database-integration",i=`/tmp/sqlite-database-integration/${(await e.listFiles("/tmp/sqlite-database-integration"))[0]}`;await e.mv(i,n),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"))),d=o.joinPaths(await e.documentRoot,"wp-content/db.php"),a=`<?php
|
|
673
673
|
// Do not preload this if WordPress comes with a custom db.php file.
|
|
674
|
-
if(file_exists(${o.phpVar(
|
|
674
|
+
if(file_exists(${o.phpVar(d)})) {
|
|
675
675
|
return;
|
|
676
676
|
}
|
|
677
|
-
?>`,u="/internal/shared/mu-plugins/sqlite-database-integration.php";await e.writeFile(u,
|
|
677
|
+
?>`,u="/internal/shared/mu-plugins/sqlite-database-integration.php";await e.writeFile(u,a+s),await e.writeFile("/internal/shared/preload/0-sqlite.php",a+`<?php
|
|
678
678
|
|
|
679
679
|
/**
|
|
680
680
|
* Loads the SQLite integration plugin before WordPress is loaded
|
|
@@ -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
|
|
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 s=r[0];e.fileExists(o.joinPaths(n,s,"wp-config-sample.php"))&&(n=o.joinPaths(n,s))}}const i=(r,s,d)=>{if(d.isDir(r)&&d.isDir(s))for(const a of d.listFiles(r)){const u=o.joinPaths(r,a),T=o.joinPaths(s,a);i(u,T,d)}else{if(d.fileExists(s)){const a=r.replace(/^\/tmp\/unzipped-wordpress\//,"/");c.logger.warn(`Skipping ${a} because something exists at the target path.`);return}d.mv(r,s)}};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(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 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=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.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { PHP, UniversalPHP } from '@php-wasm/universal';
|
|
2
|
-
export { bootWordPress, bootRequestHandler, getFileNotFoundActionForWordPress, } from './boot';
|
|
2
|
+
export { bootWordPress, bootWordPressAndRequestHandler, bootRequestHandler, getFileNotFoundActionForWordPress, } from './boot';
|
|
3
|
+
export type { PhpIniOptions, PHPInstanceCreatedHook } from './boot';
|
|
3
4
|
export { defineWpConfigConstants, ensureWpConfig } from './rewrite-wp-config';
|
|
4
5
|
export { getLoadedWordPressVersion } from './version-detect';
|
|
5
6
|
export * from './version-detect';
|
package/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { phpVars as
|
|
2
|
-
import { createMemoizedFetch as
|
|
3
|
-
import { logger as
|
|
4
|
-
import { sandboxedSpawnHandlerFactory as
|
|
5
|
-
const
|
|
1
|
+
import { phpVars as g, joinPaths as s, dirname as w, basename as $, phpVar as l } from "@php-wasm/util";
|
|
2
|
+
import { createMemoizedFetch as m, unzipFile as p } from "@wp-playground/common";
|
|
3
|
+
import { logger as _ } from "@php-wasm/logger";
|
|
4
|
+
import { sandboxedSpawnHandlerFactory as b, PHPRequestHandler as y, withPHPIniValues as k, PHP as P, setPhpIniEntries as E, writeFiles as f } from "@php-wasm/universal";
|
|
5
|
+
const T = `<?php
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Rewrites the wp-config.php file to ensure specific constants are defined
|
|
@@ -348,14 +348,14 @@ function skip_whitespace($tokens) {
|
|
|
348
348
|
return $output;
|
|
349
349
|
}
|
|
350
350
|
`;
|
|
351
|
-
async function
|
|
352
|
-
const
|
|
351
|
+
async function v(e, t, n, i = "rewrite") {
|
|
352
|
+
const r = g({ wpConfigPath: t, constants: n, whenAlreadyDefined: i });
|
|
353
353
|
if ((await e.run({
|
|
354
354
|
code: `<?php ob_start(); ?>
|
|
355
|
-
${
|
|
356
|
-
$wp_config_path = ${
|
|
355
|
+
${T}
|
|
356
|
+
$wp_config_path = ${r.wpConfigPath};
|
|
357
357
|
$wp_config = file_get_contents($wp_config_path);
|
|
358
|
-
$new_wp_config = rewrite_wp_config_to_define_constants($wp_config, ${
|
|
358
|
+
$new_wp_config = rewrite_wp_config_to_define_constants($wp_config, ${r.constants}, ${r.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,76 +364,87 @@ async function R(e, r, 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
|
|
368
|
-
const n = s(
|
|
367
|
+
async function R(e, t) {
|
|
368
|
+
const n = s(t, "wp-config.php"), i = {
|
|
369
369
|
DB_NAME: "wordpress"
|
|
370
370
|
};
|
|
371
|
-
!e.fileExists(n) && e.fileExists(s(
|
|
371
|
+
!e.fileExists(n) && e.fileExists(s(t, "wp-config-sample.php")) && await e.writeFile(
|
|
372
372
|
n,
|
|
373
373
|
await e.readFileAsBuffer(
|
|
374
|
-
s(
|
|
374
|
+
s(t, "wp-config-sample.php")
|
|
375
375
|
)
|
|
376
|
-
), await
|
|
376
|
+
), await v(e, n, i, "skip");
|
|
377
377
|
}
|
|
378
378
|
async function H(e) {
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
379
|
+
const t = await x(e);
|
|
380
|
+
return await S(t, e), t;
|
|
381
|
+
}
|
|
382
|
+
async function S(e, t) {
|
|
383
|
+
var i, r;
|
|
384
|
+
const n = await e.getPrimaryPhp();
|
|
385
|
+
if ((i = t.hooks) != null && i.beforeWordPressFiles && await t.hooks.beforeWordPressFiles(n), t.wordPressZip && await q(n, await t.wordPressZip), t.constants)
|
|
386
|
+
for (const o in t.constants)
|
|
387
|
+
n.defineConstant(o, t.constants[o]);
|
|
388
|
+
if (t.dataSqlPath && (n.defineConstant("DB_DIR", w(t.dataSqlPath)), n.defineConstant("DB_FILE", $(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(
|
|
385
389
|
n,
|
|
386
|
-
await
|
|
387
|
-
),
|
|
390
|
+
await t.sqliteIntegrationPluginZip
|
|
391
|
+
), t.wordPressZip && !t.dataSqlPath && (await c(n) || await L(n), !await c(n))) {
|
|
388
392
|
if (await U(n))
|
|
389
393
|
throw new Error("WordPress installation has failed.");
|
|
390
394
|
if (n.isFile("/internal/shared/preload/0-sqlite.php"))
|
|
391
395
|
throw new Error("Error connecting to the SQLite database.");
|
|
392
|
-
if (!
|
|
393
|
-
const
|
|
394
|
-
|
|
396
|
+
if (!t.sqliteIntegrationPluginZip) {
|
|
397
|
+
const d = s(
|
|
398
|
+
e.documentRoot,
|
|
395
399
|
"wp-content/mu-plugins/sqlite-database-integration"
|
|
396
400
|
);
|
|
397
|
-
if (n.isDir(
|
|
401
|
+
if (n.isDir(d))
|
|
398
402
|
throw new Error(
|
|
399
403
|
"Error connecting to the SQLite database."
|
|
400
404
|
);
|
|
401
405
|
}
|
|
402
406
|
throw new Error("Error connecting to the MySQL database.");
|
|
403
407
|
}
|
|
404
|
-
return
|
|
408
|
+
return e;
|
|
405
409
|
}
|
|
406
410
|
async function x(e) {
|
|
407
|
-
const
|
|
408
|
-
async function n(
|
|
409
|
-
const
|
|
410
|
-
return e.sapiName && a.setSapiName(e.sapiName),
|
|
411
|
+
const t = e.spawnHandler ?? b;
|
|
412
|
+
async function n(r, o) {
|
|
413
|
+
const d = await e.createPhpRuntime(o), a = new P(d);
|
|
414
|
+
return e.sapiName && a.setSapiName(e.sapiName), r && (a.requestHandler = r), e.phpIniEntries && E(a, e.phpIniEntries), a.defineConstant("WP_SQLITE_AST_DRIVER", !0), o && /**
|
|
415
|
+
* Only the first PHP instance of the first worker created
|
|
416
|
+
* during WordPress boot writes these files – otherwise we'll keep
|
|
417
|
+
* overwriting them with concurrent writers living in other worker
|
|
418
|
+
* threads.
|
|
419
|
+
*
|
|
420
|
+
* The `.boot-files-written` file is our primitive synchronization
|
|
421
|
+
* mechanism. It works, because secondary workers are only booted
|
|
422
|
+
* once the primary worker has fully booted.
|
|
423
|
+
*/
|
|
424
|
+
!a.isFile("/internal/.boot-files-written") && (await C(a), await f(a, "/", e.createFiles || {}), await D(
|
|
411
425
|
a,
|
|
412
426
|
s(new URL(e.siteUrl).pathname, "phpinfo.php")
|
|
413
|
-
)
|
|
414
|
-
"
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
"/internal/symlinks"
|
|
418
|
-
]), r && await a.setSpawnHandler(
|
|
419
|
-
r(i.processManager)
|
|
427
|
+
), await f(a, "/internal", {
|
|
428
|
+
".boot-files-written": ""
|
|
429
|
+
})), t && await a.setSpawnHandler(
|
|
430
|
+
t(r.processManager)
|
|
420
431
|
), a.enableRuntimeRotation({
|
|
421
|
-
cwd:
|
|
432
|
+
cwd: r.documentRoot,
|
|
422
433
|
recreateRuntime: e.createPhpRuntime,
|
|
423
434
|
maxRequests: 400
|
|
424
|
-
}), e.onPHPInstanceCreated && await e.onPHPInstanceCreated(a), a;
|
|
435
|
+
}), e.onPHPInstanceCreated && await e.onPHPInstanceCreated(a, { isPrimary: o }), a;
|
|
425
436
|
}
|
|
426
|
-
const
|
|
427
|
-
phpFactory: async ({ isPrimary:
|
|
437
|
+
const i = new y({
|
|
438
|
+
phpFactory: async ({ isPrimary: r }) => n(i, r),
|
|
428
439
|
documentRoot: e.documentRoot || "/wordpress",
|
|
429
440
|
absoluteUrl: e.siteUrl,
|
|
430
|
-
rewriteRules:
|
|
441
|
+
rewriteRules: O,
|
|
431
442
|
getFileNotFoundAction: e.getFileNotFoundAction ?? I,
|
|
432
443
|
cookieStore: e.cookieStore
|
|
433
444
|
});
|
|
434
|
-
return
|
|
445
|
+
return i;
|
|
435
446
|
}
|
|
436
|
-
async function
|
|
447
|
+
async function c(e) {
|
|
437
448
|
return (await e.run({
|
|
438
449
|
code: `<?php
|
|
439
450
|
ob_start();
|
|
@@ -453,7 +464,7 @@ async function f(e) {
|
|
|
453
464
|
})).text === "1";
|
|
454
465
|
}
|
|
455
466
|
async function L(e) {
|
|
456
|
-
await
|
|
467
|
+
await k(
|
|
457
468
|
e,
|
|
458
469
|
{
|
|
459
470
|
disable_functions: "fsockopen",
|
|
@@ -495,7 +506,7 @@ async function L(e) {
|
|
|
495
506
|
env: {
|
|
496
507
|
DOCUMENT_ROOT: e.documentRoot
|
|
497
508
|
}
|
|
498
|
-
})).text !== "1" &&
|
|
509
|
+
})).text !== "1" && _.warn("Failed to default to pretty permalinks after WP install.");
|
|
499
510
|
}
|
|
500
511
|
function I(e) {
|
|
501
512
|
return {
|
|
@@ -523,32 +534,32 @@ async function U(e) {
|
|
|
523
534
|
})).text === "1";
|
|
524
535
|
}
|
|
525
536
|
async function Q(e) {
|
|
526
|
-
const { php:
|
|
537
|
+
const { php: t, reap: n } = await e.processManager.acquirePHPInstance({
|
|
527
538
|
considerPrimary: !0
|
|
528
539
|
});
|
|
529
540
|
try {
|
|
530
|
-
const
|
|
541
|
+
const r = (await t.run({
|
|
531
542
|
code: `<?php
|
|
532
543
|
require '${e.documentRoot}/wp-includes/version.php';
|
|
533
544
|
echo $wp_version;
|
|
534
545
|
`
|
|
535
546
|
})).text;
|
|
536
|
-
if (!
|
|
547
|
+
if (!r)
|
|
537
548
|
throw new Error("Unable to read loaded WordPress version.");
|
|
538
|
-
return
|
|
549
|
+
return W(r);
|
|
539
550
|
} finally {
|
|
540
551
|
n();
|
|
541
552
|
}
|
|
542
553
|
}
|
|
543
|
-
function
|
|
554
|
+
function W(e) {
|
|
544
555
|
if (/-(alpha|beta|RC)\d*-\d+$/.test(e))
|
|
545
556
|
return "nightly";
|
|
546
557
|
if (/-(beta|RC)\d*$/.test(e))
|
|
547
558
|
return "beta";
|
|
548
|
-
const
|
|
549
|
-
return
|
|
559
|
+
const i = e.match(/^(\d+\.\d+)(?:\.\d+)?$/);
|
|
560
|
+
return i !== null ? i[1] : e;
|
|
550
561
|
}
|
|
551
|
-
const
|
|
562
|
+
const O = [
|
|
552
563
|
{
|
|
553
564
|
match: /^\/(.*?)(\/wp-(content|admin|includes)\/.*)/g,
|
|
554
565
|
replacement: "$2"
|
|
@@ -840,13 +851,13 @@ async function C(e) {
|
|
|
840
851
|
})();`
|
|
841
852
|
);
|
|
842
853
|
}
|
|
843
|
-
async function D(e,
|
|
854
|
+
async function D(e, t = "/phpinfo.php") {
|
|
844
855
|
await e.writeFile(
|
|
845
856
|
"/internal/shared/preload/phpinfo.php",
|
|
846
857
|
`<?php
|
|
847
858
|
// Render PHPInfo if the requested page is /phpinfo.php
|
|
848
859
|
if ( isset($_SERVER['REQUEST_URI']) && ${l(
|
|
849
|
-
|
|
860
|
+
t
|
|
850
861
|
)} === $_SERVER['REQUEST_URI'] ) {
|
|
851
862
|
phpinfo();
|
|
852
863
|
exit;
|
|
@@ -854,12 +865,12 @@ async function D(e, r = "/phpinfo.php") {
|
|
|
854
865
|
`
|
|
855
866
|
);
|
|
856
867
|
}
|
|
857
|
-
async function A(e,
|
|
868
|
+
async function A(e, t) {
|
|
858
869
|
await e.isDir("/tmp/sqlite-database-integration") && await e.rmdir("/tmp/sqlite-database-integration", {
|
|
859
870
|
recursive: !0
|
|
860
|
-
}), await e.mkdir("/tmp/sqlite-database-integration"), await p(e,
|
|
861
|
-
const n = "/internal/shared/sqlite-database-integration",
|
|
862
|
-
await e.mv(
|
|
871
|
+
}), await e.mkdir("/tmp/sqlite-database-integration"), await p(e, t, "/tmp/sqlite-database-integration");
|
|
872
|
+
const n = "/internal/shared/sqlite-database-integration", i = `/tmp/sqlite-database-integration/${(await e.listFiles("/tmp/sqlite-database-integration"))[0]}`;
|
|
873
|
+
await e.mv(i, n), await e.defineConstant("SQLITE_MAIN_FILE", "1");
|
|
863
874
|
const o = (await e.readFileAsText(
|
|
864
875
|
s(n, "db.copy")
|
|
865
876
|
)).replace(
|
|
@@ -868,15 +879,15 @@ async function A(e, r) {
|
|
|
868
879
|
).replace(
|
|
869
880
|
"'{SQLITE_PLUGIN}'",
|
|
870
881
|
l(s(n, "load.php"))
|
|
871
|
-
),
|
|
882
|
+
), d = s(await e.documentRoot, "wp-content/db.php"), a = `<?php
|
|
872
883
|
// Do not preload this if WordPress comes with a custom db.php file.
|
|
873
|
-
if(file_exists(${l(
|
|
884
|
+
if(file_exists(${l(d)})) {
|
|
874
885
|
return;
|
|
875
886
|
}
|
|
876
887
|
?>`, u = "/internal/shared/mu-plugins/sqlite-database-integration.php";
|
|
877
|
-
await e.writeFile(u,
|
|
888
|
+
await e.writeFile(u, a + o), await e.writeFile(
|
|
878
889
|
"/internal/shared/preload/0-sqlite.php",
|
|
879
|
-
|
|
890
|
+
a + `<?php
|
|
880
891
|
|
|
881
892
|
/**
|
|
882
893
|
* Loads the SQLite integration plugin before WordPress is loaded
|
|
@@ -963,59 +974,59 @@ if(!function_exists('mysqli_connect')) {
|
|
|
963
974
|
`
|
|
964
975
|
);
|
|
965
976
|
}
|
|
966
|
-
async function q(e,
|
|
967
|
-
e.mkdir("/tmp/unzipped-wordpress"), await p(e,
|
|
977
|
+
async function q(e, t) {
|
|
978
|
+
e.mkdir("/tmp/unzipped-wordpress"), await p(e, t, "/tmp/unzipped-wordpress"), e.fileExists("/tmp/unzipped-wordpress/wordpress.zip") && await p(
|
|
968
979
|
e,
|
|
969
980
|
"/tmp/unzipped-wordpress/wordpress.zip",
|
|
970
981
|
"/tmp/unzipped-wordpress"
|
|
971
982
|
);
|
|
972
983
|
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";
|
|
973
984
|
if (!e.fileExists(s(n, "wp-config-sample.php"))) {
|
|
974
|
-
const
|
|
975
|
-
if (
|
|
976
|
-
const o =
|
|
985
|
+
const r = e.listFiles(n);
|
|
986
|
+
if (r.length) {
|
|
987
|
+
const o = r[0];
|
|
977
988
|
e.fileExists(
|
|
978
989
|
s(n, o, "wp-config-sample.php")
|
|
979
990
|
) && (n = s(n, o));
|
|
980
991
|
}
|
|
981
992
|
}
|
|
982
|
-
const
|
|
983
|
-
if (
|
|
984
|
-
for (const
|
|
985
|
-
const u = s(
|
|
986
|
-
|
|
993
|
+
const i = (r, o, d) => {
|
|
994
|
+
if (d.isDir(r) && d.isDir(o))
|
|
995
|
+
for (const a of d.listFiles(r)) {
|
|
996
|
+
const u = s(r, a), h = s(o, a);
|
|
997
|
+
i(u, h, d);
|
|
987
998
|
}
|
|
988
999
|
else {
|
|
989
|
-
if (
|
|
990
|
-
const
|
|
1000
|
+
if (d.fileExists(o)) {
|
|
1001
|
+
const a = r.replace(
|
|
991
1002
|
/^\/tmp\/unzipped-wordpress\//,
|
|
992
1003
|
"/"
|
|
993
1004
|
);
|
|
994
|
-
|
|
995
|
-
`Skipping ${
|
|
1005
|
+
_.warn(
|
|
1006
|
+
`Skipping ${a} because something exists at the target path.`
|
|
996
1007
|
);
|
|
997
1008
|
return;
|
|
998
1009
|
}
|
|
999
|
-
|
|
1010
|
+
d.mv(r, o);
|
|
1000
1011
|
}
|
|
1001
1012
|
};
|
|
1002
|
-
|
|
1013
|
+
i(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(
|
|
1003
1014
|
s(e.documentRoot, "wp-config.php"),
|
|
1004
1015
|
e.readFileAsText(
|
|
1005
1016
|
s(e.documentRoot, "/wp-config-sample.php")
|
|
1006
1017
|
)
|
|
1007
1018
|
);
|
|
1008
1019
|
}
|
|
1009
|
-
const F =
|
|
1020
|
+
const F = m(fetch);
|
|
1010
1021
|
async function z(e = "latest") {
|
|
1011
1022
|
if (e.startsWith("https://") || e.startsWith("http://")) {
|
|
1012
|
-
const
|
|
1023
|
+
const i = await crypto.subtle.digest(
|
|
1013
1024
|
"SHA-1",
|
|
1014
1025
|
new TextEncoder().encode(e)
|
|
1015
|
-
),
|
|
1026
|
+
), r = Array.from(new Uint8Array(i)).map((o) => o.toString(16).padStart(2, "0")).join("");
|
|
1016
1027
|
return {
|
|
1017
1028
|
releaseUrl: e,
|
|
1018
|
-
version: "custom-" +
|
|
1029
|
+
version: "custom-" + r.substring(0, 8),
|
|
1019
1030
|
source: "inferred"
|
|
1020
1031
|
};
|
|
1021
1032
|
} else if (e === "trunk" || e === "nightly")
|
|
@@ -1028,25 +1039,25 @@ async function z(e = "latest") {
|
|
|
1028
1039
|
"https://api.wordpress.org/core/version-check/1.7/?channel=beta"
|
|
1029
1040
|
)).json();
|
|
1030
1041
|
n = n.offers.filter(
|
|
1031
|
-
(
|
|
1042
|
+
(i) => i.response === "autoupdate"
|
|
1032
1043
|
);
|
|
1033
|
-
for (const
|
|
1034
|
-
if (e === "beta" &&
|
|
1044
|
+
for (const i of n) {
|
|
1045
|
+
if (e === "beta" && i.version.includes("beta"))
|
|
1035
1046
|
return {
|
|
1036
|
-
releaseUrl:
|
|
1037
|
-
version:
|
|
1047
|
+
releaseUrl: i.download,
|
|
1048
|
+
version: i.version,
|
|
1038
1049
|
source: "api"
|
|
1039
1050
|
};
|
|
1040
|
-
if (e === "latest" && !
|
|
1051
|
+
if (e === "latest" && !i.version.includes("beta"))
|
|
1041
1052
|
return {
|
|
1042
|
-
releaseUrl:
|
|
1043
|
-
version:
|
|
1053
|
+
releaseUrl: i.download,
|
|
1054
|
+
version: i.version,
|
|
1044
1055
|
source: "api"
|
|
1045
1056
|
};
|
|
1046
|
-
if (
|
|
1057
|
+
if (i.version.substring(0, e.length) === e)
|
|
1047
1058
|
return {
|
|
1048
|
-
releaseUrl:
|
|
1049
|
-
version:
|
|
1059
|
+
releaseUrl: i.download,
|
|
1060
|
+
version: i.version,
|
|
1050
1061
|
source: "api"
|
|
1051
1062
|
};
|
|
1052
1063
|
}
|
|
@@ -1058,9 +1069,10 @@ async function z(e = "latest") {
|
|
|
1058
1069
|
}
|
|
1059
1070
|
export {
|
|
1060
1071
|
x as bootRequestHandler,
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1072
|
+
S as bootWordPress,
|
|
1073
|
+
H as bootWordPressAndRequestHandler,
|
|
1074
|
+
v as defineWpConfigConstants,
|
|
1075
|
+
R as ensureWpConfig,
|
|
1064
1076
|
I as getFileNotFoundActionForWordPress,
|
|
1065
1077
|
Q as getLoadedWordPressVersion,
|
|
1066
1078
|
D as preloadPhpInfoRoute,
|
|
@@ -1068,7 +1080,7 @@ export {
|
|
|
1068
1080
|
z as resolveWordPressRelease,
|
|
1069
1081
|
C as setupPlatformLevelMuPlugins,
|
|
1070
1082
|
q as unzipWordPress,
|
|
1071
|
-
|
|
1072
|
-
|
|
1083
|
+
W as versionStringToLoadedWordPressVersion,
|
|
1084
|
+
O as wordPressRewriteRules
|
|
1073
1085
|
};
|
|
1074
1086
|
//# 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": "
|
|
3
|
+
"version": "3.0.2",
|
|
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": "
|
|
38
|
+
"gitHead": "35cc84863d9e92c1e6a5d354bb0727673b461216",
|
|
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": "
|
|
46
|
-
"@php-wasm/util": "
|
|
47
|
-
"@php-wasm/logger": "
|
|
48
|
-
"@wp-playground/common": "
|
|
49
|
-
"@php-wasm/node": "
|
|
45
|
+
"@php-wasm/universal": "3.0.2",
|
|
46
|
+
"@php-wasm/util": "3.0.2",
|
|
47
|
+
"@php-wasm/logger": "3.0.2",
|
|
48
|
+
"@wp-playground/common": "3.0.2",
|
|
49
|
+
"@php-wasm/node": "3.0.2"
|
|
50
50
|
},
|
|
51
51
|
"overrides": {
|
|
52
52
|
"rollup": "^4.34.6",
|