@wp-playground/blueprints 0.3.1 → 0.5.2
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/blueprint-schema.json +282 -176
- package/index.cjs +257 -201
- package/index.d.ts +1766 -6
- package/index.js +3936 -3512
- package/lib/steps/apply-wordpress-patches/index.d.ts +2 -1
- package/lib/steps/common.d.ts +9 -6
- package/lib/steps/define-wp-config-consts.d.ts +7 -8
- package/lib/steps/export-wxr.d.ts +9 -0
- package/lib/steps/export-wxz.d.ts +9 -0
- package/lib/steps/handlers.d.ts +7 -1
- package/lib/steps/import-file.d.ts +29 -0
- package/lib/steps/import-wp-content.d.ts +41 -0
- package/lib/steps/index.d.ts +9 -5
- package/lib/steps/install-asset.d.ts +1 -1
- package/lib/steps/request.d.ts +1 -1
- package/lib/steps/run-php-with-options.d.ts +1 -1
- package/lib/steps/run-sql.d.ts +35 -0
- package/lib/steps/unzip.d.ts +28 -0
- package/lib/steps/zip-wp-content.d.ts +17 -0
- package/package.json +2 -2
- package/lib/blueprint.d.ts +0 -31
- package/lib/compile.d.ts +0 -43
- package/lib/resources.d.ts +0 -210
- package/lib/steps/import-export.d.ts +0 -107
- package/lib/steps/migration.d.ts +0 -2
package/index.d.ts
CHANGED
|
@@ -1,11 +1,1771 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
// Generated by dts-bundle-generator v7.2.0
|
|
2
|
+
|
|
3
|
+
import { Remote } from 'comlink';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Options for customizing the progress tracker.
|
|
7
|
+
*/
|
|
8
|
+
export interface ProgressTrackerOptions {
|
|
9
|
+
/** The weight of the progress, a number between 0 and 1. */
|
|
10
|
+
weight?: number;
|
|
11
|
+
/** The caption to display during progress, a string. */
|
|
12
|
+
caption?: string;
|
|
13
|
+
/** The time in milliseconds to fill the progress, a number. */
|
|
14
|
+
fillTime?: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Custom event providing information about a loading process.
|
|
18
|
+
*/
|
|
19
|
+
export type LoadingEvent = CustomEvent<{
|
|
20
|
+
/** The number representing how much was loaded. */
|
|
21
|
+
loaded: number;
|
|
22
|
+
/** The number representing how much needs to loaded in total. */
|
|
23
|
+
total: number;
|
|
24
|
+
}>;
|
|
25
|
+
/**
|
|
26
|
+
* Custom event providing progress details.
|
|
27
|
+
*/
|
|
28
|
+
export type ProgressTrackerEvent = CustomEvent<ProgressDetails>;
|
|
29
|
+
export interface ProgressDetails {
|
|
30
|
+
/** The progress percentage as a number between 0 and 100. */
|
|
31
|
+
progress: number;
|
|
32
|
+
/** The caption to display during progress, a string. */
|
|
33
|
+
caption: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* ProgressObserver A function that receives progress updates.
|
|
37
|
+
*
|
|
38
|
+
* @param progress The progress percentage as a number between 0 and 100.
|
|
39
|
+
*/
|
|
40
|
+
export type ProgressObserver = (progress: number) => void;
|
|
41
|
+
/**
|
|
42
|
+
* Listener A function for handling specific event types.
|
|
43
|
+
*
|
|
44
|
+
* @param event The event of type T.
|
|
45
|
+
*/
|
|
46
|
+
export type Listener<T> = (event: T) => void;
|
|
47
|
+
export type TSCompatibleListener<T> = EventListenerOrEventListenerObject | null | Listener<T>;
|
|
48
|
+
export interface ProgressReceiver {
|
|
49
|
+
setProgress(details: ProgressDetails): any;
|
|
50
|
+
setLoaded(): any;
|
|
51
|
+
}
|
|
52
|
+
declare class ProgressTracker extends EventTarget {
|
|
53
|
+
private _selfWeight;
|
|
54
|
+
private _selfDone;
|
|
55
|
+
private _selfProgress;
|
|
56
|
+
private _selfCaption;
|
|
57
|
+
private _weight;
|
|
58
|
+
private _progressObserver?;
|
|
59
|
+
private _loadingListener?;
|
|
60
|
+
private _isFilling;
|
|
61
|
+
private _fillTime;
|
|
62
|
+
private _fillInterval?;
|
|
63
|
+
private _subTrackers;
|
|
64
|
+
constructor({ weight, caption, fillTime, }?: ProgressTrackerOptions);
|
|
65
|
+
/**
|
|
66
|
+
* Creates a new sub-tracker with a specific weight.
|
|
67
|
+
*
|
|
68
|
+
* The weight determines what percentage of the overall progress
|
|
69
|
+
* the sub-tracker represents. For example, if the main tracker is
|
|
70
|
+
* monitoring a process that has two stages, and the first stage
|
|
71
|
+
* is expected to take twice as long as the second stage, you could
|
|
72
|
+
* create the first sub-tracker with a weight of 0.67 and the second
|
|
73
|
+
* sub-tracker with a weight of 0.33.
|
|
74
|
+
*
|
|
75
|
+
* The caption is an optional string that describes the current stage
|
|
76
|
+
* of the operation. If provided, it will be used as the progress caption
|
|
77
|
+
* for the sub-tracker. If not provided, the main tracker will look for
|
|
78
|
+
* the next sub-tracker with a non-empty caption and use that as the progress
|
|
79
|
+
* caption instead.
|
|
80
|
+
*
|
|
81
|
+
* Returns the newly-created sub-tracker.
|
|
82
|
+
*
|
|
83
|
+
* @throws {Error} If the weight of the new stage would cause the total weight of all stages to exceed 1.
|
|
84
|
+
*
|
|
85
|
+
* @param weight The weight of the new stage, as a decimal value between 0 and 1.
|
|
86
|
+
* @param caption The caption for the new stage, which will be used as the progress caption for the sub-tracker.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* const tracker = new ProgressTracker();
|
|
91
|
+
* const subTracker1 = tracker.stage(0.67, 'Slow stage');
|
|
92
|
+
* const subTracker2 = tracker.stage(0.33, 'Fast stage');
|
|
93
|
+
*
|
|
94
|
+
* subTracker2.set(50);
|
|
95
|
+
* subTracker1.set(75);
|
|
96
|
+
* subTracker2.set(100);
|
|
97
|
+
* subTracker1.set(100);
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
stage(weight?: number, caption?: string): ProgressTracker;
|
|
101
|
+
/**
|
|
102
|
+
* Fills the progress bar slowly over time, simulating progress.
|
|
103
|
+
*
|
|
104
|
+
* The progress bar is filled in a 100 steps, and each step, the progress
|
|
105
|
+
* is increased by 1. If `stopBeforeFinishing` is true, the progress bar
|
|
106
|
+
* will stop filling when it reaches 99% so that you can call `finish()`
|
|
107
|
+
* explicitly.
|
|
108
|
+
*
|
|
109
|
+
* If the progress bar is filling or already filled, this method does nothing.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```ts
|
|
113
|
+
* const progress = new ProgressTracker({ caption: 'Processing...' });
|
|
114
|
+
* progress.fillSlowly();
|
|
115
|
+
* ```
|
|
116
|
+
*
|
|
117
|
+
* @param options Optional options.
|
|
118
|
+
*/
|
|
119
|
+
fillSlowly({ stopBeforeFinishing }?: {
|
|
120
|
+
stopBeforeFinishing?: boolean | undefined;
|
|
121
|
+
}): void;
|
|
122
|
+
set(value: number): void;
|
|
123
|
+
finish(): void;
|
|
124
|
+
get caption(): string;
|
|
125
|
+
setCaption(caption: string): void;
|
|
126
|
+
get done(): boolean;
|
|
127
|
+
get progress(): number;
|
|
128
|
+
get weight(): number;
|
|
129
|
+
get observer(): ProgressObserver;
|
|
130
|
+
get loadingListener(): Listener<LoadingEvent>;
|
|
131
|
+
pipe(receiver: ProgressReceiver): void;
|
|
132
|
+
addEventListener(type: string, listener: TSCompatibleListener<ProgressTrackerEvent>): void;
|
|
133
|
+
removeEventListener(type: string, listener: TSCompatibleListener<ProgressTrackerEvent>): void;
|
|
134
|
+
private notifyProgress;
|
|
135
|
+
private notifyDone;
|
|
136
|
+
}
|
|
137
|
+
export interface PHPResponseData {
|
|
138
|
+
/**
|
|
139
|
+
* Response headers.
|
|
140
|
+
*/
|
|
141
|
+
readonly headers: Record<string, string[]>;
|
|
142
|
+
/**
|
|
143
|
+
* Response body. Contains the output from `echo`,
|
|
144
|
+
* `print`, inline HTML etc.
|
|
145
|
+
*/
|
|
146
|
+
readonly bytes: ArrayBuffer;
|
|
147
|
+
/**
|
|
148
|
+
* Stderr contents, if any.
|
|
149
|
+
*/
|
|
150
|
+
readonly errors: string;
|
|
151
|
+
/**
|
|
152
|
+
* The exit code of the script. `0` is a success, while
|
|
153
|
+
* `1` and `2` indicate an error.
|
|
154
|
+
*/
|
|
155
|
+
readonly exitCode: number;
|
|
156
|
+
/**
|
|
157
|
+
* Response HTTP status code, e.g. 200.
|
|
158
|
+
*/
|
|
159
|
+
readonly httpStatusCode: number;
|
|
160
|
+
}
|
|
161
|
+
declare class PHPResponse implements PHPResponseData {
|
|
162
|
+
/** @inheritDoc */
|
|
163
|
+
readonly headers: Record<string, string[]>;
|
|
164
|
+
/** @inheritDoc */
|
|
165
|
+
readonly bytes: ArrayBuffer;
|
|
166
|
+
/** @inheritDoc */
|
|
167
|
+
readonly errors: string;
|
|
168
|
+
/** @inheritDoc */
|
|
169
|
+
readonly exitCode: number;
|
|
170
|
+
/** @inheritDoc */
|
|
171
|
+
readonly httpStatusCode: number;
|
|
172
|
+
constructor(httpStatusCode: number, headers: Record<string, string[]>, body: ArrayBuffer, errors?: string, exitCode?: number);
|
|
173
|
+
static fromRawData(data: PHPResponseData): PHPResponse;
|
|
174
|
+
toRawData(): PHPResponseData;
|
|
175
|
+
/**
|
|
176
|
+
* Response body as JSON.
|
|
177
|
+
*/
|
|
178
|
+
get json(): any;
|
|
179
|
+
/**
|
|
180
|
+
* Response body as text.
|
|
181
|
+
*/
|
|
182
|
+
get text(): string;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Represents an event related to the PHP filesystem.
|
|
186
|
+
*/
|
|
187
|
+
export interface PHPRequestEndEvent {
|
|
188
|
+
type: "request.end";
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Represents an event related to the PHP instance.
|
|
192
|
+
* This is intentionally not an extension of CustomEvent
|
|
193
|
+
* to make it isomorphic between different JavaScript runtimes.
|
|
194
|
+
*/
|
|
195
|
+
export type PHPEvent = PHPRequestEndEvent;
|
|
196
|
+
/**
|
|
197
|
+
* A callback function that handles PHP events.
|
|
198
|
+
*/
|
|
199
|
+
export type PHPEventListener = (event: PHPEvent) => void;
|
|
200
|
+
/**
|
|
201
|
+
* Handles HTTP requests using PHP runtime as a backend.
|
|
202
|
+
*
|
|
203
|
+
* @public
|
|
204
|
+
* @example Use PHPRequestHandler implicitly with a new PHP instance:
|
|
205
|
+
* ```js
|
|
206
|
+
* import { PHP } from '@php-wasm/web';
|
|
207
|
+
*
|
|
208
|
+
* const php = await PHP.load( '7.4', {
|
|
209
|
+
* requestHandler: {
|
|
210
|
+
* // PHP FS path to serve the files from:
|
|
211
|
+
* documentRoot: '/www',
|
|
212
|
+
*
|
|
213
|
+
* // Used to populate $_SERVER['SERVER_NAME'] etc.:
|
|
214
|
+
* absoluteUrl: 'http://127.0.0.1'
|
|
215
|
+
* }
|
|
216
|
+
* } );
|
|
217
|
+
*
|
|
218
|
+
* php.mkdirTree('/www');
|
|
219
|
+
* php.writeFile('/www/index.php', '<?php echo "Hi from PHP!"; ');
|
|
220
|
+
*
|
|
221
|
+
* const response = await php.request({ path: '/index.php' });
|
|
222
|
+
* console.log(response.text);
|
|
223
|
+
* // "Hi from PHP!"
|
|
224
|
+
* ```
|
|
225
|
+
*
|
|
226
|
+
* @example Explicitly create a PHPRequestHandler instance and run a PHP script:
|
|
227
|
+
* ```js
|
|
228
|
+
* import {
|
|
229
|
+
* loadPHPRuntime,
|
|
230
|
+
* PHP,
|
|
231
|
+
* PHPRequestHandler,
|
|
232
|
+
* getPHPLoaderModule,
|
|
233
|
+
* } from '@php-wasm/web';
|
|
234
|
+
*
|
|
235
|
+
* const runtime = await loadPHPRuntime( await getPHPLoaderModule('7.4') );
|
|
236
|
+
* const php = new PHP( runtime );
|
|
237
|
+
*
|
|
238
|
+
* php.mkdirTree('/www');
|
|
239
|
+
* php.writeFile('/www/index.php', '<?php echo "Hi from PHP!"; ');
|
|
240
|
+
*
|
|
241
|
+
* const server = new PHPRequestHandler(php, {
|
|
242
|
+
* // PHP FS path to serve the files from:
|
|
243
|
+
* documentRoot: '/www',
|
|
244
|
+
*
|
|
245
|
+
* // Used to populate $_SERVER['SERVER_NAME'] etc.:
|
|
246
|
+
* absoluteUrl: 'http://127.0.0.1'
|
|
247
|
+
* });
|
|
248
|
+
*
|
|
249
|
+
* const response = server.request({ path: '/index.php' });
|
|
250
|
+
* console.log(response.text);
|
|
251
|
+
* // "Hi from PHP!"
|
|
252
|
+
* ```
|
|
253
|
+
*/
|
|
254
|
+
export interface RequestHandler {
|
|
255
|
+
/**
|
|
256
|
+
* Serves the request – either by serving a static file, or by
|
|
257
|
+
* dispatching it to the PHP runtime.
|
|
258
|
+
*
|
|
259
|
+
* The request() method mode behaves like a web server and only works if
|
|
260
|
+
* the PHP was initialized with a `requestHandler` option (which the online version
|
|
261
|
+
* of WordPress Playground does by default).
|
|
262
|
+
*
|
|
263
|
+
* In the request mode, you pass an object containing the request information
|
|
264
|
+
* (method, headers, body, etc.) and the path to the PHP file to run:
|
|
265
|
+
*
|
|
266
|
+
* ```ts
|
|
267
|
+
* const php = PHP.load('7.4', {
|
|
268
|
+
* requestHandler: {
|
|
269
|
+
* documentRoot: "/www"
|
|
270
|
+
* }
|
|
271
|
+
* })
|
|
272
|
+
* php.writeFile("/www/index.php", `<?php echo file_get_contents("php://input");`);
|
|
273
|
+
* const result = await php.request({
|
|
274
|
+
* method: "GET",
|
|
275
|
+
* headers: {
|
|
276
|
+
* "Content-Type": "text/plain"
|
|
277
|
+
* },
|
|
278
|
+
* body: "Hello world!",
|
|
279
|
+
* path: "/www/index.php"
|
|
280
|
+
* });
|
|
281
|
+
* // result.text === "Hello world!"
|
|
282
|
+
* ```
|
|
283
|
+
*
|
|
284
|
+
* The `request()` method cannot be used in conjunction with `cli()`.
|
|
285
|
+
*
|
|
286
|
+
* @example
|
|
287
|
+
* ```js
|
|
288
|
+
* const output = await php.request({
|
|
289
|
+
* method: 'GET',
|
|
290
|
+
* url: '/index.php',
|
|
291
|
+
* headers: {
|
|
292
|
+
* 'X-foo': 'bar',
|
|
293
|
+
* },
|
|
294
|
+
* formData: {
|
|
295
|
+
* foo: 'bar',
|
|
296
|
+
* },
|
|
297
|
+
* });
|
|
298
|
+
* console.log(output.stdout); // "Hello world!"
|
|
299
|
+
* ```
|
|
300
|
+
*
|
|
301
|
+
* @param request - PHP Request data.
|
|
302
|
+
*/
|
|
303
|
+
request(request: PHPRequest, maxRedirects?: number): Promise<PHPResponse>;
|
|
304
|
+
/**
|
|
305
|
+
* Converts a path to an absolute URL based at the PHPRequestHandler
|
|
306
|
+
* root.
|
|
307
|
+
*
|
|
308
|
+
* @param path The server path to convert to an absolute URL.
|
|
309
|
+
* @returns The absolute URL.
|
|
310
|
+
*/
|
|
311
|
+
pathToInternalUrl(path: string): string;
|
|
312
|
+
/**
|
|
313
|
+
* Converts an absolute URL based at the PHPRequestHandler to a relative path
|
|
314
|
+
* without the server pathname and scope.
|
|
315
|
+
*
|
|
316
|
+
* @param internalUrl An absolute URL based at the PHPRequestHandler root.
|
|
317
|
+
* @returns The relative path.
|
|
318
|
+
*/
|
|
319
|
+
internalUrlToPath(internalUrl: string): string;
|
|
320
|
+
/**
|
|
321
|
+
* The absolute URL of this PHPRequestHandler instance.
|
|
322
|
+
*/
|
|
323
|
+
absoluteUrl: string;
|
|
324
|
+
/**
|
|
325
|
+
* The directory in the PHP filesystem where the server will look
|
|
326
|
+
* for the files to serve. Default: `/var/www`.
|
|
327
|
+
*/
|
|
328
|
+
documentRoot: string;
|
|
329
|
+
}
|
|
330
|
+
export interface IsomorphicLocalPHP extends RequestHandler {
|
|
331
|
+
/**
|
|
332
|
+
* Defines a constant in the PHP runtime.
|
|
333
|
+
* @param key - The name of the constant.
|
|
334
|
+
* @param value - The value of the constant.
|
|
335
|
+
*/
|
|
336
|
+
defineConstant(key: string, value: string | number | null): void;
|
|
337
|
+
/**
|
|
338
|
+
* Adds an event listener for a PHP event.
|
|
339
|
+
* @param eventType - The type of event to listen for.
|
|
340
|
+
* @param listener - The listener function to be called when the event is triggered.
|
|
341
|
+
*/
|
|
342
|
+
addEventListener(eventType: PHPEvent["type"], listener: PHPEventListener): void;
|
|
343
|
+
/**
|
|
344
|
+
* Removes an event listener for a PHP event.
|
|
345
|
+
* @param eventType - The type of event to remove the listener from.
|
|
346
|
+
* @param listener - The listener function to be removed.
|
|
347
|
+
*/
|
|
348
|
+
removeEventListener(eventType: PHPEvent["type"], listener: PHPEventListener): void;
|
|
349
|
+
/**
|
|
350
|
+
* Sets the path to the php.ini file to use for the PHP instance.
|
|
351
|
+
*
|
|
352
|
+
* @param path - The path to the php.ini file.
|
|
353
|
+
*/
|
|
354
|
+
setPhpIniPath(path: string): void;
|
|
355
|
+
/**
|
|
356
|
+
* Sets a value for a specific key in the php.ini file for the PHP instance.
|
|
357
|
+
*
|
|
358
|
+
* @param key - The key to set the value for.
|
|
359
|
+
* @param value - The value to set for the key.
|
|
360
|
+
*/
|
|
361
|
+
setPhpIniEntry(key: string, value: string): void;
|
|
362
|
+
/**
|
|
363
|
+
* Recursively creates a directory with the given path in the PHP filesystem.
|
|
364
|
+
* For example, if the path is `/root/php/data`, and `/root` already exists,
|
|
365
|
+
* it will create the directories `/root/php` and `/root/php/data`.
|
|
366
|
+
*
|
|
367
|
+
* @param path - The directory path to create.
|
|
368
|
+
*/
|
|
369
|
+
mkdir(path: string): void;
|
|
370
|
+
/**
|
|
371
|
+
* @deprecated Use mkdir instead.
|
|
372
|
+
*/
|
|
373
|
+
mkdirTree(path: string): void;
|
|
374
|
+
/**
|
|
375
|
+
* Reads a file from the PHP filesystem and returns it as a string.
|
|
376
|
+
*
|
|
377
|
+
* @throws {@link @php-wasm/universal:ErrnoError} – If the file doesn't exist.
|
|
378
|
+
* @param path - The file path to read.
|
|
379
|
+
* @returns The file contents.
|
|
380
|
+
*/
|
|
381
|
+
readFileAsText(path: string): string;
|
|
382
|
+
/**
|
|
383
|
+
* Reads a file from the PHP filesystem and returns it as an array buffer.
|
|
384
|
+
*
|
|
385
|
+
* @throws {@link @php-wasm/universal:ErrnoError} – If the file doesn't exist.
|
|
386
|
+
* @param path - The file path to read.
|
|
387
|
+
* @returns The file contents.
|
|
388
|
+
*/
|
|
389
|
+
readFileAsBuffer(path: string): Uint8Array;
|
|
390
|
+
/**
|
|
391
|
+
* Overwrites data in a file in the PHP filesystem.
|
|
392
|
+
* Creates a new file if one doesn't exist yet.
|
|
393
|
+
*
|
|
394
|
+
* @param path - The file path to write to.
|
|
395
|
+
* @param data - The data to write to the file.
|
|
396
|
+
*/
|
|
397
|
+
writeFile(path: string, data: string | Uint8Array): void;
|
|
398
|
+
/**
|
|
399
|
+
* Removes a file from the PHP filesystem.
|
|
400
|
+
*
|
|
401
|
+
* @throws {@link @php-wasm/universal:ErrnoError} – If the file doesn't exist.
|
|
402
|
+
* @param path - The file path to remove.
|
|
403
|
+
*/
|
|
404
|
+
unlink(path: string): void;
|
|
405
|
+
/**
|
|
406
|
+
* Moves a file or directory in the PHP filesystem to a
|
|
407
|
+
* new location.
|
|
408
|
+
*
|
|
409
|
+
* @param oldPath The path to rename.
|
|
410
|
+
* @param newPath The new path.
|
|
411
|
+
*/
|
|
412
|
+
mv(oldPath: string, newPath: string): void;
|
|
413
|
+
/**
|
|
414
|
+
* Removes a directory from the PHP filesystem.
|
|
415
|
+
*
|
|
416
|
+
* @param path The directory path to remove.
|
|
417
|
+
* @param options Options for the removal.
|
|
418
|
+
*/
|
|
419
|
+
rmdir(path: string, options?: RmDirOptions): void;
|
|
420
|
+
/**
|
|
421
|
+
* Lists the files and directories in the given directory.
|
|
422
|
+
*
|
|
423
|
+
* @param path - The directory path to list.
|
|
424
|
+
* @param options - Options for the listing.
|
|
425
|
+
* @returns The list of files and directories in the given directory.
|
|
426
|
+
*/
|
|
427
|
+
listFiles(path: string, options?: ListFilesOptions): string[];
|
|
428
|
+
/**
|
|
429
|
+
* Checks if a directory exists in the PHP filesystem.
|
|
430
|
+
*
|
|
431
|
+
* @param path – The path to check.
|
|
432
|
+
* @returns True if the path is a directory, false otherwise.
|
|
433
|
+
*/
|
|
434
|
+
isDir(path: string): boolean;
|
|
435
|
+
/**
|
|
436
|
+
* Checks if a file (or a directory) exists in the PHP filesystem.
|
|
437
|
+
*
|
|
438
|
+
* @param path - The file path to check.
|
|
439
|
+
* @returns True if the file exists, false otherwise.
|
|
440
|
+
*/
|
|
441
|
+
fileExists(path: string): boolean;
|
|
442
|
+
/**
|
|
443
|
+
* Changes the current working directory in the PHP filesystem.
|
|
444
|
+
* This is the directory that will be used as the base for relative paths.
|
|
445
|
+
* For example, if the current working directory is `/root/php`, and the
|
|
446
|
+
* path is `data`, the absolute path will be `/root/php/data`.
|
|
447
|
+
*
|
|
448
|
+
* @param path - The new working directory.
|
|
449
|
+
*/
|
|
450
|
+
chdir(path: string): void;
|
|
451
|
+
/**
|
|
452
|
+
* Runs PHP code.
|
|
453
|
+
*
|
|
454
|
+
* This low-level method directly interacts with the WebAssembly
|
|
455
|
+
* PHP interpreter.
|
|
456
|
+
*
|
|
457
|
+
* Every time you call run(), it prepares the PHP
|
|
458
|
+
* environment and:
|
|
459
|
+
*
|
|
460
|
+
* * Resets the internal PHP state
|
|
461
|
+
* * Populates superglobals ($_SERVER, $_GET, etc.)
|
|
462
|
+
* * Handles file uploads
|
|
463
|
+
* * Populates input streams (stdin, argv, etc.)
|
|
464
|
+
* * Sets the current working directory
|
|
465
|
+
*
|
|
466
|
+
* You can use run() in two primary modes:
|
|
467
|
+
*
|
|
468
|
+
* ### Code snippet mode
|
|
469
|
+
*
|
|
470
|
+
* In this mode, you pass a string containing PHP code to run.
|
|
471
|
+
*
|
|
472
|
+
* ```ts
|
|
473
|
+
* const result = await php.run({
|
|
474
|
+
* code: `<?php echo "Hello world!";`
|
|
475
|
+
* });
|
|
476
|
+
* // result.text === "Hello world!"
|
|
477
|
+
* ```
|
|
478
|
+
*
|
|
479
|
+
* In this mode, information like __DIR__ or __FILE__ isn't very
|
|
480
|
+
* useful because the code is not associated with any file.
|
|
481
|
+
*
|
|
482
|
+
* Under the hood, the PHP snippet is passed to the `zend_eval_string`
|
|
483
|
+
* C function.
|
|
484
|
+
*
|
|
485
|
+
* ### File mode
|
|
486
|
+
*
|
|
487
|
+
* In the file mode, you pass a scriptPath and PHP executes a file
|
|
488
|
+
* found at a that path:
|
|
489
|
+
*
|
|
490
|
+
* ```ts
|
|
491
|
+
* php.writeFile(
|
|
492
|
+
* "/www/index.php",
|
|
493
|
+
* `<?php echo "Hello world!";"`
|
|
494
|
+
* );
|
|
495
|
+
* const result = await php.run({
|
|
496
|
+
* scriptPath: "/www/index.php"
|
|
497
|
+
* });
|
|
498
|
+
* // result.text === "Hello world!"
|
|
499
|
+
* ```
|
|
500
|
+
*
|
|
501
|
+
* In this mode, you can rely on path-related information like __DIR__
|
|
502
|
+
* or __FILE__.
|
|
503
|
+
*
|
|
504
|
+
* Under the hood, the PHP file is executed with the `php_execute_script`
|
|
505
|
+
* C function.
|
|
506
|
+
*
|
|
507
|
+
* The `run()` method cannot be used in conjunction with `cli()`.
|
|
508
|
+
*
|
|
509
|
+
* @example
|
|
510
|
+
* ```js
|
|
511
|
+
* const result = await php.run(`<?php
|
|
512
|
+
* $fp = fopen('php://stderr', 'w');
|
|
513
|
+
* fwrite($fp, "Hello, world!");
|
|
514
|
+
* `);
|
|
515
|
+
* // result.errors === "Hello, world!"
|
|
516
|
+
* ```
|
|
517
|
+
*
|
|
518
|
+
* @param options - PHP runtime options.
|
|
519
|
+
*/
|
|
520
|
+
run(options: PHPRunOptions): Promise<PHPResponse>;
|
|
521
|
+
/**
|
|
522
|
+
* Listens to message sent by the PHP code.
|
|
523
|
+
*
|
|
524
|
+
* To dispatch messages, call:
|
|
525
|
+
*
|
|
526
|
+
* post_message_to_js(string $data)
|
|
527
|
+
*
|
|
528
|
+
* Arguments:
|
|
529
|
+
* $data (string) – Data to pass to JavaScript.
|
|
530
|
+
*
|
|
531
|
+
* @example
|
|
532
|
+
*
|
|
533
|
+
* ```ts
|
|
534
|
+
* const php = await PHP.load('8.0');
|
|
535
|
+
*
|
|
536
|
+
* php.onMessage(
|
|
537
|
+
* // The data is always passed as a string
|
|
538
|
+
* function (data: string) {
|
|
539
|
+
* // Let's decode and log the data:
|
|
540
|
+
* console.log(JSON.parse(data));
|
|
541
|
+
* }
|
|
542
|
+
* );
|
|
543
|
+
*
|
|
544
|
+
* // Now that we have a listener in place, let's
|
|
545
|
+
* // dispatch a message:
|
|
546
|
+
* await php.run({
|
|
547
|
+
* code: `<?php
|
|
548
|
+
* post_message_to_js(
|
|
549
|
+
* json_encode([
|
|
550
|
+
* 'post_id' => '15',
|
|
551
|
+
* 'post_title' => 'This is a blog post!'
|
|
552
|
+
* ])
|
|
553
|
+
* ));
|
|
554
|
+
* `,
|
|
555
|
+
* });
|
|
556
|
+
* ```
|
|
557
|
+
*
|
|
558
|
+
* @param listener Callback function to handle the message.
|
|
559
|
+
*/
|
|
560
|
+
onMessage(listener: MessageListener): void;
|
|
561
|
+
/**
|
|
562
|
+
* Registers a handler to spawns a child process when
|
|
563
|
+
* `proc_open()`, `popen()`, `exec()`, `system()`, or `passthru()`
|
|
564
|
+
* is called.
|
|
565
|
+
*
|
|
566
|
+
* @param handler Callback function to spawn a process.
|
|
567
|
+
*/
|
|
568
|
+
setSpawnHandler(handler: SpawnHandler): void;
|
|
569
|
+
}
|
|
570
|
+
export type MessageListener = (data: string) => Promise<string | Uint8Array | void> | string | void;
|
|
571
|
+
export interface EventEmitter {
|
|
572
|
+
on(event: string, listener: (...args: any[]) => void): this;
|
|
573
|
+
emit(event: string, ...args: any[]): boolean;
|
|
574
|
+
}
|
|
575
|
+
export type ChildProcess = EventEmitter & {
|
|
576
|
+
stdout: EventEmitter;
|
|
577
|
+
stderr: EventEmitter;
|
|
578
|
+
};
|
|
579
|
+
export type SpawnHandler = (command: string) => ChildProcess;
|
|
580
|
+
export type IsomorphicRemotePHP = Remote<IsomorphicLocalPHP>;
|
|
581
|
+
export type UniversalPHP = IsomorphicLocalPHP | IsomorphicRemotePHP;
|
|
582
|
+
export type HTTPMethod = "GET" | "POST" | "HEAD" | "OPTIONS" | "PATCH" | "PUT" | "DELETE";
|
|
583
|
+
export type PHPRequestHeaders = Record<string, string>;
|
|
584
|
+
export interface PHPRequest {
|
|
585
|
+
/**
|
|
586
|
+
* Request method. Default: `GET`.
|
|
587
|
+
*/
|
|
588
|
+
method?: HTTPMethod;
|
|
589
|
+
/**
|
|
590
|
+
* Request path or absolute URL.
|
|
591
|
+
*/
|
|
592
|
+
url: string;
|
|
593
|
+
/**
|
|
594
|
+
* Request headers.
|
|
595
|
+
*/
|
|
596
|
+
headers?: PHPRequestHeaders;
|
|
597
|
+
/**
|
|
598
|
+
* Uploaded files
|
|
599
|
+
*/
|
|
600
|
+
files?: Record<string, File>;
|
|
601
|
+
/**
|
|
602
|
+
* Request body without the files.
|
|
603
|
+
*/
|
|
604
|
+
body?: string;
|
|
605
|
+
/**
|
|
606
|
+
* Form data. If set, the request body will be ignored and
|
|
607
|
+
* the content-type header will be set to `application/x-www-form-urlencoded`.
|
|
608
|
+
*/
|
|
609
|
+
formData?: Record<string, unknown>;
|
|
610
|
+
}
|
|
611
|
+
export interface PHPRunOptions {
|
|
612
|
+
/**
|
|
613
|
+
* Request path following the domain:port part.
|
|
614
|
+
*/
|
|
615
|
+
relativeUri?: string;
|
|
616
|
+
/**
|
|
617
|
+
* Path of the .php file to execute.
|
|
618
|
+
*/
|
|
619
|
+
scriptPath?: string;
|
|
620
|
+
/**
|
|
621
|
+
* Request protocol.
|
|
622
|
+
*/
|
|
623
|
+
protocol?: string;
|
|
624
|
+
/**
|
|
625
|
+
* Request method. Default: `GET`.
|
|
626
|
+
*/
|
|
627
|
+
method?: HTTPMethod;
|
|
628
|
+
/**
|
|
629
|
+
* Request headers.
|
|
630
|
+
*/
|
|
631
|
+
headers?: PHPRequestHeaders;
|
|
632
|
+
/**
|
|
633
|
+
* Request body without the files.
|
|
634
|
+
*/
|
|
635
|
+
body?: string;
|
|
636
|
+
/**
|
|
637
|
+
* Uploaded files.
|
|
638
|
+
*/
|
|
639
|
+
fileInfos?: FileInfo[];
|
|
640
|
+
/**
|
|
641
|
+
* The code snippet to eval instead of a php file.
|
|
642
|
+
*/
|
|
643
|
+
code?: string;
|
|
644
|
+
}
|
|
645
|
+
export interface FileInfo {
|
|
646
|
+
key: string;
|
|
647
|
+
name: string;
|
|
648
|
+
type: string;
|
|
649
|
+
data: Uint8Array;
|
|
650
|
+
}
|
|
651
|
+
export interface RmDirOptions {
|
|
652
|
+
/**
|
|
653
|
+
* If true, recursively removes the directory and all its contents.
|
|
654
|
+
* Default: true.
|
|
655
|
+
*/
|
|
656
|
+
recursive?: boolean;
|
|
657
|
+
}
|
|
658
|
+
export interface ListFilesOptions {
|
|
659
|
+
/**
|
|
660
|
+
* If true, prepend given folder path to all file names.
|
|
661
|
+
* Default: false.
|
|
662
|
+
*/
|
|
663
|
+
prependPath: boolean;
|
|
664
|
+
}
|
|
665
|
+
declare const SupportedPHPVersions: readonly [
|
|
666
|
+
"8.3",
|
|
667
|
+
"8.2",
|
|
668
|
+
"8.1",
|
|
669
|
+
"8.0",
|
|
670
|
+
"7.4",
|
|
671
|
+
"7.3",
|
|
672
|
+
"7.2",
|
|
673
|
+
"7.1",
|
|
674
|
+
"7.0"
|
|
675
|
+
];
|
|
676
|
+
export type SupportedPHPVersion = (typeof SupportedPHPVersions)[number];
|
|
677
|
+
export type SupportedPHPExtension = "iconv" | "mbstring" | "xml-bundle" | "gd";
|
|
678
|
+
export type SupportedPHPExtensionBundle = "kitchen-sink";
|
|
679
|
+
export interface SemaphoreOptions {
|
|
680
|
+
concurrency: number;
|
|
681
|
+
}
|
|
682
|
+
declare class Semaphore {
|
|
683
|
+
private _running;
|
|
684
|
+
private concurrency;
|
|
685
|
+
private queue;
|
|
686
|
+
constructor({ concurrency }: SemaphoreOptions);
|
|
687
|
+
get running(): number;
|
|
688
|
+
acquire(): Promise<() => void>;
|
|
689
|
+
run<T>(fn: () => Promise<T>): Promise<T>;
|
|
690
|
+
}
|
|
691
|
+
export declare const ResourceTypes: readonly [
|
|
692
|
+
"vfs",
|
|
693
|
+
"literal",
|
|
694
|
+
"wordpress.org/themes",
|
|
695
|
+
"wordpress.org/plugins",
|
|
696
|
+
"url"
|
|
697
|
+
];
|
|
698
|
+
export type VFSReference = {
|
|
699
|
+
/** Identifies the file resource as Virtual File System (VFS) */
|
|
700
|
+
resource: "vfs";
|
|
701
|
+
/** The path to the file in the VFS */
|
|
702
|
+
path: string;
|
|
703
|
+
};
|
|
704
|
+
export type LiteralReference = {
|
|
705
|
+
/** Identifies the file resource as a literal file */
|
|
706
|
+
resource: "literal";
|
|
707
|
+
/** The name of the file */
|
|
708
|
+
name: string;
|
|
709
|
+
/** The contents of the file */
|
|
710
|
+
contents: string | Uint8Array;
|
|
711
|
+
};
|
|
712
|
+
export type CoreThemeReference = {
|
|
713
|
+
/** Identifies the file resource as a WordPress Core theme */
|
|
714
|
+
resource: "wordpress.org/themes";
|
|
715
|
+
/** The slug of the WordPress Core theme */
|
|
716
|
+
slug: string;
|
|
717
|
+
};
|
|
718
|
+
export type CorePluginReference = {
|
|
719
|
+
/** Identifies the file resource as a WordPress Core plugin */
|
|
720
|
+
resource: "wordpress.org/plugins";
|
|
721
|
+
/** The slug of the WordPress Core plugin */
|
|
722
|
+
slug: string;
|
|
723
|
+
};
|
|
724
|
+
export type UrlReference = {
|
|
725
|
+
/** Identifies the file resource as a URL */
|
|
726
|
+
resource: "url";
|
|
727
|
+
/** The URL of the file */
|
|
728
|
+
url: string;
|
|
729
|
+
/** Optional caption for displaying a progress message */
|
|
730
|
+
caption?: string;
|
|
731
|
+
};
|
|
732
|
+
export type FileReference = VFSReference | LiteralReference | CoreThemeReference | CorePluginReference | UrlReference;
|
|
733
|
+
export interface ResourceOptions {
|
|
734
|
+
/** Optional semaphore to limit concurrent downloads */
|
|
735
|
+
semaphore?: Semaphore;
|
|
736
|
+
progress?: ProgressTracker;
|
|
737
|
+
}
|
|
738
|
+
export declare abstract class Resource {
|
|
739
|
+
/** Optional progress tracker to monitor progress */
|
|
740
|
+
abstract progress?: ProgressTracker;
|
|
741
|
+
/** A Promise that resolves to the file contents */
|
|
742
|
+
protected promise?: Promise<File>;
|
|
743
|
+
protected playground?: UniversalPHP;
|
|
744
|
+
/**
|
|
745
|
+
* Creates a new Resource based on the given file reference
|
|
746
|
+
*
|
|
747
|
+
* @param ref The file reference to create the Resource for
|
|
748
|
+
* @param options Additional options for the Resource
|
|
749
|
+
* @returns A new Resource instance
|
|
750
|
+
*/
|
|
751
|
+
static create(ref: FileReference, { semaphore, progress }: ResourceOptions): Resource;
|
|
752
|
+
setPlayground(playground: UniversalPHP): void;
|
|
753
|
+
/**
|
|
754
|
+
* Resolves the file contents
|
|
755
|
+
* @returns The resolved file.
|
|
756
|
+
*/
|
|
757
|
+
abstract resolve(): Promise<File>;
|
|
758
|
+
/** The name of the referenced file */
|
|
759
|
+
abstract get name(): string;
|
|
760
|
+
/** Whether this Resource is loaded asynchronously */
|
|
761
|
+
get isAsync(): boolean;
|
|
762
|
+
}
|
|
763
|
+
/**
|
|
764
|
+
* A `Resource` that represents a file in the VFS (virtual file system) of the playground.
|
|
765
|
+
*/
|
|
766
|
+
export declare class VFSResource extends Resource {
|
|
767
|
+
private resource;
|
|
768
|
+
progress?: ProgressTracker | undefined;
|
|
769
|
+
/**
|
|
770
|
+
* Creates a new instance of `VFSResource`.
|
|
771
|
+
* @param playground The playground client.
|
|
772
|
+
* @param resource The VFS reference.
|
|
773
|
+
* @param progress The progress tracker.
|
|
774
|
+
*/
|
|
775
|
+
constructor(resource: VFSReference, progress?: ProgressTracker | undefined);
|
|
776
|
+
/** @inheritDoc */
|
|
777
|
+
resolve(): Promise<File>;
|
|
778
|
+
/** @inheritDoc */
|
|
779
|
+
get name(): string;
|
|
780
|
+
}
|
|
781
|
+
/**
|
|
782
|
+
* A `Resource` that represents a literal file.
|
|
783
|
+
*/
|
|
784
|
+
export declare class LiteralResource extends Resource {
|
|
785
|
+
private resource;
|
|
786
|
+
progress?: ProgressTracker | undefined;
|
|
787
|
+
/**
|
|
788
|
+
* Creates a new instance of `LiteralResource`.
|
|
789
|
+
* @param resource The literal reference.
|
|
790
|
+
* @param progress The progress tracker.
|
|
791
|
+
*/
|
|
792
|
+
constructor(resource: LiteralReference, progress?: ProgressTracker | undefined);
|
|
793
|
+
/** @inheritDoc */
|
|
794
|
+
resolve(): Promise<File>;
|
|
795
|
+
/** @inheritDoc */
|
|
796
|
+
get name(): string;
|
|
797
|
+
}
|
|
798
|
+
/**
|
|
799
|
+
* A base class for `Resource`s that require fetching data from a remote URL.
|
|
800
|
+
*/
|
|
801
|
+
export declare abstract class FetchResource extends Resource {
|
|
802
|
+
progress?: ProgressTracker | undefined;
|
|
803
|
+
/**
|
|
804
|
+
* Creates a new instance of `FetchResource`.
|
|
805
|
+
* @param progress The progress tracker.
|
|
806
|
+
*/
|
|
807
|
+
constructor(progress?: ProgressTracker | undefined);
|
|
808
|
+
/** @inheritDoc */
|
|
809
|
+
resolve(): Promise<File>;
|
|
810
|
+
/**
|
|
811
|
+
* Gets the URL to fetch the data from.
|
|
812
|
+
* @returns The URL.
|
|
813
|
+
*/
|
|
814
|
+
protected abstract getURL(): string;
|
|
815
|
+
/**
|
|
816
|
+
* Gets the caption for the progress tracker.
|
|
817
|
+
* @returns The caption.
|
|
818
|
+
*/
|
|
819
|
+
protected get caption(): string;
|
|
820
|
+
/** @inheritDoc */
|
|
821
|
+
get name(): string;
|
|
822
|
+
/** @inheritDoc */
|
|
823
|
+
get isAsync(): boolean;
|
|
824
|
+
}
|
|
825
|
+
/**
|
|
826
|
+
* A `Resource` that represents a file available from a URL.
|
|
827
|
+
*/
|
|
828
|
+
export declare class UrlResource extends FetchResource {
|
|
829
|
+
private resource;
|
|
830
|
+
/**
|
|
831
|
+
* Creates a new instance of `UrlResource`.
|
|
832
|
+
* @param resource The URL reference.
|
|
833
|
+
* @param progress The progress tracker.
|
|
834
|
+
*/
|
|
835
|
+
constructor(resource: UrlReference, progress?: ProgressTracker);
|
|
836
|
+
/** @inheritDoc */
|
|
837
|
+
getURL(): string;
|
|
838
|
+
/** @inheritDoc */
|
|
839
|
+
protected get caption(): string;
|
|
840
|
+
}
|
|
841
|
+
/**
|
|
842
|
+
* A `Resource` that represents a WordPress core theme.
|
|
843
|
+
*/
|
|
844
|
+
export declare class CoreThemeResource extends FetchResource {
|
|
845
|
+
private resource;
|
|
846
|
+
constructor(resource: CoreThemeReference, progress?: ProgressTracker);
|
|
847
|
+
get name(): string;
|
|
848
|
+
getURL(): string;
|
|
849
|
+
}
|
|
850
|
+
/**
|
|
851
|
+
* A resource that fetches a WordPress plugin from wordpress.org.
|
|
852
|
+
*/
|
|
853
|
+
export declare class CorePluginResource extends FetchResource {
|
|
854
|
+
private resource;
|
|
855
|
+
constructor(resource: CorePluginReference, progress?: ProgressTracker);
|
|
856
|
+
/** @inheritDoc */
|
|
857
|
+
get name(): string;
|
|
858
|
+
/** @inheritDoc */
|
|
859
|
+
getURL(): string;
|
|
860
|
+
}
|
|
861
|
+
/**
|
|
862
|
+
* A decorator for a resource that adds functionality such as progress tracking and caching.
|
|
863
|
+
*/
|
|
864
|
+
export declare class DecoratedResource<T extends Resource> extends Resource {
|
|
865
|
+
private resource;
|
|
866
|
+
constructor(resource: T);
|
|
867
|
+
/** @inheritDoc */
|
|
868
|
+
resolve(): Promise<File>;
|
|
869
|
+
/** @inheritDoc */
|
|
870
|
+
setPlayground(playground: UniversalPHP): Promise<void>;
|
|
871
|
+
/** @inheritDoc */
|
|
872
|
+
get progress(): ProgressTracker | undefined;
|
|
873
|
+
/** @inheritDoc */
|
|
874
|
+
set progress(value: ProgressTracker | undefined);
|
|
875
|
+
/** @inheritDoc */
|
|
876
|
+
get name(): string;
|
|
877
|
+
/** @inheritDoc */
|
|
878
|
+
get isAsync(): boolean;
|
|
879
|
+
}
|
|
880
|
+
/**
|
|
881
|
+
* A decorator for a resource that adds caching functionality.
|
|
882
|
+
*/
|
|
883
|
+
export declare class CachedResource<T extends Resource> extends DecoratedResource<T> {
|
|
884
|
+
protected promise?: Promise<File>;
|
|
885
|
+
/** @inheritDoc */
|
|
886
|
+
resolve(): Promise<File>;
|
|
887
|
+
}
|
|
888
|
+
/**
|
|
889
|
+
* A decorator for a resource that adds concurrency control functionality through a semaphore.
|
|
890
|
+
*/
|
|
891
|
+
export declare class SemaphoreResource<T extends Resource> extends DecoratedResource<T> {
|
|
892
|
+
private readonly semaphore;
|
|
893
|
+
constructor(resource: T, semaphore: Semaphore);
|
|
894
|
+
/** @inheritDoc */
|
|
895
|
+
resolve(): Promise<File>;
|
|
896
|
+
}
|
|
897
|
+
/**
|
|
898
|
+
* @inheritDoc activatePlugin
|
|
899
|
+
* @example
|
|
900
|
+
*
|
|
901
|
+
* <code>
|
|
902
|
+
* {
|
|
903
|
+
* "step": "activatePlugin",
|
|
904
|
+
* "pluginName": "Gutenberg",
|
|
905
|
+
* "pluginPath": "/wordpress/wp-content/plugins/gutenberg"
|
|
906
|
+
* }
|
|
907
|
+
* </code>
|
|
908
|
+
*/
|
|
909
|
+
export interface ActivatePluginStep {
|
|
910
|
+
step: "activatePlugin";
|
|
911
|
+
/** 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). */
|
|
912
|
+
pluginPath: string;
|
|
913
|
+
/** Optional. Plugin name to display in the progress bar. */
|
|
914
|
+
pluginName?: string;
|
|
915
|
+
}
|
|
916
|
+
/**
|
|
917
|
+
* Activates a WordPress plugin (if it's installed).
|
|
918
|
+
*
|
|
919
|
+
* @param playground The playground client.
|
|
920
|
+
*/
|
|
921
|
+
export declare const activatePlugin: StepHandler<ActivatePluginStep>;
|
|
922
|
+
/**
|
|
923
|
+
* @private
|
|
924
|
+
*/
|
|
925
|
+
export interface ApplyWordPressPatchesStep {
|
|
926
|
+
step: "applyWordPressPatches";
|
|
927
|
+
siteUrl?: string;
|
|
928
|
+
wordpressPath?: string;
|
|
929
|
+
addPhpInfo?: boolean;
|
|
930
|
+
patchSecrets?: boolean;
|
|
931
|
+
disableSiteHealth?: boolean;
|
|
932
|
+
disableWpNewBlogNotification?: boolean;
|
|
933
|
+
makeEditorFrameControlled?: boolean;
|
|
934
|
+
prepareForRunningInsideWebBrowser?: boolean;
|
|
935
|
+
addFetchNetworkTransport?: boolean;
|
|
936
|
+
}
|
|
937
|
+
export declare const applyWordPressPatches: StepHandler<ApplyWordPressPatchesStep>;
|
|
938
|
+
/**
|
|
939
|
+
* @inheritDoc defineSiteUrl
|
|
940
|
+
* @hasRunnableExample
|
|
941
|
+
* @example
|
|
942
|
+
*
|
|
943
|
+
* <code>
|
|
944
|
+
* {
|
|
945
|
+
* "step": "defineSiteUrl",
|
|
946
|
+
* "siteUrl": "https://playground.wordpress.net"
|
|
947
|
+
* }
|
|
948
|
+
* </code>
|
|
949
|
+
*/
|
|
950
|
+
export interface DefineSiteUrlStep {
|
|
951
|
+
step: "defineSiteUrl";
|
|
952
|
+
/** The URL */
|
|
953
|
+
siteUrl: string;
|
|
954
|
+
}
|
|
955
|
+
/**
|
|
956
|
+
* Sets WP_HOME and WP_SITEURL constants for the WordPress installation.
|
|
957
|
+
*
|
|
958
|
+
* @param playground The playground client.
|
|
959
|
+
* @param siteUrl
|
|
960
|
+
*/
|
|
961
|
+
export declare const defineSiteUrl: StepHandler<DefineSiteUrlStep>;
|
|
962
|
+
/**
|
|
963
|
+
* @inheritDoc installPlugin
|
|
964
|
+
* @hasRunnableExample
|
|
965
|
+
* @needsLogin
|
|
966
|
+
* @landingPage /wp-admin/plugins.php
|
|
967
|
+
* @example
|
|
968
|
+
*
|
|
969
|
+
* <code>
|
|
970
|
+
* {
|
|
971
|
+
* "step": "installPlugin",
|
|
972
|
+
* "pluginZipFile": {
|
|
973
|
+
* "resource": "wordpress.org/plugins",
|
|
974
|
+
* "slug": "gutenberg"
|
|
975
|
+
* },
|
|
976
|
+
* "options": {
|
|
977
|
+
* "activate": true
|
|
978
|
+
* }
|
|
979
|
+
* }
|
|
980
|
+
* </code>
|
|
981
|
+
*/
|
|
982
|
+
export interface InstallPluginStep<ResourceType> {
|
|
983
|
+
/**
|
|
984
|
+
* The step identifier.
|
|
985
|
+
*/
|
|
986
|
+
step: "installPlugin";
|
|
987
|
+
/**
|
|
988
|
+
* The plugin zip file to install.
|
|
989
|
+
*/
|
|
990
|
+
pluginZipFile: ResourceType;
|
|
991
|
+
/**
|
|
992
|
+
* Optional installation options.
|
|
993
|
+
*/
|
|
994
|
+
options?: InstallPluginOptions;
|
|
995
|
+
}
|
|
996
|
+
export interface InstallPluginOptions {
|
|
997
|
+
/**
|
|
998
|
+
* Whether to activate the plugin after installing it.
|
|
999
|
+
*/
|
|
1000
|
+
activate?: boolean;
|
|
1001
|
+
}
|
|
1002
|
+
/**
|
|
1003
|
+
* Installs a WordPress plugin in the Playground.
|
|
1004
|
+
*
|
|
1005
|
+
* @param playground The playground client.
|
|
1006
|
+
* @param pluginZipFile The plugin zip file.
|
|
1007
|
+
* @param options Optional. Set `activate` to false if you don't want to activate the plugin.
|
|
1008
|
+
*/
|
|
1009
|
+
export declare const installPlugin: StepHandler<InstallPluginStep<File>>;
|
|
1010
|
+
/**
|
|
1011
|
+
* @inheritDoc installTheme
|
|
1012
|
+
* @hasRunnableExample
|
|
1013
|
+
* @needsLogin
|
|
1014
|
+
* @example
|
|
1015
|
+
*
|
|
1016
|
+
* <code>
|
|
1017
|
+
* {
|
|
1018
|
+
* "step": "installTheme",
|
|
1019
|
+
* "themeZipFile": {
|
|
1020
|
+
* "resource": "wordpress.org/themes",
|
|
1021
|
+
* "slug": "pendant"
|
|
1022
|
+
* },
|
|
1023
|
+
* "options": {
|
|
1024
|
+
* "activate": true
|
|
1025
|
+
* }
|
|
1026
|
+
* }
|
|
1027
|
+
* </code>
|
|
1028
|
+
*/
|
|
1029
|
+
export interface InstallThemeStep<ResourceType> {
|
|
1030
|
+
/**
|
|
1031
|
+
* The step identifier.
|
|
1032
|
+
*/
|
|
1033
|
+
step: "installTheme";
|
|
1034
|
+
/**
|
|
1035
|
+
* The theme zip file to install.
|
|
1036
|
+
*/
|
|
1037
|
+
themeZipFile: ResourceType;
|
|
1038
|
+
/**
|
|
1039
|
+
* Optional installation options.
|
|
1040
|
+
*/
|
|
1041
|
+
options?: {
|
|
1042
|
+
/**
|
|
1043
|
+
* Whether to activate the theme after installing it.
|
|
1044
|
+
*/
|
|
1045
|
+
activate?: boolean;
|
|
1046
|
+
};
|
|
1047
|
+
}
|
|
1048
|
+
export interface InstallThemeOptions {
|
|
1049
|
+
/**
|
|
1050
|
+
* Whether to activate the theme after installing it.
|
|
1051
|
+
*/
|
|
1052
|
+
activate?: boolean;
|
|
1053
|
+
}
|
|
1054
|
+
/**
|
|
1055
|
+
* Installs a WordPress theme in the Playground.
|
|
1056
|
+
*
|
|
1057
|
+
* @param playground The playground client.
|
|
1058
|
+
* @param themeZipFile The theme zip file.
|
|
1059
|
+
* @param options Optional. Set `activate` to false if you don't want to activate the theme.
|
|
1060
|
+
*/
|
|
1061
|
+
export declare const installTheme: StepHandler<InstallThemeStep<File>>;
|
|
1062
|
+
/**
|
|
1063
|
+
* @inheritDoc login
|
|
1064
|
+
* @hasRunnableExample
|
|
1065
|
+
* @example
|
|
1066
|
+
*
|
|
1067
|
+
* <code>
|
|
1068
|
+
* {
|
|
1069
|
+
* "step": "login",
|
|
1070
|
+
* "username": "admin",
|
|
1071
|
+
* "password": "password"
|
|
1072
|
+
* }
|
|
1073
|
+
* </code>
|
|
1074
|
+
*/
|
|
1075
|
+
export type LoginStep = {
|
|
1076
|
+
step: "login";
|
|
1077
|
+
/**
|
|
1078
|
+
* The user to log in as. Defaults to 'admin'.
|
|
1079
|
+
*/
|
|
1080
|
+
username?: string;
|
|
1081
|
+
/**
|
|
1082
|
+
* The password to log in with. Defaults to 'password'.
|
|
1083
|
+
*/
|
|
1084
|
+
password?: string;
|
|
1085
|
+
};
|
|
1086
|
+
/**
|
|
1087
|
+
* Logs in to the Playground.
|
|
1088
|
+
* Under the hood, this function submits the wp-login.php form
|
|
1089
|
+
* just like a user would.
|
|
1090
|
+
*/
|
|
1091
|
+
export declare const login: StepHandler<LoginStep>;
|
|
1092
|
+
/**
|
|
1093
|
+
* @private
|
|
1094
|
+
*/
|
|
1095
|
+
export interface RunWpInstallationWizardStep {
|
|
1096
|
+
step: "runWpInstallationWizard";
|
|
1097
|
+
options: WordPressInstallationOptions;
|
|
1098
|
+
}
|
|
1099
|
+
export interface WordPressInstallationOptions {
|
|
1100
|
+
adminUsername?: string;
|
|
1101
|
+
adminPassword?: string;
|
|
1102
|
+
}
|
|
1103
|
+
/**
|
|
1104
|
+
* Installs WordPress
|
|
1105
|
+
*
|
|
1106
|
+
* @param playground The playground client.
|
|
1107
|
+
* @param options Installation options.
|
|
1108
|
+
*/
|
|
1109
|
+
export declare const runWpInstallationWizard: StepHandler<RunWpInstallationWizardStep>;
|
|
1110
|
+
/**
|
|
1111
|
+
* @inheritDoc setSiteOptions
|
|
1112
|
+
* @hasRunnableExample
|
|
1113
|
+
*
|
|
1114
|
+
* @example
|
|
1115
|
+
*
|
|
1116
|
+
* <code>
|
|
1117
|
+
* {
|
|
1118
|
+
* "step": "setSiteOptions",
|
|
1119
|
+
* "options": {
|
|
1120
|
+
* "blogname": "My Blog",
|
|
1121
|
+
* "blogdescription": "A great blog"
|
|
1122
|
+
* }
|
|
1123
|
+
* }
|
|
1124
|
+
* </code>
|
|
1125
|
+
*/
|
|
1126
|
+
export type SetSiteOptionsStep = {
|
|
1127
|
+
/** The name of the step. Must be "setSiteOptions". */
|
|
1128
|
+
step: "setSiteOptions";
|
|
1129
|
+
/** The options to set on the site. */
|
|
1130
|
+
options: Record<string, unknown>;
|
|
1131
|
+
};
|
|
1132
|
+
/**
|
|
1133
|
+
* Sets site options. This is equivalent to calling `update_option` for each
|
|
1134
|
+
* option in the `options` object.
|
|
1135
|
+
*/
|
|
1136
|
+
export declare const setSiteOptions: StepHandler<SetSiteOptionsStep>;
|
|
1137
|
+
/**
|
|
1138
|
+
* @inheritDoc updateUserMeta
|
|
1139
|
+
* @hasRunnableExample
|
|
1140
|
+
*
|
|
1141
|
+
* @example
|
|
1142
|
+
*
|
|
1143
|
+
* <code>
|
|
1144
|
+
* {
|
|
1145
|
+
* "step": "updateUserMeta",
|
|
1146
|
+
* "meta": {
|
|
1147
|
+
* "first_name": "John",
|
|
1148
|
+
* "last_name": "Doe"
|
|
1149
|
+
* },
|
|
1150
|
+
* "userId": 1
|
|
1151
|
+
* }
|
|
1152
|
+
* </code>
|
|
1153
|
+
*/
|
|
1154
|
+
export interface UpdateUserMetaStep {
|
|
1155
|
+
step: "updateUserMeta";
|
|
1156
|
+
/** An object of user meta values to set, e.g. { "first_name": "John" } */
|
|
1157
|
+
meta: Record<string, unknown>;
|
|
1158
|
+
/** User ID */
|
|
1159
|
+
userId: number;
|
|
1160
|
+
}
|
|
1161
|
+
/**
|
|
1162
|
+
* Updates user meta. This is equivalent to calling `update_user_meta` for each
|
|
1163
|
+
* meta value in the `meta` object.
|
|
1164
|
+
*/
|
|
1165
|
+
export declare const updateUserMeta: StepHandler<UpdateUserMetaStep>;
|
|
1166
|
+
/**
|
|
1167
|
+
* @inheritDoc rm
|
|
1168
|
+
* @hasRunnableExample
|
|
1169
|
+
* @landingPage /index.php
|
|
1170
|
+
* @example
|
|
1171
|
+
*
|
|
1172
|
+
* <code>
|
|
1173
|
+
* {
|
|
1174
|
+
* "step": "rm",
|
|
1175
|
+
* "path": "/wordpress/index.php"
|
|
1176
|
+
* }
|
|
1177
|
+
* </code>
|
|
1178
|
+
*/
|
|
1179
|
+
export interface RmStep {
|
|
1180
|
+
step: "rm";
|
|
1181
|
+
/** The path to remove */
|
|
1182
|
+
path: string;
|
|
1183
|
+
}
|
|
1184
|
+
/**
|
|
1185
|
+
* Removes a file at the specified path.
|
|
1186
|
+
*/
|
|
1187
|
+
export declare const rm: StepHandler<RmStep>;
|
|
1188
|
+
/**
|
|
1189
|
+
* @inheritDoc cp
|
|
1190
|
+
* @hasRunnableExample
|
|
1191
|
+
* @landingPage /index2.php
|
|
1192
|
+
* @example
|
|
1193
|
+
*
|
|
1194
|
+
* <code>
|
|
1195
|
+
* {
|
|
1196
|
+
* "step": "cp",
|
|
1197
|
+
* "fromPath": "/wordpress/index.php",
|
|
1198
|
+
* "toPath": "/wordpress/index2.php"
|
|
1199
|
+
* }
|
|
1200
|
+
* </code>
|
|
1201
|
+
*/
|
|
1202
|
+
export interface CpStep {
|
|
1203
|
+
step: "cp";
|
|
1204
|
+
/** Source path */
|
|
1205
|
+
fromPath: string;
|
|
1206
|
+
/** Target path */
|
|
1207
|
+
toPath: string;
|
|
1208
|
+
}
|
|
1209
|
+
/**
|
|
1210
|
+
* Copies a file from one path to another.
|
|
1211
|
+
*/
|
|
1212
|
+
export declare const cp: StepHandler<CpStep>;
|
|
1213
|
+
/**
|
|
1214
|
+
* @inheritDoc rmdir
|
|
1215
|
+
* @hasRunnableExample
|
|
1216
|
+
* @landingPage /wp-admin/
|
|
1217
|
+
* @example
|
|
1218
|
+
*
|
|
1219
|
+
* <code>
|
|
1220
|
+
* {
|
|
1221
|
+
* "step": "rmdir",
|
|
1222
|
+
* "path": "/wordpress/wp-admin"
|
|
1223
|
+
* }
|
|
1224
|
+
* </code>
|
|
1225
|
+
*/
|
|
1226
|
+
export interface RmdirStep {
|
|
1227
|
+
step: "rmdir";
|
|
1228
|
+
/** The path to remove */
|
|
1229
|
+
path: string;
|
|
1230
|
+
}
|
|
1231
|
+
/**
|
|
1232
|
+
* Removes a directory at the specified path.
|
|
1233
|
+
*/
|
|
1234
|
+
export declare const rmdir: StepHandler<RmdirStep>;
|
|
1235
|
+
/**
|
|
1236
|
+
* @inheritDoc runSql
|
|
1237
|
+
* @hasRunnableExample
|
|
1238
|
+
* @example
|
|
1239
|
+
*
|
|
1240
|
+
* <code>
|
|
1241
|
+
* {
|
|
1242
|
+
* "step": "runSql",
|
|
1243
|
+
* "sql": {
|
|
1244
|
+
* "resource": "literal",
|
|
1245
|
+
* "name": "schema.sql",
|
|
1246
|
+
* "contents": "DELETE FROM wp_posts"
|
|
1247
|
+
* }
|
|
1248
|
+
* }
|
|
1249
|
+
* </code>
|
|
1250
|
+
*/
|
|
1251
|
+
export interface RunSqlStep<ResourceType> {
|
|
1252
|
+
/**
|
|
1253
|
+
* The step identifier.
|
|
1254
|
+
*/
|
|
1255
|
+
step: "runSql";
|
|
1256
|
+
/**
|
|
1257
|
+
* The SQL to run. Each non-empty line must contain a valid SQL query.
|
|
1258
|
+
*/
|
|
1259
|
+
sql: ResourceType;
|
|
1260
|
+
}
|
|
1261
|
+
/**
|
|
1262
|
+
* Run one or more SQL queries.
|
|
1263
|
+
*
|
|
1264
|
+
* This step will treat each non-empty line in the input SQL as a query and
|
|
1265
|
+
* try to execute it using `$wpdb`. Queries spanning multiple lines are not
|
|
1266
|
+
* yet supported.
|
|
1267
|
+
*/
|
|
1268
|
+
export declare const runSql: StepHandler<RunSqlStep<File>>;
|
|
1269
|
+
/**
|
|
1270
|
+
* @inheritDoc mkdir
|
|
1271
|
+
* @hasRunnableExample
|
|
1272
|
+
* @example
|
|
1273
|
+
*
|
|
1274
|
+
* <code>
|
|
1275
|
+
* {
|
|
1276
|
+
* "step": "mkdir",
|
|
1277
|
+
* "path": "/wordpress/my-new-folder"
|
|
1278
|
+
* }
|
|
1279
|
+
* </code>
|
|
1280
|
+
*/
|
|
1281
|
+
export interface MkdirStep {
|
|
1282
|
+
step: "mkdir";
|
|
1283
|
+
/** The path of the directory you want to create */
|
|
1284
|
+
path: string;
|
|
1285
|
+
}
|
|
1286
|
+
/**
|
|
1287
|
+
* Creates a directory at the specified path.
|
|
1288
|
+
*/
|
|
1289
|
+
export declare const mkdir: StepHandler<MkdirStep>;
|
|
1290
|
+
/**
|
|
1291
|
+
* @inheritDoc mv
|
|
1292
|
+
* @hasRunnableExample
|
|
1293
|
+
* @landingPage /index2.php
|
|
1294
|
+
* @example
|
|
1295
|
+
*
|
|
1296
|
+
* <code>
|
|
1297
|
+
* {
|
|
1298
|
+
* "step": "mv",
|
|
1299
|
+
* "fromPath": "/wordpress/index.php",
|
|
1300
|
+
* "toPath": "/wordpress/index2.php"
|
|
1301
|
+
* }
|
|
1302
|
+
* </code>
|
|
1303
|
+
*/
|
|
1304
|
+
export interface MvStep {
|
|
1305
|
+
step: "mv";
|
|
1306
|
+
/** Source path */
|
|
1307
|
+
fromPath: string;
|
|
1308
|
+
/** Target path */
|
|
1309
|
+
toPath: string;
|
|
1310
|
+
}
|
|
1311
|
+
/**
|
|
1312
|
+
* Moves a file or directory from one path to another.
|
|
1313
|
+
*/
|
|
1314
|
+
export declare const mv: StepHandler<MvStep>;
|
|
1315
|
+
/**
|
|
1316
|
+
* @inheritDoc setPhpIniEntry
|
|
1317
|
+
* @hasRunnableExample
|
|
1318
|
+
* @example
|
|
1319
|
+
*
|
|
1320
|
+
* <code>
|
|
1321
|
+
* {
|
|
1322
|
+
* "step": "setPhpIniEntry",
|
|
1323
|
+
* "key": "display_errors",
|
|
1324
|
+
* "value": "1"
|
|
1325
|
+
* }
|
|
1326
|
+
* </code>
|
|
1327
|
+
*/
|
|
1328
|
+
export interface SetPhpIniEntryStep {
|
|
1329
|
+
step: "setPhpIniEntry";
|
|
1330
|
+
/** Entry name e.g. "display_errors" */
|
|
1331
|
+
key: string;
|
|
1332
|
+
/** Entry value as a string e.g. "1" */
|
|
1333
|
+
value: string;
|
|
1334
|
+
}
|
|
1335
|
+
/**
|
|
1336
|
+
* Sets a PHP ini entry.
|
|
1337
|
+
*/
|
|
1338
|
+
export declare const setPhpIniEntry: StepHandler<SetPhpIniEntryStep>;
|
|
1339
|
+
/**
|
|
1340
|
+
* @inheritDoc runPHP
|
|
1341
|
+
* @hasRunnableExample
|
|
1342
|
+
* @example
|
|
1343
|
+
*
|
|
1344
|
+
* <code>
|
|
1345
|
+
* {
|
|
1346
|
+
* "step": "runPHP",
|
|
1347
|
+
* "code": "<?php require_once 'wordpress/wp-load.php'; wp_insert_post(array('post_title' => 'wp-load.php required for WP functionality', 'post_status' => 'publish')); ?>"
|
|
1348
|
+
* }
|
|
1349
|
+
* </code>
|
|
1350
|
+
*/
|
|
1351
|
+
export interface RunPHPStep {
|
|
1352
|
+
/** The step identifier. */
|
|
1353
|
+
step: "runPHP";
|
|
1354
|
+
/** The PHP code to run. */
|
|
1355
|
+
code: string;
|
|
1356
|
+
}
|
|
1357
|
+
/**
|
|
1358
|
+
* Runs PHP code.
|
|
1359
|
+
*/
|
|
1360
|
+
export declare const runPHP: StepHandler<RunPHPStep>;
|
|
1361
|
+
/**
|
|
1362
|
+
* @inheritDoc runPHP
|
|
1363
|
+
* @hasRunnableExample
|
|
1364
|
+
* @example
|
|
1365
|
+
*
|
|
1366
|
+
* <code>
|
|
1367
|
+
* {
|
|
1368
|
+
* "step": "runPHP",
|
|
1369
|
+
* "options": {
|
|
1370
|
+
* "code": "<?php echo $_SERVER['CONTENT_TYPE']; ?>",
|
|
1371
|
+
* "headers": {
|
|
1372
|
+
* "Content-type": "text/plain"
|
|
1373
|
+
* }
|
|
1374
|
+
* }
|
|
1375
|
+
* }
|
|
1376
|
+
* </code>
|
|
1377
|
+
*/
|
|
1378
|
+
export interface RunPHPWithOptionsStep {
|
|
1379
|
+
step: "runPHPWithOptions";
|
|
1380
|
+
/**
|
|
1381
|
+
* Run options (See /wordpress-playground/api/universal/interface/PHPRunOptions)
|
|
1382
|
+
*/
|
|
1383
|
+
options: PHPRunOptions;
|
|
1384
|
+
}
|
|
1385
|
+
/**
|
|
1386
|
+
* Runs PHP code with the given options.
|
|
1387
|
+
*/
|
|
1388
|
+
export declare const runPHPWithOptions: StepHandler<RunPHPWithOptionsStep>;
|
|
1389
|
+
/**
|
|
1390
|
+
* @inheritDoc request
|
|
1391
|
+
* @needsLogin
|
|
1392
|
+
* @hasRunnableExample
|
|
1393
|
+
* @example
|
|
1394
|
+
*
|
|
1395
|
+
* <code>
|
|
1396
|
+
* {
|
|
1397
|
+
* "step": "request",
|
|
1398
|
+
* "request": {
|
|
1399
|
+
* "method": "POST",
|
|
1400
|
+
* "url": "/wp-admin/admin-ajax.php",
|
|
1401
|
+
* "formData": {
|
|
1402
|
+
* "action": "my_action",
|
|
1403
|
+
* "foo": "bar"
|
|
1404
|
+
* }
|
|
1405
|
+
* }
|
|
1406
|
+
* }
|
|
1407
|
+
* </code>
|
|
1408
|
+
*/
|
|
1409
|
+
export interface RequestStep {
|
|
1410
|
+
step: "request";
|
|
1411
|
+
/**
|
|
1412
|
+
* Request details (See /wordpress-playground/api/universal/interface/PHPRequest)
|
|
1413
|
+
*/
|
|
1414
|
+
request: PHPRequest;
|
|
1415
|
+
}
|
|
1416
|
+
/**
|
|
1417
|
+
* Sends a HTTP request to the Playground.
|
|
1418
|
+
*/
|
|
1419
|
+
export declare const request: StepHandler<RequestStep>;
|
|
1420
|
+
/**
|
|
1421
|
+
* @inheritDoc writeFile
|
|
1422
|
+
* @hasRunnableExample
|
|
1423
|
+
* @landingPage /test.php
|
|
1424
|
+
* @example
|
|
1425
|
+
*
|
|
1426
|
+
* <code>
|
|
1427
|
+
* {
|
|
1428
|
+
* "step": "writeFile",
|
|
1429
|
+
* "path": "/wordpress/test.php",
|
|
1430
|
+
* "data": "<?php echo 'Hello World!'; ?>"
|
|
1431
|
+
* }
|
|
1432
|
+
* </code>
|
|
1433
|
+
*/
|
|
1434
|
+
export interface WriteFileStep<ResourceType> {
|
|
1435
|
+
step: "writeFile";
|
|
1436
|
+
/** The path of the file to write to */
|
|
1437
|
+
path: string;
|
|
1438
|
+
/** The data to write */
|
|
1439
|
+
data: ResourceType | string | Uint8Array;
|
|
1440
|
+
}
|
|
1441
|
+
/**
|
|
1442
|
+
* Writes data to a file at the specified path.
|
|
1443
|
+
*/
|
|
1444
|
+
export declare const writeFile: StepHandler<WriteFileStep<File>>;
|
|
1445
|
+
/**
|
|
1446
|
+
* @inheritDoc defineWpConfigConsts
|
|
1447
|
+
* @hasRunnableExample
|
|
1448
|
+
* @example
|
|
1449
|
+
*
|
|
1450
|
+
* <code>
|
|
1451
|
+
* {
|
|
1452
|
+
* "step": "defineWpConfigConsts",
|
|
1453
|
+
* "consts": {
|
|
1454
|
+
* "WP_DEBUG": true
|
|
1455
|
+
* }
|
|
1456
|
+
* }
|
|
1457
|
+
* </code>
|
|
1458
|
+
*/
|
|
1459
|
+
export interface DefineWpConfigConstsStep {
|
|
1460
|
+
step: "defineWpConfigConsts";
|
|
1461
|
+
/** The constants to define */
|
|
1462
|
+
consts: Record<string, unknown>;
|
|
1463
|
+
/**
|
|
1464
|
+
* @deprecated This option is noop and will be removed in a future version.
|
|
1465
|
+
* This option is only kept in here to avoid breaking Blueprint schema validation
|
|
1466
|
+
* for existing apps using this option.
|
|
1467
|
+
*/
|
|
1468
|
+
virtualize?: boolean;
|
|
1469
|
+
}
|
|
1470
|
+
/**
|
|
1471
|
+
* Defines constants to be used in wp-config.php file.
|
|
1472
|
+
*
|
|
1473
|
+
* This step can be called multiple times, and the constants will be merged.
|
|
1474
|
+
*
|
|
1475
|
+
* @param playground The playground client.
|
|
1476
|
+
* @param wpConfigConst
|
|
1477
|
+
*/
|
|
1478
|
+
export declare const defineWpConfigConsts: StepHandler<DefineWpConfigConstsStep>;
|
|
1479
|
+
/**
|
|
1480
|
+
* @inheritDoc activateTheme
|
|
1481
|
+
* @example
|
|
1482
|
+
*
|
|
1483
|
+
* <code>
|
|
1484
|
+
* {
|
|
1485
|
+
* "step": "activateTheme",
|
|
1486
|
+
* "pluginName": "Storefront",
|
|
1487
|
+
* "pluginPath": "/wordpress/wp-content/themes/storefront"
|
|
1488
|
+
* }
|
|
1489
|
+
* </code>
|
|
1490
|
+
*/
|
|
1491
|
+
export interface ActivateThemeStep {
|
|
1492
|
+
step: "activateTheme";
|
|
1493
|
+
/**
|
|
1494
|
+
* The name of the theme folder inside wp-content/themes/
|
|
1495
|
+
*/
|
|
1496
|
+
themeFolderName: string;
|
|
1497
|
+
}
|
|
1498
|
+
/**
|
|
1499
|
+
* Activates a WordPress theme (if it's installed).
|
|
1500
|
+
*
|
|
1501
|
+
* @param playground The playground client.
|
|
1502
|
+
* @param themeFolderName The theme folder name.
|
|
1503
|
+
*/
|
|
1504
|
+
export declare const activateTheme: StepHandler<ActivateThemeStep>;
|
|
1505
|
+
/**
|
|
1506
|
+
* @inheritDoc unzip
|
|
1507
|
+
* @example
|
|
1508
|
+
*
|
|
1509
|
+
* <code>
|
|
1510
|
+
* {
|
|
1511
|
+
* "step": "unzip",
|
|
1512
|
+
* "zipPath": "/wordpress/data.zip",
|
|
1513
|
+
* "extractToPath": "/wordpress"
|
|
1514
|
+
* }
|
|
1515
|
+
* </code>
|
|
1516
|
+
*/
|
|
1517
|
+
export interface UnzipStep {
|
|
1518
|
+
step: "unzip";
|
|
1519
|
+
/** The zip file to extract */
|
|
1520
|
+
zipPath: string;
|
|
1521
|
+
/** The path to extract the zip file to */
|
|
1522
|
+
extractToPath: string;
|
|
1523
|
+
}
|
|
1524
|
+
/**
|
|
1525
|
+
* Unzip a zip file.
|
|
1526
|
+
*
|
|
1527
|
+
* @param playground Playground client.
|
|
1528
|
+
* @param zipPath The zip file to unzip.
|
|
1529
|
+
* @param extractTo The directory to extract the zip file to.
|
|
1530
|
+
*/
|
|
1531
|
+
export declare const unzip: StepHandler<UnzipStep>;
|
|
1532
|
+
/**
|
|
1533
|
+
* @inheritDoc importWordPressFiles
|
|
1534
|
+
* @example
|
|
1535
|
+
*
|
|
1536
|
+
* <code>
|
|
1537
|
+
* {
|
|
1538
|
+
* "step": "importWordPressFilesStep",
|
|
1539
|
+
* "wordPressFilesZip": {
|
|
1540
|
+
* "resource": "fetch",
|
|
1541
|
+
* "url": "https://mysite.com/import.zip"
|
|
1542
|
+
* }
|
|
1543
|
+
* }
|
|
1544
|
+
* </code>
|
|
1545
|
+
*/
|
|
1546
|
+
export interface ImportWordPressFilesStep<ResourceType> {
|
|
1547
|
+
step: "importWordPressFiles";
|
|
1548
|
+
/**
|
|
1549
|
+
* The zip file containing the top-level WordPress files and
|
|
1550
|
+
* directories.
|
|
1551
|
+
*/
|
|
1552
|
+
wordPressFilesZip: ResourceType;
|
|
1553
|
+
/**
|
|
1554
|
+
* The path inside the zip file where the WordPress files are.
|
|
1555
|
+
*/
|
|
1556
|
+
pathInZip?: string;
|
|
1557
|
+
}
|
|
1558
|
+
/**
|
|
1559
|
+
* Imports top-level WordPress files from a given zip file into
|
|
1560
|
+
* the documentRoot. For example, if a zip file contains the
|
|
1561
|
+
* `wp-content` and `wp-includes` directories, they will replace
|
|
1562
|
+
* the corresponding directories in Playground's documentRoot.
|
|
1563
|
+
*
|
|
1564
|
+
* Any files that Playground recognizes as "excluded from the export"
|
|
1565
|
+
* will carry over from the existing document root into the imported
|
|
1566
|
+
* directories. For example, the sqlite-database-integration plugin.
|
|
1567
|
+
*
|
|
1568
|
+
* @param playground Playground client.
|
|
1569
|
+
* @param wordPressFilesZip Zipped WordPress site.
|
|
1570
|
+
*/
|
|
1571
|
+
export declare const importWordPressFiles: StepHandler<ImportWordPressFilesStep<File>>;
|
|
1572
|
+
/**
|
|
1573
|
+
* @inheritDoc importFile
|
|
1574
|
+
* @example
|
|
1575
|
+
*
|
|
1576
|
+
* <code>
|
|
1577
|
+
* {
|
|
1578
|
+
* "step": "importFile",
|
|
1579
|
+
* "file": {
|
|
1580
|
+
* "resource": "url",
|
|
1581
|
+
* "url": "https://your-site.com/starter-content.wxz"
|
|
1582
|
+
* }
|
|
1583
|
+
* }
|
|
1584
|
+
* </code>
|
|
1585
|
+
*/
|
|
1586
|
+
export interface ImportFileStep<ResourceType> {
|
|
1587
|
+
step: "importFile";
|
|
1588
|
+
/** The file to import */
|
|
1589
|
+
file: ResourceType;
|
|
1590
|
+
}
|
|
1591
|
+
/**
|
|
1592
|
+
* Uploads a file to the WordPress importer and returns the response.
|
|
1593
|
+
* Supports both WXR and WXZ files.
|
|
1594
|
+
*
|
|
1595
|
+
* @see https://github.com/WordPress/wordpress-importer/compare/master...akirk:wordpress-importer:import-wxz.patch
|
|
1596
|
+
* @param playground Playground client.
|
|
1597
|
+
* @param file The file to import.
|
|
1598
|
+
*/
|
|
1599
|
+
export declare const importFile: StepHandler<ImportFileStep<File>>;
|
|
1600
|
+
/**
|
|
1601
|
+
* Used by the export step to exclude the Playground-specific files
|
|
1602
|
+
* from the zip file. Keep it in sync with the list of files created
|
|
1603
|
+
* by WordPressPatcher.
|
|
1604
|
+
*/
|
|
1605
|
+
export declare const wpContentFilesExcludedFromExport: string[];
|
|
1606
|
+
export type Step = GenericStep<FileReference>;
|
|
1607
|
+
export type StepDefinition = Step & {
|
|
1608
|
+
progress?: {
|
|
1609
|
+
weight?: number;
|
|
1610
|
+
caption?: string;
|
|
1611
|
+
};
|
|
1612
|
+
};
|
|
1613
|
+
/**
|
|
1614
|
+
* If you add a step here, make sure to also
|
|
1615
|
+
* add it to the exports below.
|
|
1616
|
+
*/
|
|
1617
|
+
export type GenericStep<Resource> = ActivatePluginStep | ActivateThemeStep | ApplyWordPressPatchesStep | CpStep | DefineWpConfigConstsStep | DefineSiteUrlStep | ImportFileStep<Resource> | ImportWordPressFilesStep<Resource> | InstallPluginStep<Resource> | InstallThemeStep<Resource> | LoginStep | MkdirStep | MvStep | RequestStep | RmStep | RmdirStep | RunPHPStep | RunPHPWithOptionsStep | RunWpInstallationWizardStep | RunSqlStep<Resource> | SetPhpIniEntryStep | SetSiteOptionsStep | UnzipStep | UpdateUserMetaStep | WriteFileStep<Resource>;
|
|
1618
|
+
/**
|
|
1619
|
+
* Progress reporting details.
|
|
1620
|
+
*/
|
|
1621
|
+
export type StepProgress = {
|
|
1622
|
+
tracker: ProgressTracker;
|
|
1623
|
+
initialCaption?: string;
|
|
1624
|
+
};
|
|
1625
|
+
export type StepHandler<S extends GenericStep<File>> = (
|
|
1626
|
+
/**
|
|
1627
|
+
* A PHP instance or Playground client.
|
|
1628
|
+
*/
|
|
1629
|
+
php: UniversalPHP, args: Omit<S, "step">, progressArgs?: StepProgress) => any;
|
|
1630
|
+
/**
|
|
1631
|
+
* Exports the WordPress database as a WXR file using
|
|
1632
|
+
* the core WordPress export tool.
|
|
1633
|
+
*
|
|
1634
|
+
* @param playground Playground client
|
|
1635
|
+
* @returns WXR file
|
|
1636
|
+
*/
|
|
1637
|
+
export declare function exportWXR(playground: UniversalPHP): Promise<File>;
|
|
1638
|
+
/**
|
|
1639
|
+
* Exports the WordPress database as a WXZ file using
|
|
1640
|
+
* the export-wxz plugin from https://github.com/akirk/export-wxz.
|
|
1641
|
+
*
|
|
1642
|
+
* @param playground Playground client
|
|
1643
|
+
* @returns WXZ file
|
|
1644
|
+
*/
|
|
1645
|
+
export declare function exportWXZ(playground: UniversalPHP): Promise<File>;
|
|
1646
|
+
export interface ZipWpContentOptions {
|
|
1647
|
+
/**
|
|
1648
|
+
* @private
|
|
1649
|
+
* A temporary workaround to enable including the WordPress default theme
|
|
1650
|
+
* in the exported zip file.
|
|
1651
|
+
*/
|
|
1652
|
+
selfContained?: boolean;
|
|
1653
|
+
}
|
|
1654
|
+
/**
|
|
1655
|
+
* Replace the current wp-content directory with one from the provided zip file.
|
|
1656
|
+
*
|
|
1657
|
+
* @param playground Playground client.
|
|
1658
|
+
* @param wpContentZip Zipped WordPress site.
|
|
1659
|
+
*/
|
|
1660
|
+
export declare const zipWpContent: (playground: UniversalPHP, { selfContained }?: ZipWpContentOptions) => Promise<Uint8Array>;
|
|
1661
|
+
export interface Blueprint {
|
|
1662
|
+
/**
|
|
1663
|
+
* The URL to navigate to after the blueprint has been run.
|
|
1664
|
+
*/
|
|
1665
|
+
landingPage?: string;
|
|
1666
|
+
/**
|
|
1667
|
+
* Optional description. It doesn't do anything but is exposed as
|
|
1668
|
+
* a courtesy to developers who may want to document which blueprint
|
|
1669
|
+
* file does what.
|
|
1670
|
+
*/
|
|
1671
|
+
description?: string;
|
|
1672
|
+
/**
|
|
1673
|
+
* The preferred PHP and WordPress versions to use.
|
|
1674
|
+
*/
|
|
1675
|
+
preferredVersions?: {
|
|
1676
|
+
/**
|
|
1677
|
+
* The preferred PHP version to use.
|
|
1678
|
+
* If not specified, the latest supported version will be used
|
|
1679
|
+
*/
|
|
1680
|
+
php: SupportedPHPVersion | "latest";
|
|
1681
|
+
/**
|
|
1682
|
+
* The preferred WordPress version to use.
|
|
1683
|
+
* If not specified, the latest supported version will be used
|
|
1684
|
+
*/
|
|
1685
|
+
wp: string | "latest";
|
|
1686
|
+
};
|
|
1687
|
+
features?: {
|
|
1688
|
+
/** Should boot with support for network request via wp_safe_remote_get? */
|
|
1689
|
+
networking?: boolean;
|
|
1690
|
+
};
|
|
1691
|
+
/**
|
|
1692
|
+
* PHP Constants to define on every request
|
|
1693
|
+
* @deprecated This experimental option will change without warning.
|
|
1694
|
+
* Use `steps` instead.
|
|
1695
|
+
*/
|
|
1696
|
+
constants?: Record<string, string>;
|
|
1697
|
+
/**
|
|
1698
|
+
* WordPress plugins to install and activate
|
|
1699
|
+
* @deprecated This experimental option will change without warning.
|
|
1700
|
+
* Use `steps` instead.
|
|
1701
|
+
*/
|
|
1702
|
+
plugins?: Array<string | FileReference>;
|
|
1703
|
+
/**
|
|
1704
|
+
* WordPress site options to define
|
|
1705
|
+
* @deprecated This experimental option will change without warning.
|
|
1706
|
+
* Use `steps` instead.
|
|
1707
|
+
*/
|
|
1708
|
+
siteOptions?: Record<string, string> & {
|
|
1709
|
+
/** The site title */
|
|
1710
|
+
blogname?: string;
|
|
1711
|
+
};
|
|
1712
|
+
/**
|
|
1713
|
+
* User to log in as.
|
|
1714
|
+
* If true, logs the user in as admin/password.
|
|
1715
|
+
*/
|
|
1716
|
+
login?: boolean | {
|
|
1717
|
+
username: string;
|
|
1718
|
+
password: string;
|
|
1719
|
+
};
|
|
1720
|
+
/**
|
|
1721
|
+
* The PHP extensions to use.
|
|
1722
|
+
*/
|
|
1723
|
+
phpExtensionBundles?: SupportedPHPExtensionBundle[];
|
|
1724
|
+
/**
|
|
1725
|
+
* The steps to run after every other operation in this Blueprint was
|
|
1726
|
+
* executed.
|
|
1727
|
+
*/
|
|
1728
|
+
steps?: Array<StepDefinition | string | undefined | false | null>;
|
|
1729
|
+
}
|
|
1730
|
+
export type CompiledStep = (php: UniversalPHP) => Promise<void> | void;
|
|
1731
|
+
export interface CompiledBlueprint {
|
|
1732
|
+
/** The requested versions of PHP and WordPress for the blueprint */
|
|
1733
|
+
versions: {
|
|
1734
|
+
php: SupportedPHPVersion;
|
|
1735
|
+
wp: string;
|
|
1736
|
+
};
|
|
1737
|
+
/** The requested PHP extensions to load */
|
|
1738
|
+
phpExtensions: SupportedPHPExtension[];
|
|
1739
|
+
features: {
|
|
1740
|
+
/** Should boot with support for network request via wp_safe_remote_get? */
|
|
1741
|
+
networking: boolean;
|
|
1742
|
+
};
|
|
1743
|
+
/** The compiled steps for the blueprint */
|
|
1744
|
+
run: (playground: UniversalPHP) => Promise<void>;
|
|
1745
|
+
}
|
|
1746
|
+
export type OnStepCompleted = (output: any, step: StepDefinition) => any;
|
|
1747
|
+
export interface CompileBlueprintOptions {
|
|
1748
|
+
/** Optional progress tracker to monitor progress */
|
|
1749
|
+
progress?: ProgressTracker;
|
|
1750
|
+
/** Optional semaphore to control access to a shared resource */
|
|
1751
|
+
semaphore?: Semaphore;
|
|
1752
|
+
/** Optional callback with step output */
|
|
1753
|
+
onStepCompleted?: OnStepCompleted;
|
|
1754
|
+
}
|
|
1755
|
+
/**
|
|
1756
|
+
* Compiles Blueprint into a form that can be executed.
|
|
1757
|
+
*
|
|
1758
|
+
* @param playground The PlaygroundClient to use for the compilation
|
|
1759
|
+
* @param blueprint The bBueprint to compile
|
|
1760
|
+
* @param options Additional options for the compilation
|
|
1761
|
+
* @returns The compiled blueprint
|
|
1762
|
+
*/
|
|
1763
|
+
export declare function compileBlueprint(blueprint: Blueprint, { progress, semaphore, onStepCompleted, }?: CompileBlueprintOptions): CompiledBlueprint;
|
|
1764
|
+
export declare function runBlueprintSteps(compiledBlueprint: CompiledBlueprint, playground: UniversalPHP): Promise<void>;
|
|
7
1765
|
/**
|
|
8
1766
|
* @deprecated This function is a no-op. Playground no longer uses a proxy to download plugins and themes.
|
|
9
1767
|
* To be removed in v0.3.0
|
|
10
1768
|
*/
|
|
11
1769
|
export declare function setPluginProxyURL(): void;
|
|
1770
|
+
|
|
1771
|
+
export {};
|