@php-wasm/util 0.6.4 → 0.6.5
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 -301
- package/index.mjs +185 -0
- package/package.json +2 -2
- package/README.md +0 -11
package/index.js
CHANGED
|
@@ -1,301 +1 @@
|
|
|
1
|
-
|
|
2
|
-
var Semaphore = class {
|
|
3
|
-
constructor({ concurrency }) {
|
|
4
|
-
this._running = 0;
|
|
5
|
-
this.concurrency = concurrency;
|
|
6
|
-
this.queue = [];
|
|
7
|
-
}
|
|
8
|
-
get running() {
|
|
9
|
-
return this._running;
|
|
10
|
-
}
|
|
11
|
-
async acquire() {
|
|
12
|
-
while (true) {
|
|
13
|
-
if (this._running >= this.concurrency) {
|
|
14
|
-
await new Promise((resolve) => this.queue.push(resolve));
|
|
15
|
-
} else {
|
|
16
|
-
this._running++;
|
|
17
|
-
let released = false;
|
|
18
|
-
return () => {
|
|
19
|
-
if (released) {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
released = true;
|
|
23
|
-
this._running--;
|
|
24
|
-
if (this.queue.length > 0) {
|
|
25
|
-
this.queue.shift()();
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
async run(fn) {
|
|
32
|
-
const release = await this.acquire();
|
|
33
|
-
try {
|
|
34
|
-
return await fn();
|
|
35
|
-
} finally {
|
|
36
|
-
release();
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
// packages/php-wasm/util/src/lib/paths.ts
|
|
42
|
-
function joinPaths(...paths) {
|
|
43
|
-
let path = paths.join("/");
|
|
44
|
-
const isAbsolute = path[0] === "/";
|
|
45
|
-
const trailingSlash = path.substring(path.length - 1) === "/";
|
|
46
|
-
path = normalizePath(path);
|
|
47
|
-
if (!path && !isAbsolute) {
|
|
48
|
-
path = ".";
|
|
49
|
-
}
|
|
50
|
-
if (path && trailingSlash) {
|
|
51
|
-
path += "/";
|
|
52
|
-
}
|
|
53
|
-
return path;
|
|
54
|
-
}
|
|
55
|
-
function dirname(path) {
|
|
56
|
-
if (path === "/") {
|
|
57
|
-
return "/";
|
|
58
|
-
}
|
|
59
|
-
path = normalizePath(path);
|
|
60
|
-
const lastSlash = path.lastIndexOf("/");
|
|
61
|
-
if (lastSlash === -1) {
|
|
62
|
-
return "";
|
|
63
|
-
} else if (lastSlash === 0) {
|
|
64
|
-
return "/";
|
|
65
|
-
}
|
|
66
|
-
return path.substr(0, lastSlash);
|
|
67
|
-
}
|
|
68
|
-
function basename(path) {
|
|
69
|
-
if (path === "/") {
|
|
70
|
-
return "/";
|
|
71
|
-
}
|
|
72
|
-
path = normalizePath(path);
|
|
73
|
-
const lastSlash = path.lastIndexOf("/");
|
|
74
|
-
if (lastSlash === -1) {
|
|
75
|
-
return path;
|
|
76
|
-
}
|
|
77
|
-
return path.substr(lastSlash + 1);
|
|
78
|
-
}
|
|
79
|
-
function normalizePath(path) {
|
|
80
|
-
const isAbsolute = path[0] === "/";
|
|
81
|
-
path = normalizePathsArray(
|
|
82
|
-
path.split("/").filter((p) => !!p),
|
|
83
|
-
!isAbsolute
|
|
84
|
-
).join("/");
|
|
85
|
-
return (isAbsolute ? "/" : "") + path.replace(/\/$/, "");
|
|
86
|
-
}
|
|
87
|
-
function normalizePathsArray(parts, allowAboveRoot) {
|
|
88
|
-
let up = 0;
|
|
89
|
-
for (let i = parts.length - 1; i >= 0; i--) {
|
|
90
|
-
const last = parts[i];
|
|
91
|
-
if (last === ".") {
|
|
92
|
-
parts.splice(i, 1);
|
|
93
|
-
} else if (last === "..") {
|
|
94
|
-
parts.splice(i, 1);
|
|
95
|
-
up++;
|
|
96
|
-
} else if (up) {
|
|
97
|
-
parts.splice(i, 1);
|
|
98
|
-
up--;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
if (allowAboveRoot) {
|
|
102
|
-
for (; up; up--) {
|
|
103
|
-
parts.unshift("..");
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
return parts;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// packages/php-wasm/util/src/lib/split-shell-command.ts
|
|
110
|
-
function splitShellCommand(command) {
|
|
111
|
-
const MODE_UNQUOTED = 0;
|
|
112
|
-
const MODE_IN_QUOTE = 1;
|
|
113
|
-
let mode = MODE_UNQUOTED;
|
|
114
|
-
let quote = "";
|
|
115
|
-
const parts = [];
|
|
116
|
-
let currentPart = "";
|
|
117
|
-
for (let i = 0; i < command.length; i++) {
|
|
118
|
-
const char = command[i];
|
|
119
|
-
if (char === "\\") {
|
|
120
|
-
if (command[i + 1] === '"' || command[i + 1] === "'") {
|
|
121
|
-
i++;
|
|
122
|
-
}
|
|
123
|
-
currentPart += command[i];
|
|
124
|
-
} else if (mode === MODE_UNQUOTED) {
|
|
125
|
-
if (char === '"' || char === "'") {
|
|
126
|
-
mode = MODE_IN_QUOTE;
|
|
127
|
-
quote = char;
|
|
128
|
-
} else if (char.match(/\s/)) {
|
|
129
|
-
if (currentPart.trim().length) {
|
|
130
|
-
parts.push(currentPart.trim());
|
|
131
|
-
}
|
|
132
|
-
currentPart = char;
|
|
133
|
-
} else if (parts.length && !currentPart) {
|
|
134
|
-
currentPart = parts.pop() + char;
|
|
135
|
-
} else {
|
|
136
|
-
currentPart += char;
|
|
137
|
-
}
|
|
138
|
-
} else if (mode === MODE_IN_QUOTE) {
|
|
139
|
-
if (char === quote) {
|
|
140
|
-
mode = MODE_UNQUOTED;
|
|
141
|
-
quote = "";
|
|
142
|
-
} else {
|
|
143
|
-
currentPart += char;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
if (currentPart) {
|
|
148
|
-
parts.push(currentPart.trim());
|
|
149
|
-
}
|
|
150
|
-
return parts;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// packages/php-wasm/util/src/lib/create-spawn-handler.ts
|
|
154
|
-
function createSpawnHandler(program) {
|
|
155
|
-
return function(command, argsArray = [], options = {}) {
|
|
156
|
-
const childProcess = new ChildProcess();
|
|
157
|
-
const processApi = new ProcessApi(childProcess);
|
|
158
|
-
setTimeout(async () => {
|
|
159
|
-
let commandArray = [];
|
|
160
|
-
if (argsArray.length) {
|
|
161
|
-
commandArray = [command, ...argsArray];
|
|
162
|
-
} else if (typeof command === "string") {
|
|
163
|
-
commandArray = splitShellCommand(command);
|
|
164
|
-
} else if (Array.isArray(command)) {
|
|
165
|
-
commandArray = command;
|
|
166
|
-
} else {
|
|
167
|
-
throw new Error("Invalid command ", command);
|
|
168
|
-
}
|
|
169
|
-
await program(commandArray, processApi, options);
|
|
170
|
-
childProcess.emit("spawn", true);
|
|
171
|
-
});
|
|
172
|
-
return childProcess;
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
var EventEmitter = class {
|
|
176
|
-
constructor() {
|
|
177
|
-
this.listeners = {};
|
|
178
|
-
}
|
|
179
|
-
emit(eventName, data) {
|
|
180
|
-
if (this.listeners[eventName]) {
|
|
181
|
-
this.listeners[eventName].forEach(function(listener) {
|
|
182
|
-
listener(data);
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
on(eventName, listener) {
|
|
187
|
-
if (!this.listeners[eventName]) {
|
|
188
|
-
this.listeners[eventName] = [];
|
|
189
|
-
}
|
|
190
|
-
this.listeners[eventName].push(listener);
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
var ProcessApi = class extends EventEmitter {
|
|
194
|
-
constructor(childProcess) {
|
|
195
|
-
super();
|
|
196
|
-
this.childProcess = childProcess;
|
|
197
|
-
this.exited = false;
|
|
198
|
-
this.stdinData = [];
|
|
199
|
-
childProcess.on("stdin", (data) => {
|
|
200
|
-
if (this.stdinData) {
|
|
201
|
-
this.stdinData.push(data.slice());
|
|
202
|
-
} else {
|
|
203
|
-
this.emit("stdin", data);
|
|
204
|
-
}
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
stdout(data) {
|
|
208
|
-
if (typeof data === "string") {
|
|
209
|
-
data = new TextEncoder().encode(data);
|
|
210
|
-
}
|
|
211
|
-
this.childProcess.stdout.emit("data", data);
|
|
212
|
-
}
|
|
213
|
-
stdoutEnd() {
|
|
214
|
-
this.childProcess.stdout.emit("end", {});
|
|
215
|
-
}
|
|
216
|
-
stderr(data) {
|
|
217
|
-
if (typeof data === "string") {
|
|
218
|
-
data = new TextEncoder().encode(data);
|
|
219
|
-
}
|
|
220
|
-
this.childProcess.stderr.emit("data", data);
|
|
221
|
-
}
|
|
222
|
-
stderrEnd() {
|
|
223
|
-
this.childProcess.stderr.emit("end", {});
|
|
224
|
-
}
|
|
225
|
-
exit(code) {
|
|
226
|
-
if (!this.exited) {
|
|
227
|
-
this.exited = true;
|
|
228
|
-
this.childProcess.emit("exit", code);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
flushStdin() {
|
|
232
|
-
if (this.stdinData) {
|
|
233
|
-
for (let i = 0; i < this.stdinData.length; i++) {
|
|
234
|
-
this.emit("stdin", this.stdinData[i]);
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
this.stdinData = null;
|
|
238
|
-
}
|
|
239
|
-
};
|
|
240
|
-
var lastPid = 9743;
|
|
241
|
-
var ChildProcess = class extends EventEmitter {
|
|
242
|
-
constructor(pid = lastPid++) {
|
|
243
|
-
super();
|
|
244
|
-
this.pid = pid;
|
|
245
|
-
this.stdout = new EventEmitter();
|
|
246
|
-
this.stderr = new EventEmitter();
|
|
247
|
-
const self = this;
|
|
248
|
-
this.stdin = {
|
|
249
|
-
write: (data) => {
|
|
250
|
-
self.emit("stdin", data);
|
|
251
|
-
}
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
};
|
|
255
|
-
|
|
256
|
-
// packages/php-wasm/util/src/lib/random-string.ts
|
|
257
|
-
function randomString(length = 36, specialChars = "!@#$%^&*()_+=-[]/.,<>?") {
|
|
258
|
-
const chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" + specialChars;
|
|
259
|
-
let result = "";
|
|
260
|
-
for (let i = length; i > 0; --i)
|
|
261
|
-
result += chars[Math.floor(Math.random() * chars.length)];
|
|
262
|
-
return result;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
// packages/php-wasm/util/src/lib/random-filename.ts
|
|
266
|
-
function randomFilename() {
|
|
267
|
-
return randomString(36, "-_");
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
// packages/php-wasm/util/src/lib/php-vars.ts
|
|
271
|
-
function phpVar(value) {
|
|
272
|
-
return `json_decode(base64_decode('${stringToBase64(
|
|
273
|
-
JSON.stringify(value)
|
|
274
|
-
)}'), true)`;
|
|
275
|
-
}
|
|
276
|
-
function phpVars(vars) {
|
|
277
|
-
const result = {};
|
|
278
|
-
for (const key in vars) {
|
|
279
|
-
result[key] = phpVar(vars[key]);
|
|
280
|
-
}
|
|
281
|
-
return result;
|
|
282
|
-
}
|
|
283
|
-
function stringToBase64(str) {
|
|
284
|
-
return bytesToBase64(new TextEncoder().encode(str));
|
|
285
|
-
}
|
|
286
|
-
function bytesToBase64(bytes) {
|
|
287
|
-
const binString = String.fromCodePoint(...bytes);
|
|
288
|
-
return btoa(binString);
|
|
289
|
-
}
|
|
290
|
-
export {
|
|
291
|
-
Semaphore,
|
|
292
|
-
basename,
|
|
293
|
-
createSpawnHandler,
|
|
294
|
-
dirname,
|
|
295
|
-
joinPaths,
|
|
296
|
-
normalizePath,
|
|
297
|
-
phpVar,
|
|
298
|
-
phpVars,
|
|
299
|
-
randomFilename,
|
|
300
|
-
randomString
|
|
301
|
-
};
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class d{constructor({concurrency:t}){this._running=0,this.concurrency=t,this.queue=[]}get running(){return this._running}async acquire(){for(;;)if(this._running>=this.concurrency)await new Promise(t=>this.queue.push(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()}}}function g(...e){let t=e.join("/");const i=t[0]==="/",s=t.substring(t.length-1)==="/";return t=h(t),!t&&!i&&(t="."),t&&s&&(t+="/"),t}function E(e){if(e==="/")return"/";e=h(e);const t=e.lastIndexOf("/");return t===-1?"":t===0?"/":e.substr(0,t)}function m(e){if(e==="/")return"/";e=h(e);const t=e.lastIndexOf("/");return t===-1?e:e.substr(t+1)}function h(e){const t=e[0]==="/";return e=p(e.split("/").filter(i=>!!i),!t).join("/"),(t?"/":"")+e.replace(/\/$/,"")}function p(e,t){let i=0;for(let s=e.length-1;s>=0;s--){const r=e[s];r==="."?e.splice(s,1):r===".."?(e.splice(s,1),i++):i&&(e.splice(s,1),i--)}if(t)for(;i;i--)e.unshift("..");return e}function w(e){let s=0,r="";const l=[];let n="";for(let u=0;u<e.length;u++){const o=e[u];o==="\\"?((e[u+1]==='"'||e[u+1]==="'")&&u++,n+=e[u]):s===0?o==='"'||o==="'"?(s=1,r=o):o.match(/\s/)?(n.trim().length&&l.push(n.trim()),n=o):l.length&&!n?n=l.pop()+o:n+=o:s===1&&(o===r?(s=0,r=""):n+=o)}return n&&l.push(n.trim()),l}function y(e){return function(t,i=[],s={}){const r=new P,l=new D(r);return setTimeout(async()=>{let n=[];if(i.length)n=[t,...i];else if(typeof t=="string")n=w(t);else if(Array.isArray(t))n=t;else throw new Error("Invalid command ",t);await e(n,l,s),r.emit("spawn",!0)}),r}}class c{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 D extends c{constructor(t){super(),this.childProcess=t,this.exited=!1,this.stdinData=[],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",{})}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 O=9743;class P extends c{constructor(t=O++){super(),this.pid=t,this.stdout=new c,this.stderr=new c;const i=this;this.stdin={write:s=>{i.emit("stdin",s)}}}}function f(e=36,t="!@#$%^&*()_+=-[]/.,<>?"){const i="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"+t;let s="";for(let r=e;r>0;--r)s+=i[Math.floor(Math.random()*i.length)];return s}function _(){return f(36,"-_")}function a(e){return`json_decode(base64_decode('${T(JSON.stringify(e))}'), true)`}function S(e){const t={};for(const i in e)t[i]=a(e[i]);return t}function T(e){return b(new TextEncoder().encode(e))}function b(e){const t=String.fromCodePoint(...e);return btoa(t)}exports.Semaphore=d;exports.basename=m;exports.createSpawnHandler=y;exports.dirname=E;exports.joinPaths=g;exports.normalizePath=h;exports.phpVar=a;exports.phpVars=S;exports.randomFilename=_;exports.randomString=f;
|
package/index.mjs
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
class y {
|
|
2
|
+
constructor({ concurrency: t }) {
|
|
3
|
+
this._running = 0, this.concurrency = t, this.queue = [];
|
|
4
|
+
}
|
|
5
|
+
get running() {
|
|
6
|
+
return this._running;
|
|
7
|
+
}
|
|
8
|
+
async acquire() {
|
|
9
|
+
for (; ; )
|
|
10
|
+
if (this._running >= this.concurrency)
|
|
11
|
+
await new Promise((t) => this.queue.push(t));
|
|
12
|
+
else {
|
|
13
|
+
this._running++;
|
|
14
|
+
let t = !1;
|
|
15
|
+
return () => {
|
|
16
|
+
t || (t = !0, this._running--, this.queue.length > 0 && this.queue.shift()());
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
async run(t) {
|
|
21
|
+
const s = await this.acquire();
|
|
22
|
+
try {
|
|
23
|
+
return await t();
|
|
24
|
+
} finally {
|
|
25
|
+
s();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function p(...e) {
|
|
30
|
+
let t = e.join("/");
|
|
31
|
+
const s = t[0] === "/", i = t.substring(t.length - 1) === "/";
|
|
32
|
+
return t = f(t), !t && !s && (t = "."), t && i && (t += "/"), t;
|
|
33
|
+
}
|
|
34
|
+
function P(e) {
|
|
35
|
+
if (e === "/")
|
|
36
|
+
return "/";
|
|
37
|
+
e = f(e);
|
|
38
|
+
const t = e.lastIndexOf("/");
|
|
39
|
+
return t === -1 ? "" : t === 0 ? "/" : e.substr(0, t);
|
|
40
|
+
}
|
|
41
|
+
function m(e) {
|
|
42
|
+
if (e === "/")
|
|
43
|
+
return "/";
|
|
44
|
+
e = f(e);
|
|
45
|
+
const t = e.lastIndexOf("/");
|
|
46
|
+
return t === -1 ? e : e.substr(t + 1);
|
|
47
|
+
}
|
|
48
|
+
function f(e) {
|
|
49
|
+
const t = e[0] === "/";
|
|
50
|
+
return e = h(
|
|
51
|
+
e.split("/").filter((s) => !!s),
|
|
52
|
+
!t
|
|
53
|
+
).join("/"), (t ? "/" : "") + e.replace(/\/$/, "");
|
|
54
|
+
}
|
|
55
|
+
function h(e, t) {
|
|
56
|
+
let s = 0;
|
|
57
|
+
for (let i = e.length - 1; i >= 0; i--) {
|
|
58
|
+
const r = e[i];
|
|
59
|
+
r === "." ? e.splice(i, 1) : r === ".." ? (e.splice(i, 1), s++) : s && (e.splice(i, 1), s--);
|
|
60
|
+
}
|
|
61
|
+
if (t)
|
|
62
|
+
for (; s; s--)
|
|
63
|
+
e.unshift("..");
|
|
64
|
+
return e;
|
|
65
|
+
}
|
|
66
|
+
function d(e) {
|
|
67
|
+
let i = 0, r = "";
|
|
68
|
+
const l = [];
|
|
69
|
+
let n = "";
|
|
70
|
+
for (let u = 0; u < e.length; u++) {
|
|
71
|
+
const o = e[u];
|
|
72
|
+
o === "\\" ? ((e[u + 1] === '"' || e[u + 1] === "'") && u++, n += e[u]) : i === 0 ? o === '"' || o === "'" ? (i = 1, r = o) : o.match(/\s/) ? (n.trim().length && l.push(n.trim()), n = o) : l.length && !n ? n = l.pop() + o : n += o : i === 1 && (o === r ? (i = 0, r = "") : n += o);
|
|
73
|
+
}
|
|
74
|
+
return n && l.push(n.trim()), l;
|
|
75
|
+
}
|
|
76
|
+
function x(e) {
|
|
77
|
+
return function(t, s = [], i = {}) {
|
|
78
|
+
const r = new E(), l = new a(r);
|
|
79
|
+
return setTimeout(async () => {
|
|
80
|
+
let n = [];
|
|
81
|
+
if (s.length)
|
|
82
|
+
n = [t, ...s];
|
|
83
|
+
else if (typeof t == "string")
|
|
84
|
+
n = d(t);
|
|
85
|
+
else if (Array.isArray(t))
|
|
86
|
+
n = t;
|
|
87
|
+
else
|
|
88
|
+
throw new Error("Invalid command ", t);
|
|
89
|
+
await e(n, l, i), r.emit("spawn", !0);
|
|
90
|
+
}), r;
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
class c {
|
|
94
|
+
constructor() {
|
|
95
|
+
this.listeners = {};
|
|
96
|
+
}
|
|
97
|
+
emit(t, s) {
|
|
98
|
+
this.listeners[t] && this.listeners[t].forEach(function(i) {
|
|
99
|
+
i(s);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
on(t, s) {
|
|
103
|
+
this.listeners[t] || (this.listeners[t] = []), this.listeners[t].push(s);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
class a extends c {
|
|
107
|
+
constructor(t) {
|
|
108
|
+
super(), this.childProcess = t, this.exited = !1, this.stdinData = [], t.on("stdin", (s) => {
|
|
109
|
+
this.stdinData ? this.stdinData.push(s.slice()) : this.emit("stdin", s);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
stdout(t) {
|
|
113
|
+
typeof t == "string" && (t = new TextEncoder().encode(t)), this.childProcess.stdout.emit("data", t);
|
|
114
|
+
}
|
|
115
|
+
stdoutEnd() {
|
|
116
|
+
this.childProcess.stdout.emit("end", {});
|
|
117
|
+
}
|
|
118
|
+
stderr(t) {
|
|
119
|
+
typeof t == "string" && (t = new TextEncoder().encode(t)), this.childProcess.stderr.emit("data", t);
|
|
120
|
+
}
|
|
121
|
+
stderrEnd() {
|
|
122
|
+
this.childProcess.stderr.emit("end", {});
|
|
123
|
+
}
|
|
124
|
+
exit(t) {
|
|
125
|
+
this.exited || (this.exited = !0, this.childProcess.emit("exit", t));
|
|
126
|
+
}
|
|
127
|
+
flushStdin() {
|
|
128
|
+
if (this.stdinData)
|
|
129
|
+
for (let t = 0; t < this.stdinData.length; t++)
|
|
130
|
+
this.emit("stdin", this.stdinData[t]);
|
|
131
|
+
this.stdinData = null;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
let g = 9743;
|
|
135
|
+
class E extends c {
|
|
136
|
+
constructor(t = g++) {
|
|
137
|
+
super(), this.pid = t, this.stdout = new c(), this.stderr = new c();
|
|
138
|
+
const s = this;
|
|
139
|
+
this.stdin = {
|
|
140
|
+
write: (i) => {
|
|
141
|
+
s.emit("stdin", i);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
function w(e = 36, t = "!@#$%^&*()_+=-[]/.,<>?") {
|
|
147
|
+
const s = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" + t;
|
|
148
|
+
let i = "";
|
|
149
|
+
for (let r = e; r > 0; --r)
|
|
150
|
+
i += s[Math.floor(Math.random() * s.length)];
|
|
151
|
+
return i;
|
|
152
|
+
}
|
|
153
|
+
function T() {
|
|
154
|
+
return w(36, "-_");
|
|
155
|
+
}
|
|
156
|
+
function D(e) {
|
|
157
|
+
return `json_decode(base64_decode('${_(
|
|
158
|
+
JSON.stringify(e)
|
|
159
|
+
)}'), true)`;
|
|
160
|
+
}
|
|
161
|
+
function S(e) {
|
|
162
|
+
const t = {};
|
|
163
|
+
for (const s in e)
|
|
164
|
+
t[s] = D(e[s]);
|
|
165
|
+
return t;
|
|
166
|
+
}
|
|
167
|
+
function _(e) {
|
|
168
|
+
return O(new TextEncoder().encode(e));
|
|
169
|
+
}
|
|
170
|
+
function O(e) {
|
|
171
|
+
const t = String.fromCodePoint(...e);
|
|
172
|
+
return btoa(t);
|
|
173
|
+
}
|
|
174
|
+
export {
|
|
175
|
+
y as Semaphore,
|
|
176
|
+
m as basename,
|
|
177
|
+
x as createSpawnHandler,
|
|
178
|
+
P as dirname,
|
|
179
|
+
p as joinPaths,
|
|
180
|
+
f as normalizePath,
|
|
181
|
+
D as phpVar,
|
|
182
|
+
S as phpVars,
|
|
183
|
+
T as randomFilename,
|
|
184
|
+
w as randomString
|
|
185
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@php-wasm/util",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.5",
|
|
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": "eb45486a61d06a8a9e62cbd65348bfb274ff9e7c",
|
|
16
16
|
"engines": {
|
|
17
17
|
"node": ">=18.18.2",
|
|
18
18
|
"npm": ">=8.11.0"
|
package/README.md
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
# php-wasm-util
|
|
2
|
-
|
|
3
|
-
This library was generated with [Nx](https://nx.dev).
|
|
4
|
-
|
|
5
|
-
## Building
|
|
6
|
-
|
|
7
|
-
Run `nx build php-wasm-util` to build the library.
|
|
8
|
-
|
|
9
|
-
## Running unit tests
|
|
10
|
-
|
|
11
|
-
Run `nx test php-wasm-util` to execute the unit tests via [Jest](https://jestjs.io).
|