Commit Graph
190 Commits
Author SHA1 Message Date
Hong Minhee (洪 民憙)andBartek Iwańczuk b11d1d98f2 fix: handle invalid date objects in jsonify stringify (#2851)
## Summary
- Handles the case when `Date.toISOString()` throws for invalid dates by
catching the error and serializing as `"Invalid Date"`
- Round-trips correctly: `new Date("Invalid Date")` serializes to
`["Date","Invalid Date"]` and deserializes back to an invalid `Date`
object
- Adds test case and snapshot for invalid `Date`

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2026-03-26 08:31:27 +00:00
3822b4a21b test: add fresh_version_check test (#3029)
add a test file to auto check the fresh_version, based on deno.json
--version.

Close #3024 

---------

Co-authored-by: 李嘉图·M·路 <146103794+Ricardo-M-Zheng@users.noreply.github.com>
Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2026-03-26 08:20:01 +00:00
Marvin HagemeisterandBartek Iwańczuk 882b7829fd feat: expose HttpError for clients (#3080)
This PR exposes the `HttpError` class for clients. 

To do that I needed to make the error message optional to avoid bloating
up the bundle with lots of status strings.

Fixes https://github.com/denoland/fresh/issues/2995

---------

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2026-03-26 09:10:21 +01:00
0fff2b04da chore: minor code cleanups (#3103)
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 09:01:34 +01:00
022835cce6 perf: make updater faster by streaming instead of reading into memory (#3630)
Fix system crash (OOM) caused by updater spending time in folders like
docs/

- Skip hidden and vendor directories (node_modules, vendor, docs, etc.)
to avoid OOM
- free ASTs immediately
- ts-morph dependency bumped to ^27.0.2

Closes https://github.com/denoland/fresh/issues/3483

---------

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-25 20:01:01 +01:00
c863097779 fix: handle paths with whitespaces in staticFiles (#3659)
Fix #3657

Static files with special characters in their names (spaces, `#`,
unicode, etc.) fail to load due to path encoding issues.

## Root cause

`prepareStaticFile()` uses `new URL(pathname, base)` to normalize paths,
but `new URL` doesn't properly encode characters that are already
percent-encoded in the filesystem path. For example, a file literally
named `test %20encodeUri` becomes `test%20%20encodeUri` (the space and
literal `%20` are indistinguishable), instead of the correct
`test%20%2520encodeUri`.

---------

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-25 20:00:48 +01:00
421e3394a2 fix(vite): use manifest entry filename for server entry import (#3595)
## Summary
When `rollupOptions.output.entryFileNames` is customized in vite config
(e.g. `[hash].mjs`), the generated `server.js` was hardcoding
`server-entry.mjs` as the import path, causing the server to fail to
start.

This fix reads the actual entry filename from the Vite manifest and uses
it in the generated `server.js` import, falling back to
`server-entry.mjs` when no custom naming is configured.

---------

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-25 18:47:02 +00:00
cdc14a0c6e Do not assign named exports into existing default export (#3494)
Fixes: https://github.com/denoland/fresh/issues/3492

---------

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-25 19:40:46 +01:00
Marvin Hagemeister 4cc76aefed chore: release 2.2.1 (#3678) 2026-02-11 14:38:24 +01:00
Marvin Hagemeister 3d8091602c fix: .well-known static folder not working (#3676)
This folder is typically used for site metadata like `security.txt` and
other stuff.
2026-02-11 14:19:33 +01:00
Marvin Hagemeister 89ddbc4f4b chore: update preact version (#3664) 2026-01-07 14:17:59 +01:00
Eli ab14d1044c refactor(vite): replace old environment APIs (#3634)
I was perusing the code whilst investigating #3606 and noticed that,
despite the release post claiming that Fresh had ["fully
embrace[d]"](https://deno.com/blog/fresh-and-vite#:~:text=fully%20embraces)
the Vite Environment API, it was still using `ssrLoadModule`. Once I
started looking, I noticed a bunch of other code that wasn't
future-proof (env-wise, not rolldown-wise, which'll bring it's own swath
of deprecations[^1]), so I updated them as well.

The newly added source map tests from #3624 currently fail again because
the ModuleRunner API at the heart of the Environment API relies on
[`process.setSourceMapsEnabled`](https://docs.deno.com/api/node/process/~/Process.setSourceMapsEnabled),
which is [currently set to
no-op](https://github.com/denoland/deno/pull/22993) in Deno.

[^1]: Separately tried to try out rolldown-vite but it seems that Deno
doesn't support aliasing dependencies whatsoever? (I know there's not
official support, but I was going to try to edit the lockfile to hack
around it; however, it seems that there's not alias support in there at
all?)
2025-12-09 13:00:36 +01:00
eryue0220 0acebce0bb fix: update type & imports (#3638)
This pr is small fixed that update type declaration and import from
codebase.
2025-11-25 09:43:51 +01:00
David Sherret 18e47a86b0 fix(vite): force at least @deno/loader@0.3.10 (#3631)
Ref: https://github.com/denoland/deno-js-loader/pull/68
2025-11-19 23:05:45 +01:00
Marvin Hagemeister 2c36becff0 chore: release 2.2.0 (#3627)
- `@fresh/core@2.2.0`
- `@fresh/update@2.2.0`
- `@fresh/init@2.3.0`
- `@fresh/plugin-vite@1.0.8`
2025-11-18 14:09:19 +01:00
Marvin Hagemeister f5c0f16878 fix(vite): source mapping locations (#3624)
Mappings were wrong for a few reasons:
- Missing source map generation in one babel transform
- setting `compact: false` causes vite to generate incorrect mappings in
`vite:import-analysis`
- stack traces need to be mapped by vite

Fixes https://github.com/denoland/fresh/issues/3609
2025-11-18 11:40:52 +01:00
时瑶andAyaka 399dde767b feat(init): use recommended vscode settings for tailwind (#3621)
The recommended way to configure custom directives from Tailwind is to
use `files.associations`.

Check recommended settings from Tailwind CSS IntelliSense Extension:
https://github.com/tailwindlabs/tailwindcss-intellisense#recommended-vs-code-settings

This allows us to stop maintaining future changes to custom directives
from TailwindCSS, instead letting the TailwindCSS extension decide how
to handle them.

Co-authored-by: Ayaka <KiritaniAyaka@users.noreply.github.com>
2025-11-17 10:46:10 +01:00
Marvin Hagemeister 8de5b15799 feat: add .json()/.text()/.html()/.stream() context helpers (#3613)
Played around with Hono in the past days and the
`.text()/.json()/.html()` helpers are kinda neat, even if you can always
construct that yourself manually. Also added a `.stream()` helper to
create streams without having to deal with `ReadableStream` and
encodings yourself.
2025-11-11 17:25:02 +01:00
Christian Svensson fd7ecec5fa docs(core): add small usage & getting started example (#3598)
This PR just fills out the `README.md` with minimal usage example, such
that they can get a small taste of how the framework can be used. This
also helps improve the score in JSR.

Part of #3597
2025-11-11 15:34:22 +01:00
Christian Svensson 23734a00b2 docs(core): improve CORS example documentation on JSR (#3602)
Improves clarity of CORS JSDoc example for JSR:

<img width="1088" height="706" alt="image"
src="https://github.com/user-attachments/assets/8ea3b6f9-a5ee-41cc-9512-a3a0fb87a4c0"
/>

## Changes

- Split the example into two: Basic & Advances
- Uncomment "Advanced" example
2025-11-11 15:33:54 +01:00
Christian Svensson 6a1ce911d0 docs(examples): add module and public exports JSDoc for all entrypoints (#3603)
Addresses scoring of `@fresh/examples` of JSR for several metrics:

- ✅ Adds module doc for all entrypoints
- ✅ Adds descriptions to all public exports for `@fresh/examples` (0% ->
100%)

I could not find if `@fresh/examples` are part of any E2E tests to test
using JSR package as mounted app or Island, or if this is just a small
demo for users. So I just added small generic drescriptions.

Part of #3597
2025-11-11 15:33:28 +01:00
Christian Svensson 1dd8279075 docs(vite): add JSDoc and export public API (#3604)
Improves documentation of `@fresh/plugin-vite` related to public API,
and exports missing symbols/types that are part of public API
(`FreshViteConfig`).

- Adds `@module` JSDoc for the `@fresh/plugin-vite/client` entrypoint
  - Internal only, used for browser HMR
- Exports types `ImportCheck` & `ImportCheckDiagnostic`, as they are
part of the public API via `FreshViteConfig`
- Should make [`ImportCheck` link to correct
type](https://jsr.io/@fresh/plugin-vite/doc/~/FreshViteConfig#property_checkimports):
<img width="1053" height="285" alt="image"
src="https://github.com/user-attachments/assets/766c29f7-7f39-429e-bd81-234fed6b0820"
/>
- Adds JSDoc descriptions for all public exports; `fresh`,
`FreshViteConfig`, `ImportCheck` & `ImportCheckDiagnostic`
- Adds description for `FreshViteConfig.checkImports`

Part of #3597 & #3596
2025-11-11 15:33:03 +01:00
Christian Svensson ffa845ab0d docs(core): correct example code block formatting (#3601)
The example for the CSP middleware looks a bit broken currently on JSR,
due to the `@example` markdown is not wrapped in a code block.

<img width="1136" height="247" alt="image"
src="https://github.com/user-attachments/assets/57888033-aa9e-4701-87dc-4f4810365177"
/>

## Changes

- Improves formatting a bit, to be less compact
- Wraps the example in a code block ` ```ts `
- Adds a title to the `@example` - "Basic usage" - To avoid the example
being labeled as "Example1" on JSR
2025-11-04 16:03:51 +01:00
Christian Svensson a801686e9c docs(build-id): add code block example (#3600)
Adds a module doc and code block to help satisfy JSR's scoring.
Suggestions for alternatives or improvements very welcome.

Part of #3597
2025-11-04 16:02:53 +01:00
Marvin Hagemeister 42d7d9f23b chore: release 2.1.4 (#3586)
- @fresh/core@2.1.4
- @fresh/update@2.1.4
- @fresh/init@2.2.2
- @fresh/plugin-vite@1.0.7
2025-10-30 15:57:14 +01:00
Marvin Hagemeister 68e70858aa chore: improve init tests (#3590) 2025-10-30 15:49:02 +01:00
Marvin Hagemeister 5a220c6eea chore: tests add more logs for easier debugging (#3589) 2025-10-30 15:14:15 +01:00
Marvin Hagemeister 7fcae1d895 fix: HEAD when only GET is registered in .route() (#3587) 2025-10-30 14:59:12 +01:00
PastelStoic c7af11eb7c fix(vite): inherit top level outDir configuration for builds (#3570)
The Vite outDir setting is confusingly ignored, which is not documented
in the plugin documentation. This corrects that, while still preferring
the more specific environment settings.
2025-10-30 14:55:29 +01:00
Marvin Hagemeister 5e94dfe9fd fix: switch to nodeModulesDir: "manual" (#3588)
The `"auto"` value causes all kinds of race conditions between various
processes trying to auto install their view of dependencies.
2025-10-30 14:50:49 +01:00
Marvin Hagemeister 7db37d7ba1 fix(partial): buttons outside forms should not trigger navigation (#3584)
`<button>` elements that are not inside a form and have a `f-partial`
attribute should not trigger a history change.
2025-10-29 17:49:19 +01:00
Marvin Hagemeister 7b6d6315d1 fix(vite): mark transformed cjs with __esModule (#3575)
Fixes https://github.com/denoland/fresh/issues/3565
2025-10-24 19:54:37 +02:00
Marvin Hagemeister 5a228625ea chore: release 2.1.3 (#3572)
- @fresh/core@2.1.3
- @fresh/update@2.1.2
- @fresh/plugin-vite@1.0.6
- @fresh/init@2.2.1
2025-10-23 13:15:07 +02:00
Marvin Hagemeister 3681fb1c84 fix: .fsRoutes() pattern argument not working (#3571)
Fixes https://github.com/denoland/fresh/issues/3566
2025-10-23 13:05:11 +02:00
PastelStoic 07f74ffa4a fix: link to Fresh documentation in README (#3569) 2025-10-23 12:29:49 +02:00
Marvin Hagemeister 41b9422dd1 fix: HEAD method not handled properly (#3563)
- It should never contain a response body
- It should be equivalent to `GET`
2025-10-21 15:43:17 +02:00
Brett Chalupa de1810e70d fix(vite): exclude test files from production builds (#3559)
The Vite plugin was not filtering out test files from route discovery,
causing test files in routes/ (e.g., routes/api/counter_test.ts) to be
bundled into production builds, inflating bundle sizes by ~20KB per test
file and including unnecessary test dependencies.

Root cause: Vite plugin defaulted ignore patterns to [] while Builder
correctly defaults to [TEST_FILE_PATTERN].

This fix:

- Defines TEST_FILE_PATTERN in shared constants.ts for reusability
- Exports TEST_FILE_PATTERN from internals_dev.ts for Vite plugin access
- Updates Vite plugin default from [] to [TEST_FILE_PATTERN]
- Updates Builder to import TEST_FILE_PATTERN from constants.ts
- Ensures test files matching /[._]test\.(?:[tj]sx?|[mc][tj]s)$/ are
excluded
- Adds integration test to prevent regression
- Allows Deno best practice of colocating test files without bundling
them

Test coverage (prevents regression):

- Unit test: walkDir respects skip patterns
- Unit test: crawlRouteDir excludes test files
- Integration test: Vite builds exclude test files from output

Fixes #3558
2025-10-21 11:26:20 +02:00
Brett Chalupa 662f795ae8 feat: add @/ path alias to generated projects (#3562)
Sets up `@/` as the default path alias in newly generated Fresh
projects, following the official Deno documentation guidelines. This
allows developers to use `@/` for absolute imports from the project root
instead of relative paths. This is especially convenient to remove
import that require deeply traversing up the directory tree.

The `@/` alias is now included in the imports section of deno.json for
all new projects, enabling cleaner import statements like:

```
import { Button } from "@/components/Button.tsx";
```

Fixes #3485
2025-10-21 11:24:36 +02:00
Brett Chalupa 34aa46aa35 fix: disable static file caching in development (#3561)
When running Fresh 2 in development, the ETag caching was leading to
incorrect assets being served. I'd often get stale assets from days ago
or separate apps. This problem was especially bad with multiple apps
that run on the same port. For example, I may work on App A on the
default port 5173. Then boot up App B. I'd get assets from App A when I
wouldn't want them, leading to a frustrating dev experience.
2025-10-21 11:24:22 +02:00
Marvin Hagemeister 8b7caba444 chore: release 2.1.2 (#3542)
- @fresh/core@2.1.2
- @fresh/update@2.1.2
- @fresh/plugin-vite@1.0.5
2025-10-08 12:56:08 +02:00
Marvin Hagemeister efef51714b fix(vite): unable to load transpiled commonjs with node builtins (#3541) 2025-10-08 12:47:04 +02:00
Marvin Hagemeister 4b069ee0d0 fix(vite): empty commonjs files with only __esModule (#3540)
When modules only contain the `__esModule` flag, we still need to add
the `exports` and `module.exports` initializers.
2025-10-08 11:50:34 +02:00
Marvin Hagemeister 6c03a9bc26 fix(vite): support jsx namespaces (#3539)
Babel throws when encountering jsx namespaces by default. It needs a
setting to not throw.
2025-10-08 11:30:07 +02:00
fry69 88de90704e test(init): fix address in use (#3532)
Reverting back to the old init script also re-introduced the "address in
use" problem.

This does not have any effect: `env: { PORT: "0" }`

Adding arguments to `deno task start` also have no effect.

The only solution I can come up with is to ignore the task and call
`deno serve` with proper arguments directly for the build tests.
2025-10-07 10:34:10 +02:00
Marvin Hagemeister 026889dbc2 chore: release @fresh/init@2.1.1 (#3531) 2025-10-06 17:58:32 +02:00
Marvin Hagemeister 41fba500de fix(init): revert init template to make init work again (#3530)
https://github.com/denoland/fresh/pull/3524 unfortunately introduced a
regression in the init script which breaks it. This was caused by two
independent problems:

1. Only files reachable in the module graph are published, meaning the
templates itself weren't published to JSR
2. When publishing to JSR all specifiers become `https://` internally
which breaks doing path operations like `path.resolve()`,
`path.relative()` and all others. This is something that cannot be
tested locally in advance

Addressing these is going to require a bit of work. The quickest way to
get init working again is to revert it.
2025-10-06 17:48:25 +02:00
fry69 b3c91bd008 chore: fix use free port in builder globals test (#3529)
Fix "port in use" problem re-introduced in builder globals test.
2025-10-06 07:54:44 +00:00
Marvin Hagemeister 909c2b3280 chore: remove old tests (#3528)
Not needed anymore
2025-10-06 09:31:36 +02:00
Marvin Hagemeister cc9946d105 chore: remove old tests (#3527) 2025-10-06 09:29:28 +02:00
fry69 198816b042 feat(init): template based init script (#3524)
Supersedes earlier attempt ->
https://github.com/denoland/fresh/pull/3517

This is now ready for review.

The major upside and motivation for this template based approach is that
it is now possible to view what gets generated in the repository as
actual valid files including syntax highlighting and formatting.

Previously those files where just strings inside the old `init` script,
which is IMHO a nightmare for maintainability.

The approach for this template system is loosely based on Vite's
`create-vite`, which also includes (redundant) templates inside the
repository, see here ->
https://github.com/vitejs/vite/tree/main/packages/create-vite

Included in the tests are compatibility checks against the current
`@fresh/init@2.0.9`, those can get removed at a later point when the
templates start to diverge. They are only included for demonstration
purposes, that this new implementation generates 100% identical output.

This means that the first PR after this got included, which modifies the
templates so the output differs from the old `init` script, also needs
to include:
```shell
rm packages/init/tests/compatibility_test.ts
```

Since this is a rather large PR, it may be more approachable to view the
branch directly ->
https://github.com/fry69/fresh/tree/fry69/refactor-init-template-rename/packages/init

Generated PR message below:

---

Replaces inline string-based project generation with file-based
templates for improved maintainability and extensibility.

### Architecture

**Template structure:**
- `assets/template/` - Complete project templates (vite, vite-tailwind,
builder, builder-tailwind)
- `assets/variants/` - Additive overlays (docker, vscode,
vscode-tailwind)
- `assets/base/` - Common files synced across template variants

Templates use `__VARIABLE__` syntax for substitution (project name,
dependency versions). Files with `__` prefix are renamed to `.` prefix
during generation (e.g., `__gitignore` → .gitignore).

**Template selection logic:**
```
Base: vite|vite-tailwind|builder|builder-tailwind
Variants: +docker, +vscode, +vscode-tailwind
```

### Maintenance workflow

Edit shared files in `assets/base/vite/` or `assets/base/builder/`, then
run `deno task sync` to propagate changes to template variants.
Template-specific files (deno.json, vite.config.ts, styles.css) are
never overwritten.

### Version resolution

Matches existing behavior: only Fresh core version is fetched from JSR,
all other dependencies use fixed versions updated by release scripts.

### Testing

55 tests covering:
- Unit tests for core functionality
- Integration tests (project generation, builds, dev servers)
- CLI argument parsing
- Compatibility tests verifying output matches v2.0.9 (pre-refactor
baseline)
- Template sync workflow

### Breaking changes

None. CLI interface and programmatic API remain identical. Package
publishes to same `@fresh/init` scope at JSR.

### Documentation

- README.md - User-facing usage documentation
- DESIGN.md - Maintainer documentation (architecture, template
maintenance, development setup)
2025-10-06 09:12:07 +02:00