@php-wasm/universal 0.1.61 → 0.2.0
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 +9 -9
- package/index.js +182 -176
- package/lib/index.d.ts +1 -0
- package/lib/is-exit-code-zero.d.ts +7 -0
- package/lib/universal-php.d.ts +2 -2
- package/package.json +6 -2
package/index.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const R=Symbol("error"),S=Symbol("message");class v extends Event{constructor(e,t={}){super(e),this[R]=t.error===void 0?null:t.error,this[S]=t.message===void 0?"":t.message}get error(){return this[R]}get message(){return this[S]}}Object.defineProperty(v.prototype,"error",{enumerable:!0});Object.defineProperty(v.prototype,"message",{enumerable:!0});const D=typeof globalThis.ErrorEvent=="function"?globalThis.ErrorEvent:v;function U(s){return s instanceof Error?"exitCode"in s&&s?.exitCode===0||s?.name==="ExitStatus"&&"status"in s&&s.status===0:!1}class A extends EventTarget{constructor(){super(...arguments),this.listenersCount=0}addEventListener(e,t){++this.listenersCount,super.addEventListener(e,t)}removeEventListener(e,t){--this.listenersCount,super.removeEventListener(e,t)}hasListeners(){return this.listenersCount>0}}function q(s){s.asm={...s.asm};const e=new A;for(const t in s.asm)if(typeof s.asm[t]=="function"){const r=s.asm[t];s.asm[t]=function(...n){try{return r(...n)}catch(o){if(!(o instanceof Error))throw o;const i=W(o,s.lastAsyncifyStackSource?.stack);if(s.lastAsyncifyStackSource&&(o.cause=s.lastAsyncifyStackSource),e.hasListeners()){e.dispatchEvent(new D("error",{error:o,message:i}));return}throw U(o)||V(i),o}}}return e}let w=[];function j(){return w}function W(s,e){if(s.message==="unreachable"){let t=z;e||(t+=`
|
|
2
2
|
|
|
3
3
|
This stack trace is lacking. For a better one initialize
|
|
4
4
|
the PHP runtime with { debug: true }, e.g. PHPNode.load('8.1', { debug: true }).
|
|
5
5
|
|
|
6
|
-
`),w=
|
|
7
|
-
`;return t}return
|
|
6
|
+
`),w=Y(e||s.stack||"");for(const r of w)t+=` * ${r}
|
|
7
|
+
`;return t}return s.message}const z=`
|
|
8
8
|
"unreachable" WASM instruction executed.
|
|
9
9
|
|
|
10
10
|
The typical reason is a PHP function missing from the ASYNCIFY_ONLY
|
|
@@ -28,13 +28,13 @@ the Dockerfile, you'll need to trigger this error again with long stack
|
|
|
28
28
|
traces enabled. In node.js, you can do it using the --stack-trace-limit=100
|
|
29
29
|
CLI option:
|
|
30
30
|
|
|
31
|
-
`,x="\x1B[41m",
|
|
31
|
+
`,x="\x1B[41m",G="\x1B[1m",H="\x1B[0m",T="\x1B[K";let k=!1;function V(s){if(!k){k=!0,console.log(`${x}
|
|
32
32
|
${T}
|
|
33
|
-
${
|
|
34
|
-
`))console.log(`${T} ${e} `);console.log(`${H}`)}}function
|
|
35
|
-
`).slice(1).map(t=>{const r=t.trim().substring(3).split(" ");return{fn:r.length>=2?r[0]:"<unknown>",isWasm:t.includes("wasm://")}}).filter(({fn:t,isWasm:r})=>r&&!t.startsWith("dynCall_")&&!t.startsWith("invoke_")).map(({fn:t})=>t);return Array.from(new Set(e))}catch{return[]}}class y{constructor(e,t,r,
|
|
33
|
+
${G} WASM ERROR${H}${x}`);for(const e of s.split(`
|
|
34
|
+
`))console.log(`${T} ${e} `);console.log(`${H}`)}}function Y(s){try{const e=s.split(`
|
|
35
|
+
`).slice(1).map(t=>{const r=t.trim().substring(3).split(" ");return{fn:r.length>=2?r[0]:"<unknown>",isWasm:t.includes("wasm://")}}).filter(({fn:t,isWasm:r})=>r&&!t.startsWith("dynCall_")&&!t.startsWith("invoke_")).map(({fn:t})=>t);return Array.from(new Set(e))}catch{return[]}}class y{constructor(e,t,r,n="",o=0){this.httpStatusCode=e,this.headers=t,this.bytes=r,this.exitCode=o,this.errors=n}static fromRawData(e){return new y(e.httpStatusCode,e.headers,e.bytes,e.errors,e.exitCode)}toRawData(){return{headers:this.headers,bytes:this.bytes,errors:this.errors,exitCode:this.exitCode,httpStatusCode:this.httpStatusCode}}get json(){return JSON.parse(this.text)}get text(){return new TextDecoder().decode(this.bytes)}}const E=["8.2","8.1","8.0","7.4","7.3","7.2","7.1","7.0","5.6"],J=E[0],K=E;class O{#e;#t;constructor(e,t={}){this.requestHandler=e,this.#e={},this.#t={handleRedirects:!1,maxRedirects:4,...t}}async request(e,t=0){const r=await this.requestHandler.request({...e,headers:{...e.headers,cookie:this.#r()}});if(r.headers["set-cookie"]&&this.#s(r.headers["set-cookie"]),this.#t.handleRedirects&&r.headers.location&&t<this.#t.maxRedirects){const n=new URL(r.headers.location[0],this.requestHandler.absoluteUrl);return this.request({url:n.toString(),method:"GET",headers:{}},t+1)}return r}pathToInternalUrl(e){return this.requestHandler.pathToInternalUrl(e)}internalUrlToPath(e){return this.requestHandler.internalUrlToPath(e)}get absoluteUrl(){return this.requestHandler.absoluteUrl}get documentRoot(){return this.requestHandler.documentRoot}#s(e){for(const t of e)try{if(!t.includes("="))continue;const r=t.indexOf("="),n=t.substring(0,r),o=t.substring(r+1).split(";")[0];this.#e[n]=o}catch(r){console.error(r)}}#r(){const e=[];for(const t in this.#e)e.push(`${t}=${this.#e[t]}`);return e.join("; ")}}class Z{constructor({concurrency:e}){this._running=0,this.concurrency=e,this.queue=[]}get running(){return this._running}async acquire(){for(;;)if(this._running>=this.concurrency)await new Promise(e=>this.queue.push(e));else{this._running++;let e=!1;return()=>{e||(e=!0,this._running--,this.queue.length>0&&this.queue.shift()())}}}async run(e){const t=await this.acquire();try{return await e()}finally{t()}}}const I="http://example.com";function P(s){return s.toString().substring(s.origin.length)}function b(s,e){return!e||!s.startsWith(e)?s:s.substring(e.length)}function L(s,e){return!e||s.startsWith(e)?s:e+s}class N{#e;#t;#s;#r;#o;#n;#i;#a;#l;constructor(e,t={}){this.#a=new Z({concurrency:1});const{documentRoot:r="/www/",absoluteUrl:n=typeof location=="object"?location?.href:"",isStaticFilePath:o=()=>!1}=t;this.php=e,this.#e=r,this.#l=o;const i=new URL(n);this.#s=i.hostname,this.#r=i.port?Number(i.port):i.protocol==="https:"?443:80,this.#t=(i.protocol||"").replace(":","");const l=this.#r!==443&&this.#r!==80;this.#o=[this.#s,l?`:${this.#r}`:""].join(""),this.#n=i.pathname.replace(/\/+$/,""),this.#i=[`${this.#t}://`,this.#o,this.#n].join("")}pathToInternalUrl(e){return`${this.absoluteUrl}${e}`}internalUrlToPath(e){const t=new URL(e);return t.pathname.startsWith(this.#n)&&(t.pathname=t.pathname.slice(this.#n.length)),P(t)}get isRequestRunning(){return this.#a.running>0}get absoluteUrl(){return this.#i}get documentRoot(){return this.#e}async request(e){const t=e.url.startsWith("http://")||e.url.startsWith("https://"),r=new URL(e.url,t?void 0:I),n=b(r.pathname,this.#n);return this.#l(n)?this.#c(n):await this.#h(e,r)}#c(e){const t=`${this.#e}${e}`;if(!this.php.fileExists(t))return new y(404,{},new TextEncoder().encode("404 File not found"));const r=this.php.readFileAsBuffer(t);return new y(200,{"content-length":[`${r.byteLength}`],"content-type":[X(t)],"accept-ranges":["bytes"],"cache-control":["public, max-age=0"]},r)}async#h(e,t){const r=await this.#a.acquire();try{this.php.addServerGlobalEntry("DOCUMENT_ROOT",this.#e),this.php.addServerGlobalEntry("HTTPS",this.#i.startsWith("https://")?"on":"");let n="GET";const o={host:this.#o,...$(e.headers||{})},i=[];if(e.files&&Object.keys(e.files).length){n="POST";for(const c in e.files){const m=e.files[c];i.push({key:c,name:m.name,type:m.type,data:new Uint8Array(await m.arrayBuffer())})}o["content-type"]?.startsWith("multipart/form-data")&&(e.formData=Q(e.body||""),o["content-type"]="application/x-www-form-urlencoded",delete e.body)}let l;e.formData!==void 0?(n="POST",o["content-type"]=o["content-type"]||"application/x-www-form-urlencoded",l=new URLSearchParams(e.formData).toString()):l=e.body;let h;try{h=this.#u(t.pathname)}catch{return new y(404,{},new TextEncoder().encode("404 File not found"))}return await this.php.run({relativeUri:L(P(t),this.#n),protocol:this.#t,method:e.method||n,body:l,fileInfos:i,scriptPath:h,headers:o})}finally{r()}}#u(e){let t=b(e,this.#n);t.includes(".php")?t=t.split(".php")[0]+".php":(t.endsWith("/")||(t+="/"),t.endsWith("index.php")||(t+="index.php"));const r=`${this.#e}${t}`;if(this.php.fileExists(r))return r;if(!this.php.fileExists(`${this.#e}/index.php`))throw new Error(`File not found: ${r}`);return`${this.#e}/index.php`}}function Q(s){const e={},t=s.match(/--(.*)\r\n/);if(!t)return e;const r=t[1],n=s.split(`--${r}`);return n.shift(),n.pop(),n.forEach(o=>{const i=o.indexOf(`\r
|
|
36
36
|
\r
|
|
37
|
-
`),l=o.substring(0,i).trim(),
|
|
37
|
+
`),l=o.substring(0,i).trim(),h=o.substring(i+4).trim(),c=l.match(/name="([^"]+)"/);if(c){const m=c[1];e[m]=h}}),e}function X(s){switch(s.split(".").pop()){case"css":return"text/css";case"js":return"application/javascript";case"png":return"image/png";case"jpg":case"jpeg":return"image/jpeg";case"gif":return"image/gif";case"svg":return"image/svg+xml";case"woff":return"font/woff";case"woff2":return"font/woff2";case"ttf":return"font/ttf";case"otf":return"font/otf";case"eot":return"font/eot";case"ico":return"image/x-icon";case"html":return"text/html";case"json":return"application/json";case"xml":return"application/xml";case"txt":case"md":return"text/plain";default:return"application-octet-stream"}}const F={0:"No error occurred. System call completed successfully.",1:"Argument list too long.",2:"Permission denied.",3:"Address in use.",4:"Address not available.",5:"Address family not supported.",6:"Resource unavailable, or operation would block.",7:"Connection already in progress.",8:"Bad file descriptor.",9:"Bad message.",10:"Device or resource busy.",11:"Operation canceled.",12:"No child processes.",13:"Connection aborted.",14:"Connection refused.",15:"Connection reset.",16:"Resource deadlock would occur.",17:"Destination address required.",18:"Mathematics argument out of domain of function.",19:"Reserved.",20:"File exists.",21:"Bad address.",22:"File too large.",23:"Host is unreachable.",24:"Identifier removed.",25:"Illegal byte sequence.",26:"Operation in progress.",27:"Interrupted function.",28:"Invalid argument.",29:"I/O error.",30:"Socket is connected.",31:"There is a directory under that path.",32:"Too many levels of symbolic links.",33:"File descriptor value too large.",34:"Too many links.",35:"Message too large.",36:"Reserved.",37:"Filename too long.",38:"Network is down.",39:"Connection aborted by network.",40:"Network unreachable.",41:"Too many files open in system.",42:"No buffer space available.",43:"No such device.",44:"There is no such file or directory OR the parent directory does not exist.",45:"Executable file format error.",46:"No locks available.",47:"Reserved.",48:"Not enough space.",49:"No message of the desired type.",50:"Protocol not available.",51:"No space left on device.",52:"Function not supported.",53:"The socket is not connected.",54:"Not a directory or a symbolic link to a directory.",55:"Directory not empty.",56:"State not recoverable.",57:"Not a socket.",58:"Not supported, or operation not supported on socket.",59:"Inappropriate I/O control operation.",60:"No such device or address.",61:"Value too large to be stored in data type.",62:"Previous owner died.",63:"Operation not permitted.",64:"Broken pipe.",65:"Protocol error.",66:"Protocol not supported.",67:"Protocol wrong type for socket.",68:"Result too large.",69:"Read-only file system.",70:"Invalid seek.",71:"No such process.",72:"Reserved.",73:"Connection timed out.",74:"Text file busy.",75:"Cross-device link.",76:"Extension: Capabilities insufficient."};function p(s=""){return function(t,r,n){const o=n.value;n.value=function(...i){try{return o.apply(this,i)}catch(l){const h=typeof l=="object"?l?.errno:null;if(h in F){const c=F[h],m=typeof i[0]=="string"?i[0]:null,M=m!==null?s.replaceAll("{path}",m):s;throw new Error(`${M}: ${c}`,{cause:l})}throw l}}}}async function ee(s,e={},t=[]){const[r,n,o]=C(),[i,l]=C(),h=s.init(re,{onAbort(c){o(c),l(),console.error(c)},ENV:{},locateFile:c=>c,...e,noInitialRun:!0,onRuntimeInitialized(){e.onRuntimeInitialized&&e.onRuntimeInitialized(),n()},monitorRunDependencies(c){c===0&&(delete h.monitorRunDependencies,l())}});return await Promise.all(t.map(({default:c})=>c(h))),t.length||l(),await i,await r,_.push(h),_.length-1}const _=[];function te(s){return _[s]}const re=function(){return typeof process<"u"&&process.release?.name==="node"?"NODE":typeof window<"u"?"WEB":typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope?"WORKER":"NODE"}(),C=()=>{const s=[],e=new Promise((t,r)=>{s.push(t,r)});return s.unshift(e),s};var se=Object.defineProperty,ne=Object.getOwnPropertyDescriptor,f=(s,e,t,r)=>{for(var n=r>1?void 0:r?ne(e,t):e,o=s.length-1,i;o>=0;o--)(i=s[o])&&(n=(r?i(e,t,n):i(n))||n);return r&&n&&se(e,t,n),n};const u="string",g="number",a=Symbol("__private__dont__use");class d{constructor(e,t){this.#e=[],this.#t=!1,this.#s=null,this.#r={},this.#o=[],e!==void 0&&this.initializeRuntime(e),t&&(this.requestHandler=new O(new N(this,t)))}#e;#t;#s;#r;#o;async onMessage(e){this.#o.push(e)}get absoluteUrl(){return this.requestHandler.requestHandler.absoluteUrl}get documentRoot(){return this.requestHandler.requestHandler.documentRoot}pathToInternalUrl(e){return this.requestHandler.requestHandler.pathToInternalUrl(e)}internalUrlToPath(e){return this.requestHandler.requestHandler.internalUrlToPath(e)}initializeRuntime(e){if(this[a])throw new Error("PHP runtime already initialized.");const t=te(e);if(!t)throw new Error("Invalid PHP runtime id.");this[a]=t,t.onMessage=r=>{for(const n of this.#o)n(r)},this.#s=q(t)}setPhpIniPath(e){if(this.#t)throw new Error("Cannot set PHP ini path after calling run().");this[a].ccall("wasm_set_phpini_path",null,["string"],[e])}setPhpIniEntry(e,t){if(this.#t)throw new Error("Cannot set PHP ini entries after calling run().");this.#e.push([e,t])}chdir(e){this[a].FS.chdir(e)}async request(e,t){if(!this.requestHandler)throw new Error("No request handler available.");return this.requestHandler.request(e,t)}async run(e){this.#t||(this.#n(),this.#t=!0),this.#d(e.scriptPath||""),this.#a(e.relativeUri||""),this.#c(e.method||"GET");const{host:t,...r}={host:"example.com:443",...$(e.headers||{})};if(this.#l(t,e.protocol||"http"),this.#h(r),e.body&&this.#u(e.body),e.fileInfos)for(const n of e.fileInfos)this.#f(n);return e.code&&this.#m(" ?>"+e.code),this.#p(),await this.#y()}#n(){if(this.#e.length>0){const e=this.#e.map(([t,r])=>`${t}=${r}`).join(`
|
|
38
38
|
`)+`
|
|
39
39
|
|
|
40
|
-
`;this[a].ccall("wasm_set_phpini_entries",null,[
|
|
40
|
+
`;this[a].ccall("wasm_set_phpini_entries",null,[u],[e])}this[a].ccall("php_wasm_init",null,[],[])}#i(){const e="/tmp/headers.json";if(!this.fileExists(e))throw new Error("SAPI Error: Could not find response headers file.");const t=JSON.parse(this.readFileAsText(e)),r={};for(const n of t.headers){if(!n.includes(": "))continue;const o=n.indexOf(": "),i=n.substring(0,o).toLowerCase(),l=n.substring(o+2);i in r||(r[i]=[]),r[i].push(l)}return{headers:r,httpStatusCode:t.status}}#a(e){if(this[a].ccall("wasm_set_request_uri",null,[u],[e]),e.includes("?")){const t=e.substring(e.indexOf("?")+1);this[a].ccall("wasm_set_query_string",null,[u],[t])}}#l(e,t){this[a].ccall("wasm_set_request_host",null,[u],[e]);let r;try{r=parseInt(new URL(e).port,10)}catch{}(!r||isNaN(r)||r===80)&&(r=t==="https"?443:80),this[a].ccall("wasm_set_request_port",null,[g],[r]),(t==="https"||!t&&r===443)&&this.addServerGlobalEntry("HTTPS","on")}#c(e){this[a].ccall("wasm_set_request_method",null,[u],[e])}#h(e){e.cookie&&this[a].ccall("wasm_set_cookies",null,[u],[e.cookie]),e["content-type"]&&this[a].ccall("wasm_set_content_type",null,[u],[e["content-type"]]),e["content-length"]&&this[a].ccall("wasm_set_content_length",null,[g],[parseInt(e["content-length"],10)]);for(const t in e){let r="HTTP_";["content-type","content-length"].includes(t.toLowerCase())&&(r=""),this.addServerGlobalEntry(`${r}${t.toUpperCase().replace(/-/g,"_")}`,e[t])}}#u(e){this[a].ccall("wasm_set_request_body",null,[u],[e]),this[a].ccall("wasm_set_content_length",null,[g],[new TextEncoder().encode(e).length])}#d(e){this[a].ccall("wasm_set_path_translated",null,[u],[e])}addServerGlobalEntry(e,t){this.#r[e]=t}#p(){for(const e in this.#r)this[a].ccall("wasm_add_SERVER_entry",null,[u,u],[e,this.#r[e]])}#f(e){const{key:t,name:r,type:n,data:o}=e,i=`/tmp/${Math.random().toFixed(20)}`;this.writeFile(i,o);const l=0;this[a].ccall("wasm_add_uploaded_file",null,[u,u,u,u,g,g],[t,r,n,i,l,o.byteLength])}#m(e){this[a].ccall("wasm_set_php_code",null,[u],[e])}async#y(){let e,t;try{e=await new Promise((o,i)=>{t=h=>{const c=new Error("Rethrown");c.cause=h.error,c.betterMessage=h.message,i(c)},this.#s?.addEventListener("error",t);const l=this[a].ccall("wasm_sapi_handle_request",g,[],[]);return l instanceof Promise?l.then(o,i):o(l)})}catch(o){for(const c in this)typeof this[c]=="function"&&(this[c]=()=>{throw new Error("PHP runtime has crashed – see the earlier error for details.")});this.functionsMaybeMissingFromAsyncify=j();const i=o,l="betterMessage"in i?i.betterMessage:i.message,h=new Error(l);throw h.cause=i,h}finally{this.#s?.removeEventListener("error",t),this.#r={}}const{headers:r,httpStatusCode:n}=this.#i();return new y(n,r,this.readFileAsBuffer("/tmp/stdout"),this.readFileAsText("/tmp/stderr"),e)}mkdir(e){this[a].FS.mkdirTree(e)}mkdirTree(e){this.mkdir(e)}readFileAsText(e){return new TextDecoder().decode(this.readFileAsBuffer(e))}readFileAsBuffer(e){return this[a].FS.readFile(e)}writeFile(e,t){this[a].FS.writeFile(e,t)}unlink(e){this[a].FS.unlink(e)}mv(e,t){this[a].FS.rename(e,t)}rmdir(e,t={recursive:!0}){t?.recursive&&this.listFiles(e).forEach(r=>{const n=`${e}/${r}`;this.isDir(n)?this.rmdir(n,t):this.unlink(n)}),this[a].FS.rmdir(e)}listFiles(e,t={prependPath:!1}){if(!this.fileExists(e))return[];try{const r=this[a].FS.readdir(e).filter(n=>n!=="."&&n!=="..");if(t.prependPath){const n=e.replace(/\/$/,"");return r.map(o=>`${n}/${o}`)}return r}catch(r){return console.error(r,{path:e}),[]}}isDir(e){return this.fileExists(e)?this[a].FS.isDir(this[a].FS.lookupPath(e).node.mode):!1}fileExists(e){try{return this[a].FS.lookupPath(e),!0}catch{return!1}}}f([p('Could not create directory "{path}"')],d.prototype,"mkdir",1);f([p('Could not create directory "{path}"')],d.prototype,"mkdirTree",1);f([p('Could not read "{path}"')],d.prototype,"readFileAsText",1);f([p('Could not read "{path}"')],d.prototype,"readFileAsBuffer",1);f([p('Could not write to "{path}"')],d.prototype,"writeFile",1);f([p('Could not unlink "{path}"')],d.prototype,"unlink",1);f([p('Could not move "{path}"')],d.prototype,"mv",1);f([p('Could not remove directory "{path}"')],d.prototype,"rmdir",1);f([p('Could not list files in "{path}"')],d.prototype,"listFiles",1);f([p('Could not stat "{path}"')],d.prototype,"isDir",1);f([p('Could not stat "{path}"')],d.prototype,"fileExists",1);function $(s){const e={};for(const t in s)e[t.toLowerCase()]=s[t];return e}function B(s){return!(s instanceof d)}function oe(s){return!B(s)}exports.BasePHP=d;exports.DEFAULT_BASE_URL=I;exports.LatestSupportedPHPVersion=J;exports.PHPBrowser=O;exports.PHPRequestHandler=N;exports.PHPResponse=y;exports.SupportedPHPVersions=E;exports.SupportedPHPVersionsList=K;exports.UnhandledRejectionsTarget=A;exports.__private__dont__use=a;exports.ensurePathPrefix=L;exports.isExitCodeZero=U;exports.isLocalPHP=B;exports.isRemotePHP=oe;exports.loadPHPRuntime=ee;exports.removePathPrefix=b;exports.rethrowFileSystemError=p;exports.toRelativeUrl=P;
|
package/index.js
CHANGED
|
@@ -20,7 +20,10 @@ class b extends Event {
|
|
|
20
20
|
Object.defineProperty(b.prototype, "error", { enumerable: !0 });
|
|
21
21
|
Object.defineProperty(b.prototype, "message", { enumerable: !0 });
|
|
22
22
|
const A = typeof globalThis.ErrorEvent == "function" ? globalThis.ErrorEvent : b;
|
|
23
|
-
|
|
23
|
+
function I(s) {
|
|
24
|
+
return s instanceof Error ? "exitCode" in s && s?.exitCode === 0 || s?.name === "ExitStatus" && "status" in s && s.status === 0 : !1;
|
|
25
|
+
}
|
|
26
|
+
class N extends EventTarget {
|
|
24
27
|
constructor() {
|
|
25
28
|
super(...arguments), this.listenersCount = 0;
|
|
26
29
|
}
|
|
@@ -34,62 +37,62 @@ class O extends EventTarget {
|
|
|
34
37
|
return this.listenersCount > 0;
|
|
35
38
|
}
|
|
36
39
|
}
|
|
37
|
-
function
|
|
38
|
-
|
|
39
|
-
...
|
|
40
|
+
function $(s) {
|
|
41
|
+
s.asm = {
|
|
42
|
+
...s.asm
|
|
40
43
|
};
|
|
41
|
-
const e = new
|
|
42
|
-
for (const t in
|
|
43
|
-
if (typeof
|
|
44
|
-
const r =
|
|
45
|
-
|
|
44
|
+
const e = new N();
|
|
45
|
+
for (const t in s.asm)
|
|
46
|
+
if (typeof s.asm[t] == "function") {
|
|
47
|
+
const r = s.asm[t];
|
|
48
|
+
s.asm[t] = function(...n) {
|
|
46
49
|
try {
|
|
47
|
-
return r(...
|
|
50
|
+
return r(...n);
|
|
48
51
|
} catch (o) {
|
|
49
52
|
if (!(o instanceof Error))
|
|
50
53
|
throw o;
|
|
51
|
-
|
|
52
|
-
return;
|
|
53
|
-
const i = $(
|
|
54
|
+
const i = M(
|
|
54
55
|
o,
|
|
55
|
-
|
|
56
|
-
);
|
|
57
|
-
if (n.lastAsyncifyStackSource && (o.cause = n.lastAsyncifyStackSource), !e.hasListeners())
|
|
58
|
-
throw D(i), o;
|
|
59
|
-
e.dispatchEvent(
|
|
60
|
-
new A("error", {
|
|
61
|
-
error: o,
|
|
62
|
-
message: i
|
|
63
|
-
})
|
|
56
|
+
s.lastAsyncifyStackSource?.stack
|
|
64
57
|
);
|
|
58
|
+
if (s.lastAsyncifyStackSource && (o.cause = s.lastAsyncifyStackSource), e.hasListeners()) {
|
|
59
|
+
e.dispatchEvent(
|
|
60
|
+
new A("error", {
|
|
61
|
+
error: o,
|
|
62
|
+
message: i
|
|
63
|
+
})
|
|
64
|
+
);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
throw I(o) || q(i), o;
|
|
65
68
|
}
|
|
66
69
|
};
|
|
67
70
|
}
|
|
68
71
|
return e;
|
|
69
72
|
}
|
|
70
73
|
let w = [];
|
|
71
|
-
function
|
|
74
|
+
function L() {
|
|
72
75
|
return w;
|
|
73
76
|
}
|
|
74
|
-
function
|
|
75
|
-
if (
|
|
76
|
-
let t =
|
|
77
|
+
function M(s, e) {
|
|
78
|
+
if (s.message === "unreachable") {
|
|
79
|
+
let t = B;
|
|
77
80
|
e || (t += `
|
|
78
81
|
|
|
79
82
|
This stack trace is lacking. For a better one initialize
|
|
80
83
|
the PHP runtime with { debug: true }, e.g. PHPNode.load('8.1', { debug: true }).
|
|
81
84
|
|
|
82
|
-
`), w =
|
|
83
|
-
e ||
|
|
85
|
+
`), w = W(
|
|
86
|
+
e || s.stack || ""
|
|
84
87
|
);
|
|
85
88
|
for (const r of w)
|
|
86
89
|
t += ` * ${r}
|
|
87
90
|
`;
|
|
88
91
|
return t;
|
|
89
92
|
}
|
|
90
|
-
return
|
|
93
|
+
return s.message;
|
|
91
94
|
}
|
|
92
|
-
const
|
|
95
|
+
const B = `
|
|
93
96
|
"unreachable" WASM instruction executed.
|
|
94
97
|
|
|
95
98
|
The typical reason is a PHP function missing from the ASYNCIFY_ONLY
|
|
@@ -113,22 +116,22 @@ the Dockerfile, you'll need to trigger this error again with long stack
|
|
|
113
116
|
traces enabled. In node.js, you can do it using the --stack-trace-limit=100
|
|
114
117
|
CLI option:
|
|
115
118
|
|
|
116
|
-
`,
|
|
119
|
+
`, E = "\x1B[41m", D = "\x1B[1m", R = "\x1B[0m", S = "\x1B[K";
|
|
117
120
|
let x = !1;
|
|
118
|
-
function
|
|
121
|
+
function q(s) {
|
|
119
122
|
if (!x) {
|
|
120
|
-
x = !0, console.log(`${
|
|
123
|
+
x = !0, console.log(`${E}
|
|
121
124
|
${S}
|
|
122
|
-
${
|
|
123
|
-
for (const e of
|
|
125
|
+
${D} WASM ERROR${R}${E}`);
|
|
126
|
+
for (const e of s.split(`
|
|
124
127
|
`))
|
|
125
128
|
console.log(`${S} ${e} `);
|
|
126
|
-
console.log(`${
|
|
129
|
+
console.log(`${R}`);
|
|
127
130
|
}
|
|
128
131
|
}
|
|
129
|
-
function
|
|
132
|
+
function W(s) {
|
|
130
133
|
try {
|
|
131
|
-
const e =
|
|
134
|
+
const e = s.split(`
|
|
132
135
|
`).slice(1).map((t) => {
|
|
133
136
|
const r = t.trim().substring(3).split(" ");
|
|
134
137
|
return {
|
|
@@ -144,8 +147,8 @@ function B(n) {
|
|
|
144
147
|
}
|
|
145
148
|
}
|
|
146
149
|
class g {
|
|
147
|
-
constructor(e, t, r,
|
|
148
|
-
this.httpStatusCode = e, this.headers = t, this.bytes = r, this.exitCode = o, this.errors =
|
|
150
|
+
constructor(e, t, r, n = "", o = 0) {
|
|
151
|
+
this.httpStatusCode = e, this.headers = t, this.bytes = r, this.exitCode = o, this.errors = n;
|
|
149
152
|
}
|
|
150
153
|
static fromRawData(e) {
|
|
151
154
|
return new g(
|
|
@@ -178,7 +181,7 @@ class g {
|
|
|
178
181
|
return new TextDecoder().decode(this.bytes);
|
|
179
182
|
}
|
|
180
183
|
}
|
|
181
|
-
const
|
|
184
|
+
const H = [
|
|
182
185
|
"8.2",
|
|
183
186
|
"8.1",
|
|
184
187
|
"8.0",
|
|
@@ -188,8 +191,8 @@ const C = [
|
|
|
188
191
|
"7.1",
|
|
189
192
|
"7.0",
|
|
190
193
|
"5.6"
|
|
191
|
-
],
|
|
192
|
-
class
|
|
194
|
+
], re = H[0], se = H;
|
|
195
|
+
class j {
|
|
193
196
|
#e;
|
|
194
197
|
#t;
|
|
195
198
|
/**
|
|
@@ -226,13 +229,13 @@ class q {
|
|
|
226
229
|
}
|
|
227
230
|
});
|
|
228
231
|
if (r.headers["set-cookie"] && this.#s(r.headers["set-cookie"]), this.#t.handleRedirects && r.headers.location && t < this.#t.maxRedirects) {
|
|
229
|
-
const
|
|
232
|
+
const n = new URL(
|
|
230
233
|
r.headers.location[0],
|
|
231
234
|
this.requestHandler.absoluteUrl
|
|
232
235
|
);
|
|
233
236
|
return this.request(
|
|
234
237
|
{
|
|
235
|
-
url:
|
|
238
|
+
url: n.toString(),
|
|
236
239
|
method: "GET",
|
|
237
240
|
headers: {}
|
|
238
241
|
},
|
|
@@ -262,8 +265,8 @@ class q {
|
|
|
262
265
|
try {
|
|
263
266
|
if (!t.includes("="))
|
|
264
267
|
continue;
|
|
265
|
-
const r = t.indexOf("="),
|
|
266
|
-
this.#e[
|
|
268
|
+
const r = t.indexOf("="), n = t.substring(0, r), o = t.substring(r + 1).split(";")[0];
|
|
269
|
+
this.#e[n] = o;
|
|
267
270
|
} catch (r) {
|
|
268
271
|
console.error(r);
|
|
269
272
|
}
|
|
@@ -275,7 +278,7 @@ class q {
|
|
|
275
278
|
return e.join("; ");
|
|
276
279
|
}
|
|
277
280
|
}
|
|
278
|
-
class
|
|
281
|
+
class z {
|
|
279
282
|
constructor({ concurrency: e }) {
|
|
280
283
|
this._running = 0, this.concurrency = e, this.queue = [];
|
|
281
284
|
}
|
|
@@ -303,17 +306,17 @@ class W {
|
|
|
303
306
|
}
|
|
304
307
|
}
|
|
305
308
|
}
|
|
306
|
-
const
|
|
307
|
-
function T(
|
|
308
|
-
return
|
|
309
|
+
const G = "http://example.com";
|
|
310
|
+
function T(s) {
|
|
311
|
+
return s.toString().substring(s.origin.length);
|
|
309
312
|
}
|
|
310
|
-
function k(
|
|
311
|
-
return !e || !
|
|
313
|
+
function k(s, e) {
|
|
314
|
+
return !e || !s.startsWith(e) ? s : s.substring(e.length);
|
|
312
315
|
}
|
|
313
|
-
function
|
|
314
|
-
return !e ||
|
|
316
|
+
function V(s, e) {
|
|
317
|
+
return !e || s.startsWith(e) ? s : e + s;
|
|
315
318
|
}
|
|
316
|
-
class
|
|
319
|
+
class Y {
|
|
317
320
|
#e;
|
|
318
321
|
#t;
|
|
319
322
|
#s;
|
|
@@ -328,14 +331,14 @@ class G {
|
|
|
328
331
|
* @param config - Request Handler configuration.
|
|
329
332
|
*/
|
|
330
333
|
constructor(e, t = {}) {
|
|
331
|
-
this.#a = new
|
|
334
|
+
this.#a = new z({ concurrency: 1 });
|
|
332
335
|
const {
|
|
333
336
|
documentRoot: r = "/www/",
|
|
334
|
-
absoluteUrl:
|
|
337
|
+
absoluteUrl: n = typeof location == "object" ? location?.href : "",
|
|
335
338
|
isStaticFilePath: o = () => !1
|
|
336
339
|
} = t;
|
|
337
340
|
this.php = e, this.#e = r, this.#l = o;
|
|
338
|
-
const i = new URL(
|
|
341
|
+
const i = new URL(n);
|
|
339
342
|
this.#s = i.hostname, this.#r = i.port ? Number(i.port) : i.protocol === "https:" ? 443 : 80, this.#t = (i.protocol || "").replace(":", "");
|
|
340
343
|
const l = this.#r !== 443 && this.#r !== 80;
|
|
341
344
|
this.#o = [
|
|
@@ -371,12 +374,12 @@ class G {
|
|
|
371
374
|
async request(e) {
|
|
372
375
|
const t = e.url.startsWith("http://") || e.url.startsWith("https://"), r = new URL(
|
|
373
376
|
e.url,
|
|
374
|
-
t ? void 0 :
|
|
375
|
-
),
|
|
377
|
+
t ? void 0 : G
|
|
378
|
+
), n = k(
|
|
376
379
|
r.pathname,
|
|
377
380
|
this.#n
|
|
378
381
|
);
|
|
379
|
-
return this.#l(
|
|
382
|
+
return this.#l(n) ? this.#c(n) : await this.#h(e, r);
|
|
380
383
|
}
|
|
381
384
|
/**
|
|
382
385
|
* Serves a static file from the PHP filesystem.
|
|
@@ -400,7 +403,7 @@ class G {
|
|
|
400
403
|
// @TODO: Infer the content-type from the arrayBuffer instead of the file path.
|
|
401
404
|
// The code below won't return the correct mime-type if the extension
|
|
402
405
|
// was tampered with.
|
|
403
|
-
"content-type": [
|
|
406
|
+
"content-type": [K(t)],
|
|
404
407
|
"accept-ranges": ["bytes"],
|
|
405
408
|
"cache-control": ["public, max-age=0"]
|
|
406
409
|
},
|
|
@@ -421,33 +424,33 @@ class G {
|
|
|
421
424
|
"HTTPS",
|
|
422
425
|
this.#i.startsWith("https://") ? "on" : ""
|
|
423
426
|
);
|
|
424
|
-
let
|
|
427
|
+
let n = "GET";
|
|
425
428
|
const o = {
|
|
426
429
|
host: this.#o,
|
|
427
|
-
...
|
|
430
|
+
...U(e.headers || {})
|
|
428
431
|
}, i = [];
|
|
429
432
|
if (e.files && Object.keys(e.files).length) {
|
|
430
|
-
|
|
431
|
-
for (const
|
|
432
|
-
const m = e.files[
|
|
433
|
+
n = "POST";
|
|
434
|
+
for (const c in e.files) {
|
|
435
|
+
const m = e.files[c];
|
|
433
436
|
i.push({
|
|
434
|
-
key:
|
|
437
|
+
key: c,
|
|
435
438
|
name: m.name,
|
|
436
439
|
type: m.type,
|
|
437
440
|
data: new Uint8Array(await m.arrayBuffer())
|
|
438
441
|
});
|
|
439
442
|
}
|
|
440
|
-
o["content-type"]?.startsWith("multipart/form-data") && (e.formData =
|
|
443
|
+
o["content-type"]?.startsWith("multipart/form-data") && (e.formData = J(
|
|
441
444
|
e.body || ""
|
|
442
445
|
), o["content-type"] = "application/x-www-form-urlencoded", delete e.body);
|
|
443
446
|
}
|
|
444
447
|
let l;
|
|
445
|
-
e.formData !== void 0 ? (
|
|
448
|
+
e.formData !== void 0 ? (n = "POST", o["content-type"] = o["content-type"] || "application/x-www-form-urlencoded", l = new URLSearchParams(
|
|
446
449
|
e.formData
|
|
447
450
|
).toString()) : l = e.body;
|
|
448
|
-
let
|
|
451
|
+
let h;
|
|
449
452
|
try {
|
|
450
|
-
|
|
453
|
+
h = this.#u(t.pathname);
|
|
451
454
|
} catch {
|
|
452
455
|
return new g(
|
|
453
456
|
404,
|
|
@@ -456,15 +459,15 @@ class G {
|
|
|
456
459
|
);
|
|
457
460
|
}
|
|
458
461
|
return await this.php.run({
|
|
459
|
-
relativeUri:
|
|
462
|
+
relativeUri: V(
|
|
460
463
|
T(t),
|
|
461
464
|
this.#n
|
|
462
465
|
),
|
|
463
466
|
protocol: this.#t,
|
|
464
|
-
method: e.method ||
|
|
467
|
+
method: e.method || n,
|
|
465
468
|
body: l,
|
|
466
469
|
fileInfos: i,
|
|
467
|
-
scriptPath:
|
|
470
|
+
scriptPath: h,
|
|
468
471
|
headers: o
|
|
469
472
|
});
|
|
470
473
|
} finally {
|
|
@@ -491,23 +494,23 @@ class G {
|
|
|
491
494
|
return `${this.#e}/index.php`;
|
|
492
495
|
}
|
|
493
496
|
}
|
|
494
|
-
function
|
|
495
|
-
const e = {}, t =
|
|
497
|
+
function J(s) {
|
|
498
|
+
const e = {}, t = s.match(/--(.*)\r\n/);
|
|
496
499
|
if (!t)
|
|
497
500
|
return e;
|
|
498
|
-
const r = t[1],
|
|
499
|
-
return
|
|
501
|
+
const r = t[1], n = s.split(`--${r}`);
|
|
502
|
+
return n.shift(), n.pop(), n.forEach((o) => {
|
|
500
503
|
const i = o.indexOf(`\r
|
|
501
504
|
\r
|
|
502
|
-
`), l = o.substring(0, i).trim(),
|
|
503
|
-
if (
|
|
504
|
-
const m =
|
|
505
|
-
e[m] =
|
|
505
|
+
`), l = o.substring(0, i).trim(), h = o.substring(i + 4).trim(), c = l.match(/name="([^"]+)"/);
|
|
506
|
+
if (c) {
|
|
507
|
+
const m = c[1];
|
|
508
|
+
e[m] = h;
|
|
506
509
|
}
|
|
507
510
|
}), e;
|
|
508
511
|
}
|
|
509
|
-
function
|
|
510
|
-
switch (
|
|
512
|
+
function K(s) {
|
|
513
|
+
switch (s.split(".").pop()) {
|
|
511
514
|
case "css":
|
|
512
515
|
return "text/css";
|
|
513
516
|
case "js":
|
|
@@ -546,7 +549,7 @@ function Y(n) {
|
|
|
546
549
|
return "application-octet-stream";
|
|
547
550
|
}
|
|
548
551
|
}
|
|
549
|
-
const
|
|
552
|
+
const C = {
|
|
550
553
|
0: "No error occurred. System call completed successfully.",
|
|
551
554
|
1: "Argument list too long.",
|
|
552
555
|
2: "Permission denied.",
|
|
@@ -625,17 +628,17 @@ const F = {
|
|
|
625
628
|
75: "Cross-device link.",
|
|
626
629
|
76: "Extension: Capabilities insufficient."
|
|
627
630
|
};
|
|
628
|
-
function p(
|
|
629
|
-
return function(t, r,
|
|
630
|
-
const o =
|
|
631
|
-
|
|
631
|
+
function p(s = "") {
|
|
632
|
+
return function(t, r, n) {
|
|
633
|
+
const o = n.value;
|
|
634
|
+
n.value = function(...i) {
|
|
632
635
|
try {
|
|
633
636
|
return o.apply(this, i);
|
|
634
637
|
} catch (l) {
|
|
635
|
-
const
|
|
636
|
-
if (
|
|
637
|
-
const
|
|
638
|
-
throw new Error(`${
|
|
638
|
+
const h = typeof l == "object" ? l?.errno : null;
|
|
639
|
+
if (h in C) {
|
|
640
|
+
const c = C[h], m = typeof i[0] == "string" ? i[0] : null, O = m !== null ? s.replaceAll("{path}", m) : s;
|
|
641
|
+
throw new Error(`${O}: ${c}`, {
|
|
639
642
|
cause: l
|
|
640
643
|
});
|
|
641
644
|
}
|
|
@@ -644,15 +647,10 @@ function p(n = "") {
|
|
|
644
647
|
};
|
|
645
648
|
};
|
|
646
649
|
}
|
|
647
|
-
async function
|
|
648
|
-
|
|
649
|
-
const o = new Promise((c) => {
|
|
650
|
-
s = c;
|
|
651
|
-
}), i = new Promise((c) => {
|
|
652
|
-
r = c;
|
|
653
|
-
}), l = n.init(K, {
|
|
650
|
+
async function ne(s, e = {}, t = []) {
|
|
651
|
+
const [r, n, o] = F(), [i, l] = F(), h = s.init(Q, {
|
|
654
652
|
onAbort(c) {
|
|
655
|
-
|
|
653
|
+
o(c), l(), console.error(c);
|
|
656
654
|
},
|
|
657
655
|
ENV: {},
|
|
658
656
|
// Emscripten sometimes prepends a '/' to the path, which
|
|
@@ -662,29 +660,36 @@ async function re(n, e = {}, t = []) {
|
|
|
662
660
|
...e,
|
|
663
661
|
noInitialRun: !0,
|
|
664
662
|
onRuntimeInitialized() {
|
|
665
|
-
e.onRuntimeInitialized && e.onRuntimeInitialized(),
|
|
663
|
+
e.onRuntimeInitialized && e.onRuntimeInitialized(), n();
|
|
666
664
|
},
|
|
667
665
|
monitorRunDependencies(c) {
|
|
668
|
-
c === 0 && (delete
|
|
666
|
+
c === 0 && (delete h.monitorRunDependencies, l());
|
|
669
667
|
}
|
|
670
668
|
});
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
669
|
+
return await Promise.all(
|
|
670
|
+
t.map(
|
|
671
|
+
({ default: c }) => c(h)
|
|
672
|
+
)
|
|
673
|
+
), t.length || l(), await i, await r, P.push(h), P.length - 1;
|
|
674
674
|
}
|
|
675
675
|
const P = [];
|
|
676
|
-
function
|
|
677
|
-
return P[
|
|
676
|
+
function Z(s) {
|
|
677
|
+
return P[s];
|
|
678
678
|
}
|
|
679
|
-
const
|
|
679
|
+
const Q = function() {
|
|
680
680
|
return typeof process < "u" && process.release?.name === "node" ? "NODE" : typeof window < "u" ? "WEB" : typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope ? "WORKER" : "NODE";
|
|
681
|
-
}()
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
return
|
|
681
|
+
}(), F = () => {
|
|
682
|
+
const s = [], e = new Promise((t, r) => {
|
|
683
|
+
s.push(t, r);
|
|
684
|
+
});
|
|
685
|
+
return s.unshift(e), s;
|
|
686
|
+
};
|
|
687
|
+
var X = Object.defineProperty, ee = Object.getOwnPropertyDescriptor, f = (s, e, t, r) => {
|
|
688
|
+
for (var n = r > 1 ? void 0 : r ? ee(e, t) : e, o = s.length - 1, i; o >= 0; o--)
|
|
689
|
+
(i = s[o]) && (n = (r ? i(e, t, n) : i(n)) || n);
|
|
690
|
+
return r && n && X(e, t, n), n;
|
|
686
691
|
};
|
|
687
|
-
const
|
|
692
|
+
const u = "string", y = "number", a = Symbol("__private__dont__use");
|
|
688
693
|
class d {
|
|
689
694
|
/**
|
|
690
695
|
* Initializes a PHP runtime.
|
|
@@ -694,8 +699,8 @@ class d {
|
|
|
694
699
|
* @param serverOptions - Optional. Options for the PHPRequestHandler. If undefined, no request handler will be initialized.
|
|
695
700
|
*/
|
|
696
701
|
constructor(e, t) {
|
|
697
|
-
this.#e = [], this.#t = !1, this.#s = null, this.#r = {}, this.#o = [], e !== void 0 && this.initializeRuntime(e), t && (this.requestHandler = new
|
|
698
|
-
new
|
|
702
|
+
this.#e = [], this.#t = !1, this.#s = null, this.#r = {}, this.#o = [], e !== void 0 && this.initializeRuntime(e), t && (this.requestHandler = new j(
|
|
703
|
+
new Y(this, t)
|
|
699
704
|
));
|
|
700
705
|
}
|
|
701
706
|
#e;
|
|
@@ -728,13 +733,13 @@ class d {
|
|
|
728
733
|
initializeRuntime(e) {
|
|
729
734
|
if (this[a])
|
|
730
735
|
throw new Error("PHP runtime already initialized.");
|
|
731
|
-
const t =
|
|
736
|
+
const t = Z(e);
|
|
732
737
|
if (!t)
|
|
733
738
|
throw new Error("Invalid PHP runtime id.");
|
|
734
739
|
this[a] = t, t.onMessage = (r) => {
|
|
735
|
-
for (const
|
|
736
|
-
|
|
737
|
-
}, this.#s =
|
|
740
|
+
for (const n of this.#o)
|
|
741
|
+
n(r);
|
|
742
|
+
}, this.#s = $(t);
|
|
738
743
|
}
|
|
739
744
|
/** @inheritDoc */
|
|
740
745
|
setPhpIniPath(e) {
|
|
@@ -768,11 +773,11 @@ class d {
|
|
|
768
773
|
this.#t || (this.#n(), this.#t = !0), this.#d(e.scriptPath || ""), this.#a(e.relativeUri || ""), this.#c(e.method || "GET");
|
|
769
774
|
const { host: t, ...r } = {
|
|
770
775
|
host: "example.com:443",
|
|
771
|
-
...
|
|
776
|
+
...U(e.headers || {})
|
|
772
777
|
};
|
|
773
778
|
if (this.#l(t, e.protocol || "http"), this.#h(r), e.body && this.#u(e.body), e.fileInfos)
|
|
774
|
-
for (const
|
|
775
|
-
this.#f(
|
|
779
|
+
for (const n of e.fileInfos)
|
|
780
|
+
this.#f(n);
|
|
776
781
|
return e.code && this.#m(" ?>" + e.code), this.#p(), await this.#y();
|
|
777
782
|
}
|
|
778
783
|
#n() {
|
|
@@ -784,7 +789,7 @@ class d {
|
|
|
784
789
|
this[a].ccall(
|
|
785
790
|
"wasm_set_phpini_entries",
|
|
786
791
|
null,
|
|
787
|
-
[
|
|
792
|
+
[u],
|
|
788
793
|
[e]
|
|
789
794
|
);
|
|
790
795
|
}
|
|
@@ -797,10 +802,10 @@ class d {
|
|
|
797
802
|
"SAPI Error: Could not find response headers file."
|
|
798
803
|
);
|
|
799
804
|
const t = JSON.parse(this.readFileAsText(e)), r = {};
|
|
800
|
-
for (const
|
|
801
|
-
if (!
|
|
805
|
+
for (const n of t.headers) {
|
|
806
|
+
if (!n.includes(": "))
|
|
802
807
|
continue;
|
|
803
|
-
const o =
|
|
808
|
+
const o = n.indexOf(": "), i = n.substring(0, o).toLowerCase(), l = n.substring(o + 2);
|
|
804
809
|
i in r || (r[i] = []), r[i].push(l);
|
|
805
810
|
}
|
|
806
811
|
return {
|
|
@@ -812,14 +817,14 @@ class d {
|
|
|
812
817
|
if (this[a].ccall(
|
|
813
818
|
"wasm_set_request_uri",
|
|
814
819
|
null,
|
|
815
|
-
[
|
|
820
|
+
[u],
|
|
816
821
|
[e]
|
|
817
822
|
), e.includes("?")) {
|
|
818
823
|
const t = e.substring(e.indexOf("?") + 1);
|
|
819
824
|
this[a].ccall(
|
|
820
825
|
"wasm_set_query_string",
|
|
821
826
|
null,
|
|
822
|
-
[
|
|
827
|
+
[u],
|
|
823
828
|
[t]
|
|
824
829
|
);
|
|
825
830
|
}
|
|
@@ -828,7 +833,7 @@ class d {
|
|
|
828
833
|
this[a].ccall(
|
|
829
834
|
"wasm_set_request_host",
|
|
830
835
|
null,
|
|
831
|
-
[
|
|
836
|
+
[u],
|
|
832
837
|
[e]
|
|
833
838
|
);
|
|
834
839
|
let r;
|
|
@@ -847,7 +852,7 @@ class d {
|
|
|
847
852
|
this[a].ccall(
|
|
848
853
|
"wasm_set_request_method",
|
|
849
854
|
null,
|
|
850
|
-
[
|
|
855
|
+
[u],
|
|
851
856
|
[e]
|
|
852
857
|
);
|
|
853
858
|
}
|
|
@@ -855,12 +860,12 @@ class d {
|
|
|
855
860
|
e.cookie && this[a].ccall(
|
|
856
861
|
"wasm_set_cookies",
|
|
857
862
|
null,
|
|
858
|
-
[
|
|
863
|
+
[u],
|
|
859
864
|
[e.cookie]
|
|
860
865
|
), e["content-type"] && this[a].ccall(
|
|
861
866
|
"wasm_set_content_type",
|
|
862
867
|
null,
|
|
863
|
-
[
|
|
868
|
+
[u],
|
|
864
869
|
[e["content-type"]]
|
|
865
870
|
), e["content-length"] && this[a].ccall(
|
|
866
871
|
"wasm_set_content_length",
|
|
@@ -880,7 +885,7 @@ class d {
|
|
|
880
885
|
this[a].ccall(
|
|
881
886
|
"wasm_set_request_body",
|
|
882
887
|
null,
|
|
883
|
-
[
|
|
888
|
+
[u],
|
|
884
889
|
[e]
|
|
885
890
|
), this[a].ccall(
|
|
886
891
|
"wasm_set_content_length",
|
|
@@ -893,7 +898,7 @@ class d {
|
|
|
893
898
|
this[a].ccall(
|
|
894
899
|
"wasm_set_path_translated",
|
|
895
900
|
null,
|
|
896
|
-
[
|
|
901
|
+
[u],
|
|
897
902
|
[e]
|
|
898
903
|
);
|
|
899
904
|
}
|
|
@@ -905,7 +910,7 @@ class d {
|
|
|
905
910
|
this[a].ccall(
|
|
906
911
|
"wasm_add_SERVER_entry",
|
|
907
912
|
null,
|
|
908
|
-
[
|
|
913
|
+
[u, u],
|
|
909
914
|
[e, this.#r[e]]
|
|
910
915
|
);
|
|
911
916
|
}
|
|
@@ -919,21 +924,21 @@ class d {
|
|
|
919
924
|
* @param fileInfo - File details
|
|
920
925
|
*/
|
|
921
926
|
#f(e) {
|
|
922
|
-
const { key: t, name: r, type:
|
|
927
|
+
const { key: t, name: r, type: n, data: o } = e, i = `/tmp/${Math.random().toFixed(20)}`;
|
|
923
928
|
this.writeFile(i, o);
|
|
924
929
|
const l = 0;
|
|
925
930
|
this[a].ccall(
|
|
926
931
|
"wasm_add_uploaded_file",
|
|
927
932
|
null,
|
|
928
|
-
[
|
|
929
|
-
[t, r,
|
|
933
|
+
[u, u, u, u, y, y],
|
|
934
|
+
[t, r, n, i, l, o.byteLength]
|
|
930
935
|
);
|
|
931
936
|
}
|
|
932
937
|
#m(e) {
|
|
933
938
|
this[a].ccall(
|
|
934
939
|
"wasm_set_php_code",
|
|
935
940
|
null,
|
|
936
|
-
[
|
|
941
|
+
[u],
|
|
937
942
|
[e]
|
|
938
943
|
);
|
|
939
944
|
}
|
|
@@ -941,9 +946,9 @@ class d {
|
|
|
941
946
|
let e, t;
|
|
942
947
|
try {
|
|
943
948
|
e = await new Promise((o, i) => {
|
|
944
|
-
t = (
|
|
945
|
-
const
|
|
946
|
-
|
|
949
|
+
t = (h) => {
|
|
950
|
+
const c = new Error("Rethrown");
|
|
951
|
+
c.cause = h.error, c.betterMessage = h.message, i(c);
|
|
947
952
|
}, this.#s?.addEventListener(
|
|
948
953
|
"error",
|
|
949
954
|
t
|
|
@@ -957,21 +962,21 @@ class d {
|
|
|
957
962
|
return l instanceof Promise ? l.then(o, i) : o(l);
|
|
958
963
|
});
|
|
959
964
|
} catch (o) {
|
|
960
|
-
for (const
|
|
961
|
-
typeof this[
|
|
965
|
+
for (const c in this)
|
|
966
|
+
typeof this[c] == "function" && (this[c] = () => {
|
|
962
967
|
throw new Error(
|
|
963
968
|
"PHP runtime has crashed – see the earlier error for details."
|
|
964
969
|
);
|
|
965
970
|
});
|
|
966
|
-
this.functionsMaybeMissingFromAsyncify =
|
|
967
|
-
const i = o, l = "betterMessage" in i ? i.betterMessage : i.message,
|
|
968
|
-
throw
|
|
971
|
+
this.functionsMaybeMissingFromAsyncify = L();
|
|
972
|
+
const i = o, l = "betterMessage" in i ? i.betterMessage : i.message, h = new Error(l);
|
|
973
|
+
throw h.cause = i, h;
|
|
969
974
|
} finally {
|
|
970
975
|
this.#s?.removeEventListener("error", t), this.#r = {};
|
|
971
976
|
}
|
|
972
|
-
const { headers: r, httpStatusCode:
|
|
977
|
+
const { headers: r, httpStatusCode: n } = this.#i();
|
|
973
978
|
return new g(
|
|
974
|
-
|
|
979
|
+
n,
|
|
975
980
|
r,
|
|
976
981
|
this.readFileAsBuffer("/tmp/stdout"),
|
|
977
982
|
this.readFileAsText("/tmp/stderr"),
|
|
@@ -1001,8 +1006,8 @@ class d {
|
|
|
1001
1006
|
}
|
|
1002
1007
|
rmdir(e, t = { recursive: !0 }) {
|
|
1003
1008
|
t?.recursive && this.listFiles(e).forEach((r) => {
|
|
1004
|
-
const
|
|
1005
|
-
this.isDir(
|
|
1009
|
+
const n = `${e}/${r}`;
|
|
1010
|
+
this.isDir(n) ? this.rmdir(n, t) : this.unlink(n);
|
|
1006
1011
|
}), this[a].FS.rmdir(e);
|
|
1007
1012
|
}
|
|
1008
1013
|
listFiles(e, t = { prependPath: !1 }) {
|
|
@@ -1010,11 +1015,11 @@ class d {
|
|
|
1010
1015
|
return [];
|
|
1011
1016
|
try {
|
|
1012
1017
|
const r = this[a].FS.readdir(e).filter(
|
|
1013
|
-
(
|
|
1018
|
+
(n) => n !== "." && n !== ".."
|
|
1014
1019
|
);
|
|
1015
1020
|
if (t.prependPath) {
|
|
1016
|
-
const
|
|
1017
|
-
return r.map((o) => `${
|
|
1021
|
+
const n = e.replace(/\/$/, "");
|
|
1022
|
+
return r.map((o) => `${n}/${o}`);
|
|
1018
1023
|
}
|
|
1019
1024
|
return r;
|
|
1020
1025
|
} catch (r) {
|
|
@@ -1067,33 +1072,34 @@ f([
|
|
|
1067
1072
|
f([
|
|
1068
1073
|
p('Could not stat "{path}"')
|
|
1069
1074
|
], d.prototype, "fileExists", 1);
|
|
1070
|
-
function
|
|
1075
|
+
function U(s) {
|
|
1071
1076
|
const e = {};
|
|
1072
|
-
for (const t in
|
|
1073
|
-
e[t.toLowerCase()] =
|
|
1077
|
+
for (const t in s)
|
|
1078
|
+
e[t.toLowerCase()] = s[t];
|
|
1074
1079
|
return e;
|
|
1075
1080
|
}
|
|
1076
|
-
function
|
|
1077
|
-
return !(
|
|
1081
|
+
function te(s) {
|
|
1082
|
+
return !(s instanceof d);
|
|
1078
1083
|
}
|
|
1079
|
-
function
|
|
1080
|
-
return !
|
|
1084
|
+
function oe(s) {
|
|
1085
|
+
return !te(s);
|
|
1081
1086
|
}
|
|
1082
1087
|
export {
|
|
1083
1088
|
d as BasePHP,
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1089
|
+
G as DEFAULT_BASE_URL,
|
|
1090
|
+
re as LatestSupportedPHPVersion,
|
|
1091
|
+
j as PHPBrowser,
|
|
1092
|
+
Y as PHPRequestHandler,
|
|
1088
1093
|
g as PHPResponse,
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1094
|
+
H as SupportedPHPVersions,
|
|
1095
|
+
se as SupportedPHPVersionsList,
|
|
1096
|
+
N as UnhandledRejectionsTarget,
|
|
1092
1097
|
a as __private__dont__use,
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1098
|
+
V as ensurePathPrefix,
|
|
1099
|
+
I as isExitCodeZero,
|
|
1100
|
+
te as isLocalPHP,
|
|
1101
|
+
oe as isRemotePHP,
|
|
1102
|
+
ne as loadPHPRuntime,
|
|
1097
1103
|
k as removePathPrefix,
|
|
1098
1104
|
p as rethrowFileSystemError,
|
|
1099
1105
|
T as toRelativeUrl
|
package/lib/index.d.ts
CHANGED
|
@@ -16,3 +16,4 @@ export { PHPRequestHandler } from './php-request-handler';
|
|
|
16
16
|
export type { PHPBrowserConfiguration } from './php-browser';
|
|
17
17
|
export { PHPBrowser } from './php-browser';
|
|
18
18
|
export { DEFAULT_BASE_URL, ensurePathPrefix, removePathPrefix, toRelativeUrl, } from './urls';
|
|
19
|
+
export { isExitCodeZero } from './is-exit-code-zero';
|
package/lib/universal-php.d.ts
CHANGED
|
@@ -73,7 +73,7 @@ export interface RequestHandler {
|
|
|
73
73
|
* }
|
|
74
74
|
* })
|
|
75
75
|
* php.writeFile("/www/index.php", `<?php echo file_get_contents("php://input");`);
|
|
76
|
-
* const result = await php.
|
|
76
|
+
* const result = await php.request({
|
|
77
77
|
* method: "GET",
|
|
78
78
|
* headers: {
|
|
79
79
|
* "Content-Type": "text/plain"
|
|
@@ -311,7 +311,7 @@ export interface IsomorphicLocalPHP extends RequestHandler {
|
|
|
311
311
|
* post_message_to_js(string $data)
|
|
312
312
|
*
|
|
313
313
|
* Arguments:
|
|
314
|
-
* $data –
|
|
314
|
+
* $data (string) – Data to pass to JavaScript.
|
|
315
315
|
*
|
|
316
316
|
* @example
|
|
317
317
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@php-wasm/universal",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "PHP.wasm – emscripten bindings for PHP",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -36,5 +36,9 @@
|
|
|
36
36
|
"main": "./index.cjs",
|
|
37
37
|
"module": "./index.js",
|
|
38
38
|
"license": "GPL-2.0-or-later",
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "cd4062de74f7f18058d3f962e124d0fdff78b5a7",
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": ">=16.15.1",
|
|
42
|
+
"npm": ">=8.11.0"
|
|
43
|
+
}
|
|
40
44
|
}
|