seek-oss / sku

Front-end development toolkit
https://seek-oss.github.io/sku
MIT License
479 stars 35 forks source link

Add support for removing functions named `invariant` and assertions from `tiny-invariant` #966

Closed askoufis closed 5 months ago

askoufis commented 5 months ago

Support invariant function and tiny-invariant library

tiny-invariant is a small, 0 dependency assertion library. The standard way of importing its assertion function is to name it invariant, which is why I added it to the variables config for babel-plugin-unassert.

[!NOTE] Technically this changes removes support for removing assertions from power-assert, because we're now overriding the default config. There is no internal usage of power-assert that I'm aware of, so not marking this change as breaking.

Why should we support tiny-invariant?

For dev-time assertions in the browser, usually we'd reach for the assert library. This is what Braid uses. However, it has an unnecessarily large dependency graph for an assertion library.

Hopefully we can eventually replace assert with tiny-invariant within Braid. Part of that involves supporting an alternative assertion library in sku. Not sure when the change in Braid will happen, as it depends on consumers using a version of sku that supports tiny-invariant (i.e. whatever version this change is released in).

Tradeoffs between assert and tiny-invariant

assert supports checking non-primitive values, has more useful error messages, and offers various assertion functions. tiny-invariant just asserts on a user-provided condition, throwing an error if it fails. That's it. This is likely suitable for most use cases, and will probably work just fine in Braid and most front-end apps/libraries.

Meme

Show ![drug eyes polyfills meme](https://github.com/seek-oss/sku/assets/5663042/90194631-73c2-459c-b28a-55719d5c5fab)
changeset-bot[bot] commented 5 months ago

🦋 Changeset detected

Latest commit: d844d57e1f356ed850a0af062c0b2fd3edaf191b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package | Name | Type | | ---- | ----- | | sku | Minor |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR