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