diff --git a/packages/browser/test/package/npm-build.js b/packages/browser/test/package/npm-build.js index c93d6ed6f68a..a596ba3f9fab 100644 --- a/packages/browser/test/package/npm-build.js +++ b/packages/browser/test/package/npm-build.js @@ -2,7 +2,7 @@ const fs = require('fs'); const path = require('path'); const webpack = require('webpack'); const { JSDOM } = require('jsdom'); -// runTests(); + webpack( { entry: path.join(__dirname, 'test-code.js'), @@ -10,9 +10,6 @@ webpack( path: __dirname, filename: 'tmp.js', }, - // resolve: { - // mainFields: ['main'], - // }, mode: 'development', }, (err, stats) => { @@ -28,10 +25,12 @@ webpack( if (stats.hasErrors()) { console.error(info.errors); + process.exit(1); } if (stats.hasWarnings()) { console.warn(info.warnings); + process.exit(1); } runTests(); diff --git a/packages/node/package.json b/packages/node/package.json index e8c5c6e571e9..375e2f4fe0f6 100644 --- a/packages/node/package.json +++ b/packages/node/package.json @@ -60,7 +60,7 @@ "test:jest": "jest", "test:watch": "jest --watch", "test:express": "node test/manual/express-scope-separation/start.js", - "test:webpack": "cd test/manual/webpack-domain/ && yarn && yarn webpack && node dist/bundle.js", + "test:webpack": "cd test/manual/webpack-domain/ && yarn && node npm-build.js", "version": "node ../../scripts/versionbump.js src/version.ts" }, "jest": { diff --git a/packages/node/test/manual/webpack-domain/npm-build.js b/packages/node/test/manual/webpack-domain/npm-build.js new file mode 100644 index 000000000000..923d437212c5 --- /dev/null +++ b/packages/node/test/manual/webpack-domain/npm-build.js @@ -0,0 +1,46 @@ +const path = require('path'); +const webpack = require('webpack'); +const { execSync } = require('child_process'); + +// prettier-ignore +webpack( + { + entry: './index.js', + output: { + path: path.resolve(__dirname, 'dist'), + filename: 'bundle.js', + }, + target: 'node', + mode: 'development', + }, + function(err, stats) { + if (err) { + console.error(err.stack || err); + if (err.details) { + console.error(err.details); + } + return; + } + + const info = stats.toJson(); + + if (stats.hasErrors()) { + console.error(info.errors); + process.exit(1); + } + + if (stats.hasWarnings()) { + console.warn(info.warnings); + process.exit(1); + } + runTests(); + } +); + +function runTests() { + try { + execSync('node ' + path.resolve(__dirname, 'dist', 'bundle.js')); + } catch (_) { + process.exit(1); + } +} diff --git a/packages/node/test/manual/webpack-domain/webpack.config.js b/packages/node/test/manual/webpack-domain/webpack.config.js deleted file mode 100644 index 14cefa405417..000000000000 --- a/packages/node/test/manual/webpack-domain/webpack.config.js +++ /dev/null @@ -1,10 +0,0 @@ -const path = require('path'); - -module.exports = { - entry: './index.js', - output: { - path: path.resolve(__dirname, 'dist'), - filename: 'bundle.js' - }, - target: "node", -}; \ No newline at end of file diff --git a/packages/utils/src/misc.ts b/packages/utils/src/misc.ts index 28eed98dc1f0..cc63caa8f165 100644 --- a/packages/utils/src/misc.ts +++ b/packages/utils/src/misc.ts @@ -20,6 +20,16 @@ interface SentryGlobal { }; } +/** + * Requires a module which is protected against bundler minification. + * + * @param request The module path to resolve + */ +export function dynamicRequire(mod: any, request: string): any { + // tslint:disable-next-line: no-unsafe-any + return mod.require(request); +} + /** * Checks whether we're in the Node.js or Browser environment * @@ -365,8 +375,7 @@ const performanceFallback: CrossPlatformPerformance = { export const crossPlatformPerformance: CrossPlatformPerformance = (() => { if (isNodeEnv()) { try { - const req = require; - const perfHooks = req('perf_hooks') as { performance: CrossPlatformPerformance }; + const perfHooks = dynamicRequire(module, 'perf_hooks') as { performance: CrossPlatformPerformance }; return perfHooks.performance; } catch (_) { return performanceFallback;