@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 CHANGED
@@ -1,10 +1,10 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=Symbol("error"),S=Symbol("message");class v extends Event{constructor(e,t={}){super(e),this[E]=t.error===void 0?null:t.error,this[S]=t.message===void 0?"":t.message}get error(){return this[E]}get message(){return this[S]}}Object.defineProperty(v.prototype,"error",{enumerable:!0});Object.defineProperty(v.prototype,"message",{enumerable:!0});const M=typeof globalThis.ErrorEvent=="function"?globalThis.ErrorEvent:v;class C 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 B(n){n.asm={...n.asm};const e=new C;for(const t in n.asm)if(typeof n.asm[t]=="function"){const r=n.asm[t];n.asm[t]=function(...s){try{return r(...s)}catch(o){if(!(o instanceof Error))throw o;if("exitCode"in o&&o?.exitCode===0)return;const i=q(o,n.lastAsyncifyStackSource?.stack);if(n.lastAsyncifyStackSource&&(o.cause=n.lastAsyncifyStackSource),!e.hasListeners())throw z(i),o;e.dispatchEvent(new M("error",{error:o,message:i}))}}}return e}let w=[];function D(){return w}function q(n,e){if(n.message==="unreachable"){let t=W;e||(t+=`
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=G(e||n.stack||"");for(const r of w)t+=` * ${r}
7
- `;return t}return n.message}const W=`
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",j="\x1B[1m",H="\x1B[0m",T="\x1B[K";let k=!1;function z(n){if(!k){k=!0,console.log(`${x}
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
- ${j} WASM ERROR${H}${x}`);for(const e of n.split(`
34
- `))console.log(`${T} ${e} `);console.log(`${H}`)}}function G(n){try{const e=n.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,s="",o=0){this.httpStatusCode=e,this.headers=t,this.bytes=r,this.exitCode=o,this.errors=s}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 R=["8.2","8.1","8.0","7.4","7.3","7.2","7.1","7.0","5.6"],V=R[0],Y=R;class U{#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 s=new URL(r.headers.location[0],this.requestHandler.absoluteUrl);return this.request({url:s.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("="),s=t.substring(0,r),o=t.substring(r+1).split(";")[0];this.#e[s]=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 J{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 A="http://example.com";function P(n){return n.toString().substring(n.origin.length)}function b(n,e){return!e||!n.startsWith(e)?n:n.substring(e.length)}function O(n,e){return!e||n.startsWith(e)?n:e+n}class I{#e;#t;#s;#r;#o;#n;#i;#a;#l;constructor(e,t={}){this.#a=new J({concurrency:1});const{documentRoot:r="/www/",absoluteUrl:s=typeof location=="object"?location?.href:"",isStaticFilePath:o=()=>!1}=t;this.php=e,this.#e=r,this.#l=o;const i=new URL(s);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:A),s=b(r.pathname,this.#n);return this.#l(s)?this.#c(s):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":[Q(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 s="GET";const o={host:this.#o,...L(e.headers||{})},i=[];if(e.files&&Object.keys(e.files).length){s="POST";for(const u in e.files){const m=e.files[u];i.push({key:u,name:m.name,type:m.type,data:new Uint8Array(await m.arrayBuffer())})}o["content-type"]?.startsWith("multipart/form-data")&&(e.formData=K(e.body||""),o["content-type"]="application/x-www-form-urlencoded",delete e.body)}let l;e.formData!==void 0?(s="POST",o["content-type"]=o["content-type"]||"application/x-www-form-urlencoded",l=new URLSearchParams(e.formData).toString()):l=e.body;let c;try{c=this.#u(t.pathname)}catch{return new y(404,{},new TextEncoder().encode("404 File not found"))}return await this.php.run({relativeUri:O(P(t),this.#n),protocol:this.#t,method:e.method||s,body:l,fileInfos:i,scriptPath:c,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 K(n){const e={},t=n.match(/--(.*)\r\n/);if(!t)return e;const r=t[1],s=n.split(`--${r}`);return s.shift(),s.pop(),s.forEach(o=>{const i=o.indexOf(`\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(),c=o.substring(i+4).trim(),u=l.match(/name="([^"]+)"/);if(u){const m=u[1];e[m]=c}}),e}function Q(n){switch(n.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(n=""){return function(t,r,s){const o=s.value;s.value=function(...i){try{return o.apply(this,i)}catch(l){const c=typeof l=="object"?l?.errno:null;if(c in F){const u=F[c],m=typeof i[0]=="string"?i[0]:null,$=m!==null?n.replaceAll("{path}",m):n;throw new Error(`${$}: ${u}`,{cause:l})}throw l}}}}async function X(n,e={},t=[]){let r,s;const o=new Promise(c=>{s=c}),i=new Promise(c=>{r=c}),l=n.init(ee,{onAbort(c){console.error("WASM aborted: "),console.error(c)},ENV:{},locateFile:c=>c,...e,noInitialRun:!0,onRuntimeInitialized(){e.onRuntimeInitialized&&e.onRuntimeInitialized(),r()},monitorRunDependencies(c){c===0&&(delete l.monitorRunDependencies,s())}});for(const{default:c}of t)c(l);return t.length||s(),await o,await i,_.push(l),_.length-1}const _=[];function Z(n){return _[n]}const ee=function(){return typeof process<"u"&&process.release?.name==="node"?"NODE":typeof window<"u"?"WEB":typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope?"WORKER":"NODE"}();var te=Object.defineProperty,re=Object.getOwnPropertyDescriptor,f=(n,e,t,r)=>{for(var s=r>1?void 0:r?re(e,t):e,o=n.length-1,i;o>=0;o--)(i=n[o])&&(s=(r?i(e,t,s):i(s))||s);return r&&s&&te(e,t,s),s};const h="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 U(new I(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=Z(e);if(!t)throw new Error("Invalid PHP runtime id.");this[a]=t,t.onMessage=r=>{for(const s of this.#o)s(r)},this.#s=B(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",...L(e.headers||{})};if(this.#l(t,e.protocol||"http"),this.#h(r),e.body&&this.#u(e.body),e.fileInfos)for(const s of e.fileInfos)this.#f(s);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(`
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,[h],[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 s of t.headers){if(!s.includes(": "))continue;const o=s.indexOf(": "),i=s.substring(0,o).toLowerCase(),l=s.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,[h],[e]),e.includes("?")){const t=e.substring(e.indexOf("?")+1);this[a].ccall("wasm_set_query_string",null,[h],[t])}}#l(e,t){this[a].ccall("wasm_set_request_host",null,[h],[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,[h],[e])}#h(e){e.cookie&&this[a].ccall("wasm_set_cookies",null,[h],[e.cookie]),e["content-type"]&&this[a].ccall("wasm_set_content_type",null,[h],[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,[h],[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,[h],[e])}addServerGlobalEntry(e,t){this.#r[e]=t}#p(){for(const e in this.#r)this[a].ccall("wasm_add_SERVER_entry",null,[h,h],[e,this.#r[e]])}#f(e){const{key:t,name:r,type:s,data:o}=e,i=`/tmp/${Math.random().toFixed(20)}`;this.writeFile(i,o);const l=0;this[a].ccall("wasm_add_uploaded_file",null,[h,h,h,h,g,g],[t,r,s,i,l,o.byteLength])}#m(e){this[a].ccall("wasm_set_php_code",null,[h],[e])}async#y(){let e,t;try{e=await new Promise((o,i)=>{t=c=>{const u=new Error("Rethrown");u.cause=c.error,u.betterMessage=c.message,i(u)},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 u in this)typeof this[u]=="function"&&(this[u]=()=>{throw new Error("PHP runtime has crashed – see the earlier error for details.")});this.functionsMaybeMissingFromAsyncify=D();const i=o,l="betterMessage"in i?i.betterMessage:i.message,c=new Error(l);throw c.cause=i,c}finally{this.#s?.removeEventListener("error",t),this.#r={}}const{headers:r,httpStatusCode:s}=this.#i();return new y(s,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 s=`${e}/${r}`;this.isDir(s)?this.rmdir(s,t):this.unlink(s)}),this[a].FS.rmdir(e)}listFiles(e,t={prependPath:!1}){if(!this.fileExists(e))return[];try{const r=this[a].FS.readdir(e).filter(s=>s!=="."&&s!=="..");if(t.prependPath){const s=e.replace(/\/$/,"");return r.map(o=>`${s}/${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 L(n){const e={};for(const t in n)e[t.toLowerCase()]=n[t];return e}function N(n){return!(n instanceof d)}function se(n){return!N(n)}exports.BasePHP=d;exports.DEFAULT_BASE_URL=A;exports.LatestSupportedPHPVersion=V;exports.PHPBrowser=U;exports.PHPRequestHandler=I;exports.PHPResponse=y;exports.SupportedPHPVersions=R;exports.SupportedPHPVersionsList=Y;exports.UnhandledRejectionsTarget=C;exports.__private__dont__use=a;exports.ensurePathPrefix=O;exports.isLocalPHP=N;exports.isRemotePHP=se;exports.loadPHPRuntime=X;exports.removePathPrefix=b;exports.rethrowFileSystemError=p;exports.toRelativeUrl=P;
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
- class O extends EventTarget {
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 I(n) {
38
- n.asm = {
39
- ...n.asm
40
+ function $(s) {
41
+ s.asm = {
42
+ ...s.asm
40
43
  };
41
- const e = new O();
42
- for (const t in n.asm)
43
- if (typeof n.asm[t] == "function") {
44
- const r = n.asm[t];
45
- n.asm[t] = function(...s) {
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(...s);
50
+ return r(...n);
48
51
  } catch (o) {
49
52
  if (!(o instanceof Error))
50
53
  throw o;
51
- if ("exitCode" in o && o?.exitCode === 0)
52
- return;
53
- const i = $(
54
+ const i = M(
54
55
  o,
55
- n.lastAsyncifyStackSource?.stack
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 N() {
74
+ function L() {
72
75
  return w;
73
76
  }
74
- function $(n, e) {
75
- if (n.message === "unreachable") {
76
- let t = L;
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 = B(
83
- e || n.stack || ""
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 n.message;
93
+ return s.message;
91
94
  }
92
- const L = `
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
- `, R = "\x1B[41m", M = "\x1B[1m", E = "\x1B[0m", S = "\x1B[K";
119
+ `, E = "\x1B[41m", D = "\x1B[1m", R = "\x1B[0m", S = "\x1B[K";
117
120
  let x = !1;
118
- function D(n) {
121
+ function q(s) {
119
122
  if (!x) {
120
- x = !0, console.log(`${R}
123
+ x = !0, console.log(`${E}
121
124
  ${S}
122
- ${M} WASM ERROR${E}${R}`);
123
- for (const e of n.split(`
125
+ ${D} WASM ERROR${R}${E}`);
126
+ for (const e of s.split(`
124
127
  `))
125
128
  console.log(`${S} ${e} `);
126
- console.log(`${E}`);
129
+ console.log(`${R}`);
127
130
  }
128
131
  }
129
- function B(n) {
132
+ function W(s) {
130
133
  try {
131
- const e = n.split(`
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, s = "", o = 0) {
148
- this.httpStatusCode = e, this.headers = t, this.bytes = r, this.exitCode = o, this.errors = s;
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 C = [
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
- ], ee = C[0], te = C;
192
- class q {
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 s = new URL(
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: s.toString(),
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("="), s = t.substring(0, r), o = t.substring(r + 1).split(";")[0];
266
- this.#e[s] = o;
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 W {
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 j = "http://example.com";
307
- function T(n) {
308
- return n.toString().substring(n.origin.length);
309
+ const G = "http://example.com";
310
+ function T(s) {
311
+ return s.toString().substring(s.origin.length);
309
312
  }
310
- function k(n, e) {
311
- return !e || !n.startsWith(e) ? n : n.substring(e.length);
313
+ function k(s, e) {
314
+ return !e || !s.startsWith(e) ? s : s.substring(e.length);
312
315
  }
313
- function z(n, e) {
314
- return !e || n.startsWith(e) ? n : e + n;
316
+ function V(s, e) {
317
+ return !e || s.startsWith(e) ? s : e + s;
315
318
  }
316
- class G {
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 W({ concurrency: 1 });
334
+ this.#a = new z({ concurrency: 1 });
332
335
  const {
333
336
  documentRoot: r = "/www/",
334
- absoluteUrl: s = typeof location == "object" ? location?.href : "",
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(s);
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 : j
375
- ), s = k(
377
+ t ? void 0 : G
378
+ ), n = k(
376
379
  r.pathname,
377
380
  this.#n
378
381
  );
379
- return this.#l(s) ? this.#c(s) : await this.#h(e, r);
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": [Y(t)],
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 s = "GET";
427
+ let n = "GET";
425
428
  const o = {
426
429
  host: this.#o,
427
- ...H(e.headers || {})
430
+ ...U(e.headers || {})
428
431
  }, i = [];
429
432
  if (e.files && Object.keys(e.files).length) {
430
- s = "POST";
431
- for (const u in e.files) {
432
- const m = e.files[u];
433
+ n = "POST";
434
+ for (const c in e.files) {
435
+ const m = e.files[c];
433
436
  i.push({
434
- key: u,
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 = V(
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 ? (s = "POST", o["content-type"] = o["content-type"] || "application/x-www-form-urlencoded", l = new URLSearchParams(
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 c;
451
+ let h;
449
452
  try {
450
- c = this.#u(t.pathname);
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: z(
462
+ relativeUri: V(
460
463
  T(t),
461
464
  this.#n
462
465
  ),
463
466
  protocol: this.#t,
464
- method: e.method || s,
467
+ method: e.method || n,
465
468
  body: l,
466
469
  fileInfos: i,
467
- scriptPath: c,
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 V(n) {
495
- const e = {}, t = n.match(/--(.*)\r\n/);
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], s = n.split(`--${r}`);
499
- return s.shift(), s.pop(), s.forEach((o) => {
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(), c = o.substring(i + 4).trim(), u = l.match(/name="([^"]+)"/);
503
- if (u) {
504
- const m = u[1];
505
- e[m] = c;
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 Y(n) {
510
- switch (n.split(".").pop()) {
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 F = {
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(n = "") {
629
- return function(t, r, s) {
630
- const o = s.value;
631
- s.value = function(...i) {
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 c = typeof l == "object" ? l?.errno : null;
636
- if (c in F) {
637
- const u = F[c], m = typeof i[0] == "string" ? i[0] : null, U = m !== null ? n.replaceAll("{path}", m) : n;
638
- throw new Error(`${U}: ${u}`, {
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 re(n, e = {}, t = []) {
648
- let r, s;
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
- console.error("WASM aborted: "), console.error(c);
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(), r();
663
+ e.onRuntimeInitialized && e.onRuntimeInitialized(), n();
666
664
  },
667
665
  monitorRunDependencies(c) {
668
- c === 0 && (delete l.monitorRunDependencies, s());
666
+ c === 0 && (delete h.monitorRunDependencies, l());
669
667
  }
670
668
  });
671
- for (const { default: c } of t)
672
- c(l);
673
- return t.length || s(), await o, await i, P.push(l), P.length - 1;
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 J(n) {
677
- return P[n];
676
+ function Z(s) {
677
+ return P[s];
678
678
  }
679
- const K = function() {
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
- var Q = Object.defineProperty, X = Object.getOwnPropertyDescriptor, f = (n, e, t, r) => {
683
- for (var s = r > 1 ? void 0 : r ? X(e, t) : e, o = n.length - 1, i; o >= 0; o--)
684
- (i = n[o]) && (s = (r ? i(e, t, s) : i(s)) || s);
685
- return r && s && Q(e, t, s), s;
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 h = "string", y = "number", a = Symbol("__private__dont__use");
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 q(
698
- new G(this, t)
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 = J(e);
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 s of this.#o)
736
- s(r);
737
- }, this.#s = I(t);
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
- ...H(e.headers || {})
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 s of e.fileInfos)
775
- this.#f(s);
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
- [h],
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 s of t.headers) {
801
- if (!s.includes(": "))
805
+ for (const n of t.headers) {
806
+ if (!n.includes(": "))
802
807
  continue;
803
- const o = s.indexOf(": "), i = s.substring(0, o).toLowerCase(), l = s.substring(o + 2);
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
- [h],
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
- [h],
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
- [h],
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
- [h],
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
- [h],
863
+ [u],
859
864
  [e.cookie]
860
865
  ), e["content-type"] && this[a].ccall(
861
866
  "wasm_set_content_type",
862
867
  null,
863
- [h],
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
- [h],
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
- [h],
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
- [h, h],
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: s, data: o } = e, i = `/tmp/${Math.random().toFixed(20)}`;
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
- [h, h, h, h, y, y],
929
- [t, r, s, i, l, o.byteLength]
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
- [h],
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 = (c) => {
945
- const u = new Error("Rethrown");
946
- u.cause = c.error, u.betterMessage = c.message, i(u);
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 u in this)
961
- typeof this[u] == "function" && (this[u] = () => {
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 = N();
967
- const i = o, l = "betterMessage" in i ? i.betterMessage : i.message, c = new Error(l);
968
- throw c.cause = i, c;
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: s } = this.#i();
977
+ const { headers: r, httpStatusCode: n } = this.#i();
973
978
  return new g(
974
- s,
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 s = `${e}/${r}`;
1005
- this.isDir(s) ? this.rmdir(s, t) : this.unlink(s);
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
- (s) => s !== "." && s !== ".."
1018
+ (n) => n !== "." && n !== ".."
1014
1019
  );
1015
1020
  if (t.prependPath) {
1016
- const s = e.replace(/\/$/, "");
1017
- return r.map((o) => `${s}/${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 H(n) {
1075
+ function U(s) {
1071
1076
  const e = {};
1072
- for (const t in n)
1073
- e[t.toLowerCase()] = n[t];
1077
+ for (const t in s)
1078
+ e[t.toLowerCase()] = s[t];
1074
1079
  return e;
1075
1080
  }
1076
- function Z(n) {
1077
- return !(n instanceof d);
1081
+ function te(s) {
1082
+ return !(s instanceof d);
1078
1083
  }
1079
- function se(n) {
1080
- return !Z(n);
1084
+ function oe(s) {
1085
+ return !te(s);
1081
1086
  }
1082
1087
  export {
1083
1088
  d as BasePHP,
1084
- j as DEFAULT_BASE_URL,
1085
- ee as LatestSupportedPHPVersion,
1086
- q as PHPBrowser,
1087
- G as PHPRequestHandler,
1089
+ G as DEFAULT_BASE_URL,
1090
+ re as LatestSupportedPHPVersion,
1091
+ j as PHPBrowser,
1092
+ Y as PHPRequestHandler,
1088
1093
  g as PHPResponse,
1089
- C as SupportedPHPVersions,
1090
- te as SupportedPHPVersionsList,
1091
- O as UnhandledRejectionsTarget,
1094
+ H as SupportedPHPVersions,
1095
+ se as SupportedPHPVersionsList,
1096
+ N as UnhandledRejectionsTarget,
1092
1097
  a as __private__dont__use,
1093
- z as ensurePathPrefix,
1094
- Z as isLocalPHP,
1095
- se as isRemotePHP,
1096
- re as loadPHPRuntime,
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';
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Check if the Emscripten-thrown error is an exit code 0 error.
3
+ *
4
+ * @param e The error to check
5
+ * @returns True if the error is an exit code 0 error
6
+ */
7
+ export declare function isExitCodeZero(e: any): boolean;
@@ -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.run({
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 – any extra information as a string
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.1.61",
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": "f2cd7382004f7b003904b5db1d33d37fd2b1bfab"
39
+ "gitHead": "cd4062de74f7f18058d3f962e124d0fdff78b5a7",
40
+ "engines": {
41
+ "node": ">=16.15.1",
42
+ "npm": ">=8.11.0"
43
+ }
40
44
  }