2 lines
2.1 KiB
JavaScript

"use strict";var W=Object.defineProperty,j=Object.defineProperties;var T=Object.getOwnPropertyDescriptors;var y=Object.getOwnPropertySymbols;var I=Object.prototype.hasOwnProperty,b=Object.prototype.propertyIsEnumerable;var v=(e,t,n)=>t in e?W(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,g=(e,t)=>{for(var n in t||(t={}))I.call(t,n)&&v(e,n,t[n]);if(y)for(var n of y(t))b.call(t,n)&&v(e,n,t[n]);return e},h=(e,t)=>j(e,T(t));var f=(e,t,n)=>new Promise((r,s)=>{var u=a=>{try{m(n.next(a))}catch(p){s(p)}},d=a=>{try{m(n.throw(a))}catch(p){s(p)}},m=a=>a.done?r(a.value):Promise.resolve(a.value).then(u,d);m((n=n.apply(e,t)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("code-inspector-core"),w="vite-code-inspector-plugin",S=["isJsx","isTsx","lang.jsx","lang.tsx"];function _(e){const t={port:0,entry:"",output:e.output};return h(g({name:w},e.enforcePre===!1?{}:{enforce:"pre"}),{apply(r,{command:s}){return!e.close&&i.isDev(e.dev,s==="serve")},transform(r,s){return f(this,null,function*(){let u=e.exclude||[];Array.isArray(u)||(u=[u]);const d=i.matchCondition([...u,/\/node_modules\//],s),m=i.matchCondition(e.include||[],s);if(d&&!m)return r;r=yield i.getCodeWithWebComponent({options:e,file:s,code:r,record:t});const{escapeTags:a=[],mappings:p}=e,[x,C]=s.split("?",2);let l=i.normalizePath(x);l=i.getMappingFilePath(l,p);const c=new URLSearchParams(C);if(e.match&&!e.match.test(l))return r;let o="";return i.isJsTypeFile(l)||l.endsWith(".vue")&&(S.some(P=>c.get(P)!==null)||c.get("lang")==="tsx"||c.get("lang")==="jsx")?o="jsx":l.endsWith(".html")&&c.get("type")==="template"&&c.has("vue")||l.endsWith(".vue")&&c.get("type")!=="style"&&c.get("raw")===null?o="vue":l.endsWith(".svelte")&&(o="svelte"),o?i.transformCode({content:r,filePath:l,fileType:o,escapeTags:a,pathType:e.pathType}):r})},transformIndexHtml(r){return f(this,null,function*(){const s=yield i.getCodeWithWebComponent({options:h(g({},e),{importClient:"code"}),file:"main.js",code:"",record:t,inject:!0});return r.replace("<head>",'<head><script type="module">\n'.concat(s,"\n<\/script>"))})}})}exports.ViteCodeInspectorPlugin=_;