@php-wasm/util 2.0.7 → 2.0.8
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 +1 -1
- package/index.cjs.map +1 -1
- package/index.js +182 -171
- package/index.js.map +1 -1
- package/package.json +2 -2
package/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=Symbol("SleepFinished");function m(i){return new Promise(
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=Symbol("SleepFinished");function m(i){return new Promise(e=>{setTimeout(()=>e(d),i)})}class g extends Error{constructor(){super("Acquiring lock timed out")}}class E{constructor({concurrency:e,timeout:t}){this._running=0,this.concurrency=e,this.timeout=t,this.queue=[]}get remaining(){return this.concurrency-this.running}get running(){return this._running}async acquire(){for(;;)if(this._running>=this.concurrency){const e=new Promise(t=>{this.queue.push(t)});this.timeout!==void 0?await Promise.race([e,m(this.timeout)]).then(t=>{if(t===d)throw new g}):await 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()}}}class b extends Error{constructor(e,t){super(e),this.userFriendlyMessage=t??e}}function P(...i){function e(o){return o.substring(o.length-1)==="/"}let t=i.join("/");const r=t[0]==="/",s=e(t);return t=u(t),!t&&!r&&(t="."),t&&s&&!e(t)&&(t+="/"),t}function S(i){if(i==="/")return"/";i=u(i);const e=i.lastIndexOf("/");return e===-1?"":e===0?"/":i.substr(0,e)}function x(i){if(i==="/")return"/";i=u(i);const e=i.lastIndexOf("/");return e===-1?i:i.substr(e+1)}function u(i){const e=i[0]==="/";return i=T(i.split("/").filter(t=>!!t),!e).join("/"),(e?"/":"")+i.replace(/\/$/,"")}function T(i,e){let t=0;for(let r=i.length-1;r>=0;r--){const s=i[r];s==="."?i.splice(r,1):s===".."?(i.splice(r,1),t++):t&&(i.splice(r,1),t--)}if(e)for(;t;t--)i.unshift("..");return i}function _(i,e){return i==="/"?!0:(i=u(i),e=u(e),e.startsWith(i+"/")||e===i)}class c{constructor(){this.listeners={}}emit(e,t){this.listeners[e]&&this.listeners[e].forEach(function(r){r(t)})}on(e,t){this.listeners[e]||(this.listeners[e]=[]),this.listeners[e].push(t)}once(e,t){const r=(...s)=>{this.off(e,r),t(...s)};this.on(e,r)}off(e,t){this.listeners[e]&&(this.listeners[e]=this.listeners[e].filter(r=>r!==t))}}function M(i){let r=0,s="";const o=[];let n="";for(let l=0;l<i.length;l++){const f=i[l];f==="\\"?((i[l+1]==='"'||i[l+1]==="'")&&l++,n+=i[l]):r===0?f==='"'||f==="'"?(r=1,s=f):f.match(/\s/)?(n.trim().length&&o.push(n.trim()),n=f):o.length&&!n?n=o.pop()+f:n+=f:r===1&&(f===s?(r=0,s=""):n+=f)}return n&&o.push(n.trim()),o}class h extends c{constructor(e){if(super(),this.buffer=[],this.writing=!1,this.ended=!1,this.length=0,!e.write)throw new Error("WritablePolyfill requires write option");this._write=e.write,this.highWaterMark=e.highWaterMark??16*1024,this.decodeStrings=e.decodeStrings??!0,this.defaultEncoding=e.defaultEncoding??"utf8",this.defer=typeof queueMicrotask=="function"?queueMicrotask:t=>setTimeout(t,0)}write(e,t=this.defaultEncoding,r=()=>{}){if(typeof t=="function"&&(r=t,t=this.defaultEncoding),this.ended){const o=new Error("write after end"),n=this.defer;return n(()=>r(o)),this.emit("error",o),!1}if(this.decodeStrings&&typeof e=="string"){if(typeof Buffer<"u"&&typeof Buffer.from=="function")e=Buffer.from(e,t);else if(typeof TextEncoder<"u")e=new TextEncoder().encode(e);else throw new Error("String chunks are not supported in this environment: Buffer and TextEncoder are unavailable.");t="buffer"}this.length+=e.length??1;const s=this.length>=this.highWaterMark;return this.buffer.push({chunk:e,encoding:t,cb:r}),this.writing||this._clearBuffer(),!s}end(e,t,r){typeof e=="function"?(r=e,e=void 0):typeof t=="function"&&(r=t,t=void 0),e!==void 0&&this.write(e,t,()=>{}),this.ended=!0,this.writing||this._clearBuffer(),r&&this.defer(r)}cork(){}uncork(){}setDefaultEncoding(e){return this.defaultEncoding=e,this}_clearBuffer(){const e=this.buffer.shift();if(!e){this.ended&&this.emit("finish");return}this.writing=!0,this._write(e.chunk,e.encoding,t=>{this.writing=!1,this.length-=e.chunk.length??1,t&&this.emit("error",t),e.cb(t),this.buffer.length?this._clearBuffer():(this.length<this.highWaterMark&&this.emit("drain"),this.ended&&this.emit("finish"))})}}function O(i){return function(e,t=[],r={}){const s=new k,o=new A(s);return setTimeout(async()=>{let n=[];if(t.length)n=[e,...t];else if(typeof e=="string")n=M(e);else if(Array.isArray(e))n=e;else throw new Error("Invalid command ",e);try{const l=i(n,o,r);if(typeof l!="object"||l===null||!("then"in l))throw new Error(`The program callback passed to createSpawnHandler() did not return a promise. It indicates there's a bug in your code. The callback must return a promise. PHP cannot interact with program that synchronously exists at the end of the proc_open() call. All the streams would be closed already. Make sure to put an "await new Promise(resolve => setTimeout(resolve, 1))before calling processApi.exit(0) in your callback to let PHP catch up with the stdout data.`);if(o.exited)throw new Error(`The program callback passed to createSpawnHandler() exited synchronously. It indicates there's a bug in your code. The callback must return a promise. PHP cannot interact with program that synchronously exists at the end of the proc_open() call. All the streams would be closed already. Make sure to put an "await new Promise(resolve => setTimeout(resolve, 1))before calling processApi.exit(0) in your callback to let PHP catch up with the stdout data.`);s.emit("spawn",!0),await l}catch(l){s.emit("error",l),typeof l=="object"&&l!==null&&"message"in l&&typeof l.message=="string"&&o.stderr(l.message),o.exit(1)}}),s}}class A extends c{constructor(e){super(),this.exited=!1,this.stdinBuffer=[],this.childProcess=e,e.on("stdin",t=>{this.stdinBuffer?this.stdinBuffer.push(t.slice()):this.emit("stdin",t)})}stdinEnd(){this.childProcess.stdin.ended||this.childProcess.stdin.end()}stdout(e){this.childProcess.stdout.write(e)}stdoutEnd(){this.childProcess.stdout.ended||this.childProcess.stdout.end()}stderr(e){this.childProcess.stderr.write(e)}stderrEnd(){this.childProcess.stderr.ended||this.childProcess.stderr.end()}notifySpawn(){this.childProcess.emit("spawn",!0)}exit(e){this.exited||(this.exited=!0,this.stdinEnd(),this.stdoutEnd(),this.stderrEnd(),this.childProcess.emit("exit",e))}on(e,t){if(super.on(e,t),e==="stdin"&&this.stdinBuffer){for(let r=0;r<this.stdinBuffer.length;r++)this.emit("stdin",this.stdinBuffer[r]);this.stdinBuffer=null}}}let B=9743;class k extends c{constructor(e=B++){super(),this.pid=e;const t=this;this.stdout=new h({write(r,s,o){t.stdout.emit("data",r),o()}}),this.stderr=new h({write:(r,s,o)=>{t.stderr.emit("data",r),o()}}),this.stdin=new h({write:(r,s,o)=>{t.emit("stdin",r),o()}})}}function p(i=36,e="!@#$%^&*()_+=-[]/.,<>?"){const t="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"+e;let r="";for(let s=i;s>0;--s)r+=t[Math.floor(Math.random()*t.length)];return r}function U(){return p(36,"-_")}function w(i){return`json_decode(base64_decode('${D(JSON.stringify(i))}'), true)`}function q(i){const e={};for(const t in i)e[t]=w(i[t]);return e}function D(i){return W(new TextEncoder().encode(i))}function W(i){const e=String.fromCodePoint(...i);return btoa(e)}function j(i,...e){let t="",r=0;for(let s=0;s<i.length;s++)if(i[s]==="%"&&s+1<i.length){s++;const o=i[s];switch(o){case"s":{const n=e[r++];let l;if(typeof n=="object")try{l=JSON.stringify(n,(f,a)=>typeof a=="bigint"?`0x${a.toString(16)}`:a,2)}catch{}else l=String(n);t+=l;break}case"d":{const n=e[r++];typeof n=="bigint"?t+=n.toString():t+=Math.floor(Number(n));break}case"f":{const n=e[r++];t+=Number(n);break}case"x":{const n=e[r++];typeof n=="bigint"?t+=n.toString(16):t+=Math.floor(Number(n)).toString(16);break}case"%":{t+="%";break}default:t+="%"+o}}else t+=i[s];return t}function y(i){let e=0;i.forEach(s=>e+=s.length);const t=new Uint8Array(e);let r=0;return i.forEach(s=>{t.set(s,r),r+=s.length}),t}function I(i){return y(i.map(e=>new Uint8Array(e))).buffer}exports.AcquireTimeoutError=g;exports.EventEmitterPolyfill=c;exports.PhpWasmError=b;exports.Semaphore=E;exports.WritablePolyfill=h;exports.basename=x;exports.concatArrayBuffers=I;exports.concatUint8Arrays=y;exports.createSpawnHandler=O;exports.dirname=S;exports.isParentOf=_;exports.joinPaths=P;exports.normalizePath=u;exports.phpVar=w;exports.phpVars=q;exports.randomFilename=U;exports.randomString=p;exports.sprintf=j;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../../../packages/php-wasm/util/src/lib/sleep.ts","../../../../packages/php-wasm/util/src/lib/semaphore.ts","../../../../packages/php-wasm/util/src/lib/php-wasm-error.ts","../../../../packages/php-wasm/util/src/lib/paths.ts","../../../../packages/php-wasm/util/src/lib/event-emitter-polyfill.ts","../../../../packages/php-wasm/util/src/lib/split-shell-command.ts","../../../../packages/php-wasm/util/src/lib/writable-polyfill.ts","../../../../packages/php-wasm/util/src/lib/create-spawn-handler.ts","../../../../packages/php-wasm/util/src/lib/random-string.ts","../../../../packages/php-wasm/util/src/lib/random-filename.ts","../../../../packages/php-wasm/util/src/lib/php-vars.ts","../../../../packages/php-wasm/util/src/lib/sprintf.ts","../../../../packages/php-wasm/util/src/lib/index.ts"],"sourcesContent":["export const SleepFinished = Symbol('SleepFinished');\n\nexport function sleep(ms: number): Promise<typeof SleepFinished> {\n\treturn new Promise((resolve) => {\n\t\tsetTimeout(() => resolve(SleepFinished), ms);\n\t});\n}\n","import { SleepFinished, sleep } from './sleep';\n\nexport interface SemaphoreOptions {\n\t/**\n\t * The maximum number of concurrent locks.\n\t */\n\tconcurrency: number;\n\t/**\n\t * The maximum time to wait for a lock to become available.\n\t */\n\ttimeout?: number;\n}\n\nexport class AcquireTimeoutError extends Error {\n\tconstructor() {\n\t\tsuper('Acquiring lock timed out');\n\t}\n}\n\nexport default class Semaphore {\n\tprivate _running = 0;\n\tprivate concurrency: number;\n\tprivate timeout?: number;\n\tprivate queue: (() => void)[];\n\n\tconstructor({ concurrency, timeout }: SemaphoreOptions) {\n\t\tthis.concurrency = concurrency;\n\t\tthis.timeout = timeout;\n\t\tthis.queue = [];\n\t}\n\n\tget remaining(): number {\n\t\treturn this.concurrency - this.running;\n\t}\n\n\tget running(): number {\n\t\treturn this._running;\n\t}\n\n\tasync acquire(): Promise<() => void> {\n\t\twhile (true) {\n\t\t\tif (this._running >= this.concurrency) {\n\t\t\t\t// Concurrency exhausted – wait until a lock is released:\n\t\t\t\tconst acquired = new Promise<void>((resolve) => {\n\t\t\t\t\tthis.queue.push(resolve);\n\t\t\t\t});\n\t\t\t\tif (this.timeout !== undefined) {\n\t\t\t\t\tawait Promise.race([acquired, sleep(this.timeout)]).then(\n\t\t\t\t\t\t(value) => {\n\t\t\t\t\t\t\tif (value === SleepFinished) {\n\t\t\t\t\t\t\t\tthrow new AcquireTimeoutError();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tawait acquired;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Acquire the lock:\n\t\t\t\tthis._running++;\n\t\t\t\tlet released = false;\n\t\t\t\treturn () => {\n\t\t\t\t\tif (released) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\treleased = true;\n\t\t\t\t\tthis._running--;\n\t\t\t\t\t// Release the lock:\n\t\t\t\t\tif (this.queue.length > 0) {\n\t\t\t\t\t\tthis.queue.shift()!();\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t}\n\n\tasync run<T>(fn: () => T | Promise<T>): Promise<T> {\n\t\tconst release = await this.acquire();\n\t\ttry {\n\t\t\treturn await fn();\n\t\t} finally {\n\t\t\trelease();\n\t\t}\n\t}\n}\n","export class PhpWasmError extends Error {\n\tuserFriendlyMessage?: string;\n\tconstructor(message: string, userFriendlyMessage?: string) {\n\t\tsuper(message);\n\t\tthis.userFriendlyMessage = userFriendlyMessage ?? message;\n\t}\n}\n","/**\n * The functions in this module are mostly copied from the generated\n * Emscripten PHP module. This enables features like filesystem journaling,\n * which use some low-level Emscripten APIs and need access to the\n * same path helpers.\n */\n\n/**\n * Joins paths together.\n *\n * For example:\n *\n * > joinPaths('wordpress', 'wp-content')\n * 'wordpress/wp-content'\n *\n * Use this for all PHP paths and **do not** use path.join().\n * This is important because Emscripten paths are **always**\n * POSIX-style paths. Imagine joining paths on Windows:\n *\n * > path.join('wordpress', 'wp-content')\n * '\\\\wordpress\\\\wp-content' // invalid in PHP.wasm\n *\n * See the path.join issue for more details:\n *\n * https://github.com/WordPress/playground-tools/issues/11#issuecomment-1579074763\n *\n * @param paths Paths segments to join\n * @returns A joined path\n */\nexport function joinPaths(...paths: string[]) {\n\tfunction hasTrailingSlash(p: string) {\n\t\treturn p.substring(p.length - 1) === '/';\n\t}\n\n\tlet path = paths.join('/');\n\tconst isAbsolute = path[0] === '/';\n\tconst trailingSlash = hasTrailingSlash(path);\n\tpath = normalizePath(path);\n\tif (!path && !isAbsolute) {\n\t\tpath = '.';\n\t}\n\tif (path && trailingSlash && !hasTrailingSlash(path)) {\n\t\tpath += '/';\n\t}\n\treturn path;\n}\n\n/**\n * Returns the directory name of a path.\n *\n * @param path\n * @returns\n */\nexport function dirname(path: string) {\n\tif (path === '/') {\n\t\treturn '/';\n\t}\n\n\tpath = normalizePath(path);\n\n\tconst lastSlash = path.lastIndexOf('/');\n\tif (lastSlash === -1) {\n\t\treturn '';\n\t} else if (lastSlash === 0) {\n\t\treturn '/';\n\t}\n\treturn path.substr(0, lastSlash);\n}\n\n/**\n * Returns the last portion of a path.\n *\n * @param path - The path to extract the basename from.\n * @returns The basename of the path.\n */\nexport function basename(path: string) {\n\tif (path === '/') {\n\t\treturn '/';\n\t}\n\n\tpath = normalizePath(path);\n\n\tconst lastSlash = path.lastIndexOf('/');\n\tif (lastSlash === -1) {\n\t\treturn path;\n\t}\n\treturn path.substr(lastSlash + 1);\n}\n\n/**\n * Normalizes a path.\n *\n * For example:\n *\n * > normalizePath('wordpress/wp-content/../')\n * 'wordpress'\n *\n * @param path\n * @returns\n */\nexport function normalizePath(path: string) {\n\tconst isAbsolute = path[0] === '/';\n\tpath = normalizePathsArray(\n\t\tpath.split('/').filter((p: any) => !!p),\n\t\t!isAbsolute\n\t).join('/');\n\treturn (isAbsolute ? '/' : '') + path.replace(/\\/$/, '');\n}\n\n/**\n * Normalizes paths.\n *\n * For example:\n *\n * > normalizePathsArray(['wordpress', 'wp-content', '..', '', '.',\n * 'wp-includes']) ['wordpress', 'wp-includes']\n *\n * @param parts parts of the path to normalize\n * @param allowAboveRoot allow paths above the root\n * @returns normalized paths\n */\nexport function normalizePathsArray(parts: string[], allowAboveRoot: boolean) {\n\tlet up = 0;\n\tfor (let i = parts.length - 1; i >= 0; i--) {\n\t\tconst last = parts[i];\n\t\tif (last === '.') {\n\t\t\tparts.splice(i, 1);\n\t\t} else if (last === '..') {\n\t\t\tparts.splice(i, 1);\n\t\t\tup++;\n\t\t} else if (up) {\n\t\t\tparts.splice(i, 1);\n\t\t\tup--;\n\t\t}\n\t}\n\tif (allowAboveRoot) {\n\t\tfor (; up; up--) {\n\t\t\tparts.unshift('..');\n\t\t}\n\t}\n\treturn parts;\n}\n\n/**\n * Checks if the given parent path is an ancestor of the given child path.\n *\n * @param parent The parent path to check.\n * @param child The child path to verify against the parent.\n * @returns Whether the `parent` path is an ancestor of the `child` path.\n */\nexport function isParentOf(parent: string, child: string) {\n\tif (parent === '/') {\n\t\treturn true;\n\t}\n\tparent = normalizePath(parent);\n\tchild = normalizePath(child);\n\treturn child.startsWith(parent + '/') || child === parent;\n}\n","/**\n * Polyfills Node.js EventEmitter API. The main goal is to enable\n * using a child_process.spawn()-like API in both Node.js and the browser.\n *\n * @see https://nodejs.org/api/events.html#events_class_eventemitter\n */\ntype Listener = (...args: any[]) => any;\n\nexport class EventEmitterPolyfill {\n\tlisteners: Record<string, Listener[]> = {};\n\temit(eventName: string, data?: any) {\n\t\tif (this.listeners[eventName]) {\n\t\t\tthis.listeners[eventName].forEach(function (listener) {\n\t\t\t\tlistener(data);\n\t\t\t});\n\t\t}\n\t}\n\ton(eventName: string, listener: Listener) {\n\t\tif (!this.listeners[eventName]) {\n\t\t\tthis.listeners[eventName] = [];\n\t\t}\n\t\tthis.listeners[eventName].push(listener);\n\t}\n\tonce(eventName: string, listener: Listener) {\n\t\tconst wrappedListener = (...args: any[]) => {\n\t\t\tthis.off(eventName, wrappedListener);\n\t\t\tlistener(...args);\n\t\t};\n\t\tthis.on(eventName, wrappedListener);\n\t}\n\toff(eventName: string, listener: Listener) {\n\t\tif (this.listeners[eventName]) {\n\t\t\tthis.listeners[eventName] = this.listeners[eventName].filter(\n\t\t\t\t(l) => l !== listener\n\t\t\t);\n\t\t}\n\t}\n}\n","/**\n * Naive shell command parser.\n * Ensures that commands like `wp option set blogname \"My blog name\"` are split\n * into `['wp', 'option', 'set', 'blogname', 'My blog name']` instead of\n * `['wp', 'option', 'set', 'blogname', 'My', 'blog', 'name']`.\n *\n * @param command\n * @returns\n */\nexport function splitShellCommand(command: string) {\n\tconst MODE_UNQUOTED = 0;\n\tconst MODE_IN_QUOTE = 1;\n\n\tlet mode = MODE_UNQUOTED;\n\tlet quote = '';\n\n\tconst parts: string[] = [];\n\tlet currentPart = '';\n\tfor (let i = 0; i < command.length; i++) {\n\t\tconst char = command[i];\n\t\tif (char === '\\\\') {\n\t\t\t// Escaped quotes are treated as normal characters\n\t\t\t// This is a very naive approach to escaping, but it's good enough for\n\t\t\t// now. @TODO: Iterate on this later, perhaps using bun shell. @see https://github.com/WordPress/wordpress-playground/issues/1062\n\t\t\tif (command[i + 1] === '\"' || command[i + 1] === \"'\") {\n\t\t\t\ti++;\n\t\t\t}\n\t\t\tcurrentPart += command[i];\n\t\t} else if (mode === MODE_UNQUOTED) {\n\t\t\tif (char === '\"' || char === \"'\") {\n\t\t\t\tmode = MODE_IN_QUOTE;\n\t\t\t\tquote = char;\n\t\t\t} else if (char.match(/\\s/)) {\n\t\t\t\tif (currentPart.trim().length) {\n\t\t\t\t\tparts.push(currentPart.trim());\n\t\t\t\t}\n\t\t\t\tcurrentPart = char;\n\t\t\t} else if (parts.length && !currentPart) {\n\t\t\t\t// We just closed a quote to continue the same\n\t\t\t\t// argument with different escaping style, e.g.:\n\t\t\t\t// php -r 'require '\\''vendor/autoload.php'\\''\n\t\t\t\tcurrentPart = parts.pop()! + char;\n\t\t\t} else {\n\t\t\t\tcurrentPart += char;\n\t\t\t}\n\t\t} else if (mode === MODE_IN_QUOTE) {\n\t\t\tif (char === quote) {\n\t\t\t\tmode = MODE_UNQUOTED;\n\t\t\t\tquote = '';\n\t\t\t} else {\n\t\t\t\tcurrentPart += char;\n\t\t\t}\n\t\t}\n\t}\n\tif (currentPart) {\n\t\tparts.push(currentPart.trim());\n\t}\n\treturn parts;\n}\n","/**\n * Polyfills Node.js WritableStream API. The main goal is to enable\n * using a child_process.spawn()-like API in both Node.js and the browser.\n *\n * @see https://nodejs.org/api/stream.html#stream_writable_end_chunk_encoding_callback\n */\nimport { EventEmitterPolyfill } from './event-emitter-polyfill';\n\nexport interface WritableOptions {\n\thighWaterMark?: number;\n\tdecodeStrings?: boolean;\n\tdefaultEncoding?: BufferEncoding;\n\twrite: (chunk: any, encoding: BufferEncoding, cb: WriteCallback) => void;\n}\n\nexport type WriteCallback = (error?: Error | null) => void;\n\nexport class WritablePolyfill extends EventEmitterPolyfill {\n\tprivate buffer: Array<{\n\t\tchunk: any;\n\t\tencoding: BufferEncoding;\n\t\tcb: WriteCallback;\n\t}> = [];\n\tprivate writing = false;\n\tpublic ended = false;\n\tprivate length = 0;\n\tprivate highWaterMark: number;\n\tprivate decodeStrings: boolean;\n\tprivate defaultEncoding: BufferEncoding;\n\tprivate defer: (fn: () => void) => void;\n\tprivate _write: (\n\t\tchunk: any,\n\t\tencoding: BufferEncoding,\n\t\tcb: WriteCallback\n\t) => void;\n\n\tconstructor(opts: WritableOptions) {\n\t\tsuper();\n\t\tif (!opts.write) {\n\t\t\tthrow new Error('WritablePolyfill requires write option');\n\t\t}\n\t\tthis._write = opts.write;\n\t\tthis.highWaterMark = opts.highWaterMark ?? 16 * 1024;\n\t\tthis.decodeStrings = opts.decodeStrings ?? true;\n\t\tthis.defaultEncoding = opts.defaultEncoding ?? 'utf8';\n\t\t// queueMicrotask keeps browser support; fallback for older environments.\n\t\tthis.defer =\n\t\t\ttypeof queueMicrotask === 'function'\n\t\t\t\t? queueMicrotask\n\t\t\t\t: (fn) => setTimeout(fn, 0);\n\t}\n\n\twrite(\n\t\tchunk: any,\n\t\tencoding: BufferEncoding | WriteCallback = this.defaultEncoding,\n\t\tcb: WriteCallback = () => {}\n\t): boolean {\n\t\tif (typeof encoding === 'function') {\n\t\t\tcb = encoding as WriteCallback;\n\t\t\tencoding = this.defaultEncoding;\n\t\t}\n\n\t\tif (this.ended) {\n\t\t\tconst err = new Error('write after end');\n\t\t\tthis.defer(() => cb(err));\n\t\t\tthis.emit('error', err);\n\t\t\treturn false;\n\t\t}\n\n\t\tif (this.decodeStrings && typeof chunk === 'string') {\n\t\t\tchunk = Buffer.from(chunk, encoding as BufferEncoding);\n\t\t\tencoding = 'buffer' as BufferEncoding;\n\t\t}\n\n\t\tthis.length += chunk.length ?? 1;\n\t\tconst needDrain = this.length >= this.highWaterMark;\n\n\t\tthis.buffer.push({ chunk, encoding: encoding as BufferEncoding, cb });\n\n\t\tif (!this.writing) this._clearBuffer();\n\n\t\treturn !needDrain;\n\t}\n\n\tend(\n\t\tchunk?: any,\n\t\tencoding?: BufferEncoding | WriteCallback,\n\t\tcb?: WriteCallback\n\t): void {\n\t\tif (typeof chunk === 'function') {\n\t\t\tcb = chunk;\n\t\t\tchunk = undefined;\n\t\t} else if (typeof encoding === 'function') {\n\t\t\tcb = encoding as WriteCallback;\n\t\t\tencoding = undefined;\n\t\t}\n\n\t\tif (chunk !== undefined)\n\t\t\tthis.write(chunk, encoding as BufferEncoding, () => {});\n\t\tthis.ended = true;\n\t\tif (!this.writing) this._clearBuffer();\n\t\tif (cb) this.defer(cb);\n\t}\n\n\t// Stubs kept for API parity; add logic if you depend on corking.\n\tcork(): void {}\n\tuncork(): void {}\n\n\tsetDefaultEncoding(enc: BufferEncoding): this {\n\t\tthis.defaultEncoding = enc;\n\t\treturn this;\n\t}\n\n\tprivate _clearBuffer(): void {\n\t\tconst entry = this.buffer.shift();\n\t\tif (!entry) {\n\t\t\tif (this.ended) this.emit('finish');\n\t\t\treturn;\n\t\t}\n\n\t\tthis.writing = true;\n\t\tthis._write(entry.chunk, entry.encoding, (err?: Error | null) => {\n\t\t\tthis.writing = false;\n\t\t\tthis.length -= entry.chunk.length ?? 1;\n\t\t\tif (err) this.emit('error', err);\n\t\t\tentry.cb(err);\n\n\t\t\tif (this.buffer.length) {\n\t\t\t\tthis._clearBuffer();\n\t\t\t} else {\n\t\t\t\tif (this.length < this.highWaterMark) this.emit('drain');\n\t\t\t\tif (this.ended) this.emit('finish');\n\t\t\t}\n\t\t});\n\t}\n}\n","import { EventEmitterPolyfill } from './event-emitter-polyfill';\nimport { splitShellCommand } from './split-shell-command';\nimport { WritablePolyfill, type WriteCallback } from './writable-polyfill';\n\ntype Listener = (...args: any[]) => any;\n\nexport interface ProcessOptions {\n\tcwd?: string;\n\tenv?: Record<string, string>;\n}\n\n/**\n * Usage:\n * ```ts\n * php.setSpawnHandler(\n * createSpawnHandler(function (command, processApi) {\n * console.log(processApi.flushStdin());\n * processApi.stdout('/\\n/tmp\\n/home');\n *\t processApi.exit(0);\n * })\n * );\n * ```\n * @param program\n * @returns\n */\nexport function createSpawnHandler(\n\tprogram: (\n\t\tcommand: string[],\n\t\tprocessApi: ProcessApi,\n\t\toptions: ProcessOptions\n\t) => void | Promise<void>\n): any {\n\treturn function (\n\t\tcommand: string | string[],\n\t\targsArray: string[] = [],\n\t\toptions: ProcessOptions = {}\n\t) {\n\t\tconst childProcess = new ChildProcess();\n\t\tconst processApi = new ProcessApi(childProcess);\n\t\t// Give PHP a chance to register listeners\n\t\tsetTimeout(async () => {\n\t\t\tlet commandArray = [];\n\t\t\tif (argsArray.length) {\n\t\t\t\tcommandArray = [command as string, ...argsArray];\n\t\t\t} else if (typeof command === 'string') {\n\t\t\t\tcommandArray = splitShellCommand(command);\n\t\t\t} else if (Array.isArray(command)) {\n\t\t\t\tcommandArray = command;\n\t\t\t} else {\n\t\t\t\tthrow new Error('Invalid command ', command);\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tconst promise = program(commandArray, processApi, options);\n\t\t\t\tif (\n\t\t\t\t\ttypeof promise !== 'object' ||\n\t\t\t\t\tpromise === null ||\n\t\t\t\t\t!('then' in promise)\n\t\t\t\t) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`The program callback passed to createSpawnHandler() did not return a promise. It indicates there's a bug in your code. ` +\n\t\t\t\t\t\t\t`The callback must return a promise. PHP cannot interact with program that synchronously exists at the end of the proc_open() ` +\n\t\t\t\t\t\t\t`call. All the streams would be closed already. Make sure to put an \"await new Promise(resolve => setTimeout(resolve, 1))` +\n\t\t\t\t\t\t\t`before calling processApi.exit(0) in your callback to let PHP catch up with the stdout data.`\n\t\t\t\t\t);\n\t\t\t\t} else if (processApi.exited) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`The program callback passed to createSpawnHandler() exited synchronously. It indicates there's a bug in your code. ` +\n\t\t\t\t\t\t\t`The callback must return a promise. PHP cannot interact with program that synchronously exists at the end of the proc_open() ` +\n\t\t\t\t\t\t\t`call. All the streams would be closed already. Make sure to put an \"await new Promise(resolve => setTimeout(resolve, 1))` +\n\t\t\t\t\t\t\t`before calling processApi.exit(0) in your callback to let PHP catch up with the stdout data.`\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tchildProcess.emit('spawn', true);\n\t\t\t\tawait promise;\n\t\t\t} catch (e) {\n\t\t\t\tchildProcess.emit('error', e);\n\t\t\t\tif (\n\t\t\t\t\ttypeof e === 'object' &&\n\t\t\t\t\te !== null &&\n\t\t\t\t\t'message' in e &&\n\t\t\t\t\ttypeof e.message === 'string'\n\t\t\t\t) {\n\t\t\t\t\tprocessApi.stderr(e.message);\n\t\t\t\t}\n\t\t\t\tprocessApi.exit(1);\n\t\t\t}\n\t\t});\n\t\treturn childProcess;\n\t};\n}\n\nexport class ProcessApi extends EventEmitterPolyfill {\n\tpublic exited = false;\n\t/**\n\t * Keeps track of the data that was written to stdin before the\n\t * first listener was registered.\n\t */\n\tprivate stdinBuffer: Uint8Array[] | null = [];\n\tprivate childProcess: ChildProcess;\n\tconstructor(childProcess: ChildProcess) {\n\t\tsuper();\n\t\tthis.childProcess = childProcess;\n\t\tchildProcess.on('stdin', (data: Uint8Array) => {\n\t\t\tif (this.stdinBuffer) {\n\t\t\t\t// Need to clone the data buffer as it's reused by PHP\n\t\t\t\t// and the next data chunk will overwrite the previous one.\n\t\t\t\tthis.stdinBuffer.push(data.slice());\n\t\t\t} else {\n\t\t\t\tthis.emit('stdin', data);\n\t\t\t}\n\t\t});\n\t}\n\tstdinEnd() {\n\t\tif (!this.childProcess.stdin.ended) {\n\t\t\tthis.childProcess.stdin.end();\n\t\t}\n\t}\n\tstdout(data: string | ArrayBuffer) {\n\t\tthis.childProcess.stdout.write(data);\n\t}\n\tstdoutEnd() {\n\t\tif (!this.childProcess.stdout.ended) {\n\t\t\tthis.childProcess.stdout.end();\n\t\t}\n\t}\n\tstderr(data: string | ArrayBuffer) {\n\t\tthis.childProcess.stderr.write(data);\n\t}\n\tstderrEnd() {\n\t\tif (!this.childProcess.stderr.ended) {\n\t\t\tthis.childProcess.stderr.end();\n\t\t}\n\t}\n\tnotifySpawn() {\n\t\tthis.childProcess.emit('spawn', true);\n\t}\n\texit(code: number) {\n\t\tif (!this.exited) {\n\t\t\tthis.exited = true;\n\t\t\tthis.stdinEnd();\n\t\t\tthis.stdoutEnd();\n\t\t\tthis.stderrEnd();\n\t\t\tthis.childProcess.emit('exit', code);\n\t\t}\n\t}\n\toverride on(eventName: string, listener: Listener) {\n\t\tsuper.on(eventName, listener);\n\t\t/**\n\t\t * If it's the first stdin listener, flush all the data we've\n\t\t * buffered so far.\n\t\t */\n\t\tif (eventName === 'stdin' && this.stdinBuffer) {\n\t\t\tfor (let i = 0; i < this.stdinBuffer.length; i++) {\n\t\t\t\tthis.emit('stdin', this.stdinBuffer[i]);\n\t\t\t}\n\t\t\tthis.stdinBuffer = null;\n\t\t}\n\t}\n}\n\nlet lastPid = 9743;\nexport class ChildProcess extends EventEmitterPolyfill {\n\tstdout: WritablePolyfill;\n\tstderr: WritablePolyfill;\n\tstdin: WritablePolyfill;\n\tpid: number;\n\tconstructor(pid = lastPid++) {\n\t\tsuper();\n\t\tthis.pid = pid;\n\t\t// eslint-disable-next-line @typescript-eslint/no-this-alias\n\t\tconst self = this;\n\t\tthis.stdout = new WritablePolyfill({\n\t\t\twrite(data: any, encoding: BufferEncoding, cb: WriteCallback) {\n\t\t\t\tself.stdout.emit('data', data);\n\t\t\t\tcb();\n\t\t\t},\n\t\t});\n\t\tthis.stderr = new WritablePolyfill({\n\t\t\twrite: (data: any, encoding: BufferEncoding, cb: WriteCallback) => {\n\t\t\t\tself.stderr.emit('data', data);\n\t\t\t\tcb();\n\t\t\t},\n\t\t});\n\t\tthis.stdin = new WritablePolyfill({\n\t\t\twrite: (data: any, encoding: BufferEncoding, cb: WriteCallback) => {\n\t\t\t\tself.emit('stdin', data);\n\t\t\t\tcb();\n\t\t\t},\n\t\t});\n\t}\n}\n","export function randomString(\n\tlength = 36,\n\tspecialChars = '!@#$%^&*()_+=-[]/.,<>?'\n) {\n\tconst chars =\n\t\t'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' +\n\t\tspecialChars;\n\tlet result = '';\n\tfor (let i = length; i > 0; --i)\n\t\tresult += chars[Math.floor(Math.random() * chars.length)];\n\treturn result;\n}\n","import { randomString } from './random-string';\n\nexport function randomFilename() {\n\treturn randomString(36, '-_');\n}\n","export function phpVar(value: unknown): string {\n\treturn `json_decode(base64_decode('${stringToBase64(\n\t\tJSON.stringify(value)\n\t)}'), true)`;\n}\n\nexport function phpVars<T extends Record<string, unknown>>(\n\tvars: T\n): Record<keyof T, string> {\n\tconst result: Record<string, string> = {};\n\tfor (const key in vars) {\n\t\tresult[key] = phpVar(vars[key]);\n\t}\n\treturn result as Record<keyof T, string>;\n}\n\nfunction stringToBase64(str: string) {\n\treturn bytesToBase64(new TextEncoder().encode(str));\n}\n\nfunction bytesToBase64(bytes: Uint8Array) {\n\tconst binString = String.fromCodePoint(...bytes);\n\treturn btoa(binString);\n}\n","/**\n * Formats a string like sprintf().\n *\n * This function:\n * - Supports basic format specifiers: %s, %d, %f, %x, %%\n * - Supports bigint values\n *\n * The purpose of this function is for use in optional php-wasm tracing.\n * If we use printf-style formatting for trace messages, we let the trace\n * function decide whether to format and do not have to pay for formatting\n * unless tracing is enabled.\n */\nexport function sprintf(format: string, ...args: any[]): string {\n\tlet result = '';\n\tlet argIndex = 0;\n\n\tfor (let i = 0; i < format.length; i++) {\n\t\tif (format[i] === '%' && i + 1 < format.length) {\n\t\t\ti++;\n\t\t\tconst specifier = format[i];\n\n\t\t\tswitch (specifier) {\n\t\t\t\tcase 's': {\n\t\t\t\t\tconst arg = args[argIndex++];\n\t\t\t\t\tlet str;\n\t\t\t\t\tif (typeof arg === 'object') {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t// If an object doesn't provide its own toString(),\n\t\t\t\t\t\t\t// try to represent it as JSON.\n\t\t\t\t\t\t\tstr = JSON.stringify(\n\t\t\t\t\t\t\t\targ,\n\t\t\t\t\t\t\t\t// Represent bigint values as strings in JSON.stringify().\n\t\t\t\t\t\t\t\t(key, value) => {\n\t\t\t\t\t\t\t\t\tif (typeof value === 'bigint') {\n\t\t\t\t\t\t\t\t\t\treturn `0x${value.toString(16)}`;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\treturn value;\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t2\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t// Ignore error and use default representation.\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tstr = String(arg);\n\t\t\t\t\t}\n\n\t\t\t\t\tresult += str;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase 'd': {\n\t\t\t\t\tconst arg = args[argIndex++];\n\t\t\t\t\tif (typeof arg === 'bigint') {\n\t\t\t\t\t\tresult += arg.toString();\n\t\t\t\t\t} else {\n\t\t\t\t\t\tresult += Math.floor(Number(arg));\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase 'f': {\n\t\t\t\t\tconst arg = args[argIndex++];\n\t\t\t\t\tif (typeof arg === 'bigint') {\n\t\t\t\t\t\tresult += Number(arg);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tresult += Number(arg);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase 'x': {\n\t\t\t\t\tconst arg = args[argIndex++];\n\t\t\t\t\tif (typeof arg === 'bigint') {\n\t\t\t\t\t\tresult += arg.toString(16);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tresult += Math.floor(Number(arg)).toString(16);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase '%': {\n\t\t\t\t\tresult += '%';\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\tresult += '%' + specifier;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tresult += format[i];\n\t\t}\n\t}\n\n\treturn result;\n}\n","import Semaphore, { AcquireTimeoutError } from './semaphore';\nexport { Semaphore, AcquireTimeoutError };\nexport { PhpWasmError } from './php-wasm-error';\nexport type { SemaphoreOptions } from './semaphore';\nexport {\n\tdirname,\n\tjoinPaths,\n\tbasename,\n\tnormalizePath,\n\tisParentOf,\n} from './paths';\nexport { createSpawnHandler } from './create-spawn-handler';\nexport { randomString } from './random-string';\nexport { randomFilename } from './random-filename';\nexport { WritablePolyfill, type WritableOptions } from './writable-polyfill';\nexport { EventEmitterPolyfill } from './event-emitter-polyfill';\nexport * from './php-vars';\n\nexport * from './sprintf';\n\nexport function concatUint8Arrays(arrays: Uint8Array[]): Uint8Array {\n\tlet totalLength = 0;\n\tarrays.forEach((a) => (totalLength += a.length));\n\tconst result = new Uint8Array(totalLength);\n\tlet offset = 0;\n\tarrays.forEach((a) => {\n\t\tresult.set(a, offset);\n\t\toffset += a.length;\n\t});\n\treturn result;\n}\n\nexport function concatArrayBuffers(buffers: ArrayBuffer[]): ArrayBuffer {\n\treturn concatUint8Arrays(buffers.map((b) => new Uint8Array(b)))\n\t\t.buffer as ArrayBuffer;\n}\n\nexport * from './types';\n"],"names":["SleepFinished","sleep","ms","resolve","AcquireTimeoutError","Semaphore","concurrency","timeout","acquired","value","released","fn","release","PhpWasmError","message","userFriendlyMessage","joinPaths","paths","hasTrailingSlash","p","path","isAbsolute","trailingSlash","normalizePath","dirname","lastSlash","basename","normalizePathsArray","parts","allowAboveRoot","up","i","last","isParentOf","parent","child","EventEmitterPolyfill","eventName","data","listener","wrappedListener","args","l","splitShellCommand","command","mode","quote","currentPart","char","WritablePolyfill","opts","chunk","encoding","cb","err","needDrain","enc","entry","createSpawnHandler","program","argsArray","options","childProcess","ChildProcess","processApi","ProcessApi","commandArray","promise","e","code","lastPid","pid","self","randomString","length","specialChars","chars","result","randomFilename","phpVar","stringToBase64","phpVars","vars","key","str","bytesToBase64","bytes","binString","sprintf","format","argIndex","specifier","arg","concatUint8Arrays","arrays","totalLength","a","offset","concatArrayBuffers","buffers","b"],"mappings":"gFAAa,MAAAA,EAAgB,OAAO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ACvB,OAAOE,GAAQ,SACRf,GAAAe,EAAI,SAAS,EAAE,EAEzBf,GAAU,KAAK,MAAM,OAAOe,CAAG,CAAC,EAAE,SAAS,EAAE,EAE9C,KAAA,CAED,IAAK,IAAK,CACCf,GAAA,IACV,KAAA,CAED,QACCA,GAAU,IAAMc,CACjB,CACD,MAEAd,GAAUY,EAAO1D,CAAC,EAIb,OAAA8C,CACR,CCvEO,SAASgB,EAAkBC,EAAkC,CACnE,IAAIC,EAAc,EAClBD,EAAO,QAASE,GAAOD,GAAeC,EAAE,MAAO,EACzC,MAAAnB,EAAS,IAAI,WAAWkB,CAAW,EACzC,IAAIE,EAAS,EACN,OAAAH,EAAA,QAASE,GAAM,CACdnB,EAAA,IAAImB,EAAGC,CAAM,EACpBA,GAAUD,EAAE,MAAA,CACZ,EACMnB,CACR,CAEO,SAASqB,EAAmBC,EAAqC,CAChE,OAAAN,EAAkBM,EAAQ,IAAKC,GAAM,IAAI,WAAWA,CAAC,CAAC,CAAC,EAC5D,MACH"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../../../packages/php-wasm/util/src/lib/sleep.ts","../../../../packages/php-wasm/util/src/lib/semaphore.ts","../../../../packages/php-wasm/util/src/lib/php-wasm-error.ts","../../../../packages/php-wasm/util/src/lib/paths.ts","../../../../packages/php-wasm/util/src/lib/event-emitter-polyfill.ts","../../../../packages/php-wasm/util/src/lib/split-shell-command.ts","../../../../packages/php-wasm/util/src/lib/writable-polyfill.ts","../../../../packages/php-wasm/util/src/lib/create-spawn-handler.ts","../../../../packages/php-wasm/util/src/lib/random-string.ts","../../../../packages/php-wasm/util/src/lib/random-filename.ts","../../../../packages/php-wasm/util/src/lib/php-vars.ts","../../../../packages/php-wasm/util/src/lib/sprintf.ts","../../../../packages/php-wasm/util/src/lib/index.ts"],"sourcesContent":["export const SleepFinished = Symbol('SleepFinished');\n\nexport function sleep(ms: number): Promise<typeof SleepFinished> {\n\treturn new Promise((resolve) => {\n\t\tsetTimeout(() => resolve(SleepFinished), ms);\n\t});\n}\n","import { SleepFinished, sleep } from './sleep';\n\nexport interface SemaphoreOptions {\n\t/**\n\t * The maximum number of concurrent locks.\n\t */\n\tconcurrency: number;\n\t/**\n\t * The maximum time to wait for a lock to become available.\n\t */\n\ttimeout?: number;\n}\n\nexport class AcquireTimeoutError extends Error {\n\tconstructor() {\n\t\tsuper('Acquiring lock timed out');\n\t}\n}\n\nexport default class Semaphore {\n\tprivate _running = 0;\n\tprivate concurrency: number;\n\tprivate timeout?: number;\n\tprivate queue: (() => void)[];\n\n\tconstructor({ concurrency, timeout }: SemaphoreOptions) {\n\t\tthis.concurrency = concurrency;\n\t\tthis.timeout = timeout;\n\t\tthis.queue = [];\n\t}\n\n\tget remaining(): number {\n\t\treturn this.concurrency - this.running;\n\t}\n\n\tget running(): number {\n\t\treturn this._running;\n\t}\n\n\tasync acquire(): Promise<() => void> {\n\t\twhile (true) {\n\t\t\tif (this._running >= this.concurrency) {\n\t\t\t\t// Concurrency exhausted – wait until a lock is released:\n\t\t\t\tconst acquired = new Promise<void>((resolve) => {\n\t\t\t\t\tthis.queue.push(resolve);\n\t\t\t\t});\n\t\t\t\tif (this.timeout !== undefined) {\n\t\t\t\t\tawait Promise.race([acquired, sleep(this.timeout)]).then(\n\t\t\t\t\t\t(value) => {\n\t\t\t\t\t\t\tif (value === SleepFinished) {\n\t\t\t\t\t\t\t\tthrow new AcquireTimeoutError();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tawait acquired;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Acquire the lock:\n\t\t\t\tthis._running++;\n\t\t\t\tlet released = false;\n\t\t\t\treturn () => {\n\t\t\t\t\tif (released) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\treleased = true;\n\t\t\t\t\tthis._running--;\n\t\t\t\t\t// Release the lock:\n\t\t\t\t\tif (this.queue.length > 0) {\n\t\t\t\t\t\tthis.queue.shift()!();\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t}\n\n\tasync run<T>(fn: () => T | Promise<T>): Promise<T> {\n\t\tconst release = await this.acquire();\n\t\ttry {\n\t\t\treturn await fn();\n\t\t} finally {\n\t\t\trelease();\n\t\t}\n\t}\n}\n","export class PhpWasmError extends Error {\n\tuserFriendlyMessage?: string;\n\tconstructor(message: string, userFriendlyMessage?: string) {\n\t\tsuper(message);\n\t\tthis.userFriendlyMessage = userFriendlyMessage ?? message;\n\t}\n}\n","/**\n * The functions in this module are mostly copied from the generated\n * Emscripten PHP module. This enables features like filesystem journaling,\n * which use some low-level Emscripten APIs and need access to the\n * same path helpers.\n */\n\n/**\n * Joins paths together.\n *\n * For example:\n *\n * > joinPaths('wordpress', 'wp-content')\n * 'wordpress/wp-content'\n *\n * Use this for all PHP paths and **do not** use path.join().\n * This is important because Emscripten paths are **always**\n * POSIX-style paths. Imagine joining paths on Windows:\n *\n * > path.join('wordpress', 'wp-content')\n * '\\\\wordpress\\\\wp-content' // invalid in PHP.wasm\n *\n * See the path.join issue for more details:\n *\n * https://github.com/WordPress/playground-tools/issues/11#issuecomment-1579074763\n *\n * @param paths Paths segments to join\n * @returns A joined path\n */\nexport function joinPaths(...paths: string[]) {\n\tfunction hasTrailingSlash(p: string) {\n\t\treturn p.substring(p.length - 1) === '/';\n\t}\n\n\tlet path = paths.join('/');\n\tconst isAbsolute = path[0] === '/';\n\tconst trailingSlash = hasTrailingSlash(path);\n\tpath = normalizePath(path);\n\tif (!path && !isAbsolute) {\n\t\tpath = '.';\n\t}\n\tif (path && trailingSlash && !hasTrailingSlash(path)) {\n\t\tpath += '/';\n\t}\n\treturn path;\n}\n\n/**\n * Returns the directory name of a path.\n *\n * @param path\n * @returns\n */\nexport function dirname(path: string) {\n\tif (path === '/') {\n\t\treturn '/';\n\t}\n\n\tpath = normalizePath(path);\n\n\tconst lastSlash = path.lastIndexOf('/');\n\tif (lastSlash === -1) {\n\t\treturn '';\n\t} else if (lastSlash === 0) {\n\t\treturn '/';\n\t}\n\treturn path.substr(0, lastSlash);\n}\n\n/**\n * Returns the last portion of a path.\n *\n * @param path - The path to extract the basename from.\n * @returns The basename of the path.\n */\nexport function basename(path: string) {\n\tif (path === '/') {\n\t\treturn '/';\n\t}\n\n\tpath = normalizePath(path);\n\n\tconst lastSlash = path.lastIndexOf('/');\n\tif (lastSlash === -1) {\n\t\treturn path;\n\t}\n\treturn path.substr(lastSlash + 1);\n}\n\n/**\n * Normalizes a path.\n *\n * For example:\n *\n * > normalizePath('wordpress/wp-content/../')\n * 'wordpress'\n *\n * @param path\n * @returns\n */\nexport function normalizePath(path: string) {\n\tconst isAbsolute = path[0] === '/';\n\tpath = normalizePathsArray(\n\t\tpath.split('/').filter((p: any) => !!p),\n\t\t!isAbsolute\n\t).join('/');\n\treturn (isAbsolute ? '/' : '') + path.replace(/\\/$/, '');\n}\n\n/**\n * Normalizes paths.\n *\n * For example:\n *\n * > normalizePathsArray(['wordpress', 'wp-content', '..', '', '.',\n * 'wp-includes']) ['wordpress', 'wp-includes']\n *\n * @param parts parts of the path to normalize\n * @param allowAboveRoot allow paths above the root\n * @returns normalized paths\n */\nexport function normalizePathsArray(parts: string[], allowAboveRoot: boolean) {\n\tlet up = 0;\n\tfor (let i = parts.length - 1; i >= 0; i--) {\n\t\tconst last = parts[i];\n\t\tif (last === '.') {\n\t\t\tparts.splice(i, 1);\n\t\t} else if (last === '..') {\n\t\t\tparts.splice(i, 1);\n\t\t\tup++;\n\t\t} else if (up) {\n\t\t\tparts.splice(i, 1);\n\t\t\tup--;\n\t\t}\n\t}\n\tif (allowAboveRoot) {\n\t\tfor (; up; up--) {\n\t\t\tparts.unshift('..');\n\t\t}\n\t}\n\treturn parts;\n}\n\n/**\n * Checks if the given parent path is an ancestor of the given child path.\n *\n * @param parent The parent path to check.\n * @param child The child path to verify against the parent.\n * @returns Whether the `parent` path is an ancestor of the `child` path.\n */\nexport function isParentOf(parent: string, child: string) {\n\tif (parent === '/') {\n\t\treturn true;\n\t}\n\tparent = normalizePath(parent);\n\tchild = normalizePath(child);\n\treturn child.startsWith(parent + '/') || child === parent;\n}\n","/**\n * Polyfills Node.js EventEmitter API. The main goal is to enable\n * using a child_process.spawn()-like API in both Node.js and the browser.\n *\n * @see https://nodejs.org/api/events.html#events_class_eventemitter\n */\ntype Listener = (...args: any[]) => any;\n\nexport class EventEmitterPolyfill {\n\tlisteners: Record<string, Listener[]> = {};\n\temit(eventName: string, data?: any) {\n\t\tif (this.listeners[eventName]) {\n\t\t\tthis.listeners[eventName].forEach(function (listener) {\n\t\t\t\tlistener(data);\n\t\t\t});\n\t\t}\n\t}\n\ton(eventName: string, listener: Listener) {\n\t\tif (!this.listeners[eventName]) {\n\t\t\tthis.listeners[eventName] = [];\n\t\t}\n\t\tthis.listeners[eventName].push(listener);\n\t}\n\tonce(eventName: string, listener: Listener) {\n\t\tconst wrappedListener = (...args: any[]) => {\n\t\t\tthis.off(eventName, wrappedListener);\n\t\t\tlistener(...args);\n\t\t};\n\t\tthis.on(eventName, wrappedListener);\n\t}\n\toff(eventName: string, listener: Listener) {\n\t\tif (this.listeners[eventName]) {\n\t\t\tthis.listeners[eventName] = this.listeners[eventName].filter(\n\t\t\t\t(l) => l !== listener\n\t\t\t);\n\t\t}\n\t}\n}\n","/**\n * Naive shell command parser.\n * Ensures that commands like `wp option set blogname \"My blog name\"` are split\n * into `['wp', 'option', 'set', 'blogname', 'My blog name']` instead of\n * `['wp', 'option', 'set', 'blogname', 'My', 'blog', 'name']`.\n *\n * @param command\n * @returns\n */\nexport function splitShellCommand(command: string) {\n\tconst MODE_UNQUOTED = 0;\n\tconst MODE_IN_QUOTE = 1;\n\n\tlet mode = MODE_UNQUOTED;\n\tlet quote = '';\n\n\tconst parts: string[] = [];\n\tlet currentPart = '';\n\tfor (let i = 0; i < command.length; i++) {\n\t\tconst char = command[i];\n\t\tif (char === '\\\\') {\n\t\t\t// Escaped quotes are treated as normal characters\n\t\t\t// This is a very naive approach to escaping, but it's good enough for\n\t\t\t// now. @TODO: Iterate on this later, perhaps using bun shell. @see https://github.com/WordPress/wordpress-playground/issues/1062\n\t\t\tif (command[i + 1] === '\"' || command[i + 1] === \"'\") {\n\t\t\t\ti++;\n\t\t\t}\n\t\t\tcurrentPart += command[i];\n\t\t} else if (mode === MODE_UNQUOTED) {\n\t\t\tif (char === '\"' || char === \"'\") {\n\t\t\t\tmode = MODE_IN_QUOTE;\n\t\t\t\tquote = char;\n\t\t\t} else if (char.match(/\\s/)) {\n\t\t\t\tif (currentPart.trim().length) {\n\t\t\t\t\tparts.push(currentPart.trim());\n\t\t\t\t}\n\t\t\t\tcurrentPart = char;\n\t\t\t} else if (parts.length && !currentPart) {\n\t\t\t\t// We just closed a quote to continue the same\n\t\t\t\t// argument with different escaping style, e.g.:\n\t\t\t\t// php -r 'require '\\''vendor/autoload.php'\\''\n\t\t\t\tcurrentPart = parts.pop()! + char;\n\t\t\t} else {\n\t\t\t\tcurrentPart += char;\n\t\t\t}\n\t\t} else if (mode === MODE_IN_QUOTE) {\n\t\t\tif (char === quote) {\n\t\t\t\tmode = MODE_UNQUOTED;\n\t\t\t\tquote = '';\n\t\t\t} else {\n\t\t\t\tcurrentPart += char;\n\t\t\t}\n\t\t}\n\t}\n\tif (currentPart) {\n\t\tparts.push(currentPart.trim());\n\t}\n\treturn parts;\n}\n","/**\n * Polyfills Node.js WritableStream API. The main goal is to enable\n * using a child_process.spawn()-like API in both Node.js and the browser.\n *\n * @see https://nodejs.org/api/stream.html#stream_writable_end_chunk_encoding_callback\n */\nimport { EventEmitterPolyfill } from './event-emitter-polyfill';\n\nexport interface WritableOptions {\n\thighWaterMark?: number;\n\tdecodeStrings?: boolean;\n\tdefaultEncoding?: BufferEncoding;\n\twrite: (chunk: any, encoding: BufferEncoding, cb: WriteCallback) => void;\n}\n\nexport type WriteCallback = (error?: Error | null) => void;\n\nexport class WritablePolyfill extends EventEmitterPolyfill {\n\tprivate buffer: Array<{\n\t\tchunk: any;\n\t\tencoding: BufferEncoding;\n\t\tcb: WriteCallback;\n\t}> = [];\n\tprivate writing = false;\n\tpublic ended = false;\n\tprivate length = 0;\n\tprivate highWaterMark: number;\n\tprivate decodeStrings: boolean;\n\tprivate defaultEncoding: BufferEncoding;\n\tprivate defer: (fn: () => void) => void;\n\tprivate _write: (\n\t\tchunk: any,\n\t\tencoding: BufferEncoding,\n\t\tcb: WriteCallback\n\t) => void;\n\n\tconstructor(opts: WritableOptions) {\n\t\tsuper();\n\t\tif (!opts.write) {\n\t\t\tthrow new Error('WritablePolyfill requires write option');\n\t\t}\n\t\tthis._write = opts.write;\n\t\tthis.highWaterMark = opts.highWaterMark ?? 16 * 1024;\n\t\tthis.decodeStrings = opts.decodeStrings ?? true;\n\t\tthis.defaultEncoding = opts.defaultEncoding ?? 'utf8';\n\t\t// queueMicrotask keeps browser support; fallback for older environments.\n\t\tthis.defer =\n\t\t\ttypeof queueMicrotask === 'function'\n\t\t\t\t? queueMicrotask\n\t\t\t\t: (fn) => setTimeout(fn, 0);\n\t}\n\n\twrite(\n\t\tchunk: any,\n\t\tencoding: BufferEncoding | WriteCallback = this.defaultEncoding,\n\t\tcb: WriteCallback = () => {}\n\t): boolean {\n\t\tif (typeof encoding === 'function') {\n\t\t\tcb = encoding as WriteCallback;\n\t\t\tencoding = this.defaultEncoding;\n\t\t}\n\n\t\tif (this.ended) {\n\t\t\tconst err = new Error('write after end');\n\t\t\t// We can't call this.defer() directly. If this.defer is\n\t\t\t// `queueMicrotask`, a `this.defer()` call will pass the\n\t\t\t// WritablePolyfill instance as `this` argument and cause\n\t\t\t// the browser to throw an error similar to \"Invalid\n\t\t\t// invocation\".\n\t\t\tconst defer = this.defer;\n\t\t\tdefer(() => cb(err));\n\t\t\tthis.emit('error', err);\n\t\t\treturn false;\n\t\t}\n\n\t\tif (this.decodeStrings && typeof chunk === 'string') {\n\t\t\tif (\n\t\t\t\ttypeof Buffer !== 'undefined' &&\n\t\t\t\ttypeof (Buffer as any).from === 'function'\n\t\t\t) {\n\t\t\t\tchunk = Buffer.from(chunk, encoding as BufferEncoding);\n\t\t\t} else if (typeof TextEncoder !== 'undefined') {\n\t\t\t\tchunk = new TextEncoder().encode(chunk);\n\t\t\t} else {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'String chunks are not supported in this environment: Buffer and TextEncoder are unavailable.'\n\t\t\t\t);\n\t\t\t}\n\t\t\tencoding = 'buffer' as BufferEncoding;\n\t\t}\n\n\t\tthis.length += chunk.length ?? 1;\n\t\tconst needDrain = this.length >= this.highWaterMark;\n\n\t\tthis.buffer.push({ chunk, encoding: encoding as BufferEncoding, cb });\n\n\t\tif (!this.writing) this._clearBuffer();\n\n\t\treturn !needDrain;\n\t}\n\n\tend(\n\t\tchunk?: any,\n\t\tencoding?: BufferEncoding | WriteCallback,\n\t\tcb?: WriteCallback\n\t): void {\n\t\tif (typeof chunk === 'function') {\n\t\t\tcb = chunk;\n\t\t\tchunk = undefined;\n\t\t} else if (typeof encoding === 'function') {\n\t\t\tcb = encoding as WriteCallback;\n\t\t\tencoding = undefined;\n\t\t}\n\n\t\tif (chunk !== undefined)\n\t\t\tthis.write(chunk, encoding as BufferEncoding, () => {});\n\t\tthis.ended = true;\n\t\tif (!this.writing) this._clearBuffer();\n\t\tif (cb) this.defer(cb);\n\t}\n\n\t// Stubs kept for API parity; add logic if you depend on corking.\n\tcork(): void {}\n\tuncork(): void {}\n\n\tsetDefaultEncoding(enc: BufferEncoding): this {\n\t\tthis.defaultEncoding = enc;\n\t\treturn this;\n\t}\n\n\tprivate _clearBuffer(): void {\n\t\tconst entry = this.buffer.shift();\n\t\tif (!entry) {\n\t\t\tif (this.ended) this.emit('finish');\n\t\t\treturn;\n\t\t}\n\n\t\tthis.writing = true;\n\t\tthis._write(entry.chunk, entry.encoding, (err?: Error | null) => {\n\t\t\tthis.writing = false;\n\t\t\tthis.length -= entry.chunk.length ?? 1;\n\t\t\tif (err) this.emit('error', err);\n\t\t\tentry.cb(err);\n\n\t\t\tif (this.buffer.length) {\n\t\t\t\tthis._clearBuffer();\n\t\t\t} else {\n\t\t\t\tif (this.length < this.highWaterMark) this.emit('drain');\n\t\t\t\tif (this.ended) this.emit('finish');\n\t\t\t}\n\t\t});\n\t}\n}\n","import { EventEmitterPolyfill } from './event-emitter-polyfill';\nimport { splitShellCommand } from './split-shell-command';\nimport { WritablePolyfill, type WriteCallback } from './writable-polyfill';\n\ntype Listener = (...args: any[]) => any;\n\nexport interface ProcessOptions {\n\tcwd?: string;\n\tenv?: Record<string, string>;\n}\n\n/**\n * Usage:\n * ```ts\n * php.setSpawnHandler(\n * createSpawnHandler(function (command, processApi) {\n * console.log(processApi.flushStdin());\n * processApi.stdout('/\\n/tmp\\n/home');\n *\t processApi.exit(0);\n * })\n * );\n * ```\n * @param program\n * @returns\n */\nexport function createSpawnHandler(\n\tprogram: (\n\t\tcommand: string[],\n\t\tprocessApi: ProcessApi,\n\t\toptions: ProcessOptions\n\t) => void | Promise<void>\n): any {\n\treturn function (\n\t\tcommand: string | string[],\n\t\targsArray: string[] = [],\n\t\toptions: ProcessOptions = {}\n\t) {\n\t\tconst childProcess = new ChildProcess();\n\t\tconst processApi = new ProcessApi(childProcess);\n\t\t// Give PHP a chance to register listeners\n\t\tsetTimeout(async () => {\n\t\t\tlet commandArray = [];\n\t\t\tif (argsArray.length) {\n\t\t\t\tcommandArray = [command as string, ...argsArray];\n\t\t\t} else if (typeof command === 'string') {\n\t\t\t\tcommandArray = splitShellCommand(command);\n\t\t\t} else if (Array.isArray(command)) {\n\t\t\t\tcommandArray = command;\n\t\t\t} else {\n\t\t\t\tthrow new Error('Invalid command ', command);\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tconst promise = program(commandArray, processApi, options);\n\t\t\t\tif (\n\t\t\t\t\ttypeof promise !== 'object' ||\n\t\t\t\t\tpromise === null ||\n\t\t\t\t\t!('then' in promise)\n\t\t\t\t) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`The program callback passed to createSpawnHandler() did not return a promise. It indicates there's a bug in your code. ` +\n\t\t\t\t\t\t\t`The callback must return a promise. PHP cannot interact with program that synchronously exists at the end of the proc_open() ` +\n\t\t\t\t\t\t\t`call. All the streams would be closed already. Make sure to put an \"await new Promise(resolve => setTimeout(resolve, 1))` +\n\t\t\t\t\t\t\t`before calling processApi.exit(0) in your callback to let PHP catch up with the stdout data.`\n\t\t\t\t\t);\n\t\t\t\t} else if (processApi.exited) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`The program callback passed to createSpawnHandler() exited synchronously. It indicates there's a bug in your code. ` +\n\t\t\t\t\t\t\t`The callback must return a promise. PHP cannot interact with program that synchronously exists at the end of the proc_open() ` +\n\t\t\t\t\t\t\t`call. All the streams would be closed already. Make sure to put an \"await new Promise(resolve => setTimeout(resolve, 1))` +\n\t\t\t\t\t\t\t`before calling processApi.exit(0) in your callback to let PHP catch up with the stdout data.`\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tchildProcess.emit('spawn', true);\n\t\t\t\tawait promise;\n\t\t\t} catch (e) {\n\t\t\t\tchildProcess.emit('error', e);\n\t\t\t\tif (\n\t\t\t\t\ttypeof e === 'object' &&\n\t\t\t\t\te !== null &&\n\t\t\t\t\t'message' in e &&\n\t\t\t\t\ttypeof e.message === 'string'\n\t\t\t\t) {\n\t\t\t\t\tprocessApi.stderr(e.message);\n\t\t\t\t}\n\t\t\t\tprocessApi.exit(1);\n\t\t\t}\n\t\t});\n\t\treturn childProcess;\n\t};\n}\n\nexport class ProcessApi extends EventEmitterPolyfill {\n\tpublic exited = false;\n\t/**\n\t * Keeps track of the data that was written to stdin before the\n\t * first listener was registered.\n\t */\n\tprivate stdinBuffer: Uint8Array[] | null = [];\n\tprivate childProcess: ChildProcess;\n\tconstructor(childProcess: ChildProcess) {\n\t\tsuper();\n\t\tthis.childProcess = childProcess;\n\t\tchildProcess.on('stdin', (data: Uint8Array) => {\n\t\t\tif (this.stdinBuffer) {\n\t\t\t\t// Need to clone the data buffer as it's reused by PHP\n\t\t\t\t// and the next data chunk will overwrite the previous one.\n\t\t\t\tthis.stdinBuffer.push(data.slice());\n\t\t\t} else {\n\t\t\t\tthis.emit('stdin', data);\n\t\t\t}\n\t\t});\n\t}\n\tstdinEnd() {\n\t\tif (!this.childProcess.stdin.ended) {\n\t\t\tthis.childProcess.stdin.end();\n\t\t}\n\t}\n\tstdout(data: string | ArrayBuffer) {\n\t\tthis.childProcess.stdout.write(data);\n\t}\n\tstdoutEnd() {\n\t\tif (!this.childProcess.stdout.ended) {\n\t\t\tthis.childProcess.stdout.end();\n\t\t}\n\t}\n\tstderr(data: string | ArrayBuffer) {\n\t\tthis.childProcess.stderr.write(data);\n\t}\n\tstderrEnd() {\n\t\tif (!this.childProcess.stderr.ended) {\n\t\t\tthis.childProcess.stderr.end();\n\t\t}\n\t}\n\tnotifySpawn() {\n\t\tthis.childProcess.emit('spawn', true);\n\t}\n\texit(code: number) {\n\t\tif (!this.exited) {\n\t\t\tthis.exited = true;\n\t\t\tthis.stdinEnd();\n\t\t\tthis.stdoutEnd();\n\t\t\tthis.stderrEnd();\n\t\t\tthis.childProcess.emit('exit', code);\n\t\t}\n\t}\n\toverride on(eventName: string, listener: Listener) {\n\t\tsuper.on(eventName, listener);\n\t\t/**\n\t\t * If it's the first stdin listener, flush all the data we've\n\t\t * buffered so far.\n\t\t */\n\t\tif (eventName === 'stdin' && this.stdinBuffer) {\n\t\t\tfor (let i = 0; i < this.stdinBuffer.length; i++) {\n\t\t\t\tthis.emit('stdin', this.stdinBuffer[i]);\n\t\t\t}\n\t\t\tthis.stdinBuffer = null;\n\t\t}\n\t}\n}\n\nlet lastPid = 9743;\nexport class ChildProcess extends EventEmitterPolyfill {\n\tstdout: WritablePolyfill;\n\tstderr: WritablePolyfill;\n\tstdin: WritablePolyfill;\n\tpid: number;\n\tconstructor(pid = lastPid++) {\n\t\tsuper();\n\t\tthis.pid = pid;\n\t\t// eslint-disable-next-line @typescript-eslint/no-this-alias\n\t\tconst self = this;\n\t\tthis.stdout = new WritablePolyfill({\n\t\t\twrite(data: any, encoding: BufferEncoding, cb: WriteCallback) {\n\t\t\t\tself.stdout.emit('data', data);\n\t\t\t\tcb();\n\t\t\t},\n\t\t});\n\t\tthis.stderr = new WritablePolyfill({\n\t\t\twrite: (data: any, encoding: BufferEncoding, cb: WriteCallback) => {\n\t\t\t\tself.stderr.emit('data', data);\n\t\t\t\tcb();\n\t\t\t},\n\t\t});\n\t\tthis.stdin = new WritablePolyfill({\n\t\t\twrite: (data: any, encoding: BufferEncoding, cb: WriteCallback) => {\n\t\t\t\tself.emit('stdin', data);\n\t\t\t\tcb();\n\t\t\t},\n\t\t});\n\t}\n}\n","export function randomString(\n\tlength = 36,\n\tspecialChars = '!@#$%^&*()_+=-[]/.,<>?'\n) {\n\tconst chars =\n\t\t'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' +\n\t\tspecialChars;\n\tlet result = '';\n\tfor (let i = length; i > 0; --i)\n\t\tresult += chars[Math.floor(Math.random() * chars.length)];\n\treturn result;\n}\n","import { randomString } from './random-string';\n\nexport function randomFilename() {\n\treturn randomString(36, '-_');\n}\n","export function phpVar(value: unknown): string {\n\treturn `json_decode(base64_decode('${stringToBase64(\n\t\tJSON.stringify(value)\n\t)}'), true)`;\n}\n\nexport function phpVars<T extends Record<string, unknown>>(\n\tvars: T\n): Record<keyof T, string> {\n\tconst result: Record<string, string> = {};\n\tfor (const key in vars) {\n\t\tresult[key] = phpVar(vars[key]);\n\t}\n\treturn result as Record<keyof T, string>;\n}\n\nfunction stringToBase64(str: string) {\n\treturn bytesToBase64(new TextEncoder().encode(str));\n}\n\nfunction bytesToBase64(bytes: Uint8Array) {\n\tconst binString = String.fromCodePoint(...bytes);\n\treturn btoa(binString);\n}\n","/**\n * Formats a string like sprintf().\n *\n * This function:\n * - Supports basic format specifiers: %s, %d, %f, %x, %%\n * - Supports bigint values\n *\n * The purpose of this function is for use in optional php-wasm tracing.\n * If we use printf-style formatting for trace messages, we let the trace\n * function decide whether to format and do not have to pay for formatting\n * unless tracing is enabled.\n */\nexport function sprintf(format: string, ...args: any[]): string {\n\tlet result = '';\n\tlet argIndex = 0;\n\n\tfor (let i = 0; i < format.length; i++) {\n\t\tif (format[i] === '%' && i + 1 < format.length) {\n\t\t\ti++;\n\t\t\tconst specifier = format[i];\n\n\t\t\tswitch (specifier) {\n\t\t\t\tcase 's': {\n\t\t\t\t\tconst arg = args[argIndex++];\n\t\t\t\t\tlet str;\n\t\t\t\t\tif (typeof arg === 'object') {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t// If an object doesn't provide its own toString(),\n\t\t\t\t\t\t\t// try to represent it as JSON.\n\t\t\t\t\t\t\tstr = JSON.stringify(\n\t\t\t\t\t\t\t\targ,\n\t\t\t\t\t\t\t\t// Represent bigint values as strings in JSON.stringify().\n\t\t\t\t\t\t\t\t(key, value) => {\n\t\t\t\t\t\t\t\t\tif (typeof value === 'bigint') {\n\t\t\t\t\t\t\t\t\t\treturn `0x${value.toString(16)}`;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\treturn value;\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t2\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t// Ignore error and use default representation.\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tstr = String(arg);\n\t\t\t\t\t}\n\n\t\t\t\t\tresult += str;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase 'd': {\n\t\t\t\t\tconst arg = args[argIndex++];\n\t\t\t\t\tif (typeof arg === 'bigint') {\n\t\t\t\t\t\tresult += arg.toString();\n\t\t\t\t\t} else {\n\t\t\t\t\t\tresult += Math.floor(Number(arg));\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase 'f': {\n\t\t\t\t\tconst arg = args[argIndex++];\n\t\t\t\t\tif (typeof arg === 'bigint') {\n\t\t\t\t\t\tresult += Number(arg);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tresult += Number(arg);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase 'x': {\n\t\t\t\t\tconst arg = args[argIndex++];\n\t\t\t\t\tif (typeof arg === 'bigint') {\n\t\t\t\t\t\tresult += arg.toString(16);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tresult += Math.floor(Number(arg)).toString(16);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase '%': {\n\t\t\t\t\tresult += '%';\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\tresult += '%' + specifier;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tresult += format[i];\n\t\t}\n\t}\n\n\treturn result;\n}\n","import Semaphore, { AcquireTimeoutError } from './semaphore';\nexport { Semaphore, AcquireTimeoutError };\nexport { PhpWasmError } from './php-wasm-error';\nexport type { SemaphoreOptions } from './semaphore';\nexport {\n\tdirname,\n\tjoinPaths,\n\tbasename,\n\tnormalizePath,\n\tisParentOf,\n} from './paths';\nexport { createSpawnHandler } from './create-spawn-handler';\nexport { randomString } from './random-string';\nexport { randomFilename } from './random-filename';\nexport { WritablePolyfill, type WritableOptions } from './writable-polyfill';\nexport { EventEmitterPolyfill } from './event-emitter-polyfill';\nexport * from './php-vars';\n\nexport * from './sprintf';\n\nexport function concatUint8Arrays(arrays: Uint8Array[]): Uint8Array {\n\tlet totalLength = 0;\n\tarrays.forEach((a) => (totalLength += a.length));\n\tconst result = new Uint8Array(totalLength);\n\tlet offset = 0;\n\tarrays.forEach((a) => {\n\t\tresult.set(a, offset);\n\t\toffset += a.length;\n\t});\n\treturn result;\n}\n\nexport function concatArrayBuffers(buffers: ArrayBuffer[]): ArrayBuffer {\n\treturn concatUint8Arrays(buffers.map((b) => new Uint8Array(b)))\n\t\t.buffer as ArrayBuffer;\n}\n\nexport * from './types';\n"],"names":["SleepFinished","sleep","ms","resolve","AcquireTimeoutError","Semaphore","concurrency","timeout","acquired","value","released","fn","release","PhpWasmError","message","userFriendlyMessage","joinPaths","paths","hasTrailingSlash","p","path","isAbsolute","trailingSlash","normalizePath","dirname","lastSlash","basename","normalizePathsArray","parts","allowAboveRoot","up","i","last","isParentOf","parent","child","EventEmitterPolyfill","eventName","data","listener","wrappedListener","args","l","splitShellCommand","command","mode","quote","currentPart","char","WritablePolyfill","opts","chunk","encoding","cb","err","defer","needDrain","enc","entry","createSpawnHandler","program","argsArray","options","childProcess","ChildProcess","processApi","ProcessApi","commandArray","promise","e","code","lastPid","pid","self","randomString","length","specialChars","chars","result","randomFilename","phpVar","stringToBase64","phpVars","vars","key","str","bytesToBase64","bytes","binString","sprintf","format","argIndex","specifier","arg","concatUint8Arrays","arrays","totalLength","a","offset","concatArrayBuffers","buffers","b"],"mappings":"gFAAa,MAAAA,EAAgB,OAAO,eAAe,EAE5C,SAASC,EAAMC,EAA2C,CACzD,OAAA,IAAI,QAASC,GAAY,CAC/B,WAAW,IAAMA,EAAQH,CAAa,EAAGE,CAAE,CAAA,CAC3C,CACF,CCOO,MAAME,UAA4B,KAAM,CAC9C,aAAc,CACb,MAAM,0BAA0B,CAAA,CAElC,CAEA,MAAqBC,CAAU,CAM9B,YAAY,CAAE,YAAAC,EAAa,QAAAC,GAA6B,CALxD,KAAQ,SAAW,EAMlB,KAAK,YAAcD,EACnB,KAAK,QAAUC,EACf,KAAK,MAAQ,CAAC,CAAA,CAGf,IAAI,WAAoB,CAChB,OAAA,KAAK,YAAc,KAAK,OAAA,CAGhC,IAAI,SAAkB,CACrB,OAAO,KAAK,QAAA,CAGb,MAAM,SAA+B,CACpC,OACK,GAAA,KAAK,UAAY,KAAK,YAAa,CAEtC,MAAMC,EAAW,IAAI,QAAeL,GAAY,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,CAAW,EACzC,IAAIE,EAAS,EACN,OAAAH,EAAA,QAASE,GAAM,CACdnB,EAAA,IAAImB,EAAGC,CAAM,EACpBA,GAAUD,EAAE,MAAA,CACZ,EACMnB,CACR,CAEO,SAASqB,EAAmBC,EAAqC,CAChE,OAAAN,EAAkBM,EAAQ,IAAKC,GAAM,IAAI,WAAWA,CAAC,CAAC,CAAC,EAC5D,MACH"}
|
package/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const d = Symbol("SleepFinished");
|
|
2
2
|
function g(i) {
|
|
3
|
-
return new Promise((
|
|
4
|
-
setTimeout(() =>
|
|
3
|
+
return new Promise((e) => {
|
|
4
|
+
setTimeout(() => e(d), i);
|
|
5
5
|
});
|
|
6
6
|
}
|
|
7
7
|
class w extends Error {
|
|
@@ -10,8 +10,8 @@ class w extends Error {
|
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
class M {
|
|
13
|
-
constructor({ concurrency:
|
|
14
|
-
this._running = 0, this.concurrency =
|
|
13
|
+
constructor({ concurrency: e, timeout: t }) {
|
|
14
|
+
this._running = 0, this.concurrency = e, this.timeout = t, this.queue = [];
|
|
15
15
|
}
|
|
16
16
|
get remaining() {
|
|
17
17
|
return this.concurrency - this.running;
|
|
@@ -22,169 +22,180 @@ class M {
|
|
|
22
22
|
async acquire() {
|
|
23
23
|
for (; ; )
|
|
24
24
|
if (this._running >= this.concurrency) {
|
|
25
|
-
const
|
|
26
|
-
this.queue.push(
|
|
25
|
+
const e = new Promise((t) => {
|
|
26
|
+
this.queue.push(t);
|
|
27
27
|
});
|
|
28
|
-
this.timeout !== void 0 ? await Promise.race([
|
|
29
|
-
(
|
|
30
|
-
if (
|
|
28
|
+
this.timeout !== void 0 ? await Promise.race([e, g(this.timeout)]).then(
|
|
29
|
+
(t) => {
|
|
30
|
+
if (t === d)
|
|
31
31
|
throw new w();
|
|
32
32
|
}
|
|
33
|
-
) : await
|
|
33
|
+
) : await e;
|
|
34
34
|
} else {
|
|
35
35
|
this._running++;
|
|
36
|
-
let
|
|
36
|
+
let e = !1;
|
|
37
37
|
return () => {
|
|
38
|
-
|
|
38
|
+
e || (e = !0, this._running--, this.queue.length > 0 && this.queue.shift()());
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
-
async run(
|
|
43
|
-
const
|
|
42
|
+
async run(e) {
|
|
43
|
+
const t = await this.acquire();
|
|
44
44
|
try {
|
|
45
|
-
return await
|
|
45
|
+
return await e();
|
|
46
46
|
} finally {
|
|
47
|
-
|
|
47
|
+
t();
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
class O extends Error {
|
|
52
|
-
constructor(
|
|
53
|
-
super(
|
|
52
|
+
constructor(e, t) {
|
|
53
|
+
super(e), this.userFriendlyMessage = t ?? e;
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
-
function
|
|
57
|
-
function
|
|
56
|
+
function B(...i) {
|
|
57
|
+
function e(o) {
|
|
58
58
|
return o.substring(o.length - 1) === "/";
|
|
59
59
|
}
|
|
60
|
-
let
|
|
61
|
-
const
|
|
62
|
-
return
|
|
60
|
+
let t = i.join("/");
|
|
61
|
+
const r = t[0] === "/", s = e(t);
|
|
62
|
+
return t = u(t), !t && !r && (t = "."), t && s && !e(t) && (t += "/"), t;
|
|
63
63
|
}
|
|
64
|
-
function
|
|
64
|
+
function k(i) {
|
|
65
65
|
if (i === "/")
|
|
66
66
|
return "/";
|
|
67
|
-
i =
|
|
68
|
-
const
|
|
69
|
-
return
|
|
67
|
+
i = u(i);
|
|
68
|
+
const e = i.lastIndexOf("/");
|
|
69
|
+
return e === -1 ? "" : e === 0 ? "/" : i.substr(0, e);
|
|
70
70
|
}
|
|
71
|
-
function
|
|
71
|
+
function A(i) {
|
|
72
72
|
if (i === "/")
|
|
73
73
|
return "/";
|
|
74
|
-
i =
|
|
75
|
-
const
|
|
76
|
-
return
|
|
74
|
+
i = u(i);
|
|
75
|
+
const e = i.lastIndexOf("/");
|
|
76
|
+
return e === -1 ? i : i.substr(e + 1);
|
|
77
77
|
}
|
|
78
|
-
function
|
|
79
|
-
const
|
|
78
|
+
function u(i) {
|
|
79
|
+
const e = i[0] === "/";
|
|
80
80
|
return i = p(
|
|
81
|
-
i.split("/").filter((
|
|
82
|
-
!
|
|
83
|
-
).join("/"), (
|
|
81
|
+
i.split("/").filter((t) => !!t),
|
|
82
|
+
!e
|
|
83
|
+
).join("/"), (e ? "/" : "") + i.replace(/\/$/, "");
|
|
84
84
|
}
|
|
85
|
-
function p(i,
|
|
86
|
-
let
|
|
87
|
-
for (let
|
|
88
|
-
const
|
|
89
|
-
|
|
85
|
+
function p(i, e) {
|
|
86
|
+
let t = 0;
|
|
87
|
+
for (let r = i.length - 1; r >= 0; r--) {
|
|
88
|
+
const s = i[r];
|
|
89
|
+
s === "." ? i.splice(r, 1) : s === ".." ? (i.splice(r, 1), t++) : t && (i.splice(r, 1), t--);
|
|
90
90
|
}
|
|
91
|
-
if (
|
|
92
|
-
for (;
|
|
91
|
+
if (e)
|
|
92
|
+
for (; t; t--)
|
|
93
93
|
i.unshift("..");
|
|
94
94
|
return i;
|
|
95
95
|
}
|
|
96
|
-
function U(i,
|
|
97
|
-
return i === "/" ? !0 : (i =
|
|
96
|
+
function U(i, e) {
|
|
97
|
+
return i === "/" ? !0 : (i = u(i), e = u(e), e.startsWith(i + "/") || e === i);
|
|
98
98
|
}
|
|
99
99
|
class a {
|
|
100
100
|
constructor() {
|
|
101
101
|
this.listeners = {};
|
|
102
102
|
}
|
|
103
|
-
emit(
|
|
104
|
-
this.listeners[
|
|
105
|
-
|
|
103
|
+
emit(e, t) {
|
|
104
|
+
this.listeners[e] && this.listeners[e].forEach(function(r) {
|
|
105
|
+
r(t);
|
|
106
106
|
});
|
|
107
107
|
}
|
|
108
|
-
on(
|
|
109
|
-
this.listeners[
|
|
108
|
+
on(e, t) {
|
|
109
|
+
this.listeners[e] || (this.listeners[e] = []), this.listeners[e].push(t);
|
|
110
110
|
}
|
|
111
|
-
once(
|
|
112
|
-
const
|
|
113
|
-
this.off(
|
|
111
|
+
once(e, t) {
|
|
112
|
+
const r = (...s) => {
|
|
113
|
+
this.off(e, r), t(...s);
|
|
114
114
|
};
|
|
115
|
-
this.on(
|
|
115
|
+
this.on(e, r);
|
|
116
116
|
}
|
|
117
|
-
off(
|
|
118
|
-
this.listeners[
|
|
119
|
-
(
|
|
117
|
+
off(e, t) {
|
|
118
|
+
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter(
|
|
119
|
+
(r) => r !== t
|
|
120
120
|
));
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
123
|
function y(i) {
|
|
124
|
-
let
|
|
124
|
+
let r = 0, s = "";
|
|
125
125
|
const o = [];
|
|
126
126
|
let n = "";
|
|
127
|
-
for (let
|
|
128
|
-
const
|
|
129
|
-
|
|
127
|
+
for (let f = 0; f < i.length; f++) {
|
|
128
|
+
const l = i[f];
|
|
129
|
+
l === "\\" ? ((i[f + 1] === '"' || i[f + 1] === "'") && f++, n += i[f]) : r === 0 ? l === '"' || l === "'" ? (r = 1, s = l) : l.match(/\s/) ? (n.trim().length && o.push(n.trim()), n = l) : o.length && !n ? n = o.pop() + l : n += l : r === 1 && (l === s ? (r = 0, s = "") : n += l);
|
|
130
130
|
}
|
|
131
131
|
return n && o.push(n.trim()), o;
|
|
132
132
|
}
|
|
133
133
|
class c extends a {
|
|
134
|
-
constructor(
|
|
135
|
-
if (super(), this.buffer = [], this.writing = !1, this.ended = !1, this.length = 0, !
|
|
134
|
+
constructor(e) {
|
|
135
|
+
if (super(), this.buffer = [], this.writing = !1, this.ended = !1, this.length = 0, !e.write)
|
|
136
136
|
throw new Error("WritablePolyfill requires write option");
|
|
137
|
-
this._write =
|
|
137
|
+
this._write = e.write, this.highWaterMark = e.highWaterMark ?? 16 * 1024, this.decodeStrings = e.decodeStrings ?? !0, this.defaultEncoding = e.defaultEncoding ?? "utf8", this.defer = typeof queueMicrotask == "function" ? queueMicrotask : (t) => setTimeout(t, 0);
|
|
138
138
|
}
|
|
139
|
-
write(
|
|
139
|
+
write(e, t = this.defaultEncoding, r = () => {
|
|
140
140
|
}) {
|
|
141
|
-
if (typeof
|
|
142
|
-
const o = new Error("write after end");
|
|
143
|
-
return
|
|
141
|
+
if (typeof t == "function" && (r = t, t = this.defaultEncoding), this.ended) {
|
|
142
|
+
const o = new Error("write after end"), n = this.defer;
|
|
143
|
+
return n(() => r(o)), this.emit("error", o), !1;
|
|
144
144
|
}
|
|
145
|
-
this.decodeStrings && typeof
|
|
146
|
-
|
|
147
|
-
|
|
145
|
+
if (this.decodeStrings && typeof e == "string") {
|
|
146
|
+
if (typeof Buffer < "u" && typeof Buffer.from == "function")
|
|
147
|
+
e = Buffer.from(e, t);
|
|
148
|
+
else if (typeof TextEncoder < "u")
|
|
149
|
+
e = new TextEncoder().encode(e);
|
|
150
|
+
else
|
|
151
|
+
throw new Error(
|
|
152
|
+
"String chunks are not supported in this environment: Buffer and TextEncoder are unavailable."
|
|
153
|
+
);
|
|
154
|
+
t = "buffer";
|
|
155
|
+
}
|
|
156
|
+
this.length += e.length ?? 1;
|
|
157
|
+
const s = this.length >= this.highWaterMark;
|
|
158
|
+
return this.buffer.push({ chunk: e, encoding: t, cb: r }), this.writing || this._clearBuffer(), !s;
|
|
148
159
|
}
|
|
149
|
-
end(
|
|
150
|
-
typeof
|
|
151
|
-
}), this.ended = !0, this.writing || this._clearBuffer(),
|
|
160
|
+
end(e, t, r) {
|
|
161
|
+
typeof e == "function" ? (r = e, e = void 0) : typeof t == "function" && (r = t, t = void 0), e !== void 0 && this.write(e, t, () => {
|
|
162
|
+
}), this.ended = !0, this.writing || this._clearBuffer(), r && this.defer(r);
|
|
152
163
|
}
|
|
153
164
|
// Stubs kept for API parity; add logic if you depend on corking.
|
|
154
165
|
cork() {
|
|
155
166
|
}
|
|
156
167
|
uncork() {
|
|
157
168
|
}
|
|
158
|
-
setDefaultEncoding(
|
|
159
|
-
return this.defaultEncoding =
|
|
169
|
+
setDefaultEncoding(e) {
|
|
170
|
+
return this.defaultEncoding = e, this;
|
|
160
171
|
}
|
|
161
172
|
_clearBuffer() {
|
|
162
|
-
const
|
|
163
|
-
if (!
|
|
173
|
+
const e = this.buffer.shift();
|
|
174
|
+
if (!e) {
|
|
164
175
|
this.ended && this.emit("finish");
|
|
165
176
|
return;
|
|
166
177
|
}
|
|
167
|
-
this.writing = !0, this._write(
|
|
168
|
-
this.writing = !1, this.length -=
|
|
178
|
+
this.writing = !0, this._write(e.chunk, e.encoding, (t) => {
|
|
179
|
+
this.writing = !1, this.length -= e.chunk.length ?? 1, t && this.emit("error", t), e.cb(t), this.buffer.length ? this._clearBuffer() : (this.length < this.highWaterMark && this.emit("drain"), this.ended && this.emit("finish"));
|
|
169
180
|
});
|
|
170
181
|
}
|
|
171
182
|
}
|
|
172
183
|
function q(i) {
|
|
173
|
-
return function(
|
|
174
|
-
const
|
|
184
|
+
return function(e, t = [], r = {}) {
|
|
185
|
+
const s = new b(), o = new m(s);
|
|
175
186
|
return setTimeout(async () => {
|
|
176
187
|
let n = [];
|
|
177
|
-
if (
|
|
178
|
-
n = [
|
|
179
|
-
else if (typeof
|
|
180
|
-
n = y(
|
|
181
|
-
else if (Array.isArray(
|
|
182
|
-
n =
|
|
188
|
+
if (t.length)
|
|
189
|
+
n = [e, ...t];
|
|
190
|
+
else if (typeof e == "string")
|
|
191
|
+
n = y(e);
|
|
192
|
+
else if (Array.isArray(e))
|
|
193
|
+
n = e;
|
|
183
194
|
else
|
|
184
|
-
throw new Error("Invalid command ",
|
|
195
|
+
throw new Error("Invalid command ", e);
|
|
185
196
|
try {
|
|
186
|
-
const
|
|
187
|
-
if (typeof
|
|
197
|
+
const f = i(n, o, r);
|
|
198
|
+
if (typeof f != "object" || f === null || !("then" in f))
|
|
188
199
|
throw new Error(
|
|
189
200
|
`The program callback passed to createSpawnHandler() did not return a promise. It indicates there's a bug in your code. The callback must return a promise. PHP cannot interact with program that synchronously exists at the end of the proc_open() call. All the streams would be closed already. Make sure to put an "await new Promise(resolve => setTimeout(resolve, 1))before calling processApi.exit(0) in your callback to let PHP catch up with the stdout data.`
|
|
190
201
|
);
|
|
@@ -192,30 +203,30 @@ function q(i) {
|
|
|
192
203
|
throw new Error(
|
|
193
204
|
`The program callback passed to createSpawnHandler() exited synchronously. It indicates there's a bug in your code. The callback must return a promise. PHP cannot interact with program that synchronously exists at the end of the proc_open() call. All the streams would be closed already. Make sure to put an "await new Promise(resolve => setTimeout(resolve, 1))before calling processApi.exit(0) in your callback to let PHP catch up with the stdout data.`
|
|
194
205
|
);
|
|
195
|
-
|
|
196
|
-
} catch (
|
|
197
|
-
|
|
206
|
+
s.emit("spawn", !0), await f;
|
|
207
|
+
} catch (f) {
|
|
208
|
+
s.emit("error", f), typeof f == "object" && f !== null && "message" in f && typeof f.message == "string" && o.stderr(f.message), o.exit(1);
|
|
198
209
|
}
|
|
199
|
-
}),
|
|
210
|
+
}), s;
|
|
200
211
|
};
|
|
201
212
|
}
|
|
202
213
|
class m extends a {
|
|
203
|
-
constructor(
|
|
204
|
-
super(), this.exited = !1, this.stdinBuffer = [], this.childProcess =
|
|
205
|
-
this.stdinBuffer ? this.stdinBuffer.push(
|
|
214
|
+
constructor(e) {
|
|
215
|
+
super(), this.exited = !1, this.stdinBuffer = [], this.childProcess = e, e.on("stdin", (t) => {
|
|
216
|
+
this.stdinBuffer ? this.stdinBuffer.push(t.slice()) : this.emit("stdin", t);
|
|
206
217
|
});
|
|
207
218
|
}
|
|
208
219
|
stdinEnd() {
|
|
209
220
|
this.childProcess.stdin.ended || this.childProcess.stdin.end();
|
|
210
221
|
}
|
|
211
|
-
stdout(
|
|
212
|
-
this.childProcess.stdout.write(
|
|
222
|
+
stdout(e) {
|
|
223
|
+
this.childProcess.stdout.write(e);
|
|
213
224
|
}
|
|
214
225
|
stdoutEnd() {
|
|
215
226
|
this.childProcess.stdout.ended || this.childProcess.stdout.end();
|
|
216
227
|
}
|
|
217
|
-
stderr(
|
|
218
|
-
this.childProcess.stderr.write(
|
|
228
|
+
stderr(e) {
|
|
229
|
+
this.childProcess.stderr.write(e);
|
|
219
230
|
}
|
|
220
231
|
stderrEnd() {
|
|
221
232
|
this.childProcess.stderr.ended || this.childProcess.stderr.end();
|
|
@@ -223,127 +234,127 @@ class m extends a {
|
|
|
223
234
|
notifySpawn() {
|
|
224
235
|
this.childProcess.emit("spawn", !0);
|
|
225
236
|
}
|
|
226
|
-
exit(
|
|
227
|
-
this.exited || (this.exited = !0, this.stdinEnd(), this.stdoutEnd(), this.stderrEnd(), this.childProcess.emit("exit",
|
|
237
|
+
exit(e) {
|
|
238
|
+
this.exited || (this.exited = !0, this.stdinEnd(), this.stdoutEnd(), this.stderrEnd(), this.childProcess.emit("exit", e));
|
|
228
239
|
}
|
|
229
|
-
on(
|
|
230
|
-
if (super.on(
|
|
231
|
-
for (let
|
|
232
|
-
this.emit("stdin", this.stdinBuffer[
|
|
240
|
+
on(e, t) {
|
|
241
|
+
if (super.on(e, t), e === "stdin" && this.stdinBuffer) {
|
|
242
|
+
for (let r = 0; r < this.stdinBuffer.length; r++)
|
|
243
|
+
this.emit("stdin", this.stdinBuffer[r]);
|
|
233
244
|
this.stdinBuffer = null;
|
|
234
245
|
}
|
|
235
246
|
}
|
|
236
247
|
}
|
|
237
|
-
let
|
|
238
|
-
class
|
|
239
|
-
constructor(
|
|
240
|
-
super(), this.pid =
|
|
241
|
-
const
|
|
248
|
+
let E = 9743;
|
|
249
|
+
class b extends a {
|
|
250
|
+
constructor(e = E++) {
|
|
251
|
+
super(), this.pid = e;
|
|
252
|
+
const t = this;
|
|
242
253
|
this.stdout = new c({
|
|
243
|
-
write(
|
|
244
|
-
|
|
254
|
+
write(r, s, o) {
|
|
255
|
+
t.stdout.emit("data", r), o();
|
|
245
256
|
}
|
|
246
257
|
}), this.stderr = new c({
|
|
247
|
-
write: (
|
|
248
|
-
|
|
258
|
+
write: (r, s, o) => {
|
|
259
|
+
t.stderr.emit("data", r), o();
|
|
249
260
|
}
|
|
250
261
|
}), this.stdin = new c({
|
|
251
|
-
write: (
|
|
252
|
-
|
|
262
|
+
write: (r, s, o) => {
|
|
263
|
+
t.emit("stdin", r), o();
|
|
253
264
|
}
|
|
254
265
|
});
|
|
255
266
|
}
|
|
256
267
|
}
|
|
257
|
-
function P(i = 36,
|
|
258
|
-
const
|
|
259
|
-
let
|
|
260
|
-
for (let
|
|
261
|
-
|
|
262
|
-
return
|
|
268
|
+
function P(i = 36, e = "!@#$%^&*()_+=-[]/.,<>?") {
|
|
269
|
+
const t = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" + e;
|
|
270
|
+
let r = "";
|
|
271
|
+
for (let s = i; s > 0; --s)
|
|
272
|
+
r += t[Math.floor(Math.random() * t.length)];
|
|
273
|
+
return r;
|
|
263
274
|
}
|
|
264
275
|
function D() {
|
|
265
276
|
return P(36, "-_");
|
|
266
277
|
}
|
|
267
|
-
function
|
|
268
|
-
return `json_decode(base64_decode('${
|
|
278
|
+
function x(i) {
|
|
279
|
+
return `json_decode(base64_decode('${S(
|
|
269
280
|
JSON.stringify(i)
|
|
270
281
|
)}'), true)`;
|
|
271
282
|
}
|
|
272
283
|
function I(i) {
|
|
273
|
-
const
|
|
274
|
-
for (const
|
|
275
|
-
t
|
|
276
|
-
return
|
|
284
|
+
const e = {};
|
|
285
|
+
for (const t in i)
|
|
286
|
+
e[t] = x(i[t]);
|
|
287
|
+
return e;
|
|
277
288
|
}
|
|
278
|
-
function
|
|
279
|
-
return
|
|
289
|
+
function S(i) {
|
|
290
|
+
return _(new TextEncoder().encode(i));
|
|
280
291
|
}
|
|
281
|
-
function
|
|
282
|
-
const
|
|
283
|
-
return btoa(
|
|
292
|
+
function _(i) {
|
|
293
|
+
const e = String.fromCodePoint(...i);
|
|
294
|
+
return btoa(e);
|
|
284
295
|
}
|
|
285
|
-
function W(i, ...
|
|
286
|
-
let
|
|
287
|
-
for (let
|
|
288
|
-
if (i[
|
|
289
|
-
|
|
290
|
-
const o = i[
|
|
296
|
+
function W(i, ...e) {
|
|
297
|
+
let t = "", r = 0;
|
|
298
|
+
for (let s = 0; s < i.length; s++)
|
|
299
|
+
if (i[s] === "%" && s + 1 < i.length) {
|
|
300
|
+
s++;
|
|
301
|
+
const o = i[s];
|
|
291
302
|
switch (o) {
|
|
292
303
|
case "s": {
|
|
293
|
-
const n =
|
|
294
|
-
let
|
|
304
|
+
const n = e[r++];
|
|
305
|
+
let f;
|
|
295
306
|
if (typeof n == "object")
|
|
296
307
|
try {
|
|
297
|
-
|
|
308
|
+
f = JSON.stringify(
|
|
298
309
|
n,
|
|
299
310
|
// Represent bigint values as strings in JSON.stringify().
|
|
300
|
-
(
|
|
311
|
+
(l, h) => typeof h == "bigint" ? `0x${h.toString(16)}` : h,
|
|
301
312
|
2
|
|
302
313
|
);
|
|
303
314
|
} catch {
|
|
304
315
|
}
|
|
305
316
|
else
|
|
306
|
-
|
|
307
|
-
|
|
317
|
+
f = String(n);
|
|
318
|
+
t += f;
|
|
308
319
|
break;
|
|
309
320
|
}
|
|
310
321
|
case "d": {
|
|
311
|
-
const n =
|
|
312
|
-
typeof n == "bigint" ?
|
|
322
|
+
const n = e[r++];
|
|
323
|
+
typeof n == "bigint" ? t += n.toString() : t += Math.floor(Number(n));
|
|
313
324
|
break;
|
|
314
325
|
}
|
|
315
326
|
case "f": {
|
|
316
|
-
const n =
|
|
317
|
-
|
|
327
|
+
const n = e[r++];
|
|
328
|
+
t += Number(n);
|
|
318
329
|
break;
|
|
319
330
|
}
|
|
320
331
|
case "x": {
|
|
321
|
-
const n =
|
|
322
|
-
typeof n == "bigint" ?
|
|
332
|
+
const n = e[r++];
|
|
333
|
+
typeof n == "bigint" ? t += n.toString(16) : t += Math.floor(Number(n)).toString(16);
|
|
323
334
|
break;
|
|
324
335
|
}
|
|
325
336
|
case "%": {
|
|
326
|
-
|
|
337
|
+
t += "%";
|
|
327
338
|
break;
|
|
328
339
|
}
|
|
329
340
|
default:
|
|
330
|
-
|
|
341
|
+
t += "%" + o;
|
|
331
342
|
}
|
|
332
343
|
} else
|
|
333
|
-
|
|
334
|
-
return
|
|
344
|
+
t += i[s];
|
|
345
|
+
return t;
|
|
335
346
|
}
|
|
336
347
|
function T(i) {
|
|
337
|
-
let
|
|
338
|
-
i.forEach((
|
|
339
|
-
const
|
|
340
|
-
let
|
|
341
|
-
return i.forEach((
|
|
342
|
-
|
|
343
|
-
}),
|
|
348
|
+
let e = 0;
|
|
349
|
+
i.forEach((s) => e += s.length);
|
|
350
|
+
const t = new Uint8Array(e);
|
|
351
|
+
let r = 0;
|
|
352
|
+
return i.forEach((s) => {
|
|
353
|
+
t.set(s, r), r += s.length;
|
|
354
|
+
}), t;
|
|
344
355
|
}
|
|
345
356
|
function j(i) {
|
|
346
|
-
return T(i.map((
|
|
357
|
+
return T(i.map((e) => new Uint8Array(e))).buffer;
|
|
347
358
|
}
|
|
348
359
|
export {
|
|
349
360
|
w as AcquireTimeoutError,
|
|
@@ -351,15 +362,15 @@ export {
|
|
|
351
362
|
O as PhpWasmError,
|
|
352
363
|
M as Semaphore,
|
|
353
364
|
c as WritablePolyfill,
|
|
354
|
-
|
|
365
|
+
A as basename,
|
|
355
366
|
j as concatArrayBuffers,
|
|
356
367
|
T as concatUint8Arrays,
|
|
357
368
|
q as createSpawnHandler,
|
|
358
|
-
|
|
369
|
+
k as dirname,
|
|
359
370
|
U as isParentOf,
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
371
|
+
B as joinPaths,
|
|
372
|
+
u as normalizePath,
|
|
373
|
+
x as phpVar,
|
|
363
374
|
I as phpVars,
|
|
364
375
|
D as randomFilename,
|
|
365
376
|
P as randomString,
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../packages/php-wasm/util/src/lib/sleep.ts","../../../../packages/php-wasm/util/src/lib/semaphore.ts","../../../../packages/php-wasm/util/src/lib/php-wasm-error.ts","../../../../packages/php-wasm/util/src/lib/paths.ts","../../../../packages/php-wasm/util/src/lib/event-emitter-polyfill.ts","../../../../packages/php-wasm/util/src/lib/split-shell-command.ts","../../../../packages/php-wasm/util/src/lib/writable-polyfill.ts","../../../../packages/php-wasm/util/src/lib/create-spawn-handler.ts","../../../../packages/php-wasm/util/src/lib/random-string.ts","../../../../packages/php-wasm/util/src/lib/random-filename.ts","../../../../packages/php-wasm/util/src/lib/php-vars.ts","../../../../packages/php-wasm/util/src/lib/sprintf.ts","../../../../packages/php-wasm/util/src/lib/index.ts"],"sourcesContent":["export const SleepFinished = Symbol('SleepFinished');\n\nexport function sleep(ms: number): Promise<typeof SleepFinished> {\n\treturn new Promise((resolve) => {\n\t\tsetTimeout(() => resolve(SleepFinished), ms);\n\t});\n}\n","import { SleepFinished, sleep } from './sleep';\n\nexport interface SemaphoreOptions {\n\t/**\n\t * The maximum number of concurrent locks.\n\t */\n\tconcurrency: number;\n\t/**\n\t * The maximum time to wait for a lock to become available.\n\t */\n\ttimeout?: number;\n}\n\nexport class AcquireTimeoutError extends Error {\n\tconstructor() {\n\t\tsuper('Acquiring lock timed out');\n\t}\n}\n\nexport default class Semaphore {\n\tprivate _running = 0;\n\tprivate concurrency: number;\n\tprivate timeout?: number;\n\tprivate queue: (() => void)[];\n\n\tconstructor({ concurrency, timeout }: SemaphoreOptions) {\n\t\tthis.concurrency = concurrency;\n\t\tthis.timeout = timeout;\n\t\tthis.queue = [];\n\t}\n\n\tget remaining(): number {\n\t\treturn this.concurrency - this.running;\n\t}\n\n\tget running(): number {\n\t\treturn this._running;\n\t}\n\n\tasync acquire(): Promise<() => void> {\n\t\twhile (true) {\n\t\t\tif (this._running >= this.concurrency) {\n\t\t\t\t// Concurrency exhausted – wait until a lock is released:\n\t\t\t\tconst acquired = new Promise<void>((resolve) => {\n\t\t\t\t\tthis.queue.push(resolve);\n\t\t\t\t});\n\t\t\t\tif (this.timeout !== undefined) {\n\t\t\t\t\tawait Promise.race([acquired, sleep(this.timeout)]).then(\n\t\t\t\t\t\t(value) => {\n\t\t\t\t\t\t\tif (value === SleepFinished) {\n\t\t\t\t\t\t\t\tthrow new AcquireTimeoutError();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tawait acquired;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Acquire the lock:\n\t\t\t\tthis._running++;\n\t\t\t\tlet released = false;\n\t\t\t\treturn () => {\n\t\t\t\t\tif (released) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\treleased = true;\n\t\t\t\t\tthis._running--;\n\t\t\t\t\t// Release the lock:\n\t\t\t\t\tif (this.queue.length > 0) {\n\t\t\t\t\t\tthis.queue.shift()!();\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t}\n\n\tasync run<T>(fn: () => T | Promise<T>): Promise<T> {\n\t\tconst release = await this.acquire();\n\t\ttry {\n\t\t\treturn await fn();\n\t\t} finally {\n\t\t\trelease();\n\t\t}\n\t}\n}\n","export class PhpWasmError extends Error {\n\tuserFriendlyMessage?: string;\n\tconstructor(message: string, userFriendlyMessage?: string) {\n\t\tsuper(message);\n\t\tthis.userFriendlyMessage = userFriendlyMessage ?? message;\n\t}\n}\n","/**\n * The functions in this module are mostly copied from the generated\n * Emscripten PHP module. This enables features like filesystem journaling,\n * which use some low-level Emscripten APIs and need access to the\n * same path helpers.\n */\n\n/**\n * Joins paths together.\n *\n * For example:\n *\n * > joinPaths('wordpress', 'wp-content')\n * 'wordpress/wp-content'\n *\n * Use this for all PHP paths and **do not** use path.join().\n * This is important because Emscripten paths are **always**\n * POSIX-style paths. Imagine joining paths on Windows:\n *\n * > path.join('wordpress', 'wp-content')\n * '\\\\wordpress\\\\wp-content' // invalid in PHP.wasm\n *\n * See the path.join issue for more details:\n *\n * https://github.com/WordPress/playground-tools/issues/11#issuecomment-1579074763\n *\n * @param paths Paths segments to join\n * @returns A joined path\n */\nexport function joinPaths(...paths: string[]) {\n\tfunction hasTrailingSlash(p: string) {\n\t\treturn p.substring(p.length - 1) === '/';\n\t}\n\n\tlet path = paths.join('/');\n\tconst isAbsolute = path[0] === '/';\n\tconst trailingSlash = hasTrailingSlash(path);\n\tpath = normalizePath(path);\n\tif (!path && !isAbsolute) {\n\t\tpath = '.';\n\t}\n\tif (path && trailingSlash && !hasTrailingSlash(path)) {\n\t\tpath += '/';\n\t}\n\treturn path;\n}\n\n/**\n * Returns the directory name of a path.\n *\n * @param path\n * @returns\n */\nexport function dirname(path: string) {\n\tif (path === '/') {\n\t\treturn '/';\n\t}\n\n\tpath = normalizePath(path);\n\n\tconst lastSlash = path.lastIndexOf('/');\n\tif (lastSlash === -1) {\n\t\treturn '';\n\t} else if (lastSlash === 0) {\n\t\treturn '/';\n\t}\n\treturn path.substr(0, lastSlash);\n}\n\n/**\n * Returns the last portion of a path.\n *\n * @param path - The path to extract the basename from.\n * @returns The basename of the path.\n */\nexport function basename(path: string) {\n\tif (path === '/') {\n\t\treturn '/';\n\t}\n\n\tpath = normalizePath(path);\n\n\tconst lastSlash = path.lastIndexOf('/');\n\tif (lastSlash === -1) {\n\t\treturn path;\n\t}\n\treturn path.substr(lastSlash + 1);\n}\n\n/**\n * Normalizes a path.\n *\n * For example:\n *\n * > normalizePath('wordpress/wp-content/../')\n * 'wordpress'\n *\n * @param path\n * @returns\n */\nexport function normalizePath(path: string) {\n\tconst isAbsolute = path[0] === '/';\n\tpath = normalizePathsArray(\n\t\tpath.split('/').filter((p: any) => !!p),\n\t\t!isAbsolute\n\t).join('/');\n\treturn (isAbsolute ? '/' : '') + path.replace(/\\/$/, '');\n}\n\n/**\n * Normalizes paths.\n *\n * For example:\n *\n * > normalizePathsArray(['wordpress', 'wp-content', '..', '', '.',\n * 'wp-includes']) ['wordpress', 'wp-includes']\n *\n * @param parts parts of the path to normalize\n * @param allowAboveRoot allow paths above the root\n * @returns normalized paths\n */\nexport function normalizePathsArray(parts: string[], allowAboveRoot: boolean) {\n\tlet up = 0;\n\tfor (let i = parts.length - 1; i >= 0; i--) {\n\t\tconst last = parts[i];\n\t\tif (last === '.') {\n\t\t\tparts.splice(i, 1);\n\t\t} else if (last === '..') {\n\t\t\tparts.splice(i, 1);\n\t\t\tup++;\n\t\t} else if (up) {\n\t\t\tparts.splice(i, 1);\n\t\t\tup--;\n\t\t}\n\t}\n\tif (allowAboveRoot) {\n\t\tfor (; up; up--) {\n\t\t\tparts.unshift('..');\n\t\t}\n\t}\n\treturn parts;\n}\n\n/**\n * Checks if the given parent path is an ancestor of the given child path.\n *\n * @param parent The parent path to check.\n * @param child The child path to verify against the parent.\n * @returns Whether the `parent` path is an ancestor of the `child` path.\n */\nexport function isParentOf(parent: string, child: string) {\n\tif (parent === '/') {\n\t\treturn true;\n\t}\n\tparent = normalizePath(parent);\n\tchild = normalizePath(child);\n\treturn child.startsWith(parent + '/') || child === parent;\n}\n","/**\n * Polyfills Node.js EventEmitter API. The main goal is to enable\n * using a child_process.spawn()-like API in both Node.js and the browser.\n *\n * @see https://nodejs.org/api/events.html#events_class_eventemitter\n */\ntype Listener = (...args: any[]) => any;\n\nexport class EventEmitterPolyfill {\n\tlisteners: Record<string, Listener[]> = {};\n\temit(eventName: string, data?: any) {\n\t\tif (this.listeners[eventName]) {\n\t\t\tthis.listeners[eventName].forEach(function (listener) {\n\t\t\t\tlistener(data);\n\t\t\t});\n\t\t}\n\t}\n\ton(eventName: string, listener: Listener) {\n\t\tif (!this.listeners[eventName]) {\n\t\t\tthis.listeners[eventName] = [];\n\t\t}\n\t\tthis.listeners[eventName].push(listener);\n\t}\n\tonce(eventName: string, listener: Listener) {\n\t\tconst wrappedListener = (...args: any[]) => {\n\t\t\tthis.off(eventName, wrappedListener);\n\t\t\tlistener(...args);\n\t\t};\n\t\tthis.on(eventName, wrappedListener);\n\t}\n\toff(eventName: string, listener: Listener) {\n\t\tif (this.listeners[eventName]) {\n\t\t\tthis.listeners[eventName] = this.listeners[eventName].filter(\n\t\t\t\t(l) => l !== listener\n\t\t\t);\n\t\t}\n\t}\n}\n","/**\n * Naive shell command parser.\n * Ensures that commands like `wp option set blogname \"My blog name\"` are split\n * into `['wp', 'option', 'set', 'blogname', 'My blog name']` instead of\n * `['wp', 'option', 'set', 'blogname', 'My', 'blog', 'name']`.\n *\n * @param command\n * @returns\n */\nexport function splitShellCommand(command: string) {\n\tconst MODE_UNQUOTED = 0;\n\tconst MODE_IN_QUOTE = 1;\n\n\tlet mode = MODE_UNQUOTED;\n\tlet quote = '';\n\n\tconst parts: string[] = [];\n\tlet currentPart = '';\n\tfor (let i = 0; i < command.length; i++) {\n\t\tconst char = command[i];\n\t\tif (char === '\\\\') {\n\t\t\t// Escaped quotes are treated as normal characters\n\t\t\t// This is a very naive approach to escaping, but it's good enough for\n\t\t\t// now. @TODO: Iterate on this later, perhaps using bun shell. @see https://github.com/WordPress/wordpress-playground/issues/1062\n\t\t\tif (command[i + 1] === '\"' || command[i + 1] === \"'\") {\n\t\t\t\ti++;\n\t\t\t}\n\t\t\tcurrentPart += command[i];\n\t\t} else if (mode === MODE_UNQUOTED) {\n\t\t\tif (char === '\"' || char === \"'\") {\n\t\t\t\tmode = MODE_IN_QUOTE;\n\t\t\t\tquote = char;\n\t\t\t} else if (char.match(/\\s/)) {\n\t\t\t\tif (currentPart.trim().length) {\n\t\t\t\t\tparts.push(currentPart.trim());\n\t\t\t\t}\n\t\t\t\tcurrentPart = char;\n\t\t\t} else if (parts.length && !currentPart) {\n\t\t\t\t// We just closed a quote to continue the same\n\t\t\t\t// argument with different escaping style, e.g.:\n\t\t\t\t// php -r 'require '\\''vendor/autoload.php'\\''\n\t\t\t\tcurrentPart = parts.pop()! + char;\n\t\t\t} else {\n\t\t\t\tcurrentPart += char;\n\t\t\t}\n\t\t} else if (mode === MODE_IN_QUOTE) {\n\t\t\tif (char === quote) {\n\t\t\t\tmode = MODE_UNQUOTED;\n\t\t\t\tquote = '';\n\t\t\t} else {\n\t\t\t\tcurrentPart += char;\n\t\t\t}\n\t\t}\n\t}\n\tif (currentPart) {\n\t\tparts.push(currentPart.trim());\n\t}\n\treturn parts;\n}\n","/**\n * Polyfills Node.js WritableStream API. The main goal is to enable\n * using a child_process.spawn()-like API in both Node.js and the browser.\n *\n * @see https://nodejs.org/api/stream.html#stream_writable_end_chunk_encoding_callback\n */\nimport { EventEmitterPolyfill } from './event-emitter-polyfill';\n\nexport interface WritableOptions {\n\thighWaterMark?: number;\n\tdecodeStrings?: boolean;\n\tdefaultEncoding?: BufferEncoding;\n\twrite: (chunk: any, encoding: BufferEncoding, cb: WriteCallback) => void;\n}\n\nexport type WriteCallback = (error?: Error | null) => void;\n\nexport class WritablePolyfill extends EventEmitterPolyfill {\n\tprivate buffer: Array<{\n\t\tchunk: any;\n\t\tencoding: BufferEncoding;\n\t\tcb: WriteCallback;\n\t}> = [];\n\tprivate writing = false;\n\tpublic ended = false;\n\tprivate length = 0;\n\tprivate highWaterMark: number;\n\tprivate decodeStrings: boolean;\n\tprivate defaultEncoding: BufferEncoding;\n\tprivate defer: (fn: () => void) => void;\n\tprivate _write: (\n\t\tchunk: any,\n\t\tencoding: BufferEncoding,\n\t\tcb: WriteCallback\n\t) => void;\n\n\tconstructor(opts: WritableOptions) {\n\t\tsuper();\n\t\tif (!opts.write) {\n\t\t\tthrow new Error('WritablePolyfill requires write option');\n\t\t}\n\t\tthis._write = opts.write;\n\t\tthis.highWaterMark = opts.highWaterMark ?? 16 * 1024;\n\t\tthis.decodeStrings = opts.decodeStrings ?? true;\n\t\tthis.defaultEncoding = opts.defaultEncoding ?? 'utf8';\n\t\t// queueMicrotask keeps browser support; fallback for older environments.\n\t\tthis.defer =\n\t\t\ttypeof queueMicrotask === 'function'\n\t\t\t\t? queueMicrotask\n\t\t\t\t: (fn) => setTimeout(fn, 0);\n\t}\n\n\twrite(\n\t\tchunk: any,\n\t\tencoding: BufferEncoding | WriteCallback = this.defaultEncoding,\n\t\tcb: WriteCallback = () => {}\n\t): boolean {\n\t\tif (typeof encoding === 'function') {\n\t\t\tcb = encoding as WriteCallback;\n\t\t\tencoding = this.defaultEncoding;\n\t\t}\n\n\t\tif (this.ended) {\n\t\t\tconst err = new Error('write after end');\n\t\t\tthis.defer(() => cb(err));\n\t\t\tthis.emit('error', err);\n\t\t\treturn false;\n\t\t}\n\n\t\tif (this.decodeStrings && typeof chunk === 'string') {\n\t\t\tchunk = Buffer.from(chunk, encoding as BufferEncoding);\n\t\t\tencoding = 'buffer' as BufferEncoding;\n\t\t}\n\n\t\tthis.length += chunk.length ?? 1;\n\t\tconst needDrain = this.length >= this.highWaterMark;\n\n\t\tthis.buffer.push({ chunk, encoding: encoding as BufferEncoding, cb });\n\n\t\tif (!this.writing) this._clearBuffer();\n\n\t\treturn !needDrain;\n\t}\n\n\tend(\n\t\tchunk?: any,\n\t\tencoding?: BufferEncoding | WriteCallback,\n\t\tcb?: WriteCallback\n\t): void {\n\t\tif (typeof chunk === 'function') {\n\t\t\tcb = chunk;\n\t\t\tchunk = undefined;\n\t\t} else if (typeof encoding === 'function') {\n\t\t\tcb = encoding as WriteCallback;\n\t\t\tencoding = undefined;\n\t\t}\n\n\t\tif (chunk !== undefined)\n\t\t\tthis.write(chunk, encoding as BufferEncoding, () => {});\n\t\tthis.ended = true;\n\t\tif (!this.writing) this._clearBuffer();\n\t\tif (cb) this.defer(cb);\n\t}\n\n\t// Stubs kept for API parity; add logic if you depend on corking.\n\tcork(): void {}\n\tuncork(): void {}\n\n\tsetDefaultEncoding(enc: BufferEncoding): this {\n\t\tthis.defaultEncoding = enc;\n\t\treturn this;\n\t}\n\n\tprivate _clearBuffer(): void {\n\t\tconst entry = this.buffer.shift();\n\t\tif (!entry) {\n\t\t\tif (this.ended) this.emit('finish');\n\t\t\treturn;\n\t\t}\n\n\t\tthis.writing = true;\n\t\tthis._write(entry.chunk, entry.encoding, (err?: Error | null) => {\n\t\t\tthis.writing = false;\n\t\t\tthis.length -= entry.chunk.length ?? 1;\n\t\t\tif (err) this.emit('error', err);\n\t\t\tentry.cb(err);\n\n\t\t\tif (this.buffer.length) {\n\t\t\t\tthis._clearBuffer();\n\t\t\t} else {\n\t\t\t\tif (this.length < this.highWaterMark) this.emit('drain');\n\t\t\t\tif (this.ended) this.emit('finish');\n\t\t\t}\n\t\t});\n\t}\n}\n","import { EventEmitterPolyfill } from './event-emitter-polyfill';\nimport { splitShellCommand } from './split-shell-command';\nimport { WritablePolyfill, type WriteCallback } from './writable-polyfill';\n\ntype Listener = (...args: any[]) => any;\n\nexport interface ProcessOptions {\n\tcwd?: string;\n\tenv?: Record<string, string>;\n}\n\n/**\n * Usage:\n * ```ts\n * php.setSpawnHandler(\n * createSpawnHandler(function (command, processApi) {\n * console.log(processApi.flushStdin());\n * processApi.stdout('/\\n/tmp\\n/home');\n *\t processApi.exit(0);\n * })\n * );\n * ```\n * @param program\n * @returns\n */\nexport function createSpawnHandler(\n\tprogram: (\n\t\tcommand: string[],\n\t\tprocessApi: ProcessApi,\n\t\toptions: ProcessOptions\n\t) => void | Promise<void>\n): any {\n\treturn function (\n\t\tcommand: string | string[],\n\t\targsArray: string[] = [],\n\t\toptions: ProcessOptions = {}\n\t) {\n\t\tconst childProcess = new ChildProcess();\n\t\tconst processApi = new ProcessApi(childProcess);\n\t\t// Give PHP a chance to register listeners\n\t\tsetTimeout(async () => {\n\t\t\tlet commandArray = [];\n\t\t\tif (argsArray.length) {\n\t\t\t\tcommandArray = [command as string, ...argsArray];\n\t\t\t} else if (typeof command === 'string') {\n\t\t\t\tcommandArray = splitShellCommand(command);\n\t\t\t} else if (Array.isArray(command)) {\n\t\t\t\tcommandArray = command;\n\t\t\t} else {\n\t\t\t\tthrow new Error('Invalid command ', command);\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tconst promise = program(commandArray, processApi, options);\n\t\t\t\tif (\n\t\t\t\t\ttypeof promise !== 'object' ||\n\t\t\t\t\tpromise === null ||\n\t\t\t\t\t!('then' in promise)\n\t\t\t\t) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`The program callback passed to createSpawnHandler() did not return a promise. It indicates there's a bug in your code. ` +\n\t\t\t\t\t\t\t`The callback must return a promise. PHP cannot interact with program that synchronously exists at the end of the proc_open() ` +\n\t\t\t\t\t\t\t`call. All the streams would be closed already. Make sure to put an \"await new Promise(resolve => setTimeout(resolve, 1))` +\n\t\t\t\t\t\t\t`before calling processApi.exit(0) in your callback to let PHP catch up with the stdout data.`\n\t\t\t\t\t);\n\t\t\t\t} else if (processApi.exited) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`The program callback passed to createSpawnHandler() exited synchronously. It indicates there's a bug in your code. ` +\n\t\t\t\t\t\t\t`The callback must return a promise. PHP cannot interact with program that synchronously exists at the end of the proc_open() ` +\n\t\t\t\t\t\t\t`call. All the streams would be closed already. Make sure to put an \"await new Promise(resolve => setTimeout(resolve, 1))` +\n\t\t\t\t\t\t\t`before calling processApi.exit(0) in your callback to let PHP catch up with the stdout data.`\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tchildProcess.emit('spawn', true);\n\t\t\t\tawait promise;\n\t\t\t} catch (e) {\n\t\t\t\tchildProcess.emit('error', e);\n\t\t\t\tif (\n\t\t\t\t\ttypeof e === 'object' &&\n\t\t\t\t\te !== null &&\n\t\t\t\t\t'message' in e &&\n\t\t\t\t\ttypeof e.message === 'string'\n\t\t\t\t) {\n\t\t\t\t\tprocessApi.stderr(e.message);\n\t\t\t\t}\n\t\t\t\tprocessApi.exit(1);\n\t\t\t}\n\t\t});\n\t\treturn childProcess;\n\t};\n}\n\nexport class ProcessApi extends EventEmitterPolyfill {\n\tpublic exited = false;\n\t/**\n\t * Keeps track of the data that was written to stdin before the\n\t * first listener was registered.\n\t */\n\tprivate stdinBuffer: Uint8Array[] | null = [];\n\tprivate childProcess: ChildProcess;\n\tconstructor(childProcess: ChildProcess) {\n\t\tsuper();\n\t\tthis.childProcess = childProcess;\n\t\tchildProcess.on('stdin', (data: Uint8Array) => {\n\t\t\tif (this.stdinBuffer) {\n\t\t\t\t// Need to clone the data buffer as it's reused by PHP\n\t\t\t\t// and the next data chunk will overwrite the previous one.\n\t\t\t\tthis.stdinBuffer.push(data.slice());\n\t\t\t} else {\n\t\t\t\tthis.emit('stdin', data);\n\t\t\t}\n\t\t});\n\t}\n\tstdinEnd() {\n\t\tif (!this.childProcess.stdin.ended) {\n\t\t\tthis.childProcess.stdin.end();\n\t\t}\n\t}\n\tstdout(data: string | ArrayBuffer) {\n\t\tthis.childProcess.stdout.write(data);\n\t}\n\tstdoutEnd() {\n\t\tif (!this.childProcess.stdout.ended) {\n\t\t\tthis.childProcess.stdout.end();\n\t\t}\n\t}\n\tstderr(data: string | ArrayBuffer) {\n\t\tthis.childProcess.stderr.write(data);\n\t}\n\tstderrEnd() {\n\t\tif (!this.childProcess.stderr.ended) {\n\t\t\tthis.childProcess.stderr.end();\n\t\t}\n\t}\n\tnotifySpawn() {\n\t\tthis.childProcess.emit('spawn', true);\n\t}\n\texit(code: number) {\n\t\tif (!this.exited) {\n\t\t\tthis.exited = true;\n\t\t\tthis.stdinEnd();\n\t\t\tthis.stdoutEnd();\n\t\t\tthis.stderrEnd();\n\t\t\tthis.childProcess.emit('exit', code);\n\t\t}\n\t}\n\toverride on(eventName: string, listener: Listener) {\n\t\tsuper.on(eventName, listener);\n\t\t/**\n\t\t * If it's the first stdin listener, flush all the data we've\n\t\t * buffered so far.\n\t\t */\n\t\tif (eventName === 'stdin' && this.stdinBuffer) {\n\t\t\tfor (let i = 0; i < this.stdinBuffer.length; i++) {\n\t\t\t\tthis.emit('stdin', this.stdinBuffer[i]);\n\t\t\t}\n\t\t\tthis.stdinBuffer = null;\n\t\t}\n\t}\n}\n\nlet lastPid = 9743;\nexport class ChildProcess extends EventEmitterPolyfill {\n\tstdout: WritablePolyfill;\n\tstderr: WritablePolyfill;\n\tstdin: WritablePolyfill;\n\tpid: number;\n\tconstructor(pid = lastPid++) {\n\t\tsuper();\n\t\tthis.pid = pid;\n\t\t// eslint-disable-next-line @typescript-eslint/no-this-alias\n\t\tconst self = this;\n\t\tthis.stdout = new WritablePolyfill({\n\t\t\twrite(data: any, encoding: BufferEncoding, cb: WriteCallback) {\n\t\t\t\tself.stdout.emit('data', data);\n\t\t\t\tcb();\n\t\t\t},\n\t\t});\n\t\tthis.stderr = new WritablePolyfill({\n\t\t\twrite: (data: any, encoding: BufferEncoding, cb: WriteCallback) => {\n\t\t\t\tself.stderr.emit('data', data);\n\t\t\t\tcb();\n\t\t\t},\n\t\t});\n\t\tthis.stdin = new WritablePolyfill({\n\t\t\twrite: (data: any, encoding: BufferEncoding, cb: WriteCallback) => {\n\t\t\t\tself.emit('stdin', data);\n\t\t\t\tcb();\n\t\t\t},\n\t\t});\n\t}\n}\n","export function randomString(\n\tlength = 36,\n\tspecialChars = '!@#$%^&*()_+=-[]/.,<>?'\n) {\n\tconst chars =\n\t\t'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' +\n\t\tspecialChars;\n\tlet result = '';\n\tfor (let i = length; i > 0; --i)\n\t\tresult += chars[Math.floor(Math.random() * chars.length)];\n\treturn result;\n}\n","import { randomString } from './random-string';\n\nexport function randomFilename() {\n\treturn randomString(36, '-_');\n}\n","export function phpVar(value: unknown): string {\n\treturn `json_decode(base64_decode('${stringToBase64(\n\t\tJSON.stringify(value)\n\t)}'), true)`;\n}\n\nexport function phpVars<T extends Record<string, unknown>>(\n\tvars: T\n): Record<keyof T, string> {\n\tconst result: Record<string, string> = {};\n\tfor (const key in vars) {\n\t\tresult[key] = phpVar(vars[key]);\n\t}\n\treturn result as Record<keyof T, string>;\n}\n\nfunction stringToBase64(str: string) {\n\treturn bytesToBase64(new TextEncoder().encode(str));\n}\n\nfunction bytesToBase64(bytes: Uint8Array) {\n\tconst binString = String.fromCodePoint(...bytes);\n\treturn btoa(binString);\n}\n","/**\n * Formats a string like sprintf().\n *\n * This function:\n * - Supports basic format specifiers: %s, %d, %f, %x, %%\n * - Supports bigint values\n *\n * The purpose of this function is for use in optional php-wasm tracing.\n * If we use printf-style formatting for trace messages, we let the trace\n * function decide whether to format and do not have to pay for formatting\n * unless tracing is enabled.\n */\nexport function sprintf(format: string, ...args: any[]): string {\n\tlet result = '';\n\tlet argIndex = 0;\n\n\tfor (let i = 0; i < format.length; i++) {\n\t\tif (format[i] === '%' && i + 1 < format.length) {\n\t\t\ti++;\n\t\t\tconst specifier = format[i];\n\n\t\t\tswitch (specifier) {\n\t\t\t\tcase 's': {\n\t\t\t\t\tconst arg = args[argIndex++];\n\t\t\t\t\tlet str;\n\t\t\t\t\tif (typeof arg === 'object') {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t// If an object doesn't provide its own toString(),\n\t\t\t\t\t\t\t// try to represent it as JSON.\n\t\t\t\t\t\t\tstr = JSON.stringify(\n\t\t\t\t\t\t\t\targ,\n\t\t\t\t\t\t\t\t// Represent bigint values as strings in JSON.stringify().\n\t\t\t\t\t\t\t\t(key, value) => {\n\t\t\t\t\t\t\t\t\tif (typeof value === 'bigint') {\n\t\t\t\t\t\t\t\t\t\treturn `0x${value.toString(16)}`;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\treturn value;\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t2\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t// Ignore error and use default representation.\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tstr = String(arg);\n\t\t\t\t\t}\n\n\t\t\t\t\tresult += str;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase 'd': {\n\t\t\t\t\tconst arg = args[argIndex++];\n\t\t\t\t\tif (typeof arg === 'bigint') {\n\t\t\t\t\t\tresult += arg.toString();\n\t\t\t\t\t} else {\n\t\t\t\t\t\tresult += Math.floor(Number(arg));\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase 'f': {\n\t\t\t\t\tconst arg = args[argIndex++];\n\t\t\t\t\tif (typeof arg === 'bigint') {\n\t\t\t\t\t\tresult += Number(arg);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tresult += Number(arg);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase 'x': {\n\t\t\t\t\tconst arg = args[argIndex++];\n\t\t\t\t\tif (typeof arg === 'bigint') {\n\t\t\t\t\t\tresult += arg.toString(16);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tresult += Math.floor(Number(arg)).toString(16);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase '%': {\n\t\t\t\t\tresult += '%';\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\tresult += '%' + specifier;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tresult += format[i];\n\t\t}\n\t}\n\n\treturn result;\n}\n","import Semaphore, { AcquireTimeoutError } from './semaphore';\nexport { Semaphore, AcquireTimeoutError };\nexport { PhpWasmError } from './php-wasm-error';\nexport type { SemaphoreOptions } from './semaphore';\nexport {\n\tdirname,\n\tjoinPaths,\n\tbasename,\n\tnormalizePath,\n\tisParentOf,\n} from './paths';\nexport { createSpawnHandler } from './create-spawn-handler';\nexport { randomString } from './random-string';\nexport { randomFilename } from './random-filename';\nexport { WritablePolyfill, type WritableOptions } from './writable-polyfill';\nexport { EventEmitterPolyfill } from './event-emitter-polyfill';\nexport * from './php-vars';\n\nexport * from './sprintf';\n\nexport function concatUint8Arrays(arrays: Uint8Array[]): Uint8Array {\n\tlet totalLength = 0;\n\tarrays.forEach((a) => (totalLength += a.length));\n\tconst result = new Uint8Array(totalLength);\n\tlet offset = 0;\n\tarrays.forEach((a) => {\n\t\tresult.set(a, offset);\n\t\toffset += a.length;\n\t});\n\treturn result;\n}\n\nexport function concatArrayBuffers(buffers: ArrayBuffer[]): ArrayBuffer {\n\treturn concatUint8Arrays(buffers.map((b) => new Uint8Array(b)))\n\t\t.buffer as ArrayBuffer;\n}\n\nexport * from './types';\n"],"names":["SleepFinished","sleep","ms","resolve","AcquireTimeoutError","Semaphore","concurrency","timeout","acquired","value","released","fn","release","PhpWasmError","message","userFriendlyMessage","joinPaths","paths","hasTrailingSlash","p","path","isAbsolute","trailingSlash","normalizePath","dirname","lastSlash","basename","normalizePathsArray","parts","allowAboveRoot","up","i","last","isParentOf","parent","child","EventEmitterPolyfill","eventName","data","listener","wrappedListener","args","l","splitShellCommand","command","mode","quote","currentPart","char","WritablePolyfill","opts","chunk","encoding","cb","err","needDrain","enc","entry","createSpawnHandler","program","argsArray","options","childProcess","ChildProcess","processApi","ProcessApi","commandArray","promise","e","code","lastPid","pid","self","randomString","length","specialChars","chars","result","randomFilename","phpVar","stringToBase64","phpVars","vars","key","str","bytesToBase64","bytes","binString","sprintf","format","argIndex","specifier","arg","concatUint8Arrays","arrays","totalLength","a","offset","concatArrayBuffers","buffers","b"],"mappings":"AAAa,MAAAA,IAAgB,OAAO,eAAe;AAE5C,SAASC,EAAMC,GAA2C;AACzD,SAAA,IAAI,QAAQ,CAACC,MAAY;AAC/B,eAAW,MAAMA,EAAQH,CAAa,GAAGE,CAAE;AAAA,EAAA,CAC3C;AACF;ACOO,MAAME,UAA4B,MAAM;AAAA,EAC9C,cAAc;AACb,UAAM,0BAA0B;AAAA,EAAA;AAElC;AAEA,MAAqBC,EAAU;AAAA,EAM9B,YAAY,EAAE,aAAAC,GAAa,SAAAC,KAA6B;AALxD,SAAQ,WAAW,GAMlB,KAAK,cAAcD,GACnB,KAAK,UAAUC,GACf,KAAK,QAAQ,CAAC;AAAA,EAAA;AAAA,EAGf,IAAI,YAAoB;AAChB,WAAA,KAAK,cAAc,KAAK;AAAA,EAAA;AAAA,EAGhC,IAAI,UAAkB;AACrB,WAAO,KAAK;AAAA,EAAA;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AC5D;AACH;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../packages/php-wasm/util/src/lib/sleep.ts","../../../../packages/php-wasm/util/src/lib/semaphore.ts","../../../../packages/php-wasm/util/src/lib/php-wasm-error.ts","../../../../packages/php-wasm/util/src/lib/paths.ts","../../../../packages/php-wasm/util/src/lib/event-emitter-polyfill.ts","../../../../packages/php-wasm/util/src/lib/split-shell-command.ts","../../../../packages/php-wasm/util/src/lib/writable-polyfill.ts","../../../../packages/php-wasm/util/src/lib/create-spawn-handler.ts","../../../../packages/php-wasm/util/src/lib/random-string.ts","../../../../packages/php-wasm/util/src/lib/random-filename.ts","../../../../packages/php-wasm/util/src/lib/php-vars.ts","../../../../packages/php-wasm/util/src/lib/sprintf.ts","../../../../packages/php-wasm/util/src/lib/index.ts"],"sourcesContent":["export const SleepFinished = Symbol('SleepFinished');\n\nexport function sleep(ms: number): Promise<typeof SleepFinished> {\n\treturn new Promise((resolve) => {\n\t\tsetTimeout(() => resolve(SleepFinished), ms);\n\t});\n}\n","import { SleepFinished, sleep } from './sleep';\n\nexport interface SemaphoreOptions {\n\t/**\n\t * The maximum number of concurrent locks.\n\t */\n\tconcurrency: number;\n\t/**\n\t * The maximum time to wait for a lock to become available.\n\t */\n\ttimeout?: number;\n}\n\nexport class AcquireTimeoutError extends Error {\n\tconstructor() {\n\t\tsuper('Acquiring lock timed out');\n\t}\n}\n\nexport default class Semaphore {\n\tprivate _running = 0;\n\tprivate concurrency: number;\n\tprivate timeout?: number;\n\tprivate queue: (() => void)[];\n\n\tconstructor({ concurrency, timeout }: SemaphoreOptions) {\n\t\tthis.concurrency = concurrency;\n\t\tthis.timeout = timeout;\n\t\tthis.queue = [];\n\t}\n\n\tget remaining(): number {\n\t\treturn this.concurrency - this.running;\n\t}\n\n\tget running(): number {\n\t\treturn this._running;\n\t}\n\n\tasync acquire(): Promise<() => void> {\n\t\twhile (true) {\n\t\t\tif (this._running >= this.concurrency) {\n\t\t\t\t// Concurrency exhausted – wait until a lock is released:\n\t\t\t\tconst acquired = new Promise<void>((resolve) => {\n\t\t\t\t\tthis.queue.push(resolve);\n\t\t\t\t});\n\t\t\t\tif (this.timeout !== undefined) {\n\t\t\t\t\tawait Promise.race([acquired, sleep(this.timeout)]).then(\n\t\t\t\t\t\t(value) => {\n\t\t\t\t\t\t\tif (value === SleepFinished) {\n\t\t\t\t\t\t\t\tthrow new AcquireTimeoutError();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tawait acquired;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Acquire the lock:\n\t\t\t\tthis._running++;\n\t\t\t\tlet released = false;\n\t\t\t\treturn () => {\n\t\t\t\t\tif (released) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\treleased = true;\n\t\t\t\t\tthis._running--;\n\t\t\t\t\t// Release the lock:\n\t\t\t\t\tif (this.queue.length > 0) {\n\t\t\t\t\t\tthis.queue.shift()!();\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t}\n\n\tasync run<T>(fn: () => T | Promise<T>): Promise<T> {\n\t\tconst release = await this.acquire();\n\t\ttry {\n\t\t\treturn await fn();\n\t\t} finally {\n\t\t\trelease();\n\t\t}\n\t}\n}\n","export class PhpWasmError extends Error {\n\tuserFriendlyMessage?: string;\n\tconstructor(message: string, userFriendlyMessage?: string) {\n\t\tsuper(message);\n\t\tthis.userFriendlyMessage = userFriendlyMessage ?? message;\n\t}\n}\n","/**\n * The functions in this module are mostly copied from the generated\n * Emscripten PHP module. This enables features like filesystem journaling,\n * which use some low-level Emscripten APIs and need access to the\n * same path helpers.\n */\n\n/**\n * Joins paths together.\n *\n * For example:\n *\n * > joinPaths('wordpress', 'wp-content')\n * 'wordpress/wp-content'\n *\n * Use this for all PHP paths and **do not** use path.join().\n * This is important because Emscripten paths are **always**\n * POSIX-style paths. Imagine joining paths on Windows:\n *\n * > path.join('wordpress', 'wp-content')\n * '\\\\wordpress\\\\wp-content' // invalid in PHP.wasm\n *\n * See the path.join issue for more details:\n *\n * https://github.com/WordPress/playground-tools/issues/11#issuecomment-1579074763\n *\n * @param paths Paths segments to join\n * @returns A joined path\n */\nexport function joinPaths(...paths: string[]) {\n\tfunction hasTrailingSlash(p: string) {\n\t\treturn p.substring(p.length - 1) === '/';\n\t}\n\n\tlet path = paths.join('/');\n\tconst isAbsolute = path[0] === '/';\n\tconst trailingSlash = hasTrailingSlash(path);\n\tpath = normalizePath(path);\n\tif (!path && !isAbsolute) {\n\t\tpath = '.';\n\t}\n\tif (path && trailingSlash && !hasTrailingSlash(path)) {\n\t\tpath += '/';\n\t}\n\treturn path;\n}\n\n/**\n * Returns the directory name of a path.\n *\n * @param path\n * @returns\n */\nexport function dirname(path: string) {\n\tif (path === '/') {\n\t\treturn '/';\n\t}\n\n\tpath = normalizePath(path);\n\n\tconst lastSlash = path.lastIndexOf('/');\n\tif (lastSlash === -1) {\n\t\treturn '';\n\t} else if (lastSlash === 0) {\n\t\treturn '/';\n\t}\n\treturn path.substr(0, lastSlash);\n}\n\n/**\n * Returns the last portion of a path.\n *\n * @param path - The path to extract the basename from.\n * @returns The basename of the path.\n */\nexport function basename(path: string) {\n\tif (path === '/') {\n\t\treturn '/';\n\t}\n\n\tpath = normalizePath(path);\n\n\tconst lastSlash = path.lastIndexOf('/');\n\tif (lastSlash === -1) {\n\t\treturn path;\n\t}\n\treturn path.substr(lastSlash + 1);\n}\n\n/**\n * Normalizes a path.\n *\n * For example:\n *\n * > normalizePath('wordpress/wp-content/../')\n * 'wordpress'\n *\n * @param path\n * @returns\n */\nexport function normalizePath(path: string) {\n\tconst isAbsolute = path[0] === '/';\n\tpath = normalizePathsArray(\n\t\tpath.split('/').filter((p: any) => !!p),\n\t\t!isAbsolute\n\t).join('/');\n\treturn (isAbsolute ? '/' : '') + path.replace(/\\/$/, '');\n}\n\n/**\n * Normalizes paths.\n *\n * For example:\n *\n * > normalizePathsArray(['wordpress', 'wp-content', '..', '', '.',\n * 'wp-includes']) ['wordpress', 'wp-includes']\n *\n * @param parts parts of the path to normalize\n * @param allowAboveRoot allow paths above the root\n * @returns normalized paths\n */\nexport function normalizePathsArray(parts: string[], allowAboveRoot: boolean) {\n\tlet up = 0;\n\tfor (let i = parts.length - 1; i >= 0; i--) {\n\t\tconst last = parts[i];\n\t\tif (last === '.') {\n\t\t\tparts.splice(i, 1);\n\t\t} else if (last === '..') {\n\t\t\tparts.splice(i, 1);\n\t\t\tup++;\n\t\t} else if (up) {\n\t\t\tparts.splice(i, 1);\n\t\t\tup--;\n\t\t}\n\t}\n\tif (allowAboveRoot) {\n\t\tfor (; up; up--) {\n\t\t\tparts.unshift('..');\n\t\t}\n\t}\n\treturn parts;\n}\n\n/**\n * Checks if the given parent path is an ancestor of the given child path.\n *\n * @param parent The parent path to check.\n * @param child The child path to verify against the parent.\n * @returns Whether the `parent` path is an ancestor of the `child` path.\n */\nexport function isParentOf(parent: string, child: string) {\n\tif (parent === '/') {\n\t\treturn true;\n\t}\n\tparent = normalizePath(parent);\n\tchild = normalizePath(child);\n\treturn child.startsWith(parent + '/') || child === parent;\n}\n","/**\n * Polyfills Node.js EventEmitter API. The main goal is to enable\n * using a child_process.spawn()-like API in both Node.js and the browser.\n *\n * @see https://nodejs.org/api/events.html#events_class_eventemitter\n */\ntype Listener = (...args: any[]) => any;\n\nexport class EventEmitterPolyfill {\n\tlisteners: Record<string, Listener[]> = {};\n\temit(eventName: string, data?: any) {\n\t\tif (this.listeners[eventName]) {\n\t\t\tthis.listeners[eventName].forEach(function (listener) {\n\t\t\t\tlistener(data);\n\t\t\t});\n\t\t}\n\t}\n\ton(eventName: string, listener: Listener) {\n\t\tif (!this.listeners[eventName]) {\n\t\t\tthis.listeners[eventName] = [];\n\t\t}\n\t\tthis.listeners[eventName].push(listener);\n\t}\n\tonce(eventName: string, listener: Listener) {\n\t\tconst wrappedListener = (...args: any[]) => {\n\t\t\tthis.off(eventName, wrappedListener);\n\t\t\tlistener(...args);\n\t\t};\n\t\tthis.on(eventName, wrappedListener);\n\t}\n\toff(eventName: string, listener: Listener) {\n\t\tif (this.listeners[eventName]) {\n\t\t\tthis.listeners[eventName] = this.listeners[eventName].filter(\n\t\t\t\t(l) => l !== listener\n\t\t\t);\n\t\t}\n\t}\n}\n","/**\n * Naive shell command parser.\n * Ensures that commands like `wp option set blogname \"My blog name\"` are split\n * into `['wp', 'option', 'set', 'blogname', 'My blog name']` instead of\n * `['wp', 'option', 'set', 'blogname', 'My', 'blog', 'name']`.\n *\n * @param command\n * @returns\n */\nexport function splitShellCommand(command: string) {\n\tconst MODE_UNQUOTED = 0;\n\tconst MODE_IN_QUOTE = 1;\n\n\tlet mode = MODE_UNQUOTED;\n\tlet quote = '';\n\n\tconst parts: string[] = [];\n\tlet currentPart = '';\n\tfor (let i = 0; i < command.length; i++) {\n\t\tconst char = command[i];\n\t\tif (char === '\\\\') {\n\t\t\t// Escaped quotes are treated as normal characters\n\t\t\t// This is a very naive approach to escaping, but it's good enough for\n\t\t\t// now. @TODO: Iterate on this later, perhaps using bun shell. @see https://github.com/WordPress/wordpress-playground/issues/1062\n\t\t\tif (command[i + 1] === '\"' || command[i + 1] === \"'\") {\n\t\t\t\ti++;\n\t\t\t}\n\t\t\tcurrentPart += command[i];\n\t\t} else if (mode === MODE_UNQUOTED) {\n\t\t\tif (char === '\"' || char === \"'\") {\n\t\t\t\tmode = MODE_IN_QUOTE;\n\t\t\t\tquote = char;\n\t\t\t} else if (char.match(/\\s/)) {\n\t\t\t\tif (currentPart.trim().length) {\n\t\t\t\t\tparts.push(currentPart.trim());\n\t\t\t\t}\n\t\t\t\tcurrentPart = char;\n\t\t\t} else if (parts.length && !currentPart) {\n\t\t\t\t// We just closed a quote to continue the same\n\t\t\t\t// argument with different escaping style, e.g.:\n\t\t\t\t// php -r 'require '\\''vendor/autoload.php'\\''\n\t\t\t\tcurrentPart = parts.pop()! + char;\n\t\t\t} else {\n\t\t\t\tcurrentPart += char;\n\t\t\t}\n\t\t} else if (mode === MODE_IN_QUOTE) {\n\t\t\tif (char === quote) {\n\t\t\t\tmode = MODE_UNQUOTED;\n\t\t\t\tquote = '';\n\t\t\t} else {\n\t\t\t\tcurrentPart += char;\n\t\t\t}\n\t\t}\n\t}\n\tif (currentPart) {\n\t\tparts.push(currentPart.trim());\n\t}\n\treturn parts;\n}\n","/**\n * Polyfills Node.js WritableStream API. The main goal is to enable\n * using a child_process.spawn()-like API in both Node.js and the browser.\n *\n * @see https://nodejs.org/api/stream.html#stream_writable_end_chunk_encoding_callback\n */\nimport { EventEmitterPolyfill } from './event-emitter-polyfill';\n\nexport interface WritableOptions {\n\thighWaterMark?: number;\n\tdecodeStrings?: boolean;\n\tdefaultEncoding?: BufferEncoding;\n\twrite: (chunk: any, encoding: BufferEncoding, cb: WriteCallback) => void;\n}\n\nexport type WriteCallback = (error?: Error | null) => void;\n\nexport class WritablePolyfill extends EventEmitterPolyfill {\n\tprivate buffer: Array<{\n\t\tchunk: any;\n\t\tencoding: BufferEncoding;\n\t\tcb: WriteCallback;\n\t}> = [];\n\tprivate writing = false;\n\tpublic ended = false;\n\tprivate length = 0;\n\tprivate highWaterMark: number;\n\tprivate decodeStrings: boolean;\n\tprivate defaultEncoding: BufferEncoding;\n\tprivate defer: (fn: () => void) => void;\n\tprivate _write: (\n\t\tchunk: any,\n\t\tencoding: BufferEncoding,\n\t\tcb: WriteCallback\n\t) => void;\n\n\tconstructor(opts: WritableOptions) {\n\t\tsuper();\n\t\tif (!opts.write) {\n\t\t\tthrow new Error('WritablePolyfill requires write option');\n\t\t}\n\t\tthis._write = opts.write;\n\t\tthis.highWaterMark = opts.highWaterMark ?? 16 * 1024;\n\t\tthis.decodeStrings = opts.decodeStrings ?? true;\n\t\tthis.defaultEncoding = opts.defaultEncoding ?? 'utf8';\n\t\t// queueMicrotask keeps browser support; fallback for older environments.\n\t\tthis.defer =\n\t\t\ttypeof queueMicrotask === 'function'\n\t\t\t\t? queueMicrotask\n\t\t\t\t: (fn) => setTimeout(fn, 0);\n\t}\n\n\twrite(\n\t\tchunk: any,\n\t\tencoding: BufferEncoding | WriteCallback = this.defaultEncoding,\n\t\tcb: WriteCallback = () => {}\n\t): boolean {\n\t\tif (typeof encoding === 'function') {\n\t\t\tcb = encoding as WriteCallback;\n\t\t\tencoding = this.defaultEncoding;\n\t\t}\n\n\t\tif (this.ended) {\n\t\t\tconst err = new Error('write after end');\n\t\t\t// We can't call this.defer() directly. If this.defer is\n\t\t\t// `queueMicrotask`, a `this.defer()` call will pass the\n\t\t\t// WritablePolyfill instance as `this` argument and cause\n\t\t\t// the browser to throw an error similar to \"Invalid\n\t\t\t// invocation\".\n\t\t\tconst defer = this.defer;\n\t\t\tdefer(() => cb(err));\n\t\t\tthis.emit('error', err);\n\t\t\treturn false;\n\t\t}\n\n\t\tif (this.decodeStrings && typeof chunk === 'string') {\n\t\t\tif (\n\t\t\t\ttypeof Buffer !== 'undefined' &&\n\t\t\t\ttypeof (Buffer as any).from === 'function'\n\t\t\t) {\n\t\t\t\tchunk = Buffer.from(chunk, encoding as BufferEncoding);\n\t\t\t} else if (typeof TextEncoder !== 'undefined') {\n\t\t\t\tchunk = new TextEncoder().encode(chunk);\n\t\t\t} else {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'String chunks are not supported in this environment: Buffer and TextEncoder are unavailable.'\n\t\t\t\t);\n\t\t\t}\n\t\t\tencoding = 'buffer' as BufferEncoding;\n\t\t}\n\n\t\tthis.length += chunk.length ?? 1;\n\t\tconst needDrain = this.length >= this.highWaterMark;\n\n\t\tthis.buffer.push({ chunk, encoding: encoding as BufferEncoding, cb });\n\n\t\tif (!this.writing) this._clearBuffer();\n\n\t\treturn !needDrain;\n\t}\n\n\tend(\n\t\tchunk?: any,\n\t\tencoding?: BufferEncoding | WriteCallback,\n\t\tcb?: WriteCallback\n\t): void {\n\t\tif (typeof chunk === 'function') {\n\t\t\tcb = chunk;\n\t\t\tchunk = undefined;\n\t\t} else if (typeof encoding === 'function') {\n\t\t\tcb = encoding as WriteCallback;\n\t\t\tencoding = undefined;\n\t\t}\n\n\t\tif (chunk !== undefined)\n\t\t\tthis.write(chunk, encoding as BufferEncoding, () => {});\n\t\tthis.ended = true;\n\t\tif (!this.writing) this._clearBuffer();\n\t\tif (cb) this.defer(cb);\n\t}\n\n\t// Stubs kept for API parity; add logic if you depend on corking.\n\tcork(): void {}\n\tuncork(): void {}\n\n\tsetDefaultEncoding(enc: BufferEncoding): this {\n\t\tthis.defaultEncoding = enc;\n\t\treturn this;\n\t}\n\n\tprivate _clearBuffer(): void {\n\t\tconst entry = this.buffer.shift();\n\t\tif (!entry) {\n\t\t\tif (this.ended) this.emit('finish');\n\t\t\treturn;\n\t\t}\n\n\t\tthis.writing = true;\n\t\tthis._write(entry.chunk, entry.encoding, (err?: Error | null) => {\n\t\t\tthis.writing = false;\n\t\t\tthis.length -= entry.chunk.length ?? 1;\n\t\t\tif (err) this.emit('error', err);\n\t\t\tentry.cb(err);\n\n\t\t\tif (this.buffer.length) {\n\t\t\t\tthis._clearBuffer();\n\t\t\t} else {\n\t\t\t\tif (this.length < this.highWaterMark) this.emit('drain');\n\t\t\t\tif (this.ended) this.emit('finish');\n\t\t\t}\n\t\t});\n\t}\n}\n","import { EventEmitterPolyfill } from './event-emitter-polyfill';\nimport { splitShellCommand } from './split-shell-command';\nimport { WritablePolyfill, type WriteCallback } from './writable-polyfill';\n\ntype Listener = (...args: any[]) => any;\n\nexport interface ProcessOptions {\n\tcwd?: string;\n\tenv?: Record<string, string>;\n}\n\n/**\n * Usage:\n * ```ts\n * php.setSpawnHandler(\n * createSpawnHandler(function (command, processApi) {\n * console.log(processApi.flushStdin());\n * processApi.stdout('/\\n/tmp\\n/home');\n *\t processApi.exit(0);\n * })\n * );\n * ```\n * @param program\n * @returns\n */\nexport function createSpawnHandler(\n\tprogram: (\n\t\tcommand: string[],\n\t\tprocessApi: ProcessApi,\n\t\toptions: ProcessOptions\n\t) => void | Promise<void>\n): any {\n\treturn function (\n\t\tcommand: string | string[],\n\t\targsArray: string[] = [],\n\t\toptions: ProcessOptions = {}\n\t) {\n\t\tconst childProcess = new ChildProcess();\n\t\tconst processApi = new ProcessApi(childProcess);\n\t\t// Give PHP a chance to register listeners\n\t\tsetTimeout(async () => {\n\t\t\tlet commandArray = [];\n\t\t\tif (argsArray.length) {\n\t\t\t\tcommandArray = [command as string, ...argsArray];\n\t\t\t} else if (typeof command === 'string') {\n\t\t\t\tcommandArray = splitShellCommand(command);\n\t\t\t} else if (Array.isArray(command)) {\n\t\t\t\tcommandArray = command;\n\t\t\t} else {\n\t\t\t\tthrow new Error('Invalid command ', command);\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tconst promise = program(commandArray, processApi, options);\n\t\t\t\tif (\n\t\t\t\t\ttypeof promise !== 'object' ||\n\t\t\t\t\tpromise === null ||\n\t\t\t\t\t!('then' in promise)\n\t\t\t\t) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`The program callback passed to createSpawnHandler() did not return a promise. It indicates there's a bug in your code. ` +\n\t\t\t\t\t\t\t`The callback must return a promise. PHP cannot interact with program that synchronously exists at the end of the proc_open() ` +\n\t\t\t\t\t\t\t`call. All the streams would be closed already. Make sure to put an \"await new Promise(resolve => setTimeout(resolve, 1))` +\n\t\t\t\t\t\t\t`before calling processApi.exit(0) in your callback to let PHP catch up with the stdout data.`\n\t\t\t\t\t);\n\t\t\t\t} else if (processApi.exited) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`The program callback passed to createSpawnHandler() exited synchronously. It indicates there's a bug in your code. ` +\n\t\t\t\t\t\t\t`The callback must return a promise. PHP cannot interact with program that synchronously exists at the end of the proc_open() ` +\n\t\t\t\t\t\t\t`call. All the streams would be closed already. Make sure to put an \"await new Promise(resolve => setTimeout(resolve, 1))` +\n\t\t\t\t\t\t\t`before calling processApi.exit(0) in your callback to let PHP catch up with the stdout data.`\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tchildProcess.emit('spawn', true);\n\t\t\t\tawait promise;\n\t\t\t} catch (e) {\n\t\t\t\tchildProcess.emit('error', e);\n\t\t\t\tif (\n\t\t\t\t\ttypeof e === 'object' &&\n\t\t\t\t\te !== null &&\n\t\t\t\t\t'message' in e &&\n\t\t\t\t\ttypeof e.message === 'string'\n\t\t\t\t) {\n\t\t\t\t\tprocessApi.stderr(e.message);\n\t\t\t\t}\n\t\t\t\tprocessApi.exit(1);\n\t\t\t}\n\t\t});\n\t\treturn childProcess;\n\t};\n}\n\nexport class ProcessApi extends EventEmitterPolyfill {\n\tpublic exited = false;\n\t/**\n\t * Keeps track of the data that was written to stdin before the\n\t * first listener was registered.\n\t */\n\tprivate stdinBuffer: Uint8Array[] | null = [];\n\tprivate childProcess: ChildProcess;\n\tconstructor(childProcess: ChildProcess) {\n\t\tsuper();\n\t\tthis.childProcess = childProcess;\n\t\tchildProcess.on('stdin', (data: Uint8Array) => {\n\t\t\tif (this.stdinBuffer) {\n\t\t\t\t// Need to clone the data buffer as it's reused by PHP\n\t\t\t\t// and the next data chunk will overwrite the previous one.\n\t\t\t\tthis.stdinBuffer.push(data.slice());\n\t\t\t} else {\n\t\t\t\tthis.emit('stdin', data);\n\t\t\t}\n\t\t});\n\t}\n\tstdinEnd() {\n\t\tif (!this.childProcess.stdin.ended) {\n\t\t\tthis.childProcess.stdin.end();\n\t\t}\n\t}\n\tstdout(data: string | ArrayBuffer) {\n\t\tthis.childProcess.stdout.write(data);\n\t}\n\tstdoutEnd() {\n\t\tif (!this.childProcess.stdout.ended) {\n\t\t\tthis.childProcess.stdout.end();\n\t\t}\n\t}\n\tstderr(data: string | ArrayBuffer) {\n\t\tthis.childProcess.stderr.write(data);\n\t}\n\tstderrEnd() {\n\t\tif (!this.childProcess.stderr.ended) {\n\t\t\tthis.childProcess.stderr.end();\n\t\t}\n\t}\n\tnotifySpawn() {\n\t\tthis.childProcess.emit('spawn', true);\n\t}\n\texit(code: number) {\n\t\tif (!this.exited) {\n\t\t\tthis.exited = true;\n\t\t\tthis.stdinEnd();\n\t\t\tthis.stdoutEnd();\n\t\t\tthis.stderrEnd();\n\t\t\tthis.childProcess.emit('exit', code);\n\t\t}\n\t}\n\toverride on(eventName: string, listener: Listener) {\n\t\tsuper.on(eventName, listener);\n\t\t/**\n\t\t * If it's the first stdin listener, flush all the data we've\n\t\t * buffered so far.\n\t\t */\n\t\tif (eventName === 'stdin' && this.stdinBuffer) {\n\t\t\tfor (let i = 0; i < this.stdinBuffer.length; i++) {\n\t\t\t\tthis.emit('stdin', this.stdinBuffer[i]);\n\t\t\t}\n\t\t\tthis.stdinBuffer = null;\n\t\t}\n\t}\n}\n\nlet lastPid = 9743;\nexport class ChildProcess extends EventEmitterPolyfill {\n\tstdout: WritablePolyfill;\n\tstderr: WritablePolyfill;\n\tstdin: WritablePolyfill;\n\tpid: number;\n\tconstructor(pid = lastPid++) {\n\t\tsuper();\n\t\tthis.pid = pid;\n\t\t// eslint-disable-next-line @typescript-eslint/no-this-alias\n\t\tconst self = this;\n\t\tthis.stdout = new WritablePolyfill({\n\t\t\twrite(data: any, encoding: BufferEncoding, cb: WriteCallback) {\n\t\t\t\tself.stdout.emit('data', data);\n\t\t\t\tcb();\n\t\t\t},\n\t\t});\n\t\tthis.stderr = new WritablePolyfill({\n\t\t\twrite: (data: any, encoding: BufferEncoding, cb: WriteCallback) => {\n\t\t\t\tself.stderr.emit('data', data);\n\t\t\t\tcb();\n\t\t\t},\n\t\t});\n\t\tthis.stdin = new WritablePolyfill({\n\t\t\twrite: (data: any, encoding: BufferEncoding, cb: WriteCallback) => {\n\t\t\t\tself.emit('stdin', data);\n\t\t\t\tcb();\n\t\t\t},\n\t\t});\n\t}\n}\n","export function randomString(\n\tlength = 36,\n\tspecialChars = '!@#$%^&*()_+=-[]/.,<>?'\n) {\n\tconst chars =\n\t\t'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' +\n\t\tspecialChars;\n\tlet result = '';\n\tfor (let i = length; i > 0; --i)\n\t\tresult += chars[Math.floor(Math.random() * chars.length)];\n\treturn result;\n}\n","import { randomString } from './random-string';\n\nexport function randomFilename() {\n\treturn randomString(36, '-_');\n}\n","export function phpVar(value: unknown): string {\n\treturn `json_decode(base64_decode('${stringToBase64(\n\t\tJSON.stringify(value)\n\t)}'), true)`;\n}\n\nexport function phpVars<T extends Record<string, unknown>>(\n\tvars: T\n): Record<keyof T, string> {\n\tconst result: Record<string, string> = {};\n\tfor (const key in vars) {\n\t\tresult[key] = phpVar(vars[key]);\n\t}\n\treturn result as Record<keyof T, string>;\n}\n\nfunction stringToBase64(str: string) {\n\treturn bytesToBase64(new TextEncoder().encode(str));\n}\n\nfunction bytesToBase64(bytes: Uint8Array) {\n\tconst binString = String.fromCodePoint(...bytes);\n\treturn btoa(binString);\n}\n","/**\n * Formats a string like sprintf().\n *\n * This function:\n * - Supports basic format specifiers: %s, %d, %f, %x, %%\n * - Supports bigint values\n *\n * The purpose of this function is for use in optional php-wasm tracing.\n * If we use printf-style formatting for trace messages, we let the trace\n * function decide whether to format and do not have to pay for formatting\n * unless tracing is enabled.\n */\nexport function sprintf(format: string, ...args: any[]): string {\n\tlet result = '';\n\tlet argIndex = 0;\n\n\tfor (let i = 0; i < format.length; i++) {\n\t\tif (format[i] === '%' && i + 1 < format.length) {\n\t\t\ti++;\n\t\t\tconst specifier = format[i];\n\n\t\t\tswitch (specifier) {\n\t\t\t\tcase 's': {\n\t\t\t\t\tconst arg = args[argIndex++];\n\t\t\t\t\tlet str;\n\t\t\t\t\tif (typeof arg === 'object') {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t// If an object doesn't provide its own toString(),\n\t\t\t\t\t\t\t// try to represent it as JSON.\n\t\t\t\t\t\t\tstr = JSON.stringify(\n\t\t\t\t\t\t\t\targ,\n\t\t\t\t\t\t\t\t// Represent bigint values as strings in JSON.stringify().\n\t\t\t\t\t\t\t\t(key, value) => {\n\t\t\t\t\t\t\t\t\tif (typeof value === 'bigint') {\n\t\t\t\t\t\t\t\t\t\treturn `0x${value.toString(16)}`;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\treturn value;\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t2\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t// Ignore error and use default representation.\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tstr = String(arg);\n\t\t\t\t\t}\n\n\t\t\t\t\tresult += str;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase 'd': {\n\t\t\t\t\tconst arg = args[argIndex++];\n\t\t\t\t\tif (typeof arg === 'bigint') {\n\t\t\t\t\t\tresult += arg.toString();\n\t\t\t\t\t} else {\n\t\t\t\t\t\tresult += Math.floor(Number(arg));\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase 'f': {\n\t\t\t\t\tconst arg = args[argIndex++];\n\t\t\t\t\tif (typeof arg === 'bigint') {\n\t\t\t\t\t\tresult += Number(arg);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tresult += Number(arg);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase 'x': {\n\t\t\t\t\tconst arg = args[argIndex++];\n\t\t\t\t\tif (typeof arg === 'bigint') {\n\t\t\t\t\t\tresult += arg.toString(16);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tresult += Math.floor(Number(arg)).toString(16);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase '%': {\n\t\t\t\t\tresult += '%';\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\tresult += '%' + specifier;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tresult += format[i];\n\t\t}\n\t}\n\n\treturn result;\n}\n","import Semaphore, { AcquireTimeoutError } from './semaphore';\nexport { Semaphore, AcquireTimeoutError };\nexport { PhpWasmError } from './php-wasm-error';\nexport type { SemaphoreOptions } from './semaphore';\nexport {\n\tdirname,\n\tjoinPaths,\n\tbasename,\n\tnormalizePath,\n\tisParentOf,\n} from './paths';\nexport { createSpawnHandler } from './create-spawn-handler';\nexport { randomString } from './random-string';\nexport { randomFilename } from './random-filename';\nexport { WritablePolyfill, type WritableOptions } from './writable-polyfill';\nexport { EventEmitterPolyfill } from './event-emitter-polyfill';\nexport * from './php-vars';\n\nexport * from './sprintf';\n\nexport function concatUint8Arrays(arrays: Uint8Array[]): Uint8Array {\n\tlet totalLength = 0;\n\tarrays.forEach((a) => (totalLength += a.length));\n\tconst result = new Uint8Array(totalLength);\n\tlet offset = 0;\n\tarrays.forEach((a) => {\n\t\tresult.set(a, offset);\n\t\toffset += a.length;\n\t});\n\treturn result;\n}\n\nexport function concatArrayBuffers(buffers: ArrayBuffer[]): ArrayBuffer {\n\treturn concatUint8Arrays(buffers.map((b) => new Uint8Array(b)))\n\t\t.buffer as ArrayBuffer;\n}\n\nexport * from './types';\n"],"names":["SleepFinished","sleep","ms","resolve","AcquireTimeoutError","Semaphore","concurrency","timeout","acquired","value","released","fn","release","PhpWasmError","message","userFriendlyMessage","joinPaths","paths","hasTrailingSlash","p","path","isAbsolute","trailingSlash","normalizePath","dirname","lastSlash","basename","normalizePathsArray","parts","allowAboveRoot","up","i","last","isParentOf","parent","child","EventEmitterPolyfill","eventName","data","listener","wrappedListener","args","l","splitShellCommand","command","mode","quote","currentPart","char","WritablePolyfill","opts","chunk","encoding","cb","err","defer","needDrain","enc","entry","createSpawnHandler","program","argsArray","options","childProcess","ChildProcess","processApi","ProcessApi","commandArray","promise","e","code","lastPid","pid","self","randomString","length","specialChars","chars","result","randomFilename","phpVar","stringToBase64","phpVars","vars","key","str","bytesToBase64","bytes","binString","sprintf","format","argIndex","specifier","arg","concatUint8Arrays","arrays","totalLength","a","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IrB;AAAA,QAAA;AAAA,QAED,KAAK,KAAK;AACH,gBAAAA,IAAMpD,EAAKkD,GAAU;AACvB,UAAA,OAAOE,KAAQ,WACRf,KAAAe,EAAI,SAAS,EAAE,IAEzBf,KAAU,KAAK,MAAM,OAAOe,CAAG,CAAC,EAAE,SAAS,EAAE;AAE9C;AAAA,QAAA;AAAA,QAED,KAAK,KAAK;AACC,UAAAf,KAAA;AACV;AAAA,QAAA;AAAA,QAED;AACC,UAAAA,KAAU,MAAMc;AAAA,MACjB;AAAA,IACD;AAEA,MAAAd,KAAUY,EAAO3D,CAAC;AAIb,SAAA+C;AACR;ACvEO,SAASgB,EAAkBC,GAAkC;AACnE,MAAIC,IAAc;AAClB,EAAAD,EAAO,QAAQ,CAACE,MAAOD,KAAeC,EAAE,MAAO;AACzC,QAAAnB,IAAS,IAAI,WAAWkB,CAAW;AACzC,MAAIE,IAAS;AACN,SAAAH,EAAA,QAAQ,CAACE,MAAM;AACd,IAAAnB,EAAA,IAAImB,GAAGC,CAAM,GACpBA,KAAUD,EAAE;AAAA,EAAA,CACZ,GACMnB;AACR;AAEO,SAASqB,EAAmBC,GAAqC;AAChE,SAAAN,EAAkBM,EAAQ,IAAI,CAACC,MAAM,IAAI,WAAWA,CAAC,CAAC,CAAC,EAC5D;AACH;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@php-wasm/util",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"types": "index.d.ts",
|
|
6
6
|
"typedoc": {
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"main": "./index.cjs",
|
|
25
25
|
"module": "./index.js",
|
|
26
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "886a4a87ea86fed4f76ef1d71fc53601fc90c724",
|
|
27
27
|
"engines": {
|
|
28
28
|
"node": ">=20.18.3",
|
|
29
29
|
"npm": ">=10.1.0"
|