buninu 0.1.1 → 0.1.2
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/bin/bun.bat +37 -0
- package/bin/glow.bat +3 -0
- package/bin/init.js +51 -2
- package/bin/jmi.bat +3 -0
- package/bin/jsgotty.bat +3 -0
- package/bin/jsmdcui.bat +3 -0
- package/package.json +1 -1
package/bin/bun.bat
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
@echo off
|
|
2
|
+
setlocal EnableExtensions EnableDelayedExpansion
|
|
3
|
+
|
|
4
|
+
set "BUNINU_BUN_ARCHIVE=%~dp0..\apps\bun\bunBin.tgz"
|
|
5
|
+
set "BUNINU_BUN_WX=%~dp0bun-wx.exe"
|
|
6
|
+
set "BUNINU_EXTRACT_BUN="
|
|
7
|
+
|
|
8
|
+
if exist "%BUNINU_BUN_ARCHIVE%" (
|
|
9
|
+
if not exist "%BUNINU_BUN_WX%" set "BUNINU_EXTRACT_BUN=1"
|
|
10
|
+
|
|
11
|
+
if exist "%BUNINU_BUN_WX%" if exist "%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" (
|
|
12
|
+
for /f "delims=" %%U in ('"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -Command "if ((Get-Item -LiteralPath $env:BUNINU_BUN_ARCHIVE).LastWriteTimeUtc -gt (Get-Item -LiteralPath $env:BUNINU_BUN_WX).LastWriteTimeUtc) { '1' }"') do set "BUNINU_EXTRACT_BUN=%%U"
|
|
13
|
+
)
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
if defined BUNINU_EXTRACT_BUN (
|
|
17
|
+
tar -xzf "%BUNINU_BUN_ARCHIVE%" -C "%~dp0"
|
|
18
|
+
if errorlevel 1 (
|
|
19
|
+
echo Failed to extract Bun archive: %BUNINU_BUN_ARCHIVE% 1>&2
|
|
20
|
+
exit /b 1
|
|
21
|
+
)
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
if exist "%~dp0bun-wx.exe" (
|
|
25
|
+
"%~dp0bun-wx.exe" %*
|
|
26
|
+
exit /b !ERRORLEVEL!
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
for /f "delims=" %%B in ('where bun.exe 2^>nul') do (
|
|
30
|
+
if /I not "%%~dpB"=="%~dp0" (
|
|
31
|
+
"%%~fB" %*
|
|
32
|
+
exit /b !ERRORLEVEL!
|
|
33
|
+
)
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
echo Bun Binary not found: %~dp0bun-wx.exe ^(and no external bun.exe found in PATH^) 1>&2
|
|
37
|
+
exit /b 127
|
package/bin/glow.bat
ADDED
package/bin/init.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
|
|
3
3
|
import pkg from "../package.json" with { type: "json" };
|
|
4
|
-
import { existsSync, mkdirSync } from "node:fs";
|
|
4
|
+
import { existsSync, lstatSync, mkdirSync, symlinkSync, unlinkSync } from "node:fs";
|
|
5
5
|
import { tmpdir as systemTmpDir } from "node:os";
|
|
6
6
|
import { basename, delimiter, dirname, isAbsolute, resolve } from "node:path";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
@@ -109,7 +109,8 @@ async function findCommand(command) {
|
|
|
109
109
|
|
|
110
110
|
async function detectEnvironment() {
|
|
111
111
|
const windows = process.platform === "win32" || Boolean(process.env.WINDIR);
|
|
112
|
-
const
|
|
112
|
+
const termux = !windows && await pathExists("/data/data/com.termux");
|
|
113
|
+
const android = !windows && !termux && (
|
|
113
114
|
process.platform === "android" ||
|
|
114
115
|
await pathExists("/system/bin/linker64") ||
|
|
115
116
|
Boolean(process.env.ANDROID_ROOT && process.env.ANDROID_DATA)
|
|
@@ -127,6 +128,17 @@ async function detectEnvironment() {
|
|
|
127
128
|
};
|
|
128
129
|
}
|
|
129
130
|
|
|
131
|
+
if (termux) {
|
|
132
|
+
return {
|
|
133
|
+
name: "linux",
|
|
134
|
+
shell:
|
|
135
|
+
await findCommand(process.env.SHELL) ||
|
|
136
|
+
Bun.which("bash") ||
|
|
137
|
+
Bun.which("sh") ||
|
|
138
|
+
"/bin/sh",
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
130
142
|
if (android) {
|
|
131
143
|
return {
|
|
132
144
|
name: "android",
|
|
@@ -200,6 +212,42 @@ async function runPlatformSwitch(environment) {
|
|
|
200
212
|
}
|
|
201
213
|
}
|
|
202
214
|
|
|
215
|
+
function rebuildNativeSymlinks(environment) {
|
|
216
|
+
if (environment.name === "windows") return;
|
|
217
|
+
|
|
218
|
+
const platformLinks = environment.name === "android"
|
|
219
|
+
? {
|
|
220
|
+
bun: "androidNativeLibs/libbun.so",
|
|
221
|
+
shloader: "androidNativeLibs/libsh-loader.so",
|
|
222
|
+
}
|
|
223
|
+
: {
|
|
224
|
+
bun: "bun.sh",
|
|
225
|
+
shloader: "multicall.sh",
|
|
226
|
+
};
|
|
227
|
+
const links = {
|
|
228
|
+
...platformLinks,
|
|
229
|
+
glow: "shloader",
|
|
230
|
+
jmi: "shloader",
|
|
231
|
+
jsgotty: "shloader",
|
|
232
|
+
jsmdcui: "shloader",
|
|
233
|
+
"musl-la": "shloader",
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
for (const [name, target] of Object.entries(links)) {
|
|
237
|
+
const linkPath = resolve(binDir, name);
|
|
238
|
+
try {
|
|
239
|
+
const existing = lstatSync(linkPath);
|
|
240
|
+
if (!existing.isSymbolicLink()) {
|
|
241
|
+
fail(`cannot rebuild symlink over non-symlink: ${linkPath}`);
|
|
242
|
+
}
|
|
243
|
+
unlinkSync(linkPath);
|
|
244
|
+
} catch (error) {
|
|
245
|
+
if (error?.code !== "ENOENT") throw error;
|
|
246
|
+
}
|
|
247
|
+
symlinkSync(target, linkPath);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
203
251
|
function getFreePort() {
|
|
204
252
|
const listener = Bun.listen({
|
|
205
253
|
hostname: "127.0.0.1",
|
|
@@ -332,6 +380,7 @@ if (command[0] === "bun") command[0] = process.execPath;
|
|
|
332
380
|
|
|
333
381
|
const environment = await detectEnvironment();
|
|
334
382
|
await runPlatformSwitch(environment);
|
|
383
|
+
rebuildNativeSymlinks(environment);
|
|
335
384
|
const initArguments = readInitArguments(process.argv.slice(2));
|
|
336
385
|
const configuredShell =
|
|
337
386
|
pkg.buninu?.shell?.[environment.name] ??
|
package/bin/jmi.bat
ADDED
package/bin/jsgotty.bat
ADDED
package/bin/jsmdcui.bat
ADDED
package/package.json
CHANGED