@lensmcp/vite-plugin 1.18.6 → 1.18.8
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 +30 -5
- 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 r of
|
|
1
|
+
"use strict";var b=Object.defineProperty;var u=(e,t)=>b(e,"name",{value:t,configurable:!0});var I=Object.defineProperty,l=u((e,t)=>I(e,"name",{value:t,configurable:!0}),"u"),w=Object.defineProperty,d=l((e,t)=>w(e,"name",{value:t,configurable:!0}),"o"),k=Object.defineProperty,m=d((e,t)=>k(e,"name",{value:t,configurable:!0}),"o"),$=Object.defineProperty,f=m((e,t)=>$(e,"name",{value:t,configurable:!0}),"o"),h=Object.defineProperty,p=f((e,t)=>h(e,"name",{value:t,configurable:!0}),"o"),j=Object.defineProperty,g=p((e,t)=>j(e,"name",{value:t,configurable:!0}),"o"),x=Object.defineProperty,v=g((e,t)=>x(e,"name",{value:t,configurable:!0}),"o");import{fingerprint as a,ulid as c}from"@lensmcp/core";const T="pending";export function envelopeToEvent(e,t=T){const r=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,...r},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:c(),sessionId:t,timestamp:e.at,source:"client-runtime",category:"runtime",severity:"error",context:{sessionId:t,...r},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",y=e.args.map(o).join(" ");return{id:c(),sessionId:t,timestamp:e.at,source:"client-runtime",category:"runtime",severity:s,context:{sessionId:t,...r},fingerprint:a({kind:"runtime",identity:`console:${e.level}:${y.slice(0,80)}`}),title:`console.${e.level}`,message:y,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,...r},fingerprint:a({kind:"network",identity:`${e.method}:${i(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,...r},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,...r},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,...r,...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"),f(envelopeToEvent,"envelopeToEvent"),p(envelopeToEvent,"envelopeToEvent"),g(envelopeToEvent,"envelopeToEvent"),v(envelopeToEvent,"envelopeToEvent");function n(e){if(!e)return"unknown";const t=e.split(`
|
|
2
|
+
`).slice(0,2);for(const r of t){const s=r.match(/at\s+(\S+)/);if(s&&s[1])return s[1]}return"unknown"}u(n,"o"),l(n,"a"),d(n,"l"),m(n,"l"),f(n,"c"),p(n,"c"),g(n,"s"),v(n,"normaliseStackTopFrame");function i(e){try{return`${new URL(e,"http://x").pathname}`}catch{return e}}u(i,"a"),l(i,"c"),d(i,"d"),m(i,"d"),f(i,"l"),p(i,"l"),g(i,"m"),v(i,"normaliseUrl");function o(e){if(typeof e=="string")return e;try{return JSON.stringify(e)}catch{return String(e)}}u(o,"c"),l(o,"u"),d(o,"m"),m(o,"m"),f(o,"d"),p(o,"d"),g(o,"d"),v(o,"stringify");
|
package/lib/plugin.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var N=Object.defineProperty;var l=(e,t)=>N(e,"name",{value:t,configurable:!0});var x=Object.defineProperty,d=l((e,t)=>x(e,"name",{value:t,configurable:!0}),"l");import{fingerprint as v,ulid as b}from"@lensmcp/core";import{createBridgeServer as F,makePublisher as S,handleClientEnvelope as P}from"@lensmcp/bridge";const _="/@lensmcp/client-runtime",k="\0lensmcp-client-runtime";export function lensmcpVitePlugin(e={},t={}){const r=e.enabled??!0,p=e.wsHost??"127.0.0.1",o=e.injectClient??!0;let g,f;const y=S(t),L=e.aliasValtio??!0,R=e.transformSource??!0;return{name:"@lensmcp/vite-plugin",apply:r?void 0:()=>!1,enforce:"pre",wsPort:d(()=>g,"wsPort"),config(){if(!(!r||!L))return{resolve:{alias:[{find:/^valtio$/,replacement:"@lensmcp/valtio-instrumentation"}]}}},async configureServer(n){r&&(f=await F({host:p,port:e.wsPort??0,bus:t.bus,sessionId:t.sessionId}),g=f.port,n.ws.on("vite:error",i=>{y(T(i,t.sessionId))}))},resolveId(n){return n===_?k:null},load(n){if(n!==k)return null;const i=g??e.wsPort??0;return C({host:p,port:i})},async transform(n,i){if(!r||!R)return null;const s=i.split("?")[0]??i;if(s.includes("/node_modules/")||!/\.[jt]sx$/.test(s))return null;const c=await E(n,s);return c?{code:c.code,map:c.map}:null},transformIndexHtml(){if(!(!o||!r))return[{tag:"script",attrs:{type:"module",src:_},injectTo:"head-prepend"}]},handleHotUpdate(n){if(!r)return;const i=n.modules.map(s=>s.file??s.id??null).filter(s=>!!s);y({id:b(),sessionId:t.sessionId??"pending",timestamp:Date.now(),source:"vite",category:"build",severity:"info",context:{sessionId:t.sessionId??"pending"},fingerprint:v({kind:"hmr",identity:n.file}),title:`HMR ${n.file}`,location:{file:n.file},relatedFiles:i,raw:{kind:"hmr",file:n.file}})},generateBundle(n,i){if(!r)return;const s=[];let c=0;for(const A of Object.values(i)){const u=A,B=u.fileName;let h;if(u.type==="chunk")h=(u.code??"").length;else{const a=u.source;h=typeof a=="string"?a.length:a instanceof Uint8Array?a.byteLength:0}c+=h;const w=[];if(u.type==="chunk"&&u.modules){for(const[a,m]of Object.entries(u.modules)){const D=m.renderedLength??m.originalLength??0;w.push({id:a,sizeBytes:D})}w.sort((a,m)=>m.sizeBytes-a.sizeBytes)}s.push({name:B,sizeBytes:h,modules:w})}const O={timestamp:Date.now(),totalBytes:c,chunks:s};y({id:b(),sessionId:t.sessionId??"pending",timestamp:Date.now(),source:"rollup",category:"build",severity:"info",context:{sessionId:t.sessionId??"pending"},fingerprint:v({kind:"bundle",identity:"report"}),title:`Bundle report: ${s.length} chunks, ${c} bytes`,raw:{kind:"bundle-report",report:O}})},async closeBundle(){f&&(await f.close(),f=void 0)}}}l(lensmcpVitePlugin,"lensmcpVitePlugin"),d(lensmcpVitePlugin,"lensmcpVitePlugin");async function E(e,t){try{const[{transformSync:r},{lensmcpBabelPlugin:p}]=await Promise.all([import("@babel/core"),import("@lensmcp/react-instrumentation")]),o=r(e,{filename:t,babelrc:!1,configFile:!1,sourceMaps:!0,parserOpts:{plugins:["jsx","typescript"]},plugins:[[p,{rootDir:process.cwd(),production:!1}]],code:!0});return o?.code?{code:o.code,map:o.map}:null}catch{return null}}l(E,"B"),d(E,"runLensmcpBabel");export function handleClientEnvelope(e,t){P(e,S(t),t.sessionId)}l(handleClientEnvelope,"handleClientEnvelope"),d(handleClientEnvelope,"handleClientEnvelope");function I(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}:{}}}l(I,"D"),d(I,"errorLocation");function T(e,t){const r=e.err?.message??"Vite error",p=e.err?.stack,o=I(e.err);return{id:b(),sessionId:t??"pending",timestamp:Date.now(),source:"vite",category:"build",severity:"error",context:{sessionId:t??"pending"},fingerprint:v({kind:"vite",identity:e.type??r,...o?{file:o.file}:{}}),title:r,message:p,...o?{location:o}:{},raw:{kind:"build-diagnostic",...o?{file:o.file}:{},...e.err?.plugin?{plugin:e.err.plugin}:{}}}}l(T,"N"),d(T,"viteErrorToEvent");function C(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;
|
|
@@ -58,17 +58,42 @@
|
|
|
58
58
|
} catch (e) { return 'tab-' + Math.random().toString(36).slice(2, 10); }
|
|
59
59
|
})();
|
|
60
60
|
|
|
61
|
+
// BATCHED transport: capture is synchronous (per-event at/tabId stamped NOW \u2014 the recorded
|
|
62
|
+
// timeline is exact), but the stringify + socket frame happen ONCE per macrotask, off the
|
|
63
|
+
// interaction task. A commit storm (a tab switch mounting hundreds of components) used to pay
|
|
64
|
+
// one JSON.stringify + one ws.send INLINE per event \u2014 measured as the dominant slice of the
|
|
65
|
+
// post-switch long tasks. Same events, same order, same timestamps; only the transport moves.
|
|
66
|
+
let batch = [];
|
|
67
|
+
let flushScheduled = false;
|
|
68
|
+
function flushBatch() {
|
|
69
|
+
flushScheduled = false;
|
|
70
|
+
if (!batch.length) return;
|
|
71
|
+
const events = batch;
|
|
72
|
+
batch = [];
|
|
73
|
+
if (ws && ws.readyState === 1) {
|
|
74
|
+
try {
|
|
75
|
+
ws.send(JSON.stringify(events.length === 1 ? events[0] : { kind: 'batch', at: Date.now(), tabId: TAB_ID, events }));
|
|
76
|
+
return;
|
|
77
|
+
} catch (e) { /* fall through to queue */ }
|
|
78
|
+
}
|
|
79
|
+
for (const ev of events) queue.push(ev);
|
|
80
|
+
}
|
|
61
81
|
function send(env) {
|
|
62
82
|
env.at = Date.now();
|
|
63
83
|
env.tabId = TAB_ID;
|
|
64
|
-
|
|
65
|
-
|
|
84
|
+
batch.push(env);
|
|
85
|
+
if (!flushScheduled) { flushScheduled = true; setTimeout(flushBatch, 0); }
|
|
66
86
|
}
|
|
87
|
+
// The tab may die with a flush pending \u2014 drain synchronously so nothing is lost.
|
|
88
|
+
window.addEventListener('pagehide', flushBatch);
|
|
67
89
|
function open() {
|
|
68
90
|
try { ws = new WebSocket(WS_URL); } catch (e) { setTimeout(open, 1000); return; }
|
|
69
91
|
ws.addEventListener('open', () => {
|
|
70
92
|
openOnce = true;
|
|
71
|
-
while (queue.length) {
|
|
93
|
+
while (queue.length) {
|
|
94
|
+
const chunk = queue.splice(0, 200);
|
|
95
|
+
try { ws.send(JSON.stringify(chunk.length === 1 ? chunk[0] : { kind: 'batch', at: Date.now(), tabId: TAB_ID, events: chunk })); } catch (e) {}
|
|
96
|
+
}
|
|
72
97
|
send({ kind: 'ready', userAgent: navigator.userAgent, url: location.href });
|
|
73
98
|
});
|
|
74
99
|
ws.addEventListener('close', () => { if (openOnce) setTimeout(open, 1000); });
|
|
@@ -196,4 +221,4 @@
|
|
|
196
221
|
try { return JSON.parse(JSON.stringify(v)); } catch { return String(v); }
|
|
197
222
|
}
|
|
198
223
|
})();
|
|
199
|
-
`}l(
|
|
224
|
+
`}l(C,"F"),d(C,"buildInlineClientRuntime");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lensmcp/vite-plugin",
|
|
3
|
-
"version": "1.18.
|
|
3
|
+
"version": "1.18.8",
|
|
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.18.
|
|
19
|
-
"@lensmcp/core": "1.18.
|
|
20
|
-
"@lensmcp/protocol-types": "1.18.
|
|
21
|
-
"@lensmcp/react-instrumentation": "1.18.
|
|
22
|
-
"@lensmcp/valtio-instrumentation": "1.18.
|
|
18
|
+
"@lensmcp/bridge": "1.18.8",
|
|
19
|
+
"@lensmcp/core": "1.18.8",
|
|
20
|
+
"@lensmcp/protocol-types": "1.18.8",
|
|
21
|
+
"@lensmcp/react-instrumentation": "1.18.8",
|
|
22
|
+
"@lensmcp/valtio-instrumentation": "1.18.8",
|
|
23
23
|
"tslib": "^2.3.0"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|