@lensmcp/nx-plugin 1.25.41 → 1.25.43
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/generators/init/init.js +7 -7
- package/package.json +1 -1
package/generators/init/init.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`),
|
|
1
|
+
"use strict";var S=Object.defineProperty;var c=(e,s)=>S(e,"name",{value:s,configurable:!0});var g=Object.defineProperty,a=c((e,s)=>g(e,"name",{value:s,configurable:!0}),"a");Object.defineProperty(exports,"__esModule",{value:!0}),exports.LENS_SHARED_DIRS=void 0,exports.fixLensGitignore=fixLensGitignore,exports.initGenerator=initGenerator,exports.mcpServerEntry=mcpServerEntry,exports.pluginVersion=pluginVersion,exports.isGeneratedMcpEntry=isGeneratedMcpEntry,exports.refreshedMcpEntry=refreshedMcpEntry;const node_fs_1=require("node:fs"),node_path_1=require("node:path"),devkit_1=require("@nx/devkit"),DEFAULT_LENSMCP_CONFIG={schemaVersion:1,storage:"memory",transport:"stdio",retention:{sessions:5,events:5e3,screenshots:50,buildReports:20,visualFrames:200,heapSnapshots:3,tracesWithErrors:20,verifications:10},redaction:{headers:["authorization","cookie","set-cookie","x-api-key"],paths:["password","token","secret","apiKey","api_key"]},channels:{blockingStatusChanged:{enabled:!0,minSeverity:"error"},memoryLeakSuspected:{enabled:!0,minSeverity:"warning"},bundleRegression:{enabled:!0,minSeverity:"warning"},visualViolationBlocking:{enabled:!0,minSeverity:"error"},verificationCompleted:{enabled:!0,minSeverity:"info"}},thresholds:{dbInLoop:5,nPlusOne:3,renderStorm:5,slowRouteMs:500,slowRenderMs:16}},LENSMCP_GITIGNORE_MARKER="# LensMCP: this machine's runtime state is ignored; the team's analyzer instructions are kept";exports.LENS_SHARED_DIRS=["sql-review","route-review","flow-review","ui-review","cache-review","queue-review","ai-review","ai-names","team","team-design"];function fixLensGitignore(e){const s=e.split(`
|
|
2
|
+
`),r=/^(\/|\*\*\/)?\.lensmcp\/?(\*)?$/;let n=s.findIndex(o=>r.test(o.trim())),t=!1;if(n<0){const o=e.length&&!e.endsWith(`
|
|
3
3
|
`)?`${e}
|
|
4
4
|
`:e;return{text:`${o}${o.trim()?`
|
|
5
5
|
`:""}${LENSMCP_GITIGNORE_MARKER}
|
|
6
6
|
**/.lensmcp/*
|
|
7
7
|
${exports.LENS_SHARED_DIRS.map(l=>`!**/.lensmcp/${l}/`).join(`
|
|
8
8
|
`)}
|
|
9
|
-
`,changed:!0}}const i=
|
|
10
|
-
`),changed:t}}
|
|
11
|
-
`),
|
|
12
|
-
`),
|
|
13
|
-
`),
|
|
9
|
+
`,changed:!0}}const i=r.exec(s[n].trim())[1]==="/"?"/":"**/";s[n].trim()!==`${i}.lensmcp/*`&&(s[n]=`${i}.lensmcp/*`,t=!0);for(const o of exports.LENS_SHARED_DIRS){const l=`!${i}.lensmcp/${o}/`;s.some(m=>m.trim()===l||m.trim()===l.slice(0,-1))||(s.splice(++n,0,l),t=!0)}return{text:s.join(`
|
|
10
|
+
`),changed:t}}c(fixLensGitignore,"fixLensGitignore"),a(fixLensGitignore,"fixLensGitignore");async function initGenerator(e,s={}){const r={skipFormat:s.skipFormat??!1,registerHostConfig:s.registerHostConfig??"auto"},n=[];if(e.exists("nx.json")){const d=(0,devkit_1.readJson)(e,"nx.json"),p=JSON.parse(JSON.stringify(d));p.plugins=Array.isArray(p.plugins)?p.plugins:[],p.plugins.some(u=>typeof u=="string"?u==="@lensmcp/nx-plugin":u&&typeof u=="object"&&"plugin"in u?u.plugin==="@lensmcp/nx-plugin":!1)||(p.plugins.push("@lensmcp/nx-plugin"),n.push("nx.json: registered @lensmcp/nx-plugin"));const y=p.lensmcp??{};p.lensmcp=mergeDeep(DEFAULT_LENSMCP_CONFIG,y),(!("lensmcp"in p)||Object.keys(y).length===0)&&n.push("nx.json: added workspace-wide `lensmcp` config block"),canonicalJson(p)!==canonicalJson(d)&&(0,devkit_1.writeJson)(e,"nx.json",p)}else throw new Error("No nx.json found at the workspace root. Are you in a Nx workspace?");const t=".gitignore",i=e.exists(t)?e.read(t,"utf-8")??"":"",o=fixLensGitignore(i);o.changed&&(e.write(t,o.text),n.push(`${t}: ignores **/.lensmcp/* and keeps ${exports.LENS_SHARED_DIRS.map(d=>`.lensmcp/${d}/`).join(", ")}`));const l=(0,devkit_1.joinPathFragments)(".lensmcp",".keep");e.exists(l)||(e.write(l,""),n.push(`${l}: created`));const m=(0,devkit_1.joinPathFragments)(".lensmcp","install-trail.json"),f=(e.exists(m)?JSON.parse(e.read(m,"utf-8")??"{}"):void 0)??{schemaVersion:1,installedAt:new Date().toISOString(),steps:[]};f.steps.push(...n),e.write(m,JSON.stringify(f,null,2)+`
|
|
11
|
+
`),r.registerHostConfig!=="never"&®isterWorkspaceMcpConfig(e,n),r.skipFormat||await(0,devkit_1.formatFiles)(e)}c(initGenerator,"initGenerator"),a(initGenerator,"initGenerator");function mcpServerEntry(e,s={}){if((s.exists??node_fs_1.existsSync)((0,node_path_1.join)(e,"node_modules",".bin","lensmcp")))return{command:"npx",args:["--no","lensmcp","mcp"]};const r="version"in s?s.version:pluginVersion();return{command:"npx",args:["--yes",r?`lensmcp@${r}`:"lensmcp","mcp"]}}c(mcpServerEntry,"mcpServerEntry"),a(mcpServerEntry,"mcpServerEntry");function pluginVersion(e=__dirname){let s=e;for(let r=0;r<6;r++){const n=(0,node_path_1.join)(s,"package.json");try{if((0,node_fs_1.existsSync)(n)){const i=JSON.parse((0,node_fs_1.readFileSync)(n,"utf-8"));if(i.name==="@lensmcp/nx-plugin"&&typeof i.version=="string")return i.version}}catch{}const t=(0,node_path_1.dirname)(s);if(t===s)break;s=t}}c(pluginVersion,"pluginVersion"),a(pluginVersion,"pluginVersion");const PINNED_SPECIFIER=/^lensmcp@\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/;function isGeneratedMcpEntry(e){if(!e||typeof e!="object"||Array.isArray(e))return!1;const{command:s,args:r,...n}=e;if(s!=="npx"||Object.keys(n).length>0||!Array.isArray(r)||r.length!==3)return!1;const[t,i,o]=r;return o!=="mcp"||typeof i!="string"?!1:t==="--no"?i==="lensmcp":t==="-y"||t==="--yes"?i==="lensmcp"||PINNED_SPECIFIER.test(i):!1}c(isGeneratedMcpEntry,"isGeneratedMcpEntry"),a(isGeneratedMcpEntry,"isGeneratedMcpEntry");function refreshedMcpEntry(e,s){if(!isGeneratedMcpEntry(e)||e.args.join(" ")===s.args.join(" "))return;const r=e.args[0]!=="--no"&&e.args[1]==="lensmcp";return s.args[0]==="--no"||r?s:void 0}c(refreshedMcpEntry,"refreshedMcpEntry"),a(refreshedMcpEntry,"refreshedMcpEntry");function registerWorkspaceMcpConfig(e,s){const r=".mcp.json";let n={};if(e.exists(r))try{n=JSON.parse(e.read(r,"utf-8")??"{}")}catch{n={}}(!n||typeof n!="object")&&(n={}),(!n.mcpServers||typeof n.mcpServers!="object")&&(n.mcpServers={});const t=n.mcpServers.lensmcp,i=mcpServerEntry(e.root);if(t){const o=refreshedMcpEntry(t,i);if(!o)return;n.mcpServers.lensmcp=o,e.write(r,JSON.stringify(n,null,2)+`
|
|
12
|
+
`),s.push(`.mcp.json: refreshed the generated lensmcp MCP entry (${t.args.join(" ")} \u2192 ${o.args.join(" ")})`);return}n.mcpServers.lensmcp=i,e.write(r,JSON.stringify(n,null,2)+`
|
|
13
|
+
`),s.push(`.mcp.json: registered lensmcp MCP server (stdio, ${i.args.join(" ")})`)}c(registerWorkspaceMcpConfig,"registerWorkspaceMcpConfig"),a(registerWorkspaceMcpConfig,"registerWorkspaceMcpConfig"),exports.default=initGenerator;function canonicalJson(e){return JSON.stringify(e,(s,r)=>r&&typeof r=="object"&&!Array.isArray(r)?Object.fromEntries(Object.entries(r).sort(([n],[t])=>n<t?-1:n>t?1:0)):r)}c(canonicalJson,"canonicalJson"),a(canonicalJson,"canonicalJson");function mergeDeep(e,s){const r={...e};for(const[n,t]of Object.entries(s))t!==null&&typeof t=="object"&&!Array.isArray(t)&&r[n]!==null&&typeof r[n]=="object"&&!Array.isArray(r[n])?r[n]=mergeDeep(r[n],t):r[n]=t;return r}c(mergeDeep,"mergeDeep"),a(mergeDeep,"mergeDeep");
|