AssemblyScript/assemblyscript

Glue file .mjs extension

LeXXik opened this issue · 4 comments

LeXXik commented

Question

After building the project, I get release.wasm and release.js. The built library is a module. The runtime environment where it will be executed has a hard requirement for modules to have .mjs file extension. I can't seem to find from the docs how can I make it to generate the glue file release.js with that extension. For now, I have to manually change it after the build.

a-skua commented

The .mjs file extension is sometimes a requirement in Node.js, but I believe it is not always necessary.

The .mjs file extension is sometimes a requirement in Node.js, but I believe it is not always necessary.

It’s necessary when the project type is not set to module - which isn’t always feasible to do.

@LeXXik you could separate the assemblyscript to its own package and reference that in the current project. I’m pretty sure it’s possible to have regular js extensions in imported packages (otherwise dependencies more often wouldn’t work), but it might require some tinkering.

Alternatively you can build through the js api and rename the glue file, or set up a watcher that renames it.

Would be nice if the option existed, but at least there are ways so you don’t have to manually rename it every time.

@LeXXik Even simpler, you could just edit the build commands in your package.json, like this :

"asbuild:debug": "asc assembly/index.ts --target debug && cp ./build/debug.js ./build/debug.mjs",

Edit the paths as needed, and use mv instead of cp if you prefer.

LeXXik commented

Thank you! I should have thought of using cp/mv. This answers my needs.