Skip to content

Commit 324a9a7

Browse files
committed
fix: Restore dynamicRequire but for perf_hooks only
1 parent bb6cc08 commit 324a9a7

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

packages/browser/test/package/npm-build.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@ const fs = require('fs');
22
const path = require('path');
33
const webpack = require('webpack');
44
const { JSDOM } = require('jsdom');
5-
// runTests();
5+
66
webpack(
77
{
88
entry: path.join(__dirname, 'test-code.js'),
99
output: {
1010
path: __dirname,
1111
filename: 'tmp.js',
1212
},
13-
// resolve: {
14-
// mainFields: ['main'],
15-
// },
1613
mode: 'development',
1714
},
1815
(err, stats) => {
@@ -28,10 +25,12 @@ webpack(
2825

2926
if (stats.hasErrors()) {
3027
console.error(info.errors);
28+
process.exit(1);
3129
}
3230

3331
if (stats.hasWarnings()) {
3432
console.warn(info.warnings);
33+
process.exit(1);
3534
}
3635

3736
runTests();

packages/utils/src/misc.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ interface SentryGlobal {
2020
};
2121
}
2222

23+
/**
24+
* Requires a module which is protected against bundler minification.
25+
*
26+
* @param request The module path to resolve
27+
*/
28+
export function dynamicRequire(mod: any, request: string): any {
29+
// tslint:disable-next-line: no-unsafe-any
30+
return mod.require(request);
31+
}
32+
2333
/**
2434
* Checks whether we're in the Node.js or Browser environment
2535
*
@@ -365,8 +375,7 @@ const performanceFallback: CrossPlatformPerformance = {
365375
export const crossPlatformPerformance: CrossPlatformPerformance = (() => {
366376
if (isNodeEnv()) {
367377
try {
368-
const req = require;
369-
const perfHooks = req('perf_hooks') as { performance: CrossPlatformPerformance };
378+
const perfHooks = dynamicRequire(module, 'perf_hooks') as { performance: CrossPlatformPerformance };
370379
return perfHooks.performance;
371380
} catch (_) {
372381
return performanceFallback;

0 commit comments

Comments
 (0)