|
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'; |
3 | 4 |
|
4 | 5 | import { IS_PROD_BUILD } from '../util'; |
5 | 6 |
|
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); |
19 | 20 | } |
20 | | -} else { |
21 | | - // Npm or dev: run the raw code |
22 | | - ({ runHTK } = require('../index')); |
23 | 21 | } |
| 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'); |
24 | 28 |
|
25 | 29 | class HttpToolkitServer extends Command { |
26 | 30 | static description = 'start the HTTP Toolkit server' |
|
0 commit comments