@vxrn/utils 2.0.0-beta.33.1 → 2.0.0-beta.46.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/dist/cjs/createMessageSocket.cjs +115 -121
- package/dist/cjs/createMessageSocket.native.cjs +166 -0
- package/dist/cjs/createMessageSocket.native.js +152 -166
- package/dist/cjs/createMessageSocket.native.js.map +1 -1
- package/dist/cjs/detectPackageManager.cjs +76 -72
- package/dist/cjs/detectPackageManager.native.cjs +106 -0
- package/dist/cjs/detectPackageManager.native.js +82 -77
- package/dist/cjs/detectPackageManager.native.js.map +1 -1
- package/dist/cjs/exec.cjs +43 -45
- package/dist/cjs/exec.native.cjs +65 -0
- package/dist/cjs/exec.native.js +48 -49
- package/dist/cjs/exec.native.js.map +1 -1
- package/dist/cjs/index.cjs +9 -11
- package/dist/cjs/index.native.cjs +25 -0
- package/dist/cjs/index.native.js +9 -10
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/mustReplace.cjs +27 -35
- package/dist/cjs/mustReplace.native.cjs +60 -0
- package/dist/cjs/mustReplace.native.js +44 -60
- package/dist/cjs/mustReplace.native.js.map +1 -1
- package/dist/esm/createMessageSocket.mjs +103 -103
- package/dist/esm/createMessageSocket.mjs.map +1 -1
- package/dist/esm/createMessageSocket.native.js +139 -148
- package/dist/esm/createMessageSocket.native.js.map +1 -1
- package/dist/esm/detectPackageManager.mjs +65 -55
- package/dist/esm/detectPackageManager.mjs.map +1 -1
- package/dist/esm/detectPackageManager.native.js +71 -61
- package/dist/esm/detectPackageManager.native.js.map +1 -1
- package/dist/esm/exec.mjs +29 -27
- package/dist/esm/exec.mjs.map +1 -1
- package/dist/esm/exec.native.js +34 -32
- package/dist/esm/exec.native.js.map +1 -1
- package/dist/esm/index.js +11 -7
- package/dist/esm/index.mjs +11 -7
- package/dist/esm/index.native.js +11 -7
- package/dist/esm/mustReplace.mjs +15 -17
- package/dist/esm/mustReplace.mjs.map +1 -1
- package/dist/esm/mustReplace.native.js +32 -43
- package/dist/esm/mustReplace.native.js.map +1 -1
- package/package.json +4 -4
- package/types/createMessageSocket.d.ts +1 -1
- package/types/createMessageSocket.d.ts.map +1 -1
- package/types/detectPackageManager.d.ts.map +1 -1
- package/types/exec.d.ts.map +1 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/index.native.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"file":"index.native.js","names":[],"sources":["cjs/index.native.js"],"sourcesContent":["\"use strict\";\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, \"default\"), secondTarget && __copyProps(secondTarget, mod, \"default\"));\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar index_exports = {};\nmodule.exports = __toCommonJS(index_exports);\n__reExport(index_exports, require(\"@vxrn/debug\"), module.exports);\n__reExport(index_exports, require(\"@vxrn/resolve\"), module.exports);\n__reExport(index_exports, require(\"./createMessageSocket\"), module.exports);\n__reExport(index_exports, require(\"./detectPackageManager\"), module.exports);\n__reExport(index_exports, require(\"./exec\"), module.exports);\n__reExport(index_exports, require(\"./mustReplace\"), module.exports);\n//# sourceMappingURL=index.js.map\n"],"mappings":";;;AACA,IAAI,YAAY,OAAO;AACvB,IAAI,mBAAmB,OAAO;AAC9B,IAAI,oBAAoB,OAAO;AAC/B,IAAI,eAAe,OAAO,UAAU;AACpC,IAAI,eAAe,IAAI,MAAM,QAAQ,SAAS;CAC5C,IAAI,QAAQ,OAAO,SAAS,YAAY,OAAO,SAAS,YAAY;EAClE,KAAK,IAAI,OAAO,kBAAkB,IAAI,GACpC,IAAI,CAAC,aAAa,KAAK,IAAI,GAAG,KAAK,QAAQ,QACzC,UAAU,IAAI,KAAK;GAAE,WAAW,KAAK;GAAM,YAAY,EAAE,OAAO,iBAAiB,MAAM,GAAG,MAAM,KAAK;EAAW,CAAC;CACvH;CACA,OAAO;AACT;AACA,IAAI,cAAc,QAAQ,KAAK,kBAAkB,YAAY,QAAQ,KAAK,SAAS,GAAG,gBAAgB,YAAY,cAAc,KAAK,SAAS;AAC9I,IAAI,gBAAgB,QAAQ,YAAY,UAAU,CAAC,GAAG,cAAc,EAAE,OAAO,KAAK,CAAC,GAAG,GAAG;AACzF,IAAI,gBAAgB,CAAC;AACrB,OAAO,UAAU,aAAa,aAAa;AAC3C,WAAW,eAAe,QAAQ,aAAa,GAAG,OAAO,OAAO;AAChE,WAAW,eAAe,QAAQ,eAAe,GAAG,OAAO,OAAO;AAClE,WAAW,eAAe,QAAQ,iCAAuB,GAAG,OAAO,OAAO;AAC1E,WAAW,eAAe,QAAQ,kCAAwB,GAAG,OAAO,OAAO;AAC3E,WAAW,eAAe,QAAQ,kBAAQ,GAAG,OAAO,OAAO;AAC3D,WAAW,eAAe,QAAQ,yBAAe,GAAG,OAAO,OAAO"}
|
package/dist/cjs/mustReplace.cjs
CHANGED
|
@@ -3,47 +3,39 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
5
|
var __export = (target, all) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: true
|
|
9
|
+
});
|
|
10
10
|
};
|
|
11
11
|
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
14
|
+
get: () => from[key],
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
19
|
};
|
|
20
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
21
|
-
value: true
|
|
22
|
-
}), mod);
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
21
|
var mustReplace_exports = {};
|
|
24
|
-
__export(mustReplace_exports, {
|
|
25
|
-
mustReplace: () => mustReplace
|
|
26
|
-
});
|
|
22
|
+
__export(mustReplace_exports, { mustReplace: () => mustReplace });
|
|
27
23
|
module.exports = __toCommonJS(mustReplace_exports);
|
|
28
24
|
var import_node_fs = require("node:fs");
|
|
29
25
|
var import_node_os = require("node:os");
|
|
30
26
|
var import_node_path = require("node:path");
|
|
31
27
|
function mustReplace(source, replacements) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
sourceOut = sourceOut.replace(find, replace);
|
|
47
|
-
}
|
|
48
|
-
return sourceOut;
|
|
49
|
-
}
|
|
28
|
+
let sourceOut = source;
|
|
29
|
+
for (const { find, replace, optional } of replacements) {
|
|
30
|
+
if (!optional) {
|
|
31
|
+
const found = find instanceof RegExp ? find.test(sourceOut) : sourceOut.includes(find);
|
|
32
|
+
if (!found) {
|
|
33
|
+
const tmpPath = (0, import_node_path.join)((0, import_node_os.tmpdir)(), `replace-error-${Math.random()}`);
|
|
34
|
+
(0, import_node_fs.writeFileSync)(tmpPath, sourceOut, "utf-8");
|
|
35
|
+
throw new Error(`Substring or pattern "${find}" not found in the string, replacing in source: ${tmpPath}.`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
sourceOut = sourceOut.replace(find, replace);
|
|
39
|
+
}
|
|
40
|
+
return sourceOut;
|
|
41
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
16
|
+
get: () => from[key],
|
|
17
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
|
+
var mustReplace_exports = {};
|
|
24
|
+
__export(mustReplace_exports, { mustReplace: () => mustReplace });
|
|
25
|
+
module.exports = __toCommonJS(mustReplace_exports);
|
|
26
|
+
var import_fs = require("fs");
|
|
27
|
+
var import_os = require("os");
|
|
28
|
+
var import_path = require("path");
|
|
29
|
+
function mustReplace(source, replacements) {
|
|
30
|
+
var sourceOut = source;
|
|
31
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
|
32
|
+
try {
|
|
33
|
+
for (var _iterator = replacements[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
34
|
+
var { find, replace, optional } = _step.value;
|
|
35
|
+
if (!optional) {
|
|
36
|
+
var found = find instanceof RegExp ? find.test(sourceOut) : sourceOut.includes(find);
|
|
37
|
+
if (!found) {
|
|
38
|
+
var tmpPath = (0, import_path.join)((0, import_os.tmpdir)(), `replace-error-${Math.random()}`);
|
|
39
|
+
(0, import_fs.writeFileSync)(tmpPath, sourceOut, "utf-8");
|
|
40
|
+
throw new Error(`Substring or pattern "${find}" not found in the string, replacing in source: ${tmpPath}.`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
sourceOut = sourceOut.replace(find, replace);
|
|
44
|
+
}
|
|
45
|
+
} catch (err) {
|
|
46
|
+
_didIteratorError = true;
|
|
47
|
+
_iteratorError = err;
|
|
48
|
+
} finally {
|
|
49
|
+
try {
|
|
50
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
51
|
+
_iterator.return();
|
|
52
|
+
}
|
|
53
|
+
} finally {
|
|
54
|
+
if (_didIteratorError) {
|
|
55
|
+
throw _iteratorError;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return sourceOut;
|
|
60
|
+
}
|
|
@@ -5,74 +5,58 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
7
|
var __export = (target, all) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
12
|
};
|
|
13
13
|
var __copyProps = (to, from, except, desc) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
16
|
+
get: () => from[key],
|
|
17
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
21
|
};
|
|
22
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
23
|
-
value: true
|
|
24
|
-
}), mod);
|
|
22
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
23
|
var mustReplace_exports = {};
|
|
26
|
-
__export(mustReplace_exports, {
|
|
27
|
-
mustReplace: () => mustReplace
|
|
28
|
-
});
|
|
24
|
+
__export(mustReplace_exports, { mustReplace: () => mustReplace });
|
|
29
25
|
module.exports = __toCommonJS(mustReplace_exports);
|
|
30
26
|
var import_fs = require("fs");
|
|
31
27
|
var import_os = require("os");
|
|
32
28
|
var import_path = require("path");
|
|
33
|
-
function _instanceof(left, right) {
|
|
34
|
-
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
35
|
-
return !!right[Symbol.hasInstance](left);
|
|
36
|
-
} else {
|
|
37
|
-
return left instanceof right;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
29
|
function mustReplace(source, replacements) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (_didIteratorError) {
|
|
72
|
-
throw _iteratorError;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return sourceOut;
|
|
30
|
+
var sourceOut = source;
|
|
31
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
|
32
|
+
try {
|
|
33
|
+
for (var _iterator = replacements[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
34
|
+
var { find, replace, optional } = _step.value;
|
|
35
|
+
if (!optional) {
|
|
36
|
+
var found = find instanceof RegExp ? find.test(sourceOut) : sourceOut.includes(find);
|
|
37
|
+
if (!found) {
|
|
38
|
+
var tmpPath = (0, import_path.join)((0, import_os.tmpdir)(), `replace-error-${Math.random()}`);
|
|
39
|
+
(0, import_fs.writeFileSync)(tmpPath, sourceOut, "utf-8");
|
|
40
|
+
throw new Error(`Substring or pattern "${find}" not found in the string, replacing in source: ${tmpPath}.`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
sourceOut = sourceOut.replace(find, replace);
|
|
44
|
+
}
|
|
45
|
+
} catch (err) {
|
|
46
|
+
_didIteratorError = true;
|
|
47
|
+
_iteratorError = err;
|
|
48
|
+
} finally {
|
|
49
|
+
try {
|
|
50
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
51
|
+
_iterator.return();
|
|
52
|
+
}
|
|
53
|
+
} finally {
|
|
54
|
+
if (_didIteratorError) {
|
|
55
|
+
throw _iteratorError;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return sourceOut;
|
|
77
60
|
}
|
|
61
|
+
|
|
78
62
|
//# sourceMappingURL=mustReplace.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"mustReplace.native.js","names":[],"sources":["cjs/mustReplace.native.js"],"sourcesContent":["\"use strict\";\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar mustReplace_exports = {};\n__export(mustReplace_exports, {\n mustReplace: () => mustReplace\n});\nmodule.exports = __toCommonJS(mustReplace_exports);\nvar import_fs = require(\"fs\");\nvar import_os = require(\"os\");\nvar import_path = require(\"path\");\nfunction mustReplace(source, replacements) {\n var sourceOut = source;\n var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;\n try {\n for (var _iterator = replacements[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {\n var { find, replace, optional } = _step.value;\n if (!optional) {\n var found = find instanceof RegExp ? find.test(sourceOut) : sourceOut.includes(find);\n if (!found) {\n var tmpPath = (0, import_path.join)((0, import_os.tmpdir)(), `replace-error-${Math.random()}`);\n (0, import_fs.writeFileSync)(tmpPath, sourceOut, \"utf-8\");\n throw new Error(`Substring or pattern \"${find}\" not found in the string, replacing in source: ${tmpPath}.`);\n }\n }\n sourceOut = sourceOut.replace(find, replace);\n }\n } catch (err) {\n _didIteratorError = true;\n _iteratorError = err;\n } finally {\n try {\n if (!_iteratorNormalCompletion && _iterator.return != null) {\n _iterator.return();\n }\n } finally {\n if (_didIteratorError) {\n throw _iteratorError;\n }\n }\n }\n return sourceOut;\n}\n//# sourceMappingURL=mustReplace.js.map\n"],"mappings":";;;AACA,IAAI,YAAY,OAAO;AACvB,IAAI,mBAAmB,OAAO;AAC9B,IAAI,oBAAoB,OAAO;AAC/B,IAAI,eAAe,OAAO,UAAU;AACpC,IAAI,YAAY,QAAQ,QAAQ;CAC9B,KAAK,IAAI,QAAQ,KACf,UAAU,QAAQ,MAAM;EAAE,KAAK,IAAI;EAAO,YAAY;CAAK,CAAC;AAChE;AACA,IAAI,eAAe,IAAI,MAAM,QAAQ,SAAS;CAC5C,IAAI,QAAQ,OAAO,SAAS,YAAY,OAAO,SAAS,YAAY;EAClE,KAAK,IAAI,OAAO,kBAAkB,IAAI,GACpC,IAAI,CAAC,aAAa,KAAK,IAAI,GAAG,KAAK,QAAQ,QACzC,UAAU,IAAI,KAAK;GAAE,WAAW,KAAK;GAAM,YAAY,EAAE,OAAO,iBAAiB,MAAM,GAAG,MAAM,KAAK;EAAW,CAAC;CACvH;CACA,OAAO;AACT;AACA,IAAI,gBAAgB,QAAQ,YAAY,UAAU,CAAC,GAAG,cAAc,EAAE,OAAO,KAAK,CAAC,GAAG,GAAG;AACzF,IAAI,sBAAsB,CAAC;AAC3B,SAAS,qBAAqB,EAC5B,mBAAmB,YACrB,CAAC;AACD,OAAO,UAAU,aAAa,mBAAmB;AACjD,IAAI,YAAY,QAAQ,IAAI;AAC5B,IAAI,YAAY,QAAQ,IAAI;AAC5B,IAAI,cAAc,QAAQ,MAAM;AAChC,SAAS,YAAY,QAAQ,cAAc;CACzC,IAAI,YAAY;CAChB,IAAI,4BAA4B,MAAM,oBAAoB,OAAO,iBAAiB,KAAK;CACvF,IAAI;EACF,KAAK,IAAI,YAAY,aAAa,OAAO,SAAS,CAAC,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
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
});
|
|
105
|
-
return wss;
|
|
4
|
+
const PROTOCOL_VERSION = 2;
|
|
5
|
+
const wss = new WebSocketServer({ noServer: true });
|
|
6
|
+
const clients = /* @__PURE__ */ new Map();
|
|
7
|
+
let nextClientId = 0;
|
|
8
|
+
function broadcast(broadcasterId, message) {
|
|
9
|
+
const forwarded = JSON.stringify({
|
|
10
|
+
version: PROTOCOL_VERSION,
|
|
11
|
+
method: message.method,
|
|
12
|
+
params: message.params
|
|
13
|
+
});
|
|
14
|
+
for (const [otherId, other] of clients) {
|
|
15
|
+
if (otherId !== broadcasterId) {
|
|
16
|
+
try {
|
|
17
|
+
other.ws.send(forwarded);
|
|
18
|
+
} catch {}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
wss.on("connection", (clientWs, req) => {
|
|
23
|
+
const clientId = `client#${nextClientId++}`;
|
|
24
|
+
const query = Object.fromEntries(new URL(req?.url || "/", "http://localhost").searchParams);
|
|
25
|
+
clients.set(clientId, {
|
|
26
|
+
ws: clientWs,
|
|
27
|
+
query
|
|
28
|
+
});
|
|
29
|
+
const remove = () => clients.delete(clientId);
|
|
30
|
+
clientWs.on("close", remove);
|
|
31
|
+
clientWs.on("error", remove);
|
|
32
|
+
clientWs.on("message", (data, isBinary) => {
|
|
33
|
+
if (isBinary) return;
|
|
34
|
+
let message;
|
|
35
|
+
try {
|
|
36
|
+
message = JSON.parse(data.toString());
|
|
37
|
+
} catch {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (message?.version !== PROTOCOL_VERSION) return;
|
|
41
|
+
try {
|
|
42
|
+
const isBroadcastMsg = typeof message.method === "string" && message.id === void 0 && message.target === void 0;
|
|
43
|
+
const isRequest = typeof message.method === "string" && typeof message.target === "string";
|
|
44
|
+
const isResponse = typeof message.id === "object" && message.id?.requestId !== void 0 && typeof message.id?.clientId === "string" && (message.result !== void 0 || message.error !== void 0);
|
|
45
|
+
if (isBroadcastMsg) {
|
|
46
|
+
broadcast(clientId, message);
|
|
47
|
+
} else if (isRequest) {
|
|
48
|
+
if (message.target === "server") {
|
|
49
|
+
let result;
|
|
50
|
+
if (message.method === "getid") {
|
|
51
|
+
result = clientId;
|
|
52
|
+
} else if (message.method === "getpeers") {
|
|
53
|
+
const peers = {};
|
|
54
|
+
for (const [otherId, other] of clients) {
|
|
55
|
+
if (otherId !== clientId) peers[otherId] = other.query;
|
|
56
|
+
}
|
|
57
|
+
result = peers;
|
|
58
|
+
} else {
|
|
59
|
+
throw new Error(`unknown method: ${message.method}`);
|
|
60
|
+
}
|
|
61
|
+
clientWs.send(JSON.stringify({
|
|
62
|
+
version: PROTOCOL_VERSION,
|
|
63
|
+
result,
|
|
64
|
+
id: message.id
|
|
65
|
+
}));
|
|
66
|
+
} else {
|
|
67
|
+
const target = clients.get(message.target);
|
|
68
|
+
if (!target) {
|
|
69
|
+
throw new Error(`could not find id "${message.target}" while forwarding request`);
|
|
70
|
+
}
|
|
71
|
+
target.ws.send(JSON.stringify({
|
|
72
|
+
version: PROTOCOL_VERSION,
|
|
73
|
+
method: message.method,
|
|
74
|
+
params: message.params,
|
|
75
|
+
id: message.id === void 0 ? void 0 : {
|
|
76
|
+
requestId: message.id,
|
|
77
|
+
clientId
|
|
78
|
+
}
|
|
79
|
+
}));
|
|
80
|
+
}
|
|
81
|
+
} else if (isResponse) {
|
|
82
|
+
if (!message.id) return;
|
|
83
|
+
const target = clients.get(message.id.clientId);
|
|
84
|
+
target?.ws.send(JSON.stringify({
|
|
85
|
+
version: PROTOCOL_VERSION,
|
|
86
|
+
result: message.result,
|
|
87
|
+
error: message.error,
|
|
88
|
+
id: message.id.requestId
|
|
89
|
+
}));
|
|
90
|
+
}
|
|
91
|
+
} catch (err) {
|
|
92
|
+
if (message.id !== void 0) {
|
|
93
|
+
try {
|
|
94
|
+
clientWs.send(JSON.stringify({
|
|
95
|
+
version: PROTOCOL_VERSION,
|
|
96
|
+
error: String(err),
|
|
97
|
+
id: message.id
|
|
98
|
+
}));
|
|
99
|
+
} catch {}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
return wss;
|
|
106
105
|
}
|
|
106
|
+
|
|
107
107
|
export { createMessageSocket };
|
|
108
108
|
//# sourceMappingURL=createMessageSocket.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"createMessageSocket.js","names":[],"sources":["esm/createMessageSocket.js"],"sourcesContent":["import { WebSocketServer } from \"ws\";\nfunction createMessageSocket() {\n const PROTOCOL_VERSION = 2;\n const wss = new WebSocketServer({ noServer: true });\n const clients = /* @__PURE__ */ new Map();\n let nextClientId = 0;\n function broadcast(broadcasterId, message) {\n const forwarded = JSON.stringify({\n version: PROTOCOL_VERSION,\n method: message.method,\n params: message.params\n });\n for (const [otherId, other] of clients) {\n if (otherId !== broadcasterId) {\n try {\n other.ws.send(forwarded);\n } catch {\n }\n }\n }\n }\n wss.on(\"connection\", (clientWs, req) => {\n const clientId = `client#${nextClientId++}`;\n const query = Object.fromEntries(\n new URL(req?.url || \"/\", \"http://localhost\").searchParams\n );\n clients.set(clientId, { ws: clientWs, query });\n const remove = () => clients.delete(clientId);\n clientWs.on(\"close\", remove);\n clientWs.on(\"error\", remove);\n clientWs.on(\"message\", (data, isBinary) => {\n if (isBinary) return;\n let message;\n try {\n message = JSON.parse(data.toString());\n } catch {\n return;\n }\n if (message?.version !== PROTOCOL_VERSION) return;\n try {\n const isBroadcastMsg = typeof message.method === \"string\" && message.id === void 0 && message.target === void 0;\n const isRequest = typeof message.method === \"string\" && typeof message.target === \"string\";\n const isResponse = typeof message.id === \"object\" && message.id?.requestId !== void 0 && typeof message.id?.clientId === \"string\" && (message.result !== void 0 || message.error !== void 0);\n if (isBroadcastMsg) {\n broadcast(clientId, message);\n } else if (isRequest) {\n if (message.target === \"server\") {\n let result;\n if (message.method === \"getid\") {\n result = clientId;\n } else if (message.method === \"getpeers\") {\n const peers = {};\n for (const [otherId, other] of clients) {\n if (otherId !== clientId) peers[otherId] = other.query;\n }\n result = peers;\n } else {\n throw new Error(`unknown method: ${message.method}`);\n }\n clientWs.send(\n JSON.stringify({ version: PROTOCOL_VERSION, result, id: message.id })\n );\n } else {\n const target = clients.get(message.target);\n if (!target) {\n throw new Error(\n `could not find id \"${message.target}\" while forwarding request`\n );\n }\n target.ws.send(\n JSON.stringify({\n version: PROTOCOL_VERSION,\n method: message.method,\n params: message.params,\n id: message.id === void 0 ? void 0 : { requestId: message.id, clientId }\n })\n );\n }\n } else if (isResponse) {\n if (!message.id) return;\n const target = clients.get(message.id.clientId);\n target?.ws.send(\n JSON.stringify({\n version: PROTOCOL_VERSION,\n result: message.result,\n error: message.error,\n id: message.id.requestId\n })\n );\n }\n } catch (err) {\n if (message.id !== void 0) {\n try {\n clientWs.send(\n JSON.stringify({\n version: PROTOCOL_VERSION,\n error: String(err),\n id: message.id\n })\n );\n } catch {\n }\n }\n }\n });\n });\n return wss;\n}\nexport {\n createMessageSocket\n};\n//# sourceMappingURL=createMessageSocket.js.map\n"],"mappings":";;;AACA,SAAS,sBAAsB;CAC7B,MAAM,mBAAmB;CACzB,MAAM,MAAM,IAAI,gBAAgB,EAAE,UAAU,KAAK,CAAC;CAClD,MAAM,0BAA0B,IAAI,IAAI;CACxC,IAAI,eAAe;CACnB,SAAS,UAAU,eAAe,SAAS;EACzC,MAAM,YAAY,KAAK,UAAU;GAC/B,SAAS;GACT,QAAQ,QAAQ;GAChB,QAAQ,QAAQ;EAClB,CAAC;EACD,KAAK,MAAM,CAAC,SAAS,UAAU,SAAS;GACtC,IAAI,YAAY,eAAe;IAC7B,IAAI;KACF,MAAM,GAAG,KAAK,SAAS;IACzB,QAAQ,CACR;GACF;EACF;CACF;CACA,IAAI,GAAG,eAAe,UAAU,QAAQ;EACtC,MAAM,WAAW,UAAU;EAC3B,MAAM,QAAQ,OAAO,YACnB,IAAI,IAAI,KAAK,OAAO,KAAK,kBAAkB,CAAC,CAAC,YAC/C;EACA,QAAQ,IAAI,UAAU;GAAE,IAAI;GAAU;EAAM,CAAC;EAC7C,MAAM,eAAe,QAAQ,OAAO,QAAQ;EAC5C,SAAS,GAAG,SAAS,MAAM;EAC3B,SAAS,GAAG,SAAS,MAAM;EAC3B,SAAS,GAAG,YAAY,MAAM,aAAa;GACzC,IAAI,UAAU;GACd,IAAI;GACJ,IAAI;IACF,UAAU,KAAK,MAAM,KAAK,SAAS,CAAC;GACtC,QAAQ;IACN;GACF;GACA,IAAI,SAAS,YAAY,kBAAkB;GAC3C,IAAI;IACF,MAAM,iBAAiB,OAAO,QAAQ,WAAW,YAAY,QAAQ,OAAO,KA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