ComponentizeJS icon indicating copy to clipboard operation
ComponentizeJS copied to clipboard

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

Open karthik2804 opened this issue 1 year ago • 1 comments

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:
  [email protected]: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 avatar Jun 01 '24 08:06 karthik2804

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

karthik2804 avatar Jul 10 '24 10:07 karthik2804

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

guybedford avatar Sep 09 '24 17:09 guybedford