From a5f23e704ac55c62686c34ed804ef2f3aaec2cd2 Mon Sep 17 00:00:00 2001
From: Ross Robino
Date: Wed, 18 Sep 2024 06:52:18 -0400
Subject: [PATCH] 0.13 (#23)
* 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
---
.changeset/pretty-meals-buy.md | 66 +-
.changeset/swift-llamas-jam.md | 5 +
apps/cloudflare/src/+client.ts | 1 -
apps/cloudflare/src/+server.ts | 9 -
apps/cloudflare/src/{ => client}/+page.html | 5 +-
apps/cloudflare/src/{ => client}/style.css | 0
apps/cloudflare/src/env.d.ts | 2 +
apps/cloudflare/src/global.d.ts | 7 -
apps/cloudflare/src/server/+app.ts | 16 +
apps/cloudflare/src/static/+page.html | 12 -
apps/cloudflare/tsconfig.json | 3 -
apps/docs/package.json | 2 +-
.../src/{+client.ts => client/+script.ts} | 2 +-
.../+client.ts => client/docs/+script.ts} | 1 -
.../src/{style.css => client/tailwind.css} | 0
apps/docs/src/content/_preview.md | 33 -
apps/docs/src/content/migrate.md | 68 --
apps/docs/src/content/tutorial.md | 197 ---
apps/docs/src/{global.d.ts => env.d.ts} | 3 +-
apps/docs/src/generated/globals.md | 564 ---------
.../docs/src/{+server.tsx => server/+app.tsx} | 34 +-
.../docs/src/{ => server}/components/Edit.tsx | 0
.../docs/src/{ => server}/components/Hero.tsx | 0
.../src/{ => server}/components/Layout.tsx | 0
apps/docs/src/{ => server}/components/Nav.tsx | 14 +-
apps/docs/src/{ => server}/components/svg.tsx | 19 +
apps/docs/src/server/content/_preview.md | 34 +
apps/docs/src/{ => server}/content/deploy.md | 21 +-
apps/docs/src/server/content/examples.md | 37 +
apps/docs/src/server/content/migrate.md | 53 +
apps/docs/src/server/content/tutorial.md | 170 +++
.../docs/src/{ => server}/generated/README.md | 0
apps/docs/src/server/generated/globals.md | 344 ++++++
apps/tester/package.json | 5 +-
apps/tester/public/public.html | 1 +
apps/tester/src/+server.ts | 43 -
apps/tester/src/+setup.ts | 13 -
apps/tester/src/api/+server.ts | 11 -
apps/tester/src/client/+client.ts | 1 -
apps/tester/src/{ => client}/+page.html | 33 +-
.../src/{+client.ts => client/+script.ts} | 3 +-
apps/tester/src/{ => client}/react/+page.html | 4 +-
apps/tester/src/{ => client}/react/App.tsx | 4 +-
.../+client.tsx => client/react/react.tsx} | 0
apps/tester/src/client/style.css | 10 +
apps/tester/src/dynamic/+page.html | 13 -
apps/tester/src/dynamic/+server.js | 16 -
apps/tester/src/env.d.ts | 2 +
apps/tester/src/global.d.ts | 7 -
apps/tester/src/half-static/+page.html | 15 -
apps/tester/src/half-static/+server.ts | 18 -
apps/tester/src/htmx/+page.html | 22 -
apps/tester/src/htmx/partials/+client.js | 3 -
apps/tester/src/htmx/partials/+server.tsx | 15 -
.../src/htmx/partials/non-entry-import.ts | 1 -
.../tester/src/htmx/static-partial/+page.html | 2 -
apps/tester/src/mw/index.ts | 84 --
apps/tester/src/react/+server.tsx | 24 -
apps/tester/src/server/+app.tsx | 60 +
apps/tester/src/static-page/+page.html | 13 -
apps/tester/src/static-prerender/+page.html | 19 -
apps/tester/src/static-prerender/+server.ts | 48 -
.../src/static-prerender/content/post-1.md | 3 -
.../src/static-prerender/content/post-2.md | 3 -
apps/tester/src/style.css | 10 -
apps/tester/src/svelte/+client.ts | 10 -
apps/tester/src/svelte/+page.html | 9 -
apps/tester/src/svelte/+server.ts | 13 -
apps/tester/src/svelte/App.svelte | 23 -
apps/tester/svelte.config.js | 7 -
apps/tester/tsconfig.json | 1 -
apps/tester/vite.config.ts | 7 -
package-lock.json | 1078 ++++++++++-------
package.json | 8 +-
packages/create-domco/package.json | 4 +-
.../create-domco/src/dependencies/index.ts | 7 +-
packages/create-domco/src/index.ts | 6 +-
.../create-domco/src/template-files/app.ts | 29 +
.../src/template-files/deno-json.ts | 5 +-
.../{global-types.ts => env-types.ts} | 9 +-
.../src/template-files/gitignore.ts | 2 +
.../src/template-files/package-json.ts | 3 +-
.../src/template-files/page-html.ts | 9 +-
.../src/template-files/prettier.ts | 6 +-
.../src/template-files/style-css.ts | 7 +-
.../src/template-files/tailwind.ts | 2 +-
.../src/template-files/tsconfig-json.ts | 1 -
packages/domco/package.json | 29 +-
.../domco/src/adapter/cloudflare/index.ts | 29 +-
packages/domco/src/adapter/deno/index.ts | 27 +-
packages/domco/src/adapter/vercel/index.ts | 135 ++-
packages/domco/src/app/dev/index.ts | 143 ---
packages/domco/src/app/index.ts | 49 -
packages/domco/src/app/mw/index.ts | 15 -
packages/domco/src/app/util/index.ts | 173 ---
packages/domco/src/constants/index.ts | 23 +-
packages/domco/src/index.ts | 2 +-
.../request-listener => listener}/index.ts | 8 +-
packages/domco/src/node/serve-static/index.ts | 90 --
packages/domco/src/plugin/adapter/index.ts | 67 +-
packages/domco/src/plugin/config/index.ts | 113 +-
.../src/plugin/configure-server/index.ts | 112 +-
packages/domco/src/plugin/entry/index.ts | 31 -
packages/domco/src/plugin/html/index.ts | 255 ----
packages/domco/src/plugin/index.ts | 24 +-
packages/domco/src/plugin/lifecycle/index.ts | 277 ++++-
packages/domco/src/plugin/manifest/index.ts | 37 -
packages/domco/src/plugin/manifest/types.d.ts | 4 -
packages/domco/src/plugin/page/index.ts | 90 ++
packages/domco/src/plugin/routes/index.ts | 59 -
packages/domco/src/plugin/routes/types.d.ts | 4 -
packages/domco/src/plugin/script/index.ts | 156 +++
packages/domco/src/types/env.d.ts | 25 +
packages/domco/src/types/global.d.ts | 7 -
packages/domco/src/types/helper/index.ts | 2 -
packages/domco/src/types/index.ts | 129 ++
packages/domco/src/types/private/index.ts | 18 -
packages/domco/src/types/public/index.ts | 287 -----
packages/domco/src/util/code-size/index.ts | 12 +-
.../domco/src/util/create-routes/index.ts | 79 --
packages/domco/src/util/fs/index.ts | 33 +-
packages/domco/src/util/perf/index.ts | 13 +
122 files changed, 2542 insertions(+), 3489 deletions(-)
create mode 100644 .changeset/swift-llamas-jam.md
delete mode 100644 apps/cloudflare/src/+client.ts
delete mode 100644 apps/cloudflare/src/+server.ts
rename apps/cloudflare/src/{ => client}/+page.html (81%)
rename apps/cloudflare/src/{ => client}/style.css (100%)
create mode 100644 apps/cloudflare/src/env.d.ts
delete mode 100644 apps/cloudflare/src/global.d.ts
create mode 100644 apps/cloudflare/src/server/+app.ts
delete mode 100644 apps/cloudflare/src/static/+page.html
rename apps/docs/src/{+client.ts => client/+script.ts} (93%)
rename apps/docs/src/{lib/docs/+client.ts => client/docs/+script.ts} (99%)
rename apps/docs/src/{style.css => client/tailwind.css} (100%)
delete mode 100644 apps/docs/src/content/_preview.md
delete mode 100644 apps/docs/src/content/migrate.md
delete mode 100644 apps/docs/src/content/tutorial.md
rename apps/docs/src/{global.d.ts => env.d.ts} (72%)
delete mode 100644 apps/docs/src/generated/globals.md
rename apps/docs/src/{+server.tsx => server/+app.tsx} (66%)
rename apps/docs/src/{ => server}/components/Edit.tsx (100%)
rename apps/docs/src/{ => server}/components/Hero.tsx (100%)
rename apps/docs/src/{ => server}/components/Layout.tsx (100%)
rename apps/docs/src/{ => server}/components/Nav.tsx (96%)
rename apps/docs/src/{ => server}/components/svg.tsx (84%)
create mode 100644 apps/docs/src/server/content/_preview.md
rename apps/docs/src/{ => server}/content/deploy.md (75%)
create mode 100644 apps/docs/src/server/content/examples.md
create mode 100644 apps/docs/src/server/content/migrate.md
create mode 100644 apps/docs/src/server/content/tutorial.md
rename apps/docs/src/{ => server}/generated/README.md (100%)
create mode 100644 apps/docs/src/server/generated/globals.md
create mode 100644 apps/tester/public/public.html
delete mode 100644 apps/tester/src/+server.ts
delete mode 100644 apps/tester/src/+setup.ts
delete mode 100644 apps/tester/src/api/+server.ts
delete mode 100644 apps/tester/src/client/+client.ts
rename apps/tester/src/{ => client}/+page.html (52%)
rename apps/tester/src/{+client.ts => client/+script.ts} (72%)
rename apps/tester/src/{ => client}/react/+page.html (63%)
rename apps/tester/src/{ => client}/react/App.tsx (65%)
rename apps/tester/src/{react/+client.tsx => client/react/react.tsx} (100%)
create mode 100644 apps/tester/src/client/style.css
delete mode 100644 apps/tester/src/dynamic/+page.html
delete mode 100644 apps/tester/src/dynamic/+server.js
create mode 100644 apps/tester/src/env.d.ts
delete mode 100644 apps/tester/src/global.d.ts
delete mode 100644 apps/tester/src/half-static/+page.html
delete mode 100644 apps/tester/src/half-static/+server.ts
delete mode 100644 apps/tester/src/htmx/+page.html
delete mode 100644 apps/tester/src/htmx/partials/+client.js
delete mode 100644 apps/tester/src/htmx/partials/+server.tsx
delete mode 100644 apps/tester/src/htmx/partials/non-entry-import.ts
delete mode 100644 apps/tester/src/htmx/static-partial/+page.html
delete mode 100644 apps/tester/src/mw/index.ts
delete mode 100644 apps/tester/src/react/+server.tsx
create mode 100644 apps/tester/src/server/+app.tsx
delete mode 100644 apps/tester/src/static-page/+page.html
delete mode 100644 apps/tester/src/static-prerender/+page.html
delete mode 100644 apps/tester/src/static-prerender/+server.ts
delete mode 100644 apps/tester/src/static-prerender/content/post-1.md
delete mode 100644 apps/tester/src/static-prerender/content/post-2.md
delete mode 100644 apps/tester/src/style.css
delete mode 100644 apps/tester/src/svelte/+client.ts
delete mode 100644 apps/tester/src/svelte/+page.html
delete mode 100644 apps/tester/src/svelte/+server.ts
delete mode 100644 apps/tester/src/svelte/App.svelte
delete mode 100644 apps/tester/svelte.config.js
create mode 100644 packages/create-domco/src/template-files/app.ts
rename packages/create-domco/src/template-files/{global-types.ts => env-types.ts} (53%)
delete mode 100644 packages/domco/src/app/dev/index.ts
delete mode 100644 packages/domco/src/app/index.ts
delete mode 100644 packages/domco/src/app/mw/index.ts
delete mode 100644 packages/domco/src/app/util/index.ts
rename packages/domco/src/{node/request-listener => listener}/index.ts (97%)
delete mode 100644 packages/domco/src/node/serve-static/index.ts
delete mode 100644 packages/domco/src/plugin/entry/index.ts
delete mode 100644 packages/domco/src/plugin/html/index.ts
delete mode 100644 packages/domco/src/plugin/manifest/index.ts
delete mode 100644 packages/domco/src/plugin/manifest/types.d.ts
create mode 100644 packages/domco/src/plugin/page/index.ts
delete mode 100644 packages/domco/src/plugin/routes/index.ts
delete mode 100644 packages/domco/src/plugin/routes/types.d.ts
create mode 100644 packages/domco/src/plugin/script/index.ts
create mode 100644 packages/domco/src/types/env.d.ts
delete mode 100644 packages/domco/src/types/global.d.ts
create mode 100644 packages/domco/src/types/index.ts
delete mode 100644 packages/domco/src/types/private/index.ts
delete mode 100644 packages/domco/src/types/public/index.ts
delete mode 100644 packages/domco/src/util/create-routes/index.ts
create mode 100644 packages/domco/src/util/perf/index.ts
diff --git a/.changeset/pretty-meals-buy.md b/.changeset/pretty-meals-buy.md
index 2470265..ff506e4 100644
--- a/.changeset/pretty-meals-buy.md
+++ b/.changeset/pretty-meals-buy.md
@@ -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
+///
+///
+```
+
+## 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;
+```
diff --git a/.changeset/swift-llamas-jam.md b/.changeset/swift-llamas-jam.md
new file mode 100644
index 0000000..d604c05
--- /dev/null
+++ b/.changeset/swift-llamas-jam.md
@@ -0,0 +1,5 @@
+---
+"create-domco": minor
+---
+
+Updates template to 0.13
diff --git a/apps/cloudflare/src/+client.ts b/apps/cloudflare/src/+client.ts
deleted file mode 100644
index 6b2b3db..0000000
--- a/apps/cloudflare/src/+client.ts
+++ /dev/null
@@ -1 +0,0 @@
-console.log("hello world");
diff --git a/apps/cloudflare/src/+server.ts b/apps/cloudflare/src/+server.ts
deleted file mode 100644
index 635368d..0000000
--- a/apps/cloudflare/src/+server.ts
+++ /dev/null
@@ -1,9 +0,0 @@
-import { Hono } from "hono";
-
-export const prerender = true;
-
-const app = new Hono();
-
-app.get("/", (c) => c.html(c.var.page()));
-
-export default app;
diff --git a/apps/cloudflare/src/+page.html b/apps/cloudflare/src/client/+page.html
similarity index 81%
rename from apps/cloudflare/src/+page.html
rename to apps/cloudflare/src/client/+page.html
index bd9c7ab..67b3b8e 100644
--- a/apps/cloudflare/src/+page.html
+++ b/apps/cloudflare/src/client/+page.html
@@ -4,7 +4,7 @@
-
+
Cloudflare Tester
@@ -12,9 +12,6 @@
Hello Cloudflare
-
- Static
-
- Static Page
- Home
-
diff --git a/apps/cloudflare/src/style.css b/apps/cloudflare/src/client/style.css
similarity index 100%
rename from apps/cloudflare/src/style.css
rename to apps/cloudflare/src/client/style.css
diff --git a/apps/cloudflare/src/env.d.ts b/apps/cloudflare/src/env.d.ts
new file mode 100644
index 0000000..b1d9caa
--- /dev/null
+++ b/apps/cloudflare/src/env.d.ts
@@ -0,0 +1,2 @@
+///
+///
diff --git a/apps/cloudflare/src/global.d.ts b/apps/cloudflare/src/global.d.ts
deleted file mode 100644
index 65d5a21..0000000
--- a/apps/cloudflare/src/global.d.ts
+++ /dev/null
@@ -1,7 +0,0 @@
-///
-import type { DomcoContextVariableMap } from "domco";
-import "hono";
-
-declare module "hono" {
- interface ContextVariableMap extends DomcoContextVariableMap {}
-}
diff --git a/apps/cloudflare/src/server/+app.ts b/apps/cloudflare/src/server/+app.ts
new file mode 100644
index 0000000..05b04bf
--- /dev/null
+++ b/apps/cloudflare/src/server/+app.ts
@@ -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 });
+};
diff --git a/apps/cloudflare/src/static/+page.html b/apps/cloudflare/src/static/+page.html
deleted file mode 100644
index ac133d3..0000000
--- a/apps/cloudflare/src/static/+page.html
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
-
-
-
-
Static Page
-
-
-