Commit Graph
1313 Commits
Author SHA1 Message Date
Asher Gomez c3c79352b0 fix(core): refine HttpError.status property type (#2890)
As this is property only ever has an error HTTP status code (>400).
2025-06-16 17:57:49 +02:00
Asher Gomez 71b7de4581 fix(core): align defineFn() with previous definition (#3043)
https://github.com/denoland/fresh/blob/990357629e50ef123e5b5ee2b80c250be867534f/src/server/defines.ts#L13-L16

Closes #3042
2025-06-16 11:04:18 +02:00
Asher Gomez 71bec59820 chore: change patch Deno config file option to links (#3030)
Ref: https://github.com/denoland/deno/pull/29677
2025-06-14 09:55:06 +02:00
zhizhengand李嘉图·M·路 dd1721bce6 chore: refactor sreenshot and add test (#3032)
- Refactor screenshot functionality into testable utility functions
- Add comprehensive test suite to catch regressions early
- Ensure functionality doesn't break unexpectedly without notification

--patch-1
based on review, make throw error naturally

---------

Co-authored-by: 李嘉图·M·路 <146103794+Ricardo-M-Zheng@users.noreply.github.com>
2025-06-13 20:39:10 +02:00
Asher Gomez e868a924fa fix(update): correct return and argument types for defineFn() (#3023)
Previously, the return union type of the inner function and the function
itself contained a `Request` instead of a `Response`.
2025-06-12 13:25:36 +02:00
zhizhengand李嘉图·M·路 e9cb6486c8 feat(update): use std lib to replace the custom processbar (#3027)
- The constructor of the process-bar in the currently used std/cli
differs from that of the latest version, so the relevant dependencies
have been updated.

- The custom processbar has been replaced with the std lib, and
customization has been carried out to meet the current scenario.

In test env, seem like: 

![bb2868ed3911071ce9915a9c8662786](https://github.com/user-attachments/assets/e4419965-40fc-4ad8-8647-74e30c75ea98)

close #3021

---------

Co-authored-by: 李嘉图·M·路 <146103794+Ricardo-M-Zheng@users.noreply.github.com>
2025-06-12 12:32:09 +02:00
zhizhengand李嘉图·M·路 133d4bcfb5 feat(update): delete fresh.gen.ts in @fresh/update (#3028)
delete fresh.gen.ts
close #3022
- before:

![8dd2fb246bc33b206b4f50f3d8f7439](https://github.com/user-attachments/assets/fa45af2f-0241-4ad7-9837-6b14364756ed)



- after:

![50b9512afcd0f522dada0ab3f3b4cc0](https://github.com/user-attachments/assets/56539c41-3ee5-4d3a-a1ac-5c64e5d008b0)

Co-authored-by: 李嘉图·M·路 <146103794+Ricardo-M-Zheng@users.noreply.github.com>
2025-06-12 12:30:46 +02:00
zhizhengand李嘉图·M·路 cb402b9839 fix(utils): restore missing dependencies for screenshot utility (#3016)
The relevant dependencies were lost in previous cleanups. This situation
caused the screenshot function to fail.

This PR properly cleans up the functional function and restores its
operation.

---------

Co-authored-by: 李嘉图·M·路 <146103794+Ricardo-M-Zheng@users.noreply.github.com>
2025-06-11 17:47:57 +02:00
b2807b7720 feat(update): More logs for update script #2968 (#3010)
Before:

![340fffdbf558fa7a1bc1036972e0679](https://github.com/user-attachments/assets/e20e1c2f-1e1c-4477-82ee-231163d53085)

After:
Case1:

![1adc44294f2001dc43cd411254dfc2d](https://github.com/user-attachments/assets/e7bebd32-1083-4bc1-b00b-346c9ba66d43)
Case2:

![8cd3445877d5311ff8d9b9f66adb30e](https://github.com/user-attachments/assets/596ad777-6f6d-4b62-ae0e-32b82ebefb20)

In Test Env:

![df5b20de6d1437e471c6dcfc1e55178](https://github.com/user-attachments/assets/1eb53cdc-4398-4e61-874d-4c72e037e57f)

Close #2968

---------

Co-authored-by: 李嘉图·M·路 <146103794+Ricardo-M-Zheng@users.noreply.github.com>
Co-authored-by: Marvin Hagemeister <marvin@deno.com>
2025-06-11 17:40:52 +02:00
Octo8080XandMarvin Hagemeister 1213aad90d feat: add CORS middleware (#3013)
## Why was this PR initiated?

I opened an issue and held discussions about officially providing
middleware in Fresh by porting middleware from Hono.

https://github.com/denoland/fresh/issues/3011

## What does this PR do? 

I introduced the CORS middleware bundled with Fresh by porting the CORS
middleware from Hono.


I appreciate your review.

---------

Co-authored-by: Marvin Hagemeister <marvin@deno.com>
2025-06-11 17:34:00 +02:00
zhizheng 10400ff130 fix(www): quotes in markdown image alt causing html issues #3002 (#3003)
## Problem:
The problem was reproduced as described in #3002. Chrome DevTools shows
the following error:

props.js:137 Uncaught (in promise) InvalidCharacterError: Failed to
execute 'setAttribute' on 'Element': 'docs-content""' is not a valid
attribute name.
    at j (props.js:137:8)
    at V (index.js:528:5)
    at O (index.js:326:28)
    at I (children.js:97:16)
    at V (index.js:547:4)
    at O (index.js:326:28)
    at I (children.js:97:16)
    at V (index.js:547:4)
    at O (index.js:326:28)
    at I (children.js:97:16)

## Solution:
The issue was resolved by removing the double quotes around docs-content
in the Markdown image description. After this change, the application
resumed normal operation.

## Test:
Deno task ok and local env check

## Close:
close #3002
2025-06-04 19:32:31 +02:00
zhizheng a85fdf18e2 fix(update): fresh/runtime import specifier updated incorrectly (#3009)
…ports

The original code is shown in the following figure, and there is an
incorrect usage in it.


![1749021630760](https://github.com/user-attachments/assets/2d603bdd-6dd7-4ddf-9dae-8d62b8bdaedf)
2025-06-04 19:24:48 +02:00
zhizhengand李嘉图·M·路 a631ae3876 Fix[docs] correct the broken links and errors in migration-guide (#3008)
Co-authored-by: 李嘉图·M·路 <146103794+Ricardo-M-Zheng@users.noreply.github.com>
2025-06-03 13:30:12 +02:00
Christian Svensson b4c3ff8e98 feat: add flag to FreshContext for partial requests (#2993)
Addresses a gap between [Fresh
v1](https://github.com/denoland/fresh/blob/1.x/src/server/types.ts#L192)
and Fresh v2, by adding `ctx.isPartial` to `FreshContext`.

The same route (e.g. `GET /api/autocomplete`) can be called from both an
Island or a Partial. Returning JSON or HTML depending on the destination
of the code.

Or is the intent that endpoints returning partials and data should be
separated, and this pattern is not to be encouraged in Fresh v2? My use
case in Fresh v1 was an `/routes/api/cart.tsx`, which can either just
toggle a product from the cart (via cookie), but also update UI elements
(e.g. cart icon) based on if called from partial or not.


![image](https://github.com/user-attachments/assets/a1cbcfb1-2446-4d6d-bce5-4c3d6acf9bfd)
2025-05-26 14:15:36 +02:00
zhizhengand李嘉图·M·路 9eaefd5be0 showcase: add zhi's blog build by fresh (#2918)
Co-authored-by: 李嘉图·M·路 <146103794+Ricardo-M-Zheng@users.noreply.github.com>
2025-05-26 14:13:32 +02:00
Mahesh Bansod 1e6f0d69b1 init: update instructions to run project from a fresh scaffold (#2996)
After scaffolding the project with 
```
deno run -Ar jsr:@fresh/init@2.0.0-alpha.34
```
Instruction show up to run the project:
```
Enter your project directory using cd fresh-project.
Run deno task start to start the project. CTRL-C to stop.

Stuck? Join our Discord https://discord.gg/deno
```
these instructions seem to be outdated since running `deno task start`
on this project throws an error.

While this error also hints that you might want to run the dev server, I
think it gives a bad impression that a newly scaffolded project is
throwing an error after running the command that it has specified. Also,
not many people, especially beginners, read the error messages
completely.
2025-05-26 14:12:47 +02:00
zhizheng 50d6f7fd09 fix: improve styling of "Edit on GitHub" link for better visibility in Dark mode (#2994)
change style for dark mode
last:

![image](https://github.com/user-attachments/assets/52ee66b2-4779-406b-b220-ede6a9100c77)
now:

![image](https://github.com/user-attachments/assets/3c822f3b-4e41-4f30-a5e5-dd1a8cf66d2b)
2025-05-23 14:42:39 +02:00
Marvin Hagemeister 76c77e503e docs: Make "Edit on GitHub" link more prominent (#2992)
Folks seem to miss this button
2025-05-22 11:52:52 +02:00
Marvin Hagemeister 613c19221f docs: fix dark mode info background (#2991) 2025-05-22 11:52:33 +02:00
Marvin Hagemeister dbb76623a4 Revert "feat: update the tailwind plugin to suuport tailwindv4 #2819 (#2903)" (#2988)
Reverts tailwind v4 update. Something is wrong with the CSS files on
fresh.deno.dev 😢
2025-05-21 16:07:51 +02:00
40e7747228 feat: update the tailwind plugin to suuport tailwindv4 #2819 (#2903)
Inspired by #2819, #2829, and
https://github.com/pakornv/fresh-plugin-tailwindcss, I made minimal
modifications to the plugin-tailwind, I originally intended to update
based on #2829, but I was informed by the system that I couldn't push.

Due to the breaking changes in Tailwind v4, some PostCSS plugins are no
longer required. Additionally, I updated the syntax in the /www
directory. The /www directory now uses the updated plugin supported by
Tailwind v4.I think this has made initial progress.

# What This PR Solves
The Tailwind plugin has been updated to support Tailwind v4, and it is
currently functioning well both in the repository's www directory and in
the initialized project which for test.

## --patch-1

### 1. Dependency Optimization
- Removed `cssnano` dependency, using Tailwind v4's built-in
optimization(Based on @csvn 's suggestion)
- Removed `autoprefixer` dependency
- Updated `tailwind-plugin` version number
### 2. Build Configuration Adjustments
- Added `--node-modules-dir` parameter to `/www` task for Tailwind v4
support (Based on @marvinhagemeister 's suggestion)
- Added `--allow-scripts` parameter to enable `@tailwindcss/oxide`
execution
### 3. Code Adaptation
- Modified Tailwind-related code in `/www` to support Tailwind v4
- Updated dependency configuration in `deno.json`
### 4. Feature Restoration
- Added `imagescript` and `astral` dependencies to restore screenshot
functionality lost in previous PR updates
- Fixed the issue where the `tailwind-plugin` dependency was incorrectly
pointing to the JSR package instead of the local repository source code
in previous PR.

## --patch-2
- Upgraded Tailwind CSS to the latest version.
- Removed unnecessary dependencies.
- Enabled CSS minification by default when Fresh is in production mode.
- Updated docs/canary/examples/migration-guide.md to support the new
Tailwind plugin format.
- Updated init/src/init.ts to support the new Tailwind version and
plugin version, use new `@import "tailwindcss"`, and generate the new
plugin format.
- Updated init/src/init_test.ts: tests now expect `css` to match
`/tailwindcss/` instead of `/@tailwind/`.
- Removed plugin-tailwindcss/src/types.ts as it is no longer needed, and
updated plugin-tailwindcss/src/mod.ts and www/dev.ts to support the new
format.

Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>

## --patch-3
Addressing @marvinhagemeister feedback, this patch reverts the
unintended loss of PR #2960's changes caused by merge conflicts.

## --patch-4

I initialized a project according to the migration documentation and
used @fresh/update to test whether the plugin works properly with
v2-alpha-34. The results show that it works fine.

- The plugin is published at
jsr:@freshpress/fresh-plugin-tailwind@0.0.1-alpha.8.

- The test project is published at
https://github.com/SisyphusZheng/fresh-project-test/tree/main/fresh-project.

# How Testing Was Conducted

## Local Environment Testing
1. Environment Cleanup
```bash
rm -rf ./.cache/deno deno.lock node_modules
```

2. Test Execution
```bash
deno task www
```

3. Result Verification
- Checked functionality in local `/www` environment
- Confirmed all features working properly

## Code Inspection
- Passed `deno task ok` check

## This forked /www website is hosted and running on GitHub Codespaces,
with support for the latest code changes. You can check it out at:
https://silver-trout-pjr4jw7xx5x9299x6-8000.app.github.dev/

---------

Co-authored-by: 李嘉图·M·路 <146103794+Ricardo-M-Zheng@users.noreply.github.com>
Co-authored-by: deno-deploy[bot] <75045203+deno-deploy[bot]@users.noreply.github.com>
Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
Co-authored-by: Marvin Hagemeister <marvin@deno.com>
2025-05-21 16:01:57 +02:00
Marvin Hagemeister d5a2afd7ac fix(update): Update tasks + lock in deno.json (#2987)
Noticed that we don't update these.
2025-05-21 15:23:41 +02:00
Marvin Hagemeister 750ab35499 fix: add back LayoutConfig (#2982)
~~Makes it easier to upgrade from 1.x .~~

Initially, I assumed it would be just an alias to `RouteConfig`, but
upon closer inspection that has some additional properties that make no
sense for a layout.
2025-05-21 13:44:09 +02:00
Marvin Hagemeister e595d35c44 docs: simplify introduction content (#2978)
The original text is a bit wordy. This shortens the introduction content
a bit in our docs.
2025-05-21 11:32:50 +02:00
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