@php-wasm/web 0.1.56 → 0.1.58

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 CHANGED
@@ -275,9 +275,10 @@ export interface IsomorphicLocalPHP extends RequestHandler {
275
275
  * Lists the files and directories in the given directory.
276
276
  *
277
277
  * @param path - The directory path to list.
278
+ * @param options - Options for the listing.
278
279
  * @returns The list of files and directories in the given directory.
279
280
  */
280
- listFiles(path: string): string[];
281
+ listFiles(path: string, options?: ListFilesOptions): string[];
281
282
  /**
282
283
  * Checks if a directory exists in the PHP filesystem.
283
284
  *
@@ -448,6 +449,13 @@ export interface RmDirOptions {
448
449
  */
449
450
  recursive?: boolean;
450
451
  }
452
+ export interface ListFilesOptions {
453
+ /**
454
+ * If true, prepend given folder path to all file names.
455
+ * Default: false.
456
+ */
457
+ prependPath: boolean;
458
+ }
451
459
  declare const SupportedPHPVersions: readonly [
452
460
  "8.2",
453
461
  "8.1",
@@ -620,7 +628,7 @@ declare abstract class BasePHP implements IsomorphicLocalPHP {
620
628
  /** @inheritDoc */
621
629
  rmdir(path: string, options?: RmDirOptions): void;
622
630
  /** @inheritDoc */
623
- listFiles(path: string): string[];
631
+ listFiles(path: string, options?: ListFilesOptions): string[];
624
632
  /** @inheritDoc */
625
633
  isDir(path: string): boolean;
626
634
  /** @inheritDoc */
@@ -716,7 +724,7 @@ export declare class WebPHPEndpoint implements IsomorphicLocalPHP {
716
724
  /** @inheritDoc @php-wasm/web!WebPHP.unlink */
717
725
  unlink(path: string): void;
718
726
  /** @inheritDoc @php-wasm/web!WebPHP.listFiles */
719
- listFiles(path: string): string[];
727
+ listFiles(path: string, options?: ListFilesOptions): string[];
720
728
  /** @inheritDoc @php-wasm/web!WebPHP.isDir */
721
729
  isDir(path: string): boolean;
722
730
  /** @inheritDoc @php-wasm/web!WebPHP.fileExists */
@@ -1,4 +1,4 @@
1
- const W = Symbol("error"), D = Symbol("message");
1
+ const W = Symbol("error"), $ = Symbol("message");
2
2
  class I extends Event {
3
3
  /**
4
4
  * Create a new `ErrorEvent`.
@@ -8,13 +8,13 @@ class I extends Event {
8
8
  * attributes via object members of the same name.
9
9
  */
10
10
  constructor(e, r = {}) {
11
- super(e), this[W] = r.error === void 0 ? null : r.error, this[D] = r.message === void 0 ? "" : r.message;
11
+ super(e), this[W] = r.error === void 0 ? null : r.error, this[$] = r.message === void 0 ? "" : r.message;
12
12
  }
13
13
  get error() {
14
14
  return this[W];
15
15
  }
16
16
  get message() {
17
- return this[D];
17
+ return this[$];
18
18
  }
19
19
  }
20
20
  Object.defineProperty(I.prototype, "error", { enumerable: !0 });
@@ -113,13 +113,13 @@ the Dockerfile, you'll need to trigger this error again with long stack
113
113
  traces enabled. In node.js, you can do it using the --stack-trace-limit=100
114
114
  CLI option:
115
115
 
116
- `, $ = "\x1B[41m", he = "\x1B[1m", q = "\x1B[0m", z = "\x1B[K";
116
+ `, D = "\x1B[41m", he = "\x1B[1m", q = "\x1B[0m", z = "\x1B[K";
117
117
  let B = !1;
118
118
  function de(t) {
119
119
  if (!B) {
120
- B = !0, console.log(`${$}
120
+ B = !0, console.log(`${D}
121
121
  ${z}
122
- ${he} WASM ERROR${q}${$}`);
122
+ ${he} WASM ERROR${q}${D}`);
123
123
  for (const e of t.split(`
124
124
  `))
125
125
  console.log(`${z} ${e} `);
@@ -857,11 +857,13 @@ class m {
857
857
  [E],
858
858
  [parseInt(e["content-length"], 10)]
859
859
  );
860
- for (const r in e)
861
- this.addServerGlobalEntry(
862
- `HTTP_${r.toUpperCase().replace(/-/g, "_")}`,
860
+ for (const r in e) {
861
+ let n = "HTTP_";
862
+ ["content-type", "content-length"].includes(r.toLowerCase()) && (n = ""), this.addServerGlobalEntry(
863
+ `${n}${r.toUpperCase().replace(/-/g, "_")}`,
863
864
  e[r]
864
865
  );
866
+ }
865
867
  }
866
868
  #u(e) {
867
869
  this[u].ccall(
@@ -992,15 +994,20 @@ class m {
992
994
  this.isDir(s) ? this.rmdir(s, r) : this.unlink(s);
993
995
  }), this[u].FS.rmdir(e);
994
996
  }
995
- listFiles(e) {
997
+ listFiles(e, r = { prependPath: !1 }) {
996
998
  if (!this.fileExists(e))
997
999
  return [];
998
1000
  try {
999
- return this[u].FS.readdir(e).filter(
1000
- (r) => r !== "." && r !== ".."
1001
+ const n = this[u].FS.readdir(e).filter(
1002
+ (s) => s !== "." && s !== ".."
1001
1003
  );
1002
- } catch (r) {
1003
- return console.error(r, { path: e }), [];
1004
+ if (r.prependPath) {
1005
+ const s = e.replace(/\/$/, "");
1006
+ return n.map((o) => `${s}/${o}`);
1007
+ }
1008
+ return n;
1009
+ } catch (n) {
1010
+ return console.error(n, { path: e }), [];
1004
1011
  }
1005
1012
  }
1006
1013
  isDir(e) {
@@ -1372,23 +1379,23 @@ function N(t) {
1372
1379
  async function We(t = me) {
1373
1380
  switch (t) {
1374
1381
  case "8.2":
1375
- return await import("php_8_2.js");
1382
+ return await import("./php_8_2.js");
1376
1383
  case "8.1":
1377
- return await import("php_8_1.js");
1384
+ return await import("./php_8_1.js");
1378
1385
  case "8.0":
1379
- return await import("php_8_0.js");
1386
+ return await import("./php_8_0.js");
1380
1387
  case "7.4":
1381
- return await import("php_7_4.js");
1388
+ return await import("./php_7_4.js");
1382
1389
  case "7.3":
1383
- return await import("php_7_3.js");
1390
+ return await import("./php_7_3.js");
1384
1391
  case "7.2":
1385
- return await import("php_7_2.js");
1392
+ return await import("./php_7_2.js");
1386
1393
  case "7.1":
1387
- return await import("php_7_1.js");
1394
+ return await import("./php_7_1.js");
1388
1395
  case "7.0":
1389
- return await import("php_7_0.js");
1396
+ return await import("./php_7_0.js");
1390
1397
  case "5.6":
1391
- return await import("php_5_6.js");
1398
+ return await import("./php_5_6.js");
1392
1399
  }
1393
1400
  throw new Error(`Unsupported PHP version ${t}`);
1394
1401
  }
@@ -1515,8 +1522,8 @@ class Ge {
1515
1522
  return d.get(this).php.unlink(e);
1516
1523
  }
1517
1524
  /** @inheritDoc @php-wasm/web!WebPHP.listFiles */
1518
- listFiles(e) {
1519
- return d.get(this).php.listFiles(e);
1525
+ listFiles(e, r) {
1526
+ return d.get(this).php.listFiles(e, r);
1520
1527
  }
1521
1528
  /** @inheritDoc @php-wasm/web!WebPHP.isDir */
1522
1529
  isDir(e) {
@@ -1527,7 +1534,7 @@ class Ge {
1527
1534
  return d.get(this).php.fileExists(e);
1528
1535
  }
1529
1536
  }
1530
- function De(t, e) {
1537
+ function $e(t, e) {
1531
1538
  return {
1532
1539
  type: "response",
1533
1540
  requestId: t,
@@ -1540,7 +1547,7 @@ async function Ve(t, e, r, n) {
1540
1547
  throw new Error("Service workers are not supported in this browser.");
1541
1548
  const o = await s.getRegistrations();
1542
1549
  if (o.length > 0) {
1543
- const i = await $e();
1550
+ const i = await De();
1544
1551
  if (n !== i) {
1545
1552
  console.debug(
1546
1553
  `[window] Reloading the currently registered Service Worker (expected version: ${n}, registered version: ${i})`
@@ -1568,11 +1575,11 @@ async function Ve(t, e, r, n) {
1568
1575
  if (console.debug("Message from ServiceWorker", a), e && a.data.scope !== e)
1569
1576
  return;
1570
1577
  const l = a.data.args || [], c = a.data.method, h = await t[c](...l);
1571
- a.source.postMessage(De(a.data.requestId, h));
1578
+ a.source.postMessage($e(a.data.requestId, h));
1572
1579
  }
1573
1580
  ), s.startMessages();
1574
1581
  }
1575
- async function $e() {
1582
+ async function De() {
1576
1583
  try {
1577
1584
  return (await (await fetch("/version")).json()).version;
1578
1585
  } catch {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@php-wasm/web",
3
- "version": "0.1.56",
3
+ "version": "0.1.58",
4
4
  "description": "PHP.wasm for the web",
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": "af3583eb7c6644a9859ea4782702c6e2c3474821"
32
+ "gitHead": "dbc77ed4c0b0a2625cfbe08722fade036c69a425"
33
33
  }