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.
This commit is contained in:
Vendored
+3
-1
@@ -1,5 +1,7 @@
|
|||||||
{
|
{
|
||||||
".": "THIS FILE EXISTS ONLY FOR VSCODE! IT IS NOT USED AT RUNTIME.",
|
"scopes": {
|
||||||
|
"THIS FILE EXISTS ONLY FOR VSCODE! IT IS NOT USED AT RUNTIME": {}
|
||||||
|
},
|
||||||
"imports": {
|
"imports": {
|
||||||
"$fresh/": "../",
|
"$fresh/": "../",
|
||||||
|
|
||||||
|
|||||||
@@ -5,5 +5,9 @@
|
|||||||
"www": "deno run -A --watch=static/,routes/ www/dev.ts",
|
"www": "deno run -A --watch=static/,routes/ www/dev.ts",
|
||||||
"screenshot": "deno run -A www/utils/screenshot.ts"
|
"screenshot": "deno run -A www/utils/screenshot.ts"
|
||||||
},
|
},
|
||||||
"importMap": "./tests/fixture/import_map.json"
|
"importMap": "./.vscode/import_map.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"jsx": "react-jsx",
|
||||||
|
"jsxImportSource": "preact"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -2,5 +2,9 @@
|
|||||||
"tasks": {
|
"tasks": {
|
||||||
"start": "deno run -A --watch=static/,routes/ dev.ts"
|
"start": "deno run -A --watch=static/,routes/ dev.ts"
|
||||||
},
|
},
|
||||||
"importMap": "./import_map.json"
|
"importMap": "./import_map.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"jsx": "react-jsx",
|
||||||
|
"jsxImportSource": "preact"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
// This file SHOULD be checked into source version control.
|
// This file SHOULD be checked into source version control.
|
||||||
// This file is automatically updated during development when running `dev.ts`.
|
// This file is automatically updated during development when running `dev.ts`.
|
||||||
|
|
||||||
|
import config from "./deno.json" assert { type: "json" };
|
||||||
import * as $0 from "./routes/index.tsx";
|
import * as $0 from "./routes/index.tsx";
|
||||||
import * as $$0 from "./islands/Counter.tsx";
|
import * as $$0 from "./islands/Counter.tsx";
|
||||||
|
|
||||||
@@ -13,6 +14,7 @@ const manifest = {
|
|||||||
"./islands/Counter.tsx": $$0,
|
"./islands/Counter.tsx": $$0,
|
||||||
},
|
},
|
||||||
baseUrl: import.meta.url,
|
baseUrl: import.meta.url,
|
||||||
|
config,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default manifest;
|
export default manifest;
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
/** @jsx h */
|
|
||||||
import { h } from "preact";
|
|
||||||
import { useState } from "preact/hooks";
|
import { useState } from "preact/hooks";
|
||||||
import { IS_BROWSER } from "$fresh/runtime.ts";
|
import { IS_BROWSER } from "$fresh/runtime.ts";
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
/** @jsx h */
|
|
||||||
import { h } from "preact";
|
|
||||||
import Counter from "../islands/Counter.tsx";
|
import Counter from "../islands/Counter.tsx";
|
||||||
|
|
||||||
export default function Home() {
|
export default function Home() {
|
||||||
|
|||||||
@@ -1,23 +1,8 @@
|
|||||||
import { gte, join, parse, resolve } from "./src/dev/deps.ts";
|
import { join, parse, resolve } from "./src/dev/deps.ts";
|
||||||
import { error } from "./src/dev/error.ts";
|
import { error } from "./src/dev/error.ts";
|
||||||
import { collect, generate } from "./src/dev/mod.ts";
|
import { collect, ensureMinDenoVersion, generate } from "./src/dev/mod.ts";
|
||||||
|
|
||||||
const MIN_VERSION = "1.23.0";
|
ensureMinDenoVersion();
|
||||||
|
|
||||||
// Check that the minimum supported Deno version is being used.
|
|
||||||
if (!gte(Deno.version.deno, MIN_VERSION)) {
|
|
||||||
let message =
|
|
||||||
`Deno version ${MIN_VERSION} or higher is required. Please update Deno.\n\n`;
|
|
||||||
|
|
||||||
if (Deno.execPath().includes("homebrew")) {
|
|
||||||
message +=
|
|
||||||
"You seem to have installed Deno via homebrew. To update, run: `brew upgrade deno`\n";
|
|
||||||
} else {
|
|
||||||
message += "To update, run: `deno upgrade`\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
error(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
const help = `fresh-init
|
const help = `fresh-init
|
||||||
|
|
||||||
@@ -110,9 +95,7 @@ await Deno.writeTextFile(
|
|||||||
IMPORT_MAP_JSON,
|
IMPORT_MAP_JSON,
|
||||||
);
|
);
|
||||||
|
|
||||||
const ROUTES_INDEX_TSX = `/** @jsx h */
|
const ROUTES_INDEX_TSX = `import Counter from "../islands/Counter.tsx";
|
||||||
import { h } from "preact";
|
|
||||||
import Counter from "../islands/Counter.tsx";
|
|
||||||
|
|
||||||
export default function Home() {
|
export default function Home() {
|
||||||
return (
|
return (
|
||||||
@@ -136,10 +119,10 @@ await Deno.writeTextFile(
|
|||||||
ROUTES_INDEX_TSX,
|
ROUTES_INDEX_TSX,
|
||||||
);
|
);
|
||||||
|
|
||||||
const COMPONENTS_BUTTON_TSX = `/** @jsx h */
|
const COMPONENTS_BUTTON_TSX = `import { JSX } from "preact";
|
||||||
import { h } from "preact";
|
|
||||||
import { IS_BROWSER } from "$fresh/runtime.ts";
|
import { IS_BROWSER } from "$fresh/runtime.ts";
|
||||||
export function Button(props: h.JSX.HTMLAttributes<HTMLButtonElement>) {
|
|
||||||
|
export function Button(props: JSX.HTMLAttributes<HTMLButtonElement>) {
|
||||||
return (
|
return (
|
||||||
<button
|
<button
|
||||||
{...props}
|
{...props}
|
||||||
@@ -157,9 +140,7 @@ await Deno.writeTextFile(
|
|||||||
COMPONENTS_BUTTON_TSX,
|
COMPONENTS_BUTTON_TSX,
|
||||||
);
|
);
|
||||||
|
|
||||||
const ISLANDS_COUNTER_TSX = `/** @jsx h */
|
const ISLANDS_COUNTER_TSX = `import { useState } from "preact/hooks";
|
||||||
import { h } from "preact";
|
|
||||||
import { useState } from "preact/hooks";
|
|
||||||
import { Button } from "../components/Button.tsx";
|
import { Button } from "../components/Button.tsx";
|
||||||
|
|
||||||
interface CounterProps {
|
interface CounterProps {
|
||||||
@@ -182,9 +163,7 @@ await Deno.writeTextFile(
|
|||||||
ISLANDS_COUNTER_TSX,
|
ISLANDS_COUNTER_TSX,
|
||||||
);
|
);
|
||||||
|
|
||||||
const ROUTES_GREET_TSX = `/** @jsx h */
|
const ROUTES_GREET_TSX = `import { PageProps } from "$fresh/server.ts";
|
||||||
import { h } from "preact";
|
|
||||||
import { PageProps } from "$fresh/server.ts";
|
|
||||||
|
|
||||||
export default function Greet(props: PageProps) {
|
export default function Greet(props: PageProps) {
|
||||||
return <div>Hello {props.params.name}</div>;
|
return <div>Hello {props.params.name}</div>;
|
||||||
@@ -300,6 +279,10 @@ const config = {
|
|||||||
start: "deno run -A --watch=static/,routes/ dev.ts",
|
start: "deno run -A --watch=static/,routes/ dev.ts",
|
||||||
},
|
},
|
||||||
importMap: "./import_map.json",
|
importMap: "./import_map.json",
|
||||||
|
compilerOptions: {
|
||||||
|
jsx: "react-jsx",
|
||||||
|
jsxImportSource: "preact",
|
||||||
|
},
|
||||||
};
|
};
|
||||||
const DENO_CONFIG = JSON.stringify(config, null, 2) + "\n";
|
const DENO_CONFIG = JSON.stringify(config, null, 2) + "\n";
|
||||||
|
|
||||||
|
|||||||
@@ -2,12 +2,32 @@ import {
|
|||||||
dirname,
|
dirname,
|
||||||
extname,
|
extname,
|
||||||
fromFileUrl,
|
fromFileUrl,
|
||||||
|
gte,
|
||||||
join,
|
join,
|
||||||
toFileUrl,
|
toFileUrl,
|
||||||
walk,
|
walk,
|
||||||
} from "./deps.ts";
|
} from "./deps.ts";
|
||||||
import { error } from "./error.ts";
|
import { error } from "./error.ts";
|
||||||
|
|
||||||
|
const MIN_DENO_VERSION = "1.25.0";
|
||||||
|
|
||||||
|
export function ensureMinDenoVersion() {
|
||||||
|
// Check that the minimum supported Deno version is being used.
|
||||||
|
if (!gte(Deno.version.deno, MIN_DENO_VERSION)) {
|
||||||
|
let message =
|
||||||
|
`Deno version ${MIN_DENO_VERSION} or higher is required. Please update Deno.\n\n`;
|
||||||
|
|
||||||
|
if (Deno.execPath().includes("homebrew")) {
|
||||||
|
message +=
|
||||||
|
"You seem to have installed Deno via homebrew. To update, run: `brew upgrade deno`\n";
|
||||||
|
} else {
|
||||||
|
message += "To update, run: `deno upgrade`\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
error(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
interface Manifest {
|
interface Manifest {
|
||||||
routes: string[];
|
routes: string[];
|
||||||
islands: string[];
|
islands: string[];
|
||||||
@@ -83,6 +103,7 @@ export async function generate(directory: string, manifest: Manifest) {
|
|||||||
// This file SHOULD be checked into source version control.
|
// This file SHOULD be checked into source version control.
|
||||||
// This file is automatically updated during development when running \`dev.ts\`.
|
// This file is automatically updated during development when running \`dev.ts\`.
|
||||||
|
|
||||||
|
import config from "./deno.json" assert { type: "json" };
|
||||||
${
|
${
|
||||||
routes.map((file, i) => `import * as $${i} from "./routes${file}";`).join(
|
routes.map((file, i) => `import * as $${i} from "./routes${file}";`).join(
|
||||||
"\n",
|
"\n",
|
||||||
@@ -107,6 +128,7 @@ const manifest = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
baseUrl: import.meta.url,
|
baseUrl: import.meta.url,
|
||||||
|
config,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default manifest;
|
export default manifest;
|
||||||
@@ -140,6 +162,8 @@ export default manifest;
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function dev(base: string, entrypoint: string) {
|
export async function dev(base: string, entrypoint: string) {
|
||||||
|
ensureMinDenoVersion();
|
||||||
|
|
||||||
entrypoint = new URL(entrypoint, base).href;
|
entrypoint = new URL(entrypoint, base).href;
|
||||||
|
|
||||||
const dir = dirname(fromFileUrl(base));
|
const dir = dirname(fromFileUrl(base));
|
||||||
|
|||||||
+16
-1
@@ -3,12 +3,17 @@ import { BUILD_ID } from "./constants.ts";
|
|||||||
import { denoPlugin, esbuild, toFileUrl } from "./deps.ts";
|
import { denoPlugin, esbuild, toFileUrl } from "./deps.ts";
|
||||||
import { Island, Plugin } from "./types.ts";
|
import { Island, Plugin } from "./types.ts";
|
||||||
|
|
||||||
|
export interface JSXConfig {
|
||||||
|
jsx: "react" | "react-jsx";
|
||||||
|
jsxImportSource?: string;
|
||||||
|
}
|
||||||
|
|
||||||
let esbuildInitialized: boolean | Promise<void> = false;
|
let esbuildInitialized: boolean | Promise<void> = false;
|
||||||
async function ensureEsbuildInitialized() {
|
async function ensureEsbuildInitialized() {
|
||||||
if (esbuildInitialized === false) {
|
if (esbuildInitialized === false) {
|
||||||
if (Deno.run === undefined) {
|
if (Deno.run === undefined) {
|
||||||
esbuildInitialized = esbuild.initialize({
|
esbuildInitialized = esbuild.initialize({
|
||||||
wasmURL: "https://unpkg.com/esbuild-wasm@0.14.51/esbuild.wasm",
|
wasmURL: "https://deno.land/x/esbuild@v0.14.51/esbuild.wasm",
|
||||||
worker: false,
|
worker: false,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -21,8 +26,14 @@ async function ensureEsbuildInitialized() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const JSX_RUNTIME_MODE = {
|
||||||
|
"react": "transform",
|
||||||
|
"react-jsx": "automatic",
|
||||||
|
} as const;
|
||||||
|
|
||||||
export class Bundler {
|
export class Bundler {
|
||||||
#importMapURL: URL;
|
#importMapURL: URL;
|
||||||
|
#jsxConfig: JSXConfig;
|
||||||
#islands: Island[];
|
#islands: Island[];
|
||||||
#plugins: Plugin[];
|
#plugins: Plugin[];
|
||||||
#cache: Map<string, Uint8Array> | Promise<void> | undefined = undefined;
|
#cache: Map<string, Uint8Array> | Promise<void> | undefined = undefined;
|
||||||
@@ -32,11 +43,13 @@ export class Bundler {
|
|||||||
islands: Island[],
|
islands: Island[],
|
||||||
plugins: Plugin[],
|
plugins: Plugin[],
|
||||||
importMapURL: URL,
|
importMapURL: URL,
|
||||||
|
jsxConfig: JSXConfig,
|
||||||
dev: boolean,
|
dev: boolean,
|
||||||
) {
|
) {
|
||||||
this.#islands = islands;
|
this.#islands = islands;
|
||||||
this.#plugins = plugins;
|
this.#plugins = plugins;
|
||||||
this.#importMapURL = importMapURL;
|
this.#importMapURL = importMapURL;
|
||||||
|
this.#jsxConfig = jsxConfig;
|
||||||
this.#dev = dev;
|
this.#dev = dev;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,6 +95,8 @@ export class Bundler {
|
|||||||
target: ["chrome99", "firefox99", "safari15"],
|
target: ["chrome99", "firefox99", "safari15"],
|
||||||
treeShaking: true,
|
treeShaking: true,
|
||||||
write: false,
|
write: false,
|
||||||
|
jsx: JSX_RUNTIME_MODE[this.#jsxConfig.jsx],
|
||||||
|
jsxImportSource: this.#jsxConfig.jsxImportSource,
|
||||||
});
|
});
|
||||||
// const metafileOutputs = bundle.metafile!.outputs;
|
// const metafileOutputs = bundle.metafile!.outputs;
|
||||||
|
|
||||||
|
|||||||
+32
-4
@@ -11,9 +11,9 @@ import {
|
|||||||
} from "./deps.ts";
|
} from "./deps.ts";
|
||||||
import { h } from "preact";
|
import { h } from "preact";
|
||||||
import { Manifest } from "./mod.ts";
|
import { Manifest } from "./mod.ts";
|
||||||
import { Bundler } from "./bundle.ts";
|
import { Bundler, JSXConfig } from "./bundle.ts";
|
||||||
import { ALIVE_URL, BUILD_ID, JS_PREFIX, REFRESH_JS_URL } from "./constants.ts";
|
import { ALIVE_URL, BUILD_ID, JS_PREFIX, REFRESH_JS_URL } from "./constants.ts";
|
||||||
import DefaultErrorHandler from "./default_error_page.tsx";
|
import DefaultErrorHandler from "./default_error_page.ts";
|
||||||
import {
|
import {
|
||||||
AppModule,
|
AppModule,
|
||||||
ErrorPage,
|
ErrorPage,
|
||||||
@@ -31,7 +31,7 @@ import {
|
|||||||
UnknownPage,
|
UnknownPage,
|
||||||
UnknownPageModule,
|
UnknownPageModule,
|
||||||
} from "./types.ts";
|
} from "./types.ts";
|
||||||
import { render as internalRender } from "./render.tsx";
|
import { render as internalRender } from "./render.ts";
|
||||||
import { ContentSecurityPolicyDirectives, SELF } from "../runtime/csp.ts";
|
import { ContentSecurityPolicyDirectives, SELF } from "../runtime/csp.ts";
|
||||||
import { ASSET_CACHE_BUST_KEY, INTERNAL_PREFIX } from "../runtime/utils.ts";
|
import { ASSET_CACHE_BUST_KEY, INTERNAL_PREFIX } from "../runtime/utils.ts";
|
||||||
interface RouterState {
|
interface RouterState {
|
||||||
@@ -75,6 +75,7 @@ export class ServerContext {
|
|||||||
error: ErrorPage,
|
error: ErrorPage,
|
||||||
plugins: Plugin[],
|
plugins: Plugin[],
|
||||||
importMapURL: URL,
|
importMapURL: URL,
|
||||||
|
jsxConfig: JSXConfig,
|
||||||
) {
|
) {
|
||||||
this.#routes = routes;
|
this.#routes = routes;
|
||||||
this.#islands = islands;
|
this.#islands = islands;
|
||||||
@@ -90,6 +91,7 @@ export class ServerContext {
|
|||||||
this.#islands,
|
this.#islands,
|
||||||
this.#plugins,
|
this.#plugins,
|
||||||
importMapURL,
|
importMapURL,
|
||||||
|
jsxConfig,
|
||||||
this.#dev,
|
this.#dev,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -103,7 +105,32 @@ export class ServerContext {
|
|||||||
): Promise<ServerContext> {
|
): Promise<ServerContext> {
|
||||||
// Get the manifest' base URL.
|
// Get the manifest' base URL.
|
||||||
const baseUrl = new URL("./", manifest.baseUrl).href;
|
const baseUrl = new URL("./", manifest.baseUrl).href;
|
||||||
const importMapURL = new URL("./import_map.json", manifest.baseUrl);
|
|
||||||
|
const config = manifest.config || { importMap: "./import_map.json" };
|
||||||
|
if (typeof config.importMap !== "string") {
|
||||||
|
throw new Error("deno.json must contain an 'importMap' property.");
|
||||||
|
}
|
||||||
|
const importMapURL = new URL(config.importMap, manifest.baseUrl);
|
||||||
|
|
||||||
|
config.compilerOptions ??= {};
|
||||||
|
|
||||||
|
let jsx: "react" | "react-jsx";
|
||||||
|
switch (config.compilerOptions.jsx) {
|
||||||
|
case "react":
|
||||||
|
case undefined:
|
||||||
|
jsx = "react";
|
||||||
|
break;
|
||||||
|
case "react-jsx":
|
||||||
|
jsx = "react-jsx";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new Error("Unknown jsx option: " + config.compilerOptions.jsx);
|
||||||
|
}
|
||||||
|
|
||||||
|
const jsxConfig: JSXConfig = {
|
||||||
|
jsx,
|
||||||
|
jsxImportSource: config.compilerOptions.jsxImportSource,
|
||||||
|
};
|
||||||
|
|
||||||
// Extract all routes, and prepare them into the `Page` structure.
|
// Extract all routes, and prepare them into the `Page` structure.
|
||||||
const routes: Route[] = [];
|
const routes: Route[] = [];
|
||||||
@@ -271,6 +298,7 @@ export class ServerContext {
|
|||||||
error,
|
error,
|
||||||
opts.plugins ?? [],
|
opts.plugins ?? [],
|
||||||
importMapURL,
|
importMapURL,
|
||||||
|
jsxConfig,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
import { h } from "preact";
|
||||||
|
import { DEBUG } from "./constants.ts";
|
||||||
|
import type { ErrorPageProps } from "./types.ts";
|
||||||
|
|
||||||
|
export default function DefaultErrorPage(props: ErrorPageProps) {
|
||||||
|
const { error } = props;
|
||||||
|
|
||||||
|
let message = undefined;
|
||||||
|
if (DEBUG) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
message = error.stack;
|
||||||
|
} else {
|
||||||
|
message = String(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return h(
|
||||||
|
"div",
|
||||||
|
{
|
||||||
|
style: {
|
||||||
|
display: "flex",
|
||||||
|
justifyContent: "center",
|
||||||
|
alignItems: "center",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{
|
||||||
|
style: {
|
||||||
|
border: "#f3f4f6 2px solid",
|
||||||
|
borderTop: "red 4px solid",
|
||||||
|
background: "#f9fafb",
|
||||||
|
margin: 16,
|
||||||
|
minWidth: "300px",
|
||||||
|
width: "50%",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
h("p", {
|
||||||
|
style: {
|
||||||
|
margin: 0,
|
||||||
|
fontSize: "12pt",
|
||||||
|
padding: 16,
|
||||||
|
fontFamily: "sans-serif",
|
||||||
|
},
|
||||||
|
}, "An error occured during route handling or page rendering."),
|
||||||
|
message && h("pre", {
|
||||||
|
style: {
|
||||||
|
margin: 0,
|
||||||
|
fontSize: "12pt",
|
||||||
|
overflowY: "auto",
|
||||||
|
padding: 16,
|
||||||
|
paddingTop: 0,
|
||||||
|
fontFamily: "monospace",
|
||||||
|
},
|
||||||
|
}, message),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
/** @jsx h */
|
|
||||||
|
|
||||||
import { h } from "preact";
|
|
||||||
import { DEBUG } from "./constants.ts";
|
|
||||||
import type { ErrorPageProps } from "./types.ts";
|
|
||||||
|
|
||||||
export default function DefaultErrorPage(props: ErrorPageProps) {
|
|
||||||
const { error } = props;
|
|
||||||
|
|
||||||
let message = undefined;
|
|
||||||
if (DEBUG) {
|
|
||||||
if (error instanceof Error) {
|
|
||||||
message = error.stack;
|
|
||||||
} else {
|
|
||||||
message = String(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: "flex",
|
|
||||||
justifyContent: "center",
|
|
||||||
alignItems: "center",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
border: "#f3f4f6 2px solid",
|
|
||||||
borderTop: "red 4px solid",
|
|
||||||
background: "#f9fafb",
|
|
||||||
margin: 16,
|
|
||||||
minWidth: "300px",
|
|
||||||
width: "50%",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<p
|
|
||||||
style={{
|
|
||||||
margin: 0,
|
|
||||||
fontSize: "12pt",
|
|
||||||
padding: 16,
|
|
||||||
fontFamily: "sans-serif",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
An error occured during route handling or page rendering.
|
|
||||||
</p>
|
|
||||||
{message && <pre
|
|
||||||
style={{
|
|
||||||
margin: 0,
|
|
||||||
fontSize: "12pt",
|
|
||||||
overflowY: "auto",
|
|
||||||
padding: 16,
|
|
||||||
paddingTop: 0,
|
|
||||||
fontFamily: "monospace",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{message}
|
|
||||||
</pre>}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
+11
-2
@@ -33,8 +33,8 @@ export type {
|
|||||||
UnknownHandlerContext,
|
UnknownHandlerContext,
|
||||||
UnknownPageProps,
|
UnknownPageProps,
|
||||||
} from "./types.ts";
|
} from "./types.ts";
|
||||||
export { RenderContext } from "./render.tsx";
|
export { RenderContext } from "./render.ts";
|
||||||
export type { InnerRenderFunction } from "./render.tsx";
|
export type { InnerRenderFunction } from "./render.ts";
|
||||||
|
|
||||||
export interface Manifest {
|
export interface Manifest {
|
||||||
routes: Record<
|
routes: Record<
|
||||||
@@ -47,6 +47,15 @@ export interface Manifest {
|
|||||||
>;
|
>;
|
||||||
islands: Record<string, IslandModule>;
|
islands: Record<string, IslandModule>;
|
||||||
baseUrl: string;
|
baseUrl: string;
|
||||||
|
config?: DenoConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface DenoConfig {
|
||||||
|
importMap: string;
|
||||||
|
compilerOptions?: {
|
||||||
|
jsx?: string;
|
||||||
|
jsxImportSource?: string;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export { ServerContext };
|
export { ServerContext };
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
/** @jsx h */
|
|
||||||
import { renderToString } from "preact-render-to-string";
|
import { renderToString } from "preact-render-to-string";
|
||||||
import { ComponentChildren, ComponentType, h, options } from "preact";
|
import { ComponentChildren, ComponentType, h, options } from "preact";
|
||||||
import {
|
import {
|
||||||
@@ -18,7 +17,6 @@ import { CSP_CONTEXT, nonce, NONE, UNSAFE_INLINE } from "../runtime/csp.ts";
|
|||||||
import { ContentSecurityPolicy } from "../runtime/csp.ts";
|
import { ContentSecurityPolicy } from "../runtime/csp.ts";
|
||||||
import { bundleAssetUrl } from "./constants.ts";
|
import { bundleAssetUrl } from "./constants.ts";
|
||||||
import { assetHashingHook } from "../runtime/utils.ts";
|
import { assetHashingHook } from "../runtime/utils.ts";
|
||||||
import { f } from "https://dev.jspm.io/npm:@jspm/core@1.1.1/nodelibs/chunk-0c2d1322.js";
|
|
||||||
|
|
||||||
export interface RenderOptions<Data> {
|
export interface RenderOptions<Data> {
|
||||||
route: Route<Data> | UnknownPage | ErrorPage;
|
route: Route<Data> | UnknownPage | ErrorPage;
|
||||||
@@ -348,21 +346,27 @@ export interface TemplateOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function template(opts: TemplateOptions): string {
|
export function template(opts: TemplateOptions): string {
|
||||||
const page = (
|
const page = h(
|
||||||
<html lang={opts.lang}>
|
"html",
|
||||||
<head>
|
{ lang: opts.lang },
|
||||||
<meta charSet="UTF-8" />
|
h(
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
"head",
|
||||||
{opts.preloads.map((src) => <link rel="modulepreload" href={src} />)}
|
null,
|
||||||
{opts.imports.map(([src, nonce]) => (
|
h("meta", { charSet: "UTF-8" }),
|
||||||
<script src={src} nonce={nonce} type="module"></script>
|
h("meta", {
|
||||||
))}
|
name: "viewport",
|
||||||
{opts.headComponents}
|
content: "width=device-width, initial-scale=1.0",
|
||||||
</head>
|
}),
|
||||||
<body dangerouslySetInnerHTML={{ __html: opts.bodyHtml }} />
|
opts.preloads.map((src) =>
|
||||||
</html>
|
h("link", { rel: "modulepreload", href: src })
|
||||||
|
),
|
||||||
|
opts.imports.map(([src, nonce]) =>
|
||||||
|
h("script", { src: src, nonce: nonce, type: "module" })
|
||||||
|
),
|
||||||
|
opts.headComponents,
|
||||||
|
),
|
||||||
|
h("body", { dangerouslySetInnerHTML: { __html: opts.bodyHtml } }),
|
||||||
);
|
);
|
||||||
|
|
||||||
return "<!DOCTYPE html>" + renderToString(page);
|
return "<!DOCTYPE html>" + renderToString(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { template } from "./render.tsx";
|
import { template } from "./render.ts";
|
||||||
import { assertStringIncludes } from "../../tests/deps.ts";
|
import { assertStringIncludes } from "../../tests/deps.ts";
|
||||||
|
|
||||||
Deno.test("check lang", () => {
|
Deno.test("check lang", () => {
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
import { ComponentType } from "preact";
|
import { ComponentType } from "preact";
|
||||||
import { ConnInfo, rutt, ServeInit } from "./deps.ts";
|
import { ConnInfo, rutt, ServeInit } from "./deps.ts";
|
||||||
import { InnerRenderFunction, RenderContext } from "./render.tsx";
|
import { InnerRenderFunction, RenderContext } from "./render.ts";
|
||||||
|
|
||||||
// --- APPLICATION CONFIGURATION ---
|
// --- APPLICATION CONFIGURATION ---
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -4,8 +4,9 @@ import { assert, assertEquals, assertStringIncludes } from "./deps.ts";
|
|||||||
import manifest from "./fixture_error/fresh.gen.ts";
|
import manifest from "./fixture_error/fresh.gen.ts";
|
||||||
|
|
||||||
const ctx = await ServerContext.fromManifest(manifest, {});
|
const ctx = await ServerContext.fromManifest(manifest, {});
|
||||||
|
const handler = ctx.handler();
|
||||||
const router = (req: Request) => {
|
const router = (req: Request) => {
|
||||||
return ctx.handler()(req, {
|
return handler(req, {
|
||||||
localAddr: {
|
localAddr: {
|
||||||
transport: "tcp",
|
transport: "tcp",
|
||||||
hostname: "127.0.0.1",
|
hostname: "127.0.0.1",
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"importMap": "./import_map.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"jsx": "react-jsx",
|
||||||
|
"jsxImportSource": "preact"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
// This file SHOULD be checked into source version control.
|
// This file SHOULD be checked into source version control.
|
||||||
// This file is automatically updated during development when running `dev.ts`.
|
// This file is automatically updated during development when running `dev.ts`.
|
||||||
|
|
||||||
|
import config from "./deno.json" assert { type: "json" };
|
||||||
import * as $0 from "./routes/[name].tsx";
|
import * as $0 from "./routes/[name].tsx";
|
||||||
import * as $1 from "./routes/_404.tsx";
|
import * as $1 from "./routes/_404.tsx";
|
||||||
import * as $2 from "./routes/_500.tsx";
|
import * as $2 from "./routes/_500.tsx";
|
||||||
@@ -69,6 +70,7 @@ const manifest = {
|
|||||||
"./islands/kebab-case-counter-test.tsx": $$2,
|
"./islands/kebab-case-counter-test.tsx": $$2,
|
||||||
},
|
},
|
||||||
baseUrl: import.meta.url,
|
baseUrl: import.meta.url,
|
||||||
|
config,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default manifest;
|
export default manifest;
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
/** @jsx h */
|
|
||||||
import { h } from "preact";
|
|
||||||
import { useState } from "preact/hooks";
|
import { useState } from "preact/hooks";
|
||||||
import { IS_BROWSER } from "$fresh/runtime.ts";
|
import { IS_BROWSER } from "$fresh/runtime.ts";
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,3 @@
|
|||||||
/** @jsx h */
|
|
||||||
import { h } from "preact";
|
|
||||||
|
|
||||||
export default function Test(props: { message: string }) {
|
export default function Test(props: { message: string }) {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
/** @jsx h */
|
|
||||||
import { h } from "preact";
|
|
||||||
import { useState } from "preact/hooks";
|
import { useState } from "preact/hooks";
|
||||||
import { IS_BROWSER } from "$fresh/runtime.ts";
|
import { IS_BROWSER } from "$fresh/runtime.ts";
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,3 @@
|
|||||||
/** @jsx h */
|
|
||||||
import { h } from "preact";
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
params: Record<string, string | string[]>;
|
params: Record<string, string | string[]>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
/** @jsx h */
|
|
||||||
import { h } from "preact";
|
|
||||||
import { UnknownPageProps } from "$fresh/server.ts";
|
import { UnknownPageProps } from "$fresh/server.ts";
|
||||||
|
|
||||||
export default function NotFoundPage({ url }: UnknownPageProps) {
|
export default function NotFoundPage({ url }: UnknownPageProps) {
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
/** @jsx h */
|
|
||||||
import { h } from "preact";
|
|
||||||
import { ErrorPageProps } from "$fresh/server.ts";
|
import { ErrorPageProps } from "$fresh/server.ts";
|
||||||
|
|
||||||
export default function Error500Page({ error }: ErrorPageProps) {
|
export default function Error500Page({ error }: ErrorPageProps) {
|
||||||
|
|||||||
@@ -1,6 +1,3 @@
|
|||||||
/** @jsx h */
|
|
||||||
/** @jsxFrag Fragment */
|
|
||||||
import { Fragment, h } from "preact";
|
|
||||||
import { Head } from "$fresh/runtime.ts";
|
import { Head } from "$fresh/runtime.ts";
|
||||||
import { AppProps } from "$fresh/server.ts";
|
import { AppProps } from "$fresh/server.ts";
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
/** @jsx h */
|
|
||||||
import { h } from "preact";
|
|
||||||
import Test from "../../islands/Test.tsx";
|
import Test from "../../islands/Test.tsx";
|
||||||
|
|
||||||
export default function Home() {
|
export default function Home() {
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
/** @jsx h */
|
|
||||||
import { h } from "preact";
|
|
||||||
import { PageProps, RouteConfig } from "$fresh/server.ts";
|
import { PageProps, RouteConfig } from "$fresh/server.ts";
|
||||||
|
|
||||||
export default function Page(props: PageProps) {
|
export default function Page(props: PageProps) {
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
/** @jsx h */
|
|
||||||
import { h } from "preact";
|
|
||||||
import { IS_BROWSER } from "$fresh/runtime.ts";
|
import { IS_BROWSER } from "$fresh/runtime.ts";
|
||||||
import Test from "../islands/Test.tsx";
|
import Test from "../islands/Test.tsx";
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
/** @jsx h */
|
|
||||||
import { h } from "preact";
|
|
||||||
import { HandlerContext } from "$fresh/server.ts";
|
import { HandlerContext } from "$fresh/server.ts";
|
||||||
|
|
||||||
export default function Page() {
|
export default function Page() {
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
/** @jsx h */
|
|
||||||
import { h } from "preact";
|
|
||||||
import { Handlers, PageProps } from "$fresh/server.ts";
|
import { Handlers, PageProps } from "$fresh/server.ts";
|
||||||
|
|
||||||
interface Data extends Record<string, unknown> {
|
interface Data extends Record<string, unknown> {
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
/** @jsx h */
|
|
||||||
import { h } from "preact";
|
|
||||||
import Counter from "../../islands/Counter.tsx";
|
import Counter from "../../islands/Counter.tsx";
|
||||||
import KebabCaseFileNameTest from "../../islands/kebab-case-counter-test.tsx";
|
import KebabCaseFileNameTest from "../../islands/kebab-case-counter-test.tsx";
|
||||||
import Test from "../../islands/Test.tsx";
|
import Test from "../../islands/Test.tsx";
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
/** @jsx h */
|
|
||||||
import { HandlerContext, RouteConfig } from "$fresh/server.ts";
|
import { HandlerContext, RouteConfig } from "$fresh/server.ts";
|
||||||
|
|
||||||
export const handler = {
|
export const handler = {
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
/** @jsx h */
|
|
||||||
import { h } from "preact";
|
|
||||||
import { PageProps } from "$fresh/server.ts";
|
import { PageProps } from "$fresh/server.ts";
|
||||||
|
|
||||||
export default function Home(props: PageProps) {
|
export default function Home(props: PageProps) {
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
/** @jsx h */
|
|
||||||
import { h } from "preact";
|
|
||||||
import { asset } from "$fresh/runtime.ts";
|
import { asset } from "$fresh/runtime.ts";
|
||||||
|
|
||||||
export default function StaticPage() {
|
export default function StaticPage() {
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
/** @jsx h */
|
|
||||||
import { h } from "preact";
|
|
||||||
import { PageProps, RouteConfig } from "$fresh/server.ts";
|
import { PageProps, RouteConfig } from "$fresh/server.ts";
|
||||||
|
|
||||||
export default function WildcardPage({ params }: PageProps) {
|
export default function WildcardPage({ params }: PageProps) {
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"importMap": "./import_map.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"jsx": "react-jsx",
|
||||||
|
"jsxImportSource": "preact"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,16 +2,18 @@
|
|||||||
// This file SHOULD be checked into source version control.
|
// This file SHOULD be checked into source version control.
|
||||||
// This file is automatically updated during development when running `dev.ts`.
|
// This file is automatically updated during development when running `dev.ts`.
|
||||||
|
|
||||||
import * as $0 from "./routes/index.tsx";
|
import config from "./deno.json" assert { type: "json" };
|
||||||
import * as $1 from "./routes/[...all].ts";
|
import * as $0 from "./routes/[...all].ts";
|
||||||
|
import * as $1 from "./routes/index.tsx";
|
||||||
|
|
||||||
const manifest = {
|
const manifest = {
|
||||||
routes: {
|
routes: {
|
||||||
"./routes/index.tsx": $0,
|
"./routes/[...all].ts": $0,
|
||||||
"./routes/[...all].ts": $1,
|
"./routes/index.tsx": $1,
|
||||||
},
|
},
|
||||||
islands: {},
|
islands: {},
|
||||||
baseUrl: import.meta.url,
|
baseUrl: import.meta.url,
|
||||||
|
config,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default manifest;
|
export default manifest;
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"importMap": "./import-map.json"
|
||||||
|
}
|
||||||
Executable
+5
@@ -0,0 +1,5 @@
|
|||||||
|
#!/usr/bin/env -S deno run -A --watch=static/,routes/
|
||||||
|
|
||||||
|
import dev from "$fresh/dev.ts";
|
||||||
|
|
||||||
|
await dev(import.meta.url, "./main.ts");
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
// DO NOT EDIT. This file is generated by fresh.
|
||||||
|
// This file SHOULD be checked into source version control.
|
||||||
|
// This file is automatically updated during development when running `dev.ts`.
|
||||||
|
|
||||||
|
import config from "./deno.json" assert { type: "json" };
|
||||||
|
import * as $0 from "./routes/index.tsx";
|
||||||
|
import * as $$0 from "./islands/Island.tsx";
|
||||||
|
|
||||||
|
const manifest = {
|
||||||
|
routes: {
|
||||||
|
"./routes/index.tsx": $0,
|
||||||
|
},
|
||||||
|
islands: {
|
||||||
|
"./islands/Island.tsx": $$0,
|
||||||
|
},
|
||||||
|
baseUrl: import.meta.url,
|
||||||
|
config,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default manifest;
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"imports": {
|
||||||
|
"$fresh/": "../../",
|
||||||
|
"preact": "https://esm.sh/preact@10.10.0",
|
||||||
|
"preact/": "https://esm.sh/preact@10.10.0/",
|
||||||
|
"preact-render-to-string": "https://esm.sh/preact-render-to-string@5.2.1?external=preact"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
/** @jsx h */
|
||||||
|
import { h } from "preact";
|
||||||
|
import { IS_BROWSER } from "../../../src/runtime/utils.ts";
|
||||||
|
|
||||||
|
export default function Island() {
|
||||||
|
const id = IS_BROWSER ? "csr" : "ssr";
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<p id={id}>{id}</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
/// <reference no-default-lib="true" />
|
||||||
|
/// <reference lib="dom" />
|
||||||
|
/// <reference lib="dom.asynciterable" />
|
||||||
|
/// <reference lib="deno.ns" />
|
||||||
|
/// <reference lib="deno.unstable" />
|
||||||
|
|
||||||
|
import { start } from "$fresh/server.ts";
|
||||||
|
import manifest from "./fresh.gen.ts";
|
||||||
|
await start(manifest);
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
/** @jsx h */
|
||||||
|
import { h } from "preact";
|
||||||
|
import Island from "../islands/Island.tsx";
|
||||||
|
|
||||||
|
export default function Home() {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h1>Hello World</h1>
|
||||||
|
<Island />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"importMap": "./import_map.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"jsx": "react-jsx",
|
||||||
|
"jsxImportSource": "preact"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
// This file SHOULD be checked into source version control.
|
// This file SHOULD be checked into source version control.
|
||||||
// This file is automatically updated during development when running `dev.ts`.
|
// This file is automatically updated during development when running `dev.ts`.
|
||||||
|
|
||||||
|
import config from "./deno.json" assert { type: "json" };
|
||||||
import * as $0 from "./routes/static.tsx";
|
import * as $0 from "./routes/static.tsx";
|
||||||
import * as $1 from "./routes/with-island.tsx";
|
import * as $1 from "./routes/with-island.tsx";
|
||||||
import * as $$0 from "./islands/Island.tsx";
|
import * as $$0 from "./islands/Island.tsx";
|
||||||
@@ -15,6 +16,7 @@ const manifest = {
|
|||||||
"./islands/Island.tsx": $$0,
|
"./islands/Island.tsx": $$0,
|
||||||
},
|
},
|
||||||
baseUrl: import.meta.url,
|
baseUrl: import.meta.url,
|
||||||
|
config,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default manifest;
|
export default manifest;
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
/** @jsx h */
|
|
||||||
import { h } from "preact";
|
|
||||||
import { IS_BROWSER } from "../../../src/runtime/utils.ts";
|
import { IS_BROWSER } from "../../../src/runtime/utils.ts";
|
||||||
|
|
||||||
export default function Island() {
|
export default function Island() {
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
/** @jsx h */
|
|
||||||
import { h } from "preact";
|
|
||||||
import { inject } from "../utils/css-inject-plugin.ts";
|
import { inject } from "../utils/css-inject-plugin.ts";
|
||||||
|
|
||||||
export default function Home() {
|
export default function Home() {
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
/** @jsx h */
|
|
||||||
import { h } from "preact";
|
|
||||||
import Island from "../islands/Island.tsx";
|
import Island from "../islands/Island.tsx";
|
||||||
import { inject } from "../utils/css-inject-plugin.ts";
|
import { inject } from "../utils/css-inject-plugin.ts";
|
||||||
|
|
||||||
|
|||||||
+65
-2
@@ -1,11 +1,19 @@
|
|||||||
import { ServerContext, Status } from "../server.ts";
|
import { ServerContext, Status } from "../server.ts";
|
||||||
import { assert, assertEquals, assertStringIncludes } from "./deps.ts";
|
import {
|
||||||
|
assert,
|
||||||
|
assertEquals,
|
||||||
|
assertStringIncludes,
|
||||||
|
delay,
|
||||||
|
puppeteer,
|
||||||
|
TextLineStream,
|
||||||
|
} from "./deps.ts";
|
||||||
import manifest from "./fixture/fresh.gen.ts";
|
import manifest from "./fixture/fresh.gen.ts";
|
||||||
import options from "./fixture/options.ts";
|
import options from "./fixture/options.ts";
|
||||||
|
|
||||||
const ctx = await ServerContext.fromManifest(manifest, options);
|
const ctx = await ServerContext.fromManifest(manifest, options);
|
||||||
|
const handler = ctx.handler();
|
||||||
const router = (req: Request) => {
|
const router = (req: Request) => {
|
||||||
return ctx.handler()(req, {
|
return handler(req, {
|
||||||
localAddr: {
|
localAddr: {
|
||||||
transport: "tcp",
|
transport: "tcp",
|
||||||
hostname: "127.0.0.1",
|
hostname: "127.0.0.1",
|
||||||
@@ -434,3 +442,58 @@ Deno.test({
|
|||||||
assertStringIncludes(body, "404 not found: /not_found");
|
assertStringIncludes(body, "404 not found: /not_found");
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Deno.test("jsx pragma works", {
|
||||||
|
sanitizeOps: false,
|
||||||
|
sanitizeResources: false,
|
||||||
|
}, async (t) => {
|
||||||
|
// Preparation
|
||||||
|
const serverProcess = Deno.run({
|
||||||
|
cmd: ["deno", "run", "-A", "./tests/fixture_jsx_pragma/main.ts"],
|
||||||
|
stdout: "piped",
|
||||||
|
stderr: "inherit",
|
||||||
|
});
|
||||||
|
|
||||||
|
const decoder = new TextDecoderStream();
|
||||||
|
const lines = serverProcess.stdout.readable
|
||||||
|
.pipeThrough(decoder)
|
||||||
|
.pipeThrough(new TextLineStream());
|
||||||
|
|
||||||
|
let started = false;
|
||||||
|
for await (const line of lines) {
|
||||||
|
if (line.includes("Listening on http://")) {
|
||||||
|
started = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!started) {
|
||||||
|
throw new Error("Server didn't start up");
|
||||||
|
}
|
||||||
|
|
||||||
|
await delay(100);
|
||||||
|
|
||||||
|
await t.step("ssr", async () => {
|
||||||
|
const resp = await fetch("http://localhost:8000");
|
||||||
|
assertEquals(resp.status, Status.OK);
|
||||||
|
const text = await resp.text();
|
||||||
|
assertStringIncludes(text, "Hello World");
|
||||||
|
assertStringIncludes(text, "ssr");
|
||||||
|
});
|
||||||
|
|
||||||
|
const browser = await puppeteer.launch({ args: ["--no-sandbox"] });
|
||||||
|
const page = await browser.newPage();
|
||||||
|
|
||||||
|
await page.goto("http://localhost:8000", {
|
||||||
|
waitUntil: "networkidle2",
|
||||||
|
});
|
||||||
|
|
||||||
|
await t.step("island is revived", async () => {
|
||||||
|
await page.waitForSelector("#csr");
|
||||||
|
});
|
||||||
|
|
||||||
|
await browser.close();
|
||||||
|
|
||||||
|
await lines.cancel();
|
||||||
|
serverProcess.kill("SIGTERM");
|
||||||
|
serverProcess.close();
|
||||||
|
});
|
||||||
|
|||||||
@@ -11,8 +11,9 @@ import manifest from "./fixture_plugin/fresh.gen.ts";
|
|||||||
import options from "./fixture_plugin/options.ts";
|
import options from "./fixture_plugin/options.ts";
|
||||||
|
|
||||||
const ctx = await ServerContext.fromManifest(manifest, options);
|
const ctx = await ServerContext.fromManifest(manifest, options);
|
||||||
|
const handler = ctx.handler();
|
||||||
const router = (req: Request) => {
|
const router = (req: Request) => {
|
||||||
return ctx.handler()(req, {
|
return handler(req, {
|
||||||
localAddr: {
|
localAddr: {
|
||||||
transport: "tcp",
|
transport: "tcp",
|
||||||
hostname: "127.0.0.1",
|
hostname: "127.0.0.1",
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
/** @jsx h */
|
import { JSX } from "preact";
|
||||||
import { h } from "preact";
|
|
||||||
|
|
||||||
export function RoundedButton(props: h.JSX.HTMLAttributes<HTMLButtonElement>) {
|
export function RoundedButton(props: JSX.HTMLAttributes<HTMLButtonElement>) {
|
||||||
return (
|
return (
|
||||||
<button
|
<button
|
||||||
style={{
|
style={{
|
||||||
|
|||||||
@@ -1,6 +1,3 @@
|
|||||||
/** @jsx h */
|
|
||||||
import { h } from "preact";
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
CATEGORIES,
|
CATEGORIES,
|
||||||
TableOfContentsCategory,
|
TableOfContentsCategory,
|
||||||
|
|||||||
@@ -1,6 +1,3 @@
|
|||||||
/** @jsx h */
|
|
||||||
import { h } from "preact";
|
|
||||||
|
|
||||||
export function NoBuild() {
|
export function NoBuild() {
|
||||||
return (
|
return (
|
||||||
<svg
|
<svg
|
||||||
|
|||||||
@@ -1,6 +1,3 @@
|
|||||||
/** @jsx h */
|
|
||||||
import { h } from "preact";
|
|
||||||
|
|
||||||
const LINKS = [
|
const LINKS = [
|
||||||
{
|
{
|
||||||
title: "Source",
|
title: "Source",
|
||||||
|
|||||||
@@ -1,6 +1,3 @@
|
|||||||
/** @jsx h */
|
|
||||||
import { h } from "preact";
|
|
||||||
|
|
||||||
export function IconMinus() {
|
export function IconMinus() {
|
||||||
return (
|
return (
|
||||||
<svg
|
<svg
|
||||||
|
|||||||
@@ -1,6 +1,3 @@
|
|||||||
/** @jsx h */
|
|
||||||
import { h } from "preact";
|
|
||||||
|
|
||||||
export default function NavigationBar(props: { active: string }) {
|
export default function NavigationBar(props: { active: string }) {
|
||||||
const items = [
|
const items = [
|
||||||
{
|
{
|
||||||
|
|||||||
+5
-1
@@ -2,5 +2,9 @@
|
|||||||
"tasks": {
|
"tasks": {
|
||||||
"start": "deno run -A --watch=static/,routes/ dev.ts"
|
"start": "deno run -A --watch=static/,routes/ dev.ts"
|
||||||
},
|
},
|
||||||
"importMap": "./import_map.json"
|
"importMap": "./import_map.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"jsx": "react-jsx",
|
||||||
|
"jsxImportSource": "preact"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
// This file SHOULD be checked into source version control.
|
// This file SHOULD be checked into source version control.
|
||||||
// This file is automatically updated during development when running `dev.ts`.
|
// This file is automatically updated during development when running `dev.ts`.
|
||||||
|
|
||||||
|
import config from "./deno.json" assert { type: "json" };
|
||||||
import * as $0 from "./routes/_404.tsx";
|
import * as $0 from "./routes/_404.tsx";
|
||||||
import * as $1 from "./routes/_500.tsx";
|
import * as $1 from "./routes/_500.tsx";
|
||||||
import * as $2 from "./routes/docs/[...slug].tsx";
|
import * as $2 from "./routes/docs/[...slug].tsx";
|
||||||
@@ -27,6 +28,7 @@ const manifest = {
|
|||||||
"./islands/LemonDrop.tsx": $$2,
|
"./islands/LemonDrop.tsx": $$2,
|
||||||
},
|
},
|
||||||
baseUrl: import.meta.url,
|
baseUrl: import.meta.url,
|
||||||
|
config,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default manifest;
|
export default manifest;
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
/** @jsx h */
|
import { ComponentChildren } from "preact";
|
||||||
import { ComponentChildren, h } from "preact";
|
|
||||||
import { useEffect, useState } from "preact/hooks";
|
import { useEffect, useState } from "preact/hooks";
|
||||||
import { IS_BROWSER } from "$fresh/runtime.ts";
|
import { IS_BROWSER } from "$fresh/runtime.ts";
|
||||||
import * as Icons from "../components/Icons.tsx";
|
import * as Icons from "../components/Icons.tsx";
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
/** @jsx h */
|
|
||||||
import { h } from "preact";
|
|
||||||
import { useState } from "preact/hooks";
|
import { useState } from "preact/hooks";
|
||||||
import { IS_BROWSER } from "$fresh/runtime.ts";
|
import { IS_BROWSER } from "$fresh/runtime.ts";
|
||||||
import { RoundedButton } from "../components/Button.tsx";
|
import { RoundedButton } from "../components/Button.tsx";
|
||||||
|
|||||||
@@ -1,6 +1,3 @@
|
|||||||
/** @jsx h */
|
|
||||||
/** @jsxFrag Fragment */
|
|
||||||
import { Fragment, h } from "preact";
|
|
||||||
import { useEffect, useRef, useState } from "preact/hooks";
|
import { useEffect, useRef, useState } from "preact/hooks";
|
||||||
import { Spring, WaveTank } from "../components/WaveTank.ts";
|
import { Spring, WaveTank } from "../components/WaveTank.ts";
|
||||||
|
|
||||||
|
|||||||
+2
-5
@@ -1,13 +1,10 @@
|
|||||||
/** @jsx h */
|
|
||||||
/** @jsxFrag Fragment */
|
|
||||||
import { Fragment, h } from "preact";
|
|
||||||
import LemonDrop from "../islands/LemonDrop.tsx";
|
import LemonDrop from "../islands/LemonDrop.tsx";
|
||||||
|
|
||||||
export function ServerCodePage(
|
export function ServerCodePage(
|
||||||
props: { serverCode: number; codeDescription: string },
|
props: { serverCode: number; codeDescription: string },
|
||||||
) {
|
) {
|
||||||
return (
|
return (
|
||||||
<Fragment>
|
<>
|
||||||
<section>
|
<section>
|
||||||
<div class="w-full flex justify-center items-center flex-col bg-green-300">
|
<div class="w-full flex justify-center items-center flex-col bg-green-300">
|
||||||
<LemonDrop />
|
<LemonDrop />
|
||||||
@@ -26,7 +23,7 @@ export function ServerCodePage(
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</Fragment>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,3 @@
|
|||||||
/** @jsx h */
|
|
||||||
/** @jsxFrag Fragment */
|
|
||||||
import { Fragment, h } from "preact";
|
|
||||||
import { Head } from "$fresh/runtime.ts";
|
import { Head } from "$fresh/runtime.ts";
|
||||||
import { Handlers, PageProps } from "$fresh/server.ts";
|
import { Handlers, PageProps } from "$fresh/server.ts";
|
||||||
import { frontMatter, gfm } from "../../utils/markdown.ts";
|
import { frontMatter, gfm } from "../../utils/markdown.ts";
|
||||||
|
|||||||
@@ -1,6 +1,3 @@
|
|||||||
/** @jsx h */
|
|
||||||
/** @jsxFrag Fragment */
|
|
||||||
import { Fragment, h } from "preact";
|
|
||||||
import { asset, Head } from "$fresh/runtime.ts";
|
import { asset, Head } from "$fresh/runtime.ts";
|
||||||
import { Handlers, PageProps } from "$fresh/server.ts";
|
import { Handlers, PageProps } from "$fresh/server.ts";
|
||||||
import Counter from "../islands/Counter.tsx";
|
import Counter from "../islands/Counter.tsx";
|
||||||
@@ -68,7 +65,7 @@ export default function MainPage(props: PageProps) {
|
|||||||
|
|
||||||
function Hero() {
|
function Hero() {
|
||||||
return (
|
return (
|
||||||
<Fragment>
|
<>
|
||||||
<div class="flex justify-end items-center bg-green-300">
|
<div class="flex justify-end items-center bg-green-300">
|
||||||
<a
|
<a
|
||||||
href="/docs"
|
href="/docs"
|
||||||
@@ -80,7 +77,7 @@ function Hero() {
|
|||||||
<section class="w-full flex justify-center items-center flex-col bg-green-300">
|
<section class="w-full flex justify-center items-center flex-col bg-green-300">
|
||||||
<LemonDrop />
|
<LemonDrop />
|
||||||
</section>
|
</section>
|
||||||
</Fragment>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user