## 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.
Closes https://github.com/denoland/fresh/issues/3794
Fixes a regression from #3767 where CJS npm packages fail with `exports
is not defined` in dev mode.
- The old heuristic (`code.includes("export ")`) was fooled by the word
"export" appearing in comments of CJS files — e.g. `@opentelemetry/api`
has `// TODO: Remove ProxyTracerProvider export in the next major
version.` which caused the CJS shim to be skipped entirely
- Replaces the naive string check with two-layer detection:
1. **Package.json `type` field** (Node.js semantics): `.cjs` → always
CJS, `.js` → CJS unless nearest `package.json` has `"type": "module"`.
Results cached per directory.
2. **ESM statement regex fallback**: for dual CJS/ESM packages that ship
ESM in `.js` without `"type": "module"` (e.g. `@opentelemetry/api`,
`preact-render-to-string`), detects actual ESM syntax including minified
forms like `import{` and `export*from`
- Adds a test importing from a real CJS npm package (`qs`) in
`node_modules` — the existing "CJS test" fixtures were local ESM files
that never exercised the shim path
Islands used in `_app.tsx`, `_layout.tsx`, or `_error.tsx` are
discovered after `<head>` has already rendered, so their CSS `<link>`
tags were never injected. `FreshScripts` (at end of `<body>`) now emits
late CSS for any islands missed by `RemainingHead`, using an
`injectedCss` set to avoid duplicates.
In dev mode, `collectCss` only walked the `fresh:client-entry` module
graph, missing CSS imported by island modules. The dev server now also
walks `fresh-island::*` module graphs when collecting CSS.
Note: late-injected `<link>` tags in `<body>` may cause a brief flash of
unstyled content — this is inherent to the problem since `<head>`
renders before `<body>` islands are discovered.
Closes#3633
---------
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>
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
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
We're having a growing number of packages in this repository. This PR
moves them into a `packages/` directory like it's commonly done in other
projects.