@wp-playground/wordpress 1.1.1 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/boot.d.ts +1 -0
- package/index.cjs +18 -18
- package/index.d.ts +1 -1
- package/index.js +133 -121
- package/index.js.map +1 -1
- package/package.json +7 -7
package/boot.d.ts
CHANGED
|
@@ -99,6 +99,7 @@ export interface BootOptions {
|
|
|
99
99
|
* @return PHPRequestHandler instance with WordPress installed.
|
|
100
100
|
*/
|
|
101
101
|
export declare function bootWordPress(options: BootOptions): Promise<PHPRequestHandler>;
|
|
102
|
+
export declare function bootRequestHandler(options: BootOptions): Promise<PHPRequestHandler>;
|
|
102
103
|
/**
|
|
103
104
|
* Checks if WordPress is installed by checking if the wp-load.php file exists
|
|
104
105
|
* 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 r=require("@php-wasm/util"),d=require("@wp-playground/common"),s=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
|
|
347
|
-
${
|
|
348
|
-
$wp_config_path = ${
|
|
346
|
+
`;async function f(e,i,n,t="rewrite"){const a=r.phpVars({wpConfigPath:i,constants:n,whenAlreadyDefined:t});if((await e.run({code:`<?php ob_start(); ?>
|
|
347
|
+
${E}
|
|
348
|
+
$wp_config_path = ${a.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, ${a.constants}, ${a.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 _(e,i){const n=r.joinPaths(i,"wp-config.php"),t={DB_NAME:"wordpress"};!e.fileExists(n)&&e.fileExists(r.joinPaths(i,"wp-config-sample.php"))&&await e.writeFile(n,await e.readFileAsBuffer(r.joinPaths(i,"wp-config-sample.php"))),await f(e,n,t,"skip")}async function T(e){var t,a;const i=await c(e),n=await i.getPrimaryPhp();if((t=e.hooks)!=null&&t.beforeWordPressFiles&&await e.hooks.beforeWordPressFiles(n),e.wordPressZip&&await y(n,await e.wordPressZip),e.constants)for(const o in e.constants)n.defineConstant(o,e.constants[o]);if(n.defineConstant("WP_HOME",e.siteUrl),n.defineConstant("WP_SITEURL",e.siteUrl),await _(n,i.documentRoot),(a=e.hooks)!=null&&a.beforeDatabaseSetup&&await e.hooks.beforeDatabaseSetup(n),e.sqliteIntegrationPluginZip&&await b(n,await e.sqliteIntegrationPluginZip),await p(n)||await R(n),!await p(n))throw new Error("WordPress installation has failed.");return i}async function c(e){async function i(t,a){const o=new s.PHP(await e.createPhpRuntime());return e.sapiName&&o.setSapiName(e.sapiName),t&&(o.requestHandler=t),e.phpIniEntries&&s.setPhpIniEntries(o,e.phpIniEntries),a?(await w(o),await s.writeFiles(o,"/",e.createFiles||{}),await m(o,r.joinPaths(new URL(e.siteUrl).pathname,"phpinfo.php"))):s.proxyFileSystem(await t.getPrimaryPhp(),o,["/tmp",t.documentRoot,"/internal/shared"]),e.spawnHandler&&await o.setSpawnHandler(e.spawnHandler(t.processManager)),s.rotatePHPRuntime({php:o,cwd:t.documentRoot,recreateRuntime:e.createPhpRuntime,maxRequests:400}),o}const n=new s.PHPRequestHandler({phpFactory:async({isPrimary:t})=>i(n,t),documentRoot:e.documentRoot||"/wordpress",absoluteUrl:e.siteUrl,rewriteRules:$,getFileNotFoundAction:e.getFileNotFoundAction??h,cookieStore:e.cookieStore});return n}async function p(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 R(e){await s.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"&&
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
381
|
+
`,env:{DOCUMENT_ROOT:e.documentRoot}})).text!=="1"&&k.logger.warn("Failed to default to pretty permalinks after WP install.")}function h(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 a=(await i.run({code:`<?php
|
|
382
|
+
require '${e.documentRoot}/wp-includes/version.php';
|
|
383
|
+
echo $wp_version;
|
|
384
|
+
`})).text;if(!a)throw new Error("Unable to read loaded WordPress version.");return g(a)}finally{n()}}function g(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 $=[{match:/^\/(.*?)(\/wp-(content|admin|includes)\/.*)/g,replacement:"$2"}];async function w(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 m(e,
|
|
612
|
+
})();`)}async function m(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 ( ${
|
|
614
|
+
if ( isset($_SERVER['REQUEST_URI']) && ${r.phpVar(i)} === $_SERVER['REQUEST_URI'] ) {
|
|
615
615
|
phpinfo();
|
|
616
616
|
exit;
|
|
617
617
|
}
|
|
618
|
-
`)}async function b(e,
|
|
618
|
+
`)}async function b(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 d.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 o=(await e.readFileAsText(r.joinPaths(n,"db.copy"))).replace("'{SQLITE_IMPLEMENTATION_FOLDER_PATH}'",r.phpVar(n)).replace("'{SQLITE_PLUGIN}'",r.phpVar(r.joinPaths(n,"load.php"))),P=r.joinPaths(await e.documentRoot,"wp-content/db.php"),l=`<?php
|
|
619
619
|
// Do not preload this if WordPress comes with a custom db.php file.
|
|
620
|
-
if(file_exists(${
|
|
620
|
+
if(file_exists(${r.phpVar(P)})) {
|
|
621
621
|
return;
|
|
622
622
|
}
|
|
623
|
-
?>`,
|
|
623
|
+
?>`,u="/internal/shared/mu-plugins/sqlite-database-integration.php";await e.writeFile(u,l+o),await e.writeFile("/internal/shared/preload/0-sqlite.php",l+`<?php
|
|
624
624
|
|
|
625
625
|
/**
|
|
626
626
|
* Loads the SQLite integration plugin before WordPress is loaded
|
|
@@ -670,7 +670,7 @@ class Playground_SQLite_Integration_Loader {
|
|
|
670
670
|
$GLOBALS['wpdb']->$name = $value;
|
|
671
671
|
}
|
|
672
672
|
protected function load_sqlite_integration() {
|
|
673
|
-
require_once ${
|
|
673
|
+
require_once ${r.phpVar(u)};
|
|
674
674
|
}
|
|
675
675
|
}
|
|
676
676
|
$wpdb = $GLOBALS['wpdb'] = new Playground_SQLite_Integration_Loader();
|
|
@@ -692,5 +692,5 @@ if(!function_exists('mysqli_connect')) {
|
|
|
692
692
|
var_dump(isset($wpdb));
|
|
693
693
|
die("SQLite integration not loaded " . get_class($wpdb));
|
|
694
694
|
}
|
|
695
|
-
`)}async function y(e,
|
|
695
|
+
`)}async function y(e,i){e.mkdir("/tmp/unzipped-wordpress"),await d.unzipFile(e,i,"/tmp/unzipped-wordpress"),e.fileExists("/tmp/unzipped-wordpress/wordpress.zip")&&await d.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(r.joinPaths(n,"wp-config-sample.php"))){const t=e.listFiles(n);if(t.length){const a=t[0];e.fileExists(r.joinPaths(n,a,"wp-config-sample.php"))&&(n=r.joinPaths(n,a))}}if(e.isDir(e.documentRoot)&&v(e.documentRoot,e)){for(const t of e.listFiles(n)){const a=r.joinPaths(n,t),o=r.joinPaths(e.documentRoot,t);e.mv(a,o)}e.rmdir(n,{recursive:!0})}else e.mv(n,e.documentRoot);!e.fileExists(r.joinPaths(e.documentRoot,"wp-config.php"))&&e.fileExists(r.joinPaths(e.documentRoot,"wp-config-sample.php"))&&e.writeFile(r.joinPaths(e.documentRoot,"wp-config.php"),e.readFileAsText(r.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=d.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)),a=Array.from(new Uint8Array(t)).map(o=>o.toString(16).padStart(2,"0")).join("");return{releaseUrl:e,version:"custom-"+a.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=c;exports.bootWordPress=T;exports.defineWpConfigConstants=f;exports.ensureWpConfig=_;exports.getFileNotFoundActionForWordPress=h;exports.getLoadedWordPressVersion=S;exports.preloadPhpInfoRoute=m;exports.preloadSqliteIntegration=b;exports.resolveWordPressRelease=x;exports.setupPlatformLevelMuPlugins=w;exports.unzipWordPress=y;exports.versionStringToLoadedWordPressVersion=g;exports.wordPressRewriteRules=$;
|
|
696
696
|
//# sourceMappingURL=index.cjs.map
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PHP, UniversalPHP } from '@php-wasm/universal';
|
|
2
|
-
export { bootWordPress, getFileNotFoundActionForWordPress } from './boot';
|
|
2
|
+
export { bootWordPress, bootRequestHandler, getFileNotFoundActionForWordPress, } from './boot';
|
|
3
3
|
export { defineWpConfigConstants, ensureWpConfig } from './rewrite-wp-config';
|
|
4
4
|
export { getLoadedWordPressVersion } from './version-detect';
|
|
5
5
|
export * from './version-detect';
|
package/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { phpVars as _, joinPaths as
|
|
2
|
-
import { createMemoizedFetch as c, unzipFile as
|
|
3
|
-
import { PHPRequestHandler as h,
|
|
1
|
+
import { phpVars as _, joinPaths as a, phpVar as s } from "@php-wasm/util";
|
|
2
|
+
import { createMemoizedFetch as c, unzipFile as d } from "@wp-playground/common";
|
|
3
|
+
import { PHPRequestHandler as h, withPHPIniValues as g, PHP as $, setPhpIniEntries as w, writeFiles as m, proxyFileSystem as b, rotatePHPRuntime as y } from "@php-wasm/universal";
|
|
4
4
|
import { logger as k } from "@php-wasm/logger";
|
|
5
5
|
const P = `<?php
|
|
6
6
|
|
|
@@ -348,8 +348,8 @@ function skip_whitespace($tokens) {
|
|
|
348
348
|
return $output;
|
|
349
349
|
}
|
|
350
350
|
`;
|
|
351
|
-
async function E(e, i,
|
|
352
|
-
const o = _({ wpConfigPath: i, constants:
|
|
351
|
+
async function E(e, i, n, t = "rewrite") {
|
|
352
|
+
const o = _({ wpConfigPath: i, constants: n, whenAlreadyDefined: t });
|
|
353
353
|
if ((await e.run({
|
|
354
354
|
code: `<?php ob_start(); ?>
|
|
355
355
|
${P}
|
|
@@ -365,55 +365,59 @@ async function E(e, i, t, n = "rewrite") {
|
|
|
365
365
|
throw new Error("Failed to rewrite constants in wp-config.php.");
|
|
366
366
|
}
|
|
367
367
|
async function T(e, i) {
|
|
368
|
-
const
|
|
368
|
+
const n = a(i, "wp-config.php"), t = {
|
|
369
369
|
DB_NAME: "wordpress"
|
|
370
370
|
};
|
|
371
|
-
!e.fileExists(
|
|
372
|
-
|
|
371
|
+
!e.fileExists(n) && e.fileExists(a(i, "wp-config-sample.php")) && await e.writeFile(
|
|
372
|
+
n,
|
|
373
373
|
await e.readFileAsBuffer(
|
|
374
|
-
|
|
374
|
+
a(i, "wp-config-sample.php")
|
|
375
375
|
)
|
|
376
|
-
), await E(e,
|
|
376
|
+
), await E(e, n, t, "skip");
|
|
377
|
+
}
|
|
378
|
+
async function q(e) {
|
|
379
|
+
var t, o;
|
|
380
|
+
const i = await R(e), n = await i.getPrimaryPhp();
|
|
381
|
+
if ((t = e.hooks) != null && t.beforeWordPressFiles && await e.hooks.beforeWordPressFiles(n), e.wordPressZip && await O(n, await e.wordPressZip), e.constants)
|
|
382
|
+
for (const r in e.constants)
|
|
383
|
+
n.defineConstant(r, e.constants[r]);
|
|
384
|
+
if (n.defineConstant("WP_HOME", e.siteUrl), n.defineConstant("WP_SITEURL", e.siteUrl), await T(n, i.documentRoot), (o = e.hooks) != null && o.beforeDatabaseSetup && await e.hooks.beforeDatabaseSetup(n), e.sqliteIntegrationPluginZip && await W(
|
|
385
|
+
n,
|
|
386
|
+
await e.sqliteIntegrationPluginZip
|
|
387
|
+
), await p(n) || await S(n), !await p(n))
|
|
388
|
+
throw new Error("WordPress installation has failed.");
|
|
389
|
+
return i;
|
|
377
390
|
}
|
|
378
|
-
async function
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
)) : m(await a.getPrimaryPhp(), s, [
|
|
391
|
+
async function R(e) {
|
|
392
|
+
async function i(t, o) {
|
|
393
|
+
const r = new $(await e.createPhpRuntime());
|
|
394
|
+
return e.sapiName && r.setSapiName(e.sapiName), t && (r.requestHandler = t), e.phpIniEntries && w(r, e.phpIniEntries), o ? (await I(r), await m(r, "/", e.createFiles || {}), await U(
|
|
395
|
+
r,
|
|
396
|
+
a(new URL(e.siteUrl).pathname, "phpinfo.php")
|
|
397
|
+
)) : b(await t.getPrimaryPhp(), r, [
|
|
386
398
|
"/tmp",
|
|
387
|
-
|
|
399
|
+
t.documentRoot,
|
|
388
400
|
"/internal/shared"
|
|
389
|
-
]), e.spawnHandler && await
|
|
390
|
-
e.spawnHandler(
|
|
391
|
-
),
|
|
392
|
-
php:
|
|
393
|
-
cwd:
|
|
401
|
+
]), e.spawnHandler && await r.setSpawnHandler(
|
|
402
|
+
e.spawnHandler(t.processManager)
|
|
403
|
+
), y({
|
|
404
|
+
php: r,
|
|
405
|
+
cwd: t.documentRoot,
|
|
394
406
|
recreateRuntime: e.createPhpRuntime,
|
|
395
407
|
maxRequests: 400
|
|
396
|
-
}),
|
|
408
|
+
}), r;
|
|
397
409
|
}
|
|
398
|
-
const
|
|
399
|
-
phpFactory: async ({ isPrimary:
|
|
410
|
+
const n = new h({
|
|
411
|
+
phpFactory: async ({ isPrimary: t }) => i(n, t),
|
|
400
412
|
documentRoot: e.documentRoot || "/wordpress",
|
|
401
413
|
absoluteUrl: e.siteUrl,
|
|
402
|
-
rewriteRules:
|
|
403
|
-
getFileNotFoundAction: e.getFileNotFoundAction ??
|
|
414
|
+
rewriteRules: L,
|
|
415
|
+
getFileNotFoundAction: e.getFileNotFoundAction ?? v,
|
|
404
416
|
cookieStore: e.cookieStore
|
|
405
|
-
})
|
|
406
|
-
|
|
407
|
-
for (const a in e.constants)
|
|
408
|
-
n.defineConstant(a, e.constants[a]);
|
|
409
|
-
if (n.defineConstant("WP_HOME", e.siteUrl), n.defineConstant("WP_SITEURL", e.siteUrl), await T(n, t.documentRoot), (d = e.hooks) != null && d.beforeDatabaseSetup && await e.hooks.beforeDatabaseSetup(n), e.sqliteIntegrationPluginZip && await U(
|
|
410
|
-
n,
|
|
411
|
-
await e.sqliteIntegrationPluginZip
|
|
412
|
-
), await f(n) || await R(n), !await f(n))
|
|
413
|
-
throw new Error("WordPress installation has failed.");
|
|
414
|
-
return t;
|
|
417
|
+
});
|
|
418
|
+
return n;
|
|
415
419
|
}
|
|
416
|
-
async function
|
|
420
|
+
async function p(e) {
|
|
417
421
|
return (await e.run({
|
|
418
422
|
code: `<?php
|
|
419
423
|
ob_start();
|
|
@@ -432,8 +436,8 @@ async function f(e) {
|
|
|
432
436
|
}
|
|
433
437
|
})).text === "1";
|
|
434
438
|
}
|
|
435
|
-
async function
|
|
436
|
-
await
|
|
439
|
+
async function S(e) {
|
|
440
|
+
await g(
|
|
437
441
|
e,
|
|
438
442
|
{
|
|
439
443
|
disable_functions: "fsockopen",
|
|
@@ -477,38 +481,45 @@ async function R(e) {
|
|
|
477
481
|
}
|
|
478
482
|
})).text !== "1" && k.warn("Failed to default to pretty permalinks after WP install.");
|
|
479
483
|
}
|
|
480
|
-
function
|
|
484
|
+
function v(e) {
|
|
481
485
|
return {
|
|
482
486
|
type: "internal-redirect",
|
|
483
487
|
uri: "/index.php"
|
|
484
488
|
};
|
|
485
489
|
}
|
|
486
|
-
async function
|
|
487
|
-
const n =
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
490
|
+
async function M(e) {
|
|
491
|
+
const { php: i, reap: n } = await e.processManager.acquirePHPInstance({
|
|
492
|
+
considerPrimary: !0
|
|
493
|
+
});
|
|
494
|
+
try {
|
|
495
|
+
const o = (await i.run({
|
|
496
|
+
code: `<?php
|
|
497
|
+
require '${e.documentRoot}/wp-includes/version.php';
|
|
498
|
+
echo $wp_version;
|
|
499
|
+
`
|
|
500
|
+
})).text;
|
|
501
|
+
if (!o)
|
|
502
|
+
throw new Error("Unable to read loaded WordPress version.");
|
|
503
|
+
return x(o);
|
|
504
|
+
} finally {
|
|
505
|
+
n();
|
|
506
|
+
}
|
|
496
507
|
}
|
|
497
|
-
function
|
|
508
|
+
function x(e) {
|
|
498
509
|
if (/-(alpha|beta|RC)\d*-\d+$/.test(e))
|
|
499
510
|
return "nightly";
|
|
500
511
|
if (/-(beta|RC)\d*$/.test(e))
|
|
501
512
|
return "beta";
|
|
502
|
-
const
|
|
503
|
-
return
|
|
513
|
+
const t = e.match(/^(\d+\.\d+)(?:\.\d+)?$/);
|
|
514
|
+
return t !== null ? t[1] : e;
|
|
504
515
|
}
|
|
505
|
-
const
|
|
516
|
+
const L = [
|
|
506
517
|
{
|
|
507
518
|
match: /^\/(.*?)(\/wp-(content|admin|includes)\/.*)/g,
|
|
508
519
|
replacement: "$2"
|
|
509
520
|
}
|
|
510
521
|
];
|
|
511
|
-
async function
|
|
522
|
+
async function I(e) {
|
|
512
523
|
await e.mkdir("/internal/shared/mu-plugins"), await e.writeFile(
|
|
513
524
|
"/internal/shared/preload/env.php",
|
|
514
525
|
`<?php
|
|
@@ -751,41 +762,41 @@ async function L(e) {
|
|
|
751
762
|
})();`
|
|
752
763
|
);
|
|
753
764
|
}
|
|
754
|
-
async function
|
|
765
|
+
async function U(e, i = "/phpinfo.php") {
|
|
755
766
|
await e.writeFile(
|
|
756
767
|
"/internal/shared/preload/phpinfo.php",
|
|
757
768
|
`<?php
|
|
758
769
|
// Render PHPInfo if the requested page is /phpinfo.php
|
|
759
|
-
if ( ${
|
|
770
|
+
if ( isset($_SERVER['REQUEST_URI']) && ${s(i)} === $_SERVER['REQUEST_URI'] ) {
|
|
760
771
|
phpinfo();
|
|
761
772
|
exit;
|
|
762
773
|
}
|
|
763
774
|
`
|
|
764
775
|
);
|
|
765
776
|
}
|
|
766
|
-
async function
|
|
777
|
+
async function W(e, i) {
|
|
767
778
|
await e.isDir("/tmp/sqlite-database-integration") && await e.rmdir("/tmp/sqlite-database-integration", {
|
|
768
779
|
recursive: !0
|
|
769
|
-
}), await e.mkdir("/tmp/sqlite-database-integration"), await
|
|
770
|
-
const
|
|
771
|
-
await e.mv(
|
|
772
|
-
const
|
|
773
|
-
|
|
780
|
+
}), await e.mkdir("/tmp/sqlite-database-integration"), await d(e, i, "/tmp/sqlite-database-integration");
|
|
781
|
+
const n = "/internal/shared/sqlite-database-integration", t = `/tmp/sqlite-database-integration/${(await e.listFiles("/tmp/sqlite-database-integration"))[0]}`;
|
|
782
|
+
await e.mv(t, n), e.defineConstant("WP_SQLITE_AST_DRIVER", !0), await e.defineConstant("SQLITE_MAIN_FILE", "1");
|
|
783
|
+
const r = (await e.readFileAsText(
|
|
784
|
+
a(n, "db.copy")
|
|
774
785
|
)).replace(
|
|
775
786
|
"'{SQLITE_IMPLEMENTATION_FOLDER_PATH}'",
|
|
776
|
-
|
|
787
|
+
s(n)
|
|
777
788
|
).replace(
|
|
778
789
|
"'{SQLITE_PLUGIN}'",
|
|
779
|
-
|
|
780
|
-
),
|
|
790
|
+
s(a(n, "load.php"))
|
|
791
|
+
), f = a(await e.documentRoot, "wp-content/db.php"), l = `<?php
|
|
781
792
|
// Do not preload this if WordPress comes with a custom db.php file.
|
|
782
|
-
if(file_exists(${
|
|
793
|
+
if(file_exists(${s(f)})) {
|
|
783
794
|
return;
|
|
784
795
|
}
|
|
785
|
-
?>`,
|
|
786
|
-
await e.writeFile(
|
|
796
|
+
?>`, u = "/internal/shared/mu-plugins/sqlite-database-integration.php";
|
|
797
|
+
await e.writeFile(u, l + r), await e.writeFile(
|
|
787
798
|
"/internal/shared/preload/0-sqlite.php",
|
|
788
|
-
|
|
799
|
+
l + `<?php
|
|
789
800
|
|
|
790
801
|
/**
|
|
791
802
|
* Loads the SQLite integration plugin before WordPress is loaded
|
|
@@ -835,7 +846,7 @@ class Playground_SQLite_Integration_Loader {
|
|
|
835
846
|
$GLOBALS['wpdb']->$name = $value;
|
|
836
847
|
}
|
|
837
848
|
protected function load_sqlite_integration() {
|
|
838
|
-
require_once ${
|
|
849
|
+
require_once ${s(u)};
|
|
839
850
|
}
|
|
840
851
|
}
|
|
841
852
|
$wpdb = $GLOBALS['wpdb'] = new Playground_SQLite_Integration_Loader();
|
|
@@ -863,49 +874,49 @@ if(!function_exists('mysqli_connect')) {
|
|
|
863
874
|
`
|
|
864
875
|
);
|
|
865
876
|
}
|
|
866
|
-
async function
|
|
867
|
-
e.mkdir("/tmp/unzipped-wordpress"), await
|
|
877
|
+
async function O(e, i) {
|
|
878
|
+
e.mkdir("/tmp/unzipped-wordpress"), await d(e, i, "/tmp/unzipped-wordpress"), e.fileExists("/tmp/unzipped-wordpress/wordpress.zip") && await d(
|
|
868
879
|
e,
|
|
869
880
|
"/tmp/unzipped-wordpress/wordpress.zip",
|
|
870
881
|
"/tmp/unzipped-wordpress"
|
|
871
882
|
);
|
|
872
|
-
let
|
|
873
|
-
if (!e.fileExists(
|
|
874
|
-
const
|
|
875
|
-
if (
|
|
876
|
-
const o =
|
|
883
|
+
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";
|
|
884
|
+
if (!e.fileExists(a(n, "wp-config-sample.php"))) {
|
|
885
|
+
const t = e.listFiles(n);
|
|
886
|
+
if (t.length) {
|
|
887
|
+
const o = t[0];
|
|
877
888
|
e.fileExists(
|
|
878
|
-
|
|
879
|
-
) && (
|
|
889
|
+
a(n, o, "wp-config-sample.php")
|
|
890
|
+
) && (n = a(n, o));
|
|
880
891
|
}
|
|
881
892
|
}
|
|
882
|
-
if (e.isDir(e.documentRoot) &&
|
|
883
|
-
for (const
|
|
884
|
-
const o =
|
|
885
|
-
e.mv(o,
|
|
893
|
+
if (e.isDir(e.documentRoot) && C(e.documentRoot, e)) {
|
|
894
|
+
for (const t of e.listFiles(n)) {
|
|
895
|
+
const o = a(n, t), r = a(e.documentRoot, t);
|
|
896
|
+
e.mv(o, r);
|
|
886
897
|
}
|
|
887
|
-
e.rmdir(
|
|
898
|
+
e.rmdir(n, { recursive: !0 });
|
|
888
899
|
} else
|
|
889
|
-
e.mv(
|
|
890
|
-
!e.fileExists(
|
|
891
|
-
|
|
900
|
+
e.mv(n, e.documentRoot);
|
|
901
|
+
!e.fileExists(a(e.documentRoot, "wp-config.php")) && e.fileExists(a(e.documentRoot, "wp-config-sample.php")) && e.writeFile(
|
|
902
|
+
a(e.documentRoot, "wp-config.php"),
|
|
892
903
|
e.readFileAsText(
|
|
893
|
-
|
|
904
|
+
a(e.documentRoot, "/wp-config-sample.php")
|
|
894
905
|
)
|
|
895
906
|
);
|
|
896
907
|
}
|
|
897
|
-
function
|
|
898
|
-
const
|
|
899
|
-
return
|
|
900
|
-
|
|
908
|
+
function C(e, i) {
|
|
909
|
+
const n = i.listFiles(e);
|
|
910
|
+
return n.length === 0 || n.length === 1 && // TODO: use a constant from a site storage package
|
|
911
|
+
n[0] === "playground-site-metadata.json";
|
|
901
912
|
}
|
|
902
|
-
const
|
|
913
|
+
const A = c(fetch);
|
|
903
914
|
async function B(e = "latest") {
|
|
904
915
|
if (e.startsWith("https://") || e.startsWith("http://")) {
|
|
905
|
-
const
|
|
916
|
+
const t = await crypto.subtle.digest(
|
|
906
917
|
"SHA-1",
|
|
907
918
|
new TextEncoder().encode(e)
|
|
908
|
-
), o = Array.from(new Uint8Array(
|
|
919
|
+
), o = Array.from(new Uint8Array(t)).map((r) => r.toString(16).padStart(2, "0")).join("");
|
|
909
920
|
return {
|
|
910
921
|
releaseUrl: e,
|
|
911
922
|
version: "custom-" + o.substring(0, 8),
|
|
@@ -917,29 +928,29 @@ async function B(e = "latest") {
|
|
|
917
928
|
version: "nightly-" + (/* @__PURE__ */ new Date()).toISOString().split("T")[0],
|
|
918
929
|
source: "inferred"
|
|
919
930
|
};
|
|
920
|
-
let
|
|
931
|
+
let n = await (await A(
|
|
921
932
|
"https://api.wordpress.org/core/version-check/1.7/?channel=beta"
|
|
922
933
|
)).json();
|
|
923
|
-
|
|
924
|
-
(
|
|
934
|
+
n = n.offers.filter(
|
|
935
|
+
(t) => t.response === "autoupdate"
|
|
925
936
|
);
|
|
926
|
-
for (const
|
|
927
|
-
if (e === "beta" &&
|
|
937
|
+
for (const t of n) {
|
|
938
|
+
if (e === "beta" && t.version.includes("beta"))
|
|
928
939
|
return {
|
|
929
|
-
releaseUrl:
|
|
930
|
-
version:
|
|
940
|
+
releaseUrl: t.download,
|
|
941
|
+
version: t.version,
|
|
931
942
|
source: "api"
|
|
932
943
|
};
|
|
933
|
-
if (e === "latest" && !
|
|
944
|
+
if (e === "latest" && !t.version.includes("beta"))
|
|
934
945
|
return {
|
|
935
|
-
releaseUrl:
|
|
936
|
-
version:
|
|
946
|
+
releaseUrl: t.download,
|
|
947
|
+
version: t.version,
|
|
937
948
|
source: "api"
|
|
938
949
|
};
|
|
939
|
-
if (
|
|
950
|
+
if (t.version.substring(0, e.length) === e)
|
|
940
951
|
return {
|
|
941
|
-
releaseUrl:
|
|
942
|
-
version:
|
|
952
|
+
releaseUrl: t.download,
|
|
953
|
+
version: t.version,
|
|
943
954
|
source: "api"
|
|
944
955
|
};
|
|
945
956
|
}
|
|
@@ -950,17 +961,18 @@ async function B(e = "latest") {
|
|
|
950
961
|
};
|
|
951
962
|
}
|
|
952
963
|
export {
|
|
953
|
-
|
|
964
|
+
R as bootRequestHandler,
|
|
965
|
+
q as bootWordPress,
|
|
954
966
|
E as defineWpConfigConstants,
|
|
955
967
|
T as ensureWpConfig,
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
968
|
+
v as getFileNotFoundActionForWordPress,
|
|
969
|
+
M as getLoadedWordPressVersion,
|
|
970
|
+
U as preloadPhpInfoRoute,
|
|
971
|
+
W as preloadSqliteIntegration,
|
|
960
972
|
B as resolveWordPressRelease,
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
973
|
+
I as setupPlatformLevelMuPlugins,
|
|
974
|
+
O as unzipWordPress,
|
|
975
|
+
x as versionStringToLoadedWordPressVersion,
|
|
976
|
+
L as wordPressRewriteRules
|
|
965
977
|
};
|
|
966
978
|
//# 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": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
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": "977f8e90eabb2c8d4eed75677ddd9fb6c13274ae",
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"comlink": "^4.4.1",
|
|
41
41
|
"express": "4.21.2",
|
|
@@ -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": "1.1.
|
|
47
|
-
"@php-wasm/util": "1.1.
|
|
48
|
-
"@php-wasm/logger": "1.1.
|
|
49
|
-
"@wp-playground/common": "1.1.
|
|
50
|
-
"@php-wasm/node": "1.1.
|
|
46
|
+
"@php-wasm/universal": "1.1.3",
|
|
47
|
+
"@php-wasm/util": "1.1.3",
|
|
48
|
+
"@php-wasm/logger": "1.1.3",
|
|
49
|
+
"@wp-playground/common": "1.1.3",
|
|
50
|
+
"@php-wasm/node": "1.1.3"
|
|
51
51
|
},
|
|
52
52
|
"overrides": {
|
|
53
53
|
"rollup": "^4.34.6",
|