@vxrn/utils 1.25.4 → 1.25.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.
Files changed (43) hide show
  1. package/package.json +3 -3
  2. package/dist/cjs/createMessageSocket.cjs +0 -133
  3. package/dist/cjs/createMessageSocket.native.js +0 -182
  4. package/dist/cjs/createMessageSocket.native.js.map +0 -1
  5. package/dist/cjs/detectPackageManager.cjs +0 -93
  6. package/dist/cjs/detectPackageManager.native.js +0 -103
  7. package/dist/cjs/detectPackageManager.native.js.map +0 -1
  8. package/dist/cjs/exec.cjs +0 -63
  9. package/dist/cjs/exec.native.js +0 -68
  10. package/dist/cjs/exec.native.js.map +0 -1
  11. package/dist/cjs/index.cjs +0 -25
  12. package/dist/cjs/index.native.js +0 -28
  13. package/dist/cjs/index.native.js.map +0 -1
  14. package/dist/cjs/mustReplace.cjs +0 -49
  15. package/dist/cjs/mustReplace.native.js +0 -78
  16. package/dist/cjs/mustReplace.native.js.map +0 -1
  17. package/dist/esm/createMessageSocket.mjs +0 -108
  18. package/dist/esm/createMessageSocket.mjs.map +0 -1
  19. package/dist/esm/createMessageSocket.native.js +0 -154
  20. package/dist/esm/createMessageSocket.native.js.map +0 -1
  21. package/dist/esm/detectPackageManager.mjs +0 -68
  22. package/dist/esm/detectPackageManager.mjs.map +0 -1
  23. package/dist/esm/detectPackageManager.native.js +0 -75
  24. package/dist/esm/detectPackageManager.native.js.map +0 -1
  25. package/dist/esm/exec.mjs +0 -36
  26. package/dist/esm/exec.mjs.map +0 -1
  27. package/dist/esm/exec.native.js +0 -38
  28. package/dist/esm/exec.native.js.map +0 -1
  29. package/dist/esm/index.js +0 -7
  30. package/dist/esm/index.js.map +0 -1
  31. package/dist/esm/index.mjs +0 -7
  32. package/dist/esm/index.mjs.map +0 -1
  33. package/dist/esm/index.native.js +0 -7
  34. package/dist/esm/index.native.js.map +0 -1
  35. package/dist/esm/mustReplace.mjs +0 -24
  36. package/dist/esm/mustReplace.mjs.map +0 -1
  37. package/dist/esm/mustReplace.native.js +0 -50
  38. package/dist/esm/mustReplace.native.js.map +0 -1
  39. package/types/createMessageSocket.d.ts.map +0 -1
  40. package/types/detectPackageManager.d.ts.map +0 -1
  41. package/types/exec.d.ts.map +0 -1
  42. package/types/index.d.ts.map +0 -1
  43. package/types/mustReplace.d.ts.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vxrn/utils",
3
- "version": "1.25.4",
3
+ "version": "1.25.5",
4
4
  "sideEffects": false,
5
5
  "type": "module",
6
6
  "types": "./types/index.d.ts",
@@ -30,8 +30,8 @@
30
30
  "typecheck": "tsc --noEmit"
31
31
  },
32
32
  "dependencies": {
33
- "@vxrn/debug": "1.25.4",
34
- "@vxrn/resolve": "1.25.4",
33
+ "@vxrn/debug": "1.25.5",
34
+ "@vxrn/resolve": "1.25.5",
35
35
  "ws": "^8.21.0"
36
36
  },
37
37
  "devDependencies": {
@@ -1,133 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all) __defProp(target, name, {
7
- get: all[name],
8
- enumerable: true
9
- });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
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
- };
20
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
21
- value: true
22
- }), mod);
23
- var createMessageSocket_exports = {};
24
- __export(createMessageSocket_exports, {
25
- createMessageSocket: () => createMessageSocket
26
- });
27
- module.exports = __toCommonJS(createMessageSocket_exports);
28
- var import_ws = require("ws");
29
- function createMessageSocket() {
30
- const PROTOCOL_VERSION = 2;
31
- const wss = new import_ws.WebSocketServer({
32
- noServer: true
33
- });
34
- const clients = /* @__PURE__ */new Map();
35
- let nextClientId = 0;
36
- function broadcast(broadcasterId, message) {
37
- const forwarded = JSON.stringify({
38
- version: PROTOCOL_VERSION,
39
- method: message.method,
40
- params: message.params
41
- });
42
- for (const [otherId, other] of clients) {
43
- if (otherId !== broadcasterId) {
44
- try {
45
- other.ws.send(forwarded);
46
- } catch {}
47
- }
48
- }
49
- }
50
- wss.on("connection", (clientWs, req) => {
51
- const clientId = `client#${nextClientId++}`;
52
- const query = Object.fromEntries(new URL(req?.url || "/", "http://localhost").searchParams);
53
- clients.set(clientId, {
54
- ws: clientWs,
55
- query
56
- });
57
- const remove = () => clients.delete(clientId);
58
- clientWs.on("close", remove);
59
- clientWs.on("error", remove);
60
- clientWs.on("message", (data, isBinary) => {
61
- if (isBinary) return;
62
- let message;
63
- try {
64
- message = JSON.parse(data.toString());
65
- } catch {
66
- return;
67
- }
68
- if (message?.version !== PROTOCOL_VERSION) return;
69
- try {
70
- const isBroadcastMsg = typeof message.method === "string" && message.id === void 0 && message.target === void 0;
71
- const isRequest = typeof message.method === "string" && typeof message.target === "string";
72
- const isResponse = typeof message.id === "object" && message.id?.requestId !== void 0 && typeof message.id?.clientId === "string" && (message.result !== void 0 || message.error !== void 0);
73
- if (isBroadcastMsg) {
74
- broadcast(clientId, message);
75
- } else if (isRequest) {
76
- if (message.target === "server") {
77
- let result;
78
- if (message.method === "getid") {
79
- result = clientId;
80
- } else if (message.method === "getpeers") {
81
- const peers = {};
82
- for (const [otherId, other] of clients) {
83
- if (otherId !== clientId) peers[otherId] = other.query;
84
- }
85
- result = peers;
86
- } else {
87
- throw new Error(`unknown method: ${message.method}`);
88
- }
89
- clientWs.send(JSON.stringify({
90
- version: PROTOCOL_VERSION,
91
- result,
92
- id: message.id
93
- }));
94
- } else {
95
- const target = clients.get(message.target);
96
- if (!target) {
97
- throw new Error(`could not find id "${message.target}" while forwarding request`);
98
- }
99
- target.ws.send(JSON.stringify({
100
- version: PROTOCOL_VERSION,
101
- method: message.method,
102
- params: message.params,
103
- id: message.id === void 0 ? void 0 : {
104
- requestId: message.id,
105
- clientId
106
- }
107
- }));
108
- }
109
- } else if (isResponse) {
110
- if (!message.id) return;
111
- const target = clients.get(message.id.clientId);
112
- target?.ws.send(JSON.stringify({
113
- version: PROTOCOL_VERSION,
114
- result: message.result,
115
- error: message.error,
116
- id: message.id.requestId
117
- }));
118
- }
119
- } catch (err) {
120
- if (message.id !== void 0) {
121
- try {
122
- clientWs.send(JSON.stringify({
123
- version: PROTOCOL_VERSION,
124
- error: String(err),
125
- id: message.id
126
- }));
127
- } catch {}
128
- }
129
- }
130
- });
131
- });
132
- return wss;
133
- }
@@ -1,182 +0,0 @@
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", {
23
- value: true
24
- }), mod);
25
- var createMessageSocket_exports = {};
26
- __export(createMessageSocket_exports, {
27
- createMessageSocket: () => createMessageSocket
28
- });
29
- module.exports = __toCommonJS(createMessageSocket_exports);
30
- var import_ws = require("ws");
31
- function _type_of(obj) {
32
- "@swc/helpers - typeof";
33
-
34
- return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
35
- }
36
- function createMessageSocket() {
37
- var PROTOCOL_VERSION = 2;
38
- var wss = new import_ws.WebSocketServer({
39
- noServer: true
40
- });
41
- var clients = /* @__PURE__ */new Map();
42
- var nextClientId = 0;
43
- function broadcast(broadcasterId, message) {
44
- var forwarded = JSON.stringify({
45
- version: PROTOCOL_VERSION,
46
- method: message.method,
47
- params: message.params
48
- });
49
- var _iteratorNormalCompletion = true,
50
- _didIteratorError = false,
51
- _iteratorError = void 0;
52
- try {
53
- for (var _iterator = clients[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
54
- var [otherId, other] = _step.value;
55
- if (otherId !== broadcasterId) {
56
- try {
57
- other.ws.send(forwarded);
58
- } catch (unused) {}
59
- }
60
- }
61
- } catch (err) {
62
- _didIteratorError = true;
63
- _iteratorError = err;
64
- } finally {
65
- try {
66
- if (!_iteratorNormalCompletion && _iterator.return != null) {
67
- _iterator.return();
68
- }
69
- } finally {
70
- if (_didIteratorError) {
71
- throw _iteratorError;
72
- }
73
- }
74
- }
75
- }
76
- wss.on("connection", function (clientWs, req) {
77
- var clientId = `client#${nextClientId++}`;
78
- var query = Object.fromEntries(new URL((req === null || req === void 0 ? void 0 : req.url) || "/", "http://localhost").searchParams);
79
- clients.set(clientId, {
80
- ws: clientWs,
81
- query
82
- });
83
- var remove = function () {
84
- return clients.delete(clientId);
85
- };
86
- clientWs.on("close", remove);
87
- clientWs.on("error", remove);
88
- clientWs.on("message", function (data, isBinary) {
89
- if (isBinary) return;
90
- var message;
91
- try {
92
- message = JSON.parse(data.toString());
93
- } catch (unused) {
94
- return;
95
- }
96
- if ((message === null || message === void 0 ? void 0 : message.version) !== PROTOCOL_VERSION) return;
97
- try {
98
- var _message_id, _message_id1;
99
- var isBroadcastMsg = typeof message.method === "string" && message.id === void 0 && message.target === void 0;
100
- var isRequest = typeof message.method === "string" && typeof message.target === "string";
101
- var isResponse = _type_of(message.id) === "object" && ((_message_id = message.id) === null || _message_id === void 0 ? void 0 : _message_id.requestId) !== void 0 && typeof ((_message_id1 = message.id) === null || _message_id1 === void 0 ? void 0 : _message_id1.clientId) === "string" && (message.result !== void 0 || message.error !== void 0);
102
- if (isBroadcastMsg) {
103
- broadcast(clientId, message);
104
- } else if (isRequest) {
105
- if (message.target === "server") {
106
- var result;
107
- if (message.method === "getid") {
108
- result = clientId;
109
- } else if (message.method === "getpeers") {
110
- var peers = {};
111
- var _iteratorNormalCompletion = true,
112
- _didIteratorError = false,
113
- _iteratorError = void 0;
114
- try {
115
- for (var _iterator = clients[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
116
- var [otherId, other] = _step.value;
117
- if (otherId !== clientId) peers[otherId] = other.query;
118
- }
119
- } catch (err) {
120
- _didIteratorError = true;
121
- _iteratorError = err;
122
- } finally {
123
- try {
124
- if (!_iteratorNormalCompletion && _iterator.return != null) {
125
- _iterator.return();
126
- }
127
- } finally {
128
- if (_didIteratorError) {
129
- throw _iteratorError;
130
- }
131
- }
132
- }
133
- result = peers;
134
- } else {
135
- throw new Error(`unknown method: ${message.method}`);
136
- }
137
- clientWs.send(JSON.stringify({
138
- version: PROTOCOL_VERSION,
139
- result,
140
- id: message.id
141
- }));
142
- } else {
143
- var target = clients.get(message.target);
144
- if (!target) {
145
- throw new Error(`could not find id "${message.target}" while forwarding request`);
146
- }
147
- target.ws.send(JSON.stringify({
148
- version: PROTOCOL_VERSION,
149
- method: message.method,
150
- params: message.params,
151
- id: message.id === void 0 ? void 0 : {
152
- requestId: message.id,
153
- clientId
154
- }
155
- }));
156
- }
157
- } else if (isResponse) {
158
- if (!message.id) return;
159
- var target1 = clients.get(message.id.clientId);
160
- target1 === null || target1 === void 0 ? void 0 : target1.ws.send(JSON.stringify({
161
- version: PROTOCOL_VERSION,
162
- result: message.result,
163
- error: message.error,
164
- id: message.id.requestId
165
- }));
166
- }
167
- } catch (err) {
168
- if (message.id !== void 0) {
169
- try {
170
- clientWs.send(JSON.stringify({
171
- version: PROTOCOL_VERSION,
172
- error: String(err),
173
- id: message.id
174
- }));
175
- } catch (unused) {}
176
- }
177
- }
178
- });
179
- });
180
- return wss;
181
- }
182
- //# sourceMappingURL=createMessageSocket.native.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","createMessageSocket_exports","__export","createMessageSocket","module","exports","import_ws","require","_type_of","obj","Symbol","constructor","PROTOCOL_VERSION","wss","WebSocketServer","noServer","clients","Map","nextClientId","broadcast","broadcasterId","message","forwarded","JSON","stringify","version","method","params","_iteratorNormalCompletion","_didIteratorError","_iteratorError","_iterator","iterator","_step","next","done","otherId","other","ws","send","unused","err","return","on","clientWs","req","clientId","query","Object","fromEntries","URL","url","searchParams","set","remove","delete","data","isBinary","parse","toString","_message_id","_message_id1","isBroadcastMsg","id","target","isRequest","isResponse","requestId","result","error","peers","Error"],"sources":["../../src/createMessageSocket.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,2BAAA;AAAAC,QAAA,CAAAD,2BAAA;EAAAE,mBAAA,EAAAA,CAAA,KAAAA;AAAA;AAAAC,MAAA,CAAAC,OAAA,GAAgCT,YAAA,CAAAK,2BAAA;AAQzB,IAAAK,SAAS,GAAAC,OAAA;AACd,SAAMC,SAAAC,GAAA;EACN,uBAAgB;;EAChB,OAAMA,GAAA,WAAUC,MAAA,gBAGd,IAAAD,GAAA,CAAAE,WAAA,KAAAD,MAAA,qBAAAD,GAAA;AACF;AAEA,SAAAN,mBACEA,CAAA;EAGA,IAAAS,gBAAkB;EAAe,IAC/BC,GAAA,OAASP,SAAA,CAAAQ,eAAA;IAAAC,QACT,EAAQ;EAAQ;EACA,IACjBC,OAAA,sBAAAC,G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B,GAAQ,IAAG;gBAAAC,iBAAQ;gBAAAC,cAAA;cAC9C,IAAQ;gBACN,KAAK,IAAAC,SAAU,GAAAf,OAAA,CAAAN,MAAA,CAAAsB,QAAA,KAAAC,KAAA,IAAAL,yBAAA,IAAAK,KAAA,GAAAF,SAAA,CAAAG,IAAA,IAAAC,IAAA,GAAAP,yBAAA;kBACb,KAASQ,OAAA,EAAAC,KAAA,IAAAJ,KAAA,CAAAjC,KAAA;kBACT,IAAQoC,OAAA,KAAQU,QAAA,EAAAwB,KAAA,CAAAlC,OAAA,IAAAC,KAAA,CAAAU,KAAA;gBAChB;cACA,SAAIN,GAAQ;gBACbZ,iBAAA;gBACHC,cAAA,GAAAW,GAAA;cACF;gBACO,IAAK;kBACR,IAAQ,CAAAb,yBAAkB,IAAAG,SAAA,CAAAW,MAAA;oBACxBX,SAAA,CAAAW,MAAA;kBACF;gBACE,UAAK;kBACH,IAAAb,iBAAS;oBACT,MAAOC,cAAU;kBACjB;gBACD;cACH;cACFsC,MAAQ,GAAAE,KAAA;YAAC;cACX,UAAAC,KAAA,oBAAAlD,OAAA,CAAAK,MAAA;YACF;YACDkB,QAAA,CAAAL,IAAA,CAAAhB,IAAA,CAAAC,SAAA;cACFC,OAAA,EAAAb,gBAAA;cAEMwD,MAAA;cACTL,EAAA,EAAA1C,OAAA,CAAA0C","ignoreList":[]}
@@ -1,93 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all) __defProp(target, name, {
7
- get: all[name],
8
- enumerable: true
9
- });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
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
- };
20
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
21
- value: true
22
- }), mod);
23
- var detectPackageManager_exports = {};
24
- __export(detectPackageManager_exports, {
25
- detectPackageManager: () => detectPackageManager
26
- });
27
- module.exports = __toCommonJS(detectPackageManager_exports);
28
- var import_node_fs = require("node:fs");
29
- var import_node_path = require("node:path");
30
- var import_exec = require("./exec.cjs");
31
- async function pathExists(p) {
32
- try {
33
- await import_node_fs.promises.access(p);
34
- return true;
35
- } catch {
36
- return false;
37
- }
38
- }
39
- async function hasGlobal(pm) {
40
- try {
41
- const command = process.platform === "win32" ? `where ${pm}` : `which ${pm}`;
42
- const res = (0, import_exec.exec)(command);
43
- return !!res.length;
44
- } catch {
45
- return false;
46
- }
47
- }
48
- async function getFromLockfile(cwd = ".") {
49
- const [yarn, npm, pnpm, bun] = await Promise.all([pathExists((0, import_node_path.resolve)(cwd, "yarn.lock")), pathExists((0, import_node_path.resolve)(cwd, "package-lock.json")), pathExists((0, import_node_path.resolve)(cwd, "pnpm-lock.yaml")), pathExists((0, import_node_path.resolve)(cwd, "bun.lockb"))]);
50
- return {
51
- bun,
52
- yarn,
53
- pnpm,
54
- npm
55
- };
56
- }
57
- async function getFromPackage(cwd = ".") {
58
- if (await pathExists((0, import_node_path.resolve)(cwd, "package.json"))) {
59
- const json = JSON.parse(await import_node_fs.promises.readFile((0, import_node_path.resolve)(cwd, "package.json"), "utf-8"));
60
- if (json.packageManager) {
61
- const yarn = !!json.packageManager.startsWith("yarn");
62
- const pnpm = !!json.packageManager.startsWith("pnpm");
63
- const bun = !!json.packageManager.startsWith("bun");
64
- const npm = !!json.packageManager.startsWith("npm");
65
- return {
66
- bun,
67
- yarn,
68
- pnpm,
69
- npm
70
- };
71
- }
72
- }
73
- }
74
- const foundSome = obj => Object.keys(obj).some(k => !!obj[k]);
75
- const detectPackageManager = async ({
76
- cwd
77
- } = {}) => {
78
- const fromLockfile = await getFromLockfile(cwd);
79
- if (foundSome(fromLockfile)) {
80
- return fromLockfile;
81
- }
82
- const fromPackageJson = await getFromPackage(cwd);
83
- if (fromPackageJson && foundSome(fromPackageJson)) {
84
- return fromPackageJson;
85
- }
86
- const [npm, yarn, pnpm, bun] = await Promise.all([hasGlobal("npm"), hasGlobal("yarn"), hasGlobal("pnpm"), hasGlobal("bun")]);
87
- return {
88
- bun,
89
- yarn,
90
- pnpm,
91
- npm
92
- };
93
- };
@@ -1,103 +0,0 @@
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", {
23
- value: true
24
- }), mod);
25
- var detectPackageManager_exports = {};
26
- __export(detectPackageManager_exports, {
27
- detectPackageManager: () => detectPackageManager
28
- });
29
- module.exports = __toCommonJS(detectPackageManager_exports);
30
- var import_fs = require("fs");
31
- var import_path = require("path");
32
- var import_exec = require("./exec.native.js");
33
- async function pathExists(p) {
34
- try {
35
- await import_fs.promises.access(p);
36
- return true;
37
- } catch (unused) {
38
- return false;
39
- }
40
- }
41
- async function hasGlobal(pm) {
42
- try {
43
- var command = process.platform === "win32" ? `where ${pm}` : `which ${pm}`;
44
- var res = (0, import_exec.exec)(command);
45
- return !!res.length;
46
- } catch (unused) {
47
- return false;
48
- }
49
- }
50
- async function getFromLockfile() {
51
- var cwd = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : ".";
52
- var [yarn, npm, pnpm, bun] = await Promise.all([pathExists((0, import_path.resolve)(cwd, "yarn.lock")), pathExists((0, import_path.resolve)(cwd, "package-lock.json")), pathExists((0, import_path.resolve)(cwd, "pnpm-lock.yaml")), pathExists((0, import_path.resolve)(cwd, "bun.lockb"))]);
53
- return {
54
- bun,
55
- yarn,
56
- pnpm,
57
- npm
58
- };
59
- }
60
- async function getFromPackage() {
61
- var cwd = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : ".";
62
- if (await pathExists((0, import_path.resolve)(cwd, "package.json"))) {
63
- var json = JSON.parse(await import_fs.promises.readFile((0, import_path.resolve)(cwd, "package.json"), "utf-8"));
64
- if (json.packageManager) {
65
- var yarn = !!json.packageManager.startsWith("yarn");
66
- var pnpm = !!json.packageManager.startsWith("pnpm");
67
- var bun = !!json.packageManager.startsWith("bun");
68
- var npm = !!json.packageManager.startsWith("npm");
69
- return {
70
- bun,
71
- yarn,
72
- pnpm,
73
- npm
74
- };
75
- }
76
- }
77
- }
78
- var foundSome = function (obj) {
79
- return Object.keys(obj).some(function (k) {
80
- return !!obj[k];
81
- });
82
- };
83
- var detectPackageManager = async function () {
84
- var {
85
- cwd
86
- } = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
87
- var fromLockfile = await getFromLockfile(cwd);
88
- if (foundSome(fromLockfile)) {
89
- return fromLockfile;
90
- }
91
- var fromPackageJson = await getFromPackage(cwd);
92
- if (fromPackageJson && foundSome(fromPackageJson)) {
93
- return fromPackageJson;
94
- }
95
- var [npm, yarn, pnpm, bun] = await Promise.all([hasGlobal("npm"), hasGlobal("yarn"), hasGlobal("pnpm"), hasGlobal("bun")]);
96
- return {
97
- bun,
98
- yarn,
99
- pnpm,
100
- npm
101
- };
102
- };
103
- //# sourceMappingURL=detectPackageManager.native.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","detectPackageManager_exports","__export","detectPackageManager","module","exports","import_fs","require","import_path","import_exec","pathExists","p","promises","access","unused","hasGlobal","pm","command","process","platform","res","exec","length","getFromLockfile","cwd","arguments","yarn","npm","pnpm","bun","Promise","all","resolve","getFromPackage","json","JSON","parse","readFile","packageManager","startsWith","foundSome","obj","Object","keys","some","k","fromLockfile"],"sources":["../../src/detectPackageManager.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,4BAAA;AAAAC,QAAA,CAAAD,4BAAA;EAAAE,oBAAA,EAAAA,CAAA,KAAAA;AAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAT,YAA+B,CAAAK,4BAAA;AAC/B,IAAAK,SAAA,GAAAC,OAAwB;AACxB,IAAAC,WAAA,GAAqBD,OAAA;AAIrB,IAAAE,WAAe,GAAAF,OAAA,CAAW,kBAAW;AACnC,eAAIG,WAAAC,CAAA;EACF;IACA,MAAAL,SAAO,CAAAM,QAAA,CAAAC,MAAA,CAAAF,CAAA;IACT,OAAQ;EACN,SAAOG,MAAA;IACT;EACF;AAEA;AACE,eAAIC,UAAAC,EAAA;EACF;IACA,IAAAC,OAAM,GAAAC,OAAM,CAAAC,QAAA,KAAK,OAAO,YAAAH,EAAA,cAAAA,EAAA;IACxB,IAAAI,GAAO,GAAE,IAAIX,WAAA,CAAAY,IAAA,EAAAJ,OAAA;IACf,OAAQ,EAAAG,GAAA,CAAAE,MAAA;EACN,SAAOR,MAAA;IACT;EACF;AAEA;AACE,eAAaS,eAAcA,CAAA,EAAI;EAAkB,IAC/CC,GAAA,GAAAC,SAAW,CAAAH,MAAA,QAAAG,SAAQ,QAAK,SAAYA,SAAA;EAAA,IACpC,CAAAC,IAAA,EAAAC,GAAA,EAAAC,IAAW,EAAAC,GAAA,UAAAC,OA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ACA;IAAAqB;EAAA,IAAAC,SAAA,CAAAH,MAAA,QAAAG,SAAA,iBAAAA,SAAA;EAAA,IACAqB,YAAA,SAAAvB,eAAA,CAAAC,GAAA;EACF,IAAAgB,SAAA,CAAAM,YAAA;IACF,OAAAA,YAAA","ignoreList":[]}
package/dist/cjs/exec.cjs DELETED
@@ -1,63 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all) __defProp(target, name, {
7
- get: all[name],
8
- enumerable: true
9
- });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
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
- };
20
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
21
- value: true
22
- }), mod);
23
- var exec_exports = {};
24
- __export(exec_exports, {
25
- exec: () => exec,
26
- execPromise: () => execPromise,
27
- execPromiseQuiet: () => execPromiseQuiet
28
- });
29
- module.exports = __toCommonJS(exec_exports);
30
- var import_node_child_process = require("node:child_process");
31
- const exec = (cmd, options) => {
32
- return (0, import_node_child_process.execSync)(cmd, options)?.toString() || "";
33
- };
34
- const execPromise = (cmd, options) => {
35
- return new Promise((resolve, reject) => {
36
- const [command, ...args] = cmd.split(" ");
37
- const child = (0, import_node_child_process.spawn)(command, args, {
38
- stdio: options?.quiet ? "pipe" : "inherit",
39
- shell: true,
40
- ...options
41
- });
42
- if (!options?.quiet || process.env.DEBUG) {
43
- child.stdout?.pipe(process.stdout);
44
- child.stderr?.pipe(process.stderr);
45
- }
46
- child.on("close", code => {
47
- if (code !== 0) {
48
- reject(new Error(`Command failed with exit code ${code}: ${cmd}`));
49
- } else {
50
- resolve();
51
- }
52
- });
53
- child.on("error", error => {
54
- reject(error);
55
- });
56
- });
57
- };
58
- const execPromiseQuiet = (cmd, options) => {
59
- return execPromise(cmd, {
60
- ...options,
61
- quiet: true
62
- });
63
- };
@@ -1,68 +0,0 @@
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", {
23
- value: true
24
- }), mod);
25
- var exec_exports = {};
26
- __export(exec_exports, {
27
- exec: () => exec,
28
- execPromise: () => execPromise,
29
- execPromiseQuiet: () => execPromiseQuiet
30
- });
31
- module.exports = __toCommonJS(exec_exports);
32
- var import_child_process = require("child_process");
33
- var exec = function (cmd, options) {
34
- var _execSync;
35
- return ((_execSync = (0, import_child_process.execSync)(cmd, options)) === null || _execSync === void 0 ? void 0 : _execSync.toString()) || "";
36
- };
37
- var execPromise = function (cmd, options) {
38
- return new Promise(function (resolve, reject) {
39
- var [command, ...args] = cmd.split(" ");
40
- var child = (0, import_child_process.spawn)(command, args, {
41
- stdio: (options === null || options === void 0 ? void 0 : options.quiet) ? "pipe" : "inherit",
42
- shell: true,
43
- ...options
44
- });
45
- if (!(options === null || options === void 0 ? void 0 : options.quiet) || process.env.DEBUG) {
46
- var _child_stdout, _child_stderr;
47
- (_child_stdout = child.stdout) === null || _child_stdout === void 0 ? void 0 : _child_stdout.pipe(process.stdout);
48
- (_child_stderr = child.stderr) === null || _child_stderr === void 0 ? void 0 : _child_stderr.pipe(process.stderr);
49
- }
50
- child.on("close", function (code) {
51
- if (code !== 0) {
52
- reject(new Error(`Command failed with exit code ${code}: ${cmd}`));
53
- } else {
54
- resolve();
55
- }
56
- });
57
- child.on("error", function (error) {
58
- reject(error);
59
- });
60
- });
61
- };
62
- var execPromiseQuiet = function (cmd, options) {
63
- return execPromise(cmd, {
64
- ...options,
65
- quiet: true
66
- });
67
- };
68
- //# sourceMappingURL=exec.native.js.map