Skip to content

Commit

Permalink
experimental node support (not working yet)
Browse files Browse the repository at this point in the history
update deps
  • Loading branch information
jollytoad committed Nov 7, 2024
1 parent bee9c35 commit b33af2a
Show file tree
Hide file tree
Showing 19 changed files with 1,669 additions and 1,566 deletions.
4 changes: 2 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"image": "mcr.microsoft.com/devcontainers/base:jammy",
"features": {
"ghcr.io/michidk/devcontainers-features/bun:1": {
"version": "1.1.27"
"version": "1.1.34"
},
"ghcr.io/devcontainers-community/features/deno:1": {
"version": "1.46.3"
"version": "2.0.5"
},
"./pkgx-feature": {}
},
Expand Down
8 changes: 4 additions & 4 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

version: 2
updates:
- package-ecosystem: "devcontainers"
directory: "/"
schedule:
interval: weekly
- package-ecosystem: "devcontainers"
directory: "/"
schedule:
interval: weekly
5 changes: 4 additions & 1 deletion app/cache/blog/jsx_streaming
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ do this all within the same streamed response.</p>
<pre><code class="language-html">&lt;template id=&quot;_deferred_1&quot;&gt;
&lt;div&gt;My name is: Mark&lt;/div&gt;
&lt;/template&gt;
&lt;script&gt;document.getElementById(&quot;deferred_1&quot;).outerHTML = document.getElementById(&quot;_deferred_1&quot;).innerHTML;&lt;/script&gt;
&lt;script&gt;
document.getElementById(&quot;deferred_1&quot;).outerHTML =
document.getElementById(&quot;_deferred_1&quot;).innerHTML;
&lt;/script&gt;
</code></pre>
<p>NOTE: It doesn&#39;t matter that the template and script are rendered outside of the
body or html element, the HTML5 parser in every browser is designed to handle
Expand Down
10 changes: 0 additions & 10 deletions app/components/AutoRefreshScript.tsx

This file was deleted.

10 changes: 10 additions & 0 deletions app/components/DevScript.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { getEnv } from "../lib/env.ts";
import type { RequestProps } from "../lib/types.ts";

export function DevScript(
{ req, src, envVar }: RequestProps & { src: string; envVar: string },
) {
const enable = getEnv(envVar, req) === "true";

return enable ? <script src={src} type="module" /> : null;
}
4 changes: 2 additions & 2 deletions app/components/Page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Children } from "@http/jsx-stream/types";
import { Src } from "../components/Src.tsx";
import { AutoRefreshScript } from "./AutoRefreshScript.tsx";
import { DevScript } from "./DevScript.tsx";
import type { RequestProps } from "../lib/types.ts";

interface Props extends RequestProps {
Expand Down Expand Up @@ -39,7 +39,7 @@ export function Page({ req, children, reqURL, module }: Props) {

<script src="/app.js" type="module" />

<AutoRefreshScript req={req} />
<DevScript req={req} src="/auto-refresh/dev.js" envVar="AUTO_REFRESH" />
</head>
<body>
<header>
Expand Down
25 changes: 25 additions & 0 deletions app/init_hono_node_server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { withFallback } from "@http/route/with-fallback";
import { intercept } from "@http/interceptor/intercept";
import { logging } from "@http/interceptor/logger";
import type { Awaitable } from "@http/route/types";
import type { Interceptors } from "@http/interceptor/types";

export interface ServeOptions<E> {
fetch(req: Request, env: E): Awaitable<Response>;
}

/**
* Convenience function to generate Hono serve init parameter for localhost dev mode.
*/
// deno-lint-ignore require-await
export default async function initHonoNodeServer<E = unknown>(
handler: (
req: Request,
env: E,
) => Awaitable<Response | null>,
...interceptors: Interceptors<unknown[], Response>[]
): Promise<ServeOptions<E>> {
return {
fetch: intercept(withFallback(handler), logging(), ...interceptors),
};
}
17 changes: 17 additions & 0 deletions app/main_node.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env -S node --experimental-default-type=module --experimental-strip-types

// NOT CURRENTLY WORKING: transpilation of .tsx is required

import "./polyfill/bun.ts";

import handler from "./handler.ts";
import init from "./init_hono_node_server.ts";
import { serve } from "@hono/node-server";
import { setStore } from "@jollytoad/store";

setStore(import("@jollytoad/store-node-fs"));

const server = serve(await init(handler));
const address = server.address();

console.log(`Listening on ${address}`);
1 change: 1 addition & 0 deletions app/routes/_static/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

4 changes: 2 additions & 2 deletions app/routes/_static/sw_compat.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(() => {
// ../../Library/Caches/deno/deno_esbuild/[email protected]/node_modules/urlpattern-polyfill/dist/urlpattern.js
// node_modules/.deno/[email protected]/node_modules/urlpattern-polyfill/dist/urlpattern.js
var R = class {
type = 3;
name = "";
Expand Down Expand Up @@ -730,7 +730,7 @@
}
};

// ../../Library/Caches/deno/deno_esbuild/[email protected]/node_modules/urlpattern-polyfill/index.js
// node_modules/.deno/[email protected]/node_modules/urlpattern-polyfill/index.js
if (!globalThis.URLPattern) {
globalThis.URLPattern = me;
}
Expand Down
5 changes: 4 additions & 1 deletion app/routes/blog/jsx_streaming.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,10 @@ Then later in the same stream, once the component has resolved...
<template id="_deferred_1">
<div>My name is: Mark</div>
</template>
<script>document.getElementById("deferred_1").outerHTML = document.getElementById("_deferred_1").innerHTML;</script>
<script>
document.getElementById("deferred_1").outerHTML =
document.getElementById("_deferred_1").innerHTML;
</script>
```

NOTE: It doesn't matter that the template and script are rendered outside of the
Expand Down
1 change: 0 additions & 1 deletion app/routes/ex/_static/ex.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

.ex-swap {
font-size: small;
font-weight: normal;
Expand Down
1 change: 0 additions & 1 deletion app/routes/quiz/_static/quiz.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

.quiz {
border-style: solid;
border-width: 2px 1ex 1ex 2px;
Expand Down
4 changes: 2 additions & 2 deletions app/routes/quote/_static/tv.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ html {
color: white;
}

@media (orientation: landscape) {
@media (orientation: landscape) {
html {
font-size: 1vw;
}
}

@media (orientation: portrait) {
@media (orientation: portrait) {
html {
font-size: 0.8vh;
}
Expand Down
1 change: 0 additions & 1 deletion app/routes/todo/_static/todo.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

.todo-item * {
display: inline;
margin: 2px 4px;
Expand Down
53 changes: 28 additions & 25 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"start:cache": "USE_CACHE=true ./scripts/dev.ts",
"start:prod": "./app/main.ts",
"start:bun": "./app/main_bun.ts",
"start:node": "./app/main_node.ts",
"start:cloudflare": "deno task build:cloudflare && bunx wrangler pages dev ./.cloudflare/dist",
"mkcert": "mkcert -install -key-file localhost-key.pem -cert-file localhost-cert.pem localhost",
"deploy": "deno run --allow-sys --allow-net --allow-read --allow-write --allow-env jsr:@deno/deployctl deploy",
Expand All @@ -33,6 +34,7 @@
"noUncheckedIndexedAccess": true,
"verbatimModuleSyntax": true
},
"nodeModulesDir": "auto",
"exclude": [
"app/routes/_static/sw.js",
"app/routes/_static/sw_compat.js",
Expand All @@ -48,41 +50,42 @@
]
},
"imports": {
"@deno/cache-dir": "jsr:@deno/cache-dir@^0.11.1",
"@deno/emit": "jsr:@deno/emit@^0.45.0",
"@deno/graph": "jsr:@deno/graph@^0.82.1",
"@http/discovery": "jsr:@http/discovery@^0.23.0",
"@http/fs": "jsr:@http/fs@^0.23.0",
"@http/generate": "jsr:@http/generate@^0.23.1",
"@http/host-bun-local": "jsr:@http/host-bun-local@^0.23.0",
"@http/host-cloudflare-worker": "jsr:@http/host-cloudflare-worker@^0.23.0",
"@http/host-deno-deploy": "jsr:@http/host-deno-deploy@^0.23.0",
"@http/host-deno-local": "jsr:@http/host-deno-local@^0.23.0",
"@http/interceptor": "jsr:@http/interceptor@^0.23.0",
"@http/jsx-stream": "jsr:@http/jsx-stream@^0.3.0",
"@http/request": "jsr:@http/request@^0.23.0",
"@http/response": "jsr:@http/response@^0.23.0",
"@http/route": "jsr:@http/route@^0.23.0",
"@deno/cache-dir": "jsr:@deno/cache-dir@^0.13.2",
"@deno/emit": "jsr:@deno/emit@^0.46.0",
"@deno/graph": "jsr:@deno/graph@^0.84.1",
"@hono/node-server": "npm:@hono/node-server@^1.13.5",
"@http/discovery": "jsr:@http/discovery@^0.24.0",
"@http/fs": "jsr:@http/fs@^0.24.0",
"@http/generate": "jsr:@http/generate@^0.24.0",
"@http/host-bun-local": "jsr:@http/host-bun-local@^0.24.0",
"@http/host-cloudflare-worker": "jsr:@http/host-cloudflare-worker@^0.24.0",
"@http/host-deno-deploy": "jsr:@http/host-deno-deploy@^0.24.0",
"@http/host-deno-local": "jsr:@http/host-deno-local@^0.24.0",
"@http/interceptor": "jsr:@http/interceptor@^0.24.0",
"@http/jsx-stream": "jsr:@http/jsx-stream@^0.4.0",
"@http/request": "jsr:@http/request@^0.24.0",
"@http/response": "jsr:@http/response@^0.24.0",
"@http/route": "jsr:@http/route@^0.24.0",
"@jollytoad/store": "jsr:@jollytoad/store@^0.4.0",
"@jollytoad/store-deno-fs": "jsr:@jollytoad/store-deno-fs@^0.4.0",
"@jollytoad/store-deno-kv": "jsr:@jollytoad/store-deno-kv@^0.4.0",
"@jollytoad/store-no-op": "jsr:@jollytoad/store-no-op@^0.4.0",
"@jollytoad/store-node-fs": "jsr:@jollytoad/store-node-fs@^0.4.0",
"@std/async": "jsr:@std/async@^1.0.5",
"@std/collections": "jsr:@std/collections@^1.0.6",
"@std/fs": "jsr:@std/fs@^1.0.3",
"@std/http": "jsr:@std/http@^1.0.6",
"@std/path": "jsr:@std/path@^1.0.6",
"@std/async": "jsr:@std/async@^1.0.8",
"@std/collections": "jsr:@std/collections@^1.0.9",
"@std/fs": "jsr:@std/fs@^1.0.5",
"@std/http": "jsr:@std/http@^1.0.9",
"@std/path": "jsr:@std/path@^1.0.8",
"@std/ulid": "jsr:@std/ulid@^1.0.0",
"esbuild": "npm:esbuild@^0.23.1",
"esbuild-deno-loader": "jsr:@luca/esbuild-deno-loader@^0.10.3",
"esbuild": "npm:esbuild@^0.24.0",
"esbuild-deno-loader": "jsr:@luca/esbuild-deno-loader@^0.11.0",
"hast-util-raw": "npm:hast-util-raw@^9.0.4",
"hast-util-to-jsx-runtime": "npm:hast-util-to-jsx-runtime@^2.3.0",
"mdast-util-from-markdown": "npm:mdast-util-from-markdown@^2.0.1",
"hast-util-to-jsx-runtime": "npm:hast-util-to-jsx-runtime@^2.3.2",
"mdast-util-from-markdown": "npm:mdast-util-from-markdown@^2.0.2",
"mdast-util-gfm": "npm:mdast-util-gfm@^3.0.0",
"mdast-util-to-hast": "npm:mdast-util-to-hast@^13.2.0",
"micromark-extension-gfm": "npm:micromark-extension-gfm@^3.0.0",
"openai": "npm:openai@^4.61.0",
"openai": "npm:openai@^4.71.1",
"urlpattern-polyfill": "npm:urlpattern-polyfill@^10.0.0"
},
"deploy": {
Expand Down
Loading

1 comment on commit b33af2a

@deno-deploy
Copy link

@deno-deploy deno-deploy bot commented on b33af2a Nov 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failed to deploy:

npm package '@jsr/deno__cache-dir' does not exist.

Please sign in to comment.