bytecodealliance / ComponentizeJS

JS -> WebAssembly Component
Apache License 2.0
241 stars 32 forks source link

`componentize` should throw an error when it it builds a component without satisfying world exports. #113

Closed karthik2804 closed 2 months ago

karthik2804 commented 5 months ago

As the title states, consider the the following case

// hello.wit
package local:hello;

world hello {
  export hello: func(name: string) -> string;
}
// hello.js
// Intentionally left empty

when using the following script.

// componentize.js

import { componentize } from '@bytecodealliance/componentize-js';
import { readFile, writeFile } from 'node:fs/promises';
import { resolve } from 'node:path';

const jsSource = await readFile('hello.js', 'utf8');

const { component } = await componentize(jsSource, {
  witPath: resolve('hello.wit')
});

await writeFile('hello.component.wasm', component);

The output on running the script is

$ node componentize.js
Promise rejected but never handled: "source.js" source does not export a "hello" function as expected by the world.

  Try defining it:

      export function hello() {};

Stack:
  BindingsError@source.bindings.js:16:5
  @source.bindings.js:77:7

But when checking the exit code

$ echo $?
0

If a user has this as a part of a script. it is easy to not notice that the component was not built successfully.

karthik2804 commented 4 months ago

Checking again with a build from main seems to be resolved. The error case correctly has an exit code of 1 now.

guybedford commented 2 months ago

Closing this as resolved per the comment, but let me know if we still need to track this.