@php-wasm/web 0.9.29 → 0.9.31

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 CHANGED
@@ -1,12 +1,12 @@
1
1
  import { PHPResponse as C, LatestSupportedPHPVersion as R, loadPHPRuntime as L, FSHelpers as w, __private__dont__use as g } from "@php-wasm/universal";
2
2
  import * as d from "comlink";
3
- import { PhpWasmError as h, Semaphore as M, joinPaths as T } from "@php-wasm/util";
4
- import { responseTo as O } from "@php-wasm/web-service-worker";
5
- import { logger as p } from "@php-wasm/logger";
3
+ import { PhpWasmError as h, Semaphore as O, joinPaths as T } from "@php-wasm/util";
4
+ import { responseTo as S } from "@php-wasm/web-service-worker";
5
+ import { logger as m } from "@php-wasm/logger";
6
6
  import { journalFSEvents as z } from "@php-wasm/fs-journal";
7
- function B(t, r = void 0) {
7
+ function N(r, t = void 0) {
8
8
  W();
9
- const e = t instanceof Worker ? t : d.windowEndpoint(t, r), a = d.wrap(e), n = y(a);
9
+ const e = r instanceof Worker ? r : d.windowEndpoint(r, t), a = d.wrap(e), n = y(a);
10
10
  return new Proxy(n, {
11
11
  get: (i, s) => s === "isConnected" ? async () => {
12
12
  for (; ; )
@@ -18,19 +18,19 @@ function B(t, r = void 0) {
18
18
  } : a[s]
19
19
  });
20
20
  }
21
- async function D(t, r) {
21
+ async function D(r, t) {
22
22
  return new Promise((e, a) => {
23
- setTimeout(a, r), t.then(e);
23
+ setTimeout(a, t), r.then(e);
24
24
  });
25
25
  }
26
- function G(t, r) {
26
+ function G(r, t) {
27
27
  W();
28
28
  const e = Promise.resolve();
29
29
  let a, n;
30
30
  const i = new Promise((o, u) => {
31
31
  a = o, n = u;
32
- }), s = y(t), c = new Proxy(s, {
33
- get: (o, u) => u === "isConnected" ? () => e : u === "isReady" ? () => i : u in o ? o[u] : r == null ? void 0 : r[u]
32
+ }), s = y(r), c = new Proxy(s, {
33
+ get: (o, u) => u === "isConnected" ? () => e : u === "isReady" ? () => i : u in o ? o[u] : t == null ? void 0 : t[u]
34
34
  });
35
35
  return d.expose(
36
36
  c,
@@ -68,33 +68,33 @@ function W() {
68
68
  return C.fromRawData(e);
69
69
  }
70
70
  });
71
- const t = d.transferHandlers.get("throw"), r = t == null ? void 0 : t.serialize;
72
- t.serialize = ({ value: e }) => {
73
- const a = r({ value: e });
71
+ const r = d.transferHandlers.get("throw"), t = r == null ? void 0 : r.serialize;
72
+ r.serialize = ({ value: e }) => {
73
+ const a = t({ value: e });
74
74
  return e.response && (a[0].value.response = e.response), e.source && (a[0].value.source = e.source), a;
75
75
  };
76
76
  }
77
- function y(t) {
78
- return new Proxy(t, {
79
- get(r, e) {
80
- switch (typeof r[e]) {
77
+ function y(r) {
78
+ return new Proxy(r, {
79
+ get(t, e) {
80
+ switch (typeof t[e]) {
81
81
  case "function":
82
- return (...a) => r[e](...a);
82
+ return (...a) => t[e](...a);
83
83
  case "object":
84
- return r[e] === null ? r[e] : y(r[e]);
84
+ return t[e] === null ? t[e] : y(t[e]);
85
85
  case "undefined":
86
86
  case "number":
87
87
  case "string":
88
- return r[e];
88
+ return t[e];
89
89
  default:
90
- return d.proxy(r[e]);
90
+ return d.proxy(t[e]);
91
91
  }
92
92
  }
93
93
  });
94
94
  }
95
- async function S(t = R, r = "light") {
96
- if (r === "kitchen-sink")
97
- switch (t) {
95
+ async function M(r = R, t = "light") {
96
+ if (t === "kitchen-sink")
97
+ switch (r) {
98
98
  case "8.3":
99
99
  return await import("./kitchen-sink/php_8_3.js");
100
100
  case "8.2":
@@ -115,7 +115,7 @@ async function S(t = R, r = "light") {
115
115
  return await import("./kitchen-sink/php_7_0.js");
116
116
  }
117
117
  else
118
- switch (t) {
118
+ switch (r) {
119
119
  case "8.3":
120
120
  return await import("./light/php_8_3.js");
121
121
  case "8.2":
@@ -135,11 +135,11 @@ async function S(t = R, r = "light") {
135
135
  case "7.0":
136
136
  return await import("./light/php_7_0.js");
137
137
  }
138
- throw new Error(`Unsupported PHP version ${t}`);
138
+ throw new Error(`Unsupported PHP version ${r}`);
139
139
  }
140
140
  const A = () => ({
141
141
  websocket: {
142
- decorator: (t) => class extends t {
142
+ decorator: (r) => class extends r {
143
143
  constructor() {
144
144
  try {
145
145
  super();
@@ -152,24 +152,24 @@ const A = () => ({
152
152
  }
153
153
  }
154
154
  });
155
- async function Q(t, r = {}) {
155
+ async function Q(r, t = {}) {
156
156
  var n;
157
- const e = r.loadAllExtensions ? "kitchen-sink" : "light", a = await S(t, e);
158
- return (n = r.onPhpLoaderModuleLoaded) == null || n.call(r, a), await L(a, {
159
- ...r.emscriptenOptions || {},
157
+ const e = t.loadAllExtensions ? "kitchen-sink" : "light", a = await M(r, e);
158
+ return (n = t.onPhpLoaderModuleLoaded) == null || n.call(t, a), await L(a, {
159
+ ...t.emscriptenOptions || {},
160
160
  ...A()
161
161
  });
162
162
  }
163
163
  let b;
164
- const I = new Promise((t) => {
165
- b = t;
164
+ const I = new Promise((r) => {
165
+ b = r;
166
166
  });
167
- function X(t) {
168
- if (!t)
167
+ function X(r) {
168
+ if (!r)
169
169
  throw new h("PHP API client must be a valid client object.");
170
- b(t);
170
+ b(r);
171
171
  }
172
- async function Y(t, r) {
172
+ async function Y(r, t) {
173
173
  const e = navigator.serviceWorker;
174
174
  if (!e)
175
175
  throw window.isSecureContext ? new h(
@@ -177,7 +177,7 @@ async function Y(t, r) {
177
177
  ) : new h(
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 a = await e.register(r, {
180
+ const a = await e.register(t, {
181
181
  type: "module",
182
182
  // Always bypass HTTP cache when fetching the new Service Worker script:
183
183
  updateViaCache: "none"
@@ -185,66 +185,63 @@ async function Y(t, r) {
185
185
  try {
186
186
  await a.update();
187
187
  } catch (n) {
188
- p.error("Failed to update service worker.", n);
188
+ m.error("Failed to update service worker.", n);
189
189
  }
190
190
  navigator.serviceWorker.addEventListener(
191
191
  "message",
192
192
  async function(i) {
193
- if (t && i.data.scope !== t)
193
+ if (r && i.data.scope !== r)
194
194
  return;
195
195
  const s = await I, c = i.data.args || [], o = i.data.method, u = await s[o](...c);
196
- i.source.postMessage(O(i.data.requestId, u));
196
+ i.source.postMessage(S(i.data.requestId, u));
197
197
  }
198
198
  ), e.startMessages();
199
199
  }
200
- function Z(t, r) {
200
+ function Z(r, t) {
201
201
  window.addEventListener("message", (e) => {
202
- e.source === t.contentWindow && (r && e.origin !== r || typeof e.data != "object" || e.data.type !== "relay" || window.parent.postMessage(e.data, "*"));
202
+ e.source === r.contentWindow && (t && e.origin !== t || typeof e.data != "object" || e.data.type !== "relay" || window.parent.postMessage(e.data, "*"));
203
203
  }), window.addEventListener("message", (e) => {
204
204
  var a;
205
- e.source === window.parent && (typeof e.data != "object" || e.data.type !== "relay" || (a = t == null ? void 0 : t.contentWindow) == null || a.postMessage(e.data));
205
+ e.source === window.parent && (typeof e.data != "object" || e.data.type !== "relay" || (a = r == null ? void 0 : r.contentWindow) == null || a.postMessage(e.data));
206
206
  });
207
207
  }
208
- async function ee(t, r = {}) {
209
- const e = new Worker(t, { type: "module" });
210
- return new Promise((a, n) => {
211
- e.onerror = (s) => {
212
- const c = new Error(
213
- `WebWorker failed to load at ${t}. ${s.message ? `Original error: ${s.message}` : ""}`
208
+ async function ee(r) {
209
+ const t = new Worker(r, { type: "module" });
210
+ return new Promise((e, a) => {
211
+ t.onerror = (i) => {
212
+ const s = new Error(
213
+ `WebWorker failed to load at ${r}. ${i.message ? `Original error: ${i.message}` : ""}`
214
214
  );
215
- c.filename = s.filename, n(c);
216
- }, e.postMessage({
217
- type: "startup-options",
218
- startupOptions: r
219
- });
220
- function i(s) {
221
- s.data === "worker-script-started" && (a(e), e.removeEventListener("message", i));
215
+ s.filename = i.filename, a(s);
216
+ };
217
+ function n(i) {
218
+ i.data === "worker-script-started" && (e(t), t.removeEventListener("message", n));
222
219
  }
223
- e.addEventListener("message", i);
220
+ t.addEventListener("message", n);
224
221
  });
225
222
  }
226
- function te(t, r = { initialSync: {} }) {
227
- return r = {
228
- ...r,
223
+ function te(r, t = { initialSync: {} }) {
224
+ return t = {
225
+ ...t,
229
226
  initialSync: {
230
- ...r.initialSync,
231
- direction: r.initialSync.direction ?? "opfs-to-memfs"
227
+ ...t.initialSync,
228
+ direction: t.initialSync.direction ?? "opfs-to-memfs"
232
229
  }
233
230
  }, async function(e, a, n) {
234
- return r.initialSync.direction === "opfs-to-memfs" ? (w.fileExists(a, n) && w.rmdir(a, n), w.mkdir(a, n), await _(a, t, n)) : await v(
231
+ return t.initialSync.direction === "opfs-to-memfs" ? (w.fileExists(a, n) && w.rmdir(a, n), w.mkdir(a, n), await _(a, r, n)) : await v(
235
232
  a,
236
- t,
233
+ r,
237
234
  n,
238
- r.initialSync.onProgress
239
- ), q(e, t, n);
235
+ t.initialSync.onProgress
236
+ ), q(e, r, n);
240
237
  };
241
238
  }
242
- async function _(t, r, e) {
243
- w.mkdir(t, e);
244
- const a = new M({
239
+ async function _(r, t, e) {
240
+ w.mkdir(r, e);
241
+ const a = new O({
245
242
  concurrency: 40
246
243
  }), n = [], i = [
247
- [r, e]
244
+ [t, e]
248
245
  ];
249
246
  for (; i.length > 0; ) {
250
247
  const [s, c] = i.pop();
@@ -256,18 +253,18 @@ async function _(t, r, e) {
256
253
  );
257
254
  if (o.kind === "directory") {
258
255
  try {
259
- t.mkdir(l);
256
+ r.mkdir(l);
260
257
  } catch (f) {
261
258
  if ((f == null ? void 0 : f.errno) !== 20)
262
- throw p.error(f), f;
259
+ throw m.error(f), f;
263
260
  }
264
261
  i.push([o, l]);
265
262
  } else if (o.kind === "file") {
266
- const f = await o.getFile(), m = new Uint8Array(await f.arrayBuffer());
267
- t.createDataFile(
263
+ const f = await o.getFile(), p = new Uint8Array(await f.arrayBuffer());
264
+ r.createDataFile(
268
265
  c,
269
266
  o.name,
270
- m,
267
+ p,
271
268
  !0,
272
269
  !0,
273
270
  !0
@@ -281,39 +278,39 @@ async function _(t, r, e) {
281
278
  await Promise.any(n);
282
279
  }
283
280
  }
284
- async function v(t, r, e, a) {
285
- t.mkdirTree(e);
281
+ async function v(r, t, e, a) {
282
+ r.mkdirTree(e);
286
283
  const n = [];
287
284
  async function i(o, u) {
288
285
  await Promise.all(
289
- t.readdir(o).filter(
286
+ r.readdir(o).filter(
290
287
  (l) => l !== "." && l !== ".."
291
288
  ).map(async (l) => {
292
289
  const f = T(o, l);
293
- if (!$(t, f)) {
290
+ if (!$(r, f)) {
294
291
  n.push([u, f, l]);
295
292
  return;
296
293
  }
297
- const m = await u.getDirectoryHandle(l, {
294
+ const p = await u.getDirectoryHandle(l, {
298
295
  create: !0
299
296
  });
300
- return await i(f, m);
297
+ return await i(f, p);
301
298
  })
302
299
  );
303
300
  }
304
- await i(e, r);
301
+ await i(e, t);
305
302
  let s = 0;
306
303
  const c = n.map(
307
- ([o, u, l]) => x(o, l, t, u).then(() => {
304
+ ([o, u, l]) => x(o, l, r, u).then(() => {
308
305
  a == null || a({ files: ++s, total: n.length });
309
306
  })
310
307
  );
311
308
  await Promise.all(c);
312
309
  }
313
- function $(t, r) {
314
- return t.isDir(t.lookupPath(r, { follow: !0 }).node.mode);
310
+ function $(r, t) {
311
+ return r.isDir(r.lookupPath(t, { follow: !0 }).node.mode);
315
312
  }
316
- async function x(t, r, e, a) {
313
+ async function x(r, t, e, a) {
317
314
  let n;
318
315
  try {
319
316
  n = e.readFile(a, {
@@ -322,7 +319,7 @@ async function x(t, r, e, a) {
322
319
  } catch {
323
320
  return;
324
321
  }
325
- const i = await t.getFileHandle(r, { create: !0 }), s = i.createWritable !== void 0 ? (
322
+ const i = await r.getFileHandle(t, { create: !0 }), s = i.createWritable !== void 0 ? (
326
323
  // Google Chrome, Firefox, probably more browsers
327
324
  await i.createWritable()
328
325
  ) : (
@@ -335,12 +332,12 @@ async function x(t, r, e, a) {
335
332
  await s.close();
336
333
  }
337
334
  }
338
- function q(t, r, e) {
339
- const a = [], n = z(t, e, (c) => {
335
+ function q(r, t, e) {
336
+ const a = [], n = z(r, e, (c) => {
340
337
  a.push(c);
341
- }), i = new J(t, r, e);
338
+ }), i = new J(r, t, e);
342
339
  async function s() {
343
- const c = await t.semaphore.acquire();
340
+ const c = await r.semaphore.acquire();
344
341
  try {
345
342
  for (; a.length; )
346
343
  await i.processEntry(a.shift());
@@ -348,49 +345,49 @@ function q(t, r, e) {
348
345
  c();
349
346
  }
350
347
  }
351
- return t.addEventListener("request.end", s), function() {
352
- n(), t.removeEventListener("request.end", s);
348
+ return r.addEventListener("request.end", s), function() {
349
+ n(), r.removeEventListener("request.end", s);
353
350
  };
354
351
  }
355
352
  class J {
356
- constructor(r, e, a) {
357
- this.php = r, this.opfs = e, this.memfsRoot = E(a);
353
+ constructor(t, e, a) {
354
+ this.php = t, this.opfs = e, this.memfsRoot = k(a);
358
355
  }
359
- toOpfsPath(r) {
360
- return E(r.substring(this.memfsRoot.length));
356
+ toOpfsPath(t) {
357
+ return k(t.substring(this.memfsRoot.length));
361
358
  }
362
- async processEntry(r) {
363
- if (!r.path.startsWith(this.memfsRoot) || r.path === this.memfsRoot)
359
+ async processEntry(t) {
360
+ if (!t.path.startsWith(this.memfsRoot) || t.path === this.memfsRoot)
364
361
  return;
365
- const e = this.toOpfsPath(r.path), a = await H(this.opfs, e), n = k(e);
362
+ const e = this.toOpfsPath(t.path), a = await H(this.opfs, e), n = E(e);
366
363
  if (n)
367
364
  try {
368
- if (r.operation === "DELETE")
365
+ if (t.operation === "DELETE")
369
366
  try {
370
367
  await a.removeEntry(n, {
371
368
  recursive: !0
372
369
  });
373
370
  } catch {
374
371
  }
375
- else if (r.operation === "CREATE")
376
- r.nodeType === "directory" ? await a.getDirectoryHandle(n, {
372
+ else if (t.operation === "CREATE")
373
+ t.nodeType === "directory" ? await a.getDirectoryHandle(n, {
377
374
  create: !0
378
375
  }) : await a.getFileHandle(n, {
379
376
  create: !0
380
377
  });
381
- else if (r.operation === "WRITE")
378
+ else if (t.operation === "WRITE")
382
379
  await x(
383
380
  a,
384
381
  n,
385
382
  this.php[g].FS,
386
- r.path
383
+ t.path
387
384
  );
388
- else if (r.operation === "RENAME" && r.toPath.startsWith(this.memfsRoot)) {
389
- const i = this.toOpfsPath(r.toPath), s = await H(
385
+ else if (t.operation === "RENAME" && t.toPath.startsWith(this.memfsRoot)) {
386
+ const i = this.toOpfsPath(t.toPath), s = await H(
390
387
  this.opfs,
391
388
  i
392
- ), c = k(i);
393
- if (r.nodeType === "directory") {
389
+ ), c = E(i);
390
+ if (t.nodeType === "directory") {
394
391
  const o = await s.getDirectoryHandle(
395
392
  n,
396
393
  {
@@ -400,7 +397,7 @@ class J {
400
397
  await v(
401
398
  this.php[g].FS,
402
399
  o,
403
- r.toPath
400
+ t.toPath
404
401
  ), await a.removeEntry(n, {
405
402
  recursive: !0
406
403
  });
@@ -408,22 +405,22 @@ class J {
408
405
  (await a.getFileHandle(n)).move(s, c);
409
406
  }
410
407
  } catch (i) {
411
- throw p.log({ entry: r, name: n }), p.error(i), i;
408
+ throw m.log({ entry: t, name: n }), m.error(i), i;
412
409
  }
413
410
  }
414
411
  }
415
- function E(t) {
416
- return t.replace(/\/$/, "").replace(/\/\/+/g, "/");
412
+ function k(r) {
413
+ return r.replace(/\/$/, "").replace(/\/\/+/g, "/");
417
414
  }
418
- function k(t) {
419
- return t.substring(t.lastIndexOf("/") + 1);
415
+ function E(r) {
416
+ return r.substring(r.lastIndexOf("/") + 1);
420
417
  }
421
- async function H(t, r) {
422
- const e = r.replace(/^\/+|\/+$/g, "").replace(/\/+/, "/");
418
+ async function H(r, t) {
419
+ const e = t.replace(/^\/+|\/+$/g, "").replace(/\/+/, "/");
423
420
  if (!e)
424
- return t;
421
+ return r;
425
422
  const a = e.split("/");
426
- let n = t;
423
+ let n = r;
427
424
  for (let i = 0; i < a.length - 1; i++) {
428
425
  const s = a[i];
429
426
  n = await n.getDirectoryHandle(s, { create: !0 });
@@ -431,13 +428,13 @@ async function H(t, r) {
431
428
  return n;
432
429
  }
433
430
  export {
434
- B as consumeAPI,
431
+ N as consumeAPI,
435
432
  te as createDirectoryHandleMountHandler,
436
433
  G as exposeAPI,
437
- S as getPHPLoaderModule,
434
+ M as getPHPLoaderModule,
438
435
  Q as loadWebRuntime,
439
436
  Y as registerServiceWorker,
440
- X as setPhpApi,
437
+ X as setPhpInstanceUsedByServiceWorker,
441
438
  Z as setupPostMessageRelay,
442
439
  ee as spawnPHPWorkerThread
443
440
  };
@@ -13,6 +13,13 @@ declare global {
13
13
  truncate(newSize: number): Promise<void>;
14
14
  }
15
15
  }
16
+ export type MountDevice = {
17
+ type: 'opfs';
18
+ path: string;
19
+ } | {
20
+ type: 'local-fs';
21
+ handle: FileSystemDirectoryHandle;
22
+ };
16
23
  export interface MountOptions {
17
24
  initialSync: {
18
25
  direction?: 'opfs-to-memfs' | 'memfs-to-opfs';
package/lib/index.d.ts CHANGED
@@ -3,8 +3,8 @@ 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, setPhpApi } from './register-service-worker';
6
+ export { registerServiceWorker, setPhpInstanceUsedByServiceWorker, } from './register-service-worker';
7
7
  export { setupPostMessageRelay } from './setup-post-message-relay';
8
8
  export { spawnPHPWorkerThread } from './worker-thread/spawn-php-worker-thread';
9
9
  export { createDirectoryHandleMountHandler } from './directory-handle-mount';
10
- export type { MountOptions, SyncProgress, SyncProgressCallback, } from './directory-handle-mount';
10
+ export type { MountDevice, MountOptions, SyncProgress, SyncProgressCallback, } from './directory-handle-mount';
@@ -9,7 +9,7 @@ export declare const phpApiPromise: Promise<Client>;
9
9
  * @param {Client} api The PHP API client.
10
10
  *
11
11
  */
12
- export declare function setPhpApi(api: Client): void;
12
+ export declare function setPhpInstanceUsedByServiceWorker(api: Client): void;
13
13
  /**
14
14
  * Run this in the main application to register the service worker or
15
15
  * reload the registered worker if the app expects a different version
@@ -2,7 +2,6 @@
2
2
  * Spawns a new Worker Thread.
3
3
  *
4
4
  * @param workerUrl The absolute URL of the worker script.
5
- * @param config
6
5
  * @returns The spawned Worker Thread.
7
6
  */
8
- export declare function spawnPHPWorkerThread(workerUrl: string, startupOptions?: Record<string, string | string[]>): Promise<Worker>;
7
+ export declare function spawnPHPWorkerThread(workerUrl: string): Promise<Worker>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@php-wasm/web",
3
- "version": "0.9.29",
3
+ "version": "0.9.31",
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": "79ef61d98407b1a90f622f6bef8f91001c568d00",
32
+ "gitHead": "296845449383439f6304f0559eaacf14cef68989",
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.29",
44
- "@php-wasm/util": "0.9.29",
45
- "@php-wasm/logger": "0.9.29",
46
- "@php-wasm/fs-journal": "0.9.29",
47
- "@php-wasm/web-service-worker": "0.9.29"
43
+ "@php-wasm/universal": "0.9.31",
44
+ "@php-wasm/util": "0.9.31",
45
+ "@php-wasm/logger": "0.9.31",
46
+ "@php-wasm/fs-journal": "0.9.31",
47
+ "@php-wasm/web-service-worker": "0.9.31"
48
48
  }
49
49
  }