11import { Module } from "module" ;
2- import path from "path" ;
3- import fs from "fs" ;
4- import os from "os" ;
2+ import * as path from "path" ;
3+ import * as fs from "fs" ;
4+ import * as os from "os" ;
55import { getFirebaseCliRoot } from "../runner/paths.js" ;
6- import { getToolMocks } from "./tool-mocks.js" ;
76
87//
98// This file is run as a node --import parameter before the Firebase CLI to
@@ -13,18 +12,31 @@ import { getToolMocks } from "./tool-mocks.js";
1312// Path to the built MCP Tools implementation in the Firebase CLI, relative to
1413// the repo's root
1514const MCP_TOOLS_INDEX_PATH = "lib/mcp/tools/index.js" ;
15+ const CONFIGSTORE_INDEX_PATH = "lib/mcp/configstore.js" ;
1616const LOG_FILE_PATH = path . join ( os . homedir ( ) , "Desktop" , "agent_evals_mock_logs.txt" ) ;
1717// Enable this to turn on file logging. This can be helpful for debugging
1818// because console logs get swallowed
1919const ENABLE_FILE_LOGGING = false ;
2020
21- const mocks = getToolMocks ( ) ;
22-
2321const originalRequire = Module . prototype . require ;
24- Module . prototype . require = function ( id : string ) {
22+ ( Module . prototype as any ) . require = function ( id : string ) {
2523 const requiredModule = originalRequire . apply ( this , [ id ] ) ;
2624 const absolutePath = Module . createRequire ( this . filename ) . resolve ( id ) ;
2725 const pathRelativeToCliRoot = path . relative ( getFirebaseCliRoot ( ) , absolutePath ) ;
26+ console . log ( `[DEBUG] Requiring: ${ pathRelativeToCliRoot } (Absolute: ${ absolutePath } )` ) ;
27+
28+ // Mock configstore to avoid "Cannot find module ../package.json" error and side effects
29+ if ( pathRelativeToCliRoot . endsWith ( CONFIGSTORE_INDEX_PATH ) ) {
30+ logToFile ( `Mocking configstore for: ${ pathRelativeToCliRoot } ` ) ;
31+ return {
32+ configstore : {
33+ get : ( ) => undefined ,
34+ set : ( ) => { } ,
35+ delete : ( ) => { } ,
36+ } ,
37+ } ;
38+ }
39+
2840 if ( ! pathRelativeToCliRoot . endsWith ( MCP_TOOLS_INDEX_PATH ) ) {
2941 return requiredModule ;
3042 }
@@ -67,6 +79,10 @@ Module.prototype.require = function (id: string) {
6779 } ) ;
6880} ;
6981
82+ import { getToolMocks } from "./tool-mocks.js" ;
83+
84+ const mocks = getToolMocks ( ) ;
85+
7086function logToFile ( message : string ) {
7187 if ( ! ENABLE_FILE_LOGGING ) {
7288 return ;
0 commit comments