@wp-playground/client 0.1.60 → 0.2.0
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 +41 -30
- package/index.d.ts +149 -14
- package/index.js +7347 -1308
- package/package.json +6 -2
- package/blueprint-schema.json +0 -1280
package/index.d.ts
CHANGED
|
@@ -274,7 +274,7 @@ export interface RequestHandler {
|
|
|
274
274
|
* }
|
|
275
275
|
* })
|
|
276
276
|
* php.writeFile("/www/index.php", `<?php echo file_get_contents("php://input");`);
|
|
277
|
-
* const result = await php.
|
|
277
|
+
* const result = await php.request({
|
|
278
278
|
* method: "GET",
|
|
279
279
|
* headers: {
|
|
280
280
|
* "Content-Type": "text/plain"
|
|
@@ -504,7 +504,48 @@ export interface IsomorphicLocalPHP extends RequestHandler {
|
|
|
504
504
|
* @param options - PHP runtime options.
|
|
505
505
|
*/
|
|
506
506
|
run(options: PHPRunOptions): Promise<PHPResponse>;
|
|
507
|
+
/**
|
|
508
|
+
* Listens to message sent by the PHP code.
|
|
509
|
+
*
|
|
510
|
+
* To dispatch messages, call:
|
|
511
|
+
*
|
|
512
|
+
* post_message_to_js(string $data)
|
|
513
|
+
*
|
|
514
|
+
* Arguments:
|
|
515
|
+
* $data (string) – Data to pass to JavaScript.
|
|
516
|
+
*
|
|
517
|
+
* @example
|
|
518
|
+
*
|
|
519
|
+
* ```ts
|
|
520
|
+
* const php = await PHP.load('8.0');
|
|
521
|
+
*
|
|
522
|
+
* php.onMessage(
|
|
523
|
+
* // The data is always passed as a string
|
|
524
|
+
* function (data: string) {
|
|
525
|
+
* // Let's decode and log the data:
|
|
526
|
+
* console.log(JSON.parse(data));
|
|
527
|
+
* }
|
|
528
|
+
* );
|
|
529
|
+
*
|
|
530
|
+
* // Now that we have a listener in place, let's
|
|
531
|
+
* // dispatch a message:
|
|
532
|
+
* await php.run({
|
|
533
|
+
* code: `<?php
|
|
534
|
+
* post_message_to_js(
|
|
535
|
+
* json_encode([
|
|
536
|
+
* 'post_id' => '15',
|
|
537
|
+
* 'post_title' => 'This is a blog post!'
|
|
538
|
+
* ])
|
|
539
|
+
* ));
|
|
540
|
+
* `,
|
|
541
|
+
* });
|
|
542
|
+
* ```
|
|
543
|
+
*
|
|
544
|
+
* @param listener Callback function to handle the message.
|
|
545
|
+
*/
|
|
546
|
+
onMessage(listener: MessageListener): void;
|
|
507
547
|
}
|
|
548
|
+
export type MessageListener = (data: string) => void;
|
|
508
549
|
export type IsomorphicRemotePHP = Remote<IsomorphicLocalPHP>;
|
|
509
550
|
export type UniversalPHP = IsomorphicLocalPHP | IsomorphicRemotePHP;
|
|
510
551
|
export type HTTPMethod = "GET" | "POST" | "HEAD" | "OPTIONS" | "PATCH" | "PUT" | "DELETE";
|
|
@@ -739,7 +780,9 @@ export type EmscriptenOptions = {
|
|
|
739
780
|
quit?: (status: number, toThrow: any) => void;
|
|
740
781
|
onRuntimeInitialized?: () => void;
|
|
741
782
|
monitorRunDependencies?: (left: number) => void;
|
|
783
|
+
onMessage?: (listener: EmscriptenMessageListener) => void;
|
|
742
784
|
} & Record<string, any>;
|
|
785
|
+
export type EmscriptenMessageListener = (type: string, data: string) => void;
|
|
743
786
|
declare const __private__dont__use: unique symbol;
|
|
744
787
|
declare abstract class BasePHP implements IsomorphicLocalPHP {
|
|
745
788
|
#private;
|
|
@@ -754,6 +797,8 @@ declare abstract class BasePHP implements IsomorphicLocalPHP {
|
|
|
754
797
|
*/
|
|
755
798
|
constructor(PHPRuntimeId?: PHPRuntimeId, serverOptions?: PHPRequestHandlerConfiguration);
|
|
756
799
|
/** @inheritDoc */
|
|
800
|
+
onMessage(listener: MessageListener): Promise<void>;
|
|
801
|
+
/** @inheritDoc */
|
|
757
802
|
get absoluteUrl(): string;
|
|
758
803
|
/** @inheritDoc */
|
|
759
804
|
get documentRoot(): string;
|
|
@@ -1017,34 +1062,54 @@ export declare class SemaphoreResource<T extends Resource> extends DecoratedReso
|
|
|
1017
1062
|
/** @inheritDoc */
|
|
1018
1063
|
resolve(): Promise<File>;
|
|
1019
1064
|
}
|
|
1065
|
+
/**
|
|
1066
|
+
* @inheritDoc activatePlugin
|
|
1067
|
+
*/
|
|
1020
1068
|
export interface ActivatePluginStep {
|
|
1021
1069
|
step: "activatePlugin";
|
|
1070
|
+
/** Path to the plugin directory as absolute path (/wordpress/wp-content/plugins/plugin-name); or the plugin entry file relative to the plugins directory (plugin-name/plugin-name.php). */
|
|
1022
1071
|
pluginPath: string;
|
|
1072
|
+
/** Optional. Plugin name to display in the progress bar. */
|
|
1023
1073
|
pluginName?: string;
|
|
1024
1074
|
}
|
|
1025
1075
|
/**
|
|
1026
|
-
* Activates a WordPress plugin
|
|
1076
|
+
* Activates a WordPress plugin (if it's installed).
|
|
1027
1077
|
*
|
|
1028
1078
|
* @param playground The playground client.
|
|
1029
1079
|
*/
|
|
1030
1080
|
export declare const activatePlugin: StepHandler<ActivatePluginStep>;
|
|
1081
|
+
/**
|
|
1082
|
+
* @private
|
|
1083
|
+
*/
|
|
1031
1084
|
export interface ApplyWordPressPatchesStep {
|
|
1032
1085
|
step: "applyWordPressPatches";
|
|
1033
|
-
siteUrl
|
|
1086
|
+
siteUrl?: string;
|
|
1034
1087
|
wordpressPath?: string;
|
|
1035
|
-
patchSqlitePlugin?: boolean;
|
|
1036
1088
|
addPhpInfo?: boolean;
|
|
1037
|
-
|
|
1089
|
+
patchSecrets?: boolean;
|
|
1038
1090
|
disableSiteHealth?: boolean;
|
|
1039
1091
|
disableWpNewBlogNotification?: boolean;
|
|
1040
1092
|
}
|
|
1041
1093
|
export declare const applyWordPressPatches: StepHandler<ApplyWordPressPatchesStep>;
|
|
1094
|
+
/**
|
|
1095
|
+
* @inheritDoc defineSiteUrl
|
|
1096
|
+
* @hasRunnableExample
|
|
1097
|
+
* @example
|
|
1098
|
+
*
|
|
1099
|
+
* <code>
|
|
1100
|
+
* {
|
|
1101
|
+
* "step": "defineSiteUrl",
|
|
1102
|
+
* "siteUrl": "https://playground.wordpress.net"
|
|
1103
|
+
* }
|
|
1104
|
+
* </code>
|
|
1105
|
+
*/
|
|
1042
1106
|
export interface DefineSiteUrlStep {
|
|
1043
1107
|
step: "defineSiteUrl";
|
|
1108
|
+
/** The URL */
|
|
1044
1109
|
siteUrl: string;
|
|
1045
1110
|
}
|
|
1046
1111
|
/**
|
|
1047
|
-
* Sets
|
|
1112
|
+
* Sets WP_HOME and WP_SITEURL constants for the WordPress installation.
|
|
1048
1113
|
*
|
|
1049
1114
|
* @param playground The playground client.
|
|
1050
1115
|
* @param siteUrl
|
|
@@ -1059,20 +1124,31 @@ export declare const defineSiteUrl: StepHandler<DefineSiteUrlStep>;
|
|
|
1059
1124
|
* @param playground Playground client.
|
|
1060
1125
|
*/
|
|
1061
1126
|
export declare function zipEntireSite(playground: UniversalPHP): Promise<File>;
|
|
1127
|
+
/**
|
|
1128
|
+
* @inheritDoc replaceSite
|
|
1129
|
+
*/
|
|
1062
1130
|
export interface ReplaceSiteStep<ResourceType> {
|
|
1063
1131
|
step: "replaceSite";
|
|
1132
|
+
/** The zip file containing the new WordPress site */
|
|
1064
1133
|
fullSiteZip: ResourceType;
|
|
1065
1134
|
}
|
|
1066
1135
|
/**
|
|
1067
|
-
* Replace the current site with
|
|
1136
|
+
* Replace the current site with a site from the provided zip file.
|
|
1137
|
+
* Remember to install the SQLite integration plugin in the zipped site:
|
|
1138
|
+
* https://wordpress.org/plugins/sqlite-database-integration.
|
|
1068
1139
|
*
|
|
1069
1140
|
* @param playground Playground client.
|
|
1070
1141
|
* @param fullSiteZip Zipped WordPress site.
|
|
1071
1142
|
*/
|
|
1072
1143
|
export declare const replaceSite: StepHandler<ReplaceSiteStep<File>>;
|
|
1144
|
+
/**
|
|
1145
|
+
* @inheritDoc unzip
|
|
1146
|
+
*/
|
|
1073
1147
|
export interface UnzipStep {
|
|
1074
1148
|
step: "unzip";
|
|
1149
|
+
/** The zip file to extract */
|
|
1075
1150
|
zipPath: string;
|
|
1151
|
+
/** The path to extract the zip file to */
|
|
1076
1152
|
extractToPath: string;
|
|
1077
1153
|
}
|
|
1078
1154
|
/**
|
|
@@ -1083,8 +1159,12 @@ export interface UnzipStep {
|
|
|
1083
1159
|
* @param extractTo The directory to extract the zip file to.
|
|
1084
1160
|
*/
|
|
1085
1161
|
export declare const unzip: StepHandler<UnzipStep>;
|
|
1162
|
+
/**
|
|
1163
|
+
* @inheritDoc importFile
|
|
1164
|
+
*/
|
|
1086
1165
|
export interface ImportFileStep<ResourceType> {
|
|
1087
1166
|
step: "importFile";
|
|
1167
|
+
/** The file to import */
|
|
1088
1168
|
file: ResourceType;
|
|
1089
1169
|
}
|
|
1090
1170
|
/**
|
|
@@ -1226,6 +1306,9 @@ export type LoginStep = {
|
|
|
1226
1306
|
* just like a user would.
|
|
1227
1307
|
*/
|
|
1228
1308
|
export declare const login: StepHandler<LoginStep>;
|
|
1309
|
+
/**
|
|
1310
|
+
* @private
|
|
1311
|
+
*/
|
|
1229
1312
|
export interface RunWpInstallationWizardStep {
|
|
1230
1313
|
step: "runWpInstallationWizard";
|
|
1231
1314
|
options: WordPressInstallationOptions;
|
|
@@ -1287,7 +1370,9 @@ export declare const setSiteOptions: StepHandler<SetSiteOptionsStep>;
|
|
|
1287
1370
|
*/
|
|
1288
1371
|
export interface UpdateUserMetaStep {
|
|
1289
1372
|
step: "updateUserMeta";
|
|
1373
|
+
/** An object of user meta values to set, e.g. { "first_name": "John" } */
|
|
1290
1374
|
meta: Record<string, unknown>;
|
|
1375
|
+
/** User ID */
|
|
1291
1376
|
userId: number;
|
|
1292
1377
|
}
|
|
1293
1378
|
/**
|
|
@@ -1336,6 +1421,9 @@ export declare const runPHP: StepHandler<RunPHPStep>;
|
|
|
1336
1421
|
*/
|
|
1337
1422
|
export interface RunPHPWithOptionsStep {
|
|
1338
1423
|
step: "runPHPWithOptions";
|
|
1424
|
+
/**
|
|
1425
|
+
* Run options (See /wordpress-playground/api/universal/interface/PHPRunOptions)
|
|
1426
|
+
*/
|
|
1339
1427
|
options: PHPRunOptions;
|
|
1340
1428
|
}
|
|
1341
1429
|
/**
|
|
@@ -1357,7 +1445,9 @@ export declare const runPHPWithOptions: StepHandler<RunPHPWithOptionsStep>;
|
|
|
1357
1445
|
*/
|
|
1358
1446
|
export interface SetPhpIniEntryStep {
|
|
1359
1447
|
step: "setPhpIniEntry";
|
|
1448
|
+
/** Entry name e.g. "display_errors" */
|
|
1360
1449
|
key: string;
|
|
1450
|
+
/** Entry value as a string e.g. "1" */
|
|
1361
1451
|
value: string;
|
|
1362
1452
|
}
|
|
1363
1453
|
/**
|
|
@@ -1386,6 +1476,9 @@ export declare const setPhpIniEntry: StepHandler<SetPhpIniEntryStep>;
|
|
|
1386
1476
|
*/
|
|
1387
1477
|
export interface RequestStep {
|
|
1388
1478
|
step: "request";
|
|
1479
|
+
/**
|
|
1480
|
+
* Request details (See /wordpress-playground/api/universal/interface/PHPRequest)
|
|
1481
|
+
*/
|
|
1389
1482
|
request: PHPRequest;
|
|
1390
1483
|
}
|
|
1391
1484
|
/**
|
|
@@ -1408,7 +1501,9 @@ export declare const request: StepHandler<RequestStep>;
|
|
|
1408
1501
|
*/
|
|
1409
1502
|
export interface CpStep {
|
|
1410
1503
|
step: "cp";
|
|
1504
|
+
/** Source path */
|
|
1411
1505
|
fromPath: string;
|
|
1506
|
+
/** Target path */
|
|
1412
1507
|
toPath: string;
|
|
1413
1508
|
}
|
|
1414
1509
|
/**
|
|
@@ -1431,7 +1526,9 @@ export declare const cp: StepHandler<CpStep>;
|
|
|
1431
1526
|
*/
|
|
1432
1527
|
export interface MvStep {
|
|
1433
1528
|
step: "mv";
|
|
1529
|
+
/** Source path */
|
|
1434
1530
|
fromPath: string;
|
|
1531
|
+
/** Target path */
|
|
1435
1532
|
toPath: string;
|
|
1436
1533
|
}
|
|
1437
1534
|
/**
|
|
@@ -1452,6 +1549,7 @@ export declare const mv: StepHandler<MvStep>;
|
|
|
1452
1549
|
*/
|
|
1453
1550
|
export interface MkdirStep {
|
|
1454
1551
|
step: "mkdir";
|
|
1552
|
+
/** The path of the directory you want to create */
|
|
1455
1553
|
path: string;
|
|
1456
1554
|
}
|
|
1457
1555
|
/**
|
|
@@ -1473,6 +1571,7 @@ export declare const mkdir: StepHandler<MkdirStep>;
|
|
|
1473
1571
|
*/
|
|
1474
1572
|
export interface RmStep {
|
|
1475
1573
|
step: "rm";
|
|
1574
|
+
/** The path to remove */
|
|
1476
1575
|
path: string;
|
|
1477
1576
|
}
|
|
1478
1577
|
/**
|
|
@@ -1494,6 +1593,7 @@ export declare const rm: StepHandler<RmStep>;
|
|
|
1494
1593
|
*/
|
|
1495
1594
|
export interface RmdirStep {
|
|
1496
1595
|
step: "rmdir";
|
|
1596
|
+
/** The path to remove */
|
|
1497
1597
|
path: string;
|
|
1498
1598
|
}
|
|
1499
1599
|
/**
|
|
@@ -1516,7 +1616,9 @@ export declare const rmdir: StepHandler<RmdirStep>;
|
|
|
1516
1616
|
*/
|
|
1517
1617
|
export interface WriteFileStep<ResourceType> {
|
|
1518
1618
|
step: "writeFile";
|
|
1619
|
+
/** The path of the file to write to */
|
|
1519
1620
|
path: string;
|
|
1621
|
+
/** The data to write */
|
|
1520
1622
|
data: ResourceType | string | Uint8Array;
|
|
1521
1623
|
}
|
|
1522
1624
|
/**
|
|
@@ -1524,7 +1626,19 @@ export interface WriteFileStep<ResourceType> {
|
|
|
1524
1626
|
*/
|
|
1525
1627
|
export declare const writeFile: StepHandler<WriteFileStep<File>>;
|
|
1526
1628
|
/**
|
|
1527
|
-
*
|
|
1629
|
+
* @inheritDoc defineWpConfigConsts
|
|
1630
|
+
* @hasRunnableExample
|
|
1631
|
+
* @example
|
|
1632
|
+
*
|
|
1633
|
+
* <code>
|
|
1634
|
+
* {
|
|
1635
|
+
* "step": "defineWpConfigConsts",
|
|
1636
|
+
* "consts": {
|
|
1637
|
+
* "WP_DEBUG": true
|
|
1638
|
+
* },
|
|
1639
|
+
* "virtualize": true
|
|
1640
|
+
* }
|
|
1641
|
+
* </code>
|
|
1528
1642
|
*/
|
|
1529
1643
|
export interface DefineWpConfigConstsStep {
|
|
1530
1644
|
step: "defineWpConfigConsts";
|
|
@@ -1539,19 +1653,24 @@ export interface DefineWpConfigConstsStep {
|
|
|
1539
1653
|
virtualize?: boolean;
|
|
1540
1654
|
}
|
|
1541
1655
|
/**
|
|
1542
|
-
*
|
|
1656
|
+
* Defines the wp-config.php constants
|
|
1543
1657
|
*
|
|
1544
1658
|
* @param playground The playground client.
|
|
1545
|
-
* @param wpConfigConst
|
|
1546
|
-
* @returns Returns the virtual file system configuration file path.
|
|
1659
|
+
* @param wpConfigConst
|
|
1547
1660
|
*/
|
|
1548
1661
|
export declare const defineWpConfigConsts: StepHandler<DefineWpConfigConstsStep>;
|
|
1662
|
+
/**
|
|
1663
|
+
* @inheritDoc activateTheme
|
|
1664
|
+
*/
|
|
1549
1665
|
export interface ActivateThemeStep {
|
|
1550
1666
|
step: "activateTheme";
|
|
1667
|
+
/**
|
|
1668
|
+
* The name of the theme folder inside wp-content/themes/
|
|
1669
|
+
*/
|
|
1551
1670
|
themeFolderName: string;
|
|
1552
1671
|
}
|
|
1553
1672
|
/**
|
|
1554
|
-
* Activates a WordPress theme
|
|
1673
|
+
* Activates a WordPress theme (if it's installed).
|
|
1555
1674
|
*
|
|
1556
1675
|
* @param playground The playground client.
|
|
1557
1676
|
* @param themeFolderName The theme folder name.
|
|
@@ -1611,7 +1730,8 @@ declare const supportedWordPressVersions: readonly [
|
|
|
1611
1730
|
"6.2",
|
|
1612
1731
|
"6.1",
|
|
1613
1732
|
"6.0",
|
|
1614
|
-
"5.9"
|
|
1733
|
+
"5.9",
|
|
1734
|
+
"nightly"
|
|
1615
1735
|
];
|
|
1616
1736
|
export type supportedWordPressVersion = (typeof supportedWordPressVersions)[number];
|
|
1617
1737
|
export interface CompiledBlueprint {
|
|
@@ -1685,7 +1805,6 @@ declare class WebPHP extends BasePHP {
|
|
|
1685
1805
|
static loadSync(phpVersion: SupportedPHPVersion, options?: PHPWebLoaderOptions): {
|
|
1686
1806
|
php: WebPHP;
|
|
1687
1807
|
phpReady: Promise<WebPHP>;
|
|
1688
|
-
dataModules: Promise<DataModule[]>;
|
|
1689
1808
|
};
|
|
1690
1809
|
}
|
|
1691
1810
|
declare class WebPHPEndpoint implements IsomorphicLocalPHP {
|
|
@@ -1735,7 +1854,16 @@ declare class WebPHPEndpoint implements IsomorphicLocalPHP {
|
|
|
1735
1854
|
isDir(path: string): boolean;
|
|
1736
1855
|
/** @inheritDoc @php-wasm/web!WebPHP.fileExists */
|
|
1737
1856
|
fileExists(path: string): boolean;
|
|
1857
|
+
/** @inheritDoc @php-wasm/web!WebPHP.onMessage */
|
|
1858
|
+
onMessage(listener: MessageListener): void;
|
|
1738
1859
|
}
|
|
1860
|
+
export type SyncProgress = {
|
|
1861
|
+
/** The number of files that have been synced. */
|
|
1862
|
+
files: number;
|
|
1863
|
+
/** The number of all files that need to be synced. */
|
|
1864
|
+
total: number;
|
|
1865
|
+
};
|
|
1866
|
+
export type SyncProgressCallback = (progress: SyncProgress) => void;
|
|
1739
1867
|
declare class PlaygroundWorkerEndpoint extends WebPHPEndpoint {
|
|
1740
1868
|
/**
|
|
1741
1869
|
* A string representing the scope of the Playground instance.
|
|
@@ -1754,9 +1882,13 @@ declare class PlaygroundWorkerEndpoint extends WebPHPEndpoint {
|
|
|
1754
1882
|
* @returns WordPress module details, including the static assets directory and default theme.
|
|
1755
1883
|
*/
|
|
1756
1884
|
getWordPressModuleDetails(): Promise<{
|
|
1885
|
+
majorVersion: string;
|
|
1757
1886
|
staticAssetsDirectory: string;
|
|
1758
1887
|
defaultTheme: any;
|
|
1759
1888
|
}>;
|
|
1889
|
+
resetVirtualOpfs(): Promise<void>;
|
|
1890
|
+
reloadFilesFromOpfs(): Promise<void>;
|
|
1891
|
+
bindOpfs(opfs: FileSystemDirectoryHandle, onProgress?: SyncProgressCallback): Promise<void>;
|
|
1760
1892
|
}
|
|
1761
1893
|
export interface ProgressBarOptions {
|
|
1762
1894
|
caption?: string;
|
|
@@ -1797,6 +1929,9 @@ export interface WebClientMixin extends ProgressReceiver {
|
|
|
1797
1929
|
* The onDownloadProgress event listener.
|
|
1798
1930
|
*/
|
|
1799
1931
|
onDownloadProgress: PlaygroundWorkerEndpoint["onDownloadProgress"];
|
|
1932
|
+
/** @inheritDoc @php-wasm/universal!UniversalPHP.onMessage */
|
|
1933
|
+
onMessage: PlaygroundWorkerEndpoint["onMessage"];
|
|
1934
|
+
bindOpfs(opfs: FileSystemDirectoryHandle, onProgress?: SyncProgressCallback): Promise<void>;
|
|
1800
1935
|
}
|
|
1801
1936
|
/**
|
|
1802
1937
|
* The Playground Client interface.
|