@visulima/cerebro 3.0.0-alpha.6 → 3.0.0-alpha.8

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.
@@ -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 };