mswjs / interceptors

Low-level network interception library.
https://npm.im/@mswjs/interceptors
MIT License
535 stars 120 forks source link

Replace "uuid" with "crypto.randomUUID()" #470

Closed kettanaito closed 5 months ago

kettanaito commented 10 months ago

Node.js ships with the built-in way to generate UUID via the node:crypto module. We should remove the uuid dependency and use node:crypto instead.

hpohlmeyer commented 10 months ago

Since #471 is closed now, I am adding the comment here as well:

Using node:crypto would break browser compatibility. As far as I know msw uses this package to defer requests until the service worker has been registered, so browser compatibility is still needed.

Using crypto.randomUUID() work on https-sites, but cannot be used on http-sites, because crypto is undefined there.

kettanaito commented 5 months ago

@hpohlmeyer, thanks for the context around the pull request.

Using node:crypto would break browser compatibility.

True. However, both Node.js and browsers ships a global crypto object that has the .randomUIUD() method. This code runs the same in the browser and in Node.js:

crypto.randomUUID()

We don't need to import node:crypto at all!

Using crypto.randomUUID() work on https-sites, but cannot be used on http-sites, because crypto is undefined there.

This is out of the scope of this package. None of the interceptors are meant to be deployed to production. I don't treat this as a blocker.

kettanaito commented 5 months ago

Released: v0.26.12 🎉

This has been released in v0.26.12!

Make sure to always update to the latest version (npm i @mswjs/interceptors@latest) to get the newest features and bug fixes.


Predictable release automation by @ossjs/release.