Closed cataggar closed 3 weeks ago
I think you need to export the resource class explicitly on the canvas interface like:
export const canvas = { tsVersion, CompilerOptions };
Unfortunately, it is still failing with not a valid resource function
:
$ bunx jco componentize cowsay.js --wit src/cowsay.wit -o cowsay.wasm
(jco componentize) ComponentError: failed to encode a component from module
$failed to decode world from module
Caused by:
0: module was not valid
1: import of `[resource-new]compilerOptions` is not a valid resource function
at componentNew (file:///Users/cataggar/ms/jco/obj/wasm-tools.js:3714:11)
at componentNew (file:///Users/cataggar/ms/jco/src/api.js:37:10)
at async componentize (file:///Users/cataggar/ms/ComponentizeJS/src/componentize.js:381:5)
at async componentize (file:///Users/cataggar/ms/jco/src/cmd/componentize.js:11:25)
at async file:///Users/cataggar/ms/jco/src/jco.js:200:9
error: script "componentize" exited with code 1
The cowsay.wit is the same, but I updated cowsay.ts to be:
// import * as ts from 'typescript';
export function test() {
return "ok";
}
class CompilerOptions {
inner;
constructor() {
this.inner = 3;
}
}
function tsVersion() {
// return ts.version;
return "5.2";
}
export const canvas = {
tsVersion,
CompilerOptions
};
Is there something incompatible with the generated JavaScript?
// src/cowsay.ts
function test() {
return "ok";
}
function tsVersion() {
return "5.2";
}
class CompilerOptions {
inner;
constructor() {
this.inner = 3;
}
}
var canvas = {
tsVersion,
CompilerOptions
};
export {
test,
canvas
};
I'm wondering if this is a camel casing issue - if you use a resource name that is a single word, like Compileroptions
instead, does it work then?
Yes, that is it. Thank you!
Thanks for confirming, filed as a ComponentizeJS bug.
I was reviewing code this evening. Is crates/spidermonkey-embedding-splicer/src/bindgen.rs
the right place for this functionality?
It should be, yes.
I wasn't unable to hunt this one down. Would it help if I attached the generated sources?
I've been trying to make my first resource definition. I keep getting an error message that my
compilerOptions
resource function is not valid.Here is my cowsay.wit where I'm trying to define an empty
resource compiler-options
:Here is my cowsay.ts where I'm trying to define it: