fix#3470
This adds a short blurb about `deno.json` focusing on imports.
Background: Without `npm:vite` and `jsr:@fresh/plugin-vite` installed it
can lead to confusing errors like this one:
```shell
$ deno task dev
vite: command not found
```
Which might lead to users install Vite globally, which is not needed
(and will not fix this problem).
The slugger was shared across all pages and it assumes each passed value
should be unqiue. Due to that it would append additional numbers to the
id value.
The `buildVite` function returns a disposable object which was not being
properly disposed of, leading to a resource leak warning in the test
suite.
This change wraps the tests in `www/main_test.ts` in an async function
and uses `await using` to ensure that the temporary directory created by
`buildVite` is cleaned up after the tests complete.
---------
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: Marvin Hagemeister <marvin@deno.com>
Co-authored-by: Emil Krebs <68400102+emilkrebs@users.noreply.github.com>
Co-authored-by: Marvin Hagemeister <hello@marvinh.dev>
This fixes the testing page in the docs for real this time.
Every test is hand checked now. Thanks to a certain button, which
appeared recently.
Optionally I can also split this page up in separate pages:
- Middlewars
- AppWrappers and Layouts
- Routing and Handlers
- SSR and Islands
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
The tests for the `init` package were failing with a `PermissionDenied`
error in Jules container environment when creating temporary
directories. This was because the tests were attempting to create the
temporary directories in the root of the project, where permissions are
often restricted.
This change corrects the issue by removing the local `withTmpDir` helper
function in `packages/init/src/init_test.ts` and instead using the one
from `../../fresh/src/test_utils.ts`. The shared helper function
correctly creates temporary directories in the operating system's
default temporary directory, which resolves the permission issue.
Sample error message from Jules before this fix:
```
ERRORS
init - new project => ./packages/init/src/init_test.ts:99:6
error: PermissionDenied: Permission denied (os error 13): tmpdir
const dir = await Deno.makeTempDir(options);
^
at Object.makeTempDir (ext:deno_fs/30_fs.js:168:10)
at withTmpDir (file:///app/packages/fresh/src/test_utils.ts:136:26)
at withTmpDir (file:///app/packages/init/src/init_test.ts:41:10)
at file:///app/packages/init/src/init_test.ts:100:27
init - create project dir => ./packages/init/src/init_test.ts:107:6
error: PermissionDenied: Permission denied (os error 13): tmpdir
const dir = await Deno.makeTempDir(options);
^
at async withTmpDir (file:///app/packages/fresh/src/test_utils.ts:136:15)
at async file:///app/packages/init/src/init_test.ts:108:21
init - with tailwind => ./packages/init/src/init_test.ts:122:6
error: PermissionDenied: Permission denied (os error 13): tmpdir
const dir = await Deno.makeTempDir(options);
^
at Object.makeTempDir (ext:deno_fs/30_fs.js:168:10)
at withTmpDir (file:///app/packages/fresh/src/test_utils.ts:136:26)
at withTmpDir (file:///app/packages/init/src/init_test.ts:41:10)
at file:///app/packages/init/src/init_test.ts:123:27
init - with vscode => ./packages/init/src/init_test.ts:140:6
error: PermissionDenied: Permission denied (os error 13): tmpdir
const dir = await Deno.makeTempDir(options);
^
at async withTmpDir (file:///app/packages/fresh/src/test_utils.ts:136:15)
at async file:///app/packages/init/src/init_test.ts:141:21
init - fmt, lint, and type check project => ./packages/init/src/init_test.ts:153:6
error: PermissionDenied: Permission denied (os error 13): tmpdir
const dir = await Deno.makeTempDir(options);
^
at async withTmpDir (file:///app/packages/fresh/src/test_utils.ts:136:15)
at async fn (file:///app/packages/init/src/init_test.ts:159:23)
init with tailwind - fmt, lint, and type check project => ./packages/init/src/init_test.ts:179:6
error: PermissionDenied: Permission denied (os error 13): tmpdir
const dir = await Deno.makeTempDir(options);
^
at async withTmpDir (file:///app/packages/fresh/src/test_utils.ts:136:15)
at async file:///app/packages/init/src/init_test.ts:182:23
init - can start dev server => ./packages/init/src/init_test.ts:205:6
error: PermissionDenied: Permission denied (os error 13): tmpdir
const dir = await Deno.makeTempDir(options);
^
at async withTmpDir (file:///app/packages/fresh/src/test_utils.ts:136:15)
at async fn (file:///app/packages/init/src/init_test.ts:211:23)
init - can start built project => ./packages/init/src/init_test.ts:233:6
error: PermissionDenied: Permission denied (os error 13): tmpdir
const dir = await Deno.makeTempDir(options);
^
at async withTmpDir (file:///app/packages/fresh/src/test_utils.ts:136:15)
at async file:///app/packages/init/src/init_test.ts:234:21
init - errors on missing build cache in prod => ./packages/init/src/init_test.ts:265:6
error: PermissionDenied: Permission denied (os error 13): tmpdir
const dir = await Deno.makeTempDir(options);
^
at Object.makeTempDir (ext:deno_fs/30_fs.js:168:10)
at withTmpDir (file:///app/packages/fresh/src/test_utils.ts:136:26)
at withTmpDir (file:///app/packages/init/src/init_test.ts:41:10)
at file:///app/packages/init/src/init_test.ts:266:27
init - with vite => ./packages/init/src/init_test.ts:348:6
error: PermissionDenied: Permission denied (os error 13): tmpdir
const dir = await Deno.makeTempDir(options);
^
at Object.makeTempDir (ext:deno_fs/30_fs.js:168:10)
at withTmpDir (file:///app/packages/fresh/src/test_utils.ts:136:26)
at withTmpDir (file:///app/packages/init/src/init_test.ts:41:10)
at file:///app/packages/init/src/init_test.ts:349:27
FAILURES
init - new project => ./packages/init/src/init_test.ts:99:6
init - create project dir => ./packages/init/src/init_test.ts:107:6
init - with tailwind => ./packages/init/src/init_test.ts:122:6
init - with vscode => ./packages/init/src/init_test.ts:140:6
init - fmt, lint, and type check project => ./packages/init/src/init_test.ts:153:6
init with tailwind - fmt, lint, and type check project => ./packages/init/src/init_test.ts:179:6
init - can start dev server => ./packages/init/src/init_test.ts:205:6
init - can start built project => ./packages/init/src/init_test.ts:233:6
init - errors on missing build cache in prod => ./packages/init/src/init_test.ts:265:6
init - with vite => ./packages/init/src/init_test.ts:348:6
FAILED | 449 passed (14 steps) | 10 failed | 17 ignored (2m38s)
```
---------
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
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>
Fix for mountApp() with the new basePath handling
---
Generated PR message:
I successfully investigated and implemented a fix for mountApp() to make
it compatible with basePath handling. Here's what I found and fixed:
The Problem
The original mountApp() implementation completely ignored the inner
app's basePath. When mounting an app like this:
```ts
const innerApp = new App({ basePath: "/api" })
.get("/users", () => new Response("users"));
const app = new App()
.mountApp("/v1", innerApp);
```
The route would become /v1/users instead of the expected /v1/api/users
because the inner app's /api basePath was lost.
Root Cause
The issue was in the mountApp() method at packages/fresh/src/app.ts:333.
The original code only used:
```ts
pattern: mergePath(path, cmd.pattern, true)
```
This only considered the mount path (/v1) and the command pattern
(/users), but ignored app.config.basePath (/api).
The Fix
I modified the mountApp() method to properly handle the inner app's
basePath:
```ts
// Apply the inner app's basePath if it exists
let effectivePattern = cmd.pattern;
if (app.config.basePath) {
effectivePattern = mergePath(app.config.basePath, cmd.pattern, false);
}
const clone = {
...cmd,
pattern: mergePath(path, effectivePattern, true),
includeLastSegment: cmd.pattern === "/" || cmd.includeLastSegment,
};
```
The key insight was to only apply the basePath transformation when the
inner app actually has a basePath (not empty), which preserves backward
compatibility with existing code that doesn't use basePath.
Test Coverage
I added comprehensive test cases covering:
1. Inner app with basePath: /v1 + /api basePath + /users route =
/v1/api/users
2. Main app with basePath + mounted app: /main basePath + /sub mount +
/data route = /main/sub/data
3. Both main and inner basePath: /main + /services + /api/v2 + /users =
/main/services/api/v2/users
Backward Compatibility
The fix maintains full backward compatibility:
- ✅ All existing mountApp() tests pass
- ✅ All existing basePath tests pass
- ✅ New functionality works as expected
Now the three basePath mechanisms work correctly together:
1. Vite base config → Static asset URLs
2. App basePath option → Route matching (now works with mountApp!)
3. External mounting → Framework integration
The solution correctly handles the scenario you described where
vite.config.ts, main.ts, and external mounting all work together
seamlessly.
I noticed that in denoland/fresh#3393 it looks like it's possible that
the "Copied"/Check icon will be shown even if copying to clipboard
fails.
This PR changes it so that the Check icon only shows if copy succeeds.
closes#3391
---
Generated PR message:
Fix base path handling for assets in plugin-vite
Fixes issue where Fresh apps mounted at non-root paths (e.g., /ui) in
frameworks like Hono would fail to load assets correctly.
Problem
When mounting a Fresh app with app.mount('/ui', UI.fetch), the HTML
would load but all assets (CSS, JS, images) would return 404 because
asset paths
were hardcoded to start with /assets/ instead of respecting the Vite
base configuration.
Solution
- Modified packages/plugin-vite/src/plugins/server_entry.ts to read
Vite's base config and apply it to asset paths
- Added getAssetPath() helper function to construct proper asset URLs
with base path
- Updated both CSS and asset file registration to use the base path
Testing
Added comprehensive test case "vite build - base path asset handling"
that:
- Builds demo with custom base path /my-app/
- Verifies generated server.js contains correctly prefixed asset paths
- Follows existing test patterns and utilities
Usage
Users can now properly mount Fresh apps by configuring both:
```ts
// vite.config.ts
export default defineConfig({
base: "/ui/",
plugins: [fresh()],
});
// main.ts
const app = new App({ basePath: "/ui" });
// hono-app.ts
app.mount('/ui', UI.fetch); // Assets now work correctly
```
Backward compatible - no changes needed for apps mounted at root path.