## Summary
Reverts two commits that broke CJS package handling in dev mode:
- Reverts #3793 (CJS detection regex fix)
- Reverts #3767 (removal of Babel CJS→ESM transform)
The simplified CJS shim introduced in #3767 has two fundamental issues:
1. **Detection**: the heuristic (`code.includes("export ")`) is fooled
by comments containing "export"
2. **Named exports**: the shim only provides `export default
module.exports`, so `import { trace } from "@opentelemetry/api"` returns
`undefined` (#3797)
The Babel-based transform handled both correctly. Bringing it back until
we can replace it with a proper solution using `deno_ast`'s CJS parser.
- Adds `deno publish --dry-run` step to CI (ubuntu, v2.x only)
- Catches lockfile mismatches and other publish issues in PRs before
they hit main
- Prevents the recurring problem of releases failing to publish after
merge
## Summary
- **Replace Babel env var transforms with Vite's native `define`** —
`process.env.FRESH_PUBLIC_*` and `import.meta.env.FRESH_PUBLIC_*` now
use Vite's built-in `define` config. `Deno.env.get()` calls use a
lightweight regex-based transform (~10 lines vs 78-line Babel plugin).
- **Remove the 960-line CJS→ESM Babel transform** — Instead of
transforming CJS to ESM via Babel, let Vite handle CJS packages
natively:
- **Build mode**: Rollup's `@rollup/plugin-commonjs` handles CJS (always
has, but was bypassed by `deno.ts` loading through `@deno/loader`)
- **Dev mode**: A ~30-line CJS shim wraps `node_modules` CJS files with
`module`/`exports`/`require` so Vite's SSR module runner can evaluate
them
- `deno.ts` no longer attaches `meta.deno` to file:// resolved paths —
Vite loads them from disk directly
- **Remove `noDiscovery: true`** — Vite's dependency optimizer can now
pre-bundle CJS packages for the client
- **Fix React compat aliasing** — Apply `resolve.alias` (react →
preact/compat) in `deno.ts` before `@deno/loader` resolution, so the
alias works even when packages are non-external in SSR
Net: **~2,050 lines deleted**, ~150 lines added.
Fixes#3619, fixes#3653, fixes#3505, fixes#3478, fixes#3449.
- Updates `deno.lock` to resolve preact 10.29.0 → 10.29.1, which is what
Deno canary resolves
- Fixes the publish workflow failing with `Aborting due to uncommitted
changes` on `deno.lock`
## 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
- Inlined the `$ga4` module (from
`https://raw.githubusercontent.com/denoland/ga4/main/mod.ts`) into
`www/utils/ga4.ts`
- Replaced old `deno.land/std` URL imports with `@std/http`
(`getCookies`, `STATUS_TEXT`)
- Inlined the trivial `snakeCase` helper (was from `deno.land/x/case`)
- Removed `$ga4` import map entry from `deno.json`
The ga4 package was never published to jsr or npm, so inlining was the
cleanest way to eliminate the last raw URL-based dependency.
## Summary
- **docsearch**: Replaced `esm.sh` URL with `npm:@docsearch/js@^3.5.2`.
Added a type cast workaround in `SearchButton.tsx` since Deno's type
checker treats this npm package as CJS (missing `"type": "module"`).
- **imagescript**: Replaced `deno.land/x` URL with
`jsr:@matmen/imagescript@^1.3.0`. Clean swap, no code changes needed.
These were legacy URL-based imports from before Deno had native `npm:`
and `jsr:` support.
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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>
## Summary
- Refresh `deno.lock` to pick up latest dependency resolutions (notably
preact 10.28.2 → 10.29.0, new `@deno/graph` and `@std/json` entries)
- Fix stale integrity hashes for `raw.githubusercontent.com` remote
specifiers (`check_docs.ts`, `utils.ts`) that point to branch HEAD
- Run `deno fmt` on `www/static/docsearch.css` and
`www/static/markdown.css`
- Remove `deploy.yml` workflow — Deno Deploy now uses its built-in
GitHub integration
---------
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?)
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)
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>