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
```
Hello there,
Thought I would add my hobby project to the showcase, since it was built
with Fresh 1.0 and now ported to 2.0 (beta). Here's the link: [Retro
Ranker](https://retroranker.site) and the
[github](https://github.com/Nergy101/retro-ranker)
- [x] Ran `deno task ok` and passed.
If I missed anything, let me know.
Cheers!
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 adds a short blurb how to install the VS Code extension to the
troubleshooting guide.
Possible concerns:
- maybe redundant as there are already official VS Code Deno docs
- could be shortened to just refer to the main docs or completely
removed
The current version of the README is misleading, because:
1. The build instructions result in a Fresh v1.0 project.
2. Since Fresh v2.0, Fresh no longer does JIT rendering on the edge.
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>