@php-wasm/cli
Advanced tools
Comparing version 0.1.51 to 0.1.56
@@ -40,3 +40,3 @@ import{existsSync as I,writeFileSync as L}from"fs";import{rootCertificates as B}from"tls";import{NodePHP as M}from"@php-wasm/node";const q="modulepreload",D=function(s){return"/"+s},S={},W=function(e,t,r){if(!t||t.length===0)return e();const o=document.getElementsByTagName("link");return Promise.all(t.map(n=>{if(n=D(n),n in S)return;S[n]=!0;const i=n.endsWith(".css"),l=i?'[rel="stylesheet"]':"";if(!!r)for(let d=o.length-1;d>=0;d--){const y=o[d];if(y.href===n&&(!i||y.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${n}"]${l}`))return;const c=document.createElement("link");if(c.rel=i?"stylesheet":q,i||(c.as="script",c.crossOrigin=""),c.href=n,document.head.appendChild(c),i)return new Promise((d,y)=>{c.addEventListener("load",d),c.addEventListener("error",()=>y(new Error(`Unable to preload CSS for ${n}`)))})})).then(()=>e())},R=Symbol("error"),x=Symbol("message");class E extends Event{constructor(e,t={}){super(e),this[R]=t.error===void 0?null:t.error,this[x]=t.message===void 0?"":t.message}get error(){return this[R]}get message(){return this[x]}}Object.defineProperty(E.prototype,"error",{enumerable:!0});Object.defineProperty(E.prototype,"message",{enumerable:!0});const j=typeof globalThis.ErrorEvent=="function"?globalThis.ErrorEvent:E;class G 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 z(s){s.asm={...s.asm};const e=new G;for(const t in s.asm)if(typeof s.asm[t]=="function"){const r=s.asm[t];s.asm[t]=function(...o){try{return r(...o)}catch(n){if(!(n instanceof Error))throw n;if("exitCode"in n&&n?.exitCode===0)return;const i=Y(n,s.lastAsyncifyStackSource?.stack);if(s.lastAsyncifyStackSource&&(n.cause=s.lastAsyncifyStackSource),!e.hasListeners())throw Q(i),n;e.dispatchEvent(new j("error",{error:n,message:i}))}}}return e}let b=[];function V(){return b}function Y(s,e){if(s.message==="unreachable"){let t=J;e||(t+=` | ||
`;this[a].ccall("wasm_set_phpini_entries",null,[h],[e])}this[a].ccall("php_wasm_init",null,[],[])}#n(){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 o of t.headers){if(!o.includes(": "))continue;const n=o.indexOf(": "),i=o.substring(0,n).toLowerCase(),l=o.substring(n+2);i in r||(r[i]=[]),r[i].push(l)}return{headers:r,httpStatusCode:t.status}}#i(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])}}#a(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")}#l(e){this[a].ccall("wasm_set_request_method",null,[h],[e])}#c(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)this.addServerGlobalEntry(`HTTP_${t.toUpperCase().replace(/-/g,"_")}`,e[t])}#h(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])}#u(e){this[a].ccall("wasm_set_path_translated",null,[h],[e])}addServerGlobalEntry(e,t){this.#r[e]=t}#d(){for(const e in this.#r)this[a].ccall("wasm_add_SERVER_entry",null,[h,h],[e,this.#r[e]])}#p(e){const{key:t,name:r,type:o,data:n}=e,i=`/tmp/${Math.random().toFixed(20)}`;this.writeFile(i,n);const l=0;this[a].ccall("wasm_add_uploaded_file",null,[h,h,h,h,g,g],[t,r,o,i,l,n.byteLength])}#f(e){this[a].ccall("wasm_set_php_code",null,[h],[e])}async#m(){let e,t;try{e=await new Promise((n,i)=>{t=u=>{const c=new Error("Rethrown");c.cause=u.error,c.betterMessage=u.message,i(c)},this.#s?.addEventListener("error",t);const l=this[a].ccall("wasm_sapi_handle_request",g,[],[]);return l instanceof Promise?l.then(n,i):n(l)})}catch(n){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=V();const i=n,l="betterMessage"in i?i.betterMessage:i.message,u=new Error(l);throw u.cause=i,u}finally{this.#s?.removeEventListener("error",t),this.#r={}}const{headers:r,httpStatusCode:o}=this.#n();return new w(o,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.mv(e,t)}rmdir(e,t={recursive:!0}){t?.recursive&&this.listFiles(e).forEach(r=>{const o=`${e}/${r}`;this.isDir(o)?this.rmdir(o,t):this.unlink(o)}),this[a].FS.rmdir(e)}listFiles(e){if(!this.fileExists(e))return[];try{return this[a].FS.readdir(e).filter(t=>t!=="."&&t!=="..")}catch(t){return console.error(t,{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}"')],m.prototype,"mkdir",1);f([p('Could not create directory "{path}"')],m.prototype,"mkdirTree",1);f([p('Could not read "{path}"')],m.prototype,"readFileAsText",1);f([p('Could not read "{path}"')],m.prototype,"readFileAsBuffer",1);f([p('Could not write to "{path}"')],m.prototype,"writeFile",1);f([p('Could not unlink "{path}"')],m.prototype,"unlink",1);f([p('Could not move "{path}"')],m.prototype,"mv",1);f([p('Could not remove directory "{path}"')],m.prototype,"rmdir",1);f([p('Could not list files in "{path}"')],m.prototype,"listFiles",1);f([p('Could not stat "{path}"')],m.prototype,"isDir",1);f([p('Could not stat "{path}"')],m.prototype,"fileExists",1);function N(s){const e={};for(const t in s)e[t.toLowerCase()]=s[t];return e}let P=process.argv.slice(2);P.length||(P=["--help"]);const v=new URL("ca-bundle.crt",(import.meta||{}).url).pathname;I(v)||L(v,B.join(` | ||
`;this[a].ccall("wasm_set_phpini_entries",null,[h],[e])}this[a].ccall("php_wasm_init",null,[],[])}#n(){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 o of t.headers){if(!o.includes(": "))continue;const n=o.indexOf(": "),i=o.substring(0,n).toLowerCase(),l=o.substring(n+2);i in r||(r[i]=[]),r[i].push(l)}return{headers:r,httpStatusCode:t.status}}#i(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])}}#a(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")}#l(e){this[a].ccall("wasm_set_request_method",null,[h],[e])}#c(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)this.addServerGlobalEntry(`HTTP_${t.toUpperCase().replace(/-/g,"_")}`,e[t])}#h(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])}#u(e){this[a].ccall("wasm_set_path_translated",null,[h],[e])}addServerGlobalEntry(e,t){this.#r[e]=t}#d(){for(const e in this.#r)this[a].ccall("wasm_add_SERVER_entry",null,[h,h],[e,this.#r[e]])}#p(e){const{key:t,name:r,type:o,data:n}=e,i=`/tmp/${Math.random().toFixed(20)}`;this.writeFile(i,n);const l=0;this[a].ccall("wasm_add_uploaded_file",null,[h,h,h,h,g,g],[t,r,o,i,l,n.byteLength])}#f(e){this[a].ccall("wasm_set_php_code",null,[h],[e])}async#m(){let e,t;try{e=await new Promise((n,i)=>{t=u=>{const c=new Error("Rethrown");c.cause=u.error,c.betterMessage=u.message,i(c)},this.#s?.addEventListener("error",t);const l=this[a].ccall("wasm_sapi_handle_request",g,[],[]);return l instanceof Promise?l.then(n,i):n(l)})}catch(n){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=V();const i=n,l="betterMessage"in i?i.betterMessage:i.message,u=new Error(l);throw u.cause=i,u}finally{this.#s?.removeEventListener("error",t),this.#r={}}const{headers:r,httpStatusCode:o}=this.#n();return new w(o,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 o=`${e}/${r}`;this.isDir(o)?this.rmdir(o,t):this.unlink(o)}),this[a].FS.rmdir(e)}listFiles(e){if(!this.fileExists(e))return[];try{return this[a].FS.readdir(e).filter(t=>t!=="."&&t!=="..")}catch(t){return console.error(t,{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}"')],m.prototype,"mkdir",1);f([p('Could not create directory "{path}"')],m.prototype,"mkdirTree",1);f([p('Could not read "{path}"')],m.prototype,"readFileAsText",1);f([p('Could not read "{path}"')],m.prototype,"readFileAsBuffer",1);f([p('Could not write to "{path}"')],m.prototype,"writeFile",1);f([p('Could not unlink "{path}"')],m.prototype,"unlink",1);f([p('Could not move "{path}"')],m.prototype,"mv",1);f([p('Could not remove directory "{path}"')],m.prototype,"rmdir",1);f([p('Could not list files in "{path}"')],m.prototype,"listFiles",1);f([p('Could not stat "{path}"')],m.prototype,"isDir",1);f([p('Could not stat "{path}"')],m.prototype,"fileExists",1);function N(s){const e={};for(const t in s)e[t.toLowerCase()]=s[t];return e}let P=process.argv.slice(2);P.length||(P=["--help"]);const v=new URL("ca-bundle.crt",(import.meta||{}).url).pathname;I(v)||L(v,B.join(` | ||
`));P.unshift("-d",`openssl.cafile=${v}`);const de=await W(()=>import("./assets/php-e1f9edd4.js"),[]),_=process.env.PHP||Z;if(!ee.includes(_))throw new Error(`Unsupported PHP version ${_}`);const $=await M.load(_,{emscriptenOptions:{ENV:{...process.env,TERM:"xterm"}}});$.useHostFilesystem();const pe=P.some(s=>s.startsWith("-c"));pe||P.unshift("-c",de);$.cli(["php",...P]).catch(s=>{throw s.name==="ExitStatus"&&process.exit(s.status===void 0?1:s.status),s}); |
{ | ||
"name": "@php-wasm/cli", | ||
"version": "0.1.51", | ||
"version": "0.1.56", | ||
"description": "PHP.wasm CLI for node.js", | ||
@@ -26,9 +26,9 @@ "repository": { | ||
"bin": "cli.js", | ||
"gitHead": "756f9e316b51bc1496982fa4ed9310a16701afa5", | ||
"gitHead": "af3583eb7c6644a9859ea4782702c6e2c3474821", | ||
"dependencies": { | ||
"comlink": "^4.4.1", | ||
"ws": "8.13.0", | ||
"@php-wasm/universal": "0.1.51", | ||
"@php-wasm/node": "0.1.51" | ||
"@php-wasm/universal": "0.1.56", | ||
"@php-wasm/node": "0.1.56" | ||
} | ||
} |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
20078
1
+ Added@php-wasm/node@0.1.56(transitive)
+ Added@php-wasm/universal@0.1.56(transitive)
+ Added@php-wasm/util@0.1.56(transitive)
- Removed@php-wasm/node@0.1.51(transitive)
- Removed@php-wasm/universal@0.1.51(transitive)
- Removed@php-wasm/util@0.1.51(transitive)
Updated@php-wasm/node@0.1.56
Updated@php-wasm/universal@0.1.56