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?)
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
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.
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
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
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
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
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.
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
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
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.
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.
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.
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)
This fixes issues I have with running tests on one of my servers, where
port 8000 on `localhost` is occupied.
Note: The current `init` test will continue to fail, but that will
hopefully get replaced by #3524 which does not have this problem.
Before:
```
[
"error: Uncaught (in promise) AddrInUse: Address already in use (os error 98)",
" at listen (ext:deno_net/01_net.js:594:35)",
" at serveInner (ext:deno_http/00_serve.ts:675:16)",
" at Object.serve (ext:deno_http/00_serve.ts:591:10)",
" at ext:deno_http/00_serve.ts:819:10",
" at ext:runtime_main/js/99_main.js:708:13",
" at eventLoopTick (ext:core/01_core.js:179:7)"
]
[...]
Builder - write prod routePattern => ./packages/fresh/src/dev/builder_test.ts:284:6
Builder - file:// islands => ./packages/fresh/src/dev/builder_test.ts:319:6
Builder - serves static files in subdir in prod => ./packages/fresh/src/dev/builder_test.ts:474:6
init - can start built project => ./packages/init/src/init_test.ts:237:6
FAILED | 471 passed (14 steps) | 4 failed | 18 ignored
```
After:
```
ok | 475 passed (14 steps) | 0 failed | 18 ignored
```
fix#3521
Generated PR message below
---
## Problem
Island files named after JavaScript global objects (e.g., Map.tsx,
`Set.tsx`, `Array.tsx`, `Promise.tsx`) cause runtime errors. The
generated boot code uses object shorthand syntax that resolves to the
global constructor instead of the imported component:
```javascript
import Map from "/islands/Map.tsx";
boot({Map}, props); // {Map} resolves to global Map constructor
```
This results in `TypeError: Map is not a constructor` when the runtime
attempts to instantiate islands.
## Solution
Generate safe prefixed variable names (`__FRSH_ISLAND_N`) for island
imports and use explicit object property syntax to preserve the original
island names:
```javascript
import __FRSH_ISLAND_0 from "/islands/Map.tsx";
boot({"Map":__FRSH_ISLAND_0}, props);
```
This approach:
- Eliminates variable shadowing in all contexts (no scope collisions)
- Preserves original island names in HTML markers, error messages, and
runtime registry
- Allows any valid filename without restrictions
- Follows existing Fresh conventions for generated identifiers
## Changes
- preact_hooks.ts: Updated client-side boot script generation
- dev_build_cache.ts: Updated server-side snapshot generation
- Added integration tests for both Builder and Vite build systems
- Added documentation comment explaining why globals aren't in
`JS_RESERVED`
## Testing
Both tests verify that islands named after globals build successfully
and use safe variable names in generated code. Tests confirm the bug is
detected when fixes are reverted.