laybot-vite-dev 1.0.7 → 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 +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 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,14 +1,24 @@
1
1
  {
2
2
  "name": "laybot-vite-dev",
3
- "version": "1.0.7",
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",
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": {