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

feat: use native crypto.randomUUID when available #600

Merged
merged 4 commits into from
Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions bundlewatch.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
{ "path": "./examples/browser-rollup/dist/v4-size.js", "maxSize": "0.7 kB" },
{ "path": "./examples/browser-rollup/dist/v5-size.js", "maxSize": "1.5 kB" },

{ "path": "./examples/browser-webpack/dist/v1-size.js", "maxSize": "1.3 kB" },
{ "path": "./examples/browser-webpack/dist/v3-size.js", "maxSize": "2.5 kB" },
{ "path": "./examples/browser-webpack/dist/v4-size.js", "maxSize": "1.0 kB" },
{ "path": "./examples/browser-webpack/dist/v5-size.js", "maxSize": "1.9 kB" }
{ "path": "./examples/browser-webpack/dist/v1-size.js", "maxSize": "1.0 kB" },
{ "path": "./examples/browser-webpack/dist/v3-size.js", "maxSize": "2.1 kB" },
{ "path": "./examples/browser-webpack/dist/v4-size.js", "maxSize": "0.7 kB" },
{ "path": "./examples/browser-webpack/dist/v5-size.js", "maxSize": "1.5 kB" }
Comment on lines -8 to +11
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not strictly related to this PR but I noticed since I was working a lot with bundlewatch. It seems like WebPack got better with time and now matches the output size that Rollup gives us, so lowered these values to be the same for both.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

]
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"module": "./dist/esm-node/index.js",
"browser": {
"./dist/md5.js": "./dist/md5-browser.js",
"./dist/native.js": "./dist/native-browser.js",
"./dist/rng.js": "./dist/rng-browser.js",
"./dist/sha1.js": "./dist/sha1-browser.js",
"./dist/esm-node/index.js": "./dist/esm-browser/index.js"
Expand Down
4 changes: 4 additions & 0 deletions src/native-browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const randomUUID =
typeof crypto !== 'undefined' && crypto.randomUUID && crypto.randomUUID.bind(crypto);

export default { randomUUID };
3 changes: 3 additions & 0 deletions src/native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import crypto from 'crypto';

export default { randomUUID: crypto.randomUUID };
5 changes: 5 additions & 0 deletions src/v4.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import native from './native.js';
import rng from './rng.js';
import stringify from './stringify.js';

function v4(options, buf, offset) {
if (native.randomUUID && !buf && !options) {
return native.randomUUID();
}

options = options || {};

const rnds = options.random || (options.rng || rng)();
Expand Down
9 changes: 9 additions & 0 deletions wdio.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,22 @@ const capabilities = [
},

// Chrome
// Chrome 92 introduced native support for crypto.randomUUID
{
...commonCapabilities,
browserName: 'Chrome',
browser_version: '92.0',
os: 'Windows',
os_version: '10',
},
{
...commonCapabilities,
browserName: 'Chrome',
browser_version: '81.0',
os: 'Windows',
os_version: '10',
},
// Chrome 49 released on 2016-03-02 was the last version supported on Windows XP, Windows Vista, Mac OS X 10.6, 10.7, and 10.8
{
...commonCapabilities,
browserName: 'Chrome',
Expand Down