@php-wasm/web 0.9.45 → 0.9.46
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.js +38 -23
- package/lib/register-service-worker.d.ts +14 -5
- package/package.json +7 -7
package/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PHPResponse as D, LatestSupportedPHPVersion as R, loadPHPRuntime as L, FSHelpers as p, __private__dont__use as P } from "@php-wasm/universal";
|
|
2
2
|
import * as f from "comlink";
|
|
3
|
-
import { PhpWasmError as y, Semaphore as z, joinPaths as
|
|
3
|
+
import { PhpWasmError as y, Semaphore as z, joinPaths as T } from "@php-wasm/util";
|
|
4
4
|
import { responseTo as M } from "@php-wasm/web-service-worker";
|
|
5
5
|
import { logger as h } from "@php-wasm/logger";
|
|
6
6
|
import { journalFSEvents as O } from "@php-wasm/fs-journal";
|
|
@@ -169,33 +169,48 @@ function ee(r) {
|
|
|
169
169
|
throw new y("PHP API client must be a valid client object.");
|
|
170
170
|
b(r);
|
|
171
171
|
}
|
|
172
|
-
async function te(r
|
|
173
|
-
const
|
|
174
|
-
if (!
|
|
172
|
+
async function te(r) {
|
|
173
|
+
const t = navigator.serviceWorker;
|
|
174
|
+
if (!t)
|
|
175
175
|
throw window.isSecureContext ? new y(
|
|
176
176
|
"Service workers are not supported in your browser."
|
|
177
177
|
) : new y(
|
|
178
178
|
"WordPress Playground uses service workers and may only work on HTTPS and http://localhost/ sites, but the current site is neither."
|
|
179
179
|
);
|
|
180
|
-
const
|
|
180
|
+
const e = await t.register(r, {
|
|
181
181
|
type: "module",
|
|
182
182
|
// Always bypass HTTP cache when fetching the new Service Worker script:
|
|
183
183
|
updateViaCache: "none"
|
|
184
184
|
});
|
|
185
185
|
try {
|
|
186
|
-
await
|
|
187
|
-
} catch (
|
|
188
|
-
h.error("Failed to update service worker.",
|
|
186
|
+
await e.update();
|
|
187
|
+
} catch (n) {
|
|
188
|
+
h.error("Failed to update service worker.", n);
|
|
189
189
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
190
|
+
return {
|
|
191
|
+
/**
|
|
192
|
+
* Establishes the communication bridge between the service worker and the web worker
|
|
193
|
+
* where the current site is running.
|
|
194
|
+
*
|
|
195
|
+
* @param scope The string prefix used in the site URL served by the currently
|
|
196
|
+
* running remote.html. E.g. for a prefix like `/scope:playground/`,
|
|
197
|
+
* the scope would be `playground`. See the `@php-wasm/scopes` package
|
|
198
|
+
* for more details.
|
|
199
|
+
*/
|
|
200
|
+
startServiceWorkerCommunicationBridge({ scope: n }) {
|
|
201
|
+
navigator.serviceWorker.addEventListener(
|
|
202
|
+
"message",
|
|
203
|
+
async function(i) {
|
|
204
|
+
if (n && i.data.scope !== n)
|
|
205
|
+
return;
|
|
206
|
+
const s = await $, o = i.data.args || [], c = i.data.method, u = await s[c](...o);
|
|
207
|
+
i.source.postMessage(
|
|
208
|
+
M(i.data.requestId, u)
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
), t.startMessages();
|
|
197
212
|
}
|
|
198
|
-
|
|
213
|
+
};
|
|
199
214
|
}
|
|
200
215
|
function re(r, t) {
|
|
201
216
|
window.addEventListener("message", (e) => {
|
|
@@ -247,7 +262,7 @@ async function q(r, t, e) {
|
|
|
247
262
|
const [s, o] = i.pop();
|
|
248
263
|
for await (const c of s.values()) {
|
|
249
264
|
const u = n.run(async () => {
|
|
250
|
-
const w =
|
|
265
|
+
const w = T(
|
|
251
266
|
o,
|
|
252
267
|
c.name
|
|
253
268
|
);
|
|
@@ -286,7 +301,7 @@ async function x(r, t, e, n) {
|
|
|
286
301
|
r.readdir(w).filter(
|
|
287
302
|
(d) => d !== "." && d !== ".."
|
|
288
303
|
).map(async (d) => {
|
|
289
|
-
const m =
|
|
304
|
+
const m = T(w, d);
|
|
290
305
|
if (!F(r, m)) {
|
|
291
306
|
a.push([l, m, d]);
|
|
292
307
|
return;
|
|
@@ -300,7 +315,7 @@ async function x(r, t, e, n) {
|
|
|
300
315
|
}
|
|
301
316
|
await i(e, t);
|
|
302
317
|
let s = 0;
|
|
303
|
-
const o = n &&
|
|
318
|
+
const o = n && B(n, 100), c = 100, u = /* @__PURE__ */ new Set();
|
|
304
319
|
try {
|
|
305
320
|
for (const [w, l, d] of a) {
|
|
306
321
|
const m = C(
|
|
@@ -375,7 +390,7 @@ class j {
|
|
|
375
390
|
async processEntry(t) {
|
|
376
391
|
if (!t.path.startsWith(this.memfsRoot) || t.path === this.memfsRoot)
|
|
377
392
|
return;
|
|
378
|
-
const e = this.toOpfsPath(t.path), n = await
|
|
393
|
+
const e = this.toOpfsPath(t.path), n = await W(this.opfs, e), a = H(e);
|
|
379
394
|
if (a)
|
|
380
395
|
try {
|
|
381
396
|
if (t.operation === "DELETE")
|
|
@@ -399,7 +414,7 @@ class j {
|
|
|
399
414
|
t.path
|
|
400
415
|
);
|
|
401
416
|
else if (t.operation === "RENAME" && t.toPath.startsWith(this.memfsRoot)) {
|
|
402
|
-
const i = this.toOpfsPath(t.toPath), s = await
|
|
417
|
+
const i = this.toOpfsPath(t.toPath), s = await W(
|
|
403
418
|
this.opfs,
|
|
404
419
|
i
|
|
405
420
|
), o = H(i);
|
|
@@ -431,7 +446,7 @@ function k(r) {
|
|
|
431
446
|
function H(r) {
|
|
432
447
|
return r.substring(r.lastIndexOf("/") + 1);
|
|
433
448
|
}
|
|
434
|
-
async function
|
|
449
|
+
async function W(r, t) {
|
|
435
450
|
const e = t.replace(/^\/+|\/+$/g, "").replace(/\/+/, "/");
|
|
436
451
|
if (!e)
|
|
437
452
|
return r;
|
|
@@ -443,7 +458,7 @@ async function T(r, t) {
|
|
|
443
458
|
}
|
|
444
459
|
return a;
|
|
445
460
|
}
|
|
446
|
-
function
|
|
461
|
+
function B(r, t) {
|
|
447
462
|
let e = 0, n, a;
|
|
448
463
|
return function(...s) {
|
|
449
464
|
a = s;
|
|
@@ -15,10 +15,19 @@ export declare function setPhpInstanceUsedByServiceWorker(api: Client): void;
|
|
|
15
15
|
* reload the registered worker if the app expects a different version
|
|
16
16
|
* than the currently registered one.
|
|
17
17
|
*
|
|
18
|
-
* @param scope The numeric value used in the path prefix of the site
|
|
19
|
-
* this service worker is meant to serve. E.g. for a prefix
|
|
20
|
-
* like `/scope:793/`, the scope would be `793`. See the
|
|
21
|
-
* `@php-wasm/scopes` package for more details.
|
|
22
18
|
* @param scriptUrl The URL of the service worker script.
|
|
23
19
|
*/
|
|
24
|
-
export declare function registerServiceWorker(
|
|
20
|
+
export declare function registerServiceWorker(scriptUrl: string): Promise<{
|
|
21
|
+
/**
|
|
22
|
+
* Establishes the communication bridge between the service worker and the web worker
|
|
23
|
+
* where the current site is running.
|
|
24
|
+
*
|
|
25
|
+
* @param scope The string prefix used in the site URL served by the currently
|
|
26
|
+
* running remote.html. E.g. for a prefix like `/scope:playground/`,
|
|
27
|
+
* the scope would be `playground`. See the `@php-wasm/scopes` package
|
|
28
|
+
* for more details.
|
|
29
|
+
*/
|
|
30
|
+
startServiceWorkerCommunicationBridge({ scope }: {
|
|
31
|
+
scope: string;
|
|
32
|
+
}): void;
|
|
33
|
+
}>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@php-wasm/web",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.46",
|
|
4
4
|
"description": "PHP.wasm for the web",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"type": "module",
|
|
30
30
|
"main": "index.js",
|
|
31
31
|
"types": "index.d.ts",
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "fa393bcf69536e421246aa8e321e3e9af4b61c7b",
|
|
33
33
|
"engines": {
|
|
34
34
|
"node": ">=16.15.1",
|
|
35
35
|
"npm": ">=8.11.0"
|
|
@@ -40,10 +40,10 @@
|
|
|
40
40
|
"ini": "4.1.2",
|
|
41
41
|
"ws": "8.18.0",
|
|
42
42
|
"yargs": "17.7.2",
|
|
43
|
-
"@php-wasm/universal": "0.9.
|
|
44
|
-
"@php-wasm/util": "0.9.
|
|
45
|
-
"@php-wasm/logger": "0.9.
|
|
46
|
-
"@php-wasm/fs-journal": "0.9.
|
|
47
|
-
"@php-wasm/web-service-worker": "0.9.
|
|
43
|
+
"@php-wasm/universal": "0.9.46",
|
|
44
|
+
"@php-wasm/util": "0.9.46",
|
|
45
|
+
"@php-wasm/logger": "0.9.46",
|
|
46
|
+
"@php-wasm/fs-journal": "0.9.46",
|
|
47
|
+
"@php-wasm/web-service-worker": "0.9.46"
|
|
48
48
|
}
|
|
49
49
|
}
|