feat: use import maps instead of deps files (#209)

This commit updates fresh to use import maps instead of deps files in generated projects.
This commit is contained in:
Luca Casonato
2022-05-23 19:35:15 +02:00
committed by GitHub
parent fd1346ed6b
commit 80598d07fd
71 changed files with 188 additions and 141 deletions
+8 -4
View File
@@ -74,13 +74,17 @@ jobs:
run: deno check --remote cli.ts run: deno check --remote cli.ts
- name: Type check website - name: Type check website
run: deno check --remote www/main.ts run: deno check --remote main.ts
working-directory: www/
- name: Type check examples/counter - name: Type check examples/counter
run: deno check --remote examples/counter/main.ts run: deno check --remote main.ts
working-directory: examples/counter
- name: Type check tests/fixture - name: Type check tests/fixture
run: deno check tests/fixture/main.ts run: deno check main.ts
working-directory: tests/fixture/
- name: Type check tests/fixture_error - name: Type check tests/fixture_error
run: deno check tests/fixture_error/main.ts run: deno check main.ts
working-directory: tests/fixture_error/
+8
View File
@@ -0,0 +1,8 @@
{
".": "THIS FILE EXISTS ONLY FOR VSCODE! IT IS NOT USED AT RUNTIME.",
"imports": {
"$fresh/": "../",
"$twind": "https://esm.sh/twind@0.16.16",
"$twind/": "https://esm.sh/twind@0.16.16/"
}
}
+2 -1
View File
@@ -1,4 +1,5 @@
{ {
"deno.enable": true, "deno.enable": true,
"deno.lint": true "deno.lint": true,
"deno.importMap": "./.vscode/import_map.json"
} }
+3 -2
View File
@@ -1,7 +1,8 @@
{ {
"tasks": { "tasks": {
"test": "deno test -A --no-check=remote && deno check www/main.ts && deno check cli.ts", "test": "deno test -A --no-check=remote && deno check --config=www/deno.json www/main.ts && deno check cli.ts",
"fixture": "deno run -A --watch ./tests/fixture/main.ts & deno run -A ./cli.ts manifest --watch ./tests/fixture", "fixture": "deno run -A --watch ./tests/fixture/main.ts & deno run -A ./cli.ts manifest --watch ./tests/fixture",
"www": "deno run -A --watch=www/static,docs/ ./www/main.ts & deno run -A ./cli.ts manifest --watch ./www" "www": "deno run -A --watch=www/static,docs/ ./www/main.ts & deno run -A ./cli.ts manifest --watch ./www"
} },
"importMap": "./tests/fixture/import_map.json"
} }
+1 -1
View File
@@ -15,7 +15,7 @@ used to pass arbituary data to downstream (or upstream) handlers.
```ts ```ts
// routes/_middleware.ts // routes/_middleware.ts
import { MiddlewareHandlerContext } from "../deps.server.ts"; import { MiddlewareHandlerContext } from "$fresh/server.ts";
interface State { interface State {
data: string; data: string;
+4 -4
View File
@@ -22,7 +22,7 @@ Let's look at a basic route that returns a plain text string:
```tsx ```tsx
// routes/plain.tsx // routes/plain.tsx
import { HandlerContext, Handlers } from "../deps.server.ts"; import { HandlerContext, Handlers } from "$fresh/server.ts";
export const handler: Handlers = { export const handler: Handlers = {
GET(ctx: HandlerContext) { GET(ctx: HandlerContext) {
@@ -43,7 +43,7 @@ Now, let's render some HTML using the route component. Another example:
// routes/html.tsx // routes/html.tsx
/** @jsx h */ /** @jsx h */
import { h, PageProps } from "../deps.client.ts"; import { h, PageProps } from "$fresh/runtime.ts";
export default function Page(props: PageProps) { export default function Page(props: PageProps) {
return <div>You are on the page '{props.url.href}'.</div>; return <div>You are on the page '{props.url.href}'.</div>;
@@ -65,8 +65,8 @@ response after rendering the page component.
// routes/html.tsx // routes/html.tsx
/** @jsx h */ /** @jsx h */
import { h, PageProps } from "../deps.client.ts"; import { h, PageProps } from "$fresh/runtime.ts";
import { HandlerContext, Handlers } from "../deps.server.ts"; import { HandlerContext, Handlers } from "$fresh/server.ts";
export const handler: Handlers = { export const handler: Handlers = {
GET(ctx: HandlerContext) { GET(ctx: HandlerContext) {
+2 -2
View File
@@ -31,7 +31,7 @@ Here is an example of an island component that counts down to a specific time.
// islands/Countdown.tsx // islands/Countdown.tsx
/** @jsx h */ /** @jsx h */
import { h, useEffect, useMemo, useState } from "../deps.client.ts"; import { h, useEffect, useMemo, useState } from "$fresh/runtime.ts";
const timeFmt = new Intl.RelativeTimeFormat("en-US"); const timeFmt = new Intl.RelativeTimeFormat("en-US");
@@ -73,7 +73,7 @@ client with the correct props:
// routes/countdown.tsx // routes/countdown.tsx
/** @jsx h */ /** @jsx h */
import { h } from "../deps.client.ts"; import { h } from "$fresh/runtime.ts";
import { Countdown } from "../islands/Countdown.tsx"; import { Countdown } from "../islands/Countdown.tsx";
export default function Page() { export default function Page() {
+13 -13
View File
@@ -14,8 +14,8 @@ $ fresh init my-project
Manifest generated and written to ./my-project/fresh.gen.ts Manifest generated and written to ./my-project/fresh.gen.ts
``` ```
This will create a directory containing a bunch of files. Out of all of the This will create a directory containing some files and directories. There are 3
files, only two are strictly necessary for a fresh project: files that are strictly necessary to run a fresh project:
- **`main.ts`**: This is the entrypoint for your project. It is the file that - **`main.ts`**: This is the entrypoint for your project. It is the file that
will you run to start your fresh application. This file doesn't actually need will you run to start your fresh application. This file doesn't actually need
@@ -25,19 +25,17 @@ files, only two are strictly necessary for a fresh project:
your routes and islands. This file is automatically generated based on your your routes and islands. This file is automatically generated based on your
`routes/` and `islands/` folder by the `fresh` CLI when running the `routes/` and `islands/` folder by the `fresh` CLI when running the
`fresh manifest` command. `fresh manifest` command.
- **`import_map.json`**: This is an [import map][import-map] that is used to
manage dependencies for the project. This allows for easy importing and
updating of dependencies.
In addition to these two files, two other files are created that manage A **`deno.json`** file is also created in the project directory. This file does
dependencies: two things:
- **`deps.client.ts`**: This file contains dependencies that you need on the - It tells Deno about the location of the import map, so that it can be loaded
client, and possibly also on the server. It should be assumed that all of the automatically.
dependencies referenced by this file will be shipped to the client. By - It registers a "start" [task][task-runner] to run the project without having
default, it just re-exports the `fresh` runtime. to type a long `deno run` command.
- **`deps.server.ts`**: This file contains dependencies that are only used on
the server. These are often things like database drivers, API clients, or
other code that should only be executed on the server. This file should never
be referenced by modules that might be shipped to the client. By default this
just re-exports the `fresh` server libraries.
Two important folders are also created that contain your routes and islands Two important folders are also created that contain your routes and islands
respectively: respectively:
@@ -54,4 +52,6 @@ respectively:
Finally a **`static/`** folder is created that contains static files that are Finally a **`static/`** folder is created that contains static files that are
automatically served "as is". [Learn more about static files][static-files]. automatically served "as is". [Learn more about static files][static-files].
[import-map]: https://deno.land/manual/linking_to_external_code/import_maps
[task-runner]: https://deno.land/manual/tools/task_runner
[static-files]: ../concepts/static-files [static-files]: ../concepts/static-files
+1 -1
View File
@@ -38,7 +38,7 @@ This is done with JSX.
// routes/about.tsx // routes/about.tsx
/** @jsx h */ /** @jsx h */
import { h } from "../deps.client.ts"; import { h } from "$fresh/runtime.ts";
export default function AboutPage() { export default function AboutPage() {
return ( return (
+2 -2
View File
@@ -31,7 +31,7 @@ then adds a custom header to the response before returning it:
// routes/about.tsx // routes/about.tsx
/** @jsx h */ /** @jsx h */
import { h, Handlers } from "../deps.client.ts"; import { h, Handlers } from "$fresh/runtime.ts";
export const handler: Handlers = { export const handler: Handlers = {
GET(req, ctx) { GET(req, ctx) {
@@ -58,7 +58,7 @@ response:
```ts ```ts
// routes/api/random-uuid.ts // routes/api/random-uuid.ts
import { Handlers } from "../deps.client.ts"; import { Handlers } from "$fresh/runtime.ts";
export const handler: Handlers = { export const handler: Handlers = {
GET(req) { GET(req) {
+1 -1
View File
@@ -28,7 +28,7 @@ as arguments in it's `props` object though.
// routes/greet/[name].tsx // routes/greet/[name].tsx
/** @jsx h */ /** @jsx h */
import { h, PageProps } from "../../deps.client.ts"; import { h, PageProps } from "$fresh/runtime.ts";
export default function AboutPage(props: PageProps) { export default function AboutPage(props: PageProps) {
const { name } = props.params; const { name } = props.params;
+2 -2
View File
@@ -24,8 +24,8 @@ renders it in a page component.
// routes/github/[username].tsx // routes/github/[username].tsx
/** @jsx h */ /** @jsx h */
import { h, PageProps } from "../../deps.client.ts"; import { h, PageProps } from "$fresh/runtime.ts";
import { Handlers } from "../../deps.server.ts"; import { Handlers } from "$fresh/server.ts";
interface User { interface User {
login: string; login: string;
+2 -2
View File
@@ -33,8 +33,8 @@ server side:
// routes/search.tsx // routes/search.tsx
/** @jsx h */ /** @jsx h */
import { h, PageProps } from "../../deps.client.ts"; import { h, PageProps } from "$fresh/runtime.ts";
import { Handlers } from "../../deps.server.ts"; import { Handlers } from "$fresh/server.ts";
const NAMES = ["Alice", "Bob", "Charlie", "Dave", "Eve", "Frank"]; const NAMES = ["Alice", "Bob", "Charlie", "Dave", "Eve", "Frank"];
+2 -1
View File
@@ -1,5 +1,6 @@
{ {
"tasks": { "tasks": {
"start": "deno run -A --watch main.ts & deno run -A ../../cli.ts manifest --watch" "start": "deno run -A --watch main.ts & deno run -A ../../cli.ts manifest --watch"
} },
"importMap": "./import_map.json"
} }
-1
View File
@@ -1 +0,0 @@
export * from "../../runtime.ts";
-1
View File
@@ -1 +0,0 @@
export * from "../../server.ts";
+5
View File
@@ -0,0 +1,5 @@
{
"imports": {
"$fresh/": "../../"
}
}
+1 -1
View File
@@ -1,5 +1,5 @@
/** @jsx h */ /** @jsx h */
import { h, IS_BROWSER, useState } from "../deps.client.ts"; import { h, IS_BROWSER, useState } from "$fresh/runtime.ts";
interface CounterProps { interface CounterProps {
start: number; start: number;
+1 -1
View File
@@ -4,7 +4,7 @@
/// <reference lib="deno.ns" /> /// <reference lib="deno.ns" />
/// <reference lib="deno.unstable" /> /// <reference lib="deno.unstable" />
import { start } from "./deps.server.ts"; import { start } from "$fresh/server.ts";
import manifest from "./fresh.gen.ts"; import manifest from "./fresh.gen.ts";
await start(manifest); await start(manifest);
+1 -1
View File
@@ -1,5 +1,5 @@
/** @jsx h */ /** @jsx h */
import { h } from "../deps.client.ts"; import { h } from "$fresh/runtime.ts";
import Counter from "../islands/Counter.tsx"; import Counter from "../islands/Counter.tsx";
export default function Home() { export default function Home() {
+25 -21
View File
@@ -66,19 +66,19 @@ async function init(directory: string) {
await Deno.mkdir(join(directory, "islands"), { recursive: true }); await Deno.mkdir(join(directory, "islands"), { recursive: true });
await Deno.mkdir(join(directory, "static"), { recursive: true }); await Deno.mkdir(join(directory, "static"), { recursive: true });
const DEPS_CLIENT_TS = `export * from "${new URL( const IMPORT_MAP_JSON = JSON.stringify(
"../../runtime.ts", {
import.meta.url, "imports": {
)}";\n`; "$fresh/": new URL("../../", import.meta.url).href,
await Deno.writeTextFile(join(directory, "deps.client.ts"), DEPS_CLIENT_TS); },
const DEPS_SERVER_TS = `export * from "${new URL( },
"../../server.ts", null,
import.meta.url, 2,
)}";\n`; );
await Deno.writeTextFile(join(directory, "deps.server.ts"), DEPS_SERVER_TS); await Deno.writeTextFile(join(directory, "import_map.json"), IMPORT_MAP_JSON);
const ROUTES_INDEX_TSX = `/** @jsx h */ const ROUTES_INDEX_TSX = `/** @jsx h */
import { h } from "../deps.client.ts"; import { h } from "$fresh/runtime.ts";
import Counter from "../islands/Counter.tsx"; import Counter from "../islands/Counter.tsx";
export default function Home() { export default function Home() {
@@ -100,7 +100,7 @@ export default function Home() {
); );
const ISLANDS_COUNTER_TSX = `/** @jsx h */ const ISLANDS_COUNTER_TSX = `/** @jsx h */
import { h, IS_BROWSER, useState } from "../deps.client.ts"; import { h, IS_BROWSER, useState } from "$fresh/runtime.ts";
interface CounterProps { interface CounterProps {
start: number; start: number;
@@ -127,7 +127,7 @@ export default function Counter(props: CounterProps) {
); );
const ROUTES_GREET_TSX = `/** @jsx h */ const ROUTES_GREET_TSX = `/** @jsx h */
import { h, PageProps } from "../deps.client.ts"; import { h, PageProps } from "$fresh/runtime.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>;
@@ -138,8 +138,7 @@ export default function Greet(props: PageProps) {
ROUTES_GREET_TSX, ROUTES_GREET_TSX,
); );
const ROUTES_API_JOKE_TS = const ROUTES_API_JOKE_TS = `import { HandlerContext } from "$fresh/server.ts";
`import { HandlerContext } from "../../deps.server.ts";
// Jokes courtesy of https://punsandoneliners.com/randomness/programmer-jokes/ // Jokes courtesy of https://punsandoneliners.com/randomness/programmer-jokes/
const JOKES = [ const JOKES = [
@@ -188,7 +187,7 @@ export const handler = (_req: Request, _ctx: HandlerContext): Response => {
/// <reference lib="deno.ns" /> /// <reference lib="deno.ns" />
/// <reference lib="deno.unstable" /> /// <reference lib="deno.unstable" />
import { start } from "./deps.server.ts"; import { start } from "$fresh/server.ts";
import manifest from "./fresh.gen.ts"; import manifest from "./fresh.gen.ts";
await start(manifest); await start(manifest);
@@ -201,11 +200,16 @@ await start(manifest);
// this throws on windows // this throws on windows
} }
const DENO_CONFIG = `{ const DENO_CONFIG = JSON.stringify(
"tasks": { {
"start": "deno run -A --watch --no-check main.ts" tasks: {
} start: "deno run -A --watch --no-check main.ts",
}`; },
importMap: "./import_map.json",
},
null,
2,
);
await Deno.writeTextFile(join(directory, "deno.json"), DENO_CONFIG); await Deno.writeTextFile(join(directory, "deno.json"), DENO_CONFIG);
+1
View File
@@ -1,4 +1,5 @@
export * from "https://esm.sh/preact@10.6.6"; export * from "https://esm.sh/preact@10.6.6";
export { jsx, jsxDEV, jsxs } from "https://esm.sh/preact@10.6.6/jsx-runtime";
export { export {
useCallback, useCallback,
useContext, useContext,
+4 -2
View File
@@ -21,11 +21,13 @@ async function ensureEsbuildInialized() {
} }
export class Bundler { export class Bundler {
#importMapURL: URL;
#islands: Island[]; #islands: Island[];
#cache: Map<string, Uint8Array> | Promise<void> | undefined = undefined; #cache: Map<string, Uint8Array> | Promise<void> | undefined = undefined;
constructor(islands: Island[]) { constructor(islands: Island[], importMapURL: URL) {
this.#islands = islands; this.#islands = islands;
this.#importMapURL = importMapURL;
} }
async bundle() { async bundle() {
@@ -52,7 +54,7 @@ export class Bundler {
absWorkingDir, absWorkingDir,
outfile: "", outfile: "",
platform: "neutral", platform: "neutral",
plugins: [denoPlugin()], plugins: [denoPlugin({ importMapURL: this.#importMapURL })],
splitting: true, splitting: true,
target: ["chrome96", "firefox95", "safari14"], target: ["chrome96", "firefox95", "safari14"],
treeShaking: true, treeShaking: true,
+4 -1
View File
@@ -69,6 +69,7 @@ export class ServerContext {
app: AppModule, app: AppModule,
notFound: UnknownPage, notFound: UnknownPage,
error: ErrorPage, error: ErrorPage,
importMapURL: URL,
) { ) {
this.#pages = pages; this.#pages = pages;
this.#islands = islands; this.#islands = islands;
@@ -78,7 +79,7 @@ export class ServerContext {
this.#app = app; this.#app = app;
this.#notFound = notFound; this.#notFound = notFound;
this.#error = error; this.#error = error;
this.#bundler = new Bundler(this.#islands); this.#bundler = new Bundler(this.#islands, importMapURL);
this.#dev = typeof Deno.env.get("DENO_DEPLOYMENT_ID") !== "string"; // Env var is only set in prod (on Deploy). this.#dev = typeof Deno.env.get("DENO_DEPLOYMENT_ID") !== "string"; // Env var is only set in prod (on Deploy).
} }
@@ -88,6 +89,7 @@ export class ServerContext {
static async fromManifest(manifest: Manifest): Promise<ServerContext> { static async fromManifest(manifest: Manifest): 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);
// Extract all routes, and prepare them into the `Page` structure. // Extract all routes, and prepare them into the `Page` structure.
const pages: Page[] = []; const pages: Page[] = [];
@@ -254,6 +256,7 @@ export class ServerContext {
app, app,
notFound, notFound,
error, error,
importMapURL,
); );
} }
+1 -1
View File
@@ -30,4 +30,4 @@ const esbuild: typeof esbuildWasm = Deno.run === undefined
? esbuildWasm ? esbuildWasm
: esbuildNative; : esbuildNative;
export { esbuild, esbuildWasm as esbuildTypes }; export { esbuild, esbuildWasm as esbuildTypes };
export { denoPlugin } from "https://deno.land/x/esbuild_deno_loader@0.4.3/mod.ts"; export { denoPlugin } from "https://deno.land/x/esbuild_deno_loader@0.5.0/mod.ts";
+2 -3
View File
@@ -61,7 +61,7 @@ Deno.test({
"name": tmpDirName, "name": tmpDirName,
"contents": [ "contents": [
{ "type": "file", "name": "README.md" }, { "type": "file", "name": "README.md" },
{ "type": "file", "name": "deps.client.ts" }, { "type": "file", "name": "import_map.json" },
{ "type": "file", "name": "fresh.gen.ts" }, { "type": "file", "name": "fresh.gen.ts" },
{ {
"type": "directory", "type": "directory",
@@ -86,7 +86,6 @@ Deno.test({
{ "type": "file", "name": "index.tsx" }, { "type": "file", "name": "index.tsx" },
], ],
}, },
{ "type": "file", "name": "deps.server.ts" },
{ {
"type": "directory", "type": "directory",
"name": "static", "name": "static",
@@ -96,7 +95,7 @@ Deno.test({
}, },
], ],
}, },
{ "type": "report", "directories": 3, "files": 9 }, { "type": "report", "directories": 3, "files": 8 },
]; ];
await t.step("check generated files", async () => { await t.step("check generated files", async () => {
await assertFileExistence(targetFileTree); await assertFileExistence(targetFileTree);
+6
View File
@@ -1,3 +1,9 @@
/// <reference no-default-lib="true" />
/// <reference lib="dom" />
/// <reference lib="dom.asynciterable" />
/// <reference lib="deno.ns" />
/// <reference lib="deno.unstable" />
export { export {
assert, assert,
assertEquals, assertEquals,
-7
View File
@@ -1,7 +0,0 @@
/// <reference no-default-lib="true" />
/// <reference lib="dom" />
/// <reference lib="dom.asynciterable" />
/// <reference lib="deno.ns" />
/// <reference lib="deno.unstable" />
export * from "../../runtime.ts";
-1
View File
@@ -1 +0,0 @@
export * from "../../server.ts";
+5
View File
@@ -0,0 +1,5 @@
{
"imports": {
"$fresh/": "../../"
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
/** @jsx h */ /** @jsx h */
import { h } from "../deps.client.ts"; import { h } from "$fresh/runtime.ts";
export default function Test(props: { message: string }) { export default function Test(props: { message: string }) {
return ( return (
+7 -1
View File
@@ -1,4 +1,10 @@
import { start } from "./deps.server.ts"; /// <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 routes from "./fresh.gen.ts"; import routes from "./fresh.gen.ts";
await start(routes); await start(routes);
+1 -1
View File
@@ -1,6 +1,6 @@
/** @jsx h */ /** @jsx h */
import { h } from "../deps.client.ts"; import { h } from "$fresh/runtime.ts";
interface Props { interface Props {
params: Record<string, string | string[]>; params: Record<string, string | string[]>;
+1 -1
View File
@@ -1,6 +1,6 @@
/** @jsx h */ /** @jsx h */
import { h, UnknownPageProps } from "../deps.client.ts"; import { h, UnknownPageProps } from "$fresh/runtime.ts";
export default function NotFoundPage({ url }: UnknownPageProps) { export default function NotFoundPage({ url }: UnknownPageProps) {
return <p>404 not found: {url.pathname}</p>; return <p>404 not found: {url.pathname}</p>;
+1 -1
View File
@@ -1,6 +1,6 @@
/** @jsx h */ /** @jsx h */
import { ErrorPageProps, h } from "../deps.client.ts"; import { ErrorPageProps, h } from "$fresh/runtime.ts";
export default function Error500Page({ error }: ErrorPageProps) { export default function Error500Page({ error }: ErrorPageProps) {
return <p>500 internal error: {(error as Error).message}</p>; return <p>500 internal error: {(error as Error).message}</p>;
+1 -1
View File
@@ -1,7 +1,7 @@
/** @jsx h */ /** @jsx h */
/** @jsxFrag Fragment */ /** @jsxFrag Fragment */
import { AppProps, Fragment, h, Head } from "../deps.client.ts"; import { AppProps, Fragment, h, Head } from "$fresh/runtime.ts";
export default function App(props: AppProps) { export default function App(props: AppProps) {
return ( return (
+1 -1
View File
@@ -1,4 +1,4 @@
import { MiddlewareHandlerContext } from "../deps.server.ts"; import { MiddlewareHandlerContext } from "$fresh/server.ts";
export async function handler(_req: Request, ctx: MiddlewareHandlerContext) { export async function handler(_req: Request, ctx: MiddlewareHandlerContext) {
ctx.state.root = "root_mw"; ctx.state.root = "root_mw";
+1 -1
View File
@@ -1,6 +1,6 @@
/** @jsx h */ /** @jsx h */
import { asset, h } from "../../deps.client.ts"; import { asset, h } from "$fresh/runtime.ts";
import Test from "../../islands/Test.tsx"; import Test from "../../islands/Test.tsx";
export default function Home() { export default function Home() {
+1 -1
View File
@@ -1,6 +1,6 @@
/** @jsx h */ /** @jsx h */
import { h, PageProps, RouteConfig } from "../../deps.client.ts"; import { h, PageProps, RouteConfig } from "$fresh/runtime.ts";
export default function Page(props: PageProps) { export default function Page(props: PageProps) {
return <div>Book {props.params.id}</div>; return <div>Book {props.params.id}</div>;
+1 -1
View File
@@ -1,6 +1,6 @@
/** @jsx h */ /** @jsx h */
import { h, IS_BROWSER } from "../deps.client.ts"; import { h, IS_BROWSER } from "$fresh/runtime.ts";
import Test from "../islands/Test.tsx"; import Test from "../islands/Test.tsx";
export default function Home() { export default function Home() {
+1 -1
View File
@@ -1,6 +1,6 @@
/** @jsx h */ /** @jsx h */
import { h } from "../deps.client.ts"; import { h } from "$fresh/runtime.ts";
import { HandlerContext } from "../../../server.ts"; import { HandlerContext } from "../../../server.ts";
export default function Page() { export default function Page() {
+1 -1
View File
@@ -1,6 +1,6 @@
/** @jsx h */ /** @jsx h */
import { h, PageProps } from "../deps.client.ts"; import { h, PageProps } from "$fresh/runtime.ts";
import { HandlerContext, Handlers } from "../../../server.ts"; import { HandlerContext, Handlers } from "../../../server.ts";
interface Data extends Record<string, unknown> { interface Data extends Record<string, unknown> {
@@ -1,4 +1,4 @@
import { MiddlewareHandlerContext } from "../../deps.server.ts"; import { MiddlewareHandlerContext } from "$fresh/server.ts";
export async function handler(_req: Request, ctx: MiddlewareHandlerContext) { export async function handler(_req: Request, ctx: MiddlewareHandlerContext) {
ctx.state.layer1 = "layer1_mw"; ctx.state.layer1 = "layer1_mw";
@@ -1,4 +1,4 @@
import { MiddlewareHandlerContext } from "../../../deps.server.ts"; import { MiddlewareHandlerContext } from "$fresh/server.ts";
interface State { interface State {
root: string; root: string;
@@ -1,4 +1,4 @@
import { MiddlewareHandlerContext } from "../../../../deps.server.ts"; import { MiddlewareHandlerContext } from "$fresh/server.ts";
export async function handler(_req: Request, ctx: MiddlewareHandlerContext) { export async function handler(_req: Request, ctx: MiddlewareHandlerContext) {
ctx.state.layer3 = "layer3_mw"; ctx.state.layer3 = "layer3_mw";
+1 -1
View File
@@ -1,6 +1,6 @@
/** @jsx h */ /** @jsx h */
import { h, RouteConfig } from "../deps.client.ts"; import { h, RouteConfig } from "$fresh/runtime.ts";
import { HandlerContext } from "../../../server.ts"; import { HandlerContext } from "../../../server.ts";
export const handler = { export const handler = {
+1 -1
View File
@@ -1,6 +1,6 @@
/** @jsx h */ /** @jsx h */
import { h, PageProps } from "../../deps.client.ts"; import { h, PageProps } from "$fresh/runtime.ts";
export default function Home(props: PageProps) { export default function Home(props: PageProps) {
return <div>{JSON.stringify(props)}</div>; return <div>{JSON.stringify(props)}</div>;
+1 -1
View File
@@ -1,6 +1,6 @@
/** @jsx h */ /** @jsx h */
import { asset, h } from "../deps.client.ts"; import { asset, h } from "$fresh/runtime.ts";
export default function StaticPage() { export default function StaticPage() {
return ( return (
+1 -1
View File
@@ -1,6 +1,6 @@
/** @jsx h */ /** @jsx h */
import { h, PageProps, RouteConfig } from "../deps.client.ts"; import { h, PageProps, RouteConfig } from "$fresh/runtime.ts";
export default function WildcardPage({ params }: PageProps) { export default function WildcardPage({ params }: PageProps) {
if (typeof params.path === "string") { if (typeof params.path === "string") {
-1
View File
@@ -1 +0,0 @@
export * from "../../runtime.ts";
-1
View File
@@ -1 +0,0 @@
export * from "../../server.ts";
+5
View File
@@ -0,0 +1,5 @@
{
"imports": {
"$fresh/": "../../"
}
}
+1 -1
View File
@@ -4,7 +4,7 @@
/// <reference lib="deno.ns" /> /// <reference lib="deno.ns" />
/// <reference lib="deno.unstable" /> /// <reference lib="deno.unstable" />
import { start } from "./deps.server.ts"; import { start } from "$fresh/server.ts";
import manifest from "./fresh.gen.ts"; import manifest from "./fresh.gen.ts";
await start(manifest); await start(manifest);
+1 -1
View File
@@ -1,5 +1,5 @@
/** @jsx h */ /** @jsx h */
import { h } from "../deps.client.ts"; import { h } from "$fresh/runtime.ts";
export default function Home(): null { export default function Home(): null {
throw new Error("boom!"); throw new Error("boom!");
+2 -1
View File
@@ -1,6 +1,7 @@
/** @jsx h */ /** @jsx h */
import { h, tw } from "../deps.client.ts"; import { h } from "$fresh/runtime.ts";
import { tw } from "../utils/twind.ts";
export function RoundedButton(props: h.JSX.HTMLAttributes<HTMLButtonElement>) { export function RoundedButton(props: h.JSX.HTMLAttributes<HTMLButtonElement>) {
return ( return (
+3 -1
View File
@@ -1,6 +1,8 @@
/** @jsx h */ /** @jsx h */
import { apply, h, tw } from "../deps.client.ts"; import { h } from "$fresh/runtime.ts";
import { apply, tw } from "../utils/twind.ts";
import { import {
CATEGORIES, CATEGORIES,
TableOfContentsCategory, TableOfContentsCategory,
+2 -1
View File
@@ -1,6 +1,7 @@
/** @jsx h */ /** @jsx h */
import { h, tw } from "../deps.client.ts"; import { h } from "$fresh/runtime.ts";
import { tw } from "../utils/twind.ts";
const LINKS = [ const LINKS = [
{ {
+2 -1
View File
@@ -1,6 +1,7 @@
/** @jsx h */ /** @jsx h */
import { h, tw } from "../deps.client.ts"; import { h } from "$fresh/runtime.ts";
import { tw } from "../utils/twind.ts";
export function IconMinus() { export function IconMinus() {
return ( return (
+2 -1
View File
@@ -1,6 +1,7 @@
/** @jsx h */ /** @jsx h */
import { h, tw } from "../deps.client.ts"; import { h } from "$fresh/runtime.ts";
import { tw } from "../utils/twind.ts";
export default function NavigationBar(props: { active: string }) { export default function NavigationBar(props: { active: string }) {
const items = [ const items = [
+2 -1
View File
@@ -1,6 +1,7 @@
/** @jsx h */ /** @jsx h */
import { h, tw } from "../deps.client.ts"; import { h } from "$fresh/runtime.ts";
import { tw } from "../utils/twind.ts";
export default function WarningBanner() { export default function WarningBanner() {
const warning = tw`bg-yellow-100 border(1 yellow-200) p-4 mb-4`; const warning = tw`bg-yellow-100 border(1 yellow-200) p-4 mb-4`;
+6
View File
@@ -0,0 +1,6 @@
{
"tasks": {
"start": "deno run -A --watch main.ts & deno run -A ../cli.ts manifest --watch"
},
"importMap": "./import_map.json"
}
+7
View File
@@ -0,0 +1,7 @@
{
"imports": {
"$fresh/": "../",
"$twind": "https://esm.sh/twind@0.16.16",
"$twind/": "https://esm.sh/twind@0.16.16/"
}
}
+2 -1
View File
@@ -1,5 +1,6 @@
/** @jsx h */ /** @jsx h */
import { h, IS_BROWSER, tw, useState } from "../deps.client.ts"; import { h, IS_BROWSER, useState } from "$fresh/runtime.ts";
import { tw } from "../utils/twind.ts";
import { RoundedButton } from "../components/Button.tsx"; import { RoundedButton } from "../components/Button.tsx";
import { IconMinus, IconPlus } from "../components/Icons.tsx"; import { IconMinus, IconPlus } from "../components/Icons.tsx";
+5 -10
View File
@@ -1,12 +1,7 @@
/** @jsx h */ /** @jsx h */
import { /** @jsxFrag Fragment */
Fragment, import { Fragment, h, useEffect, useRef, useState } from "$fresh/runtime.ts";
h, import { tw } from "../utils/twind.ts";
tw,
useEffect,
useRef,
useState,
} from "../deps.client.ts";
import { Spring, WaveTank } from "../components/WaveTank.ts"; import { Spring, WaveTank } from "../components/WaveTank.ts";
function easeInCirc(x: number) { function easeInCirc(x: number) {
@@ -99,7 +94,7 @@ function LemonDrop() {
}, []); }, []);
return ( return (
<Fragment> <>
<svg <svg
width="100" width="100"
height="300" height="300"
@@ -143,7 +138,7 @@ function LemonDrop() {
> >
</polygon> </polygon>
</svg> </svg>
</Fragment> </>
); );
} }
+1 -1
View File
@@ -4,7 +4,7 @@
/// <reference lib="deno.ns" /> /// <reference lib="deno.ns" />
/// <reference lib="deno.unstable" /> /// <reference lib="deno.unstable" />
import { start } from "./deps.server.ts"; import { start } from "$fresh/server.ts";
import routes from "./fresh.gen.ts"; import routes from "./fresh.gen.ts";
await start(routes); await start(routes);
+3 -2
View File
@@ -1,7 +1,8 @@
// This module adds twind support. // This module adds twind support.
import { setup, theme } from "../deps.client.ts"; import { RenderContext, RenderFn } from "$fresh/server.ts";
import { RenderContext, RenderFn, virtualSheet } from "../deps.server.ts"; import { setup, theme } from "../utils/twind.ts";
import { virtualSheet } from "$twind/sheets";
const sheet = virtualSheet(); const sheet = virtualSheet();
sheet.reset(); sheet.reset();
+5 -10
View File
@@ -1,16 +1,11 @@
/** @jsx h */ /** @jsx h */
/** @jsxFrag Fragment */ /** @jsxFrag Fragment */
import { import { Fragment, h, Head, PageProps } from "$fresh/runtime.ts";
apply, import { Handlers } from "$fresh/server.ts";
asset, import { apply, tw } from "../../utils/twind.ts";
Fragment, import { frontMatter, gfm } from "../../utils/markdown.ts";
h,
Head,
PageProps,
tw,
} from "../../deps.client.ts";
import { frontMatter, gfm, Handlers } from "../../deps.server.ts";
import DocsSidebar from "../../components/DocsSidebar.tsx"; import DocsSidebar from "../../components/DocsSidebar.tsx";
import Footer from "../../components/Footer.tsx"; import Footer from "../../components/Footer.tsx";
import NavigationBar from "../../components/NavigationBar.tsx"; import NavigationBar from "../../components/NavigationBar.tsx";
+2 -1
View File
@@ -1,4 +1,5 @@
import { gfm, Handlers } from "../deps.server.ts"; import { Handlers } from "$fresh/server.ts";
import { gfm } from "../utils/markdown.ts";
// TODO(lucacasonato): hash the file and use the hash as the filename, and serve // TODO(lucacasonato): hash the file and use the hash as the filename, and serve
// with high-cacheability headers. // with high-cacheability headers.
+2 -2
View File
@@ -8,8 +8,8 @@ import {
h, h,
Head, Head,
PageProps, PageProps,
tw, } from "$fresh/runtime.ts";
} from "../deps.client.ts"; import { tw } from "../utils/twind.ts";
import Counter from "../islands/Counter.tsx"; import Counter from "../islands/Counter.tsx";
import LemonDrop from "../islands/LemonDrop.tsx"; import LemonDrop from "../islands/LemonDrop.tsx";
import Footer from "../components/Footer.tsx"; import Footer from "../components/Footer.tsx";
@@ -1,7 +1,3 @@
export * from "../server.ts";
export { virtualSheet } from "https://esm.sh/twind@0.16.16/sheets";
export * as gfm from "https://deno.land/x/gfm@0.1.19/mod.ts"; export * as gfm from "https://deno.land/x/gfm@0.1.19/mod.ts";
import "https://esm.sh/prismjs@1.27.0/components/prism-jsx.js?no-check"; import "https://esm.sh/prismjs@1.27.0/components/prism-jsx.js?no-check";
import "https://esm.sh/prismjs@1.27.0/components/prism-typescript.js?no-check"; import "https://esm.sh/prismjs@1.27.0/components/prism-typescript.js?no-check";
+3 -4
View File
@@ -1,7 +1,6 @@
export * from "../runtime.ts"; import { IS_BROWSER } from "$fresh/runtime.ts";
import { IS_BROWSER } from "../runtime.ts"; import { apply, setup, tw } from "$twind";
import { apply, setup, tw } from "https://esm.sh/twind@0.16.16"; import * as colors from "$twind/colors";
import * as colors from "https://esm.sh/twind@0.16.16/colors";
export { apply, setup, tw }; export { apply, setup, tw };
export const theme = { export const theme = {
colors: { colors: {