@@ -5,20 +5,34 @@ import fs from "node:fs/promises";
55import path from "node:path" ;
66import { fileURLToPath } from "node:url" ;
77
8- const __filename = fileURLToPath ( import . meta. url ) ;
9- const __dirname = path . dirname ( __filename ) ;
8+ // Get the directory where resources are located
9+ // In bundled output (out/mcp/cli.js), resources are at out/mcp/data/
10+ // In source/dev mode, resources are at src/resources/data/
11+ function getResourceDir ( ) : string {
12+ // In bundled mode, process.argv[1] points to the entry script (out/mcp/cli.js)
13+ // This is the most reliable way to get the directory in bundled code
14+ // since import.meta.url doesn't resolve correctly when webpack bundles ESM to CommonJS
15+ if ( typeof process !== "undefined" && process . argv && process . argv [ 1 ] ) {
16+ return path . dirname ( process . argv [ 1 ] ) ;
17+ }
18+ // Fall back to import.meta.url (works in dev mode when running with ts-node)
19+ const __filename = fileURLToPath ( import . meta. url ) ;
20+ return path . dirname ( __filename ) ;
21+ }
22+
23+ const resourceDir = getResourceDir ( ) ;
1024
1125// Schema file packaged with the extension
12- // In compiled output, files are in out/server/src/resources /data/
26+ // In compiled output, files are in out/mcp /data/
1327// In source, files are in src/resources/data/
1428const SCHEMA_FILE = path . join (
15- __dirname ,
29+ resourceDir ,
1630 "data/execution-environment-schema.json" ,
1731) ;
18- const RULES_FILE = path . join ( __dirname , "data/ee-rules.md" ) ;
32+ const RULES_FILE = path . join ( resourceDir , "data/ee-rules.md" ) ;
1933// Sample EE file packaged with the extension
2034export const SAMPLE_EE_FILE = path . join (
21- __dirname ,
35+ resourceDir ,
2236 "data/execution-environment-sample.yml" ,
2337) ;
2438
0 commit comments