@wp-playground/wordpress 1.0.11 → 1.0.13
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.js +15 -20
- package/package.json +7 -7
- package/version-detect.d.ts +16 -0
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{joinPaths as a,phpVar as d}from"@php-wasm/util";import{unzipFile as l}from"@wp-playground/common";import{PHPRequestHandler as _,withPHPIniValues as f,PHP as g,setPhpIniEntries as w,writeFiles as m,proxyFileSystem as h,rotatePHPRuntime as $}from"@php-wasm/universal";import{logger as y}from"@php-wasm/logger";async function x(e){async function n
|
|
1
|
+
import{joinPaths as a,phpVar as d}from"@php-wasm/util";import{unzipFile as l}from"@wp-playground/common";import{PHPRequestHandler as _,withPHPIniValues as f,PHP as g,setPhpIniEntries as w,writeFiles as m,proxyFileSystem as h,rotatePHPRuntime as $}from"@php-wasm/universal";import{logger as y}from"@php-wasm/logger";async function x(e){async function r(n,s){const o=new g(await e.createPhpRuntime());return e.sapiName&&o.setSapiName(e.sapiName),n&&(o.requestHandler=n),e.phpIniEntries&&w(o,e.phpIniEntries),s?(await L(o),await m(o,"/",e.createFiles||{}),await S(o,a(new URL(e.siteUrl).pathname,"phpinfo.php"))):h(await n.getPrimaryPhp(),o,["/tmp",n.documentRoot,"/internal/shared"]),e.spawnHandler&&await o.setSpawnHandler(e.spawnHandler(n.processManager)),$({php:o,cwd:n.documentRoot,recreateRuntime:e.createPhpRuntime,maxRequests:400}),o}const t=new _({phpFactory:async({isPrimary:n})=>r(t,n),documentRoot:e.documentRoot||"/wordpress",absoluteUrl:e.siteUrl,rewriteRules:R,getFileNotFoundAction:e.getFileNotFoundAction??b}),i=await t.getPrimaryPhp();if(e.hooks?.beforeWordPressFiles&&await e.hooks.beforeWordPressFiles(i),e.wordPressZip&&await I(i,await e.wordPressZip),e.constants)for(const n in e.constants)i.defineConstant(n,e.constants[n]);if(i.defineConstant("WP_HOME",e.siteUrl),i.defineConstant("WP_SITEURL",e.siteUrl),e.hooks?.beforeDatabaseSetup&&await e.hooks.beforeDatabaseSetup(i),e.sqliteIntegrationPluginZip&&await T(i,await e.sqliteIntegrationPluginZip),await c(i)||await P(i),!await c(i))throw new Error("WordPress installation has failed.");return t}async function c(e){return(await e.run({code:`<?php
|
|
2
2
|
$wp_load = getenv('DOCUMENT_ROOT') . '/wp-load.php';
|
|
3
3
|
if (!file_exists($wp_load)) {
|
|
4
4
|
echo '0';
|
|
@@ -18,10 +18,10 @@ $option_result = update_option(
|
|
|
18
18
|
'/%year%/%monthnum%/%day%/%postname%/'
|
|
19
19
|
);
|
|
20
20
|
echo $option_result ? '1' : '0';
|
|
21
|
-
`,env:{DOCUMENT_ROOT:e.documentRoot}})).text!=="1"&&y.warn("Failed to default to pretty permalinks after WP install.")}function b(e){return{type:"internal-redirect",uri:"/index.php"}}async function
|
|
21
|
+
`,env:{DOCUMENT_ROOT:e.documentRoot}})).text!=="1"&&y.warn("Failed to default to pretty permalinks after WP install.")}function b(e){return{type:"internal-redirect",uri:"/index.php"}}async function q(e){const i=(await(await e.getPrimaryPhp()).run({code:`<?php
|
|
22
22
|
require '${e.documentRoot}/wp-includes/version.php';
|
|
23
23
|
echo $wp_version;
|
|
24
|
-
`})).text;if(!i)throw new Error("Unable to read loaded WordPress version.");return E(i)}function E(e){if(/-(alpha|beta|RC)\d*-\d+$/.test(e))return"nightly";if(/-(beta|RC)\d*$/.test(e))return"beta";const i=e.match(/^(\d+\.\d+)(?:\.\d+)?$/);return i!==null?i[1]:e}const R=[{match:/^\/(.*?)(\/wp-(content|admin|includes)\/.*)/g,replacement:"$2"}];async function
|
|
24
|
+
`})).text;if(!i)throw new Error("Unable to read loaded WordPress version.");return E(i)}function E(e){if(/-(alpha|beta|RC)\d*-\d+$/.test(e))return"nightly";if(/-(beta|RC)\d*$/.test(e))return"beta";const i=e.match(/^(\d+\.\d+)(?:\.\d+)?$/);return i!==null?i[1]:e}const R=[{match:/^\/(.*?)(\/wp-(content|admin|includes)\/.*)/g,replacement:"$2"}];async function L(e){await e.mkdir("/internal/shared/mu-plugins"),await e.writeFile("/internal/shared/preload/env.php",`<?php
|
|
25
25
|
|
|
26
26
|
// Allow adding filters/actions prior to loading WordPress.
|
|
27
27
|
// $function_to_add MUST be a string.
|
|
@@ -120,21 +120,16 @@ echo $option_result ? '1' : '0';
|
|
|
120
120
|
* Reload page to ensure the user is logged in correctly.
|
|
121
121
|
* WordPress uses cookies to determine if the user is logged in,
|
|
122
122
|
* so we need to reload the page to ensure the cookies are set.
|
|
123
|
-
*
|
|
124
|
-
* Both WordPress home url and REQUEST_URI may include the site scope
|
|
125
|
-
* subdirectory.
|
|
126
|
-
* To prevent the redirect from including two scopes, we need to
|
|
127
|
-
* remove the scope from the REQUEST_URI if it's present.
|
|
128
123
|
*/
|
|
129
124
|
$redirect_url = $_SERVER['REQUEST_URI'];
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
);
|
|
125
|
+
/**
|
|
126
|
+
* Intentionally do not use wp_redirect() here. It removes
|
|
127
|
+
* %0A and %0D sequences from the URL, which we don't want.
|
|
128
|
+
* There are valid use-cases for encoded newlines in the query string,
|
|
129
|
+
* for example html-api-debugger accepts markup with newlines
|
|
130
|
+
* encoded as %0A via the query string.
|
|
131
|
+
*/
|
|
132
|
+
header( "Location: $redirect_url", true, 302 );
|
|
138
133
|
exit;
|
|
139
134
|
}
|
|
140
135
|
/**
|
|
@@ -235,13 +230,13 @@ echo $option_result ? '1' : '0';
|
|
|
235
230
|
}
|
|
236
231
|
return false;
|
|
237
232
|
});
|
|
238
|
-
})();`)}async function
|
|
233
|
+
})();`)}async function S(e,r="/phpinfo.php"){await e.writeFile("/internal/shared/preload/phpinfo.php",`<?php
|
|
239
234
|
// Render PHPInfo if the requested page is /phpinfo.php
|
|
240
|
-
if ( ${d(
|
|
235
|
+
if ( ${d(r)} === $_SERVER['REQUEST_URI'] ) {
|
|
241
236
|
phpinfo();
|
|
242
237
|
exit;
|
|
243
238
|
}
|
|
244
|
-
`)}async function
|
|
239
|
+
`)}async function T(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 l(e,r,"/tmp/sqlite-database-integration");const t="/internal/shared/sqlite-database-integration",i=await e.isDir("/tmp/sqlite-database-integration/sqlite-database-integration-main")?"/tmp/sqlite-database-integration/sqlite-database-integration-main":"/tmp/sqlite-database-integration/sqlite-database-integration-develop";await e.mv(i,t),await e.defineConstant("SQLITE_MAIN_FILE","1");const s=(await e.readFileAsText(a(t,"db.copy"))).replace("'{SQLITE_IMPLEMENTATION_FOLDER_PATH}'",d(t)).replace("'{SQLITE_PLUGIN}'",d(a(t,"load.php"))),o=a(await e.documentRoot,"wp-content/db.php"),u=`<?php
|
|
245
240
|
// Do not preload this if WordPress comes with a custom db.php file.
|
|
246
241
|
if(file_exists(${d(o)})) {
|
|
247
242
|
return;
|
|
@@ -318,4 +313,4 @@ if(!function_exists('mysqli_connect')) {
|
|
|
318
313
|
var_dump(isset($wpdb));
|
|
319
314
|
die("SQLite integration not loaded " . get_class($wpdb));
|
|
320
315
|
}
|
|
321
|
-
`)}async function I(e,
|
|
316
|
+
`)}async function I(e,r){e.mkdir("/tmp/unzipped-wordpress"),await l(e,r,"/tmp/unzipped-wordpress"),e.fileExists("/tmp/unzipped-wordpress/wordpress.zip")&&await l(e,"/tmp/unzipped-wordpress/wordpress.zip","/tmp/unzipped-wordpress");let t=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(a(t,"wp-config-sample.php"))){const i=e.listFiles(t);if(i.length){const n=i[0];e.fileExists(a(t,n,"wp-config-sample.php"))&&(t=a(t,n))}}if(e.isDir(e.documentRoot)&&v(e.documentRoot,e)){for(const i of e.listFiles(t)){const n=a(t,i),s=a(e.documentRoot,i);e.mv(n,s)}e.rmdir(t,{recursive:!0})}else e.mv(t,e.documentRoot);!e.fileExists(a(e.documentRoot,"wp-config.php"))&&e.fileExists(a(e.documentRoot,"wp-config-sample.php"))&&e.writeFile(a(e.documentRoot,"wp-config.php"),e.readFileAsText(a(e.documentRoot,"/wp-config-sample.php")))}function v(e,r){const t=r.listFiles(e);return t.length===0||t.length===1&&t[0]==="playground-site-metadata.json"}export{x as bootWordPress,b as getFileNotFoundActionForWordPress,q as getLoadedWordPressVersion,S as preloadPhpInfoRoute,T as preloadSqliteIntegration,L as setupPlatformLevelMuPlugins,I as unzipWordPress,E as versionStringToLoadedWordPressVersion,R as wordPressRewriteRules};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wp-playground/wordpress",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.13",
|
|
4
4
|
"description": "WordPress-related plumbing for WordPress Playground",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"access": "public",
|
|
29
29
|
"directory": "../../../dist/packages/playground/wordpress"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "22888c009b54e0b1e5a5c9961b9d97c08b39f672",
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"comlink": "^4.4.1",
|
|
34
34
|
"events": "3.3.0",
|
|
@@ -37,10 +37,10 @@
|
|
|
37
37
|
"wasm-feature-detect": "1.8.0",
|
|
38
38
|
"ws": "8.18.0",
|
|
39
39
|
"yargs": "17.7.2",
|
|
40
|
-
"@php-wasm/universal": "1.0.
|
|
41
|
-
"@php-wasm/util": "1.0.
|
|
42
|
-
"@php-wasm/logger": "1.0.
|
|
43
|
-
"@wp-playground/common": "1.0.
|
|
44
|
-
"@php-wasm/node": "1.0.
|
|
40
|
+
"@php-wasm/universal": "1.0.13",
|
|
41
|
+
"@php-wasm/util": "1.0.13",
|
|
42
|
+
"@php-wasm/logger": "1.0.13",
|
|
43
|
+
"@wp-playground/common": "1.0.13",
|
|
44
|
+
"@php-wasm/node": "1.0.13"
|
|
45
45
|
}
|
|
46
46
|
}
|
package/version-detect.d.ts
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
1
|
import type { PHPRequestHandler } from '@php-wasm/universal';
|
|
2
2
|
export declare function getLoadedWordPressVersion(requestHandler: PHPRequestHandler): Promise<string>;
|
|
3
|
+
/**
|
|
4
|
+
* Returns a WordPress build version string, for a given WordPress version string.
|
|
5
|
+
*
|
|
6
|
+
* You can find the full list of supported build version strings in
|
|
7
|
+
* packages/playground/wordpress-builds/src/wordpress/wp-versions.json
|
|
8
|
+
*
|
|
9
|
+
* Each released version will be converted to the major.minor format.
|
|
10
|
+
* For example 6.6.1 will be converted to 6.6.
|
|
11
|
+
*
|
|
12
|
+
* Release candidates (RC) and beta releases are converted to "beta".
|
|
13
|
+
*
|
|
14
|
+
* Nightly releases are converted to "nightly".
|
|
15
|
+
*
|
|
16
|
+
* @param wpVersionString - A WordPress version string.
|
|
17
|
+
* @returns A Playground WordPress build version.
|
|
18
|
+
*/
|
|
3
19
|
export declare function versionStringToLoadedWordPressVersion(wpVersionString: string): string;
|