@wp-playground/wordpress 1.1.2 → 1.1.4
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 +2 -0
- package/index.cjs +18 -18
- package/index.d.ts +1 -1
- package/index.js +147 -133
- package/index.js.map +1 -1
- package/package.json +9 -8
package/boot.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export interface Hooks {
|
|
|
9
9
|
export type DatabaseType = 'sqlite' | 'mysql' | 'custom';
|
|
10
10
|
export interface BootOptions {
|
|
11
11
|
createPhpRuntime: () => Promise<number>;
|
|
12
|
+
onPHPInstanceCreated?: (php: PHP) => Promise<void>;
|
|
12
13
|
/**
|
|
13
14
|
* Mounting and Copying is handled via hooks for starters.
|
|
14
15
|
*
|
|
@@ -99,6 +100,7 @@ export interface BootOptions {
|
|
|
99
100
|
* @return PHPRequestHandler instance with WordPress installed.
|
|
100
101
|
*/
|
|
101
102
|
export declare function bootWordPress(options: BootOptions): Promise<PHPRequestHandler>;
|
|
103
|
+
export declare function bootRequestHandler(options: BootOptions): Promise<PHPRequestHandler>;
|
|
102
104
|
/**
|
|
103
105
|
* Checks if WordPress is installed by checking if the wp-load.php file exists
|
|
104
106
|
* 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 R(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(e.dataSqlPath&&(n.defineConstant("DB_DIR",r.dirname(e.dataSqlPath)),n.defineConstant("DB_FILE",r.basename(e.dataSqlPath))),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),!e.dataSqlPath&&(await p(n)||await T(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}),e.onPHPInstanceCreated&&await e.onPHPInstanceCreated(o),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 T(e){await
|
|
366
|
+
`,env:{DOCUMENT_ROOT:e.documentRoot}})).text==="1"}async function T(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=R;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,8 +1,8 @@
|
|
|
1
|
-
import { phpVars as _, joinPaths as
|
|
2
|
-
import { createMemoizedFetch as
|
|
3
|
-
import { PHPRequestHandler as
|
|
4
|
-
import { logger as
|
|
5
|
-
const
|
|
1
|
+
import { phpVars as _, joinPaths as o, dirname as c, basename as h, phpVar as s } from "@php-wasm/util";
|
|
2
|
+
import { createMemoizedFetch as g, unzipFile as d } from "@wp-playground/common";
|
|
3
|
+
import { PHPRequestHandler as $, withPHPIniValues as w, PHP as m, setPhpIniEntries as b, writeFiles as y, proxyFileSystem as k, rotatePHPRuntime as P } from "@php-wasm/universal";
|
|
4
|
+
import { logger as E } from "@php-wasm/logger";
|
|
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 R(e, i, n, t = "rewrite") {
|
|
352
|
+
const a = _({ wpConfigPath: i, constants: n, whenAlreadyDefined: t });
|
|
353
353
|
if ((await e.run({
|
|
354
354
|
code: `<?php ob_start(); ?>
|
|
355
|
-
${
|
|
356
|
-
$wp_config_path = ${
|
|
355
|
+
${T}
|
|
356
|
+
$wp_config_path = ${a.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, ${a.constants}, ${a.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,60 @@ async function E(e, i, t, n = "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
|
|
367
|
+
async function S(e, i) {
|
|
368
|
+
const n = o(i, "wp-config.php"), t = {
|
|
369
369
|
DB_NAME: "wordpress"
|
|
370
370
|
};
|
|
371
|
-
!e.fileExists(
|
|
372
|
-
|
|
371
|
+
!e.fileExists(n) && e.fileExists(o(i, "wp-config-sample.php")) && await e.writeFile(
|
|
372
|
+
n,
|
|
373
373
|
await e.readFileAsBuffer(
|
|
374
|
-
|
|
374
|
+
o(i, "wp-config-sample.php")
|
|
375
375
|
)
|
|
376
|
-
), await
|
|
376
|
+
), await R(e, n, t, "skip");
|
|
377
377
|
}
|
|
378
|
-
async function
|
|
379
|
-
var
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
378
|
+
async function M(e) {
|
|
379
|
+
var t, a;
|
|
380
|
+
const i = await v(e), n = await i.getPrimaryPhp();
|
|
381
|
+
if ((t = e.hooks) != null && t.beforeWordPressFiles && await e.hooks.beforeWordPressFiles(n), e.wordPressZip && await D(n, await e.wordPressZip), e.constants)
|
|
382
|
+
for (const r in e.constants)
|
|
383
|
+
n.defineConstant(r, e.constants[r]);
|
|
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 S(n, i.documentRoot), (a = e.hooks) != null && a.beforeDatabaseSetup && await e.hooks.beforeDatabaseSetup(n), e.sqliteIntegrationPluginZip && await C(
|
|
385
|
+
n,
|
|
386
|
+
await e.sqliteIntegrationPluginZip
|
|
387
|
+
), !e.dataSqlPath && (await p(n) || await L(n), !await p(n)))
|
|
388
|
+
throw new Error("WordPress installation has failed.");
|
|
389
|
+
return i;
|
|
390
|
+
}
|
|
391
|
+
async function v(e) {
|
|
392
|
+
async function i(t, a) {
|
|
393
|
+
const r = new m(await e.createPhpRuntime());
|
|
394
|
+
return e.sapiName && r.setSapiName(e.sapiName), t && (r.requestHandler = t), e.phpIniEntries && b(r, e.phpIniEntries), a ? (await W(r), await y(r, "/", e.createFiles || {}), await O(
|
|
395
|
+
r,
|
|
396
|
+
o(new URL(e.siteUrl).pathname, "phpinfo.php")
|
|
397
|
+
)) : k(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
|
+
), P({
|
|
404
|
+
php: r,
|
|
405
|
+
cwd: t.documentRoot,
|
|
394
406
|
recreateRuntime: e.createPhpRuntime,
|
|
395
407
|
maxRequests: 400
|
|
396
|
-
}),
|
|
408
|
+
}), e.onPHPInstanceCreated && await e.onPHPInstanceCreated(r), r;
|
|
397
409
|
}
|
|
398
|
-
const
|
|
399
|
-
phpFactory: async ({ isPrimary:
|
|
410
|
+
const n = new $({
|
|
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: U,
|
|
415
|
+
getFileNotFoundAction: e.getFileNotFoundAction ?? x,
|
|
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 L(e) {
|
|
440
|
+
await w(
|
|
437
441
|
e,
|
|
438
442
|
{
|
|
439
443
|
disable_functions: "fsockopen",
|
|
@@ -475,40 +479,47 @@ async function R(e) {
|
|
|
475
479
|
env: {
|
|
476
480
|
DOCUMENT_ROOT: e.documentRoot
|
|
477
481
|
}
|
|
478
|
-
})).text !== "1" &&
|
|
482
|
+
})).text !== "1" && E.warn("Failed to default to pretty permalinks after WP install.");
|
|
479
483
|
}
|
|
480
|
-
function
|
|
484
|
+
function x(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 H(e) {
|
|
491
|
+
const { php: i, reap: n } = await e.processManager.acquirePHPInstance({
|
|
492
|
+
considerPrimary: !0
|
|
493
|
+
});
|
|
494
|
+
try {
|
|
495
|
+
const a = (await i.run({
|
|
496
|
+
code: `<?php
|
|
497
|
+
require '${e.documentRoot}/wp-includes/version.php';
|
|
498
|
+
echo $wp_version;
|
|
499
|
+
`
|
|
500
|
+
})).text;
|
|
501
|
+
if (!a)
|
|
502
|
+
throw new Error("Unable to read loaded WordPress version.");
|
|
503
|
+
return I(a);
|
|
504
|
+
} finally {
|
|
505
|
+
n();
|
|
506
|
+
}
|
|
496
507
|
}
|
|
497
|
-
function
|
|
508
|
+
function I(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 U = [
|
|
506
517
|
{
|
|
507
518
|
match: /^\/(.*?)(\/wp-(content|admin|includes)\/.*)/g,
|
|
508
519
|
replacement: "$2"
|
|
509
520
|
}
|
|
510
521
|
];
|
|
511
|
-
async function
|
|
522
|
+
async function W(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,43 @@ async function L(e) {
|
|
|
751
762
|
})();`
|
|
752
763
|
);
|
|
753
764
|
}
|
|
754
|
-
async function
|
|
765
|
+
async function O(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(
|
|
771
|
+
i
|
|
772
|
+
)} === $_SERVER['REQUEST_URI'] ) {
|
|
760
773
|
phpinfo();
|
|
761
774
|
exit;
|
|
762
775
|
}
|
|
763
776
|
`
|
|
764
777
|
);
|
|
765
778
|
}
|
|
766
|
-
async function
|
|
779
|
+
async function C(e, i) {
|
|
767
780
|
await e.isDir("/tmp/sqlite-database-integration") && await e.rmdir("/tmp/sqlite-database-integration", {
|
|
768
781
|
recursive: !0
|
|
769
|
-
}), await e.mkdir("/tmp/sqlite-database-integration"), await
|
|
770
|
-
const
|
|
771
|
-
await e.mv(
|
|
772
|
-
const
|
|
773
|
-
|
|
782
|
+
}), await e.mkdir("/tmp/sqlite-database-integration"), await d(e, i, "/tmp/sqlite-database-integration");
|
|
783
|
+
const n = "/internal/shared/sqlite-database-integration", t = `/tmp/sqlite-database-integration/${(await e.listFiles("/tmp/sqlite-database-integration"))[0]}`;
|
|
784
|
+
await e.mv(t, n), e.defineConstant("WP_SQLITE_AST_DRIVER", !0), await e.defineConstant("SQLITE_MAIN_FILE", "1");
|
|
785
|
+
const r = (await e.readFileAsText(
|
|
786
|
+
o(n, "db.copy")
|
|
774
787
|
)).replace(
|
|
775
788
|
"'{SQLITE_IMPLEMENTATION_FOLDER_PATH}'",
|
|
776
|
-
|
|
789
|
+
s(n)
|
|
777
790
|
).replace(
|
|
778
791
|
"'{SQLITE_PLUGIN}'",
|
|
779
|
-
|
|
780
|
-
),
|
|
792
|
+
s(o(n, "load.php"))
|
|
793
|
+
), f = o(await e.documentRoot, "wp-content/db.php"), l = `<?php
|
|
781
794
|
// Do not preload this if WordPress comes with a custom db.php file.
|
|
782
|
-
if(file_exists(${
|
|
795
|
+
if(file_exists(${s(f)})) {
|
|
783
796
|
return;
|
|
784
797
|
}
|
|
785
|
-
?>`,
|
|
786
|
-
await e.writeFile(
|
|
798
|
+
?>`, u = "/internal/shared/mu-plugins/sqlite-database-integration.php";
|
|
799
|
+
await e.writeFile(u, l + r), await e.writeFile(
|
|
787
800
|
"/internal/shared/preload/0-sqlite.php",
|
|
788
|
-
|
|
801
|
+
l + `<?php
|
|
789
802
|
|
|
790
803
|
/**
|
|
791
804
|
* Loads the SQLite integration plugin before WordPress is loaded
|
|
@@ -835,7 +848,7 @@ class Playground_SQLite_Integration_Loader {
|
|
|
835
848
|
$GLOBALS['wpdb']->$name = $value;
|
|
836
849
|
}
|
|
837
850
|
protected function load_sqlite_integration() {
|
|
838
|
-
require_once ${
|
|
851
|
+
require_once ${s(u)};
|
|
839
852
|
}
|
|
840
853
|
}
|
|
841
854
|
$wpdb = $GLOBALS['wpdb'] = new Playground_SQLite_Integration_Loader();
|
|
@@ -863,52 +876,52 @@ if(!function_exists('mysqli_connect')) {
|
|
|
863
876
|
`
|
|
864
877
|
);
|
|
865
878
|
}
|
|
866
|
-
async function
|
|
867
|
-
e.mkdir("/tmp/unzipped-wordpress"), await
|
|
879
|
+
async function D(e, i) {
|
|
880
|
+
e.mkdir("/tmp/unzipped-wordpress"), await d(e, i, "/tmp/unzipped-wordpress"), e.fileExists("/tmp/unzipped-wordpress/wordpress.zip") && await d(
|
|
868
881
|
e,
|
|
869
882
|
"/tmp/unzipped-wordpress/wordpress.zip",
|
|
870
883
|
"/tmp/unzipped-wordpress"
|
|
871
884
|
);
|
|
872
|
-
let
|
|
873
|
-
if (!e.fileExists(
|
|
874
|
-
const
|
|
875
|
-
if (
|
|
876
|
-
const
|
|
885
|
+
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(o(n, "wp-config-sample.php"))) {
|
|
887
|
+
const t = e.listFiles(n);
|
|
888
|
+
if (t.length) {
|
|
889
|
+
const a = t[0];
|
|
877
890
|
e.fileExists(
|
|
878
|
-
|
|
879
|
-
) && (
|
|
891
|
+
o(n, a, "wp-config-sample.php")
|
|
892
|
+
) && (n = o(n, a));
|
|
880
893
|
}
|
|
881
894
|
}
|
|
882
|
-
if (e.isDir(e.documentRoot) &&
|
|
883
|
-
for (const
|
|
884
|
-
const
|
|
885
|
-
e.mv(
|
|
895
|
+
if (e.isDir(e.documentRoot) && A(e.documentRoot, e)) {
|
|
896
|
+
for (const t of e.listFiles(n)) {
|
|
897
|
+
const a = o(n, t), r = o(e.documentRoot, t);
|
|
898
|
+
e.mv(a, r);
|
|
886
899
|
}
|
|
887
|
-
e.rmdir(
|
|
900
|
+
e.rmdir(n, { recursive: !0 });
|
|
888
901
|
} else
|
|
889
|
-
e.mv(
|
|
890
|
-
!e.fileExists(
|
|
891
|
-
|
|
902
|
+
e.mv(n, e.documentRoot);
|
|
903
|
+
!e.fileExists(o(e.documentRoot, "wp-config.php")) && e.fileExists(o(e.documentRoot, "wp-config-sample.php")) && e.writeFile(
|
|
904
|
+
o(e.documentRoot, "wp-config.php"),
|
|
892
905
|
e.readFileAsText(
|
|
893
|
-
|
|
906
|
+
o(e.documentRoot, "/wp-config-sample.php")
|
|
894
907
|
)
|
|
895
908
|
);
|
|
896
909
|
}
|
|
897
|
-
function
|
|
898
|
-
const
|
|
899
|
-
return
|
|
900
|
-
|
|
910
|
+
function A(e, i) {
|
|
911
|
+
const n = i.listFiles(e);
|
|
912
|
+
return n.length === 0 || n.length === 1 && // TODO: use a constant from a site storage package
|
|
913
|
+
n[0] === "playground-site-metadata.json";
|
|
901
914
|
}
|
|
902
|
-
const
|
|
903
|
-
async function
|
|
915
|
+
const F = g(fetch);
|
|
916
|
+
async function z(e = "latest") {
|
|
904
917
|
if (e.startsWith("https://") || e.startsWith("http://")) {
|
|
905
|
-
const
|
|
918
|
+
const t = await crypto.subtle.digest(
|
|
906
919
|
"SHA-1",
|
|
907
920
|
new TextEncoder().encode(e)
|
|
908
|
-
),
|
|
921
|
+
), a = Array.from(new Uint8Array(t)).map((r) => r.toString(16).padStart(2, "0")).join("");
|
|
909
922
|
return {
|
|
910
923
|
releaseUrl: e,
|
|
911
|
-
version: "custom-" +
|
|
924
|
+
version: "custom-" + a.substring(0, 8),
|
|
912
925
|
source: "inferred"
|
|
913
926
|
};
|
|
914
927
|
} else if (e === "trunk" || e === "nightly")
|
|
@@ -917,29 +930,29 @@ async function B(e = "latest") {
|
|
|
917
930
|
version: "nightly-" + (/* @__PURE__ */ new Date()).toISOString().split("T")[0],
|
|
918
931
|
source: "inferred"
|
|
919
932
|
};
|
|
920
|
-
let
|
|
933
|
+
let n = await (await F(
|
|
921
934
|
"https://api.wordpress.org/core/version-check/1.7/?channel=beta"
|
|
922
935
|
)).json();
|
|
923
|
-
|
|
924
|
-
(
|
|
936
|
+
n = n.offers.filter(
|
|
937
|
+
(t) => t.response === "autoupdate"
|
|
925
938
|
);
|
|
926
|
-
for (const
|
|
927
|
-
if (e === "beta" &&
|
|
939
|
+
for (const t of n) {
|
|
940
|
+
if (e === "beta" && t.version.includes("beta"))
|
|
928
941
|
return {
|
|
929
|
-
releaseUrl:
|
|
930
|
-
version:
|
|
942
|
+
releaseUrl: t.download,
|
|
943
|
+
version: t.version,
|
|
931
944
|
source: "api"
|
|
932
945
|
};
|
|
933
|
-
if (e === "latest" && !
|
|
946
|
+
if (e === "latest" && !t.version.includes("beta"))
|
|
934
947
|
return {
|
|
935
|
-
releaseUrl:
|
|
936
|
-
version:
|
|
948
|
+
releaseUrl: t.download,
|
|
949
|
+
version: t.version,
|
|
937
950
|
source: "api"
|
|
938
951
|
};
|
|
939
|
-
if (
|
|
952
|
+
if (t.version.substring(0, e.length) === e)
|
|
940
953
|
return {
|
|
941
|
-
releaseUrl:
|
|
942
|
-
version:
|
|
954
|
+
releaseUrl: t.download,
|
|
955
|
+
version: t.version,
|
|
943
956
|
source: "api"
|
|
944
957
|
};
|
|
945
958
|
}
|
|
@@ -950,17 +963,18 @@ async function B(e = "latest") {
|
|
|
950
963
|
};
|
|
951
964
|
}
|
|
952
965
|
export {
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
S as
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
W as
|
|
963
|
-
|
|
964
|
-
|
|
966
|
+
v as bootRequestHandler,
|
|
967
|
+
M as bootWordPress,
|
|
968
|
+
R as defineWpConfigConstants,
|
|
969
|
+
S as ensureWpConfig,
|
|
970
|
+
x as getFileNotFoundActionForWordPress,
|
|
971
|
+
H as getLoadedWordPressVersion,
|
|
972
|
+
O as preloadPhpInfoRoute,
|
|
973
|
+
C as preloadSqliteIntegration,
|
|
974
|
+
z as resolveWordPressRelease,
|
|
975
|
+
W as setupPlatformLevelMuPlugins,
|
|
976
|
+
D as unzipWordPress,
|
|
977
|
+
I as versionStringToLoadedWordPressVersion,
|
|
978
|
+
U as wordPressRewriteRules
|
|
965
979
|
};
|
|
966
980
|
//# 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.4",
|
|
4
4
|
"description": "WordPress-related plumbing for WordPress Playground",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -35,19 +35,20 @@
|
|
|
35
35
|
"access": "public",
|
|
36
36
|
"directory": "../../../dist/packages/playground/wordpress"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "ed646326d99ba84bad911d65b6634265f508f073",
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"comlink": "^4.4.
|
|
40
|
+
"comlink": "^4.4.2",
|
|
41
41
|
"express": "4.21.2",
|
|
42
|
+
"fs-ext": "2.1.1",
|
|
42
43
|
"ini": "4.1.2",
|
|
43
44
|
"wasm-feature-detect": "1.8.0",
|
|
44
45
|
"ws": "8.18.1",
|
|
45
46
|
"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.
|
|
47
|
+
"@php-wasm/universal": "1.1.4",
|
|
48
|
+
"@php-wasm/util": "1.1.4",
|
|
49
|
+
"@php-wasm/logger": "1.1.4",
|
|
50
|
+
"@wp-playground/common": "1.1.4",
|
|
51
|
+
"@php-wasm/node": "1.1.4"
|
|
51
52
|
},
|
|
52
53
|
"overrides": {
|
|
53
54
|
"rollup": "^4.34.6",
|