From bb6cc089074a1ba6c7c8250b1c2c078ff887ec7c Mon Sep 17 00:00:00 2001 From: Daniel Griesser Date: Fri, 27 Mar 2020 10:07:24 +0100 Subject: [PATCH 1/3] ref: Add child run to test webpack build --- packages/node/package.json | 2 +- .../test/manual/webpack-domain/npm-build.js | 46 +++++++++++++++++++ .../manual/webpack-domain/webpack.config.js | 10 ---- 3 files changed, 47 insertions(+), 11 deletions(-) create mode 100644 packages/node/test/manual/webpack-domain/npm-build.js delete mode 100644 packages/node/test/manual/webpack-domain/webpack.config.js 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..01ac1ffc8c1a --- /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'); + +webpack( + { + entry: './index.js', + output: { + path: path.resolve(__dirname, 'dist'), + filename: 'bundle.js', + }, + target: 'node', + mode: 'development', + }, + (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 From 324a9a7770fd6bdefb514712b474fe483c10169d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Og=C3=B3rek?= Date: Fri, 27 Mar 2020 10:14:15 +0100 Subject: [PATCH 2/3] fix: Restore dynamicRequire but for perf_hooks only --- packages/browser/test/package/npm-build.js | 7 +++---- packages/utils/src/misc.ts | 13 +++++++++++-- 2 files changed, 14 insertions(+), 6 deletions(-) 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/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; From e44fe4565a68a23c02df7ab967a5b26f0bbe45de Mon Sep 17 00:00:00 2001 From: Daniel Griesser Date: Fri, 27 Mar 2020 10:30:24 +0100 Subject: [PATCH 3/3] fix: Tests on node6 --- packages/node/test/manual/webpack-domain/npm-build.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/node/test/manual/webpack-domain/npm-build.js b/packages/node/test/manual/webpack-domain/npm-build.js index 01ac1ffc8c1a..923d437212c5 100644 --- a/packages/node/test/manual/webpack-domain/npm-build.js +++ b/packages/node/test/manual/webpack-domain/npm-build.js @@ -2,6 +2,7 @@ const path = require('path'); const webpack = require('webpack'); const { execSync } = require('child_process'); +// prettier-ignore webpack( { entry: './index.js', @@ -12,7 +13,7 @@ webpack( target: 'node', mode: 'development', }, - (err, stats) => { + function(err, stats) { if (err) { console.error(err.stack || err); if (err.details) { @@ -32,14 +33,13 @@ webpack( console.warn(info.warnings); process.exit(1); } - runTests(); - }, + } ); function runTests() { try { - execSync(`node ${path.resolve(__dirname, 'dist', 'bundle.js')}`); + execSync('node ' + path.resolve(__dirname, 'dist', 'bundle.js')); } catch (_) { process.exit(1); }