fresh
fresh copied to clipboard
fix(plugins/fs_routes): error when exporting middleware array with `createDefine().middleware`
According to the docs of createDefine().middleware, it accepts a single function or an array of functions. But if you actually default export something like this:
export default createDefine().middleware([
(context) => context.next(),
(context) => context.next()
]);
you get this error:
error: Uncaught (in promise) Error: Expected a route, middleware, layout or error template, but couldn't find relevant exports in: _middleware.js
throw new Error(
^
at https://jsr.io/@fresh/core/2.0.0-alpha.27/src/plugins/fs_routes/mod.ts:127:15
at async Promise.all (index 4)
at async fsRoutes (https://jsr.io/@fresh/core/2.0.0-alpha.27/src/plugins/fs_routes/mod.ts:123:48)
For this reason, I updated the isFreshFile function to also allow a non empty array of functions. I also added tests and updated types surrounding it, unfortunately this led to a lot of lines in src/plugins/fs_routes/mod_test.tsx type-erroring "Parameter 'ctx' implicitly has an 'any' type", but I was unable to fix that with my little TS knowledge.