Skip to content

Commit c873725

Browse files
authored
fix(cli): replace createRequire with static import for teammate.js (Gitlawb#1026) (Gitlawb#1033)
In commit 1f66d32, require() was changed to createRequire(). While this likely fixed an ESM warning in tests, createRequire bypasses the Bun bundler. As a result, teammate.js was no longer inlined into dist/cli.mjs. At runtime in the published npm package, this resolves to <root>/utils/teammate.js, but utils/ is not included in the npm files array, causing a crash on startup. Replaced with a static import. The original comment regarding a circular dependency is stale, as teammate.ts only relies on an import type from AppState.ts which gets erased at compile time.
1 parent 00263c5 commit c873725

1 file changed

Lines changed: 2 additions & 8 deletions

File tree

src/state/AppStateStore.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Notification } from 'src/context/notifications.js'
2-
import { createRequire } from 'node:module'
2+
import { isTeammate, isPlanModeRequired } from '../utils/teammate.js'
33
import type { TodoList } from 'src/utils/todo/types.js'
44
import type { BridgePermissionCallbacks } from '../bridge/bridgePermissionCallbacks.js'
55
import type { Command } from '../commands.js'
@@ -457,14 +457,8 @@ export type AppStateStore = Store<AppState>
457457

458458
export function getDefaultAppState(): AppState {
459459
// Determine initial permission mode for teammates spawned with plan_mode_required
460-
// Use lazy require to avoid circular dependency with teammate.ts
461-
const runtimeRequire = createRequire(import.meta.url)
462-
/* eslint-disable @typescript-eslint/no-require-imports */
463-
const teammateUtils =
464-
runtimeRequire('../utils/teammate.js') as typeof import('../utils/teammate.js')
465-
/* eslint-enable @typescript-eslint/no-require-imports */
466460
const initialMode: PermissionMode =
467-
teammateUtils.isTeammate() && teammateUtils.isPlanModeRequired()
461+
isTeammate() && isPlanModeRequired()
468462
? 'plan'
469463
: 'default'
470464

0 commit comments

Comments
 (0)