@wp-playground/client 0.1.18 → 0.1.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +62 -23
- package/index.js +115 -89
- package/package.json +2 -2
package/index.d.ts
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
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 {
|
|
3
|
+
export interface PHPResponseData {
|
|
8
4
|
/**
|
|
9
5
|
* Response headers.
|
|
10
6
|
*/
|
|
@@ -13,7 +9,7 @@ export declare class PHPResponse {
|
|
|
13
9
|
* Response body. Contains the output from `echo`,
|
|
14
10
|
* `print`, inline HTML etc.
|
|
15
11
|
*/
|
|
16
|
-
|
|
12
|
+
readonly bytes: ArrayBuffer;
|
|
17
13
|
/**
|
|
18
14
|
* Stderr contents, if any.
|
|
19
15
|
*/
|
|
@@ -27,7 +23,28 @@ export declare class PHPResponse {
|
|
|
27
23
|
* Response HTTP status code, e.g. 200.
|
|
28
24
|
*/
|
|
29
25
|
readonly httpStatusCode: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* PHP response. Body is an `ArrayBuffer` because it can
|
|
29
|
+
* contain binary data.
|
|
30
|
+
*
|
|
31
|
+
* This type is used in Comlink.transferHandlers.set('PHPResponse', { ... })
|
|
32
|
+
* so be sure to update that if you change this type.
|
|
33
|
+
*/
|
|
34
|
+
export declare class PHPResponse implements PHPResponseData {
|
|
35
|
+
/** @inheritDoc */
|
|
36
|
+
readonly headers: Record<string, string[]>;
|
|
37
|
+
/** @inheritDoc */
|
|
38
|
+
readonly bytes: ArrayBuffer;
|
|
39
|
+
/** @inheritDoc */
|
|
40
|
+
readonly errors: string;
|
|
41
|
+
/** @inheritDoc */
|
|
42
|
+
readonly exitCode: number;
|
|
43
|
+
/** @inheritDoc */
|
|
44
|
+
readonly httpStatusCode: number;
|
|
30
45
|
constructor(httpStatusCode: number, headers: Record<string, string[]>, body: ArrayBuffer, errors?: string, exitCode?: number);
|
|
46
|
+
static fromRawData(data: PHPResponseData): PHPResponse;
|
|
47
|
+
toRawData(): PHPResponseData;
|
|
31
48
|
/**
|
|
32
49
|
* Response body as JSON.
|
|
33
50
|
*/
|
|
@@ -36,20 +53,36 @@ export declare class PHPResponse {
|
|
|
36
53
|
* Response body as text.
|
|
37
54
|
*/
|
|
38
55
|
get text(): string;
|
|
56
|
+
}
|
|
57
|
+
export type HTTPMethod = "GET" | "POST" | "HEAD" | "OPTIONS" | "PATCH" | "PUT" | "DELETE";
|
|
58
|
+
export type PHPRequestHeaders = Record<string, string>;
|
|
59
|
+
export interface PHPRequest {
|
|
39
60
|
/**
|
|
40
|
-
*
|
|
61
|
+
* Request method. Default: `GET`.
|
|
62
|
+
*/
|
|
63
|
+
method?: HTTPMethod;
|
|
64
|
+
/**
|
|
65
|
+
* Request path or absolute URL.
|
|
41
66
|
*/
|
|
42
|
-
get bytes(): ArrayBuffer;
|
|
43
|
-
}
|
|
44
|
-
export type PHPRequest = Pick<PHPRunOptions, "method" | "headers"> & {
|
|
45
67
|
url: string;
|
|
68
|
+
/**
|
|
69
|
+
* Request headers.
|
|
70
|
+
*/
|
|
71
|
+
headers?: PHPRequestHeaders;
|
|
72
|
+
/**
|
|
73
|
+
* Uploaded files
|
|
74
|
+
*/
|
|
46
75
|
files?: Record<string, File>;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
body?:
|
|
51
|
-
|
|
52
|
-
|
|
76
|
+
/**
|
|
77
|
+
* Request body without the files.
|
|
78
|
+
*/
|
|
79
|
+
body?: string;
|
|
80
|
+
/**
|
|
81
|
+
* Form data. If set, the request body will be ignored and
|
|
82
|
+
* the content-type header will be set to `application/x-www-form-urlencoded`.
|
|
83
|
+
*/
|
|
84
|
+
formData?: Record<string, unknown>;
|
|
85
|
+
}
|
|
53
86
|
export interface PHPRequestHandlerConfiguration {
|
|
54
87
|
/**
|
|
55
88
|
* The directory in the PHP filesystem where the server will look
|
|
@@ -146,7 +179,6 @@ declare class PHPBrowser implements WithRequestHandler {
|
|
|
146
179
|
*/
|
|
147
180
|
request(request: PHPRequest, redirects?: number): Promise<PHPResponse>;
|
|
148
181
|
}
|
|
149
|
-
export type PHPRequestHeaders = Record<string, string>;
|
|
150
182
|
export interface FileInfo {
|
|
151
183
|
key: string;
|
|
152
184
|
name: string;
|
|
@@ -169,7 +201,7 @@ export interface PHPRunOptions {
|
|
|
169
201
|
/**
|
|
170
202
|
* Request method. Default: `GET`.
|
|
171
203
|
*/
|
|
172
|
-
method?:
|
|
204
|
+
method?: HTTPMethod;
|
|
173
205
|
/**
|
|
174
206
|
* Request headers.
|
|
175
207
|
*/
|
|
@@ -208,11 +240,11 @@ export interface WithNodeFilesystem {
|
|
|
208
240
|
/**
|
|
209
241
|
* Mounts a Node.js filesystem to a given path in the PHP filesystem.
|
|
210
242
|
*
|
|
211
|
-
* @param
|
|
212
|
-
* @param
|
|
243
|
+
* @param localPath - The path of a real local directory you want to mount.
|
|
244
|
+
* @param virtualFSPath - Where to mount it in the virtual filesystem.
|
|
213
245
|
* @see {@link https://emscripten.org/docs/api_reference/Filesystem-API.html#FS.mount}
|
|
214
246
|
*/
|
|
215
|
-
mount(
|
|
247
|
+
mount(localPath: string | MountSettings, virtualFSPath: string): void;
|
|
216
248
|
}
|
|
217
249
|
export interface WithFilesystem {
|
|
218
250
|
/**
|
|
@@ -222,6 +254,10 @@ export interface WithFilesystem {
|
|
|
222
254
|
*
|
|
223
255
|
* @param path - The directory path to create.
|
|
224
256
|
*/
|
|
257
|
+
mkdir(path: string): void;
|
|
258
|
+
/**
|
|
259
|
+
* @deprecated Use mkdir instead.
|
|
260
|
+
*/
|
|
225
261
|
mkdirTree(path: string): void;
|
|
226
262
|
/**
|
|
227
263
|
* Reads a file from the PHP filesystem and returns it as a string.
|
|
@@ -379,6 +415,8 @@ declare abstract class BasePHP implements WithPHPIniBindings, WithFilesystem, Wi
|
|
|
379
415
|
setSkipShebang(shouldSkip: boolean): void;
|
|
380
416
|
addServerGlobalEntry(key: string, value: string): void;
|
|
381
417
|
/** @inheritDoc */
|
|
418
|
+
mkdir(path: string): void;
|
|
419
|
+
/** @inheritDoc */
|
|
382
420
|
mkdirTree(path: string): void;
|
|
383
421
|
/** @inheritDoc */
|
|
384
422
|
readFileAsText(path: string): string;
|
|
@@ -395,7 +433,7 @@ declare abstract class BasePHP implements WithPHPIniBindings, WithFilesystem, Wi
|
|
|
395
433
|
/** @inheritDoc */
|
|
396
434
|
fileExists(path: string): boolean;
|
|
397
435
|
/** @inheritDoc */
|
|
398
|
-
mount(
|
|
436
|
+
mount(localPath: string | MountSettings, virtualFSPath: string): void;
|
|
399
437
|
}
|
|
400
438
|
declare const SupportedPHPVersions: readonly [
|
|
401
439
|
"8.2",
|
|
@@ -481,7 +519,6 @@ declare class PHP extends BasePHP {
|
|
|
481
519
|
* resolves when the PHP instance is ready.
|
|
482
520
|
*
|
|
483
521
|
* @see load
|
|
484
|
-
* @inheritdoc load
|
|
485
522
|
*/
|
|
486
523
|
static loadSync(phpVersion: SupportedPHPVersion, options?: PHPWebLoaderOptions): {
|
|
487
524
|
php: PHP;
|
|
@@ -522,6 +559,8 @@ declare class PHPClient implements Promisify<WithPHPIniBindings & WithFilesystem
|
|
|
522
559
|
setPhpIniPath(path: string): void;
|
|
523
560
|
/** @inheritDoc @php-wasm/web!PHP.setPhpIniEntry */
|
|
524
561
|
setPhpIniEntry(key: string, value: string): void;
|
|
562
|
+
/** @inheritDoc @php-wasm/web!PHP.mkdir */
|
|
563
|
+
mkdir(path: string): void;
|
|
525
564
|
/** @inheritDoc @php-wasm/web!PHP.mkdirTree */
|
|
526
565
|
mkdirTree(path: string): void;
|
|
527
566
|
/** @inheritDoc @php-wasm/web!PHP.readFileAsText */
|
package/index.js
CHANGED
|
@@ -95,9 +95,27 @@ class se {
|
|
|
95
95
|
};
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
|
-
class
|
|
98
|
+
class E {
|
|
99
99
|
constructor(e, n, r, o = "", a = 0) {
|
|
100
|
-
this.httpStatusCode = e, this.headers = n, this.
|
|
100
|
+
this.httpStatusCode = e, this.headers = n, this.bytes = r, this.exitCode = a, this.errors = o;
|
|
101
|
+
}
|
|
102
|
+
static fromRawData(e) {
|
|
103
|
+
return new E(
|
|
104
|
+
e.httpStatusCode,
|
|
105
|
+
e.headers,
|
|
106
|
+
e.bytes,
|
|
107
|
+
e.errors,
|
|
108
|
+
e.exitCode
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
toRawData() {
|
|
112
|
+
return {
|
|
113
|
+
headers: this.headers,
|
|
114
|
+
bytes: this.bytes,
|
|
115
|
+
errors: this.errors,
|
|
116
|
+
exitCode: this.exitCode,
|
|
117
|
+
httpStatusCode: this.httpStatusCode
|
|
118
|
+
};
|
|
101
119
|
}
|
|
102
120
|
/**
|
|
103
121
|
* Response body as JSON.
|
|
@@ -109,13 +127,7 @@ class I {
|
|
|
109
127
|
* Response body as text.
|
|
110
128
|
*/
|
|
111
129
|
get text() {
|
|
112
|
-
return new TextDecoder().decode(this.
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Response body as bytes.
|
|
116
|
-
*/
|
|
117
|
-
get bytes() {
|
|
118
|
-
return this.body;
|
|
130
|
+
return new TextDecoder().decode(this.bytes);
|
|
119
131
|
}
|
|
120
132
|
}
|
|
121
133
|
class ae {
|
|
@@ -136,7 +148,7 @@ class ae {
|
|
|
136
148
|
this.#a = new se({ concurrency: 1 });
|
|
137
149
|
const {
|
|
138
150
|
documentRoot: r = "/www/",
|
|
139
|
-
absoluteUrl: o = location
|
|
151
|
+
absoluteUrl: o = typeof location == "object" ? location?.href : "",
|
|
140
152
|
isStaticFilePath: a = () => !1
|
|
141
153
|
} = n;
|
|
142
154
|
this.php = e, this.#e = r, this.#l = a;
|
|
@@ -214,13 +226,13 @@ class ae {
|
|
|
214
226
|
#c(e) {
|
|
215
227
|
const n = `${this.#e}${e}`;
|
|
216
228
|
if (!this.php.fileExists(n))
|
|
217
|
-
return new
|
|
229
|
+
return new E(
|
|
218
230
|
404,
|
|
219
231
|
{},
|
|
220
232
|
new TextEncoder().encode("404 File not found")
|
|
221
233
|
);
|
|
222
234
|
const r = this.php.readFileAsBuffer(n);
|
|
223
|
-
return new
|
|
235
|
+
return new E(
|
|
224
236
|
200,
|
|
225
237
|
{
|
|
226
238
|
"content-length": [`${r.byteLength}`],
|
|
@@ -647,7 +659,7 @@ class g {
|
|
|
647
659
|
[],
|
|
648
660
|
[]
|
|
649
661
|
), { headers: n, httpStatusCode: r } = this.#i();
|
|
650
|
-
return new
|
|
662
|
+
return new E(
|
|
651
663
|
r,
|
|
652
664
|
n,
|
|
653
665
|
this.readFileAsBuffer("/tmp/stdout"),
|
|
@@ -655,9 +667,12 @@ class g {
|
|
|
655
667
|
e
|
|
656
668
|
);
|
|
657
669
|
}
|
|
658
|
-
|
|
670
|
+
mkdir(e) {
|
|
659
671
|
this.#e.FS.mkdirTree(e);
|
|
660
672
|
}
|
|
673
|
+
mkdirTree(e) {
|
|
674
|
+
this.mkdir(e);
|
|
675
|
+
}
|
|
661
676
|
readFileAsText(e) {
|
|
662
677
|
return new TextDecoder().decode(this.readFileAsBuffer(e));
|
|
663
678
|
}
|
|
@@ -696,11 +711,14 @@ class g {
|
|
|
696
711
|
mount(e, n) {
|
|
697
712
|
this.#e.FS.mount(
|
|
698
713
|
this.#e.FS.filesystems.NODEFS,
|
|
699
|
-
e,
|
|
714
|
+
typeof e == "object" ? e : { root: e },
|
|
700
715
|
n
|
|
701
716
|
);
|
|
702
717
|
}
|
|
703
718
|
}
|
|
719
|
+
w([
|
|
720
|
+
m('Could not create directory "{path}"')
|
|
721
|
+
], g.prototype, "mkdir", 1);
|
|
704
722
|
w([
|
|
705
723
|
m('Could not create directory "{path}"')
|
|
706
724
|
], g.prototype, "mkdirTree", 1);
|
|
@@ -739,7 +757,7 @@ function de(t) {
|
|
|
739
757
|
* Copyright 2019 Google LLC
|
|
740
758
|
* SPDX-License-Identifier: Apache-2.0
|
|
741
759
|
*/
|
|
742
|
-
const K = Symbol("Comlink.proxy"), he = Symbol("Comlink.endpoint"), pe = Symbol("Comlink.releaseProxy"),
|
|
760
|
+
const K = Symbol("Comlink.proxy"), he = Symbol("Comlink.endpoint"), pe = Symbol("Comlink.releaseProxy"), I = Symbol("Comlink.finalizer"), O = Symbol("Comlink.thrown"), X = (t) => typeof t == "object" && t !== null || typeof t == "function", fe = {
|
|
743
761
|
canHandle: (t) => X(t) && t[K],
|
|
744
762
|
serialize(t) {
|
|
745
763
|
const { port1: e, port2: n } = new MessageChannel();
|
|
@@ -749,7 +767,7 @@ const K = Symbol("Comlink.proxy"), he = Symbol("Comlink.endpoint"), pe = Symbol(
|
|
|
749
767
|
return t.start(), M(t);
|
|
750
768
|
}
|
|
751
769
|
}, me = {
|
|
752
|
-
canHandle: (t) => X(t) &&
|
|
770
|
+
canHandle: (t) => X(t) && O in t,
|
|
753
771
|
serialize({ value: t }) {
|
|
754
772
|
let e;
|
|
755
773
|
return t instanceof Error ? e = {
|
|
@@ -764,7 +782,7 @@ const K = Symbol("Comlink.proxy"), he = Symbol("Comlink.endpoint"), pe = Symbol(
|
|
|
764
782
|
deserialize(t) {
|
|
765
783
|
throw t.isError ? Object.assign(new Error(t.value.message), t.value) : t.value;
|
|
766
784
|
}
|
|
767
|
-
},
|
|
785
|
+
}, R = /* @__PURE__ */ new Map([
|
|
768
786
|
["proxy", fe],
|
|
769
787
|
["throw", me]
|
|
770
788
|
]);
|
|
@@ -815,15 +833,15 @@ function N(t, e = globalThis, n = ["*"]) {
|
|
|
815
833
|
return;
|
|
816
834
|
}
|
|
817
835
|
} catch (l) {
|
|
818
|
-
s = { value: l, [
|
|
836
|
+
s = { value: l, [O]: 0 };
|
|
819
837
|
}
|
|
820
|
-
Promise.resolve(s).catch((l) => ({ value: l, [
|
|
821
|
-
const [h, u] =
|
|
822
|
-
e.postMessage(Object.assign(Object.assign({}, h), { id: a }), u), i === "RELEASE" && (e.removeEventListener("message", r), J(e),
|
|
838
|
+
Promise.resolve(s).catch((l) => ({ value: l, [O]: 0 })).then((l) => {
|
|
839
|
+
const [h, u] = U(l);
|
|
840
|
+
e.postMessage(Object.assign(Object.assign({}, h), { id: a }), u), i === "RELEASE" && (e.removeEventListener("message", r), J(e), I in t && typeof t[I] == "function" && t[I]());
|
|
823
841
|
}).catch((l) => {
|
|
824
|
-
const [h, u] =
|
|
842
|
+
const [h, u] = U({
|
|
825
843
|
value: new TypeError("Unserializable return value"),
|
|
826
|
-
[
|
|
844
|
+
[O]: 0
|
|
827
845
|
});
|
|
828
846
|
e.postMessage(Object.assign(Object.assign({}, h), { id: a }), u);
|
|
829
847
|
});
|
|
@@ -836,9 +854,9 @@ function J(t) {
|
|
|
836
854
|
ge(t) && t.close();
|
|
837
855
|
}
|
|
838
856
|
function M(t, e) {
|
|
839
|
-
return
|
|
857
|
+
return D(t, [], e);
|
|
840
858
|
}
|
|
841
|
-
function
|
|
859
|
+
function k(t) {
|
|
842
860
|
if (t)
|
|
843
861
|
throw new Error("Proxy has been released and is not useable");
|
|
844
862
|
}
|
|
@@ -849,23 +867,23 @@ function Y(t) {
|
|
|
849
867
|
J(t);
|
|
850
868
|
});
|
|
851
869
|
}
|
|
852
|
-
const
|
|
853
|
-
const e = (
|
|
854
|
-
|
|
870
|
+
const A = /* @__PURE__ */ new WeakMap(), L = "FinalizationRegistry" in globalThis && new FinalizationRegistry((t) => {
|
|
871
|
+
const e = (A.get(t) || 0) - 1;
|
|
872
|
+
A.set(t, e), e === 0 && Y(t);
|
|
855
873
|
});
|
|
856
874
|
function ye(t, e) {
|
|
857
|
-
const n = (
|
|
858
|
-
|
|
875
|
+
const n = (A.get(e) || 0) + 1;
|
|
876
|
+
A.set(e, n), L && L.register(t, e, t);
|
|
859
877
|
}
|
|
860
878
|
function be(t) {
|
|
861
|
-
|
|
879
|
+
L && L.unregister(t);
|
|
862
880
|
}
|
|
863
|
-
function
|
|
881
|
+
function D(t, e = [], n = function() {
|
|
864
882
|
}) {
|
|
865
883
|
let r = !1;
|
|
866
884
|
const o = new Proxy(n, {
|
|
867
885
|
get(a, i) {
|
|
868
|
-
if (
|
|
886
|
+
if (k(r), i === pe)
|
|
869
887
|
return () => {
|
|
870
888
|
be(o), Y(t), r = !0;
|
|
871
889
|
};
|
|
@@ -878,11 +896,11 @@ function q(t, e = [], n = function() {
|
|
|
878
896
|
}).then(b);
|
|
879
897
|
return d.then.bind(d);
|
|
880
898
|
}
|
|
881
|
-
return
|
|
899
|
+
return D(t, [...e, i]);
|
|
882
900
|
},
|
|
883
901
|
set(a, i, d) {
|
|
884
|
-
|
|
885
|
-
const [c, s] =
|
|
902
|
+
k(r);
|
|
903
|
+
const [c, s] = U(d);
|
|
886
904
|
return P(t, {
|
|
887
905
|
type: "SET",
|
|
888
906
|
path: [...e, i].map((l) => l.toString()),
|
|
@@ -890,14 +908,14 @@ function q(t, e = [], n = function() {
|
|
|
890
908
|
}, s).then(b);
|
|
891
909
|
},
|
|
892
910
|
apply(a, i, d) {
|
|
893
|
-
|
|
911
|
+
k(r);
|
|
894
912
|
const c = e[e.length - 1];
|
|
895
913
|
if (c === he)
|
|
896
914
|
return P(t, {
|
|
897
915
|
type: "ENDPOINT"
|
|
898
916
|
}).then(b);
|
|
899
917
|
if (c === "bind")
|
|
900
|
-
return
|
|
918
|
+
return D(t, e.slice(0, -1));
|
|
901
919
|
const [s, l] = V(d);
|
|
902
920
|
return P(t, {
|
|
903
921
|
type: "APPLY",
|
|
@@ -906,7 +924,7 @@ function q(t, e = [], n = function() {
|
|
|
906
924
|
}, l).then(b);
|
|
907
925
|
},
|
|
908
926
|
construct(a, i) {
|
|
909
|
-
|
|
927
|
+
k(r);
|
|
910
928
|
const [d, c] = V(i);
|
|
911
929
|
return P(t, {
|
|
912
930
|
type: "CONSTRUCT",
|
|
@@ -921,7 +939,7 @@ function ve(t) {
|
|
|
921
939
|
return Array.prototype.concat.apply([], t);
|
|
922
940
|
}
|
|
923
941
|
function V(t) {
|
|
924
|
-
const e = t.map(
|
|
942
|
+
const e = t.map(U);
|
|
925
943
|
return [e.map((n) => n[0]), ve(e.map((n) => n[1]))];
|
|
926
944
|
}
|
|
927
945
|
const Q = /* @__PURE__ */ new WeakMap();
|
|
@@ -938,8 +956,8 @@ function xe(t, e = globalThis, n = "*") {
|
|
|
938
956
|
removeEventListener: e.removeEventListener.bind(e)
|
|
939
957
|
};
|
|
940
958
|
}
|
|
941
|
-
function
|
|
942
|
-
for (const [e, n] of
|
|
959
|
+
function U(t) {
|
|
960
|
+
for (const [e, n] of R)
|
|
943
961
|
if (n.canHandle(t)) {
|
|
944
962
|
const [r, o] = n.serialize(t);
|
|
945
963
|
return [
|
|
@@ -962,7 +980,7 @@ function L(t) {
|
|
|
962
980
|
function b(t) {
|
|
963
981
|
switch (t.type) {
|
|
964
982
|
case "HANDLER":
|
|
965
|
-
return
|
|
983
|
+
return R.get(t.name).deserialize(t.value);
|
|
966
984
|
case "RAW":
|
|
967
985
|
return t.value;
|
|
968
986
|
}
|
|
@@ -984,7 +1002,7 @@ function Fe(t) {
|
|
|
984
1002
|
return M(e);
|
|
985
1003
|
}
|
|
986
1004
|
function Te() {
|
|
987
|
-
|
|
1005
|
+
R.set("EVENT", {
|
|
988
1006
|
canHandle: (t) => t instanceof CustomEvent,
|
|
989
1007
|
serialize: (t) => [
|
|
990
1008
|
{
|
|
@@ -993,7 +1011,7 @@ function Te() {
|
|
|
993
1011
|
[]
|
|
994
1012
|
],
|
|
995
1013
|
deserialize: (t) => t
|
|
996
|
-
}),
|
|
1014
|
+
}), R.set("FUNCTION", {
|
|
997
1015
|
canHandle: (t) => typeof t == "function",
|
|
998
1016
|
serialize(t) {
|
|
999
1017
|
console.debug("[Comlink][Performance] Proxying a function");
|
|
@@ -1003,23 +1021,31 @@ function Te() {
|
|
|
1003
1021
|
deserialize(t) {
|
|
1004
1022
|
return t.start(), M(t);
|
|
1005
1023
|
}
|
|
1024
|
+
}), R.set("PHPResponse", {
|
|
1025
|
+
canHandle: (t) => typeof t == "object" && t !== null && "headers" in t && "bytes" in t && "errors" in t && "exitCode" in t && "httpStatusCode" in t,
|
|
1026
|
+
serialize(t) {
|
|
1027
|
+
return [t.toRawData(), []];
|
|
1028
|
+
},
|
|
1029
|
+
deserialize(t) {
|
|
1030
|
+
return E.fromRawData(t);
|
|
1031
|
+
}
|
|
1006
1032
|
});
|
|
1007
1033
|
}
|
|
1008
1034
|
(function() {
|
|
1009
|
-
return navigator
|
|
1035
|
+
return navigator?.userAgent?.toLowerCase().indexOf("firefox") > -1 ? "iframe" : "webworker";
|
|
1010
1036
|
})();
|
|
1011
|
-
var
|
|
1037
|
+
var T = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}, q = {}, Re = {
|
|
1012
1038
|
get exports() {
|
|
1013
|
-
return
|
|
1039
|
+
return q;
|
|
1014
1040
|
},
|
|
1015
1041
|
set exports(t) {
|
|
1016
|
-
|
|
1042
|
+
q = t;
|
|
1017
1043
|
}
|
|
1018
1044
|
};
|
|
1019
1045
|
(function(t, e) {
|
|
1020
1046
|
(function(n, r) {
|
|
1021
1047
|
r();
|
|
1022
|
-
})(
|
|
1048
|
+
})(T, function() {
|
|
1023
1049
|
function n(s, l) {
|
|
1024
1050
|
return typeof l > "u" ? l = { autoBom: !1 } : typeof l != "object" && (console.warn("Deprecated: Expected third argument to be a object"), l = { autoBom: !l }), l.autoBom && /^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(s.type) ? new Blob(["\uFEFF", s], { type: s.type }) : s;
|
|
1025
1051
|
}
|
|
@@ -1048,7 +1074,7 @@ var F = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : ty
|
|
|
1048
1074
|
l.initMouseEvent("click", !0, !0, window, 0, 0, 0, 80, 20, !1, !1, !1, !1, 0, null), s.dispatchEvent(l);
|
|
1049
1075
|
}
|
|
1050
1076
|
}
|
|
1051
|
-
var i = typeof window == "object" && window.window === window ? window : typeof self == "object" && self.self === self ? self : typeof
|
|
1077
|
+
var i = typeof window == "object" && window.window === window ? window : typeof self == "object" && self.self === self ? self : typeof T == "object" && T.global === T ? T : void 0, d = i.navigator && /Macintosh/.test(navigator.userAgent) && /AppleWebKit/.test(navigator.userAgent) && !/Safari/.test(navigator.userAgent), c = i.saveAs || (typeof window != "object" || window !== i ? function() {
|
|
1052
1078
|
} : "download" in HTMLAnchorElement.prototype && !d ? function(s, l, h) {
|
|
1053
1079
|
var u = i.URL || i.webkitURL, p = document.createElement("a");
|
|
1054
1080
|
l = l || s.name || "download", p.download = l, p.rel = "noopener", typeof s == "string" ? (p.href = s, p.origin === location.origin ? a(p) : o(p.href) ? r(s, l, h) : a(p, p.target = "_blank")) : (p.href = u.createObjectURL(s), setTimeout(function() {
|
|
@@ -1070,24 +1096,24 @@ var F = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : ty
|
|
|
1070
1096
|
} : function(s, l, h, u) {
|
|
1071
1097
|
if (u = u || open("", "_blank"), u && (u.document.title = u.document.body.innerText = "downloading..."), typeof s == "string")
|
|
1072
1098
|
return r(s, l, h);
|
|
1073
|
-
var p = s.type === "application/octet-stream",
|
|
1074
|
-
if ((_ || p &&
|
|
1075
|
-
var
|
|
1076
|
-
|
|
1077
|
-
var
|
|
1078
|
-
|
|
1079
|
-
},
|
|
1099
|
+
var p = s.type === "application/octet-stream", x = /constructor/i.test(i.HTMLElement) || i.safari, _ = /CriOS\/[\d]+/.test(navigator.userAgent);
|
|
1100
|
+
if ((_ || p && x || d) && typeof FileReader < "u") {
|
|
1101
|
+
var $ = new FileReader();
|
|
1102
|
+
$.onloadend = function() {
|
|
1103
|
+
var F = $.result;
|
|
1104
|
+
F = _ ? F : F.replace(/^data:[^;]*;/, "data:attachment/file;"), u ? u.location.href = F : location = F, u = null;
|
|
1105
|
+
}, $.readAsDataURL(s);
|
|
1080
1106
|
} else {
|
|
1081
|
-
var
|
|
1107
|
+
var C = i.URL || i.webkitURL, v = C.createObjectURL(s);
|
|
1082
1108
|
u ? u.location = v : location.href = v, u = null, setTimeout(function() {
|
|
1083
|
-
|
|
1109
|
+
C.revokeObjectURL(v);
|
|
1084
1110
|
}, 4e4);
|
|
1085
1111
|
}
|
|
1086
1112
|
});
|
|
1087
1113
|
i.saveAs = c.saveAs = c, t.exports = c;
|
|
1088
1114
|
});
|
|
1089
|
-
})(
|
|
1090
|
-
const
|
|
1115
|
+
})(Re);
|
|
1116
|
+
const z = `<?php
|
|
1091
1117
|
|
|
1092
1118
|
function generateZipFile($exportPath, $databasePath, $docRoot) {
|
|
1093
1119
|
$zip = new ZipArchive;
|
|
@@ -1162,12 +1188,12 @@ async function ke(t) {
|
|
|
1162
1188
|
})).text;
|
|
1163
1189
|
await t.writeFile(H, n);
|
|
1164
1190
|
const r = await t.wordPressVersion, o = await t.phpVersion, a = await t.documentRoot, i = `wordpress-playground--wp${r}--php${o}.zip`, d = `/${i}`, c = await t.run({
|
|
1165
|
-
code:
|
|
1191
|
+
code: z + ` generateZipFile('${d}', '${H}', '${a}');`
|
|
1166
1192
|
});
|
|
1167
1193
|
if (c.exitCode !== 0)
|
|
1168
1194
|
throw c.errors;
|
|
1169
1195
|
const s = await t.readFileAsBuffer(i), l = new File([s], i);
|
|
1170
|
-
|
|
1196
|
+
q.saveAs(l);
|
|
1171
1197
|
}
|
|
1172
1198
|
async function Oe(t, e) {
|
|
1173
1199
|
if (
|
|
@@ -1180,7 +1206,7 @@ async function Oe(t, e) {
|
|
|
1180
1206
|
const n = await e.arrayBuffer(), r = new Uint8Array(n), o = "/import.zip";
|
|
1181
1207
|
await t.writeFile(o, r);
|
|
1182
1208
|
const a = await t.run({
|
|
1183
|
-
code:
|
|
1209
|
+
code: z + ` readFileFromZipArchive('${o}', '${H}');`
|
|
1184
1210
|
});
|
|
1185
1211
|
if (a.exitCode !== 0)
|
|
1186
1212
|
throw a.errors;
|
|
@@ -1203,26 +1229,26 @@ async function Oe(t, e) {
|
|
|
1203
1229
|
"text/html"
|
|
1204
1230
|
).querySelector(
|
|
1205
1231
|
"#wpbody-content form"
|
|
1206
|
-
),
|
|
1232
|
+
), x = p?.getAttribute(
|
|
1207
1233
|
"action"
|
|
1208
1234
|
), _ = (p?.querySelector(
|
|
1209
1235
|
"input[name='_wpnonce']"
|
|
1210
|
-
)).value,
|
|
1236
|
+
)).value, $ = (p?.querySelector(
|
|
1211
1237
|
"input[name='_wp_http_referer']"
|
|
1212
|
-
)).value,
|
|
1238
|
+
)).value, C = (p?.querySelector(
|
|
1213
1239
|
"input[name='import_id']"
|
|
1214
1240
|
)).value;
|
|
1215
1241
|
await t.request({
|
|
1216
|
-
url:
|
|
1242
|
+
url: x,
|
|
1217
1243
|
method: "POST",
|
|
1218
1244
|
formData: {
|
|
1219
1245
|
_wpnonce: _,
|
|
1220
|
-
_wp_http_referer:
|
|
1221
|
-
import_id:
|
|
1246
|
+
_wp_http_referer: $,
|
|
1247
|
+
import_id: C
|
|
1222
1248
|
}
|
|
1223
1249
|
});
|
|
1224
1250
|
const v = await t.run({
|
|
1225
|
-
code:
|
|
1251
|
+
code: z + ` importZipFile('${o}');`
|
|
1226
1252
|
});
|
|
1227
1253
|
if (v.exitCode !== 0)
|
|
1228
1254
|
throw v.errors;
|
|
@@ -1241,17 +1267,17 @@ async function Ae(t, e = "admin", n = "password") {
|
|
|
1241
1267
|
}
|
|
1242
1268
|
});
|
|
1243
1269
|
}
|
|
1244
|
-
function
|
|
1270
|
+
function S(t) {
|
|
1245
1271
|
return new DOMParser().parseFromString(t.text, "text/html");
|
|
1246
1272
|
}
|
|
1247
1273
|
function te(t) {
|
|
1248
1274
|
const e = t.split(".").shift().replace("-", " ");
|
|
1249
1275
|
return e.charAt(0).toUpperCase() + e.slice(1).toLowerCase();
|
|
1250
1276
|
}
|
|
1251
|
-
async function
|
|
1277
|
+
async function Se(t, e, n = {}) {
|
|
1252
1278
|
const r = "activate" in n ? n.activate : !0, o = await t.request({
|
|
1253
1279
|
url: "/wp-admin/theme-install.php"
|
|
1254
|
-
}), a =
|
|
1280
|
+
}), a = S(o), i = new FormData(
|
|
1255
1281
|
a.querySelector(".wp-upload-form")
|
|
1256
1282
|
), { themezip: d, ...c } = Object.fromEntries(
|
|
1257
1283
|
i.entries()
|
|
@@ -1262,7 +1288,7 @@ async function Re(t, e, n = {}) {
|
|
|
1262
1288
|
files: { themezip: e }
|
|
1263
1289
|
});
|
|
1264
1290
|
if (r) {
|
|
1265
|
-
const l =
|
|
1291
|
+
const l = S(s), h = l.querySelector(
|
|
1266
1292
|
"#wpbody-content > .wrap"
|
|
1267
1293
|
);
|
|
1268
1294
|
if (h?.textContent?.includes(
|
|
@@ -1278,19 +1304,19 @@ async function Re(t, e, n = {}) {
|
|
|
1278
1304
|
console.error('The "activate" button was not found.');
|
|
1279
1305
|
return;
|
|
1280
1306
|
}
|
|
1281
|
-
const p = u.attributes.getNamedItem("href").value,
|
|
1307
|
+
const p = u.attributes.getNamedItem("href").value, x = new URL(
|
|
1282
1308
|
p,
|
|
1283
1309
|
await t.pathToInternalUrl("/wp-admin/")
|
|
1284
1310
|
).toString();
|
|
1285
1311
|
await t.request({
|
|
1286
|
-
url:
|
|
1312
|
+
url: x
|
|
1287
1313
|
});
|
|
1288
1314
|
}
|
|
1289
1315
|
}
|
|
1290
|
-
async function
|
|
1316
|
+
async function _e(t, e, n = {}) {
|
|
1291
1317
|
const r = "activate" in n ? n.activate : !0, o = await t.request({
|
|
1292
1318
|
url: "/wp-admin/plugin-install.php?tab=upload"
|
|
1293
|
-
}), a =
|
|
1319
|
+
}), a = S(o), i = new FormData(
|
|
1294
1320
|
a.querySelector(".wp-upload-form")
|
|
1295
1321
|
), { pluginzip: d, ...c } = Object.fromEntries(
|
|
1296
1322
|
i.entries()
|
|
@@ -1301,7 +1327,7 @@ async function Se(t, e, n = {}) {
|
|
|
1301
1327
|
files: { pluginzip: e }
|
|
1302
1328
|
});
|
|
1303
1329
|
if (r) {
|
|
1304
|
-
const u =
|
|
1330
|
+
const u = S(s).querySelector("#wpbody-content .button.button-primary").attributes.getNamedItem("href").value, p = new URL(
|
|
1305
1331
|
u,
|
|
1306
1332
|
await t.pathToInternalUrl("/wp-admin/")
|
|
1307
1333
|
).toString();
|
|
@@ -1330,7 +1356,7 @@ async function Se(t, e, n = {}) {
|
|
|
1330
1356
|
));
|
|
1331
1357
|
}
|
|
1332
1358
|
async function Le(t, e) {
|
|
1333
|
-
const o =
|
|
1359
|
+
const o = S(
|
|
1334
1360
|
await t.request({
|
|
1335
1361
|
url: "/wp-admin/plugins.php"
|
|
1336
1362
|
})
|
|
@@ -1395,7 +1421,7 @@ async function Ue(t, e, n = 100, r) {
|
|
|
1395
1421
|
), r.slowlyIncrementBy(n / 2)), o.status === 200) {
|
|
1396
1422
|
const a = new File([await o.blob()], e);
|
|
1397
1423
|
try {
|
|
1398
|
-
await
|
|
1424
|
+
await Se(t, a);
|
|
1399
1425
|
} catch (i) {
|
|
1400
1426
|
console.error(
|
|
1401
1427
|
`Proceeding without the ${e} theme. Could not install it in wp-admin. The original error was: ${i}`
|
|
@@ -1431,7 +1457,7 @@ async function Ie(t, e, n = 100, r) {
|
|
|
1431
1457
|
if (c.detail) {
|
|
1432
1458
|
r?.slowlyIncrementBy(i * 0.33);
|
|
1433
1459
|
try {
|
|
1434
|
-
await
|
|
1460
|
+
await _e(t, c.detail);
|
|
1435
1461
|
} catch (s) {
|
|
1436
1462
|
console.error(
|
|
1437
1463
|
`Proceeding without the ${c.detail.name} plugin. Could not install it in wp-admin. The original error was: ${s}`
|
|
@@ -1471,7 +1497,7 @@ class Z extends EventTarget {
|
|
|
1471
1497
|
}
|
|
1472
1498
|
}
|
|
1473
1499
|
}
|
|
1474
|
-
async function
|
|
1500
|
+
async function De(t, e) {
|
|
1475
1501
|
e?.loadRemote && (t.src = e?.loadRemote, await new Promise((r) => {
|
|
1476
1502
|
t.addEventListener("load", r, !1);
|
|
1477
1503
|
}));
|
|
@@ -1480,12 +1506,12 @@ async function qe(t, e) {
|
|
|
1480
1506
|
}
|
|
1481
1507
|
export {
|
|
1482
1508
|
Le as activatePlugin,
|
|
1483
|
-
|
|
1509
|
+
De as connectPlayground,
|
|
1484
1510
|
ke as exportFile,
|
|
1485
1511
|
Oe as importFile,
|
|
1486
|
-
|
|
1512
|
+
_e as installPlugin,
|
|
1487
1513
|
Ie as installPluginsFromDirectory,
|
|
1488
|
-
|
|
1514
|
+
Se as installTheme,
|
|
1489
1515
|
Ue as installThemeFromDirectory,
|
|
1490
1516
|
Ae as login
|
|
1491
1517
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wp-playground/client",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.22",
|
|
4
4
|
"description": "WordPress Playground client",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -29,5 +29,5 @@
|
|
|
29
29
|
"type": "module",
|
|
30
30
|
"main": "index.js",
|
|
31
31
|
"types": "index.d.ts",
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "01162caec209df3af47050e3fc9a4af30886166e"
|
|
33
33
|
}
|