Skip to content
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

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/legacy/setup-cpp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/legacy/setup-cpp.js.map

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@
"util.types",
"web-streams-polyfill",
"timers-browserify",
"fs-extra"
"fs-extra",
"randomuuid-polyfill"
],
"engines": {
"node": ">=12.x",
Expand Down
2 changes: 1 addition & 1 deletion src/utils/compat/crypto/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ export * from "crypto"
import * as crypto from "crypto"
export default crypto

export { randomUUID } from "randomuuid-polyfill"
export { randomUUID } from "./randomuuid.mjs"
31 changes: 31 additions & 0 deletions src/utils/compat/crypto/randomuuid.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// from https://www.npmjs.com/package/randomuuid-polyfill

import { performance } from "perf_hooks"

// Adapted from https://stackoverflow.com/a/8809472/2993077
if (!global.crypto?.randomUUID) {
if (!global.crypto) {
global.crypto = {}
}

global.crypto.randomUUID = () => {
let date = new Date().getTime()
let performanceNow = performance.now() * 1000

// cspell:disable-next-line
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, char => {
let random = Math.random() * 16
if (date > 0) {
random = (date + random) % 16 | 0
date = Math.floor(date / 16)
} else {
random = (performanceNow + random) % 16 | 0
performanceNow = Math.floor(performanceNow / 16)
}
return (char === "x" ? random : (random & 0x3 | 0x8)).toString(16)
})
}
}

const randomUUID = global.crypto.randomUUID.bind(global.crypto)
export { randomUUID }
Loading