vite-plugin-api-routes
Advanced tools
Comparing version 1.1.4-beta to 1.1.5-beta
@@ -1,2 +0,2 @@ | ||
var U=Object.defineProperty;var F=Object.getOwnPropertySymbols;var W=Object.prototype.hasOwnProperty,N=Object.prototype.propertyIsEnumerable;var j=(r,e,o)=>e in r?U(r,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):r[e]=o,A=(r,e)=>{for(var o in e||(e={}))W.call(e,o)&&j(r,o,e[o]);if(F)for(var o of F(e))N.call(e,o)&&j(r,o,e[o]);return r};import a from"slash-path";import I from"slash-path";import{build as ee}from"vite";import Z from"fs";import z from"fs";var w=(r,e)=>{let{configureFile:o,cacheDir:t}=r;if(!o.startsWith(t))return!1;let s=` | ||
var z=Object.defineProperty;var F=Object.getOwnPropertySymbols;var W=Object.prototype.hasOwnProperty,N=Object.prototype.propertyIsEnumerable;var j=(r,e,o)=>e in r?z(r,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):r[e]=o,A=(r,e)=>{for(var o in e||(e={}))W.call(e,o)&&j(r,o,e[o]);if(F)for(var o of F(e))N.call(e,o)&&j(r,o,e[o]);return r};import a from"slash-path";import h from"path";import T from"slash-path";import{build as re}from"vite";import ee from"fs";import G from"fs";var w=(r,e)=>{let{configureFile:o,cacheDir:t}=r;if(!o.startsWith(t))return!1;let s=` | ||
import express from "express"; | ||
@@ -56,3 +56,3 @@ | ||
}; | ||
`;z.writeFileSync(o,s)};import G from"fs";var B=(r,e)=>{let{cacheDir:o,handlerFile:t,moduleId:s}=r;if(!t.startsWith(o))return!1;let u=` | ||
`;G.writeFileSync(o,s)};import V from"fs";var B=(r,e)=>{let{cacheDir:o,handlerFile:t,moduleId:s}=r;if(!t.startsWith(o))return!1;let u=` | ||
import express from "express"; | ||
@@ -83,3 +83,3 @@ import { applyRouters } from "${s}/routers"; | ||
`;G.writeFileSync(t,u)};import X from"fs";import{join as J}from"slash-path";import V from"fast-glob";import R from"slash-path";var q=(...r)=>r.map(e=>e==null?void 0:e.replace(/^\//,"").replace(/\/$/,"")).map(e=>e==null?void 0:e.replaceAll("$",":")).map(e=>e==null?void 0:e.replaceAll("[",":").replaceAll("]","")).map(e=>e==null?void 0:e.replace(/\.[^.]+$/,"")).map(e=>e==null?void 0:e.replaceAll(/index$/gi,"")).map(e=>e==null?void 0:e.replaceAll(/_index$/gi,"")).filter(e=>e).join("/"),Y=(r,e)=>(r=r.replace(/\:|\$|\[/gi,"zz"),e=e.replace(/\:|\$|\[/gi,"zz"),r.localeCompare(e)),S=r=>{let{dirs:e,include:o,exclude:t}=r;return e.flatMap((s,u)=>{s.exclude=s.exclude||[];let c=[...t,...s.exclude];return V.sync(o,{ignore:c,onlyDirectories:!1,dot:!0,unique:!0,cwd:s.dir}).sort((n,l)=>Y(n,l)).map((n,l)=>{let p=q(s.route,n);p=R.join("/",p);let m=R.join("/",r.routeBase,p);return n=R.join(s.dir,n),n=R.relative(r.root,n),{order:l,name:`_${u}_${l}`,file:n,path:m,route:p}})})},D=r=>S(r).flatMap(e=>r.mapperList.map(o=>{let t=e.name+"."+o.name,s=e.file+"?fn="+o.name;return s=R.relative(r.root,s),{order:e.order,source:s,method:o.method,path:e.path,route:e.route,cb:t}}));var E=(r,e)=>{let{moduleId:o,cacheDir:t,routersFile:s}=r;if(s.startsWith(t)){let u=S(r),c=D(r),n=i=>` ${i.cb} && { | ||
`;V.writeFileSync(t,u)};import J from"fs";import{join as K}from"slash-path";import q from"fast-glob";import C from"slash-path";var Y=(...r)=>r.map(e=>e==null?void 0:e.replace(/^\//,"").replace(/\/$/,"")).map(e=>e==null?void 0:e.replaceAll("$",":")).map(e=>e==null?void 0:e.replaceAll("[",":").replaceAll("]","")).map(e=>e==null?void 0:e.replace(/\.[^.]+$/,"")).map(e=>e==null?void 0:e.replaceAll(/index$/gi,"")).map(e=>e==null?void 0:e.replaceAll(/_index$/gi,"")).filter(e=>e).join("/"),X=(r,e)=>(r=r.replace(/\:|\$|\[/gi,"zz"),e=e.replace(/\:|\$|\[/gi,"zz"),r.localeCompare(e)),S=r=>{let{dirs:e,include:o,exclude:t}=r;return e.flatMap((s,u)=>{s.exclude=s.exclude||[];let c=[...t,...s.exclude];return q.sync(o,{ignore:c,onlyDirectories:!1,dot:!0,unique:!0,cwd:s.dir}).sort((n,l)=>X(n,l)).map((n,l)=>{let p=Y(s.route,n);p=C.join("/",p);let m=C.join("/",r.routeBase,p);return n=C.join(s.dir,n),n=C.relative(r.root,n),{order:l,name:`_${u}_${l}`,file:n,path:m,route:p}})})},D=r=>S(r).flatMap(e=>r.mapperList.map(o=>{let t=e.name+"."+o.name,s=e.file+"?fn="+o.name;return s=C.relative(r.root,s),{order:e.order,source:s,method:o.method,path:e.path,route:e.route,cb:t}}));var E=(r,e)=>{let{moduleId:o,cacheDir:t,routersFile:s}=r;if(s.startsWith(t)){let u=S(r),c=D(r),n=i=>` ${i.cb} && { | ||
source : "${i.source}", | ||
@@ -89,3 +89,3 @@ method : "${i.method}", | ||
path : "${i.path}", | ||
url : "${J(e.base,i.path)}", | ||
url : "${K(e.base,i.path)}", | ||
cb : ${i.cb}, | ||
@@ -121,3 +121,3 @@ }`,l=u.map(i=>`import * as ${i.name} from "${o}/root/${i.file}";`).join(` | ||
`;X.writeFileSync(s,m)}};import K from"fs";var k=(r,e)=>{let{cacheDir:o,serverFile:t,moduleId:s}=r;if(!t.startsWith(o))return!1;let u=` | ||
`;J.writeFileSync(s,m)}};import Q from"fs";var k=(r,e)=>{let{cacheDir:o,serverFile:t,moduleId:s}=r;if(!t.startsWith(o))return!1;let u=` | ||
import { handler } from "${s}/handler"; | ||
@@ -143,3 +143,3 @@ import { endpoints } from "${s}/routers"; | ||
}); | ||
`;K.writeFileSync(t,u)};import Q from"fs";var H=(r,e)=>{let{moduleId:o,typesFile:t}=r,s=` | ||
`;Q.writeFileSync(t,u)};import Z from"fs";var H=(r,e)=>{let{moduleId:o,typesFile:t}=r,s=` | ||
declare module "${o}/handler" { | ||
@@ -167,2 +167,2 @@ import { ServerHandler } from "vite-plugin-api-routes/model"; | ||
} | ||
`;Q.writeFileSync(t,s)};var y=(r,e)=>{Z.mkdirSync(r.cacheDir,{recursive:!0}),w(r,e),B(r,e),k(r,e),H(r,e),$(r,e)},$=(r,e)=>{E(r,e)};var T=r=>{let e=t=>(t=I.slash(t),r.watcherList.find(s=>t.startsWith(s))),o={};return{name:"vite-plugin-rest-api",enforce:"pre",config:()=>({resolve:{alias:{[`${r.moduleId}/root`]:r.root,[`${r.moduleId}/server`]:r.serverFile,[`${r.moduleId}/handler`]:r.handlerFile,[`${r.moduleId}/routers`]:r.routersFile,[`${r.moduleId}/configure`]:r.configureFile}}}),configResolved:t=>{o=t,y(r,o)},handleHotUpdate:async t=>{if(e(t.file))return[]},configureServer:async t=>{var f,h;let{watcher:s,middlewares:u,ssrLoadModule:c,ssrFixStacktrace:n,restart:l}=t,p=g=>{e(g)&&($(r,o),s.off("add",p),s.off("change",p),l(!0))};s.on("add",p),s.on("change",p);let m=I.join(o.base,r.routeBase),i=await c(r.configure,{fixStacktrace:!0});(f=i.viteServerBefore)==null||f.call(i,t.middlewares,t,o),u.use(m,async(g,C,v)=>{try{(await c(r.handler,{fixStacktrace:!0})).handler(g,C,v)}catch(x){n(x),process.exitCode=1,v(x)}}),(h=i.viteServerAfter)==null||h.call(i,t.middlewares,t,o)},writeBundle:async()=>{var m,i;if(process.env.IS_API_BUILD)return;y(r,o),process.env.IS_API_BUILD="true";let{root:t,outDir:s,minify:u,preBuild:c,routeBase:n}=r,l=I.relative(s,o.build.outDir),p=await c({root:t,mode:o.mode,publicDir:"private",define:{"import.meta.env.PUBLIC_DIR":l,"import.meta.env.BASE":o.base,"import.meta.env.BASE_API":I.join(o.base,n)},build:{outDir:s,ssr:!0,minify:u,target:"es2020",assetsDir:"",emptyOutDir:!0,rollupOptions:{input:{app:r.server},external:(i=(m=o.build)==null?void 0:m.rollupOptions)==null?void 0:i.external,output:{format:"es"},onwarn:(f,h)=>{f.code==="MISSING_EXPORT"&&f.id.startsWith(r.cacheDir)||h(f)}}}});await ee(p)}}};var b=(r={})=>{let{moduleId:e="@api",cacheDir:o=".api",root:t=process.cwd(),server:s=a.join(o,"server.js"),handler:u=a.join(o,"handler.js"),configure:c=a.join(o,"configure.js"),routeBase:n="api",dirs:l=[{dir:"src/api",route:"",exclude:[]}],include:p=["**/*.ts","**/*.js"],exclude:m=[],mapper:i={},outDir:f="dist/server",minify:h=!0,preBuild:g=d=>d}=r;l=l.map(d=>(d.dir=a.join(t,d.dir),d)),i=A({default:"use",GET:"get",PUT:"put",POST:"post",PATCH:"patch",DELETE:"delete"},i),n=a.join("/",n),f=a.join(t,f),o=a.join(t,o);let C=a.join(t,s),v=a.join(t,u),x=a.join(o,"routers.js"),L=a.join(o,"types.d.ts"),_=a.join(t,c),M=Object.entries(i).filter(d=>d[1]).map(([d,O])=>({name:d,method:O})),P=l.map(d=>d.dir);return P.push(o),P.push(C),P.push(v),T({moduleId:e,server:s,handler:u,configure:c,root:t,serverFile:C,handlerFile:v,routersFile:x,typesFile:L,configureFile:_,routeBase:n,dirs:l,include:p,exclude:m,mapper:i,mapperList:M,watcherList:P,outDir:f,cacheDir:o,minify:h,preBuild:g})},De=b,Ee=b,ke=b;export{Ee as createAPI,ke as default,De as pluginAPI,b as pluginAPIRoutes}; | ||
`;Z.writeFileSync(t,s)};var y=(r,e)=>{ee.mkdirSync(r.cacheDir,{recursive:!0}),w(r,e),B(r,e),k(r,e),H(r,e),$(r,e)},$=(r,e)=>{E(r,e)};var L=r=>{let e=t=>(t=T.slash(t),r.watcherList.find(s=>t.startsWith(s))),o={};return{name:"vite-plugin-api-routes",enforce:"pre",config:()=>({resolve:{alias:{[`${r.moduleId}/root`]:h.normalize(r.root),[`${r.moduleId}/server`]:h.normalize(r.serverFile),[`${r.moduleId}/handler`]:h.normalize(r.handlerFile),[`${r.moduleId}/routers`]:h.normalize(r.routersFile),[`${r.moduleId}/configure`]:h.normalize(r.configureFile)}}}),configResolved:t=>{o=t,y(r,o)},handleHotUpdate:async t=>{if(e(t.file))return[]},configureServer:async t=>{var f,g;let{watcher:s,middlewares:u,ssrLoadModule:c,ssrFixStacktrace:n,restart:l}=t,p=v=>{e(v)&&($(r,o),s.off("add",p),s.off("change",p),l(!0))};s.on("add",p),s.on("change",p);let m=T.join(o.base,r.routeBase),i=await c(r.configure,{fixStacktrace:!0});(f=i.viteServerBefore)==null||f.call(i,t.middlewares,t,o),u.use(m,async(v,P,x)=>{try{(await c(r.handler,{fixStacktrace:!0})).handler(v,P,x)}catch(R){n(R),process.exitCode=1,x(R)}}),(g=i.viteServerAfter)==null||g.call(i,t.middlewares,t,o)},writeBundle:async()=>{var m,i;if(process.env.IS_API_BUILD)return;y(r,o),process.env.IS_API_BUILD="true";let{root:t,outDir:s,minify:u,preBuild:c,routeBase:n}=r,l=h.relative(s,o.build.outDir),p=await c({root:t,mode:o.mode,publicDir:"private",define:{"import.meta.env.PUBLIC_DIR":l,"import.meta.env.BASE":o.base,"import.meta.env.BASE_API":h.join(o.base,n)},build:{outDir:s,ssr:!0,minify:u,target:"es2020",assetsDir:"",emptyOutDir:!0,rollupOptions:{input:{app:r.server},external:(i=(m=o.build)==null?void 0:m.rollupOptions)==null?void 0:i.external,output:{format:"es"},onwarn:(f,g)=>{f.code==="MISSING_EXPORT"&&f.id.startsWith(r.cacheDir)||g(f)}}}});await re(p)}}};var b=(r={})=>{let{moduleId:e="@api",cacheDir:o=".api",root:t=process.cwd(),server:s=a.join(o,"server.js"),handler:u=a.join(o,"handler.js"),configure:c=a.join(o,"configure.js"),routeBase:n="api",dirs:l=[{dir:"src/api",route:"",exclude:[]}],include:p=["**/*.ts","**/*.js"],exclude:m=[],mapper:i={},outDir:f="dist/server",minify:g=!0,preBuild:v=d=>d}=r;t=a.slash(t),l=l.map(d=>(d.dir=a.join(t,d.dir),d)),i=A({default:"use",GET:"get",PUT:"put",POST:"post",PATCH:"patch",DELETE:"delete"},i),n=a.join("/",n),f=a.join(t,f),o=a.join(t,o);let P=a.join(t,s),x=a.join(t,u),R=a.join(o,"routers.js"),_=a.join(o,"types.d.ts"),M=a.join(t,c),O=Object.entries(i).filter(d=>d[1]).map(([d,U])=>({name:d,method:U})),I=l.map(d=>d.dir);return I.push(o),I.push(P),I.push(x),L({moduleId:e,server:s,handler:u,configure:c,root:t,serverFile:P,handlerFile:x,routersFile:R,typesFile:_,configureFile:M,routeBase:n,dirs:l,include:p,exclude:m,mapper:i,mapperList:O,watcherList:I,outDir:f,cacheDir:o,minify:g,preBuild:v})},ke=b,He=b,Te=b;export{He as createAPI,Te as default,ke as pluginAPI,b as pluginAPIRoutes}; |
{ | ||
"name": "vite-plugin-api-routes", | ||
"version": "1.1.4-beta", | ||
"version": "1.1.5-beta", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "description": "A Vite.js plugin that creates API routes by mapping the directory structure, similar to Next.js API Routes. This plugin enhances the functionality for backend development using Vite.", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
39206
378