-
Notifications
You must be signed in to change notification settings - Fork 278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Package STT wasm for npm publishing #2265
Conversation
@@ -0,0 +1,14 @@ | |||
{ | |||
"name" : "$(PROJECT_NAME)", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you test the packaged library to see if it's possible to use it from within an NPM-based project?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did test it with an example I would like to contribute eventually to stt-examples
but I think it is a good idea to test it in the CI pipeline as well. I'll add a test step for it.
native_client/BUILD
Outdated
linkopts = select({ | ||
":wasm_es6": DECODER_LINKOPTS_WASM + [ | ||
"-sEXPORT_ES6=1", | ||
"-sSINGLE_FILE=1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you kindly add a comment here explaining why, even though we have SINGLE_FILE
here, it's producing multiple files? (because of the "pthread" story you mentioned, right?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SINGLE_FILE
exists since before pthread support and it currently only inlines the wasm bytecode as a base64 string inside the main JS. Pthreads are implemented as separate (smaller) workers which actually load the main JS from within. There are some requests to inline or merge both files when using SINGLE_FILE
(see emscripten#9796 and emscripten#14329)
Generally, as noted in the references above, using SINGLE_FILE
generates a large asset (larger than the sum of both stt_wasm.js
and stt_wasm.wasm
), which means longer download and startup times. Blinded by the original goal of making it available via CDN, I thought it would be necessary to inline the wasm binary for ease of use as a library, but I just tested it and webpack can handle the separate asset perfectly (rollup should also be fine; I am not sure about parcel, but I guess it'd also work.)
I will thus remove this flag. At this point we could consider dropping es5 support (ES6 is necessary for bundlers, see emscripten#14135) but ES6 imports are still not supported in workers under Firefox (reference) so I would still add it to the github releases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, I agree with what you outlined. Thank you for the thorough explaination !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! I have a couple of comments inline, and would like to get answers to the questions by @Dexterp37 as well.
Is the ES6 package supposed to be so much smaller than the other one? |
No, I forgot to push a change to the Makefile to include the wasm binary. I can do it later. |
I added a test step for the wasm npm module but struggled with testing the library itself (it currently only tests that it is installed). I am only familiar with jest, which runs tests inside node and thus ES6 modules need to be transpiled to CommonJS (I tried unsuccessfully to run the ES6 modules with the experimental
which breaks the module and does not manage to load successfully. That is why I had to skip the test that actually tests that the library loads and can be used. I also tried the jsdom environment in jest, which emulates a browser but inside Maybe someone else can extend the tests in the future (maybe it should be tested with something such as cypress?). As I wrote, for now it only tests that the library is installed and can be imported. |
Opened a clone of this PR here to test my fixes. |
No description provided.