Commit Graph
124 Commits
Author SHA1 Message Date
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
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
Asher Gomez 20162f6896 chore: use lint tags (#2952) 2025-05-15 09:34:46 +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
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
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
Tim Reichen 1cfb4bc876 refactor: make App.prototype.handler() sync (#2906) 2025-05-12 10:12:50 +02:00
Marvin Hagemeister f9bfecab8e fix(builder): css hash incorrectly transforming data urls (#2921)
Fixes https://github.com/denoland/fresh/issues/2599
2025-05-12 09:40:35 +02:00
Asher Gomez 45ce7e3ac0 chore: add doc checker (#2877)
First steps towards #2876
Depends on https://github.com/denoland/std/pull/6632
2025-05-02 10:55:55 +02:00
Asher Gomez b582c57e57 refactor(core): use getSnapshotPath() (#2873) 2025-04-30 10:31:47 +02:00
Tim Reichen 0a634bd2d2 chore: fix lint errors (#2833)
This PR fixes current lint errors thrown by `deno lint`.
2025-03-05 12:31:25 +01:00
Luca Casonato 65d61bd1d5 feat: add open telemetry instrumentation (#2786)
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.
2024-12-10 15:03:50 +01:00
Luca Casonato 6b685dde9f fix: serve internal JS from path containing build ID (#2753)
Previously imported chunks were not cached at all. They are now cached
properly with immutable cache headers.
2024-11-08 11:44:15 +01:00
Luca CasonatoandMarvin Hagemeister 407987589f feat: support fresh projects that are part of a workspace (#2716)
Also a performance improvement & bug fix in the tailwind plugin.

---------

Co-authored-by: Marvin Hagemeister <marvin@deno.com>
2024-10-17 17:08:24 +02:00
Christian Svensson 628832af0f fix: ensure file paths in snapshot.json uses / (#2704)
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
2024-10-15 11:29:35 +02:00
Marvin HagemeisterandLuca Casonato de8f1b0c59 feat: update for Deno 2 (#2655)
Co-authored-by: Luca Casonato <hello@lcas.dev>
2024-09-30 18:30:30 +02:00
Marvin Hagemeister becd440d77 fix: error bundling JSR islands (#2552) 2024-06-26 16:55:26 +02:00
Marvin Hagemeister 72811da29b fix: etag caching HTTP headers (#2504) 2024-06-25 10:21:43 +02:00
Marvin Hagemeister 0f6b4f624f chore: remove debug trace logs (#2545) 2024-06-25 10:08:48 +02:00
Marvin Hagemeister 49839079a4 Fix: static file processed twice if outdir inside static dir (#2543)
Fixes https://github.com/denoland/fresh/issues/2541
2024-06-24 18:13:28 +02:00
Marvin Hagemeister e007597ff3 feat: remove MODE global (#2483) 2024-06-03 16:54:37 +02:00
Marvin Hagemeister 2fb8606e9e fix: path handling inconsistencies (#2482) 2024-06-03 15:03:48 +02:00
Marvin Hagemeister 9347b84cba feat: inject process.env.NODE_ENV for third party libs (#2481) 2024-05-31 15:18:23 +02:00
Marvin Hagemeister 88c3671a09 fix: error handling in fs routes (#2474)
Ran into an issue where we weren't responding with the correct status
code and passed response headers. This was a bit of a rabbit hole and it
was caused by us wrapping to more error handling middlewares than
necessary.
2024-05-31 14:27:36 +02:00
Luca Casonato 8d85945da6 fix: remove Data from FreshContext (#2473)
This is now only on `PageProps`.
2024-05-31 13:50:28 +02:00
Luca Casonato dc283a137b fix: remove @fresh/core/client export (#2477)
These files are now referenced with https URLs.
2024-05-29 12:20:57 +02:00
Luca Casonato 4fab47357f tests: wait for esbuild to shut down (#2476) 2024-05-27 20:03:48 +02:00
Luca CasonatoandMarvin Hagemeister d06dad5be6 tests: don't disable all the sanitizers (#2472)
The tests also pass with them enabled for me.

---------

Co-authored-by: Marvin Hagemeister <marvin@deno.com>
2024-05-27 15:00:40 +02:00
Marvin Hagemeister f9545c3d63 fix: don't show error overlay on HttpError < 500 (#2462) 2024-05-24 23:46:21 +02:00
Marvin Hagemeister 9a7399a769 chore: disable sanitizers in esbuild tests (#2461) 2024-05-24 20:39:54 +02:00
Marvin Hagemeister 77dc77826e fix: only load error overlay in development (#2460) 2024-05-24 20:29:59 +02:00
Marvin Hagemeister 287929e4d2 major: import Fresh 2.0 code (#2449)
🎉
2024-05-24 09:40:08 +02:00
Marvin Hagemeister e4981d30ad www: rework docs layout (#2429)
- Re-enable partials
- clean up layout a bit
2024-05-21 17:38:32 +02:00
Bedis Nbiba 1d69f167ee chore: satisfy use-import-type lint (biomejs) (#2389)
https://biomejs.dev/linter/rules/use-import-type/

From that page the argument is 

>The rule ensures that all imports used only as a type use a type-only
import. It also groups inline type imports into a grouped import type.
2024-03-27 08:00:14 +01:00
Luca CasonatoandMarvin Hagemeister 29d582c987 chore: update ahead-of-time build docs for Deno Deploy (#2381)
Co-authored-by: Marvin Hagemeister <marvin@deno.com>
2024-03-22 22:19:17 +01:00
Marvin Hagemeister a2be1abc6b chore: update Preact to 10.19.6 (#2331) 2024-02-22 10:46:41 +01:00
Reed von Redwitz 82c75f85e9 fix: update dependency recommendations (#2320)
closes https://github.com/denoland/fresh/issues/2319

The issue is because `imports.ts` wasn't changed before releasing. I
thought I would go through and bump some other versions as well. This
handles everything except the esbuild stuff and `tests/`.
2024-02-19 10:33:04 +01:00
Roj [roːʒ] d19c22d592 feat: add back twind in init wizard (#2290) 2024-01-30 12:34:38 +01:00
Benjamin Jesuiter 2652b85532 fix: GH actions warning by upgrading to v4 #2285 (#2286)
I tested the change in my own repo, the warning on github disapears for
the "actions/checkout" action.
It is still there for the denoland/setup-deno action, but an upgrade PR
is already ongoing for this action, see:
https://github.com/denoland/setup-deno/pull/56
2024-01-29 14:13:32 +01:00
Reed von Redwitz 3f28cc8977 chore: upgrade tailwind to 3.4.1 (#2287) 2024-01-29 14:10:28 +01:00
Reed von Redwitz ca8338e04d chore: bump std to 0.211.0 and loader to 0.8.3 (#2241) 2024-01-11 15:54:41 +01:00
Marvin Hagemeister 912f3782a3 feat: improve tailwind deployment flow (#2227)
By moving folks from `twind` over to the `tailwind` plugin we have
traded support questions about "how to get twind autocompletion
working?" with "my styles are not showing up in automatic mode". The
tailwind plugin has a hard requirement on having a build step. We have
documented this at various places and have a guide on how to set
everything up, but it's much better if we float those steps from Fresh
itself when we detect this.

With this PR we will prepare a `.github/workflows/deploy.yml` file
already where the user only needs to swap out the project name.

When Fresh is started in production mode, the tailwind plugin is active
and no snapshot files were loaded, then we print a helpful hint to the
console:

```sh
No pre-compiled tailwind styles found.

Did you forget to run "deno task build" prior to starting the production server?
```

When we are running inside Deno Deploy this PR goes one step further.
Since it is the first time many users might use Deno Deploy we'll also
show a simple page that shows how to finish the tailwind setup. I've
intentionally tried to not present this as a warning but rather as a
"finishing" step to avoid scaring users off. It's not the prettiest
page, but it's good enough for now.

<img width="892" alt="Screenshot 2024-01-09 at 23 41 27"
src="https://github.com/denoland/fresh/assets/1062408/9bf2a61b-5551-4d8e-bdf8-b498072f8e98">


Fixes https://github.com/denoland/fresh/issues/2223
2024-01-10 10:35:26 +01:00
Marvin Hagemeister f63752062a chore: change assert to with for import attributes (#2231) 2024-01-10 10:25:07 +01:00
Reed von Redwitz 7465dbd978 feat(init): task to generate manifest file (#1422) 2023-12-05 15:03:37 +01:00
Marvin Hagemeister 054ffbb44a fix: dots in island + route name not working (#2105) 2023-11-30 18:14:59 +01:00
Reed von Redwitz a0483bc357 chore: create manifest generation task (#2088) 2023-11-30 17:07:00 +01:00
Reed von RedwitzandMarvin Hagemeister 9ab8651018 feat(server): Add basePath config to host from a directory (#2092)
Co-authored-by: Marvin Hagemeister <marvin@deno.com>
2023-11-29 16:44:25 +00:00
Reed von RedwitzandMarvin Hagemeister ad33501692 chore: remove $fresh from import statements (#2079)
Co-authored-by: Marvin Hagemeister <marvin@deno.com>
2023-11-28 16:43:50 +00:00
Reed von RedwitzandMarvin Hagemeister b902205feb chore: bump std to 208 and deal with deprecations (#2081)
Co-authored-by: Marvin Hagemeister <marvin@deno.com>
2023-11-28 16:35:26 +00:00