@wp-playground/wordpress 1.2.2 → 2.0.0
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 +18 -16
- package/index.cjs +15 -15
- package/index.js +99 -98
- package/index.js.map +1 -1
- package/package.json +7 -7
package/boot.d.ts
CHANGED
|
@@ -7,17 +7,9 @@ export interface Hooks {
|
|
|
7
7
|
beforeDatabaseSetup?: Hook;
|
|
8
8
|
}
|
|
9
9
|
export type DatabaseType = 'sqlite' | 'mysql' | 'custom';
|
|
10
|
-
export interface
|
|
10
|
+
export interface BootRequestHandlerOptions {
|
|
11
11
|
createPhpRuntime: () => Promise<number>;
|
|
12
12
|
onPHPInstanceCreated?: (php: PHP) => Promise<void>;
|
|
13
|
-
/**
|
|
14
|
-
* Mounting and Copying is handled via hooks for starters.
|
|
15
|
-
*
|
|
16
|
-
* In the future we could standardize the
|
|
17
|
-
* browser-specific and node-specific mounts
|
|
18
|
-
* in the future.
|
|
19
|
-
*/
|
|
20
|
-
hooks?: Hooks;
|
|
21
13
|
/**
|
|
22
14
|
* PHP SAPI name to be returned by get_sapi_name(). Overriding
|
|
23
15
|
* it is useful for running programs that check for this value,
|
|
@@ -30,12 +22,6 @@ export interface BootOptions {
|
|
|
30
22
|
*/
|
|
31
23
|
siteUrl: string;
|
|
32
24
|
documentRoot?: string;
|
|
33
|
-
/** SQL file to load instead of installing WordPress. */
|
|
34
|
-
dataSqlPath?: string;
|
|
35
|
-
/** Zip with the WordPress installation to extract in /wordpress. */
|
|
36
|
-
wordPressZip?: File | Promise<File> | undefined;
|
|
37
|
-
/** Preloaded SQLite integration plugin. */
|
|
38
|
-
sqliteIntegrationPluginZip?: File | Promise<File>;
|
|
39
25
|
spawnHandler?: (processManager: PHPProcessManager) => SpawnHandler;
|
|
40
26
|
/**
|
|
41
27
|
* PHP.ini entries to define before running any code. They'll
|
|
@@ -84,6 +70,22 @@ export interface BootOptions {
|
|
|
84
70
|
*/
|
|
85
71
|
cookieStore?: CookieStore | false;
|
|
86
72
|
}
|
|
73
|
+
export interface BootOptions extends BootRequestHandlerOptions {
|
|
74
|
+
/**
|
|
75
|
+
* Mounting and Copying is handled via hooks for starters.
|
|
76
|
+
*
|
|
77
|
+
* In the future we could standardize the
|
|
78
|
+
* browser-specific and node-specific mounts
|
|
79
|
+
* in the future.
|
|
80
|
+
*/
|
|
81
|
+
hooks?: Hooks;
|
|
82
|
+
/** SQL file to load instead of installing WordPress. */
|
|
83
|
+
dataSqlPath?: string;
|
|
84
|
+
/** Zip with the WordPress installation to extract in /wordpress. */
|
|
85
|
+
wordPressZip?: File | Promise<File> | undefined;
|
|
86
|
+
/** Preloaded SQLite integration plugin. */
|
|
87
|
+
sqliteIntegrationPluginZip?: File | Promise<File>;
|
|
88
|
+
}
|
|
87
89
|
/**
|
|
88
90
|
* Boots a WordPress instance with the given options.
|
|
89
91
|
*
|
|
@@ -100,7 +102,7 @@ export interface BootOptions {
|
|
|
100
102
|
* @return PHPRequestHandler instance with WordPress installed.
|
|
101
103
|
*/
|
|
102
104
|
export declare function bootWordPress(options: BootOptions): Promise<PHPRequestHandler>;
|
|
103
|
-
export declare function bootRequestHandler(options:
|
|
105
|
+
export declare function bootRequestHandler(options: BootRequestHandlerOptions): Promise<PHPRequestHandler>;
|
|
104
106
|
/**
|
|
105
107
|
* Checks if WordPress is installed by checking if the wp-load.php file exists
|
|
106
108
|
* and if the blog is installed.
|
package/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
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
|
|
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
|
|
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
347
|
${E}
|
|
348
|
-
$wp_config_path = ${
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
382
382
|
require '${e.documentRoot}/wp-includes/version.php';
|
|
383
383
|
echo $wp_version;
|
|
384
|
-
`})).text;if(!
|
|
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
|
|
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
|
|
612
|
+
})();`)}async function b(e,i="/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']) && ${
|
|
614
|
+
if ( isset($_SERVER['REQUEST_URI']) && ${o.phpVar(i)} === $_SERVER['REQUEST_URI'] ) {
|
|
615
615
|
phpinfo();
|
|
616
616
|
exit;
|
|
617
617
|
}
|
|
618
|
-
`)}async function
|
|
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
|
|
619
619
|
// Do not preload this if WordPress comes with a custom db.php file.
|
|
620
|
-
if(file_exists(${
|
|
620
|
+
if(file_exists(${o.phpVar(a)})) {
|
|
621
621
|
return;
|
|
622
622
|
}
|
|
623
|
-
?>`,
|
|
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
|
|
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 ${
|
|
673
|
+
require_once ${o.phpVar(p)};
|
|
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
|
|
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;
|
|
696
696
|
//# sourceMappingURL=index.cjs.map
|
package/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { phpVars as _, joinPaths as
|
|
2
|
-
import { createMemoizedFetch as g, unzipFile as
|
|
3
|
-
import {
|
|
4
|
-
import { logger as
|
|
5
|
-
const
|
|
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";
|
|
5
|
+
const R = `<?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 S(e, i, n, t = "rewrite") {
|
|
352
|
+
const r = _({ wpConfigPath: i, constants: n, whenAlreadyDefined: t });
|
|
353
353
|
if ((await e.run({
|
|
354
354
|
code: `<?php ob_start(); ?>
|
|
355
|
-
${
|
|
356
|
-
$wp_config_path = ${
|
|
355
|
+
${R}
|
|
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,60 +364,61 @@ async function R(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
|
|
368
|
-
const n =
|
|
367
|
+
async function v(e, i) {
|
|
368
|
+
const n = a(i, "wp-config.php"), t = {
|
|
369
369
|
DB_NAME: "wordpress"
|
|
370
370
|
};
|
|
371
|
-
!e.fileExists(n) && e.fileExists(
|
|
371
|
+
!e.fileExists(n) && e.fileExists(a(i, "wp-config-sample.php")) && await e.writeFile(
|
|
372
372
|
n,
|
|
373
373
|
await e.readFileAsBuffer(
|
|
374
|
-
|
|
374
|
+
a(i, "wp-config-sample.php")
|
|
375
375
|
)
|
|
376
|
-
), await
|
|
376
|
+
), await S(e, n, t, "skip");
|
|
377
377
|
}
|
|
378
|
-
async function
|
|
379
|
-
var t,
|
|
380
|
-
const i = await
|
|
381
|
-
if ((t = e.hooks) != null && t.beforeWordPressFiles && await e.hooks.beforeWordPressFiles(n), e.wordPressZip && await
|
|
382
|
-
for (const
|
|
383
|
-
n.defineConstant(
|
|
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
|
|
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(
|
|
385
385
|
n,
|
|
386
386
|
await e.sqliteIntegrationPluginZip
|
|
387
|
-
), !e.dataSqlPath && (await
|
|
387
|
+
), !e.dataSqlPath && (await f(n) || await L(n), !await f(n)))
|
|
388
388
|
throw new Error("WordPress installation has failed.");
|
|
389
389
|
return i;
|
|
390
390
|
}
|
|
391
|
-
async function
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
o
|
|
397
|
-
|
|
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, [
|
|
398
399
|
"/tmp",
|
|
399
|
-
|
|
400
|
+
r.documentRoot,
|
|
400
401
|
"/internal/shared"
|
|
401
|
-
]),
|
|
402
|
-
|
|
403
|
-
),
|
|
404
|
-
php:
|
|
405
|
-
cwd:
|
|
402
|
+
]), i && await o.setSpawnHandler(
|
|
403
|
+
i(r.processManager)
|
|
404
|
+
), E({
|
|
405
|
+
php: o,
|
|
406
|
+
cwd: r.documentRoot,
|
|
406
407
|
recreateRuntime: e.createPhpRuntime,
|
|
407
408
|
maxRequests: 400
|
|
408
|
-
}), e.onPHPInstanceCreated && await e.onPHPInstanceCreated(
|
|
409
|
+
}), e.onPHPInstanceCreated && await e.onPHPInstanceCreated(o), o;
|
|
409
410
|
}
|
|
410
|
-
const
|
|
411
|
-
phpFactory: async ({ isPrimary:
|
|
411
|
+
const t = new w({
|
|
412
|
+
phpFactory: async ({ isPrimary: r }) => n(t, r),
|
|
412
413
|
documentRoot: e.documentRoot || "/wordpress",
|
|
413
414
|
absoluteUrl: e.siteUrl,
|
|
414
|
-
rewriteRules:
|
|
415
|
-
getFileNotFoundAction: e.getFileNotFoundAction ??
|
|
415
|
+
rewriteRules: W,
|
|
416
|
+
getFileNotFoundAction: e.getFileNotFoundAction ?? I,
|
|
416
417
|
cookieStore: e.cookieStore
|
|
417
418
|
});
|
|
418
|
-
return
|
|
419
|
+
return t;
|
|
419
420
|
}
|
|
420
|
-
async function
|
|
421
|
+
async function f(e) {
|
|
421
422
|
return (await e.run({
|
|
422
423
|
code: `<?php
|
|
423
424
|
ob_start();
|
|
@@ -437,7 +438,7 @@ async function p(e) {
|
|
|
437
438
|
})).text === "1";
|
|
438
439
|
}
|
|
439
440
|
async function L(e) {
|
|
440
|
-
await
|
|
441
|
+
await m(
|
|
441
442
|
e,
|
|
442
443
|
{
|
|
443
444
|
disable_functions: "fsockopen",
|
|
@@ -479,33 +480,33 @@ async function L(e) {
|
|
|
479
480
|
env: {
|
|
480
481
|
DOCUMENT_ROOT: e.documentRoot
|
|
481
482
|
}
|
|
482
|
-
})).text !== "1" &&
|
|
483
|
+
})).text !== "1" && T.warn("Failed to default to pretty permalinks after WP install.");
|
|
483
484
|
}
|
|
484
|
-
function
|
|
485
|
+
function I(e) {
|
|
485
486
|
return {
|
|
486
487
|
type: "internal-redirect",
|
|
487
488
|
uri: "/index.php"
|
|
488
489
|
};
|
|
489
490
|
}
|
|
490
|
-
async function
|
|
491
|
+
async function z(e) {
|
|
491
492
|
const { php: i, reap: n } = await e.processManager.acquirePHPInstance({
|
|
492
493
|
considerPrimary: !0
|
|
493
494
|
});
|
|
494
495
|
try {
|
|
495
|
-
const
|
|
496
|
+
const r = (await i.run({
|
|
496
497
|
code: `<?php
|
|
497
498
|
require '${e.documentRoot}/wp-includes/version.php';
|
|
498
499
|
echo $wp_version;
|
|
499
500
|
`
|
|
500
501
|
})).text;
|
|
501
|
-
if (!
|
|
502
|
+
if (!r)
|
|
502
503
|
throw new Error("Unable to read loaded WordPress version.");
|
|
503
|
-
return
|
|
504
|
+
return U(r);
|
|
504
505
|
} finally {
|
|
505
506
|
n();
|
|
506
507
|
}
|
|
507
508
|
}
|
|
508
|
-
function
|
|
509
|
+
function U(e) {
|
|
509
510
|
if (/-(alpha|beta|RC)\d*-\d+$/.test(e))
|
|
510
511
|
return "nightly";
|
|
511
512
|
if (/-(beta|RC)\d*$/.test(e))
|
|
@@ -513,13 +514,13 @@ function I(e) {
|
|
|
513
514
|
const t = e.match(/^(\d+\.\d+)(?:\.\d+)?$/);
|
|
514
515
|
return t !== null ? t[1] : e;
|
|
515
516
|
}
|
|
516
|
-
const
|
|
517
|
+
const W = [
|
|
517
518
|
{
|
|
518
519
|
match: /^\/(.*?)(\/wp-(content|admin|includes)\/.*)/g,
|
|
519
520
|
replacement: "$2"
|
|
520
521
|
}
|
|
521
522
|
];
|
|
522
|
-
async function
|
|
523
|
+
async function O(e) {
|
|
523
524
|
await e.mkdir("/internal/shared/mu-plugins"), await e.writeFile(
|
|
524
525
|
"/internal/shared/preload/env.php",
|
|
525
526
|
`<?php
|
|
@@ -762,12 +763,12 @@ async function W(e) {
|
|
|
762
763
|
})();`
|
|
763
764
|
);
|
|
764
765
|
}
|
|
765
|
-
async function
|
|
766
|
+
async function C(e, i = "/phpinfo.php") {
|
|
766
767
|
await e.writeFile(
|
|
767
768
|
"/internal/shared/preload/phpinfo.php",
|
|
768
769
|
`<?php
|
|
769
770
|
// Render PHPInfo if the requested page is /phpinfo.php
|
|
770
|
-
if ( isset($_SERVER['REQUEST_URI']) && ${
|
|
771
|
+
if ( isset($_SERVER['REQUEST_URI']) && ${d(
|
|
771
772
|
i
|
|
772
773
|
)} === $_SERVER['REQUEST_URI'] ) {
|
|
773
774
|
phpinfo();
|
|
@@ -776,29 +777,29 @@ async function O(e, i = "/phpinfo.php") {
|
|
|
776
777
|
`
|
|
777
778
|
);
|
|
778
779
|
}
|
|
779
|
-
async function
|
|
780
|
+
async function D(e, i) {
|
|
780
781
|
await e.isDir("/tmp/sqlite-database-integration") && await e.rmdir("/tmp/sqlite-database-integration", {
|
|
781
782
|
recursive: !0
|
|
782
|
-
}), await e.mkdir("/tmp/sqlite-database-integration"), await
|
|
783
|
+
}), await e.mkdir("/tmp/sqlite-database-integration"), await l(e, i, "/tmp/sqlite-database-integration");
|
|
783
784
|
const n = "/internal/shared/sqlite-database-integration", t = `/tmp/sqlite-database-integration/${(await e.listFiles("/tmp/sqlite-database-integration"))[0]}`;
|
|
784
785
|
await e.mv(t, n), e.defineConstant("WP_SQLITE_AST_DRIVER", !0), await e.defineConstant("SQLITE_MAIN_FILE", "1");
|
|
785
|
-
const
|
|
786
|
-
|
|
786
|
+
const s = (await e.readFileAsText(
|
|
787
|
+
a(n, "db.copy")
|
|
787
788
|
)).replace(
|
|
788
789
|
"'{SQLITE_IMPLEMENTATION_FOLDER_PATH}'",
|
|
789
|
-
|
|
790
|
+
d(n)
|
|
790
791
|
).replace(
|
|
791
792
|
"'{SQLITE_PLUGIN}'",
|
|
792
|
-
|
|
793
|
-
),
|
|
793
|
+
d(a(n, "load.php"))
|
|
794
|
+
), o = a(await e.documentRoot, "wp-content/db.php"), u = `<?php
|
|
794
795
|
// Do not preload this if WordPress comes with a custom db.php file.
|
|
795
|
-
if(file_exists(${
|
|
796
|
+
if(file_exists(${d(o)})) {
|
|
796
797
|
return;
|
|
797
798
|
}
|
|
798
|
-
?>`,
|
|
799
|
-
await e.writeFile(
|
|
799
|
+
?>`, p = "/internal/shared/mu-plugins/sqlite-database-integration.php";
|
|
800
|
+
await e.writeFile(p, u + s), await e.writeFile(
|
|
800
801
|
"/internal/shared/preload/0-sqlite.php",
|
|
801
|
-
|
|
802
|
+
u + `<?php
|
|
802
803
|
|
|
803
804
|
/**
|
|
804
805
|
* Loads the SQLite integration plugin before WordPress is loaded
|
|
@@ -848,7 +849,7 @@ class Playground_SQLite_Integration_Loader {
|
|
|
848
849
|
$GLOBALS['wpdb']->$name = $value;
|
|
849
850
|
}
|
|
850
851
|
protected function load_sqlite_integration() {
|
|
851
|
-
require_once ${
|
|
852
|
+
require_once ${d(p)};
|
|
852
853
|
}
|
|
853
854
|
}
|
|
854
855
|
$wpdb = $GLOBALS['wpdb'] = new Playground_SQLite_Integration_Loader();
|
|
@@ -876,52 +877,52 @@ if(!function_exists('mysqli_connect')) {
|
|
|
876
877
|
`
|
|
877
878
|
);
|
|
878
879
|
}
|
|
879
|
-
async function
|
|
880
|
-
e.mkdir("/tmp/unzipped-wordpress"), await
|
|
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(
|
|
881
882
|
e,
|
|
882
883
|
"/tmp/unzipped-wordpress/wordpress.zip",
|
|
883
884
|
"/tmp/unzipped-wordpress"
|
|
884
885
|
);
|
|
885
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";
|
|
886
|
-
if (!e.fileExists(
|
|
887
|
+
if (!e.fileExists(a(n, "wp-config-sample.php"))) {
|
|
887
888
|
const t = e.listFiles(n);
|
|
888
889
|
if (t.length) {
|
|
889
|
-
const
|
|
890
|
+
const r = t[0];
|
|
890
891
|
e.fileExists(
|
|
891
|
-
|
|
892
|
-
) && (n =
|
|
892
|
+
a(n, r, "wp-config-sample.php")
|
|
893
|
+
) && (n = a(n, r));
|
|
893
894
|
}
|
|
894
895
|
}
|
|
895
|
-
if (e.isDir(e.documentRoot) &&
|
|
896
|
+
if (e.isDir(e.documentRoot) && F(e.documentRoot, e)) {
|
|
896
897
|
for (const t of e.listFiles(n)) {
|
|
897
|
-
const
|
|
898
|
-
e.mv(
|
|
898
|
+
const r = a(n, t), s = a(e.documentRoot, t);
|
|
899
|
+
e.mv(r, s);
|
|
899
900
|
}
|
|
900
901
|
e.rmdir(n, { recursive: !0 });
|
|
901
902
|
} else
|
|
902
903
|
e.mv(n, e.documentRoot);
|
|
903
|
-
!e.fileExists(
|
|
904
|
-
|
|
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"),
|
|
905
906
|
e.readFileAsText(
|
|
906
|
-
|
|
907
|
+
a(e.documentRoot, "/wp-config-sample.php")
|
|
907
908
|
)
|
|
908
909
|
);
|
|
909
910
|
}
|
|
910
|
-
function
|
|
911
|
+
function F(e, i) {
|
|
911
912
|
const n = i.listFiles(e);
|
|
912
913
|
return n.length === 0 || n.length === 1 && // TODO: use a constant from a site storage package
|
|
913
914
|
n[0] === "playground-site-metadata.json";
|
|
914
915
|
}
|
|
915
|
-
const
|
|
916
|
-
async function
|
|
916
|
+
const G = g(fetch);
|
|
917
|
+
async function Q(e = "latest") {
|
|
917
918
|
if (e.startsWith("https://") || e.startsWith("http://")) {
|
|
918
919
|
const t = await crypto.subtle.digest(
|
|
919
920
|
"SHA-1",
|
|
920
921
|
new TextEncoder().encode(e)
|
|
921
|
-
),
|
|
922
|
+
), r = Array.from(new Uint8Array(t)).map((s) => s.toString(16).padStart(2, "0")).join("");
|
|
922
923
|
return {
|
|
923
924
|
releaseUrl: e,
|
|
924
|
-
version: "custom-" +
|
|
925
|
+
version: "custom-" + r.substring(0, 8),
|
|
925
926
|
source: "inferred"
|
|
926
927
|
};
|
|
927
928
|
} else if (e === "trunk" || e === "nightly")
|
|
@@ -930,7 +931,7 @@ async function z(e = "latest") {
|
|
|
930
931
|
version: "nightly-" + (/* @__PURE__ */ new Date()).toISOString().split("T")[0],
|
|
931
932
|
source: "inferred"
|
|
932
933
|
};
|
|
933
|
-
let n = await (await
|
|
934
|
+
let n = await (await G(
|
|
934
935
|
"https://api.wordpress.org/core/version-check/1.7/?channel=beta"
|
|
935
936
|
)).json();
|
|
936
937
|
n = n.offers.filter(
|
|
@@ -963,18 +964,18 @@ async function z(e = "latest") {
|
|
|
963
964
|
};
|
|
964
965
|
}
|
|
965
966
|
export {
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
967
|
+
x as bootRequestHandler,
|
|
968
|
+
H as bootWordPress,
|
|
969
|
+
S as defineWpConfigConstants,
|
|
970
|
+
v as ensureWpConfig,
|
|
971
|
+
I as getFileNotFoundActionForWordPress,
|
|
972
|
+
z as getLoadedWordPressVersion,
|
|
973
|
+
C as preloadPhpInfoRoute,
|
|
974
|
+
D as preloadSqliteIntegration,
|
|
975
|
+
Q as resolveWordPressRelease,
|
|
976
|
+
O as setupPlatformLevelMuPlugins,
|
|
977
|
+
A as unzipWordPress,
|
|
978
|
+
U as versionStringToLoadedWordPressVersion,
|
|
979
|
+
W as wordPressRewriteRules
|
|
979
980
|
};
|
|
980
981
|
//# 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": "2.0.0",
|
|
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": "
|
|
38
|
+
"gitHead": "4aa6ec4f0fe23920f735c0050228a509d94ce077",
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"express": "4.21.2",
|
|
41
41
|
"fs-ext": "2.1.1",
|
|
@@ -43,11 +43,11 @@
|
|
|
43
43
|
"wasm-feature-detect": "1.8.0",
|
|
44
44
|
"ws": "8.18.1",
|
|
45
45
|
"yargs": "17.7.2",
|
|
46
|
-
"@php-wasm/universal": "
|
|
47
|
-
"@php-wasm/util": "
|
|
48
|
-
"@php-wasm/logger": "
|
|
49
|
-
"@wp-playground/common": "
|
|
50
|
-
"@php-wasm/node": "
|
|
46
|
+
"@php-wasm/universal": "2.0.0",
|
|
47
|
+
"@php-wasm/util": "2.0.0",
|
|
48
|
+
"@php-wasm/logger": "2.0.0",
|
|
49
|
+
"@wp-playground/common": "2.0.0",
|
|
50
|
+
"@php-wasm/node": "2.0.0"
|
|
51
51
|
},
|
|
52
52
|
"overrides": {
|
|
53
53
|
"rollup": "^4.34.6",
|