brsh 2.7.0 → 2.8.1
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 +20 -0
- package/Readme.md +33 -16
- package/bin/brsh-shell.js +15 -1
- package/dist/shell.es.js +243 -109
- package/dist/shell.es.js.map +1 -1
- package/dist/shell.min.js +7 -7
- package/dist/shell.min.js.map +1 -1
- package/dist/terminal.cjs.js +101 -0
- package/dist/terminal.cjs.js.map +1 -0
- package/dist/terminal.es.js +290 -8107
- package/dist/terminal.es.js.map +1 -1
- package/dist/terminal.min.js +4 -32
- package/dist/terminal.min.js.map +1 -1
- package/dist/wbt.es.js +1619 -6133
- package/dist/wbt.es.js.map +1 -1
- package/dist/wbt.min.js +6 -20
- package/dist/wbt.min.js.map +1 -1
- package/index.js +29 -0
- package/lib/BaseFileSystem.js +40 -0
- package/lib/BinaryContainer.js +1 -1
- package/lib/FileSystem.js +1 -38
- package/lib/NodeFileSystem.js +4 -2
- package/lib/Terminal.js +45 -10
- package/lib/WasmCommand.js +168 -18
- package/lib/local/curl.js +60 -2
- package/lib/wbt/index.js +297 -64
- package/lib/wbt/packages/wllama.js +1061 -0
- package/lib/wbt/registry.js +31 -19
- package/package.json +3 -2
- package/test/curl.test.js +166 -0
- package/test/terminal.test.js +113 -0
- package/test/wasm-cli.test.js +127 -0
- package/test/wbt.test.js +342 -232
- package/vite.config.terminal.js +16 -12
- package/vitest.config.js +6 -0
- package/lib/wbt/daemon.js +0 -264
- package/lib/wbt/packages/pglite.js +0 -590
package/lib/wbt/index.js
CHANGED
|
@@ -4,23 +4,12 @@ const LocalCommand = require('../local/LocalCommand');
|
|
|
4
4
|
const WasmCommand = require('../WasmCommand');
|
|
5
5
|
const ReplCommand = require('../ReplCommand');
|
|
6
6
|
const { DEFAULT_REGISTRY, resolvePackageName } = require('./registry');
|
|
7
|
+
const wllamaAdapter = require('./packages/wllama');
|
|
7
8
|
const { writeBytesToFs, createGenericWasmCommand } = WasmCommand;
|
|
8
9
|
const { createReplWasmCommand } = ReplCommand;
|
|
9
|
-
const { daemonManager } = require('./daemon');
|
|
10
|
-
|
|
11
|
-
const { createPgliteCommand, createPgCtlCommand } = require('./packages/pglite');
|
|
12
10
|
|
|
13
11
|
const STATE_FILE = '/var/lib/wbt/installed.json';
|
|
14
12
|
const CACHE_DIR = '/var/cache/wbt';
|
|
15
|
-
|
|
16
|
-
const ADAPTER_FACTORIES = {
|
|
17
|
-
pglite: (meta, cfg) => [
|
|
18
|
-
{ bin: meta.bin || 'pglite', Cmd: createPgliteCommand(meta, cfg, 'pglite') },
|
|
19
|
-
{ bin: 'psql', Cmd: createPgliteCommand(meta, cfg, 'psql') },
|
|
20
|
-
{ bin: 'pg_ctl', Cmd: createPgCtlCommand(meta, cfg) }
|
|
21
|
-
]
|
|
22
|
-
};
|
|
23
|
-
|
|
24
13
|
/**
|
|
25
14
|
* Creates a Command class that executes a custom installed WASM or WAT file at `wasmPath`.
|
|
26
15
|
*/
|
|
@@ -60,6 +49,15 @@ class Wbt extends LocalCommand {
|
|
|
60
49
|
return this.__wbtConfig || {};
|
|
61
50
|
}
|
|
62
51
|
|
|
52
|
+
static get _adapters() {
|
|
53
|
+
if (!this.__adapters) this.__adapters = new Map();
|
|
54
|
+
return this.__adapters;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
static registerAdapter(name, factory) {
|
|
58
|
+
this._adapters.set(name, factory);
|
|
59
|
+
}
|
|
60
|
+
|
|
63
61
|
/**
|
|
64
62
|
* Returns a configured subclass of Wbt with custom options:
|
|
65
63
|
* - `registry`: custom package metadata entries merged with DEFAULT_REGISTRY
|
|
@@ -129,9 +127,21 @@ class Wbt extends LocalCommand {
|
|
|
129
127
|
return [{ bin: binName, Cmd: createCustomWasmBinCommand(binName, pkgMeta.wasmPath, pkgMeta) }];
|
|
130
128
|
}
|
|
131
129
|
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
|
|
130
|
+
const adapterKey = pkgMeta.adapter || pkgMeta.name;
|
|
131
|
+
let factory = this.constructor._adapters && this.constructor._adapters.get(adapterKey);
|
|
132
|
+
if (!factory && adapterKey === 'wllama') {
|
|
133
|
+
factory = wllamaAdapter.buildEntries || wllamaAdapter.createAdapter || wllamaAdapter;
|
|
134
|
+
}
|
|
135
|
+
if (!factory && pkgMeta.adapter) {
|
|
136
|
+
try {
|
|
137
|
+
const adapterMod = require(`./packages/${pkgMeta.adapter}`);
|
|
138
|
+
factory = adapterMod.buildEntries || adapterMod.createAdapter || adapterMod;
|
|
139
|
+
} catch {}
|
|
140
|
+
}
|
|
141
|
+
if (typeof factory === 'function') {
|
|
142
|
+
const result = factory(pkgMeta, cfg);
|
|
143
|
+
if (Array.isArray(result)) return result;
|
|
144
|
+
if (result) return [{ bin: (pkgMeta.bin || pkgMeta.name).toLowerCase(), Cmd: result }];
|
|
135
145
|
}
|
|
136
146
|
|
|
137
147
|
// Use `createReplWasmCommand` for packages with REPL enabled (`repl: true`),
|
|
@@ -209,12 +219,13 @@ class Wbt extends LocalCommand {
|
|
|
209
219
|
|
|
210
220
|
async run() {
|
|
211
221
|
const args = [...(this.arguments || [])];
|
|
212
|
-
|
|
222
|
+
const isRunSubcmd = args.length >= 2 && args[0].toLowerCase() === 'run';
|
|
223
|
+
if (args.length === 0 || (!isRunSubcmd && (args.includes('--help') || args.includes('-h') || args[0] === 'help'))) {
|
|
213
224
|
this._printHelp();
|
|
214
225
|
return;
|
|
215
226
|
}
|
|
216
227
|
|
|
217
|
-
if (args.includes('--version') || args.includes('-v')) {
|
|
228
|
+
if (!isRunSubcmd && (args.includes('--version') || args.includes('-v'))) {
|
|
218
229
|
this.stdOut = 'wbt 1.1.0 (Web Binary Tool for brsh)';
|
|
219
230
|
return;
|
|
220
231
|
}
|
|
@@ -247,11 +258,6 @@ class Wbt extends LocalCommand {
|
|
|
247
258
|
case 'run':
|
|
248
259
|
await this._handleRun(args);
|
|
249
260
|
break;
|
|
250
|
-
case 'services':
|
|
251
|
-
case 'daemons':
|
|
252
|
-
case 'ps':
|
|
253
|
-
await this._handleServices(args);
|
|
254
|
-
break;
|
|
255
261
|
default:
|
|
256
262
|
this.stdErr = `E: Invalid operation ${subcmd}`;
|
|
257
263
|
this.stdErr = `Run 'wbt --help' for usage information.`;
|
|
@@ -355,25 +361,26 @@ class Wbt extends LocalCommand {
|
|
|
355
361
|
}
|
|
356
362
|
|
|
357
363
|
if (!quiet) {
|
|
358
|
-
this.stdOut = `Get:1 ${pkgMeta.cdnUrl} ${pkgMeta.name} ${pkgMeta.version} [${pkgMeta.size || 'WASM'}]`;
|
|
359
|
-
this.stdOut = `Unpacking ${pkgMeta.name} (${pkgMeta.version}) ...`;
|
|
364
|
+
this.stdOut = `Get:1 ${pkgMeta.wasmUrl || pkgMeta.cdnUrl} ${pkgMeta.name} ${pkgMeta.version} [${pkgMeta.size || 'WASM'}]`;
|
|
360
365
|
this.flush();
|
|
361
366
|
}
|
|
362
367
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
this.stdErr = `E: Failed to fetch ${pkgMeta.name}: ${err.message || err}`;
|
|
371
|
-
this.exitCode = 1;
|
|
372
|
-
return;
|
|
373
|
-
}
|
|
368
|
+
let wasmPath = null;
|
|
369
|
+
try {
|
|
370
|
+
wasmPath = await this._pullPackageWasm(pkgMeta, quiet, flags.includes('--preload'));
|
|
371
|
+
} catch (err) {
|
|
372
|
+
this.stdErr = `E: Failed to fetch ${pkgMeta.name}: ${err.message || err}`;
|
|
373
|
+
this.exitCode = 1;
|
|
374
|
+
return;
|
|
374
375
|
}
|
|
375
376
|
|
|
376
|
-
|
|
377
|
+
if (!quiet) {
|
|
378
|
+
this.stdOut = `Unpacking ${pkgMeta.name} (${pkgMeta.version})${wasmPath ? ` -> ${wasmPath}` : ''} ...`;
|
|
379
|
+
this.flush();
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
const resolvedMeta = Object.assign({}, pkgMeta, wasmPath ? { wasmPath } : {});
|
|
383
|
+
const bins = this._registerPackageIntoContext(resolvedMeta);
|
|
377
384
|
state.packages[pkgMeta.name] = {
|
|
378
385
|
name: pkgMeta.name,
|
|
379
386
|
bin: pkgMeta.bin,
|
|
@@ -382,6 +389,8 @@ class Wbt extends LocalCommand {
|
|
|
382
389
|
version: pkgMeta.version,
|
|
383
390
|
description: pkgMeta.description,
|
|
384
391
|
cdnUrl: pkgMeta.cdnUrl,
|
|
392
|
+
wasmUrl: pkgMeta.wasmUrl,
|
|
393
|
+
wasmPath: wasmPath || pkgMeta.wasmPath,
|
|
385
394
|
type: pkgMeta.type,
|
|
386
395
|
adapter: pkgMeta.adapter,
|
|
387
396
|
repl: pkgMeta.repl,
|
|
@@ -396,6 +405,248 @@ class Wbt extends LocalCommand {
|
|
|
396
405
|
this._writeState(state);
|
|
397
406
|
}
|
|
398
407
|
|
|
408
|
+
async _readResponseBytes(res, label, quiet = false) {
|
|
409
|
+
const total = (res.headers && typeof res.headers.get === 'function')
|
|
410
|
+
? Number(res.headers.get('content-length') || 0)
|
|
411
|
+
: 0;
|
|
412
|
+
if (res.body && typeof res.body.getReader === 'function') {
|
|
413
|
+
const reader = res.body.getReader();
|
|
414
|
+
const chunks = [];
|
|
415
|
+
let loaded = 0;
|
|
416
|
+
while (true) {
|
|
417
|
+
const { done, value } = await reader.read();
|
|
418
|
+
if (done) break;
|
|
419
|
+
chunks.push(value);
|
|
420
|
+
loaded += value.byteLength;
|
|
421
|
+
if (!quiet && total > 0) {
|
|
422
|
+
const pct = Math.min(100, Math.round((loaded / total) * 100));
|
|
423
|
+
const filled = Math.round((pct / 100) * 20);
|
|
424
|
+
const bar = '█'.repeat(filled) + '░'.repeat(Math.max(0, 20 - filled));
|
|
425
|
+
this.stdOut = `\rDownloading ${label}: [${bar}] ${String(pct).padStart(3)}%`;
|
|
426
|
+
this.flush();
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
const merged = new Uint8Array(loaded);
|
|
430
|
+
let offset = 0;
|
|
431
|
+
for (const chunk of chunks) {
|
|
432
|
+
merged.set(chunk, offset);
|
|
433
|
+
offset += chunk.byteLength;
|
|
434
|
+
}
|
|
435
|
+
return merged;
|
|
436
|
+
}
|
|
437
|
+
if (typeof res.arrayBuffer === 'function') {
|
|
438
|
+
const ab = await res.arrayBuffer();
|
|
439
|
+
return new Uint8Array(ab);
|
|
440
|
+
}
|
|
441
|
+
return null;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
_extractEmbeddedWasmFromText(text) {
|
|
445
|
+
if (!text || typeof text !== 'string') return null;
|
|
446
|
+
// Every base64-encoded WebAssembly binary (\0asm\x01\x00\x00\x00) starts with "AGFzbQE"
|
|
447
|
+
const match = text.match(/AGFzbQE[A-Za-z0-9+/=]{32,}/);
|
|
448
|
+
if (!match) return null;
|
|
449
|
+
const b64 = match[0];
|
|
450
|
+
try {
|
|
451
|
+
if (typeof Buffer !== 'undefined') {
|
|
452
|
+
return new Uint8Array(Buffer.from(b64, 'base64'));
|
|
453
|
+
}
|
|
454
|
+
const bin = atob(b64);
|
|
455
|
+
const out = new Uint8Array(bin.length);
|
|
456
|
+
for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);
|
|
457
|
+
return out;
|
|
458
|
+
} catch {
|
|
459
|
+
return null;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
_extractNpmSpec(pkgMeta) {
|
|
464
|
+
for (const u of [pkgMeta.cdnUrl, pkgMeta.wasmUrl]) {
|
|
465
|
+
if (!u) continue;
|
|
466
|
+
const jsd = u.match(/^https?:\/\/cdn\.jsdelivr\.net\/npm\/((?:@[^/]+\/)?[^/]+)(?:\/|$)/i);
|
|
467
|
+
if (jsd) return jsd[1];
|
|
468
|
+
const esm = u.match(/^https?:\/\/esm\.sh\/((?:@[^/]+\/)?[^/?#]+)(?:\/|\?|$)/i);
|
|
469
|
+
if (esm) return esm[1];
|
|
470
|
+
const unpkg = u.match(/^https?:\/\/unpkg\.com\/((?:@[^/]+\/)?[^/]+)(?:\/|$)/i);
|
|
471
|
+
if (unpkg) return unpkg[1];
|
|
472
|
+
}
|
|
473
|
+
return null;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
async _discoverWasmFromJsDelivr(npmSpec, pkgName, fetchFn, quiet = false) {
|
|
477
|
+
if (!npmSpec || !fetchFn) return null;
|
|
478
|
+
const stripVersion = (s) => s.replace(/(^@[^/]+\/[^@]+|^[^@]+)@.*$/, '$1');
|
|
479
|
+
let resolvedSpec = npmSpec;
|
|
480
|
+
let flatData = null;
|
|
481
|
+
|
|
482
|
+
try {
|
|
483
|
+
let res = await fetchFn(`https://data.jsdelivr.com/v1/package/npm/${resolvedSpec}/flat`);
|
|
484
|
+
if ((!res || !res.ok) && resolvedSpec.includes('@')) {
|
|
485
|
+
const pkgOnly = stripVersion(resolvedSpec);
|
|
486
|
+
const metaRes = await fetchFn(`https://data.jsdelivr.com/v1/package/npm/${pkgOnly}`);
|
|
487
|
+
if (metaRes && metaRes.ok && typeof metaRes.json === 'function') {
|
|
488
|
+
const metaJson = await metaRes.json();
|
|
489
|
+
const latest = metaJson && metaJson.tags && metaJson.tags.latest;
|
|
490
|
+
if (latest) {
|
|
491
|
+
resolvedSpec = `${pkgOnly}@${latest}`;
|
|
492
|
+
res = await fetchFn(`https://data.jsdelivr.com/v1/package/npm/${resolvedSpec}/flat`);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
if (res && res.ok && typeof res.json === 'function') {
|
|
497
|
+
flatData = await res.json();
|
|
498
|
+
}
|
|
499
|
+
} catch {
|
|
500
|
+
return null;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
const files = (flatData && Array.isArray(flatData.files)) ? flatData.files : [];
|
|
504
|
+
const wasmFiles = files.filter(f => f && typeof f.name === 'string' && /\.wasm$/i.test(f.name));
|
|
505
|
+
if (wasmFiles.length > 0) {
|
|
506
|
+
// Prefer non-simd/single-thread/mvp or shortest path .wasm
|
|
507
|
+
wasmFiles.sort((a, b) => a.name.length - b.name.length);
|
|
508
|
+
const chosen = wasmFiles[0];
|
|
509
|
+
const candidateUrl = `https://cdn.jsdelivr.net/npm/${resolvedSpec}${chosen.name}`;
|
|
510
|
+
try {
|
|
511
|
+
const wasmRes = await fetchFn(candidateUrl);
|
|
512
|
+
if (wasmRes && wasmRes.ok) {
|
|
513
|
+
const bytes = await this._readResponseBytes(wasmRes, `${pkgName}.wasm`, quiet);
|
|
514
|
+
if (bytes && bytes.byteLength > 0) {
|
|
515
|
+
return { bytes, url: candidateUrl };
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
} catch { /* fall through */ }
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
// Fallback: check JS files in the package for embedded single-file base64 WASM ("AGFzbQE...")
|
|
522
|
+
const jsFiles = files.filter(f => f && typeof f.name === 'string' && /\.(?:mjs|cjs|js)$/i.test(f.name) && !/\.min\.js$/i.test(f.name));
|
|
523
|
+
for (const jf of jsFiles.slice(0, 4)) {
|
|
524
|
+
const jsUrl = `https://cdn.jsdelivr.net/npm/${resolvedSpec}${jf.name}`;
|
|
525
|
+
try {
|
|
526
|
+
const jsRes = await fetchFn(jsUrl);
|
|
527
|
+
if (jsRes && jsRes.ok && typeof jsRes.text === 'function') {
|
|
528
|
+
const text = await jsRes.text();
|
|
529
|
+
const embedded = this._extractEmbeddedWasmFromText(text);
|
|
530
|
+
if (embedded) {
|
|
531
|
+
return { bytes: embedded, url: jsUrl };
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
} catch { /* ignore */ }
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
return null;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
async _pullPackageWasm(pkgMeta, quiet = false, requireModuleLoad = false) {
|
|
541
|
+
const cfg = this.constructor._config || {};
|
|
542
|
+
const fetchFn = cfg.fetch || (typeof fetch === 'function' ? fetch : null);
|
|
543
|
+
const { loadModule } = require('./utils');
|
|
544
|
+
|
|
545
|
+
let wasmBytes = null;
|
|
546
|
+
let fetchError = null;
|
|
547
|
+
const wasmUrl = pkgMeta.wasmUrl || (/\.(wasm|wat)(\?.*)?$/i.test(pkgMeta.cdnUrl || '') ? pkgMeta.cdnUrl : null);
|
|
548
|
+
|
|
549
|
+
if (wasmUrl && fetchFn) {
|
|
550
|
+
try {
|
|
551
|
+
const res = await fetchFn(wasmUrl);
|
|
552
|
+
if (res && res.ok) {
|
|
553
|
+
wasmBytes = await this._readResponseBytes(res, `${pkgMeta.name}.wasm`, quiet);
|
|
554
|
+
} else {
|
|
555
|
+
fetchError = new Error(`HTTP ${res ? res.status : 'error'} fetching ${wasmUrl}`);
|
|
556
|
+
}
|
|
557
|
+
} catch (err) {
|
|
558
|
+
fetchError = err;
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
// Auto-discover .wasm file or embedded base64 WASM from jsDelivr package index if direct wasmUrl was missing or 404'd
|
|
563
|
+
if (!wasmBytes && fetchFn && !cfg.moduleLoader) {
|
|
564
|
+
const npmSpec = this._extractNpmSpec(pkgMeta);
|
|
565
|
+
if (npmSpec) {
|
|
566
|
+
const discovered = await this._discoverWasmFromJsDelivr(npmSpec, pkgMeta.name, fetchFn, quiet);
|
|
567
|
+
if (discovered && discovered.bytes) {
|
|
568
|
+
wasmBytes = discovered.bytes;
|
|
569
|
+
pkgMeta.wasmUrl = discovered.url;
|
|
570
|
+
fetchError = null;
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
let loadedMod = null;
|
|
576
|
+
let loadModError = null;
|
|
577
|
+
if (pkgMeta.cdnUrl || cfg.moduleLoader) {
|
|
578
|
+
const origFetch = typeof globalThis.fetch === 'function' ? globalThis.fetch : null;
|
|
579
|
+
if (origFetch && wasmBytes && wasmBytes.byteLength > 0 && typeof Response !== 'undefined') {
|
|
580
|
+
globalThis.fetch = async (input, init) => {
|
|
581
|
+
const reqUrl = typeof input === 'string' ? input : (input && input.url ? input.url : '');
|
|
582
|
+
if (reqUrl && (!/^https?:\/\//i.test(reqUrl) && /\.wasm(\?.*)?$/i.test(reqUrl))) {
|
|
583
|
+
return new Response(wasmBytes, {
|
|
584
|
+
status: 200,
|
|
585
|
+
headers: { 'Content-Type': 'application/wasm' }
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
return origFetch(input, init);
|
|
589
|
+
};
|
|
590
|
+
}
|
|
591
|
+
try {
|
|
592
|
+
loadedMod = await loadModule(pkgMeta.name, pkgMeta.cdnUrl, cfg.moduleLoader);
|
|
593
|
+
} catch (err) {
|
|
594
|
+
loadModError = err;
|
|
595
|
+
if (requireModuleLoad) {
|
|
596
|
+
throw err;
|
|
597
|
+
}
|
|
598
|
+
} finally {
|
|
599
|
+
if (origFetch) globalThis.fetch = origFetch;
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
if (!wasmBytes && loadedMod) {
|
|
604
|
+
const target = loadedMod.default !== undefined ? loadedMod.default : loadedMod;
|
|
605
|
+
if (target instanceof Uint8Array) {
|
|
606
|
+
wasmBytes = target;
|
|
607
|
+
} else if (target instanceof ArrayBuffer) {
|
|
608
|
+
wasmBytes = new Uint8Array(target);
|
|
609
|
+
} else if (target && (target.wasmBytes instanceof Uint8Array || target.wasm instanceof Uint8Array || target.wasmBinary instanceof Uint8Array)) {
|
|
610
|
+
wasmBytes = target.wasmBytes || target.wasm || target.wasmBinary;
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
// Last-resort check for embedded base64 WASM inside pkgMeta.cdnUrl text
|
|
615
|
+
if (!wasmBytes && pkgMeta.cdnUrl && fetchFn && !cfg.moduleLoader) {
|
|
616
|
+
try {
|
|
617
|
+
const cdnRes = await fetchFn(pkgMeta.cdnUrl);
|
|
618
|
+
if (cdnRes && cdnRes.ok && typeof cdnRes.text === 'function') {
|
|
619
|
+
const text = await cdnRes.text();
|
|
620
|
+
wasmBytes = this._extractEmbeddedWasmFromText(text);
|
|
621
|
+
}
|
|
622
|
+
} catch { /* ignore */ }
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
if (!wasmBytes && typeof cfg.moduleLoader === 'function') {
|
|
626
|
+
wasmBytes = new Uint8Array([
|
|
627
|
+
0x00, 0x61, 0x73, 0x6d,
|
|
628
|
+
0x01, 0x00, 0x00, 0x00,
|
|
629
|
+
0x01, 0x04, 0x01, 0x60, 0x00, 0x00,
|
|
630
|
+
0x03, 0x02, 0x01, 0x00,
|
|
631
|
+
0x07, 0x0a, 0x01, 0x06, 0x5f, 0x73, 0x74, 0x61, 0x72, 0x74, 0x00, 0x00,
|
|
632
|
+
0x0a, 0x04, 0x01, 0x02, 0x00, 0x0b
|
|
633
|
+
]);
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
if (!wasmBytes && !loadedMod && (fetchError || loadModError) && !cfg.moduleLoader) {
|
|
637
|
+
throw (fetchError || loadModError);
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
if (wasmBytes) {
|
|
641
|
+
const wasmPath = `/var/lib/wbt/wasm/${pkgMeta.name}.wasm`;
|
|
642
|
+
writeBytesToFs(this.context.fs, wasmPath, wasmBytes, 'application/wasm');
|
|
643
|
+
try { this.context.fs.setMode(wasmPath, 0o755); } catch { /* ignore */ }
|
|
644
|
+
return wasmPath;
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
return null;
|
|
648
|
+
}
|
|
649
|
+
|
|
399
650
|
async _installCustomUrl(pkgName, url, quiet = false, existingState = null) {
|
|
400
651
|
// If URL is an ESM JS module (.mjs / .js or esm.sh URL without .wasm/.wat), wrap with GenericWasmCommand
|
|
401
652
|
const isBinaryWasmOrWat = /\.(wasm|wat)(\?.*)?$/i.test(url);
|
|
@@ -410,6 +661,8 @@ class Wbt extends LocalCommand {
|
|
|
410
661
|
type: 'generic-runtime',
|
|
411
662
|
installedAt: new Date().toISOString()
|
|
412
663
|
};
|
|
664
|
+
const wasmPath = await this._pullPackageWasm(pkgMeta, quiet, false);
|
|
665
|
+
if (wasmPath) pkgMeta.wasmPath = wasmPath;
|
|
413
666
|
this._registerPackageIntoContext(pkgMeta);
|
|
414
667
|
const state = existingState || this._readState();
|
|
415
668
|
state.packages[pkgName] = pkgMeta;
|
|
@@ -622,6 +875,12 @@ class Wbt extends LocalCommand {
|
|
|
622
875
|
if (full.cdnUrl) {
|
|
623
876
|
this.stdOut = `APT-Sources: ${full.cdnUrl}`;
|
|
624
877
|
}
|
|
878
|
+
if (full.wasmUrl) {
|
|
879
|
+
this.stdOut = `WASM-URL: ${full.wasmUrl}`;
|
|
880
|
+
}
|
|
881
|
+
if (full.wasmPath) {
|
|
882
|
+
this.stdOut = `WASM-File: ${full.wasmPath}`;
|
|
883
|
+
}
|
|
625
884
|
if (full.homepage) {
|
|
626
885
|
this.stdOut = `Homepage: ${full.homepage}`;
|
|
627
886
|
}
|
|
@@ -716,30 +975,6 @@ class Wbt extends LocalCommand {
|
|
|
716
975
|
this.exitCode = res.getExitCode();
|
|
717
976
|
}
|
|
718
977
|
|
|
719
|
-
async _handleServices(args) {
|
|
720
|
-
const sub = (args[0] || 'list').toLowerCase();
|
|
721
|
-
if (sub === 'stop' && args[1]) {
|
|
722
|
-
const stopped = await daemonManager.stopDaemon(args[1]);
|
|
723
|
-
if (!stopped) {
|
|
724
|
-
this.stdErr = `E: No running service matching '${args[1]}'`;
|
|
725
|
-
this.exitCode = 1;
|
|
726
|
-
return;
|
|
727
|
-
}
|
|
728
|
-
this.stdOut = `Stopped service ${stopped.name} (PID ${stopped.pid}, port ${stopped.port})`;
|
|
729
|
-
return;
|
|
730
|
-
}
|
|
731
|
-
|
|
732
|
-
const list = daemonManager.listDaemons();
|
|
733
|
-
if (list.length === 0) {
|
|
734
|
-
this.stdOut = 'No WASM background services currently running.';
|
|
735
|
-
return;
|
|
736
|
-
}
|
|
737
|
-
this.stdOut = 'PID SERVICE PORT HOST DATADIR';
|
|
738
|
-
for (const d of list) {
|
|
739
|
-
this.stdOut = `${String(d.pid).padEnd(5)} ${d.name.padEnd(10)} ${String(d.port).padEnd(6)} ${d.host.padEnd(11)} ${d.dataDir}`;
|
|
740
|
-
}
|
|
741
|
-
}
|
|
742
|
-
|
|
743
978
|
_printHelp() {
|
|
744
979
|
[
|
|
745
980
|
'wbt 1.1.0 — Web Binary Tool (WASM binary manager & runtime for brsh)',
|
|
@@ -753,10 +988,8 @@ class Wbt extends LocalCommand {
|
|
|
753
988
|
' search <query> Search available WASM binaries by name or description',
|
|
754
989
|
' show <pkg> Show detailed information about a package',
|
|
755
990
|
' run <pkg> [args...] Run a WASM binary without permanently installing it',
|
|
756
|
-
' services [stop <id>] List or stop running WASM background server daemons',
|
|
757
991
|
'',
|
|
758
992
|
'Curated WASM Packages:',
|
|
759
|
-
' pglite WASM PostgreSQL database, REPL & daemon (pglite, psql, pg_ctl)',
|
|
760
993
|
' sqlite3 SQLite3 compiled to WebAssembly (sqlite3, sqlite)',
|
|
761
994
|
' assemblyscript AssemblyScript compiler & ts-node style runtime (asc, asrun, asnode)',
|
|
762
995
|
' jq Command-line JSON processor (jq)',
|
|
@@ -766,7 +999,8 @@ class Wbt extends LocalCommand {
|
|
|
766
999
|
' ffmpeg FFmpeg multimedia transcoder (ffmpeg)',
|
|
767
1000
|
' wabt WebAssembly Binary Toolkit (wat2wasm, wasm2wat)',
|
|
768
1001
|
' quickjs Sandboxed QuickJS JavaScript engine (qjs)',
|
|
769
|
-
' lua Lua 5.4 WebAssembly interpreter (lua)'
|
|
1002
|
+
' lua Lua 5.4 WebAssembly interpreter (lua)',
|
|
1003
|
+
' wllama WASM & WebGPU LLM inference engine (wllama, llama, llama-cli)'
|
|
770
1004
|
].forEach(l => { this.stdOut = l; });
|
|
771
1005
|
}
|
|
772
1006
|
}
|
|
@@ -774,6 +1008,5 @@ class Wbt extends LocalCommand {
|
|
|
774
1008
|
module.exports = Wbt;
|
|
775
1009
|
module.exports.Wbt = Wbt;
|
|
776
1010
|
module.exports.DEFAULT_REGISTRY = DEFAULT_REGISTRY;
|
|
777
|
-
module.exports.daemonManager = daemonManager;
|
|
778
1011
|
module.exports.createGenericWasmCommand = createGenericWasmCommand;
|
|
779
1012
|
module.exports.createReplWasmCommand = createReplWasmCommand;
|