Skip to content

Commit 8911065

Browse files
committed
Bundle error tracking too
1 parent 354dfd0 commit 8911065

File tree

3 files changed

+28
-22
lines changed

3 files changed

+28
-22
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,7 @@
112112
"@oclif/command",
113113
"@oclif/config",
114114
"@oclif/plugin-help",
115-
"@oclif/plugin-update",
116-
"@sentry/node"
115+
"@oclif/plugin-update"
117116
],
118117
"update": {
119118
"s3": {

src/commands/start.ts

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
1-
import { initErrorTracking } from '../error-tracking';
2-
initErrorTracking();
1+
// Import types only from TS
2+
import * as ErrorTrackingModule from '../error-tracking';
3+
import * as IndexTypeModule from '../index';
34

45
import { IS_PROD_BUILD } from '../util';
56

6-
import { Command, flags } from '@oclif/command'
7-
8-
import { runHTK as runHTKFunction } from '../index';
9-
10-
let runHTK: typeof runHTKFunction;
11-
if (IS_PROD_BUILD || process.env.OCLIF_TS_NODE === '0') {
12-
// Full package: try to explicitly load the bundle
13-
try {
14-
({ runHTK } = require('../../bundle/index'));
15-
} catch (e) {
16-
// Fallback (bundle is not yet included in real package)
17-
console.log('Could not load bundle, loading raw');
18-
({ runHTK } = require('../index'));
7+
function maybeBundleImport<T>(moduleName: string): T {
8+
if (IS_PROD_BUILD || process.env.OCLIF_TS_NODE === '0') {
9+
// Full package: try to explicitly load the bundle
10+
try {
11+
return require('../../bundle/' + moduleName);
12+
} catch (e) {
13+
// Fallback (bundle is included in real package)
14+
console.log(`Could not load bundle ${moduleName}, loading raw`);
15+
return require('../' + moduleName);
16+
}
17+
} else {
18+
// Npm or dev: run the raw code
19+
return require('../' + moduleName);
1920
}
20-
} else {
21-
// Npm or dev: run the raw code
22-
({ runHTK } = require('../index'));
2321
}
22+
const { initErrorTracking } = maybeBundleImport<typeof ErrorTrackingModule>('error-tracking');
23+
initErrorTracking();
24+
25+
import { Command, flags } from '@oclif/command'
26+
27+
const { runHTK } = maybeBundleImport<typeof IndexTypeModule>('index');
2428

2529
class HttpToolkitServer extends Command {
2630
static description = 'start the HTTP Toolkit server'

webpack.config.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ const path = require('path');
33
const CopyWebpackPlugin = require('copy-webpack-plugin');
44

55
module.exports = {
6-
entry: './src/index.ts',
6+
entry: {
7+
index: './src/index.ts',
8+
'error-tracking': './src/error-tracking.ts'
9+
},
710
output: {
811
path: path.resolve(__dirname, 'bundle'),
9-
filename: 'index.js',
12+
filename: '[name].js',
1013
libraryTarget: 'commonjs2'
1114
},
1215
mode: 'production',

0 commit comments

Comments
 (0)