@php-wasm/node 2.0.22 → 3.0.1

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
@@ -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 = 26575874;
11
+ export const dependenciesTotalSize = 26575810;
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
@@ -831,7 +831,7 @@ export function init(RuntimeName, PHPLoader) {
831
831
  },
832
832
  };
833
833
 
834
- var ___heap_base = 13876736;
834
+ var ___heap_base = 13876672;
835
835
 
836
836
  var alignMemory = (size, alignment) => {
837
837
  return Math.ceil(size / alignment) * alignment;
@@ -1786,13 +1786,13 @@ export function init(RuntimeName, PHPLoader) {
1786
1786
  1024
1787
1787
  );
1788
1788
 
1789
- var ___stack_high = 13876736;
1789
+ var ___stack_high = 13876672;
1790
1790
 
1791
- var ___stack_low = 12828160;
1791
+ var ___stack_low = 12828096;
1792
1792
 
1793
1793
  var ___stack_pointer = new WebAssembly.Global(
1794
1794
  { value: 'i32', mutable: true },
1795
- 13876736
1795
+ 13876672
1796
1796
  );
1797
1797
 
1798
1798
  var PATH = {
@@ -6621,7 +6621,7 @@ export function init(RuntimeName, PHPLoader) {
6621
6621
  O_NONBLOCK: 2048,
6622
6622
  POLLHUP: 16,
6623
6623
  SETFL_MASK: 3072,
6624
- init: function () {
6624
+ init: function (phpWasmInitOptions) {
6625
6625
  Module['ENV'] = Module['ENV'] || {};
6626
6626
  // Ensure a platform-level bin directory for a fallback `php` binary.
6627
6627
  Module['ENV']['PATH'] = [
@@ -6631,28 +6631,48 @@ export function init(RuntimeName, PHPLoader) {
6631
6631
  .filter(Boolean)
6632
6632
  .join(':');
6633
6633
 
6634
- // The /internal directory is required by the C module. It's where the
6634
+ // The /request directory is required by the C module. It's where the
6635
6635
  // stdout, stderr, and headers information are written for the JavaScript
6636
- // code to read later on.
6636
+ // code to read later on. This is per-request state that is isolated to a
6637
+ // single PHP process.
6638
+ FS.mkdir('/request');
6639
+ // The /internal directory is shared amongst all PHP processes
6640
+ // and contains wp-config.php, constants, etc.
6637
6641
  FS.mkdir('/internal');
6642
+
6643
+ if (phpWasmInitOptions?.nativeInternalDirPath) {
6644
+ FS.mount(
6645
+ FS.filesystems.NODEFS,
6646
+ { root: phpWasmInitOptions.nativeInternalDirPath },
6647
+ '/internal'
6648
+ );
6649
+ }
6650
+
6638
6651
  // The files from the shared directory are shared between all the
6639
6652
  // PHP processes managed by PHPProcessManager.
6640
- FS.mkdir('/internal/shared');
6653
+ FS.mkdirTree('/internal/shared');
6654
+
6641
6655
  // The files from the preload directory are preloaded using the
6642
6656
  // auto_prepend_file php.ini directive.
6643
- FS.mkdir('/internal/shared/preload');
6657
+ FS.mkdirTree('/internal/shared/preload');
6644
6658
  // Platform-level bin directory for a fallback `php` binary. Without it,
6645
6659
  // PHP may not populate the PHP_BINARY constant.
6646
- FS.mkdir('/internal/shared/bin');
6660
+ FS.mkdirTree('/internal/shared/bin');
6647
6661
  const originalOnRuntimeInitialized = Module['onRuntimeInitialized'];
6648
6662
  Module['onRuntimeInitialized'] = () => {
6649
- // Dummy PHP binary for PHP to populate the PHP_BINARY constant.
6650
- FS.writeFile(
6663
+ const { node: phpBinaryNode } = FS.lookupPath(
6651
6664
  '/internal/shared/bin/php',
6652
- new TextEncoder().encode('#!/bin/sh\nphp "$@"')
6665
+ { noent_okay: true }
6653
6666
  );
6654
- // It must be executable to be used by PHP.
6655
- FS.chmod('/internal/shared/bin/php', 0o755);
6667
+ if (!phpBinaryNode) {
6668
+ // Dummy PHP binary for PHP to populate the PHP_BINARY constant.
6669
+ FS.writeFile(
6670
+ '/internal/shared/bin/php',
6671
+ new TextEncoder().encode('#!/bin/sh\nphp "$@"')
6672
+ );
6673
+ // It must be executable to be used by PHP.
6674
+ FS.chmod('/internal/shared/bin/php', 0o755);
6675
+ }
6656
6676
  originalOnRuntimeInitialized();
6657
6677
  };
6658
6678
 
@@ -6670,7 +6690,7 @@ export function init(RuntimeName, PHPLoader) {
6670
6690
  return length;
6671
6691
  },
6672
6692
  });
6673
- FS.mkdev('/internal/stdout', FS.makedev(64, 0));
6693
+ FS.mkdev('/request/stdout', FS.makedev(64, 0));
6674
6694
 
6675
6695
  FS.registerDevice(FS.makedev(63, 0), {
6676
6696
  open: () => {},
@@ -6682,7 +6702,7 @@ export function init(RuntimeName, PHPLoader) {
6682
6702
  return length;
6683
6703
  },
6684
6704
  });
6685
- FS.mkdev('/internal/stderr', FS.makedev(63, 0));
6705
+ FS.mkdev('/request/stderr', FS.makedev(63, 0));
6686
6706
 
6687
6707
  FS.registerDevice(FS.makedev(62, 0), {
6688
6708
  open: () => {},
@@ -6694,7 +6714,7 @@ export function init(RuntimeName, PHPLoader) {
6694
6714
  return length;
6695
6715
  },
6696
6716
  });
6697
- FS.mkdev('/internal/headers', FS.makedev(62, 0));
6717
+ FS.mkdev('/request/headers', FS.makedev(62, 0));
6698
6718
 
6699
6719
  // Handle events.
6700
6720
  PHPWASM.EventEmitter = ENVIRONMENT_IS_NODE
@@ -6926,34 +6946,37 @@ export function init(RuntimeName, PHPLoader) {
6926
6946
  }
6927
6947
 
6928
6948
  function _fd_close(fd) {
6949
+ // We have to get the VFS path from the file descriptor
6950
+ // before closing it.
6951
+ const [vfsPath, vfsPathResolutionErrno] =
6952
+ locking.get_vfs_path_from_fd(fd);
6953
+
6929
6954
  const fdCloseResult = _builtin_fd_close(fd);
6930
6955
  if (fdCloseResult !== 0 || !locking.maybeLockedFds.has(fd)) {
6931
6956
  _js_wasm_trace('fd_close(%d) result %d', fd, fdCloseResult);
6932
6957
  return fdCloseResult;
6933
6958
  }
6934
6959
 
6935
- try {
6936
- const [vfsPath, pathResolutionErrno] =
6937
- locking.get_vfs_path_from_fd(fd);
6938
- if (pathResolutionErrno !== 0) {
6939
- _js_wasm_trace(
6940
- 'fd_close(%d) get_vfs_path_from_fd error %d',
6941
- fd,
6942
- pathResolutionErrno
6943
- );
6944
- /*
6945
- * It looks like the file may have had an associated lock,
6946
- * but since we cannot look up the path,
6947
- * there is nothing more for us to do.
6948
- *
6949
- * NOTE: This seems possible for files that are locked and
6950
- * then unlinked before close. It is an opportunity for a
6951
- * lock to be orphaned in the lock manager.
6952
- * @TODO: Explore how to ensure cleanup in this case.
6953
- */
6954
- return fdCloseResult;
6955
- }
6960
+ if (vfsPathResolutionErrno !== 0) {
6961
+ _js_wasm_trace(
6962
+ 'fd_close(%d) get_vfs_path_from_fd error %d',
6963
+ fd,
6964
+ vfsPathResolutionErrno
6965
+ );
6966
+ /*
6967
+ * It looks like the file may have had an associated lock,
6968
+ * but since we cannot look up the path,
6969
+ * there is nothing more for us to do.
6970
+ *
6971
+ * NOTE: This seems possible for files that are locked and
6972
+ * then unlinked before close. It is an opportunity for a
6973
+ * lock to be orphaned in the lock manager.
6974
+ * @TODO: Explore how to ensure cleanup in this case.
6975
+ */
6976
+ return fdCloseResult;
6977
+ }
6956
6978
 
6979
+ try {
6957
6980
  const nativeFilePath =
6958
6981
  locking.get_native_path_from_vfs_path(vfsPath);
6959
6982
  PHPLoader.fileLockManager.releaseLocksForProcessFd(
@@ -32049,7 +32072,7 @@ export function init(RuntimeName, PHPLoader) {
32049
32072
  if (ENVIRONMENT_IS_NODE) {
32050
32073
  NODEFS.staticInit();
32051
32074
  }
32052
- PHPWASM.init();
32075
+ PHPWASM.init(PHPLoader?.phpWasmInitOptions);
32053
32076
 
32054
32077
  Module['requestAnimationFrame'] = MainLoop.requestAnimationFrame;
32055
32078
  Module['pauseMainLoop'] = MainLoop.pause;
@@ -32115,13 +32138,13 @@ export function init(RuntimeName, PHPLoader) {
32115
32138
  // End JS library code
32116
32139
 
32117
32140
  var ASM_CONSTS = {
32118
- 12632685: ($0) => {
32141
+ 12632621: ($0) => {
32119
32142
  if (!$0) {
32120
32143
  AL.alcErr = 0xa004;
32121
32144
  return 1;
32122
32145
  }
32123
32146
  },
32124
- 12632733: ($0) => {
32147
+ 12632669: ($0) => {
32125
32148
  if (!AL.currentCtx) {
32126
32149
  err('alGetProcAddress() called without a valid context');
32127
32150
  return 1;
@@ -6621,7 +6621,7 @@ export function init(RuntimeName, PHPLoader) {
6621
6621
  O_NONBLOCK: 2048,
6622
6622
  POLLHUP: 16,
6623
6623
  SETFL_MASK: 3072,
6624
- init: function () {
6624
+ init: function (phpWasmInitOptions) {
6625
6625
  Module['ENV'] = Module['ENV'] || {};
6626
6626
  // Ensure a platform-level bin directory for a fallback `php` binary.
6627
6627
  Module['ENV']['PATH'] = [
@@ -6631,28 +6631,48 @@ export function init(RuntimeName, PHPLoader) {
6631
6631
  .filter(Boolean)
6632
6632
  .join(':');
6633
6633
 
6634
- // The /internal directory is required by the C module. It's where the
6634
+ // The /request directory is required by the C module. It's where the
6635
6635
  // stdout, stderr, and headers information are written for the JavaScript
6636
- // code to read later on.
6636
+ // code to read later on. This is per-request state that is isolated to a
6637
+ // single PHP process.
6638
+ FS.mkdir('/request');
6639
+ // The /internal directory is shared amongst all PHP processes
6640
+ // and contains wp-config.php, constants, etc.
6637
6641
  FS.mkdir('/internal');
6642
+
6643
+ if (phpWasmInitOptions?.nativeInternalDirPath) {
6644
+ FS.mount(
6645
+ FS.filesystems.NODEFS,
6646
+ { root: phpWasmInitOptions.nativeInternalDirPath },
6647
+ '/internal'
6648
+ );
6649
+ }
6650
+
6638
6651
  // The files from the shared directory are shared between all the
6639
6652
  // PHP processes managed by PHPProcessManager.
6640
- FS.mkdir('/internal/shared');
6653
+ FS.mkdirTree('/internal/shared');
6654
+
6641
6655
  // The files from the preload directory are preloaded using the
6642
6656
  // auto_prepend_file php.ini directive.
6643
- FS.mkdir('/internal/shared/preload');
6657
+ FS.mkdirTree('/internal/shared/preload');
6644
6658
  // Platform-level bin directory for a fallback `php` binary. Without it,
6645
6659
  // PHP may not populate the PHP_BINARY constant.
6646
- FS.mkdir('/internal/shared/bin');
6660
+ FS.mkdirTree('/internal/shared/bin');
6647
6661
  const originalOnRuntimeInitialized = Module['onRuntimeInitialized'];
6648
6662
  Module['onRuntimeInitialized'] = () => {
6649
- // Dummy PHP binary for PHP to populate the PHP_BINARY constant.
6650
- FS.writeFile(
6663
+ const { node: phpBinaryNode } = FS.lookupPath(
6651
6664
  '/internal/shared/bin/php',
6652
- new TextEncoder().encode('#!/bin/sh\nphp "$@"')
6665
+ { noent_okay: true }
6653
6666
  );
6654
- // It must be executable to be used by PHP.
6655
- FS.chmod('/internal/shared/bin/php', 0o755);
6667
+ if (!phpBinaryNode) {
6668
+ // Dummy PHP binary for PHP to populate the PHP_BINARY constant.
6669
+ FS.writeFile(
6670
+ '/internal/shared/bin/php',
6671
+ new TextEncoder().encode('#!/bin/sh\nphp "$@"')
6672
+ );
6673
+ // It must be executable to be used by PHP.
6674
+ FS.chmod('/internal/shared/bin/php', 0o755);
6675
+ }
6656
6676
  originalOnRuntimeInitialized();
6657
6677
  };
6658
6678
 
@@ -6670,7 +6690,7 @@ export function init(RuntimeName, PHPLoader) {
6670
6690
  return length;
6671
6691
  },
6672
6692
  });
6673
- FS.mkdev('/internal/stdout', FS.makedev(64, 0));
6693
+ FS.mkdev('/request/stdout', FS.makedev(64, 0));
6674
6694
 
6675
6695
  FS.registerDevice(FS.makedev(63, 0), {
6676
6696
  open: () => {},
@@ -6682,7 +6702,7 @@ export function init(RuntimeName, PHPLoader) {
6682
6702
  return length;
6683
6703
  },
6684
6704
  });
6685
- FS.mkdev('/internal/stderr', FS.makedev(63, 0));
6705
+ FS.mkdev('/request/stderr', FS.makedev(63, 0));
6686
6706
 
6687
6707
  FS.registerDevice(FS.makedev(62, 0), {
6688
6708
  open: () => {},
@@ -6694,7 +6714,7 @@ export function init(RuntimeName, PHPLoader) {
6694
6714
  return length;
6695
6715
  },
6696
6716
  });
6697
- FS.mkdev('/internal/headers', FS.makedev(62, 0));
6717
+ FS.mkdev('/request/headers', FS.makedev(62, 0));
6698
6718
 
6699
6719
  // Handle events.
6700
6720
  PHPWASM.EventEmitter = ENVIRONMENT_IS_NODE
@@ -6926,34 +6946,37 @@ export function init(RuntimeName, PHPLoader) {
6926
6946
  }
6927
6947
 
6928
6948
  function _fd_close(fd) {
6949
+ // We have to get the VFS path from the file descriptor
6950
+ // before closing it.
6951
+ const [vfsPath, vfsPathResolutionErrno] =
6952
+ locking.get_vfs_path_from_fd(fd);
6953
+
6929
6954
  const fdCloseResult = _builtin_fd_close(fd);
6930
6955
  if (fdCloseResult !== 0 || !locking.maybeLockedFds.has(fd)) {
6931
6956
  _js_wasm_trace('fd_close(%d) result %d', fd, fdCloseResult);
6932
6957
  return fdCloseResult;
6933
6958
  }
6934
6959
 
6935
- try {
6936
- const [vfsPath, pathResolutionErrno] =
6937
- locking.get_vfs_path_from_fd(fd);
6938
- if (pathResolutionErrno !== 0) {
6939
- _js_wasm_trace(
6940
- 'fd_close(%d) get_vfs_path_from_fd error %d',
6941
- fd,
6942
- pathResolutionErrno
6943
- );
6944
- /*
6945
- * It looks like the file may have had an associated lock,
6946
- * but since we cannot look up the path,
6947
- * there is nothing more for us to do.
6948
- *
6949
- * NOTE: This seems possible for files that are locked and
6950
- * then unlinked before close. It is an opportunity for a
6951
- * lock to be orphaned in the lock manager.
6952
- * @TODO: Explore how to ensure cleanup in this case.
6953
- */
6954
- return fdCloseResult;
6955
- }
6960
+ if (vfsPathResolutionErrno !== 0) {
6961
+ _js_wasm_trace(
6962
+ 'fd_close(%d) get_vfs_path_from_fd error %d',
6963
+ fd,
6964
+ vfsPathResolutionErrno
6965
+ );
6966
+ /*
6967
+ * It looks like the file may have had an associated lock,
6968
+ * but since we cannot look up the path,
6969
+ * there is nothing more for us to do.
6970
+ *
6971
+ * NOTE: This seems possible for files that are locked and
6972
+ * then unlinked before close. It is an opportunity for a
6973
+ * lock to be orphaned in the lock manager.
6974
+ * @TODO: Explore how to ensure cleanup in this case.
6975
+ */
6976
+ return fdCloseResult;
6977
+ }
6956
6978
 
6979
+ try {
6957
6980
  const nativeFilePath =
6958
6981
  locking.get_native_path_from_vfs_path(vfsPath);
6959
6982
  PHPLoader.fileLockManager.releaseLocksForProcessFd(
@@ -32049,7 +32072,7 @@ export function init(RuntimeName, PHPLoader) {
32049
32072
  if (ENVIRONMENT_IS_NODE) {
32050
32073
  NODEFS.staticInit();
32051
32074
  }
32052
- PHPWASM.init();
32075
+ PHPWASM.init(PHPLoader?.phpWasmInitOptions);
32053
32076
 
32054
32077
  Module['requestAnimationFrame'] = MainLoop.requestAnimationFrame;
32055
32078
  Module['pauseMainLoop'] = MainLoop.pause;