laybot-vite-dev 1.0.6 → 1.5.0

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.
Files changed (2) hide show
  1. package/dist/index.js +1 -1
  2. package/package.json +13 -3
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- var l=Object.freeze({srcRoot:"/src",viewsDir:"/src/views",htmlFallback:"index.html",debug:!1,toSrcPrefixes:["/api/","/route/","/mock/","/store/","/utils/","/plugin/","/components/","/partials/","/laybot/","/static/","/app/","/platform/","/service/"],stripPrefixes:["/assets/"],backendPrefixes:[]});function m(t){let c=[],a=new Set;for(let d of t||[]){let e=String(d||"").trim();e&&(a.has(e)||(a.add(e),c.push(e)))}return c}function P(t){return t=String(t||"").trim(),t?(t.startsWith("/")||(t="/"+t),t.endsWith("/")||(t=t+"/"),t):""}function h(t,c){return t+(c?`?${c}`:"")}function W(t={}){let c=t.prefixes||t.toSrcPrefixes||[],a=t.strip||t.stripPrefixes||[],d=t.backendPrefixes||t.passthroughPrefixes||[],e={...l,...t,toSrcPrefixes:m([...l.toSrcPrefixes,...c]),stripPrefixes:m([...l.stripPrefixes,...a]),backendPrefixes:m([...l.backendPrefixes,...d]).map(P)},f=(...x)=>{e.debug&&console.log("[laybot-vite-dev]",...x)};return{name:"laybot-vite-dev",enforce:"pre",configureServer(x){x.middlewares.use((i,p,o)=>{let n=i.url||"/",[r,u=""]=n.split("?");if((i.headers.upgrade||"").toLowerCase()==="websocket"||r==="/vite-hmr"||r==="/__vite_ping"||r.startsWith("/@vite")||r.startsWith("/@id")||r.startsWith("/@fs")||r.startsWith("/__vite")||r==="/favicon.ico")return o();if(r==="/"||r==="/index.html"){let s=`${e.viewsDir}/${e.htmlFallback}`;return i.url=h(s,u),f(n,"=>",i.url),o()}if(/\.html$/i.test(r)&&!r.startsWith(e.viewsDir+"/")&&!r.startsWith("/src/")&&!r.startsWith("/assets/")&&!r.startsWith("/components/")&&!r.startsWith("/partials/")&&!r.startsWith("/static/")){let s=`${e.viewsDir}${r}`;return i.url=h(s,u),f(n,"=>",i.url),o()}for(let s of e.stripPrefixes)if(s&&r.startsWith(s)){let b=r.slice(s.length-1),v=`${e.srcRoot}${b}`;return i.url=h(v,u),f(n,"=>",i.url),o()}for(let s of e.toSrcPrefixes)if(s&&r.startsWith(s)){let b=`${e.srcRoot}${r}`;return i.url=h(b,u),f(n,"=>",i.url),o()}for(let s of e.backendPrefixes)if(s&&r.startsWith(s))return o();return o()})}}}export{W as default};
1
+ import w from"node:fs";import F from"node:path";var g=Object.freeze({srcRoot:"/src",viewsDir:"/src/views",htmlFallback:"index.html",debug:!1,toSrcPrefixes:["/api/","/route/","/mock/","/store/","/utils/","/plugin/","/plugins/","/components/","/partials/","/laybot/","/static/","/app/","/platform/","/service/"],stripPrefixes:["/assets/"],backendPrefixes:[],pageExcludePrefixes:[],extensionlessRoutes:!1,extensionlessFallbackToIndex:!1,locale:{enabled:!1,defaultLang:"zh-CN",strategy:"prefix_except_default",prefixes:[],aliases:{},fallbackToDefaultViews:!0}});function m(e){let t=[],r=new Set;for(let s of e||[]){let n=String(s||"").trim();n&&(r.has(n)||(r.add(n),t.push(n)))}return t}function x(e){return e=String(e||"").trim(),e?(e.startsWith("/")||(e="/"+e),e.endsWith("/")||(e+="/"),e):""}function k(e){return e=String(e||"").trim(),e?(e.startsWith("/")||(e="/"+e),e.length>1&&(e=e.replace(/\/+$/,"")),e):""}function W(e){return String(e||"").trim().replace(/^\/+|\/+$/g,"")}function v(e,t){let r=String(e||""),s=x(t);if(!s)return!1;let n=s.replace(/\/+$/,"");return r===n||r.startsWith(s)}function p(e,t){return e+(t?`?${t}`:"")}function _(e){return/\/[^/]+\.[a-z0-9]+$/i.test(String(e||""))}function R(e,t){let r=e.config.root||process.cwd(),s=String(t||"").replace(/^\/+/,"");return F.resolve(r,s)}function L(e,t){try{let r=R(e,t);return w.existsSync(r)&&w.statSync(r).isFile()}catch{return!1}}function D(e,t){for(let r of t||[])if(L(e,r))return r;return""}function z(e){return String(e||"").replace(/^\/+/,"").split("/")[0]||""}function T(e={}){let t=e.locale||{},r={...g.locale,...t},s=Array.isArray(e.localePrefixes)?e.localePrefixes:[],n=Array.isArray(r.prefixes)?r.prefixes:[],o=r.aliases||{},i=o&&typeof o=="object"?Object.keys(o):[],u=m([...n,...s,...i]).map(W).filter(Boolean);return{...r,defaultLang:r.defaultLang||"zh-CN",strategy:r.strategy||"prefix_except_default",prefixes:u}}function A(e,t){if(!t.locale||t.locale.enabled!==!0)return!1;let r=z(e);return r?(t.locale.prefixes||[]).includes(r):!1}function E(e,t){if(!A(e,t))return"";let s=String(e||"").replace(/^\/+/,"").split("/").slice(1).join("/");return s?"/"+s:"/"}function C(e){return e==="/vite-hmr"||e==="/__vite_ping"||e.startsWith("/@vite")||e.startsWith("/@id")||e.startsWith("/@fs")||e.startsWith("/__vite")||e==="/favicon.ico"}function V(e){let t=[];return e.srcRoot&&t.push(x(e.srcRoot)),e.viewsDir&&t.push(x(e.viewsDir)),t.push(...e.stripPrefixes||[]),t.push(...e.toSrcPrefixes||[]),t.push(...e.backendPrefixes||[]),t.push(...e.pageExcludePrefixes||[]),m(t).map(x).filter(Boolean)}function y(e,t){let r=String(e||"");return(t._pageExcludePrefixes||[]).some(s=>v(r,s))}function j(e,t){let r=[];if(r.push(`${t.viewsDir}${e}`),t.locale&&t.locale.fallbackToDefaultViews!==!1){let s=E(e,t);s&&s!==e&&r.push(`${t.viewsDir}${s}`)}return r}function I(e,t){let r=[],s=n=>{let o=String(n||"").trim();if(!o||o==="/"){r.push(`${t.viewsDir}/${t.htmlFallback}`);return}o.startsWith("/")||(o="/"+o),o=o.replace(/\/+$/,""),r.push(`${t.viewsDir}${o}/index.html`),r.push(`${t.viewsDir}${o}.html`)};if(s(e),t.locale&&t.locale.fallbackToDefaultViews!==!1){let n=E(e,t);n&&n!==e&&s(n)}return t.extensionlessFallbackToIndex&&r.push(`${t.viewsDir}/${t.htmlFallback}`),r}function B(e={}){let t=e.prefixes||e.toSrcPrefixes||[],r=e.strip||e.stripPrefixes||[],s=e.backendPrefixes||e.passthroughPrefixes||[],n=e.pageExcludePrefixes||e.excludePrefixes||[],o=T(e),i={...g,...e,srcRoot:k(e.srcRoot||g.srcRoot),viewsDir:k(e.viewsDir||g.viewsDir),toSrcPrefixes:m([...g.toSrcPrefixes,...t]).map(x),stripPrefixes:m([...g.stripPrefixes,...r]).map(x),backendPrefixes:m([...g.backendPrefixes,...s]).map(x),pageExcludePrefixes:m([...g.pageExcludePrefixes,...n]).map(x),locale:o};i._pageExcludePrefixes=V(i);let u=(...$)=>{i.debug&&console.log("[laybot-vite-dev]",...$)};return{name:"laybot-vite-dev",enforce:"pre",configureServer($){$.middlewares.use((a,N,f)=>{let d=a.url||"/",[l,h=""]=d.split("?");if((a.headers.upgrade||"").toLowerCase()==="websocket"||C(l))return f();for(let c of i.backendPrefixes)if(c&&v(l,c))return u(d,"=> backend passthrough"),f();if(l==="/"||l==="/index.html"){let c=`${i.viewsDir}/${i.htmlFallback}`;return a.url=p(c,h),u(d,"=>",a.url),f()}if(/\.html$/i.test(l)&&!y(l,i)){let c=j(l,i),b=D($,c)||c[0];return a.url=p(b,h),u(d,"=>",a.url),f()}for(let c of i.stripPrefixes)if(c&&v(l,c)){let P=x(c),b=l.slice(P.length-1),S=`${i.srcRoot}${b}`;return a.url=p(S,h),u(d,"=>",a.url),f()}for(let c of i.toSrcPrefixes)if(c&&v(l,c)){let P=`${i.srcRoot}${l}`;return a.url=p(P,h),u(d,"=>",a.url),f()}if(i.extensionlessRoutes===!0&&l!=="/"&&!_(l)&&!y(l,i)){let c=l.replace(/\/+$/,"")||"/",P=I(c,i),b=D($,P);if(b)return a.url=p(b,h),u(d,"=>",a.url),f();if(i.extensionlessFallbackToIndex){let S=`${i.viewsDir}/${i.htmlFallback}`;return a.url=p(S,h),u(d,"=>",a.url),f()}}return f()})}}}export{B as default};
package/package.json CHANGED
@@ -1,14 +1,24 @@
1
1
  {
2
2
  "name": "laybot-vite-dev",
3
- "version": "1.0.6",
3
+ "version": "1.5.0",
4
4
  "description": "Vite dev rewrite plugin for LayBot/LarryMS MPA runtime loader",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "exports": {
8
8
  ".": "./dist/index.js"
9
9
  },
10
- "files": ["dist", "README.md", "LICENSE"],
11
- "keywords": ["vite", "plugin", "mpa", "larryms", "laybot"],
10
+ "files": [
11
+ "dist",
12
+ "README.md",
13
+ "LICENSE"
14
+ ],
15
+ "keywords": [
16
+ "vite",
17
+ "plugin",
18
+ "mpa",
19
+ "larryms",
20
+ "laybot"
21
+ ],
12
22
  "author": "larry",
13
23
  "license": "MIT",
14
24
  "peerDependencies": {