inukshuk/edtf.js

Use unassert to remove assert in release builds

tarjelavik opened this issue · 6 comments

Hi!
Me again :-/. Would you consider merging in the changes in the fork by @uf0? unassert was added to enable a build for the browser.

Changes here: main...uf0:edtf.js:main

I did the same changes in my fork, but that was for learning purposes.

Hm, that's something we'd have to look at in more detail. I think assertions are sometimes used to throw meaningful error messages, so I'd probably look into replacing them with a built-in function (either outright or via rollup replace plugin) instead of just removing them.

Yeah, i guess there is more to it :-). I am not an expert, but it seems to me that assert is mostly used in tests? There is also the isomorphic-assert library, if that helps.

I really appreciate your work on EDTF for javascript, but i have used the forks that has done changes for running in the browser. I would rather use your library of course :-).

Is assert the only obstacle to having the parser run in the browser?

Mmm, by testing your package vs uf0's repo it seemed like it. As far as i know assert is Node only....

OK I pushed 4.5.0 4.5.1 which uses a custom assert instead of the Node.js module. With this the ESM and CJS modules only import/require internal modules and the nearley package (which should work in the browser); the separate sample module entry point will also import randexp (I don't know if that one works in the browser).

Essentially, this means you should be able to use the main ESM entry point 'as is' in a browser, but you'll have to bundle everything (e.g. using rollup) of course.

Thx! I got it working, but yeah, bundling and all that is not my favorite topics. Had to work around that my plugins in turn is bundled into another app.
I'll revisit this later, but it works for now :-)