cats-effect icon indicating copy to clipboard operation
cats-effect copied to clipboard

Use `js.typeOf` checks for JS feature tests instead of try/catch

Open armanbilge opened this issue 3 years ago • 1 comments
trafficstars

This is my fault. I've been lazily using Try(js.Dynamic.global....) when I should be writing idiomatic code like this: https://github.com/typelevel/cats-effect/blob/76d2602ea651a6f0035bef4f9aa506773a335c95/std/js/src/main/scala/cats/effect/std/JavaSecureRandom.scala#L77-L78

Today in the Discord there were reports of ReferenceError: Can't find variable: process. So time to fix this.

armanbilge avatar May 19 '22 13:05 armanbilge

So I forgot, there was a reason for this besides my laziness.

  1. Said webpack plugin is essentially doing a text replacement of process.env.CATS_EFFECT_TRACING_MODE with the desired value. Note that defining process.env.CATS_EFFECT_TRACING_MODE in webpack will not define process nor process.env.

https://github.com/typelevel/cats-effect/pull/2207#issuecomment-899543589

The problem is that some env-setting bundler tooling expects it to be written in full form, so laddered undefined checks will not work 😕

armanbilge avatar May 20 '22 13:05 armanbilge