laybot-vite-dev 1.5.0 → 1.6.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 +1 -1
package/dist/index.js CHANGED
@@ -1 +1 @@
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};
1
+ import F from"node:fs";import T from"node:path";var x=Object.freeze({srcRoot:"/src",viewsDir:"/src/views",htmlFallback:"index.html",debug:!1,notFound:{enabled:!1,page:"/error/404.html",statusCode:404,mode:"rewrite"},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 w(e){let t=[],r=new Set;for(let i of e||[]){let n=String(i||"").trim();n&&(r.has(n)||(r.add(n),t.push(n)))}return t}function b(e){return e=String(e||"").trim(),e?(e.startsWith("/")||(e="/"+e),e.endsWith("/")||(e+="/"),e):""}function C(e){return e=String(e||"").trim(),e?(e.startsWith("/")||(e="/"+e),e.length>1&&(e=e.replace(/\/+$/,"")),e):""}function z(e){return String(e||"").trim().replace(/^\/+|\/+$/g,"")}function $(e,t){let r=String(e||""),i=b(t);if(!i)return!1;let n=i.replace(/\/+$/,"");return r===n||r.startsWith(i)}function p(e,t){return e+(t?`?${t}`:"")}function W(e){return/\/[^/]+\.[a-z0-9]+$/i.test(String(e||""))}function R(e,t){let r=e.config.root||process.cwd(),i=String(t||"").replace(/^\/+/,"");return T.resolve(r,i)}function N(e,t){try{let r=R(e,t);return F.existsSync(r)&&F.statSync(r).isFile()}catch{return!1}}function E(e,t){for(let r of t||[])if(N(e,r))return r;return""}function A(e){return String(e||"").replace(/^\/+/,"").split("/")[0]||""}function H(e={}){let t=e.notFound||{};return{...x.notFound,...t,enabled:t.enabled===!0,page:t.page||x.notFound.page,statusCode:Number(t.statusCode||x.notFound.statusCode||404),mode:t.mode||x.notFound.mode}}function I(e={}){let t=e.locale||{},r={...x.locale,...t},i=Array.isArray(e.localePrefixes)?e.localePrefixes:[],n=Array.isArray(r.prefixes)?r.prefixes:[],o=r.aliases||{},f=o&&typeof o=="object"?Object.keys(o):[],s=w([...n,...i,...f]).map(z).filter(Boolean);return{...r,defaultLang:r.defaultLang||"zh-CN",strategy:r.strategy||"prefix_except_default",prefixes:s}}function V(e,t){if(!t.locale||t.locale.enabled!==!0)return!1;let r=A(e);return r?(t.locale.prefixes||[]).includes(r):!1}function _(e,t){if(!V(e,t))return"";let i=String(e||"").replace(/^\/+/,"").split("/").slice(1).join("/");return i?"/"+i:"/"}function j(e){return e==="/vite-hmr"||e==="/__vite_ping"||e.startsWith("/@vite")||e.startsWith("/@id")||e.startsWith("/@fs")||e.startsWith("/__vite")||e==="/favicon.ico"}async function v(e,t,r,i,n,o){let f=n.notFound||{};if(f.enabled!==!0||f.mode&&f.mode!=="rewrite")return!1;let s=f.page||"/error/404.html",u=L(s,n),d=E(e,u);return d?(o(i,"=> 404 rewrite =>",d),await B(e,t,r,d,Number(f.statusCode||404),i),!0):!1}async function B(e,t,r,i,n,o){let f=R(e,i);if(!F.existsSync(f)||!F.statSync(f).isFile()){r.statusCode=404,r.setHeader("Content-Type","text/plain; charset=utf-8"),r.end("404 Not Found");return}let s=F.readFileSync(f,"utf-8");s=await e.transformIndexHtml(o||t.url||"/",s,t.originalUrl),r.statusCode=n||200,r.setHeader("Content-Type","text/html; charset=utf-8"),r.end(s)}function U(e){let t=[];return e.srcRoot&&t.push(b(e.srcRoot)),e.viewsDir&&t.push(b(e.viewsDir)),t.push(...e.stripPrefixes||[]),t.push(...e.toSrcPrefixes||[]),t.push(...e.backendPrefixes||[]),t.push(...e.pageExcludePrefixes||[]),w(t).map(b).filter(Boolean)}function D(e,t){let r=String(e||"");return(t._pageExcludePrefixes||[]).some(i=>$(r,i))}function L(e,t){let r=[];if(r.push(`${t.viewsDir}${e}`),t.locale&&t.locale.fallbackToDefaultViews!==!1){let i=_(e,t);i&&i!==e&&r.push(`${t.viewsDir}${i}`)}return r}function Q(e,t){let r=[],i=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(i(e),t.locale&&t.locale.fallbackToDefaultViews!==!1){let n=_(e,t);n&&n!==e&&i(n)}return t.extensionlessFallbackToIndex&&r.push(`${t.viewsDir}/${t.htmlFallback}`),r}function G(e={}){let t=e.prefixes||e.toSrcPrefixes||[],r=e.strip||e.stripPrefixes||[],i=e.backendPrefixes||e.passthroughPrefixes||[],n=e.pageExcludePrefixes||e.excludePrefixes||[],o=I(e),f=H(e),s={...x,...e,srcRoot:C(e.srcRoot||x.srcRoot),viewsDir:C(e.viewsDir||x.viewsDir),toSrcPrefixes:w([...x.toSrcPrefixes,...t]).map(b),stripPrefixes:w([...x.stripPrefixes,...r]).map(b),backendPrefixes:w([...x.backendPrefixes,...i]).map(b),pageExcludePrefixes:w([...x.pageExcludePrefixes,...n]).map(b),locale:o,notFound:f};s._pageExcludePrefixes=U(s);let u=(...d)=>{s.debug&&console.log("[laybot-vite-dev]",...d)};return{name:"laybot-vite-dev",enforce:"pre",configureServer(d){d.middlewares.use(async(c,y,g)=>{let h=c.url||"/",[a,m=""]=h.split("?");if((c.headers.upgrade||"").toLowerCase()==="websocket"||j(a))return g();for(let l of s.backendPrefixes)if(l&&$(a,l))return u(h,"=> backend passthrough"),g();if(a==="/"||a==="/index.html"){let l=`${s.viewsDir}/${s.htmlFallback}`;return c.url=p(l,m),u(h,"=>",c.url),g()}if(/\.html$/i.test(a)&&!D(a,s)){let l=L(a,s),P=E(d,l);return P?(c.url=p(P,m),u(h,"=>",c.url),g()):await v(d,c,y,h,s,u)?void 0:g()}for(let l of s.stripPrefixes)if(l&&$(a,l)){let P=b(l),S=a.slice(P.length-1),k=`${s.srcRoot}${S}`;return c.url=p(k,m),u(h,"=>",c.url),g()}for(let l of s.toSrcPrefixes)if(l&&$(a,l)){let P=`${s.srcRoot}${a}`;return c.url=p(P,m),u(h,"=>",c.url),g()}if(s.extensionlessRoutes===!0&&a!=="/"&&!W(a)&&!D(a,s)){let l=a.replace(/\/+$/,"")||"/",P=Q(l,s),S=E(d,P);if(S)return c.url=p(S,m),u(h,"=>",c.url),g();if(s.extensionlessFallbackToIndex){let k=`${s.viewsDir}/${s.htmlFallback}`;return c.url=p(k,m),u(h,"=>",c.url),g()}if(await v(d,c,y,h,s,u))return}if(!(s.notFound?.enabled===!0&&a!=="/"&&!W(a)&&!D(a,s)&&await v(d,c,y,h,s,u)))return g()})}}}export{G as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "laybot-vite-dev",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
4
4
  "description": "Vite dev rewrite plugin for LayBot/LarryMS MPA runtime loader",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",