@php-wasm/node 3.0.44 → 3.0.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 +180 -24
- package/index.js +173 -17
- package/lib/extensions/memcached/get-memcached-extension-module.d.ts +11 -0
- package/lib/extensions/memcached/with-memcached.d.ts +2 -0
- package/lib/extensions/redis/get-redis-extension-module.d.ts +11 -0
- package/lib/extensions/redis/with-redis.d.ts +2 -0
- package/lib/load-runtime.d.ts +2 -0
- package/package.json +14 -14
package/index.cjs
CHANGED
|
@@ -97,7 +97,6 @@ async function getPHPLoaderModule(version = import_universal.LatestSupportedPHPV
|
|
|
97
97
|
var dns = __toESM(require("dns"), 1);
|
|
98
98
|
var http = __toESM(require("http"), 1);
|
|
99
99
|
var net2 = __toESM(require("net"), 1);
|
|
100
|
-
var util = __toESM(require("node:util"), 1);
|
|
101
100
|
var import_ws = require("ws");
|
|
102
101
|
|
|
103
102
|
// packages/php-wasm/node/src/lib/networking/utils.ts
|
|
@@ -135,7 +134,17 @@ function listenOnRandomPort() {
|
|
|
135
134
|
function log(...args) {
|
|
136
135
|
debugLog("[WS Server]", ...args);
|
|
137
136
|
}
|
|
138
|
-
|
|
137
|
+
function lookupIPv4(hostname) {
|
|
138
|
+
return new Promise((resolve, reject) => {
|
|
139
|
+
dns.lookup(hostname, { family: 4 }, (err, address) => {
|
|
140
|
+
if (err) {
|
|
141
|
+
reject(err);
|
|
142
|
+
} else {
|
|
143
|
+
resolve(address);
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
}
|
|
139
148
|
function prependByte(chunk, byte) {
|
|
140
149
|
if (typeof chunk === "string") {
|
|
141
150
|
chunk = String.fromCharCode(byte) + chunk;
|
|
@@ -263,8 +272,7 @@ async function onWsConnect(client, request) {
|
|
|
263
272
|
if (net2.isIP(reqTargetHost) === 0) {
|
|
264
273
|
clientLog("resolving " + reqTargetHost + "... ");
|
|
265
274
|
try {
|
|
266
|
-
|
|
267
|
-
reqTargetIp = resolution.address;
|
|
275
|
+
reqTargetIp = await lookupIPv4(reqTargetHost);
|
|
268
276
|
clientLog("resolved " + reqTargetHost + " -> " + reqTargetIp);
|
|
269
277
|
} catch (e) {
|
|
270
278
|
clientLog("can't resolve " + reqTargetHost + " due to:", e);
|
|
@@ -415,8 +423,8 @@ async function withNetworking(phpModuleArgs = {}) {
|
|
|
415
423
|
}
|
|
416
424
|
|
|
417
425
|
// packages/php-wasm/node/src/lib/load-runtime.ts
|
|
418
|
-
var
|
|
419
|
-
var
|
|
426
|
+
var import_universal10 = require("@php-wasm/universal");
|
|
427
|
+
var import_fs5 = __toESM(require("fs"), 1);
|
|
420
428
|
|
|
421
429
|
// packages/php-wasm/node/src/lib/extensions/xdebug/with-xdebug.ts
|
|
422
430
|
var import_universal3 = require("@php-wasm/universal");
|
|
@@ -588,6 +596,148 @@ async function withIntl(version = import_universal5.LatestSupportedPHPVersion, o
|
|
|
588
596
|
};
|
|
589
597
|
}
|
|
590
598
|
|
|
599
|
+
// packages/php-wasm/node/src/lib/extensions/redis/with-redis.ts
|
|
600
|
+
var import_universal7 = require("@php-wasm/universal");
|
|
601
|
+
var import_fs3 = __toESM(require("fs"), 1);
|
|
602
|
+
|
|
603
|
+
// packages/php-wasm/node/src/lib/extensions/redis/get-redis-extension-module.ts
|
|
604
|
+
var import_universal6 = require("@php-wasm/universal");
|
|
605
|
+
async function getRedisExtensionModule(version = import_universal6.LatestSupportedPHPVersion) {
|
|
606
|
+
switch (version) {
|
|
607
|
+
case "8.5":
|
|
608
|
+
return (await import("@php-wasm/node-8-5")).getRedisExtensionPath();
|
|
609
|
+
case "8.4":
|
|
610
|
+
return (await import("@php-wasm/node-8-4")).getRedisExtensionPath();
|
|
611
|
+
case "8.3":
|
|
612
|
+
return (await import("@php-wasm/node-8-3")).getRedisExtensionPath();
|
|
613
|
+
case "8.2":
|
|
614
|
+
return (await import("@php-wasm/node-8-2")).getRedisExtensionPath();
|
|
615
|
+
case "8.1":
|
|
616
|
+
return (await import("@php-wasm/node-8-1")).getRedisExtensionPath();
|
|
617
|
+
case "8.0":
|
|
618
|
+
return (await import("@php-wasm/node-8-0")).getRedisExtensionPath();
|
|
619
|
+
case "7.4":
|
|
620
|
+
return (await import("@php-wasm/node-7-4")).getRedisExtensionPath();
|
|
621
|
+
}
|
|
622
|
+
throw new Error(`Unsupported PHP version ${version}`);
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
// packages/php-wasm/node/src/lib/extensions/redis/with-redis.ts
|
|
626
|
+
async function withRedis(version = import_universal7.LatestSupportedPHPVersion, options) {
|
|
627
|
+
const extensionName = "redis.so";
|
|
628
|
+
const extensionPath = await getRedisExtensionModule(version);
|
|
629
|
+
const extension = import_fs3.default.readFileSync(extensionPath);
|
|
630
|
+
return {
|
|
631
|
+
...options,
|
|
632
|
+
ENV: {
|
|
633
|
+
...options.ENV,
|
|
634
|
+
PHP_INI_SCAN_DIR: "/internal/shared/extensions"
|
|
635
|
+
},
|
|
636
|
+
onRuntimeInitialized: (phpRuntime) => {
|
|
637
|
+
if (options.onRuntimeInitialized) {
|
|
638
|
+
options.onRuntimeInitialized(phpRuntime);
|
|
639
|
+
}
|
|
640
|
+
if (!import_universal7.FSHelpers.fileExists(
|
|
641
|
+
phpRuntime.FS,
|
|
642
|
+
"/internal/shared/extensions"
|
|
643
|
+
)) {
|
|
644
|
+
phpRuntime.FS.mkdirTree("/internal/shared/extensions");
|
|
645
|
+
}
|
|
646
|
+
if (!import_universal7.FSHelpers.fileExists(
|
|
647
|
+
phpRuntime.FS,
|
|
648
|
+
`/internal/shared/extensions/${extensionName}`
|
|
649
|
+
)) {
|
|
650
|
+
phpRuntime.FS.writeFile(
|
|
651
|
+
`/internal/shared/extensions/${extensionName}`,
|
|
652
|
+
new Uint8Array(extension)
|
|
653
|
+
);
|
|
654
|
+
}
|
|
655
|
+
if (!import_universal7.FSHelpers.fileExists(
|
|
656
|
+
phpRuntime.FS,
|
|
657
|
+
"/internal/shared/extensions/redis.ini"
|
|
658
|
+
)) {
|
|
659
|
+
phpRuntime.FS.writeFile(
|
|
660
|
+
"/internal/shared/extensions/redis.ini",
|
|
661
|
+
[
|
|
662
|
+
`extension=/internal/shared/extensions/${extensionName}`
|
|
663
|
+
].join("\n")
|
|
664
|
+
);
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
};
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
// packages/php-wasm/node/src/lib/extensions/memcached/with-memcached.ts
|
|
671
|
+
var import_universal9 = require("@php-wasm/universal");
|
|
672
|
+
var import_fs4 = __toESM(require("fs"), 1);
|
|
673
|
+
|
|
674
|
+
// packages/php-wasm/node/src/lib/extensions/memcached/get-memcached-extension-module.ts
|
|
675
|
+
var import_universal8 = require("@php-wasm/universal");
|
|
676
|
+
async function getMemcachedExtensionModule(version = import_universal8.LatestSupportedPHPVersion) {
|
|
677
|
+
switch (version) {
|
|
678
|
+
case "8.5":
|
|
679
|
+
return (await import("@php-wasm/node-8-5")).getMemcachedExtensionPath();
|
|
680
|
+
case "8.4":
|
|
681
|
+
return (await import("@php-wasm/node-8-4")).getMemcachedExtensionPath();
|
|
682
|
+
case "8.3":
|
|
683
|
+
return (await import("@php-wasm/node-8-3")).getMemcachedExtensionPath();
|
|
684
|
+
case "8.2":
|
|
685
|
+
return (await import("@php-wasm/node-8-2")).getMemcachedExtensionPath();
|
|
686
|
+
case "8.1":
|
|
687
|
+
return (await import("@php-wasm/node-8-1")).getMemcachedExtensionPath();
|
|
688
|
+
case "8.0":
|
|
689
|
+
return (await import("@php-wasm/node-8-0")).getMemcachedExtensionPath();
|
|
690
|
+
case "7.4":
|
|
691
|
+
return (await import("@php-wasm/node-7-4")).getMemcachedExtensionPath();
|
|
692
|
+
}
|
|
693
|
+
throw new Error(`Unsupported PHP version ${version}`);
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
// packages/php-wasm/node/src/lib/extensions/memcached/with-memcached.ts
|
|
697
|
+
async function withMemcached(version = import_universal9.LatestSupportedPHPVersion, options) {
|
|
698
|
+
const extensionName = "memcached.so";
|
|
699
|
+
const extensionPath = await getMemcachedExtensionModule(version);
|
|
700
|
+
const extension = import_fs4.default.readFileSync(extensionPath);
|
|
701
|
+
return {
|
|
702
|
+
...options,
|
|
703
|
+
ENV: {
|
|
704
|
+
...options.ENV,
|
|
705
|
+
PHP_INI_SCAN_DIR: "/internal/shared/extensions"
|
|
706
|
+
},
|
|
707
|
+
onRuntimeInitialized: (phpRuntime) => {
|
|
708
|
+
if (options.onRuntimeInitialized) {
|
|
709
|
+
options.onRuntimeInitialized(phpRuntime);
|
|
710
|
+
}
|
|
711
|
+
if (!import_universal9.FSHelpers.fileExists(
|
|
712
|
+
phpRuntime.FS,
|
|
713
|
+
"/internal/shared/extensions"
|
|
714
|
+
)) {
|
|
715
|
+
phpRuntime.FS.mkdirTree("/internal/shared/extensions");
|
|
716
|
+
}
|
|
717
|
+
if (!import_universal9.FSHelpers.fileExists(
|
|
718
|
+
phpRuntime.FS,
|
|
719
|
+
`/internal/shared/extensions/${extensionName}`
|
|
720
|
+
)) {
|
|
721
|
+
phpRuntime.FS.writeFile(
|
|
722
|
+
`/internal/shared/extensions/${extensionName}`,
|
|
723
|
+
new Uint8Array(extension)
|
|
724
|
+
);
|
|
725
|
+
}
|
|
726
|
+
if (!import_universal9.FSHelpers.fileExists(
|
|
727
|
+
phpRuntime.FS,
|
|
728
|
+
"/internal/shared/extensions/memcached.ini"
|
|
729
|
+
)) {
|
|
730
|
+
phpRuntime.FS.writeFile(
|
|
731
|
+
"/internal/shared/extensions/memcached.ini",
|
|
732
|
+
[
|
|
733
|
+
`extension=/internal/shared/extensions/${extensionName}`
|
|
734
|
+
].join("\n")
|
|
735
|
+
);
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
};
|
|
739
|
+
}
|
|
740
|
+
|
|
591
741
|
// packages/php-wasm/node/src/lib/load-runtime.ts
|
|
592
742
|
var import_util = require("@php-wasm/util");
|
|
593
743
|
var import_path2 = require("path");
|
|
@@ -606,7 +756,7 @@ async function loadNodeRuntime(phpVersion, options = {}) {
|
|
|
606
756
|
if (options?.followSymlinks === true) {
|
|
607
757
|
phpRuntime.FS.filesystems.NODEFS.node_ops.readlink = (node) => {
|
|
608
758
|
const absoluteSourcePath = phpRuntime.FS.filesystems.NODEFS.tryFSOperation(
|
|
609
|
-
() =>
|
|
759
|
+
() => import_fs5.default.realpathSync(
|
|
610
760
|
phpRuntime.FS.filesystems.NODEFS.realPath(node)
|
|
611
761
|
)
|
|
612
762
|
);
|
|
@@ -614,12 +764,12 @@ async function loadNodeRuntime(phpVersion, options = {}) {
|
|
|
614
764
|
`/internal/symlinks`,
|
|
615
765
|
absoluteSourcePath
|
|
616
766
|
);
|
|
617
|
-
if (
|
|
618
|
-
if (!
|
|
767
|
+
if (import_fs5.default.existsSync(absoluteSourcePath)) {
|
|
768
|
+
if (!import_universal10.FSHelpers.fileExists(
|
|
619
769
|
phpRuntime.FS,
|
|
620
770
|
symlinkMountPath
|
|
621
771
|
)) {
|
|
622
|
-
const sourceStat =
|
|
772
|
+
const sourceStat = import_fs5.default.statSync(absoluteSourcePath);
|
|
623
773
|
if (sourceStat.isDirectory()) {
|
|
624
774
|
phpRuntime.FS.mkdirTree(symlinkMountPath);
|
|
625
775
|
} else if (sourceStat.isFile()) {
|
|
@@ -663,8 +813,14 @@ async function loadNodeRuntime(phpVersion, options = {}) {
|
|
|
663
813
|
if (options?.withIntl === true) {
|
|
664
814
|
emscriptenOptions = await withIntl(phpVersion, emscriptenOptions);
|
|
665
815
|
}
|
|
816
|
+
if (options?.withRedis === true) {
|
|
817
|
+
emscriptenOptions = await withRedis(phpVersion, emscriptenOptions);
|
|
818
|
+
}
|
|
819
|
+
if (options?.withMemcached === true) {
|
|
820
|
+
emscriptenOptions = await withMemcached(phpVersion, emscriptenOptions);
|
|
821
|
+
}
|
|
666
822
|
emscriptenOptions = await withNetworking(emscriptenOptions);
|
|
667
|
-
return await (0,
|
|
823
|
+
return await (0, import_universal10.loadPHPRuntime)(
|
|
668
824
|
await getPHPLoaderModule(phpVersion),
|
|
669
825
|
emscriptenOptions
|
|
670
826
|
);
|
|
@@ -674,15 +830,15 @@ async function loadNodeRuntime(phpVersion, options = {}) {
|
|
|
674
830
|
var import_node_fs = require("node:fs");
|
|
675
831
|
|
|
676
832
|
// packages/php-wasm/node/src/lib/node-fs-mount.ts
|
|
677
|
-
var
|
|
833
|
+
var import_universal11 = require("@php-wasm/universal");
|
|
678
834
|
var import_util2 = require("@php-wasm/util");
|
|
679
|
-
var
|
|
835
|
+
var import_fs6 = require("fs");
|
|
680
836
|
var import_path3 = require("path");
|
|
681
837
|
function createNodeFsMountHandler(localPath) {
|
|
682
838
|
return function(php, FS, vfsMountPoint) {
|
|
683
839
|
let removeVfsNode = false;
|
|
684
|
-
if (!
|
|
685
|
-
const lstat = (0,
|
|
840
|
+
if (!import_universal11.FSHelpers.fileExists(FS, vfsMountPoint)) {
|
|
841
|
+
const lstat = (0, import_fs6.lstatSync)(localPath);
|
|
686
842
|
if (lstat.isFile() || lstat.isSymbolicLink()) {
|
|
687
843
|
FS.mkdirTree((0, import_path3.dirname)(vfsMountPoint));
|
|
688
844
|
FS.writeFile(vfsMountPoint, "");
|
|
@@ -695,9 +851,9 @@ function createNodeFsMountHandler(localPath) {
|
|
|
695
851
|
}
|
|
696
852
|
removeVfsNode = true;
|
|
697
853
|
}
|
|
698
|
-
let
|
|
854
|
+
let lookup2;
|
|
699
855
|
try {
|
|
700
|
-
|
|
856
|
+
lookup2 = FS.lookupPath(vfsMountPoint);
|
|
701
857
|
} catch (e) {
|
|
702
858
|
const error = e;
|
|
703
859
|
if (error.errno === 44) {
|
|
@@ -711,7 +867,7 @@ function createNodeFsMountHandler(localPath) {
|
|
|
711
867
|
return () => {
|
|
712
868
|
FS.unmount(vfsMountPoint);
|
|
713
869
|
if (removeVfsNode) {
|
|
714
|
-
if (FS.isDir(
|
|
870
|
+
if (FS.isDir(lookup2.node.mode)) {
|
|
715
871
|
if ((0, import_util2.isParentOf)(vfsMountPoint, FS.cwd())) {
|
|
716
872
|
throw new Error(
|
|
717
873
|
`Cannot remove the VFS directory "${vfsMountPoint}" on umount cleanup \u2013 it is a parent of the CWD "${FS.cwd()}". Change CWD before unmounting or explicitly disable post-unmount node cleanup with createNodeFsMountHandler(path, {cleanupNodesOnUnmount: false}).`
|
|
@@ -746,7 +902,7 @@ function useHostFilesystem(php) {
|
|
|
746
902
|
function statPathFollowSymlinks(path2) {
|
|
747
903
|
let stat = (0, import_node_fs.lstatSync)(path2);
|
|
748
904
|
if (stat.isSymbolicLink()) {
|
|
749
|
-
const
|
|
905
|
+
const fs6 = require("fs");
|
|
750
906
|
let target = path2;
|
|
751
907
|
const seen = /* @__PURE__ */ new Set();
|
|
752
908
|
while (true) {
|
|
@@ -756,7 +912,7 @@ function statPathFollowSymlinks(path2) {
|
|
|
756
912
|
seen.add(target);
|
|
757
913
|
const linkStat = (0, import_node_fs.lstatSync)(target);
|
|
758
914
|
if (linkStat.isSymbolicLink()) {
|
|
759
|
-
target =
|
|
915
|
+
target = fs6.realpathSync(target);
|
|
760
916
|
continue;
|
|
761
917
|
}
|
|
762
918
|
stat = linkStat;
|
|
@@ -768,7 +924,7 @@ function statPathFollowSymlinks(path2) {
|
|
|
768
924
|
|
|
769
925
|
// packages/php-wasm/node/src/lib/file-lock-manager-for-node.ts
|
|
770
926
|
var import_logger2 = require("@php-wasm/logger");
|
|
771
|
-
var
|
|
927
|
+
var import_fs7 = require("fs");
|
|
772
928
|
var MAX_64BIT_OFFSET = BigInt(2n ** 64n - 1n);
|
|
773
929
|
var FileLockManagerForNode = class {
|
|
774
930
|
/**
|
|
@@ -903,7 +1059,7 @@ var FileLock = class _FileLock {
|
|
|
903
1059
|
static maybeCreate(path2, mode, nativeFlockSync) {
|
|
904
1060
|
let fd;
|
|
905
1061
|
try {
|
|
906
|
-
fd = (0,
|
|
1062
|
+
fd = (0, import_fs7.openSync)(path2, "a+");
|
|
907
1063
|
const flockFlags = mode === "exclusive" ? "exnb" : "shnb";
|
|
908
1064
|
nativeFlockSync(fd, flockFlags);
|
|
909
1065
|
const nativeLock = { fd, mode, nativeFlockSync };
|
|
@@ -911,7 +1067,7 @@ var FileLock = class _FileLock {
|
|
|
911
1067
|
} catch {
|
|
912
1068
|
if (fd !== void 0) {
|
|
913
1069
|
try {
|
|
914
|
-
(0,
|
|
1070
|
+
(0, import_fs7.closeSync)(fd);
|
|
915
1071
|
} catch (error) {
|
|
916
1072
|
import_logger2.logger.error(
|
|
917
1073
|
"Error closing locking file descriptor",
|
|
@@ -934,7 +1090,7 @@ var FileLock = class _FileLock {
|
|
|
934
1090
|
*/
|
|
935
1091
|
dispose() {
|
|
936
1092
|
try {
|
|
937
|
-
(0,
|
|
1093
|
+
(0, import_fs7.closeSync)(this.nativeLock.fd);
|
|
938
1094
|
} catch (error) {
|
|
939
1095
|
import_logger2.logger.error("Error closing locking file descriptor", error);
|
|
940
1096
|
}
|
package/index.js
CHANGED
|
@@ -64,7 +64,6 @@ async function getPHPLoaderModule(version = LatestSupportedPHPVersion) {
|
|
|
64
64
|
import * as dns from "dns";
|
|
65
65
|
import * as http from "http";
|
|
66
66
|
import * as net2 from "net";
|
|
67
|
-
import * as util from "node:util";
|
|
68
67
|
import { WebSocketServer } from "ws";
|
|
69
68
|
|
|
70
69
|
// packages/php-wasm/node/src/lib/networking/utils.ts
|
|
@@ -102,7 +101,17 @@ function listenOnRandomPort() {
|
|
|
102
101
|
function log(...args) {
|
|
103
102
|
debugLog("[WS Server]", ...args);
|
|
104
103
|
}
|
|
105
|
-
|
|
104
|
+
function lookupIPv4(hostname) {
|
|
105
|
+
return new Promise((resolve, reject) => {
|
|
106
|
+
dns.lookup(hostname, { family: 4 }, (err, address) => {
|
|
107
|
+
if (err) {
|
|
108
|
+
reject(err);
|
|
109
|
+
} else {
|
|
110
|
+
resolve(address);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
}
|
|
106
115
|
function prependByte(chunk, byte) {
|
|
107
116
|
if (typeof chunk === "string") {
|
|
108
117
|
chunk = String.fromCharCode(byte) + chunk;
|
|
@@ -230,8 +239,7 @@ async function onWsConnect(client, request) {
|
|
|
230
239
|
if (net2.isIP(reqTargetHost) === 0) {
|
|
231
240
|
clientLog("resolving " + reqTargetHost + "... ");
|
|
232
241
|
try {
|
|
233
|
-
|
|
234
|
-
reqTargetIp = resolution.address;
|
|
242
|
+
reqTargetIp = await lookupIPv4(reqTargetHost);
|
|
235
243
|
clientLog("resolved " + reqTargetHost + " -> " + reqTargetIp);
|
|
236
244
|
} catch (e) {
|
|
237
245
|
clientLog("can't resolve " + reqTargetHost + " due to:", e);
|
|
@@ -382,8 +390,8 @@ async function withNetworking(phpModuleArgs = {}) {
|
|
|
382
390
|
}
|
|
383
391
|
|
|
384
392
|
// packages/php-wasm/node/src/lib/load-runtime.ts
|
|
385
|
-
import { loadPHPRuntime, FSHelpers as
|
|
386
|
-
import
|
|
393
|
+
import { loadPHPRuntime, FSHelpers as FSHelpers5 } from "@php-wasm/universal";
|
|
394
|
+
import fs5 from "fs";
|
|
387
395
|
|
|
388
396
|
// packages/php-wasm/node/src/lib/extensions/xdebug/with-xdebug.ts
|
|
389
397
|
import { LatestSupportedPHPVersion as LatestSupportedPHPVersion3, FSHelpers } from "@php-wasm/universal";
|
|
@@ -554,6 +562,148 @@ async function withIntl(version = LatestSupportedPHPVersion5, options) {
|
|
|
554
562
|
};
|
|
555
563
|
}
|
|
556
564
|
|
|
565
|
+
// packages/php-wasm/node/src/lib/extensions/redis/with-redis.ts
|
|
566
|
+
import { LatestSupportedPHPVersion as LatestSupportedPHPVersion7, FSHelpers as FSHelpers3 } from "@php-wasm/universal";
|
|
567
|
+
import fs3 from "fs";
|
|
568
|
+
|
|
569
|
+
// packages/php-wasm/node/src/lib/extensions/redis/get-redis-extension-module.ts
|
|
570
|
+
import { LatestSupportedPHPVersion as LatestSupportedPHPVersion6 } from "@php-wasm/universal";
|
|
571
|
+
async function getRedisExtensionModule(version = LatestSupportedPHPVersion6) {
|
|
572
|
+
switch (version) {
|
|
573
|
+
case "8.5":
|
|
574
|
+
return (await import("@php-wasm/node-8-5")).getRedisExtensionPath();
|
|
575
|
+
case "8.4":
|
|
576
|
+
return (await import("@php-wasm/node-8-4")).getRedisExtensionPath();
|
|
577
|
+
case "8.3":
|
|
578
|
+
return (await import("@php-wasm/node-8-3")).getRedisExtensionPath();
|
|
579
|
+
case "8.2":
|
|
580
|
+
return (await import("@php-wasm/node-8-2")).getRedisExtensionPath();
|
|
581
|
+
case "8.1":
|
|
582
|
+
return (await import("@php-wasm/node-8-1")).getRedisExtensionPath();
|
|
583
|
+
case "8.0":
|
|
584
|
+
return (await import("@php-wasm/node-8-0")).getRedisExtensionPath();
|
|
585
|
+
case "7.4":
|
|
586
|
+
return (await import("@php-wasm/node-7-4")).getRedisExtensionPath();
|
|
587
|
+
}
|
|
588
|
+
throw new Error(`Unsupported PHP version ${version}`);
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
// packages/php-wasm/node/src/lib/extensions/redis/with-redis.ts
|
|
592
|
+
async function withRedis(version = LatestSupportedPHPVersion7, options) {
|
|
593
|
+
const extensionName = "redis.so";
|
|
594
|
+
const extensionPath = await getRedisExtensionModule(version);
|
|
595
|
+
const extension = fs3.readFileSync(extensionPath);
|
|
596
|
+
return {
|
|
597
|
+
...options,
|
|
598
|
+
ENV: {
|
|
599
|
+
...options.ENV,
|
|
600
|
+
PHP_INI_SCAN_DIR: "/internal/shared/extensions"
|
|
601
|
+
},
|
|
602
|
+
onRuntimeInitialized: (phpRuntime) => {
|
|
603
|
+
if (options.onRuntimeInitialized) {
|
|
604
|
+
options.onRuntimeInitialized(phpRuntime);
|
|
605
|
+
}
|
|
606
|
+
if (!FSHelpers3.fileExists(
|
|
607
|
+
phpRuntime.FS,
|
|
608
|
+
"/internal/shared/extensions"
|
|
609
|
+
)) {
|
|
610
|
+
phpRuntime.FS.mkdirTree("/internal/shared/extensions");
|
|
611
|
+
}
|
|
612
|
+
if (!FSHelpers3.fileExists(
|
|
613
|
+
phpRuntime.FS,
|
|
614
|
+
`/internal/shared/extensions/${extensionName}`
|
|
615
|
+
)) {
|
|
616
|
+
phpRuntime.FS.writeFile(
|
|
617
|
+
`/internal/shared/extensions/${extensionName}`,
|
|
618
|
+
new Uint8Array(extension)
|
|
619
|
+
);
|
|
620
|
+
}
|
|
621
|
+
if (!FSHelpers3.fileExists(
|
|
622
|
+
phpRuntime.FS,
|
|
623
|
+
"/internal/shared/extensions/redis.ini"
|
|
624
|
+
)) {
|
|
625
|
+
phpRuntime.FS.writeFile(
|
|
626
|
+
"/internal/shared/extensions/redis.ini",
|
|
627
|
+
[
|
|
628
|
+
`extension=/internal/shared/extensions/${extensionName}`
|
|
629
|
+
].join("\n")
|
|
630
|
+
);
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
};
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
// packages/php-wasm/node/src/lib/extensions/memcached/with-memcached.ts
|
|
637
|
+
import { LatestSupportedPHPVersion as LatestSupportedPHPVersion9, FSHelpers as FSHelpers4 } from "@php-wasm/universal";
|
|
638
|
+
import fs4 from "fs";
|
|
639
|
+
|
|
640
|
+
// packages/php-wasm/node/src/lib/extensions/memcached/get-memcached-extension-module.ts
|
|
641
|
+
import { LatestSupportedPHPVersion as LatestSupportedPHPVersion8 } from "@php-wasm/universal";
|
|
642
|
+
async function getMemcachedExtensionModule(version = LatestSupportedPHPVersion8) {
|
|
643
|
+
switch (version) {
|
|
644
|
+
case "8.5":
|
|
645
|
+
return (await import("@php-wasm/node-8-5")).getMemcachedExtensionPath();
|
|
646
|
+
case "8.4":
|
|
647
|
+
return (await import("@php-wasm/node-8-4")).getMemcachedExtensionPath();
|
|
648
|
+
case "8.3":
|
|
649
|
+
return (await import("@php-wasm/node-8-3")).getMemcachedExtensionPath();
|
|
650
|
+
case "8.2":
|
|
651
|
+
return (await import("@php-wasm/node-8-2")).getMemcachedExtensionPath();
|
|
652
|
+
case "8.1":
|
|
653
|
+
return (await import("@php-wasm/node-8-1")).getMemcachedExtensionPath();
|
|
654
|
+
case "8.0":
|
|
655
|
+
return (await import("@php-wasm/node-8-0")).getMemcachedExtensionPath();
|
|
656
|
+
case "7.4":
|
|
657
|
+
return (await import("@php-wasm/node-7-4")).getMemcachedExtensionPath();
|
|
658
|
+
}
|
|
659
|
+
throw new Error(`Unsupported PHP version ${version}`);
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
// packages/php-wasm/node/src/lib/extensions/memcached/with-memcached.ts
|
|
663
|
+
async function withMemcached(version = LatestSupportedPHPVersion9, options) {
|
|
664
|
+
const extensionName = "memcached.so";
|
|
665
|
+
const extensionPath = await getMemcachedExtensionModule(version);
|
|
666
|
+
const extension = fs4.readFileSync(extensionPath);
|
|
667
|
+
return {
|
|
668
|
+
...options,
|
|
669
|
+
ENV: {
|
|
670
|
+
...options.ENV,
|
|
671
|
+
PHP_INI_SCAN_DIR: "/internal/shared/extensions"
|
|
672
|
+
},
|
|
673
|
+
onRuntimeInitialized: (phpRuntime) => {
|
|
674
|
+
if (options.onRuntimeInitialized) {
|
|
675
|
+
options.onRuntimeInitialized(phpRuntime);
|
|
676
|
+
}
|
|
677
|
+
if (!FSHelpers4.fileExists(
|
|
678
|
+
phpRuntime.FS,
|
|
679
|
+
"/internal/shared/extensions"
|
|
680
|
+
)) {
|
|
681
|
+
phpRuntime.FS.mkdirTree("/internal/shared/extensions");
|
|
682
|
+
}
|
|
683
|
+
if (!FSHelpers4.fileExists(
|
|
684
|
+
phpRuntime.FS,
|
|
685
|
+
`/internal/shared/extensions/${extensionName}`
|
|
686
|
+
)) {
|
|
687
|
+
phpRuntime.FS.writeFile(
|
|
688
|
+
`/internal/shared/extensions/${extensionName}`,
|
|
689
|
+
new Uint8Array(extension)
|
|
690
|
+
);
|
|
691
|
+
}
|
|
692
|
+
if (!FSHelpers4.fileExists(
|
|
693
|
+
phpRuntime.FS,
|
|
694
|
+
"/internal/shared/extensions/memcached.ini"
|
|
695
|
+
)) {
|
|
696
|
+
phpRuntime.FS.writeFile(
|
|
697
|
+
"/internal/shared/extensions/memcached.ini",
|
|
698
|
+
[
|
|
699
|
+
`extension=/internal/shared/extensions/${extensionName}`
|
|
700
|
+
].join("\n")
|
|
701
|
+
);
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
};
|
|
705
|
+
}
|
|
706
|
+
|
|
557
707
|
// packages/php-wasm/node/src/lib/load-runtime.ts
|
|
558
708
|
import { joinPaths } from "@php-wasm/util";
|
|
559
709
|
import { dirname } from "path";
|
|
@@ -572,7 +722,7 @@ async function loadNodeRuntime(phpVersion, options = {}) {
|
|
|
572
722
|
if (options?.followSymlinks === true) {
|
|
573
723
|
phpRuntime.FS.filesystems.NODEFS.node_ops.readlink = (node) => {
|
|
574
724
|
const absoluteSourcePath = phpRuntime.FS.filesystems.NODEFS.tryFSOperation(
|
|
575
|
-
() =>
|
|
725
|
+
() => fs5.realpathSync(
|
|
576
726
|
phpRuntime.FS.filesystems.NODEFS.realPath(node)
|
|
577
727
|
)
|
|
578
728
|
);
|
|
@@ -580,12 +730,12 @@ async function loadNodeRuntime(phpVersion, options = {}) {
|
|
|
580
730
|
`/internal/symlinks`,
|
|
581
731
|
absoluteSourcePath
|
|
582
732
|
);
|
|
583
|
-
if (
|
|
584
|
-
if (!
|
|
733
|
+
if (fs5.existsSync(absoluteSourcePath)) {
|
|
734
|
+
if (!FSHelpers5.fileExists(
|
|
585
735
|
phpRuntime.FS,
|
|
586
736
|
symlinkMountPath
|
|
587
737
|
)) {
|
|
588
|
-
const sourceStat =
|
|
738
|
+
const sourceStat = fs5.statSync(absoluteSourcePath);
|
|
589
739
|
if (sourceStat.isDirectory()) {
|
|
590
740
|
phpRuntime.FS.mkdirTree(symlinkMountPath);
|
|
591
741
|
} else if (sourceStat.isFile()) {
|
|
@@ -629,6 +779,12 @@ async function loadNodeRuntime(phpVersion, options = {}) {
|
|
|
629
779
|
if (options?.withIntl === true) {
|
|
630
780
|
emscriptenOptions = await withIntl(phpVersion, emscriptenOptions);
|
|
631
781
|
}
|
|
782
|
+
if (options?.withRedis === true) {
|
|
783
|
+
emscriptenOptions = await withRedis(phpVersion, emscriptenOptions);
|
|
784
|
+
}
|
|
785
|
+
if (options?.withMemcached === true) {
|
|
786
|
+
emscriptenOptions = await withMemcached(phpVersion, emscriptenOptions);
|
|
787
|
+
}
|
|
632
788
|
emscriptenOptions = await withNetworking(emscriptenOptions);
|
|
633
789
|
return await loadPHPRuntime(
|
|
634
790
|
await getPHPLoaderModule(phpVersion),
|
|
@@ -641,7 +797,7 @@ import { lstatSync as lstatSync2, readdirSync } from "node:fs";
|
|
|
641
797
|
|
|
642
798
|
// packages/php-wasm/node/src/lib/node-fs-mount.ts
|
|
643
799
|
import {
|
|
644
|
-
FSHelpers as
|
|
800
|
+
FSHelpers as FSHelpers6
|
|
645
801
|
} from "@php-wasm/universal";
|
|
646
802
|
import { isParentOf } from "@php-wasm/util";
|
|
647
803
|
import { lstatSync } from "fs";
|
|
@@ -649,7 +805,7 @@ import { dirname as dirname2 } from "path";
|
|
|
649
805
|
function createNodeFsMountHandler(localPath) {
|
|
650
806
|
return function(php, FS, vfsMountPoint) {
|
|
651
807
|
let removeVfsNode = false;
|
|
652
|
-
if (!
|
|
808
|
+
if (!FSHelpers6.fileExists(FS, vfsMountPoint)) {
|
|
653
809
|
const lstat = lstatSync(localPath);
|
|
654
810
|
if (lstat.isFile() || lstat.isSymbolicLink()) {
|
|
655
811
|
FS.mkdirTree(dirname2(vfsMountPoint));
|
|
@@ -663,9 +819,9 @@ function createNodeFsMountHandler(localPath) {
|
|
|
663
819
|
}
|
|
664
820
|
removeVfsNode = true;
|
|
665
821
|
}
|
|
666
|
-
let
|
|
822
|
+
let lookup2;
|
|
667
823
|
try {
|
|
668
|
-
|
|
824
|
+
lookup2 = FS.lookupPath(vfsMountPoint);
|
|
669
825
|
} catch (e) {
|
|
670
826
|
const error = e;
|
|
671
827
|
if (error.errno === 44) {
|
|
@@ -679,7 +835,7 @@ function createNodeFsMountHandler(localPath) {
|
|
|
679
835
|
return () => {
|
|
680
836
|
FS.unmount(vfsMountPoint);
|
|
681
837
|
if (removeVfsNode) {
|
|
682
|
-
if (FS.isDir(
|
|
838
|
+
if (FS.isDir(lookup2.node.mode)) {
|
|
683
839
|
if (isParentOf(vfsMountPoint, FS.cwd())) {
|
|
684
840
|
throw new Error(
|
|
685
841
|
`Cannot remove the VFS directory "${vfsMountPoint}" on umount cleanup \u2013 it is a parent of the CWD "${FS.cwd()}". Change CWD before unmounting or explicitly disable post-unmount node cleanup with createNodeFsMountHandler(path, {cleanupNodesOnUnmount: false}).`
|
|
@@ -714,7 +870,7 @@ function useHostFilesystem(php) {
|
|
|
714
870
|
function statPathFollowSymlinks(path2) {
|
|
715
871
|
let stat = lstatSync2(path2);
|
|
716
872
|
if (stat.isSymbolicLink()) {
|
|
717
|
-
const
|
|
873
|
+
const fs6 = __require("fs");
|
|
718
874
|
let target = path2;
|
|
719
875
|
const seen = /* @__PURE__ */ new Set();
|
|
720
876
|
while (true) {
|
|
@@ -724,7 +880,7 @@ function statPathFollowSymlinks(path2) {
|
|
|
724
880
|
seen.add(target);
|
|
725
881
|
const linkStat = lstatSync2(target);
|
|
726
882
|
if (linkStat.isSymbolicLink()) {
|
|
727
|
-
target =
|
|
883
|
+
target = fs6.realpathSync(target);
|
|
728
884
|
continue;
|
|
729
885
|
}
|
|
730
886
|
stat = linkStat;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { SupportedPHPVersion } from '@php-wasm/universal';
|
|
2
|
+
/**
|
|
3
|
+
* Returns the path to the memcached extension for the specified PHP version.
|
|
4
|
+
*
|
|
5
|
+
* Each PHP version's memcached extension is packaged separately. Install the
|
|
6
|
+
* version-specific package you need:
|
|
7
|
+
* - @php-wasm/node-8-5
|
|
8
|
+
* - @php-wasm/node-8-4
|
|
9
|
+
* - etc.
|
|
10
|
+
*/
|
|
11
|
+
export declare function getMemcachedExtensionModule(version?: SupportedPHPVersion): Promise<any>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { SupportedPHPVersion } from '@php-wasm/universal';
|
|
2
|
+
/**
|
|
3
|
+
* Returns the path to the redis extension for the specified PHP version.
|
|
4
|
+
*
|
|
5
|
+
* Each PHP version's redis extension is packaged separately. Install the
|
|
6
|
+
* version-specific package you need:
|
|
7
|
+
* - @php-wasm/node-8-5
|
|
8
|
+
* - @php-wasm/node-8-4
|
|
9
|
+
* - etc.
|
|
10
|
+
*/
|
|
11
|
+
export declare function getRedisExtensionModule(version?: SupportedPHPVersion): Promise<any>;
|
package/lib/load-runtime.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ export interface PHPLoaderOptions {
|
|
|
8
8
|
withXdebug?: boolean;
|
|
9
9
|
xdebug?: XdebugOptions;
|
|
10
10
|
withIntl?: boolean;
|
|
11
|
+
withRedis?: boolean;
|
|
12
|
+
withMemcached?: boolean;
|
|
11
13
|
}
|
|
12
14
|
export type PHPLoaderOptionsForNode = PHPLoaderOptions & {
|
|
13
15
|
emscriptenOptions?: EmscriptenOptions & {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@php-wasm/node",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.45",
|
|
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": "
|
|
41
|
+
"gitHead": "90da64a5068b13069ea9faf8ff9f5b1e36fd6099",
|
|
42
42
|
"engines": {
|
|
43
43
|
"node": ">=20.18.3",
|
|
44
44
|
"npm": ">=10.1.0"
|
|
@@ -49,18 +49,18 @@
|
|
|
49
49
|
"wasm-feature-detect": "1.8.0",
|
|
50
50
|
"ws": "8.18.3",
|
|
51
51
|
"yargs": "17.7.2",
|
|
52
|
-
"@php-wasm/node-polyfills": "3.0.
|
|
53
|
-
"@php-wasm/universal": "3.0.
|
|
54
|
-
"@php-wasm/node-8-5": "3.0.
|
|
55
|
-
"@php-wasm/node-8-4": "3.0.
|
|
56
|
-
"@php-wasm/node-8-3": "3.0.
|
|
57
|
-
"@php-wasm/node-8-2": "3.0.
|
|
58
|
-
"@php-wasm/node-8-1": "3.0.
|
|
59
|
-
"@php-wasm/node-8-0": "3.0.
|
|
60
|
-
"@php-wasm/node-7-4": "3.0.
|
|
61
|
-
"@php-wasm/logger": "3.0.
|
|
62
|
-
"@php-wasm/util": "3.0.
|
|
63
|
-
"@wp-playground/common": "3.0.
|
|
52
|
+
"@php-wasm/node-polyfills": "3.0.45",
|
|
53
|
+
"@php-wasm/universal": "3.0.45",
|
|
54
|
+
"@php-wasm/node-8-5": "3.0.45",
|
|
55
|
+
"@php-wasm/node-8-4": "3.0.45",
|
|
56
|
+
"@php-wasm/node-8-3": "3.0.45",
|
|
57
|
+
"@php-wasm/node-8-2": "3.0.45",
|
|
58
|
+
"@php-wasm/node-8-1": "3.0.45",
|
|
59
|
+
"@php-wasm/node-8-0": "3.0.45",
|
|
60
|
+
"@php-wasm/node-7-4": "3.0.45",
|
|
61
|
+
"@php-wasm/logger": "3.0.45",
|
|
62
|
+
"@php-wasm/util": "3.0.45",
|
|
63
|
+
"@wp-playground/common": "3.0.45"
|
|
64
64
|
},
|
|
65
65
|
"packageManager": "npm@10.9.2",
|
|
66
66
|
"overrides": {
|