Skip to content

Commit

Permalink
0.13 (#23)
Browse files Browse the repository at this point in the history
* test

* test

* test

* test

* test

* better error handling

* rm error

* test

* redeploy

* test

* test

* perf

* update deps

* preview static html files

* improve static file serving

* rm isr

* deploy

* test

* isr

* doc/format

* rm isr

* styles

* docs
  • Loading branch information
rossrobino authored Sep 18, 2024
1 parent f721ce8 commit a5f23e7
Show file tree
Hide file tree
Showing 122 changed files with 2,542 additions and 3,489 deletions.
66 changes: 65 additions & 1 deletion .changeset/pretty-meals-buy.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,68 @@
"domco": minor
---

rm default immutable headers - leave to adapters instead
Server framework agnostic

This project had a lot of overlap with HonoX, HonoX should be the default if you are wanting all of the features Hono provides like client components. This update removes the dependency on Hono and making the library framework agnostic. Hono can still be easily used with domco (see below).

This makes domco have no dependencies other than Vite. You can now build your app with vanilla JS without any external libraries. You can now use any server framework like Hono that provides a function that handles a web `Request` and returns a `Response`. This update also simplifies domco's API and refactors much of the codebase to make it smaller and builds faster.

## Overview of Changes

- `+server` renamed to `+app`
- `+client` renamed to `+script`
- Instead of exporting the `app` as the default export, you now must export `app.fetch` as a named `handler` export.
- Removes `page`, `client`, and `server` context variables.
- `page` is replaced with the `client:page` virtual module.
- `script` is replaced with the `client:script` virtual module.
- The `server` context variable is removed. This is better handled by the user - perhaps with libraries like `ofetch`.
- The `tags` imported from `client:script` are now just strings, so you'll need to pass them through `hono/html` - `raw` function to pass them into a JSX template if you were using them directly in Hono.
- Multiple `+server` entry points are removed in favor of just one `src/server/+app` entry. Note this is located within `src/server/` now instead of directly in `src/`.
- Removes `+setup` - since domco no longer mounts routes, user can control the entire lifecycle through the `handler`.
- Removes default immutable headers - leave to adapters instead.
- Import `handler` from `dist/server/app.js` instead of the `createApp` export.
- Script entry points are no longer automatically injected into pages in the same directory.
- Static pages must be prerendered, nothing from `src/client/` is included in the app if not imported into the server entry.
- d.ts changes - instead of adding the context variable map, you now just need to add types for the virtual modules from `domco/env`.

```ts
/// <reference types="vite/client" />
/// <reference types="domco/env" />
```

## Examples

### Vanilla

```ts
import { html } from "client:page";
import type { Handler } from "domco";

export const handler: Handler = (req) => {
const { pathname } = new URL(req.url);

if (pathname === "/") {
return new Response(html, {
headers: {
"Content-Type": "text/html",
},
});
}

return new Response("Not found", { status: 404 });
};
```

### Hono - Migrate from 0.12

```ts
// src/server/+app.ts
import { html } from "client:page";
import { Hono } from "hono";

const app = new Hono();

app.use((c) => c.html(html));

export const handler = app.fetch;
```
5 changes: 5 additions & 0 deletions .changeset/swift-llamas-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-domco": minor
---

Updates template to 0.13
1 change: 0 additions & 1 deletion apps/cloudflare/src/+client.ts

This file was deleted.

9 changes: 0 additions & 9 deletions apps/cloudflare/src/+server.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<link rel="stylesheet" href="/style.css" />
<link rel="stylesheet" href="/client/style.css" />
<title>Cloudflare Tester</title>
<meta name="description" content="Description" />
</head>
<body>
<header></header>
<main>
<h1>Hello Cloudflare</h1>
<p>
<a href="/static">Static</a>
</p>
</main>
<footer></footer>
</body>
Expand Down
File renamed without changes.
2 changes: 2 additions & 0 deletions apps/cloudflare/src/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// <reference types="vite/client" />
/// <reference types="domco/env" />
7 changes: 0 additions & 7 deletions apps/cloudflare/src/global.d.ts

This file was deleted.

16 changes: 16 additions & 0 deletions apps/cloudflare/src/server/+app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { html } from "client:page";
import type { Handler } from "domco";

export const handler: Handler = (req) => {
const { pathname } = new URL(req.url);

if (pathname === "/") {
return new Response(html, {
headers: {
"Content-Type": "text/html",
},
});
}

return new Response("Not found", { status: 404 });
};
12 changes: 0 additions & 12 deletions apps/cloudflare/src/static/+page.html

This file was deleted.

3 changes: 0 additions & 3 deletions apps/cloudflare/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{
"extends": "@robino/tsconfig/bundler.json",
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "hono/jsx",

"paths": {
"@": ["./src"],
"@/*": ["./src/*"]
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"autoprefixer": "^10.4.20",
"domco": "*",
"drab": "^5.4.2",
"tailwindcss": "^3.4.10",
"tailwindcss": "^3.4.12",
"uico": "^0.3.1"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import "@/style.css";
import "@/client/tailwind.css";
import "drab/details/define";
import "drab/dialog/define";
import "drab/prefetch/define";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ headings.forEach((heading) => {
} else {
link.classList.add("text-muted-foreground");
const last = tableOfContents.querySelector(".level-2:last-child");
console.log(last);

let nestedUl = last?.querySelector("ul");
if (!nestedUl) {
Expand Down
File renamed without changes.
33 changes: 0 additions & 33 deletions apps/docs/src/content/_preview.md

This file was deleted.

68 changes: 0 additions & 68 deletions apps/docs/src/content/migrate.md

This file was deleted.

Loading

0 comments on commit a5f23e7

Please sign in to comment.