ms-vite-plugin 1.5.28 → 1.5.29

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.
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.createDebugInstrumentPlugin=C;const{parseSync:D}=require("oxc-parser"),x=require("magic-string"),F="__kjs_bp_hit",E="__kjs_bp",d="__kjs_enter",$="__kjs_leave",h="__kjs_throw",f="__kjsErr",A="<anonymous>";function C(){let t=process.cwd(),e="";const n=new Map;return{name:"kuaijs-debug-instrument",enforce:"pre",configResolved(r){t=r.root||t,e=r.build?.outDir??""},writeBundle(){H(t,e,n)},renderChunk(r){return M(r)},transform(r,i){const a=k(i,t);if(!a)return null;const{edits:o,lines:s}=B(r,a,i);if(o.length===0)return null;const l=n.get(a)??new Set;for(const u of s)l.add(u);n.set(a,l);const c=new x(r);for(const u of o)u.start===u.end?c.appendLeft(u.start,u.text):c.overwrite(u.start,u.end,u.text);return{code:c.toString(),map:c.generateMap({hires:!0})}}}}function k(t,e){if(!t||t.startsWith("\0")||t.includes("node_modules"))return null;const n=t.split("?")[0].split("#")[0];return!/\.[cm]?[jt]sx?$/.test(n)||!n.startsWith(e)?null:n.slice(e.length).replace(/^[\\/]+/,"").replace(/\\/g,"/")}function L(t,e){try{const n=D(t,e);return Array.isArray(n?.errors)&&n.errors.length>0?null:n?.program??null}catch{return null}}function B(t,e,n){const r=L(n,t);if(!r)return{edits:[],lines:[]};const i=[],a=Z(t),o=JSON.stringify(e),s=new Set;return j(r,[],{onStatement:(c,u)=>{if(typeof c.start!="number")return;const m=_(a,c.start),I=`()=>({${u.map(y=>y.writable?`get ${y.name}(){return ${y.name}},set ${y.name}(v){${y.name}=v}`:`get ${y.name}(){return ${y.name}}`).join(",")}})`,N=c.type==="DebuggerStatement",w=`${E}(${o},${m},${I}${N?",true":""})`;s.add(m),i.push({start:c.start,end:c.start,text:N?`${w};`:`${F}(${o},${m})&&${w};`})},onFunctionBody:c=>R(i,c,e,_(a,c.start)),onExpressionBody:c=>J(i,c,t,e,_(a,c.start)),onCatchClause:c=>U(i,c)}),{edits:i,lines:[...s].sort((c,u)=>c-u)}}function M(t){if(!t||/(^|[\s;])export[\s{]/.test(t)||/(^|[\s;])import[\s({]/.test(t))return null;const e=new x(t);return e.prepend("try{"),e.appendLeft(P(t),`}catch(${f}){if(typeof ${h}==='function')${h}(${f},()=>({exception:${f}}));throw ${f}}`),{code:e.toString(),map:e.generateMap({hires:!0})}}function P(t){const n=t.lastIndexOf(`
2
- `)+1;return t.slice(n).trimStart().startsWith("//")?n:t.length}const T="kuaijs-debug-lines.json";function H(t,e,n){if(!t||!e)return;const r={};for(const[i,a]of n)r[i]=[...a].sort((o,s)=>o-s);try{const i=require("fs"),a=require("path"),o=a.join(t,e);i.mkdirSync(o,{recursive:!0}),i.writeFileSync(a.join(o,T),JSON.stringify(r),"utf8")}catch{}}function R(t,e,n,r){const i=e?.body;if(!i||typeof i.start!="number"||typeof i.end!="number")return;const a=JSON.stringify(O(e));let o=i.start+1;if(Array.isArray(i.body)){let s=0;for(;s<i.body.length&&v(i.body[s]);){const l=i.body[s];typeof l.end=="number"&&(o=l.end),s+=1}}t.push({start:o,end:o,text:`${d}(${a},${JSON.stringify(n)},${r});try{`}),t.push({start:i.end-1,end:i.end-1,text:`}catch(${f}){${h}(${f},()=>({exception:${f}}));throw ${f}}finally{${$}();}`})}function J(t,e,n,r,i){const a=e.body;if(!a||typeof a.start!="number"||typeof a.end!="number")return;const o=n.slice(a.start,a.end),s=e.async?"(async()=>":"(()=>",l=JSON.stringify(O(e));t.push({start:a.start,end:a.end,text:`${s}{${d}(${l},${JSON.stringify(r)},${i});try{return ${o};}catch(${f}){${h}(${f},()=>({exception:${f}}));throw ${f}}finally{${$}();}})()`})}function O(t){const e=t?.id?.name;if(typeof e=="string"&&e)return e;const n=t?.__kjsNameHint;return typeof n=="string"&&n?n:A}function W(t,e,n){if(!S(n))return"";if(t?.type==="VariableDeclarator"&&e==="init"&&t.id?.type==="Identifier")return t.id.name;if(t?.type==="Property"&&e==="value"||(t?.type==="MethodDefinition"||t?.type==="PropertyDefinition")&&e==="value")return b(t.key);if(t?.type==="AssignmentExpression"&&e==="right"){const r=t.left;if(r?.type==="Identifier")return r.name;if(r?.type==="MemberExpression"&&r.property)return b(r.property)}return""}function b(t){return t?t.type==="Identifier"&&typeof t.name=="string"?t.name:t.type==="Literal"&&typeof t.value=="string"?t.value:"":""}function U(t,e){if(e?.param?.type!=="Identifier"||typeof e.body?.start!="number")return;const n=e.param.name;t.push({start:e.body.start+1,end:e.body.start+1,text:`${h}(${n},()=>({exception:${n}}));`})}function j(t,e,n,r=!1){if(!(!t||typeof t!="object")){if(S(t)){const i=new Map;for(const a of t.params??[])p(a,i);t.body?.type==="BlockStatement"?(G(t.body,i),n.onFunctionBody(t)):t.body&&n.onExpressionBody(t),e.push(i),g(t,e,n,r),e.pop();return}if(t.type==="Program"){const i=new Map;for(const a of t.body??[])if(a?.type==="ImportDeclaration")for(const o of a.specifiers??[])o?.local?.name&&i.set(o.local.name,!1);e.push(i),g(t,e,n,r),e.pop();return}if(t.type==="CatchClause"){n.onCatchClause(t);const i=new Map;t.param&&p(t.param,i,!0),e.push(i),g(t,e,n,r),e.pop();return}if(z(t)){e.push(new Map),g(t,e,n,r),e.pop();return}g(t,e,n,r)}}function g(t,e,n,r){for(const i of Object.keys(t)){if(i==="start"||i==="end"||i==="type")continue;const a=t[i],o=Array.isArray(a)?a:[a];for(const s of o){if(!s||typeof s!="object")continue;const l=Y(t)&&K.has(i),c=t.type==="LabeledStatement"&&i==="body",u=(t.type==="ExportNamedDeclaration"||t.type==="ExportDefaultDeclaration")&&i==="declaration",m=W(t,i,s);m&&!s.__kjsNameHint&&(s.__kjsNameHint=m),!r&&!l&&!c&&!u&&Q(s)&&!v(s)&&!X(s)&&n.onStatement(s,V(e)),j(s,e,n,r||l),q(s,e)}}}function V(t){const e=new Map;for(let n=t.length-1;n>=0;n-=1)for(const[r,i]of t[n])e.has(r)||e.set(r,i);return[...e.entries()].map(([n,r])=>({name:n,writable:r})).sort((n,r)=>n.name<r.name?-1:n.name>r.name?1:0)}function q(t,e){const n=e[e.length-1];if(!n)return;if(t?.type==="VariableDeclaration"&&t.kind!=="var"){const i=t.kind!=="const";for(const a of t.declarations??[])p(a.id,n,i);return}const r=t?.declaration;r?.type==="ClassDeclaration"&&r.id?.name&&n.set(r.id.name,!0)}function p(t,e,n=!0){if(t)switch(t.type){case"Identifier":e.set(t.name,n);return;case"ObjectPattern":for(const r of t.properties??[])p(r.value??r.argument??r.key,e,n);return;case"ArrayPattern":for(const r of t.elements??[])p(r,e,n);return;case"AssignmentPattern":p(t.left,e,n);return;case"RestElement":p(t.argument,e);return;default:return}}function G(t,e){const n=[t];for(;n.length>0;){const r=n.pop();if(!(!r||typeof r!="object")){if(r.type==="VariableDeclaration"&&r.kind==="var")for(const i of r.declarations??[])p(i.id,e);if(r.type==="FunctionDeclaration"&&r.id?.name&&e.set(r.id.name,!0),!(S(r)&&r!==t))for(const i of Object.keys(r)){if(i==="start"||i==="end"||i==="type")continue;const a=r[i],o=Array.isArray(a)?a:[a];for(const s of o)s&&typeof s=="object"&&n.push(s)}}}}function S(t){return t.type==="FunctionDeclaration"||t.type==="FunctionExpression"||t.type==="ArrowFunctionExpression"}const K=new Set(["init","left","right","test","update"]);function Y(t){return t.type==="ForStatement"||t.type==="ForInStatement"||t.type==="ForOfStatement"}function z(t){return t.type==="BlockStatement"||t.type==="Program"||t.type==="SwitchStatement"||t.type==="ForStatement"||t.type==="ForInStatement"||t.type==="ForOfStatement"}function Q(t){return t.type==="BlockStatement"||t.type==="EmptyStatement"||t.type==="LabeledStatement"?!1:typeof t.type=="string"&&(t.type.endsWith("Statement")||t.type.endsWith("Declaration"))}function v(t){return t?.type==="ExpressionStatement"&&t.expression?.type==="Literal"&&typeof t.expression.value=="string"}function X(t){const e=t?.expression;if(e?.type!=="CallExpression")return!1;const n=e.callee?.name;return n===F||n===E||n===d||n===$||n===h}function Z(t){const e=[0];for(let n=0;n<t.length;n+=1)t.charCodeAt(n)===10&&e.push(n+1);return e}function _(t,e){let n=0,r=t.length-1;for(;n<r;){const i=n+r+1>>1;t[i]<=e?n=i:r=i-1}return n+1}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.createDebugInstrumentPlugin=T;const{parseSync:k}=require("oxc-parser"),x=require("magic-string"),O="__kjs_bp_hit",E="__kjs_bp",b="__kjs_enter",S="__kjs_leave",g="__kjs_throw",F="__kjs_pos",u="__kjsErr",D="<anonymous>";function T(){let t=process.cwd(),e="";const n=new Map;return{name:"kuaijs-debug-instrument",enforce:"pre",configResolved(r){t=r.root||t,e=r.build?.outDir??""},writeBundle(){R(t,e,n)},renderChunk(r){return H(r)},transform(r,i){const a=L(i,t);if(!a)return null;const{edits:c,lines:s}=M(r,a,i);if(c.length===0)return null;const l=n.get(a)??new Set;for(const f of s)l.add(f);n.set(a,l);const o=new x(r);for(const f of c)f.start===f.end?o.appendLeft(f.start,f.text):o.overwrite(f.start,f.end,f.text);return{code:o.toString(),map:o.generateMap({hires:!0})}}}}function L(t,e){if(!t||t.startsWith("\0")||t.includes("node_modules"))return null;const n=t.split("?")[0].split("#")[0];return!/\.[cm]?[jt]sx?$/.test(n)||!n.startsWith(e)?null:n.slice(e.length).replace(/^[\\/]+/,"").replace(/\\/g,"/")}function B(t,e){try{const n=k(t,e);return Array.isArray(n?.errors)&&n.errors.length>0?null:n?.program??null}catch{return null}}function M(t,e,n){const r=B(n,t);if(!r)return{edits:[],lines:[]};const i=[],a=et(t),c=JSON.stringify(e),s=new Set;return I(r,[],{onStatement:(o,f)=>{if(typeof o.start!="number")return;const y=h(a,o.start),A=`()=>({${f.map(m=>m.writable?`get ${m.name}(){return ${m.name}},set ${m.name}(v){${m.name}=v}`:`get ${m.name}(){return ${m.name}}`).join(",")}})`,_=o.type==="DebuggerStatement",w=`${E}(${c},${y},${A}${_?",true":""})`;s.add(y),i.push({start:o.start,end:o.start,text:_?`${w};`:`${O}(${c},${y})&&${w};`}),C(o)&&i.push({start:o.start,end:o.start,text:`${F}(${c},${y});`})},onFunctionBody:o=>U(i,o,e,h(a,o.start)),onExpressionBody:o=>W(i,o,t,e,h(a,o.start)),onCatchClause:o=>q(i,o,e,h(a,o.start))}),{edits:i,lines:[...s].sort((o,f)=>o-f)}}function H(t){if(!t||/(^|[\s;])export[\s{]/.test(t)||/(^|[\s;])import[\s({]/.test(t))return null;const e=new x(t);return e.prepend("try{"),e.appendLeft(P(t),`}catch(${u}){if(typeof ${g}==='function')${g}(${u},"",0,()=>({exception:${u}}));throw ${u}}`),{code:e.toString(),map:e.generateMap({hires:!0})}}function P(t){const n=t.lastIndexOf(`
2
+ `)+1;return t.slice(n).trimStart().startsWith("//")?n:t.length}const J="kuaijs-debug-lines.json";function R(t,e,n){if(!t||!e)return;const r={};for(const[i,a]of n)r[i]=[...a].sort((c,s)=>c-s);try{const i=require("fs"),a=require("path"),c=a.join(t,e);i.mkdirSync(c,{recursive:!0}),i.writeFileSync(a.join(c,J),JSON.stringify(r),"utf8")}catch{}}function U(t,e,n,r){const i=e?.body;if(!i||typeof i.start!="number"||typeof i.end!="number")return;const a=JSON.stringify(j(e));let c=i.start+1;if(Array.isArray(i.body)){let s=0;for(;s<i.body.length&&v(i.body[s]);){const l=i.body[s];typeof l.end=="number"&&(c=l.end),s+=1}}t.push({start:c,end:c,text:`${b}(${a},${JSON.stringify(n)},${r});try{`}),t.push({start:i.end-1,end:i.end-1,text:`}catch(${u}){${g}(${u},${JSON.stringify(n)},${r},()=>({exception:${u}}));throw ${u}}finally{${S}();}`})}function W(t,e,n,r,i){const a=e.body;if(!a||typeof a.start!="number"||typeof a.end!="number")return;const c=n.slice(a.start,a.end),s=e.async?"(async()=>":"(()=>",l=JSON.stringify(j(e));t.push({start:a.start,end:a.end,text:`${s}{${b}(${l},${JSON.stringify(r)},${i});try{return ${c};}catch(${u}){${g}(${u},${JSON.stringify(r)},${i},()=>({exception:${u}}));throw ${u}}finally{${S}();}})()`})}function j(t){const e=t?.id?.name;if(typeof e=="string"&&e)return e;const n=t?.__kjsNameHint;return typeof n=="string"&&n?n:D}function V(t,e,n){if(!N(n))return"";if(t?.type==="VariableDeclarator"&&e==="init"&&t.id?.type==="Identifier")return t.id.name;if(t?.type==="Property"&&e==="value"||(t?.type==="MethodDefinition"||t?.type==="PropertyDefinition")&&e==="value")return d(t.key);if(t?.type==="AssignmentExpression"&&e==="right"){const r=t.left;if(r?.type==="Identifier")return r.name;if(r?.type==="MemberExpression"&&r.property)return d(r.property)}return""}function d(t){return t?t.type==="Identifier"&&typeof t.name=="string"?t.name:t.type==="Literal"&&typeof t.value=="string"?t.value:"":""}function q(t,e,n,r){if(e?.param?.type!=="Identifier"||typeof e.body?.start!="number")return;const i=e.param.name;t.push({start:e.body.start+1,end:e.body.start+1,text:`${g}(${i},${JSON.stringify(n)},${r},()=>({exception:${i}}));`})}function I(t,e,n,r=!1){if(!(!t||typeof t!="object")){if(N(t)){const i=new Map;for(const a of t.params??[])p(a,i);t.body?.type==="BlockStatement"?(Y(t.body,i),n.onFunctionBody(t)):t.body&&n.onExpressionBody(t),e.push(i),$(t,e,n,r),e.pop();return}if(t.type==="Program"){const i=new Map;for(const a of t.body??[])if(a?.type==="ImportDeclaration")for(const c of a.specifiers??[])c?.local?.name&&i.set(c.local.name,!1);e.push(i),$(t,e,n,r),e.pop();return}if(t.type==="CatchClause"){n.onCatchClause(t);const i=new Map;t.param&&p(t.param,i,!0),e.push(i),$(t,e,n,r),e.pop();return}if(X(t)){e.push(new Map),$(t,e,n,r),e.pop();return}$(t,e,n,r)}}function $(t,e,n,r){for(const i of Object.keys(t)){if(i==="start"||i==="end"||i==="type")continue;const a=t[i],c=Array.isArray(a)?a:[a];for(const s of c){if(!s||typeof s!="object")continue;const l=Q(t)&&z.has(i),o=t.type==="LabeledStatement"&&i==="body",f=(t.type==="ExportNamedDeclaration"||t.type==="ExportDefaultDeclaration")&&i==="declaration",y=V(t,i,s);y&&!s.__kjsNameHint&&(s.__kjsNameHint=y),!r&&!l&&!o&&!f&&Z(s)&&!v(s)&&!tt(s)&&n.onStatement(s,G(e)),I(s,e,n,r||l),K(s,e)}}}function G(t){const e=new Map;for(let n=t.length-1;n>=0;n-=1)for(const[r,i]of t[n])e.has(r)||e.set(r,i);return[...e.entries()].map(([n,r])=>({name:n,writable:r})).sort((n,r)=>n.name<r.name?-1:n.name>r.name?1:0)}function K(t,e){const n=e[e.length-1];if(!n)return;if(t?.type==="VariableDeclaration"&&t.kind!=="var"){const i=t.kind!=="const";for(const a of t.declarations??[])p(a.id,n,i);return}const r=t?.declaration;r?.type==="ClassDeclaration"&&r.id?.name&&n.set(r.id.name,!0)}function p(t,e,n=!0){if(t)switch(t.type){case"Identifier":e.set(t.name,n);return;case"ObjectPattern":for(const r of t.properties??[])p(r.value??r.argument??r.key,e,n);return;case"ArrayPattern":for(const r of t.elements??[])p(r,e,n);return;case"AssignmentPattern":p(t.left,e,n);return;case"RestElement":p(t.argument,e);return;default:return}}function Y(t,e){const n=[t];for(;n.length>0;){const r=n.pop();if(!(!r||typeof r!="object")){if(r.type==="VariableDeclaration"&&r.kind==="var")for(const i of r.declarations??[])p(i.id,e);if(r.type==="FunctionDeclaration"&&r.id?.name&&e.set(r.id.name,!0),!(N(r)&&r!==t))for(const i of Object.keys(r)){if(i==="start"||i==="end"||i==="type")continue;const a=r[i],c=Array.isArray(a)?a:[a];for(const s of c)s&&typeof s=="object"&&n.push(s)}}}}function N(t){return t.type==="FunctionDeclaration"||t.type==="FunctionExpression"||t.type==="ArrowFunctionExpression"}const z=new Set(["init","left","right","test","update"]);function Q(t){return t.type==="ForStatement"||t.type==="ForInStatement"||t.type==="ForOfStatement"}function X(t){return t.type==="BlockStatement"||t.type==="Program"||t.type==="SwitchStatement"||t.type==="ForStatement"||t.type==="ForInStatement"||t.type==="ForOfStatement"}function Z(t){return t.type==="BlockStatement"||t.type==="EmptyStatement"||t.type==="LabeledStatement"?!1:typeof t.type=="string"&&(t.type.endsWith("Statement")||t.type.endsWith("Declaration"))}function v(t){return t?.type==="ExpressionStatement"&&t.expression?.type==="Literal"&&typeof t.expression.value=="string"}function C(t){if(!t||typeof t!="object")return!1;if(t.type==="CallExpression"||t.type==="NewExpression"||t.type==="TaggedTemplateExpression")return!0;for(const e of Object.keys(t)){if(e==="start"||e==="end"||e==="type")continue;const n=t[e],r=Array.isArray(n)?n:[n];for(const i of r)if(i&&typeof i=="object"&&C(i))return!0}return!1}function tt(t){const e=t?.expression;if(e?.type!=="CallExpression")return!1;const n=e.callee?.name;return n===O||n===E||n===b||n===S||n===g||n===F}function et(t){const e=[0];for(let n=0;n<t.length;n+=1)t.charCodeAt(n)===10&&e.push(n+1);return e}function h(t,e){let n=0,r=t.length-1;for(;n<r;){const i=n+r+1>>1;t[i]<=e?n=i:r=i-1}return n+1}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ms-vite-plugin",
3
- "version": "1.5.28",
3
+ "version": "1.5.29",
4
4
  "type": "commonjs",
5
5
  "license": "MIT",
6
6
  "publishConfig": {