## Summary
- `staticDir` now accepts `string | string[]` in both the **Vite
plugin** (`FreshViteConfig`) and the **Builder API** (`BuildOptions`)
- When multiple directories are specified, they are searched in order
and the first match wins
- **Vite plugin**: first dir maps to Vite's native `publicDir`; extra
dirs are served manually in the dev server and walked during production
builds
- **Builder API**: both `MemoryBuildCache` (dev) and `DiskBuildCache`
(prod) iterate over all directories
- Updated tailwind v3 plugin to use `config.root` instead of
`path.dirname(config.staticDir)`
- Docs updated: `static-files.md`, `vite.md`, `builder.md`
Closes#3105
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
## Summary
Fixes several issues in the Fresh Vite plugin's CommonJS-to-ESM Babel
transform (`commonjs.ts`) that caused npm packages to break during
builds while working fine in dev mode.
- **Fix `.mts`/`.cts` extension detection** — `.cts` was incorrectly in
the ESM branch (should be `.mts`), causing TypeScript CJS files to skip
the transform
- **Handle `require.resolve()`** — injects
`createRequire(import.meta.url)` polyfill so `require.resolve()` calls
work in ESM output (#3619)
- **Polyfill `__dirname`/`__filename`** — injects
`fileURLToPath`/`dirname` based polyfill when these CJS globals are used
- **Use `var` instead of `let` for `_default`** — avoids TDZ errors when
Rollup reorders declarations in bundled output (#3653)
- **Track `module.exports.X` as named exports** — the MemberExpression
visitor now handles both `exports.X` and `module.exports.X` patterns
Addresses: #3619, #3653
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
## Summary
Three targeted fixes to Fresh's Vite plugin for better module
resolution, plus new test coverage.
### 1. Workspace import map resolution
Pass the importer's file URL to `loader.resolve()` so bare specifiers
from workspace member packages resolve through the correct import map —
not just the root `deno.json`.
Fixes#3654
### 2. Remote island resolution
Use `this.resolve(spec)` in the `fresh-island::` and
`fresh-client-island::` resolveId handlers (`server_snapshot.ts` /
`client_snapshot.ts`) so JSR remote islands get proper `\0deno::`
specifiers. Without this, remote islands resolved to bare specifiers
that Vite couldn't load.
Fixes#3437
### 3. Babel JSX operator precedence fix
`!ssr && id.endsWith(".tsx") || id.endsWith(".jsx")` → `!ssr &&
(id.endsWith(".tsx") || id.endsWith(".jsx"))`. The missing parentheses
caused `.jsx` files to incorrectly get Preact JSX transforms during SSR.
### Other changes
- Bump `@deno/loader` from ^0.3.10 to ^0.4.0 (needed for workspace
resolution fix)
- Bump `@astral/astral` from ^0.5.5 to ^0.5.6 (fixes `@std/async@1.2.0`
compat)
- Add dev server tests for CJS module import and maxmind CJS (#3653)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
## Summary
- Adds an `integrationTest()` wrapper in
`packages/fresh/src/test_utils.ts` that calls `Deno.test` with
`sanitizeOps: false` and `sanitizeResources: false`
- Converts ~88 integration tests across 5 files to use the new helper,
removing repetitive sanitizer boilerplate
- Net reduction of ~344 lines (-1678/+1334)
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
In many places, Fresh marketing claims the framework ships no JS by
default, **this was false**.
This PR reworks core parts of the framework to check whether JS is
needed on the client with these criteria:
1. Use of islands
2. Use of Partials (`f-client-nav`)
If either of those those criteria are met, JavaScript will be loaded as
normal, but if both are false, then the `client-entry` script is omitted
from the page.
Fixes https://github.com/denoland/fresh/issues/3662
---------
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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>
## 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>
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
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 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
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.
This PR makes nested islands work. Problem was that only entry files
have the `src` property in the vite manifest. For that we need to ensure
that every island is an entry point.
Fixes https://github.com/denoland/fresh/issues/3439
Detect if a file is ESM based on file extension or finding ESM-only
statements. When we know that it's an ESM file we should keep
`require()` calls as is, because some libraries use it as a conditional
check like `npm:motion`.
Fixes https://github.com/denoland/fresh/issues/3429
When disabling `node_modules` directory in Deno, prefresh plugin
transforms files in ~/.cache/deno/npm/registry.npmjs.org/ directory,
causing an arcane error to occur:
https://github.com/preactjs/prefresh/issues/124
After disabling this transform my site now works on updated fresh
version
I'm not sure if is the correct way to exclude this, but I don't see any
longer pattern that would work here
The cache is stored in $XDG_CACHE_HOME/deno/npm/$REGISTRY_HOST, where
only deno/npm part seems to be static
---------
Co-authored-by: Marvin Hagemeister <marvin@deno.com>