@php-wasm/web 0.9.45 → 1.0.0

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.
Files changed (70) hide show
  1. package/index.js +76 -115
  2. package/lib/get-php-loader-module.d.ts +1 -1
  3. package/lib/index.d.ts +0 -1
  4. package/package.json +7 -7
  5. package/{kitchen-sink → php/asyncify}/7_0_33/php_7_0.wasm +0 -0
  6. package/{kitchen-sink → php/asyncify}/7_1_30/php_7_1.wasm +0 -0
  7. package/{kitchen-sink → php/asyncify}/7_2_34/php_7_2.wasm +0 -0
  8. package/{kitchen-sink → php/asyncify}/7_3_33/php_7_3.wasm +0 -0
  9. package/{kitchen-sink → php/asyncify}/7_4_33/php_7_4.wasm +0 -0
  10. package/{kitchen-sink → php/asyncify}/8_0_30/php_8_0.wasm +0 -0
  11. package/{kitchen-sink → php/asyncify}/8_1_23/php_8_1.wasm +0 -0
  12. package/{kitchen-sink → php/asyncify}/8_2_10/php_8_2.wasm +0 -0
  13. package/{kitchen-sink → php/asyncify}/8_3_0/php_8_3.wasm +0 -0
  14. package/php/asyncify/php_7_0.js +105 -0
  15. package/php/asyncify/php_7_1.js +105 -0
  16. package/php/asyncify/php_7_2.js +105 -0
  17. package/php/asyncify/php_7_3.js +105 -0
  18. package/php/asyncify/php_7_4.js +105 -0
  19. package/php/asyncify/php_8_0.js +105 -0
  20. package/php/asyncify/php_8_1.js +105 -0
  21. package/php/asyncify/php_8_2.js +105 -0
  22. package/php/asyncify/php_8_3.js +105 -0
  23. package/php/jspi/7_0_33/php_7_0.wasm +0 -0
  24. package/php/jspi/7_1_30/php_7_1.wasm +0 -0
  25. package/php/jspi/7_2_34/php_7_2.wasm +0 -0
  26. package/php/jspi/7_3_33/php_7_3.wasm +0 -0
  27. package/php/jspi/7_4_33/php_7_4.wasm +0 -0
  28. package/php/jspi/8_0_30/php_8_0.wasm +0 -0
  29. package/php/jspi/8_1_23/php_8_1.wasm +0 -0
  30. package/php/jspi/8_2_10/php_8_2.wasm +0 -0
  31. package/php/jspi/8_3_0/php_8_3.wasm +0 -0
  32. package/php/jspi/php_7_0.js +105 -0
  33. package/php/jspi/php_7_1.js +105 -0
  34. package/php/jspi/php_7_2.js +105 -0
  35. package/php/jspi/php_7_3.js +105 -0
  36. package/php/jspi/php_7_4.js +105 -0
  37. package/php/jspi/php_8_0.js +105 -0
  38. package/php/jspi/php_8_1.js +105 -0
  39. package/php/jspi/php_8_2.js +105 -0
  40. package/php/jspi/php_8_3.js +105 -0
  41. package/kitchen-sink/8_3/php_8_3.wasm +0 -0
  42. package/kitchen-sink/php_7_0.js +0 -105
  43. package/kitchen-sink/php_7_1.js +0 -105
  44. package/kitchen-sink/php_7_2.js +0 -105
  45. package/kitchen-sink/php_7_3.js +0 -105
  46. package/kitchen-sink/php_7_4.js +0 -105
  47. package/kitchen-sink/php_8_0.js +0 -105
  48. package/kitchen-sink/php_8_1.js +0 -105
  49. package/kitchen-sink/php_8_2.js +0 -105
  50. package/kitchen-sink/php_8_3.js +0 -105
  51. package/lib/register-service-worker.d.ts +0 -24
  52. package/light/7_0_33/php_7_0.wasm +0 -0
  53. package/light/7_1_30/php_7_1.wasm +0 -0
  54. package/light/7_2_34/php_7_2.wasm +0 -0
  55. package/light/7_3_33/php_7_3.wasm +0 -0
  56. package/light/7_4_33/php_7_4.wasm +0 -0
  57. package/light/8_0_30/php_8_0.wasm +0 -0
  58. package/light/8_1_23/php_8_1.wasm +0 -0
  59. package/light/8_2_10/php_8_2.wasm +0 -0
  60. package/light/8_3/php_8_3.wasm +0 -0
  61. package/light/8_3_0/php_8_3.wasm +0 -0
  62. package/light/php_7_0.js +0 -105
  63. package/light/php_7_1.js +0 -105
  64. package/light/php_7_2.js +0 -105
  65. package/light/php_7_3.js +0 -105
  66. package/light/php_7_4.js +0 -105
  67. package/light/php_8_0.js +0 -105
  68. package/light/php_8_1.js +0 -105
  69. package/light/php_8_2.js +0 -105
  70. package/light/php_8_3.js +0 -105
package/index.js CHANGED
@@ -1,35 +1,35 @@
1
- import { PHPResponse as D, LatestSupportedPHPVersion as R, loadPHPRuntime as L, FSHelpers as p, __private__dont__use as P } from "@php-wasm/universal";
1
+ import { PHPResponse as R, LatestSupportedPHPVersion as b, loadPHPRuntime as z, FSHelpers as p, __private__dont__use as g } from "@php-wasm/universal";
2
2
  import * as f from "comlink";
3
- import { PhpWasmError as y, Semaphore as z, joinPaths as W } from "@php-wasm/util";
4
- import { responseTo as M } from "@php-wasm/web-service-worker";
3
+ import { jspi as L } from "wasm-feature-detect";
4
+ import { Semaphore as O, joinPaths as k } from "@php-wasm/util";
5
5
  import { logger as h } from "@php-wasm/logger";
6
- import { journalFSEvents as O } from "@php-wasm/fs-journal";
7
- function Q(r, t = void 0) {
8
- v();
9
- const e = r instanceof Worker ? r : f.windowEndpoint(r, t), n = f.wrap(e), a = g(n);
6
+ import { journalFSEvents as v } from "@php-wasm/fs-journal";
7
+ function B(r, t = void 0) {
8
+ W();
9
+ const e = r instanceof Worker ? r : f.windowEndpoint(r, t), n = f.wrap(e), a = y(n);
10
10
  return new Proxy(a, {
11
11
  get: (i, s) => s === "isConnected" ? async () => {
12
12
  for (; ; )
13
13
  try {
14
- await A(n.isConnected(), 200);
14
+ await S(n.isConnected(), 200);
15
15
  break;
16
16
  } catch {
17
17
  }
18
18
  } : n[s]
19
19
  });
20
20
  }
21
- async function A(r, t) {
21
+ async function S(r, t) {
22
22
  return new Promise((e, n) => {
23
23
  setTimeout(n, t), r.then(e);
24
24
  });
25
25
  }
26
- function X(r, t) {
27
- v();
26
+ function G(r, t) {
27
+ W();
28
28
  const e = Promise.resolve();
29
29
  let n, a;
30
30
  const i = new Promise((c, u) => {
31
31
  n = c, a = u;
32
- }), s = g(r), o = new Proxy(s, {
32
+ }), s = y(r), o = new Proxy(s, {
33
33
  get: (c, u) => u === "isConnected" ? () => e : u === "isReady" ? () => i : u in c ? c[u] : t == null ? void 0 : t[u]
34
34
  });
35
35
  return f.expose(
@@ -37,11 +37,11 @@ function X(r, t) {
37
37
  typeof window < "u" ? f.windowEndpoint(self.parent) : void 0
38
38
  ), [n, a, o];
39
39
  }
40
- let E = !1;
41
- function v() {
42
- if (E)
40
+ let P = !1;
41
+ function W() {
42
+ if (P)
43
43
  return;
44
- E = !0, f.transferHandlers.set("EVENT", {
44
+ P = !0, f.transferHandlers.set("EVENT", {
45
45
  canHandle: (e) => e instanceof CustomEvent,
46
46
  serialize: (e) => [
47
47
  {
@@ -65,7 +65,7 @@ function v() {
65
65
  return [e.toRawData(), []];
66
66
  },
67
67
  deserialize(e) {
68
- return D.fromRawData(e);
68
+ return R.fromRawData(e);
69
69
  }
70
70
  });
71
71
  const r = f.transferHandlers.get("throw"), t = r == null ? void 0 : r.serialize;
@@ -74,14 +74,14 @@ function v() {
74
74
  return e.response && (n[0].value.response = e.response), e.source && (n[0].value.source = e.source), n;
75
75
  };
76
76
  }
77
- function g(r) {
77
+ function y(r) {
78
78
  return new Proxy(r, {
79
79
  get(t, e) {
80
80
  switch (typeof t[e]) {
81
81
  case "function":
82
82
  return (...n) => t[e](...n);
83
83
  case "object":
84
- return t[e] === null ? t[e] : g(t[e]);
84
+ return t[e] === null ? t[e] : y(t[e]);
85
85
  case "undefined":
86
86
  case "number":
87
87
  case "string":
@@ -92,52 +92,52 @@ function g(r) {
92
92
  }
93
93
  });
94
94
  }
95
- async function I(r = R, t = "light") {
96
- if (t === "kitchen-sink")
95
+ async function M(r = b) {
96
+ if (await L())
97
97
  switch (r) {
98
98
  case "8.3":
99
- return await import("./kitchen-sink/php_8_3.js");
99
+ return await import("./jspi/php_8_3.js");
100
100
  case "8.2":
101
- return await import("./kitchen-sink/php_8_2.js");
101
+ return await import("./jspi/php_8_2.js");
102
102
  case "8.1":
103
- return await import("./kitchen-sink/php_8_1.js");
103
+ return await import("./jspi/php_8_1.js");
104
104
  case "8.0":
105
- return await import("./kitchen-sink/php_8_0.js");
105
+ return await import("./jspi/php_8_0.js");
106
106
  case "7.4":
107
- return await import("./kitchen-sink/php_7_4.js");
107
+ return await import("./jspi/php_7_4.js");
108
108
  case "7.3":
109
- return await import("./kitchen-sink/php_7_3.js");
109
+ return await import("./jspi/php_7_3.js");
110
110
  case "7.2":
111
- return await import("./kitchen-sink/php_7_2.js");
111
+ return await import("./jspi/php_7_2.js");
112
112
  case "7.1":
113
- return await import("./kitchen-sink/php_7_1.js");
113
+ return await import("./jspi/php_7_1.js");
114
114
  case "7.0":
115
- return await import("./kitchen-sink/php_7_0.js");
115
+ return await import("./jspi/php_7_0.js");
116
116
  }
117
117
  else
118
118
  switch (r) {
119
119
  case "8.3":
120
- return await import("./light/php_8_3.js");
120
+ return await import("./asyncify/php_8_3.js");
121
121
  case "8.2":
122
- return await import("./light/php_8_2.js");
122
+ return await import("./asyncify/php_8_2.js");
123
123
  case "8.1":
124
- return await import("./light/php_8_1.js");
124
+ return await import("./asyncify/php_8_1.js");
125
125
  case "8.0":
126
- return await import("./light/php_8_0.js");
126
+ return await import("./asyncify/php_8_0.js");
127
127
  case "7.4":
128
- return await import("./light/php_7_4.js");
128
+ return await import("./asyncify/php_7_4.js");
129
129
  case "7.3":
130
- return await import("./light/php_7_3.js");
130
+ return await import("./asyncify/php_7_3.js");
131
131
  case "7.2":
132
- return await import("./light/php_7_2.js");
132
+ return await import("./asyncify/php_7_2.js");
133
133
  case "7.1":
134
- return await import("./light/php_7_1.js");
134
+ return await import("./asyncify/php_7_1.js");
135
135
  case "7.0":
136
- return await import("./light/php_7_0.js");
136
+ return await import("./asyncify/php_7_0.js");
137
137
  }
138
138
  throw new Error(`Unsupported PHP version ${r}`);
139
139
  }
140
- const _ = () => ({
140
+ const I = () => ({
141
141
  websocket: {
142
142
  decorator: (r) => class extends r {
143
143
  constructor() {
@@ -152,52 +152,15 @@ const _ = () => ({
152
152
  }
153
153
  }
154
154
  });
155
- async function Z(r, t = {}) {
156
- var a;
157
- const e = t.loadAllExtensions ? "kitchen-sink" : "light", n = await I(r, e);
158
- return (a = t.onPhpLoaderModuleLoaded) == null || a.call(t, n), await L(n, {
155
+ async function Q(r, t = {}) {
156
+ var n;
157
+ const e = await M(r);
158
+ return (n = t.onPhpLoaderModuleLoaded) == null || n.call(t, e), await z(e, {
159
159
  ...t.emscriptenOptions || {},
160
- ..._()
160
+ ...I()
161
161
  });
162
162
  }
163
- let b;
164
- const $ = new Promise((r) => {
165
- b = r;
166
- });
167
- function ee(r) {
168
- if (!r)
169
- throw new y("PHP API client must be a valid client object.");
170
- b(r);
171
- }
172
- async function te(r, t) {
173
- const e = navigator.serviceWorker;
174
- if (!e)
175
- throw window.isSecureContext ? new y(
176
- "Service workers are not supported in your browser."
177
- ) : new y(
178
- "WordPress Playground uses service workers and may only work on HTTPS and http://localhost/ sites, but the current site is neither."
179
- );
180
- const n = await e.register(t, {
181
- type: "module",
182
- // Always bypass HTTP cache when fetching the new Service Worker script:
183
- updateViaCache: "none"
184
- });
185
- try {
186
- await n.update();
187
- } catch (a) {
188
- h.error("Failed to update service worker.", a);
189
- }
190
- navigator.serviceWorker.addEventListener(
191
- "message",
192
- async function(i) {
193
- if (r && i.data.scope !== r)
194
- return;
195
- const s = await $, o = i.data.args || [], c = i.data.method, u = await s[c](...o);
196
- i.source.postMessage(M(i.data.requestId, u));
197
- }
198
- ), e.startMessages();
199
- }
200
- function re(r, t) {
163
+ function X(r, t) {
201
164
  window.addEventListener("message", (e) => {
202
165
  e.source === r.contentWindow && (t && e.origin !== t || typeof e.data != "object" || e.data.type !== "relay" || window.parent.postMessage(e.data, "*"));
203
166
  }), window.addEventListener("message", (e) => {
@@ -205,7 +168,7 @@ function re(r, t) {
205
168
  e.source === window.parent && (typeof e.data != "object" || e.data.type !== "relay" || (n = r == null ? void 0 : r.contentWindow) == null || n.postMessage(e.data));
206
169
  });
207
170
  }
208
- async function ne(r) {
171
+ async function Y(r) {
209
172
  const t = new Worker(r, { type: "module" });
210
173
  return new Promise((e, n) => {
211
174
  t.onerror = (i) => {
@@ -220,7 +183,7 @@ async function ne(r) {
220
183
  t.addEventListener("message", a);
221
184
  });
222
185
  }
223
- function ae(r, t = { initialSync: {} }) {
186
+ function Z(r, t = { initialSync: {} }) {
224
187
  return t = {
225
188
  ...t,
226
189
  initialSync: {
@@ -228,17 +191,17 @@ function ae(r, t = { initialSync: {} }) {
228
191
  direction: t.initialSync.direction ?? "opfs-to-memfs"
229
192
  }
230
193
  }, async function(e, n, a) {
231
- return t.initialSync.direction === "opfs-to-memfs" ? (p.fileExists(n, a) && p.rmdir(n, a), p.mkdir(n, a), await q(n, r, a)) : await x(
194
+ return t.initialSync.direction === "opfs-to-memfs" ? (p.fileExists(n, a) && p.rmdir(n, a), p.mkdir(n, a), await _(n, r, a)) : await x(
232
195
  n,
233
196
  r,
234
197
  a,
235
198
  t.initialSync.onProgress
236
- ), J(e, r, a);
199
+ ), A(e, r, a);
237
200
  };
238
201
  }
239
- async function q(r, t, e) {
202
+ async function _(r, t, e) {
240
203
  p.mkdir(r, e);
241
- const n = new z({
204
+ const n = new O({
242
205
  concurrency: 40
243
206
  }), a = [], i = [
244
207
  [t, e]
@@ -247,7 +210,7 @@ async function q(r, t, e) {
247
210
  const [s, o] = i.pop();
248
211
  for await (const c of s.values()) {
249
212
  const u = n.run(async () => {
250
- const w = W(
213
+ const w = k(
251
214
  o,
252
215
  c.name
253
216
  );
@@ -286,21 +249,21 @@ async function x(r, t, e, n) {
286
249
  r.readdir(w).filter(
287
250
  (d) => d !== "." && d !== ".."
288
251
  ).map(async (d) => {
289
- const m = W(w, d);
290
- if (!F(r, m)) {
252
+ const m = k(w, d);
253
+ if (!$(r, m)) {
291
254
  a.push([l, m, d]);
292
255
  return;
293
256
  }
294
- const S = await l.getDirectoryHandle(d, {
257
+ const D = await l.getDirectoryHandle(d, {
295
258
  create: !0
296
259
  });
297
- return await i(m, S);
260
+ return await i(m, D);
298
261
  })
299
262
  );
300
263
  }
301
264
  await i(e, t);
302
265
  let s = 0;
303
- const o = n && N(n, 100), c = 100, u = /* @__PURE__ */ new Set();
266
+ const o = n && j(n, 100), c = 100, u = /* @__PURE__ */ new Set();
304
267
  try {
305
268
  for (const [w, l, d] of a) {
306
269
  const m = C(
@@ -323,7 +286,7 @@ async function x(r, t, e, n) {
323
286
  await Promise.allSettled(u);
324
287
  }
325
288
  }
326
- function F(r, t) {
289
+ function $(r, t) {
327
290
  return r.isDir(r.lookupPath(t, { follow: !0 }).node.mode);
328
291
  }
329
292
  async function C(r, t, e, n) {
@@ -348,10 +311,10 @@ async function C(r, t, e, n) {
348
311
  await s.close();
349
312
  }
350
313
  }
351
- function J(r, t, e) {
352
- const n = [], a = O(r, e, (o) => {
314
+ function A(r, t, e) {
315
+ const n = [], a = v(r, e, (o) => {
353
316
  n.push(o);
354
- }), i = new j(r, t, e);
317
+ }), i = new J(r, t, e);
355
318
  async function s() {
356
319
  const o = await r.semaphore.acquire();
357
320
  try {
@@ -365,12 +328,12 @@ function J(r, t, e) {
365
328
  a(), r.removeEventListener("request.end", s);
366
329
  };
367
330
  }
368
- class j {
331
+ class J {
369
332
  constructor(t, e, n) {
370
- this.php = t, this.opfs = e, this.memfsRoot = k(n);
333
+ this.php = t, this.opfs = e, this.memfsRoot = E(n);
371
334
  }
372
335
  toOpfsPath(t) {
373
- return k(t.substring(this.memfsRoot.length));
336
+ return E(t.substring(this.memfsRoot.length));
374
337
  }
375
338
  async processEntry(t) {
376
339
  if (!t.path.startsWith(this.memfsRoot) || t.path === this.memfsRoot)
@@ -395,7 +358,7 @@ class j {
395
358
  await C(
396
359
  n,
397
360
  a,
398
- this.php[P].FS,
361
+ this.php[g].FS,
399
362
  t.path
400
363
  );
401
364
  else if (t.operation === "RENAME" && t.toPath.startsWith(this.memfsRoot)) {
@@ -411,7 +374,7 @@ class j {
411
374
  }
412
375
  );
413
376
  await x(
414
- this.php[P].FS,
377
+ this.php[g].FS,
415
378
  c,
416
379
  t.toPath
417
380
  ), await n.removeEntry(a, {
@@ -425,7 +388,7 @@ class j {
425
388
  }
426
389
  }
427
390
  }
428
- function k(r) {
391
+ function E(r) {
429
392
  return r.replace(/\/$/, "").replace(/\/\/+/g, "/");
430
393
  }
431
394
  function H(r) {
@@ -443,7 +406,7 @@ async function T(r, t) {
443
406
  }
444
407
  return a;
445
408
  }
446
- function N(r, t) {
409
+ function j(r, t) {
447
410
  let e = 0, n, a;
448
411
  return function(...s) {
449
412
  a = s;
@@ -457,13 +420,11 @@ function N(r, t) {
457
420
  };
458
421
  }
459
422
  export {
460
- Q as consumeAPI,
461
- ae as createDirectoryHandleMountHandler,
462
- X as exposeAPI,
463
- I as getPHPLoaderModule,
464
- Z as loadWebRuntime,
465
- te as registerServiceWorker,
466
- ee as setPhpInstanceUsedByServiceWorker,
467
- re as setupPostMessageRelay,
468
- ne as spawnPHPWorkerThread
423
+ B as consumeAPI,
424
+ Z as createDirectoryHandleMountHandler,
425
+ G as exposeAPI,
426
+ M as getPHPLoaderModule,
427
+ Q as loadWebRuntime,
428
+ X as setupPostMessageRelay,
429
+ Y as spawnPHPWorkerThread
469
430
  };
@@ -6,4 +6,4 @@ import { PHPLoaderModule, SupportedPHPVersion } from '@php-wasm/universal';
6
6
  * @param variant Internal. Do not use.
7
7
  * @returns The PHP loader module.
8
8
  */
9
- export declare function getPHPLoaderModule(version?: SupportedPHPVersion, variant?: 'light' | 'kitchen-sink'): Promise<PHPLoaderModule>;
9
+ export declare function getPHPLoaderModule(version?: SupportedPHPVersion): Promise<PHPLoaderModule>;
package/lib/index.d.ts CHANGED
@@ -3,7 +3,6 @@ export type { WithAPIState as WithIsReady } from './api';
3
3
  export type { LoaderOptions as PHPWebLoaderOptions } from './load-runtime';
4
4
  export { loadWebRuntime } from './load-runtime';
5
5
  export { getPHPLoaderModule } from './get-php-loader-module';
6
- export { registerServiceWorker, setPhpInstanceUsedByServiceWorker, } from './register-service-worker';
7
6
  export { setupPostMessageRelay } from './setup-post-message-relay';
8
7
  export { spawnPHPWorkerThread } from './worker-thread/spawn-php-worker-thread';
9
8
  export { createDirectoryHandleMountHandler } from './directory-handle-mount';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@php-wasm/web",
3
- "version": "0.9.45",
3
+ "version": "1.0.0",
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": "0c51051f503936c8bc92974ed660bd83f1957922",
32
+ "gitHead": "9461d056ede8310ecfe01b72b5b095998a742ea3",
33
33
  "engines": {
34
34
  "node": ">=16.15.1",
35
35
  "npm": ">=8.11.0"
@@ -38,12 +38,12 @@
38
38
  "comlink": "^4.4.1",
39
39
  "express": "4.19.2",
40
40
  "ini": "4.1.2",
41
+ "wasm-feature-detect": "1.8.0",
41
42
  "ws": "8.18.0",
42
43
  "yargs": "17.7.2",
43
- "@php-wasm/universal": "0.9.45",
44
- "@php-wasm/util": "0.9.45",
45
- "@php-wasm/logger": "0.9.45",
46
- "@php-wasm/fs-journal": "0.9.45",
47
- "@php-wasm/web-service-worker": "0.9.45"
44
+ "@php-wasm/universal": "1.0.0",
45
+ "@php-wasm/util": "1.0.0",
46
+ "@php-wasm/logger": "1.0.0",
47
+ "@php-wasm/fs-journal": "1.0.0"
48
48
  }
49
49
  }