Skip to content

Commit

Permalink
fix: fix worker polyfill by adding performance
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Nov 10, 2020
1 parent f9e35f6 commit a30fed4
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/targets/worker.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { SLSTarget } from '../config'

// https://github.com/cabinjs/browser-hrtime
const hrTimeP = '!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).hrtime=n()}(this,(function(){"use strict";var e=function(e){!function(){if("performance"in window==0&&(window.performance={}),Date.now=Date.now||function(){return(new Date).getTime()},"now"in window.performance==0){var e=Date.now();performance.timing&&performance.timing.navigationStart&&(e=performance.timing.navigationStart),window.performance.now=function(){return Date.now()-e}}}();var n=Math.floor(.001*(Date.now()-performance.now())),o=.001*performance.now(),r=Math.floor(o)+n,i=Math.floor(o%1*1e9);return e&&(r-=e[0],(i-=e[1])<0&&(r--,i+=1e9)),[r,i]};return e.bigint=function(n){var o=e(n);return 1e9*o[0]+o[1]},"undefined"!=typeof process&&void 0!==process.hrtime||void 0!==window.process||(window.process={}),void 0===process.hrtime?window.process.hrtime=e:process.hrtime}));'
const polyfill = `
const exports = {};
const module = { exports };
const process = { env: {} };
const performance = {};
const cjsP = 'const exports = {}; const module = {exports};'
const processP = 'const process = {env: {}};'
const globalP = 'const global = { process }; const window = global;'
// https://github.com/cabinjs/browser-hrtime
'!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).hrtime=n()}(this,(function(){"use strict";var e=function(e){!function(){if("performance"in window==0&&(window.performance={}),Date.now=Date.now||function(){return(new Date).getTime()},"now"in window.performance==0){var e=Date.now();performance.timing&&performance.timing.navigationStart&&(e=performance.timing.navigationStart),window.performance.now=function(){return Date.now()-e}}}();var n=Math.floor(.001*(Date.now()-performance.now())),o=.001*performance.now(),r=Math.floor(o)+n,i=Math.floor(o%1*1e9);return e&&(r-=e[0],(i-=e[1])<0&&(r--,i+=1e9)),[r,i]};return e.bigint=function(n){var o=e(n);return 1e9*o[0]+o[1]},"undefined"!=typeof process&&void 0!==process.hrtime||void 0!==window.process||(window.process={}),void 0===process.hrtime?window.process.hrtime=e:process.hrtime}));'
const polyfill = cjsP + processP + globalP + hrTimeP
const global = { process };
const window = global;
`

export const worker: SLSTarget = {
entry: '{{ runtimeDir }}/worker',
Expand Down

0 comments on commit a30fed4

Please sign in to comment.