@lensmcp/vite-plugin 1.20.0 → 1.20.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/lib/event-mappers.js +2 -2
- package/lib/plugin.js +2 -2
- package/package.json +6 -6
package/lib/event-mappers.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`).slice(0,2);for(const o of t){const s=o.match(/at\s+(\S+)/);if(s&&s[1])return s[1]}return"unknown"}
|
|
1
|
+
"use strict";var $=Object.defineProperty;var c=(e,t)=>$(e,"name",{value:t,configurable:!0});var h=Object.defineProperty,l=c((e,t)=>h(e,"name",{value:t,configurable:!0}),"u"),x=Object.defineProperty,d=l((e,t)=>x(e,"name",{value:t,configurable:!0}),"u"),S=Object.defineProperty,m=d((e,t)=>S(e,"name",{value:t,configurable:!0}),"u"),U=Object.defineProperty,v=m((e,t)=>U(e,"name",{value:t,configurable:!0}),"c"),R=Object.defineProperty,f=v((e,t)=>R(e,"name",{value:t,configurable:!0}),"c"),A=Object.defineProperty,p=f((e,t)=>A(e,"name",{value:t,configurable:!0}),"c"),C=Object.defineProperty,g=p((e,t)=>C(e,"name",{value:t,configurable:!0}),"u"),F=Object.defineProperty,y=g((e,t)=>F(e,"name",{value:t,configurable:!0}),"u"),J=Object.defineProperty,b=y((e,t)=>J(e,"name",{value:t,configurable:!0}),"u"),L=Object.defineProperty,j=b((e,t)=>L(e,"name",{value:t,configurable:!0}),"u"),N=Object.defineProperty,T=j((e,t)=>N(e,"name",{value:t,configurable:!0}),"o"),q=Object.defineProperty,E=T((e,t)=>q(e,"name",{value:t,configurable:!0}),"o"),z=Object.defineProperty,I=E((e,t)=>z(e,"name",{value:t,configurable:!0}),"o"),B=Object.defineProperty,O=I((e,t)=>B(e,"name",{value:t,configurable:!0}),"o"),D=Object.defineProperty,w=O((e,t)=>D(e,"name",{value:t,configurable:!0}),"o"),G=Object.defineProperty,P=w((e,t)=>G(e,"name",{value:t,configurable:!0}),"o");import{fingerprint as a,ulid as u}from"@lensmcp/core";const H="pending";export function envelopeToEvent(e,t=H){const o=e.tabId?{tabId:e.tabId}:{};switch(e.kind){case"error":return{id:u(),sessionId:t,timestamp:e.at,source:"client-runtime",category:"runtime",severity:"error",context:{sessionId:t,...o},fingerprint:a({kind:"runtime",identity:`error:${n(e.stack)}`,file:e.source,detail:e.message}),title:e.message,message:e.stack??e.message,location:e.source?{file:e.source,line:e.lineno,column:e.colno}:void 0,raw:e};case"unhandledrejection":return{id:u(),sessionId:t,timestamp:e.at,source:"client-runtime",category:"runtime",severity:"error",context:{sessionId:t,...o},fingerprint:a({kind:"runtime",identity:`unhandledrejection:${e.reason.slice(0,80)}`}),title:"Unhandled promise rejection",message:e.reason,raw:e};case"console":{const s=e.level==="error"?"error":e.level==="warn"?"warning":"info",k=e.args.map(i).join(" ");return{id:u(),sessionId:t,timestamp:e.at,source:"client-runtime",category:"runtime",severity:s,context:{sessionId:t,...o},fingerprint:a({kind:"runtime",identity:`console:${e.level}:${k.slice(0,80)}`}),title:`console.${e.level}`,message:k,raw:e}}case"fetch":{const s=e.error!==void 0||e.status!==void 0&&e.status>=400;return{id:u(),sessionId:t,timestamp:e.at,source:"client-runtime",category:"network",severity:s?"error":"info",context:{sessionId:t,...o},fingerprint:a({kind:"network",identity:`${e.method}:${r(e.url)}:${e.status??"err"}`}),title:`${e.method} ${e.url}${e.status!==void 0?` \u2192 ${e.status}`:""}`,message:e.error,relatedUrls:[e.url],raw:e}}case"route":return{id:u(),sessionId:t,timestamp:e.at,source:"client-runtime",category:"runtime",severity:"info",context:{sessionId:t,url:e.url,...o},fingerprint:a({kind:"runtime",identity:`route:${e.url}`}),title:`Route \u2192 ${e.url}`,raw:e};case"ready":return{id:u(),sessionId:t,timestamp:e.at,source:"client-runtime",category:"runtime",severity:"info",context:{sessionId:t,url:e.url,...o},fingerprint:a({kind:"runtime",identity:"client-ready"}),title:"Client runtime ready",message:e.userAgent,raw:e};case"publish":return{id:u(),sessionId:t,timestamp:e.at,source:e.source,category:e.category,severity:e.severity??"info",context:{sessionId:t,...o,...e.context??{}},fingerprint:e.fingerprint??a({kind:"publish",identity:e.title}),title:e.title,message:e.message,raw:e.raw}}}c(envelopeToEvent,"envelopeToEvent"),l(envelopeToEvent,"envelopeToEvent"),d(envelopeToEvent,"envelopeToEvent"),m(envelopeToEvent,"envelopeToEvent"),v(envelopeToEvent,"envelopeToEvent"),f(envelopeToEvent,"envelopeToEvent"),p(envelopeToEvent,"envelopeToEvent"),g(envelopeToEvent,"envelopeToEvent"),y(envelopeToEvent,"envelopeToEvent"),b(envelopeToEvent,"envelopeToEvent"),j(envelopeToEvent,"envelopeToEvent"),T(envelopeToEvent,"envelopeToEvent"),E(envelopeToEvent,"envelopeToEvent"),I(envelopeToEvent,"envelopeToEvent"),O(envelopeToEvent,"envelopeToEvent"),w(envelopeToEvent,"envelopeToEvent"),P(envelopeToEvent,"envelopeToEvent");function n(e){if(!e)return"unknown";const t=e.split(`
|
|
2
|
+
`).slice(0,2);for(const o of t){const s=o.match(/at\s+(\S+)/);if(s&&s[1])return s[1]}return"unknown"}c(n,"t"),l(n,"r"),d(n,"t"),m(n,"r"),v(n,"t"),f(n,"n"),p(n,"n"),g(n,"r"),y(n,"n"),b(n,"o"),j(n,"a"),T(n,"l"),E(n,"l"),I(n,"c"),O(n,"c"),w(n,"s"),P(n,"normaliseStackTopFrame");function r(e){try{return`${new URL(e,"http://x").pathname}`}catch{return e}}c(r,"r"),l(r,"n"),d(r,"r"),m(r,"n"),v(r,"r"),f(r,"r"),p(r,"r"),g(r,"i"),y(r,"i"),b(r,"a"),j(r,"c"),T(r,"d"),E(r,"d"),I(r,"l"),O(r,"l"),w(r,"m"),P(r,"normaliseUrl");function i(e){if(typeof e=="string")return e;try{return JSON.stringify(e)}catch{return String(e)}}c(i,"i"),l(i,"i"),d(i,"i"),m(i,"i"),v(i,"i"),f(i,"i"),p(i,"i"),g(i,"o"),y(i,"o"),b(i,"c"),j(i,"u"),T(i,"m"),E(i,"m"),I(i,"d"),O(i,"d"),w(i,"d"),P(i,"stringify");
|
package/lib/plugin.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var N=Object.defineProperty;var d=(e,t)=>N(e,"name",{value:t,configurable:!0});var x=Object.defineProperty,u=d((e,t)=>x(e,"name",{value:t,configurable:!0}),"c");import{resolve as P}from"node:path";import{fingerprint as k,ulid as _}from"@lensmcp/core";import{createBridgeServer as j,makePublisher as E,handleClientEnvelope as M}from"@lensmcp/bridge";const I="/@lensmcp/client-runtime",T="\0lensmcp-client-runtime",H="/__lensmcp/watcher-health",C=256;export function lensmcpVitePlugin(e={},t={}){const s=e.enabled??!0,f=e.wsHost??"127.0.0.1",i=e.injectClient??!0;let v,g;const b=E(t),D=e.aliasValtio??!0,B=e.transformSource??!0;return{name:"@lensmcp/vite-plugin",apply:s?void 0:()=>!1,enforce:"pre",wsPort:u(()=>v,"wsPort"),config(){if(!(!s||!D))return{resolve:{alias:[{find:/^valtio$/,replacement:"@lensmcp/valtio-instrumentation"}]}}},async configureServer(r){if(!s)return;g=await j({host:f,port:e.wsPort??0,bus:t.bus,sessionId:t.sessionId}),v=g.port,r.ws.on("vite:error",n=>{b(O(n,t.sessionId))});let a=0,o=0,l=0;const p=[],m=u((n,h)=>{a=Date.now(),o+=1,l+=1,p.push({sequence:l,kind:n,path:P(h),at:a}),p.length>C&&p.splice(0,p.length-C)},"stampFsSetEvent");r.watcher.on("add",n=>m("add",n)),r.watcher.on("addDir",n=>m("addDir",n)),r.watcher.on("unlink",n=>m("unlink",n)),r.watcher.on("unlinkDir",n=>m("unlinkDir",n)),r.middlewares.use(H,(n,h)=>{h.setHeader("content-type","application/json"),h.setHeader("cache-control","no-store"),h.end(JSON.stringify({schemaVersion:2,ready:!0,sequence:l,lastFsSetEventAt:a,fsSetEvents:o,recentEvents:p,now:Date.now()}))})},resolveId(r){return r===I?T:null},load(r){if(r!==T)return null;const a=v??e.wsPort??0;return A({host:f,port:a})},async transform(r,a){if(!s||!B)return null;const o=a.split("?")[0]??a;if(o.includes("/node_modules/")||!/\.[jt]sx$/.test(o))return null;const l=await L(r,o);return l?{code:l.code,map:l.map}:null},transformIndexHtml(){if(!(!i||!s))return[{tag:"script",attrs:{type:"module",src:I},injectTo:"head-prepend"}]},handleHotUpdate(r){if(!s)return;const a=r.modules.map(o=>o.file??o.id??null).filter(o=>!!o);b({id:_(),sessionId:t.sessionId??"pending",timestamp:Date.now(),source:"vite",category:"build",severity:"info",context:{sessionId:t.sessionId??"pending"},fingerprint:k({kind:"hmr",identity:r.file}),title:`HMR ${r.file}`,location:{file:r.file},relatedFiles:a,raw:{kind:"hmr",file:r.file}})},generateBundle(r,a){if(!s)return;const o=[];let l=0;for(const m of Object.values(a)){const n=m,h=n.fileName;let w;if(n.type==="chunk")w=(n.code??"").length;else{const c=n.source;w=typeof c=="string"?c.length:c instanceof Uint8Array?c.byteLength:0}l+=w;const S=[];if(n.type==="chunk"&&n.modules){for(const[c,y]of Object.entries(n.modules)){const F=y.renderedLength??y.originalLength??0;S.push({id:c,sizeBytes:F})}S.sort((c,y)=>y.sizeBytes-c.sizeBytes)}o.push({name:h,sizeBytes:w,modules:S})}const p={timestamp:Date.now(),totalBytes:l,chunks:o};b({id:_(),sessionId:t.sessionId??"pending",timestamp:Date.now(),source:"rollup",category:"build",severity:"info",context:{sessionId:t.sessionId??"pending"},fingerprint:k({kind:"bundle",identity:"report"}),title:`Bundle report: ${o.length} chunks, ${l} bytes`,raw:{kind:"bundle-report",report:p}})},async closeBundle(){g&&(await g.close(),g=void 0)}}}d(lensmcpVitePlugin,"lensmcpVitePlugin"),u(lensmcpVitePlugin,"lensmcpVitePlugin");async function L(e,t){try{const[{transformSync:s},{lensmcpBabelPlugin:f}]=await Promise.all([import("@babel/core"),import("@lensmcp/react-instrumentation")]),i=s(e,{filename:t,babelrc:!1,configFile:!1,sourceMaps:!0,parserOpts:{plugins:["jsx","typescript"]},plugins:[[f,{rootDir:process.cwd(),production:!1}]],code:!0});return i?.code?{code:i.code,map:i.map}:null}catch{return null}}d(L,"F"),u(L,"runLensmcpBabel");export function handleClientEnvelope(e,t){M(e,E(t),t.sessionId)}d(handleClientEnvelope,"handleClientEnvelope"),u(handleClientEnvelope,"handleClientEnvelope");function R(e){const t=e?.loc?.file??e?.id;return typeof t!="string"||t.length===0?void 0:{file:t.split("?")[0]||t,...typeof e?.loc?.line=="number"?{line:e.loc.line}:{},...typeof e?.loc?.column=="number"?{column:e.loc.column}:{}}}d(R,"P"),u(R,"errorLocation");function O(e,t){const s=e.err?.message??"Vite error",f=e.err?.stack,i=R(e.err);return{id:_(),sessionId:t??"pending",timestamp:Date.now(),source:"vite",category:"build",severity:"error",context:{sessionId:t??"pending"},fingerprint:k({kind:"vite",identity:e.type??s,...i?{file:i.file}:{}}),title:s,message:f,...i?{location:i}:{},raw:{kind:"build-diagnostic",...i?{file:i.file}:{},...e.err?.plugin?{plugin:e.err.plugin}:{}}}}d(O,"j"),u(O,"viteErrorToEvent");function A(e){return`// @lensmcp/client-runtime (inlined by @lensmcp/vite-plugin)
|
|
2
2
|
(() => {
|
|
3
3
|
if (typeof window === 'undefined') return;
|
|
4
4
|
if (window.__LENSMCP_CLIENT__) return;
|
|
@@ -221,4 +221,4 @@
|
|
|
221
221
|
try { return JSON.parse(JSON.stringify(v)); } catch { return String(v); }
|
|
222
222
|
}
|
|
223
223
|
})();
|
|
224
|
-
`}d(
|
|
224
|
+
`}d(A,"x"),u(A,"buildInlineClientRuntime");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lensmcp/vite-plugin",
|
|
3
|
-
"version": "1.20.
|
|
3
|
+
"version": "1.20.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -15,11 +15,11 @@
|
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@babel/core": "^7.0.0",
|
|
18
|
-
"@lensmcp/bridge": "1.20.
|
|
19
|
-
"@lensmcp/core": "1.20.
|
|
20
|
-
"@lensmcp/protocol-types": "1.20.
|
|
21
|
-
"@lensmcp/react-instrumentation": "1.20.
|
|
22
|
-
"@lensmcp/valtio-instrumentation": "1.20.
|
|
18
|
+
"@lensmcp/bridge": "1.20.1",
|
|
19
|
+
"@lensmcp/core": "1.20.1",
|
|
20
|
+
"@lensmcp/protocol-types": "1.20.1",
|
|
21
|
+
"@lensmcp/react-instrumentation": "1.20.1",
|
|
22
|
+
"@lensmcp/valtio-instrumentation": "1.20.1",
|
|
23
23
|
"tslib": "^2.3.0"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|