@php-wasm/node 2.0.22 → 3.0.2

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 (39) hide show
  1. package/asyncify/7_2_34/php_7_2.wasm +0 -0
  2. package/asyncify/7_3_33/php_7_3.wasm +0 -0
  3. package/asyncify/7_4_33/php_7_4.wasm +0 -0
  4. package/asyncify/8_0_30/php_8_0.wasm +0 -0
  5. package/asyncify/8_1_33/php_8_1.wasm +0 -0
  6. package/asyncify/8_2_29/php_8_2.wasm +0 -0
  7. package/asyncify/8_3_23/php_8_3.wasm +0 -0
  8. package/asyncify/8_3_25/php_8_3.wasm +0 -0
  9. package/asyncify/8_4_10/php_8_4.wasm +0 -0
  10. package/asyncify/8_4_12/php_8_4.wasm +0 -0
  11. package/asyncify/php_7_2.js +32177 -35528
  12. package/asyncify/php_7_3.js +32190 -35541
  13. package/asyncify/php_7_4.js +32201 -35551
  14. package/asyncify/php_8_0.js +66 -43
  15. package/asyncify/php_8_1.js +59 -36
  16. package/asyncify/php_8_2.js +59 -36
  17. package/asyncify/php_8_3.js +66 -43
  18. package/asyncify/php_8_4.js +59 -36
  19. package/index.cjs +6322 -17736
  20. package/index.js +6322 -17736
  21. package/jspi/7_2_34/php_7_2.wasm +0 -0
  22. package/jspi/7_3_33/php_7_3.wasm +0 -0
  23. package/jspi/7_4_33/php_7_4.wasm +0 -0
  24. package/jspi/8_0_30/php_8_0.wasm +0 -0
  25. package/jspi/8_1_33/php_8_1.wasm +0 -0
  26. package/jspi/8_2_29/php_8_2.wasm +0 -0
  27. package/jspi/8_3_24/php_8_3.wasm +0 -0
  28. package/jspi/8_3_25/php_8_3.wasm +0 -0
  29. package/jspi/8_4_12/php_8_4.wasm +0 -0
  30. package/jspi/php_7_2.js +31550 -34341
  31. package/jspi/php_7_3.js +31550 -34341
  32. package/jspi/php_7_4.js +31550 -34340
  33. package/jspi/php_8_0.js +66 -43
  34. package/jspi/php_8_1.js +59 -36
  35. package/jspi/php_8_2.js +66 -43
  36. package/jspi/php_8_3.js +66 -43
  37. package/jspi/php_8_4.js +59 -36
  38. package/lib/load-runtime.d.ts +11 -0
  39. package/package.json +7 -7
package/jspi/php_8_3.js CHANGED
@@ -8,7 +8,7 @@ import path from 'path';
8
8
 
9
9
  const dependencyFilename = path.join(__dirname, '8_3_25', 'php_8_3.wasm');
10
10
  export { dependencyFilename };
11
- export const dependenciesTotalSize = 26008228;
11
+ export const dependenciesTotalSize = 26008164;
12
12
  const phpVersionString = '8.3.25';
13
13
  export function init(RuntimeName, PHPLoader) {
14
14
  // The rest of the code comes from the built php.js file and esm-suffix.js
@@ -848,7 +848,7 @@ export function init(RuntimeName, PHPLoader) {
848
848
  },
849
849
  };
850
850
 
851
- var ___heap_base = 13877856;
851
+ var ___heap_base = 13877792;
852
852
 
853
853
  var alignMemory = (size, alignment) => {
854
854
  return Math.ceil(size / alignment) * alignment;
@@ -1743,13 +1743,13 @@ export function init(RuntimeName, PHPLoader) {
1743
1743
  1024
1744
1744
  );
1745
1745
 
1746
- var ___stack_high = 13877856;
1746
+ var ___stack_high = 13877792;
1747
1747
 
1748
- var ___stack_low = 12829280;
1748
+ var ___stack_low = 12829216;
1749
1749
 
1750
1750
  var ___stack_pointer = new WebAssembly.Global(
1751
1751
  { value: 'i32', mutable: true },
1752
- 13877856
1752
+ 13877792
1753
1753
  );
1754
1754
 
1755
1755
  var PATH = {
@@ -6578,7 +6578,7 @@ export function init(RuntimeName, PHPLoader) {
6578
6578
  O_NONBLOCK: 2048,
6579
6579
  POLLHUP: 16,
6580
6580
  SETFL_MASK: 3072,
6581
- init: function () {
6581
+ init: function (phpWasmInitOptions) {
6582
6582
  Module['ENV'] = Module['ENV'] || {};
6583
6583
  // Ensure a platform-level bin directory for a fallback `php` binary.
6584
6584
  Module['ENV']['PATH'] = [
@@ -6588,28 +6588,48 @@ export function init(RuntimeName, PHPLoader) {
6588
6588
  .filter(Boolean)
6589
6589
  .join(':');
6590
6590
 
6591
- // The /internal directory is required by the C module. It's where the
6591
+ // The /request directory is required by the C module. It's where the
6592
6592
  // stdout, stderr, and headers information are written for the JavaScript
6593
- // code to read later on.
6593
+ // code to read later on. This is per-request state that is isolated to a
6594
+ // single PHP process.
6595
+ FS.mkdir('/request');
6596
+ // The /internal directory is shared amongst all PHP processes
6597
+ // and contains wp-config.php, constants, etc.
6594
6598
  FS.mkdir('/internal');
6599
+
6600
+ if (phpWasmInitOptions?.nativeInternalDirPath) {
6601
+ FS.mount(
6602
+ FS.filesystems.NODEFS,
6603
+ { root: phpWasmInitOptions.nativeInternalDirPath },
6604
+ '/internal'
6605
+ );
6606
+ }
6607
+
6595
6608
  // The files from the shared directory are shared between all the
6596
6609
  // PHP processes managed by PHPProcessManager.
6597
- FS.mkdir('/internal/shared');
6610
+ FS.mkdirTree('/internal/shared');
6611
+
6598
6612
  // The files from the preload directory are preloaded using the
6599
6613
  // auto_prepend_file php.ini directive.
6600
- FS.mkdir('/internal/shared/preload');
6614
+ FS.mkdirTree('/internal/shared/preload');
6601
6615
  // Platform-level bin directory for a fallback `php` binary. Without it,
6602
6616
  // PHP may not populate the PHP_BINARY constant.
6603
- FS.mkdir('/internal/shared/bin');
6617
+ FS.mkdirTree('/internal/shared/bin');
6604
6618
  const originalOnRuntimeInitialized = Module['onRuntimeInitialized'];
6605
6619
  Module['onRuntimeInitialized'] = () => {
6606
- // Dummy PHP binary for PHP to populate the PHP_BINARY constant.
6607
- FS.writeFile(
6620
+ const { node: phpBinaryNode } = FS.lookupPath(
6608
6621
  '/internal/shared/bin/php',
6609
- new TextEncoder().encode('#!/bin/sh\nphp "$@"')
6622
+ { noent_okay: true }
6610
6623
  );
6611
- // It must be executable to be used by PHP.
6612
- FS.chmod('/internal/shared/bin/php', 0o755);
6624
+ if (!phpBinaryNode) {
6625
+ // Dummy PHP binary for PHP to populate the PHP_BINARY constant.
6626
+ FS.writeFile(
6627
+ '/internal/shared/bin/php',
6628
+ new TextEncoder().encode('#!/bin/sh\nphp "$@"')
6629
+ );
6630
+ // It must be executable to be used by PHP.
6631
+ FS.chmod('/internal/shared/bin/php', 0o755);
6632
+ }
6613
6633
  originalOnRuntimeInitialized();
6614
6634
  };
6615
6635
 
@@ -6627,7 +6647,7 @@ export function init(RuntimeName, PHPLoader) {
6627
6647
  return length;
6628
6648
  },
6629
6649
  });
6630
- FS.mkdev('/internal/stdout', FS.makedev(64, 0));
6650
+ FS.mkdev('/request/stdout', FS.makedev(64, 0));
6631
6651
 
6632
6652
  FS.registerDevice(FS.makedev(63, 0), {
6633
6653
  open: () => {},
@@ -6639,7 +6659,7 @@ export function init(RuntimeName, PHPLoader) {
6639
6659
  return length;
6640
6660
  },
6641
6661
  });
6642
- FS.mkdev('/internal/stderr', FS.makedev(63, 0));
6662
+ FS.mkdev('/request/stderr', FS.makedev(63, 0));
6643
6663
 
6644
6664
  FS.registerDevice(FS.makedev(62, 0), {
6645
6665
  open: () => {},
@@ -6651,7 +6671,7 @@ export function init(RuntimeName, PHPLoader) {
6651
6671
  return length;
6652
6672
  },
6653
6673
  });
6654
- FS.mkdev('/internal/headers', FS.makedev(62, 0));
6674
+ FS.mkdev('/request/headers', FS.makedev(62, 0));
6655
6675
 
6656
6676
  // Handle events.
6657
6677
  PHPWASM.EventEmitter = ENVIRONMENT_IS_NODE
@@ -6884,34 +6904,37 @@ export function init(RuntimeName, PHPLoader) {
6884
6904
 
6885
6905
  var _fd_close = function fd_close(fd) {
6886
6906
  return Asyncify.handleAsync(async () => {
6907
+ // We have to get the VFS path from the file descriptor
6908
+ // before closing it.
6909
+ const [vfsPath, vfsPathResolutionErrno] =
6910
+ locking.get_vfs_path_from_fd(fd);
6911
+
6887
6912
  const fdCloseResult = _builtin_fd_close(fd);
6888
6913
  if (fdCloseResult !== 0 || !locking.maybeLockedFds.has(fd)) {
6889
6914
  _js_wasm_trace('fd_close(%d) result %d', fd, fdCloseResult);
6890
6915
  return fdCloseResult;
6891
6916
  }
6892
6917
 
6893
- try {
6894
- const [vfsPath, pathResolutionErrno] =
6895
- locking.get_vfs_path_from_fd(fd);
6896
- if (pathResolutionErrno !== 0) {
6897
- _js_wasm_trace(
6898
- 'fd_close(%d) get_vfs_path_from_fd error %d',
6899
- fd,
6900
- pathResolutionErrno
6901
- );
6902
- /*
6903
- * It looks like the file may have had an associated lock,
6904
- * but since we cannot look up the path,
6905
- * there is nothing more for us to do.
6906
- *
6907
- * NOTE: This seems possible for files that are locked and
6908
- * then unlinked before close. It is an opportunity for a
6909
- * lock to be orphaned in the lock manager.
6910
- * @TODO: Explore how to ensure cleanup in this case.
6911
- */
6912
- return fdCloseResult;
6913
- }
6918
+ if (vfsPathResolutionErrno !== 0) {
6919
+ _js_wasm_trace(
6920
+ 'fd_close(%d) get_vfs_path_from_fd error %d',
6921
+ fd,
6922
+ vfsPathResolutionErrno
6923
+ );
6924
+ /*
6925
+ * It looks like the file may have had an associated lock,
6926
+ * but since we cannot look up the path,
6927
+ * there is nothing more for us to do.
6928
+ *
6929
+ * NOTE: This seems possible for files that are locked and
6930
+ * then unlinked before close. It is an opportunity for a
6931
+ * lock to be orphaned in the lock manager.
6932
+ * @TODO: Explore how to ensure cleanup in this case.
6933
+ */
6934
+ return fdCloseResult;
6935
+ }
6914
6936
 
6937
+ try {
6915
6938
  const nativeFilePath =
6916
6939
  locking.get_native_path_from_vfs_path(vfsPath);
6917
6940
  await PHPLoader.fileLockManager.releaseLocksForProcessFd(
@@ -31209,7 +31232,7 @@ export function init(RuntimeName, PHPLoader) {
31209
31232
  if (ENVIRONMENT_IS_NODE) {
31210
31233
  NODEFS.staticInit();
31211
31234
  }
31212
- PHPWASM.init();
31235
+ PHPWASM.init(PHPLoader?.phpWasmInitOptions);
31213
31236
 
31214
31237
  Module['requestAnimationFrame'] = MainLoop.requestAnimationFrame;
31215
31238
  Module['pauseMainLoop'] = MainLoop.pause;
@@ -31275,13 +31298,13 @@ export function init(RuntimeName, PHPLoader) {
31275
31298
  // End JS library code
31276
31299
 
31277
31300
  var ASM_CONSTS = {
31278
- 12633246: ($0) => {
31301
+ 12633182: ($0) => {
31279
31302
  if (!$0) {
31280
31303
  AL.alcErr = 0xa004;
31281
31304
  return 1;
31282
31305
  }
31283
31306
  },
31284
- 12633294: ($0) => {
31307
+ 12633230: ($0) => {
31285
31308
  if (!AL.currentCtx) {
31286
31309
  err('alGetProcAddress() called without a valid context');
31287
31310
  return 1;
package/jspi/php_8_4.js CHANGED
@@ -6578,7 +6578,7 @@ export function init(RuntimeName, PHPLoader) {
6578
6578
  O_NONBLOCK: 2048,
6579
6579
  POLLHUP: 16,
6580
6580
  SETFL_MASK: 3072,
6581
- init: function () {
6581
+ init: function (phpWasmInitOptions) {
6582
6582
  Module['ENV'] = Module['ENV'] || {};
6583
6583
  // Ensure a platform-level bin directory for a fallback `php` binary.
6584
6584
  Module['ENV']['PATH'] = [
@@ -6588,28 +6588,48 @@ export function init(RuntimeName, PHPLoader) {
6588
6588
  .filter(Boolean)
6589
6589
  .join(':');
6590
6590
 
6591
- // The /internal directory is required by the C module. It's where the
6591
+ // The /request directory is required by the C module. It's where the
6592
6592
  // stdout, stderr, and headers information are written for the JavaScript
6593
- // code to read later on.
6593
+ // code to read later on. This is per-request state that is isolated to a
6594
+ // single PHP process.
6595
+ FS.mkdir('/request');
6596
+ // The /internal directory is shared amongst all PHP processes
6597
+ // and contains wp-config.php, constants, etc.
6594
6598
  FS.mkdir('/internal');
6599
+
6600
+ if (phpWasmInitOptions?.nativeInternalDirPath) {
6601
+ FS.mount(
6602
+ FS.filesystems.NODEFS,
6603
+ { root: phpWasmInitOptions.nativeInternalDirPath },
6604
+ '/internal'
6605
+ );
6606
+ }
6607
+
6595
6608
  // The files from the shared directory are shared between all the
6596
6609
  // PHP processes managed by PHPProcessManager.
6597
- FS.mkdir('/internal/shared');
6610
+ FS.mkdirTree('/internal/shared');
6611
+
6598
6612
  // The files from the preload directory are preloaded using the
6599
6613
  // auto_prepend_file php.ini directive.
6600
- FS.mkdir('/internal/shared/preload');
6614
+ FS.mkdirTree('/internal/shared/preload');
6601
6615
  // Platform-level bin directory for a fallback `php` binary. Without it,
6602
6616
  // PHP may not populate the PHP_BINARY constant.
6603
- FS.mkdir('/internal/shared/bin');
6617
+ FS.mkdirTree('/internal/shared/bin');
6604
6618
  const originalOnRuntimeInitialized = Module['onRuntimeInitialized'];
6605
6619
  Module['onRuntimeInitialized'] = () => {
6606
- // Dummy PHP binary for PHP to populate the PHP_BINARY constant.
6607
- FS.writeFile(
6620
+ const { node: phpBinaryNode } = FS.lookupPath(
6608
6621
  '/internal/shared/bin/php',
6609
- new TextEncoder().encode('#!/bin/sh\nphp "$@"')
6622
+ { noent_okay: true }
6610
6623
  );
6611
- // It must be executable to be used by PHP.
6612
- FS.chmod('/internal/shared/bin/php', 0o755);
6624
+ if (!phpBinaryNode) {
6625
+ // Dummy PHP binary for PHP to populate the PHP_BINARY constant.
6626
+ FS.writeFile(
6627
+ '/internal/shared/bin/php',
6628
+ new TextEncoder().encode('#!/bin/sh\nphp "$@"')
6629
+ );
6630
+ // It must be executable to be used by PHP.
6631
+ FS.chmod('/internal/shared/bin/php', 0o755);
6632
+ }
6613
6633
  originalOnRuntimeInitialized();
6614
6634
  };
6615
6635
 
@@ -6627,7 +6647,7 @@ export function init(RuntimeName, PHPLoader) {
6627
6647
  return length;
6628
6648
  },
6629
6649
  });
6630
- FS.mkdev('/internal/stdout', FS.makedev(64, 0));
6650
+ FS.mkdev('/request/stdout', FS.makedev(64, 0));
6631
6651
 
6632
6652
  FS.registerDevice(FS.makedev(63, 0), {
6633
6653
  open: () => {},
@@ -6639,7 +6659,7 @@ export function init(RuntimeName, PHPLoader) {
6639
6659
  return length;
6640
6660
  },
6641
6661
  });
6642
- FS.mkdev('/internal/stderr', FS.makedev(63, 0));
6662
+ FS.mkdev('/request/stderr', FS.makedev(63, 0));
6643
6663
 
6644
6664
  FS.registerDevice(FS.makedev(62, 0), {
6645
6665
  open: () => {},
@@ -6651,7 +6671,7 @@ export function init(RuntimeName, PHPLoader) {
6651
6671
  return length;
6652
6672
  },
6653
6673
  });
6654
- FS.mkdev('/internal/headers', FS.makedev(62, 0));
6674
+ FS.mkdev('/request/headers', FS.makedev(62, 0));
6655
6675
 
6656
6676
  // Handle events.
6657
6677
  PHPWASM.EventEmitter = ENVIRONMENT_IS_NODE
@@ -6884,34 +6904,37 @@ export function init(RuntimeName, PHPLoader) {
6884
6904
 
6885
6905
  var _fd_close = function fd_close(fd) {
6886
6906
  return Asyncify.handleAsync(async () => {
6907
+ // We have to get the VFS path from the file descriptor
6908
+ // before closing it.
6909
+ const [vfsPath, vfsPathResolutionErrno] =
6910
+ locking.get_vfs_path_from_fd(fd);
6911
+
6887
6912
  const fdCloseResult = _builtin_fd_close(fd);
6888
6913
  if (fdCloseResult !== 0 || !locking.maybeLockedFds.has(fd)) {
6889
6914
  _js_wasm_trace('fd_close(%d) result %d', fd, fdCloseResult);
6890
6915
  return fdCloseResult;
6891
6916
  }
6892
6917
 
6893
- try {
6894
- const [vfsPath, pathResolutionErrno] =
6895
- locking.get_vfs_path_from_fd(fd);
6896
- if (pathResolutionErrno !== 0) {
6897
- _js_wasm_trace(
6898
- 'fd_close(%d) get_vfs_path_from_fd error %d',
6899
- fd,
6900
- pathResolutionErrno
6901
- );
6902
- /*
6903
- * It looks like the file may have had an associated lock,
6904
- * but since we cannot look up the path,
6905
- * there is nothing more for us to do.
6906
- *
6907
- * NOTE: This seems possible for files that are locked and
6908
- * then unlinked before close. It is an opportunity for a
6909
- * lock to be orphaned in the lock manager.
6910
- * @TODO: Explore how to ensure cleanup in this case.
6911
- */
6912
- return fdCloseResult;
6913
- }
6918
+ if (vfsPathResolutionErrno !== 0) {
6919
+ _js_wasm_trace(
6920
+ 'fd_close(%d) get_vfs_path_from_fd error %d',
6921
+ fd,
6922
+ vfsPathResolutionErrno
6923
+ );
6924
+ /*
6925
+ * It looks like the file may have had an associated lock,
6926
+ * but since we cannot look up the path,
6927
+ * there is nothing more for us to do.
6928
+ *
6929
+ * NOTE: This seems possible for files that are locked and
6930
+ * then unlinked before close. It is an opportunity for a
6931
+ * lock to be orphaned in the lock manager.
6932
+ * @TODO: Explore how to ensure cleanup in this case.
6933
+ */
6934
+ return fdCloseResult;
6935
+ }
6914
6936
 
6937
+ try {
6915
6938
  const nativeFilePath =
6916
6939
  locking.get_native_path_from_vfs_path(vfsPath);
6917
6940
  await PHPLoader.fileLockManager.releaseLocksForProcessFd(
@@ -31209,7 +31232,7 @@ export function init(RuntimeName, PHPLoader) {
31209
31232
  if (ENVIRONMENT_IS_NODE) {
31210
31233
  NODEFS.staticInit();
31211
31234
  }
31212
- PHPWASM.init();
31235
+ PHPWASM.init(PHPLoader?.phpWasmInitOptions);
31213
31236
 
31214
31237
  Module['requestAnimationFrame'] = MainLoop.requestAnimationFrame;
31215
31238
  Module['pauseMainLoop'] = MainLoop.pause;
@@ -36,6 +36,17 @@ type PHPLoaderOptionsForNode = PHPLoaderOptions & {
36
36
  * @param args - Arguments to the format string.
37
37
  */
38
38
  trace?: (processId: number, format: string, ...args: any[]) => void;
39
+ /**
40
+ * An optional object to pass to the PHP-WASM library's `init` function.
41
+ *
42
+ * phpWasmInitOptions.nativeInternalDirPath is used to mount a
43
+ * real, native directory as the php-wasm /internal directory.
44
+ *
45
+ * @see https://github.com/php-wasm/php-wasm/blob/main/compile/php/phpwasm-emscripten-library.js#L100
46
+ */
47
+ phpWasmInitOptions?: {
48
+ nativeInternalDirPath?: string;
49
+ };
39
50
  };
40
51
  };
41
52
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@php-wasm/node",
3
- "version": "2.0.22",
3
+ "version": "3.0.2",
4
4
  "description": "PHP.wasm for Node.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -38,7 +38,7 @@
38
38
  },
39
39
  "license": "GPL-2.0-or-later",
40
40
  "types": "index.d.ts",
41
- "gitHead": "4ba4984b3ab981acafc5d7139258985d345f1caf",
41
+ "gitHead": "35cc84863d9e92c1e6a5d354bb0727673b461216",
42
42
  "engines": {
43
43
  "node": ">=20.18.3",
44
44
  "npm": ">=10.1.0"
@@ -49,11 +49,11 @@
49
49
  "wasm-feature-detect": "1.8.0",
50
50
  "ws": "8.18.1",
51
51
  "yargs": "17.7.2",
52
- "@php-wasm/node-polyfills": "2.0.22",
53
- "@php-wasm/universal": "2.0.22",
54
- "@php-wasm/logger": "2.0.22",
55
- "@php-wasm/util": "2.0.22",
56
- "@wp-playground/common": "2.0.22"
52
+ "@php-wasm/node-polyfills": "3.0.2",
53
+ "@php-wasm/universal": "3.0.2",
54
+ "@php-wasm/logger": "3.0.2",
55
+ "@php-wasm/util": "3.0.2",
56
+ "@wp-playground/common": "3.0.2"
57
57
  },
58
58
  "overrides": {
59
59
  "rollup": "^4.34.6",