Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vite-plugin-api-routes

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vite-plugin-api-routes - npm Package Compare versions

Comparing version 1.1.6-beta to 1.1.7-beta

34

dist/index.js

@@ -1,2 +0,2 @@

var z=Object.defineProperty;var j=Object.getOwnPropertySymbols;var W=Object.prototype.hasOwnProperty,N=Object.prototype.propertyIsEnumerable;var A=(r,e,o)=>e in r?z(r,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):r[e]=o,w=(r,e)=>{for(var o in e||(e={}))W.call(e,o)&&A(r,o,e[o]);if(j)for(var o of j(e))N.call(e,o)&&A(r,o,e[o]);return r};import a from"slash-path";import C from"path";import S from"slash-path";import{build as re}from"vite";import ee from"fs";import G from"fs";var B=(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 B=(r,e,o)=>e in r?z(r,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):r[e]=o,j=(r,e)=>{for(var o in e||(e={}))W.call(e,o)&&B(r,o,e[o]);if(F)for(var o of F(e))N.call(e,o)&&B(r,o,e[o]);return r};import a from"slash-path";import S from"path";import I from"slash-path";import{build as re}from"vite";import ee from"fs";import V from"fs";var E=(r,e)=>{let{configureFile:o,cacheDir:t}=r;if(!o.startsWith(t))return!1;let s=`
import express from "express";

@@ -56,3 +56,3 @@

};
`;G.writeFileSync(o,s)};import V from"fs";var D=(r,e)=>{let{cacheDir:o,handlerFile:t,moduleId:s}=r;if(!t.startsWith(o))return!1;let u=`
`;V.writeFileSync(o,s)};import G from"fs";var w=(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";

`;V.writeFileSync(t,u)};import J from"fs";import{join as K}from"slash-path";import q from"fast-glob";import R 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)),y=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=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}})})},E=r=>y(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 k=(r,e)=>{let{moduleId:o,cacheDir:t,routersFile:s}=r;if(s.startsWith(t)){let u=y(r),c=E(r),n=i=>` ${i.cb} && {
`;G.writeFileSync(t,u)};import J from"fs";import{join as K}from"slash-path";import q from"fast-glob";import R 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)),$=r=>{let{dirs:e,include:o,exclude:t}=r;return e.flatMap((s,u)=>{s.exclude=s.exclude||[];let d=[...t,...s.exclude];return q.sync(o,{ignore:d,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=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=>$(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 k=(r,e)=>{let{moduleId:o,cacheDir:t,routersFile:s}=r;if(s.startsWith(t)){let u=$(r),d=D(r),n=i=>` ${i.cb} && {
source : "${i.source}",

@@ -92,3 +92,3 @@ method : "${i.method}",

}`,l=u.map(i=>`import * as ${i.name} from "${o}/root/${i.file}";`).join(`
`),p=c.map(i=>n(i)).join(`,
`),p=d.map(i=>n(i)).join(`,
`),m=`

@@ -130,15 +130,27 @@ // Imports

configure.serverBefore?.(server);
const { PORT = 3000, PUBLIC_DIR = "import.meta.env.PUBLIC_DIR" } = process.env;
server.use("import.meta.env.BASE", express.static(PUBLIC_DIR));
server.use("import.meta.env.BASE_API", handler);
const {
HOST = '0.0.0.0',
PORT = 3000,
BASE = '"import.meta.env.BASE"',
BASE_API = '"import.meta.env.BASE_API"',
PUBLIC_DIR = '"import.meta.env.PUBLIC_DIR"',
} = process.env;
const SERVER_URL = \`http://\${HOST}:\${PORT}\${BASE}\`;
server.use(BASE, express.static(PUBLIC_DIR));
server.use(BASE_API, handler);
configure.serverAfter?.(server);
server.on("error", (error) => {
console.error(\`Error at http://localhost:\${PORT}import.meta.env.BASE\`, error);
console.error(\`Error at \${SERVER_URL}\`, error);
configure.serverError?.(server, error);
});
server.listen(PORT, () => {
console.log(\`Ready at http://localhost:\${PORT}import.meta.env.BASE\`);
console.log(\`Ready at \${SERVER_URL}\`);
configure.serverListening?.(server, endpoints);
});
`;Q.writeFileSync(t,u)};import Z from"fs";var T=(r,e)=>{let{moduleId:o,typesFile:t}=r,s=`
`;Q.writeFileSync(t,u)};import Z from"fs";var _=(r,e)=>{let{moduleId:o,typesFile:t}=r,s=`
declare module "${o}/handler" {

@@ -166,2 +178,2 @@ import { ServerHandler } from "vite-plugin-api-routes/model";

}
`;Z.writeFileSync(t,s)};var $=(r,e)=>{ee.mkdirSync(r.cacheDir,{recursive:!0}),B(r,e),D(r,e),H(r,e),T(r,e),b(r,e)},b=(r,e)=>{k(r,e)};var L=r=>{let e=t=>(t=S.slash(t),r.watcherList.find(s=>t.startsWith(s))),o={};return{name:"vite-plugin-api-routes",enforce:"pre",config:()=>({resolve:{alias:{[`${r.moduleId}/root`]:C.normalize(r.root),[`${r.moduleId}/server`]:C.normalize(r.serverFile),[`${r.moduleId}/handler`]:C.normalize(r.handlerFile),[`${r.moduleId}/routers`]:C.normalize(r.routersFile),[`${r.moduleId}/configure`]:C.normalize(r.configureFile)}}}),configResolved:t=>{o=t,$(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)&&(b(r,o),s.off("add",p),s.off("change",p),l(!0))};s.on("add",p),s.on("change",p);let m=S.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,P,v)=>{try{(await c(r.handler,{fixStacktrace:!0})).handler(g,P,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;$(r,o),process.env.IS_API_BUILD="true";let{root:t,outDir:s,minify:u,preBuild:c,routeBase:n}=r,l=S.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":S.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 re(p)}}};var F=(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;t=a.slash(t),l=l.map(d=>(d.dir=a.join(t,d.dir),d)),i=w({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),v=a.join(t,u),x=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(v),L({moduleId:e,server:s,handler:u,configure:c,root:t,serverFile:P,handlerFile:v,routersFile:x,typesFile:_,configureFile:M,routeBase:n,dirs:l,include:p,exclude:m,mapper:i,mapperList:O,watcherList:I,outDir:f,cacheDir:o,minify:h,preBuild:g})},ke=F,He=F,Te=F;export{He as createAPI,Te as default,ke as pluginAPI,F as pluginAPIRoutes};
`;Z.writeFileSync(t,s)};var y=(r,e)=>{ee.mkdirSync(r.cacheDir,{recursive:!0}),E(r,e),w(r,e),H(r,e),_(r,e),A(r,e)},A=(r,e)=>{k(r,e)};var L=r=>{let e=t=>(t=I.slash(t),r.watcherList.find(s=>t.startsWith(s))),o={};return{name:"vite-plugin-api-routes",enforce:"pre",config:()=>({resolve:{alias:{[`${r.moduleId}/root`]:S.normalize(r.root),[`${r.moduleId}/server`]:S.normalize(r.serverFile),[`${r.moduleId}/handler`]:S.normalize(r.handlerFile),[`${r.moduleId}/routers`]:S.normalize(r.routersFile),[`${r.moduleId}/configure`]:S.normalize(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:d,ssrFixStacktrace:n,restart:l}=t,p=g=>{e(g)&&(A(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 d(r.configure,{fixStacktrace:!0});(f=i.viteServerBefore)==null||f.call(i,t.middlewares,t,o),u.use(m,async(g,C,v)=>{try{(await d(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:d,routeBase:n}=r,l=I.relative(s,o.build.outDir),p=await d({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 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:d=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=c=>c}=r;t=a.slash(t),l=l.map(c=>(c.dir=a.join(t,c.dir),c)),i=j({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"),T=a.join(o,"types.d.ts"),U=a.join(t,d),O=Object.entries(i).filter(c=>c[1]).map(([c,M])=>({name:c,method:M})),P=l.map(c=>c.dir);return P.push(o),P.push(C),P.push(v),L({moduleId:e,server:s,handler:u,configure:d,root:t,serverFile:C,handlerFile:v,routersFile:x,typesFile:T,configureFile:U,routeBase:n,dirs:l,include:p,exclude:m,mapper:i,mapperList:O,watcherList:P,outDir:f,cacheDir:o,minify:h,preBuild:g})},ke=b,He=b,_e=b;export{He as createAPI,_e as default,ke as pluginAPI,b as pluginAPIRoutes};
{
"name": "vite-plugin-api-routes",
"version": "1.1.6-beta",
"version": "1.1.7-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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc