@wp-playground/client 0.1.19 → 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 +12 -4
- package/index.js +135 -129
- package/package.json +2 -2
package/index.d.ts
CHANGED
|
@@ -240,11 +240,11 @@ export interface WithNodeFilesystem {
|
|
|
240
240
|
/**
|
|
241
241
|
* Mounts a Node.js filesystem to a given path in the PHP filesystem.
|
|
242
242
|
*
|
|
243
|
-
* @param
|
|
244
|
-
* @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.
|
|
245
245
|
* @see {@link https://emscripten.org/docs/api_reference/Filesystem-API.html#FS.mount}
|
|
246
246
|
*/
|
|
247
|
-
mount(
|
|
247
|
+
mount(localPath: string | MountSettings, virtualFSPath: string): void;
|
|
248
248
|
}
|
|
249
249
|
export interface WithFilesystem {
|
|
250
250
|
/**
|
|
@@ -254,6 +254,10 @@ export interface WithFilesystem {
|
|
|
254
254
|
*
|
|
255
255
|
* @param path - The directory path to create.
|
|
256
256
|
*/
|
|
257
|
+
mkdir(path: string): void;
|
|
258
|
+
/**
|
|
259
|
+
* @deprecated Use mkdir instead.
|
|
260
|
+
*/
|
|
257
261
|
mkdirTree(path: string): void;
|
|
258
262
|
/**
|
|
259
263
|
* Reads a file from the PHP filesystem and returns it as a string.
|
|
@@ -411,6 +415,8 @@ declare abstract class BasePHP implements WithPHPIniBindings, WithFilesystem, Wi
|
|
|
411
415
|
setSkipShebang(shouldSkip: boolean): void;
|
|
412
416
|
addServerGlobalEntry(key: string, value: string): void;
|
|
413
417
|
/** @inheritDoc */
|
|
418
|
+
mkdir(path: string): void;
|
|
419
|
+
/** @inheritDoc */
|
|
414
420
|
mkdirTree(path: string): void;
|
|
415
421
|
/** @inheritDoc */
|
|
416
422
|
readFileAsText(path: string): string;
|
|
@@ -427,7 +433,7 @@ declare abstract class BasePHP implements WithPHPIniBindings, WithFilesystem, Wi
|
|
|
427
433
|
/** @inheritDoc */
|
|
428
434
|
fileExists(path: string): boolean;
|
|
429
435
|
/** @inheritDoc */
|
|
430
|
-
mount(
|
|
436
|
+
mount(localPath: string | MountSettings, virtualFSPath: string): void;
|
|
431
437
|
}
|
|
432
438
|
declare const SupportedPHPVersions: readonly [
|
|
433
439
|
"8.2",
|
|
@@ -553,6 +559,8 @@ declare class PHPClient implements Promisify<WithPHPIniBindings & WithFilesystem
|
|
|
553
559
|
setPhpIniPath(path: string): void;
|
|
554
560
|
/** @inheritDoc @php-wasm/web!PHP.setPhpIniEntry */
|
|
555
561
|
setPhpIniEntry(key: string, value: string): void;
|
|
562
|
+
/** @inheritDoc @php-wasm/web!PHP.mkdir */
|
|
563
|
+
mkdir(path: string): void;
|
|
556
564
|
/** @inheritDoc @php-wasm/web!PHP.mkdirTree */
|
|
557
565
|
mkdirTree(path: string): void;
|
|
558
566
|
/** @inheritDoc @php-wasm/web!PHP.readFileAsText */
|
package/index.js
CHANGED
|
@@ -35,13 +35,13 @@ class re {
|
|
|
35
35
|
}
|
|
36
36
|
});
|
|
37
37
|
if (r.headers["set-cookie"] && this.#n(r.headers["set-cookie"]), this.#t.handleRedirects && r.headers.location && n < this.#t.maxRedirects) {
|
|
38
|
-
const
|
|
38
|
+
const o = new URL(
|
|
39
39
|
r.headers.location[0],
|
|
40
40
|
this.server.absoluteUrl
|
|
41
41
|
);
|
|
42
42
|
return this.request(
|
|
43
43
|
{
|
|
44
|
-
url:
|
|
44
|
+
url: o.toString(),
|
|
45
45
|
method: "GET",
|
|
46
46
|
headers: {}
|
|
47
47
|
},
|
|
@@ -55,8 +55,8 @@ class re {
|
|
|
55
55
|
try {
|
|
56
56
|
if (!n.includes("="))
|
|
57
57
|
continue;
|
|
58
|
-
const r = n.indexOf("="),
|
|
59
|
-
this.#e[
|
|
58
|
+
const r = n.indexOf("="), o = n.substring(0, r), a = n.substring(r + 1).split(";")[0];
|
|
59
|
+
this.#e[o] = a;
|
|
60
60
|
} catch (r) {
|
|
61
61
|
console.error(r);
|
|
62
62
|
}
|
|
@@ -68,14 +68,14 @@ class re {
|
|
|
68
68
|
return e.join("; ");
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
|
-
const
|
|
72
|
-
function
|
|
71
|
+
const oe = "http://example.com";
|
|
72
|
+
function j(t) {
|
|
73
73
|
return t.toString().substring(t.origin.length);
|
|
74
74
|
}
|
|
75
|
-
function
|
|
75
|
+
function B(t, e) {
|
|
76
76
|
return !e || !t.startsWith(e) ? t : t.substring(e.length);
|
|
77
77
|
}
|
|
78
|
-
function
|
|
78
|
+
function ie(t, e) {
|
|
79
79
|
return !e || t.startsWith(e) ? t : e + t;
|
|
80
80
|
}
|
|
81
81
|
class se {
|
|
@@ -96,8 +96,8 @@ class se {
|
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
class E {
|
|
99
|
-
constructor(e, n, r,
|
|
100
|
-
this.httpStatusCode = e, this.headers = n, this.bytes = r, this.exitCode = a, this.errors =
|
|
99
|
+
constructor(e, n, r, o = "", a = 0) {
|
|
100
|
+
this.httpStatusCode = e, this.headers = n, this.bytes = r, this.exitCode = a, this.errors = o;
|
|
101
101
|
}
|
|
102
102
|
static fromRawData(e) {
|
|
103
103
|
return new E(
|
|
@@ -135,8 +135,8 @@ class ae {
|
|
|
135
135
|
#t;
|
|
136
136
|
#n;
|
|
137
137
|
#r;
|
|
138
|
-
#o;
|
|
139
138
|
#i;
|
|
139
|
+
#o;
|
|
140
140
|
#s;
|
|
141
141
|
#a;
|
|
142
142
|
#l;
|
|
@@ -148,20 +148,20 @@ class ae {
|
|
|
148
148
|
this.#a = new se({ concurrency: 1 });
|
|
149
149
|
const {
|
|
150
150
|
documentRoot: r = "/www/",
|
|
151
|
-
absoluteUrl:
|
|
151
|
+
absoluteUrl: o = typeof location == "object" ? location?.href : "",
|
|
152
152
|
isStaticFilePath: a = () => !1
|
|
153
153
|
} = n;
|
|
154
154
|
this.php = e, this.#e = r, this.#l = a;
|
|
155
|
-
const
|
|
156
|
-
this.#n =
|
|
155
|
+
const i = new URL(o);
|
|
156
|
+
this.#n = i.hostname, this.#r = i.port ? Number(i.port) : i.protocol === "https:" ? 443 : 80, this.#t = (i.protocol || "").replace(":", "");
|
|
157
157
|
const d = this.#r !== 443 && this.#r !== 80;
|
|
158
|
-
this.#
|
|
158
|
+
this.#i = [
|
|
159
159
|
this.#n,
|
|
160
160
|
d ? `:${this.#r}` : ""
|
|
161
|
-
].join(""), this.#
|
|
161
|
+
].join(""), this.#o = i.pathname.replace(/\/+$/, ""), this.#s = [
|
|
162
162
|
`${this.#t}://`,
|
|
163
|
-
this.#
|
|
164
|
-
this.#
|
|
163
|
+
this.#i,
|
|
164
|
+
this.#o
|
|
165
165
|
].join("");
|
|
166
166
|
}
|
|
167
167
|
/**
|
|
@@ -183,7 +183,7 @@ class ae {
|
|
|
183
183
|
*/
|
|
184
184
|
internalUrlToPath(e) {
|
|
185
185
|
const n = new URL(e);
|
|
186
|
-
return n.pathname.startsWith(this.#
|
|
186
|
+
return n.pathname.startsWith(this.#o) && (n.pathname = n.pathname.slice(this.#o.length)), j(n);
|
|
187
187
|
}
|
|
188
188
|
get isRequestRunning() {
|
|
189
189
|
return this.#a.running > 0;
|
|
@@ -210,12 +210,12 @@ class ae {
|
|
|
210
210
|
async request(e) {
|
|
211
211
|
const n = e.url.startsWith("http://") || e.url.startsWith("https://"), r = new URL(
|
|
212
212
|
e.url,
|
|
213
|
-
n ? void 0 :
|
|
214
|
-
),
|
|
213
|
+
n ? void 0 : oe
|
|
214
|
+
), o = B(
|
|
215
215
|
r.pathname,
|
|
216
|
-
this.#
|
|
216
|
+
this.#o
|
|
217
217
|
);
|
|
218
|
-
return this.#l(
|
|
218
|
+
return this.#l(o) ? this.#c(o) : await this.#u(e, r);
|
|
219
219
|
}
|
|
220
220
|
/**
|
|
221
221
|
* Serves a static file from the PHP filesystem.
|
|
@@ -260,10 +260,10 @@ class ae {
|
|
|
260
260
|
"HTTPS",
|
|
261
261
|
this.#s.startsWith("https://") ? "on" : ""
|
|
262
262
|
);
|
|
263
|
-
let
|
|
263
|
+
let o = "GET";
|
|
264
264
|
const a = [];
|
|
265
265
|
if (e.files) {
|
|
266
|
-
|
|
266
|
+
o = "POST";
|
|
267
267
|
for (const c in e.files) {
|
|
268
268
|
const s = e.files[c];
|
|
269
269
|
a.push({
|
|
@@ -274,24 +274,24 @@ class ae {
|
|
|
274
274
|
});
|
|
275
275
|
}
|
|
276
276
|
}
|
|
277
|
-
const
|
|
278
|
-
host: this.#
|
|
277
|
+
const i = {
|
|
278
|
+
host: this.#i
|
|
279
279
|
};
|
|
280
280
|
let d;
|
|
281
|
-
return e.formData !== void 0 ? (
|
|
281
|
+
return e.formData !== void 0 ? (o = "POST", i["content-type"] = "application/x-www-form-urlencoded", d = new URLSearchParams(
|
|
282
282
|
e.formData
|
|
283
283
|
).toString()) : d = e.body, await this.php.run({
|
|
284
|
-
relativeUri:
|
|
285
|
-
|
|
286
|
-
this.#
|
|
284
|
+
relativeUri: ie(
|
|
285
|
+
j(n),
|
|
286
|
+
this.#o
|
|
287
287
|
),
|
|
288
288
|
protocol: this.#t,
|
|
289
|
-
method: e.method ||
|
|
289
|
+
method: e.method || o,
|
|
290
290
|
body: d,
|
|
291
291
|
fileInfos: a,
|
|
292
292
|
scriptPath: this.#d(n.pathname),
|
|
293
293
|
headers: {
|
|
294
|
-
...
|
|
294
|
+
...i,
|
|
295
295
|
...e.headers || {}
|
|
296
296
|
}
|
|
297
297
|
});
|
|
@@ -308,7 +308,7 @@ class ae {
|
|
|
308
308
|
* @returns The resolved filesystem path.
|
|
309
309
|
*/
|
|
310
310
|
#d(e) {
|
|
311
|
-
let n =
|
|
311
|
+
let n = B(e, this.#o);
|
|
312
312
|
n.includes(".php") ? n = n.split(".php")[0] + ".php" : (n.endsWith("/") || (n += "/"), n.endsWith("index.php") || (n += "index.php"));
|
|
313
313
|
const r = `${this.#e}${n}`;
|
|
314
314
|
return this.php.fileExists(r) ? r : `${this.#e}/index.php`;
|
|
@@ -434,15 +434,15 @@ const W = {
|
|
|
434
434
|
76: "Extension: Capabilities insufficient."
|
|
435
435
|
};
|
|
436
436
|
function m(t = "") {
|
|
437
|
-
return function(n, r,
|
|
438
|
-
const a =
|
|
439
|
-
|
|
437
|
+
return function(n, r, o) {
|
|
438
|
+
const a = o.value;
|
|
439
|
+
o.value = function(...i) {
|
|
440
440
|
try {
|
|
441
|
-
return a.apply(this,
|
|
441
|
+
return a.apply(this, i);
|
|
442
442
|
} catch (d) {
|
|
443
443
|
const c = typeof d == "object" ? d?.errno : null;
|
|
444
444
|
if (c in W) {
|
|
445
|
-
const s = W[c], l = typeof
|
|
445
|
+
const s = W[c], l = typeof i[0] == "string" ? i[0] : null, h = l !== null ? t.replaceAll("{path}", l) : t;
|
|
446
446
|
throw new Error(`${h}: ${s}`, {
|
|
447
447
|
cause: d
|
|
448
448
|
});
|
|
@@ -453,9 +453,9 @@ function m(t = "") {
|
|
|
453
453
|
};
|
|
454
454
|
}
|
|
455
455
|
var ce = Object.defineProperty, ue = Object.getOwnPropertyDescriptor, w = (t, e, n, r) => {
|
|
456
|
-
for (var
|
|
457
|
-
(
|
|
458
|
-
return r &&
|
|
456
|
+
for (var o = r > 1 ? void 0 : r ? ue(e, n) : e, a = t.length - 1, i; a >= 0; a--)
|
|
457
|
+
(i = t[a]) && (o = (r ? i(e, n, o) : i(o)) || o);
|
|
458
|
+
return r && o && ce(e, n, o), o;
|
|
459
459
|
};
|
|
460
460
|
const f = "string", y = "number", G = [];
|
|
461
461
|
(function() {
|
|
@@ -508,14 +508,14 @@ class g {
|
|
|
508
508
|
}
|
|
509
509
|
/** @inheritDoc */
|
|
510
510
|
async run(e = {}) {
|
|
511
|
-
this.#n || (this.#r(), this.#n = !0), this.#u(e.scriptPath || ""), this.#
|
|
511
|
+
this.#n || (this.#r(), this.#n = !0), this.#u(e.scriptPath || ""), this.#o(e.relativeUri || ""), this.#a(e.method || "GET");
|
|
512
512
|
const { host: n, ...r } = {
|
|
513
513
|
host: "example.com:443",
|
|
514
514
|
...de(e.headers || {})
|
|
515
515
|
};
|
|
516
516
|
if (this.#s(n, e.protocol || "http"), this.#l(r), e.body && this.#c(e.body), e.fileInfos)
|
|
517
|
-
for (const
|
|
518
|
-
this.#d(
|
|
517
|
+
for (const o of e.fileInfos)
|
|
518
|
+
this.#d(o);
|
|
519
519
|
return e.code && this.#h(" ?>" + e.code), await this.#p();
|
|
520
520
|
}
|
|
521
521
|
#r() {
|
|
@@ -538,25 +538,25 @@ class g {
|
|
|
538
538
|
this.#e.ccall("wasm_add_cli_arg", null, [f], [n]);
|
|
539
539
|
return this.#e.ccall("run_cli", null, [], [], { async: !0 });
|
|
540
540
|
}
|
|
541
|
-
#
|
|
541
|
+
#i() {
|
|
542
542
|
const e = "/tmp/headers.json";
|
|
543
543
|
if (!this.fileExists(e))
|
|
544
544
|
throw new Error(
|
|
545
545
|
"SAPI Error: Could not find response headers file."
|
|
546
546
|
);
|
|
547
547
|
const n = JSON.parse(this.readFileAsText(e)), r = {};
|
|
548
|
-
for (const
|
|
549
|
-
if (!
|
|
548
|
+
for (const o of n.headers) {
|
|
549
|
+
if (!o.includes(": "))
|
|
550
550
|
continue;
|
|
551
|
-
const a =
|
|
552
|
-
|
|
551
|
+
const a = o.indexOf(": "), i = o.substring(0, a).toLowerCase(), d = o.substring(a + 2);
|
|
552
|
+
i in r || (r[i] = []), r[i].push(d);
|
|
553
553
|
}
|
|
554
554
|
return {
|
|
555
555
|
headers: r,
|
|
556
556
|
httpStatusCode: n.status
|
|
557
557
|
};
|
|
558
558
|
}
|
|
559
|
-
#
|
|
559
|
+
#o(e) {
|
|
560
560
|
if (this.#e.ccall("wasm_set_request_uri", null, [f], [e]), e.includes("?")) {
|
|
561
561
|
const n = e.substring(e.indexOf("?") + 1);
|
|
562
562
|
this.#e.ccall(
|
|
@@ -639,14 +639,14 @@ class g {
|
|
|
639
639
|
* @param fileInfo - File details
|
|
640
640
|
*/
|
|
641
641
|
#d(e) {
|
|
642
|
-
const { key: n, name: r, type:
|
|
643
|
-
this.writeFile(
|
|
642
|
+
const { key: n, name: r, type: o, data: a } = e, i = `/tmp/${Math.random().toFixed(20)}`;
|
|
643
|
+
this.writeFile(i, a);
|
|
644
644
|
const d = 0;
|
|
645
645
|
this.#e.ccall(
|
|
646
646
|
"wasm_add_uploaded_file",
|
|
647
647
|
null,
|
|
648
648
|
[f, f, f, f, y, y],
|
|
649
|
-
[n, r,
|
|
649
|
+
[n, r, o, i, d, a.byteLength]
|
|
650
650
|
);
|
|
651
651
|
}
|
|
652
652
|
#h(e) {
|
|
@@ -658,7 +658,7 @@ class g {
|
|
|
658
658
|
y,
|
|
659
659
|
[],
|
|
660
660
|
[]
|
|
661
|
-
), { headers: n, httpStatusCode: r } = this.#
|
|
661
|
+
), { headers: n, httpStatusCode: r } = this.#i();
|
|
662
662
|
return new E(
|
|
663
663
|
r,
|
|
664
664
|
n,
|
|
@@ -667,9 +667,12 @@ class g {
|
|
|
667
667
|
e
|
|
668
668
|
);
|
|
669
669
|
}
|
|
670
|
-
|
|
670
|
+
mkdir(e) {
|
|
671
671
|
this.#e.FS.mkdirTree(e);
|
|
672
672
|
}
|
|
673
|
+
mkdirTree(e) {
|
|
674
|
+
this.mkdir(e);
|
|
675
|
+
}
|
|
673
676
|
readFileAsText(e) {
|
|
674
677
|
return new TextDecoder().decode(this.readFileAsBuffer(e));
|
|
675
678
|
}
|
|
@@ -708,11 +711,14 @@ class g {
|
|
|
708
711
|
mount(e, n) {
|
|
709
712
|
this.#e.FS.mount(
|
|
710
713
|
this.#e.FS.filesystems.NODEFS,
|
|
711
|
-
e,
|
|
714
|
+
typeof e == "object" ? e : { root: e },
|
|
712
715
|
n
|
|
713
716
|
);
|
|
714
717
|
}
|
|
715
718
|
}
|
|
719
|
+
w([
|
|
720
|
+
m('Could not create directory "{path}"')
|
|
721
|
+
], g.prototype, "mkdir", 1);
|
|
716
722
|
w([
|
|
717
723
|
m('Could not create directory "{path}"')
|
|
718
724
|
], g.prototype, "mkdirTree", 1);
|
|
@@ -787,23 +793,23 @@ function we(t, e) {
|
|
|
787
793
|
return !1;
|
|
788
794
|
}
|
|
789
795
|
function N(t, e = globalThis, n = ["*"]) {
|
|
790
|
-
e.addEventListener("message", function r(
|
|
791
|
-
if (!
|
|
796
|
+
e.addEventListener("message", function r(o) {
|
|
797
|
+
if (!o || !o.data)
|
|
792
798
|
return;
|
|
793
|
-
if (!we(n,
|
|
794
|
-
console.warn(`Invalid origin '${
|
|
799
|
+
if (!we(n, o.origin)) {
|
|
800
|
+
console.warn(`Invalid origin '${o.origin}' for comlink proxy`);
|
|
795
801
|
return;
|
|
796
802
|
}
|
|
797
|
-
const { id: a, type:
|
|
803
|
+
const { id: a, type: i, path: d } = Object.assign({ path: [] }, o.data), c = (o.data.argumentList || []).map(b);
|
|
798
804
|
let s;
|
|
799
805
|
try {
|
|
800
806
|
const l = d.slice(0, -1).reduce((u, p) => u[p], t), h = d.reduce((u, p) => u[p], t);
|
|
801
|
-
switch (
|
|
807
|
+
switch (i) {
|
|
802
808
|
case "GET":
|
|
803
809
|
s = h;
|
|
804
810
|
break;
|
|
805
811
|
case "SET":
|
|
806
|
-
l[d.slice(-1)[0]] = b(
|
|
812
|
+
l[d.slice(-1)[0]] = b(o.data.value), s = !0;
|
|
807
813
|
break;
|
|
808
814
|
case "APPLY":
|
|
809
815
|
s = h.apply(l, c);
|
|
@@ -831,7 +837,7 @@ function N(t, e = globalThis, n = ["*"]) {
|
|
|
831
837
|
}
|
|
832
838
|
Promise.resolve(s).catch((l) => ({ value: l, [O]: 0 })).then((l) => {
|
|
833
839
|
const [h, u] = U(l);
|
|
834
|
-
e.postMessage(Object.assign(Object.assign({}, h), { id: a }), u),
|
|
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]());
|
|
835
841
|
}).catch((l) => {
|
|
836
842
|
const [h, u] = U({
|
|
837
843
|
value: new TypeError("Unserializable return value"),
|
|
@@ -875,33 +881,33 @@ function be(t) {
|
|
|
875
881
|
function D(t, e = [], n = function() {
|
|
876
882
|
}) {
|
|
877
883
|
let r = !1;
|
|
878
|
-
const
|
|
879
|
-
get(a,
|
|
880
|
-
if (k(r),
|
|
884
|
+
const o = new Proxy(n, {
|
|
885
|
+
get(a, i) {
|
|
886
|
+
if (k(r), i === pe)
|
|
881
887
|
return () => {
|
|
882
|
-
be(
|
|
888
|
+
be(o), Y(t), r = !0;
|
|
883
889
|
};
|
|
884
|
-
if (
|
|
890
|
+
if (i === "then") {
|
|
885
891
|
if (e.length === 0)
|
|
886
|
-
return { then: () =>
|
|
892
|
+
return { then: () => o };
|
|
887
893
|
const d = P(t, {
|
|
888
894
|
type: "GET",
|
|
889
895
|
path: e.map((c) => c.toString())
|
|
890
896
|
}).then(b);
|
|
891
897
|
return d.then.bind(d);
|
|
892
898
|
}
|
|
893
|
-
return D(t, [...e,
|
|
899
|
+
return D(t, [...e, i]);
|
|
894
900
|
},
|
|
895
|
-
set(a,
|
|
901
|
+
set(a, i, d) {
|
|
896
902
|
k(r);
|
|
897
903
|
const [c, s] = U(d);
|
|
898
904
|
return P(t, {
|
|
899
905
|
type: "SET",
|
|
900
|
-
path: [...e,
|
|
906
|
+
path: [...e, i].map((l) => l.toString()),
|
|
901
907
|
value: c
|
|
902
908
|
}, s).then(b);
|
|
903
909
|
},
|
|
904
|
-
apply(a,
|
|
910
|
+
apply(a, i, d) {
|
|
905
911
|
k(r);
|
|
906
912
|
const c = e[e.length - 1];
|
|
907
913
|
if (c === he)
|
|
@@ -917,9 +923,9 @@ function D(t, e = [], n = function() {
|
|
|
917
923
|
argumentList: s
|
|
918
924
|
}, l).then(b);
|
|
919
925
|
},
|
|
920
|
-
construct(a,
|
|
926
|
+
construct(a, i) {
|
|
921
927
|
k(r);
|
|
922
|
-
const [d, c] = V(
|
|
928
|
+
const [d, c] = V(i);
|
|
923
929
|
return P(t, {
|
|
924
930
|
type: "CONSTRUCT",
|
|
925
931
|
path: e.map((s) => s.toString()),
|
|
@@ -927,7 +933,7 @@ function D(t, e = [], n = function() {
|
|
|
927
933
|
}, c).then(b);
|
|
928
934
|
}
|
|
929
935
|
});
|
|
930
|
-
return ye(
|
|
936
|
+
return ye(o, t), o;
|
|
931
937
|
}
|
|
932
938
|
function ve(t) {
|
|
933
939
|
return Array.prototype.concat.apply([], t);
|
|
@@ -945,7 +951,7 @@ function Ee(t) {
|
|
|
945
951
|
}
|
|
946
952
|
function xe(t, e = globalThis, n = "*") {
|
|
947
953
|
return {
|
|
948
|
-
postMessage: (r,
|
|
954
|
+
postMessage: (r, o) => t.postMessage(r, n, o),
|
|
949
955
|
addEventListener: e.addEventListener.bind(e),
|
|
950
956
|
removeEventListener: e.removeEventListener.bind(e)
|
|
951
957
|
};
|
|
@@ -953,14 +959,14 @@ function xe(t, e = globalThis, n = "*") {
|
|
|
953
959
|
function U(t) {
|
|
954
960
|
for (const [e, n] of R)
|
|
955
961
|
if (n.canHandle(t)) {
|
|
956
|
-
const [r,
|
|
962
|
+
const [r, o] = n.serialize(t);
|
|
957
963
|
return [
|
|
958
964
|
{
|
|
959
965
|
type: "HANDLER",
|
|
960
966
|
name: e,
|
|
961
967
|
value: r
|
|
962
968
|
},
|
|
963
|
-
|
|
969
|
+
o
|
|
964
970
|
];
|
|
965
971
|
}
|
|
966
972
|
return [
|
|
@@ -981,10 +987,10 @@ function b(t) {
|
|
|
981
987
|
}
|
|
982
988
|
function P(t, e, n) {
|
|
983
989
|
return new Promise((r) => {
|
|
984
|
-
const
|
|
985
|
-
t.addEventListener("message", function a(
|
|
986
|
-
!
|
|
987
|
-
}), t.start && t.start(), t.postMessage(Object.assign({ id:
|
|
990
|
+
const o = $e();
|
|
991
|
+
t.addEventListener("message", function a(i) {
|
|
992
|
+
!i.data || !i.data.id || i.data.id !== o || (t.removeEventListener("message", a), r(i.data));
|
|
993
|
+
}), t.start && t.start(), t.postMessage(Object.assign({ id: o }, e), n);
|
|
988
994
|
});
|
|
989
995
|
}
|
|
990
996
|
function $e() {
|
|
@@ -1026,7 +1032,7 @@ function Te() {
|
|
|
1026
1032
|
});
|
|
1027
1033
|
}
|
|
1028
1034
|
(function() {
|
|
1029
|
-
return navigator
|
|
1035
|
+
return navigator?.userAgent?.toLowerCase().indexOf("firefox") > -1 ? "iframe" : "webworker";
|
|
1030
1036
|
})();
|
|
1031
1037
|
var T = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}, q = {}, Re = {
|
|
1032
1038
|
get exports() {
|
|
@@ -1051,7 +1057,7 @@ var T = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : ty
|
|
|
1051
1057
|
console.error("could not download file");
|
|
1052
1058
|
}, u.send();
|
|
1053
1059
|
}
|
|
1054
|
-
function
|
|
1060
|
+
function o(s) {
|
|
1055
1061
|
var l = new XMLHttpRequest();
|
|
1056
1062
|
l.open("HEAD", s, !1);
|
|
1057
1063
|
try {
|
|
@@ -1068,10 +1074,10 @@ var T = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : ty
|
|
|
1068
1074
|
l.initMouseEvent("click", !0, !0, window, 0, 0, 0, 80, 20, !1, !1, !1, !1, 0, null), s.dispatchEvent(l);
|
|
1069
1075
|
}
|
|
1070
1076
|
}
|
|
1071
|
-
var
|
|
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() {
|
|
1072
1078
|
} : "download" in HTMLAnchorElement.prototype && !d ? function(s, l, h) {
|
|
1073
|
-
var u =
|
|
1074
|
-
l = l || s.name || "download", p.download = l, p.rel = "noopener", typeof s == "string" ? (p.href = s, p.origin === location.origin ? a(p) :
|
|
1079
|
+
var u = i.URL || i.webkitURL, p = document.createElement("a");
|
|
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() {
|
|
1075
1081
|
u.revokeObjectURL(p.href);
|
|
1076
1082
|
}, 4e4), setTimeout(function() {
|
|
1077
1083
|
a(p);
|
|
@@ -1079,7 +1085,7 @@ var T = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : ty
|
|
|
1079
1085
|
} : "msSaveOrOpenBlob" in navigator ? function(s, l, h) {
|
|
1080
1086
|
if (l = l || s.name || "download", typeof s != "string")
|
|
1081
1087
|
navigator.msSaveOrOpenBlob(n(s, h), l);
|
|
1082
|
-
else if (
|
|
1088
|
+
else if (o(s))
|
|
1083
1089
|
r(s, l, h);
|
|
1084
1090
|
else {
|
|
1085
1091
|
var u = document.createElement("a");
|
|
@@ -1090,7 +1096,7 @@ var T = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : ty
|
|
|
1090
1096
|
} : function(s, l, h, u) {
|
|
1091
1097
|
if (u = u || open("", "_blank"), u && (u.document.title = u.document.body.innerText = "downloading..."), typeof s == "string")
|
|
1092
1098
|
return r(s, l, h);
|
|
1093
|
-
var p = s.type === "application/octet-stream", x = /constructor/i.test(
|
|
1099
|
+
var p = s.type === "application/octet-stream", x = /constructor/i.test(i.HTMLElement) || i.safari, _ = /CriOS\/[\d]+/.test(navigator.userAgent);
|
|
1094
1100
|
if ((_ || p && x || d) && typeof FileReader < "u") {
|
|
1095
1101
|
var $ = new FileReader();
|
|
1096
1102
|
$.onloadend = function() {
|
|
@@ -1098,13 +1104,13 @@ var T = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : ty
|
|
|
1098
1104
|
F = _ ? F : F.replace(/^data:[^;]*;/, "data:attachment/file;"), u ? u.location.href = F : location = F, u = null;
|
|
1099
1105
|
}, $.readAsDataURL(s);
|
|
1100
1106
|
} else {
|
|
1101
|
-
var C =
|
|
1107
|
+
var C = i.URL || i.webkitURL, v = C.createObjectURL(s);
|
|
1102
1108
|
u ? u.location = v : location.href = v, u = null, setTimeout(function() {
|
|
1103
1109
|
C.revokeObjectURL(v);
|
|
1104
1110
|
}, 4e4);
|
|
1105
1111
|
}
|
|
1106
1112
|
});
|
|
1107
|
-
|
|
1113
|
+
i.saveAs = c.saveAs = c, t.exports = c;
|
|
1108
1114
|
});
|
|
1109
1115
|
})(Re);
|
|
1110
1116
|
const z = `<?php
|
|
@@ -1181,12 +1187,12 @@ async function ke(t) {
|
|
|
1181
1187
|
url: "/wp-admin/export.php?download=true&content=all"
|
|
1182
1188
|
})).text;
|
|
1183
1189
|
await t.writeFile(H, n);
|
|
1184
|
-
const r = await t.wordPressVersion,
|
|
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({
|
|
1185
1191
|
code: z + ` generateZipFile('${d}', '${H}', '${a}');`
|
|
1186
1192
|
});
|
|
1187
1193
|
if (c.exitCode !== 0)
|
|
1188
1194
|
throw c.errors;
|
|
1189
|
-
const s = await t.readFileAsBuffer(
|
|
1195
|
+
const s = await t.readFileAsBuffer(i), l = new File([s], i);
|
|
1190
1196
|
q.saveAs(l);
|
|
1191
1197
|
}
|
|
1192
1198
|
async function Oe(t, e) {
|
|
@@ -1197,17 +1203,17 @@ async function Oe(t, e) {
|
|
|
1197
1203
|
)
|
|
1198
1204
|
)
|
|
1199
1205
|
return !1;
|
|
1200
|
-
const n = await e.arrayBuffer(), r = new Uint8Array(n),
|
|
1201
|
-
await t.writeFile(
|
|
1206
|
+
const n = await e.arrayBuffer(), r = new Uint8Array(n), o = "/import.zip";
|
|
1207
|
+
await t.writeFile(o, r);
|
|
1202
1208
|
const a = await t.run({
|
|
1203
|
-
code: z + ` readFileFromZipArchive('${
|
|
1209
|
+
code: z + ` readFileFromZipArchive('${o}', '${H}');`
|
|
1204
1210
|
});
|
|
1205
1211
|
if (a.exitCode !== 0)
|
|
1206
1212
|
throw a.errors;
|
|
1207
|
-
const
|
|
1213
|
+
const i = new TextDecoder().decode(
|
|
1208
1214
|
a.bytes
|
|
1209
1215
|
), d = new File(
|
|
1210
|
-
[
|
|
1216
|
+
[i],
|
|
1211
1217
|
ee
|
|
1212
1218
|
), c = await t.request({
|
|
1213
1219
|
url: "/wp-admin/admin.php?import=wordpress"
|
|
@@ -1242,7 +1248,7 @@ async function Oe(t, e) {
|
|
|
1242
1248
|
}
|
|
1243
1249
|
});
|
|
1244
1250
|
const v = await t.run({
|
|
1245
|
-
code: z + ` importZipFile('${
|
|
1251
|
+
code: z + ` importZipFile('${o}');`
|
|
1246
1252
|
});
|
|
1247
1253
|
if (v.exitCode !== 0)
|
|
1248
1254
|
throw v.errors;
|
|
@@ -1269,12 +1275,12 @@ function te(t) {
|
|
|
1269
1275
|
return e.charAt(0).toUpperCase() + e.slice(1).toLowerCase();
|
|
1270
1276
|
}
|
|
1271
1277
|
async function Se(t, e, n = {}) {
|
|
1272
|
-
const r = "activate" in n ? n.activate : !0,
|
|
1278
|
+
const r = "activate" in n ? n.activate : !0, o = await t.request({
|
|
1273
1279
|
url: "/wp-admin/theme-install.php"
|
|
1274
|
-
}), a = S(
|
|
1280
|
+
}), a = S(o), i = new FormData(
|
|
1275
1281
|
a.querySelector(".wp-upload-form")
|
|
1276
1282
|
), { themezip: d, ...c } = Object.fromEntries(
|
|
1277
|
-
|
|
1283
|
+
i.entries()
|
|
1278
1284
|
), s = await t.request({
|
|
1279
1285
|
url: "/wp-admin/update.php?action=upload-theme",
|
|
1280
1286
|
method: "POST",
|
|
@@ -1308,12 +1314,12 @@ async function Se(t, e, n = {}) {
|
|
|
1308
1314
|
}
|
|
1309
1315
|
}
|
|
1310
1316
|
async function _e(t, e, n = {}) {
|
|
1311
|
-
const r = "activate" in n ? n.activate : !0,
|
|
1317
|
+
const r = "activate" in n ? n.activate : !0, o = await t.request({
|
|
1312
1318
|
url: "/wp-admin/plugin-install.php?tab=upload"
|
|
1313
|
-
}), a = S(
|
|
1319
|
+
}), a = S(o), i = new FormData(
|
|
1314
1320
|
a.querySelector(".wp-upload-form")
|
|
1315
1321
|
), { pluginzip: d, ...c } = Object.fromEntries(
|
|
1316
|
-
|
|
1322
|
+
i.entries()
|
|
1317
1323
|
), s = await t.request({
|
|
1318
1324
|
url: "/wp-admin/update.php?action=upload-plugin",
|
|
1319
1325
|
method: "POST",
|
|
@@ -1350,7 +1356,7 @@ async function _e(t, e, n = {}) {
|
|
|
1350
1356
|
));
|
|
1351
1357
|
}
|
|
1352
1358
|
async function Le(t, e) {
|
|
1353
|
-
const
|
|
1359
|
+
const o = S(
|
|
1354
1360
|
await t.request({
|
|
1355
1361
|
url: "/wp-admin/plugins.php"
|
|
1356
1362
|
})
|
|
@@ -1358,18 +1364,18 @@ async function Le(t, e) {
|
|
|
1358
1364
|
`tr[data-slug="${e}"] a`
|
|
1359
1365
|
).attributes.getNamedItem("href").value;
|
|
1360
1366
|
await t.request({
|
|
1361
|
-
url: "/wp-admin/" +
|
|
1367
|
+
url: "/wp-admin/" + o
|
|
1362
1368
|
});
|
|
1363
1369
|
}
|
|
1364
1370
|
const Ce = 5 * 1024 * 1024;
|
|
1365
1371
|
function ne(t, e) {
|
|
1366
1372
|
const n = t.headers.get("content-length") || "", r = parseInt(n, 10) || Ce;
|
|
1367
|
-
function
|
|
1373
|
+
function o(a, i) {
|
|
1368
1374
|
e(
|
|
1369
1375
|
new CustomEvent("progress", {
|
|
1370
1376
|
detail: {
|
|
1371
1377
|
loaded: a,
|
|
1372
|
-
total:
|
|
1378
|
+
total: i
|
|
1373
1379
|
}
|
|
1374
1380
|
})
|
|
1375
1381
|
);
|
|
@@ -1381,16 +1387,16 @@ function ne(t, e) {
|
|
|
1381
1387
|
a.close();
|
|
1382
1388
|
return;
|
|
1383
1389
|
}
|
|
1384
|
-
const
|
|
1390
|
+
const i = t.body.getReader();
|
|
1385
1391
|
let d = 0;
|
|
1386
1392
|
for (; ; )
|
|
1387
1393
|
try {
|
|
1388
|
-
const { done: c, value: s } = await
|
|
1394
|
+
const { done: c, value: s } = await i.read();
|
|
1389
1395
|
if (s && (d += s.byteLength), c) {
|
|
1390
|
-
|
|
1396
|
+
o(d, d), a.close();
|
|
1391
1397
|
break;
|
|
1392
1398
|
} else
|
|
1393
|
-
|
|
1399
|
+
o(d, r), a.enqueue(s);
|
|
1394
1400
|
} catch (c) {
|
|
1395
1401
|
console.error({ e: c }), a.error(c);
|
|
1396
1402
|
break;
|
|
@@ -1405,21 +1411,21 @@ function ne(t, e) {
|
|
|
1405
1411
|
);
|
|
1406
1412
|
}
|
|
1407
1413
|
async function Ue(t, e, n = 100, r) {
|
|
1408
|
-
let
|
|
1409
|
-
if (r && (
|
|
1410
|
-
|
|
1414
|
+
let o = await fetch("/plugin-proxy?theme=" + e);
|
|
1415
|
+
if (r && (o = ne(
|
|
1416
|
+
o,
|
|
1411
1417
|
r.partialObserver(
|
|
1412
1418
|
n / 2,
|
|
1413
1419
|
`Installing ${te(e)} theme...`
|
|
1414
1420
|
)
|
|
1415
|
-
), r.slowlyIncrementBy(n / 2)),
|
|
1416
|
-
const a = new File([await
|
|
1421
|
+
), r.slowlyIncrementBy(n / 2)), o.status === 200) {
|
|
1422
|
+
const a = new File([await o.blob()], e);
|
|
1417
1423
|
try {
|
|
1418
1424
|
await Se(t, a);
|
|
1419
|
-
} catch (
|
|
1425
|
+
} catch (i) {
|
|
1420
1426
|
console.error(
|
|
1421
|
-
`Proceeding without the ${e} theme. Could not install it in wp-admin. The original error was: ${
|
|
1422
|
-
), console.error(
|
|
1427
|
+
`Proceeding without the ${e} theme. Could not install it in wp-admin. The original error was: ${i}`
|
|
1428
|
+
), console.error(i);
|
|
1423
1429
|
}
|
|
1424
1430
|
} else
|
|
1425
1431
|
console.error(
|
|
@@ -1427,17 +1433,17 @@ async function Ue(t, e, n = 100, r) {
|
|
|
1427
1433
|
);
|
|
1428
1434
|
}
|
|
1429
1435
|
async function Ie(t, e, n = 100, r) {
|
|
1430
|
-
const
|
|
1436
|
+
const o = new Z(), a = new Z(), i = n / e.length;
|
|
1431
1437
|
await new Promise((d) => {
|
|
1432
1438
|
for (const c of e)
|
|
1433
|
-
|
|
1439
|
+
o.enqueue(async () => {
|
|
1434
1440
|
let s = await fetch(
|
|
1435
1441
|
"/plugin-proxy?plugin=" + c
|
|
1436
1442
|
);
|
|
1437
1443
|
return r && (s = ne(
|
|
1438
1444
|
s,
|
|
1439
1445
|
r.partialObserver(
|
|
1440
|
-
|
|
1446
|
+
i * 0.66,
|
|
1441
1447
|
`Installing ${te(
|
|
1442
1448
|
c
|
|
1443
1449
|
)} plugin...`
|
|
@@ -1446,10 +1452,10 @@ async function Ie(t, e, n = 100, r) {
|
|
|
1446
1452
|
`Proceeding without the ${c} plugin. Could not download the zip bundle from https://downloads.wordpress.org/plugin/${c} – Is the file name correct?`
|
|
1447
1453
|
), null) : new File([await s.blob()], c);
|
|
1448
1454
|
});
|
|
1449
|
-
|
|
1455
|
+
o.addEventListener("resolved", (c) => {
|
|
1450
1456
|
a.enqueue(async () => {
|
|
1451
1457
|
if (c.detail) {
|
|
1452
|
-
r?.slowlyIncrementBy(
|
|
1458
|
+
r?.slowlyIncrementBy(i * 0.33);
|
|
1453
1459
|
try {
|
|
1454
1460
|
await _e(t, c.detail);
|
|
1455
1461
|
} catch (s) {
|
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
|
}
|