@php-wasm/util 0.6.16 → 0.7.1
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.js +1 -1
- package/index.mjs +63 -41
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=Symbol("SleepFinished");function g(t){return new Promise(e=>{setTimeout(()=>e(f),t)})}class m extends Error{constructor(){super("Acquiring lock timed out")}}class p{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,g(this.timeout)]).then(i=>{if(i===f)throw new m}):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 E extends Error{constructor(e,i){super(e),this.userFriendlyMessage=i,this.userFriendlyMessage||(this.userFriendlyMessage=e)}}function w(...t){let e=t.join("/");const i=e[0]==="/",s=e.substring(e.length-1)==="/";return e=h(e),!e&&!i&&(e="."),e&&s&&(e+="/"),e}function y(t){if(t==="/")return"/";t=h(t);const e=t.lastIndexOf("/");return e===-1?"":e===0?"/":t.substr(0,e)}function P(t){if(t==="/")return"/";t=h(t);const e=t.lastIndexOf("/");return e===-1?t:t.substr(e+1)}function h(t){const e=t[0]==="/";return t=S(t.split("/").filter(i=>!!i),!e).join("/"),(e?"/":"")+t.replace(/\/$/,"")}function S(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 D(t){let s=0,r="";const u=[];let n="";for(let l=0;l<t.length;l++){const o=t[l];o==="\\"?((t[l+1]==='"'||t[l+1]==="'")&&l++,n+=t[l]):s===0?o==='"'||o==="'"?(s=1,r=o):o.match(/\s/)?(n.trim().length&&u.push(n.trim()),n=o):u.length&&!n?n=u.pop()+o:n+=o:s===1&&(o===r?(s=0,r=""):n+=o)}return n&&u.push(n.trim()),u}function O(t){return function(e,i=[],s={}){const r=new b,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);await t(n,u,s),r.emit("spawn",!0)}),r}}class c{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 c{constructor(e){super(),this.childProcess=e,this.exited=!1,this.stdinData=[],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 T=9743;class b extends c{constructor(e=T++){super(),this.pid=e,this.stdout=new c,this.stderr=new c;const i=this;this.stdin={write:s=>{i.emit("stdin",s)}}}}function a(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 x(){return a(36,"-_")}function d(t){return`json_decode(base64_decode('${U(JSON.stringify(t))}'), true)`}function M(t){const e={};for(const i in t)e[i]=d(t[i]);return e}function U(t){return q(new TextEncoder().encode(t))}function q(t){const e=String.fromCodePoint(...t);return btoa(e)}exports.PhpWasmError=E;exports.Semaphore=p;exports.basename=P;exports.createSpawnHandler=O;exports.dirname=y;exports.joinPaths=w;exports.normalizePath=h;exports.phpVar=d;exports.phpVars=M;exports.randomFilename=x;exports.randomString=a;
|
package/index.mjs
CHANGED
|
@@ -1,15 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
const f = Symbol("SleepFinished");
|
|
2
|
+
function d(e) {
|
|
3
|
+
return new Promise((t) => {
|
|
4
|
+
setTimeout(() => t(f), e);
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
class a extends Error {
|
|
8
|
+
constructor() {
|
|
9
|
+
super("Acquiring lock timed out");
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
class O {
|
|
13
|
+
constructor({ concurrency: t, timeout: s }) {
|
|
14
|
+
this._running = 0, this.concurrency = t, this.timeout = s, this.queue = [];
|
|
15
|
+
}
|
|
16
|
+
get remaining() {
|
|
17
|
+
return this.concurrency - this.running;
|
|
4
18
|
}
|
|
5
19
|
get running() {
|
|
6
20
|
return this._running;
|
|
7
21
|
}
|
|
8
22
|
async acquire() {
|
|
9
23
|
for (; ; )
|
|
10
|
-
if (this._running >= this.concurrency)
|
|
11
|
-
|
|
12
|
-
|
|
24
|
+
if (this._running >= this.concurrency) {
|
|
25
|
+
const t = new Promise((s) => {
|
|
26
|
+
this.queue.push(s);
|
|
27
|
+
});
|
|
28
|
+
this.timeout !== void 0 ? await Promise.race([t, d(this.timeout)]).then(
|
|
29
|
+
(s) => {
|
|
30
|
+
if (s === f)
|
|
31
|
+
throw new a();
|
|
32
|
+
}
|
|
33
|
+
) : await t;
|
|
34
|
+
} else {
|
|
13
35
|
this._running++;
|
|
14
36
|
let t = !1;
|
|
15
37
|
return () => {
|
|
@@ -26,24 +48,24 @@ class p {
|
|
|
26
48
|
}
|
|
27
49
|
}
|
|
28
50
|
}
|
|
29
|
-
class
|
|
51
|
+
class x extends Error {
|
|
30
52
|
constructor(t, s) {
|
|
31
53
|
super(t), this.userFriendlyMessage = s, this.userFriendlyMessage || (this.userFriendlyMessage = t);
|
|
32
54
|
}
|
|
33
55
|
}
|
|
34
|
-
function
|
|
56
|
+
function T(...e) {
|
|
35
57
|
let t = e.join("/");
|
|
36
58
|
const s = t[0] === "/", i = t.substring(t.length - 1) === "/";
|
|
37
59
|
return t = h(t), !t && !s && (t = "."), t && i && (t += "/"), t;
|
|
38
60
|
}
|
|
39
|
-
function
|
|
61
|
+
function S(e) {
|
|
40
62
|
if (e === "/")
|
|
41
63
|
return "/";
|
|
42
64
|
e = h(e);
|
|
43
65
|
const t = e.lastIndexOf("/");
|
|
44
66
|
return t === -1 ? "" : t === 0 ? "/" : e.substr(0, t);
|
|
45
67
|
}
|
|
46
|
-
function
|
|
68
|
+
function M(e) {
|
|
47
69
|
if (e === "/")
|
|
48
70
|
return "/";
|
|
49
71
|
e = h(e);
|
|
@@ -52,12 +74,12 @@ function m(e) {
|
|
|
52
74
|
}
|
|
53
75
|
function h(e) {
|
|
54
76
|
const t = e[0] === "/";
|
|
55
|
-
return e =
|
|
77
|
+
return e = g(
|
|
56
78
|
e.split("/").filter((s) => !!s),
|
|
57
79
|
!t
|
|
58
80
|
).join("/"), (t ? "/" : "") + e.replace(/\/$/, "");
|
|
59
81
|
}
|
|
60
|
-
function
|
|
82
|
+
function g(e, t) {
|
|
61
83
|
let s = 0;
|
|
62
84
|
for (let i = e.length - 1; i >= 0; i--) {
|
|
63
85
|
const r = e[i];
|
|
@@ -68,30 +90,30 @@ function f(e, t) {
|
|
|
68
90
|
e.unshift("..");
|
|
69
91
|
return e;
|
|
70
92
|
}
|
|
71
|
-
function
|
|
93
|
+
function E(e) {
|
|
72
94
|
let i = 0, r = "";
|
|
73
|
-
const
|
|
95
|
+
const u = [];
|
|
74
96
|
let n = "";
|
|
75
|
-
for (let
|
|
76
|
-
const o = e[
|
|
77
|
-
o === "\\" ? ((e[
|
|
97
|
+
for (let l = 0; l < e.length; l++) {
|
|
98
|
+
const o = e[l];
|
|
99
|
+
o === "\\" ? ((e[l + 1] === '"' || e[l + 1] === "'") && l++, n += e[l]) : i === 0 ? o === '"' || o === "'" ? (i = 1, r = o) : o.match(/\s/) ? (n.trim().length && u.push(n.trim()), n = o) : u.length && !n ? n = u.pop() + o : n += o : i === 1 && (o === r ? (i = 0, r = "") : n += o);
|
|
78
100
|
}
|
|
79
|
-
return n &&
|
|
101
|
+
return n && u.push(n.trim()), u;
|
|
80
102
|
}
|
|
81
|
-
function
|
|
103
|
+
function b(e) {
|
|
82
104
|
return function(t, s = [], i = {}) {
|
|
83
|
-
const r = new
|
|
105
|
+
const r = new p(), u = new m(r);
|
|
84
106
|
return setTimeout(async () => {
|
|
85
107
|
let n = [];
|
|
86
108
|
if (s.length)
|
|
87
109
|
n = [t, ...s];
|
|
88
110
|
else if (typeof t == "string")
|
|
89
|
-
n =
|
|
111
|
+
n = E(t);
|
|
90
112
|
else if (Array.isArray(t))
|
|
91
113
|
n = t;
|
|
92
114
|
else
|
|
93
115
|
throw new Error("Invalid command ", t);
|
|
94
|
-
await e(n,
|
|
116
|
+
await e(n, u, i), r.emit("spawn", !0);
|
|
95
117
|
}), r;
|
|
96
118
|
};
|
|
97
119
|
}
|
|
@@ -108,7 +130,7 @@ class c {
|
|
|
108
130
|
this.listeners[t] || (this.listeners[t] = []), this.listeners[t].push(s);
|
|
109
131
|
}
|
|
110
132
|
}
|
|
111
|
-
class
|
|
133
|
+
class m extends c {
|
|
112
134
|
constructor(t) {
|
|
113
135
|
super(), this.childProcess = t, this.exited = !1, this.stdinData = [], t.on("stdin", (s) => {
|
|
114
136
|
this.stdinData ? this.stdinData.push(s.slice()) : this.emit("stdin", s);
|
|
@@ -136,9 +158,9 @@ class a extends c {
|
|
|
136
158
|
this.stdinData = null;
|
|
137
159
|
}
|
|
138
160
|
}
|
|
139
|
-
let
|
|
140
|
-
class
|
|
141
|
-
constructor(t =
|
|
161
|
+
let w = 9743;
|
|
162
|
+
class p extends c {
|
|
163
|
+
constructor(t = w++) {
|
|
142
164
|
super(), this.pid = t, this.stdout = new c(), this.stderr = new c();
|
|
143
165
|
const s = this;
|
|
144
166
|
this.stdin = {
|
|
@@ -155,21 +177,21 @@ function y(e = 36, t = "!@#$%^&*()_+=-[]/.,<>?") {
|
|
|
155
177
|
i += s[Math.floor(Math.random() * s.length)];
|
|
156
178
|
return i;
|
|
157
179
|
}
|
|
158
|
-
function
|
|
180
|
+
function U() {
|
|
159
181
|
return y(36, "-_");
|
|
160
182
|
}
|
|
161
|
-
function
|
|
162
|
-
return `json_decode(base64_decode('${
|
|
183
|
+
function D(e) {
|
|
184
|
+
return `json_decode(base64_decode('${P(
|
|
163
185
|
JSON.stringify(e)
|
|
164
186
|
)}'), true)`;
|
|
165
187
|
}
|
|
166
|
-
function
|
|
188
|
+
function q(e) {
|
|
167
189
|
const t = {};
|
|
168
190
|
for (const s in e)
|
|
169
|
-
t[s] =
|
|
191
|
+
t[s] = D(e[s]);
|
|
170
192
|
return t;
|
|
171
193
|
}
|
|
172
|
-
function
|
|
194
|
+
function P(e) {
|
|
173
195
|
return _(new TextEncoder().encode(e));
|
|
174
196
|
}
|
|
175
197
|
function _(e) {
|
|
@@ -177,15 +199,15 @@ function _(e) {
|
|
|
177
199
|
return btoa(t);
|
|
178
200
|
}
|
|
179
201
|
export {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
202
|
+
x as PhpWasmError,
|
|
203
|
+
O as Semaphore,
|
|
204
|
+
M as basename,
|
|
205
|
+
b as createSpawnHandler,
|
|
206
|
+
S as dirname,
|
|
207
|
+
T as joinPaths,
|
|
186
208
|
h as normalizePath,
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
209
|
+
D as phpVar,
|
|
210
|
+
q as phpVars,
|
|
211
|
+
U as randomFilename,
|
|
190
212
|
y as randomString
|
|
191
213
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@php-wasm/util",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"typedoc": {
|
|
6
6
|
"entryPoint": "./src/index.ts",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"access": "public",
|
|
13
13
|
"directory": "../../../dist/packages/php-wasm/util"
|
|
14
14
|
},
|
|
15
|
-
"gitHead": "
|
|
15
|
+
"gitHead": "ed0ec39040ab4cd69dc48a8eac157436b30f9d55",
|
|
16
16
|
"engines": {
|
|
17
17
|
"node": ">=18.18.0",
|
|
18
18
|
"npm": ">=8.11.0"
|