brsh 3.10.3 → 3.10.4
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 +7 -0
- package/dist/wbt.es.js +38 -8
- package/dist/wbt.es.js.map +1 -1
- package/dist/wbt.min.js +18 -4
- package/dist/wbt.min.js.map +1 -1
- package/lib/wbt/index.js +21 -9
- package/lib/wbt/registry.js +18 -1
- package/package.json +1 -1
- package/test/wbt.test.js +82 -4
package/lib/wbt/index.js
CHANGED
|
@@ -6,6 +6,9 @@ const WasmCommand = require('../WasmCommand');
|
|
|
6
6
|
const ReplCommand = require('../ReplCommand');
|
|
7
7
|
const { DEFAULT_REGISTRY, resolvePackageName } = require('./registry');
|
|
8
8
|
const wllamaAdapter = require('./packages/wllama');
|
|
9
|
+
if (typeof globalThis !== 'undefined') {
|
|
10
|
+
globalThis.__brshWllamaAdapter = wllamaAdapter;
|
|
11
|
+
}
|
|
9
12
|
const { writeBytesToFs, createGenericWasmCommand } = WasmCommand;
|
|
10
13
|
const { createReplWasmCommand } = ReplCommand;
|
|
11
14
|
|
|
@@ -23,7 +26,7 @@ function createCustomWasmBinCommand(binName, wasmPath, pkgMeta = {}) {
|
|
|
23
26
|
const isHelpOrVersion = (this.arguments || []).some(a => a === '--help' || a === '-h' || a === '--version' || a === '-V' || a === '-v');
|
|
24
27
|
if (isHelpOrVersion) return false;
|
|
25
28
|
if (this._isInteractive !== undefined) return Boolean(this._isInteractive);
|
|
26
|
-
return Boolean(pkgMeta.interactive || binName === 'nano');
|
|
29
|
+
return Boolean(pkgMeta.interactive || binName === 'nano' || binName === 'pico' || binName === 'vim' || binName === 'vi');
|
|
27
30
|
}
|
|
28
31
|
|
|
29
32
|
get captureInput() {
|
|
@@ -258,18 +261,27 @@ class Wbt extends Command {
|
|
|
258
261
|
|
|
259
262
|
_generateJsCommandSource(pkgMeta, binName) {
|
|
260
263
|
if (pkgMeta.adapter === 'wllama' || pkgMeta.name === 'wllama') {
|
|
261
|
-
const wllamaPath =
|
|
264
|
+
const wllamaPath = typeof __dirname !== 'undefined'
|
|
265
|
+
? path.resolve(__dirname, 'packages/wllama.js')
|
|
266
|
+
: null;
|
|
262
267
|
return `'use strict';\n` +
|
|
263
268
|
`let wllamaModule;\n` +
|
|
264
|
-
`
|
|
265
|
-
` wllamaModule = require(${JSON.stringify(wllamaPath)});\n` +
|
|
266
|
-
`
|
|
267
|
-
`
|
|
268
|
-
`
|
|
269
|
-
`
|
|
270
|
-
`
|
|
269
|
+
`if (typeof require === 'function') {\n` +
|
|
270
|
+
(wllamaPath ? ` try {\n wllamaModule = require(${JSON.stringify(wllamaPath)});\n } catch (_) {}\n` : '') +
|
|
271
|
+
` if (!wllamaModule) {\n` +
|
|
272
|
+
` try {\n` +
|
|
273
|
+
` wllamaModule = require('brsh/wbt/packages/wllama');\n` +
|
|
274
|
+
` } catch (_) {\n` +
|
|
275
|
+
` try { wllamaModule = require('./wllama'); } catch (e) {}\n` +
|
|
276
|
+
` }\n` +
|
|
271
277
|
` }\n` +
|
|
272
278
|
`}\n` +
|
|
279
|
+
`if (!wllamaModule && typeof globalThis !== 'undefined') {\n` +
|
|
280
|
+
` wllamaModule = globalThis.__brshWllamaAdapter;\n` +
|
|
281
|
+
`}\n` +
|
|
282
|
+
`if (!wllamaModule) {\n` +
|
|
283
|
+
` throw new Error('Unable to load wllama adapter module');\n` +
|
|
284
|
+
`}\n` +
|
|
273
285
|
`module.exports = wllamaModule.createWllamaCommand(${JSON.stringify(pkgMeta)}, {}, ${JSON.stringify(binName)});\n`;
|
|
274
286
|
}
|
|
275
287
|
|
package/lib/wbt/registry.js
CHANGED
|
@@ -170,7 +170,7 @@ const DEFAULT_REGISTRY = {
|
|
|
170
170
|
nano: {
|
|
171
171
|
name: 'nano',
|
|
172
172
|
bin: 'nano',
|
|
173
|
-
aliases: ['nano-wasm'],
|
|
173
|
+
aliases: ['nano-wasm', 'pico'],
|
|
174
174
|
version: '8.0.1',
|
|
175
175
|
description: 'GNU nano 8.0 text editor compiled to WebAssembly (wasm32-wasip1) with ncurses',
|
|
176
176
|
details: 'GNU nano is a small, user-friendly command-line text editor compiled to WebAssembly with wide-character ncurses 6.5, built-in terminfo fallbacks (xterm-256color, vt100, etc.), dynamic terminal dimensions (TIOCGWINSZ / LINES & COLUMNS), and zero custom imports (standard wasi_snapshot_preview1).',
|
|
@@ -181,6 +181,20 @@ const DEFAULT_REGISTRY = {
|
|
|
181
181
|
interactive: true,
|
|
182
182
|
size: '680 KB'
|
|
183
183
|
},
|
|
184
|
+
vim: {
|
|
185
|
+
name: 'vim',
|
|
186
|
+
bin: 'vim',
|
|
187
|
+
aliases: ['vi', 'vim-wasm'],
|
|
188
|
+
version: '9.1.0700',
|
|
189
|
+
description: 'Vim 9.1 text editor compiled to WebAssembly (wasm32-wasip1) with ncurses',
|
|
190
|
+
details: 'Vim 9.1 (9.1.0700) compiled to WebAssembly (wasm32-wasip1) with static ncursesw 6.5, built-in terminfo fallbacks (xterm-256color, vt100, etc.), Asyncify interactive I/O, built-in defaults.vim fallback, and zero custom imports (standard wasi_snapshot_preview1).',
|
|
191
|
+
homepage: 'https://github.com/eliotstocker/vim-wasm',
|
|
192
|
+
cdnUrl: 'https://cdn.jsdelivr.net/gh/eliotstocker/vim-wasm@main/dist/vim.wasm',
|
|
193
|
+
wasmUrl: 'https://cdn.jsdelivr.net/gh/eliotstocker/vim-wasm@main/dist/vim.wasm',
|
|
194
|
+
type: 'custom-wasm',
|
|
195
|
+
interactive: true,
|
|
196
|
+
size: '4.5 MB'
|
|
197
|
+
},
|
|
184
198
|
doom: {
|
|
185
199
|
name: 'doom',
|
|
186
200
|
bin: 'doom',
|
|
@@ -219,6 +233,9 @@ const PACKAGE_ALIASES = {
|
|
|
219
233
|
'llama.cpp': 'wllama',
|
|
220
234
|
'@wllama/wllama': 'wllama',
|
|
221
235
|
'nano-wasm': 'nano',
|
|
236
|
+
pico: 'nano',
|
|
237
|
+
vi: 'vim',
|
|
238
|
+
'vim-wasm': 'vim',
|
|
222
239
|
'doom-wasm': 'doom',
|
|
223
240
|
'doom-ascii': 'doom',
|
|
224
241
|
freedoom: 'doom'
|
package/package.json
CHANGED
package/test/wbt.test.js
CHANGED
|
@@ -1150,6 +1150,43 @@ describe('WBT Wllama v3 WASM & WebGPU package (`wllama`, `llama`, `llama-cli`)',
|
|
|
1150
1150
|
expect(runHelpRes.output.join('\n')).toContain('Usage: wllama');
|
|
1151
1151
|
});
|
|
1152
1152
|
|
|
1153
|
+
it('installs wllama from the built ESM browser bundle without __dirname', async () => {
|
|
1154
|
+
const { default: BundledWbt } = await import('../dist/wbt.es.js');
|
|
1155
|
+
const ConfiguredBundledWbt = BundledWbt.configure({
|
|
1156
|
+
fetch: async (url) => {
|
|
1157
|
+
if (url.endsWith('.wasm')) {
|
|
1158
|
+
return {
|
|
1159
|
+
ok: true,
|
|
1160
|
+
status: 200,
|
|
1161
|
+
arrayBuffer: async () => new Uint8Array([0x00, 0x61, 0x73, 0x6d]).buffer
|
|
1162
|
+
};
|
|
1163
|
+
}
|
|
1164
|
+
throw new Error(`Unexpected fetch: ${url}`);
|
|
1165
|
+
}
|
|
1166
|
+
});
|
|
1167
|
+
|
|
1168
|
+
const browserShell = await createShell({ filesystem: { home: {} } });
|
|
1169
|
+
browserShell.context.setCommand(ConfiguredBundledWbt);
|
|
1170
|
+
|
|
1171
|
+
const installRes = await run(browserShell, 'wbt install wllama');
|
|
1172
|
+
expect(installRes.exitCode).toBe(0);
|
|
1173
|
+
expect(browserShell.context.fs.exists('/bin/wllama')).toBe(true);
|
|
1174
|
+
expect(browserShell.context.fs.exists('/bin/llama')).toBe(true);
|
|
1175
|
+
expect(browserShell.context.fs.exists('/bin/llama-cli')).toBe(true);
|
|
1176
|
+
|
|
1177
|
+
const helpRes = await run(browserShell, 'wllama --help');
|
|
1178
|
+
expect(helpRes.exitCode).toBe(0);
|
|
1179
|
+
expect(helpRes.output.join('\n')).toContain('Usage: wllama');
|
|
1180
|
+
|
|
1181
|
+
// Also verify generated __source can be evaluated without Node require() via globalThis.__brshWllamaAdapter
|
|
1182
|
+
const WllamaCmd = browserShell.context.fs.getFileByPath('/usr/lib/wllama/wllama.js');
|
|
1183
|
+
expect(typeof WllamaCmd).toBe('function');
|
|
1184
|
+
expect(typeof WllamaCmd.__source).toBe('string');
|
|
1185
|
+
const mod = { exports: {} };
|
|
1186
|
+
new Function('module', 'exports', 'require', WllamaCmd.__source)(mod, mod.exports, undefined);
|
|
1187
|
+
expect(typeof mod.exports).toBe('function');
|
|
1188
|
+
});
|
|
1189
|
+
|
|
1153
1190
|
it('runs one-shot chat completions from a local filesystem .gguf model, piped stdin, or -f file with WebGPU or --no-gpu', async () => {
|
|
1154
1191
|
const res1 = await run(
|
|
1155
1192
|
shell,
|
|
@@ -1399,19 +1436,24 @@ describe('WBT GNU nano WASM package (nano / nano-wasm)', () => {
|
|
|
1399
1436
|
expect(showRes.exitCode).toBe(0);
|
|
1400
1437
|
expect(showRes.output.join('\n')).toContain('Package: nano');
|
|
1401
1438
|
expect(showRes.output.join('\n')).toContain('Version: 8.0.1');
|
|
1402
|
-
expect(showRes.output.join('\n')).toContain('Aliases: nano-wasm');
|
|
1439
|
+
expect(showRes.output.join('\n')).toContain('Aliases: nano-wasm, pico');
|
|
1403
1440
|
|
|
1404
1441
|
const showAliasRes = await run(shell, 'wbt show nano-wasm');
|
|
1405
1442
|
expect(showAliasRes.exitCode).toBe(0);
|
|
1406
1443
|
expect(showAliasRes.output.join('\n')).toContain('Package: nano');
|
|
1444
|
+
|
|
1445
|
+
const showPicoRes = await run(shell, 'wbt show pico');
|
|
1446
|
+
expect(showPicoRes.exitCode).toBe(0);
|
|
1447
|
+
expect(showPicoRes.output.join('\n')).toContain('Package: nano');
|
|
1407
1448
|
});
|
|
1408
1449
|
|
|
1409
|
-
it('installs nano
|
|
1450
|
+
it('installs nano, nano-wasm, and pico into /bin and runs --version and --help', async () => {
|
|
1410
1451
|
const installRes = await run(shell, 'wbt install nano');
|
|
1411
1452
|
expect(installRes.exitCode).toBe(0);
|
|
1412
1453
|
expect(shell.context.fs.exists('/usr/lib/nano/nano.wasm')).toBe(true);
|
|
1413
1454
|
expect(shell.context.fs.exists('/bin/nano')).toBe(true);
|
|
1414
1455
|
expect(shell.context.fs.exists('/bin/nano-wasm')).toBe(true);
|
|
1456
|
+
expect(shell.context.fs.exists('/bin/pico')).toBe(true);
|
|
1415
1457
|
|
|
1416
1458
|
const verRes = await run(shell, 'nano --version');
|
|
1417
1459
|
expect(verRes.exitCode).toBe(0);
|
|
@@ -1424,6 +1466,10 @@ describe('WBT GNU nano WASM package (nano / nano-wasm)', () => {
|
|
|
1424
1466
|
const aliasVerRes = await run(shell, 'nano-wasm --version');
|
|
1425
1467
|
expect(aliasVerRes.exitCode).toBe(0);
|
|
1426
1468
|
expect(aliasVerRes.output.join('\n')).toMatch(/GNU nano, version 8\.0|nano.*8\.0\.[0-9]+.*wasm/i);
|
|
1469
|
+
|
|
1470
|
+
const picoVerRes = await run(shell, 'pico --version');
|
|
1471
|
+
expect(picoVerRes.exitCode).toBe(0);
|
|
1472
|
+
expect(picoVerRes.output.join('\n')).toMatch(/GNU nano, version 8\.0|nano.*8\.0\.[0-9]+.*wasm/i);
|
|
1427
1473
|
});
|
|
1428
1474
|
|
|
1429
1475
|
it('supports wbt run nano --version without permanently installing', async () => {
|
|
@@ -1433,16 +1479,18 @@ describe('WBT GNU nano WASM package (nano / nano-wasm)', () => {
|
|
|
1433
1479
|
expect(shell.context.fs.exists('/bin/nano')).toBe(false);
|
|
1434
1480
|
});
|
|
1435
1481
|
|
|
1436
|
-
it('removes nano and unregisters
|
|
1437
|
-
await run(shell, 'wbt install
|
|
1482
|
+
it('removes nano and unregisters nano, nano-wasm, and pico from /bin', async () => {
|
|
1483
|
+
await run(shell, 'wbt install pico');
|
|
1438
1484
|
expect(shell.context.fs.exists('/bin/nano')).toBe(true);
|
|
1439
1485
|
expect(shell.context.fs.exists('/bin/nano-wasm')).toBe(true);
|
|
1486
|
+
expect(shell.context.fs.exists('/bin/pico')).toBe(true);
|
|
1440
1487
|
expect(shell.context.fs.exists('/usr/lib/nano/nano.wasm')).toBe(true);
|
|
1441
1488
|
|
|
1442
1489
|
const rmRes = await run(shell, 'wbt remove nano');
|
|
1443
1490
|
expect(rmRes.exitCode).toBe(0);
|
|
1444
1491
|
expect(shell.context.fs.exists('/bin/nano')).toBe(false);
|
|
1445
1492
|
expect(shell.context.fs.exists('/bin/nano-wasm')).toBe(false);
|
|
1493
|
+
expect(shell.context.fs.exists('/bin/pico')).toBe(false);
|
|
1446
1494
|
expect(shell.context.fs.exists('/usr/lib/nano/nano.wasm')).toBe(false);
|
|
1447
1495
|
});
|
|
1448
1496
|
|
|
@@ -1677,6 +1725,36 @@ describe('WBT filesystem installer architecture (installer, not runtime)', () =>
|
|
|
1677
1725
|
expect(execRes.exitCode).toBe(0);
|
|
1678
1726
|
});
|
|
1679
1727
|
|
|
1728
|
+
it('registers vim package from eliotstocker/vim-wasm with vi and vim-wasm aliases', async () => {
|
|
1729
|
+
const searchRes = await run(shell, 'wbt search vim');
|
|
1730
|
+
expect(searchRes.exitCode).toBe(0);
|
|
1731
|
+
expect(searchRes.output.join('\n')).toContain('vim');
|
|
1732
|
+
|
|
1733
|
+
const showRes = await run(shell, 'wbt show vim');
|
|
1734
|
+
expect(showRes.exitCode).toBe(0);
|
|
1735
|
+
expect(showRes.output.join('\n')).toContain('Package: vim');
|
|
1736
|
+
expect(showRes.output.join('\n')).toContain('Version: 9.1.0700');
|
|
1737
|
+
expect(showRes.output.join('\n')).toContain('Aliases: vi, vim-wasm');
|
|
1738
|
+
|
|
1739
|
+
const showViRes = await run(shell, 'wbt show vi');
|
|
1740
|
+
expect(showViRes.exitCode).toBe(0);
|
|
1741
|
+
expect(showViRes.output.join('\n')).toContain('Package: vim');
|
|
1742
|
+
|
|
1743
|
+
const installRes = await run(shell, 'wbt install vi');
|
|
1744
|
+
expect(installRes.exitCode).toBe(0);
|
|
1745
|
+
expect(shell.context.fs.exists('/usr/lib/vim/vim.wasm')).toBe(true);
|
|
1746
|
+
expect(shell.context.fs.isSymlink('/bin/vim')).toBe(true);
|
|
1747
|
+
expect(shell.context.fs.isSymlink('/bin/vi')).toBe(true);
|
|
1748
|
+
expect(shell.context.fs.isSymlink('/bin/vim-wasm')).toBe(true);
|
|
1749
|
+
|
|
1750
|
+
const rmRes = await run(shell, 'wbt remove vim');
|
|
1751
|
+
expect(rmRes.exitCode).toBe(0);
|
|
1752
|
+
expect(shell.context.fs.exists('/bin/vim')).toBe(false);
|
|
1753
|
+
expect(shell.context.fs.exists('/bin/vi')).toBe(false);
|
|
1754
|
+
expect(shell.context.fs.exists('/bin/vim-wasm')).toBe(false);
|
|
1755
|
+
expect(shell.context.fs.exists('/usr/lib/vim/vim.wasm')).toBe(false);
|
|
1756
|
+
});
|
|
1757
|
+
|
|
1680
1758
|
it('registers doom package with aliases doom-wasm, doom-ascii, and freedoom launcher script', async () => {
|
|
1681
1759
|
const BaseWbt = createTestWbt();
|
|
1682
1760
|
const registry = BaseWbt.DEFAULT_REGISTRY;
|