@lensmcp/vite-plugin 1.19.0 → 1.20.0
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
|
|
1
|
+
"use strict";var O=Object.defineProperty;var u=(e,t)=>O(e,"name",{value:t,configurable:!0});var $=Object.defineProperty,l=u((e,t)=>$(e,"name",{value:t,configurable:!0}),"u"),h=Object.defineProperty,d=l((e,t)=>h(e,"name",{value:t,configurable:!0}),"c"),P=Object.defineProperty,m=d((e,t)=>P(e,"name",{value:t,configurable:!0}),"c"),x=Object.defineProperty,v=m((e,t)=>x(e,"name",{value:t,configurable:!0}),"c"),S=Object.defineProperty,f=v((e,t)=>S(e,"name",{value:t,configurable:!0}),"u"),U=Object.defineProperty,p=f((e,t)=>U(e,"name",{value:t,configurable:!0}),"u"),R=Object.defineProperty,g=p((e,t)=>R(e,"name",{value:t,configurable:!0}),"u"),A=Object.defineProperty,y=g((e,t)=>A(e,"name",{value:t,configurable:!0}),"u"),C=Object.defineProperty,b=y((e,t)=>C(e,"name",{value:t,configurable:!0}),"o"),F=Object.defineProperty,j=b((e,t)=>F(e,"name",{value:t,configurable:!0}),"o"),J=Object.defineProperty,I=j((e,t)=>J(e,"name",{value:t,configurable:!0}),"o"),L=Object.defineProperty,w=I((e,t)=>L(e,"name",{value:t,configurable:!0}),"o"),N=Object.defineProperty,T=w((e,t)=>N(e,"name",{value:t,configurable:!0}),"o"),q=Object.defineProperty,k=T((e,t)=>q(e,"name",{value:t,configurable:!0}),"o");import{fingerprint as a,ulid as c}from"@lensmcp/core";const z="pending";export function envelopeToEvent(e,t=z){const o=e.tabId?{tabId:e.tabId}:{};switch(e.kind){case"error":return{id:c(),sessionId:t,timestamp:e.at,source:"client-runtime",category:"runtime",severity:"error",context:{sessionId:t,...o},fingerprint:a({kind:"runtime",identity:`error:${r(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:c(),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",E=e.args.map(i).join(" ");return{id:c(),sessionId:t,timestamp:e.at,source:"client-runtime",category:"runtime",severity:s,context:{sessionId:t,...o},fingerprint:a({kind:"runtime",identity:`console:${e.level}:${E.slice(0,80)}`}),title:`console.${e.level}`,message:E,raw:e}}case"fetch":{const s=e.error!==void 0||e.status!==void 0&&e.status>=400;return{id:c(),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}:${n(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:c(),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:c(),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:c(),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}}}u(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"),I(envelopeToEvent,"envelopeToEvent"),w(envelopeToEvent,"envelopeToEvent"),T(envelopeToEvent,"envelopeToEvent"),k(envelopeToEvent,"envelopeToEvent");function r(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"}u(r,"t"),l(r,"r"),d(r,"t"),m(r,"n"),v(r,"n"),f(r,"r"),p(r,"n"),g(r,"o"),y(r,"a"),b(r,"l"),j(r,"l"),I(r,"c"),w(r,"c"),T(r,"s"),k(r,"normaliseStackTopFrame");function n(e){try{return`${new URL(e,"http://x").pathname}`}catch{return e}}u(n,"r"),l(n,"n"),d(n,"r"),m(n,"r"),v(n,"r"),f(n,"i"),p(n,"i"),g(n,"a"),y(n,"c"),b(n,"d"),j(n,"d"),I(n,"l"),w(n,"l"),T(n,"m"),k(n,"normaliseUrl");function i(e){if(typeof e=="string")return e;try{return JSON.stringify(e)}catch{return String(e)}}u(i,"i"),l(i,"i"),d(i,"i"),m(i,"i"),v(i,"i"),f(i,"o"),p(i,"o"),g(i,"c"),y(i,"u"),b(i,"m"),j(i,"m"),I(i,"d"),w(i,"d"),T(i,"d"),k(i,"stringify");
|
package/lib/plugin.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var x=Object.defineProperty;var d=(e,t)=>x(e,"name",{value:t,configurable:!0});var N=Object.defineProperty,f=d((e,t)=>N(e,"name",{value:t,configurable:!0}),"d"),j=Object.defineProperty,u=f((e,t)=>j(e,"name",{value:t,configurable:!0}),"c");import{resolve as M}from"node:path";import{fingerprint as _,ulid as E}from"@lensmcp/core";import{createBridgeServer as H,makePublisher as O,handleClientEnvelope as U}from"@lensmcp/bridge";const R="/@lensmcp/client-runtime",A="\0lensmcp-client-runtime",V="/__lensmcp/watcher-health",D=256;export function lensmcpVitePlugin(e={},t={}){const s=e.enabled??!0,m=e.wsHost??"127.0.0.1",i=e.injectClient??!0;let b,w;const S=O(t),B=e.aliasValtio??!0,F=e.transformSource??!0;return{name:"@lensmcp/vite-plugin",apply:s?void 0:()=>!1,enforce:"pre",wsPort:u(()=>b,"wsPort"),config(){if(!(!s||!B))return{resolve:{alias:[{find:/^valtio$/,replacement:"@lensmcp/valtio-instrumentation"}]}}},async configureServer(r){if(!s)return;w=await H({host:m,port:e.wsPort??0,bus:t.bus,sessionId:t.sessionId}),b=w.port,r.ws.on("vite:error",n=>{S(T(n,t.sessionId))});let a=0,o=0,l=0;const p=[],g=u((n,h)=>{a=Date.now(),o+=1,l+=1,p.push({sequence:l,kind:n,path:M(h),at:a}),p.length>D&&p.splice(0,p.length-D)},"stampFsSetEvent");r.watcher.on("add",n=>g("add",n)),r.watcher.on("addDir",n=>g("addDir",n)),r.watcher.on("unlink",n=>g("unlink",n)),r.watcher.on("unlinkDir",n=>g("unlinkDir",n)),r.middlewares.use(V,(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===R?A:null},load(r){if(r!==A)return null;const a=b??e.wsPort??0;return L({host:m,port:a})},async transform(r,a){if(!s||!F)return null;const o=a.split("?")[0]??a;if(o.includes("/node_modules/")||!/\.[jt]sx$/.test(o))return null;const l=await I(r,o);return l?{code:l.code,map:l.map}:null},transformIndexHtml(){if(!(!i||!s))return[{tag:"script",attrs:{type:"module",src:R},injectTo:"head-prepend"}]},handleHotUpdate(r){if(!s)return;const a=r.modules.map(o=>o.file??o.id??null).filter(o=>!!o);S({id:E(),sessionId:t.sessionId??"pending",timestamp:Date.now(),source:"vite",category:"build",severity:"info",context:{sessionId:t.sessionId??"pending"},fingerprint:_({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 g of Object.values(a)){const n=g,h=n.fileName;let v;if(n.type==="chunk")v=(n.code??"").length;else{const c=n.source;v=typeof c=="string"?c.length:c instanceof Uint8Array?c.byteLength:0}l+=v;const k=[];if(n.type==="chunk"&&n.modules){for(const[c,y]of Object.entries(n.modules)){const P=y.renderedLength??y.originalLength??0;k.push({id:c,sizeBytes:P})}k.sort((c,y)=>y.sizeBytes-c.sizeBytes)}o.push({name:h,sizeBytes:v,modules:k})}const p={timestamp:Date.now(),totalBytes:l,chunks:o};S({id:E(),sessionId:t.sessionId??"pending",timestamp:Date.now(),source:"rollup",category:"build",severity:"info",context:{sessionId:t.sessionId??"pending"},fingerprint:_({kind:"bundle",identity:"report"}),title:`Bundle report: ${o.length} chunks, ${l} bytes`,raw:{kind:"bundle-report",report:p}})},async closeBundle(){w&&(await w.close(),w=void 0)}}}d(lensmcpVitePlugin,"lensmcpVitePlugin"),f(lensmcpVitePlugin,"lensmcpVitePlugin"),u(lensmcpVitePlugin,"lensmcpVitePlugin");async function I(e,t){try{const[{transformSync:s},{lensmcpBabelPlugin:m}]=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:[[m,{rootDir:process.cwd(),production:!1}]],code:!0});return i?.code?{code:i.code,map:i.map}:null}catch{return null}}d(I,"L"),f(I,"F"),u(I,"runLensmcpBabel");export function handleClientEnvelope(e,t){U(e,O(t),t.sessionId)}d(handleClientEnvelope,"handleClientEnvelope"),f(handleClientEnvelope,"handleClientEnvelope"),u(handleClientEnvelope,"handleClientEnvelope");function C(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(C,"R"),f(C,"P"),u(C,"errorLocation");function T(e,t){const s=e.err?.message??"Vite error",m=e.err?.stack,i=C(e.err);return{id:E(),sessionId:t??"pending",timestamp:Date.now(),source:"vite",category:"build",severity:"error",context:{sessionId:t??"pending"},fingerprint:_({kind:"vite",identity:e.type??s,...i?{file:i.file}:{}}),title:s,message:m,...i?{location:i}:{},raw:{kind:"build-diagnostic",...i?{file:i.file}:{},...e.err?.plugin?{plugin:e.err.plugin}:{}}}}d(T,"O"),f(T,"j"),u(T,"viteErrorToEvent");function L(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
|
-
`}
|
|
224
|
+
`}d(L,"A"),f(L,"x"),u(L,"buildInlineClientRuntime");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lensmcp/vite-plugin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.20.0",
|
|
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.
|
|
19
|
-
"@lensmcp/core": "1.
|
|
20
|
-
"@lensmcp/protocol-types": "1.
|
|
21
|
-
"@lensmcp/react-instrumentation": "1.
|
|
22
|
-
"@lensmcp/valtio-instrumentation": "1.
|
|
18
|
+
"@lensmcp/bridge": "1.20.0",
|
|
19
|
+
"@lensmcp/core": "1.20.0",
|
|
20
|
+
"@lensmcp/protocol-types": "1.20.0",
|
|
21
|
+
"@lensmcp/react-instrumentation": "1.20.0",
|
|
22
|
+
"@lensmcp/valtio-instrumentation": "1.20.0",
|
|
23
23
|
"tslib": "^2.3.0"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|