Commit Graph
48 Commits
Author SHA1 Message Date
Marvin Hagemeister 118242eaa6 major: build islands + scan routeDir without importing user code (#3122)
This fixes a bunch of long standing issues in our tracker where a build
wouldn't finish because of importing user code. It's common for backend
apps to spawn some open ended tasks like subscribing to Deno KV or other
things. This addresses another problem of having to set up ENV vars just
for the build, even though they are technically not required to build
islands.

This also gives a roughly ~30% performance boost on cold starts (at
least on `deno.com`). Unfortunately, this does require some breaking
changes. But I believe the performance improvements + removing the
footgun of loading user code during build is well worth it. This work is
also a precursor in case we want to exploring moving to vite at some
point in the future.

## Breaking changes

1. Build options have moved to the builder.
```diff
  // main.ts
- const app = new App({ build: { outDir: "dist/" } })
+ const app = new App()

  // dev.ts
- const builder = new Builder();
+ const builder = new Builder({ outDir: "dist/" });
```

2. Another breaking change is how file based routes are loaded. Since
they're prepared and loaded by the builder the API changed.

```diff
  // main.ts
  const app = new App()
    .use(staticFiles())
  
- await fsRoutes(app, {
-   loadIsland: (path) => import(`./islands/${path}`),
-   loadRoute: (path) => import(`./routes/${path}`),
- }); 
+ app.fsRoutes()
```
You can optionally change the `islandDir` or `routeDir` by passing that
to the `Builder`:

```ts
// dev.ts
const builder = new Builder({
  islandDir: "/path/to/islands", 
  routeDir: "/path/to/routes"
});
```

3. Import `app` lazily in `dev.ts`. Passing `app` to `builder.build()`
is not necessary anymore.

```diff
- import { app } from "./main.ts";

  const builder = new Builder({ target: "safari12" });
  
  if (Deno.args.includes("build")) {
-    await builder.build(app);
+    await builder.build();
  } else {
-   await builder.listen(app);
+   await builder.listen(() => import("./main.ts"));
  }
```

4. The production run command has changed. It's now using `deno serve`
```diff
  // deno.json
  {
    "tasks": {
      "dev": "deno run -A --watch=static/,routes/ dev.ts",
      "dev": "deno run -A dev.ts build",
-     "start": "deno run -A main.ts",
+     "start": "deno serve -A _fresh/server.js",
    }
  }
```
Remove this bit in `main.ts`:

```diff
  // main.ts
  
- if (import.meta.main) {
-   await app.listen()
- }
```

Fixes https://github.com/denoland/fresh/issues/2240
Fixes https://github.com/denoland/fresh/issues/2640
Fixes https://github.com/denoland/fresh/issues/2592
Fixes https://github.com/denoland/fresh/issues/1843
2025-07-24 15:04:05 +02:00
Marvin Hagemeister dbb76623a4 Revert "feat: update the tailwind plugin to suuport tailwindv4 #2819 (#2903)" (#2988)
Reverts tailwind v4 update. Something is wrong with the CSS files on
fresh.deno.dev 😢
2025-05-21 16:07:51 +02:00
40e7747228 feat: update the tailwind plugin to suuport tailwindv4 #2819 (#2903)
Inspired by #2819, #2829, and
https://github.com/pakornv/fresh-plugin-tailwindcss, I made minimal
modifications to the plugin-tailwind, I originally intended to update
based on #2829, but I was informed by the system that I couldn't push.

Due to the breaking changes in Tailwind v4, some PostCSS plugins are no
longer required. Additionally, I updated the syntax in the /www
directory. The /www directory now uses the updated plugin supported by
Tailwind v4.I think this has made initial progress.

# What This PR Solves
The Tailwind plugin has been updated to support Tailwind v4, and it is
currently functioning well both in the repository's www directory and in
the initialized project which for test.

## --patch-1

### 1. Dependency Optimization
- Removed `cssnano` dependency, using Tailwind v4's built-in
optimization(Based on @csvn 's suggestion)
- Removed `autoprefixer` dependency
- Updated `tailwind-plugin` version number
### 2. Build Configuration Adjustments
- Added `--node-modules-dir` parameter to `/www` task for Tailwind v4
support (Based on @marvinhagemeister 's suggestion)
- Added `--allow-scripts` parameter to enable `@tailwindcss/oxide`
execution
### 3. Code Adaptation
- Modified Tailwind-related code in `/www` to support Tailwind v4
- Updated dependency configuration in `deno.json`
### 4. Feature Restoration
- Added `imagescript` and `astral` dependencies to restore screenshot
functionality lost in previous PR updates
- Fixed the issue where the `tailwind-plugin` dependency was incorrectly
pointing to the JSR package instead of the local repository source code
in previous PR.

## --patch-2
- Upgraded Tailwind CSS to the latest version.
- Removed unnecessary dependencies.
- Enabled CSS minification by default when Fresh is in production mode.
- Updated docs/canary/examples/migration-guide.md to support the new
Tailwind plugin format.
- Updated init/src/init.ts to support the new Tailwind version and
plugin version, use new `@import "tailwindcss"`, and generate the new
plugin format.
- Updated init/src/init_test.ts: tests now expect `css` to match
`/tailwindcss/` instead of `/@tailwind/`.
- Removed plugin-tailwindcss/src/types.ts as it is no longer needed, and
updated plugin-tailwindcss/src/mod.ts and www/dev.ts to support the new
format.

Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>

## --patch-3
Addressing @marvinhagemeister feedback, this patch reverts the
unintended loss of PR #2960's changes caused by merge conflicts.

## --patch-4

I initialized a project according to the migration documentation and
used @fresh/update to test whether the plugin works properly with
v2-alpha-34. The results show that it works fine.

- The plugin is published at
jsr:@freshpress/fresh-plugin-tailwind@0.0.1-alpha.8.

- The test project is published at
https://github.com/SisyphusZheng/fresh-project-test/tree/main/fresh-project.

# How Testing Was Conducted

## Local Environment Testing
1. Environment Cleanup
```bash
rm -rf ./.cache/deno deno.lock node_modules
```

2. Test Execution
```bash
deno task www
```

3. Result Verification
- Checked functionality in local `/www` environment
- Confirmed all features working properly

## Code Inspection
- Passed `deno task ok` check

## This forked /www website is hosted and running on GitHub Codespaces,
with support for the latest code changes. You can check it out at:
https://silver-trout-pjr4jw7xx5x9299x6-8000.app.github.dev/

---------

Co-authored-by: 李嘉图·M·路 <146103794+Ricardo-M-Zheng@users.noreply.github.com>
Co-authored-by: deno-deploy[bot] <75045203+deno-deploy[bot]@users.noreply.github.com>
Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
Co-authored-by: Marvin Hagemeister <marvin@deno.com>
2025-05-21 16:01:57 +02:00
Asher Gomez 3776ef3154 refactor: centralise imports and cleanup exports (#2900)
The benefits of these changes are:
1. Managing and updating dependencies is easier. One only needs to run
`deno outdated` at the root, instead of in each workspace.
2. The versions of dependencies across workspaces is kept consistent.

Closes #2788
2025-05-19 09:41:06 +02:00
Marvin Hagemeister 6ff0becd0a fix: duplicate @preact/signals version (#2964)
We initialized new projects with `@preact/signals@2.x` but Fresh itself
was using `1.x`. There shall only ever be one version.

Kinda makes me wish Deno had some sort of `peerDependencies`.

Fixes https://github.com/denoland/fresh/issues/2962
2025-05-16 21:23:53 +02:00
d68b5ecd5b refactor: replace puppeteer with astral for screenshot and close #2919 (#2920)
due to resolves the `NotFound: No such file or directory` error in the
`www/utils/screenshot.ts` script, which was caused by improper file path
construction. This error prevented screenshots from being saved
correctly. close #2919

-- update --patch1
## Current Status
- Using npm:puppeteer for webpage screenshots
- npm lifecycle script warnings present
- deno-puppeteer is no longer maintained
- npm:puppeteer still has compatibility issues

## References
- [astral](https://github.com/lino-levan/astral): Browser automation
library designed for Deno
-
[deno-puppeteer#92](https://github.com/lucacasonato/deno-puppeteer/issues/92):
Recent discussion about deno-puppeteer

## Changes Made
1. Dependency Replacement
   - Replaced npm:puppeteer with jsr:@astral/astral
   - Removed npm lifecycle script warnings

2. Dependency Management Optimization
   - Centralized all imports in deno.json
   - Using jsr: and URL imports

## Testing Steps
1. Run screenshot command:
```bash
deno task screenshot https://google.com google
```

2. Check output:
   - Verify no npm warnings
   - Validate generated image files:
     - ./www/static/showcase/google2x.jpg
     - ./www/static/showcase/google1x.jpg
   - Confirm image quality

3. Run complete test suite:
```bash
deno task ok
```
- Ensure all tests pass

4. Verify functionality:
   - Screenshot feature works correctly
   - Image processing (2x/1x) functions properly

---------

Co-authored-by: 李嘉图·M·路 <146103794+Ricardo-M-Zheng@users.noreply.github.com>
Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
2025-05-12 20:02:15 +02:00
Luca Casonato 03847e9a33 2.0.0-alpha.26 2024-12-10 16:05:22 +01:00
Luca Casonato 65d61bd1d5 feat: add open telemetry instrumentation (#2786)
This commit adds some useful automatic instrumentation for when users
are using `--unstable-otel`:

- Fresh renames the span for incoming HTTP requests to `$METHOD $ROUTE`
and the `http.route` attribute is added.
- Fresh creates a span around FS route handlers, showing whether they
returned a response or data.
- Fresh creates a span around async components, showing how long they
took to execute.
- Fresh adds a span around preact rendering, showing how long rendering
takes.
- Fresh adds a span around static file serving, showing how long it took
and whether there were requests without a cache bust key.

We can improve this in the future with more telemetry, such as metrics.
2024-12-10 15:03:50 +01:00
Luca Casonato 4a25ac385f refactor: make this repo a Deno workspace (#2719) 2024-12-10 13:41:18 +01:00
Luca CasonatoandMarvin Hagemeister 407987589f feat: support fresh projects that are part of a workspace (#2716)
Also a performance improvement & bug fix in the tailwind plugin.

---------

Co-authored-by: Marvin Hagemeister <marvin@deno.com>
2024-10-17 17:08:24 +02:00
Marvin Hagemeister 1081aa2eb9 fix: docs markdown smartypants (#2671)
This was a regression introduced in
https://github.com/denoland/fresh/pull/2655

Fixes https://github.com/denoland/fresh/issues/2670
2024-10-02 11:43:47 +02:00
Marvin HagemeisterandLuca Casonato de8f1b0c59 feat: update for Deno 2 (#2655)
Co-authored-by: Luca Casonato <hello@lcas.dev>
2024-09-30 18:30:30 +02:00
Marvin Hagemeister 6be6435467 fix: missing dom root frag polyfill after preact update (#2569) 2024-07-03 10:39:33 +02:00
Marvin Hagemeister a79e797245 chore: remove $std alias (#2548) 2024-06-26 11:21:11 +02:00
Luca Casonato c3ec742a65 feat: import fresh from fresh (#2479)
Instead of importing as `@fresh/core`.
2024-06-05 14:51:35 +02:00
Luca Casonato aa19b393e7 feat: export compat types from /compat export (#2478) 2024-06-03 14:32:38 +00:00
Luca Casonato dc283a137b fix: remove @fresh/core/client export (#2477)
These files are now referenced with https URLs.
2024-05-29 12:20:57 +02:00
Marvin Hagemeister 8865d290ce www: switch to precompile jsx (#2469) 2024-05-25 13:31:12 +02:00
Marvin Hagemeister 287929e4d2 major: import Fresh 2.0 code (#2449)
🎉
2024-05-24 09:40:08 +02:00
Marvin Hagemeister e4981d30ad www: rework docs layout (#2429)
- Re-enable partials
- clean up layout a bit
2024-05-21 17:38:32 +02:00
Marvin Hagemeister 25d4d16a8f www: fully remove component gallery (#2430) 2024-05-17 18:39:32 +02:00
Josh CollinsworthandMarvin Hagemeister e8d1a68b58 www: refresh home page (#2418)
Overhauls the Fresh homepage with a new design, new demos, and new
sections highlighting Fresh's capabilities.

---------

Co-authored-by: Marvin Hagemeister <marvin@deno.com>
2024-05-17 16:08:55 +02:00
Marvin Hagemeister a2be1abc6b chore: update Preact to 10.19.6 (#2331) 2024-02-22 10:46:41 +01:00
Reed von Redwitz 82c75f85e9 fix: update dependency recommendations (#2320)
closes https://github.com/denoland/fresh/issues/2319

The issue is because `imports.ts` wasn't changed before releasing. I
thought I would go through and bump some other versions as well. This
handles everything except the esbuild stuff and `tests/`.
2024-02-19 10:33:04 +01:00
Reed von Redwitz 3f28cc8977 chore: upgrade tailwind to 3.4.1 (#2287) 2024-01-29 14:10:28 +01:00
Reed von Redwitz ca8338e04d chore: bump std to 0.211.0 and loader to 0.8.3 (#2241) 2024-01-11 15:54:41 +01:00
Marvin Hagemeister 8c4385043c Revert "refactor: use --env CLI arg" (#2212)
Reverts denoland/fresh#2204

The `--env` flag cannot be used by default because it fails when no
`.env` file is present. Therefore this PR accidentally introduced a
breaking change.
2024-01-04 11:53:15 +01:00
Asher Gomez 99eb5435bb refactor: use --env CLI arg (#2204)
This change replaces the use of the Standard Library's `dotenv.load()`
with the native `--env` CLI flag.

The benefits include:
* One less dependency
* More obvious consumption of the `.env` file in the CLI output
2023-12-29 10:47:15 +01:00
Marvin Hagemeister de55d80dee docs: improve design (#2097) 2023-11-29 22:50:51 +01:00
Reed von RedwitzandMarvin Hagemeister b902205feb chore: bump std to 208 and deal with deprecations (#2081)
Co-authored-by: Marvin Hagemeister <marvin@deno.com>
2023-11-28 16:35:26 +00:00
Marvin Hagemeister bb035ae8da docs: port over to TailwindCSS (#2058) 2023-11-22 11:12:21 +01:00
Craig Doremus b5816cd001 feat(tests): add fresh-testing-library tests (#1990) 2023-11-15 18:25:13 +01:00
Reed von Redwitz da90d92ebd chore: bump deps (#2000) 2023-11-03 16:52:54 +01:00
Reed von Redwitz 781247b180 chore: explicitly version rts in deps.ts (#1684) 2023-10-30 17:59:22 +01:00
Marvin Hagemeister 0e58c6b475 docs: reload when ../src changes (#1855) 2023-10-04 17:40:56 +02:00
Marvin Hagemeister 477364c567 feat: prebundle code + restore from snapshot (#1604) 2023-08-16 16:47:51 +02:00
Marvin Hagemeister 6a599dbed5 www: new fenced code block design (#1629) 2023-08-13 10:52:41 +02:00
Marvin Hagemeister 86f92114d8 feat: Support setting <html> in _app template (#1617) 2023-08-11 18:40:20 +02:00
Roj 95d352d1dd www: use smart quotes (#1502) 2023-07-22 13:03:03 +02:00
Marvin Hagemeister 17811dd593 feat: support Preact error boundaries (#1442) 2023-07-10 13:02:45 +02:00
Lino Le Van 292b4c2d6f chore: bump dependencies (#1428) 2023-07-08 22:47:12 +02:00
Marvin Hagemeister 5724b73e71 fix(ssr): invalid HTML comment tags (#1260) 2023-06-09 11:21:36 +02:00
Asher GomezandLuca Casonato 1b6678951a feat: support embedded import map in deno.json (#1188)
One can now inline the `imports` and `scopes` from the import map directly into deno.json.

For new projects, `import_map.json` is not generated anymore.

Co-authored-by: Luca Casonato <hello@lcas.dev>
2023-06-03 10:46:40 +02:00
Asher Gomez 8db73e0485 refactor: disable lock (#1186) 2023-05-18 21:20:48 +10:00
Luca Casonato b12867a582 feat: support JSX automatic mode (#610)
This commit adds support for JSX automatic mode instead of the default
mode that requires the presence of the JSX pragma in each file.

This commit also adds the config file to the `fresh.gen.ts` manifest,
which is used to determine if the client emit should use automatic mode.

The minimum Deno version has also been bumped to 1.25.0.
2022-08-26 11:03:00 +02:00
Luca Casonato de6c3f6ed5 chore: remove --no-check flags (#259)
Since Deno 1.23.0, `--no-check` has become the default type checking
mode for `deno run`. As such, we don't need to specify this flag
anymore.
2022-06-20 12:45:48 +02:00
Luca Casonato 836cc24bdd feat: remove fresh cli, do manifest generation in process (#223)
This commit removes the `fresh` cli, replacing it with a small bootstrap script,
and JIT generation of the manifest that happens in process during development.
2022-06-14 09:39:38 +02:00
Luca Casonato 80598d07fd feat: use import maps instead of deps files (#209)
This commit updates fresh to use import maps instead of deps files in generated projects.
2022-05-23 19:35:15 +02:00