Skip to content

Commit

Permalink
fix(hcl2json): do not always overwrite global.performance
Browse files Browse the repository at this point in the history
new node version already have a performance global, see
https://nodejs.org/api/globals.html#performance

it contains many methods, see https://nodejs.org/api/perf_hooks.html

when always overwriting it, other modules like `undici` which use
the performance object won't work any more. in genera using the
performance object become sunusable as soon as the `@cdktf/hcl2json`
package is required.

discussion/bug: renovatebot/renovate#22615
  • Loading branch information
robertkowalski committed Jun 8, 2023
1 parent a03bc2d commit 43a7212
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/@cdktf/hcl2json/wasm/bridge_wasm_exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ globalThis.fs = require("fs");
globalThis.TextEncoder = require("util").TextEncoder;
globalThis.TextDecoder = require("util").TextDecoder;

globalThis.performance = {
now() {
if (!globalThis.performance) {
globalThis.performance = {}
}

if (!globalThis.performance.now) {
globalThis.performance.now = function() {
const [sec, nsec] = process.hrtime();
return sec * 1000 + nsec / 1000000;
},
};
}
}

// Node >= 19 has a crypto function object, lower node versions need this polyfill
if (!globalThis.crypto) {
Expand Down

0 comments on commit 43a7212

Please sign in to comment.