@visulima/vite-overlay 2.0.10 → 2.0.12
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.
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import{createRequire as T}from"node:module";import{distance as x}from"fastest-levenshtein";let D;const I=e=>(D??=T(import.meta.url))(e),v=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,C=e=>{if(typeof v<"u"&&v.versions&&v.versions.node){const[n,o]=v.versions.node.split(".").map(Number);if(n>22||n===22&&o>=3||n===20&&o>=16)return v.getBuiltinModule(e)}return I(e)},V=C("node:fs"),c=C("node:path"),k=/Failed to resolve import ["']([^"']+)["']/,P=/Cannot resolve module ["']([^"']+)["']/,R=/Cannot resolve ["'](\.\.?\/[^"']*)["']/,F=4,M=1e3,A=5,E=.5,L=[".js",".ts",".jsx",".tsx",".mjs",".cjs"],$=[".css",".scss",".sass",".less"],_=[".svg",".png",".jpg",".jpeg",".gif",".webp",".ico"],H=new Set([..._,...L,...$]),a=(e,...n)=>{const o=e.toLowerCase();return n.some(i=>o.includes(i.toLowerCase()))},q=(e,n)=>{const o=c.relative(e,n);return o.startsWith(".")?o:`./${o}`},B=e=>e===0?"":e===1?" (in parent directory)":e===2?" (in grandparent directory)":` (${e} directories away)`,O=(e,n)=>{try{const o=c.relative(e,n).split(c.sep).filter(t=>t&&t!==".");let i=0;for(const t of o)i+=t===".."?2:1;return i}catch{return 10}},U=(e,n,o,i)=>{if(n&&i===n){const s=x(e,o);return s<=Math.max(3,Math.floor(e.length*E))?10-s:0}if(!n){const s=x(e,o);return s===0?9:s<=Math.max(2,Math.floor(e.length*.3))&&H.has(i)?7-s:0}const t=x(e,o);return t<=Math.max(2,Math.floor(e.length*.4))?5-t:0},N=async(e,n)=>{const o=n.get(e);if(o!==void 0)return o;let i;try{i=(await V.promises.readdir(e,{withFileTypes:!0})).map(t=>({isDirectory:t.isDirectory(),isFile:t.isFile(),name:t.name}))}catch{i=[]}return n.set(e,i),i},z=async(e,n,o,i)=>{const t=[],s=async(l,u=0)=>{if(u>F||t.length>M)return;const p=await N(l,i);for(const r of p){if(t.length>M)break;const f=c.join(l,r.name);if(r.isDirectory&&!r.name.startsWith(".")&&r.name!=="node_modules")await s(f,u+1);else if(r.isFile){const m=c.extname(r.name),g=c.basename(r.name,m),y=U(n,o,g,m);y>0&&t.push({baseName:g,extension:m,fullPath:f,path:f,relevanceScore:y})}}};return await s(e),t},j=async(e,n,o,i)=>{const t=c.basename(e),s=c.extname(t),l=c.basename(t,s),u=c.dirname(n),p=(await z(o,l,s,i)).map(d=>{const h=x(l,d.baseName),b=O(u,c.dirname(d.fullPath)),w=d.relevanceScore*.7-b*.2-h*.1;return{...d,nameDistance:h,pathDistance:b,score:w}});p.sort((d,h)=>h.score-d.score);const r=[],f=p.slice(0,8);let m=!1;for(const d of f){const h=q(u,d.fullPath);if(!r.includes(h)){const b=B(d.pathDistance);r.push(h+b);const w=d.fullPath.replaceAll("\\","/").split("/"),S=w.indexOf("public");S!==-1&&S<w.length-1&&(m=!0)}}const g=[...new Set(r)].slice(0,A);if(g.length===0)return"";let y=g.map(d=>`- \`${d}\``).join(`
|
|
2
|
+
`);if(m){const d=t;[..._].some(h=>d.includes(h))&&(y+=`
|
|
3
|
+
|
|
4
|
+
Files in the \`public\` folder should be accessed via absolute URLs like \`/${d}\`.`)}return y},W=[{solution:{body:"Browser APIs like `window` and `document` are not available during server-side rendering. Use dynamic imports or check for SSR environment before using browser APIs.",header:"SSR Browser API Error"},test:e=>a(e,"window is not defined","document is not defined")},{solution:{body:"Some plugins need specific ordering. Use `enforce: 'pre'` for plugins that need to run first, or `enforce: 'post'` for plugins that need to run last.",header:"Plugin Ordering Issue"},test:e=>a(e,"Plugin ordering","enforce")},{solution:{body:"CSS Modules require proper configuration. Make sure your CSS files use the `.module.css` extension and are imported correctly.",header:"CSS Modules Configuration"},test:e=>a(e,"CSS Modules","module.css")},{solution:{body:["Only variables prefixed with `VITE_` are exposed on `import.meta.env` to the client at build time.","Server-only variables should not be prefixed with `VITE_`.","- Do not use `process.env` in browser code; prefer `import.meta.env.*`","- Custom vars must be prefixed with `VITE_` to be exposed to client",'- For TS, add `/// <reference types="vite/client" />` for type-safe access'].join(`
|
|
5
|
+
`),header:"Environment Variables"},test:e=>a(e,"VITE_","process.env")},{solution:{body:"For static assets, use the `new URL('./path/to/asset', import.meta.url)` syntax or import them and use the returned URL.",header:"Asset Import Issue"},test:e=>a(e,"Failed to load")&&a(e,".png",".jpg",".svg")},{solution:{body:"Some issues only occur in production builds. Check if the error happens in development mode. You might need different configurations for build vs dev.",header:"Build vs Development Mode"},test:e=>a(e,"production","build")},{solution:{body:"HMR issues can occur with certain patterns. Make sure you're not mutating module-level variables and consider using `import.meta.hot` guards.",header:"Hot Module Replacement Issue"},test:e=>a(e,"HMR","hot reload")},{solution:{body:"Check your `tsconfig.json` and make sure it includes proper paths and compiler options. For Vite, you might need a `vite-env.d.ts` file.",header:"TypeScript Configuration"},test:e=>a(e,"TypeScript","tsconfig","vite-env.d.ts")},{solution:{body:"Some dependencies need to be excluded from pre-bundling. Add them to `optimizeDeps.exclude` in your Vite config.",header:"Dependency Optimization"},test:e=>a(e,"optimizeDeps","pre-bundling")},{solution:{body:"Configure path aliases in your Vite config using the `resolve.alias` option to match your TypeScript path mappings.",header:"Path Resolution"},test:e=>a(e,"resolve.alias","Cannot find module")},{solution:{body:"Server middleware and proxy settings should be configured in the `server` section of your Vite config.",header:"Server Configuration"},test:e=>a(e,"middleware","proxy")},{solution:{body:"Check your plugin configuration in `vite.config.js/ts`. Make sure all required options are provided and options are correctly typed.",header:"Plugin Configuration"},test:e=>a(e,"plugin","configuration")},{solution:{body:"Configure your build output directory using `build.outDir` in your Vite config. Make sure the directory is writable.",header:"Build Output Configuration"},test:e=>a(e,"build.outDir","dist")},{solution:{body:["Client and server rendered markup differ.","","Checklist:","- A server/client branch `if (typeof window !== 'undefined')`.","- Variable input such as `Date.now()` or `Math.random()` which changes each time it's called.","- Date formatting in a user's locale which doesn't match the server.","- External changing data without sending a snapshot of it along with the HTML.","- Invalid HTML tag nesting.","","It can also happen if the client has a browser extension installed which messes with the HTML before React loaded.","","https://react.dev/link/hydration-mismatch"].join(`
|
|
6
|
+
`)},test:e=>a(e,"hydration failed","did not match","expected server html","text content does not match")}],G=e=>{const n=new Map;return{async handle(o,i){const{file:t,language:s}=i,l=o.message??"";if(a(l,"Failed to resolve import","Cannot resolve module")){const u=l.match(k),p=l.match(P),r=u?.[1]||p?.[1];if(r&&t){const f=await j(r,t,e,n);if(f)return{body:`The import path \`${r}\` could not be resolved.
|
|
7
|
+
|
|
8
|
+
Did you mean one of these files?
|
|
9
|
+
|
|
10
|
+
${f}`};if([".jsx",".tsx"].includes(s)||a(l,"react"))return{body:"Install and configure the React plugin. Add `@vitejs/plugin-react` to your dependencies and include it in your Vite config.",header:"Missing React Plugin"};if(s==="vue")return{body:"Install and configure the Vue plugin. Add `@vitejs/plugin-vue` to your dependencies and include it in your Vite config.",header:"Missing Vue Plugin"};if(s==="svelte")return{body:"Install and configure the Svelte plugin. Add `@sveltejs/vite-plugin-svelte` to your dependencies and include it in your Vite config.",header:"Missing Svelte Plugin"}}}if(a(l,"Cannot resolve")&&(s==="typescript"||s==="javascript")){const u=l.match(R);if(u){const p=u[1];if(p&&t){const r=await j(p,t,e,n);if(r)return{body:`Cannot resolve \`${p}\`. Did you mean one of these files?
|
|
11
|
+
|
|
12
|
+
${r}`,header:"File Not Found"}}}return{body:"In Vite, you may need to include file extensions in imports, especially for TypeScript files. Try adding `.js` extension to your imports.",header:"Missing File Extension"}}for(const u of W)if(u.test(l))return u.solution},name:"vite-solution-finder",priority:20}};export{G as default};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@visulima/vite-overlay",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.12",
|
|
4
4
|
"description": "Improved vite overlay",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"error-handling",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"dependencies": {
|
|
61
61
|
"@shikijs/cli": "4.3.0",
|
|
62
62
|
"@shikijs/langs": "^4.3.0",
|
|
63
|
-
"@visulima/error": "6.
|
|
63
|
+
"@visulima/error": "6.1.0",
|
|
64
64
|
"fastest-levenshtein": "^1.0.16",
|
|
65
65
|
"shiki": "^4.3.0"
|
|
66
66
|
},
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import{createRequire as I}from"node:module";import{distance as x}from"fastest-levenshtein";const V=I(import.meta.url),b=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,T=e=>{if(typeof b<"u"&&b.versions&&b.versions.node){const[t,i]=b.versions.node.split(".").map(Number);if(t>22||t===22&&i>=3||t===20&&i>=16)return b.getBuiltinModule(e)}return V(e)},_=T("node:fs"),c=T("node:path"),k=/Failed to resolve import ["']([^"']+)["']/,P=/Cannot resolve module ["']([^"']+)["']/,F=/Cannot resolve ["'](\.\.?\/[^"']*)["']/,R=4,C=1e3,A=5,$=.5,E=[".js",".ts",".jsx",".tsx",".mjs",".cjs"],L=[".css",".scss",".sass",".less"],D=[".svg",".png",".jpg",".jpeg",".gif",".webp",".ico"],q=new Set([...D,...E,...L]),a=(e,...t)=>{const i=e.toLowerCase();return t.some(n=>i.includes(n.toLowerCase()))},H=/[&<>"']/g,B={'"':""","&":"&","'":"'","<":"<",">":">"},S=e=>e.replaceAll(H,t=>B[t]??t),O=(e,t)=>{const i=c.relative(e,t);return i.startsWith(".")?i:`./${i}`},U=e=>e===0?"":e===1?" (in parent directory)":e===2?" (in grandparent directory)":` (${e} directories away)`,N=(e,t)=>{try{const i=c.relative(e,t).split(c.sep).filter(o=>o&&o!==".");let n=0;for(const o of i)n+=o===".."?2:1;return n}catch{return 10}},z=(e,t,i,n)=>{if(t&&n===t){const s=x(e,i);return s<=Math.max(3,Math.floor(e.length*$))?10-s:0}if(!t){const s=x(e,i);return s===0?9:s<=Math.max(2,Math.floor(e.length*.3))&&q.has(n)?7-s:0}const o=x(e,i);return o<=Math.max(2,Math.floor(e.length*.4))?5-o:0},W=async(e,t)=>{const i=t.get(e);if(i!==void 0)return i;let n;try{n=(await _.promises.readdir(e,{withFileTypes:!0})).map(o=>({isDirectory:o.isDirectory(),isFile:o.isFile(),name:o.name}))}catch{n=[]}return t.set(e,n),n},Y=async(e,t,i,n)=>{const o=[],s=async(l,u=0)=>{if(u>R||o.length>C)return;const p=await W(l,n);for(const r of p){if(o.length>C)break;const f=c.join(l,r.name);if(r.isDirectory&&!r.name.startsWith(".")&&r.name!=="node_modules")await s(f,u+1);else if(r.isFile){const m=c.extname(r.name),g=c.basename(r.name,m),y=z(t,i,g,m);y>0&&o.push({baseName:g,extension:m,fullPath:f,path:f,relevanceScore:y})}}};return await s(e),o},j=async(e,t,i,n)=>{const o=c.basename(e),s=c.extname(o),l=c.basename(o,s),u=c.dirname(t),p=(await Y(i,l,s,n)).map(d=>{const h=x(l,d.baseName),v=N(u,c.dirname(d.fullPath)),w=d.relevanceScore*.7-v*.2-h*.1;return{...d,nameDistance:h,pathDistance:v,score:w}});p.sort((d,h)=>h.score-d.score);const r=[],f=p.slice(0,8);let m=!1;for(const d of f){const h=O(u,d.fullPath);if(!r.includes(h)){const v=U(d.pathDistance);r.push(h+v);const w=d.fullPath.replaceAll("\\","/").split("/"),M=w.indexOf("public");M!==-1&&M<w.length-1&&(m=!0)}}const g=[...new Set(r)].slice(0,A);if(g.length===0)return"";let y=`<ul>${g.map(d=>`<li>\`${S(d)}\`</li>`).join(`
|
|
2
|
-
`)}</ul>`;if(m){const d=o;[...D].some(h=>d.includes(h))&&(y+=`Files in the \`public\` folder should be accessed via absolute URLs like \`/${S(d)}\`.`)}return y},X=[{solution:{body:"Browser APIs like `window` and `document` are not available during server-side rendering. Use dynamic imports or check for SSR environment before using browser APIs.",header:"SSR Browser API Error"},test:e=>a(e,"window is not defined","document is not defined")},{solution:{body:"Some plugins need specific ordering. Use `enforce: 'pre'` for plugins that need to run first, or `enforce: 'post'` for plugins that need to run last.",header:"Plugin Ordering Issue"},test:e=>a(e,"Plugin ordering","enforce")},{solution:{body:"CSS Modules require proper configuration. Make sure your CSS files use the `.module.css` extension and are imported correctly.",header:"CSS Modules Configuration"},test:e=>a(e,"CSS Modules","module.css")},{solution:{body:["Only variables prefixed with `VITE_` are exposed on `import.meta.env` to the client at build time.","Server-only variables should not be prefixed with `VITE_`.","- Do not use `process.env` in browser code; prefer `import.meta.env.*`","- Custom vars must be prefixed with `VITE_` to be exposed to client",'- For TS, add `/// <reference types="vite/client" />` for type-safe access'].join(`
|
|
3
|
-
`),header:"Environment Variables"},test:e=>a(e,"VITE_","process.env")},{solution:{body:"For static assets, use the `new URL('./path/to/asset', import.meta.url)` syntax or import them and use the returned URL.",header:"Asset Import Issue"},test:e=>a(e,"Failed to load")&&a(e,".png",".jpg",".svg")},{solution:{body:"Some issues only occur in production builds. Check if the error happens in development mode. You might need different configurations for build vs dev.",header:"Build vs Development Mode"},test:e=>a(e,"production","build")},{solution:{body:"HMR issues can occur with certain patterns. Make sure you're not mutating module-level variables and consider using `import.meta.hot` guards.",header:"Hot Module Replacement Issue"},test:e=>a(e,"HMR","hot reload")},{solution:{body:"Check your `tsconfig.json` and make sure it includes proper paths and compiler options. For Vite, you might need a `vite-env.d.ts` file.",header:"TypeScript Configuration"},test:(e,t)=>a(e,"TypeScript")||t?.endsWith(".ts")},{solution:{body:"Some dependencies need to be excluded from pre-bundling. Add them to `optimizeDeps.exclude` in your Vite config.",header:"Dependency Optimization"},test:e=>a(e,"optimizeDeps","pre-bundling")},{solution:{body:"Configure path aliases in your Vite config using the `resolve.alias` option to match your TypeScript path mappings.",header:"Path Resolution"},test:e=>a(e,"resolve.alias","Cannot find module")},{solution:{body:"Server middleware and proxy settings should be configured in the `server` section of your Vite config.",header:"Server Configuration"},test:e=>a(e,"middleware","proxy")},{solution:{body:"Check your plugin configuration in `vite.config.js/ts`. Make sure all required options are provided and options are correctly typed.",header:"Plugin Configuration"},test:e=>a(e,"plugin","configuration")},{solution:{body:"Configure your build output directory using `build.outDir` in your Vite config. Make sure the directory is writable.",header:"Build Output Configuration"},test:e=>a(e,"build.outDir","dist")},{solution:{body:["Client and server rendered markup differ.","","Checklist:","- A server/client branch `if (typeof window !== 'undefined')`.","- Variable input such as `Date.now()` or `Math.random()` which changes each time it's called.","- Date formatting in a user's locale which doesn't match the server.","- External changing data without sending a snapshot of it along with the HTML.","- Invalid HTML tag nesting.","","It can also happen if the client has a browser extension installed which messes with the HTML before React loaded.","","https://react.dev/link/hydration-mismatch"].join(`
|
|
4
|
-
`)},test:e=>a(e,"hydration failed","did not match","expected server html","text content does not match")}],K=e=>{const t=new Map;return{async handle(i,n){const{file:o,language:s}=n,l=i.message??"";if(a(l,"Failed to resolve import","Cannot resolve module")){const u=l.match(k),p=l.match(P),r=u?.[1]||p?.[1];if(r&&o){const f=await j(r,o,e,t);if(f)return{body:`The import path \`${S(r)}\` could not be resolved.<br/><br/>Did you mean one of these files?<br/>${f}`};if([".jsx",".tsx"].includes(s)||a(l,"react"))return{body:"Install and configure the React plugin. Add `@vitejs/plugin-react` to your dependencies and include it in your Vite config.",header:"Missing React Plugin"};if(s==="vue")return{body:"Install and configure the Vue plugin. Add `@vitejs/plugin-vue` to your dependencies and include it in your Vite config.",header:"Missing Vue Plugin"};if(s==="svelte")return{body:"Install and configure the Svelte plugin. Add `@sveltejs/vite-plugin-svelte` to your dependencies and include it in your Vite config.",header:"Missing Svelte Plugin"}}}if(a(l,"Cannot resolve")&&(s==="typescript"||s==="javascript")){const u=l.match(F);if(u){const p=u[1];if(p&&o){const r=await j(p,o,e,t);if(r)return{body:`Cannot resolve \`${S(p)}\`. Did you mean one of these files?${r}`,header:"File Not Found"}}}return{body:"In Vite, you may need to include file extensions in imports, especially for TypeScript files. Try adding `.js` extension to your imports.",header:"Missing File Extension"}}for(const u of X)if(u.test(l,o))return u.solution},name:"vite-solution-finder",priority:20}};export{K as default};
|