TypeScript generation not supporting map configuration
When I compile a rust wasi component with cargo component build --release and I run jco on the result with
jco transpile plugin-wasi/target/wasm32-wasi/release/plugin_wasi.wasm --instantiation -o out-dir/
Then the generated TS bindings do not match what the JS actually does in the instantiate function.
Genrated TS bindings:
export interface ImportObject {
'import-point': {
default(pnt: Point): Point,
},
print: {
default(msg: string): void,
},
'wasi:cli-base/environment': typeof ImportsEnvironment,
'wasi:cli-base/exit': typeof ImportsExit,
'wasi:cli-base/preopens': typeof ImportsPreopens,
'wasi:cli-base/stderr': typeof ImportsStderr,
'wasi:cli-base/stdin': typeof ImportsStdin,
'wasi:cli-base/stdout': typeof ImportsStdout,
'wasi:filesystem/filesystem': typeof ImportsFilesystem,
'wasi:io/streams': typeof ImportsStreams,
}
Actual JS code:
export async function instantiate(compileCore, imports, instantiateCore = WebAssembly.instantiate) {
const module0 = compileCore('plugin_wasi.core.wasm');
const module1 = compileCore('plugin_wasi.core2.wasm');
const module2 = compileCore('plugin_wasi.core3.wasm');
const module3 = compileCore('plugin_wasi.core4.wasm');
const { environment, exit: exit$1, preopens, stderr, stdin, stdout } = imports['@bytecodealliance/preview2-shim/cli-base'];
const { filesystem } = imports['@bytecodealliance/preview2-shim/filesystem'];
const { streams } = imports['@bytecodealliance/preview2-shim/io'];
const importPoint = imports['import-point'].default;
const print = imports.print.default;
The custom imported functions are fine, but the wasi import object does not match.
Edit: jco version 0.9.4
Try adding the --no-wasi-shim flag. The WASI bindings are automatically mapped using mapping configuration - https://github.com/bytecodealliance/jco/blob/main/src/cmd/transpile.js#L92.
The bug here is that TypeScript output does not yet support the map configuration itself, so whenever using --map typings and JS will be out of sync.
Changing to title to match the issue, but your problem should be resolved with that flag for now.