@wp-playground/client 0.1.17 → 0.1.18
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/README.md +38 -4
- package/index.d.ts +361 -160
- package/index.js +1126 -398
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
# Playground Client
|
|
2
2
|
|
|
3
|
-
Provides a
|
|
4
|
-
to control the embedded WordPress site. Here's how to use it:
|
|
3
|
+
Provides a [PlaygroundClient](https://wordpress.github.io/wordpress-playground/interfaces/_wp_playground_client.PlaygroundClient.html) that can be used to control a WordPress Playground iframe:
|
|
5
4
|
|
|
6
5
|
```ts
|
|
7
6
|
import { connectPlayground } from '@wp-playground/client';
|
|
@@ -10,11 +9,46 @@ const client = await connectPlayground(
|
|
|
10
9
|
// An iframe pointing to https://playground.wordpress.net/remote.html
|
|
11
10
|
document.getElementById('wp')! as HTMLIFrameElement
|
|
12
11
|
);
|
|
12
|
+
// client is now a PlaygroundClient instance
|
|
13
13
|
await client.isReady();
|
|
14
14
|
await client.goTo('/wp-admin/');
|
|
15
15
|
|
|
16
|
-
const
|
|
16
|
+
const response = await client.run({
|
|
17
17
|
code: '<?php echo "Hi!"; ',
|
|
18
18
|
});
|
|
19
|
-
console.log(
|
|
19
|
+
console.log(response.text);
|
|
20
20
|
```
|
|
21
|
+
|
|
22
|
+
Using TypeScript is highly recommended as this package ships with comprehensive types – hit ctrl+space in your IDE after `client.` and you'll see all the available methods.
|
|
23
|
+
|
|
24
|
+
Once you have a [PlaygroundClient](https://wordpress.github.io/wordpress-playground/interfaces/_wp_playground_client.PlaygroundClient.html) instance, you can use it to control the playground:
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
client.writeFile('/index.php', '<?php echo "Hi!"; ');
|
|
28
|
+
client.run({
|
|
29
|
+
scriptPath: '/index.php',
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
console.log(client.readFileAsText('/index.php'));
|
|
33
|
+
|
|
34
|
+
client.request({
|
|
35
|
+
url: '/index.php',
|
|
36
|
+
method: 'POST',
|
|
37
|
+
formData: {
|
|
38
|
+
foo: 'bar',
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
To see all the available methods, check out the [PlaygroundClient](https://wordpress.github.io/wordpress-playground/interfaces/_wp_playground_client.PlaygroundClient.html) interface.
|
|
44
|
+
|
|
45
|
+
## Helpers
|
|
46
|
+
|
|
47
|
+
The `@wp-playground/client` package also provides a few helpers:
|
|
48
|
+
|
|
49
|
+
- [login](https://wordpress.github.io/wordpress-playground/functions/_wp_playground_client.login.html) - Logs the user in to wp-admin.
|
|
50
|
+
- [installPlugin](https://wordpress.github.io/wordpress-playground/functions/_wp_playground_client.installPlugin.html) - Installs a plugin from a given zip file.
|
|
51
|
+
- [installPluginsFromDirectory](https://wordpress.github.io/wordpress-playground/functions/_wp_playground_client.installPluginsFromDirectory.html) - Downloads and installs one or more plugins from the WordPress Plugin Directory.
|
|
52
|
+
- [activatePlugin](https://wordpress.github.io/wordpress-playground/functions/_wp_playground_client.activatePlugin.html) - Activates a specific plugin.
|
|
53
|
+
- [installTheme](https://wordpress.github.io/wordpress-playground/functions/_wp_playground_client.installTheme.html) - Installs a theme from a given zip file.
|
|
54
|
+
- [installThemeFromDirectory](https://wordpress.github.io/wordpress-playground/functions/_wp_playground_client.installThemeFromDirectory.html) - Downloads and installs a theme with a specific name from the WordPress Theme Directory.
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,151 @@
|
|
|
1
1
|
// Generated by dts-bundle-generator v7.2.0
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* PHP response. Body is an `ArrayBuffer` because it can
|
|
5
|
+
* contain binary data.
|
|
6
|
+
*/
|
|
7
|
+
export declare class PHPResponse {
|
|
8
|
+
/**
|
|
9
|
+
* Response headers.
|
|
10
|
+
*/
|
|
11
|
+
readonly headers: Record<string, string[]>;
|
|
12
|
+
/**
|
|
13
|
+
* Response body. Contains the output from `echo`,
|
|
14
|
+
* `print`, inline HTML etc.
|
|
15
|
+
*/
|
|
16
|
+
private readonly body;
|
|
17
|
+
/**
|
|
18
|
+
* Stderr contents, if any.
|
|
19
|
+
*/
|
|
20
|
+
readonly errors: string;
|
|
21
|
+
/**
|
|
22
|
+
* The exit code of the script. `0` is a success, while
|
|
23
|
+
* `1` and `2` indicate an error.
|
|
24
|
+
*/
|
|
25
|
+
readonly exitCode: number;
|
|
26
|
+
/**
|
|
27
|
+
* Response HTTP status code, e.g. 200.
|
|
28
|
+
*/
|
|
29
|
+
readonly httpStatusCode: number;
|
|
30
|
+
constructor(httpStatusCode: number, headers: Record<string, string[]>, body: ArrayBuffer, errors?: string, exitCode?: number);
|
|
31
|
+
/**
|
|
32
|
+
* Response body as JSON.
|
|
33
|
+
*/
|
|
34
|
+
get json(): any;
|
|
35
|
+
/**
|
|
36
|
+
* Response body as text.
|
|
37
|
+
*/
|
|
38
|
+
get text(): string;
|
|
39
|
+
/**
|
|
40
|
+
* Response body as bytes.
|
|
41
|
+
*/
|
|
42
|
+
get bytes(): ArrayBuffer;
|
|
43
|
+
}
|
|
44
|
+
export type PHPRequest = Pick<PHPRunOptions, "method" | "headers"> & {
|
|
45
|
+
url: string;
|
|
46
|
+
files?: Record<string, File>;
|
|
47
|
+
} & ((Pick<PHPRunOptions, "body"> & {
|
|
48
|
+
formData?: never;
|
|
49
|
+
}) | {
|
|
50
|
+
body?: never;
|
|
51
|
+
formData: Record<string, unknown>;
|
|
52
|
+
});
|
|
53
|
+
export interface PHPRequestHandlerConfiguration {
|
|
54
|
+
/**
|
|
55
|
+
* The directory in the PHP filesystem where the server will look
|
|
56
|
+
* for the files to serve. Default: `/var/www`.
|
|
57
|
+
*/
|
|
58
|
+
documentRoot?: string;
|
|
59
|
+
/**
|
|
60
|
+
* Request Handler URL. Used to populate $_SERVER details like HTTP_HOST.
|
|
61
|
+
*/
|
|
62
|
+
absoluteUrl?: string;
|
|
63
|
+
/**
|
|
64
|
+
* Callback used by the PHPRequestHandler to decide whether
|
|
65
|
+
* the requested path refers to a PHP file or a static file.
|
|
66
|
+
*/
|
|
67
|
+
isStaticFilePath?: (path: string) => boolean;
|
|
68
|
+
}
|
|
69
|
+
declare class PHPRequestHandler {
|
|
70
|
+
#private;
|
|
71
|
+
/**
|
|
72
|
+
* The PHP instance
|
|
73
|
+
*/
|
|
74
|
+
php: BasePHP;
|
|
75
|
+
/**
|
|
76
|
+
* @param php - The PHP instance.
|
|
77
|
+
* @param config - Request Handler configuration.
|
|
78
|
+
*/
|
|
79
|
+
constructor(php: BasePHP, config?: PHPRequestHandlerConfiguration);
|
|
80
|
+
/**
|
|
81
|
+
* Converts a path to an absolute URL based at the PHPRequestHandler
|
|
82
|
+
* root.
|
|
83
|
+
*
|
|
84
|
+
* @param path The server path to convert to an absolute URL.
|
|
85
|
+
* @returns The absolute URL.
|
|
86
|
+
*/
|
|
87
|
+
pathToInternalUrl(path: string): string;
|
|
88
|
+
/**
|
|
89
|
+
* Converts an absolute URL based at the PHPRequestHandler to a relative path
|
|
90
|
+
* without the server pathname and scope.
|
|
91
|
+
*
|
|
92
|
+
* @param internalUrl An absolute URL based at the PHPRequestHandler root.
|
|
93
|
+
* @returns The relative path.
|
|
94
|
+
*/
|
|
95
|
+
internalUrlToPath(internalUrl: string): string;
|
|
96
|
+
get isRequestRunning(): boolean;
|
|
97
|
+
/**
|
|
98
|
+
* The absolute URL of this PHPRequestHandler instance.
|
|
99
|
+
*/
|
|
100
|
+
get absoluteUrl(): string;
|
|
101
|
+
/**
|
|
102
|
+
* The absolute URL of this PHPRequestHandler instance.
|
|
103
|
+
*/
|
|
104
|
+
get documentRoot(): string;
|
|
105
|
+
/**
|
|
106
|
+
* Serves the request – either by serving a static file, or by
|
|
107
|
+
* dispatching it to the PHP runtime.
|
|
108
|
+
*
|
|
109
|
+
* @param request - The request.
|
|
110
|
+
* @returns The response.
|
|
111
|
+
*/
|
|
112
|
+
request(request: PHPRequest): Promise<PHPResponse>;
|
|
113
|
+
}
|
|
114
|
+
export interface PHPBrowserConfiguration {
|
|
115
|
+
/**
|
|
116
|
+
* Should handle redirects internally?
|
|
117
|
+
*/
|
|
118
|
+
handleRedirects?: boolean;
|
|
119
|
+
/**
|
|
120
|
+
* The maximum number of redirects to follow internally. Once
|
|
121
|
+
* exceeded, request() will return the redirecting response.
|
|
122
|
+
*/
|
|
123
|
+
maxRedirects?: number;
|
|
124
|
+
}
|
|
125
|
+
declare class PHPBrowser implements WithRequestHandler {
|
|
126
|
+
#private;
|
|
127
|
+
server: PHPRequestHandler;
|
|
128
|
+
/**
|
|
129
|
+
* @param server - The PHP server to browse.
|
|
130
|
+
* @param config - The browser configuration.
|
|
131
|
+
*/
|
|
132
|
+
constructor(server: PHPRequestHandler, config?: PHPBrowserConfiguration);
|
|
133
|
+
/**
|
|
134
|
+
* Sends the request to the server.
|
|
135
|
+
*
|
|
136
|
+
* When cookies are present in the response, this method stores
|
|
137
|
+
* them and sends them with any subsequent requests.
|
|
138
|
+
*
|
|
139
|
+
* When a redirection is present in the response, this method
|
|
140
|
+
* follows it by discarding a response and sending a subsequent
|
|
141
|
+
* request.
|
|
142
|
+
*
|
|
143
|
+
* @param request - The request.
|
|
144
|
+
* @param redirects - Internal. The number of redirects handled so far.
|
|
145
|
+
* @returns PHPRequestHandler response.
|
|
146
|
+
*/
|
|
147
|
+
request(request: PHPRequest, redirects?: number): Promise<PHPResponse>;
|
|
148
|
+
}
|
|
3
149
|
export type PHPRequestHeaders = Record<string, string>;
|
|
4
150
|
export interface FileInfo {
|
|
5
151
|
key: string;
|
|
@@ -7,7 +153,7 @@ export interface FileInfo {
|
|
|
7
153
|
type: string;
|
|
8
154
|
data: Uint8Array;
|
|
9
155
|
}
|
|
10
|
-
export interface
|
|
156
|
+
export interface PHPRunOptions {
|
|
11
157
|
/**
|
|
12
158
|
* Request path following the domain:port part.
|
|
13
159
|
*/
|
|
@@ -41,30 +187,6 @@ export interface PHPRequest {
|
|
|
41
187
|
*/
|
|
42
188
|
code?: string;
|
|
43
189
|
}
|
|
44
|
-
export interface PHPResponse {
|
|
45
|
-
/**
|
|
46
|
-
* The exit code of the script. `0` is a success, while
|
|
47
|
-
* `1` and `2` indicate an error.
|
|
48
|
-
*/
|
|
49
|
-
exitCode: number;
|
|
50
|
-
/**
|
|
51
|
-
* Response body. Contains the output from `echo`,
|
|
52
|
-
* `print`, inline HTML etc.
|
|
53
|
-
*/
|
|
54
|
-
body: ArrayBuffer;
|
|
55
|
-
/**
|
|
56
|
-
* PHP errors.
|
|
57
|
-
*/
|
|
58
|
-
errors: string;
|
|
59
|
-
/**
|
|
60
|
-
* Response headers.
|
|
61
|
-
*/
|
|
62
|
-
headers: Record<string, string[]>;
|
|
63
|
-
/**
|
|
64
|
-
* Response HTTP status code, e.g. 200.
|
|
65
|
-
*/
|
|
66
|
-
httpStatusCode: number;
|
|
67
|
-
}
|
|
68
190
|
export type PHPRuntimeId = number;
|
|
69
191
|
export interface WithPHPIniBindings {
|
|
70
192
|
setPhpIniPath(path: string): void;
|
|
@@ -153,21 +275,30 @@ export interface WithFilesystem {
|
|
|
153
275
|
* @returns True if the file exists, false otherwise.
|
|
154
276
|
*/
|
|
155
277
|
fileExists(path: string): boolean;
|
|
278
|
+
/**
|
|
279
|
+
* Changes the current working directory in the PHP filesystem.
|
|
280
|
+
* This is the directory that will be used as the base for relative paths.
|
|
281
|
+
* For example, if the current working directory is `/root/php`, and the
|
|
282
|
+
* path is `data`, the absolute path will be `/root/php/data`.
|
|
283
|
+
*
|
|
284
|
+
* @param path - The new working directory.
|
|
285
|
+
*/
|
|
286
|
+
chdir(path: string): void;
|
|
156
287
|
}
|
|
157
288
|
export interface WithRun {
|
|
158
289
|
/**
|
|
159
|
-
*
|
|
290
|
+
* Runs PHP code.
|
|
160
291
|
* Cannot be used in conjunction with `cli()`.
|
|
161
292
|
*
|
|
162
293
|
* @example
|
|
163
294
|
* ```js
|
|
164
|
-
* const output = php.run('<?php echo "Hello world!";');
|
|
295
|
+
* const output = await php.run('<?php echo "Hello world!";');
|
|
165
296
|
* console.log(output.stdout); // "Hello world!"
|
|
166
297
|
* ```
|
|
167
298
|
*
|
|
168
299
|
* @example
|
|
169
300
|
* ```js
|
|
170
|
-
* console.log(php.run(`<?php
|
|
301
|
+
* console.log(await php.run(`<?php
|
|
171
302
|
* $fp = fopen('php://stderr', 'w');
|
|
172
303
|
* fwrite($fp, "Hello, world!");
|
|
173
304
|
* `));
|
|
@@ -176,33 +307,80 @@ export interface WithRun {
|
|
|
176
307
|
*
|
|
177
308
|
* @param request - PHP Request data.
|
|
178
309
|
*/
|
|
179
|
-
run(request?:
|
|
310
|
+
run(request?: PHPRunOptions): Promise<PHPResponse>;
|
|
311
|
+
}
|
|
312
|
+
export interface WithRequestHandler {
|
|
313
|
+
/**
|
|
314
|
+
* Dispatches a HTTP request using PHP as a backend.
|
|
315
|
+
* Cannot be used in conjunction with `cli()`.
|
|
316
|
+
*
|
|
317
|
+
* @example
|
|
318
|
+
* ```js
|
|
319
|
+
* const output = await php.request({
|
|
320
|
+
* method: 'GET',
|
|
321
|
+
* url: '/index.php',
|
|
322
|
+
* headers: {
|
|
323
|
+
* 'X-foo': 'bar',
|
|
324
|
+
* },
|
|
325
|
+
* formData: {
|
|
326
|
+
* foo: 'bar',
|
|
327
|
+
* },
|
|
328
|
+
* });
|
|
329
|
+
* console.log(output.stdout); // "Hello world!"
|
|
330
|
+
* ```
|
|
331
|
+
*
|
|
332
|
+
* @param request - PHP Request data.
|
|
333
|
+
*/
|
|
334
|
+
request(request?: PHPRequest): Promise<PHPResponse>;
|
|
180
335
|
}
|
|
336
|
+
export type PHPRuntime = any;
|
|
337
|
+
export type DataModule = {
|
|
338
|
+
dependencyFilename: string;
|
|
339
|
+
dependenciesTotalSize: number;
|
|
340
|
+
default: (phpRuntime: PHPRuntime) => void;
|
|
341
|
+
};
|
|
342
|
+
export type EmscriptenOptions = {
|
|
343
|
+
onAbort?: (message: string) => void;
|
|
344
|
+
ENV?: Record<string, string>;
|
|
345
|
+
locateFile?: (path: string) => string;
|
|
346
|
+
noInitialRun?: boolean;
|
|
347
|
+
dataFileDownloads?: Record<string, number>;
|
|
348
|
+
print?: (message: string) => void;
|
|
349
|
+
printErr?: (message: string) => void;
|
|
350
|
+
onRuntimeInitialized?: () => void;
|
|
351
|
+
monitorRunDependencies?: (left: number) => void;
|
|
352
|
+
} & Record<string, any>;
|
|
181
353
|
export type MountSettings = {
|
|
182
354
|
root: string;
|
|
183
|
-
mountpoint?: string;
|
|
184
355
|
};
|
|
185
|
-
declare class
|
|
356
|
+
declare abstract class BasePHP implements WithPHPIniBindings, WithFilesystem, WithNodeFilesystem, WithCLI, WithRequestHandler, WithRun {
|
|
186
357
|
#private;
|
|
358
|
+
requestHandler?: PHPBrowser;
|
|
187
359
|
/**
|
|
188
360
|
* Initializes a PHP runtime.
|
|
189
361
|
*
|
|
190
362
|
* @internal
|
|
191
363
|
* @param PHPRuntime - Optional. PHP Runtime ID as initialized by loadPHPRuntime.
|
|
364
|
+
* @param serverOptions - Optional. Options for the PHPRequestHandler. If undefined, no request handler will be initialized.
|
|
192
365
|
*/
|
|
193
|
-
constructor(PHPRuntimeId?: PHPRuntimeId);
|
|
366
|
+
constructor(PHPRuntimeId?: PHPRuntimeId, serverOptions?: PHPRequestHandlerConfiguration);
|
|
194
367
|
initializeRuntime(runtimeId: PHPRuntimeId): void;
|
|
195
368
|
/** @inheritDoc */
|
|
196
369
|
setPhpIniPath(path: string): void;
|
|
197
370
|
/** @inheritDoc */
|
|
198
371
|
setPhpIniEntry(key: string, value: string): void;
|
|
372
|
+
/** @inheritDoc */
|
|
199
373
|
chdir(path: string): void;
|
|
200
374
|
/** @inheritDoc */
|
|
201
|
-
|
|
375
|
+
request(request: PHPRequest, maxRedirects?: number): Promise<PHPResponse>;
|
|
376
|
+
/** @inheritDoc */
|
|
377
|
+
run(request?: PHPRunOptions): Promise<PHPResponse>;
|
|
202
378
|
cli(argv: string[]): Promise<number>;
|
|
203
379
|
setSkipShebang(shouldSkip: boolean): void;
|
|
204
380
|
addServerGlobalEntry(key: string, value: string): void;
|
|
381
|
+
/** @inheritDoc */
|
|
205
382
|
mkdirTree(path: string): void;
|
|
383
|
+
/** @inheritDoc */
|
|
206
384
|
readFileAsText(path: string): string;
|
|
207
385
|
/** @inheritDoc */
|
|
208
386
|
readFileAsBuffer(path: string): Uint8Array;
|
|
@@ -212,122 +390,25 @@ declare class PHP implements WithPHPIniBindings, WithFilesystem, WithNodeFilesys
|
|
|
212
390
|
unlink(path: string): void;
|
|
213
391
|
/** @inheritDoc */
|
|
214
392
|
listFiles(path: string): string[];
|
|
393
|
+
/** @inheritDoc */
|
|
215
394
|
isDir(path: string): boolean;
|
|
395
|
+
/** @inheritDoc */
|
|
216
396
|
fileExists(path: string): boolean;
|
|
397
|
+
/** @inheritDoc */
|
|
217
398
|
mount(settings: MountSettings, path: string): void;
|
|
218
399
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
formData: Record<string, unknown>;
|
|
232
|
-
});
|
|
233
|
-
declare class PHPServer {
|
|
234
|
-
#private;
|
|
235
|
-
/**
|
|
236
|
-
* The PHP instance
|
|
237
|
-
*/
|
|
238
|
-
php: PHP;
|
|
239
|
-
/**
|
|
240
|
-
* @param php - The PHP instance.
|
|
241
|
-
* @param config - Server configuration.
|
|
242
|
-
*/
|
|
243
|
-
constructor(php: PHP, config?: PHPServerConfigation);
|
|
244
|
-
/**
|
|
245
|
-
* Converts a path to an absolute URL based at the PHPServer
|
|
246
|
-
* root.
|
|
247
|
-
*
|
|
248
|
-
* @param path The server path to convert to an absolute URL.
|
|
249
|
-
* @returns The absolute URL.
|
|
250
|
-
*/
|
|
251
|
-
pathToInternalUrl(path: string): string;
|
|
252
|
-
/**
|
|
253
|
-
* Converts an absolute URL based at the PHPServer to a relative path
|
|
254
|
-
* without the server pathname and scope.
|
|
255
|
-
*
|
|
256
|
-
* @param internalUrl An absolute URL based at the PHPServer root.
|
|
257
|
-
* @returns The relative path.
|
|
258
|
-
*/
|
|
259
|
-
internalUrlToPath(internalUrl: string): string;
|
|
260
|
-
/**
|
|
261
|
-
* The absolute URL of this PHPServer instance.
|
|
262
|
-
*/
|
|
263
|
-
get absoluteUrl(): string;
|
|
264
|
-
/**
|
|
265
|
-
* The absolute URL of this PHPServer instance.
|
|
266
|
-
*/
|
|
267
|
-
get documentRoot(): string;
|
|
268
|
-
/**
|
|
269
|
-
* Serves the request – either by serving a static file, or by
|
|
270
|
-
* dispatching it to the PHP runtime.
|
|
271
|
-
*
|
|
272
|
-
* @param request - The request.
|
|
273
|
-
* @returns The response.
|
|
274
|
-
*/
|
|
275
|
-
request(request: PHPServerRequest): Promise<PHPResponse>;
|
|
276
|
-
}
|
|
277
|
-
export interface PHPServerConfigation {
|
|
278
|
-
/**
|
|
279
|
-
* The directory in the PHP filesystem where the server will look
|
|
280
|
-
* for the files to serve. Default: `/var/www`.
|
|
281
|
-
*/
|
|
282
|
-
documentRoot?: string;
|
|
283
|
-
/**
|
|
284
|
-
* Server URL. Used to populate $_SERVER details like HTTP_HOST.
|
|
285
|
-
*/
|
|
286
|
-
absoluteUrl?: string;
|
|
287
|
-
/**
|
|
288
|
-
* Callback used by the PHPServer to decide whether
|
|
289
|
-
* the requested path refers to a PHP file or a static file.
|
|
290
|
-
*/
|
|
291
|
-
isStaticFilePath?: (path: string) => boolean;
|
|
292
|
-
}
|
|
293
|
-
export interface WithRequest {
|
|
294
|
-
/**
|
|
295
|
-
* Sends the request to the server.
|
|
296
|
-
*
|
|
297
|
-
* When cookies are present in the response, this method stores
|
|
298
|
-
* them and sends them with any subsequent requests.
|
|
299
|
-
*
|
|
300
|
-
* When a redirection is present in the response, this method
|
|
301
|
-
* follows it by discarding a response and sending a subsequent
|
|
302
|
-
* request.
|
|
303
|
-
*
|
|
304
|
-
* @param request - The request.
|
|
305
|
-
* @param redirects - Internal. The number of redirects handled so far.
|
|
306
|
-
* @returns PHPServer response.
|
|
307
|
-
*/
|
|
308
|
-
request(request: PHPServerRequest, redirects?: number): Promise<PHPResponse>;
|
|
309
|
-
}
|
|
310
|
-
declare class PHPBrowser implements WithRequest {
|
|
311
|
-
#private;
|
|
312
|
-
server: PHPServer;
|
|
313
|
-
/**
|
|
314
|
-
* @param server - The PHP server to browse.
|
|
315
|
-
* @param config - The browser configuration.
|
|
316
|
-
*/
|
|
317
|
-
constructor(server: PHPServer, config?: PHPBrowserConfiguration);
|
|
318
|
-
request(request: PHPServerRequest, redirects?: number): Promise<PHPResponse>;
|
|
319
|
-
}
|
|
320
|
-
export interface PHPBrowserConfiguration {
|
|
321
|
-
/**
|
|
322
|
-
* Should handle redirects internally?
|
|
323
|
-
*/
|
|
324
|
-
handleRedirects?: boolean;
|
|
325
|
-
/**
|
|
326
|
-
* The maximum number of redirects to follow internally. Once
|
|
327
|
-
* exceeded, request() will return the redirecting response.
|
|
328
|
-
*/
|
|
329
|
-
maxRedirects?: number;
|
|
330
|
-
}
|
|
400
|
+
declare const SupportedPHPVersions: readonly [
|
|
401
|
+
"8.2",
|
|
402
|
+
"8.1",
|
|
403
|
+
"8.0",
|
|
404
|
+
"7.4",
|
|
405
|
+
"7.3",
|
|
406
|
+
"7.2",
|
|
407
|
+
"7.1",
|
|
408
|
+
"7.0",
|
|
409
|
+
"5.6"
|
|
410
|
+
];
|
|
411
|
+
export type SupportedPHPVersion = (typeof SupportedPHPVersions)[number];
|
|
331
412
|
export type PublicAPI<Methods, PipedAPI = unknown> = Methods & PipedAPI & {
|
|
332
413
|
isReady: () => Promise<void>;
|
|
333
414
|
};
|
|
@@ -338,7 +419,7 @@ export interface MonitoredModule {
|
|
|
338
419
|
declare class EmscriptenDownloadMonitor extends EventTarget {
|
|
339
420
|
#private;
|
|
340
421
|
constructor(modules?: MonitoredModule[]);
|
|
341
|
-
|
|
422
|
+
getEmscriptenOptions(): {
|
|
342
423
|
dataFileDownloads: Record<string, any>;
|
|
343
424
|
};
|
|
344
425
|
setModules(modules: MonitoredModule[]): void;
|
|
@@ -374,6 +455,40 @@ declare class ProgressObserver extends EventTarget {
|
|
|
374
455
|
slowlyIncrementBy(progress: number): void;
|
|
375
456
|
get totalProgress(): number;
|
|
376
457
|
}
|
|
458
|
+
export interface PHPWebLoaderOptions {
|
|
459
|
+
emscriptenOptions?: EmscriptenOptions;
|
|
460
|
+
downloadMonitor?: EmscriptenDownloadMonitor;
|
|
461
|
+
requestHandler?: PHPRequestHandlerConfiguration;
|
|
462
|
+
dataModules?: Array<DataModule | Promise<DataModule>>;
|
|
463
|
+
}
|
|
464
|
+
declare class PHP extends BasePHP {
|
|
465
|
+
/**
|
|
466
|
+
* Creates a new PHP instance.
|
|
467
|
+
*
|
|
468
|
+
* Dynamically imports the PHP module, initializes the runtime,
|
|
469
|
+
* and sets up networking. It's a shorthand for the lower-level
|
|
470
|
+
* functions like `getPHPLoaderModule`, `loadPHPRuntime`, and
|
|
471
|
+
* `PHP.initializeRuntime`
|
|
472
|
+
*
|
|
473
|
+
* @param phpVersion The PHP Version to load
|
|
474
|
+
* @param options The options to use when loading PHP
|
|
475
|
+
* @returns A new PHP instance
|
|
476
|
+
*/
|
|
477
|
+
static load(phpVersion: SupportedPHPVersion, options?: PHPWebLoaderOptions): Promise<PHP>;
|
|
478
|
+
/**
|
|
479
|
+
* Does what load() does, but synchronously returns
|
|
480
|
+
* an object with the PHP instance and a promise that
|
|
481
|
+
* resolves when the PHP instance is ready.
|
|
482
|
+
*
|
|
483
|
+
* @see load
|
|
484
|
+
* @inheritdoc load
|
|
485
|
+
*/
|
|
486
|
+
static loadSync(phpVersion: SupportedPHPVersion, options?: PHPWebLoaderOptions): {
|
|
487
|
+
php: PHP;
|
|
488
|
+
phpReady: Promise<PHP>;
|
|
489
|
+
dataModules: Promise<DataModule[]>;
|
|
490
|
+
};
|
|
491
|
+
}
|
|
377
492
|
/** @inheritdoc T */
|
|
378
493
|
export type Promisify<T> = {
|
|
379
494
|
[P in keyof T]: T[P] extends (...args: infer A) => infer R ? R extends void | Promise<any> ? T[P] : (...args: A) => Promise<ReturnType<T[P]>> : Promise<T[P]>;
|
|
@@ -385,22 +500,24 @@ export interface WithPathConversion {
|
|
|
385
500
|
export interface WithProgress {
|
|
386
501
|
onDownloadProgress(callback: (progress: CustomEvent<ProgressEvent>) => void): Promise<void>;
|
|
387
502
|
}
|
|
388
|
-
declare class PHPClient implements Promisify<
|
|
389
|
-
/** @inheritDoc @php-wasm/web!
|
|
503
|
+
declare class PHPClient implements Promisify<WithPHPIniBindings & WithFilesystem & WithRun & WithRequestHandler & WithProgress & WithPathConversion> {
|
|
504
|
+
/** @inheritDoc @php-wasm/web!PHPRequestHandler.absoluteUrl */
|
|
390
505
|
absoluteUrl: Promise<string>;
|
|
391
|
-
/** @inheritDoc @php-wasm/web!
|
|
506
|
+
/** @inheritDoc @php-wasm/web!PHPRequestHandler.documentRoot */
|
|
392
507
|
documentRoot: Promise<string>;
|
|
393
508
|
/** @inheritDoc */
|
|
394
|
-
constructor(
|
|
395
|
-
/** @inheritDoc @php-wasm/web!
|
|
509
|
+
constructor(php: BasePHP, monitor?: EmscriptenDownloadMonitor);
|
|
510
|
+
/** @inheritDoc @php-wasm/web!PHPRequestHandler.pathToInternalUrl */
|
|
396
511
|
pathToInternalUrl(path: string): Promise<string>;
|
|
397
|
-
/** @inheritDoc @php-wasm/web!
|
|
512
|
+
/** @inheritDoc @php-wasm/web!PHPRequestHandler.internalUrlToPath */
|
|
398
513
|
internalUrlToPath(internalUrl: string): Promise<string>;
|
|
399
514
|
onDownloadProgress(callback: (progress: CustomEvent<ProgressEvent>) => void): Promise<void>;
|
|
400
|
-
/** @inheritDoc @php-wasm/web!
|
|
401
|
-
request(request:
|
|
515
|
+
/** @inheritDoc @php-wasm/web!PHPRequestHandler.request */
|
|
516
|
+
request(request: PHPRequest, redirects?: number): Promise<PHPResponse>;
|
|
402
517
|
/** @inheritDoc @php-wasm/web!PHP.run */
|
|
403
|
-
run(request?:
|
|
518
|
+
run(request?: PHPRunOptions): Promise<PHPResponse>;
|
|
519
|
+
/** @inheritDoc @php-wasm/web!PHP.chdir */
|
|
520
|
+
chdir(path: string): void;
|
|
404
521
|
/** @inheritDoc @php-wasm/web!PHP.setPhpIniPath */
|
|
405
522
|
setPhpIniPath(path: string): void;
|
|
406
523
|
/** @inheritDoc @php-wasm/web!PHP.setPhpIniEntry */
|
|
@@ -426,7 +543,7 @@ declare class PlaygroundWorkerClientClass extends PHPClient {
|
|
|
426
543
|
scope: Promise<string>;
|
|
427
544
|
wordPressVersion: Promise<string>;
|
|
428
545
|
phpVersion: Promise<string>;
|
|
429
|
-
constructor(
|
|
546
|
+
constructor(php: PHP, monitor: EmscriptenDownloadMonitor, scope: string, wordPressVersion: string, phpVersion: string);
|
|
430
547
|
getWordPressModuleDetails(): Promise<{
|
|
431
548
|
staticAssetsDirectory: string;
|
|
432
549
|
defaultTheme: any;
|
|
@@ -449,12 +566,96 @@ export interface PlaygroundClient extends WebClientMixin, PlaygroundWorkerClient
|
|
|
449
566
|
}
|
|
450
567
|
export declare function exportFile(playground: PlaygroundClient): Promise<void>;
|
|
451
568
|
export declare function importFile(playground: PlaygroundClient, file: File): Promise<boolean>;
|
|
569
|
+
/**
|
|
570
|
+
* Logs in to the Playground.
|
|
571
|
+
* Under the hood, this function submits the wp-login.php form
|
|
572
|
+
* just like a user would.
|
|
573
|
+
*
|
|
574
|
+
* @param playground The playground client.
|
|
575
|
+
* @param user The user to log in as. Defaults to 'admin'.
|
|
576
|
+
* @param password The password to log in with. Defaults to 'password'.
|
|
577
|
+
*/
|
|
452
578
|
export declare function login(playground: PlaygroundClient, user?: string, password?: string): Promise<void>;
|
|
453
|
-
export
|
|
454
|
-
|
|
579
|
+
export interface InstallThemeOptions {
|
|
580
|
+
/**
|
|
581
|
+
* Whether to activate the theme after installing it.
|
|
582
|
+
*/
|
|
583
|
+
activate?: boolean;
|
|
584
|
+
}
|
|
585
|
+
/**
|
|
586
|
+
* Installs a WordPress theme in the Playground.
|
|
587
|
+
* Technically, it uses the same theme upload form as a WordPress user
|
|
588
|
+
* would, and then activates the theme if needed.
|
|
589
|
+
*
|
|
590
|
+
* @param playground The playground client.
|
|
591
|
+
* @param themeZipFile The theme zip file.
|
|
592
|
+
* @param options Optional. Set `activate` to false if you don't want to activate the theme.
|
|
593
|
+
*/
|
|
594
|
+
export declare function installTheme(playground: PlaygroundClient, themeZipFile: File, options?: InstallThemeOptions): Promise<void>;
|
|
595
|
+
export interface InstallPluginOptions {
|
|
596
|
+
/**
|
|
597
|
+
* Whether to activate the plugin after installing it.
|
|
598
|
+
*/
|
|
599
|
+
activate?: boolean;
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* Installs a WordPress plugin in the Playground.
|
|
603
|
+
* Technically, it uses the same plugin upload form as a WordPress user
|
|
604
|
+
* would, and then activates the plugin if needed.
|
|
605
|
+
*
|
|
606
|
+
* @param playground The playground client.
|
|
607
|
+
* @param pluginZipFile The plugin zip file.
|
|
608
|
+
* @param options Optional. Set `activate` to false if you don't want to activate the plugin.
|
|
609
|
+
*/
|
|
610
|
+
export declare function installPlugin(playground: PlaygroundClient, pluginZipFile: File, options?: InstallPluginOptions): Promise<void>;
|
|
611
|
+
/**
|
|
612
|
+
* Activates a WordPress plugin in the Playground.
|
|
613
|
+
*
|
|
614
|
+
* @param playground The playground client.
|
|
615
|
+
* @param plugin The plugin slug.
|
|
616
|
+
*/
|
|
455
617
|
export declare function activatePlugin(playground: PlaygroundClient, plugin: string): Promise<void>;
|
|
618
|
+
/**
|
|
619
|
+
* Downloads and installs a theme from the WordPress.org theme directory.
|
|
620
|
+
* Under the hood, it downloads the themes through a proxy endpoint
|
|
621
|
+
* and installs then one after another using the installTheme function.
|
|
622
|
+
*
|
|
623
|
+
* @see installPlugin
|
|
624
|
+
* @param playground The playground client.
|
|
625
|
+
* @param themeZipName The theme zip file name. For example, set this parameter
|
|
626
|
+
* to "twentytwentythree.1.1.zip" to download the Twenty Twenty Three theme
|
|
627
|
+
* from https://downloads.wordpress.org/theme/twentytwentythree.1.1.zip.
|
|
628
|
+
*
|
|
629
|
+
* @param maxProgress Optional. The maximum progress value to use. Defaults to 100.
|
|
630
|
+
* @param progress Optional. The progress observer that will be notified of the progress.
|
|
631
|
+
*/
|
|
456
632
|
export declare function installThemeFromDirectory(playground: PlaygroundClient, themeZipName: string, progressBudget?: number, progress?: ProgressObserver): Promise<void>;
|
|
457
|
-
|
|
458
|
-
|
|
633
|
+
/**
|
|
634
|
+
* Downloads and installs multiple plugins from the WordPress.org plugin directory.
|
|
635
|
+
* Under the hood, it downloads the plugins through a proxy endpoint
|
|
636
|
+
* and installs then one after another using the installPlugin function.
|
|
637
|
+
*
|
|
638
|
+
* @see installPlugin
|
|
639
|
+
* @param playground The playground client.
|
|
640
|
+
* @param pluginsZipNames The plugin zip file names. For example, set this parameter
|
|
641
|
+
* to ["gutenberg.15.5.0.zip"] to download the Gutenberg plugin
|
|
642
|
+
* from https://downloads.wordpress.org/plugin/gutenberg.15.5.0.zip.
|
|
643
|
+
* @param maxProgress Optional. The maximum progress value to use. Defaults to 100.
|
|
644
|
+
* @param progress Optional. The progress observer that will be notified of the progress.
|
|
645
|
+
*/
|
|
646
|
+
export declare function installPluginsFromDirectory(playground: PlaygroundClient, pluginsZipNames: string[], maxProgress?: number, progress?: ProgressObserver): Promise<void>;
|
|
647
|
+
export interface ConnectPlaygroundOptions {
|
|
648
|
+
loadRemote?: string;
|
|
649
|
+
}
|
|
650
|
+
/**
|
|
651
|
+
* Connects to a playground iframe and returns a PlaygroundClient instance.
|
|
652
|
+
*
|
|
653
|
+
* @param iframe Any iframe with Playground's remote.html loaded.
|
|
654
|
+
* @param options Optional. If `loadRemote` is set, the iframe's `src` will be set to that URL.
|
|
655
|
+
* In other words, use this option if your iframe doesn't have remote.html already
|
|
656
|
+
* loaded.
|
|
657
|
+
* @returns A PlaygroundClient instance.
|
|
658
|
+
*/
|
|
659
|
+
export declare function connectPlayground(iframe: HTMLIFrameElement, options?: ConnectPlaygroundOptions): Promise<PlaygroundClient>;
|
|
459
660
|
|
|
460
661
|
export {};
|