ms-vite-plugin 1.5.24 → 1.5.26

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 +1 @@
1
- "use strict";var j=exports&&exports.__createBinding||(Object.create?(function(t,e,n,r){r===void 0&&(r=n);var i=Object.getOwnPropertyDescriptor(e,n);(!i||("get"in i?!e.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(t,r,i)}):(function(t,e,n,r){r===void 0&&(r=n),t[r]=e[n]})),F=exports&&exports.__setModuleDefault||(Object.create?(function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}):function(t,e){t.default=e}),O=exports&&exports.__importStar||(function(){var t=function(e){return t=Object.getOwnPropertyNames||function(n){var r=[];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(r[r.length]=i);return r},t(e)};return function(e){if(e&&e.__esModule)return e;var n={};if(e!=null)for(var r=t(e),i=0;i<r.length;i++)r[i]!=="default"&&j(n,e,r[i]);return F(n,e),n}})();Object.defineProperty(exports,"__esModule",{value:!0}),exports.createDebugInstrumentPlugin=E;const g=O(require("acorn")),$=require("magic-string"),h="__kjs_bp_hit",_="__kjs_bp",f="__kjs_enter",l="__kjs_leave";function E(){let t=process.cwd();return{name:"kuaijs-debug-instrument",enforce:"post",configResolved(e){t=e.root||t},transform(e,n){const r=N(n,t);if(!r)return null;const i=D(e,r);if(i.length===0)return null;const s=new $(e);for(const o of i)o.start===o.end?s.appendLeft(o.start,o.text):s.overwrite(o.start,o.end,o.text);return{code:s.toString(),map:s.generateMap({hires:!0})}}}}function N(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 P(t){try{return g.parse(t,{allowHashBang:!0,ecmaVersion:"latest",sourceType:"script"})}catch{return g.parse(t,{allowHashBang:!0,ecmaVersion:"latest",sourceType:"module"})}}function D(t,e){const n=P(t),r=[],i=R(t),s=JSON.stringify(e);return b(n,[],{onStatement:(a,u)=>{if(typeof a.start!="number")return;const y=W(i,a.start),w=`()=>({${u.join(",")}})`,m=a.type==="DebuggerStatement",d=`${_}(${s},${y},${w}${m?",true":""})`;r.push({start:a.start,end:a.start,text:m?`${d};`:`${h}(${s},${y})&&${d};`})},onFunctionBody:a=>B(r,a),onExpressionBody:a=>x(r,a,t)}),r}function B(t,e){if(typeof e.start!="number"||typeof e.end!="number")return;let n=e.start+1;if(Array.isArray(e.body)){let r=0;for(;r<e.body.length&&v(e.body[r]);){const i=e.body[r];typeof i.end=="number"&&(n=i.end),r+=1}}t.push({start:n,end:n,text:`${f}();try{`}),t.push({start:e.end-1,end:e.end-1,text:`}finally{${l}();}`})}function x(t,e,n){const r=e.body;if(!r||typeof r.start!="number"||typeof r.end!="number")return;const i=n.slice(r.start,r.end),s=e.async?"(async()=>":"(()=>";t.push({start:r.start,end:r.end,text:`${s}{${f}();try{return ${i};}finally{${l}();}})()`})}function b(t,e,n,r=!1){if(!(!t||typeof t!="object")){if(S(t)){const i=new Map;for(const s of t.params??[])c(s,i);t.body?.type==="BlockStatement"?(C(t.body,i),n.onFunctionBody(t.body)):t.body&&n.onExpressionBody(t),e.push(i),p(t,e,n,r),e.pop();return}if(H(t)){e.push(new Map),p(t,e,n,r),e.pop();return}p(t,e,n,r)}}function p(t,e,n,r){for(const i of Object.keys(t)){if(i==="start"||i==="end"||i==="type")continue;const s=t[i],o=Array.isArray(s)?s:[s];for(const a of o){if(!a||typeof a!="object")continue;const u=T(t)&&M.has(i);!r&&!u&&V(a)&&!v(a)&&!k(a)&&n.onStatement(a,A(e)),b(a,e,n,r||u),I(a,e)}}}function A(t){const e=new Set;for(const n of t)for(const r of n.keys())e.add(r);return[...e].sort()}function I(t,e){const n=e[e.length-1];if(!n)return;if(t?.type==="VariableDeclaration"&&t.kind!=="var"){for(const i of t.declarations??[])c(i.id,n);return}const r=t?.declaration;r?.type==="ClassDeclaration"&&r.id?.name&&n.set(r.id.name,!0)}function c(t,e){if(t)switch(t.type){case"Identifier":e.set(t.name,!0);return;case"ObjectPattern":for(const n of t.properties??[])c(n.value??n.argument??n.key,e);return;case"ArrayPattern":for(const n of t.elements??[])c(n,e);return;case"AssignmentPattern":c(t.left,e);return;case"RestElement":c(t.argument,e);return;default:return}}function C(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??[])c(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 s=r[i],o=Array.isArray(s)?s:[s];for(const a of o)a&&typeof a=="object"&&n.push(a)}}}}function S(t){return t.type==="FunctionDeclaration"||t.type==="FunctionExpression"||t.type==="ArrowFunctionExpression"}const M=new Set(["init","left","right","test","update"]);function T(t){return t.type==="ForStatement"||t.type==="ForInStatement"||t.type==="ForOfStatement"}function H(t){return t.type==="BlockStatement"||t.type==="Program"||t.type==="SwitchStatement"||t.type==="ForStatement"||t.type==="ForInStatement"||t.type==="ForOfStatement"}function V(t){return t.type==="BlockStatement"||t.type==="EmptyStatement"?!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 k(t){const e=t?.expression;if(e?.type!=="CallExpression")return!1;const n=e.callee?.name;return n===h||n===_||n===f||n===l}function R(t){const e=[0];for(let n=0;n<t.length;n+=1)t.charCodeAt(n)===10&&e.push(n+1);return e}function W(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=I;const{parseSync:x}=require("oxc-parser"),A=require("magic-string"),F="__kjs_bp_hit",w="__kjs_bp",m="__kjs_enter",d="__kjs_leave",g="__kjs_throw",k="<anonymous>";function I(){let t=process.cwd(),n="";const e=new Map;return{name:"kuaijs-debug-instrument",enforce:"pre",configResolved(r){t=r.root||t,n=r.build?.outDir??""},writeBundle(){H(t,n,e)},transform(r,i){const s=D(i,t);if(!s)return null;const{edits:a,lines:o}=M(r,s,i);if(a.length===0)return null;const f=e.get(s)??new Set;for(const u of o)f.add(u);e.set(s,f);const c=new A(r);for(const u of a)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 D(t,n){if(!t||t.startsWith("\0")||t.includes("node_modules"))return null;const e=t.split("?")[0].split("#")[0];return!/\.[cm]?[jt]sx?$/.test(e)||!e.startsWith(n)?null:e.slice(n.length).replace(/^[\\/]+/,"").replace(/\\/g,"/")}function B(t,n){try{const e=x(t,n);return Array.isArray(e?.errors)&&e.errors.length>0?null:e?.program??null}catch{return null}}function M(t,n,e){const r=B(e,t);if(!r)return{edits:[],lines:[]};const i=[],s=Y(t),a=JSON.stringify(n),o=new Set;return O(r,[],{onStatement:(c,u)=>{if(typeof c.start!="number")return;const p=_(s,c.start),v=`()=>({${u.map(l=>l.writable?`get ${l.name}(){return ${l.name}},set ${l.name}(v){${l.name}=v}`:`get ${l.name}(){return ${l.name}}`).join(",")}})`,N=c.type==="DebuggerStatement",$=`${w}(${a},${p},${v}${N?",true":""})`;o.add(p),i.push({start:c.start,end:c.start,text:N?`${$};`:`${F}(${a},${p})&&${$};`})},onFunctionBody:c=>L(i,c,n,_(s,c.start)),onExpressionBody:c=>C(i,c,t,n,_(s,c.start))}),{edits:i,lines:[...o].sort((c,u)=>c-u)}}const P="kuaijs-debug-lines.json";function H(t,n,e){if(!t||!n)return;const r={};for(const[i,s]of e)r[i]=[...s].sort((a,o)=>a-o);try{const i=require("fs"),s=require("path"),a=s.join(t,n);i.mkdirSync(a,{recursive:!0}),i.writeFileSync(s.join(a,P),JSON.stringify(r),"utf8")}catch{}}function L(t,n,e,r){const i=n?.body;if(!i||typeof i.start!="number"||typeof i.end!="number")return;const s=JSON.stringify(E(n));let a=i.start+1;if(Array.isArray(i.body)){let o=0;for(;o<i.body.length&&j(i.body[o]);){const f=i.body[o];typeof f.end=="number"&&(a=f.end),o+=1}}t.push({start:a,end:a,text:`${m}(${s},${JSON.stringify(e)},${r});try{`}),t.push({start:i.end-1,end:i.end-1,text:`}catch(e){${g}(e);throw e}finally{${d}();}`})}function C(t,n,e,r,i){const s=n.body;if(!s||typeof s.start!="number"||typeof s.end!="number")return;const a=e.slice(s.start,s.end),o=n.async?"(async()=>":"(()=>",f=JSON.stringify(E(n));t.push({start:s.start,end:s.end,text:`${o}{${m}(${f},${JSON.stringify(r)},${i});try{return ${a};}catch(e){${g}(e);throw e}finally{${d}();}})()`})}function E(t){const n=t?.id?.name;if(typeof n=="string"&&n)return n;const e=t?.__kjsNameHint;return typeof e=="string"&&e?e:k}function T(t,n,e){if(!S(e))return"";if(t?.type==="VariableDeclarator"&&n==="init"&&t.id?.type==="Identifier")return t.id.name;if(t?.type==="Property"&&n==="value"||(t?.type==="MethodDefinition"||t?.type==="PropertyDefinition")&&n==="value")return h(t.key);if(t?.type==="AssignmentExpression"&&n==="right"){const r=t.left;if(r?.type==="Identifier")return r.name;if(r?.type==="MemberExpression"&&r.property)return h(r.property)}return""}function h(t){return t?t.type==="Identifier"&&typeof t.name=="string"?t.name:t.type==="Literal"&&typeof t.value=="string"?t.value:"":""}function O(t,n,e,r=!1){if(!(!t||typeof t!="object")){if(S(t)){const i=new Map;for(const s of t.params??[])y(s,i);t.body?.type==="BlockStatement"?(U(t.body,i),e.onFunctionBody(t)):t.body&&e.onExpressionBody(t),n.push(i),b(t,n,e,r),n.pop();return}if(q(t)){n.push(new Map),b(t,n,e,r),n.pop();return}b(t,n,e,r)}}function b(t,n,e,r){for(const i of Object.keys(t)){if(i==="start"||i==="end"||i==="type")continue;const s=t[i],a=Array.isArray(s)?s:[s];for(const o of a){if(!o||typeof o!="object")continue;const f=V(t)&&W.has(i),c=t.type==="LabeledStatement"&&i==="body",u=T(t,i,o);u&&!o.__kjsNameHint&&(o.__kjsNameHint=u),!r&&!f&&!c&&K(o)&&!j(o)&&!G(o)&&e.onStatement(o,J(n)),O(o,n,e,r||f),R(o,n)}}}function J(t){const n=new Map;for(let e=t.length-1;e>=0;e-=1)for(const[r,i]of t[e])n.has(r)||n.set(r,i);return[...n.entries()].map(([e,r])=>({name:e,writable:r})).sort((e,r)=>e.name<r.name?-1:e.name>r.name?1:0)}function R(t,n){const e=n[n.length-1];if(!e)return;if(t?.type==="VariableDeclaration"&&t.kind!=="var"){const i=t.kind!=="const";for(const s of t.declarations??[])y(s.id,e,i);return}const r=t?.declaration;r?.type==="ClassDeclaration"&&r.id?.name&&e.set(r.id.name,!0)}function y(t,n,e=!0){if(t)switch(t.type){case"Identifier":n.set(t.name,e);return;case"ObjectPattern":for(const r of t.properties??[])y(r.value??r.argument??r.key,n,e);return;case"ArrayPattern":for(const r of t.elements??[])y(r,n,e);return;case"AssignmentPattern":y(t.left,n,e);return;case"RestElement":y(t.argument,n);return;default:return}}function U(t,n){const e=[t];for(;e.length>0;){const r=e.pop();if(!(!r||typeof r!="object")){if(r.type==="VariableDeclaration"&&r.kind==="var")for(const i of r.declarations??[])y(i.id,n);if(r.type==="FunctionDeclaration"&&r.id?.name&&n.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 s=r[i],a=Array.isArray(s)?s:[s];for(const o of a)o&&typeof o=="object"&&e.push(o)}}}}function S(t){return t.type==="FunctionDeclaration"||t.type==="FunctionExpression"||t.type==="ArrowFunctionExpression"}const W=new Set(["init","left","right","test","update"]);function V(t){return t.type==="ForStatement"||t.type==="ForInStatement"||t.type==="ForOfStatement"}function q(t){return t.type==="BlockStatement"||t.type==="Program"||t.type==="SwitchStatement"||t.type==="ForStatement"||t.type==="ForInStatement"||t.type==="ForOfStatement"}function K(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 j(t){return t?.type==="ExpressionStatement"&&t.expression?.type==="Literal"&&typeof t.expression.value=="string"}function G(t){const n=t?.expression;if(n?.type!=="CallExpression")return!1;const e=n.callee?.name;return e===F||e===w||e===m||e===d||e===g}function Y(t){const n=[0];for(let e=0;e<t.length;e+=1)t.charCodeAt(e)===10&&n.push(e+1);return n}function _(t,n){let e=0,r=t.length-1;for(;e<r;){const i=e+r+1>>1;t[i]<=n?e=i:r=i-1}return e+1}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ms-vite-plugin",
3
- "version": "1.5.24",
3
+ "version": "1.5.26",
4
4
  "type": "commonjs",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -35,6 +35,7 @@
35
35
  "jpeg-js": "^0.4.4",
36
36
  "kuaijs-forward-service": "^0.1.1",
37
37
  "magic-string": "^0.30.21",
38
+ "oxc-parser": "^0.151.0",
38
39
  "pngjs": "^7.0.0",
39
40
  "uuid": "^14.0.0",
40
41
  "vite": "^8.0.13",
@@ -53,4 +54,4 @@
53
54
  "esbuild": "^0.28.2",
54
55
  "typescript": "~6.0.3"
55
56
  }
56
- }
57
+ }