@php-wasm/cli 1.1.2 → 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/main.js +4 -4
- package/main.js.map +1 -1
- package/package.json +6 -5
package/main.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import{existsSync as
|
|
2
|
-
`));e.unshift("-d",`openssl.cafile=${
|
|
3
|
-
|
|
4
|
-
`);
|
|
1
|
+
import{existsSync as w,writeFileSync as d,mkdtempSync as a,chmodSync as P}from"fs";import{rootCertificates as v}from"tls";import{SupportedPHPVersionsList as y,LatestSupportedPHPVersion as S,PHP as T}from"@php-wasm/universal";import{loadNodeRuntime as $,useHostFilesystem as H}from"@php-wasm/node";import c from"path";const m={};var h={};let e=process.argv.slice(2);e.length||(e=["--help"]);const u=(import.meta||{}).url,r=new URL("ca-bundle.crt",u).pathname;w(r)||d(r,v.join(`
|
|
2
|
+
`));e.unshift("-d",`openssl.cafile=${r}`);async function b(){const f=new URL("php.ini",u).pathname,s=h.PHP||S;if(!y.includes(s))throw new Error(`Unsupported PHP version ${s}`);const{TMPDIR:x,...n}=h,i=a(c.join(m.tmpdir(),"php-wasm-bin"));d(`${i}/php`,`#!/bin/sh
|
|
3
|
+
${process.argv[0]} ${process.execArgv.join(" ")} ${process.argv[1]}
|
|
4
|
+
`),P(`${i}/php`,493);const l=a(c.join(m.tmpdir(),"php-wasm-sys-tmp")),p=new T(await $(s,{emscriptenOptions:{ENV:{...n,TMPDIR:l,TERM:"xterm",PATH:`${i}:${n.PATH}`}}}));H(p),e.some(t=>t.startsWith("-c"))||e.unshift("-c",f);const o=await p.cli(["php",...e]);o.stderr.pipeTo(new WritableStream({write(t){process.stderr.write(t)}})),o.stdout.pipeTo(new WritableStream({write(t){process.stdout.write(t)}})),o.exitCode.catch(t=>{throw t.name==="ExitStatus"&&process.exit(t.status===void 0?1:t.status),t}).finally(()=>{setTimeout(()=>{process.exit(0)},100)})}b();
|
|
5
5
|
//# sourceMappingURL=main.js.map
|
package/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.js","sources":["../../../../packages/php-wasm/cli/src/main.ts"],"sourcesContent":["/**\n * A CLI script that runs PHP CLI via the WebAssembly build.\n */\nimport { writeFileSync, existsSync, mkdtempSync,
|
|
1
|
+
{"version":3,"file":"main.js","sources":["../../../../__vite-browser-external","../../../../packages/php-wasm/cli/src/main.ts"],"sourcesContent":["export default {}","/**\n * A CLI script that runs PHP CLI via the WebAssembly build.\n */\nimport os from 'os';\nimport { writeFileSync, existsSync, mkdtempSync, chmodSync } from 'fs';\nimport { rootCertificates } from 'tls';\n\nimport {\n\tLatestSupportedPHPVersion,\n\tSupportedPHPVersionsList,\n} from '@php-wasm/universal';\nimport type { SupportedPHPVersion } from '@php-wasm/universal';\n\nimport { PHP } from '@php-wasm/universal';\nimport { loadNodeRuntime, useHostFilesystem } from '@php-wasm/node';\nimport path from 'path';\n\nlet args = process.argv.slice(2);\nif (!args.length) {\n\targs = ['--help'];\n}\n\nconst baseUrl = (import.meta || {}).url;\n\n// Write the ca-bundle.crt file to disk so that PHP can find it.\nconst caBundlePath = new URL('ca-bundle.crt', baseUrl).pathname;\nif (!existsSync(caBundlePath)) {\n\twriteFileSync(caBundlePath, rootCertificates.join('\\n'));\n}\nargs.unshift('-d', `openssl.cafile=${caBundlePath}`);\n\nasync function run() {\n\tconst defaultPhpIniPath = new URL('php.ini', baseUrl).pathname;\n\tconst phpVersion = (process.env['PHP'] ||\n\t\tLatestSupportedPHPVersion) as SupportedPHPVersion;\n\tif (!SupportedPHPVersionsList.includes(phpVersion)) {\n\t\tthrow new Error(`Unsupported PHP version ${phpVersion}`);\n\t}\n\n\t// npm scripts set the TMPDIR env variable\n\t// PHP accepts a TMPDIR env variable and expects it to\n\t// be a writable directory within the PHP filesystem.\n\t// These two clash and prevent PHP from creating temporary\n\t// files and directories so let's just not pass the npm TMPDIR\n\t// to PHP.\n\t// @see https://github.com/npm/npm/issues/4531\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tconst { TMPDIR, ...envVariables } = process.env;\n\n\t/**\n\t * Ensure the PHP_BINARY constant is set to the PHP-WASM binary.\n\t *\n\t * ## Rationale\n\t *\n\t * We want any `proc_open()` calls to use the PHP-WASM binary and\n\t * not the system PHP binary.\n\t *\n\t * ## How it works\n\t *\n\t * The code below creates a temporary `php` executable in PATH,\n\t * which covers `proc_open( \"php\", ... )` calls.\n\t *\n\t * Furthermore, when PHP detects the `php` executable in PATH, it\n\t * sets the PHP_BINARY constant to it.\n\t */\n\tconst tempDir = mkdtempSync(path.join(os.tmpdir(), 'php-wasm-bin'));\n\twriteFileSync(\n\t\t`${tempDir}/php`,\n\t\t`#!/bin/sh\n${process.argv[0]} ${process.execArgv.join(' ')} ${process.argv[1]}\n\t`\n\t);\n\tchmodSync(`${tempDir}/php`, 0o755);\n\n\tconst sysTempDir = mkdtempSync(path.join(os.tmpdir(), 'php-wasm-sys-tmp'));\n\tconst php = new PHP(\n\t\tawait loadNodeRuntime(phpVersion, {\n\t\t\temscriptenOptions: {\n\t\t\t\tENV: {\n\t\t\t\t\t...envVariables,\n\t\t\t\t\tTMPDIR: sysTempDir,\n\t\t\t\t\tTERM: 'xterm',\n\t\t\t\t\tPATH: `${tempDir}:${envVariables['PATH']}`,\n\t\t\t\t},\n\t\t\t},\n\t\t})\n\t);\n\n\tuseHostFilesystem(php);\n\n\tconst hasMinusCOption = args.some((arg) => arg.startsWith('-c'));\n\tif (!hasMinusCOption) {\n\t\targs.unshift('-c', defaultPhpIniPath);\n\t}\n\n\tconst response = await php.cli(['php', ...args]);\n\tresponse.stderr.pipeTo(\n\t\tnew WritableStream({\n\t\t\twrite(chunk) {\n\t\t\t\tprocess.stderr.write(chunk);\n\t\t\t},\n\t\t})\n\t);\n\tresponse.stdout.pipeTo(\n\t\tnew WritableStream({\n\t\t\twrite(chunk) {\n\t\t\t\tprocess.stdout.write(chunk);\n\t\t\t},\n\t\t})\n\t);\n\n\tresponse.exitCode\n\t\t.catch((result) => {\n\t\t\tif (result.name === 'ExitStatus') {\n\t\t\t\tprocess.exit(result.status === undefined ? 1 : result.status);\n\t\t\t}\n\t\t\tthrow result;\n\t\t})\n\t\t.finally(() => {\n\t\t\tsetTimeout(() => {\n\t\t\t\tprocess.exit(0);\n\t\t\t\t// 100 is an arbitrary number. It's there to give any child processes\n\t\t\t\t// a chance to pass their output to JS before the main process exits.\n\t\t\t}, 100);\n\t\t});\n}\n\nrun();\n"],"names":["os","args","baseUrl","caBundlePath","existsSync","writeFileSync","rootCertificates","run","defaultPhpIniPath","phpVersion","define_process_env_default","LatestSupportedPHPVersion","SupportedPHPVersionsList","TMPDIR","envVariables","tempDir","mkdtempSync","path","chmodSync","sysTempDir","php","PHP","loadNodeRuntime","useHostFilesystem","arg","response","chunk","result"],"mappings":"6TAAA,MAAeA,EAAA,CAAA,WCiBf,IAAIC,EAAO,QAAQ,KAAK,MAAM,CAAC,EAC1BA,EAAK,SACTA,EAAO,CAAC,QAAQ,GAGjB,MAAMC,GAAW,aAAe,CAAI,GAAA,IAG9BC,EAAe,IAAI,IAAI,gBAAiBD,CAAO,EAAE,SAClDE,EAAWD,CAAY,GAC3BE,EAAcF,EAAcG,EAAiB,KAAK;AAAA,CAAI,CAAC,EAExDL,EAAK,QAAQ,KAAM,kBAAkBE,CAAY,EAAE,EAEnD,eAAeI,GAAM,CACpB,MAAMC,EAAoB,IAAI,IAAI,UAAWN,CAAO,EAAE,SAChDO,EAAcC,EAAY,KAC/BC,EACD,GAAI,CAACC,EAAyB,SAASH,CAAU,EAChD,MAAM,IAAI,MAAM,2BAA2BA,CAAU,EAAE,EAWxD,KAAM,CAAE,OAAAI,EAAQ,GAAGC,CAAA,EAAiBJ,EAkB9BK,EAAUC,EAAYC,EAAK,KAAKjB,EAAG,OAAO,EAAG,cAAc,CAAC,EAClEK,EACC,GAAGU,CAAO,OACV;AAAA,EACA,QAAQ,KAAK,C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
"type": "git",
|
|
@@ -23,16 +23,17 @@
|
|
|
23
23
|
"type": "module",
|
|
24
24
|
"main": "main.js",
|
|
25
25
|
"bin": "php-wasm.js",
|
|
26
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "ed646326d99ba84bad911d65b6634265f508f073",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"comlink": "^4.4.
|
|
28
|
+
"comlink": "^4.4.2",
|
|
29
29
|
"express": "4.21.2",
|
|
30
|
+
"fs-ext": "2.1.1",
|
|
30
31
|
"ini": "4.1.2",
|
|
31
32
|
"wasm-feature-detect": "1.8.0",
|
|
32
33
|
"ws": "8.18.1",
|
|
33
34
|
"yargs": "17.7.2",
|
|
34
|
-
"@php-wasm/universal": "1.1.
|
|
35
|
-
"@php-wasm/node": "1.1.
|
|
35
|
+
"@php-wasm/universal": "1.1.4",
|
|
36
|
+
"@php-wasm/node": "1.1.4"
|
|
36
37
|
},
|
|
37
38
|
"overrides": {
|
|
38
39
|
"rollup": "^4.34.6",
|