Skip to content
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

Q: Is there interest in adding more assertion libraries? #22

Open
wooorm opened this issue Oct 8, 2021 · 12 comments
Open

Q: Is there interest in adding more assertion libraries? #22

wooorm opened this issue Oct 8, 2021 · 12 comments

Comments

@wooorm
Copy link

wooorm commented Oct 8, 2021

Background

I’m using assertions in micromark. It’s a complex parser using state machines. It’s also extendable with plugins. So assertions makes it much easier to reason about.

I’m using an export map to differentiate between code that does have assertions, and code that doesn’t: https://github.com/micromark/micromark/blob/a03a08ce677b91a2960be2f4fcaacd64b3b8ec18/packages/micromark/package.json#L55-L58. Most people will get unasserted files. With node --conditions development, code with assertions is loaded. This is very useful when making plugins.

Problem

  • However, some browser bundlers (Vite, webpack), don’t load assert normally. While users can configure their bundlers, micromark is often used through many other packages, and I’d rather have everything just work by default
  • power-assert contains tons of code and also doesn’t bundle well in at least webpack.

Solution

  • I could either create a new, small, typed assert library, or perhaps use something like uvu/assert
  • Is unassert interested in adding support for more libraries, and if so, what are the requirements?

I can do the work on adding one.

/cc @twada

Related-to: micromark/micromark#87, micromark/micromark#95.

@falsandtru
Copy link

Have you tried to change the options?

https://github.com/unassert-js/unassert#options

@wooorm
Copy link
Author

wooorm commented Oct 8, 2021

Ah. Thanks and sorry.

My question is most specifically about https://github.com/unassert-js/babel-plugin-unassert/blob/210a5c6e45c0c3d6d963f6f21efcf9d0094f177e/index.js#L29, because I’m using that, and I don’t think it has such an option. I posted it here as this was more a question for the whole unassert org

@wooorm
Copy link
Author

wooorm commented Oct 8, 2021

But if there’s an option here already, then there could perhaps also be an option there to allow other values than ['assert', 'node:assert', 'power-assert']?

@twada
Copy link
Member

twada commented Oct 8, 2021

Hello @wooorm, and thanks to @falsandtru. That's a nice suggestion and relatively easy add some import/require options to babel-plugin-unassert. I'll work on it.

@falsandtru
Copy link

Can you support options also with gulp-unassert?

@twada
Copy link
Member

twada commented Oct 8, 2021

@falsandtru Yes. I'll support it. (maybe after #21 or before it since #21 is a little difficult one)

@falsandtru
Copy link

Thanks.

@wooorm
Copy link
Author

wooorm commented Oct 8, 2021

This is a very pressing issue for me btw, so I can do the work to support it in the babel plugin if that means it can then be released soonish?

@twada
Copy link
Member

twada commented Oct 8, 2021

@wooorm I mean adding options to babel-plugin-unassert is reatively easy, so it will be released soon. Adding options to gulp-unassert is slightly difficult (due to the blocking issue).

@wooorm
Copy link
Author

wooorm commented Oct 8, 2021

ah okay, thanks <3

@twada
Copy link
Member

twada commented Oct 8, 2021

@wooorm babel-plugin-unassert v3.2.0 is out. Thank you for your suggestion!

Release v3.2.0: customization options (2021-10-09)

@wooorm
Copy link
Author

wooorm commented Oct 8, 2021

That's awesome! Thank you! 🌸

wooorm added a commit to micromark/micromark that referenced this issue Oct 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants