Skip to content

ref: Add child run to test webpack build #2524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions packages/browser/test/package/npm-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@ 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'),
output: {
path: __dirname,
filename: 'tmp.js',
},
// resolve: {
// mainFields: ['main'],
// },
mode: 'development',
},
(err, stats) => {
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion packages/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
46 changes: 46 additions & 0 deletions packages/node/test/manual/webpack-domain/npm-build.js
Original file line number Diff line number Diff line change
@@ -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);
}
}
10 changes: 0 additions & 10 deletions packages/node/test/manual/webpack-domain/webpack.config.js

This file was deleted.

13 changes: 11 additions & 2 deletions packages/utils/src/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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;
Expand Down