Preview1 state lives in the host, so Go modules (esbuild) work. esbuild bundles byte-identical to native; uutils and QuickJS-ng file tests pass. The failed guest-side adapter attempt (T7) moves to spikes/s7-preview1-adapter/.
44 lines
2.3 KiB
Nu
44 lines
2.3 KiB
Nu
# Compare esbuild bundles and test preview1 uutils and QuickJS with this adapter.
|
|
use std/assert
|
|
def checked [program: string, args: list<string>] {
|
|
let result = (run-external $program ...$args | complete)
|
|
if $result.exit_code != 0 {
|
|
print $result.stdout
|
|
print --stderr $result.stderr
|
|
error make {msg: $'Failed: ($program) ($args | str join " ")'}
|
|
}
|
|
$result.stdout | str trim
|
|
}
|
|
def main [] {
|
|
let root = '/tmp/p1-adapter'
|
|
let adapter = $root | path join adapter-command.wasm
|
|
for guest in [
|
|
{name: coreutils, path: '/tmp/wasi-userland-lab/uu/coreutils-0.12.0-wasm32-wasip1/coreutils.wasm', args: [echo adapter-ok], expected: adapter-ok},
|
|
{name: QuickJS, path: '/tmp/wasi-userland-lab/qjs-wasi.wasm', args: [-e 'console.log(6 * 7)'], expected: '42'}
|
|
] {
|
|
let binary = $root | path join $'($guest.name).wasm'
|
|
checked wasm-tools [component new $guest.path --adapt $'wasi_snapshot_preview1=($adapter)' -o $binary] | ignore
|
|
assert equal (checked wasmtime ([run $binary] | append $guest.args)) $guest.expected
|
|
print $'PASS ($guest.name): ($guest.expected)'
|
|
}
|
|
let fixture = $env.FILE_PWD | path join ../s6-esbuild | path expand
|
|
let app = $root | path join app
|
|
mkdir $app
|
|
cp ($fixture | path join app.tsx) ($fixture | path join check.mjs) ($fixture | path join package.json) ($fixture | path join package-lock.json) $app
|
|
cd $app
|
|
print (checked npm [ci --ignore-scripts --no-audit --no-fund])
|
|
let flags = [app.tsx --bundle --minify --format=iife --platform=browser --jsx=automatic --jsx-import-source=preact --legal-comments=none --log-level=error]
|
|
for variant in [module component] {
|
|
let binary = if $variant == module { '/tmp/s6-esbuild/esbuild.wasm' } else { $root | path join esbuild.component.wasm }
|
|
if $variant == component {
|
|
checked wasm-tools [component new /tmp/s6-esbuild/esbuild.wasm --adapt $'wasi_snapshot_preview1=($adapter)' -o $binary] | ignore
|
|
}
|
|
assert equal (checked wasmtime [run --dir .::/ $binary --version]) '0.27.7'
|
|
checked wasmtime ([run --dir .::/ $binary] | append $flags | append $'--outfile=($variant).js') | ignore
|
|
print (checked node [check.mjs $'($variant).js'])
|
|
}
|
|
assert equal (open --raw module.js) (open --raw component.js)
|
|
print 'PASS byte-identical module/component bundles'
|
|
print 'PASS all adapter checks'
|
|
}
|