@php-wasm/util 1.1.2 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=Symbol("SleepFinished");function m(t){return new Promise(e=>{setTimeout(()=>e(f),t)})}class a extends Error{constructor(){super("Acquiring lock timed out")}}class E{constructor({concurrency:e,timeout:i}){this._running=0,this.concurrency=e,this.timeout=i,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(i=>{this.queue.push(i)});this.timeout!==void 0?await Promise.race([e,m(this.timeout)]).then(i=>{if(i===f)throw new a}):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 i=await this.acquire();try{return await e()}finally{i()}}}class p extends Error{constructor(e,i){super(e),this.userFriendlyMessage=i??e}}function y(...t){function e(u){return u.substring(u.length-1)==="/"}let i=t.join("/");const s=i[0]==="/",r=e(i);return i=c(i),!i&&!s&&(i="."),i&&r&&!e(i)&&(i+="/"),i}function P(t){if(t==="/")return"/";t=c(t);const e=t.lastIndexOf("/");return e===-1?"":e===0?"/":t.substr(0,e)}function w(t){if(t==="/")return"/";t=c(t);const e=t.lastIndexOf("/");return e===-1?t:t.substr(e+1)}function c(t){const e=t[0]==="/";return t=O(t.split("/").filter(i=>!!i),!e).join("/"),(e?"/":"")+t.replace(/\/$/,"")}function O(t,e){let i=0;for(let s=t.length-1;s>=0;s--){const r=t[s];r==="."?t.splice(s,1):r===".."?(t.splice(s,1),i++):i&&(t.splice(s,1),i--)}if(e)for(;i;i--)t.unshift("..");return t}function S(t,e){return t==="/"?!0:(t=c(t),e=c(e),e.startsWith(t+"/")||e===t)}function D(t){let s=0,r="";const u=[];let n="";for(let o=0;o<t.length;o++){const l=t[o];l==="\\"?((t[o+1]==='"'||t[o+1]==="'")&&o++,n+=t[o]):s===0?l==='"'||l==="'"?(s=1,r=l):l.match(/\s/)?(n.trim().length&&u.push(n.trim()),n=l):u.length&&!n?n=u.pop()+l:n+=l:s===1&&(l===r?(s=0,r=""):n+=l)}return n&&u.push(n.trim()),u}function T(t){return function(e,i=[],s={}){const r=new x,u=new _(r);return setTimeout(async()=>{let n=[];if(i.length)n=[e,...i];else if(typeof e=="string")n=D(e);else if(Array.isArray(e))n=e;else throw new Error("Invalid command ",e);try{await t(n,u,s)}catch(o){r.emit("error",o),typeof o=="object"&&o!==null&&"message"in o&&typeof o.message=="string"&&u.stderr(o.message),u.exit(1)}r.emit("spawn",!0)}),r}}class h{constructor(){this.listeners={}}emit(e,i){this.listeners[e]&&this.listeners[e].forEach(function(s){s(i)})}on(e,i){this.listeners[e]||(this.listeners[e]=[]),this.listeners[e].push(i)}}class _ extends h{constructor(e){super(),this.exited=!1,this.stdinData=[],this.childProcess=e,e.on("stdin",i=>{this.stdinData?this.stdinData.push(i.slice()):this.emit("stdin",i)})}stdout(e){typeof e=="string"&&(e=new TextEncoder().encode(e)),this.childProcess.stdout.emit("data",e)}stdoutEnd(){this.childProcess.stdout.emit("end",{})}stderr(e){typeof e=="string"&&(e=new TextEncoder().encode(e)),this.childProcess.stderr.emit("data",e)}stderrEnd(){this.childProcess.stderr.emit("end",{})}exit(e){this.exited||(this.exited=!0,this.childProcess.emit("exit",e))}flushStdin(){if(this.stdinData)for(let e=0;e<this.stdinData.length;e++)this.emit("stdin",this.stdinData[e]);this.stdinData=null}}let b=9743;class x extends h{constructor(e=b++){super(),this.stdout=new h,this.stderr=new h;const i=this;this.pid=e,this.stdin={write:s=>{i.emit("stdin",s)}}}}function d(t=36,e="!@#$%^&*()_+=-[]/.,<>?"){const i="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"+e;let s="";for(let r=t;r>0;--r)s+=i[Math.floor(Math.random()*i.length)];return s}function q(){return d(36,"-_")}function g(t){return`json_decode(base64_decode('${U(JSON.stringify(t))}'), true)`}function M(t){const e={};for(const i in t)e[i]=g(t[i]);return e}function U(t){return A(new TextEncoder().encode(t))}function A(t){const e=String.fromCodePoint(...t);return btoa(e)}exports.AcquireTimeoutError=a;exports.PhpWasmError=p;exports.Semaphore=E;exports.basename=w;exports.createSpawnHandler=T;exports.dirname=P;exports.isParentOf=S;exports.joinPaths=y;exports.normalizePath=c;exports.phpVar=g;exports.phpVars=M;exports.randomFilename=q;exports.randomString=d;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=Symbol("SleepFinished");function E(e){return new Promise(t=>{setTimeout(()=>t(h),e)})}class a extends Error{constructor(){super("Acquiring lock timed out")}}class y{constructor({concurrency:t,timeout:i}){this._running=0,this.concurrency=t,this.timeout=i,this.queue=[]}get remaining(){return this.concurrency-this.running}get running(){return this._running}async acquire(){for(;;)if(this._running>=this.concurrency){const t=new Promise(i=>{this.queue.push(i)});this.timeout!==void 0?await Promise.race([t,E(this.timeout)]).then(i=>{if(i===h)throw new a}):await t}else{this._running++;let t=!1;return()=>{t||(t=!0,this._running--,this.queue.length>0&&this.queue.shift()())}}}async run(t){const i=await this.acquire();try{return await t()}finally{i()}}}class p extends Error{constructor(t,i){super(t),this.userFriendlyMessage=i??t}}function w(...e){function t(u){return u.substring(u.length-1)==="/"}let i=e.join("/");const s=i[0]==="/",n=t(i);return i=l(i),!i&&!s&&(i="."),i&&n&&!t(i)&&(i+="/"),i}function P(e){if(e==="/")return"/";e=l(e);const t=e.lastIndexOf("/");return t===-1?"":t===0?"/":e.substr(0,t)}function S(e){if(e==="/")return"/";e=l(e);const t=e.lastIndexOf("/");return t===-1?e:e.substr(t+1)}function l(e){const t=e[0]==="/";return e=O(e.split("/").filter(i=>!!i),!t).join("/"),(t?"/":"")+e.replace(/\/$/,"")}function O(e,t){let i=0;for(let s=e.length-1;s>=0;s--){const n=e[s];n==="."?e.splice(s,1):n===".."?(e.splice(s,1),i++):i&&(e.splice(s,1),i--)}if(t)for(;i;i--)e.unshift("..");return e}function D(e,t){return e==="/"?!0:(e=l(e),t=l(t),t.startsWith(e+"/")||t===e)}function T(e){let s=0,n="";const u=[];let r="";for(let o=0;o<e.length;o++){const c=e[o];c==="\\"?((e[o+1]==='"'||e[o+1]==="'")&&o++,r+=e[o]):s===0?c==='"'||c==="'"?(s=1,n=c):c.match(/\s/)?(r.trim().length&&u.push(r.trim()),r=c):u.length&&!r?r=u.pop()+c:r+=c:s===1&&(c===n?(s=0,n=""):r+=c)}return r&&u.push(r.trim()),u}function _(e){return function(t,i=[],s={}){const n=new x,u=new b(n);return setTimeout(async()=>{let r=[];if(i.length)r=[t,...i];else if(typeof t=="string")r=T(t);else if(Array.isArray(t))r=t;else throw new Error("Invalid command ",t);try{await e(r,u,s)}catch(o){n.emit("error",o),typeof o=="object"&&o!==null&&"message"in o&&typeof o.message=="string"&&u.stderr(o.message),u.exit(1)}n.emit("spawn",!0)}),n}}class f{constructor(){this.listeners={}}emit(t,i){this.listeners[t]&&this.listeners[t].forEach(function(s){s(i)})}on(t,i){this.listeners[t]||(this.listeners[t]=[]),this.listeners[t].push(i)}}class b extends f{constructor(t){super(),this.exited=!1,this.stdinData=[],this.childProcess=t,t.on("stdin",i=>{this.stdinData?this.stdinData.push(i.slice()):this.emit("stdin",i)})}stdout(t){typeof t=="string"&&(t=new TextEncoder().encode(t)),this.childProcess.stdout.emit("data",t)}stdoutEnd(){this.childProcess.stdout.emit("end",{})}stderr(t){typeof t=="string"&&(t=new TextEncoder().encode(t)),this.childProcess.stderr.emit("data",t)}stderrEnd(){this.childProcess.stderr.emit("end",{})}notifySpawn(){this.childProcess.emit("spawn",!0)}exit(t){this.exited||(this.exited=!0,this.childProcess.emit("exit",t))}flushStdin(){if(this.stdinData)for(let t=0;t<this.stdinData.length;t++)this.emit("stdin",this.stdinData[t]);this.stdinData=null}}let A=9743;class x extends f{constructor(t=A++){super(),this.stdout=new f,this.stderr=new f;const i=this;this.pid=t,this.stdin={write:s=>{i.emit("stdin",s)}}}}function d(e=36,t="!@#$%^&*()_+=-[]/.,<>?"){const i="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"+t;let s="";for(let n=e;n>0;--n)s+=i[Math.floor(Math.random()*i.length)];return s}function U(){return d(36,"-_")}function g(e){return`json_decode(base64_decode('${M(JSON.stringify(e))}'), true)`}function q(e){const t={};for(const i in e)t[i]=g(e[i]);return t}function M(e){return j(new TextEncoder().encode(e))}function j(e){const t=String.fromCodePoint(...e);return btoa(t)}function m(e){let t=0;e.forEach(n=>t+=n.length);const i=new Uint8Array(t);let s=0;return e.forEach(n=>{i.set(n,s),s+=n.length}),i}function Q(e){return m(e.map(t=>new Uint8Array(t))).buffer}exports.AcquireTimeoutError=a;exports.PhpWasmError=p;exports.Semaphore=y;exports.basename=S;exports.concatArrayBuffers=Q;exports.concatUint8Arrays=m;exports.createSpawnHandler=_;exports.dirname=P;exports.isParentOf=D;exports.joinPaths=w;exports.normalizePath=l;exports.phpVar=g;exports.phpVars=q;exports.randomFilename=U;exports.randomString=d;
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/split-shell-command.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"],"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 * 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","import { splitShellCommand } from './split-shell-command';\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\tawait program(commandArray, processApi, options);\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\tchildProcess.emit('spawn', true);\n\t\t});\n\t\treturn childProcess;\n\t};\n}\n\nclass EventEmitter {\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}\n\nexport class ProcessApi extends EventEmitter {\n\tprivate exited = false;\n\tprivate stdinData: 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.stdinData) {\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.stdinData.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\tstdout(data: string | ArrayBuffer) {\n\t\tif (typeof data === 'string') {\n\t\t\tdata = new TextEncoder().encode(data);\n\t\t}\n\t\tthis.childProcess.stdout.emit('data', data);\n\t}\n\tstdoutEnd() {\n\t\tthis.childProcess.stdout.emit('end', {});\n\t}\n\tstderr(data: string | ArrayBuffer) {\n\t\tif (typeof data === 'string') {\n\t\t\tdata = new TextEncoder().encode(data);\n\t\t}\n\t\tthis.childProcess.stderr.emit('data', data);\n\t}\n\tstderrEnd() {\n\t\tthis.childProcess.stderr.emit('end', {});\n\t}\n\texit(code: number) {\n\t\tif (!this.exited) {\n\t\t\tthis.exited = true;\n\t\t\tthis.childProcess.emit('exit', code);\n\t\t}\n\t}\n\tflushStdin() {\n\t\tif (this.stdinData) {\n\t\t\tfor (let i = 0; i < this.stdinData.length; i++) {\n\t\t\t\tthis.emit('stdin', this.stdinData[i]);\n\t\t\t}\n\t\t}\n\t\tthis.stdinData = null;\n\t}\n}\n\nexport type StdIn = {\n\twrite: (data: string) => void;\n};\n\nlet lastPid = 9743;\nexport class ChildProcess extends EventEmitter {\n\tstdout: EventEmitter = new EventEmitter();\n\tstderr: EventEmitter = new EventEmitter();\n\tstdin: StdIn;\n\tpid: number;\n\tconstructor(pid = lastPid++) {\n\t\tsuper();\n\t\t// eslint-disable-next-line @typescript-eslint/no-this-alias\n\t\tconst self = this;\n\t\tthis.pid = pid;\n\t\tthis.stdin = {\n\t\t\twrite: (data: string) => {\n\t\t\t\tself.emit('stdin', data);\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"],"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","splitShellCommand","command","mode","quote","currentPart","char","createSpawnHandler","program","argsArray","options","childProcess","ChildProcess","processApi","ProcessApi","commandArray","e","EventEmitter","eventName","data","listener","code","lastPid","pid","self","randomString","length","specialChars","chars","result","randomFilename","phpVar","stringToBase64","phpVars","vars","key","str","bytesToBase64","bytes","binString"],"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,CAC1C,KAAA,MAAM,KAAKA,CAAO,CAAA,CACvB,EACG,KAAK,UAAY,OACd,MAAA,QAAQ,KAAK,CAACK,EAAUP,EAAM,KAAK,OAAO,CAAC,CAAC,EAAE,KAClDQ,GAAU,CACV,GAAIA,IAAUT,EACb,MAAM,IAAII,CACX,CAEF,EAEM,MAAAI,CACP,KACM,CAED,KAAA,WACL,IAAIE,EAAW,GACf,MAAO,IAAM,CACRA,IAGOA,EAAA,GACN,KAAA,WAED,KAAK,MAAM,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ACR,CCTO,SAASC,GAAiB,CACzB,OAAAL,EAAa,GAAI,IAAI,CAC7B,CCJO,SAASM,EAAOzD,EAAwB,CAC9C,MAAO,8BAA8B0D,EACpC,KAAK,UAAU1D,CAAK,CACpB,CAAA,WACF,CAEO,SAAS2D,EACfC,EAC0B,CAC1B,MAAML,EAAiC,CAAC,EACxC,UAAWM,KAAOD,EACjBL,EAAOM,CAAG,EAAIJ,EAAOG,EAAKC,CAAG,CAAC,EAExB,OAAAN,CACR,CAEA,SAASG,EAAeI,EAAa,CACpC,OAAOC,EAAc,IAAI,YAAc,EAAA,OAAOD,CAAG,CAAC,CACnD,CAEA,SAASC,EAAcC,EAAmB,CACzC,MAAMC,EAAY,OAAO,cAAc,GAAGD,CAAK,EAC/C,OAAO,KAAKC,CAAS,CACtB"}
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/split-shell-command.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/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 * 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","import { splitShellCommand } from './split-shell-command';\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\tawait program(commandArray, processApi, options);\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\tchildProcess.emit('spawn', true);\n\t\t});\n\t\treturn childProcess;\n\t};\n}\n\nclass EventEmitter {\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}\n\nexport class ProcessApi extends EventEmitter {\n\tprivate exited = false;\n\tprivate stdinData: 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.stdinData) {\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.stdinData.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\tstdout(data: string | ArrayBuffer) {\n\t\tif (typeof data === 'string') {\n\t\t\tdata = new TextEncoder().encode(data);\n\t\t}\n\t\tthis.childProcess.stdout.emit('data', data);\n\t}\n\tstdoutEnd() {\n\t\tthis.childProcess.stdout.emit('end', {});\n\t}\n\tstderr(data: string | ArrayBuffer) {\n\t\tif (typeof data === 'string') {\n\t\t\tdata = new TextEncoder().encode(data);\n\t\t}\n\t\tthis.childProcess.stderr.emit('data', data);\n\t}\n\tstderrEnd() {\n\t\tthis.childProcess.stderr.emit('end', {});\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.childProcess.emit('exit', code);\n\t\t}\n\t}\n\tflushStdin() {\n\t\tif (this.stdinData) {\n\t\t\tfor (let i = 0; i < this.stdinData.length; i++) {\n\t\t\t\tthis.emit('stdin', this.stdinData[i]);\n\t\t\t}\n\t\t}\n\t\tthis.stdinData = null;\n\t}\n}\n\nexport type StdIn = {\n\twrite: (data: string) => void;\n};\n\nlet lastPid = 9743;\nexport class ChildProcess extends EventEmitter {\n\tstdout: EventEmitter = new EventEmitter();\n\tstderr: EventEmitter = new EventEmitter();\n\tstdin: StdIn;\n\tpid: number;\n\tconstructor(pid = lastPid++) {\n\t\tsuper();\n\t\t// eslint-disable-next-line @typescript-eslint/no-this-alias\n\t\tconst self = this;\n\t\tthis.pid = pid;\n\t\tthis.stdin = {\n\t\t\twrite: (data: string) => {\n\t\t\t\tself.emit('stdin', data);\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","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';\n\nexport * from './php-vars';\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))).buffer;\n}\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","splitShellCommand","command","mode","quote","currentPart","char","createSpawnHandler","program","argsArray","options","childProcess","ChildProcess","processApi","ProcessApi","commandArray","e","EventEmitter","eventName","data","listener","code","lastPid","pid","self","randomString","length","specialChars","chars","result","randomFilename","phpVar","stringToBase64","phpVars","vars","key","str","bytesToBase64","bytes","binString","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,SA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,EACMd,CACR,CAEO,SAASgB,EAAmBC,EAAqC,CAChE,OAAAN,EAAkBM,EAAQ,IAAKC,GAAM,IAAI,WAAWA,CAAC,CAAC,CAAC,EAAE,MACjE"}
package/index.js CHANGED
@@ -1,7 +1,7 @@
1
- const f = Symbol("SleepFinished");
1
+ const h = Symbol("SleepFinished");
2
2
  function a(e) {
3
3
  return new Promise((t) => {
4
- setTimeout(() => t(f), e);
4
+ setTimeout(() => t(h), e);
5
5
  });
6
6
  }
7
7
  class d extends Error {
@@ -9,7 +9,7 @@ class d extends Error {
9
9
  super("Acquiring lock timed out");
10
10
  }
11
11
  }
12
- class _ {
12
+ class x {
13
13
  constructor({ concurrency: t, timeout: s }) {
14
14
  this._running = 0, this.concurrency = t, this.timeout = s, this.queue = [];
15
15
  }
@@ -27,7 +27,7 @@ class _ {
27
27
  });
28
28
  this.timeout !== void 0 ? await Promise.race([t, a(this.timeout)]).then(
29
29
  (s) => {
30
- if (s === f)
30
+ if (s === h)
31
31
  throw new d();
32
32
  }
33
33
  ) : await t;
@@ -48,7 +48,7 @@ class _ {
48
48
  }
49
49
  }
50
50
  }
51
- class x extends Error {
51
+ class S extends Error {
52
52
  constructor(t, s) {
53
53
  super(t), this.userFriendlyMessage = s ?? t;
54
54
  }
@@ -59,23 +59,23 @@ function T(...e) {
59
59
  }
60
60
  let s = e.join("/");
61
61
  const i = s[0] === "/", n = t(s);
62
- return s = c(s), !s && !i && (s = "."), s && n && !t(s) && (s += "/"), s;
62
+ return s = l(s), !s && !i && (s = "."), s && n && !t(s) && (s += "/"), s;
63
63
  }
64
- function S(e) {
64
+ function U(e) {
65
65
  if (e === "/")
66
66
  return "/";
67
- e = c(e);
67
+ e = l(e);
68
68
  const t = e.lastIndexOf("/");
69
69
  return t === -1 ? "" : t === 0 ? "/" : e.substr(0, t);
70
70
  }
71
71
  function b(e) {
72
72
  if (e === "/")
73
73
  return "/";
74
- e = c(e);
74
+ e = l(e);
75
75
  const t = e.lastIndexOf("/");
76
76
  return t === -1 ? e : e.substr(t + 1);
77
77
  }
78
- function c(e) {
78
+ function l(e) {
79
79
  const t = e[0] === "/";
80
80
  return e = g(
81
81
  e.split("/").filter((s) => !!s),
@@ -93,16 +93,16 @@ function g(e, t) {
93
93
  e.unshift("..");
94
94
  return e;
95
95
  }
96
- function U(e, t) {
97
- return e === "/" ? !0 : (e = c(e), t = c(t), t.startsWith(e + "/") || t === e);
96
+ function A(e, t) {
97
+ return e === "/" ? !0 : (e = l(e), t = l(t), t.startsWith(e + "/") || t === e);
98
98
  }
99
99
  function m(e) {
100
100
  let i = 0, n = "";
101
101
  const u = [];
102
102
  let r = "";
103
103
  for (let o = 0; o < e.length; o++) {
104
- const l = e[o];
105
- l === "\\" ? ((e[o + 1] === '"' || e[o + 1] === "'") && o++, r += e[o]) : i === 0 ? l === '"' || l === "'" ? (i = 1, n = l) : l.match(/\s/) ? (r.trim().length && u.push(r.trim()), r = l) : u.length && !r ? r = u.pop() + l : r += l : i === 1 && (l === n ? (i = 0, n = "") : r += l);
104
+ const c = e[o];
105
+ c === "\\" ? ((e[o + 1] === '"' || e[o + 1] === "'") && o++, r += e[o]) : i === 0 ? c === '"' || c === "'" ? (i = 1, n = c) : c.match(/\s/) ? (r.trim().length && u.push(r.trim()), r = c) : u.length && !r ? r = u.pop() + c : r += c : i === 1 && (c === n ? (i = 0, n = "") : r += c);
106
106
  }
107
107
  return r && u.push(r.trim()), u;
108
108
  }
@@ -128,7 +128,7 @@ function q(e) {
128
128
  }), n;
129
129
  };
130
130
  }
131
- class h {
131
+ class f {
132
132
  constructor() {
133
133
  this.listeners = {};
134
134
  }
@@ -141,7 +141,7 @@ class h {
141
141
  this.listeners[t] || (this.listeners[t] = []), this.listeners[t].push(s);
142
142
  }
143
143
  }
144
- class E extends h {
144
+ class E extends f {
145
145
  constructor(t) {
146
146
  super(), this.exited = !1, this.stdinData = [], this.childProcess = t, t.on("stdin", (s) => {
147
147
  this.stdinData ? this.stdinData.push(s.slice()) : this.emit("stdin", s);
@@ -159,6 +159,9 @@ class E extends h {
159
159
  stderrEnd() {
160
160
  this.childProcess.stderr.emit("end", {});
161
161
  }
162
+ notifySpawn() {
163
+ this.childProcess.emit("spawn", !0);
164
+ }
162
165
  exit(t) {
163
166
  this.exited || (this.exited = !0, this.childProcess.emit("exit", t));
164
167
  }
@@ -170,9 +173,9 @@ class E extends h {
170
173
  }
171
174
  }
172
175
  let w = 9743;
173
- class y extends h {
176
+ class y extends f {
174
177
  constructor(t = w++) {
175
- super(), this.stdout = new h(), this.stderr = new h();
178
+ super(), this.stdout = new f(), this.stderr = new f();
176
179
  const s = this;
177
180
  this.pid = t, this.stdin = {
178
181
  write: (i) => {
@@ -181,7 +184,7 @@ class y extends h {
181
184
  };
182
185
  }
183
186
  }
184
- function P(e = 36, t = "!@#$%^&*()_+=-[]/.,<>?") {
187
+ function p(e = 36, t = "!@#$%^&*()_+=-[]/.,<>?") {
185
188
  const s = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" + t;
186
189
  let i = "";
187
190
  for (let n = e; n > 0; --n)
@@ -189,17 +192,17 @@ function P(e = 36, t = "!@#$%^&*()_+=-[]/.,<>?") {
189
192
  return i;
190
193
  }
191
194
  function M() {
192
- return P(36, "-_");
195
+ return p(36, "-_");
193
196
  }
194
- function p(e) {
197
+ function P(e) {
195
198
  return `json_decode(base64_decode('${D(
196
199
  JSON.stringify(e)
197
200
  )}'), true)`;
198
201
  }
199
- function A(e) {
202
+ function Q(e) {
200
203
  const t = {};
201
204
  for (const s in e)
202
- t[s] = p(e[s]);
205
+ t[s] = P(e[s]);
203
206
  return t;
204
207
  }
205
208
  function D(e) {
@@ -209,19 +212,33 @@ function O(e) {
209
212
  const t = String.fromCodePoint(...e);
210
213
  return btoa(t);
211
214
  }
215
+ function _(e) {
216
+ let t = 0;
217
+ e.forEach((n) => t += n.length);
218
+ const s = new Uint8Array(t);
219
+ let i = 0;
220
+ return e.forEach((n) => {
221
+ s.set(n, i), i += n.length;
222
+ }), s;
223
+ }
224
+ function I(e) {
225
+ return _(e.map((t) => new Uint8Array(t))).buffer;
226
+ }
212
227
  export {
213
228
  d as AcquireTimeoutError,
214
- x as PhpWasmError,
215
- _ as Semaphore,
229
+ S as PhpWasmError,
230
+ x as Semaphore,
216
231
  b as basename,
232
+ I as concatArrayBuffers,
233
+ _ as concatUint8Arrays,
217
234
  q as createSpawnHandler,
218
- S as dirname,
219
- U as isParentOf,
235
+ U as dirname,
236
+ A as isParentOf,
220
237
  T as joinPaths,
221
- c as normalizePath,
222
- p as phpVar,
223
- A as phpVars,
238
+ l as normalizePath,
239
+ P as phpVar,
240
+ Q as phpVars,
224
241
  M as randomFilename,
225
- P as randomString
242
+ p as randomString
226
243
  };
227
244
  //# sourceMappingURL=index.js.map
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/split-shell-command.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"],"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 * 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","import { splitShellCommand } from './split-shell-command';\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\tawait program(commandArray, processApi, options);\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\tchildProcess.emit('spawn', true);\n\t\t});\n\t\treturn childProcess;\n\t};\n}\n\nclass EventEmitter {\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}\n\nexport class ProcessApi extends EventEmitter {\n\tprivate exited = false;\n\tprivate stdinData: 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.stdinData) {\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.stdinData.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\tstdout(data: string | ArrayBuffer) {\n\t\tif (typeof data === 'string') {\n\t\t\tdata = new TextEncoder().encode(data);\n\t\t}\n\t\tthis.childProcess.stdout.emit('data', data);\n\t}\n\tstdoutEnd() {\n\t\tthis.childProcess.stdout.emit('end', {});\n\t}\n\tstderr(data: string | ArrayBuffer) {\n\t\tif (typeof data === 'string') {\n\t\t\tdata = new TextEncoder().encode(data);\n\t\t}\n\t\tthis.childProcess.stderr.emit('data', data);\n\t}\n\tstderrEnd() {\n\t\tthis.childProcess.stderr.emit('end', {});\n\t}\n\texit(code: number) {\n\t\tif (!this.exited) {\n\t\t\tthis.exited = true;\n\t\t\tthis.childProcess.emit('exit', code);\n\t\t}\n\t}\n\tflushStdin() {\n\t\tif (this.stdinData) {\n\t\t\tfor (let i = 0; i < this.stdinData.length; i++) {\n\t\t\t\tthis.emit('stdin', this.stdinData[i]);\n\t\t\t}\n\t\t}\n\t\tthis.stdinData = null;\n\t}\n}\n\nexport type StdIn = {\n\twrite: (data: string) => void;\n};\n\nlet lastPid = 9743;\nexport class ChildProcess extends EventEmitter {\n\tstdout: EventEmitter = new EventEmitter();\n\tstderr: EventEmitter = new EventEmitter();\n\tstdin: StdIn;\n\tpid: number;\n\tconstructor(pid = lastPid++) {\n\t\tsuper();\n\t\t// eslint-disable-next-line @typescript-eslint/no-this-alias\n\t\tconst self = this;\n\t\tthis.pid = pid;\n\t\tthis.stdin = {\n\t\t\twrite: (data: string) => {\n\t\t\t\tself.emit('stdin', data);\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"],"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","last","isParentOf","parent","child","splitShellCommand","command","mode","quote","currentPart","i","char","createSpawnHandler","program","argsArray","options","childProcess","ChildProcess","processApi","ProcessApi","commandArray","e","EventEmitter","eventName","data","listener","code","lastPid","pid","self","randomString","length","specialChars","chars","result","randomFilename","phpVar","stringToBase64","phpVars","vars","key","str","bytesToBase64","bytes","binString"],"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;AAAA,EAGb,MAAM,UAA+B;AACpC;AACK,UAAA,KAAK,YAAY,KAAK,aAAa;AAEtC,cAAMC,IAAW,IAAI,QAAc,CAACL,MAAY;AAC1C,eAAA,MAAM,KAAKA,CAAO;AAAA,QAAA,CACvB;AACG,QAAA,KAAK,YAAY,SACd,MAAA,QAAQ,KAAK,CAACK,GAAUP,EAAM,KAAK,OAAO,CAAC,CAAC,EAAE;AAAA,UACnD,CAACQ,MAAU;AACV,gBAAIA,MAAUT;AACb,oBAAM,IAAII,EAAoB;AAAA,UAC/B;AAAA,QAEF,IAEM,MAAAI;AAAA,MACP,OACM;AAED,aAAA;AACL,YAAIE,IAAW;AACf,eAAO,MAAM;AACZ,UAAIA,MAGOA,IAAA,IACN,KAAA,YAED,KAAK,MAAM,SAAS,KAClB,KAAA,MAAM,QAAS;AAAA,QAEtB;AAAA,MAAA;AAAA,EAEF;AAAA,EAGD,MAAM,IAAOC,GAAsC;AAC5C,UA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AAO,CAACJ,MAAiB;AACnB,QAAAK,EAAA,KAAK,SAASL,CAAI;AAAA,MAAA;AAAA,IAEzB;AAAA,EAAA;AAEF;AC9JO,SAASM,EACfC,IAAS,IACTC,IAAe,0BACd;AACD,QAAMC,IACL,mEACAD;AACD,MAAIE,IAAS;AACb,WAASxB,IAAIqB,GAAQrB,IAAI,GAAG,EAAEA;AACnB,IAAAwB,KAAAD,EAAM,KAAK,MAAM,KAAK,OAAW,IAAAA,EAAM,MAAM,CAAC;AAClD,SAAAC;AACR;ACTO,SAASC,IAAiB;AACzB,SAAAL,EAAa,IAAI,IAAI;AAC7B;ACJO,SAASM,EAAOzD,GAAwB;AAC9C,SAAO,8BAA8B0D;AAAA,IACpC,KAAK,UAAU1D,CAAK;AAAA,EACpB,CAAA;AACF;AAEO,SAAS2D,EACfC,GAC0B;AAC1B,QAAML,IAAiC,CAAC;AACxC,aAAWM,KAAOD;AACjB,IAAAL,EAAOM,CAAG,IAAIJ,EAAOG,EAAKC,CAAG,CAAC;AAExB,SAAAN;AACR;AAEA,SAASG,EAAeI,GAAa;AACpC,SAAOC,EAAc,IAAI,YAAc,EAAA,OAAOD,CAAG,CAAC;AACnD;AAEA,SAASC,EAAcC,GAAmB;AACzC,QAAMC,IAAY,OAAO,cAAc,GAAGD,CAAK;AAC/C,SAAO,KAAKC,CAAS;AACtB;"}
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/split-shell-command.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/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 * 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","import { splitShellCommand } from './split-shell-command';\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\tawait program(commandArray, processApi, options);\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\tchildProcess.emit('spawn', true);\n\t\t});\n\t\treturn childProcess;\n\t};\n}\n\nclass EventEmitter {\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}\n\nexport class ProcessApi extends EventEmitter {\n\tprivate exited = false;\n\tprivate stdinData: 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.stdinData) {\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.stdinData.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\tstdout(data: string | ArrayBuffer) {\n\t\tif (typeof data === 'string') {\n\t\t\tdata = new TextEncoder().encode(data);\n\t\t}\n\t\tthis.childProcess.stdout.emit('data', data);\n\t}\n\tstdoutEnd() {\n\t\tthis.childProcess.stdout.emit('end', {});\n\t}\n\tstderr(data: string | ArrayBuffer) {\n\t\tif (typeof data === 'string') {\n\t\t\tdata = new TextEncoder().encode(data);\n\t\t}\n\t\tthis.childProcess.stderr.emit('data', data);\n\t}\n\tstderrEnd() {\n\t\tthis.childProcess.stderr.emit('end', {});\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.childProcess.emit('exit', code);\n\t\t}\n\t}\n\tflushStdin() {\n\t\tif (this.stdinData) {\n\t\t\tfor (let i = 0; i < this.stdinData.length; i++) {\n\t\t\t\tthis.emit('stdin', this.stdinData[i]);\n\t\t\t}\n\t\t}\n\t\tthis.stdinData = null;\n\t}\n}\n\nexport type StdIn = {\n\twrite: (data: string) => void;\n};\n\nlet lastPid = 9743;\nexport class ChildProcess extends EventEmitter {\n\tstdout: EventEmitter = new EventEmitter();\n\tstderr: EventEmitter = new EventEmitter();\n\tstdin: StdIn;\n\tpid: number;\n\tconstructor(pid = lastPid++) {\n\t\tsuper();\n\t\t// eslint-disable-next-line @typescript-eslint/no-this-alias\n\t\tconst self = this;\n\t\tthis.pid = pid;\n\t\tthis.stdin = {\n\t\t\twrite: (data: string) => {\n\t\t\t\tself.emit('stdin', data);\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","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';\n\nexport * from './php-vars';\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))).buffer;\n}\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","last","isParentOf","parent","child","splitShellCommand","command","mode","quote","currentPart","i","char","createSpawnHandler","program","argsArray","options","childProcess","ChildProcess","processApi","ProcessApi","commandArray","e","EventEmitter","eventName","data","listener","code","lastPid","pid","self","randomString","length","specialChars","chars","result","randomFilename","phpVar","stringToBase64","phpVars","vars","key","str","bytesToBase64","bytes","binString","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,M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ACD,QAAMC,IACL,mEACAD;AACD,MAAIE,IAAS;AACb,WAASxB,IAAIqB,GAAQrB,IAAI,GAAG,EAAEA;AACnB,IAAAwB,KAAAD,EAAM,KAAK,MAAM,KAAK,OAAW,IAAAA,EAAM,MAAM,CAAC;AAClD,SAAAC;AACR;ACTO,SAASC,IAAiB;AACzB,SAAAL,EAAa,IAAI,IAAI;AAC7B;ACJO,SAASM,EAAOzD,GAAwB;AAC9C,SAAO,8BAA8B0D;AAAA,IACpC,KAAK,UAAU1D,CAAK;AAAA,EACpB,CAAA;AACF;AAEO,SAAS2D,EACfC,GAC0B;AAC1B,QAAML,IAAiC,CAAC;AACxC,aAAWM,KAAOD;AACjB,IAAAL,EAAOM,CAAG,IAAIJ,EAAOG,EAAKC,CAAG,CAAC;AAExB,SAAAN;AACR;AAEA,SAASG,EAAeI,GAAa;AACpC,SAAOC,EAAc,IAAI,YAAc,EAAA,OAAOD,CAAG,CAAC;AACnD;AAEA,SAASC,EAAcC,GAAmB;AACzC,QAAMC,IAAY,OAAO,cAAc,GAAGD,CAAK;AAC/C,SAAO,KAAKC,CAAS;AACtB;ACNO,SAASC,EAAkBC,GAAkC;AACnE,MAAIC,IAAc;AAClB,EAAAD,EAAO,QAAQ,CAACE,MAAOD,KAAeC,EAAE,MAAO;AACzC,QAAAd,IAAS,IAAI,WAAWa,CAAW;AACzC,MAAIE,IAAS;AACN,SAAAH,EAAA,QAAQ,CAACE,MAAM;AACd,IAAAd,EAAA,IAAIc,GAAGC,CAAM,GACpBA,KAAUD,EAAE;AAAA,EAAA,CACZ,GACMd;AACR;AAEO,SAASgB,EAAmBC,GAAqC;AAChE,SAAAN,EAAkBM,EAAQ,IAAI,CAACC,MAAM,IAAI,WAAWA,CAAC,CAAC,CAAC,EAAE;AACjE;"}
@@ -32,6 +32,7 @@ export declare class ProcessApi extends EventEmitter {
32
32
  stdoutEnd(): void;
33
33
  stderr(data: string | ArrayBuffer): void;
34
34
  stderrEnd(): void;
35
+ notifySpawn(): void;
35
36
  exit(code: number): void;
36
37
  flushStdin(): void;
37
38
  }
package/lib/index.d.ts CHANGED
@@ -7,3 +7,5 @@ export { createSpawnHandler } from './create-spawn-handler';
7
7
  export { randomString } from './random-string';
8
8
  export { randomFilename } from './random-filename';
9
9
  export * from './php-vars';
10
+ export declare function concatUint8Arrays(arrays: Uint8Array[]): Uint8Array;
11
+ export declare function concatArrayBuffers(buffers: ArrayBuffer[]): ArrayBuffer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@php-wasm/util",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
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": "59c2db1ec41efa10ffa01e6e1ea7ac6e78bc693e",
26
+ "gitHead": "977f8e90eabb2c8d4eed75677ddd9fb6c13274ae",
27
27
  "engines": {
28
28
  "node": ">=20.18.3",
29
29
  "npm": ">=10.1.0"