Commit Graph
1289 Commits
Author SHA1 Message Date
Asher GomezandMarvin Hagemeister da8879dede tests: use the same browser instance across tests and better use explicit resource management (#2901)
On my machine, reduces time taken to perform `deno task test` from
~1m20s to ~30s.

Inspired by and supersedes #2110.

---------

Co-authored-by: Marvin Hagemeister <marvin@deno.com>
2025-05-21 11:32:18 +02:00
Christian Svensson 17257dd1c2 test: use disposable tmp dirs (#2983)
Replaces the patterns below with consistent `AsyncDisposable` and `await
using` resource management for automatic cleanup.

- `await withTmpDir(async (dir) => { ... })` with `finally`
  - Makes code a bit flatter, and reduces callback-hell a bit
- `await Deno.makeTempDir()` + `Deno.remove()`
- `await Deno.makeTempDir()`

Helps be more consistent in removing temporary folders. Among others,
ensures temp folders are removed in the tests below:

- `src/build_cache_test.ts`
- `src/dev/builder_test.ts`
- `src/dev/dev_build_cache_test.ts`

## TODO's

The `Deno.makeTempDir()` method is still used by `buildProd` as well,
but this method is used in the top module scope, where it does not work
correctly with `Deno.test` (it runs before the test methods). I removed
this part from the PR and leave this for later to avoid making the PR
too big.

-
https://github.com/csvn/fresh/blob/test%2Fdisposable-tmp-dirs/tests/test_utils.tsx/#L64
-
https://github.com/csvn/fresh/blob/test%2Fdisposable-tmp-dirs/www/main_test.ts/#L7
2025-05-21 11:13:02 +02:00
Christian Svensson db142115ec feat: support automatic workspace detection in Dev (#2985)
Adds support for [Automatic Workspace
Detection](https://chromium.googlesource.com/devtools/devtools-frontend/+/main/docs/ecosystem/automatic_workspace_folders.md).

- Avoids 404's or middleware logging when this feature is active (e.g.
Chrome/Edge with DevTools open)
- Generates the same UUID based on root folder path (without writing
anything to disk)
- The middleware is lazy and does nothing until the path is opened for
`com.chrome.devtools.json`
2025-05-21 11:09:43 +02:00
Christian Svensson bc8cdb9c7b fix: convert island filePath to valid variable name (#2984)
I only added a unit test, but maybe it's testing internals too much?
Should I add a more E2E test in `tests/` with real files?


Closes #2971
2025-05-21 11:06:16 +02:00
Brian Knight b6c02b0668 docs: Fix build command in deployment documentation (#2840)
The `Self Contained Executable` instructions in the `Deployment`
documentation contains an error in the sample code.

```sh Terminal
$ deno build
$ deno compile --include static --include _fresh --include deno.json -A main.ts
```

should be:

```sh Terminal
$ deno task build
$ deno compile --include static --include _fresh --include deno.json -A main.ts
```

This PR fixes that.
2025-05-19 13:28:48 +02:00
Sviatoslav M. 1321cda916 docs: update rendering-markdown.md (#2800)
When using deno add @deno/gfm outputs the following:
```
error: @deno/gfm is missing a prefix. Did you mean `deno add jsr:@deno/gfm`?
```
Then when jsr is specified:
```
deno add jsr:@deno/gfm
Add jsr:@deno/gfm@0.10.0
```

deno --version: 2.1.4
2025-05-19 13:20:10 +02:00
Asher Gomez b8c75ec0e3 chore: update dependencies (#2975)
Updates relating to Tailwind CSS v4 can be handled in #2903 or #2829.
2025-05-19 13:17:53 +02:00
Asher Gomez 144ed2e75c refactor(core): minor fresh/compat cleanups (#2880) 2025-05-19 12:05:22 +02:00
Asher Gomez 8953650420 refactor(init): tidy up check task (#2976) 2025-05-19 11:04:52 +02:00
Asher Gomez cc93a1f469 tests(init): remove MockTTY (#2974)
These changes simplify implementation logic of the init workflow and
mock `prompt()` and `console()` functionality in a more direct manner.
This makes things easier to reason about by jumping through fewer mental
hoops.
2025-05-19 10:56:16 +02:00
Asher Gomez 3776ef3154 refactor: centralise imports and cleanup exports (#2900)
The benefits of these changes are:
1. Managing and updating dependencies is easier. One only needs to run
`deno outdated` at the root, instead of in each workspace.
2. The versions of dependencies across workspaces is kept consistent.

Closes #2788
2025-05-19 09:41:06 +02:00
Marvin Hagemeister 3900aa70d4 chore: release alpha 34 (#2967) 2025-05-16 21:36:12 +02:00
zhizhengand李嘉图·M·路 ebe65b035e docs(canary): clean the twind part for canary version (#2966)
## What does this PR do?

This PR cleans all the Twind - related parts in the canary
documentation. Specifically, it removes the Twind - related entries in
the docs/toc.ts file, which streamlines the documentation and eliminates
references to the Twind technology that might no longer be relevant or
in use.

## Problem Being Solved
Outdated Information: Twind removed from fresh v2. Keeping Twind -
related content in the documentation can lead to confusion for new users
who might be using the canary version of Fresh with Tailwind CSS.

## Changes Made
docs/toc.ts:
Removed the "migrating - to - tailwind" entry. 
Removed the "using - twind - v1" entry, which is directly related to
using the Twind v1 version and is no longer needed in the canary
documentation.
Removed the "using - fresh - canary - version" entry, which is no reason
in canary docs

---------

Co-authored-by: 李嘉图·M·路 <146103794+Ricardo-M-Zheng@users.noreply.github.com>
2025-05-16 21:35:56 +02:00
Christian Svensson 49737c05c5 ci: improve CI perf by adding dependency caching (#2961)
The `denoland/setup-deno` action recently added built-in caching
(https://github.com/denoland/setup-deno/pull/89,
https://github.com/denoland/setup-deno/pull/98). This makes it a lot
simpler to add caching of the `DENO_DIR` during CI runs, without needing
`@actions/cache` manual setup.

This should speed up CI runs by avoiding downloading dependencies
between every run.
2025-05-16 21:28:39 +02:00
Marvin Hagemeister 6ff0becd0a fix: duplicate @preact/signals version (#2964)
We initialized new projects with `@preact/signals@2.x` but Fresh itself
was using `1.x`. There shall only ever be one version.

Kinda makes me wish Deno had some sort of `peerDependencies`.

Fixes https://github.com/denoland/fresh/issues/2962
2025-05-16 21:23:53 +02:00
Marvin Hagemeister fa5aac5233 chore: fix formatting error in Deno 2.3.3 (#2965)
Upstream bug: https://github.com/denoland/deno/issues/29337
2025-05-16 21:09:34 +02:00
Marvin Hagemeister 4a8dea14ac www: link banner to Fresh 2 blog post (#2958)
Fixes https://github.com/denoland/fresh/issues/2957
2025-05-16 15:25:02 +02:00
Marvin Hagemeister e996b5e2fe feat(core): support exclude option for transformers (#2960)
This PR adds general support for an `exclude` option to file
transformers. This allows plugin to skip processing excluded files. The
exclude array can be a `string`, a `RegExp` or a glob pattern.

Fixes https://github.com/denoland/fresh/issues/2937
2025-05-16 15:17:43 +02:00
Matt NieldandMarvin Hagemeister 107c25b79a chore: Update links (#2956)
This commit updates several links which are outdated and now redirect to
different URLs on the updated Deno website and documentation.

There are a few dozen instances of URLs starting with
`https:://deno.land/x` and `https:://deno.land/std`. I left these alone
since they are dependencies. Would it make sense to update these from
the versions hosted at `deno.land` to their JSR equivalents, since that
is the new and preferred location of the Deno Standard Library packages
as well as other JavaScript/TypeScript packages used by Deno projects?

For example, the latest version of the Deno Standard Library is now
hosted at `https://jsr.io/@std` instead of `https://deno.land/std`.


![image](https://github.com/user-attachments/assets/7416da3b-3867-4d8f-9a1a-79e6a11ddb46)

---------

Co-authored-by: Marvin Hagemeister <hello@marvinh.dev>
2025-05-15 19:24:27 +02:00
Marvin Hagemeister 63cb208f8b fix(core): support method handler on _error, _404 and _500 routes (#2955)
This PR adds support for using method handlers in `_error`, `_404` and
`_500` files.

Fixes https://github.com/denoland/fresh/issues/2953
2025-05-15 17:15:30 +02:00
Christian Svensson b852fe7deb fix: log warning on invalid route configurations (#2954)
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
2025-05-15 17:09:53 +02:00
Asher Gomez 20162f6896 chore: use lint tags (#2952) 2025-05-15 09:34:46 +02:00
Marvin Hagemeister f8d390e2c3 chore: release alpha 33 (#2949) 2025-05-14 23:25:08 +02:00
Marvin Hagemeister ffd7cdd0bd fix(init): fetch favicon from network like before (#2948)
Reverts back to fetching the favicon from the network. Copying assets
from JSR turns out to be difficult.

Fixes https://github.com/denoland/fresh/issues/2941
2025-05-14 23:20:42 +02:00
Marvin Hagemeister 638a98b106 chore: release alpha 32 (#2947) 2025-05-14 23:05:22 +02:00
Marvin Hagemeister 1957fd0ff6 fix(init): must use urls for asset copying (#2946)
Second attempt to fix https://github.com/denoland/fresh/pull/2943 .
Turns out that `import.meta.dirname` is `undefined` when served from
JSR. I'm not able to reproduce that error locally though.

Fixes https://github.com/denoland/fresh/pull/2943
2025-05-14 22:59:02 +02:00
Marvin Hagemeister 74d5c0f98f chore: release alpha.31 (#2945) 2025-05-14 22:50:25 +02:00
Marvin Hagemeister 36442d0ded fix(core): silence esbuild jsx comment warning (#2944)
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
2025-05-14 22:45:04 +02:00
Marvin Hagemeister 2306be1188 chore: add coverage/ to gitignore (#2940)
When running `deno test --coverage` Deno will create a `coverage/`
directory by default. We were missing that in our gitignore.
2025-05-14 22:38:26 +02:00
Marvin Hagemeister 4fc1a2b92e fix(init): include favicon.ico in init package (#2943)
Fixes a regression introduced by
https://github.com/denoland/fresh/pull/2867

Fixes https://github.com/denoland/fresh/issues/2941
2025-05-14 22:38:10 +02:00
Asher Gomez 7728e1cb52 chore(core): simplify tasks (#2892) 2025-05-14 13:27:13 +02:00
Marvin Hagemeister c3095f38c4 chore: release 2.0.0-alpha.30 (#2939) 2025-05-14 10:55:47 +02:00
Christian Svensson e2d0624512 fix: do not skip app-wrapper for sibling routes (#2911)
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
2025-05-13 18:03:13 +02:00
Christian Svensson f15f225576 fix: make static folders with dot such as .well-known allowed (#2929)
This PR intends to address an error logged when opening a DevTools in a
Chromium based browser while using Fresh in dev mode.

<details>

<summary><strong>See error</strong></summary>

```
Error: Processed file resolved outside of static dir C:\Users\<name>\fresh-site\src\static\.well-known\appspecific\com.chrome.devtools.json
    at MemoryBuildCache.readFile (https://jsr.io/@fresh/core/2.0.0-alpha.29/src/dev/dev_build_cache.ts:81:13)
    at eventLoopTick (ext:core/01_core.js:178:7)
    at async freshStaticFiles (https://jsr.io/@fresh/core/2.0.0-alpha.29/src/middlewares/static_files.ts:30:18)
    at async FreshReqContext.fn (https://jsr.io/@fresh/core/2.0.0-alpha.29/src/middlewares/mod.ts:99:18)
    at async https://jsr.io/@fresh/core/2.0.0-alpha.29/src/dev/middlewares/error_overlay/middleware.tsx:15:14
    at async FreshReqContext.fn (https://jsr.io/@fresh/core/2.0.0-alpha.29/src/middlewares/mod.ts:99:18)
    at async fn (https://jsr.io/@fresh/core/2.0.0-alpha.29/src/middlewares/mod.ts:99:18)
    at async https://jsr.io/@fresh/core/2.0.0-alpha.29/src/app.ts:232:16
    at async mapped (ext:deno_http/00_serve.ts:407:18)
```

</details>

DevTools tries to load a
`<root>/static/.well-known/appspecific/com.chrome.devtools.json` file,
which incorrectly is flagged as "outside" the static directory, and thus
generates errors instead of 404.

Maybe hidden folders (starting with `.`) in `/static` should be opt-in
though? I'm not sure if anyone puts folders with `.` prefix inside
`static/` without intending them to be accessible?

- `..` throws errors (outside staticDir)
- `.` returns "missing file" (unless `config.allowHiddenFolders` is
true)

## Automatic workspace folders

I think a follow-up PR could be for the Dev `Builder` to also implement
support for [Automatic workspace
folders](https://chromium.googlesource.com/devtools/devtools-frontend/+/main/docs/ecosystem/automatic_workspace_folders.md),
by returning JSON content automatically at
`.well-known/appspecific/com.chrome.devtools.json`.

I think a good first step is to allow `.<folder-name>`, especially since
`.well-known/` has [many valid
use-cases](https://en.wikipedia.org/wiki/Well-known_URI), and as such is
not unreasonable to want to add static files in.
2025-05-13 10:03:05 +02:00
TylerandTyler 50e5bc7ae4 docs: fix readme url for deployment (#2930)
fixes #2695

this is my best guess to what the url is meant to link to now

Co-authored-by: Tyler <26290074+thegitduck@users.noreply.github.com>
2025-05-13 09:31:11 +02:00
Marvin Hagemeister fcd94809c8 fix(esbuild): disable spammy warning for monaco editor (#2928)
It's a super spammy warning message when you're using the monaco editor.
They have code like that as the result of minifcation.

Fixes https://github.com/denoland/fresh/issues/2775
2025-05-13 00:13:21 +02:00
Asher Gomez 84a03ee66c chore(init): cleanup twind options (#2868)
These values are no longer used.
2025-05-12 23:29:17 +02:00
Asher Gomez 8ea3dbeac5 refactor(www): use useSignal() instead of useState() (#2894) 2025-05-12 23:28:46 +02:00
Marvin Hagemeister d2da471d67 fix(partial): form dialog method not supported (#2927)
The `<form>` method value `dialog` does no network request, so we should
ignore it for partials.

Fixes https://github.com/denoland/fresh/issues/2885
2025-05-12 21:19:19 +02:00
Marvin Hagemeister 95b82f5281 chore: don't spam test output with "Listening on..." (#2926)
Follow up to https://github.com/denoland/fresh/pull/2897
2025-05-12 20:34:14 +02:00
Marvin Hagemeister 24ad244a79 fix: error when no Response instance is returned (#2924)
Fixes https://github.com/denoland/fresh/issues/1494
2025-05-12 20:30:45 +02:00
Marvin Hagemeister a49fc3796f chore: ignore check fmt on canary (#2925)
Ignore checking formatting on canary as the formatting might be
different from stable releases of Deno.
2025-05-12 20:30:17 +02:00
d68b5ecd5b refactor: replace puppeteer with astral for screenshot and close #2919 (#2920)
due to resolves the `NotFound: No such file or directory` error in the
`www/utils/screenshot.ts` script, which was caused by improper file path
construction. This error prevented screenshots from being saved
correctly. close #2919

-- update --patch1
## Current Status
- Using npm:puppeteer for webpage screenshots
- npm lifecycle script warnings present
- deno-puppeteer is no longer maintained
- npm:puppeteer still has compatibility issues

## References
- [astral](https://github.com/lino-levan/astral): Browser automation
library designed for Deno
-
[deno-puppeteer#92](https://github.com/lucacasonato/deno-puppeteer/issues/92):
Recent discussion about deno-puppeteer

## Changes Made
1. Dependency Replacement
   - Replaced npm:puppeteer with jsr:@astral/astral
   - Removed npm lifecycle script warnings

2. Dependency Management Optimization
   - Centralized all imports in deno.json
   - Using jsr: and URL imports

## Testing Steps
1. Run screenshot command:
```bash
deno task screenshot https://google.com google
```

2. Check output:
   - Verify no npm warnings
   - Validate generated image files:
     - ./www/static/showcase/google2x.jpg
     - ./www/static/showcase/google1x.jpg
   - Confirm image quality

3. Run complete test suite:
```bash
deno task ok
```
- Ensure all tests pass

4. Verify functionality:
   - Screenshot feature works correctly
   - Image processing (2x/1x) functions properly

---------

Co-authored-by: 李嘉图·M·路 <146103794+Ricardo-M-Zheng@users.noreply.github.com>
Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
2025-05-12 20:02:15 +02:00
Marvin Hagemeister 09705b9b7f fix: bigint key values erroring (#2923)
Fixes https://github.com/denoland/fresh/issues/2802
2025-05-12 19:49:13 +02:00
Tim Reichen 1cfb4bc876 refactor: make App.prototype.handler() sync (#2906) 2025-05-12 10:12:50 +02:00
Tim Reichen 9605cd81b5 refactor: move mergePaths() to utils.ts (#2905) 2025-05-12 09:59:37 +02:00
Tim Reichen c6d4c47e00 refactor: App.prototype.listen() (#2907) 2025-05-12 09:58:37 +02:00
Christian Svensson c0e2b80690 fix: allow relative paths for outDir and staticDir (#2914)
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
2025-05-12 09:43:01 +02:00
Christian Svensson d10ea5a89a fix: remove unnecessary config property in init script (#2915)
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.
2025-05-12 09:42:16 +02:00
Christian Svensson a23596153b fix: allow Data to be inferred from Handler function (#2916)
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.
2025-05-12 09:41:28 +02:00