Skip to content

Commit 04ebb8e

Browse files
committed
Fix bundling for MCP/CTL commands
1 parent 6f7097c commit 04ebb8e

File tree

4 files changed

+32
-8
lines changed

4 files changed

+32
-8
lines changed

pack.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ const packageApp = async () => {
5151
// Add the fully bundled source (not normally packaged by npm):
5252
path.join('bundle', 'index.js'),
5353
path.join('bundle', 'error-tracking.js'),
54+
path.join('bundle', 'api', 'bridge-client.js'),
5455
// Static resources normally stored in browser-launcher
5556
path.join('bundle', 'bl-resources')
5657
].map((extraFile) =>

rspack.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ console.log(
1515
module.exports = {
1616
entry: {
1717
index: './src/index.ts',
18-
'error-tracking': './src/error-tracking.ts'
18+
'error-tracking': './src/error-tracking.ts',
19+
'api/bridge-client': './src/api/bridge-client.ts'
1920
},
2021
output: {
2122
path: OUTPUT_DIR,

src/commands/ctl.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
1+
type BridgeClientModule = typeof import('../api/bridge-client');
2+
13
import { parseArgs } from 'util';
24

35
import { Command } from '@oclif/command';
46

5-
import { apiRequest } from '../api/bridge-client';
6-
import { HtkOperation } from '../api/ui-operation-bridge';
7+
import { IS_PROD_BUILD } from '../constants';
8+
import type { HtkOperation } from '../api/ui-operation-bridge';
9+
10+
function maybeBundleImport<T>(moduleName: string): T {
11+
if (IS_PROD_BUILD || process.env.OCLIF_TS_NODE === '0') {
12+
return require('../../bundle/' + moduleName);
13+
} else {
14+
return require('../' + moduleName);
15+
}
16+
}
17+
18+
const { apiRequest } = maybeBundleImport<BridgeClientModule>('api/bridge-client');
719

820
// Custom argument parsing setup. Included here as Oclif's parsing can't handle the dynamic command
921
// config (commands defined by the UI itself) and the logic isn't quite complex enough for a separate dep.

src/commands/mcp.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
1+
type BridgeClientModule = typeof import('../api/bridge-client');
2+
13
import * as readline from 'readline';
24
import { execFile } from 'child_process';
35

46
import { Command, flags } from '@oclif/command';
5-
import { delay } from '@httptoolkit/util';
67

7-
import { SERVER_VERSION } from '../constants';
8-
import { apiRequest } from '../api/bridge-client';
9-
import { HtkOperation } from '../api/ui-operation-bridge';
8+
import { IS_PROD_BUILD, SERVER_VERSION } from '../constants';
9+
import type { HtkOperation } from '../api/ui-operation-bridge';
10+
11+
function maybeBundleImport<T>(moduleName: string): T {
12+
if (IS_PROD_BUILD || process.env.OCLIF_TS_NODE === '0') {
13+
return require('../../bundle/' + moduleName);
14+
} else {
15+
return require('../' + moduleName);
16+
}
17+
}
18+
19+
const { apiRequest } = maybeBundleImport<BridgeClientModule>('api/bridge-client');
1020

1121
interface JsonRpcRequest {
1222
jsonrpc: '2.0';
@@ -88,7 +98,7 @@ async function startHttpToolkit(
8898
// Wait for the UI to connect and send operations
8999
const deadline = Date.now() + LAUNCH_TIMEOUT_MS;
90100
while (Date.now() < deadline) {
91-
await delay(LAUNCH_POLL_MS);
101+
await new Promise(resolve => setTimeout(resolve, LAUNCH_POLL_MS));
92102
await refreshOperations();
93103
try {
94104
const status = await apiRequest('GET', '/api/status');

0 commit comments

Comments
 (0)