fix: use same global to inject process.hrtime

This commit is contained in:
Pooya Parsa 2020-11-13 19:05:45 +01:00
parent 989f6811c2
commit e8f52bd383

View File

@ -5,8 +5,8 @@ import { SLSTarget } from '../config'
const polyfill = ` const polyfill = `
const exports = {}; const exports = {};
const module = { exports }; const module = { exports };
const global = { process: {} }; const global = typeof globalThis !== 'undefined' ? globalThis : "undefined" !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
const window = global; global.process = global.process || {};
(function(){const o=Date.now(),t=()=>Date.now()-o;global.process.hrtime=o=>{const e=Math.floor(.001*(Date.now()-t())),n=.001*t();let a=Math.floor(n)+e,r=Math.floor(n%1*1e9);return o&&(a-=o[0],r-=o[1],r<0&&(a--,r+=1e9)),[a,r]};})(); (function(){const o=Date.now(),t=()=>Date.now()-o;global.process.hrtime=o=>{const e=Math.floor(.001*(Date.now()-t())),n=.001*t();let a=Math.floor(n)+e,r=Math.floor(n%1*1e9);return o&&(a-=o[0],r-=o[1],r<0&&(a--,r+=1e9)),[a,r]};})();
` `