@php-wasm/cli 0.1.16 → 0.1.18
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/main.js +2 -5
- package/package.json +4 -3
package/main.js
CHANGED
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
import{existsSync as
|
|
2
|
-
|
|
3
|
-
`),s.end()});return new Promise(t=>{r.listen(e,c,function(){new N({server:r}).on("connection",F),t(r)})})}async function F(e,c){const r=e._socket.remoteAddress,t=function(...o){v(" "+r+": ",...o)};t("WebSocket connection from : "+r+" at URL "+(c?c.url:e.upgradeReq.url)),t("Version "+e.protocolVersion+", subprotocol: "+e.protocol);const s=new URL("ws://0.0.0.0"+c.url),l=Number(s.searchParams.get("port")),f=s.searchParams.get("host");if(!l||!f){t("Missing host or port information"),e.close(3e3);return}let i;const u=[];function n(){for(;u.length>0;){const o=u.pop(),d=o[0];t("flushing",{commandType:d},o),d===y?i.write(o.slice(1)):d===T?o[1]===1&&o[2]===9?i.setKeepAlive(o[3]):o[1]===6&&o[2]===1&&i.setNoDelay(o[3]):(t("Unknown command type: "+d),process.exit())}}e.on("message",function(o){u.unshift(o),i&&n()}),e.on("close",function(o,d){t("WebSocket client disconnected: "+o+" ["+d+"]"),i.end()}),e.on("error",function(o){t("WebSocket client error: "+o),i.end()});let a;h.isIP(f)===0?(t("resolving "+f+"... "),a=(await B(f)).address,t("resolved "+f+" -> "+a)):a=f,t("Opening a socket connection to "+a+":"+l),i=h.createConnection(l,a,function(){t("Connected to target"),n()}),i.on("data",function(o){try{e.send(o)}catch{t("Client closed, cleaning up target"),i.end()}}),i.on("end",function(){t("target disconnected"),e.close()}),i.on("error",function(o){t("target connection error",o),i.end(),e.close(3e3)})}function m(...e){C("[TCP Server]",...e)}function j(e,c){return class extends c{constructor(t,s){const l=t.port;t.port=e,G({tcpListenPort:l,wsConnectPort:e}),super(t,s)}}}function G(e){e={wsConnectHost:"127.0.0.1",...e};const{tcpListenPort:c,wsConnectHost:r,wsConnectPort:t}=e,s=_();s.on("connection",function(f){const i=[],u=new S(`ws://${r}:${t}/`);u.binaryType="arraybuffer";function n(a){u.send(new Uint8Array(a))}u.addEventListener("open",function(){for(m("Outbound WebSocket connection established");i.length>0;)n(i.shift())}),u.addEventListener("message",a=>{m("WS->TCP message:",new TextDecoder().decode(a.data)),f.write(Buffer.from(a.data))}),u.addEventListener("close",()=>{m("WebSocket connection closed"),f.end()}),f.on("data",function(a){if(m("TCP->WS message:",a),u.readyState===S.OPEN){for(;i.length>0;)n(i.shift());n(a)}else i.push(a)}),f.once("close",function(){m("TCP connection closed"),u.close()}),f.on("error",function(){m("TCP connection error"),u.close()})}),s.listen(c,function(){m("TCP server listening")})}let p=process.argv.slice(2);p.length||(p=["--help"]);const P=new URL("ca-bundle.crt",(import.meta||{}).url).pathname;b(P)||E(P,g.join(`
|
|
4
|
-
`));async function Q(){const e=await I(()=>import("./assets/php-e1f9edd4.js"),[]),c=process.env.PHP||"8.2",[r,t]=await H(2);await K(t);const s=await R(c),l=await x(s,{ENV:{...process.env,TERM:"xterm"},websocket:{url:(n,a,o)=>{const d=new URLSearchParams({host:a,port:o}).toString();return`ws://127.0.0.1:${t}/?${d}`},subprotocol:"binary",decorator:q,serverDecorator:j.bind(null,r)}});p.some(n=>n.startsWith("-c"))||p.unshift("-c",e);const i=new U(l),u=O("/").map(n=>`/${n}`).filter(n=>L(n).isDirectory());for(const n of u)i.fileExists(n)||i.mkdirTree(n),i.mount({root:n},n);i.chdir(process.cwd()),i.writeFile(P,g.join(`
|
|
5
|
-
`)),p.unshift("-d",`openssl.cafile=${P}`),i.cli(["php",...p]).catch(n=>{throw n.name==="ExitStatus"&&process.exit(n.status===void 0?1:n.status),n})}Q();
|
|
1
|
+
import{existsSync as P,writeFileSync as v}from"fs";import{rootCertificates as E}from"tls";import{LatestSupportedPHPVersion as w,SupportedPHPVersionsList as S,PHP as g}from"@php-wasm/node";const y="modulepreload",L=function(e){return"/"+e},f={},R=function(u,c,p){if(!c||c.length===0)return u();const h=document.getElementsByTagName("link");return Promise.all(c.map(t=>{if(t=L(t),t in f)return;f[t]=!0;const r=t.endsWith(".css"),d=r?'[rel="stylesheet"]':"";if(!!p)for(let i=h.length-1;i>=0;i--){const o=h[i];if(o.href===t&&(!r||o.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${t}"]${d}`))return;const s=document.createElement("link");if(s.rel=r?"stylesheet":y,r||(s.as="script",s.crossOrigin=""),s.href=t,document.head.appendChild(s),r)return new Promise((i,o)=>{s.addEventListener("load",i),s.addEventListener("error",()=>o(new Error(`Unable to preload CSS for ${t}`)))})})).then(()=>u())};let n=process.argv.slice(2);n.length||(n=["--help"]);const a=new URL("ca-bundle.crt",(import.meta||{}).url).pathname;P(a)||v(a,E.join(`
|
|
2
|
+
`));n.unshift("-d",`openssl.cafile=${a}`);const _=await R(()=>import("./assets/php-e1f9edd4.js"),[]),l=process.env.PHP||w;if(!S.includes(l))throw new Error(`Unsupported PHP version ${l}`);const m=await g.load(l,{emscriptenOptions:{ENV:{...process.env,TERM:"xterm"}}});m.useHostFilesystem();const k=n.some(e=>e.startsWith("-c"));k||n.unshift("-c",_);m.cli(["php",...n]).catch(e=>{throw e.name==="ExitStatus"&&process.exit(e.status===void 0?1:e.status),e});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@php-wasm/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.18",
|
|
4
4
|
"description": "PHP.wasm CLI for node.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -23,10 +23,11 @@
|
|
|
23
23
|
"type": "module",
|
|
24
24
|
"main": "main.js",
|
|
25
25
|
"bin": "cli.js",
|
|
26
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "2de8f9182b249b7e87694efaa06e7f25b64b7bb3",
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"comlink": "4.4.1",
|
|
29
|
+
"express": "4.18.2",
|
|
29
30
|
"ws": "8.13.0",
|
|
30
|
-
"@php-wasm/node": "0.1.
|
|
31
|
+
"@php-wasm/node": "0.1.18"
|
|
31
32
|
}
|
|
32
33
|
}
|