project-graph-mcp 2.2.0 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@ function l(t){r.mkdirSync(s,{recursive:!0}),r.writeFileSync(c,JSON.stringify(t,n
|
|
|
6
6
|
function d(){if(!r.existsSync(a))return;const t=r.readdirSync(a).filter(t=>t.endsWith(".json"));let e=!1;const n=p();for(const s of t)try{const t=JSON.parse(r.readFileSync(o.join(a,s),"utf8"));try{process.kill(t.pid,0)}catch{r.unlinkSync(o.join(a,s));continue}const c=t.name||"root",i=`/${c}`;n["project-graph.local"]=n["project-graph.local"]||{name:"project-graph",routes:{}},n["project-graph.local"].routes[i]||(n["project-graph.local"].routes[i]={port:t.port,pid:t.pid,projectPath:t.project,projectName:c},e=!0)}catch{}e&&l(n)}
|
|
7
7
|
export function registerService(t,e,r={}){const o=`${t}.local`,s=p();if(r.projectName){s[o]||(s[o]={name:t,routes:{}});const n=`/${r.projectName}`;s[o].routes=s[o].routes||{},s[o].routes[n]={port:e,pid:process.pid,projectPath:r.projectPath,projectName:r.projectName}}else s[o]={port:e,pid:process.pid,name:t};l(s);f();const gwPort=getGatewayPort();const c=n(o,gwPort);const i=()=>{c.cleanup()};process.on("exit",i),process.on("SIGINT",()=>{i(),process.exit()}),process.on("SIGTERM",()=>{i(),process.exit()});const d=80===gwPort?"":`:${gwPort}`,u=r.projectName?`http://${o}${d}/${r.projectName}/`:`http://${o}${d}/`;return{cleanup:i,url:u,directUrl:`http://localhost:${e}/`}}
|
|
8
8
|
function u(t,e,r){const o=r[t];if(!o)return null;if(o.routes){const t=Object.keys(o.routes).sort((t,e)=>e.length-t.length);for(const r of t)if(e===r||e.startsWith(r+"/")){const t=o.routes[r];try{process.kill(t.pid,0)}catch{if(t.projectPath){_autoRestart(t.projectPath);return{port:t.port,rewritePath:"/restarting",restarting:true,prefix:r}}continue}const n=e.slice(r.length)||"/";return{port:t.port,rewritePath:n,prefix:r}}for(const r of t)try{const t=o.routes[r];process.kill(t.pid,0);const n="/"===e||""===e?"/dashboard.html":e;return{port:t.port,rewritePath:n}}catch{continue}}if(o.port){const t="/"===e||""===e?"/dashboard.html":e;return{port:o.port,rewritePath:t}}return null}
|
|
9
|
-
const _restarts=new Map();function _autoRestart(projectPath){const now=Date.now();if(_restarts.has(projectPath)&&now-_restarts.get(projectPath)<15e3)return;_restarts.set(projectPath,now);console.error(`[gateway] Auto-restarting backend for ${projectPath}`);
|
|
9
|
+
const _restarts=new Map();function _autoRestart(projectPath){const now=Date.now();if(_restarts.has(projectPath)&&now-_restarts.get(projectPath)<15e3)return;_restarts.set(projectPath,now);console.error(`[gateway] Auto-restarting backend for ${projectPath}`);import("node:child_process").then(({spawn:s})=>{const b=o.join(o.dirname(new URL(import.meta.url).pathname),"backend.js");s(process.execPath,[b,projectPath],{detached:true,stdio:"ignore",env:{...process.env,PROJECT_GRAPH_BACKEND:"1"}}).unref()}).catch(e=>console.error(`[gateway] Auto-restart failed: ${e.message}`))}
|
|
10
10
|
function h(){try{const t=r.readFileSync(i,"utf8");return t.trim().startsWith("{")?JSON.parse(t):{pid:parseInt(t,10),port:80}}catch{return null}}
|
|
11
11
|
export function getGatewayPort(){const t=h();return t?.port||80}
|
|
12
12
|
const RESTART_HTML='<!DOCTYPE html><html><head><meta charset="utf-8"><meta http-equiv="refresh" content="3"><title>Restarting...</title><style>body{background:#1a1a2e;color:#e0e0e0;font-family:system-ui;display:flex;justify-content:center;align-items:center;height:100vh;margin:0}.box{text-align:center}.spinner{width:40px;height:40px;border:3px solid #333;border-top:3px solid #7c3aed;border-radius:50%;animation:spin 1s linear infinite;margin:0 auto 16px}@keyframes spin{to{transform:rotate(360deg)}}</style></head><body><div class="box"><div class="spinner"></div><h2>⬡ Backend restarting...</h2><p>Auto-refreshing in 3 seconds</p></div></body></html>';
|