ComponentizeJS
ComponentizeJS copied to clipboard
`componentize` should throw an error when it it builds a component without satisfying world exports.
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.
Checking again with a build from main seems to be resolved. The error case correctly has an exit code of 1 now.
Closing this as resolved per the comment, but let me know if we still need to track this.