kwhitley / itty-router

A little router.
MIT License
1.71k stars 77 forks source link

Version 2.6.0 generated mjs file does not have named exports #100

Closed copyrighthero closed 2 years ago

copyrighthero commented 2 years ago

In version 2.6.0, the generated .mjs file exposes only a default export of an object containing the Router, the syntax import {Router} from 'itty-router' does not work.

The generated .mjs file contains the following code, and is picked up by Rollup and Webpack by default, causes build to fail. Reverting back to version 2.5.3 works.

export default{Router:function({base:t="",routes:n=[]}={}){return{__proto__:new Proxy({},{get:(e,a,o)=>(e,...r)=>n.push([a.toUpperCase(),RegExp(`^${(t+e).replace(/(\/?)\*/g,"($1.*)?").replace(/\/$/,"").replace(/:(\w+)(\?)?(\.)?/g,"$2(?<$1>[^/]+)$2$3").replace(/\.(?=[\w(])/,"\\.").replace(/\)\.\?\(([^\[]+)\[\^/g,"?)\\.?($1(?<=\\.)[^\\.")}/*$`),r])&&o}),routes:n,async handle(e,...r){let a,o,t=new URL(e.url);e.query=Object.fromEntries(t.searchParams);for(var[p,s,u]of n)if((p===e.method||"ALL"===p)&&(o=t.pathname.match(s))){e.params=o.groups;for(var c of u)if(void 0!==(a=await c(e.proxy||e,...r)))return a}}}}};
kwhitley commented 2 years ago

Thanks! PR pending :)