Related to #2953.
I found it confusing that there were unsupported route configurations,
that fails silently without any errors or wanings. Though I think it is
a good idea to not throw for this, as that would be worse DX. But
logging a warning if the developer is migrating from Fresh v1, or if the
developer is using code that will not work (e.g. copy pasting a handler
from a route to `_middleware`), I think it's helpful where reasonable to
help guide a bit more.
Does a small refactor first to hopefully improve typing to be more
correct for `InternalRoute.handlers`, then adds warnings for the
following:
- `_middleware` using Object form (`GET`, `POST` handlers) of the
handler format
- Helps find issues when moving handler from route to middleware
- `_layout` using `handlers`
- E.g. if developer moves a route to a layout
- ~~`_404`, `_500` or `_error` using Object handler form (`GET`, `POST`
handlers), which is not yet supported (See #2953)~~
- No longer necessary as it is fixed by #2955
JSR is a bit over-eager with inserting JSX comments and inserts both
`@jsx classic` and `@jsxImportSource` which are ignored in combination
Fixes https://github.com/denoland/fresh/issues/2942
This PR adds a unit test for the issue in #2910. I have not found a
solution yet, since I'm not very familiar with the `fsRoutes` code, and
what it is doing. But a thought a unit test with the failing code could
help to find a bug fix.
**Edit:** I managed to fix the failing test by removing a couple of
lines, but I'm not too familiar with the code so I'm not sure if it's
correct. It seems to pass all the tests still...
Closes#2910
This PR consists of several commits, where the goal is to re-enable the
test (fix for Windows), as well as allow relative paths for config
options to address #2913.
1. Re-enables test and normalizes paths for Windows
2. Add unit test for `normalizeConfig` and the `root` option
3. Add unit test for `normalizeConfig` for `build.outDir` and
`staticDir`, and allow the properties to be relative
4. Add JSDoc for fields in `FreshConfig`
I can split these into separate PR's if preferred, but all code changes
are very in nearly the same places.
Closes#2913
From what I can see, `fsRoutes` uses the `FreshConfig.root` option by
default, so this property does not need to be specified. I also added
some JSDoc for the `dir` option in `fsRoutes()` as I understood it's
purpose.
This PR adds support for single-function GET handler data to be inferred
when using `define.page<typeof handler>()`.
```ts
export const handler = define.handlers((ctx) => {
return page({ foo: "foo" });
});
export default define.page<typeof handler>((ctx) => {
ctx.data; // Correctly resolves as { foo: string }
});
```
This PR also adds a test that checks that the types inferred are correct
by type checking.
- Now extends `Error`, so that it satisfies `instanceof Error`
operations.
- Narrows the `status` property to be an actual HTTP status code.
- Outsources default evaluation of the `message` property to
`@std/http/status`, which already implements this functionality.
- Brings the `stack` property to the class, regardless of its status,
which seems like a needless constraint.
This is a follow-up fix to https://github.com/denoland/fresh/pull/2792
The original fix skipped over route groups which lead to them being
mixed with non-grouped routes. This in turn confused the middleware
processing part when building the final routes.
I noticed a small bug with the default GET handlers where middlewares
were not being run. This pull requests fixes the bug and adds some unit
tests for this behavior.
This PR fixes an issue in the route sorting logic when comparing a route
segment with a group vs a segment without one.
- `/(app)/[org]/[app]/index.ts`
- `/auth/login.ts`
When determing the order of these two routes we need to skip over the
`(app)` group to the next non-group segment. This ensures that we are
only scoring actual segments with each other and non-existing ones.
This commit fixes a bug where negative numbers were not correctly
serialized, because the value parser confused "references" (which is
where special negative tokens for special values exist), and "values"
(where negative numbers are just negative numbers). The parser now
correctly distinguishes between the two.
This commit adds some useful automatic instrumentation for when users
are using `--unstable-otel`:
- Fresh renames the span for incoming HTTP requests to `$METHOD $ROUTE`
and the `http.route` attribute is added.
- Fresh creates a span around FS route handlers, showing whether they
returned a response or data.
- Fresh creates a span around async components, showing how long they
took to execute.
- Fresh adds a span around preact rendering, showing how long rendering
takes.
- Fresh adds a span around static file serving, showing how long it took
and whether there were requests without a cache bust key.
We can improve this in the future with more telemetry, such as metrics.
Avoids `\\\\` paths ending up in `snapshot.json` when using `deno task
build` on Windows. Backslashes do not which pathnames in URLs, so these
assets are not returned.
Closes#2703
The whole point of `asset()` is to enable caching. Yet we were not
adding cache control headers... :D
---------
Co-authored-by: Marvin Hagemeister <marvin@deno.com>
I'm trying to migrate one of my projects which publishes a plugin, and
this was blocking me.
Looks like key is typed as `export type Key = string | number | any;`,
so we might need to make more changes here in the future.