@wp-playground/wordpress 1.0.12 → 1.0.14
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.d.ts +24 -0
- package/index.js +11 -11
- package/package.json +7 -7
- package/version-detect.d.ts +16 -0
package/index.d.ts
CHANGED
|
@@ -31,3 +31,27 @@ export declare function preloadSqliteIntegration(php: UniversalPHP, sqliteZip: F
|
|
|
31
31
|
* as that's viable.
|
|
32
32
|
*/
|
|
33
33
|
export declare function unzipWordPress(php: PHP, wpZip: File): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Resolves a specific WordPress release URL and version string based on
|
|
36
|
+
* a version query string such as "latest", "beta", or "6.6".
|
|
37
|
+
*
|
|
38
|
+
* Examples:
|
|
39
|
+
* ```js
|
|
40
|
+
* const { releaseUrl, version } = await resolveWordPressRelease('latest')
|
|
41
|
+
* // becomes https://wordpress.org/wordpress-6.6.2.zip and '6.6.2'
|
|
42
|
+
*
|
|
43
|
+
* const { releaseUrl, version } = await resolveWordPressRelease('beta')
|
|
44
|
+
* // becomes https://wordpress.org/wordpress-6.6.2-RC1.zip and '6.6.2-RC1'
|
|
45
|
+
*
|
|
46
|
+
* const { releaseUrl, version } = await resolveWordPressRelease('6.6')
|
|
47
|
+
* // becomes https://wordpress.org/wordpress-6.6.2.zip and '6.6.2'
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* @param versionQuery - The WordPress version query string to resolve.
|
|
51
|
+
* @returns The resolved WordPress release URL and version string.
|
|
52
|
+
*/
|
|
53
|
+
export declare function resolveWordPressRelease(versionQuery?: string): Promise<{
|
|
54
|
+
releaseUrl: any;
|
|
55
|
+
version: any;
|
|
56
|
+
source: string;
|
|
57
|
+
}>;
|
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{joinPaths as a,phpVar as
|
|
1
|
+
import{joinPaths as a,phpVar as l}from"@php-wasm/util";import{createMemoizedFetch as _,unzipFile as d}from"@wp-playground/common";import{PHPRequestHandler as f,withPHPIniValues as g,PHP as w,setPhpIniEntries as h,writeFiles as m,proxyFileSystem as $,rotatePHPRuntime as P}from"@php-wasm/universal";import{logger as b}from"@php-wasm/logger";async function q(e){async function n(r,o){const s=new w(await e.createPhpRuntime());return e.sapiName&&s.setSapiName(e.sapiName),r&&(s.requestHandler=r),e.phpIniEntries&&h(s,e.phpIniEntries),o?(await L(s),await m(s,"/",e.createFiles||{}),await T(s,a(new URL(e.siteUrl).pathname,"phpinfo.php"))):$(await r.getPrimaryPhp(),s,["/tmp",r.documentRoot,"/internal/shared"]),e.spawnHandler&&await s.setSpawnHandler(e.spawnHandler(r.processManager)),P({php:s,cwd:r.documentRoot,recreateRuntime:e.createPhpRuntime,maxRequests:400}),s}const i=new f({phpFactory:async({isPrimary:r})=>n(i,r),documentRoot:e.documentRoot||"/wordpress",absoluteUrl:e.siteUrl,rewriteRules:S,getFileNotFoundAction:e.getFileNotFoundAction??E}),t=await i.getPrimaryPhp();if(e.hooks?.beforeWordPressFiles&&await e.hooks.beforeWordPressFiles(t),e.wordPressZip&&await U(t,await e.wordPressZip),e.constants)for(const r in e.constants)t.defineConstant(r,e.constants[r]);if(t.defineConstant("WP_HOME",e.siteUrl),t.defineConstant("WP_SITEURL",e.siteUrl),e.hooks?.beforeDatabaseSetup&&await e.hooks.beforeDatabaseSetup(t),e.sqliteIntegrationPluginZip&&await I(t,await e.sqliteIntegrationPluginZip),await c(t)||await y(t),!await c(t))throw new Error("WordPress installation has failed.");return i}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';
|
|
@@ -6,7 +6,7 @@ if (!file_exists($wp_load)) {
|
|
|
6
6
|
}
|
|
7
7
|
require $wp_load;
|
|
8
8
|
echo is_blog_installed() ? '1' : '0';
|
|
9
|
-
`,env:{DOCUMENT_ROOT:e.documentRoot}})).text==="1"}async function
|
|
9
|
+
`,env:{DOCUMENT_ROOT:e.documentRoot}})).text==="1"}async function y(e){await g(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
|
|
10
10
|
$wp_load = getenv('DOCUMENT_ROOT') . '/wp-load.php';
|
|
11
11
|
if (!file_exists($wp_load)) {
|
|
12
12
|
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"&&
|
|
21
|
+
`,env:{DOCUMENT_ROOT:e.documentRoot}})).text!=="1"&&b.warn("Failed to default to pretty permalinks after WP install.")}function E(e){return{type:"internal-redirect",uri:"/index.php"}}async function A(e){const t=(await(await e.getPrimaryPhp()).run({code:`<?php
|
|
22
22
|
require '${e.documentRoot}/wp-includes/version.php';
|
|
23
23
|
echo $wp_version;
|
|
24
|
-
`})).text;if(!
|
|
24
|
+
`})).text;if(!t)throw new Error("Unable to read loaded WordPress version.");return R(t)}function R(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 S=[{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.
|
|
@@ -230,18 +230,18 @@ echo $option_result ? '1' : '0';
|
|
|
230
230
|
}
|
|
231
231
|
return false;
|
|
232
232
|
});
|
|
233
|
-
})();`)}async function
|
|
233
|
+
})();`)}async function T(e,n="/phpinfo.php"){await e.writeFile("/internal/shared/preload/phpinfo.php",`<?php
|
|
234
234
|
// Render PHPInfo if the requested page is /phpinfo.php
|
|
235
|
-
if ( ${
|
|
235
|
+
if ( ${l(n)} === $_SERVER['REQUEST_URI'] ) {
|
|
236
236
|
phpinfo();
|
|
237
237
|
exit;
|
|
238
238
|
}
|
|
239
|
-
`)}async function
|
|
239
|
+
`)}async function I(e,n){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(e,n,"/tmp/sqlite-database-integration");const i="/internal/shared/sqlite-database-integration",t=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(t,i),await e.defineConstant("SQLITE_MAIN_FILE","1");const o=(await e.readFileAsText(a(i,"db.copy"))).replace("'{SQLITE_IMPLEMENTATION_FOLDER_PATH}'",l(i)).replace("'{SQLITE_PLUGIN}'",l(a(i,"load.php"))),s=a(await e.documentRoot,"wp-content/db.php"),u=`<?php
|
|
240
240
|
// Do not preload this if WordPress comes with a custom db.php file.
|
|
241
|
-
if(file_exists(${
|
|
241
|
+
if(file_exists(${l(s)})) {
|
|
242
242
|
return;
|
|
243
243
|
}
|
|
244
|
-
?>`,p="/internal/shared/mu-plugins/sqlite-database-integration.php";await e.writeFile(p,u+
|
|
244
|
+
?>`,p="/internal/shared/mu-plugins/sqlite-database-integration.php";await e.writeFile(p,u+o),await e.writeFile("/internal/shared/preload/0-sqlite.php",u+`<?php
|
|
245
245
|
|
|
246
246
|
/**
|
|
247
247
|
* Loads the SQLite integration plugin before WordPress is loaded
|
|
@@ -291,7 +291,7 @@ class Playground_SQLite_Integration_Loader {
|
|
|
291
291
|
$GLOBALS['wpdb']->$name = $value;
|
|
292
292
|
}
|
|
293
293
|
protected function load_sqlite_integration() {
|
|
294
|
-
require_once ${
|
|
294
|
+
require_once ${l(p)};
|
|
295
295
|
}
|
|
296
296
|
}
|
|
297
297
|
$wpdb = $GLOBALS['wpdb'] = new Playground_SQLite_Integration_Loader();
|
|
@@ -313,4 +313,4 @@ if(!function_exists('mysqli_connect')) {
|
|
|
313
313
|
var_dump(isset($wpdb));
|
|
314
314
|
die("SQLite integration not loaded " . get_class($wpdb));
|
|
315
315
|
}
|
|
316
|
-
`)}async function
|
|
316
|
+
`)}async function U(e,n){e.mkdir("/tmp/unzipped-wordpress"),await d(e,n,"/tmp/unzipped-wordpress"),e.fileExists("/tmp/unzipped-wordpress/wordpress.zip")&&await d(e,"/tmp/unzipped-wordpress/wordpress.zip","/tmp/unzipped-wordpress");let i=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(i,"wp-config-sample.php"))){const t=e.listFiles(i);if(t.length){const r=t[0];e.fileExists(a(i,r,"wp-config-sample.php"))&&(i=a(i,r))}}if(e.isDir(e.documentRoot)&&v(e.documentRoot,e)){for(const t of e.listFiles(i)){const r=a(i,t),o=a(e.documentRoot,t);e.mv(r,o)}e.rmdir(i,{recursive:!0})}else e.mv(i,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,n){const i=n.listFiles(e);return i.length===0||i.length===1&&i[0]==="playground-site-metadata.json"}const O=_(fetch);async function N(e="latest"){if(e.startsWith("https://")||e.startsWith("http://")){const t=await crypto.subtle.digest("SHA-1",new TextEncoder().encode(e)),r=Array.from(new Uint8Array(t)).map(o=>o.toString(16).padStart(2,"0")).join("");return{releaseUrl:e,version:"custom-"+r.substring(0,8),source:"inferred"}}else if(e==="trunk"||e==="nightly")return{releaseUrl:"https://wordpress.org/nightly-builds/wordpress-latest.zip",version:"nightly-"+new Date().toISOString().split("T")[0],source:"inferred"};let i=await(await O("https://api.wordpress.org/core/version-check/1.7/?channel=beta")).json();i=i.offers.filter(t=>t.response==="autoupdate");for(const t of i){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"}}export{q as bootWordPress,E as getFileNotFoundActionForWordPress,A as getLoadedWordPressVersion,T as preloadPhpInfoRoute,I as preloadSqliteIntegration,N as resolveWordPressRelease,L as setupPlatformLevelMuPlugins,U as unzipWordPress,R as versionStringToLoadedWordPressVersion,S 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.14",
|
|
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": "4d191fdd33db1949e51d54e2b03decbb103db4ac",
|
|
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.14",
|
|
41
|
+
"@php-wasm/util": "1.0.14",
|
|
42
|
+
"@php-wasm/logger": "1.0.14",
|
|
43
|
+
"@wp-playground/common": "1.0.14",
|
|
44
|
+
"@php-wasm/node": "1.0.14"
|
|
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;
|