@visulima/cerebro 2.1.5 → 3.0.0-alpha.10
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/CHANGELOG.md +228 -0
- package/LICENSE.md +1810 -98
- package/README.md +28 -21
- package/dist/cli.d.ts +22 -0
- package/dist/commands/completion-command.js +204 -5
- package/dist/commands/help-command.js +200 -1
- package/dist/commands/readme-command.js +326 -32
- package/dist/commands/version-command.js +18 -1
- package/dist/default-env.d.ts +1 -1
- package/dist/index.js +7 -1
- package/dist/logger/create-pail-logger.js +34 -1
- package/dist/packem_chunks/has-new-version.js +264 -1
- package/dist/packem_shared/Cerebro-bgCm5Tb1.js +3444 -0
- package/dist/packem_shared/VERBOSITY_QUIET-Dp46zlLW.js +10 -0
- package/dist/packem_shared/VisulimaError-DA7QsCxH.js +34 -0
- package/dist/packem_shared/cerebro-error-GmJ3jN7Q.js +16 -0
- package/dist/packem_shared/index-CS31xKFe.js +264 -0
- package/dist/packem_shared/runtime-process-B6ZplyWn.js +187 -0
- package/dist/plugins/error-handler-plugin.js +648 -1
- package/dist/plugins/runtime-version-check-plugin.js +77 -1
- package/dist/plugins/update-notifier/update-notifier-plugin.js +517 -1
- package/dist/types/cli.d.ts +11 -0
- package/dist/types/command-line-usage.d.ts +1 -1
- package/dist/types/command.d.ts +10 -10
- package/dist/util/command-processing/option-processor.d.ts +8 -8
- package/dist/util/general/compile-cache.d.ts +41 -0
- package/dist/util/general/compile-cache.js +16 -0
- package/dist/util/general/heap-tuning.d.ts +81 -0
- package/dist/util/general/heap-tuning.js +91 -0
- package/dist/util/general/register-exception-handler.d.ts +1 -1
- package/dist/util/process-env-variables.d.ts +1 -1
- package/package.json +18 -9
- package/dist/packem_shared/Cerebro-CQZ9sj4S.js +0 -4
- package/dist/packem_shared/VERBOSITY_QUIET-XPultrIA.js +0 -1
- package/dist/packem_shared/VisulimaError--04oA1Oy.js +0 -76
- package/dist/packem_shared/cerebro-error-BnJTixb2.js +0 -1
- package/dist/packem_shared/help-command-CIRIXN03.js +0 -1
- package/dist/packem_shared/index-DQ3pvLQH.js +0 -6
- package/dist/packem_shared/isVisulimaError-jVZgumOU-C4fgdbWg.js +0 -1
- package/dist/packem_shared/renderError-ZMlMvw1N-eVUSdl6c.js +0 -24
- package/dist/packem_shared/runtime-process-G-n-wOub.js +0 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const OUTPUT_NORMAL = 1;
|
|
2
|
+
const OUTPUT_RAW = 2;
|
|
3
|
+
const OUTPUT_PLAIN = 4;
|
|
4
|
+
const VERBOSITY_QUIET = 16;
|
|
5
|
+
const VERBOSITY_NORMAL = 32;
|
|
6
|
+
const VERBOSITY_VERBOSE = 64;
|
|
7
|
+
const VERBOSITY_DEBUG = 128;
|
|
8
|
+
const POSITIONALS_KEY = "positionals";
|
|
9
|
+
|
|
10
|
+
export { OUTPUT_NORMAL, OUTPUT_PLAIN, OUTPUT_RAW, POSITIONALS_KEY, VERBOSITY_DEBUG, VERBOSITY_NORMAL, VERBOSITY_QUIET, VERBOSITY_VERBOSE };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const isVisulimaError = (error) => error instanceof Error && error.type === "VisulimaError";
|
|
2
|
+
class VisulimaError extends Error {
|
|
3
|
+
loc;
|
|
4
|
+
title;
|
|
5
|
+
/**
|
|
6
|
+
* A message that explains to the user how they can fix the error.
|
|
7
|
+
*/
|
|
8
|
+
hint;
|
|
9
|
+
type = "VisulimaError";
|
|
10
|
+
constructor({ cause, hint, location, message, name, stack, title }) {
|
|
11
|
+
super(message, {
|
|
12
|
+
cause
|
|
13
|
+
});
|
|
14
|
+
this.title = title;
|
|
15
|
+
this.name = name;
|
|
16
|
+
this.stack = stack ?? this.stack;
|
|
17
|
+
this.loc = location;
|
|
18
|
+
this.hint = hint;
|
|
19
|
+
}
|
|
20
|
+
setLocation(location) {
|
|
21
|
+
this.loc = location;
|
|
22
|
+
}
|
|
23
|
+
setName(name) {
|
|
24
|
+
this.name = name;
|
|
25
|
+
}
|
|
26
|
+
setMessage(message) {
|
|
27
|
+
this.message = message;
|
|
28
|
+
}
|
|
29
|
+
setHint(hint) {
|
|
30
|
+
this.hint = hint;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { VisulimaError, isVisulimaError };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { VisulimaError } from './VisulimaError-DA7QsCxH.js';
|
|
2
|
+
|
|
3
|
+
class CerebroError extends VisulimaError {
|
|
4
|
+
code;
|
|
5
|
+
context;
|
|
6
|
+
constructor(message, code, context) {
|
|
7
|
+
super({
|
|
8
|
+
message,
|
|
9
|
+
name: "CerebroError"
|
|
10
|
+
});
|
|
11
|
+
this.code = code;
|
|
12
|
+
this.context = context;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { CerebroError as C };
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import { createRequire as __cjs_createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
4
|
+
|
|
5
|
+
const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
|
|
6
|
+
|
|
7
|
+
const __cjs_getBuiltinModule = (module) => {
|
|
8
|
+
// Check if we're in Node.js and version supports getBuiltinModule
|
|
9
|
+
if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
|
|
10
|
+
const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
|
|
11
|
+
// Node.js 20.16.0+ and 22.3.0+
|
|
12
|
+
if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
|
|
13
|
+
return __cjs_getProcess.getBuiltinModule(module);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
// Fallback to createRequire
|
|
17
|
+
return __cjs_require(module);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
import { createTable } from '@visulima/tabular';
|
|
21
|
+
import { NO_BORDER } from '@visulima/tabular/style';
|
|
22
|
+
import colorizeTemplate from '@visulima/colorize/template';
|
|
23
|
+
import { d as getEnv } from './runtime-process-B6ZplyWn.js';
|
|
24
|
+
const os = __cjs_getBuiltinModule("node:os");
|
|
25
|
+
import { bold } from '@visulima/colorize';
|
|
26
|
+
|
|
27
|
+
const formatCache = /* @__PURE__ */ new Map();
|
|
28
|
+
const MAX_CACHE_SIZE = 500;
|
|
29
|
+
const templateFormat = (string_) => {
|
|
30
|
+
if (!string_) {
|
|
31
|
+
return "";
|
|
32
|
+
}
|
|
33
|
+
if (string_ === "") {
|
|
34
|
+
return "";
|
|
35
|
+
}
|
|
36
|
+
const cached = formatCache.get(string_);
|
|
37
|
+
if (cached !== void 0) {
|
|
38
|
+
return cached;
|
|
39
|
+
}
|
|
40
|
+
const result = colorizeTemplate(Object.assign([], { raw: [string_] }));
|
|
41
|
+
if (formatCache.size >= MAX_CACHE_SIZE) {
|
|
42
|
+
const firstKey = formatCache.keys().next().value;
|
|
43
|
+
if (firstKey !== void 0) {
|
|
44
|
+
formatCache.delete(firstKey);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
formatCache.set(string_, result);
|
|
48
|
+
return result;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const getTerminalWidth = () => {
|
|
52
|
+
const env = getEnv();
|
|
53
|
+
const terminalWidth = env.CEREBRO_TERMINAL_WIDTH;
|
|
54
|
+
if (terminalWidth === void 0) {
|
|
55
|
+
return void 0;
|
|
56
|
+
}
|
|
57
|
+
const parsed = Number.parseInt(terminalWidth, 10);
|
|
58
|
+
if (Number.isNaN(parsed) || parsed <= 0) {
|
|
59
|
+
return void 0;
|
|
60
|
+
}
|
|
61
|
+
return parsed;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
class BaseSection {
|
|
65
|
+
lines;
|
|
66
|
+
constructor() {
|
|
67
|
+
this.lines = [];
|
|
68
|
+
}
|
|
69
|
+
add(line) {
|
|
70
|
+
this.lines.push(line);
|
|
71
|
+
}
|
|
72
|
+
toString() {
|
|
73
|
+
return this.lines.join(os.EOL);
|
|
74
|
+
}
|
|
75
|
+
header(text) {
|
|
76
|
+
this.add(bold(text));
|
|
77
|
+
this.lines.push("");
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
class ContentSection extends BaseSection {
|
|
82
|
+
constructor(section) {
|
|
83
|
+
super();
|
|
84
|
+
if (section.header) {
|
|
85
|
+
this.header(templateFormat(section.header));
|
|
86
|
+
}
|
|
87
|
+
if (section.content) {
|
|
88
|
+
if (section.raw) {
|
|
89
|
+
if (Array.isArray(section.content) && section.content.every((value) => typeof value === "string")) {
|
|
90
|
+
section.content.forEach((row) => {
|
|
91
|
+
if (Array.isArray(row)) {
|
|
92
|
+
row.forEach((cell) => {
|
|
93
|
+
this.add(templateFormat(cell));
|
|
94
|
+
});
|
|
95
|
+
} else {
|
|
96
|
+
this.add(templateFormat(row));
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
} else if (typeof section.content === "string") {
|
|
100
|
+
this.add(templateFormat(section.content));
|
|
101
|
+
} else {
|
|
102
|
+
throw new TypeError("Invalid raw content, must be a string or array of strings.");
|
|
103
|
+
}
|
|
104
|
+
} else {
|
|
105
|
+
this.add(this.getContentLines(section.content));
|
|
106
|
+
}
|
|
107
|
+
this.add("");
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
// eslint-disable-next-line class-methods-use-this
|
|
111
|
+
getContentLines(content) {
|
|
112
|
+
if (typeof content === "string") {
|
|
113
|
+
const table = createTable({
|
|
114
|
+
showHeader: false,
|
|
115
|
+
style: {
|
|
116
|
+
border: NO_BORDER,
|
|
117
|
+
paddingLeft: 4,
|
|
118
|
+
paddingRight: 1
|
|
119
|
+
},
|
|
120
|
+
terminalWidth: getTerminalWidth(),
|
|
121
|
+
truncateOverflow: false,
|
|
122
|
+
wordWrap: true
|
|
123
|
+
});
|
|
124
|
+
table.addRow([templateFormat(content)]);
|
|
125
|
+
return table.toString();
|
|
126
|
+
}
|
|
127
|
+
if (Array.isArray(content) && content.every((value) => typeof value === "string" || Array.isArray(value) && value.every((value2) => typeof value2 === "string"))) {
|
|
128
|
+
const table = createTable({
|
|
129
|
+
showHeader: false,
|
|
130
|
+
style: {
|
|
131
|
+
border: NO_BORDER,
|
|
132
|
+
paddingLeft: 4,
|
|
133
|
+
paddingRight: 1
|
|
134
|
+
},
|
|
135
|
+
terminalWidth: getTerminalWidth(),
|
|
136
|
+
truncateOverflow: false,
|
|
137
|
+
wordWrap: true
|
|
138
|
+
});
|
|
139
|
+
content.forEach((row) => {
|
|
140
|
+
if (Array.isArray(row)) {
|
|
141
|
+
table.addRow(row.map((cell) => templateFormat(cell)));
|
|
142
|
+
} else {
|
|
143
|
+
table.addRow([templateFormat(row)]);
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
return table.toString();
|
|
147
|
+
}
|
|
148
|
+
if (typeof content === "object") {
|
|
149
|
+
const contentObject = content;
|
|
150
|
+
if (!contentObject.options || !contentObject.data) {
|
|
151
|
+
throw new Error(`Must have an "options" or "data" property
|
|
152
|
+
${JSON.stringify(content)}`);
|
|
153
|
+
}
|
|
154
|
+
const table = createTable({
|
|
155
|
+
showHeader: false,
|
|
156
|
+
style: {
|
|
157
|
+
border: NO_BORDER,
|
|
158
|
+
paddingLeft: 4,
|
|
159
|
+
paddingRight: 1
|
|
160
|
+
},
|
|
161
|
+
terminalWidth: getTerminalWidth(),
|
|
162
|
+
truncateOverflow: false,
|
|
163
|
+
wordWrap: true
|
|
164
|
+
});
|
|
165
|
+
contentObject.data.forEach((row) => {
|
|
166
|
+
if (Array.isArray(row)) {
|
|
167
|
+
table.addRow(row.map((cell) => templateFormat(cell)));
|
|
168
|
+
} else {
|
|
169
|
+
table.addRow([templateFormat(row)]);
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
return table.toString();
|
|
173
|
+
}
|
|
174
|
+
throw new Error(`invalid input - 'content' must be a string, array of strings or a object:
|
|
175
|
+
|
|
176
|
+
${JSON.stringify(content)}`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
class OptionListSection extends BaseSection {
|
|
181
|
+
constructor(data) {
|
|
182
|
+
super();
|
|
183
|
+
let definitions = data.optionList ?? [];
|
|
184
|
+
const hide = Array.isArray(data.hide) ? data.hide : [data.hide].filter((item) => typeof item === "string");
|
|
185
|
+
const groups = Array.isArray(data.group) ? data.group : [data.group].filter((item) => typeof item === "string");
|
|
186
|
+
if (hide.length > 0) {
|
|
187
|
+
definitions = definitions.filter((definition) => !hide.includes(definition.name));
|
|
188
|
+
}
|
|
189
|
+
if (data.header) {
|
|
190
|
+
this.header(templateFormat(data.header));
|
|
191
|
+
}
|
|
192
|
+
if (groups.length > 0) {
|
|
193
|
+
definitions = definitions.filter((definition) => {
|
|
194
|
+
const typedDefinition = definition;
|
|
195
|
+
const noGroupMatch = groups.includes("_none") && !typedDefinition.group;
|
|
196
|
+
const definitionGroup = typedDefinition.group;
|
|
197
|
+
const groupMatch = this.intersect(Array.isArray(definitionGroup) ? definitionGroup : [definitionGroup], groups);
|
|
198
|
+
return noGroupMatch || groupMatch ? definition : void 0;
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
const table = createTable({
|
|
202
|
+
showHeader: false,
|
|
203
|
+
style: {
|
|
204
|
+
border: NO_BORDER,
|
|
205
|
+
paddingLeft: 2,
|
|
206
|
+
paddingRight: 1,
|
|
207
|
+
...data.tableOptions?.style
|
|
208
|
+
},
|
|
209
|
+
terminalWidth: getTerminalWidth() ?? data.tableOptions?.terminalWidth,
|
|
210
|
+
truncateOverflow: false,
|
|
211
|
+
wordWrap: data.tableOptions?.wordWrap ?? true,
|
|
212
|
+
...data.tableOptions
|
|
213
|
+
});
|
|
214
|
+
definitions.forEach((definition) => {
|
|
215
|
+
const typedDefinition = definition;
|
|
216
|
+
table.addRow([this.getOptionNames(typedDefinition, data.reverseNameOrder ?? false, data.isArgument ?? false), templateFormat(typedDefinition.description)]);
|
|
217
|
+
});
|
|
218
|
+
this.add(table.toString());
|
|
219
|
+
this.lines.push("");
|
|
220
|
+
}
|
|
221
|
+
// eslint-disable-next-line class-methods-use-this,sonarjs/cognitive-complexity,@typescript-eslint/no-explicit-any
|
|
222
|
+
getOptionNames(definition, reverseNameOrder, isArgument) {
|
|
223
|
+
if (!definition.name) {
|
|
224
|
+
throw new TypeError("Invalid option definition, name is required.");
|
|
225
|
+
}
|
|
226
|
+
let type = definition.type ? definition.type.name.toLowerCase() : "string";
|
|
227
|
+
const multiple = definition.multiple || definition.lazyMultiple ? "[]" : "";
|
|
228
|
+
type = templateFormat(definition.typeLabel ?? `{underline ${type}${multiple}}`);
|
|
229
|
+
let result;
|
|
230
|
+
if (definition.alias) {
|
|
231
|
+
if (definition.name) {
|
|
232
|
+
const name = isArgument ? definition.name : `{yellow --${definition.name}}`;
|
|
233
|
+
result = reverseNameOrder ? templateFormat(`{bold ${name}}, {bold -${definition.alias}} ${type}`) : templateFormat(`{bold -${definition.alias}}, {bold ${name}} ${type}`);
|
|
234
|
+
} else if (reverseNameOrder) {
|
|
235
|
+
result = templateFormat(`{bold -${definition.alias}} ${type}`);
|
|
236
|
+
} else {
|
|
237
|
+
result = templateFormat(`{bold -${definition.alias}} ${type}`);
|
|
238
|
+
}
|
|
239
|
+
} else {
|
|
240
|
+
result = templateFormat(`{bold ${isArgument ? definition.name : `{yellow --${definition.name}}`}} ${type}`);
|
|
241
|
+
}
|
|
242
|
+
return result;
|
|
243
|
+
}
|
|
244
|
+
// eslint-disable-next-line class-methods-use-this
|
|
245
|
+
intersect(array1, array2) {
|
|
246
|
+
return array1.some((item1) => array2.includes(item1));
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const commandLineUsage = (sections) => {
|
|
251
|
+
const lines = Array.isArray(sections) ? sections : [sections];
|
|
252
|
+
if (lines.length === 0) {
|
|
253
|
+
return "";
|
|
254
|
+
}
|
|
255
|
+
return `
|
|
256
|
+
${sections.map((section) => {
|
|
257
|
+
if (section.optionList) {
|
|
258
|
+
return new OptionListSection(section).toString();
|
|
259
|
+
}
|
|
260
|
+
return new ContentSection(section).toString();
|
|
261
|
+
}).join("\n")}`;
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
export { commandLineUsage as c, templateFormat as t };
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
const hasDeno = (global) => "Deno" in global;
|
|
2
|
+
const hasBun = (global) => "Bun" in global;
|
|
3
|
+
const getArgv = () => {
|
|
4
|
+
if (hasDeno(globalThis)) {
|
|
5
|
+
const deno = globalThis.Deno;
|
|
6
|
+
const execPath = deno.execPath();
|
|
7
|
+
let scriptPath = execPath;
|
|
8
|
+
try {
|
|
9
|
+
const { importMeta } = globalThis;
|
|
10
|
+
if (importMeta?.url) {
|
|
11
|
+
scriptPath = importMeta.url;
|
|
12
|
+
}
|
|
13
|
+
} catch {
|
|
14
|
+
}
|
|
15
|
+
return [execPath, scriptPath, ...deno.args];
|
|
16
|
+
}
|
|
17
|
+
if (hasBun(globalThis)) {
|
|
18
|
+
const bun = globalThis.Bun;
|
|
19
|
+
return bun.process.argv;
|
|
20
|
+
}
|
|
21
|
+
return process.argv;
|
|
22
|
+
};
|
|
23
|
+
const getCwd = () => {
|
|
24
|
+
if (hasDeno(globalThis)) {
|
|
25
|
+
const deno = globalThis.Deno;
|
|
26
|
+
return deno.cwd();
|
|
27
|
+
}
|
|
28
|
+
if (hasBun(globalThis)) {
|
|
29
|
+
const bun = globalThis.Bun;
|
|
30
|
+
return bun.process.cwd();
|
|
31
|
+
}
|
|
32
|
+
return process.cwd();
|
|
33
|
+
};
|
|
34
|
+
const getEnv = () => {
|
|
35
|
+
if (hasDeno(globalThis)) {
|
|
36
|
+
const deno = globalThis.Deno;
|
|
37
|
+
return /* @__PURE__ */ new Proxy(deno.env.toObject(), {
|
|
38
|
+
get: (target, prop) => {
|
|
39
|
+
if (typeof prop === "string") {
|
|
40
|
+
return deno.env.get(prop);
|
|
41
|
+
}
|
|
42
|
+
return target[prop];
|
|
43
|
+
},
|
|
44
|
+
has: (target, prop) => {
|
|
45
|
+
if (typeof prop === "string") {
|
|
46
|
+
return deno.env.has(prop);
|
|
47
|
+
}
|
|
48
|
+
return prop in target;
|
|
49
|
+
},
|
|
50
|
+
set: (_target, prop, value) => {
|
|
51
|
+
if (typeof prop === "string") {
|
|
52
|
+
if (value === void 0) {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
deno.env.set(prop, value);
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
if (hasBun(globalThis)) {
|
|
63
|
+
const bun = globalThis.Bun;
|
|
64
|
+
return bun.process.env;
|
|
65
|
+
}
|
|
66
|
+
return process.env;
|
|
67
|
+
};
|
|
68
|
+
const getExecArgv = () => {
|
|
69
|
+
if (hasDeno(globalThis)) {
|
|
70
|
+
return [];
|
|
71
|
+
}
|
|
72
|
+
if (hasBun(globalThis)) {
|
|
73
|
+
const bun = globalThis.Bun;
|
|
74
|
+
return bun.process.execArgv;
|
|
75
|
+
}
|
|
76
|
+
return process.execArgv;
|
|
77
|
+
};
|
|
78
|
+
const getExecPath = () => {
|
|
79
|
+
if (hasDeno(globalThis)) {
|
|
80
|
+
const deno = globalThis.Deno;
|
|
81
|
+
return deno.execPath();
|
|
82
|
+
}
|
|
83
|
+
if (hasBun(globalThis)) {
|
|
84
|
+
const bun = globalThis.Bun;
|
|
85
|
+
return bun.process.execPath;
|
|
86
|
+
}
|
|
87
|
+
return process.execPath;
|
|
88
|
+
};
|
|
89
|
+
const getPlatform = () => {
|
|
90
|
+
if (hasDeno(globalThis)) {
|
|
91
|
+
const deno = globalThis.Deno;
|
|
92
|
+
const os = deno.build?.os ?? "unknown";
|
|
93
|
+
return os === "windows" ? "win32" : os;
|
|
94
|
+
}
|
|
95
|
+
if (hasBun(globalThis)) {
|
|
96
|
+
const bun = globalThis.Bun;
|
|
97
|
+
return bun.platform ?? "unknown";
|
|
98
|
+
}
|
|
99
|
+
return process.platform;
|
|
100
|
+
};
|
|
101
|
+
const getArch = () => {
|
|
102
|
+
if (hasDeno(globalThis)) {
|
|
103
|
+
const deno = globalThis.Deno;
|
|
104
|
+
const arch = deno.build?.arch ?? "unknown";
|
|
105
|
+
if (arch === "x86_64") {
|
|
106
|
+
return "x64";
|
|
107
|
+
}
|
|
108
|
+
if (arch === "aarch64") {
|
|
109
|
+
return "arm64";
|
|
110
|
+
}
|
|
111
|
+
return arch;
|
|
112
|
+
}
|
|
113
|
+
if (hasBun(globalThis)) {
|
|
114
|
+
const bun = globalThis.Bun;
|
|
115
|
+
return bun.process.arch;
|
|
116
|
+
}
|
|
117
|
+
return process.arch;
|
|
118
|
+
};
|
|
119
|
+
const getVersions = () => {
|
|
120
|
+
if (hasDeno(globalThis)) {
|
|
121
|
+
const deno = globalThis.Deno;
|
|
122
|
+
const versions = {};
|
|
123
|
+
if (deno.version?.deno) {
|
|
124
|
+
versions.deno = deno.version.deno;
|
|
125
|
+
}
|
|
126
|
+
if (deno.version?.v8) {
|
|
127
|
+
versions.v8 = deno.version.v8;
|
|
128
|
+
}
|
|
129
|
+
if (deno.version?.typescript) {
|
|
130
|
+
versions.typescript = deno.version.typescript;
|
|
131
|
+
}
|
|
132
|
+
return versions;
|
|
133
|
+
}
|
|
134
|
+
if (hasBun(globalThis)) {
|
|
135
|
+
const bun = globalThis.Bun;
|
|
136
|
+
const versions = { ...bun.process.versions };
|
|
137
|
+
if (bun.version) {
|
|
138
|
+
versions.bun = bun.version;
|
|
139
|
+
}
|
|
140
|
+
return versions;
|
|
141
|
+
}
|
|
142
|
+
return process.versions;
|
|
143
|
+
};
|
|
144
|
+
const exitProcess = (exitCode = 0) => {
|
|
145
|
+
if (hasDeno(globalThis)) {
|
|
146
|
+
const deno = globalThis.Deno;
|
|
147
|
+
deno.exit(exitCode);
|
|
148
|
+
throw new Error("Deno exit failed");
|
|
149
|
+
}
|
|
150
|
+
if (hasBun(globalThis)) {
|
|
151
|
+
const bun = globalThis.Bun;
|
|
152
|
+
bun.process.exit(exitCode);
|
|
153
|
+
throw new Error("Bun exit failed");
|
|
154
|
+
}
|
|
155
|
+
const nodeProcess = process;
|
|
156
|
+
nodeProcess.exit(exitCode);
|
|
157
|
+
return void 0;
|
|
158
|
+
};
|
|
159
|
+
const onProcessEvent = (event, handler) => {
|
|
160
|
+
if (hasDeno(globalThis)) {
|
|
161
|
+
return () => {
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
if (hasBun(globalThis)) {
|
|
165
|
+
try {
|
|
166
|
+
const bun = globalThis.Bun;
|
|
167
|
+
if (bun.process?.on) {
|
|
168
|
+
bun.process.on(event, handler);
|
|
169
|
+
return () => {
|
|
170
|
+
if (bun.process?.removeListener) {
|
|
171
|
+
bun.process.removeListener(event, handler);
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
} catch {
|
|
176
|
+
}
|
|
177
|
+
return () => {
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
const nodeProcess = process;
|
|
181
|
+
nodeProcess.on(event, handler);
|
|
182
|
+
return () => {
|
|
183
|
+
nodeProcess.removeListener(event, handler);
|
|
184
|
+
};
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
export { getVersions as a, getPlatform as b, getArch as c, getEnv as d, exitProcess as e, getArgv as f, getCwd as g, getExecPath as h, getExecArgv as i, onProcessEvent as o };
|