@php-wasm/node 0.1.40 → 0.1.45

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.cjs CHANGED
@@ -10638,7 +10638,7 @@ var dependenciesTotalSize, dependencyFilename;
10638
10638
  var init_php_8_2 = __esm({
10639
10639
  "packages/php-wasm/node/public/php_8_2.js"() {
10640
10640
  "use strict";
10641
- dependenciesTotalSize = 10302568;
10641
+ dependenciesTotalSize = 10302665;
10642
10642
  dependencyFilename = __dirname + "/php_8_2.wasm";
10643
10643
  }
10644
10644
  });
@@ -17733,7 +17733,7 @@ var dependenciesTotalSize2, dependencyFilename2;
17733
17733
  var init_php_8_1 = __esm({
17734
17734
  "packages/php-wasm/node/public/php_8_1.js"() {
17735
17735
  "use strict";
17736
- dependenciesTotalSize2 = 10044212;
17736
+ dependenciesTotalSize2 = 10044311;
17737
17737
  dependencyFilename2 = __dirname + "/php_8_1.wasm";
17738
17738
  }
17739
17739
  });
@@ -24801,7 +24801,7 @@ var dependenciesTotalSize3, dependencyFilename3;
24801
24801
  var init_php_8_0 = __esm({
24802
24802
  "packages/php-wasm/node/public/php_8_0.js"() {
24803
24803
  "use strict";
24804
- dependenciesTotalSize3 = 10172214;
24804
+ dependenciesTotalSize3 = 10172313;
24805
24805
  dependencyFilename3 = __dirname + "/php_8_0.wasm";
24806
24806
  }
24807
24807
  });
@@ -31854,7 +31854,7 @@ var dependenciesTotalSize4, dependencyFilename4;
31854
31854
  var init_php_7_4 = __esm({
31855
31855
  "packages/php-wasm/node/public/php_7_4.js"() {
31856
31856
  "use strict";
31857
- dependenciesTotalSize4 = 11015874;
31857
+ dependenciesTotalSize4 = 11015985;
31858
31858
  dependencyFilename4 = __dirname + "/php_7_4.wasm";
31859
31859
  }
31860
31860
  });
@@ -38900,7 +38900,7 @@ var dependenciesTotalSize5, dependencyFilename5;
38900
38900
  var init_php_7_3 = __esm({
38901
38901
  "packages/php-wasm/node/public/php_7_3.js"() {
38902
38902
  "use strict";
38903
- dependenciesTotalSize5 = 10915930;
38903
+ dependenciesTotalSize5 = 10916038;
38904
38904
  dependencyFilename5 = __dirname + "/php_7_3.wasm";
38905
38905
  }
38906
38906
  });
@@ -45811,7 +45811,7 @@ var dependenciesTotalSize6, dependencyFilename6;
45811
45811
  var init_php_7_2 = __esm({
45812
45812
  "packages/php-wasm/node/public/php_7_2.js"() {
45813
45813
  "use strict";
45814
- dependenciesTotalSize6 = 10993263;
45814
+ dependenciesTotalSize6 = 10992646;
45815
45815
  dependencyFilename6 = __dirname + "/php_7_2.wasm";
45816
45816
  }
45817
45817
  });
@@ -52707,7 +52707,7 @@ var dependenciesTotalSize7, dependencyFilename7;
52707
52707
  var init_php_7_1 = __esm({
52708
52708
  "packages/php-wasm/node/public/php_7_1.js"() {
52709
52709
  "use strict";
52710
- dependenciesTotalSize7 = 10583644;
52710
+ dependenciesTotalSize7 = 10583119;
52711
52711
  dependencyFilename7 = __dirname + "/php_7_1.wasm";
52712
52712
  }
52713
52713
  });
@@ -59617,7 +59617,7 @@ var dependenciesTotalSize8, dependencyFilename8;
59617
59617
  var init_php_7_0 = __esm({
59618
59618
  "packages/php-wasm/node/public/php_7_0.js"() {
59619
59619
  "use strict";
59620
- dependenciesTotalSize8 = 10389382;
59620
+ dependenciesTotalSize8 = 10389492;
59621
59621
  dependencyFilename8 = __dirname + "/php_7_0.wasm";
59622
59622
  }
59623
59623
  });
@@ -66546,7 +66546,7 @@ var dependenciesTotalSize9, dependencyFilename9;
66546
66546
  var init_php_5_6 = __esm({
66547
66547
  "packages/php-wasm/node/public/php_5_6.js"() {
66548
66548
  "use strict";
66549
- dependenciesTotalSize9 = 10176138;
66549
+ dependenciesTotalSize9 = 10176192;
66550
66550
  dependencyFilename9 = __dirname + "/php_5_6.wasm";
66551
66551
  }
66552
66552
  });
@@ -66560,6 +66560,177 @@ __export(src_exports, {
66560
66560
  });
66561
66561
  module.exports = __toCommonJS(src_exports);
66562
66562
 
66563
+ // packages/php-wasm/universal/src/lib/error-event-polyfill.ts
66564
+ var kError = Symbol("error");
66565
+ var kMessage = Symbol("message");
66566
+ var ErrorEvent2 = class extends Event {
66567
+ [kError];
66568
+ [kMessage];
66569
+ /**
66570
+ * Create a new `ErrorEvent`.
66571
+ *
66572
+ * @param type The name of the event
66573
+ * @param options A dictionary object that allows for setting
66574
+ * attributes via object members of the same name.
66575
+ */
66576
+ constructor(type, options = {}) {
66577
+ super(type);
66578
+ this[kError] = options.error === void 0 ? null : options.error;
66579
+ this[kMessage] = options.message === void 0 ? "" : options.message;
66580
+ }
66581
+ get error() {
66582
+ return this[kError];
66583
+ }
66584
+ get message() {
66585
+ return this[kMessage];
66586
+ }
66587
+ };
66588
+ Object.defineProperty(ErrorEvent2.prototype, "error", { enumerable: true });
66589
+ Object.defineProperty(ErrorEvent2.prototype, "message", { enumerable: true });
66590
+ var ErrorEvent = typeof globalThis.ErrorEvent === "function" ? globalThis.ErrorEvent : ErrorEvent2;
66591
+
66592
+ // packages/php-wasm/universal/src/lib/wasm-error-reporting.ts
66593
+ var UnhandledRejectionsTarget = class extends EventTarget {
66594
+ listenersCount = 0;
66595
+ addEventListener(type, callback) {
66596
+ ++this.listenersCount;
66597
+ super.addEventListener(type, callback);
66598
+ }
66599
+ removeEventListener(type, callback) {
66600
+ --this.listenersCount;
66601
+ super.removeEventListener(type, callback);
66602
+ }
66603
+ hasListeners() {
66604
+ return this.listenersCount > 0;
66605
+ }
66606
+ };
66607
+ function improveWASMErrorReporting(runtime) {
66608
+ runtime.asm = {
66609
+ ...runtime.asm
66610
+ };
66611
+ const target = new UnhandledRejectionsTarget();
66612
+ for (const key in runtime.asm) {
66613
+ if (typeof runtime.asm[key] == "function") {
66614
+ const original = runtime.asm[key];
66615
+ runtime.asm[key] = function(...args) {
66616
+ try {
66617
+ return original(...args);
66618
+ } catch (e) {
66619
+ if (!(e instanceof Error)) {
66620
+ throw e;
66621
+ }
66622
+ if ("exitCode" in e && e?.exitCode === 0) {
66623
+ return;
66624
+ }
66625
+ const clearMessage = clarifyErrorMessage(
66626
+ e,
66627
+ runtime.lastAsyncifyStackSource?.stack
66628
+ );
66629
+ if (runtime.lastAsyncifyStackSource) {
66630
+ e.cause = runtime.lastAsyncifyStackSource;
66631
+ }
66632
+ if (!target.hasListeners()) {
66633
+ showCriticalErrorBox(clearMessage);
66634
+ throw e;
66635
+ }
66636
+ target.dispatchEvent(
66637
+ new ErrorEvent("error", {
66638
+ error: e,
66639
+ message: clearMessage
66640
+ })
66641
+ );
66642
+ }
66643
+ };
66644
+ }
66645
+ }
66646
+ return target;
66647
+ }
66648
+ var functionsMaybeMissingFromAsyncify = [];
66649
+ function getFunctionsMaybeMissingFromAsyncify() {
66650
+ return functionsMaybeMissingFromAsyncify;
66651
+ }
66652
+ function clarifyErrorMessage(crypticError, asyncifyStack) {
66653
+ if (crypticError.message === "unreachable") {
66654
+ let betterMessage = UNREACHABLE_ERROR;
66655
+ if (!asyncifyStack) {
66656
+ betterMessage += `
66657
+
66658
+ This stack trace is lacking. For a better one initialize
66659
+ the PHP runtime with { debug: true }, e.g. PHPNode.load('8.1', { debug: true }).
66660
+
66661
+ `;
66662
+ }
66663
+ functionsMaybeMissingFromAsyncify = extractPHPFunctionsFromStack(
66664
+ asyncifyStack || crypticError.stack || ""
66665
+ );
66666
+ for (const fn of functionsMaybeMissingFromAsyncify) {
66667
+ betterMessage += ` * ${fn}
66668
+ `;
66669
+ }
66670
+ return betterMessage;
66671
+ }
66672
+ return crypticError.message;
66673
+ }
66674
+ var UNREACHABLE_ERROR = `
66675
+ "unreachable" WASM instruction executed.
66676
+
66677
+ The typical reason is a PHP function missing from the ASYNCIFY_ONLY
66678
+ list when building PHP.wasm.
66679
+
66680
+ You will need to file a new issue in the WordPress Playground repository
66681
+ and paste this error message there:
66682
+
66683
+ https://github.com/WordPress/wordpress-playground/issues/new
66684
+
66685
+ If you're a core developer, the typical fix is to:
66686
+
66687
+ * Isolate a minimal reproduction of the error
66688
+ * Add a reproduction of the error to php-asyncify.spec.ts in the WordPress Playground repository
66689
+ * Run 'npm run fix-asyncify'
66690
+ * Commit the changes, push to the repo, release updated NPM packages
66691
+
66692
+ Below is a list of all the PHP functions found in the stack trace to
66693
+ help with the minimal reproduction. If they're all already listed in
66694
+ the Dockerfile, you'll need to trigger this error again with long stack
66695
+ traces enabled. In node.js, you can do it using the --stack-trace-limit=100
66696
+ CLI option:
66697
+
66698
+ `;
66699
+ var redBg = "\x1B[41m";
66700
+ var bold = "\x1B[1m";
66701
+ var reset = "\x1B[0m";
66702
+ var eol = "\x1B[K";
66703
+ var logged = false;
66704
+ function showCriticalErrorBox(message) {
66705
+ if (logged) {
66706
+ return;
66707
+ }
66708
+ logged = true;
66709
+ console.log(`${redBg}
66710
+ ${eol}
66711
+ ${bold} WASM ERROR${reset}${redBg}`);
66712
+ for (const line of message.split("\n")) {
66713
+ console.log(`${eol} ${line} `);
66714
+ }
66715
+ console.log(`${reset}`);
66716
+ }
66717
+ function extractPHPFunctionsFromStack(stack) {
66718
+ try {
66719
+ const names = stack.split("\n").slice(1).map((line) => {
66720
+ const parts = line.trim().substring("at ".length).split(" ");
66721
+ return {
66722
+ fn: parts.length >= 2 ? parts[0] : "<unknown>",
66723
+ isWasm: line.includes("wasm://")
66724
+ };
66725
+ }).filter(
66726
+ ({ fn, isWasm }) => isWasm && !fn.startsWith("dynCall_") && !fn.startsWith("invoke_")
66727
+ ).map(({ fn }) => fn);
66728
+ return Array.from(new Set(names));
66729
+ } catch (err) {
66730
+ return [];
66731
+ }
66732
+ }
66733
+
66563
66734
  // packages/php-wasm/universal/src/lib/php-response.ts
66564
66735
  var PHPResponse = class {
66565
66736
  /** @inheritDoc */
@@ -67216,177 +67387,6 @@ var currentJsRuntime = function() {
67216
67387
  }
67217
67388
  }();
67218
67389
 
67219
- // packages/php-wasm/universal/src/lib/error-event-polyfill.ts
67220
- var kError = Symbol("error");
67221
- var kMessage = Symbol("message");
67222
- var ErrorEvent2 = class extends Event {
67223
- [kError];
67224
- [kMessage];
67225
- /**
67226
- * Create a new `ErrorEvent`.
67227
- *
67228
- * @param type The name of the event
67229
- * @param options A dictionary object that allows for setting
67230
- * attributes via object members of the same name.
67231
- */
67232
- constructor(type, options = {}) {
67233
- super(type);
67234
- this[kError] = options.error === void 0 ? null : options.error;
67235
- this[kMessage] = options.message === void 0 ? "" : options.message;
67236
- }
67237
- get error() {
67238
- return this[kError];
67239
- }
67240
- get message() {
67241
- return this[kMessage];
67242
- }
67243
- };
67244
- Object.defineProperty(ErrorEvent2.prototype, "error", { enumerable: true });
67245
- Object.defineProperty(ErrorEvent2.prototype, "message", { enumerable: true });
67246
- var ErrorEvent = typeof globalThis.ErrorEvent === "function" ? globalThis.ErrorEvent : ErrorEvent2;
67247
-
67248
- // packages/php-wasm/universal/src/lib/wasm-error-reporting.ts
67249
- var UnhandledRejectionsTarget = class extends EventTarget {
67250
- listenersCount = 0;
67251
- addEventListener(type, callback) {
67252
- ++this.listenersCount;
67253
- super.addEventListener(type, callback);
67254
- }
67255
- removeEventListener(type, callback) {
67256
- --this.listenersCount;
67257
- super.removeEventListener(type, callback);
67258
- }
67259
- hasListeners() {
67260
- return this.listenersCount > 0;
67261
- }
67262
- };
67263
- function improveWASMErrorReporting(runtime) {
67264
- runtime.asm = {
67265
- ...runtime.asm
67266
- };
67267
- const target = new UnhandledRejectionsTarget();
67268
- for (const key in runtime.asm) {
67269
- if (typeof runtime.asm[key] == "function") {
67270
- const original = runtime.asm[key];
67271
- runtime.asm[key] = function(...args) {
67272
- try {
67273
- return original(...args);
67274
- } catch (e) {
67275
- if (!(e instanceof Error)) {
67276
- throw e;
67277
- }
67278
- if ("exitCode" in e && e?.exitCode === 0) {
67279
- return;
67280
- }
67281
- const clearMessage = clarifyErrorMessage(
67282
- e,
67283
- runtime.lastAsyncifyStackSource?.stack
67284
- );
67285
- if (runtime.lastAsyncifyStackSource) {
67286
- e.cause = runtime.lastAsyncifyStackSource;
67287
- }
67288
- if (!target.hasListeners()) {
67289
- showCriticalErrorBox(clearMessage);
67290
- throw e;
67291
- }
67292
- target.dispatchEvent(
67293
- new ErrorEvent("error", {
67294
- error: e,
67295
- message: clearMessage
67296
- })
67297
- );
67298
- }
67299
- };
67300
- }
67301
- }
67302
- return target;
67303
- }
67304
- var functionsMaybeMissingFromAsyncify = [];
67305
- function getFunctionsMaybeMissingFromAsyncify() {
67306
- return functionsMaybeMissingFromAsyncify;
67307
- }
67308
- function clarifyErrorMessage(crypticError, asyncifyStack) {
67309
- if (crypticError.message === "unreachable") {
67310
- let betterMessage = UNREACHABLE_ERROR;
67311
- if (!asyncifyStack) {
67312
- betterMessage += `
67313
-
67314
- This stack trace is lacking. For a better one initialize
67315
- the PHP runtime with { debug: true }, e.g. PHPNode.load('8.1', { debug: true }).
67316
-
67317
- `;
67318
- }
67319
- functionsMaybeMissingFromAsyncify = extractPHPFunctionsFromStack(
67320
- asyncifyStack || crypticError.stack || ""
67321
- );
67322
- for (const fn of functionsMaybeMissingFromAsyncify) {
67323
- betterMessage += ` * ${fn}
67324
- `;
67325
- }
67326
- return betterMessage;
67327
- }
67328
- return crypticError.message;
67329
- }
67330
- var UNREACHABLE_ERROR = `
67331
- "unreachable" WASM instruction executed.
67332
-
67333
- The typical reason is a PHP function missing from the ASYNCIFY_ONLY
67334
- list when building PHP.wasm.
67335
-
67336
- You will need to file a new issue in the WordPress Playground repository
67337
- and paste this error message there:
67338
-
67339
- https://github.com/WordPress/wordpress-playground/issues/new
67340
-
67341
- If you're a core developer, the typical fix is to:
67342
-
67343
- * Isolate a minimal reproduction of the error
67344
- * Add a reproduction of the error to php-asyncify.spec.ts in the WordPress Playground repository
67345
- * Run 'npm run fix-asyncify'
67346
- * Commit the changes, push to the repo, release updated NPM packages
67347
-
67348
- Below is a list of all the PHP functions found in the stack trace to
67349
- help with the minimal reproduction. If they're all already listed in
67350
- the Dockerfile, you'll need to trigger this error again with long stack
67351
- traces enabled. In node.js, you can do it using the --stack-trace-limit=100
67352
- CLI option:
67353
-
67354
- `;
67355
- var redBg = "\x1B[41m";
67356
- var bold = "\x1B[1m";
67357
- var reset = "\x1B[0m";
67358
- var eol = "\x1B[K";
67359
- var logged = false;
67360
- function showCriticalErrorBox(message) {
67361
- if (logged) {
67362
- return;
67363
- }
67364
- logged = true;
67365
- console.log(`${redBg}
67366
- ${eol}
67367
- ${bold} WASM ERROR${reset}${redBg}`);
67368
- for (const line of message.split("\n")) {
67369
- console.log(`${eol} ${line} `);
67370
- }
67371
- console.log(`${reset}`);
67372
- }
67373
- function extractPHPFunctionsFromStack(stack) {
67374
- try {
67375
- const names = stack.split("\n").slice(1).map((line) => {
67376
- const parts = line.trim().substring("at ".length).split(" ");
67377
- return {
67378
- fn: parts.length >= 2 ? parts[0] : "<unknown>",
67379
- isWasm: line.includes("wasm://")
67380
- };
67381
- }).filter(
67382
- ({ fn, isWasm }) => isWasm && !fn.startsWith("dynCall_") && !fn.startsWith("invoke_")
67383
- ).map(({ fn }) => fn);
67384
- return Array.from(new Set(names));
67385
- } catch (err) {
67386
- return [];
67387
- }
67388
- }
67389
-
67390
67390
  // packages/php-wasm/universal/src/lib/base-php.ts
67391
67391
  var STRING = "string";
67392
67392
  var NUMBER = "number";
@@ -67396,6 +67396,7 @@ var BasePHP2 = class {
67396
67396
  #phpIniOverrides = [];
67397
67397
  #webSapiInitialized = false;
67398
67398
  #wasmErrorsTarget = null;
67399
+ #serverEntries = {};
67399
67400
  requestHandler;
67400
67401
  /**
67401
67402
  * Initializes a PHP runtime.
@@ -67499,6 +67500,7 @@ var BasePHP2 = class {
67499
67500
  if (request.code) {
67500
67501
  this.#setPHPCode(" ?>" + request.code);
67501
67502
  }
67503
+ this.#addServerGlobalEntriesInWasm();
67502
67504
  return await this.#handleRequest();
67503
67505
  }
67504
67506
  #initWebRuntime() {
@@ -67644,12 +67646,17 @@ var BasePHP2 = class {
67644
67646
  );
67645
67647
  }
67646
67648
  addServerGlobalEntry(key, value) {
67647
- this[__private__dont__use].ccall(
67648
- "wasm_add_SERVER_entry",
67649
- null,
67650
- [STRING, STRING],
67651
- [key, value]
67652
- );
67649
+ this.#serverEntries[key] = value;
67650
+ }
67651
+ #addServerGlobalEntriesInWasm() {
67652
+ for (const key in this.#serverEntries) {
67653
+ this[__private__dont__use].ccall(
67654
+ "wasm_add_SERVER_entry",
67655
+ null,
67656
+ [STRING, STRING],
67657
+ [key, this.#serverEntries[key]]
67658
+ );
67659
+ }
67653
67660
  }
67654
67661
  /**
67655
67662
  * Adds file information to $_FILES superglobal in PHP.
@@ -67732,6 +67739,7 @@ var BasePHP2 = class {
67732
67739
  throw rethrown;
67733
67740
  } finally {
67734
67741
  this.#wasmErrorsTarget?.removeEventListener("error", errorListener);
67742
+ this.#serverEntries = {};
67735
67743
  }
67736
67744
  const { headers, httpStatusCode } = this.#getResponseHeaders();
67737
67745
  return new PHPResponse(
@@ -68247,6 +68255,9 @@ var _NodePHP = class extends BasePHP2 {
68247
68255
  this.chdir(process.cwd());
68248
68256
  }
68249
68257
  mount(localPath, virtualFSPath) {
68258
+ if (!this.fileExists(virtualFSPath)) {
68259
+ this.mkdirTree(virtualFSPath);
68260
+ }
68250
68261
  this[__private__dont__use].FS.mount(
68251
68262
  this[__private__dont__use].FS.filesystems.NODEFS,
68252
68263
  typeof localPath === "object" ? localPath : { root: localPath },
@@ -68286,7 +68297,7 @@ var _NodePHP = class extends BasePHP2 {
68286
68297
  };
68287
68298
  var NodePHP = _NodePHP;
68288
68299
  __decorateClass([
68289
- rethrowFileSystemError("Could not mount a directory")
68300
+ rethrowFileSystemError("Could not mount {path}")
68290
68301
  ], NodePHP.prototype, "mount", 1);
68291
68302
  // Annotate the CommonJS export names for ESM import in node:
68292
68303
  0 && (module.exports = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@php-wasm/node",
3
- "version": "0.1.40",
3
+ "version": "0.1.45",
4
4
  "description": "PHP.wasm for Node.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -28,13 +28,13 @@
28
28
  "license": "GPL-2.0-or-later",
29
29
  "main": "index.cjs",
30
30
  "types": "index.d.ts",
31
- "gitHead": "d4817100bc505f21309e07a5b2cec1f2be38e85d",
31
+ "gitHead": "ca75514c17b912dc8b5dc529f6d123295671320a",
32
32
  "dependencies": {
33
33
  "comlink": "4.4.1",
34
34
  "express": "4.18.2",
35
35
  "ws": "8.13.0",
36
36
  "yargs": "17.7.2",
37
- "@php-wasm/universal": "0.1.40",
38
- "@php-wasm/util": "0.1.40"
37
+ "@php-wasm/universal": "0.1.45",
38
+ "@php-wasm/util": "0.1.45"
39
39
  }
40
40
  }
package/php_5_6.wasm CHANGED
Binary file
package/php_7_0.wasm CHANGED
Binary file
package/php_7_1.wasm CHANGED
Binary file
package/php_7_2.wasm CHANGED
Binary file
package/php_7_3.wasm CHANGED
Binary file
package/php_7_4.wasm CHANGED
Binary file
package/php_8_0.wasm CHANGED
Binary file
package/php_8_1.wasm CHANGED
Binary file
package/php_8_2.wasm CHANGED
Binary file