@wp-playground/wordpress 2.0.1 → 2.0.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/index.cjs +15 -15
- package/index.js +111 -104
- package/index.js.map +1 -1
- package/package.json +10 -8
package/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@php-wasm/util"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@php-wasm/util"),p=require("@wp-playground/common"),_=require("@php-wasm/logger"),d=require("@php-wasm/universal"),T=`<?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 c(e,r,n,t="rewrite"){const i=o.phpVars({wpConfigPath:r,constants:n,whenAlreadyDefined:t});if((await e.run({code:`<?php ob_start(); ?>
|
|
347
|
+
${T}
|
|
348
|
+
$wp_config_path = ${i.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, ${i.constants}, ${i.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 h(e,r){const n=o.joinPaths(r,"wp-config.php"),t={DB_NAME:"wordpress"};!e.fileExists(n)&&e.fileExists(o.joinPaths(r,"wp-config-sample.php"))&&await e.writeFile(n,await e.readFileAsBuffer(o.joinPaths(r,"wp-config-sample.php"))),await c(e,n,t,"skip")}async function S(e){var t,i;const r=await g(e),n=await r.getPrimaryPhp();if((t=e.hooks)!=null&&t.beforeWordPressFiles&&await e.hooks.beforeWordPressFiles(n),e.wordPressZip&&await k(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 h(n,r.documentRoot),(i=e.hooks)!=null&&i.beforeDatabaseSetup&&await e.hooks.beforeDatabaseSetup(n),e.sqliteIntegrationPluginZip&&await P(n,await e.sqliteIntegrationPluginZip),!e.dataSqlPath&&(await f(n)||await R(n),!await f(n)))throw new Error("WordPress installation has failed.");return r}async function g(e){const r=e.spawnHandler??d.sandboxedSpawnHandlerFactory;async function n(i,s){const a=new d.PHP(await e.createPhpRuntime());return e.sapiName&&a.setSapiName(e.sapiName),i&&(a.requestHandler=i),e.phpIniEntries&&d.setPhpIniEntries(a,e.phpIniEntries),s?(await b(a),await d.writeFiles(a,"/",e.createFiles||{}),await y(a,o.joinPaths(new URL(e.siteUrl).pathname,"phpinfo.php"))):d.proxyFileSystem(await i.getPrimaryPhp(),a,["/tmp",i.documentRoot,"/internal/shared"]),r&&await a.setSpawnHandler(r(i.processManager)),d.rotatePHPRuntime({php:a,cwd:i.documentRoot,recreateRuntime:e.createPhpRuntime,maxRequests:400}),e.onPHPInstanceCreated&&await e.onPHPInstanceCreated(a),a}const t=new d.PHPRequestHandler({phpFactory:async({isPrimary:i})=>n(t,i),documentRoot:e.documentRoot||"/wordpress",absoluteUrl:e.siteUrl,rewriteRules:m,getFileNotFoundAction:e.getFileNotFoundAction??$,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
|
|
366
|
+
`,env:{DOCUMENT_ROOT:e.documentRoot}})).text==="1"}async function R(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"&&
|
|
381
|
+
`,env:{DOCUMENT_ROOT:e.documentRoot}})).text!=="1"&&_.logger.warn("Failed to default to pretty permalinks after WP install.")}function $(e){return{type:"internal-redirect",uri:"/index.php"}}async function v(e){const{php:r,reap:n}=await e.processManager.acquirePHPInstance({considerPrimary:!0});try{const i=(await r.run({code:`<?php
|
|
382
382
|
require '${e.documentRoot}/wp-includes/version.php';
|
|
383
383
|
echo $wp_version;
|
|
384
|
-
`})).text;if(!
|
|
384
|
+
`})).text;if(!i)throw new Error("Unable to read loaded WordPress version.");return w(i)}finally{n()}}function w(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 m=[{match:/^\/(.*?)(\/wp-(content|admin|includes)\/.*)/g,replacement:"$2"}];async function b(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 y(e,r="/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']) && ${o.phpVar(
|
|
614
|
+
if ( isset($_SERVER['REQUEST_URI']) && ${o.phpVar(r)} === $_SERVER['REQUEST_URI'] ) {
|
|
615
615
|
phpinfo();
|
|
616
616
|
exit;
|
|
617
617
|
}
|
|
618
|
-
`)}async function
|
|
618
|
+
`)}async function P(e,r){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,r,"/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"),l=`<?php
|
|
619
619
|
// Do not preload this if WordPress comes with a custom db.php file.
|
|
620
620
|
if(file_exists(${o.phpVar(a)})) {
|
|
621
621
|
return;
|
|
622
622
|
}
|
|
623
|
-
?>`,
|
|
623
|
+
?>`,u="/internal/shared/mu-plugins/sqlite-database-integration.php";await e.writeFile(u,l+s),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 ${o.phpVar(
|
|
673
|
+
require_once ${o.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
|
|
695
|
+
`)}async function k(e,r){e.mkdir("/tmp/unzipped-wordpress"),await p.unzipFile(e,r,"/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 i=e.listFiles(n);if(i.length){const s=i[0];e.fileExists(o.joinPaths(n,s,"wp-config-sample.php"))&&(n=o.joinPaths(n,s))}}const t=(i,s,a)=>{if(a.isDir(i)&&a.isDir(s))for(const l of a.listFiles(i)){const u=o.joinPaths(i,l),E=o.joinPaths(s,l);t(u,E,a)}else{if(a.fileExists(s)){const l=i.replace(/^\/tmp\/unzipped-wordpress\//,"/");_.logger.warn(`Skipping ${l} because something exists at the target path.`);return}a.mv(i,s)}};t(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 L=p.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)),i=Array.from(new Uint8Array(t)).map(s=>s.toString(16).padStart(2,"0")).join("");return{releaseUrl:e,version:"custom-"+i.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=g;exports.bootWordPress=S;exports.defineWpConfigConstants=c;exports.ensureWpConfig=h;exports.getFileNotFoundActionForWordPress=$;exports.getLoadedWordPressVersion=v;exports.preloadPhpInfoRoute=y;exports.preloadSqliteIntegration=P;exports.resolveWordPressRelease=x;exports.setupPlatformLevelMuPlugins=b;exports.unzipWordPress=k;exports.versionStringToLoadedWordPressVersion=w;exports.wordPressRewriteRules=m;
|
|
696
696
|
//# sourceMappingURL=index.cjs.map
|
package/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { phpVars as
|
|
2
|
-
import { createMemoizedFetch as
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { phpVars as h, joinPaths as s, dirname as $, basename as g, phpVar as l } from "@php-wasm/util";
|
|
2
|
+
import { createMemoizedFetch as w, unzipFile as p } from "@wp-playground/common";
|
|
3
|
+
import { logger as _ } from "@php-wasm/logger";
|
|
4
|
+
import { sandboxedSpawnHandlerFactory as m, PHPRequestHandler as b, withPHPIniValues as y, PHP as k, setPhpIniEntries as P, writeFiles as E, proxyFileSystem as T, rotatePHPRuntime as S } from "@php-wasm/universal";
|
|
5
5
|
const R = `<?php
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -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, r, n, t = "rewrite") {
|
|
352
|
+
const i = h({ wpConfigPath: r, constants: n, whenAlreadyDefined: t });
|
|
353
353
|
if ((await e.run({
|
|
354
354
|
code: `<?php ob_start(); ?>
|
|
355
355
|
${R}
|
|
356
|
-
$wp_config_path = ${
|
|
356
|
+
$wp_config_path = ${i.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, ${i.constants}, ${i.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,56 +364,56 @@ async function S(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 x(e, r) {
|
|
368
|
+
const n = s(r, "wp-config.php"), t = {
|
|
369
369
|
DB_NAME: "wordpress"
|
|
370
370
|
};
|
|
371
|
-
!e.fileExists(n) && e.fileExists(
|
|
371
|
+
!e.fileExists(n) && e.fileExists(s(r, "wp-config-sample.php")) && await e.writeFile(
|
|
372
372
|
n,
|
|
373
373
|
await e.readFileAsBuffer(
|
|
374
|
-
|
|
374
|
+
s(r, "wp-config-sample.php")
|
|
375
375
|
)
|
|
376
|
-
), await
|
|
376
|
+
), await v(e, n, t, "skip");
|
|
377
377
|
}
|
|
378
|
-
async function
|
|
379
|
-
var t,
|
|
380
|
-
const
|
|
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",
|
|
378
|
+
async function M(e) {
|
|
379
|
+
var t, i;
|
|
380
|
+
const r = await L(e), n = await r.getPrimaryPhp();
|
|
381
|
+
if ((t = e.hooks) != null && t.beforeWordPressFiles && await e.hooks.beforeWordPressFiles(n), e.wordPressZip && await F(n, await e.wordPressZip), e.constants)
|
|
382
|
+
for (const o in e.constants)
|
|
383
|
+
n.defineConstant(o, e.constants[o]);
|
|
384
|
+
if (e.dataSqlPath && (n.defineConstant("DB_DIR", $(e.dataSqlPath)), n.defineConstant("DB_FILE", g(e.dataSqlPath))), n.defineConstant("WP_HOME", e.siteUrl), n.defineConstant("WP_SITEURL", e.siteUrl), await x(n, r.documentRoot), (i = e.hooks) != null && i.beforeDatabaseSetup && await e.hooks.beforeDatabaseSetup(n), e.sqliteIntegrationPluginZip && await A(
|
|
385
385
|
n,
|
|
386
386
|
await e.sqliteIntegrationPluginZip
|
|
387
|
-
), !e.dataSqlPath && (await f(n) || await
|
|
387
|
+
), !e.dataSqlPath && (await f(n) || await I(n), !await f(n)))
|
|
388
388
|
throw new Error("WordPress installation has failed.");
|
|
389
|
-
return
|
|
389
|
+
return r;
|
|
390
390
|
}
|
|
391
|
-
async function
|
|
392
|
-
const
|
|
393
|
-
async function n(
|
|
394
|
-
const
|
|
395
|
-
return e.sapiName &&
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
)) :
|
|
391
|
+
async function L(e) {
|
|
392
|
+
const r = e.spawnHandler ?? m;
|
|
393
|
+
async function n(i, o) {
|
|
394
|
+
const a = new k(await e.createPhpRuntime());
|
|
395
|
+
return e.sapiName && a.setSapiName(e.sapiName), i && (a.requestHandler = i), e.phpIniEntries && P(a, e.phpIniEntries), o ? (await C(a), await E(a, "/", e.createFiles || {}), await D(
|
|
396
|
+
a,
|
|
397
|
+
s(new URL(e.siteUrl).pathname, "phpinfo.php")
|
|
398
|
+
)) : T(await i.getPrimaryPhp(), a, [
|
|
399
399
|
"/tmp",
|
|
400
|
-
|
|
400
|
+
i.documentRoot,
|
|
401
401
|
"/internal/shared"
|
|
402
|
-
]),
|
|
403
|
-
i
|
|
404
|
-
),
|
|
405
|
-
php:
|
|
406
|
-
cwd:
|
|
402
|
+
]), r && await a.setSpawnHandler(
|
|
403
|
+
r(i.processManager)
|
|
404
|
+
), S({
|
|
405
|
+
php: a,
|
|
406
|
+
cwd: i.documentRoot,
|
|
407
407
|
recreateRuntime: e.createPhpRuntime,
|
|
408
408
|
maxRequests: 400
|
|
409
|
-
}), e.onPHPInstanceCreated && await e.onPHPInstanceCreated(
|
|
409
|
+
}), e.onPHPInstanceCreated && await e.onPHPInstanceCreated(a), a;
|
|
410
410
|
}
|
|
411
|
-
const t = new
|
|
412
|
-
phpFactory: async ({ isPrimary:
|
|
411
|
+
const t = new b({
|
|
412
|
+
phpFactory: async ({ isPrimary: i }) => n(t, i),
|
|
413
413
|
documentRoot: e.documentRoot || "/wordpress",
|
|
414
414
|
absoluteUrl: e.siteUrl,
|
|
415
|
-
rewriteRules:
|
|
416
|
-
getFileNotFoundAction: e.getFileNotFoundAction ??
|
|
415
|
+
rewriteRules: O,
|
|
416
|
+
getFileNotFoundAction: e.getFileNotFoundAction ?? U,
|
|
417
417
|
cookieStore: e.cookieStore
|
|
418
418
|
});
|
|
419
419
|
return t;
|
|
@@ -437,8 +437,8 @@ async function f(e) {
|
|
|
437
437
|
}
|
|
438
438
|
})).text === "1";
|
|
439
439
|
}
|
|
440
|
-
async function
|
|
441
|
-
await
|
|
440
|
+
async function I(e) {
|
|
441
|
+
await y(
|
|
442
442
|
e,
|
|
443
443
|
{
|
|
444
444
|
disable_functions: "fsockopen",
|
|
@@ -480,33 +480,33 @@ async function L(e) {
|
|
|
480
480
|
env: {
|
|
481
481
|
DOCUMENT_ROOT: e.documentRoot
|
|
482
482
|
}
|
|
483
|
-
})).text !== "1" &&
|
|
483
|
+
})).text !== "1" && _.warn("Failed to default to pretty permalinks after WP install.");
|
|
484
484
|
}
|
|
485
|
-
function
|
|
485
|
+
function U(e) {
|
|
486
486
|
return {
|
|
487
487
|
type: "internal-redirect",
|
|
488
488
|
uri: "/index.php"
|
|
489
489
|
};
|
|
490
490
|
}
|
|
491
491
|
async function z(e) {
|
|
492
|
-
const { php:
|
|
492
|
+
const { php: r, reap: n } = await e.processManager.acquirePHPInstance({
|
|
493
493
|
considerPrimary: !0
|
|
494
494
|
});
|
|
495
495
|
try {
|
|
496
|
-
const
|
|
496
|
+
const i = (await r.run({
|
|
497
497
|
code: `<?php
|
|
498
498
|
require '${e.documentRoot}/wp-includes/version.php';
|
|
499
499
|
echo $wp_version;
|
|
500
500
|
`
|
|
501
501
|
})).text;
|
|
502
|
-
if (!
|
|
502
|
+
if (!i)
|
|
503
503
|
throw new Error("Unable to read loaded WordPress version.");
|
|
504
|
-
return
|
|
504
|
+
return W(i);
|
|
505
505
|
} finally {
|
|
506
506
|
n();
|
|
507
507
|
}
|
|
508
508
|
}
|
|
509
|
-
function
|
|
509
|
+
function W(e) {
|
|
510
510
|
if (/-(alpha|beta|RC)\d*-\d+$/.test(e))
|
|
511
511
|
return "nightly";
|
|
512
512
|
if (/-(beta|RC)\d*$/.test(e))
|
|
@@ -514,13 +514,13 @@ function U(e) {
|
|
|
514
514
|
const t = e.match(/^(\d+\.\d+)(?:\.\d+)?$/);
|
|
515
515
|
return t !== null ? t[1] : e;
|
|
516
516
|
}
|
|
517
|
-
const
|
|
517
|
+
const O = [
|
|
518
518
|
{
|
|
519
519
|
match: /^\/(.*?)(\/wp-(content|admin|includes)\/.*)/g,
|
|
520
520
|
replacement: "$2"
|
|
521
521
|
}
|
|
522
522
|
];
|
|
523
|
-
async function
|
|
523
|
+
async function C(e) {
|
|
524
524
|
await e.mkdir("/internal/shared/mu-plugins"), await e.writeFile(
|
|
525
525
|
"/internal/shared/preload/env.php",
|
|
526
526
|
`<?php
|
|
@@ -763,13 +763,13 @@ async function O(e) {
|
|
|
763
763
|
})();`
|
|
764
764
|
);
|
|
765
765
|
}
|
|
766
|
-
async function
|
|
766
|
+
async function D(e, r = "/phpinfo.php") {
|
|
767
767
|
await e.writeFile(
|
|
768
768
|
"/internal/shared/preload/phpinfo.php",
|
|
769
769
|
`<?php
|
|
770
770
|
// Render PHPInfo if the requested page is /phpinfo.php
|
|
771
|
-
if ( isset($_SERVER['REQUEST_URI']) && ${
|
|
772
|
-
|
|
771
|
+
if ( isset($_SERVER['REQUEST_URI']) && ${l(
|
|
772
|
+
r
|
|
773
773
|
)} === $_SERVER['REQUEST_URI'] ) {
|
|
774
774
|
phpinfo();
|
|
775
775
|
exit;
|
|
@@ -777,29 +777,29 @@ async function C(e, i = "/phpinfo.php") {
|
|
|
777
777
|
`
|
|
778
778
|
);
|
|
779
779
|
}
|
|
780
|
-
async function
|
|
780
|
+
async function A(e, r) {
|
|
781
781
|
await e.isDir("/tmp/sqlite-database-integration") && await e.rmdir("/tmp/sqlite-database-integration", {
|
|
782
782
|
recursive: !0
|
|
783
|
-
}), await e.mkdir("/tmp/sqlite-database-integration"), await
|
|
783
|
+
}), await e.mkdir("/tmp/sqlite-database-integration"), await p(e, r, "/tmp/sqlite-database-integration");
|
|
784
784
|
const n = "/internal/shared/sqlite-database-integration", t = `/tmp/sqlite-database-integration/${(await e.listFiles("/tmp/sqlite-database-integration"))[0]}`;
|
|
785
785
|
await e.mv(t, n), e.defineConstant("WP_SQLITE_AST_DRIVER", !0), await e.defineConstant("SQLITE_MAIN_FILE", "1");
|
|
786
|
-
const
|
|
787
|
-
|
|
786
|
+
const o = (await e.readFileAsText(
|
|
787
|
+
s(n, "db.copy")
|
|
788
788
|
)).replace(
|
|
789
789
|
"'{SQLITE_IMPLEMENTATION_FOLDER_PATH}'",
|
|
790
|
-
|
|
790
|
+
l(n)
|
|
791
791
|
).replace(
|
|
792
792
|
"'{SQLITE_PLUGIN}'",
|
|
793
|
-
|
|
794
|
-
),
|
|
793
|
+
l(s(n, "load.php"))
|
|
794
|
+
), a = s(await e.documentRoot, "wp-content/db.php"), d = `<?php
|
|
795
795
|
// Do not preload this if WordPress comes with a custom db.php file.
|
|
796
|
-
if(file_exists(${
|
|
796
|
+
if(file_exists(${l(a)})) {
|
|
797
797
|
return;
|
|
798
798
|
}
|
|
799
|
-
?>`,
|
|
800
|
-
await e.writeFile(
|
|
799
|
+
?>`, u = "/internal/shared/mu-plugins/sqlite-database-integration.php";
|
|
800
|
+
await e.writeFile(u, d + o), await e.writeFile(
|
|
801
801
|
"/internal/shared/preload/0-sqlite.php",
|
|
802
|
-
|
|
802
|
+
d + `<?php
|
|
803
803
|
|
|
804
804
|
/**
|
|
805
805
|
* Loads the SQLite integration plugin before WordPress is loaded
|
|
@@ -849,7 +849,7 @@ class Playground_SQLite_Integration_Loader {
|
|
|
849
849
|
$GLOBALS['wpdb']->$name = $value;
|
|
850
850
|
}
|
|
851
851
|
protected function load_sqlite_integration() {
|
|
852
|
-
require_once ${
|
|
852
|
+
require_once ${l(u)};
|
|
853
853
|
}
|
|
854
854
|
}
|
|
855
855
|
$wpdb = $GLOBALS['wpdb'] = new Playground_SQLite_Integration_Loader();
|
|
@@ -877,52 +877,59 @@ if(!function_exists('mysqli_connect')) {
|
|
|
877
877
|
`
|
|
878
878
|
);
|
|
879
879
|
}
|
|
880
|
-
async function
|
|
881
|
-
e.mkdir("/tmp/unzipped-wordpress"), await
|
|
880
|
+
async function F(e, r) {
|
|
881
|
+
e.mkdir("/tmp/unzipped-wordpress"), await p(e, r, "/tmp/unzipped-wordpress"), e.fileExists("/tmp/unzipped-wordpress/wordpress.zip") && await p(
|
|
882
882
|
e,
|
|
883
883
|
"/tmp/unzipped-wordpress/wordpress.zip",
|
|
884
884
|
"/tmp/unzipped-wordpress"
|
|
885
885
|
);
|
|
886
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";
|
|
887
|
-
if (!e.fileExists(
|
|
888
|
-
const
|
|
889
|
-
if (
|
|
890
|
-
const
|
|
887
|
+
if (!e.fileExists(s(n, "wp-config-sample.php"))) {
|
|
888
|
+
const i = e.listFiles(n);
|
|
889
|
+
if (i.length) {
|
|
890
|
+
const o = i[0];
|
|
891
891
|
e.fileExists(
|
|
892
|
-
|
|
893
|
-
) && (n =
|
|
892
|
+
s(n, o, "wp-config-sample.php")
|
|
893
|
+
) && (n = s(n, o));
|
|
894
894
|
}
|
|
895
895
|
}
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
const
|
|
899
|
-
|
|
896
|
+
const t = (i, o, a) => {
|
|
897
|
+
if (a.isDir(i) && a.isDir(o))
|
|
898
|
+
for (const d of a.listFiles(i)) {
|
|
899
|
+
const u = s(i, d), c = s(o, d);
|
|
900
|
+
t(u, c, a);
|
|
901
|
+
}
|
|
902
|
+
else {
|
|
903
|
+
if (a.fileExists(o)) {
|
|
904
|
+
const d = i.replace(
|
|
905
|
+
/^\/tmp\/unzipped-wordpress\//,
|
|
906
|
+
"/"
|
|
907
|
+
);
|
|
908
|
+
_.warn(
|
|
909
|
+
`Skipping ${d} because something exists at the target path.`
|
|
910
|
+
);
|
|
911
|
+
return;
|
|
912
|
+
}
|
|
913
|
+
a.mv(i, o);
|
|
900
914
|
}
|
|
901
|
-
|
|
902
|
-
}
|
|
903
|
-
e.
|
|
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"),
|
|
915
|
+
};
|
|
916
|
+
t(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(
|
|
917
|
+
s(e.documentRoot, "wp-config.php"),
|
|
906
918
|
e.readFileAsText(
|
|
907
|
-
|
|
919
|
+
s(e.documentRoot, "/wp-config-sample.php")
|
|
908
920
|
)
|
|
909
921
|
);
|
|
910
922
|
}
|
|
911
|
-
|
|
912
|
-
const n = i.listFiles(e);
|
|
913
|
-
return n.length === 0 || n.length === 1 && // TODO: use a constant from a site storage package
|
|
914
|
-
n[0] === "playground-site-metadata.json";
|
|
915
|
-
}
|
|
916
|
-
const G = g(fetch);
|
|
923
|
+
const G = w(fetch);
|
|
917
924
|
async function Q(e = "latest") {
|
|
918
925
|
if (e.startsWith("https://") || e.startsWith("http://")) {
|
|
919
926
|
const t = await crypto.subtle.digest(
|
|
920
927
|
"SHA-1",
|
|
921
928
|
new TextEncoder().encode(e)
|
|
922
|
-
),
|
|
929
|
+
), i = Array.from(new Uint8Array(t)).map((o) => o.toString(16).padStart(2, "0")).join("");
|
|
923
930
|
return {
|
|
924
931
|
releaseUrl: e,
|
|
925
|
-
version: "custom-" +
|
|
932
|
+
version: "custom-" + i.substring(0, 8),
|
|
926
933
|
source: "inferred"
|
|
927
934
|
};
|
|
928
935
|
} else if (e === "trunk" || e === "nightly")
|
|
@@ -964,18 +971,18 @@ async function Q(e = "latest") {
|
|
|
964
971
|
};
|
|
965
972
|
}
|
|
966
973
|
export {
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
974
|
+
L as bootRequestHandler,
|
|
975
|
+
M as bootWordPress,
|
|
976
|
+
v as defineWpConfigConstants,
|
|
977
|
+
x as ensureWpConfig,
|
|
978
|
+
U as getFileNotFoundActionForWordPress,
|
|
972
979
|
z as getLoadedWordPressVersion,
|
|
973
|
-
|
|
974
|
-
|
|
980
|
+
D as preloadPhpInfoRoute,
|
|
981
|
+
A as preloadSqliteIntegration,
|
|
975
982
|
Q as resolveWordPressRelease,
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
983
|
+
C as setupPlatformLevelMuPlugins,
|
|
984
|
+
F as unzipWordPress,
|
|
985
|
+
W as versionStringToLoadedWordPressVersion,
|
|
986
|
+
O as wordPressRewriteRules
|
|
980
987
|
};
|
|
981
988
|
//# 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": "2.0.
|
|
3
|
+
"version": "2.0.3",
|
|
4
4
|
"description": "WordPress-related plumbing for WordPress Playground",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -35,19 +35,18 @@
|
|
|
35
35
|
"access": "public",
|
|
36
36
|
"directory": "../../../dist/packages/playground/wordpress"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "6355c320ae2de93d4a0176e45ded2ad4cc6f4ae2",
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"express": "4.21.2",
|
|
41
|
-
"fs-ext": "2.1.1",
|
|
42
41
|
"ini": "4.1.2",
|
|
43
42
|
"wasm-feature-detect": "1.8.0",
|
|
44
43
|
"ws": "8.18.1",
|
|
45
44
|
"yargs": "17.7.2",
|
|
46
|
-
"@php-wasm/universal": "2.0.
|
|
47
|
-
"@php-wasm/util": "2.0.
|
|
48
|
-
"@php-wasm/logger": "2.0.
|
|
49
|
-
"@wp-playground/common": "2.0.
|
|
50
|
-
"@php-wasm/node": "2.0.
|
|
45
|
+
"@php-wasm/universal": "2.0.3",
|
|
46
|
+
"@php-wasm/util": "2.0.3",
|
|
47
|
+
"@php-wasm/logger": "2.0.3",
|
|
48
|
+
"@wp-playground/common": "2.0.3",
|
|
49
|
+
"@php-wasm/node": "2.0.3"
|
|
51
50
|
},
|
|
52
51
|
"overrides": {
|
|
53
52
|
"rollup": "^4.34.6",
|
|
@@ -55,5 +54,8 @@
|
|
|
55
54
|
"react-dom": "18.3.1",
|
|
56
55
|
"typescript": "5.4.5",
|
|
57
56
|
"ws": "^8.18.0"
|
|
57
|
+
},
|
|
58
|
+
"optionalDependencies": {
|
|
59
|
+
"fs-ext": "2.1.1"
|
|
58
60
|
}
|
|
59
61
|
}
|