k6 icon indicating copy to clipboard operation
k6 copied to clipboard

Drop aliasing `global` to `globalThis` in `extented` compatibility-mode

Open mstoykov opened this issue 1 year ago • 0 comments

What?

As of #3456 the only difference between base and extended compatibility-mode is that extended adds an alias for global that points to globalThis.

This only exists as this was what core-js did and when it was dropped it was readded in https://github.com/grafana/k6/pull/1845.

I don't remember if we had a particular user that complaint about this or not, but it has been a few years and globalThis is pretty much everywhere.

This also has been known to be used as a test if you are running in a browser or NodeJS like environment - which doesn't usually work great with k6.

Solution

Just stop aliasing it - making base and extented the same.

Counter points

The support for this is literally 3 lines

https://github.com/grafana/k6/blob/111985bfe258f1b68cc8d19c8b8a21737a5b4f89/js/bundle.go#L387-L392 it doesn't really add much

Arguably removing this will require us to explain why extended and base are the same thing :sweat_smile:

This being used

The only thing I know about that this is being used for is k6chaijs which is due to dependancy.

https://github.com/chaijs/type-detect which is part of chaijs is using it instead of globalThis a patch for this has been done years ago, but no new version has been released in 7 years.

https://github.com/chaijs/type-detect/issues/146 asked for it to be bumped few years ago, and it might be good idea for us to go ahead and start this rolling

I would argue that this is blocking this specifically from going forward, but once this is done we can think about it more.

Related issues

#3860

mstoykov avatar Jul 19 '24 09:07 mstoykov