@php-wasm/util 0.9.20 → 0.9.21

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.
Files changed (3) hide show
  1. package/index.cjs +1 -1
  2. package/index.js +35 -32
  3. package/package.json +2 -2
package/index.cjs CHANGED
@@ -1 +1 @@
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:s}){this._running=0,this.concurrency=e,this.timeout=s,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(s=>{this.queue.push(s)});this.timeout!==void 0?await Promise.race([e,m(this.timeout)]).then(s=>{if(s===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 s=await this.acquire();try{return await e()}finally{s()}}}class p extends Error{constructor(e,s){super(e),this.userFriendlyMessage=s,this.userFriendlyMessage||(this.userFriendlyMessage=e)}}function y(...t){let e=t.join("/");const s=e[0]==="/",i=e.substring(e.length-1)==="/";return e=c(e),!e&&!s&&(e="."),e&&i&&(e+="/"),e}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(s=>!!s),!e).join("/"),(e?"/":"")+t.replace(/\/$/,"")}function O(t,e){let s=0;for(let i=t.length-1;i>=0;i--){const n=t[i];n==="."?t.splice(i,1):n===".."?(t.splice(i,1),s++):s&&(t.splice(i,1),s--)}if(e)for(;s;s--)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 i=0,n="";const l=[];let r="";for(let o=0;o<t.length;o++){const u=t[o];u==="\\"?((t[o+1]==='"'||t[o+1]==="'")&&o++,r+=t[o]):i===0?u==='"'||u==="'"?(i=1,n=u):u.match(/\s/)?(r.trim().length&&l.push(r.trim()),r=u):l.length&&!r?r=l.pop()+u:r+=u:i===1&&(u===n?(i=0,n=""):r+=u)}return r&&l.push(r.trim()),l}function _(t){return function(e,s=[],i={}){const n=new x,l=new T(n);return setTimeout(async()=>{let r=[];if(s.length)r=[e,...s];else if(typeof e=="string")r=D(e);else if(Array.isArray(e))r=e;else throw new Error("Invalid command ",e);try{await t(r,l,i)}catch(o){n.emit("error",o),typeof o=="object"&&o!==null&&"message"in o&&typeof o.message=="string"&&l.stderr(o.message),l.exit(1)}n.emit("spawn",!0)}),n}}class h{constructor(){this.listeners={}}emit(e,s){this.listeners[e]&&this.listeners[e].forEach(function(i){i(s)})}on(e,s){this.listeners[e]||(this.listeners[e]=[]),this.listeners[e].push(s)}}class T extends h{constructor(e){super(),this.childProcess=e,this.exited=!1,this.stdinData=[],e.on("stdin",s=>{this.stdinData?this.stdinData.push(s.slice()):this.emit("stdin",s)})}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.pid=e,this.stdout=new h,this.stderr=new h;const s=this;this.stdin={write:i=>{s.emit("stdin",i)}}}}function d(t=36,e="!@#$%^&*()_+=-[]/.,<>?"){const s="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"+e;let i="";for(let n=t;n>0;--n)i+=s[Math.floor(Math.random()*s.length)];return i}function M(){return d(36,"-_")}function g(t){return`json_decode(base64_decode('${U(JSON.stringify(t))}'), true)`}function q(t){const e={};for(const s in t)e[s]=g(t[s]);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=_;exports.dirname=P;exports.isParentOf=S;exports.joinPaths=y;exports.normalizePath=c;exports.phpVar=g;exports.phpVars=q;exports.randomFilename=M;exports.randomString=d;
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:s}){this._running=0,this.concurrency=e,this.timeout=s,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(s=>{this.queue.push(s)});this.timeout!==void 0?await Promise.race([e,m(this.timeout)]).then(s=>{if(s===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 s=await this.acquire();try{return await e()}finally{s()}}}class y extends Error{constructor(e,s){super(e),this.userFriendlyMessage=s,this.userFriendlyMessage||(this.userFriendlyMessage=e)}}function p(...t){function e(u){return u.substring(u.length-1)==="/"}let s=t.join("/");const i=s[0]==="/",r=e(s);return s=c(s),!s&&!i&&(s="."),s&&r&&!e(s)&&(s+="/"),s}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(s=>!!s),!e).join("/"),(e?"/":"")+t.replace(/\/$/,"")}function O(t,e){let s=0;for(let i=t.length-1;i>=0;i--){const r=t[i];r==="."?t.splice(i,1):r===".."?(t.splice(i,1),s++):s&&(t.splice(i,1),s--)}if(e)for(;s;s--)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 i=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]):i===0?l==='"'||l==="'"?(i=1,r=l):l.match(/\s/)?(n.trim().length&&u.push(n.trim()),n=l):u.length&&!n?n=u.pop()+l:n+=l:i===1&&(l===r?(i=0,r=""):n+=l)}return n&&u.push(n.trim()),u}function T(t){return function(e,s=[],i={}){const r=new x,u=new _(r);return setTimeout(async()=>{let n=[];if(s.length)n=[e,...s];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,i)}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,s){this.listeners[e]&&this.listeners[e].forEach(function(i){i(s)})}on(e,s){this.listeners[e]||(this.listeners[e]=[]),this.listeners[e].push(s)}}class _ extends h{constructor(e){super(),this.childProcess=e,this.exited=!1,this.stdinData=[],e.on("stdin",s=>{this.stdinData?this.stdinData.push(s.slice()):this.emit("stdin",s)})}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.pid=e,this.stdout=new h,this.stderr=new h;const s=this;this.stdin={write:i=>{s.emit("stdin",i)}}}}function d(t=36,e="!@#$%^&*()_+=-[]/.,<>?"){const s="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"+e;let i="";for(let r=t;r>0;--r)i+=s[Math.floor(Math.random()*s.length)];return i}function M(){return d(36,"-_")}function g(t){return`json_decode(base64_decode('${U(JSON.stringify(t))}'), true)`}function q(t){const e={};for(const s in t)e[s]=g(t[s]);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=y;exports.Semaphore=E;exports.basename=w;exports.createSpawnHandler=T;exports.dirname=P;exports.isParentOf=S;exports.joinPaths=p;exports.normalizePath=c;exports.phpVar=g;exports.phpVars=q;exports.randomFilename=M;exports.randomString=d;
package/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  const f = Symbol("SleepFinished");
2
- function d(e) {
2
+ function a(e) {
3
3
  return new Promise((t) => {
4
4
  setTimeout(() => t(f), e);
5
5
  });
6
6
  }
7
- class a extends Error {
7
+ class d extends Error {
8
8
  constructor() {
9
9
  super("Acquiring lock timed out");
10
10
  }
@@ -25,10 +25,10 @@ class _ {
25
25
  const t = new Promise((s) => {
26
26
  this.queue.push(s);
27
27
  });
28
- this.timeout !== void 0 ? await Promise.race([t, d(this.timeout)]).then(
28
+ this.timeout !== void 0 ? await Promise.race([t, a(this.timeout)]).then(
29
29
  (s) => {
30
30
  if (s === f)
31
- throw new a();
31
+ throw new d();
32
32
  }
33
33
  ) : await t;
34
34
  } else {
@@ -54,9 +54,12 @@ class x extends Error {
54
54
  }
55
55
  }
56
56
  function T(...e) {
57
- let t = e.join("/");
58
- const s = t[0] === "/", i = t.substring(t.length - 1) === "/";
59
- return t = c(t), !t && !s && (t = "."), t && i && (t += "/"), t;
57
+ function t(u) {
58
+ return u.substring(u.length - 1) === "/";
59
+ }
60
+ let s = e.join("/");
61
+ const i = s[0] === "/", n = t(s);
62
+ return s = c(s), !s && !i && (s = "."), s && n && !t(s) && (s += "/"), s;
60
63
  }
61
64
  function S(e) {
62
65
  if (e === "/")
@@ -82,8 +85,8 @@ function c(e) {
82
85
  function g(e, t) {
83
86
  let s = 0;
84
87
  for (let i = e.length - 1; i >= 0; i--) {
85
- const r = e[i];
86
- r === "." ? e.splice(i, 1) : r === ".." ? (e.splice(i, 1), s++) : s && (e.splice(i, 1), s--);
88
+ const n = e[i];
89
+ n === "." ? e.splice(i, 1) : n === ".." ? (e.splice(i, 1), s++) : s && (e.splice(i, 1), s--);
87
90
  }
88
91
  if (t)
89
92
  for (; s; s--)
@@ -94,35 +97,35 @@ function M(e, t) {
94
97
  return e === "/" ? !0 : (e = c(e), t = c(t), t.startsWith(e + "/") || t === e);
95
98
  }
96
99
  function m(e) {
97
- let i = 0, r = "";
98
- const l = [];
99
- let n = "";
100
+ let i = 0, n = "";
101
+ const u = [];
102
+ let r = "";
100
103
  for (let o = 0; o < e.length; o++) {
101
- const u = e[o];
102
- u === "\\" ? ((e[o + 1] === '"' || e[o + 1] === "'") && o++, n += e[o]) : i === 0 ? u === '"' || u === "'" ? (i = 1, r = u) : u.match(/\s/) ? (n.trim().length && l.push(n.trim()), n = u) : l.length && !n ? n = l.pop() + u : n += u : i === 1 && (u === r ? (i = 0, r = "") : n += u);
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);
103
106
  }
104
- return n && l.push(n.trim()), l;
107
+ return r && u.push(r.trim()), u;
105
108
  }
106
109
  function U(e) {
107
110
  return function(t, s = [], i = {}) {
108
- const r = new w(), l = new E(r);
111
+ const n = new w(), u = new E(n);
109
112
  return setTimeout(async () => {
110
- let n = [];
113
+ let r = [];
111
114
  if (s.length)
112
- n = [t, ...s];
115
+ r = [t, ...s];
113
116
  else if (typeof t == "string")
114
- n = m(t);
117
+ r = m(t);
115
118
  else if (Array.isArray(t))
116
- n = t;
119
+ r = t;
117
120
  else
118
121
  throw new Error("Invalid command ", t);
119
122
  try {
120
- await e(n, l, i);
123
+ await e(r, u, i);
121
124
  } catch (o) {
122
- r.emit("error", o), typeof o == "object" && o !== null && "message" in o && typeof o.message == "string" && l.stderr(o.message), l.exit(1);
125
+ n.emit("error", o), typeof o == "object" && o !== null && "message" in o && typeof o.message == "string" && u.stderr(o.message), u.exit(1);
123
126
  }
124
- r.emit("spawn", !0);
125
- }), r;
127
+ n.emit("spawn", !0);
128
+ }), n;
126
129
  };
127
130
  }
128
131
  class h {
@@ -178,17 +181,17 @@ class w extends h {
178
181
  };
179
182
  }
180
183
  }
181
- function p(e = 36, t = "!@#$%^&*()_+=-[]/.,<>?") {
184
+ function P(e = 36, t = "!@#$%^&*()_+=-[]/.,<>?") {
182
185
  const s = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" + t;
183
186
  let i = "";
184
- for (let r = e; r > 0; --r)
187
+ for (let n = e; n > 0; --n)
185
188
  i += s[Math.floor(Math.random() * s.length)];
186
189
  return i;
187
190
  }
188
191
  function q() {
189
- return p(36, "-_");
192
+ return P(36, "-_");
190
193
  }
191
- function P(e) {
194
+ function p(e) {
192
195
  return `json_decode(base64_decode('${D(
193
196
  JSON.stringify(e)
194
197
  )}'), true)`;
@@ -196,7 +199,7 @@ function P(e) {
196
199
  function A(e) {
197
200
  const t = {};
198
201
  for (const s in e)
199
- t[s] = P(e[s]);
202
+ t[s] = p(e[s]);
200
203
  return t;
201
204
  }
202
205
  function D(e) {
@@ -207,7 +210,7 @@ function O(e) {
207
210
  return btoa(t);
208
211
  }
209
212
  export {
210
- a as AcquireTimeoutError,
213
+ d as AcquireTimeoutError,
211
214
  x as PhpWasmError,
212
215
  _ as Semaphore,
213
216
  b as basename,
@@ -216,8 +219,8 @@ export {
216
219
  M as isParentOf,
217
220
  T as joinPaths,
218
221
  c as normalizePath,
219
- P as phpVar,
222
+ p as phpVar,
220
223
  A as phpVars,
221
224
  q as randomFilename,
222
- p as randomString
225
+ P as randomString
223
226
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@php-wasm/util",
3
- "version": "0.9.20",
3
+ "version": "0.9.21",
4
4
  "type": "module",
5
5
  "types": "index.d.ts",
6
6
  "typedoc": {
@@ -13,7 +13,7 @@
13
13
  "access": "public",
14
14
  "directory": "../../../dist/packages/php-wasm/util"
15
15
  },
16
- "gitHead": "f619fcb719128d247bec296b9339aff52101e948",
16
+ "gitHead": "a497916495035caba2f28cfdef75a8a0f3732f0e",
17
17
  "engines": {
18
18
  "node": ">=18.18.0",
19
19
  "npm": ">=8.11.0"