@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.
- package/index.cjs +1 -1
- package/index.js +35 -32
- 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
|
|
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
|
|
2
|
+
function a(e) {
|
|
3
3
|
return new Promise((t) => {
|
|
4
4
|
setTimeout(() => t(f), e);
|
|
5
5
|
});
|
|
6
6
|
}
|
|
7
|
-
class
|
|
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,
|
|
28
|
+
this.timeout !== void 0 ? await Promise.race([t, a(this.timeout)]).then(
|
|
29
29
|
(s) => {
|
|
30
30
|
if (s === f)
|
|
31
|
-
throw new
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
|
86
|
-
|
|
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,
|
|
98
|
-
const
|
|
99
|
-
let
|
|
100
|
+
let i = 0, n = "";
|
|
101
|
+
const u = [];
|
|
102
|
+
let r = "";
|
|
100
103
|
for (let o = 0; o < e.length; o++) {
|
|
101
|
-
const
|
|
102
|
-
|
|
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
|
|
107
|
+
return r && u.push(r.trim()), u;
|
|
105
108
|
}
|
|
106
109
|
function U(e) {
|
|
107
110
|
return function(t, s = [], i = {}) {
|
|
108
|
-
const
|
|
111
|
+
const n = new w(), u = new E(n);
|
|
109
112
|
return setTimeout(async () => {
|
|
110
|
-
let
|
|
113
|
+
let r = [];
|
|
111
114
|
if (s.length)
|
|
112
|
-
|
|
115
|
+
r = [t, ...s];
|
|
113
116
|
else if (typeof t == "string")
|
|
114
|
-
|
|
117
|
+
r = m(t);
|
|
115
118
|
else if (Array.isArray(t))
|
|
116
|
-
|
|
119
|
+
r = t;
|
|
117
120
|
else
|
|
118
121
|
throw new Error("Invalid command ", t);
|
|
119
122
|
try {
|
|
120
|
-
await e(
|
|
123
|
+
await e(r, u, i);
|
|
121
124
|
} catch (o) {
|
|
122
|
-
|
|
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
|
-
|
|
125
|
-
}),
|
|
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
|
|
184
|
+
function P(e = 36, t = "!@#$%^&*()_+=-[]/.,<>?") {
|
|
182
185
|
const s = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" + t;
|
|
183
186
|
let i = "";
|
|
184
|
-
for (let
|
|
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
|
|
192
|
+
return P(36, "-_");
|
|
190
193
|
}
|
|
191
|
-
function
|
|
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] =
|
|
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
|
-
|
|
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
|
-
|
|
222
|
+
p as phpVar,
|
|
220
223
|
A as phpVars,
|
|
221
224
|
q as randomFilename,
|
|
222
|
-
|
|
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.
|
|
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": "
|
|
16
|
+
"gitHead": "a497916495035caba2f28cfdef75a8a0f3732f0e",
|
|
17
17
|
"engines": {
|
|
18
18
|
"node": ">=18.18.0",
|
|
19
19
|
"npm": ">=8.11.0"
|