brsh 2.8.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 +7 -0
- package/dist/shell.es.js +160 -81
- package/dist/shell.es.js.map +1 -1
- package/dist/shell.min.js +4 -4
- package/dist/shell.min.js.map +1 -1
- package/dist/wbt.es.js +1584 -623
- package/dist/wbt.es.js.map +1 -1
- package/dist/wbt.min.js +6 -6
- package/dist/wbt.min.js.map +1 -1
- 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/WasmCommand.js +168 -18
- package/lib/wbt/index.js +270 -14
- package/lib/wbt/packages/wllama.js +12 -2
- package/lib/wbt/registry.js +11 -2
- package/package.json +1 -1
- package/test/wbt.test.js +24 -5
package/lib/wbt/index.js
CHANGED
|
@@ -4,6 +4,7 @@ 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
10
|
|
|
@@ -128,6 +129,9 @@ class Wbt extends LocalCommand {
|
|
|
128
129
|
|
|
129
130
|
const adapterKey = pkgMeta.adapter || pkgMeta.name;
|
|
130
131
|
let factory = this.constructor._adapters && this.constructor._adapters.get(adapterKey);
|
|
132
|
+
if (!factory && adapterKey === 'wllama') {
|
|
133
|
+
factory = wllamaAdapter.buildEntries || wllamaAdapter.createAdapter || wllamaAdapter;
|
|
134
|
+
}
|
|
131
135
|
if (!factory && pkgMeta.adapter) {
|
|
132
136
|
try {
|
|
133
137
|
const adapterMod = require(`./packages/${pkgMeta.adapter}`);
|
|
@@ -357,25 +361,26 @@ class Wbt extends LocalCommand {
|
|
|
357
361
|
}
|
|
358
362
|
|
|
359
363
|
if (!quiet) {
|
|
360
|
-
this.stdOut = `Get:1 ${pkgMeta.cdnUrl} ${pkgMeta.name} ${pkgMeta.version} [${pkgMeta.size || 'WASM'}]`;
|
|
361
|
-
this.stdOut = `Unpacking ${pkgMeta.name} (${pkgMeta.version}) ...`;
|
|
364
|
+
this.stdOut = `Get:1 ${pkgMeta.wasmUrl || pkgMeta.cdnUrl} ${pkgMeta.name} ${pkgMeta.version} [${pkgMeta.size || 'WASM'}]`;
|
|
362
365
|
this.flush();
|
|
363
366
|
}
|
|
364
367
|
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
}
|
|
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;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
if (!quiet) {
|
|
378
|
+
this.stdOut = `Unpacking ${pkgMeta.name} (${pkgMeta.version})${wasmPath ? ` -> ${wasmPath}` : ''} ...`;
|
|
379
|
+
this.flush();
|
|
376
380
|
}
|
|
377
381
|
|
|
378
|
-
const
|
|
382
|
+
const resolvedMeta = Object.assign({}, pkgMeta, wasmPath ? { wasmPath } : {});
|
|
383
|
+
const bins = this._registerPackageIntoContext(resolvedMeta);
|
|
379
384
|
state.packages[pkgMeta.name] = {
|
|
380
385
|
name: pkgMeta.name,
|
|
381
386
|
bin: pkgMeta.bin,
|
|
@@ -385,6 +390,7 @@ class Wbt extends LocalCommand {
|
|
|
385
390
|
description: pkgMeta.description,
|
|
386
391
|
cdnUrl: pkgMeta.cdnUrl,
|
|
387
392
|
wasmUrl: pkgMeta.wasmUrl,
|
|
393
|
+
wasmPath: wasmPath || pkgMeta.wasmPath,
|
|
388
394
|
type: pkgMeta.type,
|
|
389
395
|
adapter: pkgMeta.adapter,
|
|
390
396
|
repl: pkgMeta.repl,
|
|
@@ -399,6 +405,248 @@ class Wbt extends LocalCommand {
|
|
|
399
405
|
this._writeState(state);
|
|
400
406
|
}
|
|
401
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
|
+
|
|
402
650
|
async _installCustomUrl(pkgName, url, quiet = false, existingState = null) {
|
|
403
651
|
// If URL is an ESM JS module (.mjs / .js or esm.sh URL without .wasm/.wat), wrap with GenericWasmCommand
|
|
404
652
|
const isBinaryWasmOrWat = /\.(wasm|wat)(\?.*)?$/i.test(url);
|
|
@@ -413,6 +661,8 @@ class Wbt extends LocalCommand {
|
|
|
413
661
|
type: 'generic-runtime',
|
|
414
662
|
installedAt: new Date().toISOString()
|
|
415
663
|
};
|
|
664
|
+
const wasmPath = await this._pullPackageWasm(pkgMeta, quiet, false);
|
|
665
|
+
if (wasmPath) pkgMeta.wasmPath = wasmPath;
|
|
416
666
|
this._registerPackageIntoContext(pkgMeta);
|
|
417
667
|
const state = existingState || this._readState();
|
|
418
668
|
state.packages[pkgName] = pkgMeta;
|
|
@@ -625,6 +875,12 @@ class Wbt extends LocalCommand {
|
|
|
625
875
|
if (full.cdnUrl) {
|
|
626
876
|
this.stdOut = `APT-Sources: ${full.cdnUrl}`;
|
|
627
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
|
+
}
|
|
628
884
|
if (full.homepage) {
|
|
629
885
|
this.stdOut = `Homepage: ${full.homepage}`;
|
|
630
886
|
}
|
|
@@ -237,8 +237,18 @@ async function getOrInitWllamaInstance(opts = {}) {
|
|
|
237
237
|
const Wllama = mod.Wllama || mod.default || mod;
|
|
238
238
|
const LoggerWithoutDebug = mod.LoggerWithoutDebug || undefined;
|
|
239
239
|
|
|
240
|
-
|
|
241
|
-
|
|
240
|
+
let wasmUrl = pkgMeta.wasmUrl || DEFAULT_WASM_URL;
|
|
241
|
+
if (pkgMeta.wasmPath && fs && typeof URL !== 'undefined' && typeof URL.createObjectURL === 'function') {
|
|
242
|
+
const persistedWasm = readBytesFromFs(fs, pkgMeta.wasmPath);
|
|
243
|
+
if (persistedWasm && persistedWasm.byteLength > 0) {
|
|
244
|
+
wasmUrl = URL.createObjectURL(new Blob([persistedWasm], { type: 'application/wasm' }));
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
const pathConfig = {
|
|
248
|
+
default: wasmUrl,
|
|
249
|
+
'single-thread/wllama.wasm': wasmUrl,
|
|
250
|
+
'multi-thread/wllama.wasm': wasmUrl
|
|
251
|
+
};
|
|
242
252
|
|
|
243
253
|
const createWllama = () => {
|
|
244
254
|
try {
|
package/lib/wbt/registry.js
CHANGED
|
@@ -38,6 +38,7 @@ const DEFAULT_REGISTRY = {
|
|
|
38
38
|
details: 'AssemblyScript compiles a strict variant of TypeScript to WebAssembly. Includes `asc` (ahead-of-time compiler to .wasm/.wat) and `asrun` / `asnode`.',
|
|
39
39
|
homepage: 'https://www.assemblyscript.org',
|
|
40
40
|
cdnUrl: 'https://esm.sh/assemblyscript@0.27.31/asc',
|
|
41
|
+
wasmUrl: 'https://cdn.jsdelivr.net/npm/binaryen@119.0.0/index.wasm',
|
|
41
42
|
type: 'generic-runtime',
|
|
42
43
|
repl: { prompt: 'as> ', evalFlag: '-e' },
|
|
43
44
|
size: '1.4 MB'
|
|
@@ -46,11 +47,12 @@ const DEFAULT_REGISTRY = {
|
|
|
46
47
|
name: 'jq',
|
|
47
48
|
bin: 'jq',
|
|
48
49
|
aliases: [],
|
|
49
|
-
version: '
|
|
50
|
+
version: '0.6.2',
|
|
50
51
|
description: 'Command-line JSON processor compiled to WebAssembly (jq-web)',
|
|
51
52
|
details: 'jq is like sed for JSON data — you can use it to slice, filter, map, and transform structured JSON data from files or piped standard input.',
|
|
52
53
|
homepage: 'https://jqlang.github.io/jq/',
|
|
53
|
-
cdnUrl: 'https://esm.sh/jq-web@0.
|
|
54
|
+
cdnUrl: 'https://esm.sh/jq-web@0.6.2',
|
|
55
|
+
wasmUrl: 'https://cdn.jsdelivr.net/npm/jq-web@0.6.2/jq.wasm',
|
|
54
56
|
type: 'generic-runtime',
|
|
55
57
|
size: '620 KB'
|
|
56
58
|
},
|
|
@@ -63,6 +65,7 @@ const DEFAULT_REGISTRY = {
|
|
|
63
65
|
details: 'Full Python 3.12 runtime in WebAssembly powered by Pyodide. Supports interactive Python REPL (`>>>`), running `.py` scripts from the brsh filesystem, `-c` inline code evaluation, and piped standard input.',
|
|
64
66
|
homepage: 'https://pyodide.org',
|
|
65
67
|
cdnUrl: 'https://cdn.jsdelivr.net/pyodide/v0.26.4/full/pyodide.mjs',
|
|
68
|
+
wasmUrl: 'https://cdn.jsdelivr.net/pyodide/v0.26.4/full/pyodide.asm.wasm',
|
|
66
69
|
indexURL: 'https://cdn.jsdelivr.net/pyodide/v0.26.4/full/',
|
|
67
70
|
type: 'generic-runtime',
|
|
68
71
|
repl: { prompt: '>>> ', evalFlag: '-c' },
|
|
@@ -77,6 +80,7 @@ const DEFAULT_REGISTRY = {
|
|
|
77
80
|
details: 'DuckDB-WASM executes analytical SQL queries directly in WebAssembly, including querying CSV and JSON files stored in the brsh filesystem, interactive SQL shell, and one-shot / piped queries.',
|
|
78
81
|
homepage: 'https://duckdb.org',
|
|
79
82
|
cdnUrl: 'https://esm.sh/@duckdb/duckdb-wasm@1.29.0',
|
|
83
|
+
wasmUrl: 'https://cdn.jsdelivr.net/npm/@duckdb/duckdb-wasm@1.29.0/dist/duckdb-mvp.wasm',
|
|
80
84
|
type: 'generic-runtime',
|
|
81
85
|
repl: { prompt: 'D ', continuePrompt: ' > ', evalFlag: '-c' },
|
|
82
86
|
size: '4.2 MB'
|
|
@@ -90,6 +94,7 @@ const DEFAULT_REGISTRY = {
|
|
|
90
94
|
details: 'Powered by @hpcc-js/wasm-graphviz. Compiles DOT language graph descriptions (`.dot` / `.gv`) into SVG, DOT, canon, or JSON formats (`dot -Tsvg input.dot -o output.svg`).',
|
|
91
95
|
homepage: 'https://graphviz.org',
|
|
92
96
|
cdnUrl: 'https://esm.sh/@hpcc-js/wasm-graphviz@1.13.0',
|
|
97
|
+
wasmUrl: 'https://cdn.jsdelivr.net/npm/@hpcc-js/wasm-graphviz@1.13.0/dist/graphvizlib.wasm',
|
|
93
98
|
type: 'generic-runtime',
|
|
94
99
|
size: '1.1 MB'
|
|
95
100
|
},
|
|
@@ -103,6 +108,7 @@ const DEFAULT_REGISTRY = {
|
|
|
103
108
|
homepage: 'https://ffmpegwasm.netlify.app',
|
|
104
109
|
cdnUrl: 'https://esm.sh/@ffmpeg/ffmpeg@0.12.10',
|
|
105
110
|
coreUrl: 'https://unpkg.com/@ffmpeg/core@0.12.6/dist/esm/ffmpeg-core.js',
|
|
111
|
+
wasmUrl: 'https://cdn.jsdelivr.net/npm/@ffmpeg/core@0.12.6/dist/esm/ffmpeg-core.wasm',
|
|
106
112
|
type: 'generic-runtime',
|
|
107
113
|
size: '8.5 MB'
|
|
108
114
|
},
|
|
@@ -115,6 +121,7 @@ const DEFAULT_REGISTRY = {
|
|
|
115
121
|
details: 'WABT provides tools for translating between WebAssembly Text Format (.wat) and the WebAssembly binary format (.wasm), as well as inspecting WASM modules.',
|
|
116
122
|
homepage: 'https://github.com/WebAssembly/wabt',
|
|
117
123
|
cdnUrl: 'https://esm.sh/wabt@1.0.36',
|
|
124
|
+
wasmUrl: 'https://cdn.jsdelivr.net/npm/wabt@1.0.36/libwabt.wasm',
|
|
118
125
|
type: 'generic-runtime',
|
|
119
126
|
size: '540 KB'
|
|
120
127
|
},
|
|
@@ -127,6 +134,7 @@ const DEFAULT_REGISTRY = {
|
|
|
127
134
|
details: 'QuickJS is a small and embeddable Javascript engine supporting ES2023. Runs JS code and files inside an isolated WebAssembly sandbox.',
|
|
128
135
|
homepage: 'https://bellard.org/quickjs/',
|
|
129
136
|
cdnUrl: 'https://esm.sh/quickjs-emscripten@0.31.0',
|
|
137
|
+
wasmUrl: 'https://cdn.jsdelivr.net/npm/@jitl/quickjs-wasmfile-release-sync@0.31.0/dist/emscripten-module.wasm',
|
|
130
138
|
type: 'generic-runtime',
|
|
131
139
|
repl: { prompt: 'qjs > ', evalFlag: '-e' },
|
|
132
140
|
size: '820 KB'
|
|
@@ -140,6 +148,7 @@ const DEFAULT_REGISTRY = {
|
|
|
140
148
|
details: 'Full Lua 5.4 virtual machine compiled to WebAssembly. Supports interactive REPL, script execution from the brsh filesystem, and `-e` one-liners.',
|
|
141
149
|
homepage: 'https://www.lua.org',
|
|
142
150
|
cdnUrl: 'https://esm.sh/wasmoon@1.16.0',
|
|
151
|
+
wasmUrl: 'https://cdn.jsdelivr.net/npm/wasmoon@1.16.0/dist/glue.wasm',
|
|
143
152
|
type: 'generic-runtime',
|
|
144
153
|
repl: { prompt: 'lua> ', evalFlag: '-e' },
|
|
145
154
|
size: '410 KB'
|
package/package.json
CHANGED
package/test/wbt.test.js
CHANGED
|
@@ -508,7 +508,7 @@ function createTestWbt() {
|
|
|
508
508
|
return null;
|
|
509
509
|
},
|
|
510
510
|
fetch: async (url) => {
|
|
511
|
-
if (url === 'https://example.com/hello.wasm') {
|
|
511
|
+
if (url === 'https://example.com/hello.wasm' || /\.wasm(\?.*)?$/i.test(url)) {
|
|
512
512
|
return {
|
|
513
513
|
ok: true,
|
|
514
514
|
status: 200,
|
|
@@ -624,6 +624,29 @@ describe('WBT CLI subcommands (list, search, show, install, remove, update)', ()
|
|
|
624
624
|
expect(errors.join(' ')).toContain('Unable to locate package nonexistent-wasm-pkg');
|
|
625
625
|
});
|
|
626
626
|
|
|
627
|
+
it('pulls and persists the .wasm binary to /var/lib/wbt/wasm/<pkg>.wasm on `wbt install` and removes it on `wbt remove`', async () => {
|
|
628
|
+
const fetchedUrls = [];
|
|
629
|
+
const BaseWbt = createTestWbt();
|
|
630
|
+
const TrackingWbt = BaseWbt.configure({
|
|
631
|
+
fetch: async (url) => {
|
|
632
|
+
fetchedUrls.push(url);
|
|
633
|
+
return BaseWbt._config.fetch(url);
|
|
634
|
+
}
|
|
635
|
+
});
|
|
636
|
+
shell.context.setCommand(TrackingWbt);
|
|
637
|
+
|
|
638
|
+
const installRes = await run(shell, 'wbt install sqlite3');
|
|
639
|
+
expect(installRes.exitCode).toBe(0);
|
|
640
|
+
expect(fetchedUrls.some(u => u.includes('sql-wasm.wasm'))).toBe(true);
|
|
641
|
+
expect(shell.context.fs.exists('/var/lib/wbt/wasm/sqlite3.wasm')).toBe(true);
|
|
642
|
+
|
|
643
|
+
const showRes = await run(shell, 'wbt show sqlite3');
|
|
644
|
+
expect(showRes.output.join('\n')).toContain('WASM-File: /var/lib/wbt/wasm/sqlite3.wasm');
|
|
645
|
+
|
|
646
|
+
await run(shell, 'wbt remove sqlite3');
|
|
647
|
+
expect(shell.context.fs.exists('/var/lib/wbt/wasm/sqlite3.wasm')).toBe(false);
|
|
648
|
+
});
|
|
649
|
+
|
|
627
650
|
it('removes an installed package and unregisters its binary from /bin', async () => {
|
|
628
651
|
await run(shell, 'wbt install sqlite3');
|
|
629
652
|
const check1 = await run(shell, 'which sqlite3');
|
|
@@ -1169,7 +1192,3 @@ describe('WBT Wllama v3 WASM & WebGPU package (`wllama`, `llama`, `llama-cli`)',
|
|
|
1169
1192
|
expect(modelsRes.output.join('\n')).toContain('persisted (fs)');
|
|
1170
1193
|
});
|
|
1171
1194
|
});
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|